diff options
-rw-r--r-- | src/cli/run_command.zig | 3 | ||||
-rw-r--r-- | src/js/builtins/ProcessObjectInternals.ts | 11 | ||||
-rw-r--r-- | src/js/out/WebCoreJSBuiltins.cpp | 4 |
3 files changed, 9 insertions, 9 deletions
diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig index 490cbe111..b445ccdc4 100644 --- a/src/cli/run_command.zig +++ b/src/cli/run_command.zig @@ -1079,8 +1079,7 @@ pub const RunCommand = struct { return true; } else if ((script_name_to_search.len > 1 and script_name_to_search[0] == '/') or - (script_name_to_search.len > 2 and script_name_to_search[0] == '.' and script_name_to_search[1] == '/' and - script_name_to_search[script_name_to_search.len - 1] != '/')) + (script_name_to_search.len > 2 and script_name_to_search[0] == '.' and script_name_to_search[1] == '/')) { Run.boot(ctx, ctx.allocator.dupe(u8, script_name_to_search) catch unreachable) catch |err| { if (Output.enable_ansi_colors) { diff --git a/src/js/builtins/ProcessObjectInternals.ts b/src/js/builtins/ProcessObjectInternals.ts index af51d25cd..242b310fd 100644 --- a/src/js/builtins/ProcessObjectInternals.ts +++ b/src/js/builtins/ProcessObjectInternals.ts @@ -128,9 +128,9 @@ export function getStdioWriteStream(fd_, getWindowSize) { _write(chunk, encoding, callback) { if (!this.#writeStream) { var { createWriteStream } = require("node:fs"); - this.#writeStream = createWriteStream(this.#fdPath); + var stream = (this.#writeStream = createWriteStream(this.#fdPath)); - this.#writeStream.on("finish", () => { + stream.on("finish", () => { if (this.#onFinish) { const cb = this.#onFinish; this.#onFinish = null; @@ -138,7 +138,7 @@ export function getStdioWriteStream(fd_, getWindowSize) { } }); - this.#writeStream.on("drain", () => { + stream.on("drain", () => { if (this.#onDrain) { const cb = this.#onDrain; this.#onDrain = null; @@ -146,14 +146,15 @@ export function getStdioWriteStream(fd_, getWindowSize) { } }); - eos(this.#writeStream, err => { + eos(stream, err => { this.#writable = false; if (err) { - destroy(this.#writeStream, err); + destroy(stream, err); } this.#onFinished(err); }); } + if (this.#writeStream.write(chunk, encoding)) { callback(); } else { diff --git a/src/js/out/WebCoreJSBuiltins.cpp b/src/js/out/WebCoreJSBuiltins.cpp index 5dbc6c2c9..3f9361d13 100644 --- a/src/js/out/WebCoreJSBuiltins.cpp +++ b/src/js/out/WebCoreJSBuiltins.cpp @@ -646,9 +646,9 @@ const char* const s_processObjectInternalsBindingCode = "(function (bindingName) const JSC::ConstructAbility s_processObjectInternalsGetStdioWriteStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; const JSC::ConstructorKind s_processObjectInternalsGetStdioWriteStreamCodeConstructorKind = JSC::ConstructorKind::None; const JSC::ImplementationVisibility s_processObjectInternalsGetStdioWriteStreamCodeImplementationVisibility = JSC::ImplementationVisibility::Public; -const int s_processObjectInternalsGetStdioWriteStreamCodeLength = 7801; +const int s_processObjectInternalsGetStdioWriteStreamCodeLength = 7764; static const JSC::Intrinsic s_processObjectInternalsGetStdioWriteStreamCodeIntrinsic = JSC::NoIntrinsic; -const char* const s_processObjectInternalsGetStdioWriteStreamCode = "(function (fd_,getWindowSize){\"use strict\";var EventEmitter=@getInternalField(@internalModuleRegistry,15)||@createInternalModuleById(15);function createStdioWriteStream(fd_2){var{Duplex,eos,destroy}=@getInternalField(@internalModuleRegistry,34)||@createInternalModuleById(34),StdioWriteStream=class StdioWriteStream2 extends Duplex{#writeStream;#readStream;#readable=!0;#writable=!0;#fdPath;#onClose;#onDrain;#onFinish;#onReadable;#isTTY;get isTTY(){return this.#isTTY\?\?=@requireNativeModule(\"node:tty\").isatty(fd_2)}get fd(){return fd_2}get writable(){return this.#writable}get readable(){return this.#readable}constructor(fd){super({readable:!0,writable:!0});this.#fdPath=`/dev/fd/${fd}`}#onFinished(err){const cb=this.#onClose;if(this.#onClose=null,cb)cb(err);else if(err)this.destroy(err);else if(!this.#readable&&!this.#writable)this.destroy()}_destroy(err,callback){if(!err&&this.#onClose!==null){var AbortError=class AbortError2 extends Error{code;name;constructor(message=\"The operation was aborted\",options=void 0){if(options!==void 0&&typeof options!==\"object\")throw new Error(`Invalid AbortError options:\\n\\n${JSON.stringify(options,null,2)}`);super(message,options);this.code=\"ABORT_ERR\",this.name=\"AbortError\"}};err=new AbortError}if(this.#onDrain=null,this.#onFinish=null,this.#onClose===null)callback(err);else{if(this.#onClose=callback,this.#writeStream)destroy(this.#writeStream,err);if(this.#readStream)destroy(this.#readStream,err)}}_write(chunk,encoding,callback){if(!this.#writeStream){var{createWriteStream}=@getInternalField(@internalModuleRegistry,16)||@createInternalModuleById(16);this.#writeStream=createWriteStream(this.#fdPath),this.#writeStream.on(\"finish\",()=>{if(this.#onFinish){const cb=this.#onFinish;this.#onFinish=null,cb()}}),this.#writeStream.on(\"drain\",()=>{if(this.#onDrain){const cb=this.#onDrain;this.#onDrain=null,cb()}}),eos(this.#writeStream,(err)=>{if(this.#writable=!1,err)destroy(this.#writeStream,err);this.#onFinished(err)})}if(this.#writeStream.write(chunk,encoding))callback();else this.#onDrain=callback}_final(callback){this.#writeStream&&this.#writeStream.end(),this.#onFinish=callback}#loadReadStream(){var{createReadStream}=@getInternalField(@internalModuleRegistry,16)||@createInternalModuleById(16),readStream=this.#readStream=createReadStream(this.#fdPath);return readStream.on(\"readable\",()=>{if(this.#onReadable){const cb=this.#onReadable;this.#onReadable=null,cb()}else this.read()}),readStream.on(\"end\",()=>{this.push(null)}),eos(readStream,(err)=>{if(this.#readable=!1,err)destroy(readStream,err);this.#onFinished(err)}),readStream}_read(){var stream=this.#readStream;if(!stream)stream=this.#loadReadStream();while(!0){const buf=stream.read();if(buf===null||!this.push(buf))return}}};return new StdioWriteStream(fd_2)}function isFastEncoding(encoding){if(!encoding)return!0;var normalied=encoding.toLowerCase();return normalied===\"utf8\"||normalied===\"utf-8\"||normalied===\"buffer\"||normalied===\"binary\"}var readline,windowSizeArray=[0,0],FastStdioWriteStreamInternal=class StdioWriteStream extends EventEmitter{#fd;#innerStream;#writer;#isTTY;bytesWritten=0;setDefaultEncoding(encoding){if(this.#innerStream||!isFastEncoding(encoding))return this.#ensureInnerStream(),this.#innerStream.setDefaultEncoding(encoding)}#createWriter(){switch(this.#fd){case 1:{var writer=@Bun.stdout.writer({highWaterMark:0});return writer.unref(),writer}case 2:{var writer=@Bun.stderr.writer({highWaterMark:0});return writer.unref(),writer}default:throw new Error(\"Unsupported writer\")}}#getWriter(){return this.#writer\?\?=this.#createWriter()}constructor(fd_2){super();this.#fd=fd_2}get fd(){return this.#fd}ref(){this.#getWriter().ref()}unref(){this.#getWriter().unref()}on(event,listener){if(event===\"close\"||event===\"finish\")return this.#ensureInnerStream(),this.#innerStream.on(event,listener);if(event===\"drain\")return super.on(\"drain\",listener);if(event===\"error\")return super.on(\"error\",listener);return super.on(event,listener)}get _writableState(){return this.#ensureInnerStream(),this.#innerStream._writableState}get _readableState(){return this.#ensureInnerStream(),this.#innerStream._readableState}get writable(){return this.#ensureInnerStream(),this.#innerStream.writable}get readable(){return this.#ensureInnerStream(),this.#innerStream.readable}pipe(destination){return this.#ensureInnerStream(),this.#innerStream.pipe(destination)}unpipe(destination){return this.#ensureInnerStream(),this.#innerStream.unpipe(destination)}#ensureInnerStream(){if(this.#innerStream)return;this.#innerStream=createStdioWriteStream(this.#fd);const events=this.eventNames();for(let event of events)this.#innerStream.on(event,(...args)=>{this.emit(event,...args)})}#write1(chunk){var writer=this.#getWriter();const writeResult=writer.write(chunk);this.bytesWritten+=writeResult;const flushResult=writer.flush(!1);return!!(writeResult||flushResult)}#writeWithEncoding(chunk,encoding){if(!isFastEncoding(encoding))return this.#ensureInnerStream(),this.#innerStream.write(chunk,encoding);return this.#write1(chunk)}#performCallback(cb,err){if(err)this.emit(\"error\",err);try{cb(err\?err:null)}catch(err2){this.emit(\"error\",err2)}}#writeWithCallbackAndEncoding(chunk,encoding,callback){if(!isFastEncoding(encoding))return this.#ensureInnerStream(),this.#innerStream.write(chunk,encoding,callback);var writer=this.#getWriter();const writeResult=writer.write(chunk),flushResult=writer.flush(!0);if(flushResult\?.then)return flushResult.then(()=>{this.#performCallback(callback),this.emit(\"drain\")},(err)=>this.#performCallback(callback,err)),!1;return queueMicrotask(()=>{this.#performCallback(callback)}),!!(writeResult||flushResult)}get isTTY(){return!1}write(chunk,encoding,callback){const result=this._write(chunk,encoding,callback);if(result)this.emit(\"drain\");return result}get hasColors(){return @Bun.tty[this.#fd].hasColors}_write(chunk,encoding,callback){var inner=this.#innerStream;if(inner)return inner.write(chunk,encoding,callback);switch(arguments.length){case 0:{var error=new Error(\"Invalid arguments\");throw error.code=\"ERR_INVALID_ARG_TYPE\",error}case 1:return this.#write1(chunk);case 2:if(typeof encoding===\"function\")return this.#writeWithCallbackAndEncoding(chunk,\"\",encoding);else if(typeof encoding===\"string\")return this.#writeWithEncoding(chunk,encoding);default:{if(typeof encoding!==\"undefined\"&&typeof encoding!==\"string\"||typeof callback!==\"undefined\"&&typeof callback!==\"function\"){var error=new Error(\"Invalid arguments\");throw error.code=\"ERR_INVALID_ARG_TYPE\",error}if(typeof callback===\"undefined\")return this.#writeWithEncoding(chunk,encoding);return this.#writeWithCallbackAndEncoding(chunk,encoding,callback)}}}destroy(){return this}end(){return this}};if(getWindowSize(fd_,windowSizeArray)){var WriteStream=class WriteStream2 extends FastStdioWriteStreamInternal{get isTTY(){return!0}cursorTo(x,y,callback){return(readline\?\?=@getInternalField(@internalModuleRegistry,30)||@createInternalModuleById(30)).cursorTo(this,x,y,callback)}moveCursor(dx,dy,callback){return(readline\?\?=@getInternalField(@internalModuleRegistry,30)||@createInternalModuleById(30)).moveCursor(this,dx,dy,callback)}clearLine(dir,callback){return(readline\?\?=@getInternalField(@internalModuleRegistry,30)||@createInternalModuleById(30)).clearLine(this,dir,callback)}clearScreenDown(callback){return(readline\?\?=@getInternalField(@internalModuleRegistry,30)||@createInternalModuleById(30)).clearScreenDown(this,callback)}getWindowSize(){if(getWindowSize(fd_,windowSizeArray)===!0)return[windowSizeArray[0],windowSizeArray[1]]}get columns(){if(getWindowSize(fd_,windowSizeArray)===!0)return windowSizeArray[0]}get rows(){if(getWindowSize(fd_,windowSizeArray)===!0)return windowSizeArray[1]}};return new WriteStream(fd_)}return new FastStdioWriteStreamInternal(fd_)})\n"; +const char* const s_processObjectInternalsGetStdioWriteStreamCode = "(function (fd_,getWindowSize){\"use strict\";var EventEmitter=@getInternalField(@internalModuleRegistry,15)||@createInternalModuleById(15);function createStdioWriteStream(fd_2){var{Duplex,eos,destroy}=@getInternalField(@internalModuleRegistry,34)||@createInternalModuleById(34),StdioWriteStream=class StdioWriteStream2 extends Duplex{#writeStream;#readStream;#readable=!0;#writable=!0;#fdPath;#onClose;#onDrain;#onFinish;#onReadable;#isTTY;get isTTY(){return this.#isTTY\?\?=@requireNativeModule(\"node:tty\").isatty(fd_2)}get fd(){return fd_2}get writable(){return this.#writable}get readable(){return this.#readable}constructor(fd){super({readable:!0,writable:!0});this.#fdPath=`/dev/fd/${fd}`}#onFinished(err){const cb=this.#onClose;if(this.#onClose=null,cb)cb(err);else if(err)this.destroy(err);else if(!this.#readable&&!this.#writable)this.destroy()}_destroy(err,callback){if(!err&&this.#onClose!==null){var AbortError=class AbortError2 extends Error{code;name;constructor(message=\"The operation was aborted\",options=void 0){if(options!==void 0&&typeof options!==\"object\")throw new Error(`Invalid AbortError options:\\n\\n${JSON.stringify(options,null,2)}`);super(message,options);this.code=\"ABORT_ERR\",this.name=\"AbortError\"}};err=new AbortError}if(this.#onDrain=null,this.#onFinish=null,this.#onClose===null)callback(err);else{if(this.#onClose=callback,this.#writeStream)destroy(this.#writeStream,err);if(this.#readStream)destroy(this.#readStream,err)}}_write(chunk,encoding,callback){if(!this.#writeStream){var{createWriteStream}=@getInternalField(@internalModuleRegistry,16)||@createInternalModuleById(16),stream=this.#writeStream=createWriteStream(this.#fdPath);stream.on(\"finish\",()=>{if(this.#onFinish){const cb=this.#onFinish;this.#onFinish=null,cb()}}),stream.on(\"drain\",()=>{if(this.#onDrain){const cb=this.#onDrain;this.#onDrain=null,cb()}}),eos(stream,(err)=>{if(this.#writable=!1,err)destroy(stream,err);this.#onFinished(err)})}if(this.#writeStream.write(chunk,encoding))callback();else this.#onDrain=callback}_final(callback){this.#writeStream&&this.#writeStream.end(),this.#onFinish=callback}#loadReadStream(){var{createReadStream}=@getInternalField(@internalModuleRegistry,16)||@createInternalModuleById(16),readStream=this.#readStream=createReadStream(this.#fdPath);return readStream.on(\"readable\",()=>{if(this.#onReadable){const cb=this.#onReadable;this.#onReadable=null,cb()}else this.read()}),readStream.on(\"end\",()=>{this.push(null)}),eos(readStream,(err)=>{if(this.#readable=!1,err)destroy(readStream,err);this.#onFinished(err)}),readStream}_read(){var stream=this.#readStream;if(!stream)stream=this.#loadReadStream();while(!0){const buf=stream.read();if(buf===null||!this.push(buf))return}}};return new StdioWriteStream(fd_2)}function isFastEncoding(encoding){if(!encoding)return!0;var normalied=encoding.toLowerCase();return normalied===\"utf8\"||normalied===\"utf-8\"||normalied===\"buffer\"||normalied===\"binary\"}var readline,windowSizeArray=[0,0],FastStdioWriteStreamInternal=class StdioWriteStream extends EventEmitter{#fd;#innerStream;#writer;#isTTY;bytesWritten=0;setDefaultEncoding(encoding){if(this.#innerStream||!isFastEncoding(encoding))return this.#ensureInnerStream(),this.#innerStream.setDefaultEncoding(encoding)}#createWriter(){switch(this.#fd){case 1:{var writer=@Bun.stdout.writer({highWaterMark:0});return writer.unref(),writer}case 2:{var writer=@Bun.stderr.writer({highWaterMark:0});return writer.unref(),writer}default:throw new Error(\"Unsupported writer\")}}#getWriter(){return this.#writer\?\?=this.#createWriter()}constructor(fd_2){super();this.#fd=fd_2}get fd(){return this.#fd}ref(){this.#getWriter().ref()}unref(){this.#getWriter().unref()}on(event,listener){if(event===\"close\"||event===\"finish\")return this.#ensureInnerStream(),this.#innerStream.on(event,listener);if(event===\"drain\")return super.on(\"drain\",listener);if(event===\"error\")return super.on(\"error\",listener);return super.on(event,listener)}get _writableState(){return this.#ensureInnerStream(),this.#innerStream._writableState}get _readableState(){return this.#ensureInnerStream(),this.#innerStream._readableState}get writable(){return this.#ensureInnerStream(),this.#innerStream.writable}get readable(){return this.#ensureInnerStream(),this.#innerStream.readable}pipe(destination){return this.#ensureInnerStream(),this.#innerStream.pipe(destination)}unpipe(destination){return this.#ensureInnerStream(),this.#innerStream.unpipe(destination)}#ensureInnerStream(){if(this.#innerStream)return;this.#innerStream=createStdioWriteStream(this.#fd);const events=this.eventNames();for(let event of events)this.#innerStream.on(event,(...args)=>{this.emit(event,...args)})}#write1(chunk){var writer=this.#getWriter();const writeResult=writer.write(chunk);this.bytesWritten+=writeResult;const flushResult=writer.flush(!1);return!!(writeResult||flushResult)}#writeWithEncoding(chunk,encoding){if(!isFastEncoding(encoding))return this.#ensureInnerStream(),this.#innerStream.write(chunk,encoding);return this.#write1(chunk)}#performCallback(cb,err){if(err)this.emit(\"error\",err);try{cb(err\?err:null)}catch(err2){this.emit(\"error\",err2)}}#writeWithCallbackAndEncoding(chunk,encoding,callback){if(!isFastEncoding(encoding))return this.#ensureInnerStream(),this.#innerStream.write(chunk,encoding,callback);var writer=this.#getWriter();const writeResult=writer.write(chunk),flushResult=writer.flush(!0);if(flushResult\?.then)return flushResult.then(()=>{this.#performCallback(callback),this.emit(\"drain\")},(err)=>this.#performCallback(callback,err)),!1;return queueMicrotask(()=>{this.#performCallback(callback)}),!!(writeResult||flushResult)}get isTTY(){return!1}write(chunk,encoding,callback){const result=this._write(chunk,encoding,callback);if(result)this.emit(\"drain\");return result}get hasColors(){return @Bun.tty[this.#fd].hasColors}_write(chunk,encoding,callback){var inner=this.#innerStream;if(inner)return inner.write(chunk,encoding,callback);switch(arguments.length){case 0:{var error=new Error(\"Invalid arguments\");throw error.code=\"ERR_INVALID_ARG_TYPE\",error}case 1:return this.#write1(chunk);case 2:if(typeof encoding===\"function\")return this.#writeWithCallbackAndEncoding(chunk,\"\",encoding);else if(typeof encoding===\"string\")return this.#writeWithEncoding(chunk,encoding);default:{if(typeof encoding!==\"undefined\"&&typeof encoding!==\"string\"||typeof callback!==\"undefined\"&&typeof callback!==\"function\"){var error=new Error(\"Invalid arguments\");throw error.code=\"ERR_INVALID_ARG_TYPE\",error}if(typeof callback===\"undefined\")return this.#writeWithEncoding(chunk,encoding);return this.#writeWithCallbackAndEncoding(chunk,encoding,callback)}}}destroy(){return this}end(){return this}};if(getWindowSize(fd_,windowSizeArray)){var WriteStream=class WriteStream2 extends FastStdioWriteStreamInternal{get isTTY(){return!0}cursorTo(x,y,callback){return(readline\?\?=@getInternalField(@internalModuleRegistry,30)||@createInternalModuleById(30)).cursorTo(this,x,y,callback)}moveCursor(dx,dy,callback){return(readline\?\?=@getInternalField(@internalModuleRegistry,30)||@createInternalModuleById(30)).moveCursor(this,dx,dy,callback)}clearLine(dir,callback){return(readline\?\?=@getInternalField(@internalModuleRegistry,30)||@createInternalModuleById(30)).clearLine(this,dir,callback)}clearScreenDown(callback){return(readline\?\?=@getInternalField(@internalModuleRegistry,30)||@createInternalModuleById(30)).clearScreenDown(this,callback)}getWindowSize(){if(getWindowSize(fd_,windowSizeArray)===!0)return[windowSizeArray[0],windowSizeArray[1]]}get columns(){if(getWindowSize(fd_,windowSizeArray)===!0)return windowSizeArray[0]}get rows(){if(getWindowSize(fd_,windowSizeArray)===!0)return windowSizeArray[1]}};return new WriteStream(fd_)}return new FastStdioWriteStreamInternal(fd_)})\n"; // getStdinStream const JSC::ConstructAbility s_processObjectInternalsGetStdinStreamCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; |