From 27247de7e9969b4ae414a2fd3410a47beeaac0e4 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Tue, 25 Apr 2023 16:11:57 +0200 Subject: [PATCH 1/3] build: Build core & utils into a single output file This may speed up usage, as it avoids some potentially expensive require/import calls. --- packages/core/rollup.npm.config.js | 11 +++++++- packages/utils/package.json | 6 ++--- packages/utils/rollup.npm.config.js | 25 +++++++++++++++++-- .../{buildRollup.ts => fixPolyfillsBuild.ts} | 15 ++--------- 4 files changed, 38 insertions(+), 19 deletions(-) rename packages/utils/scripts/{buildRollup.ts => fixPolyfillsBuild.ts} (62%) diff --git a/packages/core/rollup.npm.config.js b/packages/core/rollup.npm.config.js index 5a62b528ef44..4da05b01c503 100644 --- a/packages/core/rollup.npm.config.js +++ b/packages/core/rollup.npm.config.js @@ -1,3 +1,12 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js'; -export default makeNPMConfigVariants(makeBaseNPMConfig()); +export default makeNPMConfigVariants( + makeBaseNPMConfig({ + packageSpecificConfig: { + output: { + // Combine output into a single file to avoid expensive require/import calls + preserveModules: false, + }, + }, + }), +); diff --git a/packages/utils/package.json b/packages/utils/package.json index de28673548ca..c9da1d9a486f 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -25,10 +25,10 @@ "chai": "^4.1.2" }, "scripts": { - "build": "run-p build:transpile build:types", + "build": "run-p build:transpile:uncached build:types", "build:dev": "yarn build", - "build:transpile": "yarn ts-node scripts/buildRollup.ts", - "build:transpile:uncached": "yarn ts-node scripts/buildRollup.ts", + "build:transpile": "yarn rollup -c rollup.npm.config.js", + "build:transpile:uncached": "yarn build:transpile && yarn ts-node scripts/fixPolyfillsBuild.ts", "build:types": "tsc -p tsconfig.types.json", "build:watch": "run-p build:transpile:watch build:types:watch", "build:dev:watch": "yarn build:watch", diff --git a/packages/utils/rollup.npm.config.js b/packages/utils/rollup.npm.config.js index dcf32469a4e4..ae5dfdc610aa 100644 --- a/packages/utils/rollup.npm.config.js +++ b/packages/utils/rollup.npm.config.js @@ -1,9 +1,30 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js'; -export default makeNPMConfigVariants( +const baseVariants = makeNPMConfigVariants( + makeBaseNPMConfig({ + entrypoints: ['src/index.ts'], + packageSpecificConfig: { + output: { + // Combine output into a single file to avoid expensive require/import calls + preserveModules: false, + }, + }, + }), +); + +const polyfillVariants = makeNPMConfigVariants( makeBaseNPMConfig({ // We build the polyfills separately because they're not included in the top-level exports of the package, in order // to keep them out of the public API. - entrypoints: ['src/index.ts', 'src/buildPolyfills/index.ts'], + entrypoints: ['src/buildPolyfills/index.ts'], + packageSpecificConfig: { + output: { + entryFileNames: () => 'buildPolyfills.js', + // Combine output into a single file to avoid expensive require/import calls + preserveModules: false, + }, + }, }), ); + +export default baseVariants.concat(polyfillVariants); diff --git a/packages/utils/scripts/buildRollup.ts b/packages/utils/scripts/fixPolyfillsBuild.ts similarity index 62% rename from packages/utils/scripts/buildRollup.ts rename to packages/utils/scripts/fixPolyfillsBuild.ts index f48b0b23d6d9..cf233edc24ef 100644 --- a/packages/utils/scripts/buildRollup.ts +++ b/packages/utils/scripts/fixPolyfillsBuild.ts @@ -1,19 +1,8 @@ -import * as childProcess from 'child_process'; import * as fs from 'fs'; -/** - * Run the given shell command, piping the shell process's `stdin`, `stdout`, and `stderr` to that of the current - * process. Returns contents of `stdout`. - */ -function run(cmd: string, options?: childProcess.ExecSyncOptions): string | Buffer { - return childProcess.execSync(cmd, { stdio: 'inherit', ...options }); -} - -run('yarn rollup -c rollup.npm.config.js'); - // We want to distribute the README because it contains the MIT license blurb from Sucrase and Rollup -fs.copyFileSync('src/buildPolyfills/README.md', 'build/cjs/buildPolyfills/README.md'); -fs.copyFileSync('src/buildPolyfills/README.md', 'build/esm/buildPolyfills/README.md'); +fs.copyFileSync('src/buildPolyfills/README.md', 'build/cjs/buildPolyfills_README.md'); +fs.copyFileSync('src/buildPolyfills/README.md', 'build/esm/buildPolyfills_README.md'); // Because we import our polyfills from `@sentry/utils/cjs/buildPolyfills` and `@sentry/utils/esm/buildPolyfills` rather // than straight from `@sentry/utils` (so as to avoid having them in the package's public API), when tests run, they'll From 2cf1ea8ccdda7a4073e4749484f1bb29080a81fe Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Tue, 25 Apr 2023 16:43:09 +0200 Subject: [PATCH 2/3] build: Disable `preserveModules` for tracing-internal & browser --- packages/browser/rollup.npm.config.js | 6 ++++++ packages/tracing-internal/rollup.npm.config.js | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/browser/rollup.npm.config.js b/packages/browser/rollup.npm.config.js index 4ffa8b9396d8..30f7f0acdbd9 100644 --- a/packages/browser/rollup.npm.config.js +++ b/packages/browser/rollup.npm.config.js @@ -4,5 +4,11 @@ export default makeNPMConfigVariants( makeBaseNPMConfig({ // packages with bundles have a different build directory structure hasBundles: true, + packageSpecificConfig: { + output: { + // Combine output into a single file to avoid expensive require/import calls + preserveModules: false, + }, + }, }), ); diff --git a/packages/tracing-internal/rollup.npm.config.js b/packages/tracing-internal/rollup.npm.config.js index 5a62b528ef44..4da05b01c503 100644 --- a/packages/tracing-internal/rollup.npm.config.js +++ b/packages/tracing-internal/rollup.npm.config.js @@ -1,3 +1,12 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js'; -export default makeNPMConfigVariants(makeBaseNPMConfig()); +export default makeNPMConfigVariants( + makeBaseNPMConfig({ + packageSpecificConfig: { + output: { + // Combine output into a single file to avoid expensive require/import calls + preserveModules: false, + }, + }, + }), +); From 0351a0fca690ba37ea53ab3fa1a91cd33ec50c81 Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Tue, 25 Apr 2023 16:43:09 +0200 Subject: [PATCH 3/3] Revert "build: Disable `preserveModules` for tracing-internal & browser" This reverts commit 2cf1ea8ccdda7a4073e4749484f1bb29080a81fe. --- packages/browser/rollup.npm.config.js | 6 ------ packages/tracing-internal/rollup.npm.config.js | 11 +---------- 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/packages/browser/rollup.npm.config.js b/packages/browser/rollup.npm.config.js index 30f7f0acdbd9..4ffa8b9396d8 100644 --- a/packages/browser/rollup.npm.config.js +++ b/packages/browser/rollup.npm.config.js @@ -4,11 +4,5 @@ export default makeNPMConfigVariants( makeBaseNPMConfig({ // packages with bundles have a different build directory structure hasBundles: true, - packageSpecificConfig: { - output: { - // Combine output into a single file to avoid expensive require/import calls - preserveModules: false, - }, - }, }), ); diff --git a/packages/tracing-internal/rollup.npm.config.js b/packages/tracing-internal/rollup.npm.config.js index 4da05b01c503..5a62b528ef44 100644 --- a/packages/tracing-internal/rollup.npm.config.js +++ b/packages/tracing-internal/rollup.npm.config.js @@ -1,12 +1,3 @@ import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js'; -export default makeNPMConfigVariants( - makeBaseNPMConfig({ - packageSpecificConfig: { - output: { - // Combine output into a single file to avoid expensive require/import calls - preserveModules: false, - }, - }, - }), -); +export default makeNPMConfigVariants(makeBaseNPMConfig());