From 4b1474e2098e4dd1ca1bcecd1bbf6c6d5f29e492 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 13 Dec 2023 14:33:19 -0500 Subject: [PATCH 1/9] add bundle name config option to bundler core --- .../__tests__/bundleAnalysisPluginFactory.test.ts | 6 +++--- .../src/bundle-analysis/bundleAnalysisPluginFactory.ts | 9 ++++++++- packages/bundler-plugin-core/src/types.ts | 8 ++++++++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/bundler-plugin-core/src/bundle-analysis/__tests__/bundleAnalysisPluginFactory.test.ts b/packages/bundler-plugin-core/src/bundle-analysis/__tests__/bundleAnalysisPluginFactory.test.ts index 8bf70d2a..4d2474b7 100644 --- a/packages/bundler-plugin-core/src/bundle-analysis/__tests__/bundleAnalysisPluginFactory.test.ts +++ b/packages/bundler-plugin-core/src/bundle-analysis/__tests__/bundleAnalysisPluginFactory.test.ts @@ -3,7 +3,7 @@ import { bundleAnalysisPluginFactory } from "../bundleAnalysisPluginFactory"; describe("bundleAnalysisPluginFactory", () => { it("returns a build start function", () => { const plugin = bundleAnalysisPluginFactory({ - userOptions: {}, + userOptions: { bundleName: "test" }, bundleAnalysisUploadPlugin: () => ({ version: "1", name: "plugin-name", @@ -16,7 +16,7 @@ describe("bundleAnalysisPluginFactory", () => { it("returns a build end function", () => { const plugin = bundleAnalysisPluginFactory({ - userOptions: {}, + userOptions: { bundleName: "test" }, bundleAnalysisUploadPlugin: () => ({ version: "1", name: "plugin-name", @@ -29,7 +29,7 @@ describe("bundleAnalysisPluginFactory", () => { it("returns a write bundle function", () => { const plugin = bundleAnalysisPluginFactory({ - userOptions: {}, + userOptions: { bundleName: "test" }, bundleAnalysisUploadPlugin: () => ({ version: "1", name: "plugin-name", diff --git a/packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts b/packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts index eb5dff2c..598a5d4b 100644 --- a/packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts +++ b/packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts @@ -9,6 +9,7 @@ import { import { type UnpluginOptions } from "unplugin"; import { getPreSignedURL } from "../utils/getPreSignedURL.ts"; import { uploadStats } from "../utils/uploadStats.ts"; +import { red } from "../utils/logging.ts"; interface BundleAnalysisUploadPluginArgs { userOptions: Options; @@ -19,9 +20,9 @@ export const bundleAnalysisPluginFactory = ({ userOptions, bundleAnalysisUploadPlugin, }: BundleAnalysisUploadPluginArgs): UnpluginOptions => { - // const dryRun = userOptions?.dryRun ?? false; const output: Output = { version: "1", + bundleName: userOptions.bundleName ?? "", }; const { pluginVersion, version, ...pluginOpts } = bundleAnalysisUploadPlugin({ @@ -47,6 +48,12 @@ export const bundleAnalysisPluginFactory = ({ // don't need to do anything here if dryRun is true if (userOptions?.dryRun) return; + // don't need to do anything if the bundle name is not present or empty + if (!userOptions.bundleName || userOptions.bundleName === "") { + red("Bundle name is not present or empty."); + return; + } + const args: UploadOverrides = userOptions.uploaderOverrides ?? {}; const envs = process.env; const inputs: ProviderUtilInputs = { envs, args }; diff --git a/packages/bundler-plugin-core/src/types.ts b/packages/bundler-plugin-core/src/types.ts index a369977e..8c1ec4ff 100644 --- a/packages/bundler-plugin-core/src/types.ts +++ b/packages/bundler-plugin-core/src/types.ts @@ -28,6 +28,7 @@ export interface Module { export interface Output { version?: string; + bundleName: string; bundler?: { name: string; version: string; @@ -92,6 +93,13 @@ export interface Options { * Defaults to `false` */ dryRun?: boolean; + + /** + * The name for the bundle being built. + * + * Example: `rollup-package` + */ + bundleName: string; } export type BundleAnalysisUploadPlugin = ( From 26098f0908832eea953da3a8dcc81532b8309ef0 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 13 Dec 2023 14:33:35 -0500 Subject: [PATCH 2/9] update unit tests --- .../__tests__/rollupBundleAnalysisPlugin.test.ts | 8 ++++++-- .../__tests__/viteBundleAnalysisPlugin.test.ts | 8 ++++++-- .../__tests__/webpackBundleAnalysisPlugin.test.ts | 8 ++++++-- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/rollup-plugin/src/rollup-bundle-analysis/__tests__/rollupBundleAnalysisPlugin.test.ts b/packages/rollup-plugin/src/rollup-bundle-analysis/__tests__/rollupBundleAnalysisPlugin.test.ts index b746299b..c2ac3b5c 100644 --- a/packages/rollup-plugin/src/rollup-bundle-analysis/__tests__/rollupBundleAnalysisPlugin.test.ts +++ b/packages/rollup-plugin/src/rollup-bundle-analysis/__tests__/rollupBundleAnalysisPlugin.test.ts @@ -4,8 +4,12 @@ describe("rollupBundleAnalysisPlugin", () => { describe("when called", () => { it("returns a plugin object", () => { const plugin = rollupBundleAnalysisPlugin({ - output: {}, - userOptions: {}, + output: { + bundleName: "test", + }, + userOptions: { + bundleName: "test", + }, }); expect(plugin.version).toEqual("1"); diff --git a/packages/vite-plugin/src/vite-bundle-analysis/__tests__/viteBundleAnalysisPlugin.test.ts b/packages/vite-plugin/src/vite-bundle-analysis/__tests__/viteBundleAnalysisPlugin.test.ts index 4331948d..1590ec34 100644 --- a/packages/vite-plugin/src/vite-bundle-analysis/__tests__/viteBundleAnalysisPlugin.test.ts +++ b/packages/vite-plugin/src/vite-bundle-analysis/__tests__/viteBundleAnalysisPlugin.test.ts @@ -4,8 +4,12 @@ describe("viteBundleAnalysisPlugin", () => { describe("when called", () => { it("returns a plugin object", () => { const plugin = viteBundleAnalysisPlugin({ - output: {}, - userOptions: {}, + output: { + bundleName: "test", + }, + userOptions: { + bundleName: "test", + }, }); expect(plugin.version).toEqual("1"); diff --git a/packages/webpack-plugin/src/webpack-bundle-analysis/__tests__/webpackBundleAnalysisPlugin.test.ts b/packages/webpack-plugin/src/webpack-bundle-analysis/__tests__/webpackBundleAnalysisPlugin.test.ts index 06d2118a..619a6d83 100644 --- a/packages/webpack-plugin/src/webpack-bundle-analysis/__tests__/webpackBundleAnalysisPlugin.test.ts +++ b/packages/webpack-plugin/src/webpack-bundle-analysis/__tests__/webpackBundleAnalysisPlugin.test.ts @@ -4,8 +4,12 @@ describe("webpackBundleAnalysisPlugin", () => { describe("when called", () => { it("returns a plugin object", () => { const plugin = webpackBundleAnalysisPlugin({ - output: {}, - userOptions: {}, + output: { + bundleName: "test", + }, + userOptions: { + bundleName: "test", + }, }); expect(plugin.version).toEqual("1"); From ccd55ed33dde3fb984b2165ef72441175a80a38c Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 13 Dec 2023 14:33:53 -0500 Subject: [PATCH 3/9] update integration tests --- .../generate-bundle-stats/rollup-plugin.test.ts | 10 +++++++++- .../fixtures/generate-bundle-stats/vite-plugin.test.ts | 10 +++++++++- .../generate-bundle-stats/webpack-plugin.test.ts | 10 +++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/integration-tests/fixtures/generate-bundle-stats/rollup-plugin.test.ts b/integration-tests/fixtures/generate-bundle-stats/rollup-plugin.test.ts index fdc074d4..446be5d6 100644 --- a/integration-tests/fixtures/generate-bundle-stats/rollup-plugin.test.ts +++ b/integration-tests/fixtures/generate-bundle-stats/rollup-plugin.test.ts @@ -52,7 +52,11 @@ describe("Generating rollup stats", () => { // eslint-disable-next-line @typescript-eslint/no-unsafe-call resolve(), commonjs(), - codecovRollupPlugin({ enableBundleAnalysis: true, dryRun: true }), + codecovRollupPlugin({ + enableBundleAnalysis: true, + dryRun: true, + bundleName: "rollup-test", + }), ], }).then((bundle) => bundle.write({ @@ -89,4 +93,8 @@ describe("Generating rollup stats", () => { it("sets the correct bundler information", () => { expect(stats.bundler).toStrictEqual(expectedStats.bundler); }); + + it("sets the correct bundle name", () => { + expect(stats.bundleName).toStrictEqual("rollup-test"); + }); }); diff --git a/integration-tests/fixtures/generate-bundle-stats/vite-plugin.test.ts b/integration-tests/fixtures/generate-bundle-stats/vite-plugin.test.ts index 49960a10..69f60d55 100644 --- a/integration-tests/fixtures/generate-bundle-stats/vite-plugin.test.ts +++ b/integration-tests/fixtures/generate-bundle-stats/vite-plugin.test.ts @@ -56,7 +56,11 @@ describe("Generating vite stats", () => { }, }, plugins: [ - codecovVitePlugin({ enableBundleAnalysis: true, dryRun: true }), + codecovVitePlugin({ + enableBundleAnalysis: true, + dryRun: true, + bundleName: "vite-test", + }), ], }); @@ -88,4 +92,8 @@ describe("Generating vite stats", () => { it("sets the correct bundler information", () => { expect(stats.bundler).toStrictEqual(expectedStats.bundler); }); + + it("sets the correct bundle name", () => { + expect(stats.bundleName).toStrictEqual("vite-test"); + }); }); diff --git a/integration-tests/fixtures/generate-bundle-stats/webpack-plugin.test.ts b/integration-tests/fixtures/generate-bundle-stats/webpack-plugin.test.ts index 76c94873..92206862 100644 --- a/integration-tests/fixtures/generate-bundle-stats/webpack-plugin.test.ts +++ b/integration-tests/fixtures/generate-bundle-stats/webpack-plugin.test.ts @@ -54,7 +54,11 @@ describe("Generating webpack stats", () => { }, mode: "production", plugins: [ - codecovWebpackPlugin({ enableBundleAnalysis: true, dryRun: true }), + codecovWebpackPlugin({ + enableBundleAnalysis: true, + dryRun: true, + bundleName: "webpack-test", + }), ], }, (err) => { @@ -95,4 +99,8 @@ describe("Generating webpack stats", () => { it("sets the correct bundler information", () => { expect(stats.bundler).toStrictEqual(expectedStats.bundler); }); + + it("sets the correct bundle name", () => { + expect(stats.bundleName).toStrictEqual("webpack-test"); + }); }); From f37a830a4bf90d33018ba753c3a3778244f2b77e Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 13 Dec 2023 14:50:04 -0500 Subject: [PATCH 4/9] make bundle name optional for future incase we expand our plugins --- .../src/bundle-analysis/bundleAnalysisPluginFactory.ts | 7 ------- packages/bundler-plugin-core/src/index.ts | 4 +++- packages/bundler-plugin-core/src/types.ts | 4 +++- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts b/packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts index 598a5d4b..7e70187b 100644 --- a/packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts +++ b/packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts @@ -9,7 +9,6 @@ import { import { type UnpluginOptions } from "unplugin"; import { getPreSignedURL } from "../utils/getPreSignedURL.ts"; import { uploadStats } from "../utils/uploadStats.ts"; -import { red } from "../utils/logging.ts"; interface BundleAnalysisUploadPluginArgs { userOptions: Options; @@ -48,12 +47,6 @@ export const bundleAnalysisPluginFactory = ({ // don't need to do anything here if dryRun is true if (userOptions?.dryRun) return; - // don't need to do anything if the bundle name is not present or empty - if (!userOptions.bundleName || userOptions.bundleName === "") { - red("Bundle name is not present or empty."); - return; - } - const args: UploadOverrides = userOptions.uploaderOverrides ?? {}; const envs = process.env; const inputs: ProviderUtilInputs = { envs, args }; diff --git a/packages/bundler-plugin-core/src/index.ts b/packages/bundler-plugin-core/src/index.ts index 120b7525..56415ab8 100644 --- a/packages/bundler-plugin-core/src/index.ts +++ b/packages/bundler-plugin-core/src/index.ts @@ -21,7 +21,7 @@ interface CodecovUnpluginFactoryOptions { bundleAnalysisUploadPlugin: BundleAnalysisUploadPlugin; } -export function codecovUnpluginFactory({ +function codecovUnpluginFactory({ bundleAnalysisUploadPlugin, }: CodecovUnpluginFactoryOptions) { return createUnplugin((userOptions, unpluginMetaContext) => { @@ -48,6 +48,8 @@ export function codecovUnpluginFactory({ }); } +export { red, codecovUnpluginFactory }; + export type { BundleAnalysisUploadPlugin, Asset, diff --git a/packages/bundler-plugin-core/src/types.ts b/packages/bundler-plugin-core/src/types.ts index 8c1ec4ff..e3e005e1 100644 --- a/packages/bundler-plugin-core/src/types.ts +++ b/packages/bundler-plugin-core/src/types.ts @@ -97,9 +97,11 @@ export interface Options { /** * The name for the bundle being built. * + * Required for uploading bundle analysis information. + * * Example: `rollup-package` */ - bundleName: string; + bundleName?: string; } export type BundleAnalysisUploadPlugin = ( From df6652bcab1f0d6654e5d9f796485dbbc593df98 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 13 Dec 2023 14:51:08 -0500 Subject: [PATCH 5/9] early return so we don't attempt to upload --- .../src/bundle-analysis/bundleAnalysisPluginFactory.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts b/packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts index 7e70187b..5d9880b8 100644 --- a/packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts +++ b/packages/bundler-plugin-core/src/bundle-analysis/bundleAnalysisPluginFactory.ts @@ -47,6 +47,9 @@ export const bundleAnalysisPluginFactory = ({ // don't need to do anything here if dryRun is true if (userOptions?.dryRun) return; + // don't need to do anything if the bundle name is not present or empty + if (!userOptions.bundleName || userOptions.bundleName === "") return; + const args: UploadOverrides = userOptions.uploaderOverrides ?? {}; const envs = process.env; const inputs: ProviderUtilInputs = { envs, args }; From 2da2a1904186fdda630a1aeb6fe50ef5be2caea2 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Wed, 13 Dec 2023 14:51:30 -0500 Subject: [PATCH 6/9] emit warning from the various bundler plugins --- .../rollupBundleAnalysisPlugin.ts | 7 +++++++ .../vite-bundle-analysis/viteBundleAnalysisPlugin.ts | 7 +++++++ .../webpackBundleAnalysisPlugin.ts | 11 ++++++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts b/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts index ab4eef48..ac674344 100644 --- a/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts +++ b/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts @@ -4,6 +4,7 @@ import { type Chunk, type Module, type BundleAnalysisUploadPlugin, + red, } from "@codecov/bundler-plugin-core"; const PLUGIN_NAME = "codecov-rollup-bundle-analysis-plugin"; @@ -17,6 +18,12 @@ export const rollupBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ pluginVersion: "1.0.0", rollup: { generateBundle(this, options, bundle) { + // don't need to do anything if the bundle name is not present or empty + if (!userOptions.bundleName || userOptions.bundleName === "") { + red("Bundle name is not present or empty. Skipping upload."); + return; + } + const customOptions = { moduleOriginalSize: false, ...options, diff --git a/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts b/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts index f26d102d..6a972f8f 100644 --- a/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts +++ b/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts @@ -4,6 +4,7 @@ import { type Chunk, type Module, type BundleAnalysisUploadPlugin, + red, } from "@codecov/bundler-plugin-core"; const PLUGIN_NAME = "codecov-vite-bundle-analysis-plugin"; @@ -17,6 +18,12 @@ export const viteBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ pluginVersion: "1.0.0", vite: { generateBundle(this, options, bundle) { + // don't need to do anything if the bundle name is not present or empty + if (!userOptions.bundleName || userOptions.bundleName === "") { + red("Bundle name is not present or empty. Skipping upload."); + return; + } + const customOptions = { moduleOriginalSize: false, ...options, diff --git a/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts b/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts index f529f8ca..f74841ef 100644 --- a/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts +++ b/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts @@ -1,4 +1,7 @@ -import { type BundleAnalysisUploadPlugin } from "@codecov/bundler-plugin-core"; +import { + type BundleAnalysisUploadPlugin, + red, +} from "@codecov/bundler-plugin-core"; import * as webpack4or5 from "webpack"; const PLUGIN_NAME = "codecov-webpack-bundle-analysis-plugin"; @@ -18,6 +21,12 @@ export const webpackBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ stage: webpack4or5.Compilation.PROCESS_ASSETS_STAGE_REPORT, }, () => { + // don't need to do anything if the bundle name is not present or empty + if (!userOptions.bundleName || userOptions.bundleName === "") { + red("Bundle name is not present or empty. Skipping upload."); + return; + } + const compilationStats = compilation.getStats().toJson({ assets: true, chunks: true, From acba306aa1cca540e3fe96c9b8547a2f8af49db8 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 14 Dec 2023 12:18:50 -0500 Subject: [PATCH 7/9] append bundler name option if present --- .../src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts | 4 ++++ .../src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts | 4 ++++ .../webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts | 4 ++++ 3 files changed, 12 insertions(+) diff --git a/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts b/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts index ac674344..9f5fc805 100644 --- a/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts +++ b/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts @@ -24,6 +24,10 @@ export const rollupBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ return; } + if (options.name && options.name !== "") { + output.bundleName = `${userOptions.bundleName}-${options.name}`; + } + const customOptions = { moduleOriginalSize: false, ...options, diff --git a/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts b/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts index 6a972f8f..7c241389 100644 --- a/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts +++ b/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts @@ -24,6 +24,10 @@ export const viteBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ return; } + if (options.name && options.name !== "") { + output.bundleName = `${userOptions.bundleName}-${options.name}`; + } + const customOptions = { moduleOriginalSize: false, ...options, diff --git a/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts b/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts index f74841ef..66dc10e0 100644 --- a/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts +++ b/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts @@ -27,6 +27,10 @@ export const webpackBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ return; } + if (compilation.name && compilation.name !== "") { + output.bundleName = `${userOptions.bundleName}-${compilation.name}`; + } + const compilationStats = compilation.getStats().toJson({ assets: true, chunks: true, From 4f9e05bae7eeb814543201b58006ff41be6cd947 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 14 Dec 2023 12:32:35 -0500 Subject: [PATCH 8/9] append output format to bundle name --- .../src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts | 3 +++ .../src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts | 4 ++++ .../webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts b/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts index 9f5fc805..4e9a351b 100644 --- a/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts +++ b/packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts @@ -24,6 +24,9 @@ export const rollupBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ return; } + // append bundle output format to bundle name + output.bundleName = `${userOptions.bundleName}-${options.format}`; + if (options.name && options.name !== "") { output.bundleName = `${userOptions.bundleName}-${options.name}`; } diff --git a/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts b/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts index 7c241389..f5ac4d6a 100644 --- a/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts +++ b/packages/vite-plugin/src/vite-bundle-analysis/viteBundleAnalysisPlugin.ts @@ -24,6 +24,10 @@ export const viteBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ return; } + // append bundle output format to bundle name + output.bundleName = `${userOptions.bundleName}-${options.format}`; + + // add in bundle name if present if (options.name && options.name !== "") { output.bundleName = `${userOptions.bundleName}-${options.name}`; } diff --git a/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts b/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts index 66dc10e0..7ce1c4c1 100644 --- a/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts +++ b/packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts @@ -27,6 +27,10 @@ export const webpackBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({ return; } + if (typeof compilation.outputOptions.chunkFormat === "string") { + output.bundleName = `${userOptions.bundleName}-${compilation.outputOptions.chunkFormat}`; + } + if (compilation.name && compilation.name !== "") { output.bundleName = `${userOptions.bundleName}-${compilation.name}`; } From 92ae7b46b00dc571cc51e7806557a7bfd3dbbd37 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Thu, 14 Dec 2023 12:32:57 -0500 Subject: [PATCH 9/9] update integration tests --- .../fixtures/generate-bundle-stats/rollup-plugin.test.ts | 2 +- .../fixtures/generate-bundle-stats/vite-plugin.test.ts | 2 +- .../fixtures/generate-bundle-stats/webpack-plugin.test.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/integration-tests/fixtures/generate-bundle-stats/rollup-plugin.test.ts b/integration-tests/fixtures/generate-bundle-stats/rollup-plugin.test.ts index 446be5d6..0a970927 100644 --- a/integration-tests/fixtures/generate-bundle-stats/rollup-plugin.test.ts +++ b/integration-tests/fixtures/generate-bundle-stats/rollup-plugin.test.ts @@ -95,6 +95,6 @@ describe("Generating rollup stats", () => { }); it("sets the correct bundle name", () => { - expect(stats.bundleName).toStrictEqual("rollup-test"); + expect(stats.bundleName).toStrictEqual("rollup-test-es"); }); }); diff --git a/integration-tests/fixtures/generate-bundle-stats/vite-plugin.test.ts b/integration-tests/fixtures/generate-bundle-stats/vite-plugin.test.ts index 69f60d55..7f6c7bc0 100644 --- a/integration-tests/fixtures/generate-bundle-stats/vite-plugin.test.ts +++ b/integration-tests/fixtures/generate-bundle-stats/vite-plugin.test.ts @@ -94,6 +94,6 @@ describe("Generating vite stats", () => { }); it("sets the correct bundle name", () => { - expect(stats.bundleName).toStrictEqual("vite-test"); + expect(stats.bundleName).toStrictEqual("vite-test-cjs"); }); }); diff --git a/integration-tests/fixtures/generate-bundle-stats/webpack-plugin.test.ts b/integration-tests/fixtures/generate-bundle-stats/webpack-plugin.test.ts index 92206862..c23b9b78 100644 --- a/integration-tests/fixtures/generate-bundle-stats/webpack-plugin.test.ts +++ b/integration-tests/fixtures/generate-bundle-stats/webpack-plugin.test.ts @@ -101,6 +101,6 @@ describe("Generating webpack stats", () => { }); it("sets the correct bundle name", () => { - expect(stats.bundleName).toStrictEqual("webpack-test"); + expect(stats.bundleName).toStrictEqual("webpack-test-array-push"); }); });