mirror of
https://github.com/alkimake/paperclip.git
synced 2026-06-14 01:50:39 +09:00
Fix worktree provisioning and relinking
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
parent
8be6fe987b
commit
7e34d6c66b
5 changed files with 35 additions and 99 deletions
|
|
@ -223,21 +223,7 @@ describe("ensureServerWorkspaceLinksCurrent", () => {
|
|||
);
|
||||
await fs.symlink(stalePackageDir, path.join(serverNodeModulesScopeDir, "db"));
|
||||
|
||||
const commands: Array<{ command: string; args: string[]; cwd: string }> = [];
|
||||
await ensureServerWorkspaceLinksCurrent(path.join(repoRoot, "server"), {
|
||||
runCommand: async (command, args, cwd) => {
|
||||
commands.push({ command, args, cwd });
|
||||
await fs.rm(path.join(serverNodeModulesScopeDir, "db"), { force: true });
|
||||
await fs.symlink(expectedPackageDir, path.join(serverNodeModulesScopeDir, "db"));
|
||||
},
|
||||
});
|
||||
|
||||
expect(commands).toHaveLength(1);
|
||||
expect(commands[0]).toMatchObject({
|
||||
command: process.platform === "win32" ? "pnpm.cmd" : "pnpm",
|
||||
args: ["install", "--force", "--config.confirmModulesPurge=false"],
|
||||
cwd: repoRoot,
|
||||
});
|
||||
await ensureServerWorkspaceLinksCurrent(path.join(repoRoot, "server"));
|
||||
expect(await fs.realpath(path.join(serverNodeModulesScopeDir, "db"))).toBe(await fs.realpath(expectedPackageDir));
|
||||
});
|
||||
|
||||
|
|
@ -267,14 +253,7 @@ describe("ensureServerWorkspaceLinksCurrent", () => {
|
|||
);
|
||||
await fs.symlink(expectedPackageDir, path.join(serverNodeModulesScopeDir, "db"));
|
||||
|
||||
let invoked = false;
|
||||
await ensureServerWorkspaceLinksCurrent(path.join(repoRoot, "server"), {
|
||||
runCommand: async () => {
|
||||
invoked = true;
|
||||
},
|
||||
});
|
||||
|
||||
expect(invoked).toBe(false);
|
||||
await ensureServerWorkspaceLinksCurrent(path.join(repoRoot, "server"));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -208,35 +208,10 @@ function findServerWorkspaceLinkMismatches(rootDir: string): WorkspaceLinkMismat
|
|||
return mismatches;
|
||||
}
|
||||
|
||||
async function runCommand(command: string, args: string[], cwd: string) {
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
const child = spawn(command, args, {
|
||||
cwd,
|
||||
env: process.env,
|
||||
stdio: "ignore",
|
||||
shell: process.platform === "win32",
|
||||
});
|
||||
|
||||
child.on("error", reject);
|
||||
child.on("exit", (code, signal) => {
|
||||
if (code === 0) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
reject(
|
||||
new Error(
|
||||
`${command} ${args.join(" ")} failed with ${signal ? `signal ${signal}` : `exit code ${code ?? "unknown"}`}`,
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export async function ensureServerWorkspaceLinksCurrent(
|
||||
startCwd: string,
|
||||
opts?: {
|
||||
onLog?: (stream: "stdout" | "stderr", chunk: string) => Promise<void>;
|
||||
runCommand?: (command: string, args: string[], cwd: string) => Promise<void>;
|
||||
},
|
||||
) {
|
||||
const workspaceRoot = findWorkspaceRoot(startCwd);
|
||||
|
|
@ -255,12 +230,12 @@ export async function ensureServerWorkspaceLinksCurrent(
|
|||
}
|
||||
}
|
||||
|
||||
const pnpmBin = process.platform === "win32" ? "pnpm.cmd" : "pnpm";
|
||||
await (opts?.runCommand ?? runCommand)(
|
||||
pnpmBin,
|
||||
["install", "--force", "--config.confirmModulesPurge=false"],
|
||||
workspaceRoot,
|
||||
);
|
||||
for (const mismatch of mismatches) {
|
||||
const linkPath = path.join(workspaceRoot, "server", "node_modules", ...mismatch.packageName.split("/"));
|
||||
await fs.mkdir(path.dirname(linkPath), { recursive: true });
|
||||
await fs.rm(linkPath, { recursive: true, force: true });
|
||||
await fs.symlink(mismatch.expectedPath, linkPath);
|
||||
}
|
||||
|
||||
const remainingMismatches = findServerWorkspaceLinkMismatches(workspaceRoot);
|
||||
if (remainingMismatches.length === 0) return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue