From 9f16a9fcfd82a0d907aeac6ee9778c9ee55636e8 Mon Sep 17 00:00:00 2001 From: Biraru Date: Fri, 3 Jul 2026 02:50:47 +0500 Subject: [PATCH] fix: rename GUID-suffixed scripts when name conflicts are resolved --- src/index.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/index.ts b/src/index.ts index 988286f..8dd1531 100644 --- a/src/index.ts +++ b/src/index.ts @@ -309,6 +309,36 @@ export class SyncDaemon { } } + if (node.parentGuid) { + const siblingScriptNodes = this.tree.getDescendantScripts(node.parentGuid); + const sameNameScriptNodes = siblingScriptNodes.filter(sibling => sibling.name === node.name); + + if (sameNameScriptNodes.length !== 0) { + // SN meaning same name + const scriptToRename = sameNameScriptNodes.at(-1); + if (scriptToRename) { + const oldFilePaths = scriptToRename.path; + const newFilePath = this.fileWriter.getFilePath(scriptToRename); + + if (oldFilePaths.length !== 0) { + // Write new one path + this.fileWatcher.suppressNextChange(newFilePath, scriptToRename.source); + this.fileWriter.writeScript(scriptToRename); + + // Upsert the subtree into the sourcemap + this.sourcemapGenerator.upsertSubtree( + scriptToRename, + this.tree.getAllNodes(), + this.fileWriter.getAllMappings(), + config.sourcemapPath, + oldFilePaths, + false, + ); + } + } + } + } + this.fileWriter.cleanupEmptyDirectories(); }