-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add in bundle name config option #26
Changes from all commits
4b1474e
26098f0
ccd55ed
f37a830
df6652b
2da2a19
acba306
4f9e05b
92ae7b4
3930adc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test checks if the |
||
expect(stats.bundleName).toStrictEqual("rollup-test-es"); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,9 @@ export const bundleAnalysisPluginFactory = ({ | |
userOptions, | ||
bundleAnalysisUploadPlugin, | ||
}: BundleAnalysisUploadPluginArgs): UnpluginOptions => { | ||
// const dryRun = userOptions?.dryRun ?? false; | ||
const output: Output = { | ||
version: "1", | ||
bundleName: userOptions.bundleName ?? "", | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
|
||
const { pluginVersion, version, ...pluginOpts } = bundleAnalysisUploadPlugin({ | ||
|
@@ -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 | ||
nicholas-codecov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!userOptions.bundleName || userOptions.bundleName === "") return; | ||
|
||
const args: UploadOverrides = userOptions.uploaderOverrides ?? {}; | ||
const envs = process.env; | ||
const inputs: ProviderUtilInputs = { envs, args }; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ interface CodecovUnpluginFactoryOptions { | |
bundleAnalysisUploadPlugin: BundleAnalysisUploadPlugin; | ||
} | ||
|
||
export function codecovUnpluginFactory({ | ||
function codecovUnpluginFactory({ | ||
bundleAnalysisUploadPlugin, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The codecovUnpluginFactory function is sightly modified, and it's not clear why. Perhaps it is related to the |
||
}: CodecovUnpluginFactoryOptions) { | ||
return createUnplugin<Options, true>((userOptions, unpluginMetaContext) => { | ||
|
@@ -48,6 +48,8 @@ export function codecovUnpluginFactory({ | |
}); | ||
} | ||
|
||
export { red, codecovUnpluginFactory }; | ||
|
||
export type { | ||
BundleAnalysisUploadPlugin, | ||
Asset, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ export interface Module { | |
|
||
export interface Output { | ||
version?: string; | ||
bundleName: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
bundler?: { | ||
name: string; | ||
version: string; | ||
|
@@ -92,6 +93,15 @@ export interface Options { | |
* Defaults to `false` | ||
*/ | ||
dryRun?: boolean; | ||
|
||
/** | ||
* The name for the bundle being built. | ||
* | ||
* Required for uploading bundle analysis information. | ||
* | ||
* Example: `rollup-package` | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
bundleName?: string; | ||
} | ||
nicholas-codecov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export type BundleAnalysisUploadPlugin = ( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
type Chunk, | ||
type Module, | ||
type BundleAnalysisUploadPlugin, | ||
red, | ||
} from "@codecov/bundler-plugin-core"; | ||
|
||
const PLUGIN_NAME = "codecov-rollup-bundle-analysis-plugin"; | ||
|
@@ -17,6 +18,19 @@ | |
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 === "") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If |
||
red("Bundle name is not present or empty. Skipping upload."); | ||
return; | ||
Check warning on line 24 in packages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts Codecov / codecov/patchpackages/rollup-plugin/src/rollup-bundle-analysis/rollupBundleAnalysisPlugin.ts#L23-L24
|
||
} | ||
|
||
// append bundle output format to bundle name | ||
output.bundleName = `${userOptions.bundleName}-${options.format}`; | ||
|
||
if (options.name && options.name !== "") { | ||
output.bundleName = `${userOptions.bundleName}-${options.name}`; | ||
} | ||
|
||
const customOptions = { | ||
moduleOriginalSize: false, | ||
...options, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
type Chunk, | ||
type Module, | ||
type BundleAnalysisUploadPlugin, | ||
red, | ||
} from "@codecov/bundler-plugin-core"; | ||
|
||
const PLUGIN_NAME = "codecov-vite-bundle-analysis-plugin"; | ||
|
@@ -17,6 +18,20 @@ | |
pluginVersion: "1.0.0", | ||
vite: { | ||
generateBundle(this, options, bundle) { | ||
// don't need to do anything if the bundle name is not present or empty | ||
nicholas-codecov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!userOptions.bundleName || userOptions.bundleName === "") { | ||
red("Bundle name is not present or empty. Skipping upload."); | ||
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}`; | ||
} | ||
|
||
const customOptions = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again here, the upload is skipped if bundleName is not present. There seems to be a pattern of operational changes depending on whether the |
||
moduleOriginalSize: false, | ||
...options, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,7 @@ | ||
import { type BundleAnalysisUploadPlugin } from "@codecov/bundler-plugin-core"; | ||
import { | ||
type BundleAnalysisUploadPlugin, | ||
red, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Red is imported but unused. This needs to be reviewed and removed if it's not needed. |
||
} from "@codecov/bundler-plugin-core"; | ||
import * as webpack4or5 from "webpack"; | ||
|
||
const PLUGIN_NAME = "codecov-webpack-bundle-analysis-plugin"; | ||
|
@@ -18,6 +21,20 @@ | |
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 === "") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without the context of what this |
||
red("Bundle name is not present or empty. Skipping upload."); | ||
return; | ||
Check warning on line 27 in packages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts Codecov / codecov/patchpackages/webpack-plugin/src/webpack-bundle-analysis/webpackBundleAnalysisPlugin.ts#L26-L27
|
||
} | ||
|
||
if (typeof compilation.outputOptions.chunkFormat === "string") { | ||
output.bundleName = `${userOptions.bundleName}-${compilation.outputOptions.chunkFormat}`; | ||
} | ||
|
||
if (compilation.name && compilation.name !== "") { | ||
output.bundleName = `${userOptions.bundleName}-${compilation.name}`; | ||
} | ||
|
||
const compilationStats = compilation.getStats().toJson({ | ||
assets: true, | ||
chunks: true, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
bundleName
option is added to the plugin, but it is not clear what it means or how it is used within the plugin itself. It could be helpful to add comments explaining what it does.