Compare commits

...

5 Commits

Author SHA1 Message Date
RiskyMH
14780a6063 . 2025-07-23 01:11:37 +10:00
autofix-ci[bot]
41354aae95 [autofix.ci] apply automated fixes 2025-07-22 14:14:57 +00:00
RiskyMH
05c58ec7d6 subthread to delete it 2025-07-23 00:11:38 +10:00
autofix-ci[bot]
499e59b30b [autofix.ci] apply automated fixes 2025-07-22 13:58:01 +00:00
RiskyMH
cf10147d3e delete node_modules 2025-07-22 23:54:03 +10:00
6 changed files with 109 additions and 4 deletions

View File

@@ -168,5 +168,5 @@
"WebKit/WebInspectorUI": true,
},
"git.detectSubmodules": false,
// "bun.test.customScript": "./build/debug/bun-debug test"
"bun.test.customScript": "./build/debug/bun-debug test"
}

View File

@@ -13,6 +13,17 @@ pub const InstallCommand = struct {
}
};
fn deleteOldNodeModules(fd: bun.FileDescriptor) void {
var dir = std.fs.Dir{ .fd = fd.cast() };
var iter = dir.iterate();
while (iter.next() catch null) |entry| {
if (entry.kind == .directory and bun.strings.hasPrefixComptime(entry.name, ".node_modules_old_")) {
fd.deleteTree(entry.name) catch {};
}
}
}
fn install(ctx: Command.Context) !void {
var cli = try CommandLineArguments.parse(ctx.allocator, .install);
@@ -62,6 +73,19 @@ fn installWithCLI(ctx: Command.Context, cli: CommandLineArguments) !void {
// and cleanup install/add subcommand usage
var manager, const original_cwd = try PackageManager.init(ctx, cli, .install);
if (cli.is_ci_command and subcommand == .install) {
const timestamp = @as(u64, @intCast(std.time.milliTimestamp()));
var temp_name_buf: [256]u8 = undefined;
const temp_name = std.fmt.bufPrintZ(&temp_name_buf, ".node_modules_old_{d}", .{timestamp}) catch ".node_modules_old";
_ = bun.sys.renameat(manager.root_dir.fd, "node_modules", manager.root_dir.fd, temp_name);
const delete_thread = std.Thread.spawn(.{}, deleteOldNodeModules, .{manager.root_dir.fd}) catch null;
if (delete_thread) |thread| {
thread.detach();
}
}
// switch to `bun add <package>`
if (subcommand == .add) {
manager.subcommand = .add;

View File

@@ -294,10 +294,11 @@ pub fn copyFileReadWriteLoop(
}
}
const debug = bun.Output.scoped(.copy_file, true);
const bun = @import("bun");
const Environment = bun.Environment;
const Maybe = bun.sys.Maybe;
const debug = bun.Output.scoped(.copy_file, true);
const Platform = bun.analytics.GenerateHeader.GeneratePlatform;
const std = @import("std");

View File

@@ -174,6 +174,7 @@ positionals: []const string = &[_]string{},
yarn: bool = false,
production: bool = false,
frozen_lockfile: bool = false,
is_ci_command: bool = false,
no_save: bool = false,
dry_run: bool = false,
force: bool = false,
@@ -715,7 +716,8 @@ pub fn parse(allocator: std.mem.Allocator, comptime subcommand: Subcommand) !Com
cli.positionals = args.positionals();
cli.yarn = args.flag("--yarn");
cli.production = args.flag("--production");
cli.frozen_lockfile = args.flag("--frozen-lockfile") or (cli.positionals.len > 0 and strings.eqlComptime(cli.positionals[0], "ci"));
cli.is_ci_command = cli.positionals.len > 0 and strings.eqlComptime(cli.positionals[0], "ci");
cli.frozen_lockfile = args.flag("--frozen-lockfile") or cli.is_ci_command;
cli.no_progress = args.flag("--no-progress");
cli.dry_run = args.flag("--dry-run");
cli.global = args.flag("--global");

View File

@@ -6257,6 +6257,84 @@ it("should handle bun ci alias (to --frozen-lockfile)", async () => {
expect(await exited2).toBe(1);
});
it("should delete node_modules before install on bun ci", async () => {
let urls: string[] = [];
setHandler(dummyRegistry(urls, { "0.0.3": { as: "0.0.3" } }));
await writeFile(
join(package_dir, "package.json"),
JSON.stringify({ name: "foo", version: "0.0.1", dependencies: { baz: "0.0.3" } }),
);
expect(
await spawn({
cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: "ignore",
stdin: "ignore",
stderr: "ignore",
env,
}).exited,
).toBe(0);
await writeFile(join(package_dir, "node_modules", "test-file.txt"), "should be deleted");
expect(exists(join(package_dir, "node_modules", "test-file.txt"))).resolves.toBe(true);
expect(
spawn({
cmd: [bunExe(), "ci"],
cwd: package_dir,
stdout: "ignore",
stdin: "ignore",
stderr: "ignore",
env,
}).exited,
).resolves.toBe(0);
expect(exists(join(package_dir, "node_modules", "test-file.txt"))).resolves.toBe(false);
expect(exists(join(package_dir, "node_modules", "baz"))).resolves.toBe(true);
});
it("should delete node_modules when bun ci is run from subdirectory", async () => {
let urls: string[] = [];
setHandler(dummyRegistry(urls, { "0.0.3": { as: "0.0.3" } }));
await writeFile(
join(package_dir, "package.json"),
JSON.stringify({ name: "foo", version: "0.0.1", dependencies: { baz: "0.0.3" } }),
);
await mkdir(join(package_dir, "src"));
expect(
await spawn({
cmd: [bunExe(), "install"],
cwd: package_dir,
stdout: "ignore",
stdin: "ignore",
stderr: "ignore",
env,
}).exited,
).toBe(0);
await writeFile(join(package_dir, "node_modules", "test-file.txt"), "should be deleted");
expect(exists(join(package_dir, "node_modules", "test-file.txt"))).resolves.toBe(true);
expect(
spawn({
cmd: [bunExe(), "ci"],
cwd: join(package_dir, "src"),
stdout: "ignore",
stdin: "ignore",
stderr: "ignore",
env,
}).exited,
).resolves.toBe(0);
expect(exists(join(package_dir, "node_modules", "test-file.txt"))).resolves.toBe(false);
expect(exists(join(package_dir, "node_modules", "baz"))).resolves.toBe(true);
});
it("should handle frozenLockfile in config file", async () => {
let urls: string[] = [];
setHandler(dummyRegistry(urls, { "0.0.3": { as: "0.0.3" }, "0.0.5": { as: "0.0.5" } }));

View File

@@ -35,7 +35,7 @@ const words: Record<string, { reason: string; limit?: number; regex?: boolean }>
[String.raw`: [a-zA-Z0-9_\.\*\?\[\]\(\)]+ = undefined,`]: { reason: "Do not default a struct field to undefined", limit: 230, regex: true },
"usingnamespace": { reason: "Zig 0.15 will remove `usingnamespace`" },
"std.fs.Dir": { reason: "Prefer bun.sys + bun.FD instead of std.fs", limit: 170 },
"std.fs.Dir": { reason: "Prefer bun.sys + bun.FD instead of std.fs", limit: 171 },
"std.fs.cwd": { reason: "Prefer bun.FD.cwd()", limit: 103 },
"std.fs.File": { reason: "Prefer bun.sys + bun.FD instead of std.fs", limit: 62 },
".stdFile()": { reason: "Prefer bun.sys + bun.FD instead of std.fs.File. Zig hides 'errno' when Bun wants to match libuv", limit: 18 },