some fixes

This commit is contained in:
dave caruso
2024-12-03 03:11:03 -08:00
committed by snwy
parent 56b729d87b
commit 185bdfbbb6
5 changed files with 58 additions and 30 deletions

View File

@@ -468,7 +468,7 @@ pub const Framework = struct {
} else if (exts_js.isArray()) {
var it_2 = exts_js.arrayIterator(global);
var i_2: usize = 0;
const extensions = try arena.alloc([]const u8, array.getLength(global));
const extensions = try arena.alloc([]const u8, exts_js.getLength(global));
while (it_2.next()) |array_item| : (i_2 += 1) {
const slice = refs.track(try array_item.toSlice2(global, arena));
if (bun.strings.eqlComptime(slice, "*"))
@@ -616,8 +616,10 @@ pub const Framework = struct {
});
if (mode != .development) {
out.options.entry_naming = "[name]-[hash].[ext]";
out.options.chunk_naming = "chunk-[name]-[hash].[ext]";
// Hide information about the source repository, at the cost of debugging quality.
out.options.entry_naming = "_bun/[hash].[ext]";
out.options.chunk_naming = "_bun/[hash].[ext]";
out.options.asset_naming = "_bun/[hash].[ext]";
}
out.resolver.opts = out.options;

View File

@@ -185,6 +185,9 @@ pub fn buildWithVm(ctx: bun.CLI.Command.Context, cwd: []const u8, vm: *VirtualMa
bundler.options.minify_syntax = false;
bundler.options.minify_identifiers = false;
bundler.options.minify_whitespace = false;
bundler.resolver.opts.entry_naming = "";
bundler.resolver.opts.chunk_naming = "";
bundler.resolver.opts.asset_naming = "";
}
}
@@ -293,15 +296,22 @@ pub fn buildWithVm(ctx: bun.CLI.Command.Context, cwd: []const u8, vm: *VirtualMa
}
}
switch (file.side orelse .client) {
switch (file.side orelse continue) {
.client => {
// Client-side resources will be written to disk for usage in on the client side
_ = try file.writeToDisk(root_dir, root_dir_path);
_ = file.writeToDisk(root_dir, ".") catch |err| {
bun.handleErrorReturnTrace(err, @errorReturnTrace());
Output.err(err, "Failed to write {} to output directory", .{bun.fmt.quote(file.dest_path)});
};
},
.server => {
// For Debugging
if (ctx.bundler_options.bake_debug_dump_server)
_ = try file.writeToDisk(root_dir, root_dir_path);
if (ctx.bundler_options.bake_debug_dump_server) {
_ = file.writeToDisk(root_dir, ".") catch |err| {
bun.handleErrorReturnTrace(err, @errorReturnTrace());
Output.err(err, "Failed to write {} to output directory", .{bun.fmt.quote(file.dest_path)});
};
}
switch (file.output_kind) {
.@"entry-point", .chunk => {

View File

@@ -11084,7 +11084,7 @@ pub const LinkerContext = struct {
const items = try allocator.alloc(Expr, st.items.len);
for (st.items, items) |item, *str| {
str.* = Expr.init(E.String, .{ .data = item.original_name }, item.name.loc);
str.* = Expr.init(E.String, .{ .data = item.alias }, item.name.loc);
}
break :call Expr.init(E.Call, .{

View File

@@ -9062,7 +9062,7 @@ fn NewParser_(
if (symbol.namespace_alias == null) {
symbol.namespace_alias = .{
.namespace_ref = stmt.namespace_ref,
.alias = name,
.alias = item.alias,
.import_record_index = stmt.import_record_index,
};
}

View File

@@ -2071,42 +2071,58 @@ pub const OutputFile = struct {
}
/// Given the `--outdir` as root_dir, this will return the relative path to display in terminal
pub fn writeToDisk(f: OutputFile, root_dir: std.fs.Dir, root_dir_path: []const u8) ![]const u8 {
pub fn writeToDisk(f: OutputFile, root_dir: std.fs.Dir, longest_common_path: []const u8) ![]const u8 {
switch (f.value) {
.saved => {
var rel_path = f.dest_path;
if (f.dest_path.len > root_dir_path.len) {
rel_path = resolve_path.relative(root_dir_path, f.dest_path);
if (f.dest_path.len > longest_common_path.len) {
rel_path = resolve_path.relative(longest_common_path, f.dest_path);
}
return rel_path;
},
.buffer => |value| {
var rel_path = f.dest_path;
if (f.dest_path.len > root_dir_path.len) {
rel_path = resolve_path.relative(root_dir_path, f.dest_path);
if (f.dest_path.len > longest_common_path.len) {
rel_path = resolve_path.relative(longest_common_path, f.dest_path);
if (std.fs.path.dirname(rel_path)) |parent| {
if (parent.len > root_dir_path.len) {
if (parent.len > longest_common_path.len) {
try root_dir.makePath(parent);
}
}
}
var path_buf: bun.PathBuffer = undefined;
_ = try JSC.Node.NodeFS.writeFileWithPathBuffer(&path_buf, .{
.data = .{ .buffer = .{
.buffer = .{
.ptr = @constCast(value.bytes.ptr),
.len = value.bytes.len,
.byte_len = value.bytes.len,
var handled_file_not_found = false;
while (true) {
var path_buf: bun.PathBuffer = undefined;
JSC.Node.NodeFS.writeFileWithPathBuffer(&path_buf, .{
.data = .{ .buffer = .{
.buffer = .{
.ptr = @constCast(value.bytes.ptr),
.len = value.bytes.len,
.byte_len = value.bytes.len,
},
} },
.encoding = .buffer,
.mode = if (f.is_executable) 0o755 else 0o644,
.dirfd = bun.toFD(root_dir.fd),
.file = .{ .path = .{
.string = JSC.PathString.init(rel_path),
} },
}).unwrap() catch |err| switch (err) {
error.FileNotFound, error.ENOENT => {
if (handled_file_not_found) return err;
handled_file_not_found = true;
try root_dir.makePath(
std.fs.path.dirname(rel_path) orelse
return err,
);
continue;
},
} },
.encoding = .buffer,
.mode = if (f.is_executable) 0o755 else 0o644,
.dirfd = bun.toFD(root_dir.fd),
.file = .{ .path = .{
.string = JSC.PathString.init(rel_path),
} },
}).unwrap();
else => return err,
};
break;
}
return rel_path;
},