fix: targetDir symlink handling in postinstall script (#272)

This commit is contained in:
Ayaan Zaidi
2026-01-06 11:06:11 +05:30
committed by GitHub
parent b759cb6f37
commit a79c100594

View File

@@ -25,12 +25,16 @@ function applyPatchIfNeeded(opts) {
throw new Error(`missing patch: ${patchPath}`);
}
const targetDir = path.resolve(opts.targetDir);
let targetDir = path.resolve(opts.targetDir);
if (!fs.existsSync(targetDir) || !fs.statSync(targetDir).isDirectory()) {
console.warn(`[postinstall] skip missing target: ${targetDir}`);
return;
}
// Resolve symlinks to avoid "beyond a symbolic link" errors from git apply
// (bun/pnpm use symlinks in node_modules)
targetDir = fs.realpathSync(targetDir);
const gitArgsBase = ["apply", "--unsafe-paths", "--whitespace=nowarn"];
const reverseCheck = [
...gitArgsBase,