Skip to content

Commit a0ba764

Browse files
authored
Merge pull request #54 from CodinGame/fix-node-polyfill
[FIX] Restore node polyfill mocking
2 parents c793f51 + 28f8891 commit a0ba764

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

package-lock.json

Lines changed: 47 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"proxy-polyfill": "^0.3.2",
6969
"rollup": "2.76.0",
7070
"rollup-plugin-dts": "^4.2.2",
71+
"rollup-plugin-polyfill-node": "^0.10.1",
7172
"rollup-plugin-postcss": "4.0.2",
7273
"rollup-plugin-visualizer": "5.6.0",
7374
"rollup-plugin-web-worker-loader": "1.6.1",

rollup.config.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import eslint from '@rollup/plugin-eslint'
66
import { babel } from '@rollup/plugin-babel'
77
import * as rollup from 'rollup'
88
import * as recast from 'recast'
9+
import nodePolyfills from 'rollup-plugin-polyfill-node'
910
import path from 'path'
1011
import pkg from './package.json'
1112

@@ -19,6 +20,11 @@ const externals = [
1920

2021
const extensions = ['.js', '.ts']
2122

23+
// Ignore those polyfills by marking them as external, rollup will treeshake-out the imports for us
24+
// We ignore them because it's imported by a code which isn't included in the final bundle
25+
// But the polyfill doesn't export all required fields and make the build crash
26+
const IGNORED_NODE_POLYFILLS = new Set(['os', 'fs'])
27+
2228
export default rollup.defineConfig({
2329
cache: false,
2430
input: {
@@ -29,6 +35,9 @@ export default rollup.defineConfig({
2935
moduleSideEffects: false
3036
},
3137
external: function isExternal (source, importer, isResolved) {
38+
if (IGNORED_NODE_POLYFILLS.has(source)) {
39+
return true
40+
}
3241
if (isResolved) {
3342
return false
3443
}
@@ -51,6 +60,7 @@ export default rollup.defineConfig({
5160
}
5261
}],
5362
plugins: [
63+
nodePolyfills(),
5464
eslint({
5565
throwOnError: true,
5666
throwOnWarning: true,

0 commit comments

Comments
 (0)