Skip to content

Commit

Permalink
feat: polyfill more node:* modules in bundle engines
Browse files Browse the repository at this point in the history
  • Loading branch information
ChALkeR committed Sep 8, 2024
1 parent 7d41038 commit 1deb507
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions bundler/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,27 @@ export const build = async (...files) => {

const hasBuffer = ['node', 'bun'].includes(options.platform)
const api = (f) => resolveRequire(`./modules/${f}`)
const nodeUnprefixed = {
assert: dirname(dirname(resolveRequire('assert/'))),
'assert/strict': api('assert-strict.cjs'),
buffer: hasBuffer ? api('node-buffer.cjs') : dirname(resolveRequire('buffer/')),
child_process: api('child_process.cjs'),
constants: resolveRequire('constants-browserify'),
crypto: api('crypto.cjs'),
events: dirname(resolveRequire('events/')),
fs: api('fs.cjs'),
'fs/promises': api('fs-promises.cjs'),
http: api('http.cjs'),
https: api('https.cjs'),
os: resolveRequire('os-browserify'),
path: resolveRequire('path-browserify'),
querystring: resolveRequire('querystring-es3'),
stream: resolveRequire('stream-browserify'),
timers: resolveRequire('timers-browserify'),
url: dirname(resolveRequire('url/')),
util: dirname(resolveRequire('util/')),
zlib: resolveRequire('browserify-zlib'),
}
const res = await buildWrap({
logLevel: 'silent',
stdin: {
Expand Down Expand Up @@ -214,29 +235,9 @@ export const build = async (...files) => {
'node:test': resolveImport('../src/node.js'),
// Inner
'exodus-test:util-format': api('util-format.cjs'),
// Node browserify
'node:assert': dirname(dirname(resolveRequire('assert/'))),
'node:assert/strict': api('assert-strict.cjs'),
'node:fs': api('fs.cjs'),
'node:fs/promises': api('fs-promises.cjs'),
fs: api('fs.cjs'),
'fs/promises': api('fs-promises.cjs'),
assert: dirname(dirname(resolveRequire('assert/'))),
buffer: hasBuffer ? api('node-buffer.cjs') : dirname(resolveRequire('buffer/')),
child_process: api('child_process.cjs'),
constants: resolveRequire('constants-browserify'),
crypto: api('crypto.cjs'),
events: dirname(resolveRequire('events/')),
http: api('http.cjs'),
https: api('https.cjs'),
os: resolveRequire('os-browserify'),
path: resolveRequire('path-browserify'),
querystring: resolveRequire('querystring-es3'),
stream: resolveRequire('stream-browserify'),
timers: resolveRequire('timers-browserify'),
url: dirname(resolveRequire('url/')),
util: dirname(resolveRequire('util/')),
zlib: resolveRequire('browserify-zlib'),
// Node.js (except node:test)
...Object.fromEntries(Object.entries(nodeUnprefixed).map(([k, v]) => [`node:${k}`, v])),
...nodeUnprefixed,
// expect-related deps
'ansi-styles': api('ansi-styles.cjs'),
'jest-util': api('jest-util.js'),
Expand Down

0 comments on commit 1deb507

Please sign in to comment.