From 5eaa7301ebed7d79d113c581fa94f0b32feacf24 Mon Sep 17 00:00:00 2001 From: Dylan Conway <35280289+dylan-conway@users.noreply.github.com> Date: Fri, 25 Oct 2024 00:03:19 -0700 Subject: [PATCH] fix(install): patches with `bin` in package.json (#14807) --- src/install/lockfile.zig | 30 +++++++++++++++--------------- test/cli/install/bun-run.test.ts | 4 ++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/install/lockfile.zig b/src/install/lockfile.zig index fa7e39a01c..0bb4969463 100644 --- a/src/install/lockfile.zig +++ b/src/install/lockfile.zig @@ -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) { @@ -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, diff --git a/test/cli/install/bun-run.test.ts b/test/cli/install/bun-run.test.ts index e20c2efda2..6ee3225013 100644 --- a/test/cli/install/bun-run.test.ts +++ b/test/cli/install/bun-run.test.ts @@ -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"; @@ -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");