Skip to content

Commit e48ffef

Browse files
authored
feat(build)!: Drop pre-ES2020 polyfills (#14882)
This PR updates to use a forked version of sucrase (https://github.com/getsentry/sucrase/tree/es2020-polyfills). On this branch, a new option `disableES2019Transforms` is added, which can be used to only polyfill ES2020 features: * numeric separators (e.g. `10_000`) * class fields (e.g. `class X { field; }`) It also adds a lint step that checks all build output for ES2020 compatibility, to avoid regressions in this regard.
1 parent ed8d23c commit e48ffef

File tree

8 files changed

+185
-26
lines changed

8 files changed

+185
-26
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ jobs:
267267
run: yarn lint:lerna
268268
- name: Lint C++ files
269269
run: yarn lint:clang
270+
- name: Lint for ES compatibility
271+
run: yarn lint:es-compatibility
270272

271273
job_check_format:
272274
name: Check file formatting

dev-packages/e2e-tests/test-applications/webpack-4/build.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ webpack(
1919
},
2020
plugins: [new HtmlWebpackPlugin(), new webpack.EnvironmentPlugin(['E2E_TEST_DSN'])],
2121
mode: 'production',
22+
// webpack 4 does not support ES2020 features out of the box, so we need to transpile them
23+
module: {
24+
rules: [
25+
{
26+
test: /\.(?:js|mjs|cjs)$/,
27+
use: {
28+
loader: 'babel-loader',
29+
options: {
30+
presets: [['@babel/preset-env', { targets: 'ie 11' }]],
31+
},
32+
},
33+
},
34+
],
35+
},
2236
},
2337
(err, stats) => {
2438
if (err) {

dev-packages/e2e-tests/test-applications/webpack-4/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "webpack-4-test",
2+
"name": "webpack-4",
33
"version": "1.0.0",
44
"scripts": {
55
"start": "serve -s build",
@@ -11,6 +11,9 @@
1111
"@playwright/test": "^1.44.1",
1212
"@sentry-internal/test-utils": "link:../../../test-utils",
1313
"@sentry/browser": "latest || *",
14+
"babel-loader": "^8.0.0",
15+
"@babel/core": "^7.0.0",
16+
"@babel/preset-env": "^7.0.0",
1417
"webpack": "^4.47.0",
1518
"terser-webpack-plugin": "^4.2.3",
1619
"html-webpack-plugin": "^4.5.2",

dev-packages/rollup-utils/npmHelpers.mjs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ export function makeBaseNPMConfig(options = {}) {
3333
esModuleInterop = false,
3434
hasBundles = false,
3535
packageSpecificConfig = {},
36-
addPolyfills = true,
3736
sucrase = {},
3837
bundledBuiltins = [],
3938
} = options;
4039

4140
const nodeResolvePlugin = makeNodeResolvePlugin();
42-
const sucrasePlugin = makeSucrasePlugin({}, { disableESTransforms: !addPolyfills, ...sucrase });
41+
const sucrasePlugin = makeSucrasePlugin({}, sucrase);
4342
const debugBuildStatementReplacePlugin = makeDebugBuildStatementReplacePlugin();
4443
const importMetaUrlReplacePlugin = makeImportMetaUrlReplacePlugin();
4544
const cleanupPlugin = makeCleanupPlugin();
@@ -64,13 +63,9 @@ export function makeBaseNPMConfig(options = {}) {
6463
// output individual files rather than one big bundle
6564
preserveModules: true,
6665

67-
// Allow wrappers or helper functions generated by rollup to use any ES2015 features except symbols. (Symbols in
68-
// general are fine, but the `[Symbol.toStringTag]: 'Module'` which Rollup adds alongside `__esModule:
69-
// true` in CJS modules makes it so that Jest <= 29.2.2 crashes when trying to mock generated `@sentry/xxx`
70-
// packages. See https://github.com/getsentry/sentry-javascript/pull/6043.)
66+
// Allow wrappers or helper functions generated by rollup to use any ES2015 features
7167
generatedCode: {
7268
preset: 'es2015',
73-
symbols: false,
7469
},
7570

7671
// don't add `"use strict"` to the top of cjs files

dev-packages/rollup-utils/plugins/npmPlugins.mjs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ export function makeSucrasePlugin(options = {}, sucraseOptions = {}) {
2929
},
3030
{
3131
transforms: ['typescript', 'jsx'],
32+
// We use a custom forked version of sucrase,
33+
// where there is a new option `disableES2019Transforms`
34+
disableESTransforms: false,
35+
disableES2019Transforms: true,
3236
...sucraseOptions,
3337
},
3438
);

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"lint:lerna": "lerna run lint",
3232
"lint:biome": "biome check .",
3333
"lint:prettier": "prettier \"**/*.md\" \"**/*.css\" --check",
34+
"lint:es-compatibility": "es-check es2020 ./packages/*/build/{bundles,npm/cjs,cjs}/*.js && es-check es2020 ./packages/*/build/{npm/esm,esm}/*.js --module",
3435
"postpublish": "lerna run --stream --concurrency 1 postpublish",
3536
"test": "lerna run --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests}\" test",
3637
"test:unit": "lerna run --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests}\" test:unit",
@@ -115,6 +116,7 @@
115116
"@vitest/coverage-v8": "^1.6.0",
116117
"deepmerge": "^4.2.2",
117118
"downlevel-dts": "~0.11.0",
119+
"es-check": "^7.2.1",
118120
"eslint": "7.32.0",
119121
"jest": "^27.5.1",
120122
"jest-environment-node": "^27.5.1",
@@ -144,7 +146,8 @@
144146
"resolutions": {
145147
"gauge/strip-ansi": "6.0.1",
146148
"wide-align/string-width": "4.2.3",
147-
"cliui/wrap-ansi": "7.0.0"
149+
"cliui/wrap-ansi": "7.0.0",
150+
"**/sucrase": "getsentry/sucrase#es2020-polyfills"
148151
},
149152
"version": "0.0.0",
150153
"name": "sentry-javascript",

packages/node/rollup.anr-worker.config.mjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ export function createWorkerCodeBuilder(entry, outDir) {
77
makeBaseBundleConfig({
88
bundleType: 'node-worker',
99
entrypoints: [entry],
10-
sucrase: { disableESTransforms: true },
1110
licenseTitle: '@sentry/node',
1211
outputFileBase: () => 'worker-script.js',
1312
packageSpecificConfig: {

0 commit comments

Comments
 (0)