Skip to content

Commit

Permalink
fix: warn when using --no-bundle with --minify or --node-compat (
Browse files Browse the repository at this point in the history
…cloudflare#1500)

fix: warn when using `--no-bundle` with `--minify` or `--node-compat`

Co-authored-by: Cameron Robey <[email protected]>
  • Loading branch information
cameron-robey and Cameron Robey authored Jul 19, 2022
1 parent 7098b1e commit 0826f83
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changeset/clean-spoons-buy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

fix: warn when using `--no-bundle` with `--minify` or `--node-compat`

Fixes https://github.com/cloudflare/wrangler2/issues/1491
76 changes: 76 additions & 0 deletions packages/wrangler/src/__tests__/publish.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6108,6 +6108,82 @@ addEventListener('fetch', event => {});`
expect(fs.readFileSync("dist/index.js", "utf-8")).toMatch(scriptContent);
});
});

describe("--no-bundle --minify", () => {
it("should warn that no-bundle and minify can't be used together", async () => {
writeWranglerToml();
const scriptContent = `
const xyz = 123; // a statement that would otherwise be compiled out
`;
fs.writeFileSync("index.js", scriptContent);
await runWrangler(
"publish index.js --no-bundle --minify --dry-run --outdir dist"
);
expect(std.warn).toMatchInlineSnapshot(`
"▲ [WARNING] \`--minify\` and \`--no-bundle\` can't be used together. If you want to minify your Worker and disable Wrangler's bundling, please minify as part of your own bundling process.
"
`);
});

it("should warn that no-bundle and minify can't be used together", async () => {
writeWranglerToml({
no_bundle: true,
minify: true,
});
const scriptContent = `
const xyz = 123; // a statement that would otherwise be compiled out
`;
fs.writeFileSync("index.js", scriptContent);
await runWrangler("publish index.js --dry-run --outdir dist");
expect(std.warn).toMatchInlineSnapshot(`
"▲ [WARNING] \`--minify\` and \`--no-bundle\` can't be used together. If you want to minify your Worker and disable Wrangler's bundling, please minify as part of your own bundling process.
"
`);
});
});

describe("--no-bundle --node-compat", () => {
it("should warn that no-bundle and node-compat can't be used together", async () => {
writeWranglerToml();
const scriptContent = `
const xyz = 123; // a statement that would otherwise be compiled out
`;
fs.writeFileSync("index.js", scriptContent);
await runWrangler(
"publish index.js --no-bundle --node-compat --dry-run --outdir dist"
);
expect(std.warn).toMatchInlineSnapshot(`
"▲ [WARNING] Enabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.
▲ [WARNING] \`--node-compat\` and \`--no-bundle\` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process.
"
`);
});

it("should warn that no-bundle and node-compat can't be used together", async () => {
writeWranglerToml({
no_bundle: true,
node_compat: true,
});
const scriptContent = `
const xyz = 123; // a statement that would otherwise be compiled out
`;
fs.writeFileSync("index.js", scriptContent);
await runWrangler("publish index.js --dry-run --outdir dist");
expect(std.warn).toMatchInlineSnapshot(`
"▲ [WARNING] Enabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs. Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.
▲ [WARNING] \`--node-compat\` and \`--no-bundle\` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process.
"
`);
});
});
});

/** Write mock assets to the file system so they can be uploaded. */
Expand Down
13 changes: 13 additions & 0 deletions packages/wrangler/src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,19 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
);
}

// Warn if user tries minify or node-compat with no-bundle
if (props.noBundle && minify) {
logger.warn(
"`--minify` and `--no-bundle` can't be used together. If you want to minify your Worker and disable Wrangler's bundling, please minify as part of your own bundling process."
);
}

if (props.noBundle && nodeCompat) {
logger.warn(
"`--node-compat` and `--no-bundle` can't be used together. If you want to polyfill Node.js built-ins and disable Wrangler's bundling, please polyfill as part of your own bundling process."
);
}

const scriptName = props.name;
assert(
scriptName,
Expand Down

0 comments on commit 0826f83

Please sign in to comment.