Skip to content

Commit

Permalink
fix: include additional modules in largest dependencies warning (#4696
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mrbbot authored Jan 4, 2024
1 parent 0f8a03c commit 624084c
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .changeset/small-fishes-tan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"wrangler": patch
---

fix: include additional modules in `largest dependencies` warning

If your Worker fails to deploy because it's too large, Wrangler will display of list of your Worker's largest dependencies. Previously, this just included JavaScript dependencies. This change ensures additional module dependencies (e.g. WebAssembly, text blobs, etc.) are included when computing this list.
18 changes: 15 additions & 3 deletions packages/wrangler/src/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8114,15 +8114,25 @@ export default{
)
);

fs.writeFileSync(
"add.wasm",
"AGFzbQEAAAABBwFgAn9/AX8DAgEABwcBA2FkZAAACgkBBwAgACABagsACgRuYW1lAgMBAAA=",
"base64"
);
fs.writeFileSync("message.txt", "👋");
fs.writeFileSync("dependency.js", `export const thing = "a string dep";`);

fs.writeFileSync(
"index.js",
`import { thing } from "./dependency";
`
import addModule from "./add.wasm";
import message from "./message.txt";
import { thing } from "./dependency";
export default {
async fetch() {
return new Response('response plus ' + thing);
const instance = new WebAssembly.Instance(addModule);
return Response.json({ add: instance.exports.add(1, 2), message, thing });
}
}`
);
Expand Down Expand Up @@ -8150,10 +8160,12 @@ export default{
https://github.com/cloudflare/workers-sdk/issues/new/choose
",
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mHere are the 2 largest dependencies included in your script:[0m
"warn": "[33m▲ [43;33m[[43;30mWARNING[43;33m][0m [1mHere are the 4 largest dependencies included in your script:[0m
- index.js - xx KiB
- add.wasm - xx KiB
- dependency.js - xx KiB
- message.txt - xx KiB
If these are unnecessary, consider removing them
",
Expand Down
15 changes: 14 additions & 1 deletion packages/wrangler/src/deploy/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,19 @@ See https://developers.cloudflare.com/workers/platform/compatibility-dates for m
}
);

// Add modules to dependencies for size warning
for (const module of modules) {
const modulePath =
module.filePath === undefined
? module.name
: path.relative("", module.filePath);
const bytesInOutput =
typeof module.content === "string"
? Buffer.byteLength(module.content)
: module.content.byteLength;
dependencies[modulePath] = { bytesInOutput };
}

const content = readFileSync(resolvedEntryPointPath, {
encoding: "utf-8",
});
Expand Down Expand Up @@ -1137,7 +1150,7 @@ async function noBundleWorker(

return {
modules,
dependencies: {},
dependencies: {} as { [path: string]: { bytesInOutput: number } },
resolvedEntryPointPath: entry.file,
bundleType: getBundleType(entry.format),
};
Expand Down

0 comments on commit 624084c

Please sign in to comment.