Skip to content

Commit

Permalink
fix(install): patches with bin in package.json (#14807)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylan-conway authored Oct 25, 2024
1 parent f21870a commit 5eaa730
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
30 changes: 15 additions & 15 deletions src/install/lockfile.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4980,6 +4980,21 @@ pub const Package = extern struct {
};
}

if (json.asProperty("patchedDependencies")) |patched_deps| {
const obj = patched_deps.expr.data.e_object;
lockfile.patched_dependencies.ensureTotalCapacity(allocator, obj.properties.len) catch unreachable;
for (obj.properties.slice()) |prop| {
const key = prop.key.?;
const value = prop.value.?;
if (key.isString() and value.isString()) {
var sfb = std.heap.stackFallback(1024, allocator);
const keyhash = try key.asStringHash(sfb.get(), String.Builder.stringHash) orelse unreachable;
const patch_path = string_builder.append(String, value.asString(allocator).?);
lockfile.patched_dependencies.put(allocator, keyhash, .{ .path = patch_path }) catch unreachable;
}
}
}

bin: {
if (json.asProperty("bin")) |bin| {
switch (bin.expr.data) {
Expand Down Expand Up @@ -5042,21 +5057,6 @@ pub const Package = extern struct {
}
}

if (json.asProperty("patchedDependencies")) |patched_deps| {
const obj = patched_deps.expr.data.e_object;
lockfile.patched_dependencies.ensureTotalCapacity(allocator, obj.properties.len) catch unreachable;
for (obj.properties.slice()) |prop| {
const key = prop.key.?;
const value = prop.value.?;
if (key.isString() and value.isString()) {
var sfb = std.heap.stackFallback(1024, allocator);
const keyhash = try key.asStringHash(sfb.get(), String.Builder.stringHash) orelse unreachable;
const patch_path = string_builder.append(String, value.asString(allocator).?);
lockfile.patched_dependencies.put(allocator, keyhash, .{ .path = patch_path }) catch unreachable;
}
}
}

if (json.asProperty("directories")) |dirs| {
// https://docs.npmjs.com/cli/v8/configuring-npm/package-json#directoriesbin
// Because of the way the bin directive works,
Expand Down
4 changes: 2 additions & 2 deletions test/cli/install/bun-run.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { file, spawn, spawnSync } from "bun";
import { beforeEach, describe, expect, it } from "bun:test";
import { exists, mkdir, rm, writeFile } from "fs/promises";
import { bunEnv, bunExe, bunEnv as env, isWindows, tempDirWithFiles, tmpdirSync } from "harness";
import { bunEnv, bunExe, bunEnv as env, isWindows, tempDirWithFiles, tmpdirSync, stderrForInstall } from "harness";
import { join } from "path";
import { readdirSorted } from "./dummy.registry";

Expand Down Expand Up @@ -300,7 +300,7 @@ console.log(minify("print(6 * 7)").code);
BUN_INSTALL_CACHE_DIR: join(run_dir, ".cache"),
},
});
const err2 = await new Response(stderr2).text();
const err2 = stderrForInstall(await new Response(stderr2).text());
expect(err2).toBe("");
expect(await readdirSorted(run_dir)).toEqual([".cache", "test.js"]);
expect(await readdirSorted(join(run_dir, ".cache"))).toContain("uglify-js");
Expand Down

0 comments on commit 5eaa730

Please sign in to comment.