Skip to content

Commit

Permalink
feat: Bundle Reporter (#1272)
Browse files Browse the repository at this point in the history
* feat: Bundle Reporter (Publish)
The `publish` command will output a message of the "total upload"
which includes script + modules showing the original size versus gzip size.

* Added bundle reporter to the initial server start for remote `dev`

* Worker script content is added to the modules processed for bundle reporter.

* handle the .01 KiB variation in tests causing flakes

* Handled this with an addition to the  for stdout which masks the hundredth of a kilobyte variation (± .01 KiB)

* nits by Sunil

Co-authored-by: Sunil Pai <[email protected]>
  • Loading branch information
JacobMGEvans and threepointone authored Jun 18, 2022
1 parent f6836b0 commit f7d362e
Show file tree
Hide file tree
Showing 7 changed files with 294 additions and 69 deletions.
9 changes: 9 additions & 0 deletions .changeset/breezy-scissors-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
"wrangler": patch
---

feat: print bundle size during `publish` and `dev`

This logs the complete bundle size of the Worker (as well as when compressed) during `publish` and `dev`.

Via https://github.com/cloudflare/wrangler2/issues/405#issuecomment-1156762297)
12 changes: 11 additions & 1 deletion packages/wrangler/src/__tests__/helpers/mock-console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ const std = {

function normalizeOutput(spy: jest.SpyInstance): string {
return normalizeErrorMarkers(
stripTrailingWhitespace(normalizeSlashes(stripTimings(captureCalls(spy))))
replaceByte(
stripTrailingWhitespace(normalizeSlashes(stripTimings(captureCalls(spy))))
)
);
}

Expand Down Expand Up @@ -85,3 +87,11 @@ export function stripTimings(stdout: string): string {
export function stripTrailingWhitespace(str: string): string {
return str.replace(/[^\S\n]+\n/g, "\n");
}

/**
* Removing leading kilobit (tenth of a byte) from test output due to
* variation causing every few tests the value to change by ± .01
*/
function replaceByte(stdout: string): string {
return stdout.replaceAll(/.[0-9][0-9] KiB/g, "xx KiB");
}
3 changes: 2 additions & 1 deletion packages/wrangler/src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,8 @@ describe("wrangler", () => {
Attempting to run \`wrangler publish --dry-run --outdir=dist\` for you instead:
--dry-run: exiting now."
--dry-run: exiting now.
Total Upload: 0xx KiB / gzip: 0xx KiB"
`);
});
});
Expand Down
Loading

0 comments on commit f7d362e

Please sign in to comment.