From 254133c2581655990a59fd8bf288988630be3ddf Mon Sep 17 00:00:00 2001 From: Don Isaac Date: Thu, 9 Jan 2025 14:12:36 -0800 Subject: [PATCH] feat(cli/init): new repos use text-based lockfile --- src/cli/init/bunfig.default.toml | 6 ++++++ src/cli/init_command.zig | 10 ++++++++++ test/cli/init/init.test.ts | 2 ++ 3 files changed, 18 insertions(+) create mode 100644 src/cli/init/bunfig.default.toml diff --git a/src/cli/init/bunfig.default.toml b/src/cli/init/bunfig.default.toml new file mode 100644 index 00000000000000..1aea14ef006d4a --- /dev/null +++ b/src/cli/init/bunfig.default.toml @@ -0,0 +1,6 @@ +# Bun-specific configuration. This file is optional. +# Docs: https://bun.sh/docs/runtime/bunfig + +[install] +# Use a text-based lockfile instead of a binary one. This will become the default in v1.2 +saveTextLockfile = true diff --git a/src/cli/init_command.zig b/src/cli/init_command.zig index 01d4d3112acd2e..fd55e9e9bb7479 100644 --- a/src/cli/init_command.zig +++ b/src/cli/init_command.zig @@ -65,6 +65,7 @@ pub const InitCommand = struct { const @".gitignore" = @embedFile("init/gitignore.default"); const @"tsconfig.json" = @embedFile("init/tsconfig.default.json"); const @"README.md" = @embedFile("init/README.default.md"); + const @"bunfig.toml" = @embedFile("init/bunfig.default.toml"); /// Create a new asset file, overriding anything that already exists. Known /// assets will have their contents pre-populated; otherwise the file will be empty. @@ -321,6 +322,7 @@ pub const InitCommand = struct { write_gitignore: bool = true, write_package_json: bool = true, write_tsconfig: bool = true, + write_bunfig: bool = true, write_readme: bool = true, }; @@ -342,6 +344,8 @@ pub const InitCommand = struct { break :brk true; }; + steps.write_bunfig = !existsZ("bunfig.toml"); + { try fields.object.putString(alloc, "name", fields.name); if (fields.entry_point.len > 0) { @@ -440,6 +444,12 @@ pub const InitCommand = struct { }; } + if (steps.write_bunfig) { + Assets.create("bunfig.toml", .{}) catch { + // suppressed + }; + } + if (steps.write_tsconfig) { brk: { const extname = std.fs.path.extension(fields.entry_point); diff --git a/test/cli/init/init.test.ts b/test/cli/init/init.test.ts index fb8f7c2ee82b8a..9ee0efba90549d 100644 --- a/test/cli/init/init.test.ts +++ b/test/cli/init/init.test.ts @@ -37,6 +37,7 @@ test("bun init works", () => { expect(fs.existsSync(path.join(temp, ".gitignore"))).toBe(true); expect(fs.existsSync(path.join(temp, "node_modules"))).toBe(true); expect(fs.existsSync(path.join(temp, "tsconfig.json"))).toBe(true); + expect(fs.existsSync(path.join(temp, "bunfig.toml"))).toBe(true); }, 30_000); test("bun init with piped cli", () => { @@ -73,4 +74,5 @@ test("bun init with piped cli", () => { expect(fs.existsSync(path.join(temp, ".gitignore"))).toBe(true); expect(fs.existsSync(path.join(temp, "node_modules"))).toBe(true); expect(fs.existsSync(path.join(temp, "tsconfig.json"))).toBe(true); + expect(fs.existsSync(path.join(temp, "bunfig.toml"))).toBe(true); }, 30_000);