Files
bun.sh/src/ConfigVersion.zig
Dylan Conway aad4d800ff add "configVersion" to bun.lock(b) (#24236)
### What does this PR do?

Adds `"configVersion"` to bun.lock(b). The version will be used to keep
default settings the same if they would be breaking across bun versions.

fixes ENG-21389
fixes ENG-21388
### How did you verify your code works?
TODO:
- [ ] new project
- [ ] existing project without configVersion
- [ ] existing project with configVersion
- [ ] same as above but with bun.lockb
- [ ] configVersion@0 defaults to hoisted linker
- [ ] new projects use isolated linker

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2025-11-03 22:20:07 -08:00

46 lines
931 B
Zig

pub const ConfigVersion = enum {
v0,
v1,
pub const current: ConfigVersion = .v1;
pub fn fromExpr(expr: bun.ast.Expr) ?ConfigVersion {
if (expr.data != .e_number) {
return null;
}
const version = expr.data.e_number.value;
if (version == 0) {
return .v0;
} else if (version == 1) {
return .v1;
}
if (@trunc(version) != version) {
return null;
}
if (version > @intFromEnum(current)) {
return current;
}
return null;
}
pub fn fromInt(int: u64) ?ConfigVersion {
return switch (int) {
0 => .v0,
1 => .v1,
else => {
if (int > @intFromEnum(current)) {
return current;
}
return null;
},
};
}
};
const bun = @import("bun");