Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bun 1.0.15
27 changes: 16 additions & 11 deletions src/vm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn detectProjectVersion(allocator: mem.Allocator, is_debug: bool) !?[]const
const files = comptime [_]VersionFile{
PackageJsonVersionFile.init(),
BunVersionFile.init(),
// ToolVersionsFile.init(),
ToolVersionsFile.init(),
};

var current_dir = try fs.cwd().realpathAlloc(allocator, ".");
Expand Down Expand Up @@ -309,17 +309,22 @@ const ToolVersionsFile = struct {
};
}
fn extractBunVersion(allocator: mem.Allocator, contents: []u8) ?[]u8 {
const regex = std.regex.compile(allocator, "^bun\\s*(.*?)$", .{});
defer std.regex.free(regex);

const match = try std.regex.match(allocator, regex, contents, 0, contents.len);
defer allocator.free(match);
var lines_it = mem.splitScalar(u8, contents, '\n');
while (lines_it.next()) |line| {
// Skip empty lines and comments
if (line.len == 0 or line[0] == '#') {
continue;
}

if (match.len == 0) {
return null;
// Check if line starts with "bun "
if (mem.startsWith(u8, line, "bun ")) {
// Extract version part after "bun "
const version_part = mem.trim(u8, line[4..], &std.ascii.whitespace);
if (version_part.len > 0) {
return allocator.dupe(u8, version_part) catch return null;
}
}
}

const version = match[0].groups[0];
return allocator.dupe(u8, version);
return null;
}
};