From 185bdfbbb682d61e010cd258d371336320adf9d7 Mon Sep 17 00:00:00 2001 From: dave caruso Date: Tue, 3 Dec 2024 03:11:03 -0800 Subject: [PATCH] some fixes --- src/bake/bake.zig | 8 ++++-- src/bake/production.zig | 18 +++++++++--- src/bundler/bundle_v2.zig | 2 +- src/js_parser.zig | 2 +- src/options.zig | 58 +++++++++++++++++++++++++-------------- 5 files changed, 58 insertions(+), 30 deletions(-) diff --git a/src/bake/bake.zig b/src/bake/bake.zig index 8bc0f6d46e..b64815b4cf 100644 --- a/src/bake/bake.zig +++ b/src/bake/bake.zig @@ -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; diff --git a/src/bake/production.zig b/src/bake/production.zig index 58c53279f1..145b19e2d6 100644 --- a/src/bake/production.zig +++ b/src/bake/production.zig @@ -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 => { diff --git a/src/bundler/bundle_v2.zig b/src/bundler/bundle_v2.zig index 8176a209d4..0615d140d0 100644 --- a/src/bundler/bundle_v2.zig +++ b/src/bundler/bundle_v2.zig @@ -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, .{ diff --git a/src/js_parser.zig b/src/js_parser.zig index 812ff3580f..7a2aaf3efe 100644 --- a/src/js_parser.zig +++ b/src/js_parser.zig @@ -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, }; } diff --git a/src/options.zig b/src/options.zig index d1f669b821..4bccea93e6 100644 --- a/src/options.zig +++ b/src/options.zig @@ -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; },