diff --git a/.changeset/old-cameras-search.md b/.changeset/old-cameras-search.md new file mode 100644 index 00000000..382ea0a9 --- /dev/null +++ b/.changeset/old-cameras-search.md @@ -0,0 +1,11 @@ +--- +"@codecov/bundler-plugin-core": patch +"@codecov/webpack-plugin": patch +"@codecov/rollup-plugin": patch +"@codecov/vite-plugin": patch +"@codecov/nuxt-plugin": patch +"@codecov/remix-vite-plugin": patch +"@codecov/sveltekit-plugin": patch +--- + +Adjust asset type to contain gzipSize, add new function to collect gzip values diff --git a/.changeset/stupid-points-vanish.md b/.changeset/stupid-points-vanish.md new file mode 100644 index 00000000..a80b69ca --- /dev/null +++ b/.changeset/stupid-points-vanish.md @@ -0,0 +1,11 @@ +--- +"@codecov/bundler-plugin-core": patch +"@codecov/remix-vite-plugin": patch +"@codecov/sveltekit-plugin": patch +"@codecov/webpack-plugin": patch +"@codecov/rollup-plugin": patch +"@codecov/nuxt-plugin": patch +"@codecov/vite-plugin": patch +--- + +Set version from passed output arg, and collect gzip information in plugins diff --git a/.changeset/wise-insects-accept.md b/.changeset/wise-insects-accept.md new file mode 100644 index 00000000..0e4252b7 --- /dev/null +++ b/.changeset/wise-insects-accept.md @@ -0,0 +1,11 @@ +--- +"@codecov/bundler-plugin-core": patch +"@codecov/remix-vite-plugin": patch +"@codecov/sveltekit-plugin": patch +"@codecov/webpack-plugin": patch +"@codecov/rollup-plugin": patch +"@codecov/nuxt-plugin": patch +"@codecov/vite-plugin": patch +--- + +Update meta-framework plugins to collect version generated in output arg diff --git a/integration-tests/fixtures/generate-bundle-stats/nuxt/__snapshots__/nuxt-plugin.test.ts.snap b/integration-tests/fixtures/generate-bundle-stats/nuxt/__snapshots__/nuxt-plugin.test.ts.snap index 69e6c3a4..10d5de4c 100644 --- a/integration-tests/fixtures/generate-bundle-stats/nuxt/__snapshots__/nuxt-plugin.test.ts.snap +++ b/integration-tests/fixtures/generate-bundle-stats/nuxt/__snapshots__/nuxt-plugin.test.ts.snap @@ -17,7 +17,7 @@ exports[`Generating nuxt stats 3 {"format":"amd","expected":"amd"} matches the s "name": StringMatching "@codecov/nuxt-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -38,7 +38,7 @@ exports[`Generating nuxt stats 3 {"format":"amd","expected":"amd"} matches the s "name": StringMatching "@codecov/nuxt-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -59,7 +59,7 @@ exports[`Generating nuxt stats 3 {"format":"cjs","expected":"cjs"} matches the s "name": StringMatching "@codecov/nuxt-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -80,7 +80,7 @@ exports[`Generating nuxt stats 3 {"format":"cjs","expected":"cjs"} matches the s "name": StringMatching "@codecov/nuxt-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -101,7 +101,7 @@ exports[`Generating nuxt stats 3 {"format":"es","expected":"esm"} matches the sn "name": StringMatching "@codecov/nuxt-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -122,7 +122,7 @@ exports[`Generating nuxt stats 3 {"format":"es","expected":"esm"} matches the sn "name": StringMatching "@codecov/nuxt-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -143,7 +143,7 @@ exports[`Generating nuxt stats 3 {"format":"esm","expected":"esm"} matches the s "name": StringMatching "@codecov/nuxt-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -164,7 +164,7 @@ exports[`Generating nuxt stats 3 {"format":"esm","expected":"esm"} matches the s "name": StringMatching "@codecov/nuxt-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -185,7 +185,7 @@ exports[`Generating nuxt stats 3 {"format":"module","expected":"esm"} matches th "name": StringMatching "@codecov/nuxt-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -206,7 +206,7 @@ exports[`Generating nuxt stats 3 {"format":"module","expected":"esm"} matches th "name": StringMatching "@codecov/nuxt-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -227,7 +227,7 @@ exports[`Generating nuxt stats 3 {"format":"iife","expected":"iife"} matches the "name": StringMatching "@codecov/nuxt-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -248,7 +248,7 @@ exports[`Generating nuxt stats 3 {"format":"iife","expected":"iife"} matches the "name": StringMatching "@codecov/nuxt-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -269,7 +269,7 @@ exports[`Generating nuxt stats 3 {"format":"umd","expected":"umd"} matches the s "name": StringMatching "@codecov/nuxt-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -290,7 +290,7 @@ exports[`Generating nuxt stats 3 {"format":"umd","expected":"umd"} matches the s "name": StringMatching "@codecov/nuxt-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -311,7 +311,7 @@ exports[`Generating nuxt stats 3 {"format":"system","expected":"system"} matches "name": StringMatching "@codecov/nuxt-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -332,7 +332,7 @@ exports[`Generating nuxt stats 3 {"format":"system","expected":"system"} matches "name": StringMatching "@codecov/nuxt-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -353,7 +353,7 @@ exports[`Generating nuxt stats 3 {"format":"systemjs","expected":"system"} match "name": StringMatching "@codecov/nuxt-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -374,6 +374,6 @@ exports[`Generating nuxt stats 3 {"format":"systemjs","expected":"system"} match "name": StringMatching "@codecov/nuxt-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; diff --git a/integration-tests/fixtures/generate-bundle-stats/nuxt/nuxt-plugin.test.ts b/integration-tests/fixtures/generate-bundle-stats/nuxt/nuxt-plugin.test.ts index 4a1aff3c..fb8d8098 100644 --- a/integration-tests/fixtures/generate-bundle-stats/nuxt/nuxt-plugin.test.ts +++ b/integration-tests/fixtures/generate-bundle-stats/nuxt/nuxt-plugin.test.ts @@ -80,6 +80,7 @@ describe("Generating nuxt stats", () => { name: expect.any(String), normalized: expect.any(String), size: expect.any(Number), + gzipSize: expect.anything(), }, ]), chunks: expect.arrayContaining([ @@ -123,6 +124,7 @@ describe("Generating nuxt stats", () => { name: expect.any(String), normalized: expect.any(String), size: expect.any(Number), + gzipSize: expect.anything(), }, ]), chunks: expect.arrayContaining([ diff --git a/integration-tests/fixtures/generate-bundle-stats/remix/__snapshots__/remix-plugin.test.ts.snap b/integration-tests/fixtures/generate-bundle-stats/remix/__snapshots__/remix-plugin.test.ts.snap index d79ae71d..0cf99098 100644 --- a/integration-tests/fixtures/generate-bundle-stats/remix/__snapshots__/remix-plugin.test.ts.snap +++ b/integration-tests/fixtures/generate-bundle-stats/remix/__snapshots__/remix-plugin.test.ts.snap @@ -1,5 +1,131 @@ // Bun Snapshot v1, https://goo.gl/fbAQLP +exports[`Generating remix stats 2 {"format":"amd","expected":"amd"} matches the snapshot 1`] = ` +{ + "assets": ExpectArrayContaining {}, + "builtAt": Any, + "bundleName": StringContaining "test-remix-v2-client-amd", + "bundler": { + "name": "rollup", + "version": "4.16.2", + }, + "chunks": ExpectArrayContaining {}, + "duration": Any, + "modules": ExpectArrayContaining {}, + "outputPath": StringContaining "build", + "plugin": { + "name": StringMatching "@codecov/remix-vite-plugin", + "version": "0.0.1-beta.10", + }, + "version": "2", +} +`; + +exports[`Generating remix stats 2 {"format":"amd","expected":"amd"} matches the snapshot 2`] = ` +{ + "assets": ExpectArrayContaining {}, + "builtAt": Any, + "bundleName": StringContaining "test-remix-v2-server-esm", + "bundler": { + "name": "rollup", + "version": "4.16.2", + }, + "chunks": ExpectArrayContaining {}, + "duration": Any, + "modules": ExpectArrayContaining {}, + "outputPath": StringContaining "build", + "plugin": { + "name": StringMatching "@codecov/remix-vite-plugin", + "version": "0.0.1-beta.10", + }, + "version": "2", +} +`; + +exports[`Generating remix stats 2 {"format":"cjs","expected":"cjs"} matches the snapshot 1`] = ` +{ + "assets": ExpectArrayContaining {}, + "builtAt": Any, + "bundleName": StringContaining "test-remix-v2-client-cjs", + "bundler": { + "name": "rollup", + "version": "4.16.2", + }, + "chunks": ExpectArrayContaining {}, + "duration": Any, + "modules": ExpectArrayContaining {}, + "outputPath": StringContaining "build", + "plugin": { + "name": StringMatching "@codecov/remix-vite-plugin", + "version": "0.0.1-beta.10", + }, + "version": "2", +} +`; + +exports[`Generating remix stats 2 {"format":"cjs","expected":"cjs"} matches the snapshot 2`] = ` +{ + "assets": ExpectArrayContaining {}, + "builtAt": Any, + "bundleName": StringContaining "test-remix-v2-server-esm", + "bundler": { + "name": "rollup", + "version": "4.16.2", + }, + "chunks": ExpectArrayContaining {}, + "duration": Any, + "modules": ExpectArrayContaining {}, + "outputPath": StringContaining "build", + "plugin": { + "name": StringMatching "@codecov/remix-vite-plugin", + "version": "0.0.1-beta.10", + }, + "version": "2", +} +`; + +exports[`Generating remix stats 2 {"format":"es","expected":"esm"} matches the snapshot 1`] = ` +{ + "assets": ExpectArrayContaining {}, + "builtAt": Any, + "bundleName": StringContaining "test-remix-v2-client-esm", + "bundler": { + "name": "rollup", + "version": "4.16.2", + }, + "chunks": ExpectArrayContaining {}, + "duration": Any, + "modules": ExpectArrayContaining {}, + "outputPath": StringContaining "build", + "plugin": { + "name": StringMatching "@codecov/remix-vite-plugin", + "version": "0.0.1-beta.10", + }, + "version": "2", +} +`; + +exports[`Generating remix stats 2 {"format":"es","expected":"esm"} matches the snapshot 2`] = ` +{ + "assets": ExpectArrayContaining {}, + "builtAt": Any, + "bundleName": StringContaining "test-remix-v2-server-esm", + "bundler": { + "name": "rollup", + "version": "4.16.2", + }, + "chunks": ExpectArrayContaining {}, + "duration": Any, + "modules": ExpectArrayContaining {}, + "outputPath": StringContaining "build", + "plugin": { + "name": StringMatching "@codecov/remix-vite-plugin", + "version": "0.0.1-beta.10", + }, + "version": "2", +} +`; + exports[`Generating remix stats 2 {"format":"esm","expected":"esm"} matches the snapshot 1`] = ` { "assets": ExpectArrayContaining {}, @@ -17,7 +143,7 @@ exports[`Generating remix stats 2 {"format":"esm","expected":"esm"} matches the "name": StringMatching "@codecov/remix-vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -38,6 +164,48 @@ exports[`Generating remix stats 2 {"format":"esm","expected":"esm"} matches the "name": StringMatching "@codecov/remix-vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", +} +`; + +exports[`Generating remix stats 2 {"format":"module","expected":"esm"} matches the snapshot 1`] = ` +{ + "assets": ExpectArrayContaining {}, + "builtAt": Any, + "bundleName": StringContaining "test-remix-v2-client-esm", + "bundler": { + "name": "rollup", + "version": "4.16.2", + }, + "chunks": ExpectArrayContaining {}, + "duration": Any, + "modules": ExpectArrayContaining {}, + "outputPath": StringContaining "build", + "plugin": { + "name": StringMatching "@codecov/remix-vite-plugin", + "version": "0.0.1-beta.10", + }, + "version": "2", +} +`; + +exports[`Generating remix stats 2 {"format":"module","expected":"esm"} matches the snapshot 2`] = ` +{ + "assets": ExpectArrayContaining {}, + "builtAt": Any, + "bundleName": StringContaining "test-remix-v2-server-esm", + "bundler": { + "name": "rollup", + "version": "4.16.2", + }, + "chunks": ExpectArrayContaining {}, + "duration": Any, + "modules": ExpectArrayContaining {}, + "outputPath": StringContaining "build", + "plugin": { + "name": StringMatching "@codecov/remix-vite-plugin", + "version": "0.0.1-beta.10", + }, + "version": "2", } `; diff --git a/integration-tests/fixtures/generate-bundle-stats/remix/remix-plugin.test.ts b/integration-tests/fixtures/generate-bundle-stats/remix/remix-plugin.test.ts index 20b4bb7d..32ec38b2 100644 --- a/integration-tests/fixtures/generate-bundle-stats/remix/remix-plugin.test.ts +++ b/integration-tests/fixtures/generate-bundle-stats/remix/remix-plugin.test.ts @@ -7,8 +7,13 @@ const remixApp = "test-apps/remix"; const VERSIONS = [2]; -// Default Rollup formats: https://rollupjs.org/configuration-options/#output-format -const FORMATS = [{ format: "esm", expected: "esm" }]; +const FORMATS = [ + { format: "amd", expected: "amd" }, + { format: "cjs", expected: "cjs" }, + { format: "es", expected: "esm" }, + { format: "esm", expected: "esm" }, + { format: "module", expected: "esm" }, +]; describe("Generating remix stats", () => { describe.each(VERSIONS)("%d", (version) => { @@ -72,6 +77,7 @@ describe("Generating remix stats", () => { name: expect.any(String), normalized: expect.any(String), size: expect.any(Number), + gzipSize: expect.anything(), }, ]), chunks: expect.arrayContaining([ @@ -104,9 +110,7 @@ describe("Generating remix stats", () => { builtAt: expect.any(Number), duration: expect.any(Number), outputPath: expect.stringContaining(`build`), - bundleName: expect.stringContaining( - `test-remix-v${version}-server-${expected}`, - ), + bundleName: expect.stringContaining(serverBundleName), plugin: { name: expect.stringMatching("@codecov/remix-vite-plugin"), }, @@ -115,6 +119,7 @@ describe("Generating remix stats", () => { name: expect.any(String), normalized: expect.any(String), size: expect.any(Number), + gzipSize: expect.anything(), }, ]), chunks: expect.arrayContaining([ diff --git a/integration-tests/fixtures/generate-bundle-stats/remix/vite-base.config.ts b/integration-tests/fixtures/generate-bundle-stats/remix/vite-base.config.ts index 3315405c..592ccfa4 100644 --- a/integration-tests/fixtures/generate-bundle-stats/remix/vite-base.config.ts +++ b/integration-tests/fixtures/generate-bundle-stats/remix/vite-base.config.ts @@ -4,6 +4,13 @@ import tsconfigPaths from "vite-tsconfig-paths"; import { codecovRemixVitePlugin } from "@codecov/remix-vite-plugin"; export default defineConfig({ + build: { + rollupOptions: { + output: { + format: "esm", + }, + }, + }, plugins: [ remix({ future: { diff --git a/integration-tests/fixtures/generate-bundle-stats/rollup/__snapshots__/rollup-plugin.test.ts.snap b/integration-tests/fixtures/generate-bundle-stats/rollup/__snapshots__/rollup-plugin.test.ts.snap index 250f1bec..9a7451b0 100644 --- a/integration-tests/fixtures/generate-bundle-stats/rollup/__snapshots__/rollup-plugin.test.ts.snap +++ b/integration-tests/fixtures/generate-bundle-stats/rollup/__snapshots__/rollup-plugin.test.ts.snap @@ -4,9 +4,10 @@ exports[`Generating rollup stats 3 {"format":"amd","expected":"amd"} matches the { "assets": [ { + "gzipSize": 98808, "name": "main-1cbfd464.js", "normalized": "main-*.js", - "size": 577071, + "size": 577073, }, ], "builtAt": Any, @@ -72,7 +73,7 @@ exports[`Generating rollup stats 3 {"format":"amd","expected":"amd"} matches the "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -80,9 +81,10 @@ exports[`Generating rollup stats 3 {"format":"cjs","expected":"cjs"} matches the { "assets": [ { + "gzipSize": 98252, "name": "main-420d8aeb.js", "normalized": "main-*.js", - "size": 560886, + "size": 560888, }, ], "builtAt": Any, @@ -148,7 +150,7 @@ exports[`Generating rollup stats 3 {"format":"cjs","expected":"cjs"} matches the "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -156,9 +158,10 @@ exports[`Generating rollup stats 3 {"format":"es","expected":"esm"} matches the { "assets": [ { + "gzipSize": 98243, "name": "main-6ff1e9ca.js", "normalized": "main-*.js", - "size": 560871, + "size": 560873, }, ], "builtAt": Any, @@ -224,7 +227,7 @@ exports[`Generating rollup stats 3 {"format":"es","expected":"esm"} matches the "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -232,9 +235,10 @@ exports[`Generating rollup stats 3 {"format":"esm","expected":"esm"} matches the { "assets": [ { + "gzipSize": 98243, "name": "main-6ff1e9ca.js", "normalized": "main-*.js", - "size": 560871, + "size": 560873, }, ], "builtAt": Any, @@ -300,7 +304,7 @@ exports[`Generating rollup stats 3 {"format":"esm","expected":"esm"} matches the "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -308,9 +312,10 @@ exports[`Generating rollup stats 3 {"format":"module","expected":"esm"} matches { "assets": [ { + "gzipSize": 98243, "name": "main-6ff1e9ca.js", "normalized": "main-*.js", - "size": 560871, + "size": 560873, }, ], "builtAt": Any, @@ -376,7 +381,7 @@ exports[`Generating rollup stats 3 {"format":"module","expected":"esm"} matches "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -384,9 +389,10 @@ exports[`Generating rollup stats 3 {"format":"iife","expected":"iife"} matches t { "assets": [ { + "gzipSize": 98804, "name": "main-cc182ba1.js", "normalized": "main-*.js", - "size": 577066, + "size": 577068, }, ], "builtAt": Any, @@ -452,7 +458,7 @@ exports[`Generating rollup stats 3 {"format":"iife","expected":"iife"} matches t "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -460,9 +466,10 @@ exports[`Generating rollup stats 3 {"format":"umd","expected":"umd"} matches the { "assets": [ { + "gzipSize": 98845, "name": "main-cdb2522f.js", "normalized": "main-*.js", - "size": 577165, + "size": 577167, }, ], "builtAt": Any, @@ -528,7 +535,7 @@ exports[`Generating rollup stats 3 {"format":"umd","expected":"umd"} matches the "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -536,9 +543,10 @@ exports[`Generating rollup stats 3 {"format":"system","expected":"system"} match { "assets": [ { + "gzipSize": 99908, "name": "main-b7135d24.js", "normalized": "main-*.js", - "size": 609444, + "size": 609446, }, ], "builtAt": Any, @@ -604,7 +612,7 @@ exports[`Generating rollup stats 3 {"format":"system","expected":"system"} match "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -612,9 +620,10 @@ exports[`Generating rollup stats 3 {"format":"systemjs","expected":"system"} mat { "assets": [ { + "gzipSize": 99908, "name": "main-b7135d24.js", "normalized": "main-*.js", - "size": 609444, + "size": 609446, }, ], "builtAt": Any, @@ -680,7 +689,7 @@ exports[`Generating rollup stats 3 {"format":"systemjs","expected":"system"} mat "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -688,9 +697,10 @@ exports[`Generating rollup stats 3 source maps are enabled does not include any { "assets": [ { + "gzipSize": 98275, "name": "main-6ff1e9ca.js", "normalized": "main-*.js", - "size": 560913, + "size": 560915, }, ], "builtAt": Any, @@ -756,7 +766,7 @@ exports[`Generating rollup stats 3 source maps are enabled does not include any "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -764,9 +774,10 @@ exports[`Generating rollup stats 4 {"format":"amd","expected":"amd"} matches the { "assets": [ { + "gzipSize": 98808, "name": "main-H2_1FSsQ.js", "normalized": "main-H2_1FSsQ.js", - "size": 577071, + "size": 577073, }, ], "builtAt": Any, @@ -832,7 +843,7 @@ exports[`Generating rollup stats 4 {"format":"amd","expected":"amd"} matches the "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -840,9 +851,10 @@ exports[`Generating rollup stats 4 {"format":"cjs","expected":"cjs"} matches the { "assets": [ { + "gzipSize": 98252, "name": "main-MVbZZknk.js", "normalized": "main-*.js", - "size": 560886, + "size": 560888, }, ], "builtAt": Any, @@ -908,7 +920,7 @@ exports[`Generating rollup stats 4 {"format":"cjs","expected":"cjs"} matches the "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -916,9 +928,10 @@ exports[`Generating rollup stats 4 {"format":"es","expected":"esm"} matches the { "assets": [ { + "gzipSize": 98243, "name": "main-v-vWaFyT.js", "normalized": "main-*.js", - "size": 560871, + "size": 560873, }, ], "builtAt": Any, @@ -984,7 +997,7 @@ exports[`Generating rollup stats 4 {"format":"es","expected":"esm"} matches the "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -992,9 +1005,10 @@ exports[`Generating rollup stats 4 {"format":"esm","expected":"esm"} matches the { "assets": [ { + "gzipSize": 98243, "name": "main-v-vWaFyT.js", "normalized": "main-*.js", - "size": 560871, + "size": 560873, }, ], "builtAt": Any, @@ -1060,7 +1074,7 @@ exports[`Generating rollup stats 4 {"format":"esm","expected":"esm"} matches the "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -1068,9 +1082,10 @@ exports[`Generating rollup stats 4 {"format":"module","expected":"esm"} matches { "assets": [ { + "gzipSize": 98243, "name": "main-v-vWaFyT.js", "normalized": "main-*.js", - "size": 560871, + "size": 560873, }, ], "builtAt": Any, @@ -1136,7 +1151,7 @@ exports[`Generating rollup stats 4 {"format":"module","expected":"esm"} matches "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -1144,9 +1159,10 @@ exports[`Generating rollup stats 4 {"format":"iife","expected":"iife"} matches t { "assets": [ { + "gzipSize": 98804, "name": "main-ChwnvxRF.js", "normalized": "main-*.js", - "size": 577066, + "size": 577068, }, ], "builtAt": Any, @@ -1212,7 +1228,7 @@ exports[`Generating rollup stats 4 {"format":"iife","expected":"iife"} matches t "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -1220,9 +1236,10 @@ exports[`Generating rollup stats 4 {"format":"umd","expected":"umd"} matches the { "assets": [ { + "gzipSize": 98845, "name": "main-ymXr0nql.js", "normalized": "main-*.js", - "size": 577165, + "size": 577167, }, ], "builtAt": Any, @@ -1288,7 +1305,7 @@ exports[`Generating rollup stats 4 {"format":"umd","expected":"umd"} matches the "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -1296,9 +1313,10 @@ exports[`Generating rollup stats 4 {"format":"system","expected":"system"} match { "assets": [ { + "gzipSize": 99908, "name": "main-VyFuBFOR.js", "normalized": "main-*.js", - "size": 609444, + "size": 609446, }, ], "builtAt": Any, @@ -1364,7 +1382,7 @@ exports[`Generating rollup stats 4 {"format":"system","expected":"system"} match "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -1372,9 +1390,10 @@ exports[`Generating rollup stats 4 {"format":"systemjs","expected":"system"} mat { "assets": [ { + "gzipSize": 99908, "name": "main-VyFuBFOR.js", "normalized": "main-*.js", - "size": 609444, + "size": 609446, }, ], "builtAt": Any, @@ -1440,7 +1459,7 @@ exports[`Generating rollup stats 4 {"format":"systemjs","expected":"system"} mat "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -1448,9 +1467,10 @@ exports[`Generating rollup stats 4 source maps are enabled does not include any { "assets": [ { + "gzipSize": 98277, "name": "main-v-vWaFyT.js", "normalized": "main-*.js", - "size": 560913, + "size": 560915, }, ], "builtAt": Any, @@ -1516,6 +1536,6 @@ exports[`Generating rollup stats 4 source maps are enabled does not include any "name": StringMatching "@codecov/rollup-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; diff --git a/integration-tests/fixtures/generate-bundle-stats/sveltekit/__snapshots__/sveltekit-plugin.test.ts.snap b/integration-tests/fixtures/generate-bundle-stats/sveltekit/__snapshots__/sveltekit-plugin.test.ts.snap index 6f9edc44..28527fff 100644 --- a/integration-tests/fixtures/generate-bundle-stats/sveltekit/__snapshots__/sveltekit-plugin.test.ts.snap +++ b/integration-tests/fixtures/generate-bundle-stats/sveltekit/__snapshots__/sveltekit-plugin.test.ts.snap @@ -1,5 +1,47 @@ // Bun Snapshot v1, https://goo.gl/fbAQLP +exports[`Generating sveltekit stats 2 {"format":"es","expected":"esm"} matches the snapshot 1`] = ` +{ + "assets": ExpectArrayContaining {}, + "builtAt": Any, + "bundleName": StringContaining "test-sveltekit-v2-client-esm", + "bundler": { + "name": "rollup", + "version": "4.16.2", + }, + "chunks": ExpectArrayContaining {}, + "duration": Any, + "modules": ExpectArrayContaining {}, + "outputPath": StringContaining ".svelte-kit", + "plugin": { + "name": StringMatching "@codecov/sveltekit-plugin", + "version": "0.0.1-beta.10", + }, + "version": "2", +} +`; + +exports[`Generating sveltekit stats 2 {"format":"es","expected":"esm"} matches the snapshot 2`] = ` +{ + "assets": ExpectArrayContaining {}, + "builtAt": Any, + "bundleName": StringContaining "test-sveltekit-v2-server-esm", + "bundler": { + "name": "rollup", + "version": "4.16.2", + }, + "chunks": ExpectArrayContaining {}, + "duration": Any, + "modules": ExpectArrayContaining {}, + "outputPath": StringContaining ".svelte-kit", + "plugin": { + "name": StringMatching "@codecov/sveltekit-plugin", + "version": "0.0.1-beta.10", + }, + "version": "2", +} +`; + exports[`Generating sveltekit stats 2 {"format":"esm","expected":"esm"} matches the snapshot 1`] = ` { "assets": ExpectArrayContaining {}, @@ -17,7 +59,7 @@ exports[`Generating sveltekit stats 2 {"format":"esm","expected":"esm"} matches "name": StringMatching "@codecov/sveltekit-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -38,6 +80,48 @@ exports[`Generating sveltekit stats 2 {"format":"esm","expected":"esm"} matches "name": StringMatching "@codecov/sveltekit-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", +} +`; + +exports[`Generating sveltekit stats 2 {"format":"module","expected":"esm"} matches the snapshot 1`] = ` +{ + "assets": ExpectArrayContaining {}, + "builtAt": Any, + "bundleName": StringContaining "test-sveltekit-v2-client-esm", + "bundler": { + "name": "rollup", + "version": "4.16.2", + }, + "chunks": ExpectArrayContaining {}, + "duration": Any, + "modules": ExpectArrayContaining {}, + "outputPath": StringContaining ".svelte-kit", + "plugin": { + "name": StringMatching "@codecov/sveltekit-plugin", + "version": "0.0.1-beta.10", + }, + "version": "2", +} +`; + +exports[`Generating sveltekit stats 2 {"format":"module","expected":"esm"} matches the snapshot 2`] = ` +{ + "assets": ExpectArrayContaining {}, + "builtAt": Any, + "bundleName": StringContaining "test-sveltekit-v2-server-esm", + "bundler": { + "name": "rollup", + "version": "4.16.2", + }, + "chunks": ExpectArrayContaining {}, + "duration": Any, + "modules": ExpectArrayContaining {}, + "outputPath": StringContaining ".svelte-kit", + "plugin": { + "name": StringMatching "@codecov/sveltekit-plugin", + "version": "0.0.1-beta.10", + }, + "version": "2", } `; diff --git a/integration-tests/fixtures/generate-bundle-stats/sveltekit/sveltekit-plugin.test.ts b/integration-tests/fixtures/generate-bundle-stats/sveltekit/sveltekit-plugin.test.ts index 398515d0..42351091 100644 --- a/integration-tests/fixtures/generate-bundle-stats/sveltekit/sveltekit-plugin.test.ts +++ b/integration-tests/fixtures/generate-bundle-stats/sveltekit/sveltekit-plugin.test.ts @@ -7,8 +7,11 @@ const sveltekitApp = "test-apps/sveltekit"; const VERSIONS = [2]; -// Default Rollup formats: https://rollupjs.org/configuration-options/#output-format -const FORMATS = [{ format: "esm", expected: "esm" }]; +const FORMATS = [ + { format: "es", expected: "esm" }, + { format: "esm", expected: "esm" }, + { format: "module", expected: "esm" }, +]; describe("Generating sveltekit stats", () => { describe.each(VERSIONS)("%d", (version) => { @@ -61,9 +64,7 @@ describe("Generating sveltekit stats", () => { builtAt: expect.any(Number), duration: expect.any(Number), outputPath: expect.stringContaining(`.svelte-kit`), - bundleName: expect.stringContaining( - `test-sveltekit-v${version}-client-${expected}`, - ), + bundleName: expect.stringContaining(clientBundleName), plugin: { name: expect.stringMatching("@codecov/sveltekit-plugin"), }, @@ -72,6 +73,7 @@ describe("Generating sveltekit stats", () => { name: expect.any(String), normalized: expect.any(String), size: expect.any(Number), + gzipSize: expect.anything(), }, ]), chunks: expect.arrayContaining([ @@ -104,9 +106,7 @@ describe("Generating sveltekit stats", () => { builtAt: expect.any(Number), duration: expect.any(Number), outputPath: expect.stringContaining(`.svelte-kit`), - bundleName: expect.stringContaining( - `test-sveltekit-v${version}-server-${expected}`, - ), + bundleName: expect.stringContaining(serverBundleName), plugin: { name: expect.stringMatching("@codecov/sveltekit-plugin"), }, @@ -115,6 +115,7 @@ describe("Generating sveltekit stats", () => { name: expect.any(String), normalized: expect.any(String), size: expect.any(Number), + gzipSize: expect.anything(), }, ]), chunks: expect.arrayContaining([ diff --git a/integration-tests/fixtures/generate-bundle-stats/vite/__snapshots__/vite-plugin.test.ts.snap b/integration-tests/fixtures/generate-bundle-stats/vite/__snapshots__/vite-plugin.test.ts.snap index 2c3f567b..ac0c782b 100644 --- a/integration-tests/fixtures/generate-bundle-stats/vite/__snapshots__/vite-plugin.test.ts.snap +++ b/integration-tests/fixtures/generate-bundle-stats/vite/__snapshots__/vite-plugin.test.ts.snap @@ -4,6 +4,7 @@ exports[`Generating vite stats v4 {"format":"amd","expected":"amd"} matches the { "assets": [ { + "gzipSize": 26821, "name": "assets/index-b7a309be.js", "normalized": "assets/index-*.js", "size": 72360, @@ -86,7 +87,7 @@ exports[`Generating vite stats v4 {"format":"amd","expected":"amd"} matches the "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -94,6 +95,7 @@ exports[`Generating vite stats v4 {"format":"cjs","expected":"cjs"} matches the { "assets": [ { + "gzipSize": 26812, "name": "assets/index-7de22500.js", "normalized": "assets/index-*.js", "size": 72342, @@ -176,7 +178,7 @@ exports[`Generating vite stats v4 {"format":"cjs","expected":"cjs"} matches the "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -184,6 +186,7 @@ exports[`Generating vite stats v4 {"format":"es","expected":"esm"} matches the s { "assets": [ { + "gzipSize": 27169, "name": "assets/index-320c8eaf.js", "normalized": "assets/index-*.js", "size": 73071, @@ -266,7 +269,7 @@ exports[`Generating vite stats v4 {"format":"es","expected":"esm"} matches the s "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -274,6 +277,7 @@ exports[`Generating vite stats v4 {"format":"esm","expected":"esm"} matches the { "assets": [ { + "gzipSize": 27169, "name": "assets/index-320c8eaf.js", "normalized": "assets/index-*.js", "size": 73071, @@ -356,7 +360,7 @@ exports[`Generating vite stats v4 {"format":"esm","expected":"esm"} matches the "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -364,6 +368,7 @@ exports[`Generating vite stats v4 {"format":"module","expected":"esm"} matches t { "assets": [ { + "gzipSize": 27169, "name": "assets/index-320c8eaf.js", "normalized": "assets/index-*.js", "size": 73071, @@ -446,7 +451,7 @@ exports[`Generating vite stats v4 {"format":"module","expected":"esm"} matches t "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -454,6 +459,7 @@ exports[`Generating vite stats v4 {"format":"iife","expected":"iife"} matches th { "assets": [ { + "gzipSize": 26821, "name": "assets/index-646c8a11.js", "normalized": "assets/index-*.js", "size": 72356, @@ -536,7 +542,7 @@ exports[`Generating vite stats v4 {"format":"iife","expected":"iife"} matches th "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -544,6 +550,7 @@ exports[`Generating vite stats v4 {"format":"umd","expected":"umd"} matches the { "assets": [ { + "gzipSize": 26850, "name": "assets/index-5458a54a.js", "normalized": "assets/index-*.js", "size": 72423, @@ -626,7 +633,7 @@ exports[`Generating vite stats v4 {"format":"umd","expected":"umd"} matches the "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -634,6 +641,7 @@ exports[`Generating vite stats v4 {"format":"system","expected":"system"} matche { "assets": [ { + "gzipSize": 26850, "name": "assets/index-2fd1a797.js", "normalized": "assets/index-*.js", "size": 72405, @@ -716,7 +724,7 @@ exports[`Generating vite stats v4 {"format":"system","expected":"system"} matche "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -724,6 +732,7 @@ exports[`Generating vite stats v4 {"format":"systemjs","expected":"system"} matc { "assets": [ { + "gzipSize": 26850, "name": "assets/index-2fd1a797.js", "normalized": "assets/index-*.js", "size": 72405, @@ -806,7 +815,7 @@ exports[`Generating vite stats v4 {"format":"systemjs","expected":"system"} matc "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -814,6 +823,7 @@ exports[`Generating vite stats v4 source maps are enabled does not include any s { "assets": [ { + "gzipSize": 27198, "name": "assets/index-320c8eaf.js", "normalized": "assets/index-*.js", "size": 73114, @@ -896,7 +906,7 @@ exports[`Generating vite stats v4 source maps are enabled does not include any s "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -904,6 +914,7 @@ exports[`Generating vite stats v5 {"format":"amd","expected":"amd"} matches the { "assets": [ { + "gzipSize": 26821, "name": "assets/index-D0r0olUW.js", "normalized": "assets/index-*.js", "size": 72360, @@ -986,7 +997,7 @@ exports[`Generating vite stats v5 {"format":"amd","expected":"amd"} matches the "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -994,6 +1005,7 @@ exports[`Generating vite stats v5 {"format":"cjs","expected":"cjs"} matches the { "assets": [ { + "gzipSize": 26812, "name": "assets/index-_9bu_Rar.js", "normalized": "assets/index-_9bu_Rar.js", "size": 72342, @@ -1076,7 +1088,7 @@ exports[`Generating vite stats v5 {"format":"cjs","expected":"cjs"} matches the "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -1084,6 +1096,7 @@ exports[`Generating vite stats v5 {"format":"es","expected":"esm"} matches the s { "assets": [ { + "gzipSize": 27169, "name": "assets/index-Cq3U4pkx.js", "normalized": "assets/index-*.js", "size": 73071, @@ -1166,7 +1179,7 @@ exports[`Generating vite stats v5 {"format":"es","expected":"esm"} matches the s "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -1174,6 +1187,7 @@ exports[`Generating vite stats v5 {"format":"esm","expected":"esm"} matches the { "assets": [ { + "gzipSize": 27169, "name": "assets/index-Cq3U4pkx.js", "normalized": "assets/index-*.js", "size": 73071, @@ -1256,7 +1270,7 @@ exports[`Generating vite stats v5 {"format":"esm","expected":"esm"} matches the "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -1264,6 +1278,7 @@ exports[`Generating vite stats v5 {"format":"module","expected":"esm"} matches t { "assets": [ { + "gzipSize": 27169, "name": "assets/index-Cq3U4pkx.js", "normalized": "assets/index-*.js", "size": 73071, @@ -1346,7 +1361,7 @@ exports[`Generating vite stats v5 {"format":"module","expected":"esm"} matches t "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -1354,6 +1369,7 @@ exports[`Generating vite stats v5 {"format":"iife","expected":"iife"} matches th { "assets": [ { + "gzipSize": 26821, "name": "assets/index-B31DUBuo.js", "normalized": "assets/index-*.js", "size": 72356, @@ -1436,7 +1452,7 @@ exports[`Generating vite stats v5 {"format":"iife","expected":"iife"} matches th "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -1444,6 +1460,7 @@ exports[`Generating vite stats v5 {"format":"umd","expected":"umd"} matches the { "assets": [ { + "gzipSize": 26850, "name": "assets/index-BFgpG9Ne.js", "normalized": "assets/index-*.js", "size": 72423, @@ -1526,7 +1543,7 @@ exports[`Generating vite stats v5 {"format":"umd","expected":"umd"} matches the "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -1534,6 +1551,7 @@ exports[`Generating vite stats v5 {"format":"system","expected":"system"} matche { "assets": [ { + "gzipSize": 26850, "name": "assets/index-Cn9uVtOh.js", "normalized": "assets/index-*.js", "size": 72405, @@ -1616,7 +1634,7 @@ exports[`Generating vite stats v5 {"format":"system","expected":"system"} matche "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -1624,6 +1642,7 @@ exports[`Generating vite stats v5 {"format":"systemjs","expected":"system"} matc { "assets": [ { + "gzipSize": 26850, "name": "assets/index-Cn9uVtOh.js", "normalized": "assets/index-*.js", "size": 72405, @@ -1706,7 +1725,7 @@ exports[`Generating vite stats v5 {"format":"systemjs","expected":"system"} matc "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -1714,6 +1733,7 @@ exports[`Generating vite stats v5 source maps are enabled does not include any s { "assets": [ { + "gzipSize": 27198, "name": "assets/index-Cq3U4pkx.js", "normalized": "assets/index-*.js", "size": 73114, @@ -1796,6 +1816,6 @@ exports[`Generating vite stats v5 source maps are enabled does not include any s "name": StringMatching "@codecov/vite-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; diff --git a/integration-tests/fixtures/generate-bundle-stats/webpack/__snapshots__/webpack-plugin.test.ts.snap b/integration-tests/fixtures/generate-bundle-stats/webpack/__snapshots__/webpack-plugin.test.ts.snap index b57eea76..d41c374b 100644 --- a/integration-tests/fixtures/generate-bundle-stats/webpack/__snapshots__/webpack-plugin.test.ts.snap +++ b/integration-tests/fixtures/generate-bundle-stats/webpack/__snapshots__/webpack-plugin.test.ts.snap @@ -4,6 +4,7 @@ exports[`Generating webpack stats 5 {"format":"array-push","expected":"array-pus { "assets": [ { + "gzipSize": 25254, "name": "main-6c1d26e76f6ba1fc75c8.js", "normalized": "main-*.js", "size": 70961, @@ -70,7 +71,7 @@ exports[`Generating webpack stats 5 {"format":"array-push","expected":"array-pus "name": StringMatching "@codecov/webpack-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -78,6 +79,7 @@ exports[`Generating webpack stats 5 {"format":"commonjs","expected":"cjs"} match { "assets": [ { + "gzipSize": 25254, "name": "main-6c1d26e76f6ba1fc75c8.js", "normalized": "main-*.js", "size": 70961, @@ -144,7 +146,7 @@ exports[`Generating webpack stats 5 {"format":"commonjs","expected":"cjs"} match "name": StringMatching "@codecov/webpack-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -152,6 +154,7 @@ exports[`Generating webpack stats 5 {"format":"module","expected":"esm"} matches { "assets": [ { + "gzipSize": 25254, "name": "main-6c1d26e76f6ba1fc75c8.js", "normalized": "main-*.js", "size": 70961, @@ -218,7 +221,7 @@ exports[`Generating webpack stats 5 {"format":"module","expected":"esm"} matches "name": StringMatching "@codecov/webpack-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; @@ -226,6 +229,7 @@ exports[`Generating webpack stats 5 source maps are enabled does not include any { "assets": [ { + "gzipSize": 25254, "name": "main-6c1d26e76f6ba1fc75c8.js", "normalized": "main-*.js", "size": 70961, @@ -292,6 +296,6 @@ exports[`Generating webpack stats 5 source maps are enabled does not include any "name": StringMatching "@codecov/webpack-plugin", "version": "0.0.1-beta.10", }, - "version": "1", + "version": "2", } `; diff --git a/packages/bundler-plugin-core/src/index.ts b/packages/bundler-plugin-core/src/index.ts index b7ccea78..d6f1e489 100644 --- a/packages/bundler-plugin-core/src/index.ts +++ b/packages/bundler-plugin-core/src/index.ts @@ -7,11 +7,16 @@ import { type ProviderUtilInputs, type UploadOverrides, } from "./types.ts"; -import { checkNodeVersion } from "./utils/checkNodeVersion.ts"; -import { red } from "./utils/logging.ts"; -import { handleErrors, normalizeOptions } from "./utils/normalizeOptions.ts"; -import { normalizePath } from "./utils/normalizePath.ts"; -import { Output } from "./utils/Output.ts"; +import { + checkNodeVersion, + createRollupAsset, + getCompressedSize, + handleErrors, + normalizeOptions, + normalizePath, + Output, + red, +} from "./utils"; export type { Asset, @@ -25,7 +30,9 @@ export type { export { checkNodeVersion, + createRollupAsset, handleErrors, + getCompressedSize, normalizeOptions, normalizePath, Output, diff --git a/packages/bundler-plugin-core/src/types.ts b/packages/bundler-plugin-core/src/types.ts index 09fe43e6..fc3725fd 100644 --- a/packages/bundler-plugin-core/src/types.ts +++ b/packages/bundler-plugin-core/src/types.ts @@ -9,6 +9,7 @@ export interface Dependency { export interface Asset { name: string; size: number; + gzipSize: number | null; normalized: string; } diff --git a/packages/bundler-plugin-core/src/utils/Output.ts b/packages/bundler-plugin-core/src/utils/Output.ts index b9019263..5ff245e3 100644 --- a/packages/bundler-plugin-core/src/utils/Output.ts +++ b/packages/bundler-plugin-core/src/utils/Output.ts @@ -50,7 +50,7 @@ class Output { }; constructor(userOptions: NormalizedOptions) { - this.version = "1"; + this.version = "2"; this.apiUrl = userOptions.apiUrl; this.dryRun = userOptions.dryRun; this.retryCount = userOptions.retryCount; diff --git a/packages/bundler-plugin-core/src/utils/__tests__/createRollupAsset.test.ts b/packages/bundler-plugin-core/src/utils/__tests__/createRollupAsset.test.ts new file mode 100644 index 00000000..4ce6773e --- /dev/null +++ b/packages/bundler-plugin-core/src/utils/__tests__/createRollupAsset.test.ts @@ -0,0 +1,67 @@ +import { describe, it, expect } from "vitest"; + +import { createRollupAsset } from "../createRollupAsset"; + +describe("createRollupAsset", () => { + it("sets the asset name", async () => { + const asset = await createRollupAsset({ + fileName: "test.D4lWaVuy.js", + source: Buffer.from("test"), + formatString: "[name].[hash].js", + }); + + expect(asset.name).toBe("test.D4lWaVuy.js"); + }); + + it("sets the normalized name", async () => { + const asset = await createRollupAsset({ + fileName: "test.D4lWaVuy.js", + source: Buffer.from("test"), + formatString: "[name].[hash].js", + }); + + expect(asset.normalized).toBe("test.*.js"); + }); + + describe("when the source is a Buffer", () => { + it("sets the size", async () => { + const asset = await createRollupAsset({ + fileName: "test.D4lWaVuy.js", + source: Buffer.from("test"), + formatString: "[name].[hash].js", + }); + + expect(asset.size).toBe(4); + }); + + it("sets the gzip size", async () => { + const asset = await createRollupAsset({ + fileName: "test.D4lWaVuy.js", + source: Buffer.from("test"), + formatString: "[name].[hash].js", + }); + expect(asset.gzipSize).toBe(24); + }); + }); + + describe("when the source is a string", () => { + it("sets the size", async () => { + const asset = await createRollupAsset({ + fileName: "test.D4lWaVuy.js", + source: "test", + formatString: "[name].[hash].js", + }); + + expect(asset.size).toBe(4); + }); + + it("sets the gzip size", async () => { + const asset = await createRollupAsset({ + fileName: "test.D4lWaVuy.js", + source: "test", + formatString: "[name].[hash].js", + }); + expect(asset.gzipSize).toBe(24); + }); + }); +}); diff --git a/packages/bundler-plugin-core/src/utils/__tests__/getCompressedSize.spec.ts b/packages/bundler-plugin-core/src/utils/__tests__/getCompressedSize.spec.ts new file mode 100644 index 00000000..fab8f08b --- /dev/null +++ b/packages/bundler-plugin-core/src/utils/__tests__/getCompressedSize.spec.ts @@ -0,0 +1,38 @@ +import { getCompressedSize } from "../getCompressedSize"; +import { describe, it, expect } from "vitest"; + +describe("getCompressedSize", () => { + describe("file extension is not compressible", () => { + it("should return null", async () => { + const result = await getCompressedSize({ + fileName: "file.png", + code: "", + }); + + expect(result).toBe(null); + }); + }); + + describe("file extension is compressible", () => { + describe("code is a string", () => { + it("should return the compressed size", async () => { + const result = await getCompressedSize({ + fileName: "file.css", + code: "body { color: red; }", + }); + + expect(result).toBe(40); + }); + }); + describe("code is a Uint8Array", () => { + it("should return the compressed size", async () => { + const result = await getCompressedSize({ + fileName: "file.css", + code: new TextEncoder().encode("body { color: red; }"), + }); + + expect(result).toBe(40); + }); + }); + }); +}); diff --git a/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts b/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts index 33ff1fec..520b7443 100644 --- a/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts +++ b/packages/bundler-plugin-core/src/utils/__tests__/normalizeOptions.test.ts @@ -226,8 +226,10 @@ describe("handleErrors", () => { }); expect(consoleSpy).toHaveBeenCalled(); - expect(consoleSpy).toHaveBeenCalledWith( - "[codecov] `bundleName` is required for uploading bundle analysis information.", + expect(consoleSpy.mock.lastCall?.[0]).toStrictEqual( + expect.stringContaining( + "`bundleName` is required for uploading bundle analysis information.", + ), ); }); @@ -252,8 +254,10 @@ describe("handleErrors", () => { }); expect(consoleSpy).toHaveBeenCalled(); - expect(consoleSpy).toHaveBeenCalledWith( - "[codecov] `bundleName` is required for uploading bundle analysis information.", + expect(consoleSpy.mock.lastCall?.[0]).toStrictEqual( + expect.stringContaining( + "`bundleName` is required for uploading bundle analysis information.", + ), ); }); diff --git a/packages/bundler-plugin-core/src/utils/createRollupAsset.ts b/packages/bundler-plugin-core/src/utils/createRollupAsset.ts new file mode 100644 index 00000000..740c42e3 --- /dev/null +++ b/packages/bundler-plugin-core/src/utils/createRollupAsset.ts @@ -0,0 +1,31 @@ +import { getCompressedSize } from "./getCompressedSize.ts"; +import { normalizePath } from "./normalizePath.ts"; + +interface CreateAssetOptions { + fileName: string; + source: Uint8Array | string; + formatString: string; +} + +export const createRollupAsset = async ({ + source, + fileName, + formatString, +}: CreateAssetOptions) => { + const size = + source instanceof Buffer + ? source.byteLength + : Buffer.from(source).byteLength; + + const gzipSize = await getCompressedSize({ + fileName, + code: source, + }); + + return { + name: fileName, + size: size, + gzipSize: gzipSize, + normalized: normalizePath(fileName, formatString), + }; +}; diff --git a/packages/bundler-plugin-core/src/utils/getCompressedSize.ts b/packages/bundler-plugin-core/src/utils/getCompressedSize.ts new file mode 100644 index 00000000..06ced9ee --- /dev/null +++ b/packages/bundler-plugin-core/src/utils/getCompressedSize.ts @@ -0,0 +1,28 @@ +import { promisify } from "node:util"; +import { gzip } from "node:zlib"; + +const COMPRESSIBLE_ASSETS_RE = /\.(?:css|html|json|js|svg|txt|xml|xhtml)$/; + +interface GetCompressedSizeOptions { + fileName: string; + code: string | Uint8Array; +} + +export const getCompressedSize = async ({ + fileName, + code, +}: GetCompressedSizeOptions) => { + const isCompressible = COMPRESSIBLE_ASSETS_RE.test(fileName); + + if (!isCompressible) { + return null; + } + + const compress = promisify(gzip); + + const compressed = await compress( + typeof code === "string" ? code : Buffer.from(code), + ); + + return compressed.length; +}; diff --git a/packages/bundler-plugin-core/src/utils/index.ts b/packages/bundler-plugin-core/src/utils/index.ts new file mode 100644 index 00000000..43556f6a --- /dev/null +++ b/packages/bundler-plugin-core/src/utils/index.ts @@ -0,0 +1,7 @@ +export { checkNodeVersion } from "./checkNodeVersion.ts"; +export { createRollupAsset } from "./createRollupAsset.ts"; +export { red } from "./logging.ts"; +export { getCompressedSize } from "./getCompressedSize.ts"; +export { normalizeOptions, handleErrors } from "./normalizeOptions.ts"; +export { normalizePath } from "./normalizePath.ts"; +export { Output } from "./Output.ts"; diff --git a/packages/nuxt-plugin/src/nuxt-bundle-analysis/__tests__/__snapshots__/nuxtBundleAnalysisPlugin.test.ts.snap b/packages/nuxt-plugin/src/nuxt-bundle-analysis/__tests__/__snapshots__/nuxtBundleAnalysisPlugin.test.ts.snap index a2461872..c75a1a2e 100644 --- a/packages/nuxt-plugin/src/nuxt-bundle-analysis/__tests__/__snapshots__/nuxtBundleAnalysisPlugin.test.ts.snap +++ b/packages/nuxt-plugin/src/nuxt-bundle-analysis/__tests__/__snapshots__/nuxtBundleAnalysisPlugin.test.ts.snap @@ -4,7 +4,7 @@ exports[`nuxtBundleAnalysisPlugin > when called > returns a plugin object 1`] = { "name": "@codecov/nuxt-plugin", "pluginVersion": "0.0.1-beta.10", - "version": "1", + "version": "2", "vite": { "generateBundle": [Function], }, diff --git a/packages/nuxt-plugin/src/nuxt-bundle-analysis/nuxtBundleAnalysisPlugin.ts b/packages/nuxt-plugin/src/nuxt-bundle-analysis/nuxtBundleAnalysisPlugin.ts index 8d4f08af..b96707d4 100644 --- a/packages/nuxt-plugin/src/nuxt-bundle-analysis/nuxtBundleAnalysisPlugin.ts +++ b/packages/nuxt-plugin/src/nuxt-bundle-analysis/nuxtBundleAnalysisPlugin.ts @@ -12,7 +12,7 @@ const PLUGIN_VERSION = __PACKAGE_VERSION__ as string; export const nuxtBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ output, }) => ({ - version: "1", + version: output.version, name: PLUGIN_NAME, pluginVersion: PLUGIN_VERSION, vite: { diff --git a/packages/remix-vite-plugin/src/remix-bundle-analysis/__tests__/__snapshots__/remixBundleAnalysisPlugin.test.ts.snap b/packages/remix-vite-plugin/src/remix-bundle-analysis/__tests__/__snapshots__/remixBundleAnalysisPlugin.test.ts.snap index 4b0eaada..83cb15e4 100644 --- a/packages/remix-vite-plugin/src/remix-bundle-analysis/__tests__/__snapshots__/remixBundleAnalysisPlugin.test.ts.snap +++ b/packages/remix-vite-plugin/src/remix-bundle-analysis/__tests__/__snapshots__/remixBundleAnalysisPlugin.test.ts.snap @@ -4,7 +4,7 @@ exports[`remixBundleAnalysisPlugin > when called > returns a plugin object 1`] = { "name": "@codecov/remix-vite-plugin", "pluginVersion": "0.0.1-beta.10", - "version": "1", + "version": "2", "vite": { "generateBundle": [Function], }, diff --git a/packages/remix-vite-plugin/src/remix-bundle-analysis/remixBundleAnalysisPlugin.ts b/packages/remix-vite-plugin/src/remix-bundle-analysis/remixBundleAnalysisPlugin.ts index 65981631..6e43c9d1 100644 --- a/packages/remix-vite-plugin/src/remix-bundle-analysis/remixBundleAnalysisPlugin.ts +++ b/packages/remix-vite-plugin/src/remix-bundle-analysis/remixBundleAnalysisPlugin.ts @@ -12,7 +12,7 @@ const PLUGIN_VERSION = __PACKAGE_VERSION__ as string; export const remixBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ output, }) => ({ - version: "1", + version: output.version, name: PLUGIN_NAME, pluginVersion: PLUGIN_VERSION, vite: { diff --git a/packages/rollup-plugin/src/rollup-bundle-analysis/__tests__/__snapshots__/rollupBundleAnalysisPlugin.test.ts.snap b/packages/rollup-plugin/src/rollup-bundle-analysis/__tests__/__snapshots__/rollupBundleAnalysisPlugin.test.ts.snap index c9ea597e..a18addce 100644 --- a/packages/rollup-plugin/src/rollup-bundle-analysis/__tests__/__snapshots__/rollupBundleAnalysisPlugin.test.ts.snap +++ b/packages/rollup-plugin/src/rollup-bundle-analysis/__tests__/__snapshots__/rollupBundleAnalysisPlugin.test.ts.snap @@ -9,7 +9,7 @@ exports[`rollupBundleAnalysisPlugin > when called > returns a plugin object 1`] "rollup": { "generateBundle": [Function], }, - "version": "1", + "version": "2", "writeBundle": [Function], } `; diff --git a/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts b/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts index 2fcac3e1..061ed048 100644 --- a/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts +++ b/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts @@ -5,7 +5,7 @@ import { type Module, type BundleAnalysisUploadPlugin, red, - normalizePath, + createRollupAsset, } from "@codecov/bundler-plugin-core"; // @ts-expect-error this value is being replaced by rollup @@ -16,7 +16,7 @@ const PLUGIN_VERSION = __PACKAGE_VERSION__ as string; export const rollupBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ output, }) => ({ - version: "1", + version: output.version, name: PLUGIN_NAME, pluginVersion: PLUGIN_VERSION, buildStart: () => { @@ -30,7 +30,7 @@ export const rollupBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ await output.write(); }, rollup: { - generateBundle(this, options, bundle) { + async generateBundle(this, options, bundle) { // TODO - remove this once we hard fail on not having a bundle name // don't need to do anything if the bundle name is not present or empty if (!output.bundleName || output.bundleName === "") { @@ -68,98 +68,87 @@ export const rollupBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ } let counter = 0; - for (const item of items) { - if (item?.type === "asset") { - if (typeof item.source === "string") { + await Promise.all( + items.map(async (item) => { + if (item?.type === "asset") { const fileName = item?.fileName ?? ""; - const size = Buffer.from(item.source).byteLength; - if (path.extname(fileName) === ".map") { - continue; + return; } - assets.push({ - name: fileName, - size: size, - normalized: normalizePath(fileName, assetFormatString), + const asset = await createRollupAsset({ + fileName: fileName, + source: item.source, + formatString: assetFormatString, }); - } else { + assets.push(asset); + } else if (item?.type === "chunk") { const fileName = item?.fileName ?? ""; - const size = item?.source?.byteLength; - if (path.extname(fileName) === ".map") { - continue; + return; } - assets.push({ - name: fileName, - size: size, - normalized: normalizePath(fileName, assetFormatString), + const asset = await createRollupAsset({ + fileName, + source: item.code, + formatString: chunkFormatString, + }); + assets.push(asset); + + const chunkId = item?.name ?? ""; + const uniqueId = `${counter}-${chunkId}`; + + chunks.push({ + id: chunkId, + uniqueId: uniqueId, + entry: item?.isEntry, + initial: item?.isDynamicEntry, + files: [fileName], + names: [item?.name], }); - } - } - - if (item?.type === "chunk") { - const chunkId = item?.name ?? ""; - const fileName = item?.fileName ?? ""; - const moduleEntries = Object.entries(item?.modules ?? {}); - const size = item?.code?.length; - const uniqueId = `${counter}-${chunkId}`; - - if (path.extname(fileName) === ".map") { - continue; - } - assets.push({ - name: fileName, - size: size, - normalized: normalizePath(fileName, chunkFormatString), - }); - - chunks.push({ - id: chunkId, - uniqueId: uniqueId, - entry: item?.isEntry, - initial: item?.isDynamicEntry, - files: [fileName], - names: [item?.name], - }); - - for (const [modulePath, moduleInfo] of moduleEntries) { - const normalizedModulePath = modulePath.replace("\u0000", ""); - const relativeModulePath = path.relative(cwd, normalizedModulePath); - const relativeModulePathWithPrefix = relativeModulePath.match( - /^\.\./, - ) - ? relativeModulePath - : `.${path.sep}${relativeModulePath}`; - - // try to grab module already set in map - const moduleEntry = moduleByFileName.get( - relativeModulePathWithPrefix, - ); - - // if the modules exists append chunk ids to the grabbed module - // else create a new module and create a new entry in the map - if (moduleEntry) { - moduleEntry.chunkUniqueIds.push(uniqueId); - } else { - const size = customOptions.moduleOriginalSize - ? moduleInfo.originalLength - : moduleInfo.renderedLength; - - const module: Module = { - name: relativeModulePathWithPrefix, - size: size, - chunkUniqueIds: [uniqueId], - }; - - moduleByFileName.set(relativeModulePathWithPrefix, module); + const moduleEntries = Object.entries(item?.modules ?? {}); + for (const [modulePath, moduleInfo] of moduleEntries) { + const normalizedModulePath = modulePath.replace("\u0000", ""); + const relativeModulePath = path.relative( + cwd, + normalizedModulePath, + ); + const relativeModulePathWithPrefix = relativeModulePath.match( + /^\.\./, + ) + ? relativeModulePath + : `.${path.sep}${relativeModulePath}`; + + // try to grab module already set in map + const moduleEntry = moduleByFileName.get( + relativeModulePathWithPrefix, + ); + + // if the modules exists append chunk ids to the grabbed module + // else create a new module and create a new entry in the map + if (moduleEntry) { + moduleEntry.chunkUniqueIds.push(uniqueId); + } else { + const size = customOptions.moduleOriginalSize + ? moduleInfo.originalLength + : moduleInfo.renderedLength; + + const module: Module = { + name: relativeModulePathWithPrefix, + size: size, + chunkUniqueIds: [uniqueId], + }; + + moduleByFileName.set(relativeModulePathWithPrefix, module); + } } + counter += 1; } - counter += 1; - } - } + + return; + }), + ); // grab the modules from the map and convert it to an array const modules = Array.from(moduleByFileName.values()); diff --git a/packages/sveltekit-plugin/src/sveltekit-bundle-analysis/__tests__/__snapshots__/sveltekitBundleAnalysisPlugin.test.ts.snap b/packages/sveltekit-plugin/src/sveltekit-bundle-analysis/__tests__/__snapshots__/sveltekitBundleAnalysisPlugin.test.ts.snap index c0c76c35..9bb46d06 100644 --- a/packages/sveltekit-plugin/src/sveltekit-bundle-analysis/__tests__/__snapshots__/sveltekitBundleAnalysisPlugin.test.ts.snap +++ b/packages/sveltekit-plugin/src/sveltekit-bundle-analysis/__tests__/__snapshots__/sveltekitBundleAnalysisPlugin.test.ts.snap @@ -4,7 +4,7 @@ exports[`sveltekitBundleAnalysisPlugin > when called > returns a plugin object 1 { "name": "@codecov/sveltekit-plugin", "pluginVersion": "0.0.1-beta.10", - "version": "1", + "version": "2", "vite": { "generateBundle": [Function], }, diff --git a/packages/sveltekit-plugin/src/sveltekit-bundle-analysis/sveltekitBundleAnalysisPlugin.ts b/packages/sveltekit-plugin/src/sveltekit-bundle-analysis/sveltekitBundleAnalysisPlugin.ts index 3d80fdc1..24ef67c2 100644 --- a/packages/sveltekit-plugin/src/sveltekit-bundle-analysis/sveltekitBundleAnalysisPlugin.ts +++ b/packages/sveltekit-plugin/src/sveltekit-bundle-analysis/sveltekitBundleAnalysisPlugin.ts @@ -12,7 +12,7 @@ const PLUGIN_VERSION = __PACKAGE_VERSION__ as string; export const sveltekitBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ output, }) => ({ - version: "1", + version: output.version, name: PLUGIN_NAME, pluginVersion: PLUGIN_VERSION, vite: { diff --git a/packages/vite-plugin/src/vite-bundle-analysis/__tests__/__snapshots__/viteBundleAnalysisPlugin.test.ts.snap b/packages/vite-plugin/src/vite-bundle-analysis/__tests__/__snapshots__/viteBundleAnalysisPlugin.test.ts.snap index 7e61c95c..0c100ac7 100644 --- a/packages/vite-plugin/src/vite-bundle-analysis/__tests__/__snapshots__/viteBundleAnalysisPlugin.test.ts.snap +++ b/packages/vite-plugin/src/vite-bundle-analysis/__tests__/__snapshots__/viteBundleAnalysisPlugin.test.ts.snap @@ -6,7 +6,7 @@ exports[`viteBundleAnalysisPlugin > when called > returns a plugin object 1`] = "buildStart": [Function], "name": "@codecov/vite-plugin", "pluginVersion": "0.0.1-beta.10", - "version": "1", + "version": "2", "vite": { "generateBundle": [Function], }, diff --git a/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts b/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts index 10c8e5a6..8d53ecdc 100644 --- a/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts +++ b/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts @@ -1,11 +1,11 @@ import path from "node:path"; import { - normalizePath, type Asset, type Chunk, type Module, type BundleAnalysisUploadPlugin, red, + createRollupAsset, } from "@codecov/bundler-plugin-core"; // @ts-expect-error this value is being replaced by rollup @@ -16,7 +16,7 @@ const PLUGIN_VERSION = __PACKAGE_VERSION__ as string; export const viteBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ output, }) => ({ - version: "1", + version: output.version, name: PLUGIN_NAME, pluginVersion: PLUGIN_VERSION, buildStart: () => { @@ -30,7 +30,7 @@ export const viteBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ await output.write(); }, vite: { - generateBundle(this, options, bundle) { + async generateBundle(this, options, bundle) { // TODO - remove this once we hard fail on not having a bundle name // don't need to do anything if the bundle name is not present or empty if (!output.bundleName || output.bundleName === "") { @@ -69,99 +69,87 @@ export const viteBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ } let counter = 0; - for (const item of items) { - if (item?.type === "asset") { - if (typeof item.source === "string") { + await Promise.all( + items.map(async (item) => { + if (item?.type === "asset") { const fileName = item?.fileName ?? ""; - const size = Buffer.from(item.source).byteLength; - if (path.extname(fileName) === ".map") { - continue; + return; } - assets.push({ - name: fileName, - size: size, - normalized: normalizePath(fileName, assetFormatString), + const asset = await createRollupAsset({ + fileName: fileName, + source: item.source, + formatString: assetFormatString, }); - } else { + assets.push(asset); + } else if (item?.type === "chunk") { const fileName = item?.fileName ?? ""; - const size = item?.source.byteLength; - if (path.extname(fileName) === ".map") { - continue; + return; } - assets.push({ - name: fileName, - size: size, - normalized: normalizePath(fileName, assetFormatString), + const asset = await createRollupAsset({ + fileName, + source: item.code, + formatString: chunkFormatString, + }); + assets.push(asset); + + const chunkId = item?.name ?? ""; + const uniqueId = `${counter}-${chunkId}`; + chunks.push({ + id: chunkId, + uniqueId: uniqueId, + entry: item?.isEntry, + initial: item?.isDynamicEntry, + files: [fileName], + names: [item?.name], }); - } - } - - if (item?.type === "chunk") { - const chunkId = item?.name ?? ""; - const fileName = item?.fileName ?? ""; - const moduleEntries = Object.entries(item?.modules ?? {}); - const size = Buffer.from(item?.code).byteLength; - const uniqueId = `${counter}-${chunkId}`; - - if (path.extname(fileName) === ".map") { - continue; - } - assets.push({ - name: fileName, - size: size, - normalized: normalizePath(fileName, chunkFormatString), - }); - - chunks.push({ - id: chunkId, - uniqueId: uniqueId, - entry: item?.isEntry, - initial: item?.isDynamicEntry, - files: [fileName], - names: [item?.name], - }); - - for (const [modulePath, moduleInfo] of moduleEntries) { - const normalizedModulePath = modulePath.replace("\u0000", ""); - const relativeModulePath = path.relative(cwd, normalizedModulePath); - - const relativeModulePathWithPrefix = relativeModulePath.match( - /^\.\./, - ) - ? relativeModulePath - : `.${path.sep}${relativeModulePath}`; - - // try to grab module already set in map - const moduleEntry = moduleByFileName.get( - relativeModulePathWithPrefix, - ); - - // if the modules exists append chunk ids to the grabbed module - // else create a new module and create a new entry in the map - if (moduleEntry) { - moduleEntry.chunkUniqueIds.push(uniqueId); - } else { - const size = customOptions.moduleOriginalSize - ? moduleInfo.originalLength - : moduleInfo.renderedLength; - - const module: Module = { - name: relativeModulePathWithPrefix, - size: size, - chunkUniqueIds: [uniqueId], - }; - - moduleByFileName.set(relativeModulePathWithPrefix, module); + const moduleEntries = Object.entries(item?.modules ?? {}); + for (const [modulePath, moduleInfo] of moduleEntries) { + const normalizedModulePath = modulePath.replace("\u0000", ""); + const relativeModulePath = path.relative( + cwd, + normalizedModulePath, + ); + + const relativeModulePathWithPrefix = relativeModulePath.match( + /^\.\./, + ) + ? relativeModulePath + : `.${path.sep}${relativeModulePath}`; + + // try to grab module already set in map + const moduleEntry = moduleByFileName.get( + relativeModulePathWithPrefix, + ); + + // if the modules exists append chunk ids to the grabbed module + // else create a new module and create a new entry in the map + if (moduleEntry) { + moduleEntry.chunkUniqueIds.push(uniqueId); + } else { + const size = customOptions.moduleOriginalSize + ? moduleInfo.originalLength + : moduleInfo.renderedLength; + + const module: Module = { + name: relativeModulePathWithPrefix, + size: size, + chunkUniqueIds: [uniqueId], + }; + + moduleByFileName.set(relativeModulePathWithPrefix, module); + } } + counter += 1; } - counter += 1; - } - } + + return; + }), + ); // grab the modules from the map and convert it to an array const modules = Array.from(moduleByFileName.values()); diff --git a/packages/webpack-plugin/src/webpack-bundle-analysis/__tests__/__snapshots__/webpackBundleAnalysisPlugin.test.ts.snap b/packages/webpack-plugin/src/webpack-bundle-analysis/__tests__/__snapshots__/webpackBundleAnalysisPlugin.test.ts.snap index 7a0ab353..6fa9b802 100644 --- a/packages/webpack-plugin/src/webpack-bundle-analysis/__tests__/__snapshots__/webpackBundleAnalysisPlugin.test.ts.snap +++ b/packages/webpack-plugin/src/webpack-bundle-analysis/__tests__/__snapshots__/webpackBundleAnalysisPlugin.test.ts.snap @@ -6,7 +6,7 @@ exports[`webpackBundleAnalysisPlugin > when called > returns a plugin object 1`] "buildStart": [Function], "name": "@codecov/webpack-plugin", "pluginVersion": "0.0.1-beta.10", - "version": "1", + "version": "2", "webpack": [Function], "writeBundle": [Function], } diff --git a/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts b/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts index 7dc8de4c..97d03f82 100644 --- a/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts +++ b/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts @@ -4,6 +4,7 @@ import { normalizePath, type BundleAnalysisUploadPlugin, type Asset, + getCompressedSize, } from "@codecov/bundler-plugin-core"; import * as webpack from "webpack"; @@ -17,7 +18,7 @@ const PLUGIN_VERSION = __PACKAGE_VERSION__ as string; export const webpackBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ output, }) => ({ - version: "1", + version: output.version, name: PLUGIN_NAME, pluginVersion: PLUGIN_VERSION, buildStart: () => { @@ -32,12 +33,12 @@ export const webpackBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ }, webpack(compiler) { compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => { - compilation.hooks.processAssets.tap( + compilation.hooks.processAssets.tapPromise( { name: PLUGIN_NAME, stage: webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT, }, - () => { + async () => { // TODO - remove this once we hard fail on not having a bundle name // don't need to do anything if the bundle name is not present or empty if (!output.bundleName || output.bundleName === "") { @@ -101,26 +102,41 @@ export const webpackBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ ? outputOptions.chunkFilename : ""; - for (const asset of assets) { - const format = findFilenameFormat({ - assetName: asset.name, - filename, - assetModuleFilename, - chunkFilename, - cssFilename, - cssChunkFilename, - }); + await Promise.all( + assets.map(async (asset) => { + const format = findFilenameFormat({ + assetName: asset.name, + filename, + assetModuleFilename, + chunkFilename, + cssFilename, + cssChunkFilename, + }); + + if (path.extname(asset.name) === ".map") { + return; + } - if (path.extname(asset.name) === ".map") { - continue; - } + const currentAsset = compilation.getAsset(asset.name); - collectedAssets.push({ - name: asset.name, - size: asset.size, - normalized: normalizePath(asset.name, format), - }); - } + let compressedSize = null; + if (currentAsset) { + compressedSize = await getCompressedSize({ + fileName: asset.name, + code: currentAsset.source.source(), + }); + } + + collectedAssets.push({ + name: asset.name, + size: asset.size, + gzipSize: compressedSize, + normalized: normalizePath(asset.name, format), + }); + + return; + }), + ); output.assets = collectedAssets; }