fix: install vendored node_modules when using hardlinks (#9007)

* fix: install vendored node_modules when using hardlinks

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Eemeli Palotie
2024-02-20 08:50:24 +02:00
committed by GitHub
parent 2656418e50
commit 48e7c0fb8e
3 changed files with 81 additions and 1 deletions

View File

@@ -1366,7 +1366,7 @@ pub const PackageInstall = struct {
cached_package_dir,
this.allocator,
&[_]bun.OSPathSlice{},
&[_]bun.OSPathSlice{bun.OSPathLiteral("node_modules")},
&[_]bun.OSPathSlice{},
) catch |err| return Result{
.fail = .{ .err = err, .step = .opening_cache_dir },
};

Binary file not shown.

View File

@@ -0,0 +1,80 @@
import { file, spawn } from "bun";
import { afterAll, afterEach, beforeAll, beforeEach, expect, it } from "bun:test";
import { bunExe, bunEnv as env } from "harness";
import { access, writeFile } from "fs/promises";
import { join } from "path";
import {
dummyAfterAll,
dummyAfterEach,
dummyBeforeAll,
dummyBeforeEach,
dummyRegistry,
package_dir,
readdirSorted,
requested,
root_url,
setHandler,
} from "./../../cli/install/dummy.registry.js";
beforeAll(dummyBeforeAll);
afterAll(dummyAfterAll);
beforeEach(dummyBeforeEach);
afterEach(dummyAfterEach);
it("should install vendored node_modules with hardlink", async () => {
const urls: string[] = [];
setHandler(
dummyRegistry(urls, {
"0.0.1": {},
latest: "0.0.1",
}),
);
await writeFile(
join(package_dir, "package.json"),
JSON.stringify({
name: "foo",
version: "0.0.1",
dependencies: {
"vendor-baz": "0.0.1",
},
}),
);
const { stdout, stderr, exited } = spawn({
cmd: [bunExe(), "install", "--backend", "hardlink"],
cwd: package_dir,
stdout: null,
stdin: "pipe",
stderr: "pipe",
env,
});
expect(stderr).toBeDefined();
const err = await new Response(stderr).text();
expect(err).toContain("Saved lockfile");
expect(stdout).toBeDefined();
const out = await new Response(stdout).text();
expect(out).toContain("1 package installed");
expect(await exited).toBe(0);
expect(urls.sort()).toEqual([`${root_url}/vendor-baz`, `${root_url}/vendor-baz-0.0.1.tgz`]);
expect(requested).toBe(2);
expect(await readdirSorted(join(package_dir, "node_modules"))).toEqual([".cache", "vendor-baz"]);
expect(await readdirSorted(join(package_dir, "node_modules", "vendor-baz"))).toEqual([
"cjs",
"index.js",
"package.json",
]);
expect(await readdirSorted(join(package_dir, "node_modules", "vendor-baz", "cjs", "node_modules"))).toEqual([
"foo-dep",
]);
expect(
await readdirSorted(join(package_dir, "node_modules", "vendor-baz", "cjs", "node_modules", "foo-dep")),
).toEqual(["index.js"]);
expect(await file(join(package_dir, "node_modules", "vendor-baz", "package.json")).json()).toEqual({
name: "vendor-baz",
version: "0.0.1",
});
await access(join(package_dir, "bun.lockb"));
});