Skip to content

Commit

Permalink
Log total amount + size of all modules
Browse files Browse the repository at this point in the history
  • Loading branch information
WalshyDev committed Jul 15, 2024
1 parent 4f524f2 commit e263a42
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 59 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-pumpkins-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

chore: add total module size to the logged table, this makes it much easier to see the total size of all modules combined.
98 changes: 52 additions & 46 deletions packages/wrangler/src/__tests__/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2674,28 +2674,30 @@ addEventListener('fetch', event => {});`
Uploaded 100% [2 out of 2]"
`);
expect(std.out).toMatchInlineSnapshot(`
"┌─────────────┬──────┬──────────┐
│ 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)
https://test-name.test-sub-domain.workers.dev
Current Deployment ID: Galaxy-Class
Current Version ID: Galaxy-Class
"┌───────────────────┬──────┬──────────┐
│ 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 │
├───────────────────┼──────┼──────────┤
│ Total (4 modules) │ │ xx KiB │
└───────────────────┴──────┴──────────┘
↗️ Done syncing assets
Total Upload: xx KiB / gzip: xx KiB
Uploaded test-name (TIMINGS)
Published test-name (TIMINGS)
https://test-name.test-sub-domain.workers.dev
Current Deployment ID: Galaxy-Class
Current Version ID: Galaxy-Class
Note: Deployment ID has been renamed to Version ID. Deployment ID is present to maintain compatibility with the previous behavior of this command. This output will change in a future version of Wrangler. To learn more visit: https://developers.cloudflare.com/workers/configuration/versions-and-deployments"
`);
Note: Deployment ID has been renamed to Version ID. Deployment ID is present to maintain compatibility with the previous behavior of this command. This output will change in a future version of Wrangler. To learn more visit: https://developers.cloudflare.com/workers/configuration/versions-and-deployments"
`);
expect(std.err).toMatchInlineSnapshot(`""`);
});

Expand Down Expand Up @@ -10086,21 +10088,23 @@ export default{
".wrangler/tmp/deploy/index.py"
)
).toMatchInlineSnapshot(`
"┌──────────────────────────────────────┬────────┬──────────┐
│ Name │ Type │ Size │
├──────────────────────────────────────┼────────┼──────────┤
│ .wrangler/tmp/deploy/index.py │ python │ xx KiB │
└──────────────────────────────────────┴────────┴──────────┘
Total Upload: xx KiB / gzip: xx KiB
Uploaded test-name (TIMINGS)
Published test-name (TIMINGS)
https://test-name.test-sub-domain.workers.dev
Current Deployment ID: Galaxy-Class
Current Version ID: Galaxy-Class
"┌──────────────────────────────────────┬────────┬──────────┐
│ Name │ Type │ Size │
├──────────────────────────────────────┼────────┼──────────┤
│ .wrangler/tmp/deploy/index.py │ python │ xx KiB │
├──────────────────────────────────────┼────────┼──────────┤
│ Total (1 modules) │ │ xx KiB │
└──────────────────────────────────────┴────────┴──────────┘
Total Upload: xx KiB / gzip: xx KiB
Uploaded test-name (TIMINGS)
Published test-name (TIMINGS)
https://test-name.test-sub-domain.workers.dev
Current Deployment ID: Galaxy-Class
Current Version ID: Galaxy-Class
Note: Deployment ID has been renamed to Version ID. Deployment ID is present to maintain compatibility with the previous behavior of this command. This output will change in a future version of Wrangler. To learn more visit: https://developers.cloudflare.com/workers/configuration/versions-and-deployments"
`);
Note: Deployment ID has been renamed to Version ID. Deployment ID is present to maintain compatibility with the previous behavior of this command. This output will change in a future version of Wrangler. To learn more visit: https://developers.cloudflare.com/workers/configuration/versions-and-deployments"
`);
});

it("should upload python module specified in CLI args", async () => {
Expand All @@ -10121,21 +10125,23 @@ export default{
".wrangler/tmp/deploy/index.py"
)
).toMatchInlineSnapshot(`
"┌──────────────────────────────────────┬────────┬──────────┐
│ Name │ Type │ Size │
├──────────────────────────────────────┼────────┼──────────┤
│ .wrangler/tmp/deploy/index.py │ python │ xx KiB │
└──────────────────────────────────────┴────────┴──────────┘
Total Upload: xx KiB / gzip: xx KiB
Uploaded test-name (TIMINGS)
Published test-name (TIMINGS)
https://test-name.test-sub-domain.workers.dev
Current Deployment ID: Galaxy-Class
Current Version ID: Galaxy-Class
"┌──────────────────────────────────────┬────────┬──────────┐
│ Name │ Type │ Size │
├──────────────────────────────────────┼────────┼──────────┤
│ .wrangler/tmp/deploy/index.py │ python │ xx KiB │
├──────────────────────────────────────┼────────┼──────────┤
│ Total (1 modules) │ │ xx KiB │
└──────────────────────────────────────┴────────┴──────────┘
Total Upload: xx KiB / gzip: xx KiB
Uploaded test-name (TIMINGS)
Published test-name (TIMINGS)
https://test-name.test-sub-domain.workers.dev
Current Deployment ID: Galaxy-Class
Current Version ID: Galaxy-Class
Note: Deployment ID has been renamed to Version ID. Deployment ID is present to maintain compatibility with the previous behavior of this command. This output will change in a future version of Wrangler. To learn more visit: https://developers.cloudflare.com/workers/configuration/versions-and-deployments"
`);
Note: Deployment ID has been renamed to Version ID. Deployment ID is present to maintain compatibility with the previous behavior of this command. This output will change in a future version of Wrangler. To learn more visit: https://developers.cloudflare.com/workers/configuration/versions-and-deployments"
`);
});
});

Expand Down
20 changes: 11 additions & 9 deletions packages/wrangler/src/__tests__/pages/functions-build.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,15 +473,17 @@ export const cat = "dog";`

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

const workerBundleContents = readFileSync("public/_worker.bundle", "utf-8");
const workerBundleWithConstantData = replaceRandomWithConstantData(
Expand Down
18 changes: 14 additions & 4 deletions packages/wrangler/src/deployment-bundle/find-additional-modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,13 @@ export async function findAdditionalModules(

if (modules.length > 0) {
logger.info(`Attaching additional modules:`);
logger.table(
modules.map(({ name, type, content }) => {
const totalSize = modules.reduce(
(previous, { content }) => previous + content.length,
0
);

logger.table([
...modules.map(({ name, type, content }) => {
return {
Name: name,
Type: type ?? "",
Expand All @@ -119,8 +124,13 @@ export async function findAdditionalModules(
? ""
: `${(content.length / 1024).toFixed(2)} KiB`,
};
})
);
}),
{
Name: `Total (${modules.length} modules)`,
Type: "",
Size: `${(totalSize / 1024).toFixed(2)} KiB`,
},
]);
}

return modules;
Expand Down

0 comments on commit e263a42

Please sign in to comment.