mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
[bun build] Automatically set target to bun when a hashbang is provided
This commit is contained in:
@@ -2592,7 +2592,7 @@ pub const ParseTask = struct {
|
||||
.contents_is_recycled = false,
|
||||
};
|
||||
|
||||
const target = use_directive.target(task.known_target orelse bundler.options.target);
|
||||
const target = targetFromHashbang(entry.contents) orelse use_directive.target(task.known_target orelse bundler.options.target);
|
||||
|
||||
var opts = js_parser.Parser.Options.init(task.jsx, loader);
|
||||
opts.legacy_transform_require_to_import = false;
|
||||
@@ -11320,3 +11320,16 @@ fn getRedirectId(id: u32) ?u32 {
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
fn targetFromHashbang(buffer: []const u8) ?options.Target {
|
||||
if (buffer.len > "#!/usr/bin/env bun".len) {
|
||||
if (strings.hasPrefixComptime(buffer, "#!/usr/bin/env bun")) {
|
||||
switch (buffer["#!/usr/bin/env bun".len]) {
|
||||
'\n', ' ' => return options.Target.bun,
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -400,6 +400,7 @@ pub const BuildCommand = struct {
|
||||
},
|
||||
},
|
||||
.encoding = .buffer,
|
||||
.mode = if (f.is_executable) 0o755 else 0o644,
|
||||
.dirfd = @intCast(bun.FileDescriptor, root_dir.dir.fd),
|
||||
.file = .{
|
||||
.path = JSC.Node.PathLike{
|
||||
|
||||
Reference in New Issue
Block a user