Skip to content

Commit

Permalink
[broccoi-eyeglass] Address code review comments:
Browse files Browse the repository at this point in the history
* Shim for fs.Stats.mtimeMs.
* Removed unnecessary symbolic link handling for stat results.
* Handle statSync errors if a file has gone missing.
  • Loading branch information
chriseppstein committed Mar 28, 2019
1 parent 1089db0 commit d56c68c
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/broccoli-eyeglass/src/broccoli_sass_compiler.ts
Expand Up @@ -631,16 +631,17 @@ export default class BroccoliSassCompiler extends BroccoliPlugin {
}

/* compute a key for a file that will change if the file has changed. */
fileKey(file: string, isRealPath = false): string {
fileKey(file: string): string {
let cachedKeyKey = `fileKey(${file})`;
let cachedKey = this.buildCache.get(cachedKeyKey) as string;
if (cachedKey) { return cachedKey; }
let stat = statSync(file);
let key;
if (!isRealPath && stat.isSymbolicLink) {
key = this.fileKey(realpathSync(file), true);
} else {
key = `${stat.mtimeMs}:${stat.size}:${stat.mode}`;
try {
let stat = statSync(file);
key = `${mtimeMs(stat)}:${stat.size}:${stat.mode}`;
this.buildCache.set(cachedKeyKey, key);
} catch (_) {
key = `0:0:0`;
}
this.buildCache.set(cachedKeyKey, key);
return key;
Expand Down Expand Up @@ -1242,3 +1243,12 @@ class SassRenderSchema {
}

module.exports.shouldPersist = shouldPersist;

/* shim for fs.Stats.mtimeMS which was introduced in node 8. */
function mtimeMs(stat: fs.Stats): number {
if (stat.mtimeMs) {
return stat.mtimeMs;
} else {
return stat.mtime.valueOf();
}
}

0 comments on commit d56c68c

Please sign in to comment.