Skip to content

Commit

Permalink
feat(cli/init): new repos use text-based lockfile
Browse files Browse the repository at this point in the history
  • Loading branch information
DonIsaac committed Jan 9, 2025
1 parent d918825 commit adfcb9a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/cli/init/bunfig.default.toml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions src/cli/init_command.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
};

Expand All @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions test/cli/init/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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);

0 comments on commit adfcb9a

Please sign in to comment.