Skip to content

Commit

Permalink
Skip hashing for files that won't ever exist, don't create an empty a…
Browse files Browse the repository at this point in the history
…rray just to discard it.
  • Loading branch information
chriseppstein committed Feb 19, 2019
1 parent 19eb8e4 commit 5f248e1
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions packages/broccoli-eyeglass/src/broccoli_sass_compiler.ts
Expand Up @@ -690,32 +690,48 @@ export default class BroccoliSassCompiler extends BroccoliPlugin {
return this.outputs[this.relativize(file)] || new Set();
}

/**
* Some filenames returned from importers are not really files
* on disk. These three prefixes are used in eyeglass.
* Skipping a read on these files avoids a more expensive fs call
* and exception handling.
* @param filename a filename returned from an importer
*/
isNotFile(filename: string): boolean {
return filename.startsWith("already-imported:") ||
filename.startsWith("autoGenerated:") ||
filename.startsWith("fs:");
}

/* hash all dependencies synchronously and return the files that exist
* as an array of pairs (filename, hash).
*/
hashDependencies(details: CompilationDetails): Array<[string, string]> {
let depsWithHashes = new Array<[string, string] | []>();
let depsWithHashes = new Array<[string, string]>();

this.dependenciesOf(details.fullSassFilename).forEach(f => {
try {
let h = this.hashForFile(f);
if (this.isNotFile(f)) {
persistentCacheDebug("Ignoring non-file dependency: %s", f);
} else {
let h = this.hashForFile(f);

if (f.startsWith(details.srcPath)) {
f = f.substring(details.srcPath.length + 1);
if (f.startsWith(details.srcPath)) {
f = f.substring(details.srcPath.length + 1);
}
depsWithHashes.push([f, h.digest("hex")]);
}
depsWithHashes.push([f, h.digest("hex")]);
} catch (e) {
if (typeof e === "object" && e !== null && e.code === "ENOENT") {
persistentCacheDebug("Ignoring non-existent file: %s", f);
depsWithHashes.push([]);
} else {
throw e;
}
}
});

// prune out the dependencies that weren't files.
return depsWithHashes.filter(dwh => dwh.length > 0) as Array<[string, string]>;
return depsWithHashes;
}

/* read all output files asynchronously and return the contents
Expand Down

0 comments on commit 5f248e1

Please sign in to comment.