Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .changeset/neat-jobs-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
"@codecov/nextjs-webpack-plugin": patch
"@codecov/bundler-plugin-core": patch
"@codecov/webpack-plugin": patch
"@codecov/rollup-plugin": patch
"@codecov/vite-plugin": patch
"@codecov/bundle-analyzer": patch
"@codecov/nuxt-plugin": patch
"@codecov/remix-vite-plugin": patch
"@codecov/solidstart-plugin": patch
"@codecov/sveltekit-plugin": patch
---

Fix issue with bundle names not being reset in nextjs, rollup, vite, and webpack plugins.
8 changes: 6 additions & 2 deletions packages/bundler-plugin-core/src/utils/Output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class Output {
};
debug: boolean;
gitService?: ValidGitService;
originalBundleName: string;
#internalOriginalBundleName: string;
// uploader overrides
branch?: string;
build?: string;
Expand Down Expand Up @@ -65,7 +65,7 @@ class Output {
this.uploadToken = userOptions.uploadToken;
this.debug = userOptions.debug;
this.gitService = userOptions.gitService;
this.originalBundleName = userOptions.bundleName;
this.#internalOriginalBundleName = userOptions.bundleName;
this.oidc = userOptions.oidc;

if (userOptions.uploadOverrides) {
Expand Down Expand Up @@ -107,6 +107,10 @@ class Output {
return this.#internalBundleName;
}

get originalBundleName() {
return this.#internalOriginalBundleName;
}

setPlugin(pluginName: string, pluginVersion: string) {
if (!this.#internalLocks.pluginDetails) {
this.#internalPlugin = {
Expand Down
41 changes: 41 additions & 0 deletions packages/bundler-plugin-core/src/utils/__tests__/Output.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,47 @@ describe("Output", () => {
});
});

describe("resetBundleName method", () => {
describe("bundle name is not locked", () => {
it("resets the bundle name", () => {
const output = new Output({
apiUrl: "http://localhost",
bundleName: "output-test",
debug: false,
dryRun: false,
enableBundleAnalysis: true,
retryCount: 1,
uploadToken: "token",
});

output.setBundleName("new-bundle");
output.resetBundleName();

expect(output.bundleName).toBe("output-test");
});
});

describe("bundle name is locked", () => {
it("does not reset the bundle name", () => {
const output = new Output({
apiUrl: "http://localhost",
bundleName: "output-test",
debug: false,
dryRun: false,
enableBundleAnalysis: true,
retryCount: 1,
uploadToken: "token",
});

output.setBundleName("new-bundle");
output.lockBundleName();
output.resetBundleName();

expect(output.bundleName).toBe("new-bundle");
});
});
});

describe("write method", () => {
describe("dryRun is enabled", () => {
it("immediately returns", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const nextJSWebpackBundleAnalysisPlugin: ExtendedBAUploadPlugin<{
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT,
},
async () => {
output.setBundleName(output.bundleName);
output.setBundleName(output.originalBundleName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this a function to invoke like output.originalBundleName()?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so with a get method you don't need to actually call it, it handles that under the hood for you.

// Webpack base chunk format options: https://webpack.js.org/configuration/output/#outputchunkformat
if (typeof compilation.outputOptions.chunkFormat === "string") {
if (compilation.name && compilation.name !== "") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const rollupBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({
return;
}

output.setBundleName(output.bundleName);
output.setBundleName(output.originalBundleName);
if (options.name && options.name !== "") {
output.setBundleName(`${output.bundleName}-${options.name}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const viteBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({
return;
}

output.setBundleName(output.bundleName);
output.setBundleName(output.originalBundleName);
// add in bundle name if present
if (options.name && options.name !== "") {
output.setBundleName(`${output.bundleName}-${options.name}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const webpackBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT,
},
async () => {
output.setBundleName(output.bundleName);
output.setBundleName(output.originalBundleName);
// Webpack base chunk format options: https://webpack.js.org/configuration/output/#outputchunkformat
if (typeof compilation.outputOptions.chunkFormat === "string") {
if (compilation.name && compilation.name !== "") {
Expand Down
Loading