Skip to content

Commit

Permalink
run files without extensions (#4113)
Browse files Browse the repository at this point in the history
* run script without extension

* process stdio write fix
  • Loading branch information
dylan-conway authored and Jarred-Sumner committed Aug 11, 2023
1 parent c314346 commit 18fe04f
Showing 4 changed files with 46 additions and 11 deletions.
17 changes: 17 additions & 0 deletions src/cli/run_command.zig
Original file line number Diff line number Diff line change
@@ -1078,6 +1078,23 @@ 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] != '/'))
{
Run.boot(ctx, ctx.allocator.dupe(u8, script_name_to_search) catch unreachable) catch |err| {
if (Output.enable_ansi_colors) {
ctx.log.printForLogLevelWithEnableAnsiColors(Output.errorWriter(), true) catch {};
} else {
ctx.log.printForLogLevelWithEnableAnsiColors(Output.errorWriter(), false) catch {};
}

Output.prettyErrorln("<r><red>error<r>: Failed to run <b>{s}<r> due to error <b>{s}<r>", .{
std.fs.path.basename(script_name_to_search),
@errorName(err),
});
Global.exit(1);
};
}
},
}
30 changes: 24 additions & 6 deletions src/js/builtins/ProcessObjectInternals.ts
Original file line number Diff line number Diff line change
@@ -71,6 +71,14 @@ export function getStdioWriteStream(fd_, getWindowSize) {
return fd_;
}

get writable() {
return this.#writable;
}

get readable() {
return this.#readable;
}

constructor(fd) {
super({ readable: true, writable: true });
this.#fdPath = `/dev/fd/${fd}`;
@@ -120,33 +128,33 @@ export function getStdioWriteStream(fd_, getWindowSize) {
_write(chunk, encoding, callback) {
if (!this.#writeStream) {
var { createWriteStream } = require("node:fs");
var stream = (this.#writeStream = createWriteStream(this.#fdPath));
this.#writeStream = createWriteStream(this.#fdPath);

stream.on("finish", () => {
this.#writeStream.on("finish", () => {
if (this.#onFinish) {
const cb = this.#onFinish;
this.#onFinish = null;
cb();
}
});

stream.on("drain", () => {
this.#writeStream.on("drain", () => {
if (this.#onDrain) {
const cb = this.#onDrain;
this.#onDrain = null;
cb();
}
});

eos(stream, err => {
eos(this.#writeStream, err => {
this.#writable = false;
if (err) {
destroy(stream, err);
destroy(this.#writeStream, err);
}
this.#onFinished(err);
});
}
if (stream.write(chunk, encoding)) {
if (this.#writeStream.write(chunk, encoding)) {
callback();
} else {
this.#onDrain = callback;
@@ -296,6 +304,16 @@ export function getStdioWriteStream(fd_, getWindowSize) {
return this.#innerStream._readableState;
}

get writable() {
this.#ensureInnerStream();
return this.#innerStream.writable;
}

get readable() {
this.#ensureInnerStream();
return this.#innerStream.readable;
}

pipe(destination) {
this.#ensureInnerStream();
return this.#innerStream.pipe(destination);
Loading

0 comments on commit 18fe04f

Please sign in to comment.