Skip to content

Commit

Permalink
Better fix for #2278. Fixes #1038
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Jun 24, 2022
1 parent 42b2140 commit b8076f3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/TemplatePassthrough.js
Expand Up @@ -67,10 +67,14 @@ class TemplatePassthrough {
TemplatePath.join(outputDir, outputPath)
);

if (this.isIncremental && TemplatePath.isDirectorySync(fullOutputPath)) {
if (
fs.existsSync(inputPath) &&
!TemplatePath.isDirectorySync(inputPath) &&
TemplatePath.isDirectorySync(fullOutputPath)
) {
let filename = path.parse(inputPath).base;
return TemplatePath.normalize(
TemplatePath.join(outputDir, outputPath, filename)
TemplatePath.join(fullOutputPath, filename)
);
}

Expand Down Expand Up @@ -141,7 +145,7 @@ class TemplatePassthrough {
*/
async copy(src, dest, copyOptions) {
if (
!TemplatePath.stripLeadingDotSlash(dest).includes(
!TemplatePath.stripLeadingDotSlash(dest).startsWith(
TemplatePath.stripLeadingDotSlash(this.outputDir)
)
) {
Expand Down
16 changes: 13 additions & 3 deletions test/TemplatePassthroughTest.js
Expand Up @@ -299,12 +299,22 @@ test("Output paths match with different templatePassthrough methods", async (t)
// t.is(pass.getOutputPath(), "_site/rename.js");
// });

test("Bug with incremental copying to a directory output, issue #2278", async (t) => {
test("Bug with incremental file copying to a directory output, issue #2278 #1038", async (t) => {
let pass1 = getTemplatePassthrough(
{ inputPath: "./public/test.css", outputPath: "/" },
{ inputPath: "./test/stubs/public/test.css", outputPath: "/" },
"test/stubs",
"."
);
pass1.setIsIncremental(true);

t.is(pass1.getOutputPath(), "test/stubs/test.css");
});

test("Bug with incremental dir copying to a directory output, issue #2278 #1038", async (t) => {
let pass1 = getTemplatePassthrough(
{ inputPath: "./test/stubs/public/", outputPath: "/" },
"test/stubs",
"."
);

t.is(pass1.getOutputPath(), "test/stubs");
});
Empty file added test/stubs/public/test.css
Empty file.

0 comments on commit b8076f3

Please sign in to comment.