Skip to content

Commit 69e6275

Browse files
authored
fix(build): Fix temporary sucrase CI jobs (#5021)
Until we officially switch over to rullup/sucrase builds, there are extra CI jobs running to test the build changes so far without us having had to switch to them yet. That said, the first attempt at creating such a system had a significant flaw, in that the supposedly-sucrase unit tests were actually running against the normal tsc build output. Further, it was very flaky, but it seems there might occasionally have been some scope bleed between the tsc-built file cache and the sucrase-built one. (It seems unlikely, I know, and I could be imagining it. Regardless, the changes here make it a moot point.) This fixes those unit tests to run against sucrase builds, by adding a script to build with sucrase in the test job itself (and all other sucrase test jobs). It also moves a prior hack (rebuilding in es5 for node 8 tests) from the main test script into the new hacky script, so it can't get missed when pulling these temporary fixes out of the code when we switch. (That move is why our regular unit tests also run that script, to get the prior hack.) Finally, it makes a temporary modification to our base rollup config when in node 8, to enable the just-in-time rollup builds. Disclaimer: This is definitely a hack, and is a little ugly, but it's also coming out in a week, so... ¯\\_(ツ)_/¯ Note: Node 8 sucrase tests are an xfail at this point, until more of the new build pipeline is merged.
1 parent f18a938 commit 69e6275

File tree

4 files changed

+98
-72
lines changed

4 files changed

+98
-72
lines changed

.github/workflows/build.yml

Lines changed: 34 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -105,45 +105,6 @@ jobs:
105105
# `job_build` can't see `job_install_deps` and what it returned)
106106
dependency_cache_key: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
107107

108-
# This isn't a full `yarn build` using sucrase - it's just the cache from the normal build, with `build/cjs` and
109-
# `build/esm` overwritten by sucrase. This way we don't need to worry about all of the other random stuff which
110-
# packages build, because it will already be there.
111-
job_build_with_sucrase:
112-
name: Sucrase Build
113-
needs: [job_install_deps, job_build]
114-
runs-on: ubuntu-latest
115-
timeout-minutes: 20
116-
steps:
117-
- name: Check out current commit (${{ env.HEAD_COMMIT }})
118-
uses: actions/checkout@v2
119-
with:
120-
ref: ${{ env.HEAD_COMMIT }}
121-
- name: Set up Node
122-
uses: actions/setup-node@v1
123-
- name: Check dependency cache
124-
uses: actions/cache@v2
125-
with:
126-
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
127-
key: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
128-
- name: Check tsc build cache
129-
uses: actions/cache@v2
130-
with:
131-
path: ${{ env.CACHED_BUILD_PATHS }}
132-
key: ${{ env.BUILD_CACHE_KEY }}
133-
- name: Check sucrase build cache
134-
uses: actions/cache@v2
135-
id: cache_built_sucrase_packages
136-
with:
137-
path: ${{ env.CACHED_BUILD_PATHS }}
138-
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
139-
- name: Build packages with sucrase
140-
if: steps.cache_built_sucrase_packages.outputs.cache-hit == ''
141-
run: 'yarn build:rollup'
142-
outputs:
143-
# this needs to be passed on, because the `needs` context only looks at direct ancestors (so steps which depend on
144-
# `job_build` can't see `job_install_deps` and what it returned)
145-
dependency_cache_key: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
146-
147108
job_size_check:
148109
name: Size Check
149110
needs: job_build
@@ -295,6 +256,8 @@ jobs:
295256
NODE_VERSION: ${{ matrix.node }}
296257
run: |
297258
[[ $NODE_VERSION == 8 ]] && yarn add --dev --ignore-engines --ignore-scripts --ignore-workspace-root-check [email protected]
259+
# TODO remove this when we switch to sucrase
260+
yarn ts-node scripts/sucrase-test-hack.ts
298261
yarn test-ci
299262
- name: Compute test coverage
300263
uses: codecov/codecov-action@v1
@@ -534,7 +497,7 @@ jobs:
534497
535498
job_unit_test_sucrase:
536499
name: Sucrase Test (Node ${{ matrix.node }})
537-
needs: job_build_with_sucrase
500+
needs: job_build
538501
continue-on-error: true
539502
timeout-minutes: 30
540503
runs-on: ubuntu-latest
@@ -554,24 +517,26 @@ jobs:
554517
uses: actions/cache@v2
555518
with:
556519
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
557-
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
520+
key: ${{ needs.job_build.outputs.dependency_cache_key }}
558521
- name: Check build cache
559522
uses: actions/cache@v2
560523
with:
561524
path: ${{ env.CACHED_BUILD_PATHS }}
562-
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
525+
key: ${{ env.BUILD_CACHE_KEY }}
563526
- name: Run tests
564527
env:
565528
NODE_VERSION: ${{ matrix.node }}
529+
SUCRASE: true
566530
run: |
567-
[[ $NODE_VERSION == 8 ]] && yarn add --dev --ignore-engines --ignore-scripts --ignore-workspace-root-check [email protected]
531+
[[ $NODE_VERSION == 8 ]] && yarn add --dev --ignore-engines --ignore-scripts --ignore-workspace-root-check [email protected] [email protected] @rollup/[email protected] [email protected] [email protected]
532+
yarn ts-node scripts/sucrase-test-hack.ts
568533
yarn test-ci
569534
- name: Compute test coverage
570535
uses: codecov/codecov-action@v1
571536

572537
job_nextjs_integration_test_sucrase:
573538
name: Sucrase Test @sentry/nextjs on (Node ${{ matrix.node }})
574-
needs: job_build_with_sucrase
539+
needs: job_build
575540
continue-on-error: true
576541
timeout-minutes: 30
577542
runs-on: ubuntu-latest
@@ -591,24 +556,25 @@ jobs:
591556
uses: actions/cache@v2
592557
with:
593558
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
594-
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
559+
key: ${{ needs.job_build.outputs.dependency_cache_key }}
595560
- name: Check build cache
596561
uses: actions/cache@v2
597562
with:
598563
path: ${{ env.CACHED_BUILD_PATHS }}
599-
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
564+
key: ${{ env.BUILD_CACHE_KEY }}
600565
- name: Run tests
601566
env:
602567
NODE_VERSION: ${{ matrix.node }}
603568
run: |
569+
yarn ts-node scripts/sucrase-test-hack.ts
604570
cd packages/nextjs
605571
yarn test:integration
606572
607573
# Ember tests are separate from the rest because they are the slowest part of the test suite, and making them a
608574
# separate job allows them to run in parallel with the other tests.
609575
job_ember_tests_sucrase:
610576
name: Sucrase Test @sentry/ember
611-
needs: job_build_with_sucrase
577+
needs: job_build
612578
continue-on-error: true
613579
timeout-minutes: 30
614580
runs-on: ubuntu-latest
@@ -634,20 +600,22 @@ jobs:
634600
uses: actions/cache@v2
635601
with:
636602
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
637-
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
603+
key: ${{ needs.job_build.outputs.dependency_cache_key }}
638604
- name: Check build cache
639605
uses: actions/cache@v2
640606
with:
641607
path: ${{ env.CACHED_BUILD_PATHS }}
642-
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
608+
key: ${{ env.BUILD_CACHE_KEY }}
643609
- name: Run Ember tests
644-
run: yarn test --scope=@sentry/ember
610+
run: |
611+
yarn ts-node scripts/sucrase-test-hack.ts
612+
yarn test --scope=@sentry/ember
645613
- name: Compute test coverage
646614
uses: codecov/codecov-action@v1
647615

648616
job_browser_playwright_tests_sucrase:
649617
name: Sucrase Playwright - ${{ (matrix.tracing_only && 'Browser + Tracing') || 'Browser' }} (${{ matrix.bundle }})
650-
needs: job_build_with_sucrase
618+
needs: job_build
651619
runs-on: ubuntu-latest
652620
strategy:
653621
matrix:
@@ -677,24 +645,25 @@ jobs:
677645
uses: actions/cache@v2
678646
with:
679647
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
680-
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
648+
key: ${{ needs.job_build.outputs.dependency_cache_key }}
681649
- name: Check build cache
682650
uses: actions/cache@v2
683651
with:
684652
path: ${{ env.CACHED_BUILD_PATHS }}
685-
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
653+
key: ${{ env.BUILD_CACHE_KEY }}
686654
- name: Run Playwright tests
687655
env:
688656
PW_BUNDLE: ${{ matrix.bundle }}
689657
PW_TRACING_ONLY: ${{ matrix.tracing_only }}
690658
run: |
659+
yarn ts-node scripts/sucrase-test-hack.ts
691660
cd packages/integration-tests
692661
yarn run playwright install-deps webkit
693662
yarn test:ci
694663
695664
job_browser_integration_tests_sucrase:
696665
name: Sucrase Old Browser Integration Tests (${{ matrix.browser }})
697-
needs: job_build_with_sucrase
666+
needs: job_build
698667
runs-on: ubuntu-latest
699668
timeout-minutes: 10
700669
continue-on-error: true
@@ -715,23 +684,24 @@ jobs:
715684
uses: actions/cache@v2
716685
with:
717686
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
718-
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
687+
key: ${{ needs.job_build.outputs.dependency_cache_key }}
719688
- name: Check build cache
720689
uses: actions/cache@v2
721690
with:
722691
path: ${{ env.CACHED_BUILD_PATHS }}
723-
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
692+
key: ${{ env.BUILD_CACHE_KEY }}
724693
- name: Run integration tests
725694
env:
726695
KARMA_BROWSER: ${{ matrix.browser }}
727696
run: |
697+
yarn ts-node scripts/sucrase-test-hack.ts
728698
cd packages/browser
729699
[[ $KARMA_BROWSER == WebkitHeadless ]] && yarn run playwright install-deps webkit
730700
yarn test:integration
731701
732702
job_browser_build_tests_sucrase:
733703
name: Sucrase Browser Build Tests
734-
needs: job_build_with_sucrase
704+
needs: job_build
735705
runs-on: ubuntu-latest
736706
timeout-minutes: 5
737707
continue-on-error: true
@@ -748,14 +718,15 @@ jobs:
748718
uses: actions/cache@v2
749719
with:
750720
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
751-
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
721+
key: ${{ needs.job_build.outputs.dependency_cache_key }}
752722
- name: Check build cache
753723
uses: actions/cache@v2
754724
with:
755725
path: ${{ env.CACHED_BUILD_PATHS }}
756-
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
726+
key: ${{ env.BUILD_CACHE_KEY }}
757727
- name: Run browser build tests
758728
run: |
729+
yarn ts-node scripts/sucrase-test-hack.ts
759730
cd packages/browser
760731
yarn test:package
761732
- name: Run utils build tests
@@ -765,7 +736,7 @@ jobs:
765736
766737
job_node_integration_tests_sucrase:
767738
name: Sucrase Node SDK Integration Tests (${{ matrix.node }})
768-
needs: job_build_with_sucrase
739+
needs: job_build
769740
runs-on: ubuntu-latest
770741
timeout-minutes: 10
771742
continue-on-error: true
@@ -785,15 +756,16 @@ jobs:
785756
uses: actions/cache@v2
786757
with:
787758
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
788-
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
759+
key: ${{ needs.job_build.outputs.dependency_cache_key }}
789760
- name: Check build cache
790761
uses: actions/cache@v2
791762
with:
792763
path: ${{ env.CACHED_BUILD_PATHS }}
793-
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
764+
key: ${{ env.BUILD_CACHE_KEY }}
794765
- name: Run integration tests
795766
env:
796767
NODE_VERSION: ${{ matrix.node }}
797768
run: |
769+
yarn ts-node scripts/sucrase-test-hack.ts
798770
cd packages/node-integration-tests
799771
yarn test

rollup/npmHelpers.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export function makeBaseNPMConfig(options = {}) {
2222
const nodeResolvePlugin = makeNodeResolvePlugin();
2323
const sucrasePlugin = makeSucrasePlugin();
2424

25-
return {
25+
// return {
26+
const config = {
2627
input: entrypoints,
2728

2829
output: {
@@ -32,10 +33,10 @@ export function makeBaseNPMConfig(options = {}) {
3233
sourcemap: true,
3334

3435
// output individual files rather than one big bundle
35-
preserveModules: true,
36+
// preserveModules: true,
3637

3738
// any wrappers or helper functions generated by rollup can use ES6 features
38-
generatedCode: 'es2015',
39+
// generatedCode: 'es2015',
3940

4041
// don't add `"use strict"` to the top of cjs files
4142
strict: false,
@@ -78,6 +79,17 @@ export function makeBaseNPMConfig(options = {}) {
7879
// treeshake: 'smallest',
7980
treeshake: false,
8081
};
82+
83+
// temporary hack for testing sucrase bundles before we switch over
84+
if (!process.version.startsWith('v8')) {
85+
console.log('Doing normal preserveModules');
86+
config.output.preserveModules = true;
87+
} else {
88+
console.log('Doing node 8 preserveModules');
89+
config.preserveModules = true;
90+
}
91+
92+
return config;
8193
}
8294

8395
export function makeNPMConfigVariants(baseConfig) {

scripts/sucrase-test-hack.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// A temporary hack to use sucrase versions of packages for testing in CI.
2+
3+
import * as childProcess from 'child_process';
4+
import * as fs from 'fs';
5+
import * as path from 'path';
6+
7+
function run(cmd: string, options?: childProcess.ExecSyncOptions): unknown {
8+
return childProcess.execSync(cmd, { stdio: 'inherit', ...options });
9+
}
10+
11+
const ignorePackages = process.version.startsWith('v8')
12+
? [
13+
'@sentry/ember',
14+
'@sentry-internal/eslint-plugin-sdk',
15+
'@sentry/react',
16+
'@sentry/wasm',
17+
'@sentry/gatsby',
18+
'@sentry/serverless',
19+
'@sentry/nextjs',
20+
'@sentry/angular',
21+
]
22+
: ['@sentry/serverless'];
23+
24+
// clear current builds and rebuild with rollup/sucrase (this way, all of the extra, random stuff which gets built in
25+
// the main build job remains, and only the part affected by this project gets overwritten)
26+
if (process.env.SUCRASE) {
27+
// just to be super sure
28+
fs.readdirSync(path.join(process.cwd(), 'packages')).forEach(dir => {
29+
if (fs.existsSync(path.join(process.cwd(), 'packages', dir, 'build', 'npm'))) {
30+
run(`rm -rf packages/${dir}/build/npm/cjs`);
31+
run(`rm -rf packages/${dir}/build/npm/esm`);
32+
} else if (fs.existsSync(path.join(process.cwd(), 'packages', dir, 'build', 'cjs'))) {
33+
run(`rm -rf packages/${dir}/build/cjs`);
34+
run(`rm -rf packages/${dir}/build/esm`);
35+
}
36+
});
37+
38+
// rebuild the packages we're going to test with rollup/sucrase
39+
run(`yarn build:rollup ${ignorePackages.map(dep => `--ignore="${dep}"`).join(' ')}`);
40+
}
41+
// if we're in tsc-land, rebuild using es5 - temporary until switch to sucrase
42+
else {
43+
const baseTSConfigPath = 'packages/typescript/tsconfig.json';
44+
fs.writeFileSync(
45+
baseTSConfigPath,
46+
String(fs.readFileSync(baseTSConfigPath)).replace('"target": "es6"', '"target": "es5"'),
47+
);
48+
run(`yarn build:dev ${ignorePackages.map(dep => `--ignore="${dep}"`).join(' ')}`);
49+
}

scripts/test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { spawnSync } from 'child_process';
2-
import * as fs from 'fs';
32
import { join } from 'path';
43

54
function run(cmd: string, cwd: string = '') {
@@ -48,12 +47,6 @@ if (nodeMajorVersion <= 10) {
4847
// against a single version of node, but in the short run, this at least allows us to not be blocked by the
4948
// failures.)
5049
run('rm -rf packages/tracing/test/browser');
51-
52-
// TODO Pull this out once we switch to sucrase builds
53-
// Recompile as es5, so as not to have to fix a compatibility problem that will soon be moot
54-
const baseTSConfig = 'packages/typescript/tsconfig.json';
55-
fs.writeFileSync(baseTSConfig, String(fs.readFileSync(baseTSConfig)).replace('"target": "es6"', '"target": "es5"'));
56-
run(`yarn build:dev ${ignorePackages.map(dep => `--ignore="${dep}"`).join(' ')}`);
5750
}
5851
// Node 10
5952
else {

0 commit comments

Comments
 (0)