Skip to content

Commit

Permalink
Throw an error on invalid passthrough copy modes #3573
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleat committed Dec 11, 2024
1 parent 8bd3b97 commit a07facb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/UserConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,12 @@ class UserConfig {
* @returns {any} a reference to the `EleventyConfig` object.
*/
addPassthroughCopy(fileOrDir, copyOptions = {}) {
if (copyOptions.mode === "html-relative") {
if (copyOptions.mode) {
if (copyOptions.mode !== "html-relative") {
throw new Error(
"Invalid `mode` option for `addPassthroughCopy`. Received: '" + copyOptions.mode + "'",
);
}
if (isPlainObject(fileOrDir)) {
throw new Error(
"mode: 'html-relative' does not yet support passthrough copy objects (input -> output mapping). Use a string glob or an Array of string globs.",
Expand Down
24 changes: 23 additions & 1 deletion test/HtmlRelativeCopyTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,8 +592,30 @@ test("Input -> output remapping not yet supported (throws error)", async (t) =>
await t.throwsAsync(async () => {
await elev.write();
}, {
message: `mode: \'html-relative\' does not yet support passthrough copy objects (input -> output mapping). Use a string glob or an Array of string globs.`
message: `mode: 'html-relative' does not yet support passthrough copy objects (input -> output mapping). Use a string glob or an Array of string globs.`
});

t.is(fs.existsSync("test/stubs-autocopy/_site12/test/index.html"), false);
});

test("Invalid copy mode throws error", async (t) => {
let elev = new Eleventy("./test/stubs-autocopy/", "./test/stubs-autocopy/_site13", {
configPath: false,
config: function (eleventyConfig) {
// not yet supported
eleventyConfig.addPassthroughCopy({"**/*.png": "yo"}, {
mode: "throw-an-error"
});
},
});

elev.disableLogger();

await t.throwsAsync(async () => {
await elev.write();
}, {
message: `Invalid \`mode\` option for \`addPassthroughCopy\`. Received: 'throw-an-error'`
});

t.is(fs.existsSync("test/stubs-autocopy/_site13/test/index.html"), false);
});

0 comments on commit a07facb

Please sign in to comment.