mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 11:29:02 +00:00
fix(install): patches with bin in package.json (#14807)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user