sindresorhus / gulp-changed

Only pass through changed files
MIT License
742 stars 44 forks source link

sourceFile.stat.mtimeMs and targetStat.mtimeMs #89

Closed mobiliabrus closed 11 months ago

mobiliabrus commented 11 months ago

For most of files, it works greatly. Sometimes, not. Eg, sourceFile.stat.mtimeMs is 1702113370657.8303, and the mtimeMs I got from fs.statSync(targetPath, { bigint: true }) is 1702113370657n.

So I tried this.

function hasChanged(sourceFile, targetPath) {
  if (!fs.existsSync(targetPath)) {
    return sourceFile;
  }
  const targetStat = fs.statSync(targetPath);
  if (sourceFile.stat && sourceFile.stat.mtimeMs - targetStat.mtimeMs > 1) { // 👈 
    console.log(chalk.green('processing ') + path.basename(targetPath));
    return sourceFile;
  }
  console.log('ignoring ' + path.basename(targetPath));
}