Skip to content

Commit f715933

Browse files
authored
ref(build): Use rollup/sucrase for non-watch npm builds (#5035)
This switches our `build` and `build:dev` yarn scripts to use the new rollup/sucrase build process. This is the culmination of a number of previous changes, whose highlights include: - #4724, which made building types files a separate build process - #4895, which updated the SDK to use TS 3.8.3 - #4926, which removed use of the `Severity` enum - #5005, which switch our default tsconfig to target es6 - #4992, which added the Sucrase plugin, some helper functions, and the `yarn build:rollup` script - #4993, which added rollup plugins to use `var` rather than `const` and clean up the built code in various ways - #5022, which applied the same `const`-to-`var` translation to tests - #5023, which added the ability to change injected polyfills into imports The result is that, as of this PR, we will no longer use `tsc` to transpile or down-complile our code when building npm packages. Instead, we will be using Rollup to handle making our code CJS-friendlly and Sucrase to handle the transpilation from TS to JS. The main advantages of this change are: - It forced us to do a lot of updating, centralizing, and cleanup of our tooling, not just for build but also for testing and linting. - It brings our CDN build process and our npm build process much more in line with each other, for easier maintainability. - It gives us more control over the eventual output, because we have access to a whole internet full of Rollup plugins (not to mention the ability to make our own), rather than being constrained to tsconfig options. (Plugins also allow us to interact with the code directly.) - It speeds up our builds fairly significantly. I ran a number of trials in GHA of running `yarn build:dev` at the top level of the repo. Before this change, the average time was ~150 seconds. After this change, it's about half that, roughly 75 seconds. Because of the switch in tooling, the code we publish is going to be slightly different. In order to make sure that those differences weren't going to be breaking, I built each package under the old system and under the new system, ran a `git diff`, and checked every file, both CJS and ESM, in every package affected by this change. The differences (none of which affect behavior or eventual bundle size by more than a few bytes in each direction), fell into a few categories: - Purely cosmetic changes, things like which comments are retained, the order of imports, where in the file exports live, etc. - Changes to class constructors, things like not explicitly assigning `undefined` to undefined attributes, using regular assignment rather than `Object.defineProperty` for attributes which are assigned values, and splitting some of those assignments off into helper functions. - Changes related to the upgrade to ES6 and dropping of support for Node 6, things like not polyfilling object spread or async/await While this represents the most significant part of the overall change, a few outstanding tasks remain: - Making this same switch in `build:watch` - Parallelizing the builds, both locally and in CI - Perhaps applying the new process to our CDN bundle builds - Generalized cleanup These will all be included in separate PRs, some in the immediate future and some in the hopefully-not-too-distant short-to-medium term.
1 parent 94554b3 commit f715933

File tree

17 files changed

+23
-361
lines changed

17 files changed

+23
-361
lines changed

.github/workflows/build.yml

-277
Original file line numberDiff line numberDiff line change
@@ -256,8 +256,6 @@ jobs:
256256
NODE_VERSION: ${{ matrix.node }}
257257
run: |
258258
[[ $NODE_VERSION == 8 ]] && yarn add --dev --ignore-engines --ignore-scripts --ignore-workspace-root-check ts-node@8.x
259-
# TODO remove this when we switch to sucrase
260-
yarn ts-node scripts/sucrase-test-hack.ts
261259
yarn test-ci
262260
- name: Compute test coverage
263261
uses: codecov/codecov-action@v1
@@ -494,278 +492,3 @@ jobs:
494492
run: |
495493
cd packages/node-integration-tests
496494
yarn test
497-
498-
job_unit_test_sucrase:
499-
name: Sucrase Test (Node ${{ matrix.node }})
500-
needs: job_build
501-
continue-on-error: true
502-
timeout-minutes: 30
503-
runs-on: ubuntu-latest
504-
strategy:
505-
matrix:
506-
node: [8, 10, 12, 14, 16]
507-
steps:
508-
- name: Check out current commit (${{ env.HEAD_COMMIT }})
509-
uses: actions/checkout@v2
510-
with:
511-
ref: ${{ env.HEAD_COMMIT }}
512-
- name: Set up Node
513-
uses: actions/setup-node@v1
514-
with:
515-
node-version: ${{ matrix.node }}
516-
- name: Check dependency cache
517-
uses: actions/cache@v2
518-
with:
519-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
520-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
521-
- name: Check build cache
522-
uses: actions/cache@v2
523-
with:
524-
path: ${{ env.CACHED_BUILD_PATHS }}
525-
key: ${{ env.BUILD_CACHE_KEY }}
526-
- name: Run tests
527-
env:
528-
NODE_VERSION: ${{ matrix.node }}
529-
SUCRASE: true
530-
run: |
531-
[[ $NODE_VERSION == 8 ]] && yarn add --dev --ignore-engines --ignore-scripts --ignore-workspace-root-check ts-node@8.x rollup@2.2.0 @rollup/plugin-node-resolve@10.x rollup-plugin-terser@5.0.0 rollup-plugin-typescript2@0.30.0
532-
yarn ts-node scripts/sucrase-test-hack.ts
533-
yarn test-ci
534-
- name: Compute test coverage
535-
uses: codecov/codecov-action@v1
536-
537-
job_nextjs_integration_test_sucrase:
538-
name: Sucrase Test @sentry/nextjs on (Node ${{ matrix.node }})
539-
needs: job_build
540-
continue-on-error: true
541-
timeout-minutes: 30
542-
runs-on: ubuntu-latest
543-
strategy:
544-
matrix:
545-
node: [10, 12, 14, 16]
546-
steps:
547-
- name: Check out current commit (${{ env.HEAD_COMMIT }})
548-
uses: actions/checkout@v2
549-
with:
550-
ref: ${{ env.HEAD_COMMIT }}
551-
- name: Set up Node
552-
uses: actions/setup-node@v1
553-
with:
554-
node-version: ${{ matrix.node }}
555-
- name: Check dependency cache
556-
uses: actions/cache@v2
557-
with:
558-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
559-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
560-
- name: Check build cache
561-
uses: actions/cache@v2
562-
with:
563-
path: ${{ env.CACHED_BUILD_PATHS }}
564-
key: ${{ env.BUILD_CACHE_KEY }}
565-
- name: Run tests
566-
env:
567-
NODE_VERSION: ${{ matrix.node }}
568-
run: |
569-
yarn ts-node scripts/sucrase-test-hack.ts
570-
cd packages/nextjs
571-
yarn test:integration
572-
573-
# Ember tests are separate from the rest because they are the slowest part of the test suite, and making them a
574-
# separate job allows them to run in parallel with the other tests.
575-
job_ember_tests_sucrase:
576-
name: Sucrase Test @sentry/ember
577-
needs: job_build
578-
continue-on-error: true
579-
timeout-minutes: 30
580-
runs-on: ubuntu-latest
581-
steps:
582-
- name: Check out current commit (${{ env.HEAD_COMMIT }})
583-
uses: actions/checkout@v2
584-
with:
585-
ref: ${{ env.HEAD_COMMIT }}
586-
# TODO: removing `fetch-depth` below seems to have no effect, and the commit which added it had no description,
587-
# so it's not clear why it's necessary. That said, right now ember tests are xfail, so it's a little hard to
588-
# tell if it's safe to remove. Once ember tests are fixed, let's try again with it turned off, and if all goes
589-
# well, we can pull it out.
590-
fetch-depth: 0
591-
- name: Set up Node
592-
uses: actions/setup-node@v1
593-
with:
594-
# The only danger with Ember in terms of Node versions is that the build tool, ember-cli, won't work if Node
595-
# is too old. Since Oct 2019, Node 10 has been the oldest version supported by ember-cli, so test against
596-
# that. If it passes, newer versions of Node should also be fine. This saves us from having to run the Ember
597-
# tests in our Node matrix above.
598-
node-version: '10'
599-
- name: Check dependency cache
600-
uses: actions/cache@v2
601-
with:
602-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
603-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
604-
- name: Check build cache
605-
uses: actions/cache@v2
606-
with:
607-
path: ${{ env.CACHED_BUILD_PATHS }}
608-
key: ${{ env.BUILD_CACHE_KEY }}
609-
- name: Run Ember tests
610-
run: |
611-
yarn ts-node scripts/sucrase-test-hack.ts
612-
yarn test --scope=@sentry/ember
613-
- name: Compute test coverage
614-
uses: codecov/codecov-action@v1
615-
616-
job_browser_playwright_tests_sucrase:
617-
name: Sucrase Playwright - ${{ (matrix.tracing_only && 'Browser + Tracing') || 'Browser' }} (${{ matrix.bundle }})
618-
needs: job_build
619-
runs-on: ubuntu-latest
620-
strategy:
621-
matrix:
622-
bundle:
623-
- esm
624-
- cjs
625-
tracing_only:
626-
- true
627-
- false
628-
exclude:
629-
# `tracing_only` only makes a difference for bundles - tests of the esm and cjs builds always include the
630-
# tracing tests
631-
- bundle: esm
632-
tracing_only: false
633-
- bundle: cjs
634-
tracing_only: false
635-
steps:
636-
- name: Check out current commit (${{ env.HEAD_COMMIT }})
637-
uses: actions/checkout@v2
638-
with:
639-
ref: ${{ env.HEAD_COMMIT }}
640-
- name: Set up Node
641-
uses: actions/setup-node@v1
642-
with:
643-
node-version: '16'
644-
- name: Check dependency cache
645-
uses: actions/cache@v2
646-
with:
647-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
648-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
649-
- name: Check build cache
650-
uses: actions/cache@v2
651-
with:
652-
path: ${{ env.CACHED_BUILD_PATHS }}
653-
key: ${{ env.BUILD_CACHE_KEY }}
654-
- name: Run Playwright tests
655-
env:
656-
PW_BUNDLE: ${{ matrix.bundle }}
657-
PW_TRACING_ONLY: ${{ matrix.tracing_only }}
658-
run: |
659-
yarn ts-node scripts/sucrase-test-hack.ts
660-
cd packages/integration-tests
661-
yarn run playwright install-deps webkit
662-
yarn test:ci
663-
664-
job_browser_integration_tests_sucrase:
665-
name: Sucrase Old Browser Integration Tests (${{ matrix.browser }})
666-
needs: job_build
667-
runs-on: ubuntu-latest
668-
timeout-minutes: 10
669-
continue-on-error: true
670-
strategy:
671-
matrix:
672-
browser:
673-
- ChromeHeadless
674-
- FirefoxHeadless
675-
- WebkitHeadless
676-
steps:
677-
- name: Check out current commit (${{ env.HEAD_COMMIT }})
678-
uses: actions/checkout@v2
679-
with:
680-
ref: ${{ env.HEAD_COMMIT }}
681-
- name: Set up Node
682-
uses: actions/setup-node@v1
683-
- name: Check dependency cache
684-
uses: actions/cache@v2
685-
with:
686-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
687-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
688-
- name: Check build cache
689-
uses: actions/cache@v2
690-
with:
691-
path: ${{ env.CACHED_BUILD_PATHS }}
692-
key: ${{ env.BUILD_CACHE_KEY }}
693-
- name: Run integration tests
694-
env:
695-
KARMA_BROWSER: ${{ matrix.browser }}
696-
run: |
697-
yarn ts-node scripts/sucrase-test-hack.ts
698-
cd packages/browser
699-
[[ $KARMA_BROWSER == WebkitHeadless ]] && yarn run playwright install-deps webkit
700-
yarn test:integration
701-
702-
job_browser_build_tests_sucrase:
703-
name: Sucrase Browser Build Tests
704-
needs: job_build
705-
runs-on: ubuntu-latest
706-
timeout-minutes: 5
707-
continue-on-error: true
708-
steps:
709-
- name: Check out current commit (${ env.HEAD_COMMIT }})
710-
uses: actions/checkout@v2
711-
with:
712-
ref: ${{ env.HEAD_COMMIT }}
713-
- name: Set up Node
714-
uses: actions/setup-node@v1
715-
with:
716-
node-version: '16'
717-
- name: Check dependency cache
718-
uses: actions/cache@v2
719-
with:
720-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
721-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
722-
- name: Check build cache
723-
uses: actions/cache@v2
724-
with:
725-
path: ${{ env.CACHED_BUILD_PATHS }}
726-
key: ${{ env.BUILD_CACHE_KEY }}
727-
- name: Run browser build tests
728-
run: |
729-
yarn ts-node scripts/sucrase-test-hack.ts
730-
cd packages/browser
731-
yarn test:package
732-
- name: Run utils build tests
733-
run: |
734-
cd packages/utils
735-
yarn test:package
736-
737-
job_node_integration_tests_sucrase:
738-
name: Sucrase Node SDK Integration Tests (${{ matrix.node }})
739-
needs: job_build
740-
runs-on: ubuntu-latest
741-
timeout-minutes: 10
742-
continue-on-error: true
743-
strategy:
744-
matrix:
745-
node: [10, 12, 14, 16]
746-
steps:
747-
- name: Check out current commit (${{ github.sha }})
748-
uses: actions/checkout@v2
749-
with:
750-
ref: ${{ env.HEAD_COMMIT }}
751-
- name: Set up Node
752-
uses: actions/setup-node@v1
753-
with:
754-
node-version: ${{ matrix.node }}
755-
- name: Check dependency cache
756-
uses: actions/cache@v2
757-
with:
758-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
759-
key: ${{ needs.job_build.outputs.dependency_cache_key }}
760-
- name: Check build cache
761-
uses: actions/cache@v2
762-
with:
763-
path: ${{ env.CACHED_BUILD_PATHS }}
764-
key: ${{ env.BUILD_CACHE_KEY }}
765-
- name: Run integration tests
766-
env:
767-
NODE_VERSION: ${{ matrix.node }}
768-
run: |
769-
yarn ts-node scripts/sucrase-test-hack.ts
770-
cd packages/node-integration-tests
771-
yarn test

