Closed niieani closed 1 year ago
@arcanis got any feedback? would love to get this merged, as it's making it impossible to use clipanion in bun
without manually patching the package.
What's the exact repro? Running the following with bun 1.0 doesn't fail for me (the code doesn't seem incorrect to me):
'use strict';
Object.defineProperty(exports, `__esModule`, {value: true});
var tty = require(`tty`);
function _interopDefaultLegacy (e) { return e && typeof e === `object` && `default` in e ? e : {default: e}; }
var tty__default = /*#__PURE__*/_interopDefaultLegacy(tty);
tty__default.default && `getColorDepth` in tty__default.default.WriteStream.prototype;
Making a require('./lib/advanced')
fails, but with an error that suggests it's a bug in Bun:
82 | }, WriteStream.prototype.clearScreenDown = function(cb) {
83 | return (readline ??= @getInternalField(@internalModuleRegistry, 33) || @createInternalModuleById(33)).clearScreenDown(this, cb);
84 | }, WriteStream.prototype.cursorTo = function(x, y, cb) {
85 | return (readline ??= @getInternalField(@internalModuleRegistry, 33) || @createInternalModuleById(33)).cursorTo(this, x, y, cb);
86 |
87 | }, WriteStream.prototype.getColorDepth = function(env = process.env) {
^
ReferenceError: Can't find variable: RegExpPrototypeExec
at node:tty:87:106
at getDefaultColorDepth (/Users/mael.nison/clipanion/lib/platform/node.js:13:15)
at /Users/mael.nison/clipanion/lib/advanced/Cli.js:454:16
at globalThis (/Users/mael.nison/clipanion/lib/advanced/Cli.js:462:18)
at require (:1:20)
at /Users/mael.nison/clipanion/lib/advanced/index.js:8:4
at globalThis (/Users/mael.nison/clipanion/lib/advanced/index.js:21:17)
at require (:1:20)
From the look of it Bun 1.0.3 seems to work great with Clipanion, I'm going to close this PR:
$ bun init -y
$ bun add clipanion
$ cp ~/clipanion/demos/advanced.ts .
$ sed -i '' 's#../sources/advanced#clipanion#' ./advanced.ts
$ bun run ./advanced.ts
Usage Error: Invalid value for maxRetries: expected to be at least 1 (got 0)
$ yarn [--frozen-lockfile] [--max-retries #0]
The rollup-compiled .js version of the distributable
lib/platform/node.js
tries to access thedefault
property of thedefault
export from the'tty'
package. Somehow this works innode
(probably because node circularly re-wrapsdefault
export), but fails inbun
, which is more strict. The code generated by Rollup is clearly invalid (offending parttty__default['default']
).This PR fixes the problem by correcting the
tty
import, and changing the check forgetColorDepth
function to be a little more permissive (WriteStream is not fully implemented in bun yet).Original error:
Offending code: