mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-24 07:01:49 +00:00
fix(runtime): make dist-runtime staging idempotent
This commit is contained in:
@@ -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 = {}) {
|
||||
|
||||
Reference in New Issue
Block a user