Skip to content

feat(build)!: Drop pre-ES2020 polyfills #14882

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 3 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ jobs:
run: yarn lint:lerna
- name: Lint C++ files
run: yarn lint:clang
- name: Lint for ES compatibility
run: yarn lint:es-compatibility

job_check_format:
name: Check file formatting
Expand Down
14 changes: 14 additions & 0 deletions dev-packages/e2e-tests/test-applications/webpack-4/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,20 @@ webpack(
},
plugins: [new HtmlWebpackPlugin(), new webpack.EnvironmentPlugin(['E2E_TEST_DSN'])],
mode: 'production',
// webpack 4 does not support ES2020 features out of the box, so we need to transpile them
module: {
rules: [
{
test: /\.(?:js|mjs|cjs)$/,
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', { targets: 'ie 11' }]],
},
},
},
],
},
},
(err, stats) => {
if (err) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "webpack-4-test",
"name": "webpack-4",
"version": "1.0.0",
"scripts": {
"start": "serve -s build",
Expand All @@ -11,6 +11,9 @@
"@playwright/test": "^1.44.1",
"@sentry-internal/test-utils": "link:../../../test-utils",
"@sentry/browser": "latest || *",
"babel-loader": "^8.0.0",
"@babel/core": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"webpack": "^4.47.0",
"terser-webpack-plugin": "^4.2.3",
"html-webpack-plugin": "^4.5.2",
Expand Down
9 changes: 2 additions & 7 deletions dev-packages/rollup-utils/npmHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ export function makeBaseNPMConfig(options = {}) {
esModuleInterop = false,
hasBundles = false,
packageSpecificConfig = {},
addPolyfills = true,
sucrase = {},
bundledBuiltins = [],
} = options;

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

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

// don't add `"use strict"` to the top of cjs files
Expand Down
4 changes: 4 additions & 0 deletions dev-packages/rollup-utils/plugins/npmPlugins.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ export function makeSucrasePlugin(options = {}, sucraseOptions = {}) {
},
{
transforms: ['typescript', 'jsx'],
// We use a custom forked version of sucrase,
// where there is a new option `disableES2019Transforms`
disableESTransforms: false,
disableES2019Transforms: true,
...sucraseOptions,
},
);
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"lint:lerna": "lerna run lint",
"lint:biome": "biome check .",
"lint:prettier": "prettier \"**/*.md\" \"**/*.css\" --check",
"lint:es-compatibility": "es-check es2020 ./packages/*/build/{bundles,npm/cjs,cjs}/*.js && es-check es2020 ./packages/*/build/{npm/esm,esm}/*.js --module",
"postpublish": "lerna run --stream --concurrency 1 postpublish",
"test": "lerna run --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests}\" test",
"test:unit": "lerna run --ignore \"@sentry-internal/{browser-integration-tests,e2e-tests,integration-shims,node-integration-tests}\" test:unit",
Expand Down Expand Up @@ -115,6 +116,7 @@
"@vitest/coverage-v8": "^1.6.0",
"deepmerge": "^4.2.2",
"downlevel-dts": "~0.11.0",
"es-check": "^7.2.1",
"eslint": "7.32.0",
"jest": "^27.5.1",
"jest-environment-node": "^27.5.1",
Expand Down Expand Up @@ -144,7 +146,8 @@
"resolutions": {
"gauge/strip-ansi": "6.0.1",
"wide-align/string-width": "4.2.3",
"cliui/wrap-ansi": "7.0.0"
"cliui/wrap-ansi": "7.0.0",
"**/sucrase": "getsentry/sucrase#es2020-polyfills"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotta admit, I had no idea that one can simply specify a repo/branch name here. Nice!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it required us to ensure that the dist folder is actually checked in on that branch, but IMHO this appears easier than to publish stuff from there etc 😅

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for sure!

},
"version": "0.0.0",
"name": "sentry-javascript",
Expand Down
1 change: 0 additions & 1 deletion packages/node/rollup.anr-worker.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export function createWorkerCodeBuilder(entry, outDir) {
makeBaseBundleConfig({
bundleType: 'node-worker',
entrypoints: [entry],
sucrase: { disableESTransforms: true },
licenseTitle: '@sentry/node',
outputFileBase: () => 'worker-script.js',
packageSpecificConfig: {
Expand Down
Loading
Loading