Skip to content

Commit 27247de

Browse files
committed
build: Build core & utils into a single output file
This may speed up usage, as it avoids some potentially expensive require/import calls.
1 parent 8b97f80 commit 27247de

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

packages/core/rollup.npm.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js';
22

3-
export default makeNPMConfigVariants(makeBaseNPMConfig());
3+
export default makeNPMConfigVariants(
4+
makeBaseNPMConfig({
5+
packageSpecificConfig: {
6+
output: {
7+
// Combine output into a single file to avoid expensive require/import calls
8+
preserveModules: false,
9+
},
10+
},
11+
}),
12+
);

packages/utils/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
"chai": "^4.1.2"
2626
},
2727
"scripts": {
28-
"build": "run-p build:transpile build:types",
28+
"build": "run-p build:transpile:uncached build:types",
2929
"build:dev": "yarn build",
30-
"build:transpile": "yarn ts-node scripts/buildRollup.ts",
31-
"build:transpile:uncached": "yarn ts-node scripts/buildRollup.ts",
30+
"build:transpile": "yarn rollup -c rollup.npm.config.js",
31+
"build:transpile:uncached": "yarn build:transpile && yarn ts-node scripts/fixPolyfillsBuild.ts",
3232
"build:types": "tsc -p tsconfig.types.json",
3333
"build:watch": "run-p build:transpile:watch build:types:watch",
3434
"build:dev:watch": "yarn build:watch",
Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
11
import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js';
22

3-
export default makeNPMConfigVariants(
3+
const baseVariants = makeNPMConfigVariants(
4+
makeBaseNPMConfig({
5+
entrypoints: ['src/index.ts'],
6+
packageSpecificConfig: {
7+
output: {
8+
// Combine output into a single file to avoid expensive require/import calls
9+
preserveModules: false,
10+
},
11+
},
12+
}),
13+
);
14+
15+
const polyfillVariants = makeNPMConfigVariants(
416
makeBaseNPMConfig({
517
// We build the polyfills separately because they're not included in the top-level exports of the package, in order
618
// to keep them out of the public API.
7-
entrypoints: ['src/index.ts', 'src/buildPolyfills/index.ts'],
19+
entrypoints: ['src/buildPolyfills/index.ts'],
20+
packageSpecificConfig: {
21+
output: {
22+
entryFileNames: () => 'buildPolyfills.js',
23+
// Combine output into a single file to avoid expensive require/import calls
24+
preserveModules: false,
25+
},
26+
},
827
}),
928
);
29+
30+
export default baseVariants.concat(polyfillVariants);

packages/utils/scripts/buildRollup.ts renamed to packages/utils/scripts/fixPolyfillsBuild.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,8 @@
1-
import * as childProcess from 'child_process';
21
import * as fs from 'fs';
32

4-
/**
5-
* Run the given shell command, piping the shell process's `stdin`, `stdout`, and `stderr` to that of the current
6-
* process. Returns contents of `stdout`.
7-
*/
8-
function run(cmd: string, options?: childProcess.ExecSyncOptions): string | Buffer {
9-
return childProcess.execSync(cmd, { stdio: 'inherit', ...options });
10-
}
11-
12-
run('yarn rollup -c rollup.npm.config.js');
13-
143
// We want to distribute the README because it contains the MIT license blurb from Sucrase and Rollup
15-
fs.copyFileSync('src/buildPolyfills/README.md', 'build/cjs/buildPolyfills/README.md');
16-
fs.copyFileSync('src/buildPolyfills/README.md', 'build/esm/buildPolyfills/README.md');
4+
fs.copyFileSync('src/buildPolyfills/README.md', 'build/cjs/buildPolyfills_README.md');
5+
fs.copyFileSync('src/buildPolyfills/README.md', 'build/esm/buildPolyfills_README.md');
176

187
// Because we import our polyfills from `@sentry/utils/cjs/buildPolyfills` and `@sentry/utils/esm/buildPolyfills` rather
198
// than straight from `@sentry/utils` (so as to avoid having them in the package's public API), when tests run, they'll

0 commit comments

Comments
 (0)