Skip to content

Commit ee498fb

Browse files
committed
refactor how we define and access the plugin name and version
1 parent 90901a5 commit ee498fb

File tree

28 files changed

+221
-90
lines changed

28 files changed

+221
-90
lines changed

packages/astro-plugin/src/astro-bundle-analysis/__tests__/astroBundleAnalysisPlugin.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { Output } from "@codecov/bundler-plugin-core";
22
import { describe, it, expect } from "vitest";
33
import { astroBundleAnalysisPlugin } from "../astroBundleAnalysisPlugin";
44

5+
// @ts-expect-error this value is being replaced by rollup
6+
const PLUGIN_NAME = __PACKAGE_NAME__ as string;
7+
// @ts-expect-error this value is being replaced by rollup
8+
const PLUGIN_VERSION = __PACKAGE_VERSION__ as string;
9+
510
describe("astroBundleAnalysisPlugin", () => {
611
describe("when called", () => {
712
it("returns a plugin object", () => {
@@ -16,6 +21,8 @@ describe("astroBundleAnalysisPlugin", () => {
1621
retryCount: 1,
1722
uploadToken: "test-token",
1823
}),
24+
pluginName: PLUGIN_NAME,
25+
pluginVersion: PLUGIN_VERSION,
1926
});
2027

2128
expect(plugin).toMatchSnapshot();

packages/astro-plugin/src/astro-bundle-analysis/astroBundleAnalysisPlugin.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ import {
55
} from "@codecov/bundler-plugin-core";
66
import { getBundleName } from "./getBundleName";
77

8-
// @ts-expect-error this value is being replaced by rollup
9-
const PLUGIN_NAME = __PACKAGE_NAME__ as string;
10-
// @ts-expect-error this value is being replaced by rollup
11-
const PLUGIN_VERSION = __PACKAGE_VERSION__ as string;
12-
138
interface AstroBundleAnalysisArgs extends BundleAnalysisUploadPluginArgs {
149
target: "client" | "server";
1510
}
@@ -21,10 +16,12 @@ type AstroBundleAnalysisPlugin = (
2116
export const astroBundleAnalysisPlugin: AstroBundleAnalysisPlugin = ({
2217
output,
2318
target,
19+
pluginName,
20+
pluginVersion,
2421
}) => ({
2522
version: output.version,
26-
name: PLUGIN_NAME,
27-
pluginVersion: PLUGIN_VERSION,
23+
name: pluginName,
24+
pluginVersion,
2825
vite: {
2926
generateBundle(this, options) {
3027
// TODO - remove this once we hard fail on not having a bundle name
@@ -46,7 +43,7 @@ export const astroBundleAnalysisPlugin: AstroBundleAnalysisPlugin = ({
4643
output.lockBundleName();
4744

4845
// manually set this to avoid resetting in the vite plugin
49-
output.setPlugin(PLUGIN_NAME, PLUGIN_VERSION);
46+
output.setPlugin(pluginName, pluginVersion);
5047
},
5148
},
5249
});

packages/astro-plugin/src/index.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import { type PluginOption } from "vite";
1212

1313
import { astroBundleAnalysisPlugin } from "./astro-bundle-analysis/astroBundleAnalysisPlugin";
1414

15-
// @ts-expect-error - This is a placeholder for the package name.
15+
// @ts-expect-error this value is being replaced by rollup
1616
const PLUGIN_NAME = __PACKAGE_NAME__ as string;
17+
// @ts-expect-error this value is being replaced by rollup
18+
const PLUGIN_VERSION = __PACKAGE_VERSION__ as string;
1719

1820
interface AstroPluginFactoryOptions extends Options {
1921
// type can be found from the AstroIntegration type
@@ -41,8 +43,17 @@ const astroPluginFactory = createVitePlugin<AstroPluginFactoryOptions, true>(
4143
const options = normalizedOptions.options;
4244
if (options.enableBundleAnalysis) {
4345
plugins.push(
44-
astroBundleAnalysisPlugin({ output, target }),
45-
_internal_viteBundleAnalysisPlugin({ output }),
46+
astroBundleAnalysisPlugin({
47+
output,
48+
target,
49+
pluginName: PLUGIN_NAME,
50+
pluginVersion: PLUGIN_VERSION,
51+
}),
52+
_internal_viteBundleAnalysisPlugin({
53+
output,
54+
pluginName: PLUGIN_NAME,
55+
pluginVersion: PLUGIN_VERSION,
56+
}),
4657
);
4758
}
4859

packages/bundler-plugin-core/src/types.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ export interface OutputPayload {
5151

5252
export interface BundleAnalysisUploadPluginArgs {
5353
output: Output;
54+
pluginName: string;
55+
pluginVersion: string;
5456
}
5557

5658
export interface ExtendedBAUploadArgs<TArgs extends object>

packages/nextjs-webpack-plugin/src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import {
1515

1616
import { nextJSWebpackBundleAnalysisPlugin } from "./nextjs-webpack-bundle-analysis/nextJSWebpackBundleAnalysisPlugin.ts";
1717

18+
// @ts-expect-error this value is being replaced by rollup
19+
const PLUGIN_NAME = __PACKAGE_NAME__ as string;
20+
// @ts-expect-error this value is being replaced by rollup
21+
const PLUGIN_VERSION = __PACKAGE_VERSION__ as string;
22+
1823
interface NextPluginOptions extends Options {
1924
webpack: typeof webpack | null;
2025
}
@@ -47,6 +52,8 @@ const codecovNextJSWebpackPluginFactory = createWebpackPlugin<
4752
options: {
4853
webpack: userOptions.webpack,
4954
},
55+
pluginName: PLUGIN_NAME,
56+
pluginVersion: PLUGIN_VERSION,
5057
}),
5158
);
5259
}

packages/nextjs-webpack-plugin/src/nextjs-webpack-bundle-analysis/__tests__/nextJSWebpackBundleAnalysisPlugin.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ import { describe, it, expect } from "vitest";
33
import * as webpack from "webpack";
44
import { nextJSWebpackBundleAnalysisPlugin } from "../nextJSWebpackBundleAnalysisPlugin";
55

6+
// @ts-expect-error this value is being replaced by rollup
7+
const PLUGIN_NAME = __PACKAGE_NAME__ as string;
8+
// @ts-expect-error this value is being replaced by rollup
9+
const PLUGIN_VERSION = __PACKAGE_VERSION__ as string;
10+
611
describe("webpackBundleAnalysisPlugin", () => {
712
describe("when called", () => {
813
it("returns a plugin object", () => {
@@ -19,6 +24,8 @@ describe("webpackBundleAnalysisPlugin", () => {
1924
options: {
2025
webpack: webpack,
2126
},
27+
pluginName: PLUGIN_NAME,
28+
pluginVersion: PLUGIN_VERSION,
2229
});
2330

2431
expect(plugin).toMatchSnapshot();

packages/nextjs-webpack-plugin/src/nextjs-webpack-bundle-analysis/nextJSWebpackBundleAnalysisPlugin.ts

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,15 @@ import {
77
_internal_processModules as processModules,
88
} from "@codecov/webpack-plugin";
99

10-
// @ts-expect-error this value is being replaced by rollup
11-
const PLUGIN_NAME = __PACKAGE_NAME__ as string;
12-
// @ts-expect-error this value is being replaced by rollup
13-
const PLUGIN_VERSION = __PACKAGE_VERSION__ as string;
14-
1510
export const nextJSWebpackBundleAnalysisPlugin: ExtendedBAUploadPlugin<{
1611
webpack: typeof webpack | null;
17-
}> = ({ output, options: { webpack } }) => ({
12+
}> = ({ output, pluginName, pluginVersion }) => ({
1813
version: output.version,
19-
name: PLUGIN_NAME,
20-
pluginVersion: PLUGIN_VERSION,
14+
name: pluginName,
15+
pluginVersion,
2116
buildStart: () => {
2217
output.start();
23-
output.setPlugin(PLUGIN_NAME, PLUGIN_VERSION);
18+
output.setPlugin(pluginName, pluginVersion);
2419
},
2520
buildEnd: () => {
2621
output.end();
@@ -29,7 +24,7 @@ export const nextJSWebpackBundleAnalysisPlugin: ExtendedBAUploadPlugin<{
2924
await output.write();
3025
},
3126
webpack(compiler) {
32-
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, (compilation) => {
27+
compiler.hooks.thisCompilation.tap(pluginName, (compilation) => {
3328
if (!webpack) {
3429
red(
3530
"Unable to run bundle analysis, Webpack wasn't passed successfully.",
@@ -39,7 +34,7 @@ export const nextJSWebpackBundleAnalysisPlugin: ExtendedBAUploadPlugin<{
3934

4035
compilation.hooks.processAssets.tapPromise(
4136
{
42-
name: PLUGIN_NAME,
37+
name: pluginName,
4338
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_REPORT,
4439
},
4540
async () => {

packages/nuxt-plugin/src/index.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import { addVitePlugin, defineNuxtModule } from "@nuxt/kit";
1313
import { nuxtBundleAnalysisPlugin } from "./nuxt-bundle-analysis/nuxtBundleAnalysisPlugin";
1414
import { type NuxtModule } from "nuxt/schema";
1515

16-
// @ts-expect-error - This is a placeholder for the package name.
16+
// @ts-expect-error this value is being replaced by rollup
1717
const PLUGIN_NAME = __PACKAGE_NAME__ as string;
18+
// @ts-expect-error this value is being replaced by rollup
19+
const PLUGIN_VERSION = __PACKAGE_VERSION__ as string;
1820

1921
const codecovNuxtPluginFactory = createVitePlugin<Options, true>(
2022
(userOptions, unpluginMetaContext) => {
@@ -37,8 +39,16 @@ const codecovNuxtPluginFactory = createVitePlugin<Options, true>(
3739
const options = normalizedOptions.options;
3840
if (options.enableBundleAnalysis) {
3941
plugins.push(
40-
nuxtBundleAnalysisPlugin({ output }),
41-
_internal_viteBundleAnalysisPlugin({ output }),
42+
nuxtBundleAnalysisPlugin({
43+
output,
44+
pluginName: PLUGIN_NAME,
45+
pluginVersion: PLUGIN_VERSION,
46+
}),
47+
_internal_viteBundleAnalysisPlugin({
48+
output,
49+
pluginName: PLUGIN_NAME,
50+
pluginVersion: PLUGIN_VERSION,
51+
}),
4252
);
4353
}
4454

packages/nuxt-plugin/src/nuxt-bundle-analysis/__tests__/nuxtBundleAnalysisPlugin.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { Output } from "@codecov/bundler-plugin-core";
22
import { describe, it, expect } from "vitest";
33
import { nuxtBundleAnalysisPlugin } from "../nuxtBundleAnalysisPlugin";
44

5+
// @ts-expect-error this value is being replaced by rollup
6+
const PLUGIN_NAME = __PACKAGE_NAME__ as string;
7+
// @ts-expect-error this value is being replaced by rollup
8+
const PLUGIN_VERSION = __PACKAGE_VERSION__ as string;
9+
510
describe("nuxtBundleAnalysisPlugin", () => {
611
describe("when called", () => {
712
it("returns a plugin object", () => {
@@ -15,6 +20,8 @@ describe("nuxtBundleAnalysisPlugin", () => {
1520
retryCount: 1,
1621
uploadToken: "test-token",
1722
}),
23+
pluginName: PLUGIN_NAME,
24+
pluginVersion: PLUGIN_VERSION,
1825
});
1926

2027
expect(plugin).toMatchSnapshot();

packages/nuxt-plugin/src/nuxt-bundle-analysis/nuxtBundleAnalysisPlugin.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,14 @@ import {
44
} from "@codecov/bundler-plugin-core";
55
import { getBundleName } from "./getBundleName";
66

7-
// @ts-expect-error this value is being replaced by rollup
8-
const PLUGIN_NAME = __PACKAGE_NAME__ as string;
9-
// @ts-expect-error this value is being replaced by rollup
10-
const PLUGIN_VERSION = __PACKAGE_VERSION__ as string;
11-
127
export const nuxtBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({
138
output,
9+
pluginName,
10+
pluginVersion,
1411
}) => ({
1512
version: output.version,
16-
name: PLUGIN_NAME,
17-
pluginVersion: PLUGIN_VERSION,
13+
name: pluginName,
14+
pluginVersion,
1815
vite: {
1916
generateBundle(this, options) {
2017
// TODO - remove this once we hard fail on not having a bundle name
@@ -36,7 +33,7 @@ export const nuxtBundleAnalysisPlugin: BundleAnalysisUploadPlugin = ({
3633
output.lockBundleName();
3734

3835
// manually set this to avoid resetting in the vite plugin
39-
output.setPlugin(PLUGIN_NAME, PLUGIN_VERSION);
36+
output.setPlugin(pluginName, pluginVersion);
4037
},
4138
},
4239
});

0 commit comments

Comments
 (0)