packages/browser/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
"webpack": "^4.30.0"
4444
},
4545
"scripts": {
46-
"build": "run-p build:cjs build:esm build:bundle build:types",
46+
"build": "run-p build:rollup build:bundle build:types",
4747
"build:bundle": "rollup --config rollup.bundle.config.js",
4848
"build:cjs": "tsc -p tsconfig.cjs.json",
49-
"build:dev": "run-p build:cjs build:esm build:types",
49+
"build:dev": "run-p build:rollup build:types",
5050
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
5151
"build:esm": "tsc -p tsconfig.esm.json",
5252
"build:rollup": "rollup -c rollup.npm.config.js",

packages/core/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"tslib": "^1.9.3"
2323
},
2424
"scripts": {
25-
"build": "run-p build:cjs build:esm build:types",
25+
"build": "run-p build:rollup build:types",
2626
"build:cjs": "tsc -p tsconfig.cjs.json",
2727
"build:dev": "run-s build",
2828
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",

packages/gatsby/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"react": "^18.0.0"
3636
},
3737
"scripts": {
38-
"build": "run-p build:cjs build:esm build:types build:plugin",
38+
"build": "run-p build:rollup build:types build:plugin",
3939
"build:cjs": "tsc -p tsconfig.cjs.json",
4040
"build:dev": "run-s build",
4141
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",

packages/hub/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"tslib": "^1.9.3"
2222
},
2323
"scripts": {
24-
"build": "run-p build:cjs build:esm build:types",
24+
"build": "run-p build:rollup build:types",
2525
"build:cjs": "tsc -p tsconfig.cjs.json",
2626
"build:dev": "run-s build",
2727
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",

packages/integrations/package.json

+2-2
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:cjs build:esm build:types build:bundle",
28+
"build": "run-p build:rollup build:types build:bundle",
2929
"build:bundle": "bash scripts/buildBundles.sh",
3030
"build:cjs": "tsc -p tsconfig.cjs.json",
31-
"build:dev": "run-p build:cjs build:esm build:types",
31+
"build:dev": "run-p build:rollup build:types",
3232
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
3333
"build:esm": "tsc -p tsconfig.esm.json",
3434
"build:rollup": "rollup -c rollup.npm.config.js",

packages/nextjs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
}
4444
},
4545
"scripts": {
46-
"build": "run-p build:cjs build:esm build:types",
46+
"build": "run-p build:rollup build:types",
4747
"build:cjs": "tsc -p tsconfig.cjs.json",
4848
"build:dev": "run-s build",
4949
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",

packages/node/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"nock": "^13.0.5"
3535
},
3636
"scripts": {
37-
"build": "run-p build:cjs build:esm build:types",
37+
"build": "run-p build:rollup build:types",
3838
"build:cjs": "tsc -p tsconfig.cjs.json",
3939
"build:dev": "run-s build",
4040
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",

packages/react/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"redux": "^4.0.5"
4848
},
4949
"scripts": {
50-
"build": "run-p build:cjs build:esm build:types",
50+
"build": "run-p build:rollup build:types",
5151
"build:cjs": "tsc -p tsconfig.cjs.json",
5252
"build:dev": "run-s build",
5353
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",

packages/serverless/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@
3838
"read-pkg": "^5.2.0"
3939
},
4040
"scripts": {
41-
"build": "run-p build:cjs build:esm build:types && yarn build:awslambda-layer",
41+
"build": "run-p build:rollup build:types && yarn build:awslambda-layer",
4242
"build:awslambda-layer": "node scripts/build-awslambda-layer.js",
4343
"build:cjs": "tsc -p tsconfig.cjs.json",
44-
"build:dev": "run-p build:cjs build:esm build:types",
44+
"build:dev": "run-p build:rollup build:types",
4545
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
4646
"build:esm": "tsc -p tsconfig.esm.json",
4747
"build:rollup": "rollup -c rollup.npm.config.js",

packages/tracing/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626
"@types/express": "^4.17.1"
2727
},
2828
"scripts": {
29-
"build": "run-p build:cjs build:esm build:types build:bundle && ts-node ../../scripts/prepack.ts --bundles #necessary for integration tests",
29+
"build": "run-p build:rollup build:types build:bundle && ts-node ../../scripts/prepack.ts --bundles #necessary for integration tests",
3030
"build:bundle": "rollup --config rollup.bundle.config.js",
3131
"build:cjs": "tsc -p tsconfig.cjs.json",
32-
"build:dev": "run-p build:cjs build:esm build:types",
32+
"build:dev": "run-p build:rollup build:types",
3333
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
3434
"build:esm": "tsc -p tsconfig.esm.json",
3535
"build:rollup": "rollup -c rollup.npm.config.js",

0 commit comments

Comments
 (0)