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