Skip to content

Commit 3ae830c

Browse files
authored
build: Add codecov bundle analysis for npm packages (#11276)
Given our bundling setup is a little more complicated, this patch adds codecov bundle analysis for our just our npm builds (ESM and CJS). It generates the bundle name from the package.json Previous attempt: #10682 https://docs.codecov.com/docs/rollup-quick-start https://app.codecov.io/gh/getsentry/sentry-javascript/bundles
1 parent 7bec613 commit 3ae830c

File tree

7 files changed

+70
-11
lines changed

7 files changed

+70
-11
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ jobs:
271271
${{needs.job_get_metadata.outputs.is_develop == 'false' && env.NX_CACHE_RESTORE_KEYS || 'nx-never-restore'}}
272272

273273
- name: Build packages
274+
# Set the CODECOV_TOKEN for Bundle Analysis
275+
env:
276+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
274277
run: yarn build
275278
outputs:
276279
# this needs to be passed on, because the `needs` context only looks at direct ancestors (so steps which depend on

dev-packages/e2e-tests/Dockerfile.publish-packages

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# This Dockerfile exists for the purpose of using a specific node/npm version (ie. the same we use in CI) to run npm publish with
2-
ARG NODE_VERSION=18.17.1
2+
ARG NODE_VERSION=18.18.0
33
FROM node:${NODE_VERSION}
44

55
WORKDIR /sentry-javascript/dev-packages/e2e-tests

dev-packages/e2e-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"yaml": "2.2.2"
2727
},
2828
"volta": {
29-
"node": "18.17.1",
29+
"node": "18.18.0",
3030
"yarn": "1.22.19"
3131
}
3232
}

dev-packages/rollup-utils/npmHelpers.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import deepMerge from 'deepmerge';
1010

1111
import {
1212
makeCleanupPlugin,
13+
makeCodeCovPlugin,
1314
makeDebugBuildStatementReplacePlugin,
1415
makeExtractPolyfillsPlugin,
1516
makeNodeResolvePlugin,
@@ -43,6 +44,8 @@ export function makeBaseNPMConfig(options = {}) {
4344
excludeIframe: undefined,
4445
});
4546

47+
const codecovPlugin = makeCodeCovPlugin();
48+
4649
const defaultBaseConfig = {
4750
input: entrypoints,
4851

@@ -103,6 +106,7 @@ export function makeBaseNPMConfig(options = {}) {
103106
debugBuildStatementReplacePlugin,
104107
rrwebBuildPlugin,
105108
cleanupPlugin,
109+
codecovPlugin,
106110
],
107111

108112
// don't include imported modules from outside the package in the final output

dev-packages/rollup-utils/plugins/npmPlugins.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
* Sucrase plugin docs: https://github.com/rollup/plugins/tree/master/packages/sucrase
88
*/
99

10+
import * as fs from 'fs';
11+
import * as path from 'path';
12+
13+
import { codecovRollupPlugin } from '@codecov/rollup-plugin';
1014
import json from '@rollup/plugin-json';
1115
import replace from '@rollup/plugin-replace';
1216
import sucrase from '@rollup/plugin-sucrase';
@@ -138,4 +142,19 @@ export function makeRrwebBuildPlugin({ excludeShadowDom, excludeIframe } = {}) {
138142
});
139143
}
140144

