require('bare-node-runtime/global') const path = require('path') const { pathToFileURL } = require('url') const bnr = require('bare-node-runtime/imports') const root = path.join(__dirname, '..') const eventsShim = pathToFileURL(path.join(root, 'build/shims/node-events.cjs')).href const map = { ...bnr } map.events = { bare: eventsShim, default: 'events' } map['node:events'] = { bare: eventsShim, default: 'events' } const fs = require('fs') const imp = path.join(root, 'build/squid-imports.json') fs.writeFileSync(imp, JSON.stringify(map)) console.log('shim', eventsShim) const mod = require('events', { with: { imports: imp } }) const EE = mod.EventEmitter console.log('EE type', typeof EE) console.log('slice', String(EE).slice(0, 100)) function S() { EE.call(this) } try { const s = new S() console.log('call works', typeof s.on) } catch (e) { console.log('call failed', e.message) } try { const { Transform } = require('readable-stream', { with: { imports: imp } }) const t = new Transform({ transform (c, e, cb) { cb() } }) console.log('Transform ok', !!t) } catch (e) { console.log('Transform failed', e.message) }