diff options
author | 2023-07-11 19:14:34 -0700 | |
---|---|---|
committer | 2023-07-11 19:14:34 -0700 | |
commit | cbb88672f217a90db1aa1eb29cd92d5d9035b22b (patch) | |
tree | 43a00501f3cde495967e116f0b660777051551f8 /src/cli | |
parent | 1f900cff453700b19bca2acadfe26da4468c1282 (diff) | |
parent | 34b0e7a2bbd8bf8097341cdb0075d0908283e834 (diff) | |
download | bun-jarred/esm-conditions.tar.gz bun-jarred/esm-conditions.tar.zst bun-jarred/esm-conditions.zip |
Merge branch 'main' into jarred/esm-conditionsjarred/esm-conditions
Diffstat (limited to 'src/cli')
-rw-r--r-- | src/cli/add_completions.zig | 2 | ||||
-rw-r--r-- | src/cli/build_command.zig | 17 | ||||
-rw-r--r-- | src/cli/bunx_command.zig | 4 | ||||
-rw-r--r-- | src/cli/create_command.zig | 32 | ||||
-rw-r--r-- | src/cli/init_command.zig | 2 | ||||
-rw-r--r-- | src/cli/install.sh | 2 | ||||
-rw-r--r-- | src/cli/list-of-yarn-commands.zig | 5 | ||||
-rw-r--r-- | src/cli/package_manager_command.zig | 6 | ||||
-rw-r--r-- | src/cli/run_command.zig | 2 | ||||
-rw-r--r-- | src/cli/test_command.zig | 5 | ||||
-rw-r--r-- | src/cli/upgrade_command.zig | 6 |
11 files changed, 44 insertions, 39 deletions
diff --git a/src/cli/add_completions.zig b/src/cli/add_completions.zig index 95201659d..2e7d6b4ea 100644 --- a/src/cli/add_completions.zig +++ b/src/cli/add_completions.zig @@ -66,7 +66,7 @@ pub const index: Index = if (Environment.isDebug) Index.initFill(&.{"OOMWorkArou break; } } - array.set(@intToEnum(FirstLetter, i), &record); + array.set(@enumFromInt(FirstLetter, i), &record); @setEvalBranchQuota(999999); i = next_i; diff --git a/src/cli/build_command.zig b/src/cli/build_command.zig index 14414c7de..ef99f7765 100644 --- a/src/cli/build_command.zig +++ b/src/cli/build_command.zig @@ -107,6 +107,7 @@ pub const BuildCommand = struct { // We never want to hit the filesystem for these files // This "compiled" protocol is specially handled by the module resolver. this_bundler.options.public_path = "compiled://root/"; + this_bundler.resolver.opts.public_path = "compiled://root/"; if (outfile.len == 0) { outfile = std.fs.path.basename(this_bundler.options.entry_points[0]); @@ -320,8 +321,8 @@ pub const BuildCommand = struct { var from_path = resolve_path.longestCommonPath(all_paths); for (output_files) |f| { - max_path_len = std.math.max( - std.math.max(from_path.len, f.dest_path.len) + 2 - from_path.len, + max_path_len = @max( + @max(from_path.len, f.dest_path.len) + 2 - from_path.len, max_path_len, ); } @@ -356,7 +357,7 @@ pub const BuildCommand = struct { Output.pretty("{s}", .{padding_buf[0..@intCast(usize, compiled_elapsed_digit_count)]}); - Output.printElapsedStdoutTrim(@intToFloat(f64, compiled_elapsed)); + Output.printElapsedStdoutTrim(@floatFromInt(f64, compiled_elapsed)); Output.prettyln(" <green>compile<r> <b><blue>{s}<r>", .{ outfile, @@ -446,11 +447,11 @@ pub const BuildCommand = struct { // Print summary _ = try writer.write("\n"); - const padding_count = 2 + (std.math.max(rel_path.len, max_path_len) - rel_path.len); + const padding_count = 2 + (@max(rel_path.len, max_path_len) - rel_path.len); try writer.writeByteNTimes(' ', 2); try writer.writeAll(rel_path); try writer.writeByteNTimes(' ', padding_count); - const size = @intToFloat(f64, f.size) / 1000.0; + const size = @floatFromInt(f64, f.size) / 1000.0; try std.fmt.formatFloatDecimal(size, .{ .precision = 2 }, writer); try writer.writeAll(" KB\n"); } @@ -460,7 +461,7 @@ pub const BuildCommand = struct { if (write_summary and log.errors == 0) { Output.prettyln("\n", .{}); Output.printElapsedStdoutTrim( - @intToFloat(f64, (@divTrunc(@truncate(i64, std.time.nanoTimestamp() - bun.CLI.start_time), @as(i64, std.time.ns_per_ms)))), + @floatFromInt(f64, (@divTrunc(@truncate(i64, std.time.nanoTimestamp() - bun.CLI.start_time), @as(i64, std.time.ns_per_ms)))), ); if (this_bundler.options.transform_only) { Output.prettyln(" <green>transpile<r>", .{}); @@ -505,7 +506,7 @@ fn printSummary(bundled_end: i128, minify_duration: u64, minified: bool, input_c }; if (minified) { Output.pretty("{s}", .{padding_buf[0..@intCast(usize, minified_digit_count)]}); - Output.printElapsedStdoutTrim(@intToFloat(f64, minify_duration)); + Output.printElapsedStdoutTrim(@floatFromInt(f64, minify_duration)); const output_size = brk: { var total_size: u64 = 0; for (output_files) |f| { @@ -547,7 +548,7 @@ fn printSummary(bundled_end: i128, minify_duration: u64, minified: bool, input_c }; Output.pretty("{s}", .{padding_buf[0..@intCast(usize, bundle_elapsed_digit_count)]}); - Output.printElapsedStdoutTrim(@intToFloat(f64, bundle_elapsed)); + Output.printElapsedStdoutTrim(@floatFromInt(f64, bundle_elapsed)); Output.prettyln( " <green>bundle<r> {d} modules", .{ diff --git a/src/cli/bunx_command.zig b/src/cli/bunx_command.zig index 7fb028b68..365f2c9ed 100644 --- a/src/cli/bunx_command.zig +++ b/src/cli/bunx_command.zig @@ -66,7 +66,7 @@ pub const BunxCommand = struct { .result => |result| result, } orelse break; - if (current.kind == .File) { + if (current.kind == .file) { if (current.name.len == 0) continue; return try bundler.allocator.dupe(u8, current.name.slice()); } @@ -81,7 +81,7 @@ pub const BunxCommand = struct { fn getBinNameFromProjectDirectory(bundler: *bun.Bundler, dir_fd: std.os.fd_t, package_name: []const u8) ![]const u8 { var subpath: [bun.MAX_PATH_BYTES]u8 = undefined; subpath[0.."node_modules/".len].* = "node_modules/".*; - @memcpy(subpath["node_modules/".len..], package_name.ptr, package_name.len); + @memcpy(subpath["node_modules/".len..][0..package_name.len], package_name); subpath["node_modules/".len + package_name.len] = std.fs.path.sep; subpath["node_modules/".len + package_name.len + 1 ..][0.."package.json".len].* = "package.json".*; subpath["node_modules/".len + package_name.len + 1 + "package.json".len] = 0; diff --git a/src/cli/create_command.zig b/src/cli/create_command.zig index fcbee9dbb..d536c4750 100644 --- a/src/cli/create_command.zig +++ b/src/cli/create_command.zig @@ -104,7 +104,7 @@ fn execTask(allocator: std.mem.Allocator, task_: string, cwd: string, _: string, count += 1; } - const npm_args = 2 * @intCast(usize, @boolToInt(npm_client != null)); + const npm_args = 2 * @intCast(usize, @intFromBool(npm_client != null)); const total = count + npm_args; var argv = allocator.alloc(string, total) catch return; var proc: std.ChildProcess = undefined; @@ -491,7 +491,7 @@ pub const CreateCommand = struct { [1]Archive.Plucker{undefined}; var archive_context = Archive.Context{ - .pluckers = pluckers[0..@intCast(usize, @boolToInt(!create_options.skip_package_json))], + .pluckers = pluckers[0..@intCast(usize, @intFromBool(!create_options.skip_package_json))], .all_files = undefined, .overwrite_list = bun.StringArrayHashMap(void).init(ctx.allocator), }; @@ -523,7 +523,7 @@ pub const CreateCommand = struct { ); for (archive_context.overwrite_list.keys()) |path| { if (strings.endsWith(path, std.fs.path.sep_str)) { - Output.prettyError("<r> <blue>{s}<r>", .{path[0 .. std.math.max(path.len, 1) - 1]}); + Output.prettyError("<r> <blue>{s}<r>", .{path[0 .. @max(path.len, 1) - 1]}); Output.prettyErrorln(std.fs.path.sep_str, .{}); } else { Output.prettyErrorln("<r> {s}", .{path}); @@ -594,7 +594,7 @@ pub const CreateCommand = struct { progress_: *std.Progress, ) !void { while (try walker.next()) |entry| { - if (entry.kind != .File) continue; + if (entry.kind != .file) continue; var outfile = destination_dir_.createFile(entry.path, .{}) catch brk: { if (std.fs.path.dirname(entry.path)) |entry_dirname| { @@ -643,7 +643,7 @@ pub const CreateCommand = struct { break :read_package_json; }; - if (stat.kind != .File or stat.size == 0) { + if (stat.kind != .file or stat.size == 0) { package_json_file = null; node.end(); @@ -736,7 +736,7 @@ pub const CreateCommand = struct { if (package_json_expr.asProperty("name")) |name_expr| { if (name_expr.expr.data == .e_string) { var basename = std.fs.path.basename(destination); - name_expr.expr.data.e_string.data = @intToPtr([*]u8, @ptrToInt(basename.ptr))[0..basename.len]; + name_expr.expr.data.e_string.data = @ptrFromInt([*]u8, @intFromPtr(basename.ptr))[0..basename.len]; } } @@ -778,7 +778,7 @@ pub const CreateCommand = struct { const key = list[i].key.?.data.e_string.data; const do_prune = packages.has(key); - prune_count += @intCast(u16, @boolToInt(do_prune)); + prune_count += @intCast(u16, @intFromBool(do_prune)); if (!do_prune) { list[out_i] = list[i]; @@ -902,14 +902,14 @@ pub const CreateCommand = struct { var needs_to_inject_dev_dependency = needs.react_refresh or needs.bun_macro_relay; var needs_to_inject_dependency = needs.bun_framework_next; - const dependencies_to_inject_count = @intCast(usize, @boolToInt(needs.bun_framework_next)); + const dependencies_to_inject_count = @intCast(usize, @intFromBool(needs.bun_framework_next)); - const dev_dependencies_to_inject_count = @intCast(usize, @boolToInt(needs.react_refresh)) + - @intCast(usize, @boolToInt(needs.bun_macro_relay)); + const dev_dependencies_to_inject_count = @intCast(usize, @intFromBool(needs.react_refresh)) + + @intCast(usize, @intFromBool(needs.bun_macro_relay)); - const new_properties_count = @intCast(usize, @boolToInt(needs_to_inject_dev_dependency and dev_dependencies == null)) + - @intCast(usize, @boolToInt(needs_to_inject_dependency and dependencies == null)) + - @intCast(usize, @boolToInt(needs_bun_prop)); + const new_properties_count = @intCast(usize, @intFromBool(needs_to_inject_dev_dependency and dev_dependencies == null)) + + @intCast(usize, @intFromBool(needs_to_inject_dependency and dependencies == null)) + + @intCast(usize, @intFromBool(needs_bun_prop)); if (new_properties_count != 0) { try properties_list.ensureUnusedCapacity(new_properties_count); @@ -1463,7 +1463,7 @@ pub const CreateCommand = struct { } if (create_options.verbose) { - Output.prettyErrorln("Has dependencies? {d}", .{@boolToInt(has_dependencies)}); + Output.prettyErrorln("Has dependencies? {d}", .{@intFromBool(has_dependencies)}); } var npm_client_: ?NPMClient = null; @@ -1692,7 +1692,7 @@ pub const Example = struct { var app_name_buf: [512]u8 = undefined; pub fn print(examples: []const Example, default_app_name: ?string) void { for (examples) |example| { - var app_name = default_app_name orelse (std.fmt.bufPrint(&app_name_buf, "./{s}-app", .{example.name[0..std.math.min(example.name.len, 492)]}) catch unreachable); + var app_name = default_app_name orelse (std.fmt.bufPrint(&app_name_buf, "./{s}-app", .{example.name[0..@min(example.name.len, 492)]}) catch unreachable); if (example.description.len > 0) { Output.pretty(" <r># {s}<r>\n <b>bun create <cyan>{s}<r><b> {s}<r>\n<d> \n\n", .{ @@ -1754,7 +1754,7 @@ pub const Example = struct { const entry: std.fs.IterableDir.Entry = entry_; switch (entry.kind) { - .Directory => { + .directory => { inline for (skip_dirs) |skip_dir| { if (strings.eqlComptime(entry.name, skip_dir)) { continue :loop; diff --git a/src/cli/init_command.zig b/src/cli/init_command.zig index c7f566836..9b5ad7144 100644 --- a/src/cli/init_command.zig +++ b/src/cli/init_command.zig @@ -112,7 +112,7 @@ pub const InitCommand = struct { if (package_json_file) |pkg| { const stat = pkg.stat() catch break :read_package_json; - if (stat.kind != .File or stat.size == 0) { + if (stat.kind != .file or stat.size == 0) { break :read_package_json; } package_json_contents = try MutableString.init(alloc, stat.size); diff --git a/src/cli/install.sh b/src/cli/install.sh index ffb70b6cb..782e8592e 100644 --- a/src/cli/install.sh +++ b/src/cli/install.sh @@ -50,7 +50,7 @@ success() { } command -v unzip >/dev/null || - error 'unzip is required to install bun (see: https://bun.sh/docs/installation)' + error 'unzip is required to install bun' if [[ $# -gt 2 ]]; then error 'Too many arguments, only 2 are allowed. The first can be a specific tag of bun to install. (e.g. "bun-v0.1.4") The second can be a build variant of bun to install. (e.g. "debug-info")' diff --git a/src/cli/list-of-yarn-commands.zig b/src/cli/list-of-yarn-commands.zig index 250541360..4109ed727 100644 --- a/src/cli/list-of-yarn-commands.zig +++ b/src/cli/list-of-yarn-commands.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const bun = @import("root").bun; // yarn v2.3 commands const yarn_v2 = [_][]const u8{ @@ -82,7 +83,7 @@ pub const all_yarn_commands = brk: { var array: [yarn_v2.len + yarn_v1.len]u64 = undefined; var array_i: usize = 0; for (yarn_v2) |yarn| { - const hash = std.hash.Wyhash.hash(0, yarn); + const hash = bun.hash(yarn); @setEvalBranchQuota(9999); if (std.mem.indexOfScalar(u64, array[0..array_i], hash) == null) { @setEvalBranchQuota(9999); @@ -94,7 +95,7 @@ pub const all_yarn_commands = brk: { for (yarn_v1) |yarn| { @setEvalBranchQuota(9999); - const hash = std.hash.Wyhash.hash(0, yarn); + const hash = bun.hash(yarn); if (std.mem.indexOfScalar(u64, array[0..array_i], hash) == null) { @setEvalBranchQuota(9999); diff --git a/src/cli/package_manager_command.zig b/src/cli/package_manager_command.zig index 83d3dd023..0d92c4232 100644 --- a/src/cli/package_manager_command.zig +++ b/src/cli/package_manager_command.zig @@ -48,7 +48,7 @@ pub const PackageManagerCommand = struct { pub fn printHash(ctx: Command.Context, lockfile_: []const u8) !void { @setCold(true); var lockfile_buffer: [bun.MAX_PATH_BYTES]u8 = undefined; - @memcpy(&lockfile_buffer, lockfile_.ptr, lockfile_.len); + @memcpy(lockfile_buffer[0..lockfile_.len], lockfile_); lockfile_buffer[lockfile_.len] = 0; var lockfile = lockfile_buffer[0..lockfile_.len :0]; var pm = try PackageManager.init(ctx, null, PackageManager.Subcommand.pm); @@ -224,7 +224,7 @@ pub const PackageManagerCommand = struct { for (sorted_dependencies, 0..) |*dep, i| { dep.* = @truncate(DependencyID, root_deps.off + i); } - std.sort.sort(DependencyID, sorted_dependencies, ByName{ + std.sort.block(DependencyID, sorted_dependencies, ByName{ .dependencies = dependencies, .buf = string_bytes, }, ByName.isLessThan); @@ -336,7 +336,7 @@ fn printNodeModulesFolderStructure( const sorted_dependencies = try allocator.alloc(DependencyID, directory.dependencies.len); defer allocator.free(sorted_dependencies); bun.copy(DependencyID, sorted_dependencies, directory.dependencies); - std.sort.sort(DependencyID, sorted_dependencies, ByName{ + std.sort.block(DependencyID, sorted_dependencies, ByName{ .dependencies = dependencies, .buf = string_bytes, }, ByName.isLessThan); diff --git a/src/cli/run_command.zig b/src/cli/run_command.zig index 0c9145db1..48bbd36d2 100644 --- a/src/cli/run_command.zig +++ b/src/cli/run_command.zig @@ -135,7 +135,7 @@ pub const RunCommand = struct { } // implicit yarn commands - if (std.mem.indexOfScalar(u64, yarn_commands, std.hash.Wyhash.hash(0, yarn_cmd)) == null) { + if (std.mem.indexOfScalar(u64, yarn_commands, bun.hash(yarn_cmd)) == null) { try copy_script.appendSlice(BUN_RUN); try copy_script.append(' '); try copy_script.appendSlice(yarn_cmd); diff --git a/src/cli/test_command.zig b/src/cli/test_command.zig index b7712c0de..dc67c6d98 100644 --- a/src/cli/test_command.zig +++ b/src/cli/test_command.zig @@ -41,7 +41,7 @@ const HTTPThread = @import("root").bun.HTTP.HTTPThread; const JSC = @import("root").bun.JSC; const jest = JSC.Jest; const TestRunner = JSC.Jest.TestRunner; -const Snapshots = JSC.Jest.Snapshots; +const Snapshots = JSC.Snapshot.Snapshots; const Test = TestRunner.Test; const NetworkThread = @import("root").bun.HTTP.NetworkThread; const uws = @import("root").bun.uws; @@ -363,6 +363,9 @@ const Scanner = struct { return; } + if (comptime Environment.allow_assert) + std.debug.assert(!strings.contains(name, std.fs.path.sep_str ++ "node_modules" ++ std.fs.path.sep_str)); + for (this.exclusion_names) |exclude_name| { if (strings.eql(exclude_name, name)) return; } diff --git a/src/cli/upgrade_command.zig b/src/cli/upgrade_command.zig index 2f06fe674..e9d16999d 100644 --- a/src/cli/upgrade_command.zig +++ b/src/cli/upgrade_command.zig @@ -344,7 +344,7 @@ pub const UpgradeCommand = struct { if (asset.asProperty("size")) |size_| { if (size_.expr.data == .e_number) { - version.size = @intCast(u32, @max(@floatToInt(i32, std.math.ceil(size_.expr.data.e_number.value)), 0)); + version.size = @intCast(u32, @max(@intFromFloat(i32, std.math.ceil(size_.expr.data.e_number.value)), 0)); } } return version; @@ -648,13 +648,13 @@ pub const UpgradeCommand = struct { if (target_stat.size == dest_stat.size and target_stat.size > 0) { var input_buf = try ctx.allocator.alloc(u8, target_stat.size); - const target_hash = std.hash.Wyhash.hash(0, target_dir.readFile(target_filename, input_buf) catch |err| { + const target_hash = bun.hash(target_dir.readFile(target_filename, input_buf) catch |err| { save_dir_.deleteTree(version_name) catch {}; Output.prettyErrorln("<r><red>error:<r> Failed to read target bun {s}", .{@errorName(err)}); Global.exit(1); }); - const source_hash = std.hash.Wyhash.hash(0, save_dir.readFile(exe, input_buf) catch |err| { + const source_hash = bun.hash(save_dir.readFile(exe, input_buf) catch |err| { save_dir_.deleteTree(version_name) catch {}; Output.prettyErrorln("<r><red>error:<r> Failed to read source bun {s}", .{@errorName(err)}); Global.exit(1); |