getlibs
getlibs copied to clipboard
Better support for node core modules?
I'm trying to use a lot of modules that were originally written for browserify and really jumping through a lot of hoops. Is that a use case you'd be willing to consider? I believe it would be a matter of adding new entries in getlibs/config/ for assert, util, and so on that point at the correct browserify shims.
Should I map node built-in packages to https://www.npmjs.com/package/browser-builtins ?
Looks like browserify no longer relies on browser-builtins bundle but maps to individual packages - https://unpkg.com/[email protected]/lib/builtins.js . So I guess I should do the same thing here.
I spent a while looking at this topic yesterday... namely comparing https://github.com/calvinmetcalf/rollup-plugin-node-builtins and https://unpkg.com/[email protected]/lib/builtins.js. Unfortunately, some of the choices rollup makes (like buffer-es6) are just forks of the browserify versions that are not as well maintained. (buffer-es6 is a good 100 commits behind buffer). I ultimately decided not to use rollup-plugin-node-builtins but rather use both rollup and browserify in consecutive build steps.
So... that illustrates the wonderful wonderful thing about getlibs I like so much. When it works It just works (TM). None of these awful build tools... which are wonderful yes, but now that I've tasted dynamic module loading I can't see how anyone would ever want to go back.
I'm rambling off topic. Yes, let's use the mappings in https://unpkg.com/[email protected]/lib/builtins.js except for the empty ones and ones that don't make sense. (console?)
A'ight, so I've whittled down the list to these:
assert: https://unpkg.com/assert buffer: https://unpkg.com/buffer crypto: https://unpkg.com/crypto-browserify domain: https://unpkg.com/domain-browser events: https://unpkg.com/events http: https://unpkg.com/stream-http https: https://unpkg.com/https-browserify os: https://unpkg.com/os-browserify path: https://unpkg.com/path-browserify punycode: https://unpkg.com/punycode querystring: https://unpkg.com/querystring stream: https://unpkg.com/stream-browserify util: https://unpkg.com/util tty: https://unpkg.com/tty-browserify url: https://unpkg.com/url vm: https://unpkg.com/vm-browserify zlib: https://unpkg.com/browserify-zlib process: https://unpkg.com/process
I need to think of a good way to test them. Lemme grab a coffee.
Test playground: https://codepen.io/wmhilton/project/editor/XbNoRz
Using configuration:
System.config({
meta: {
//util: {loader: 'js'}
},
map: {
assert: 'https://unpkg.com/assert',
buffer: 'https://unpkg.com/buffer',
crypto: 'https://unpkg.com/crypto-browserify',
domain: 'https://unpkg.com/domain-browser',
events: 'https://unpkg.com/events',
http: 'https://unpkg.com/stream-http',
https: 'https://unpkg.com/https-browserify',
os: 'https://unpkg.com/os-browserify',
path: 'https://unpkg.com/path-browserify',
punycode: 'https://unpkg.com/punycode',
querystring: 'https://unpkg.com/querystring',
stream: 'https://unpkg.com/stream-browserify',
util: 'https://unpkg.com/util/util.js',
'util/': 'https://unpkg.com/util/util.js',
tty: 'https://unpkg.com/tty-browserify',
url: 'https://unpkg.com/url',
vm: 'https://unpkg.com/vm-browserify',
zlib: 'https://unpkg.com/browserify-zlib',
process: 'https://unpkg.com/process'
}
})
System.load('./main.js')
Here's my results so far. commented out ones fail.
const { Buffer } = require('buffer');
alert(Buffer.isBuffer);
global.Buffer = Buffer
alert(require('process'));
global.process = require('process');
alert(require('assert'));
//alert(require('crypto'));
alert(require('domain'));
alert(require('events'));
//alert(require('http'));
//alert(require('https'));
alert(require('os'));
alert(require('path'));
alert(require('punycode'));
//alert(require('querystring'));
alert(require('stream'));
alert(require('util'));
alert(require('tty'));
alert(require('vm'));
//alert(require('zlib'));
//alert(require('url'));