diff options
author | 2022-07-11 03:41:03 -0700 | |
---|---|---|
committer | 2022-07-11 03:41:03 -0700 | |
commit | 7904f49b5dc48dc057729eb158067baf54f94cfb (patch) | |
tree | 0b84871ed4f116f9350240d5d667391870d5a7cd | |
parent | d35ca945c22917756e8c09f4fae750ed85b4b59f (diff) | |
download | bun-7904f49b5dc48dc057729eb158067baf54f94cfb.tar.gz bun-7904f49b5dc48dc057729eb158067baf54f94cfb.tar.zst bun-7904f49b5dc48dc057729eb158067baf54f94cfb.zip |
Fixes https://github.com/oven-sh/bun/issues/229
-rw-r--r-- | src/resolver/dir_info.zig | 2 | ||||
-rw-r--r-- | src/resolver/resolver.zig | 7 | ||||
-rw-r--r-- | test/apps/bun-run-check-nameless-package.json | 6 | ||||
-rw-r--r-- | test/apps/bun-run-check.sh | 47 |
4 files changed, 56 insertions, 6 deletions
diff --git a/src/resolver/dir_info.zig b/src/resolver/dir_info.zig index c8c54c490..86d165df9 100644 --- a/src/resolver/dir_info.zig +++ b/src/resolver/dir_info.zig @@ -31,6 +31,8 @@ enclosing_tsconfig_json: ?*const TSConfigJSON = null, /// package.json used for bundling /// it's the deepest one in the hierarchy with a "name" field +/// or, if using `bun run`, the name field is optional +/// https://github.com/oven-sh/bun/issues/229 enclosing_package_json: ?*PackageJSON = null, abs_path: string = "", diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig index 0a49e68a1..8dbbba50e 100644 --- a/src/resolver/resolver.zig +++ b/src/resolver/resolver.zig @@ -700,7 +700,7 @@ pub const Resolver = struct { while (iter.next()) |path| { var dir: *DirInfo = (r.readDirInfo(path.name.dir) catch continue) orelse continue; if (result.package_json) |existing| { - if (existing.name.len == 0) result.package_json = null; + if (existing.name.len == 0 or r.care_about_bin_folder) result.package_json = null; } result.package_json = result.package_json orelse dir.enclosing_package_json; @@ -2597,7 +2597,8 @@ pub const Resolver = struct { info.enclosing_tsconfig_json = parent.?.enclosing_tsconfig_json; if (parent.?.package_json) |parent_package_json| { - if (parent_package_json.name.len > 0) { + // https://github.com/oven-sh/bun/issues/229 + if (parent_package_json.name.len > 0 or r.care_about_bin_folder) { info.enclosing_package_json = parent_package_json; } } @@ -2645,7 +2646,7 @@ pub const Resolver = struct { info.package_json_for_browser_field = pkg; } - if (pkg.name.len > 0) + if (pkg.name.len > 0 or r.care_about_bin_folder) info.enclosing_package_json = pkg; if (r.debug_logs) |*logs| { diff --git a/test/apps/bun-run-check-nameless-package.json b/test/apps/bun-run-check-nameless-package.json new file mode 100644 index 000000000..8ace03613 --- /dev/null +++ b/test/apps/bun-run-check-nameless-package.json @@ -0,0 +1,6 @@ +{ + "scripts": { + "this-should-work": "echo \"✅ bun run test passed!\"", + "argv": "node -e 'console.log(process.argv)'" + } +} diff --git a/test/apps/bun-run-check.sh b/test/apps/bun-run-check.sh index a904959e9..c86062f7b 100644 --- a/test/apps/bun-run-check.sh +++ b/test/apps/bun-run-check.sh @@ -1,5 +1,7 @@ #!/usr/bin/env bash +# TODO: move this test to bun once we have a child_process equivalent. + set -euo pipefail (killall -9 "$(basename "$BUN_BIN")" || echo "") >/dev/null 2>&1 @@ -10,9 +12,48 @@ fn() { :; } # The important bit: export the function export -f fn -DIR=$(mktemp -d -t bun-run-check) +rm -rf /tmp/bun-run-check +mkdir -p /tmp/bun-run-check +DIR=/tmp/bun-run-check cp ./bun-run-check-package.json "$DIR/package.json" +cp ./bun-run-check-nameless-package.json "$DIR/package.json" + +cd "$DIR" + +$BUN_BIN run bash -- -c "" + +if (($?)); then + echo "Bash exported functions are broken" + exit 1 +fi + +# https://github.com/oven-sh/bun/issues/53 +rm -f "$DIR/bun-run-out.expected.txt" "$DIR/bun-run-out.txt" >/dev/null 2>&1 + +$BUN_BIN run --silent argv -- foo bar baz >"$DIR/bun-run-out.txt" +npm run --silent argv -- foo bar baz >"$DIR/bun-run-out.expected.txt" + +cmp -s "$DIR/bun-run-out.expected.txt" "$DIR/bun-run-out.txt" +if (($?)); then + echo "argv failed" + exit 1 +fi + +$BUN_BIN run --silent this-should-work + +if (($?)); then + echo "this-should work failed" + exit 1 +fi + +# Run it a second time with our other script which has no name + +rm -rf /tmp/bun-run-check +mkdir -p /tmp/bun-run-check +DIR=/tmp/bun-run-check + +cd "../" cd "$DIR" $BUN_BIN run bash -- -c "" @@ -25,8 +66,8 @@ fi # https://github.com/oven-sh/bun/issues/53 rm -f "$DIR/bun-run-out.expected.txt" "$DIR/bun-run-out.txt" >/dev/null 2>&1 -$BUN_BIN run --silent argv -- foo bar baz > "$DIR/bun-run-out.txt" -npm run --silent argv -- foo bar baz > "$DIR/bun-run-out.expected.txt" +$BUN_BIN run --silent argv -- foo bar baz >"$DIR/bun-run-out.txt" +npm run --silent argv -- foo bar baz >"$DIR/bun-run-out.expected.txt" cmp -s "$DIR/bun-run-out.expected.txt" "$DIR/bun-run-out.txt" if (($?)); then |