fix(scripts): copy pnpm state files into fixture node_modules (00-01)
Linking every top-level entry also linked .pnpm-workspace-state-v1.json, so pnpm running inside a fixture rewrote the repository's own install state. Top-level files are now copied; directories stay symlinks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
23336f2300
commit
e771e5e032
@@ -1,4 +1,4 @@
|
||||
import { mkdtemp, mkdir, readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
||||
import { lstat, mkdtemp, mkdir, readdir, readFile, rm, stat, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
|
||||
@@ -69,12 +69,37 @@ describe("fixture node_modules linking", () => {
|
||||
}
|
||||
});
|
||||
|
||||
// pnpm rewrites `.pnpm-workspace-state-v1.json` in place when it runs inside
|
||||
// the fixture. Through a symlink that write landed in the repository's own
|
||||
// state file, so the next pnpm command there re-verified the install.
|
||||
it("copies the pnpm state files instead of linking them", async () => {
|
||||
const source = await sourceTree();
|
||||
const fixture = await mkdtemp(path.join(tmpdir(), "fixture-root-"));
|
||||
const stateFiles = [".modules.yaml", ".package-map.json", ".pnpm-workspace-state-v1.json"];
|
||||
try {
|
||||
for (const file of stateFiles) {
|
||||
await writeFile(path.join(source, "node_modules", file), `{"projects":{"${source}":{}}}\n`);
|
||||
}
|
||||
await linkFixtureNodeModules(fixture, source);
|
||||
|
||||
for (const file of stateFiles) {
|
||||
const copied = path.join(fixture, "node_modules", file);
|
||||
expect((await lstat(copied)).isSymbolicLink(), file).toBe(false);
|
||||
await writeFile(copied, `{"projects":{"${fixture}":{}}}\n`);
|
||||
expect(await readFile(path.join(source, "node_modules", file), "utf8"), file)
|
||||
.toBe(`{"projects":{"${source}":{}}}\n`);
|
||||
}
|
||||
} finally {
|
||||
await rm(source, { recursive: true, force: true });
|
||||
await rm(fixture, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
it("creates node_modules as a real directory, never a symlink", async () => {
|
||||
const source = await sourceTree();
|
||||
const fixture = await mkdtemp(path.join(tmpdir(), "fixture-root-"));
|
||||
try {
|
||||
await linkFixtureNodeModules(fixture, source);
|
||||
const { lstat } = await import("node:fs/promises");
|
||||
const entry = await lstat(path.join(fixture, "node_modules"));
|
||||
expect(entry.isSymbolicLink()).toBe(false);
|
||||
expect(entry.isDirectory()).toBe(true);
|
||||
|
||||
Reference in New Issue
Block a user