Skip to content

Commit

Permalink
Make --incremental work with passthrough copy #108
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Sep 18, 2019
1 parent be76af7 commit f7fb085
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
4 changes: 3 additions & 1 deletion src/Eleventy.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,8 @@ Arguments:
let isInclude =
path &&
TemplatePath.startsWithSubPath(path, this.eleventyFiles.getIncludesDir());
let isJavaScriptDependency =
path && this.watchTargets.isJavaScriptDependency(path);

let localProjectConfigPath = config.getLocalProjectConfigFile();
// reset and reload global configuration :O
Expand All @@ -417,7 +419,7 @@ Arguments:
await this.restart();
this.watchTargets.clearDependencyRequireCache();

if (path && !isInclude && this.isIncremental) {
if (path && !isInclude && !isJavaScriptDependency && this.isIncremental) {
this.writer.setIncrementalFile(path);
}

Expand Down
4 changes: 4 additions & 0 deletions src/EleventyWatchTargets.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class EleventyWatchTargets {
return this._watchJavaScriptDependencies;
}

isJavaScriptDependency(path) {
return this.dependencies.has(path);
}

_normalizeTargets(targets) {
if (!targets) {
return [];
Expand Down
20 changes: 15 additions & 5 deletions src/TemplatePassthroughManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class TemplatePassthroughManager {

reset() {
this.count = 0;
this.incrementalFile = null;
debug("Resetting counts to 0");
}

Expand All @@ -34,6 +35,10 @@ class TemplatePassthroughManager {
this.isDryRun = !!isDryRun;
}

setIncrementalFile(path) {
this.incrementalFile = path;
}

_normalizePaths(path, outputPath) {
return {
inputPath: TemplatePath.addLeadingDotSlash(path),
Expand Down Expand Up @@ -87,16 +92,21 @@ class TemplatePassthroughManager {

async copyPath(path) {
let pass = new TemplatePassthrough(path, this.outputDir, this.inputDir);
pass.setDryRun(this.isDryRun);

if (this.incrementalFile && path.inputPath !== this.incrementalFile) {
pass.setDryRun(true);
} else {
pass.setDryRun(this.isDryRun);
}

return pass
.write()
.then(
function() {
.then(() => {
if (!pass.isDryRun) {
this.count++;
debug("Copied %o", path.inputPath);
}.bind(this)
)
}
})
.catch(function(e) {
return Promise.reject(
new TemplatePassthroughManagerCopyError(
Expand Down
21 changes: 12 additions & 9 deletions src/TemplateWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,19 @@ TemplateWriter.prototype.write = async function() {
let promises = [];
let paths = await this._getAllPaths();
debug("Found: %o", paths);

let passthroughManager = this.getFileManager().getPassthroughManager();
passthroughManager.setIncrementalFile(
this.incrementalFile ? this.incrementalFile : false
);

promises.push(
this.getFileManager()
.getPassthroughManager()
.copyAll(paths)
.catch(e => {
EleventyErrorHandler.warn(e, "Error with passthrough copy");
return Promise.reject(
new TemplateWriterWriteError(`Having trouble copying`, e)
);
})
passthroughManager.copyAll(paths).catch(e => {
EleventyErrorHandler.warn(e, "Error with passthrough copy");
return Promise.reject(
new TemplateWriterWriteError("Having trouble copying", e)
);
})
);

// TODO optimize await here
Expand Down

0 comments on commit f7fb085

Please sign in to comment.