aboutsummaryrefslogtreecommitdiff
path: root/src/bundler/generate_node_modules_bundle.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/bundler/generate_node_modules_bundle.zig')
-rw-r--r--src/bundler/generate_node_modules_bundle.zig35
1 files changed, 19 insertions, 16 deletions
diff --git a/src/bundler/generate_node_modules_bundle.zig b/src/bundler/generate_node_modules_bundle.zig
index b302e984e..a3f47debc 100644
--- a/src/bundler/generate_node_modules_bundle.zig
+++ b/src/bundler/generate_node_modules_bundle.zig
@@ -211,7 +211,7 @@ pub const ThreadPool = struct {
pub const ProcessFileTask = struct {
resolution: _resolver.Result,
- task: ThreadPoolLib.Task = .{ .callback = callback },
+ task: ThreadPoolLib.Task = .{ .callback = &callback },
pub fn callback(task: *ThreadPoolLib.Task) void {
var worker = @ptrCast(
@@ -334,11 +334,11 @@ pub const magic_bytes = "#!/usr/bin/env bun\n\n";
// Then, you add that number to initial_header.len
const initial_header = brk: {
var buf = std.mem.zeroes([magic_bytes.len + 5]u8);
- std.mem.copy(u8, &buf, magic_bytes);
- var remainder = buf[magic_bytes.len..];
- // Write an invalid byte offset to be updated after we finish generating the code
- std.mem.writeIntNative(u32, remainder[0 .. remainder.len - 1], 0);
- buf[buf.len - 1] = '\n';
+ // std.mem.copy(u8, &buf, magic_bytes);
+ // var remainder = buf[magic_bytes.len..];
+ // // Write an invalid byte offset to be updated after we finish generating the code
+ // std.mem.writeIntNative(u32, remainder[0 .. remainder.len - 1], 0);
+ // buf[buf.len - 1] = '\n';
break :brk buf;
};
const code_start_byte_offset: u32 = initial_header.len;
@@ -692,15 +692,16 @@ pub fn generate(
var refresh_runtime_injector_buf: [1024]u8 = undefined;
var fixed_buffer = std.io.fixedBufferStream(&refresh_runtime_injector_buf);
var fixed_buffer_writer = fixed_buffer.writer();
+ const hex_bytes = bun.fmt.hexIntLower(refresh_runtime_module_id);
fixed_buffer_writer.print(
\\if ('window' in globalThis) {{
\\ (function() {{
- \\ BUN_RUNTIME.__injectFastRefresh(${x}());
+ \\ BUN_RUNTIME.__injectFastRefresh(${any}());
\\ }})();
\\}}
,
- .{refresh_runtime_module_id},
+ .{hex_bytes},
) catch unreachable;
try this.tmpfile.writeAll(fixed_buffer.buffer[0..fixed_buffer.pos]);
}
@@ -805,7 +806,7 @@ pub fn generate(
const etag_u64 = hasher.final();
// We store the etag as a ascii hex encoded u64
// This is so we can send the bytes directly in the HTTP server instead of formatting it as hex each time.
- javascript_bundle.etag = try std.fmt.allocPrint(allocator, "{x}", .{etag_u64});
+ javascript_bundle.etag = try std.fmt.allocPrint(allocator, "{any}", .{bun.fmt.hexIntLower(etag_u64)});
javascript_bundle.generated_at = @truncate(u32, @intCast(u64, std.time.milliTimestamp()));
const basename = std.fs.path.basename(std.mem.span(destination));
@@ -815,10 +816,10 @@ pub fn generate(
else
try std.fmt.allocPrint(
this.allocator,
- "/{s}.{x}.bun",
+ "/{s}.{s}.bun",
.{
basename[0 .. basename.len - extname.len],
- etag_u64,
+ javascript_bundle.etag,
},
);
@@ -860,7 +861,7 @@ pub fn generate(
_ = C.fchmod(
this.tmpfile.handle,
// chmod 777
- 0000010 | 0000100 | 0000001 | 0001000 | 0000040 | 0000004 | 0000002 | 0000400 | 0000200 | 0000020,
+ 0o0000010 | 0o0000100 | 0o0000001 | 0o0001000 | 0o0000040 | 0o0000004 | 0o0000002 | 0o0000400 | 0o0000200 | 0o0000020,
);
try tmpfile.promote(tmpname, top_dir.fd, destination);
// Print any errors at the end
@@ -1351,7 +1352,8 @@ pub fn processFile(this: *GenerateNodeModuleBundle, worker: *ThreadPool.Worker,
}
}
- if (bundler.resolver.resolve(source_dir, import_record.path.text, import_record.kind)) |*_resolved_import| {
+ if (bundler.resolver.resolve(source_dir, import_record.path.text, import_record.kind)) |tmp| {
+ var _resolved_import = tmp;
if (_resolved_import.is_external) {
continue;
}
@@ -1376,7 +1378,7 @@ pub fn processFile(this: *GenerateNodeModuleBundle, worker: *ThreadPool.Worker,
// _resolved_import.package_json;
// }
- const resolved_import: *const _resolver.Result = _resolved_import;
+ const resolved_import: *const _resolver.Result = &_resolved_import;
const _module_data = BundledModuleData.getForceBundle(this, resolved_import) orelse {
// if a macro imports code that cannot be bundled
@@ -1397,7 +1399,7 @@ pub fn processFile(this: *GenerateNodeModuleBundle, worker: *ThreadPool.Worker,
_ = queue.getOrPutValue(
_module_data.module_id,
.{
- .resolution = _resolved_import.*,
+ .resolution = _resolved_import,
},
) catch unreachable;
} else |err| {
@@ -1780,7 +1782,8 @@ pub fn processFile(this: *GenerateNodeModuleBundle, worker: *ThreadPool.Worker,
}
}
- if (bundler.resolver.resolve(source_dir, import_record.path.text, import_record.kind)) |*_resolved_import| {
+ var tmp = bundler.resolver.resolve(source_dir, import_record.path.text, import_record.kind);
+ if (tmp) |*_resolved_import| {
if (_resolved_import.is_external) {
continue;
}