Skip to content

Commit

Permalink
Read node polyfill versions from package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
mischnic committed Aug 30, 2022
1 parent 02290e2 commit 65884f9
Showing 1 changed file with 38 additions and 25 deletions.
63 changes: 38 additions & 25 deletions packages/utils/node-resolver-core/src/builtins.js
@@ -1,6 +1,9 @@
// @flow strict-local
// $FlowFixMe this is untyped
import {builtinModules} from 'module';
import nullthrows from 'nullthrows';
// flowlint-next-line untyped-import:off
import packageJson from '../package.json';

export const empty: string = require.resolve('./_empty.js');

Expand All @@ -13,30 +16,40 @@ for (let key of builtinModules) {
builtins[key] = {name: empty, range: null};
}

// These are mostly the versions considered "new enough" by
// https://www.npmjs.com/package/node-libs-browser (with a few version bumps)
builtins.assert = {name: 'assert/', range: '^2.0.0'};
builtins.buffer = {name: 'buffer/', range: '^5.5.0'};
builtins.console = {name: 'console-browserify', range: '^1.2.0'};
builtins.constants = {name: 'constants-browserify', range: '^1.0.0'};
builtins.crypto = {name: 'crypto-browserify', range: '^3.12.0'};
builtins.domain = {name: 'domain-browser', range: '^3.5.0'};
builtins.events = {name: 'events/', range: '^3.1.0'};
builtins.http = {name: 'stream-http', range: '^3.1.0'};
builtins.https = {name: 'https-browserify', range: '^1.0.0'};
builtins.os = {name: 'os-browserify/browser.js', range: '^0.3.0'};
builtins.path = {name: 'path-browserify', range: '^1.0.0'};
builtins.process = {name: 'process/browser.js', range: '^0.11.10'};
builtins.punycode = {name: 'punycode/', range: '^1.4.1'};
builtins.querystring = {name: 'querystring-es3/', range: '^0.2.1'};
builtins.stream = {name: 'stream-browserify', range: '^3.0.0'};
builtins.string_decoder = {name: 'string_decoder/', range: '^1.3.0'};
builtins.sys = {name: 'util/util.js', range: '^0.12.3'};
builtins.timers = {name: 'timers-browserify', range: '^2.0.11'};
builtins.tty = {name: 'tty-browserify', range: '^0.0.1'};
builtins.url = {name: 'url/', range: '^0.11.0'};
builtins.util = {name: 'util/util.js', range: '^0.12.3'};
builtins.vm = {name: 'vm-browserify', range: '^1.1.2'};
builtins.zlib = {name: 'browserify-zlib', range: '^0.2.0'};
let polyfills = {
assert: 'assert',
buffer: 'buffer',
console: 'console-browserify',
constants: 'constants-browserify',
crypto: 'crypto-browserify',
domain: 'domain-browser',
events: 'events',
http: 'stream-http',
https: 'https-browserify',
os: 'os-browserify',
path: 'path-browserify',
process: 'process',
punycode: 'punycode',
querystring: 'querystring-es3',
stream: 'stream-browserify',
string_decoder: 'string_decoder',
sys: 'util',
timers: 'timers-browserify',
tty: 'tty-browserify',
url: 'url',
util: 'util',
vm: 'vm-browserify',
zlib: 'browserify-zlib',
};

for (let k in polyfills) {
let polyfill = polyfills[k];
builtins[k] = {
name: polyfill + (builtinModules.includes(polyfill) ? '/' : ''),
range: nullthrows(packageJson.devDependencies[polyfill]),
};
}

console.log(builtins);

export default builtins;

0 comments on commit 65884f9

Please sign in to comment.