diff options
author | 2023-09-18 20:14:32 -0700 | |
---|---|---|
committer | 2023-09-18 20:14:32 -0700 | |
commit | 1b949d4f5a855838c7169a4a6033fee6638c87f8 (patch) | |
tree | b8cca531ab95a4a0e613bbcee877d6bb0d4d3951 | |
parent | 064721668740397763a2ab6b6293d5d34a7b14a8 (diff) | |
download | bun-1b949d4f5a855838c7169a4a6033fee6638c87f8.tar.gz bun-1b949d4f5a855838c7169a4a6033fee6638c87f8.tar.zst bun-1b949d4f5a855838c7169a4a6033fee6638c87f8.zip |
`bun run` fix missing script error on empty file (#5025)
* Fix empty file not found bug
* Add tests
* fix test
---------
Co-authored-by: Jeremy Funk <jeremy@kombo.dev>
Co-authored-by: dave caruso <me@paperdave.net>
-rw-r--r-- | src/cli/run_command.zig | 1 | ||||
-rw-r--r-- | test/cli/run/empty-file.js | 0 | ||||
-rw-r--r-- | test/cli/run/empty-file.test.ts | 15 |
3 files changed, 15 insertions, 1 deletions
diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig index 3ef68b494..f31520cc8 100644 --- a/src/cli/run_command.zig +++ b/src/cli/run_command.zig @@ -973,7 +973,6 @@ pub const RunCommand = struct { var shebang: string = shebang_buf[0..shebang_size]; shebang = std.mem.trim(u8, shebang, " \r\n\t"); - if (shebang.len == 0) break :possibly_open_with_bun_js; if (strings.hasPrefixComptime(shebang, "#!")) { const first_arg: string = if (bun.argv().len > 0) bun.span(bun.argv()[0]) else ""; const filename = std.fs.path.basename(first_arg); diff --git a/test/cli/run/empty-file.js b/test/cli/run/empty-file.js new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/test/cli/run/empty-file.js diff --git a/test/cli/run/empty-file.test.ts b/test/cli/run/empty-file.test.ts new file mode 100644 index 000000000..f29162bf7 --- /dev/null +++ b/test/cli/run/empty-file.test.ts @@ -0,0 +1,15 @@ +import { it, expect } from "bun:test"; +import { bunEnv, bunExe } from "harness"; +import { join } from "path"; + +it("should execute empty scripts", () => { + const { stdout, stderr, exitCode } = Bun.spawnSync({ + cmd: [bunExe(), "run", "--bun", join(import.meta.dir, "empty-file.js")], + env: bunEnv, + stdout: "pipe", + stderr: "pipe", + }); + expect(stdout.toString()).toBeEmpty(); + expect(stderr.toString()).toBeEmpty(); + expect(exitCode).toBe(0); +}); |