Skip to content

feat(build): Add sucrase build foundations #4992

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Apr 28, 2022
305 changes: 305 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,45 @@ jobs:
# `job_build` can't see `job_install_deps` and what it returned)
dependency_cache_key: ${{ needs.job_install_deps.outputs.dependency_cache_key }}

# This isn't a full `yarn build` using sucrase - it's just the cache from the normal build, with `build/cjs` and
# `build/esm` overwritten by sucrase. This way we don't need to worry about all of the other random stuff which
# packages build, because it will already be there.
job_build_with_sucrase:
name: Sucrase Build
needs: [job_install_deps, job_build]
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Check out current commit (${{ env.HEAD_COMMIT }})
uses: actions/checkout@v2
with:
ref: ${{ env.HEAD_COMMIT }}
- name: Set up Node
uses: actions/setup-node@v1
- name: Check dependency cache
uses: actions/cache@v2
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ needs.job_install_deps.outputs.dependency_cache_key }}
- name: Check tsc build cache
uses: actions/cache@v2
with:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}
- name: Check sucrase build cache
uses: actions/cache@v2
id: cache_built_sucrase_packages
with:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
- name: Build packages with sucrase
if: steps.cache_built_sucrase_packages.outputs.cache-hit == ''
run: 'yarn build:rollup'
outputs:
# this needs to be passed on, because the `needs` context only looks at direct ancestors (so steps which depend on
# `job_build` can't see `job_install_deps` and what it returned)
dependency_cache_key: ${{ needs.job_install_deps.outputs.dependency_cache_key }}

job_size_check:
name: Size Check
needs: job_build
Expand Down Expand Up @@ -492,3 +531,269 @@ jobs:
run: |
cd packages/node-integration-tests
yarn test

job_unit_test_sucrase:
name: Sucrase Test (Node ${{ matrix.node }})
needs: job_build_with_sucrase
continue-on-error: true
timeout-minutes: 30
runs-on: ubuntu-latest
strategy:
matrix:
node: [8, 10, 12, 14, 16]
steps:
- name: Check out current commit (${{ env.HEAD_COMMIT }})
uses: actions/checkout@v2
with:
ref: ${{ env.HEAD_COMMIT }}
- name: Set up Node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: Check dependency cache
uses: actions/cache@v2
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
- name: Check build cache
uses: actions/cache@v2
with:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
- name: Run tests
env:
NODE_VERSION: ${{ matrix.node }}
run: |
[[ $NODE_VERSION == 8 ]] && yarn add --dev --ignore-engines --ignore-scripts --ignore-workspace-root-check [email protected]
yarn test-ci
- name: Compute test coverage
uses: codecov/codecov-action@v1

job_nextjs_integration_test_sucrase:
name: Sucrase Test @sentry/nextjs on (Node ${{ matrix.node }})
needs: job_build_with_sucrase
continue-on-error: true
timeout-minutes: 30
runs-on: ubuntu-latest
strategy:
matrix:
node: [10, 12, 14, 16]
steps:
- name: Check out current commit (${{ env.HEAD_COMMIT }})
uses: actions/checkout@v2
with:
ref: ${{ env.HEAD_COMMIT }}
- name: Set up Node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: Check dependency cache
uses: actions/cache@v2
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
- name: Check build cache
uses: actions/cache@v2
with:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
- name: Run tests
env:
NODE_VERSION: ${{ matrix.node }}
run: |
cd packages/nextjs
yarn test:integration

# Ember tests are separate from the rest because they are the slowest part of the test suite, and making them a
# separate job allows them to run in parallel with the other tests.
job_ember_tests_sucrase:
name: Sucrase Test @sentry/ember
needs: job_build_with_sucrase
continue-on-error: true
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- name: Check out current commit (${{ env.HEAD_COMMIT }})
uses: actions/checkout@v2
with:
ref: ${{ env.HEAD_COMMIT }}
# TODO: removing `fetch-depth` below seems to have no effect, and the commit which added it had no description,
# so it's not clear why it's necessary. That said, right now ember tests are xfail, so it's a little hard to
# tell if it's safe to remove. Once ember tests are fixed, let's try again with it turned off, and if all goes
# well, we can pull it out.
fetch-depth: 0
- name: Set up Node
uses: actions/setup-node@v1
with:
# The only danger with Ember in terms of Node versions is that the build tool, ember-cli, won't work if Node
# is too old. Since Oct 2019, Node 10 has been the oldest version supported by ember-cli, so test against
# that. If it passes, newer versions of Node should also be fine. This saves us from having to run the Ember
# tests in our Node matrix above.
node-version: '10'
- name: Check dependency cache
uses: actions/cache@v2
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
- name: Check build cache
uses: actions/cache@v2
with:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
- name: Run Ember tests
run: yarn test --scope=@sentry/ember
- name: Compute test coverage
uses: codecov/codecov-action@v1