145+
/**
146+
* Plugin that uploads bundle analysis to codecov.
147+
*
148+
* @param type The type of bundle being uploaded.
149+
* @param prefix The prefix for the codecov bundle name. Defaults to 'npm'.
150+
*/
151+
export function makeCodeCovPlugin() {
152+
const packageJson = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), './package.json'), { encoding: 'utf8' }));
153+
return codecovRollupPlugin({
154+
enableBundleAnalysis: process.env.CODECOV_TOKEN !== undefined,
155+
bundleName: packageJson.name,
156+
uploadToken: process.env.CODECOV_TOKEN,
157+
});
158+
}
159+
141160
export { makeExtractPolyfillsPlugin } from './extractPolyfillsPlugin.mjs';

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"yalc:publish": "lerna run yalc:publish"
4141
},
4242
"volta": {
43-
"node": "18.17.0",
43+
"node": "18.18.0",
4444
"yarn": "1.22.19"
4545
},
4646
"workspaces": [
@@ -86,6 +86,7 @@
8686
],
8787
"devDependencies": {
8888
"@biomejs/biome": "^1.4.0",
89+
"@codecov/rollup-plugin": "0.0.1-beta.5",
8990
"@rollup/plugin-commonjs": "^25.0.7",
9091
"@rollup/plugin-esm-shim": "^0.1.5",
9192
"@rollup/plugin-json": "^6.1.0",

yarn.lock

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2316,6 +2316,23 @@
23162316
exec-sh "^0.3.2"
23172317
minimist "^1.2.0"
23182318

2319+
"@codecov/bundler-plugin-core@^0.0.1-beta.5":
2320+
version "0.0.1-beta.5"
2321+
resolved "https://registry.yarnpkg.com/@codecov/bundler-plugin-core/-/bundler-plugin-core-0.0.1-beta.5.tgz#f516c080abe4c99fb5cfdc7d39513b277fac2bae"
2322+
integrity sha512-eltwv1aRJdwonlTD47jQ2GYdKZfMv3jCviDui32JOu12ZAiI3WdJCtjWF9zxpmnHEZ30pn0WbeZir+sXSFLJHw==
2323+
dependencies:
2324+
chalk "4.1.2"
2325+
semver "^7.5.4"
2326+
unplugin "^1.6.0"
2327+
zod "^3.22.4"
2328+
2329+
"@codecov/rollup-plugin@0.0.1-beta.5":
2330+
version "0.0.1-beta.5"
2331+
resolved "https://registry.yarnpkg.com/@codecov/rollup-plugin/-/rollup-plugin-0.0.1-beta.5.tgz#cca4c68989efbcf4e2dbe3db5e9a5bf5b7501fe2"
2332+
integrity sha512-3x6vmt59Hgfpr8jroB7LYa2XX+kFds8HaWsUTBX08sJ2bCw+BzlW1Mnc+IdxBdMtjo1jkYEceRvfwQ0X2LK4ZQ==
2333+
dependencies:
2334+
"@codecov/bundler-plugin-core" "^0.0.1-beta.5"
2335+
23192336
"@colors/colors@1.5.0":
23202337
version "1.5.0"
23212338
resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9"
@@ -11337,6 +11354,14 @@ chalk@4.1.0:
1133711354
ansi-styles "^4.1.0"
1133811355
supports-color "^7.1.0"
1133911356

11357+
chalk@4.1.2, chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0, chalk@^4.1.1, chalk@^4.1.2:
11358+
version "4.1.2"
11359+
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
11360+
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
11361+
dependencies:
11362+
ansi-styles "^4.1.0"
11363+
supports-color "^7.1.0"
11364+
1134011365
chalk@^1.0.0, chalk@^1.1.3:
1134111366
version "1.1.3"
1134211367
resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98"
@@ -11348,14 +11373,6 @@ chalk@^1.0.0, chalk@^1.1.3:
1134811373
strip-ansi "^3.0.0"
1134911374
supports-color "^2.0.0"
1135011375

11351-
chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0, chalk@^4.1.1, chalk@^4.1.2:
11352-
version "4.1.2"
11353-
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
11354-
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
11355-
dependencies:
11356-
ansi-styles "^4.1.0"
11357-
supports-color "^7.1.0"
11358-
1135911376
chalk@^5.0.0, chalk@^5.2.0, chalk@^5.3.0:
1136011377
version "5.3.0"
1136111378
resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.3.0.tgz#67c20a7ebef70e7f3970a01f90fa210cb6860385"
@@ -29331,6 +29348,16 @@ unplugin@1.0.1:
2933129348
webpack-sources "^3.2.3"
2933229349
webpack-virtual-modules "^0.5.0"
2933329350

29351+
unplugin@^1.6.0:
29352+
version "1.10.0"
29353+
resolved "https://registry.yarnpkg.com/unplugin/-/unplugin-1.10.0.tgz#9cb8140f61e3fbcf27c7c38d305e9d62d5dbbf0b"
29354+
integrity sha512-CuZtvvO8ua2Wl+9q2jEaqH6m3DoQ38N7pvBYQbbaeNlWGvK2l6GHiKi29aIHDPoSxdUzQ7Unevf1/ugil5X6Pg==
29355+
dependencies:
29356+
acorn "^8.11.3"
29357+
chokidar "^3.6.0"
29358+
webpack-sources "^3.2.3"
29359+
webpack-virtual-modules "^0.6.1"
29360+
2933429361
unset-value@^1.0.0:
2933529362
version "1.0.0"
2933629363
resolved "https://registry.yarnpkg.com/unset-value/-/unset-value-1.0.0.tgz#8376873f7d2335179ffb1e6fc3a8ed0dfc8ab559"
@@ -30112,6 +30139,11 @@ webpack-virtual-modules@^0.5.0:
3011230139
resolved "https://registry.yarnpkg.com/webpack-virtual-modules/-/webpack-virtual-modules-0.5.0.tgz#362f14738a56dae107937ab98ea7062e8bdd3b6c"
3011330140
integrity sha512-kyDivFZ7ZM0BVOUteVbDFhlRt7Ah/CSPwJdi8hBpkK7QLumUqdLtVfm/PX/hkcnrvr0i77fO5+TjZ94Pe+C9iw==
3011430141

30142+
webpack-virtual-modules@^0.6.1:
30143+
version "0.6.1"
30144+
resolved "https://registry.yarnpkg.com/webpack-virtual-modules/-/webpack-virtual-modules-0.6.1.tgz#ac6fdb9c5adb8caecd82ec241c9631b7a3681b6f"
30145+
integrity sha512-poXpCylU7ExuvZK8z+On3kX+S8o/2dQ/SVYueKA0D4WEMXROXgY8Ez50/bQEUmvoSMMrWcrJqCHuhAbsiwg7Dg==
30146+
3011530147
webpack@5.76.1:
3011630148
version "5.76.1"
3011730149
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.76.1.tgz#7773de017e988bccb0f13c7d75ec245f377d295c"

0 commit comments

Comments
 (0)