From 2a9c79b2121215879717a4afe9c6d401d3deb5a7 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 19 Jun 2024 14:10:59 -0300 Subject: [PATCH 01/14] update bundler plugin core with updated asset type and function to collect gzip value --- .changeset/old-cameras-search.md | 11 ++++++ packages/bundler-plugin-core/src/index.ts | 2 + packages/bundler-plugin-core/src/types.ts | 1 + .../bundler-plugin-core/src/utils/Output.ts | 2 +- .../utils/__tests__/getCompressedSize.spec.ts | 38 +++++++++++++++++++ .../utils/__tests__/normalizeOptions.test.ts | 12 ++++-- .../src/utils/getCompressedSize.ts | 28 ++++++++++++++ 7 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 .changeset/old-cameras-search.md create mode 100644 packages/bundler-plugin-core/src/utils/__tests__/getCompressedSize.spec.ts create mode 100644 packages/bundler-plugin-core/src/utils/getCompressedSize.ts 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/packages/bundler-plugin-core/src/index.ts b/packages/bundler-plugin-core/src/index.ts index b7ccea78..c5b7a6ca 100644 --- a/packages/bundler-plugin-core/src/index.ts +++ b/packages/bundler-plugin-core/src/index.ts @@ -12,6 +12,7 @@ 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 { getCompressedSize } from "./utils/getCompressedSize.ts"; export type { Asset, @@ -26,6 +27,7 @@ export type { export { checkNodeVersion, 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__/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/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; +}; From bfec3a2b60d23387002d0d38825107e8df6d2634 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 19 Jun 2024 14:16:35 -0300 Subject: [PATCH 02/14] update base plugins to collect gzip info --- .changeset/stupid-points-vanish.md | 11 +++++++++ .../rollupBundleAnalysisPlugin.test.ts.snap | 2 +- .../rollupBundleAnalysisPlugin.ts | 23 +++++++++++++++++-- .../viteBundleAnalysisPlugin.test.ts.snap | 2 +- .../viteBundleAnalysisPlugin.ts | 23 +++++++++++++++++-- .../webpackBundleAnalysisPlugin.test.ts.snap | 2 +- .../webpackBundleAnalysisPlugin.ts | 18 ++++++++++++--- 7 files changed, 71 insertions(+), 10 deletions(-) create mode 100644 .changeset/stupid-points-vanish.md diff --git a/.changeset/stupid-points-vanish.md b/.changeset/stupid-points-vanish.md new file mode 100644 index 00000000..977003f2 --- /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 +--- + +Collect gzip information in plugins 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..b5b1dd6c 100644 --- a/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts +++ b/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts @@ -6,6 +6,7 @@ import { type BundleAnalysisUploadPlugin, red, normalizePath, + getCompressedSize, } from "@codecov/bundler-plugin-core"; // @ts-expect-error this value is being replaced by rollup @@ -16,7 +17,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 +31,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 === "") { @@ -78,9 +79,15 @@ export const rollupBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ continue; } + const compressedSize = await getCompressedSize({ + fileName, + code: item.source, + }); + assets.push({ name: fileName, size: size, + gzipSize: compressedSize, normalized: normalizePath(fileName, assetFormatString), }); } else { @@ -91,9 +98,15 @@ export const rollupBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ continue; } + const compressedSize = await getCompressedSize({ + fileName, + code: item.source, + }); + assets.push({ name: fileName, size: size, + gzipSize: compressedSize, normalized: normalizePath(fileName, assetFormatString), }); } @@ -110,9 +123,15 @@ export const rollupBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ continue; } + const compressedSize = await getCompressedSize({ + fileName, + code: item.code, + }); + assets.push({ name: fileName, size: size, + gzipSize: compressedSize, normalized: normalizePath(fileName, chunkFormatString), }); 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..c9887fe0 100644 --- a/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts +++ b/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts @@ -6,6 +6,7 @@ import { type Module, type BundleAnalysisUploadPlugin, red, + getCompressedSize, } from "@codecov/bundler-plugin-core"; // @ts-expect-error this value is being replaced by rollup @@ -16,7 +17,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 +31,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 === "") { @@ -79,9 +80,15 @@ export const viteBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ continue; } + const compressedSize = await getCompressedSize({ + fileName, + code: item.source, + }); + assets.push({ name: fileName, size: size, + gzipSize: compressedSize, normalized: normalizePath(fileName, assetFormatString), }); } else { @@ -92,9 +99,15 @@ export const viteBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ continue; } + const compressedSize = await getCompressedSize({ + fileName, + code: item.source, + }); + assets.push({ name: fileName, size: size, + gzipSize: compressedSize, normalized: normalizePath(fileName, assetFormatString), }); } @@ -111,9 +124,15 @@ export const viteBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ continue; } + const compressedSize = await getCompressedSize({ + fileName, + code: item.code, + }); + assets.push({ name: fileName, size: size, + gzipSize: compressedSize, normalized: normalizePath(fileName, chunkFormatString), }); 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..9623b70c 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 === "") { @@ -115,9 +116,20 @@ export const webpackBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ continue; } + const currentAsset = compilation.getAsset(asset.name); + + 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), }); } From b564dc0cce243cc68f63400a876a2976871567b6 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 19 Jun 2024 14:17:48 -0300 Subject: [PATCH 03/14] Update meta-framework plugins to collect version generated in output arg --- .changeset/wise-insects-accept.md | 11 +++++++++++ .../nuxtBundleAnalysisPlugin.test.ts.snap | 2 +- .../nuxt-bundle-analysis/nuxtBundleAnalysisPlugin.ts | 2 +- .../remixBundleAnalysisPlugin.test.ts.snap | 2 +- .../remixBundleAnalysisPlugin.ts | 2 +- .../sveltekitBundleAnalysisPlugin.test.ts.snap | 2 +- .../sveltekitBundleAnalysisPlugin.ts | 2 +- 7 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 .changeset/wise-insects-accept.md 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/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/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: { From ca6d8332c698193367a629a1b2af580d1669bf0d Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 19 Jun 2024 14:18:24 -0300 Subject: [PATCH 04/14] modify changeset name --- .changeset/stupid-points-vanish.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/stupid-points-vanish.md b/.changeset/stupid-points-vanish.md index 977003f2..a80b69ca 100644 --- a/.changeset/stupid-points-vanish.md +++ b/.changeset/stupid-points-vanish.md @@ -8,4 +8,4 @@ "@codecov/vite-plugin": patch --- -Collect gzip information in plugins +Set version from passed output arg, and collect gzip information in plugins From 7049612f093a17c109f61d97b41f05fe28db45f0 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 19 Jun 2024 14:19:27 -0300 Subject: [PATCH 05/14] update meta-framework plugin integration tests to check for gzipSize and build for more output formats --- .../__snapshots__/nuxt-plugin.test.ts.snap | 36 ++-- .../nuxt/nuxt-plugin.test.ts | 2 + .../__snapshots__/remix-plugin.test.ts.snap | 172 +++++++++++++++++- .../remix/remix-plugin.test.ts | 15 +- .../remix/vite-base.config.ts | 7 + .../sveltekit-plugin.test.ts.snap | 88 ++++++++- .../sveltekit/sveltekit-plugin.test.ts | 17 +- 7 files changed, 302 insertions(+), 35 deletions(-) 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/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([ From 182e6836587035257a229d37f79ac5116432159b Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 19 Jun 2024 14:19:43 -0300 Subject: [PATCH 06/14] update base plugin integration test snapshots --- .../__snapshots__/rollup-plugin.test.ts.snap | 60 ++++++++++++------- .../__snapshots__/vite-plugin.test.ts.snap | 60 ++++++++++++------- .../__snapshots__/webpack-plugin.test.ts.snap | 12 ++-- 3 files changed, 88 insertions(+), 44 deletions(-) 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..d01ba54b 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,6 +4,7 @@ exports[`Generating rollup stats 3 {"format":"amd","expected":"amd"} matches the { "assets": [ { + "gzipSize": 98808, "name": "main-1cbfd464.js", "normalized": "main-*.js", "size": 577071, @@ -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,6 +81,7 @@ exports[`Generating rollup stats 3 {"format":"cjs","expected":"cjs"} matches the { "assets": [ { + "gzipSize": 98252, "name": "main-420d8aeb.js", "normalized": "main-*.js", "size": 560886, @@ -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,6 +158,7 @@ exports[`Generating rollup stats 3 {"format":"es","expected":"esm"} matches the { "assets": [ { + "gzipSize": 98243, "name": "main-6ff1e9ca.js", "normalized": "main-*.js", "size": 560871, @@ -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,6 +235,7 @@ exports[`Generating rollup stats 3 {"format":"esm","expected":"esm"} matches the { "assets": [ { + "gzipSize": 98243, "name": "main-6ff1e9ca.js", "normalized": "main-*.js", "size": 560871, @@ -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,6 +312,7 @@ exports[`Generating rollup stats 3 {"format":"module","expected":"esm"} matches { "assets": [ { + "gzipSize": 98243, "name": "main-6ff1e9ca.js", "normalized": "main-*.js", "size": 560871, @@ -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,6 +389,7 @@ exports[`Generating rollup stats 3 {"format":"iife","expected":"iife"} matches t { "assets": [ { + "gzipSize": 98804, "name": "main-cc182ba1.js", "normalized": "main-*.js", "size": 577066, @@ -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,6 +466,7 @@ exports[`Generating rollup stats 3 {"format":"umd","expected":"umd"} matches the { "assets": [ { + "gzipSize": 98845, "name": "main-cdb2522f.js", "normalized": "main-*.js", "size": 577165, @@ -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,6 +543,7 @@ exports[`Generating rollup stats 3 {"format":"system","expected":"system"} match { "assets": [ { + "gzipSize": 99908, "name": "main-b7135d24.js", "normalized": "main-*.js", "size": 609444, @@ -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,6 +620,7 @@ exports[`Generating rollup stats 3 {"format":"systemjs","expected":"system"} mat { "assets": [ { + "gzipSize": 99908, "name": "main-b7135d24.js", "normalized": "main-*.js", "size": 609444, @@ -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,6 +697,7 @@ 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, @@ -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,6 +774,7 @@ 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, @@ -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,6 +851,7 @@ exports[`Generating rollup stats 4 {"format":"cjs","expected":"cjs"} matches the { "assets": [ { + "gzipSize": 98252, "name": "main-MVbZZknk.js", "normalized": "main-*.js", "size": 560886, @@ -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,6 +928,7 @@ exports[`Generating rollup stats 4 {"format":"es","expected":"esm"} matches the { "assets": [ { + "gzipSize": 98243, "name": "main-v-vWaFyT.js", "normalized": "main-*.js", "size": 560871, @@ -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,6 +1005,7 @@ exports[`Generating rollup stats 4 {"format":"esm","expected":"esm"} matches the { "assets": [ { + "gzipSize": 98243, "name": "main-v-vWaFyT.js", "normalized": "main-*.js", "size": 560871, @@ -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,6 +1082,7 @@ exports[`Generating rollup stats 4 {"format":"module","expected":"esm"} matches { "assets": [ { + "gzipSize": 98243, "name": "main-v-vWaFyT.js", "normalized": "main-*.js", "size": 560871, @@ -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,6 +1159,7 @@ exports[`Generating rollup stats 4 {"format":"iife","expected":"iife"} matches t { "assets": [ { + "gzipSize": 98804, "name": "main-ChwnvxRF.js", "normalized": "main-*.js", "size": 577066, @@ -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,6 +1236,7 @@ exports[`Generating rollup stats 4 {"format":"umd","expected":"umd"} matches the { "assets": [ { + "gzipSize": 98845, "name": "main-ymXr0nql.js", "normalized": "main-*.js", "size": 577165, @@ -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,6 +1313,7 @@ exports[`Generating rollup stats 4 {"format":"system","expected":"system"} match { "assets": [ { + "gzipSize": 99908, "name": "main-VyFuBFOR.js", "normalized": "main-*.js", "size": 609444, @@ -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,6 +1390,7 @@ exports[`Generating rollup stats 4 {"format":"systemjs","expected":"system"} mat { "assets": [ { + "gzipSize": 99908, "name": "main-VyFuBFOR.js", "normalized": "main-*.js", "size": 609444, @@ -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,6 +1467,7 @@ 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, @@ -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/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", } `; From b6e56add86461290544a87761a77431408e79138 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Fri, 21 Jun 2024 14:09:18 -0300 Subject: [PATCH 07/14] update webpack plugin to run all promises --- .../webpackBundleAnalysisPlugin.ts | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts b/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts index 9623b70c..97d03f82 100644 --- a/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts +++ b/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts @@ -102,37 +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); - const currentAsset = compilation.getAsset(asset.name); + let compressedSize = null; + if (currentAsset) { + compressedSize = await getCompressedSize({ + fileName: asset.name, + code: currentAsset.source.source(), + }); + } - 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), }); - } - collectedAssets.push({ - name: asset.name, - size: asset.size, - gzipSize: compressedSize, - normalized: normalizePath(asset.name, format), - }); - } + return; + }), + ); output.assets = collectedAssets; } From 90c343725fcd70da83dc1474253be93381127769 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Fri, 21 Jun 2024 14:14:53 -0300 Subject: [PATCH 08/14] add in util function to create assets for vite plugin --- .../__tests__/createAsset.test.ts | 67 +++++++++++++++++++ .../src/vite-bundle-analysis/createAsset.ts | 32 +++++++++ 2 files changed, 99 insertions(+) create mode 100644 packages/vite-plugin/src/vite-bundle-analysis/__tests__/createAsset.test.ts create mode 100644 packages/vite-plugin/src/vite-bundle-analysis/createAsset.ts diff --git a/packages/vite-plugin/src/vite-bundle-analysis/__tests__/createAsset.test.ts b/packages/vite-plugin/src/vite-bundle-analysis/__tests__/createAsset.test.ts new file mode 100644 index 00000000..70697324 --- /dev/null +++ b/packages/vite-plugin/src/vite-bundle-analysis/__tests__/createAsset.test.ts @@ -0,0 +1,67 @@ +import { describe, it, expect } from "vitest"; + +import { createAsset } from "../createAsset"; + +describe("createAsset", () => { + it("sets the asset name", async () => { + const asset = await createAsset({ + 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 createAsset({ + 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 createAsset({ + 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 createAsset({ + 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 createAsset({ + fileName: "test.D4lWaVuy.js", + source: "test", + formatString: "[name].[hash].js", + }); + + expect(asset.size).toBe(4); + }); + + it("sets the gzip size", async () => { + const asset = await createAsset({ + fileName: "test.D4lWaVuy.js", + source: "test", + formatString: "[name].[hash].js", + }); + expect(asset.gzipSize).toBe(24); + }); + }); +}); diff --git a/packages/vite-plugin/src/vite-bundle-analysis/createAsset.ts b/packages/vite-plugin/src/vite-bundle-analysis/createAsset.ts new file mode 100644 index 00000000..108dc91a --- /dev/null +++ b/packages/vite-plugin/src/vite-bundle-analysis/createAsset.ts @@ -0,0 +1,32 @@ +import { getCompressedSize, normalizePath } from "@codecov/bundler-plugin-core"; + +interface CreateAssetOptions { + fileName: string; + source: Uint8Array | string; + formatString: string; +} + +export const createAsset = async ({ + source, + fileName, + formatString, +}: CreateAssetOptions) => { + let size = 0; + if (source instanceof Buffer) { + size = source?.byteLength; + } else { + size = Buffer.from(source).byteLength; + } + + const gzipSize = await getCompressedSize({ + fileName, + code: source, + }); + + return { + name: fileName, + size: size, + gzipSize: gzipSize, + normalized: normalizePath(fileName, formatString), + }; +}; From 7e3ea161c6261642b9e297a8418e78c067e3e32b Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Fri, 21 Jun 2024 14:15:32 -0300 Subject: [PATCH 09/14] update vite plugin to run calculate asset gzip sizes with promise.all and use new createAsset func --- .../viteBundleAnalysisPlugin.ts | 165 +++++++----------- 1 file changed, 67 insertions(+), 98 deletions(-) diff --git a/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts b/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts index c9887fe0..b95acea8 100644 --- a/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts +++ b/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts @@ -1,13 +1,12 @@ import path from "node:path"; import { - normalizePath, type Asset, type Chunk, type Module, type BundleAnalysisUploadPlugin, red, - getCompressedSize, } from "@codecov/bundler-plugin-core"; +import { createAsset } from "./createAsset"; // @ts-expect-error this value is being replaced by rollup const PLUGIN_NAME = __PACKAGE_NAME__ as string; @@ -70,117 +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; } - const compressedSize = await getCompressedSize({ - fileName, - code: item.source, - }); - - assets.push({ - name: fileName, - size: size, - gzipSize: compressedSize, - normalized: normalizePath(fileName, assetFormatString), + const asset = await createAsset({ + 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; } - const compressedSize = await getCompressedSize({ + const asset = await createAsset({ fileName, - code: item.source, + source: item.code, + formatString: chunkFormatString, }); - - assets.push({ - name: fileName, - size: size, - gzipSize: compressedSize, - normalized: normalizePath(fileName, assetFormatString), + 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; - } - const compressedSize = await getCompressedSize({ - fileName, - code: item.code, - }); - - assets.push({ - name: fileName, - size: size, - gzipSize: compressedSize, - 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()); From 54400bb7351b95b225cd5732513244d2c350c12a Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Fri, 21 Jun 2024 14:15:43 -0300 Subject: [PATCH 10/14] add in util function to create assets for rollup plugin --- .../__tests__/createAsset.test.ts | 67 +++++++++++++++++++ .../src/rollup-bundle-analysis/createAsset.ts | 32 +++++++++ 2 files changed, 99 insertions(+) create mode 100644 packages/rollup-plugin/src/rollup-bundle-analysis/__tests__/createAsset.test.ts create mode 100644 packages/rollup-plugin/src/rollup-bundle-analysis/createAsset.ts diff --git a/packages/rollup-plugin/src/rollup-bundle-analysis/__tests__/createAsset.test.ts b/packages/rollup-plugin/src/rollup-bundle-analysis/__tests__/createAsset.test.ts new file mode 100644 index 00000000..70697324 --- /dev/null +++ b/packages/rollup-plugin/src/rollup-bundle-analysis/__tests__/createAsset.test.ts @@ -0,0 +1,67 @@ +import { describe, it, expect } from "vitest"; + +import { createAsset } from "../createAsset"; + +describe("createAsset", () => { + it("sets the asset name", async () => { + const asset = await createAsset({ + 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 createAsset({ + 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 createAsset({ + 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 createAsset({ + 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 createAsset({ + fileName: "test.D4lWaVuy.js", + source: "test", + formatString: "[name].[hash].js", + }); + + expect(asset.size).toBe(4); + }); + + it("sets the gzip size", async () => { + const asset = await createAsset({ + fileName: "test.D4lWaVuy.js", + source: "test", + formatString: "[name].[hash].js", + }); + expect(asset.gzipSize).toBe(24); + }); + }); +}); diff --git a/packages/rollup-plugin/src/rollup-bundle-analysis/createAsset.ts b/packages/rollup-plugin/src/rollup-bundle-analysis/createAsset.ts new file mode 100644 index 00000000..108dc91a --- /dev/null +++ b/packages/rollup-plugin/src/rollup-bundle-analysis/createAsset.ts @@ -0,0 +1,32 @@ +import { getCompressedSize, normalizePath } from "@codecov/bundler-plugin-core"; + +interface CreateAssetOptions { + fileName: string; + source: Uint8Array | string; + formatString: string; +} + +export const createAsset = async ({ + source, + fileName, + formatString, +}: CreateAssetOptions) => { + let size = 0; + if (source instanceof Buffer) { + size = source?.byteLength; + } else { + size = Buffer.from(source).byteLength; + } + + const gzipSize = await getCompressedSize({ + fileName, + code: source, + }); + + return { + name: fileName, + size: size, + gzipSize: gzipSize, + normalized: normalizePath(fileName, formatString), + }; +}; From 7c7c49c84a4c11bd82864684cce9e34f219aa785 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Fri, 21 Jun 2024 14:15:56 -0300 Subject: [PATCH 11/14] update rollup plugin to run calculate asset gzip sizes with promise.all and use new createAsset func --- .../rollupBundleAnalysisPlugin.ts | 164 +++++++----------- 1 file changed, 67 insertions(+), 97 deletions(-) diff --git a/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts b/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts index b5b1dd6c..e83be17d 100644 --- a/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts +++ b/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts @@ -5,9 +5,8 @@ import { type Module, type BundleAnalysisUploadPlugin, red, - normalizePath, - getCompressedSize, } from "@codecov/bundler-plugin-core"; +import { createAsset } from "./createAsset"; // @ts-expect-error this value is being replaced by rollup const PLUGIN_NAME = __PACKAGE_NAME__ as string; @@ -69,116 +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; } - const compressedSize = await getCompressedSize({ - fileName, - code: item.source, - }); - - assets.push({ - name: fileName, - size: size, - gzipSize: compressedSize, - normalized: normalizePath(fileName, assetFormatString), + const asset = await createAsset({ + 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; } - const compressedSize = await getCompressedSize({ + const asset = await createAsset({ fileName, - code: item.source, + source: item.code, + formatString: chunkFormatString, }); - - assets.push({ - name: fileName, - size: size, - gzipSize: compressedSize, - normalized: normalizePath(fileName, assetFormatString), + 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; - } - const compressedSize = await getCompressedSize({ - fileName, - code: item.code, - }); - - assets.push({ - name: fileName, - size: size, - gzipSize: compressedSize, - 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()); From c5fbd519f8b927671c78d81c43bee0d4a403812f Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Mon, 24 Jun 2024 07:29:20 -0300 Subject: [PATCH 12/14] move and rename createRollupAssets to bundler core --- packages/bundler-plugin-core/src/index.ts | 17 +++-- .../__tests__/createRollupAsset.test.ts} | 16 ++--- .../src/utils/createRollupAsset.ts} | 15 ++--- .../bundler-plugin-core/src/utils/index.ts | 7 ++ .../__tests__/createAsset.test.ts | 67 ------------------- .../src/vite-bundle-analysis/createAsset.ts | 32 --------- 6 files changed, 33 insertions(+), 121 deletions(-) rename packages/{rollup-plugin/src/rollup-bundle-analysis/__tests__/createAsset.test.ts => bundler-plugin-core/src/utils/__tests__/createRollupAsset.test.ts} (79%) rename packages/{rollup-plugin/src/rollup-bundle-analysis/createAsset.ts => bundler-plugin-core/src/utils/createRollupAsset.ts} (59%) create mode 100644 packages/bundler-plugin-core/src/utils/index.ts delete mode 100644 packages/vite-plugin/src/vite-bundle-analysis/__tests__/createAsset.test.ts delete mode 100644 packages/vite-plugin/src/vite-bundle-analysis/createAsset.ts diff --git a/packages/bundler-plugin-core/src/index.ts b/packages/bundler-plugin-core/src/index.ts index c5b7a6ca..d6f1e489 100644 --- a/packages/bundler-plugin-core/src/index.ts +++ b/packages/bundler-plugin-core/src/index.ts @@ -7,12 +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 { getCompressedSize } from "./utils/getCompressedSize.ts"; +import { + checkNodeVersion, + createRollupAsset, + getCompressedSize, + handleErrors, + normalizeOptions, + normalizePath, + Output, + red, +} from "./utils"; export type { Asset, @@ -26,6 +30,7 @@ export type { export { checkNodeVersion, + createRollupAsset, handleErrors, getCompressedSize, normalizeOptions, diff --git a/packages/rollup-plugin/src/rollup-bundle-analysis/__tests__/createAsset.test.ts b/packages/bundler-plugin-core/src/utils/__tests__/createRollupAsset.test.ts similarity index 79% rename from packages/rollup-plugin/src/rollup-bundle-analysis/__tests__/createAsset.test.ts rename to packages/bundler-plugin-core/src/utils/__tests__/createRollupAsset.test.ts index 70697324..4ce6773e 100644 --- a/packages/rollup-plugin/src/rollup-bundle-analysis/__tests__/createAsset.test.ts +++ b/packages/bundler-plugin-core/src/utils/__tests__/createRollupAsset.test.ts @@ -1,10 +1,10 @@ import { describe, it, expect } from "vitest"; -import { createAsset } from "../createAsset"; +import { createRollupAsset } from "../createRollupAsset"; -describe("createAsset", () => { +describe("createRollupAsset", () => { it("sets the asset name", async () => { - const asset = await createAsset({ + const asset = await createRollupAsset({ fileName: "test.D4lWaVuy.js", source: Buffer.from("test"), formatString: "[name].[hash].js", @@ -14,7 +14,7 @@ describe("createAsset", () => { }); it("sets the normalized name", async () => { - const asset = await createAsset({ + const asset = await createRollupAsset({ fileName: "test.D4lWaVuy.js", source: Buffer.from("test"), formatString: "[name].[hash].js", @@ -25,7 +25,7 @@ describe("createAsset", () => { describe("when the source is a Buffer", () => { it("sets the size", async () => { - const asset = await createAsset({ + const asset = await createRollupAsset({ fileName: "test.D4lWaVuy.js", source: Buffer.from("test"), formatString: "[name].[hash].js", @@ -35,7 +35,7 @@ describe("createAsset", () => { }); it("sets the gzip size", async () => { - const asset = await createAsset({ + const asset = await createRollupAsset({ fileName: "test.D4lWaVuy.js", source: Buffer.from("test"), formatString: "[name].[hash].js", @@ -46,7 +46,7 @@ describe("createAsset", () => { describe("when the source is a string", () => { it("sets the size", async () => { - const asset = await createAsset({ + const asset = await createRollupAsset({ fileName: "test.D4lWaVuy.js", source: "test", formatString: "[name].[hash].js", @@ -56,7 +56,7 @@ describe("createAsset", () => { }); it("sets the gzip size", async () => { - const asset = await createAsset({ + const asset = await createRollupAsset({ fileName: "test.D4lWaVuy.js", source: "test", formatString: "[name].[hash].js", diff --git a/packages/rollup-plugin/src/rollup-bundle-analysis/createAsset.ts b/packages/bundler-plugin-core/src/utils/createRollupAsset.ts similarity index 59% rename from packages/rollup-plugin/src/rollup-bundle-analysis/createAsset.ts rename to packages/bundler-plugin-core/src/utils/createRollupAsset.ts index 108dc91a..740c42e3 100644 --- a/packages/rollup-plugin/src/rollup-bundle-analysis/createAsset.ts +++ b/packages/bundler-plugin-core/src/utils/createRollupAsset.ts @@ -1,4 +1,5 @@ -import { getCompressedSize, normalizePath } from "@codecov/bundler-plugin-core"; +import { getCompressedSize } from "./getCompressedSize.ts"; +import { normalizePath } from "./normalizePath.ts"; interface CreateAssetOptions { fileName: string; @@ -6,17 +7,15 @@ interface CreateAssetOptions { formatString: string; } -export const createAsset = async ({ +export const createRollupAsset = async ({ source, fileName, formatString, }: CreateAssetOptions) => { - let size = 0; - if (source instanceof Buffer) { - size = source?.byteLength; - } else { - size = Buffer.from(source).byteLength; - } + const size = + source instanceof Buffer + ? source.byteLength + : Buffer.from(source).byteLength; const gzipSize = await getCompressedSize({ fileName, 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/vite-plugin/src/vite-bundle-analysis/__tests__/createAsset.test.ts b/packages/vite-plugin/src/vite-bundle-analysis/__tests__/createAsset.test.ts deleted file mode 100644 index 70697324..00000000 --- a/packages/vite-plugin/src/vite-bundle-analysis/__tests__/createAsset.test.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { describe, it, expect } from "vitest"; - -import { createAsset } from "../createAsset"; - -describe("createAsset", () => { - it("sets the asset name", async () => { - const asset = await createAsset({ - 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 createAsset({ - 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 createAsset({ - 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 createAsset({ - 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 createAsset({ - fileName: "test.D4lWaVuy.js", - source: "test", - formatString: "[name].[hash].js", - }); - - expect(asset.size).toBe(4); - }); - - it("sets the gzip size", async () => { - const asset = await createAsset({ - fileName: "test.D4lWaVuy.js", - source: "test", - formatString: "[name].[hash].js", - }); - expect(asset.gzipSize).toBe(24); - }); - }); -}); diff --git a/packages/vite-plugin/src/vite-bundle-analysis/createAsset.ts b/packages/vite-plugin/src/vite-bundle-analysis/createAsset.ts deleted file mode 100644 index 108dc91a..00000000 --- a/packages/vite-plugin/src/vite-bundle-analysis/createAsset.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { getCompressedSize, normalizePath } from "@codecov/bundler-plugin-core"; - -interface CreateAssetOptions { - fileName: string; - source: Uint8Array | string; - formatString: string; -} - -export const createAsset = async ({ - source, - fileName, - formatString, -}: CreateAssetOptions) => { - let size = 0; - if (source instanceof Buffer) { - size = source?.byteLength; - } else { - size = Buffer.from(source).byteLength; - } - - const gzipSize = await getCompressedSize({ - fileName, - code: source, - }); - - return { - name: fileName, - size: size, - gzipSize: gzipSize, - normalized: normalizePath(fileName, formatString), - }; -}; From d8ff5e3628daa74203c5d2b1a60d4a323fb4e0e5 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Mon, 24 Jun 2024 07:29:38 -0300 Subject: [PATCH 13/14] update rollup and vite plugins to import createRollupAsset from core --- .../rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts | 6 +++--- .../src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts b/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts index e83be17d..061ed048 100644 --- a/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts +++ b/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts @@ -5,8 +5,8 @@ import { type Module, type BundleAnalysisUploadPlugin, red, + createRollupAsset, } from "@codecov/bundler-plugin-core"; -import { createAsset } from "./createAsset"; // @ts-expect-error this value is being replaced by rollup const PLUGIN_NAME = __PACKAGE_NAME__ as string; @@ -76,7 +76,7 @@ export const rollupBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ return; } - const asset = await createAsset({ + const asset = await createRollupAsset({ fileName: fileName, source: item.source, formatString: assetFormatString, @@ -88,7 +88,7 @@ export const rollupBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ return; } - const asset = await createAsset({ + const asset = await createRollupAsset({ fileName, source: item.code, formatString: chunkFormatString, diff --git a/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts b/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts index b95acea8..8d53ecdc 100644 --- a/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts +++ b/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts @@ -5,8 +5,8 @@ import { type Module, type BundleAnalysisUploadPlugin, red, + createRollupAsset, } from "@codecov/bundler-plugin-core"; -import { createAsset } from "./createAsset"; // @ts-expect-error this value is being replaced by rollup const PLUGIN_NAME = __PACKAGE_NAME__ as string; @@ -77,7 +77,7 @@ export const viteBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ return; } - const asset = await createAsset({ + const asset = await createRollupAsset({ fileName: fileName, source: item.source, formatString: assetFormatString, @@ -89,7 +89,7 @@ export const viteBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ return; } - const asset = await createAsset({ + const asset = await createRollupAsset({ fileName, source: item.code, formatString: chunkFormatString, From 15080633626cafcb92691ce0b8b4a01e27ed3968 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Mon, 24 Jun 2024 07:29:49 -0300 Subject: [PATCH 14/14] update rollup snapshots --- .../__snapshots__/rollup-plugin.test.ts.snap | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) 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 d01ba54b..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 @@ -7,7 +7,7 @@ exports[`Generating rollup stats 3 {"format":"amd","expected":"amd"} matches the "gzipSize": 98808, "name": "main-1cbfd464.js", "normalized": "main-*.js", - "size": 577071, + "size": 577073, }, ], "builtAt": Any, @@ -84,7 +84,7 @@ exports[`Generating rollup stats 3 {"format":"cjs","expected":"cjs"} matches the "gzipSize": 98252, "name": "main-420d8aeb.js", "normalized": "main-*.js", - "size": 560886, + "size": 560888, }, ], "builtAt": Any, @@ -161,7 +161,7 @@ exports[`Generating rollup stats 3 {"format":"es","expected":"esm"} matches the "gzipSize": 98243, "name": "main-6ff1e9ca.js", "normalized": "main-*.js", - "size": 560871, + "size": 560873, }, ], "builtAt": Any, @@ -238,7 +238,7 @@ exports[`Generating rollup stats 3 {"format":"esm","expected":"esm"} matches the "gzipSize": 98243, "name": "main-6ff1e9ca.js", "normalized": "main-*.js", - "size": 560871, + "size": 560873, }, ], "builtAt": Any, @@ -315,7 +315,7 @@ exports[`Generating rollup stats 3 {"format":"module","expected":"esm"} matches "gzipSize": 98243, "name": "main-6ff1e9ca.js", "normalized": "main-*.js", - "size": 560871, + "size": 560873, }, ], "builtAt": Any, @@ -392,7 +392,7 @@ exports[`Generating rollup stats 3 {"format":"iife","expected":"iife"} matches t "gzipSize": 98804, "name": "main-cc182ba1.js", "normalized": "main-*.js", - "size": 577066, + "size": 577068, }, ], "builtAt": Any, @@ -469,7 +469,7 @@ exports[`Generating rollup stats 3 {"format":"umd","expected":"umd"} matches the "gzipSize": 98845, "name": "main-cdb2522f.js", "normalized": "main-*.js", - "size": 577165, + "size": 577167, }, ], "builtAt": Any, @@ -546,7 +546,7 @@ exports[`Generating rollup stats 3 {"format":"system","expected":"system"} match "gzipSize": 99908, "name": "main-b7135d24.js", "normalized": "main-*.js", - "size": 609444, + "size": 609446, }, ], "builtAt": Any, @@ -623,7 +623,7 @@ exports[`Generating rollup stats 3 {"format":"systemjs","expected":"system"} mat "gzipSize": 99908, "name": "main-b7135d24.js", "normalized": "main-*.js", - "size": 609444, + "size": 609446, }, ], "builtAt": Any, @@ -700,7 +700,7 @@ exports[`Generating rollup stats 3 source maps are enabled does not include any "gzipSize": 98275, "name": "main-6ff1e9ca.js", "normalized": "main-*.js", - "size": 560913, + "size": 560915, }, ], "builtAt": Any, @@ -777,7 +777,7 @@ exports[`Generating rollup stats 4 {"format":"amd","expected":"amd"} matches the "gzipSize": 98808, "name": "main-H2_1FSsQ.js", "normalized": "main-H2_1FSsQ.js", - "size": 577071, + "size": 577073, }, ], "builtAt": Any, @@ -854,7 +854,7 @@ exports[`Generating rollup stats 4 {"format":"cjs","expected":"cjs"} matches the "gzipSize": 98252, "name": "main-MVbZZknk.js", "normalized": "main-*.js", - "size": 560886, + "size": 560888, }, ], "builtAt": Any, @@ -931,7 +931,7 @@ exports[`Generating rollup stats 4 {"format":"es","expected":"esm"} matches the "gzipSize": 98243, "name": "main-v-vWaFyT.js", "normalized": "main-*.js", - "size": 560871, + "size": 560873, }, ], "builtAt": Any, @@ -1008,7 +1008,7 @@ exports[`Generating rollup stats 4 {"format":"esm","expected":"esm"} matches the "gzipSize": 98243, "name": "main-v-vWaFyT.js", "normalized": "main-*.js", - "size": 560871, + "size": 560873, }, ], "builtAt": Any, @@ -1085,7 +1085,7 @@ exports[`Generating rollup stats 4 {"format":"module","expected":"esm"} matches "gzipSize": 98243, "name": "main-v-vWaFyT.js", "normalized": "main-*.js", - "size": 560871, + "size": 560873, }, ], "builtAt": Any, @@ -1162,7 +1162,7 @@ exports[`Generating rollup stats 4 {"format":"iife","expected":"iife"} matches t "gzipSize": 98804, "name": "main-ChwnvxRF.js", "normalized": "main-*.js", - "size": 577066, + "size": 577068, }, ], "builtAt": Any, @@ -1239,7 +1239,7 @@ exports[`Generating rollup stats 4 {"format":"umd","expected":"umd"} matches the "gzipSize": 98845, "name": "main-ymXr0nql.js", "normalized": "main-*.js", - "size": 577165, + "size": 577167, }, ], "builtAt": Any, @@ -1316,7 +1316,7 @@ exports[`Generating rollup stats 4 {"format":"system","expected":"system"} match "gzipSize": 99908, "name": "main-VyFuBFOR.js", "normalized": "main-*.js", - "size": 609444, + "size": 609446, }, ], "builtAt": Any, @@ -1393,7 +1393,7 @@ exports[`Generating rollup stats 4 {"format":"systemjs","expected":"system"} mat "gzipSize": 99908, "name": "main-VyFuBFOR.js", "normalized": "main-*.js", - "size": 609444, + "size": 609446, }, ], "builtAt": Any, @@ -1470,7 +1470,7 @@ exports[`Generating rollup stats 4 source maps are enabled does not include any "gzipSize": 98277, "name": "main-v-vWaFyT.js", "normalized": "main-*.js", - "size": 560913, + "size": 560915, }, ], "builtAt": Any,