Skip to content
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

Merged
merged 10 commits into from
Dec 19, 2023

Conversation

nicholas-codecov
Copy link
Collaborator

Description

This PR adds in a new configuration option bundleName which is required when using the bundle analysis plugin. If not provided then an error message will be emitted and the core plugin will not attempt and upload.

Code Example

codecovVitePlugin({
  enableBundleAnalysis: true,
  bundleName: "vite-test",
}),

Notable Changes

  • Add new bundleName config option
  • Append bundleName to stats JSON output
  • Update bundler plugins to early return and emit console error message
  • Update tests

Copy link

codecov bot commented Dec 13, 2023

Codecov Report

Attention: 20 lines in your changes are missing coverage. Please review.

Comparison is base (7fc27b3) 85.81% compared to head (3930adc) 84.56%.

Files Patch % Lines
...ack-bundle-analysis/webpackBundleAnalysisPlugin.ts 12.50% 6 Missing and 1 partial ⚠️
...llup-bundle-analysis/rollupBundleAnalysisPlugin.ts 0.00% 6 Missing ⚠️
...c/vite-bundle-analysis/viteBundleAnalysisPlugin.ts 0.00% 6 Missing ⚠️
...src/bundle-analysis/bundleAnalysisPluginFactory.ts 50.00% 1 Missing ⚠️
Additional details and impacted files
Components Coverage Δ
Plugin core 96.26% <50.00%> (-0.09%) ⬇️
Rollup plugin 7.93% <0.00%> (+0.79%) ⬆️
Vite plugin 7.93% <0.00%> (+0.79%) ⬆️
Webpack plugin 9.80% <12.50%> (+0.50%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@codecov codecov bot left a comment

Choose a reason for hiding this comment

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

The changes in the git diff seem to be about the addition of a new bundleName option to the bundling plugins. The bundleName is set in the tests, function calls, and is added to the Output interface, but there is no clear use of it in the plugins themselves except for some condition checks and warning logging. The description or purpose behind this bundleName addition is not clear from the git diff alone and it could be helpful to provide more information on its usage.

codecovRollupPlugin({
enableBundleAnalysis: true,
dryRun: true,
bundleName: "rollup-test",
Copy link

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.

@@ -89,4 +93,8 @@
it("sets the correct bundler information", () => {
expect(stats.bundler).toStrictEqual(expectedStats.bundler);
});

it("sets the correct bundle name", () => {
Copy link

Choose a reason for hiding this comment

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

The test checks if the bundleName in the stats is correctly set to the one provided in the plugin options. However, it is not clear how this bundleName is used in the test or the functionality it provides.

const output: Output = {
version: "1",
bundleName: userOptions.bundleName ?? "",
};
Copy link

Choose a reason for hiding this comment

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

The bundleName is added to the Output object here. It would be useful to know where this object is used and what effect the bundleName has on it.

@@ -21,7 +21,7 @@ interface CodecovUnpluginFactoryOptions {
bundleAnalysisUploadPlugin: BundleAnalysisUploadPlugin;
}

export function codecovUnpluginFactory({
function codecovUnpluginFactory({
bundleAnalysisUploadPlugin,
Copy link

Choose a reason for hiding this comment

The 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 bundleName implementation but it needs clarification.

@@ -28,6 +28,7 @@ export interface Module {

export interface Output {
version?: string;
bundleName: string;
Copy link

Choose a reason for hiding this comment

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

The bundleName field is added to the Output Interface. But, It seems to be mandatory in the Interface which might not be sensible as it's optional in Options Interface (and can be undefined).

* Required for uploading bundle analysis information.
*
* Example: `rollup-package`
*/
Copy link

Choose a reason for hiding this comment

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

The bundleName field is added to the Options Interface, but it's marked as optional. It should be mandatory if it's required for uploading bundle analysis information.

@@ -17,6 +18,12 @@
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 === "") {
Copy link

Choose a reason for hiding this comment

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

If bundleName is not provided or is an empty string, red text stating 'Bundle name is not present or empty. Skipping upload.' is logged to the console. However, it's not sure if this behavior of skipping upload when bundleName is missing suits all use-cases.

red("Bundle name is not present or empty. Skipping upload.");
return;
}

const customOptions = {
Copy link

Choose a reason for hiding this comment

The 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 bundleName exists.

import { type BundleAnalysisUploadPlugin } from "@codecov/bundler-plugin-core";
import {
type BundleAnalysisUploadPlugin,
red,
Copy link

Choose a reason for hiding this comment

The 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.

@@ -18,6 +21,12 @@
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 === "") {
Copy link

Choose a reason for hiding this comment

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

Without the context of what this bundleName is meant to contribute to the functionality of the plugins, the addition of it at so many points throughout these files lessens the readability and understanding.

Copy link

@codecov codecov bot left a comment

Choose a reason for hiding this comment

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

CodecovAI submitted a new review for 3930adc

@nicholas-codecov nicholas-codecov merged commit 78966dc into main Dec 19, 2023
7 of 12 checks passed
@nicholas-codecov nicholas-codecov deleted the add-in-bundle-name-config-option branch December 19, 2023 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants