diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ba48a87bb6f5..7d9b944b0444 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -274,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/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/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 6085a502200f..04a976ce75d4 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,8 @@ export function makeBaseNPMConfig(options = {}) { hasBundles = false, packageSpecificConfig = {}, addPolyfills = true, + bundleAnalysis = true, + bundleName, } = options; const nodeResolvePlugin = makeNodeResolvePlugin(); @@ -111,6 +114,10 @@ export function makeBaseNPMConfig(options = {}) { defaultBaseConfig.plugins.push(extractPolyfillsPlugin); } + if (bundleAnalysis) { + defaultBaseConfig.plugins.push(makeCodeCovPlugin(bundleName)); + } + 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), diff --git a/dev-packages/rollup-utils/plugins/npmPlugins.mjs b/dev-packages/rollup-utils/plugins/npmPlugins.mjs index 507480c1dd43..01756909d1e8 100644 --- a/dev-packages/rollup-utils/plugins/npmPlugins.mjs +++ b/dev-packages/rollup-utils/plugins/npmPlugins.mjs @@ -7,6 +7,10 @@ * 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'; import cleanup from 'rollup-plugin-cleanup'; @@ -131,4 +135,25 @@ 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(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, + uploadToken: process.env.CODECOV_TOKEN, + }); +} + export { makeExtractPolyfillsPlugin } from './extractPolyfillsPlugin.mjs'; diff --git a/package.json b/package.json index 9ecacd34c252..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": [ @@ -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/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, 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"