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: Expand bundle-analyzer options #163

Merged
merged 8 commits into from
Sep 10, 2024
Merged

feat: Expand bundle-analyzer options #163

merged 8 commits into from
Sep 10, 2024

Conversation

suejung-sentry
Copy link
Contributor

@suejung-sentry suejung-sentry commented Sep 9, 2024

Description

This PR handles follow-up functionality to add to the bundle-analyzer package.
Closes codecov/engineering-team#2464

  1. Expand the configuration options offered by the bundle-analyzer package.
    i. Allow multiple paths for directory traversal to be included in the single bundle stats report
    ii. Include an "ignore" pattern/list for which files to exclude
    iii. Support an optional configuration option pathPattern such as [name]-[hash].[ext] instead of just the default of replacing anything "hashlike" with *. Has the limitation that the single pattern would get applies to all.
  2. A good callout that the CLI should be tested for Windows and MacOS. To reduce the complexity and maintainability of this package, I specified we will only support MacOS and Linux. We can add Windows support if someone ever asks for it.
  3. In the whole package, examples, integration-tests, make sure we can handle new tokenless and GitHub OIDC capabilities. For this, I updated the requirement so uploadToken is NOT required.

UPDATE 9/9 - also includes addressing this to better wrap the error from the report overrider (beforeReportUpload)

Copy link

codecov bot commented Sep 9, 2024

Codecov Report

Attention: Patch coverage is 75.18797% with 33 lines in your changes missing coverage. Please review.

Project coverage is 74.85%. Comparing base (0f04bce) to head (9644b1d).
Report is 1 commits behind head on prerelease.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
packages/bundle-analyzer/src/cli.ts 0.00% 31 Missing ⚠️
packages/bundle-analyzer/src/index.ts 96.77% 1 Missing ⚠️
packages/bundle-analyzer/src/version.ts 92.85% 1 Missing ⚠️
Additional details and impacted files
Components Coverage Δ
Plugin core 96.69% <ø> (ø)
Rollup plugin 10.81% <ø> (ø)
Vite plugin 11.02% <ø> (ø)
Webpack plugin 50.11% <ø> (ø)

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

@codecov-notifications
Copy link

codecov-notifications bot commented Sep 9, 2024

Codecov Report

Attention: Patch coverage is 75.18797% with 33 lines in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files Patch % Lines
packages/bundle-analyzer/src/cli.ts 0.00% 31 Missing ⚠️
packages/bundle-analyzer/src/index.ts 96.77% 1 Missing ⚠️
packages/bundle-analyzer/src/version.ts 92.85% 1 Missing ⚠️
Components Coverage Δ
Plugin core 96.69% <ø> (ø)
Rollup plugin 10.81% <ø> (ø)
Vite plugin 11.02% <ø> (ø)
Webpack plugin 50.11% <ø> (ø)

📢 Thoughts on this report? Let us know!

Copy link

codecov bot commented Sep 9, 2024

Bundle Report

