diff options
author | 2023-01-29 00:10:24 -0800 | |
---|---|---|
committer | 2023-01-29 00:10:46 -0800 | |
commit | 75181ea1f3fa6361c46c7e2d2b81e630021958ae (patch) | |
tree | c2eb78b67630121186dba7a76e0ce178a3fa6196 | |
parent | d9c1a18776a9e692083b590a5d04b30efd9a4c03 (diff) | |
download | bun-75181ea1f3fa6361c46c7e2d2b81e630021958ae.tar.gz bun-75181ea1f3fa6361c46c7e2d2b81e630021958ae.tar.zst bun-75181ea1f3fa6361c46c7e2d2b81e630021958ae.zip |
Add helper
-rw-r--r-- | src/cli.zig | 2 | ||||
-rw-r--r-- | src/cli/run_command.zig | 4 | ||||
-rw-r--r-- | src/options.zig | 7 |
3 files changed, 10 insertions, 3 deletions
diff --git a/src/cli.zig b/src/cli.zig index 4b4f87ae9..5b0b47edd 100644 --- a/src/cli.zig +++ b/src/cli.zig @@ -1243,7 +1243,7 @@ pub const Command = struct { const force_using_bun = ctx.debug.run_in_bun; var did_check = false; if (default_loader) |loader| { - if (loader.isJavaScriptLike() or loader == .wasm) { + if (loader.canBeRunByBun()) { was_js_like = true; if (maybeOpenWithBunJS(&ctx)) { return; diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig index b6784cdf2..c266c8611 100644 --- a/src/cli/run_command.zig +++ b/src/cli/run_command.zig @@ -731,7 +731,7 @@ pub const RunCommand = struct { while (iter.next()) |entry| { const value = entry.value_ptr.*; const name = value.base(); - if (name[0] != '.' and this_bundler.options.loader(std.fs.path.extension(name)).isJavaScriptLike() and + if (name[0] != '.' and this_bundler.options.loader(std.fs.path.extension(name)).canBeRunByBun() and !strings.contains(name, ".config") and !strings.contains(name, ".d.ts") and !strings.contains(name, ".d.mts") and @@ -857,7 +857,7 @@ pub const RunCommand = struct { possibly_open_with_bun_js: { if (!force_using_bun) { if (options.defaultLoaders.get(std.fs.path.extension(script_name_to_search))) |load| { - if (!(load.isJavaScriptLike() or load == .wasm)) + if (!load.canBeRunByBun()) break :possibly_open_with_bun_js; } else { break :possibly_open_with_bun_js; diff --git a/src/options.zig b/src/options.zig index e161e9582..863e12e14 100644 --- a/src/options.zig +++ b/src/options.zig @@ -636,6 +636,13 @@ pub const Loader = enum(u4) { wasm, napi, + pub fn canBeRunByBun(this: Loader) bool { + return switch (this) { + .jsx, .js, .ts, .tsx, .json, .wasm => true, + else => false, + }; + } + pub const Map = std.EnumArray(Loader, string); pub const stdin_name: Map = brk: { var map = Map.initFill(""); |