fix(runtime): make dist-runtime staging idempotent

This commit is contained in:
Vincent Koc
2026-03-22 22:36:05 -07:00
parent 5822892fee
commit fd5555d5be
2 changed files with 62 additions and 4 deletions

View File

@@ -12,8 +12,30 @@ function relativeSymlinkTarget(sourcePath, targetPath) {
return relativeTarget || ".";
}
function ensureSymlink(targetValue, targetPath, type) {
try {
fs.symlinkSync(targetValue, targetPath, type);
return;
} catch (error) {
if (error?.code !== "EEXIST") {
throw error;
}
}
try {
if (fs.lstatSync(targetPath).isSymbolicLink() && fs.readlinkSync(targetPath) === targetValue) {
return;
}
} catch {
// Fall through and recreate the target when inspection fails.
}
removePathIfExists(targetPath);
fs.symlinkSync(targetValue, targetPath, type);
}
function symlinkPath(sourcePath, targetPath, type) {
fs.symlinkSync(relativeSymlinkTarget(sourcePath, targetPath), targetPath, type);
ensureSymlink(relativeSymlinkTarget(sourcePath, targetPath), targetPath, type);
}
function shouldWrapRuntimeJsFile(sourcePath) {
@@ -63,7 +85,7 @@ function stagePluginRuntimeOverlay(sourceDir, targetDir) {
}
if (dirent.isSymbolicLink()) {
fs.symlinkSync(fs.readlinkSync(sourcePath), targetPath);
ensureSymlink(fs.readlinkSync(sourcePath), targetPath);
continue;
}
@@ -91,7 +113,7 @@ function linkPluginNodeModules(params) {
if (!fs.existsSync(params.sourcePluginNodeModulesDir)) {
return;
}
fs.symlinkSync(params.sourcePluginNodeModulesDir, runtimeNodeModulesDir, symlinkType());
ensureSymlink(params.sourcePluginNodeModulesDir, runtimeNodeModulesDir, symlinkType());
}
export function stageBundledPluginRuntime(params = {}) {