aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-30 03:50:32 -0800
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-12-30 04:46:52 -0800
commit385c81d67be14abaaa938c0d7d46acd90d714392 (patch)
tree0b1ec5439c6fd8ac14c3260ea32ec540e046b927
parent8b0a7b9fb8377269866194e494d7b31dc395e3a3 (diff)
downloadbun-385c81d67be14abaaa938c0d7d46acd90d714392.tar.gz
bun-385c81d67be14abaaa938c0d7d46acd90d714392.tar.zst
bun-385c81d67be14abaaa938c0d7d46acd90d714392.zip
Fix crash with `bun install <foo>`
-rw-r--r--src/install/install.zig44
1 files changed, 26 insertions, 18 deletions
diff --git a/src/install/install.zig b/src/install/install.zig
index 186d287e1..8bb0828c7 100644
--- a/src/install/install.zig
+++ b/src/install/install.zig
@@ -4107,24 +4107,27 @@ pub const PackageManager = struct {
}
var needs_new_dependency_list = true;
- var dependencies_object: JSAst.Expr = undefined;
- if (current_package_json.asProperty(dependency_list)) |query| {
- if (query.expr.data == .e_object) {
- needs_new_dependency_list = false;
+ const dependencies_object: JSAst.Expr = brk: {
+ if (current_package_json.asProperty(dependency_list)) |query| {
+ if (query.expr.data == .e_object) {
+ needs_new_dependency_list = false;
- dependencies_object = query.expr;
+ break :brk query.expr;
+ }
}
- }
- if (needs_new_dependency_list) {
- dependencies_object = JSAst.Expr.init(
+ break :brk JSAst.Expr.init(
JSAst.E.Object,
JSAst.E.Object{
.properties = JSAst.G.Property.List.init(new_dependencies),
},
logger.Loc.Empty,
);
- }
+ };
+
+ dependencies_object.data.e_object.properties = JSAst.G.Property.List.init(new_dependencies);
+ if (new_dependencies.len > 1)
+ dependencies_object.data.e_object.alphabetizeProperties();
if (current_package_json.data != .e_object or current_package_json.data.e_object.properties.len == 0) {
var root_properties = try allocator.alloc(JSAst.G.Property, 1);
@@ -4142,19 +4145,24 @@ pub const PackageManager = struct {
} else if (needs_new_dependency_list) {
var root_properties = try allocator.alloc(JSAst.G.Property, current_package_json.data.e_object.properties.len + 1);
std.mem.copy(JSAst.G.Property, root_properties, current_package_json.data.e_object.properties.slice());
- root_properties[root_properties.len - 1].key = JSAst.Expr.init(
- JSAst.E.String,
- JSAst.E.String{
- .data = dependency_list,
+ root_properties[root_properties.len - 1] = .{
+ .key = JSAst.Expr.init(
+ JSAst.E.String,
+ JSAst.E.String{
+ .data = dependency_list,
+ },
+ logger.Loc.Empty,
+ ),
+ .value = dependencies_object,
+ };
+ current_package_json.* = JSAst.Expr.init(
+ JSAst.E.Object,
+ JSAst.E.Object{
+ .properties = JSAst.G.Property.List.init(root_properties),
},
logger.Loc.Empty,
);
- root_properties[root_properties.len - 1].value = dependencies_object;
- current_package_json.* = JSAst.Expr.init(JSAst.E.Object, JSAst.E.Object{ .properties = JSAst.G.Property.List.init(root_properties) }, logger.Loc.Empty);
}
-
- dependencies_object.data.e_object.properties = JSAst.G.Property.List.init(new_dependencies);
- dependencies_object.data.e_object.packageJSONSort();
}
for (updates) |*update| {