From 9e4b9d106d25041d38dfb64b4c1516bbaa5ffd72 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 15 Feb 2024 13:14:42 -0500 Subject: [PATCH 1/3] chore: Add CodeCov bundle analysis --- dev-packages/rollup-utils/npmHelpers.mjs | 9 ++++ .../rollup-utils/plugins/npmPlugins.mjs | 13 +++++ package.json | 3 ++ packages/core/rollup.npm.config.mjs | 2 +- yarn.lock | 53 ++++++++++++++++--- 5 files changed, 71 insertions(+), 9 deletions(-) diff --git a/dev-packages/rollup-utils/npmHelpers.mjs b/dev-packages/rollup-utils/npmHelpers.mjs index 6085a502200f..cdffcee86df6 100644 --- a/dev-packages/rollup-utils/npmHelpers.mjs +++ b/dev-packages/rollup-utils/npmHelpers.mjs @@ -10,6 +10,7 @@ import deepMerge from 'deepmerge'; import { makeCleanupPlugin, + makeCodeCovPlugin, makeDebugBuildStatementReplacePlugin, makeExtractPolyfillsPlugin, makeNodeResolvePlugin, @@ -28,6 +29,7 @@ export function makeBaseNPMConfig(options = {}) { hasBundles = false, packageSpecificConfig = {}, addPolyfills = true, + bundleAnalysis, } = options; const nodeResolvePlugin = makeNodeResolvePlugin(); @@ -111,6 +113,10 @@ export function makeBaseNPMConfig(options = {}) { defaultBaseConfig.plugins.push(extractPolyfillsPlugin); } + if (bundleAnalysis && bundleAnalysis.length) { + defaultBaseConfig.plugins.push(makeCodeCovPlugin(bundleAnalysis)); + } + return deepMerge(defaultBaseConfig, packageSpecificConfig, { // Plugins have to be in the correct order or everything breaks, so when merging we have to manually re-order them customMerge: key => (key === 'plugins' ? mergePlugins : undefined), @@ -118,6 +124,9 @@ export function makeBaseNPMConfig(options = {}) { } export function makeNPMConfigVariants(baseConfig) { + baseConfig.plugins = baseConfig.plugins || []; + baseConfig.plugins.push() + const variantSpecificConfigs = [ { output: { format: 'cjs', dir: path.join(baseConfig.output.dir, 'cjs') } }, { output: { format: 'esm', dir: path.join(baseConfig.output.dir, 'esm') } }, diff --git a/dev-packages/rollup-utils/plugins/npmPlugins.mjs b/dev-packages/rollup-utils/plugins/npmPlugins.mjs index 507480c1dd43..51b49d12773a 100644 --- a/dev-packages/rollup-utils/plugins/npmPlugins.mjs +++ b/dev-packages/rollup-utils/plugins/npmPlugins.mjs @@ -7,6 +7,7 @@ * Sucrase plugin docs: https://github.com/rollup/plugins/tree/master/packages/sucrase */ +import { codecovRollupPlugin } from '@codecov/rollup-plugin'; import replace from '@rollup/plugin-replace'; import sucrase from '@rollup/plugin-sucrase'; import cleanup from 'rollup-plugin-cleanup'; @@ -131,4 +132,16 @@ export function makeRrwebBuildPlugin({ excludeShadowDom, excludeIframe } = {}) { }); } +/** + * Plugin that uploads bundle analysis to codecov. + */ +export function makeCodeCovPlugin(bundleName) { + console.log(process.env.GITHUB_ACTIONS, process.env.CODECOV_TOKEN === undefined) + return codecovRollupPlugin({ + enableBundleAnalysis: process.env.GITHUB_ACTIONS === 'true' && process.env.CODECOV_TOKEN, + bundleName, + uploadToken: process.env.CODECOV_TOKEN, + }) +} + export { makeExtractPolyfillsPlugin } from './extractPolyfillsPlugin.mjs'; diff --git a/package.json b/package.json index 9ecacd34c252..171c70f1da69 100644 --- a/package.json +++ b/package.json @@ -148,5 +148,8 @@ "proseWrap": "always", "singleQuote": true, "trailingComma": "all" + }, + "dependencies": { + "@codecov/rollup-plugin": "^0.0.1-beta.0" } } diff --git a/packages/core/rollup.npm.config.mjs b/packages/core/rollup.npm.config.mjs index 84a06f2fb64a..d60703144758 100644 --- a/packages/core/rollup.npm.config.mjs +++ b/packages/core/rollup.npm.config.mjs @@ -1,3 +1,3 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '@sentry-internal/rollup-utils'; -export default makeNPMConfigVariants(makeBaseNPMConfig()); +export default makeNPMConfigVariants(makeBaseNPMConfig({ bundleAnalysis: 'npm:@sentry/core' })); diff --git a/yarn.lock b/yarn.lock index f618c7d7d485..bfb109cdc98a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2527,6 +2527,23 @@ exec-sh "^0.3.2" minimist "^1.2.0" +"@codecov/bundler-plugin-core@^0.0.1-beta.0": + version "0.0.1-beta.0" + resolved "https://registry.yarnpkg.com/@codecov/bundler-plugin-core/-/bundler-plugin-core-0.0.1-beta.0.tgz#b8c2bd4513c6d5ea5b2f1ca241b58b0d48a9453f" + integrity sha512-b3b2fZs9r9COefZEZYzGbLf0gab4HWKudwr6pkyUzXJEq061gIgQomeMxsBSRGVWkXtY6k9zzMDzkcVtj7A6GA== + dependencies: + chalk "4.1.2" + semver "^7.5.4" + unplugin "^1.6.0" + zod "^3.22.4" + +"@codecov/rollup-plugin@^0.0.1-beta.0": + version "0.0.1-beta.0" + resolved "https://registry.yarnpkg.com/@codecov/rollup-plugin/-/rollup-plugin-0.0.1-beta.0.tgz#6d9dd52f751053171fb1576702646d1b912916fc" + integrity sha512-W0a/k8KG7FC534F/C9QrsSgH9Q07xHgvMAFm6PoUMJBdvYR8FS0NhdtUuyQTuo/zYBIone8UCYWDxnQbvmjAbQ== + dependencies: + "@codecov/bundler-plugin-core" "^0.0.1-beta.0" + "@colors/colors@1.5.0": version "1.5.0" resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9" @@ -8086,6 +8103,11 @@ acorn@^8.10.0: resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.10.0.tgz#8be5b3907a67221a81ab23c7889c4c5526b62ec5" integrity sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw== +acorn@^8.11.3: + version "8.11.3" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.11.3.tgz#71e0b14e13a4ec160724b38fb7b0f233b1b81d7a" + integrity sha512-Y9rRfJG5jcKOE0CLisYbojUjIrIEE7AGMzA/Sm4BslANhbS+cDMpgBdcPT91oJ7OuJ9hYJBx59RjbhxVnrF8Xg== + acorn@^8.2.4, acorn@^8.4.1, acorn@^8.5.0, acorn@^8.7.0, acorn@^8.7.1: version "8.8.0" resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.0.tgz#88c0187620435c7f6015803f5539dae05a9dbea8" @@ -11368,6 +11390,14 @@ chalk@4.1.0: ansi-styles "^4.1.0" supports-color "^7.1.0" +chalk@4.1.2, chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0, chalk@^4.1.1, chalk@^4.1.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" + integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== + dependencies: + ansi-styles "^4.1.0" + supports-color "^7.1.0" + chalk@^1.0.0, chalk@^1.1.3: version "1.1.3" resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98" @@ -11379,14 +11409,6 @@ chalk@^1.0.0, chalk@^1.1.3: strip-ansi "^3.0.0" supports-color "^2.0.0" -chalk@^4.0.0, chalk@^4.0.2, chalk@^4.1.0, chalk@^4.1.1, chalk@^4.1.2: - version "4.1.2" - resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01" - integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA== - dependencies: - ansi-styles "^4.1.0" - supports-color "^7.1.0" - chalk@^5.0.0, chalk@^5.2.0, chalk@^5.3.0: version "5.3.0" resolved "https://registry.yarnpkg.com/chalk/-/chalk-5.3.0.tgz#67c20a7ebef70e7f3970a01f90fa210cb6860385" @@ -31618,6 +31640,16 @@ unplugin@1.0.1: webpack-sources "^3.2.3" webpack-virtual-modules "^0.5.0" +unplugin@^1.6.0: + version "1.7.1" + resolved "https://registry.yarnpkg.com/unplugin/-/unplugin-1.7.1.tgz#009571e3128640f4e327f33680d2db27afaf1e11" + integrity sha512-JqzORDAPxxs8ErLV4x+LL7bk5pk3YlcWqpSNsIkAZj972KzFZLClc/ekppahKkOczGkwIG6ElFgdOgOlK4tXZw== + dependencies: + acorn "^8.11.3" + chokidar "^3.5.3" + webpack-sources "^3.2.3" + webpack-virtual-modules "^0.6.1" + unquote@~1.1.1: version "1.1.1" resolved "https://registry.yarnpkg.com/unquote/-/unquote-1.1.1.tgz#8fded7324ec6e88a0ff8b905e7c098cdc086d544" @@ -32515,6 +32547,11 @@ webpack-virtual-modules@^0.5.0: resolved "https://registry.yarnpkg.com/webpack-virtual-modules/-/webpack-virtual-modules-0.5.0.tgz#362f14738a56dae107937ab98ea7062e8bdd3b6c" integrity sha512-kyDivFZ7ZM0BVOUteVbDFhlRt7Ah/CSPwJdi8hBpkK7QLumUqdLtVfm/PX/hkcnrvr0i77fO5+TjZ94Pe+C9iw== +webpack-virtual-modules@^0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/webpack-virtual-modules/-/webpack-virtual-modules-0.6.1.tgz#ac6fdb9c5adb8caecd82ec241c9631b7a3681b6f" + integrity sha512-poXpCylU7ExuvZK8z+On3kX+S8o/2dQ/SVYueKA0D4WEMXROXgY8Ez50/bQEUmvoSMMrWcrJqCHuhAbsiwg7Dg== + webpack@4.44.1: version "4.44.1" resolved "https://registry.yarnpkg.com/webpack/-/webpack-4.44.1.tgz#17e69fff9f321b8f117d1fda714edfc0b939cc21" From 0ec4059fc87d85c99e042ab285ee0e77815d895d Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Thu, 15 Feb 2024 13:27:39 -0500 Subject: [PATCH 2/3] node version --- .github/workflows/build.yml | 1 + dev-packages/e2e-tests/Dockerfile.publish-packages | 2 +- dev-packages/e2e-tests/package.json | 2 +- dev-packages/rollup-utils/npmHelpers.mjs | 3 --- dev-packages/rollup-utils/plugins/npmPlugins.mjs | 3 +-- package.json | 2 +- 6 files changed, 5 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ba48a87bb6f5..b80396030089 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,6 +23,7 @@ concurrency: env: HEAD_COMMIT: ${{ github.event.inputs.commit || github.sha }} + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} # WARNING: this disables cross os caching as ~ and # github.workspace evaluate to differents paths diff --git a/dev-packages/e2e-tests/Dockerfile.publish-packages b/dev-packages/e2e-tests/Dockerfile.publish-packages index 907f6655ca3d..4d5b2ba3abf3 100644 --- a/dev-packages/e2e-tests/Dockerfile.publish-packages +++ b/dev-packages/e2e-tests/Dockerfile.publish-packages @@ -1,5 +1,5 @@ # 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 -ARG NODE_VERSION=18.17.1 +ARG NODE_VERSION=18.18.0 FROM node:${NODE_VERSION} WORKDIR /sentry-javascript/dev-packages/e2e-tests diff --git a/dev-packages/e2e-tests/package.json b/dev-packages/e2e-tests/package.json index 1a583e39b848..abf0dd4f5769 100644 --- a/dev-packages/e2e-tests/package.json +++ b/dev-packages/e2e-tests/package.json @@ -26,7 +26,7 @@ "esbuild": "0.20.0" }, "volta": { - "node": "18.17.1", + "node": "18.18.0", "yarn": "1.22.19" } } diff --git a/dev-packages/rollup-utils/npmHelpers.mjs b/dev-packages/rollup-utils/npmHelpers.mjs index cdffcee86df6..19d3f2f8051f 100644 --- a/dev-packages/rollup-utils/npmHelpers.mjs +++ b/dev-packages/rollup-utils/npmHelpers.mjs @@ -124,9 +124,6 @@ export function makeBaseNPMConfig(options = {}) { } export function makeNPMConfigVariants(baseConfig) { - baseConfig.plugins = baseConfig.plugins || []; - baseConfig.plugins.push() - const variantSpecificConfigs = [ { output: { format: 'cjs', dir: path.join(baseConfig.output.dir, 'cjs') } }, { output: { format: 'esm', dir: path.join(baseConfig.output.dir, 'esm') } }, diff --git a/dev-packages/rollup-utils/plugins/npmPlugins.mjs b/dev-packages/rollup-utils/plugins/npmPlugins.mjs index 51b49d12773a..fd6703b0e519 100644 --- a/dev-packages/rollup-utils/plugins/npmPlugins.mjs +++ b/dev-packages/rollup-utils/plugins/npmPlugins.mjs @@ -136,12 +136,11 @@ export function makeRrwebBuildPlugin({ excludeShadowDom, excludeIframe } = {}) { * Plugin that uploads bundle analysis to codecov. */ export function makeCodeCovPlugin(bundleName) { - console.log(process.env.GITHUB_ACTIONS, process.env.CODECOV_TOKEN === undefined) return codecovRollupPlugin({ enableBundleAnalysis: process.env.GITHUB_ACTIONS === 'true' && process.env.CODECOV_TOKEN, bundleName, uploadToken: process.env.CODECOV_TOKEN, - }) + }); } export { makeExtractPolyfillsPlugin } from './extractPolyfillsPlugin.mjs'; diff --git a/package.json b/package.json index 171c70f1da69..66fdf096f088 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "yalc:publish": "lerna run yalc:publish" }, "volta": { - "node": "18.17.0", + "node": "18.18.0", "yarn": "1.22.19" }, "workspaces": [ From 256c89291ea4f4a99e449d6b1ec78b3a1daef986 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 20 Feb 2024 18:45:59 -0500 Subject: [PATCH 3/3] try uploading all bundles --- .github/workflows/build.yml | 4 +++- dev-packages/rollup-utils/bundleHelpers.mjs | 17 +++++++++++++++-- dev-packages/rollup-utils/npmHelpers.mjs | 7 ++++--- .../rollup-utils/plugins/npmPlugins.mjs | 15 ++++++++++++++- packages/nextjs/rollup.npm.config.mjs | 2 ++ packages/serverless/rollup.aws.config.mjs | 1 + 6 files changed, 39 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b80396030089..7d9b944b0444 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -23,7 +23,6 @@ concurrency: env: HEAD_COMMIT: ${{ github.event.inputs.commit || github.sha }} - CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} # WARNING: this disables cross os caching as ~ and # github.workspace evaluate to differents paths @@ -275,6 +274,9 @@ jobs: ${{needs.job_get_metadata.outputs.is_develop == 'false' && env.NX_CACHE_RESTORE_KEYS || 'nx-never-restore'}} - name: Build packages + # Set the CODECOV_TOKEN for Bundle Analysis + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} # Under normal circumstances, using the git SHA as a cache key, there shouldn't ever be a cache hit on the built # packages, and so `yarn build` should always run. This `if` check is therefore only there for testing CI issues # where the built packages are beside the point. In that case, you can change `BUILD_CACHE_KEY` (at the top of diff --git a/dev-packages/rollup-utils/bundleHelpers.mjs b/dev-packages/rollup-utils/bundleHelpers.mjs index 66bded3b62de..617ac1eab0b2 100644 --- a/dev-packages/rollup-utils/bundleHelpers.mjs +++ b/dev-packages/rollup-utils/bundleHelpers.mjs @@ -10,6 +10,7 @@ import { getEs5Polyfills, makeBrowserBuildPlugin, makeCleanupPlugin, + makeCodeCovPlugin, makeCommonJSPlugin, makeIsDebugBuildPlugin, makeLicensePlugin, @@ -152,7 +153,7 @@ export function makeBaseBundleConfig(options) { * @returns An array of versions of that config */ export function makeBundleConfigVariants(baseConfig, options = {}) { - const { variants = BUNDLE_VARIANTS } = options; + const { variants = BUNDLE_VARIANTS, bundleAnalysis = true } = options; const includeDebuggingPlugin = makeIsDebugBuildPlugin(true); const stripDebuggingPlugin = makeIsDebugBuildPlugin(false); @@ -183,7 +184,7 @@ export function makeBundleConfigVariants(baseConfig, options = {}) { }, }; - return variants.map(variant => { + const bundles = variants.map(variant => { if (!BUNDLE_VARIANTS.includes(variant)) { throw new Error(`Unknown bundle variant requested: ${variant}`); } @@ -193,4 +194,16 @@ export function makeBundleConfigVariants(baseConfig, options = {}) { customMerge: key => (key === 'plugins' ? mergePlugins : undefined), }); }); + + if (bundleAnalysis) { + bundles.forEach(bundle => { + try { + bundle.plugins.push(makeCodeCovPlugin(bundle.output.entryFileNames())); + } catch (_) { + // empty + } + }); + } + + return bundles; } diff --git a/dev-packages/rollup-utils/npmHelpers.mjs b/dev-packages/rollup-utils/npmHelpers.mjs index 19d3f2f8051f..04a976ce75d4 100644 --- a/dev-packages/rollup-utils/npmHelpers.mjs +++ b/dev-packages/rollup-utils/npmHelpers.mjs @@ -29,7 +29,8 @@ export function makeBaseNPMConfig(options = {}) { hasBundles = false, packageSpecificConfig = {}, addPolyfills = true, - bundleAnalysis, + bundleAnalysis = true, + bundleName, } = options; const nodeResolvePlugin = makeNodeResolvePlugin(); @@ -113,8 +114,8 @@ export function makeBaseNPMConfig(options = {}) { defaultBaseConfig.plugins.push(extractPolyfillsPlugin); } - if (bundleAnalysis && bundleAnalysis.length) { - defaultBaseConfig.plugins.push(makeCodeCovPlugin(bundleAnalysis)); + if (bundleAnalysis) { + defaultBaseConfig.plugins.push(makeCodeCovPlugin(bundleName)); } return deepMerge(defaultBaseConfig, packageSpecificConfig, { diff --git a/dev-packages/rollup-utils/plugins/npmPlugins.mjs b/dev-packages/rollup-utils/plugins/npmPlugins.mjs index fd6703b0e519..01756909d1e8 100644 --- a/dev-packages/rollup-utils/plugins/npmPlugins.mjs +++ b/dev-packages/rollup-utils/plugins/npmPlugins.mjs @@ -7,6 +7,9 @@ * Sucrase plugin docs: https://github.com/rollup/plugins/tree/master/packages/sucrase */ +import * as fs from 'fs'; +import * as path from 'path'; + import { codecovRollupPlugin } from '@codecov/rollup-plugin'; import replace from '@rollup/plugin-replace'; import sucrase from '@rollup/plugin-sucrase'; @@ -134,8 +137,18 @@ export function makeRrwebBuildPlugin({ excludeShadowDom, excludeIframe } = {}) { /** * Plugin that uploads bundle analysis to codecov. + * + * @param type The type of bundle being uploaded. + * @param prefix The prefix for the codecov bundle name. Defaults to 'npm'. */ -export function makeCodeCovPlugin(bundleName) { +export function makeCodeCovPlugin(suffix) { + const packageJson = JSON.parse(fs.readFileSync(path.resolve(process.cwd(), './package.json'), { encoding: 'utf8' })); + + let bundleName = packageJson.name; + if (suffix != undefined) { + bundleName += `:${suffix}`; + } + return codecovRollupPlugin({ enableBundleAnalysis: process.env.GITHUB_ACTIONS === 'true' && process.env.CODECOV_TOKEN, bundleName, diff --git a/packages/nextjs/rollup.npm.config.mjs b/packages/nextjs/rollup.npm.config.mjs index 39b79c9593b2..0ccd1590ddba 100644 --- a/packages/nextjs/rollup.npm.config.mjs +++ b/packages/nextjs/rollup.npm.config.mjs @@ -23,6 +23,7 @@ export default [ ), ...makeNPMConfigVariants( makeBaseNPMConfig({ + bundleName: 'config', entrypoints: [ 'src/config/templates/apiWrapperTemplate.ts', 'src/config/templates/middlewareWrapperTemplate.ts', @@ -58,6 +59,7 @@ export default [ ), ...makeNPMConfigVariants( makeBaseNPMConfig({ + bundleName: 'loaders', entrypoints: ['src/config/loaders/index.ts'], packageSpecificConfig: { diff --git a/packages/serverless/rollup.aws.config.mjs b/packages/serverless/rollup.aws.config.mjs index 5d9883a3f9f7..1e7550933cc5 100644 --- a/packages/serverless/rollup.aws.config.mjs +++ b/packages/serverless/rollup.aws.config.mjs @@ -27,6 +27,7 @@ export default [ // launches (via the `NODE_OPTIONS="-r @sentry/serverless/dist/awslambda-auto"` variable). Note the inclusion in this // path of the legacy `dist` folder; for backwards compatibility, in the build script we'll copy the file there. makeBaseNPMConfig({ + bundleName: 'awslambda-auto', entrypoints: ['src/awslambda-auto.ts'], packageSpecificConfig: { // Normally `makeNPMConfigVariants` sets both of these values for us, but we don't actually want the ESM variant,