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:
DongHyeonka
2026-09-25 21:10:58 +09:00
co-authored by Claude Opus 5.5
parent 23336f2300
commit e771e5e032
2 changed files with 37 additions and 5 deletions
+10 -3
View File
@@ -1,4 +1,4 @@
import { lstat, mkdir, readdir, symlink } from "node:fs/promises";
import { copyFile, mkdir, readdir, stat, symlink } from "node:fs/promises";
import path from "node:path";
/**
@@ -15,6 +15,12 @@ import path from "node:path";
* is an individual symlink. Package resolution is unchanged, but a recursive
* delete unlinks the fixture's own symlinks instead of walking through one link
* into the shared tree.
*
* Top-level files are pnpm's install state (`.modules.yaml`,
* `.pnpm-workspace-state-v1.json`, ...). pnpm rewrites them in place when it
* runs inside the fixture, so they are copied: a link would carry the fixture's
* path into the repository's own state and make its next pnpm command
* re-verify the install.
*/
export async function linkFixtureNodeModules(
fixtureRoot: string,
@@ -25,7 +31,8 @@ export async function linkFixtureNodeModules(
await mkdir(target, { recursive: true });
for (const entry of await readdir(source)) {
const from = path.join(source, entry);
const stats = await lstat(from);
await symlink(from, path.join(target, entry), stats.isDirectory() ? "dir" : "file");
const to = path.join(target, entry);
if ((await stat(from)).isDirectory()) await symlink(from, to, "dir");
else await copyFile(from, to);
}
}