job_browser_playwright_tests_sucrase:
name: Sucrase Playwright - ${{ (matrix.tracing_only && 'Browser + Tracing') || 'Browser' }} (${{ matrix.bundle }})
needs: job_build_with_sucrase
runs-on: ubuntu-latest
strategy:
matrix:
bundle:
- esm
- cjs
tracing_only:
- true
- false
exclude:
# `tracing_only` only makes a difference for bundles - tests of the esm and cjs builds always include the
# tracing tests
- bundle: esm
tracing_only: false
- bundle: cjs
tracing_only: false
steps:
- name: Check out current commit (${{ env.HEAD_COMMIT }})
uses: actions/checkout@v2
with:
ref: ${{ env.HEAD_COMMIT }}
- name: Set up Node
uses: actions/setup-node@v1
with:
node-version: '16'
- name: Check dependency cache
uses: actions/cache@v2
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
- name: Check build cache
uses: actions/cache@v2
with:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
- name: Run Playwright tests
env:
PW_BUNDLE: ${{ matrix.bundle }}
PW_TRACING_ONLY: ${{ matrix.tracing_only }}
run: |
cd packages/integration-tests
yarn run playwright install-deps webkit
yarn test:ci

job_browser_integration_tests_sucrase:
name: Sucrase Old Browser Integration Tests (${{ matrix.browser }})
needs: job_build_with_sucrase
runs-on: ubuntu-latest
timeout-minutes: 10
continue-on-error: true
strategy:
matrix:
browser:
- ChromeHeadless
- FirefoxHeadless
- WebkitHeadless
steps:
- name: Check out current commit (${{ env.HEAD_COMMIT }})
uses: actions/checkout@v2
with:
ref: ${{ env.HEAD_COMMIT }}
- name: Set up Node
uses: actions/setup-node@v1
- name: Check dependency cache
uses: actions/cache@v2
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
- name: Check build cache
uses: actions/cache@v2
with:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
- name: Run integration tests
env:
KARMA_BROWSER: ${{ matrix.browser }}
run: |
cd packages/browser
[[ $KARMA_BROWSER == WebkitHeadless ]] && yarn run playwright install-deps webkit
yarn test:integration

job_browser_build_tests_sucrase:
name: Sucrase Browser Build Tests
needs: job_build_with_sucrase
runs-on: ubuntu-latest
timeout-minutes: 5
continue-on-error: true
steps:
- name: Check out current commit (${ env.HEAD_COMMIT }})
uses: actions/checkout@v2
with:
ref: ${{ env.HEAD_COMMIT }}
- name: Set up Node
uses: actions/setup-node@v1
with:
node-version: '16'
- name: Check dependency cache
uses: actions/cache@v2
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
- name: Check build cache
uses: actions/cache@v2
with:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
- name: Run browser build tests
run: |
cd packages/browser
yarn test:package
- name: Run utils build tests
run: |
cd packages/utils
yarn test:package

