Skip to content

Commit

Permalink
build(webpack): polyfill setImmediate (#26398)
Browse files Browse the repository at this point in the history
Fixes flaky test `Sentry errors after initialization, after opting into metrics @no-mmi should send error events in background` in the webpack build.
  • Loading branch information
davidmurdoch authored Aug 14, 2024
1 parent 42326a7 commit c5c13d5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions .depcheckrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ ignores:
- 'https-browserify' # polyfill
- 'path-browserify' # polyfill
- 'nyc' # coverage
- 'core-js-pure' # polyfills
# babel
- '@babel/plugin-transform-logical-assignment-operators'
# trezor
Expand Down
8 changes: 8 additions & 0 deletions development/webpack/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,14 @@ const plugins: WebpackPluginInstance[] = [
Buffer: ['buffer', 'Buffer'],
// Make a global `process` variable that points to the `process` package.
process: 'process/browser',
// polyfill usages of `setImmediate`, ideally this would be automatically
// handled by `swcLoader`'s `env.usage = 'entry'` option, but that setting
// results in a compilation error: `Module parse failed: 'import' and
// 'export' may appear only with 'sourceType: module' (2:0)`. I spent a few
// hours trying to figure it out but couldn't. So, this is the workaround.
// Note: we should probably remove usages of `setImmediate` from our
// codebase so we don't have to polyfill it.
setImmediate: 'core-js-pure/actual/set-immediate',
}),
new CopyPlugin({
patterns: [
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@
"concurrently": "^8.2.2",
"contentful": "^10.8.7",
"copy-webpack-plugin": "^12.0.2",
"core-js-pure": "^3.38.0",
"cross-spawn": "^7.0.3",
"crypto-browserify": "^3.12.0",
"css-loader": "^6.10.0",
Expand Down Expand Up @@ -754,7 +755,8 @@
"@pmmmwh/react-refresh-webpack-plugin>core-js-pure": true,
"@swc/core": true,
"@lydell/node-pty": true,
"$root$": true
"$root$": true,
"core-js-pure": true
}
},
"packageManager": "[email protected]"
Expand Down
9 changes: 5 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15584,10 +15584,10 @@ __metadata:
languageName: node
linkType: hard

"core-js-pure@npm:^3.0.0, core-js-pure@npm:^3.23.3":
version: 3.30.2
resolution: "core-js-pure@npm:3.30.2"
checksum: 10/52bba8bf4bfdec61c3459244a4f349393dd9890307df698993f0c575abc891c5dda9ff8d2af7fc8d4abdef06e6babe48483ddc44749760557b3015406b8d2acc
"core-js-pure@npm:^3.0.0, core-js-pure@npm:^3.23.3, core-js-pure@npm:^3.38.0":
version: 3.38.0
resolution: "core-js-pure@npm:3.38.0"
checksum: 10/56a0346bb691f0a9eddd88e92daa29213f3591c4db84731fe47c89dfb7bab116c9c1bd983a2286a558a35b736312da2d0ccb603a40d73af6857bd22b352f2988
languageName: node
linkType: hard

Expand Down Expand Up @@ -26163,6 +26163,7 @@ __metadata:
contentful: "npm:^10.8.7"
copy-to-clipboard: "npm:^3.3.3"
copy-webpack-plugin: "npm:^12.0.2"
core-js-pure: "npm:^3.38.0"
cross-spawn: "npm:^7.0.3"
crypto-browserify: "npm:^3.12.0"
css-loader: "npm:^6.10.0"
Expand Down

0 comments on commit c5c13d5

Please sign in to comment.