Skip to content

Commit

Permalink
Log size of additional modules (#4198)
Browse files Browse the repository at this point in the history
* Log size of additional modules

* Update snapshots

* Create tiny-icons-breathe.md
  • Loading branch information
penalosa committed Oct 25, 2023
1 parent 69b4303 commit b404ab7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/tiny-icons-breathe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": minor
---

When uploading additional modules with your worker, Wrangler will now report the (uncompressed) size of each individual module, as well as the aggregate size of your Worker
17 changes: 12 additions & 5 deletions packages/wrangler/src/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2354,10 +2354,6 @@ addEventListener('fetch', event => {});`

expect(std.info).toMatchInlineSnapshot(`
"Attaching additional modules:
- a/1.mjs (esm)
- a/b/2.mjs (esm)
- a/b/3.mjs (esm)
- a/b/c/4.mjs (esm)
Fetching list of already uploaded assets...
Building list of assets to upload...
+ file-1.2ca234f380.text (uploading new version of file-1.text)
Expand All @@ -2366,7 +2362,18 @@ addEventListener('fetch', event => {});`
Uploaded 100% [2 out of 2]"
`);
expect(std.out).toMatchInlineSnapshot(`
"↗️ Done syncing assets
"┌─────────────┬──────┬──────────┐
│ Name │ Type │ Size │
├─────────────┼──────┼──────────┤
│ a/1.mjs │ esm │ xx KiB │
├─────────────┼──────┼──────────┤
│ a/b/2.mjs │ esm │ xx KiB │
├─────────────┼──────┼──────────┤
│ a/b/3.mjs │ esm │ xx KiB │
├─────────────┼──────┼──────────┤
│ a/b/c/4.mjs │ esm │ xx KiB │
└─────────────┴──────┴──────────┘
↗️ Done syncing assets
Total Upload: xx KiB / gzip: xx KiB
Uploaded test-name (TIMINGS)
Published test-name (TIMINGS)
Expand Down
11 changes: 10 additions & 1 deletion packages/wrangler/src/__tests__/pages/functions-build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,16 @@ export const cat = "dog";`
await runWrangler(`pages functions build --outfile=public/_worker.bundle`);

expect(existsSync("public/_worker.bundle")).toBe(true);
expect(std.out).toMatchInlineSnapshot(`"✨ Compiled Worker successfully"`);
expect(std.out).toMatchInlineSnapshot(`
"┌─────────┬──────┬──────────┐
│ Name │ Type │ Size │
├─────────┼──────┼──────────┤
│ cat.js │ esm │ xx KiB │
├─────────┼──────┼──────────┤
│ dog.mjs │ esm │ xx KiB │
└─────────┴──────┴──────────┘
✨ Compiled Worker successfully"
`);

const workerBundleContents = readFileSync("public/_worker.bundle", "utf-8");
const workerBundleWithConstantData = replaceRandomWithConstantData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,15 @@ export async function findAdditionalModules(

if (modules.length > 0) {
logger.info(`Attaching additional modules:`);
modules.forEach(({ name, type }) => {
logger.info(`- ${chalk.blue(name)} (${chalk.green(type ?? "")})`);
});
logger.table(
modules.map(({ name, type, content }) => {
return {
Name: name,
Type: type ?? "",
Size: `${(content.length / 1024).toFixed(2)} KiB`,
};
})
);
}

return modules;
Expand Down

0 comments on commit b404ab7

Please sign in to comment.