Skip to content

Commit 7f35773

Browse files
committed
handle polyfills when building
1 parent dbc7cc3 commit 7f35773

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

packages/utils/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"build:dev": "run-s build",
2929
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
3030
"build:esm": "tsc -p tsconfig.esm.json",
31-
"build:rollup": "rollup -c rollup.npm.config.js",
31+
"build:rollup": "yarn ts-node scripts/buildRollup.ts",
3232
"build:types": "tsc -p tsconfig.types.json",
3333
"build:watch": "run-p build:cjs:watch build:esm:watch build:types:watch",
3434
"build:cjs:watch": "tsc -p tsconfig.cjs.json --watch",

packages/utils/rollup.npm.config.js

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

3-
export default makeNPMConfigVariants(makeBaseNPMConfig());
3+
export default makeNPMConfigVariants(
4+
makeBaseNPMConfig({
5+
// We build the polyfills separately because they're not included in the top-level exports of the package, in order
6+
// to keep them out of the public API.
7+
entrypoints: ['src/index.ts', 'src/buildPolyfills/index.ts'],
8+
}),
9+
);

packages/utils/scripts/buildRollup.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import * as childProcess from 'child_process';
2+
import * as fs from 'fs';
3+
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+
14+
// 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');
17+
18+
// Because we import our polyfills from `@sentry/utils/cjs/buildPolyfills` and `@sentry/utils/esm/buildPolyfills` rather
19+
// than straight from `@sentry/utils` (so as to avoid having them in the package's public API), when tests run, they'll
20+
// expect to find `cjs` and `esm` at the root level of the repo.
21+
fs.symlinkSync('build/cjs', 'cjs');
22+
fs.symlinkSync('build/esm', 'esm');

0 commit comments

Comments
 (0)