job_node_integration_tests_sucrase:
name: Sucrase Node SDK Integration Tests (${{ matrix.node }})
needs: job_build_with_sucrase
runs-on: ubuntu-latest
timeout-minutes: 10
continue-on-error: true
strategy:
matrix:
node: [10, 12, 14, 16]
steps:
- name: Check out current commit (${{ github.sha }})
uses: actions/checkout@v2
with:
ref: ${{ env.HEAD_COMMIT }}
- name: Set up Node
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- name: Check dependency cache
uses: actions/cache@v2
with:
path: ${{ env.CACHED_DEPENDENCY_PATHS }}
key: ${{ needs.job_build_with_sucrase.outputs.dependency_cache_key }}
- name: Check build cache
uses: actions/cache@v2
with:
path: ${{ env.CACHED_BUILD_PATHS }}
key: ${{ env.BUILD_CACHE_KEY }}-sucrase
- name: Run integration tests
env:
NODE_VERSION: ${{ matrix.node }}
run: |
cd packages/node-integration-tests
yarn test
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"build:dev:filter": "lerna run --stream --concurrency 1 --sort build:dev --include-filtered-dependencies --include-filtered-dependents --scope",
"build:es5": "yarn lerna run --stream --concurrency 1 --sort build:cjs # *** backwards compatibility - remove in v7 ***",
"build:esm": "lerna run --stream --concurrency 1 --sort build:esm",
"build:rollup": "lerna run --stream --concurrency 1 --sort build:rollup",
"build:types": "lerna run --stream --concurrency 1 --sort build:types",
"build:watch": "lerna run --parallel build:watch",
"build:dev:watch": "lerna run --parallel build:dev:watch",
Expand Down Expand Up @@ -57,6 +58,7 @@
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-node-resolve": "^13.1.3",
"@rollup/plugin-replace": "^3.0.1",
"@rollup/plugin-sucrase": "^4.0.3",
"@size-limit/preset-small-lib": "^4.5.5",
"@strictsoftware/typedoc-plugin-monorepo": "^0.3.1",
"@types/chai": "^4.1.3",
Expand Down
2 changes: 2 additions & 0 deletions packages/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,15 @@
"build:dev": "run-p build:cjs build:esm build:types",
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
"build:esm": "tsc -p tsconfig.esm.json",
"build:rollup": "rollup -c rollup.npm.config.js",
"build:types": "tsc -p tsconfig.types.json",
"build:watch": "run-p build:cjs:watch build:esm:watch build:bundle:watch build:types:watch",
"build:bundle:watch": "rollup --config --watch",
"build:cjs:watch": "tsc -p tsconfig.cjs.json --watch",
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
"build:dev:watch": "run-p build:cjs:watch build:esm:watch build:types:watch",
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
"build:rollup:watch": "rollup -c rollup.npm.config.js --watch",
"build:types:watch": "tsc -p tsconfig.types.json --watch",
"build:npm": "ts-node ../../scripts/prepack.ts --bundles && npm pack ./build/npm",
"circularDepCheck": "madge --circular src/index.ts",
Expand Down
8 changes: 8 additions & 0 deletions packages/browser/rollup.npm.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js';

export default makeNPMConfigVariants(
makeBaseNPMConfig({
// packages with bundles have a different build directory structure
hasBundles: true,
}),
);
2 changes: 2 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@
"build:dev": "run-s build",
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
"build:esm": "tsc -p tsconfig.esm.json",
"build:rollup": "rollup -c rollup.npm.config.js",
"build:types": "tsc -p tsconfig.types.json",
"build:watch": "run-p build:cjs:watch build:esm:watch build:types:watch",
"build:cjs:watch": "tsc -p tsconfig.cjs.json --watch",
"build:dev:watch": "run-s build:watch",
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
"build:rollup:watch": "rollup -c rollup.npm.config.js --watch",
"build:types:watch": "tsc -p tsconfig.types.json --watch",
"build:npm": "ts-node ../../scripts/prepack.ts && npm pack ./build",
"circularDepCheck": "madge --circular src/index.ts",
Expand Down
3 changes: 3 additions & 0 deletions packages/core/rollup.npm.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js';

export default makeNPMConfigVariants(makeBaseNPMConfig());
2 changes: 2 additions & 0 deletions packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@
"build:es5": "yarn build:cjs # *** backwards compatibility - remove in v7 ***",
"build:esm": "tsc -p tsconfig.esm.json",
"build:plugin": "tsc -p tsconfig.plugin.json",
"build:rollup": "rollup -c rollup.npm.config.js",
"build:types": "tsc -p tsconfig.types.json",
"build:watch": "run-p build:cjs:watch build:esm:watch build:types:watch",
"build:cjs:watch": "tsc -p tsconfig.cjs.json --watch",
"build:dev:watch": "run-s build:watch",
"build:es5:watch": "yarn build:cjs:watch # *** backwards compatibility - remove in v7 ***",
"build:esm:watch": "tsc -p tsconfig.esm.json --watch",
"build:rollup:watch": "rollup -c rollup.npm.config.js --watch",
"build:types:watch": "tsc -p tsconfig.types.json --watch",
"build:npm": "ts-node ../../scripts/prepack.ts && npm pack ./build",
"circularDepCheck": "madge --circular src/index.ts",
Expand Down
3 changes: 3 additions & 0 deletions packages/gatsby/rollup.npm.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { makeBaseNPMConfig, makeNPMConfigVariants } from '../../rollup/index.js';

export default makeNPMConfigVariants(makeBaseNPMConfig());
Loading