Changes will increase total bundle size by 30.42kB (0.53%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
@codecov/bundler-plugin-core-esm 41.56kB 29.29kB ⬆️
@codecov/example-solidstart-app-client-esm 47.8kB 193 bytes ⬇️
@codecov/solidstart-plugin-esm 1.09kB 142 bytes ⬆️
@codecov/example-oidc-app-esm 150.57kB 4 bytes ⬆️
@codecov/bundle-analyzer-cjs 4.51kB 606 bytes ⬆️
@codecov/bundle-analyzer-esm 2.69kB 565 bytes ⬆️

@codecov-staging
Copy link

codecov-staging bot commented Sep 9, 2024

Bundle Report

Changes will increase total bundle size by 26.42kB ⬆️

Bundle name Size Change
@codecov/nextjs-webpack-plugin-cjs 2.1kB 2.1kB ⬆️
@codecov/example-rollup-app-iife 95.46kB 95.46kB ⬆️
@codecov/nextjs-webpack-plugin-esm 1.11kB 753 bytes ⬇️
@codecov/bundle-analyzer-esm 3.48kB 1.35kB ⬆️
@codecov/remix-vite-plugin-esm 957 bytes 133 bytes ⬇️
@codecov/rollup-plugin-esm 1.3kB 1.02kB ⬇️
@codecov/sveltekit-plugin-esm 891 bytes 0 bytes
@codecov/nuxt-plugin-cjs 1.4kB 0 bytes
@codecov/sveltekit-plugin-cjs 1.32kB 0 bytes
@codecov/bundler-plugin-core-esm 41.56kB 0 bytes
@codecov/webpack-plugin-cjs 4.35kB 0 bytes
@codecov/solidstart-plugin-esm 949 bytes 0 bytes
@codecov/vite-plugin-cjs 2.79kB 0 bytes
@codecov/solidstart-plugin-cjs 1.33kB 0 bytes
@codecov/webpack-plugin-esm 3.36kB 0 bytes
@codecov/nuxt-plugin-esm 830 bytes 0 bytes
@codecov/vite-plugin-esm 1.24kB 0 bytes
@codecov/bundle-analyzer-cjs 4.51kB 606 bytes ⬆️
@codecov/remix-vite-plugin-cjs 1.31kB 0 bytes
@codecov/bundler-plugin-core-cjs 46.59kB 0 bytes
@codecov/rollup-plugin-cjs 2.81kB 0 bytes
@codecov/example-webpack-app-array-push (removed) 71.19kB ⬇️

@suejung-sentry suejung-sentry marked this pull request as ready for review September 9, 2024 01:09
@@ -5,6 +5,7 @@ import yargs from "yargs";
import { hideBin } from "yargs/helpers";
import { createAndUploadReport } from "./index.js";
import { red, type Options } from "@codecov/bundler-plugin-core";
import { type BundleAnalyzerOptions } from "./options";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this file is tested by cli.test.ts (which runs via npx tsx)

packages/bundle-analyzer/README.md Show resolved Hide resolved
/**
* Additional directories to include in the build analysis. By default, it returns an empty list.
*/
additionalBuildDirectories?: string[];
Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you think about changing the API of createAndUploadReport to accept an array? I feel like that would be easier to use than to have both buildDirectoryPath as the first argument, and then additionalBuildDirectories on top of that.

We could also make buildDirectoryPath of createAndUploadReport be able to take a glob string, so that it still is a string argument, but can be used for array-like queries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense! My original thought there was that the default usage in most cases would expect a single build directory. And then if people are doing something off the usual path or "fancier" could supply the additional paths optionally.
I went ahead and pulled them together to one array input to reduce the complexity.
Glob string is an interesting idea - I think I can add it on top of the array in the future if it seems users want to go in that direction

packages/bundle-analyzer/src/assets.ts Outdated Show resolved Hide resolved
Base automatically changed from sshin/2222-new to prerelease September 9, 2024 16:01
* .then(() => console.log('Report successfully generated and uploaded.'))
* .catch((error) => console.error('Failed to generate or upload report:', error));
*/
export const createAndUploadReport = async (
buildDirectoryPath: string,
buildDirectoryPaths: string[],
Copy link
Collaborator

Choose a reason for hiding this comment

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

What do you think about making this string | string[]?

Might be excess complexity though, I'm fine with sticking with the string[].

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I had turned that over in my head, too... I think it would be easy to extend to allow string | string[] in the future so thought it'd be good to keep the simple case until can get some more feedback

Copy link
Collaborator

Choose a reason for hiding this comment

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

We'll need to update the README about the changes to createAndUploadReport and the new bundle analyzer options

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I missed that spot!
This is the problem with code duplication in the docs :(

I'll think about that - maybe can lean more into Typedoc, which I'm generating with my annotations, or a reference to the examples in the same directory instead of spelling it out in the README.
We've also got extensive docs in https://docs.codecov.com/docs/javascript-bundle-analysis, which I can potentially write a page and point to instead.

Updated the README for now to have similar level of information to the other plugin packages in this repo.

packages/bundle-analyzer/src/assets.ts Outdated Show resolved Hide resolved
@suejung-sentry suejung-sentry merged commit 9ddc21b into prerelease Sep 10, 2024
55 checks passed
@suejung-sentry suejung-sentry deleted the sshin/2464 branch September 10, 2024 16:50
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.

2 participants