From e263a42119cd82a03353e08c5699ca926c6d7b91 Mon Sep 17 00:00:00 2001 From: Daniel Walsh Date: Mon, 15 Jul 2024 20:45:30 +0100 Subject: [PATCH] Log total amount + size of all modules --- .changeset/few-pumpkins-fetch.md | 5 + .../wrangler/src/__tests__/deploy.test.ts | 98 ++++++++++--------- .../__tests__/pages/functions-build.test.ts | 20 ++-- .../find-additional-modules.ts | 18 +++- 4 files changed, 82 insertions(+), 59 deletions(-) create mode 100644 .changeset/few-pumpkins-fetch.md diff --git a/.changeset/few-pumpkins-fetch.md b/.changeset/few-pumpkins-fetch.md new file mode 100644 index 000000000000..24a53f9a1923 --- /dev/null +++ b/.changeset/few-pumpkins-fetch.md @@ -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. diff --git a/packages/wrangler/src/__tests__/deploy.test.ts b/packages/wrangler/src/__tests__/deploy.test.ts index 4c39d9b9459e..bd0d48679aa9 100644 --- a/packages/wrangler/src/__tests__/deploy.test.ts +++ b/packages/wrangler/src/__tests__/deploy.test.ts @@ -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(`""`); }); @@ -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 () => { @@ -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" + `); }); }); diff --git a/packages/wrangler/src/__tests__/pages/functions-build.test.ts b/packages/wrangler/src/__tests__/pages/functions-build.test.ts index 3d9faee2015e..f796e6f106e8 100644 --- a/packages/wrangler/src/__tests__/pages/functions-build.test.ts +++ b/packages/wrangler/src/__tests__/pages/functions-build.test.ts @@ -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( diff --git a/packages/wrangler/src/deployment-bundle/find-additional-modules.ts b/packages/wrangler/src/deployment-bundle/find-additional-modules.ts index adee245adbf3..237ff378312f 100644 --- a/packages/wrangler/src/deployment-bundle/find-additional-modules.ts +++ b/packages/wrangler/src/deployment-bundle/find-additional-modules.ts @@ -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 ?? "", @@ -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;