@intlayer/chokidar 8.1.10 → 8.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/dist/assets/installSkills/skills/astro.md +1 -1
  2. package/dist/assets/installSkills/skills/cli.md +2 -2
  3. package/dist/cjs/cli.cjs +1 -1
  4. package/dist/cjs/createDictionaryEntryPoint/generateDictionaryListContent.cjs +1 -1
  5. package/dist/cjs/createDictionaryEntryPoint/generateDictionaryListContent.cjs.map +1 -1
  6. package/dist/cjs/createType/createModuleAugmentation.cjs +3 -3
  7. package/dist/cjs/createType/createModuleAugmentation.cjs.map +1 -1
  8. package/dist/cjs/init/utils/configManipulation.cjs +1 -1
  9. package/dist/cjs/init/utils/configManipulation.cjs.map +1 -1
  10. package/dist/cjs/installMCP/installMCP.cjs +2 -0
  11. package/dist/cjs/installMCP/installMCP.cjs.map +1 -0
  12. package/dist/cjs/installSkills/index.cjs +1 -1
  13. package/dist/cjs/installSkills/index.cjs.map +1 -1
  14. package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs +1 -1
  15. package/dist/cjs/loadDictionaries/log.cjs +1 -1
  16. package/dist/cjs/loadDictionaries/log.cjs.map +1 -1
  17. package/dist/cjs/prepareIntlayer.cjs +1 -1
  18. package/dist/cjs/utils/getPathHash.cjs +2 -0
  19. package/dist/cjs/utils/getPathHash.cjs.map +1 -0
  20. package/dist/cjs/utils/index.cjs +1 -1
  21. package/dist/cjs/watcher.cjs +1 -1
  22. package/dist/cjs/watcher.cjs.map +1 -1
  23. package/dist/cjs/writeContentDeclaration/transformJSFile.cjs +1 -2
  24. package/dist/cjs/writeContentDeclaration/transformJSFile.cjs.map +1 -1
  25. package/dist/cjs/writeContentDeclaration/transformJSONFile.cjs +1 -1
  26. package/dist/cjs/writeContentDeclaration/transformJSONFile.cjs.map +1 -1
  27. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +1 -1
  28. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
  29. package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +1 -1
  30. package/dist/esm/cli.mjs +1 -1
  31. package/dist/esm/createDictionaryEntryPoint/generateDictionaryListContent.mjs +1 -1
  32. package/dist/esm/createDictionaryEntryPoint/generateDictionaryListContent.mjs.map +1 -1
  33. package/dist/esm/createType/createModuleAugmentation.mjs +9 -9
  34. package/dist/esm/createType/createModuleAugmentation.mjs.map +1 -1
  35. package/dist/esm/init/utils/configManipulation.mjs +1 -1
  36. package/dist/esm/init/utils/configManipulation.mjs.map +1 -1
  37. package/dist/esm/installMCP/installMCP.mjs +2 -0
  38. package/dist/esm/installMCP/installMCP.mjs.map +1 -0
  39. package/dist/esm/installSkills/index.mjs +1 -1
  40. package/dist/esm/installSkills/index.mjs.map +1 -1
  41. package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs +1 -1
  42. package/dist/esm/loadDictionaries/log.mjs +2 -2
  43. package/dist/esm/loadDictionaries/log.mjs.map +1 -1
  44. package/dist/esm/prepareIntlayer.mjs +1 -1
  45. package/dist/esm/utils/getPathHash.mjs +2 -0
  46. package/dist/esm/utils/getPathHash.mjs.map +1 -0
  47. package/dist/esm/utils/index.mjs +1 -1
  48. package/dist/esm/utils/runParallel/pidTree.mjs.map +1 -1
  49. package/dist/esm/utils/runParallel/ps.mjs.map +1 -1
  50. package/dist/esm/utils/runParallel/wmic.mjs.map +1 -1
  51. package/dist/esm/watcher.mjs +1 -1
  52. package/dist/esm/watcher.mjs.map +1 -1
  53. package/dist/esm/writeContentDeclaration/transformJSFile.mjs +1 -2
  54. package/dist/esm/writeContentDeclaration/transformJSFile.mjs.map +1 -1
  55. package/dist/esm/writeContentDeclaration/transformJSONFile.mjs +1 -1
  56. package/dist/esm/writeContentDeclaration/transformJSONFile.mjs.map +1 -1
  57. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +1 -1
  58. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
  59. package/dist/esm/writeContentDeclaration/writeJSFile.mjs +1 -1
  60. package/dist/types/build.d.ts +0 -5
  61. package/dist/types/cli.d.ts +8 -5
  62. package/dist/types/createType/createModuleAugmentation.d.ts.map +1 -1
  63. package/dist/types/fetchDistantDictionaries.d.ts +0 -1
  64. package/dist/types/fetchDistantDictionaries.d.ts.map +1 -1
  65. package/dist/types/init/utils/configManipulation.d.ts +0 -12
  66. package/dist/types/init/utils/configManipulation.d.ts.map +1 -1
  67. package/dist/types/installMCP/installMCP.d.ts +11 -0
  68. package/dist/types/installMCP/installMCP.d.ts.map +1 -0
  69. package/dist/types/installSkills/index.d.ts +23 -49
  70. package/dist/types/installSkills/index.d.ts.map +1 -1
  71. package/dist/types/loadDictionaries/log.d.ts.map +1 -1
  72. package/dist/types/utils/getPathHash.d.ts +5 -0
  73. package/dist/types/utils/getPathHash.d.ts.map +1 -0
  74. package/dist/types/utils/index.d.ts +2 -2
  75. package/dist/types/watcher.d.ts.map +1 -1
  76. package/dist/types/writeContentDeclaration/transformJSFile.d.ts +1 -26
  77. package/dist/types/writeContentDeclaration/transformJSFile.d.ts.map +1 -1
  78. package/dist/types/writeContentDeclaration/transformJSONFile.d.ts.map +1 -1
  79. package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
  80. package/package.json +9 -23
  81. package/dist/cjs/index.cjs +0 -1
  82. package/dist/cjs/transformFiles/extractDictionaryKey.cjs +0 -2
  83. package/dist/cjs/transformFiles/extractDictionaryKey.cjs.map +0 -1
  84. package/dist/cjs/transformFiles/index.cjs +0 -1
  85. package/dist/cjs/transformFiles/transformFiles.cjs +0 -2
  86. package/dist/cjs/transformFiles/transformFiles.cjs.map +0 -1
  87. package/dist/cjs/utils/getFileHash.cjs +0 -2
  88. package/dist/cjs/utils/getFileHash.cjs.map +0 -1
  89. package/dist/esm/index.mjs +0 -1
  90. package/dist/esm/transformFiles/extractDictionaryKey.mjs +0 -2
  91. package/dist/esm/transformFiles/extractDictionaryKey.mjs.map +0 -1
  92. package/dist/esm/transformFiles/index.mjs +0 -1
  93. package/dist/esm/transformFiles/transformFiles.mjs +0 -2
  94. package/dist/esm/transformFiles/transformFiles.mjs.map +0 -1
  95. package/dist/esm/utils/getFileHash.mjs +0 -2
  96. package/dist/esm/utils/getFileHash.mjs.map +0 -1
  97. package/dist/types/index.d.ts +0 -57
  98. package/dist/types/transformFiles/extractDictionaryKey.d.ts +0 -5
  99. package/dist/types/transformFiles/extractDictionaryKey.d.ts.map +0 -1
  100. package/dist/types/transformFiles/index.d.ts +0 -3
  101. package/dist/types/transformFiles/transformFiles.d.ts +0 -24
  102. package/dist/types/transformFiles/transformFiles.d.ts.map +0 -1
  103. package/dist/types/utils/getFileHash.d.ts +0 -5
  104. package/dist/types/utils/getFileHash.d.ts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"log.mjs","names":[],"sources":["../../../src/loadDictionaries/log.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n ANSIColors,\n colorize,\n extractErrorMessage,\n spinnerFrames,\n v,\n x,\n} from '@intlayer/config/client';\nimport type { DictionariesStatus } from './loadDictionaries';\n\nexport class DictionariesLogger {\n private statuses: DictionariesStatus[] = [];\n private spinnerTimer: NodeJS.Timeout | null = null;\n private spinnerIndex = 0;\n private renderedLines = 0;\n private readonly spinnerFrames = spinnerFrames;\n private isFinished = false;\n private readonly prefix: string;\n private lastRenderedState: string = '';\n private remoteCheckInProgress = false;\n private expectRemote = false;\n private remoteError: string | undefined;\n private pluginTotal = 0;\n private pluginDone = 0;\n private pluginError: string | undefined;\n\n constructor() {\n this.prefix = configuration?.log?.prefix ?? '';\n }\n\n setExpectRemote(expect: boolean) {\n this.expectRemote = expect;\n }\n\n startRemoteCheck() {\n if (this.isFinished) return;\n this.remoteCheckInProgress = true;\n this.startSpinner();\n this.render();\n }\n\n stopRemoteCheck() {\n this.remoteCheckInProgress = false;\n }\n\n update(newStatuses: DictionariesStatus[]) {\n if (this.isFinished) return;\n for (const status of newStatuses) {\n const index = this.statuses.findIndex(\n (s) =>\n s.dictionaryKey === status.dictionaryKey && s.type === status.type\n );\n if (index >= 0) {\n this.statuses[index] = status;\n } else {\n this.statuses.push(status);\n }\n }\n\n // If we expect remote fetch later, avoid rendering a local-only line first\n const { remoteTotal } = this.computeProgress();\n if (this.expectRemote && !this.remoteCheckInProgress && remoteTotal === 0) {\n // Do not start spinner or render yet; wait until remote check starts\n return;\n }\n\n this.startSpinner();\n this.render();\n }\n\n finish() {\n this.isFinished = true;\n this.stopSpinner();\n // Render final state and keep it visible\n this.render();\n }\n\n private startSpinner() {\n if (this.spinnerTimer || this.isFinished) return;\n this.spinnerTimer = setInterval(() => {\n this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length;\n this.render();\n }, 100);\n }\n\n private stopSpinner() {\n if (!this.spinnerTimer) return;\n clearInterval(this.spinnerTimer);\n this.spinnerTimer = null;\n }\n\n public setRemoteError = (error?: Error) => {\n this.remoteError = extractErrorMessage(error);\n // Avoid rendering a transient remote-only line while the remote check flag is still true\n // Ensure local + remote are rendered together after a failure\n this.stopRemoteCheck();\n this.render();\n };\n\n setPluginTotal(total: number) {\n if (this.isFinished) return;\n this.pluginTotal = total;\n if (total > 0) {\n this.startSpinner();\n }\n this.render();\n }\n\n setPluginDone(done: number) {\n if (this.isFinished) return;\n this.pluginDone = done;\n this.render();\n }\n\n setPluginError(error?: Error) {\n if (this.isFinished) return;\n this.pluginError = extractErrorMessage(error);\n this.render();\n }\n\n private render() {\n const {\n localTotal,\n localDone,\n remoteTotal,\n remoteDone,\n pluginTotal,\n pluginDone,\n } = this.computeProgress();\n\n const frame = this.spinnerFrames[this.spinnerIndex];\n const clock = colorize(frame, ANSIColors.BLUE);\n const lines: string[] = [];\n\n const isLocalDone = localDone === localTotal;\n const isRemoteDone = remoteDone === remoteTotal;\n const isPluginDone = pluginDone === pluginTotal;\n\n const suppressLocalWhileCheckingRemote =\n this.expectRemote && this.remoteCheckInProgress && remoteTotal === 0;\n\n if (!suppressLocalWhileCheckingRemote) {\n if (isLocalDone) {\n lines.push(\n `${this.prefix} ${v} Local content: ${colorize(`${localDone}`, ANSIColors.GREEN)}${colorize(`/${localTotal}`, ANSIColors.GREY)}`\n );\n } else {\n lines.push(\n `${this.prefix} ${clock} Local content: ${colorize(`${localDone}`, ANSIColors.BLUE)}${colorize(`/${localTotal}`, ANSIColors.GREY)}`\n );\n }\n }\n\n // Single remote line: show error, check, or progress counts\n if (remoteTotal > 0 || this.remoteCheckInProgress || this.remoteError) {\n if (this.remoteError) {\n lines.push(\n `${this.prefix} ${x} Remote content: ${colorize(\n this.remoteError,\n ANSIColors.RED\n )}`\n );\n } else if (remoteTotal === 0) {\n lines.push(\n `${this.prefix} ${clock} Remote content: ${colorize('Check server', ANSIColors.BLUE)}`\n );\n } else if (isRemoteDone) {\n lines.push(\n `${this.prefix} ${v} Remote content: ${colorize(`${remoteDone}`, ANSIColors.GREEN)}${colorize(`/${remoteTotal}`, ANSIColors.GREY)}`\n );\n } else {\n lines.push(\n `${this.prefix} ${clock} Remote content: ${colorize(`${remoteDone}`, ANSIColors.BLUE)}${colorize(`/${remoteTotal}`, ANSIColors.GREY)}`\n );\n }\n }\n\n // Plugin line: show error or progress counts\n if (pluginTotal > 0 || this.pluginError) {\n if (this.pluginError) {\n lines.push(\n `${this.prefix} ${x} Plugin content: ${colorize(\n this.pluginError,\n ANSIColors.RED\n )}`\n );\n } else if (isPluginDone) {\n lines.push(\n `${this.prefix} ${v} Plugin content: ${colorize(`${pluginDone}`, ANSIColors.GREEN)}${colorize(`/${pluginTotal}`, ANSIColors.GREY)}`\n );\n } else {\n lines.push(\n `${this.prefix} ${clock} Plugin content: ${colorize(`${pluginDone}`, ANSIColors.BLUE)}${colorize(`/${pluginTotal}`, ANSIColors.GREY)}`\n );\n }\n }\n\n // Check if the state has changed to avoid duplicate rendering\n const currentState = lines.join('\\n');\n if (currentState === this.lastRenderedState) {\n return;\n }\n this.lastRenderedState = currentState;\n\n if (this.renderedLines > 0) {\n process.stdout.write(`\\x1b[${this.renderedLines}F`);\n }\n\n const totalLinesToClear = Math.max(this.renderedLines, lines.length);\n for (let i = 0; i < totalLinesToClear; i++) {\n process.stdout.write('\\x1b[2K');\n const line = lines[i];\n if (line !== undefined) {\n process.stdout.write(line);\n }\n process.stdout.write('\\n');\n }\n\n this.renderedLines = lines.length;\n }\n\n private computeProgress() {\n const localKeys = new Set(\n this.statuses\n .filter((s) => s.type === 'local')\n .map((s) => s.dictionaryKey)\n );\n\n const localDoneKeys = new Set(\n this.statuses\n .filter(\n (s) =>\n s.type === 'local' && (s.status === 'built' || s.status === 'error')\n )\n .map((s) => s.dictionaryKey)\n );\n\n const remoteKeys = new Set(\n this.statuses\n .filter((s) => s.type === 'remote')\n .map((s) => s.dictionaryKey)\n );\n\n const remoteDoneKeys = new Set(\n this.statuses\n .filter(\n (s) =>\n s.type === 'remote' &&\n (s.status === 'fetched' ||\n s.status === 'imported' ||\n s.status === 'error')\n )\n .map((s) => s.dictionaryKey)\n );\n\n return {\n localTotal: localKeys.size,\n localDone: localDoneKeys.size,\n remoteTotal: remoteKeys.size,\n remoteDone: remoteDoneKeys.size,\n pluginTotal: this.pluginTotal,\n pluginDone: this.pluginDone,\n } as const;\n }\n}\n"],"mappings":"mKAWA,IAAa,EAAb,KAAgC,CAC9B,SAAyC,EAAE,CAC3C,aAA8C,KAC9C,aAAuB,EACvB,cAAwB,EACxB,cAAiC,EACjC,WAAqB,GACrB,OACA,kBAAoC,GACpC,sBAAgC,GAChC,aAAuB,GACvB,YACA,YAAsB,EACtB,WAAqB,EACrB,YAEA,aAAc,CACZ,KAAK,OAAS,GAAe,KAAK,QAAU,GAG9C,gBAAgB,EAAiB,CAC/B,KAAK,aAAe,EAGtB,kBAAmB,CACb,KAAK,aACT,KAAK,sBAAwB,GAC7B,KAAK,cAAc,CACnB,KAAK,QAAQ,EAGf,iBAAkB,CAChB,KAAK,sBAAwB,GAG/B,O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EAErB,KAAK,cAAgB,GACvB,QAAQ,OAAO,MAAM,QAAQ,KAAK,cAAc,GAAG,CAGrD,IAAM,EAAoB,KAAK,IAAI,KAAK,cAAe,EAAM,OAAO,CACpE,IAAK,IAAI,EAAI,EAAG,EAAI,EAAmB,IAAK,CAC1C,QAAQ,OAAO,MAAM,UAAU,CAC/B,IAAM,EAAO,EAAM,GACf,IAAS,IAAA,IACX,QAAQ,OAAO,MAAM,EAAK,CAE5B,QAAQ,OAAO,MAAM;EAAK,CAG5B,KAAK,cAAgB,EAAM,OAG7B,iBAA0B,CACxB,IAAM,EAAY,IAAI,IACpB,KAAK,SACF,OAAQ,GAAM,EAAE,OAAS,QAAQ,CACjC,IAAK,GAAM,EAAE,cAAc,CAC/B,CAEK,EAAgB,IAAI,IACxB,KAAK,SACF,OACE,GACC,EAAE,OAAS,UAAY,EAAE,SAAW,SAAW,EAAE,SAAW,SAC/D,CACA,IAAK,GAAM,EAAE,cAAc,CAC/B,CAEK,EAAa,IAAI,IACrB,KAAK,SACF,OAAQ,GAAM,EAAE,OAAS,SAAS,CAClC,IAAK,GAAM,EAAE,cAAc,CAC/B,CAEK,EAAiB,IAAI,IACzB,KAAK,SACF,OACE,GACC,EAAE,OAAS,WACV,EAAE,SAAW,WACZ,EAAE,SAAW,YACb,EAAE,SAAW,SAClB,CACA,IAAK,GAAM,EAAE,cAAc,CAC/B,CAED,MAAO,CACL,WAAY,EAAU,KACtB,UAAW,EAAc,KACzB,YAAa,EAAW,KACxB,WAAY,EAAe,KAC3B,YAAa,KAAK,YAClB,WAAY,KAAK,WAClB"}
1
+ {"version":3,"file":"log.mjs","names":[],"sources":["../../../src/loadDictionaries/log.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport {\n ANSIColors,\n colorize,\n extractErrorMessage,\n getPrefix,\n spinnerFrames,\n v,\n x,\n} from '@intlayer/config/client';\nimport type { DictionariesStatus } from './loadDictionaries';\n\nexport class DictionariesLogger {\n private statuses: DictionariesStatus[] = [];\n private spinnerTimer: NodeJS.Timeout | null = null;\n private spinnerIndex = 0;\n private renderedLines = 0;\n private readonly spinnerFrames = spinnerFrames;\n private isFinished = false;\n private readonly prefix: string;\n private lastRenderedState: string = '';\n private remoteCheckInProgress = false;\n private expectRemote = false;\n private remoteError: string | undefined;\n private pluginTotal = 0;\n private pluginDone = 0;\n private pluginError: string | undefined;\n\n constructor() {\n this.prefix = getPrefix(configuration?.log?.prefix) ?? '';\n }\n\n setExpectRemote(expect: boolean) {\n this.expectRemote = expect;\n }\n\n startRemoteCheck() {\n if (this.isFinished) return;\n this.remoteCheckInProgress = true;\n this.startSpinner();\n this.render();\n }\n\n stopRemoteCheck() {\n this.remoteCheckInProgress = false;\n }\n\n update(newStatuses: DictionariesStatus[]) {\n if (this.isFinished) return;\n for (const status of newStatuses) {\n const index = this.statuses.findIndex(\n (s) =>\n s.dictionaryKey === status.dictionaryKey && s.type === status.type\n );\n if (index >= 0) {\n this.statuses[index] = status;\n } else {\n this.statuses.push(status);\n }\n }\n\n // If we expect remote fetch later, avoid rendering a local-only line first\n const { remoteTotal } = this.computeProgress();\n if (this.expectRemote && !this.remoteCheckInProgress && remoteTotal === 0) {\n // Do not start spinner or render yet; wait until remote check starts\n return;\n }\n\n this.startSpinner();\n this.render();\n }\n\n finish() {\n this.isFinished = true;\n this.stopSpinner();\n // Render final state and keep it visible\n this.render();\n }\n\n private startSpinner() {\n if (this.spinnerTimer || this.isFinished) return;\n this.spinnerTimer = setInterval(() => {\n this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerFrames.length;\n this.render();\n }, 100);\n }\n\n private stopSpinner() {\n if (!this.spinnerTimer) return;\n clearInterval(this.spinnerTimer);\n this.spinnerTimer = null;\n }\n\n public setRemoteError = (error?: Error) => {\n this.remoteError = extractErrorMessage(error);\n // Avoid rendering a transient remote-only line while the remote check flag is still true\n // Ensure local + remote are rendered together after a failure\n this.stopRemoteCheck();\n this.render();\n };\n\n setPluginTotal(total: number) {\n if (this.isFinished) return;\n this.pluginTotal = total;\n if (total > 0) {\n this.startSpinner();\n }\n this.render();\n }\n\n setPluginDone(done: number) {\n if (this.isFinished) return;\n this.pluginDone = done;\n this.render();\n }\n\n setPluginError(error?: Error) {\n if (this.isFinished) return;\n this.pluginError = extractErrorMessage(error);\n this.render();\n }\n\n private render() {\n const {\n localTotal,\n localDone,\n remoteTotal,\n remoteDone,\n pluginTotal,\n pluginDone,\n } = this.computeProgress();\n\n const frame = this.spinnerFrames[this.spinnerIndex];\n const clock = colorize(frame, ANSIColors.BLUE);\n const lines: string[] = [];\n\n const isLocalDone = localDone === localTotal;\n const isRemoteDone = remoteDone === remoteTotal;\n const isPluginDone = pluginDone === pluginTotal;\n\n const suppressLocalWhileCheckingRemote =\n this.expectRemote && this.remoteCheckInProgress && remoteTotal === 0;\n\n if (!suppressLocalWhileCheckingRemote) {\n if (isLocalDone) {\n lines.push(\n `${this.prefix} ${v} Local content: ${colorize(`${localDone}`, ANSIColors.GREEN)}${colorize(`/${localTotal}`, ANSIColors.GREY)}`\n );\n } else {\n lines.push(\n `${this.prefix} ${clock} Local content: ${colorize(`${localDone}`, ANSIColors.BLUE)}${colorize(`/${localTotal}`, ANSIColors.GREY)}`\n );\n }\n }\n\n // Single remote line: show error, check, or progress counts\n if (remoteTotal > 0 || this.remoteCheckInProgress || this.remoteError) {\n if (this.remoteError) {\n lines.push(\n `${this.prefix} ${x} Remote content: ${colorize(\n this.remoteError,\n ANSIColors.RED\n )}`\n );\n } else if (remoteTotal === 0) {\n lines.push(\n `${this.prefix} ${clock} Remote content: ${colorize('Check server', ANSIColors.BLUE)}`\n );\n } else if (isRemoteDone) {\n lines.push(\n `${this.prefix} ${v} Remote content: ${colorize(`${remoteDone}`, ANSIColors.GREEN)}${colorize(`/${remoteTotal}`, ANSIColors.GREY)}`\n );\n } else {\n lines.push(\n `${this.prefix} ${clock} Remote content: ${colorize(`${remoteDone}`, ANSIColors.BLUE)}${colorize(`/${remoteTotal}`, ANSIColors.GREY)}`\n );\n }\n }\n\n // Plugin line: show error or progress counts\n if (pluginTotal > 0 || this.pluginError) {\n if (this.pluginError) {\n lines.push(\n `${this.prefix} ${x} Plugin content: ${colorize(\n this.pluginError,\n ANSIColors.RED\n )}`\n );\n } else if (isPluginDone) {\n lines.push(\n `${this.prefix} ${v} Plugin content: ${colorize(`${pluginDone}`, ANSIColors.GREEN)}${colorize(`/${pluginTotal}`, ANSIColors.GREY)}`\n );\n } else {\n lines.push(\n `${this.prefix} ${clock} Plugin content: ${colorize(`${pluginDone}`, ANSIColors.BLUE)}${colorize(`/${pluginTotal}`, ANSIColors.GREY)}`\n );\n }\n }\n\n // Check if the state has changed to avoid duplicate rendering\n const currentState = lines.join('\\n');\n if (currentState === this.lastRenderedState) {\n return;\n }\n this.lastRenderedState = currentState;\n\n if (this.renderedLines > 0) {\n process.stdout.write(`\\x1b[${this.renderedLines}F`);\n }\n\n const totalLinesToClear = Math.max(this.renderedLines, lines.length);\n for (let i = 0; i < totalLinesToClear; i++) {\n process.stdout.write('\\x1b[2K');\n const line = lines[i];\n if (line !== undefined) {\n process.stdout.write(line);\n }\n process.stdout.write('\\n');\n }\n\n this.renderedLines = lines.length;\n }\n\n private computeProgress() {\n const localKeys = new Set(\n this.statuses\n .filter((s) => s.type === 'local')\n .map((s) => s.dictionaryKey)\n );\n\n const localDoneKeys = new Set(\n this.statuses\n .filter(\n (s) =>\n s.type === 'local' && (s.status === 'built' || s.status === 'error')\n )\n .map((s) => s.dictionaryKey)\n );\n\n const remoteKeys = new Set(\n this.statuses\n .filter((s) => s.type === 'remote')\n .map((s) => s.dictionaryKey)\n );\n\n const remoteDoneKeys = new Set(\n this.statuses\n .filter(\n (s) =>\n s.type === 'remote' &&\n (s.status === 'fetched' ||\n s.status === 'imported' ||\n s.status === 'error')\n )\n .map((s) => s.dictionaryKey)\n );\n\n return {\n localTotal: localKeys.size,\n localDone: localDoneKeys.size,\n remoteTotal: remoteKeys.size,\n remoteDone: remoteDoneKeys.size,\n plugin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,OACE,GACC,EAAE,OAAS,WACV,EAAE,SAAW,WACZ,EAAE,SAAW,YACb,EAAE,SAAW,SAClB,CACA,IAAK,GAAM,EAAE,cAAc,CAC/B,CAED,MAAO,CACL,WAAY,EAAU,KACtB,UAAW,EAAc,KACzB,YAAa,EAAW,KACxB,WAAY,EAAe,KAC3B,YAAa,KAAK,YAClB,WAAY,KAAK,WAClB"}
@@ -1,2 +1,2 @@
1
- import{buildDictionary as e}from"./buildIntlayerDictionary/buildIntlayerDictionary.mjs";import{cleanOutputDir as t}from"./cleanOutputDir.mjs";import{createDictionaryEntryPoint as n}from"./createDictionaryEntryPoint/createDictionaryEntryPoint.mjs";import{createModuleAugmentation as r}from"./createType/createModuleAugmentation.mjs";import{createTypes as i}from"./createType/createType.mjs";import{loadDictionaries as a}from"./loadDictionaries/loadDictionaries.mjs";import{writeRemoteDictionary as o}from"./buildIntlayerDictionary/writeRemoteDictionary.mjs";import{listDictionariesWithStats as s}from"./listDictionariesPath.mjs";import{runOnce as c}from"./utils/runOnce.mjs";import{isCachedConfigurationUpToDate as l,writeConfiguration as u}from"./writeConfiguration/index.mjs";import{stat as d}from"node:fs/promises";import{join as f}from"node:path";import{ANSIColors as p,colorize as m,getAppLogger as h}from"@intlayer/config/logger";import{cacheDisk as g}from"@intlayer/config/utils";import _ from"@intlayer/config/package.json"with{type:"json"};const v={clean:!1,format:[`cjs`,`esm`],cacheTimeoutMs:1e3*60*60},y=async(y,b)=>{let x=h(y),S=f(y.system.cacheDir,`intlayer-prepared.lock`),C=g(y,[`intlayer-version`]),w=await C.get(),T=!!(w&&w===_.version),E=await l(y),D=await s(y),O=!1;try{let e=await d(S);O=D.some(t=>t.stats.mtime.getTime()>e.mtime.getTime())}catch{}let k=y.plugins?.some(e=>!!e.loadDictionaries),{clean:A,format:j,forceRun:M,onIsCached:N,cacheTimeoutMs:P}={...v,forceRun:!T||!E||O||k,...b??{}};await c(S,async()=>{(A||!T)&&await t(y),await C.set(_.version);let s=Date.now();x([`Preparing Intlayer`,m(`(v${_.version})`,p.GREY_DARK)]),await u(y);let c=Date.now();x([`Configuration written`,m(`(${c-s}ms)`,p.GREY_DARK)],{isVerbose:!0});let l=await a(D.map(e=>e.path),y),d=Date.now();x([`Content loaded`,m([l.remoteDictionaries.length+l.pluginDictionaries.length>0?[`(Total: ${d-c}ms`,l.localDictionaries.length>0?` - Local: ${l.time.localDictionaries}ms`:``,l.remoteDictionaries.length>0?` - Remote: ${l.time.remoteDictionaries}ms`:``,l.pluginDictionaries.length>0?` - Plugin: ${l.time.pluginDictionaries}ms`:``,`)`].join(``):`(${d-c}ms)`].join(``),p.GREY_DARK)],{isVerbose:!0});let f=await e([...l.localDictionaries,...l.remoteDictionaries,...l.pluginDictionaries],y,j,!1);await o(l.remoteDictionaries,y),await i(Object.values(f?.mergedDictionaries??{}).map(e=>e.dictionary),y),await n(y);let h=Date.now();x([`Dictionaries built`,m(`(${h-s}ms)`,p.GREY_DARK)]),await r(y),x([`Module augmentation built`,m(`(${Date.now()-h}ms)`,p.GREY_DARK)],{isVerbose:!0});for await(let e of y.plugins??[]){let{unmergedDictionaries:t,mergedDictionaries:n}=f;await e.afterBuild?.({dictionaries:{unmergedDictionaries:t,mergedDictionaries:n},configuration:y})}x([`Done`,m(`${Date.now()-s}ms`,p.GREEN)],{level:`info`,isVerbose:!0})},{forceRun:M,onIsCached:N,cacheTimeoutMs:P})};export{y as prepareIntlayer};
1
+ import{buildDictionary as e}from"./buildIntlayerDictionary/buildIntlayerDictionary.mjs";import{cleanOutputDir as t}from"./cleanOutputDir.mjs";import{createDictionaryEntryPoint as n}from"./createDictionaryEntryPoint/createDictionaryEntryPoint.mjs";import{runOnce as r}from"./utils/runOnce.mjs";import{createModuleAugmentation as i}from"./createType/createModuleAugmentation.mjs";import{createTypes as a}from"./createType/createType.mjs";import{loadDictionaries as o}from"./loadDictionaries/loadDictionaries.mjs";import{writeRemoteDictionary as s}from"./buildIntlayerDictionary/writeRemoteDictionary.mjs";import{listDictionariesWithStats as c}from"./listDictionariesPath.mjs";import{isCachedConfigurationUpToDate as l,writeConfiguration as u}from"./writeConfiguration/index.mjs";import{stat as d}from"node:fs/promises";import{join as f}from"node:path";import{ANSIColors as p,colorize as m,getAppLogger as h}from"@intlayer/config/logger";import{cacheDisk as g}from"@intlayer/config/utils";import _ from"@intlayer/config/package.json"with{type:"json"};const v={clean:!1,format:[`cjs`,`esm`],cacheTimeoutMs:1e3*60*60},y=async(y,b)=>{let x=h(y),S=f(y.system.cacheDir,`intlayer-prepared.lock`),C=g(y,[`intlayer-version`]),w=await C.get(),T=!!(w&&w===_.version),E=await l(y),D=await c(y),O=!1;try{let e=await d(S);O=D.some(t=>t.stats.mtime.getTime()>e.mtime.getTime())}catch{}let k=y.plugins?.some(e=>!!e.loadDictionaries),{clean:A,format:j,forceRun:M,onIsCached:N,cacheTimeoutMs:P}={...v,forceRun:!T||!E||O||k,...b??{}};await r(S,async()=>{(A||!T)&&await t(y),await C.set(_.version);let r=Date.now();x([`Preparing Intlayer`,m(`(v${_.version})`,p.GREY_DARK)]),await u(y);let c=Date.now();x([`Configuration written`,m(`(${c-r}ms)`,p.GREY_DARK)],{isVerbose:!0});let l=await o(D.map(e=>e.path),y),d=Date.now();x([`Content loaded`,m([l.remoteDictionaries.length+l.pluginDictionaries.length>0?[`(Total: ${d-c}ms`,l.localDictionaries.length>0?` - Local: ${l.time.localDictionaries}ms`:``,l.remoteDictionaries.length>0?` - Remote: ${l.time.remoteDictionaries}ms`:``,l.pluginDictionaries.length>0?` - Plugin: ${l.time.pluginDictionaries}ms`:``,`)`].join(``):`(${d-c}ms)`].join(``),p.GREY_DARK)],{isVerbose:!0});let f=await e([...l.localDictionaries,...l.remoteDictionaries,...l.pluginDictionaries],y,j,!1);await s(l.remoteDictionaries,y),await a(Object.values(f?.mergedDictionaries??{}).map(e=>e.dictionary),y),await n(y);let h=Date.now();x([`Dictionaries built`,m(`(${h-r}ms)`,p.GREY_DARK)]),await i(y),x([`Module augmentation built`,m(`(${Date.now()-h}ms)`,p.GREY_DARK)],{isVerbose:!0});for await(let e of y.plugins??[]){let{unmergedDictionaries:t,mergedDictionaries:n}=f;await e.afterBuild?.({dictionaries:{unmergedDictionaries:t,mergedDictionaries:n},configuration:y})}x([`Done`,m(`${Date.now()-r}ms`,p.GREEN)],{level:`info`,isVerbose:!0})},{forceRun:M,onIsCached:N,cacheTimeoutMs:P})};export{y as prepareIntlayer};
2
2
  //# sourceMappingURL=prepareIntlayer.mjs.map
@@ -0,0 +1,2 @@
1
+ import e from"node:crypto";const t=t=>e.createHash(`sha3-256`).update(t).digest(`base64`).replace(/[^A-Z\d]/gi,``).substring(0,20);export{t as getPathHash};
2
+ //# sourceMappingURL=getPathHash.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getPathHash.mjs","names":[],"sources":["../../../src/utils/getPathHash.ts"],"sourcesContent":["import crypto from 'node:crypto';\n\nexport const getPathHash = (filePath: string) =>\n crypto\n .createHash('sha3-256')\n .update(filePath)\n .digest('base64')\n .replace(/[^A-Z\\d]/gi, '')\n .substring(0, 20);\n"],"mappings":"2BAEA,MAAa,EAAe,GAC1B,EACG,WAAW,WAAW,CACtB,OAAO,EAAS,CAChB,OAAO,SAAS,CAChB,QAAQ,aAAc,GAAG,CACzB,UAAU,EAAG,GAAG"}
@@ -1 +1 @@
1
- import{Queue as e,pLimit as t}from"./pLimit.mjs";import{parallelize as n}from"./parallelize.mjs";import{formatLocale as r,formatPath as i}from"./formatter.mjs";import{autoDecorateContent as a}from"./autoDecorateContent.mjs";import{resolveObjectPromises as o}from"./resolveObjectPromises.mjs";import{getFileHash as s}from"./getFileHash.mjs";import{sortAlphabetically as c}from"./sortAlphabetically.mjs";import{runOnce as l}from"./runOnce.mjs";import{getExtensionFromFormat as u,getFormatFromExtension as d}from"./getFormatFromExtension.mjs";import{buildFilesList as f}from"./buildFilesList.mjs";import{splitTextByLines as p}from"./splitTextByLine.mjs";import{getChunk as m}from"./getChunk.mjs";import{assembleJSON as h,chunkJSON as g,reconstructFromSingleChunk as _}from"./chunkJSON.mjs";import{getComponentTransformPattern as v,getComponentTransformPatternSync as y}from"./getComponentTransformPattern.mjs";import{mergeChunks as b}from"./mergeChunks.mjs";import{getGlobalLimiter as x,getTaskLimiter as S,parallelizeGlobal as C}from"./parallelizeGlobal.mjs";import{reduceObjectFormat as w}from"./reduceObjectFormat.mjs";import{runParallel as T}from"./runParallel/index.mjs";import{verifyIdenticObjectFormat as E}from"./verifyIdenticObjectFormat.mjs";export{e as Queue,h as assembleJSON,a as autoDecorateContent,f as buildFilesList,g as chunkJSON,r as formatLocale,i as formatPath,m as getChunk,v as getComponentTransformPattern,y as getComponentTransformPatternSync,u as getExtensionFromFormat,s as getFileHash,d as getFormatFromExtension,x as getGlobalLimiter,S as getTaskLimiter,b as mergeChunks,t as pLimit,n as parallelize,C as parallelizeGlobal,_ as reconstructFromSingleChunk,w as reduceObjectFormat,o as resolveObjectPromises,l as runOnce,T as runParallel,c as sortAlphabetically,p as splitTextByLines,E as verifyIdenticObjectFormat};
1
+ import{Queue as e,pLimit as t}from"./pLimit.mjs";import{parallelize as n}from"./parallelize.mjs";import{formatLocale as r,formatPath as i}from"./formatter.mjs";import{autoDecorateContent as a}from"./autoDecorateContent.mjs";import{resolveObjectPromises as o}from"./resolveObjectPromises.mjs";import{getPathHash as s}from"./getPathHash.mjs";import{buildFilesList as c}from"./buildFilesList.mjs";import{splitTextByLines as l}from"./splitTextByLine.mjs";import{getChunk as u}from"./getChunk.mjs";import{assembleJSON as d,chunkJSON as f,reconstructFromSingleChunk as p}from"./chunkJSON.mjs";import{getComponentTransformPattern as m,getComponentTransformPatternSync as h}from"./getComponentTransformPattern.mjs";import{getExtensionFromFormat as g,getFormatFromExtension as _}from"./getFormatFromExtension.mjs";import{mergeChunks as v}from"./mergeChunks.mjs";import{getGlobalLimiter as y,getTaskLimiter as b,parallelizeGlobal as x}from"./parallelizeGlobal.mjs";import{reduceObjectFormat as S}from"./reduceObjectFormat.mjs";import{runOnce as C}from"./runOnce.mjs";import{runParallel as w}from"./runParallel/index.mjs";import{sortAlphabetically as T}from"./sortAlphabetically.mjs";import{verifyIdenticObjectFormat as E}from"./verifyIdenticObjectFormat.mjs";export{e as Queue,d as assembleJSON,a as autoDecorateContent,c as buildFilesList,f as chunkJSON,r as formatLocale,i as formatPath,u as getChunk,m as getComponentTransformPattern,h as getComponentTransformPatternSync,g as getExtensionFromFormat,_ as getFormatFromExtension,y as getGlobalLimiter,s as getPathHash,b as getTaskLimiter,v as mergeChunks,t as pLimit,n as parallelize,x as parallelizeGlobal,p as reconstructFromSingleChunk,S as reduceObjectFormat,o as resolveObjectPromises,C as runOnce,w as runParallel,T as sortAlphabetically,l as splitTextByLines,E as verifyIdenticObjectFormat};
@@ -1 +1 @@
1
- {"version":3,"file":"pidTree.mjs","names":[],"sources":["../../../../src/utils/runParallel/pidTree.ts"],"sourcesContent":["import * as os from 'node:os';\nimport { ps } from './ps';\nimport { wmic } from './wmic';\n\ntype Platform =\n | 'darwin'\n | 'sunos'\n | 'freebsd'\n | 'netbsd'\n | 'win'\n | 'linux'\n | 'aix';\ntype Method = 'ps' | 'wmic';\n\ntype ProcessList = [number, number][]; // [PPID, PID][]\n\ninterface ListOptions {\n root?: boolean;\n advanced?: boolean;\n}\n\ntype ProcessInfo = { pid: number; ppid?: number };\ntype ResultType<T extends ListOptions | undefined> = T extends {\n advanced: true;\n}\n ? ProcessInfo[]\n : number[];\n\ntype ProcessListCallback = (err: Error | null, list?: ProcessList) => void;\ntype ListCallback<T extends ListOptions | undefined> = (\n err: Error | null,\n list?: ResultType<T>\n) => void;\n\ntype ProcessListFn = (callback: ProcessListCallback) => void;\n\nconst platformToMethod: Record<Platform, Method> = {\n darwin: 'ps',\n sunos: 'ps',\n freebsd: 'ps',\n netbsd: 'ps',\n win: 'wmic',\n linux: 'ps',\n aix: 'ps',\n};\n\nconst methodToFn: Record<Method, ProcessListFn> = {\n ps,\n wmic,\n};\n\nlet platform: string = os.platform();\nif (platform.startsWith('win')) {\n platform = 'win';\n}\n\nconst method: Method | undefined = platformToMethod[platform as Platform];\n\n/**\n * Gets the list of all the pids of the system.\n */\nconst getAll = (callback: ProcessListCallback): void => {\n if (method === undefined) {\n callback(\n new Error(\n os.platform() +\n ' is not supported yet, please open an issue (https://github.com/simonepri/pidtree)'\n ),\n undefined\n );\n return;\n }\n\n const listFn = methodToFn[method];\n listFn(callback);\n};\n\n/**\n * Get the list of children and grandchildren pids of the given PID.\n * @param PID A PID. If -1 will return all the pids.\n * @param options Optional options object.\n * @param callback Called when the list is ready.\n */\nconst pidtree = <T extends ListOptions | undefined>(\n PID: number | string,\n options: T | ListCallback<T> | undefined,\n callback?: ListCallback<T>\n): void => {\n let normalizedOptions: ListOptions;\n let normalizedCallback: ListCallback<T>;\n\n if (typeof options === 'function') {\n normalizedCallback = options;\n normalizedOptions = {};\n } else {\n normalizedCallback = callback!;\n normalizedOptions = typeof options === 'object' ? options : {};\n }\n\n const parsedPID = parseInt(String(PID), 10);\n if (Number.isNaN(parsedPID) || parsedPID < -1) {\n normalizedCallback(\n new TypeError('The pid provided is invalid') as Error,\n undefined\n );\n return;\n }\n\n getAll((err, processList) => {\n if (err) {\n normalizedCallback(err, undefined);\n return;\n }\n\n if (!processList) {\n normalizedCallback(new Error('Failed to get process list'), undefined);\n return;\n }\n\n // If the user wants the whole list just return it\n if (parsedPID === -1) {\n const result = processList.map(([ppid, pid]) =>\n normalizedOptions.advanced ? { ppid, pid } : pid\n ) as ResultType<T>;\n\n normalizedCallback(null, result);\n return;\n }\n\n let root: ProcessInfo | number | undefined;\n for (let l = 0; l < processList.length; l++) {\n if (processList[l][1] === parsedPID) {\n root = normalizedOptions.advanced\n ? { ppid: processList[l][0], pid: parsedPID }\n : parsedPID;\n break;\n }\n\n if (processList[l][0] === parsedPID) {\n root = normalizedOptions.advanced ? { pid: parsedPID } : parsedPID; // Special pids like 0 on *nix\n }\n }\n\n if (root === undefined) {\n normalizedCallback(new Error('No matching pid found'), undefined);\n return;\n }\n\n // Build the adjacency Hash Map (pid -> [children of pid])\n const tree: Record<number, number[]> = {};\n const listCopy = [...processList];\n while (listCopy.length > 0) {\n const element = listCopy.pop()!;\n if (tree[element[0]]) {\n tree[element[0]].push(element[1]);\n } else {\n tree[element[0]] = [element[1]];\n }\n }\n\n // Starting by the PID provided by the user, traverse the tree using the\n // adjacency Hash Map until the whole subtree is visited.\n // Each pid encountered while visiting is added to the pids array.\n let idx = 0;\n const pids: (ProcessInfo | number)[] = [root];\n while (idx < pids.length) {\n const curpid = normalizedOptions.advanced\n ? (pids[idx++] as ProcessInfo).pid\n : (pids[idx++] as number);\n if (!tree[curpid]) continue;\n const length = tree[curpid].length;\n for (let j = 0; j < length; j++) {\n pids.push(\n normalizedOptions.advanced\n ? { ppid: curpid, pid: tree[curpid][j] }\n : tree[curpid][j]\n );\n }\n\n delete tree[curpid];\n }\n\n if (!normalizedOptions.root) {\n pids.shift(); // Remove root\n }\n\n normalizedCallback(null, pids as ResultType<T>);\n });\n};\n\nconst pify = <T extends ListOptions | undefined>(\n fn: typeof pidtree,\n arg1: number | string,\n arg2: T | undefined\n): Promise<ResultType<T>> => {\n return new Promise((resolve, reject) => {\n fn(arg1, arg2, (err, data) => {\n if (err) return reject(err);\n if (data === undefined) {\n return reject(new Error('No data returned'));\n }\n resolve(data);\n });\n });\n};\n\n// Node versions prior to 4.0.0 do not define have `startsWith`.\n/* istanbul ignore if */\nif (!String.prototype.startsWith) {\n String.prototype.startsWith = function (suffix: string): boolean {\n return this.substring(0, suffix.length) === suffix;\n };\n}\n\n/**\n * Get the list of children pids of the given pid.\n * @param pid A PID. If -1 will return all the pids.\n * @param options Optional options object.\n * @param callback Called when the list is ready. If not provided a promise is returned instead.\n * @returns Only when the callback is not provided.\n */\nexport const list = <T extends ListOptions | undefined>(\n pid: number | string,\n options?: T | ListCallback<T>,\n callback?: ListCallback<T>\n): Promise<ResultType<T>> | undefined => {\n if (typeof options === 'function') {\n pidtree(pid, undefined, options);\n return;\n }\n\n if (typeof callback === 'function') {\n pidtree(pid, options, callback);\n return;\n }\n\n return pify(pidtree, pid, options);\n};\n"],"mappings":"0FAoCA,MAAM,EAA6C,CACjD,OAAQ,KACR,MAAO,KACP,QAAS,KACT,OAAQ,KACR,IAAK,OACL,MAAO,KACP,IAAK,KACN,CAEK,EAA4C,CAChD,KACA,OACD,CAED,IAAI,EAAmB,EAAG,UAAU,CAChC,EAAS,WAAW,MAAM,GAC5B,EAAW,OAGb,MAAM,EAA6B,EAAiB,GAK9C,EAAU,GAAwC,CACtD,GAAI,IAAW,IAAA,GAAW,CACxB,EACM,MACF,EAAG,UAAU,CACX,qFACH,CACD,IAAA,GACD,CACD,OAGF,IAAM,EAAS,EAAW,GAC1B,EAAO,EAAS,EASZ,GACJ,EACA,EACA,IACS,CACT,IAAI,EACA,EAEA,OAAO,GAAY,YACrB,EAAqB,EACrB,EAAoB,EAAE,GAEtB,EAAqB,EACrB,EAAoB,OAAO,GAAY,SAAW,EAAU,EAAE,EAGhE,IAAM,EAAY,SAAS,OAAO,EAAI,CAAE,GAAG,CAC3C,GAAI,OAAO,MAAM,EAAU,EAAI,EAAY,GAAI,CAC7C,EACM,UAAU,8BAA8B,CAC5C,IAAA,GACD,CACD,OAGF,GAAQ,EAAK,IAAgB,CAC3B,GAAI,EAAK,CACP,EAAmB,EAAK,IAAA,GAAU,CAClC,OAGF,GAAI,CAAC,EAAa,CAChB,EAAuB,MAAM,6BAA6B,CAAE,IAAA,GAAU,CACtE,OAIF,GAAI,IAAc,GAAI,CACpB,IAAM,EAAS,EAAY,KAAK,CAAC,EAAM,KACrC,EAAkB,SAAW,CAAE,OAAM,MAAK,CAAG,EAC9C,CAED,EAAmB,KAAM,EAAO,CAChC,OAGF,IAAI,EACJ,IAAK,IAAI,EAAI,EAAG,EAAI,EAAY,OAAQ,IAAK,CAC3C,GAAI,EAAY,GAAG,KAAO,EAAW,CACnC,EAAO,EAAkB,SACrB,CAAE,KAAM,EAA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CACjC,EAAQ,EAAK,IAAA,GAAW,EAAQ,CAChC,OAGF,GAAI,OAAO,GAAa,WAAY,CAClC,EAAQ,EAAK,EAAS,EAAS,CAC/B,OAGF,OAAO,EAAK,EAAS,EAAK,EAAQ"}
1
+ {"version":3,"file":"pidTree.mjs","names":["os"],"sources":["../../../../src/utils/runParallel/pidTree.ts"],"sourcesContent":["import * as os from 'node:os';\nimport { ps } from './ps';\nimport { wmic } from './wmic';\n\ntype Platform =\n | 'darwin'\n | 'sunos'\n | 'freebsd'\n | 'netbsd'\n | 'win'\n | 'linux'\n | 'aix';\ntype Method = 'ps' | 'wmic';\n\ntype ProcessList = [number, number][]; // [PPID, PID][]\n\ninterface ListOptions {\n root?: boolean;\n advanced?: boolean;\n}\n\ntype ProcessInfo = { pid: number; ppid?: number };\ntype ResultType<T extends ListOptions | undefined> = T extends {\n advanced: true;\n}\n ? ProcessInfo[]\n : number[];\n\ntype ProcessListCallback = (err: Error | null, list?: ProcessList) => void;\ntype ListCallback<T extends ListOptions | undefined> = (\n err: Error | null,\n list?: ResultType<T>\n) => void;\n\ntype ProcessListFn = (callback: ProcessListCallback) => void;\n\nconst platformToMethod: Record<Platform, Method> = {\n darwin: 'ps',\n sunos: 'ps',\n freebsd: 'ps',\n netbsd: 'ps',\n win: 'wmic',\n linux: 'ps',\n aix: 'ps',\n};\n\nconst methodToFn: Record<Method, ProcessListFn> = {\n ps,\n wmic,\n};\n\nlet platform: string = os.platform();\nif (platform.startsWith('win')) {\n platform = 'win';\n}\n\nconst method: Method | undefined = platformToMethod[platform as Platform];\n\n/**\n * Gets the list of all the pids of the system.\n */\nconst getAll = (callback: ProcessListCallback): void => {\n if (method === undefined) {\n callback(\n new Error(\n os.platform() +\n ' is not supported yet, please open an issue (https://github.com/simonepri/pidtree)'\n ),\n undefined\n );\n return;\n }\n\n const listFn = methodToFn[method];\n listFn(callback);\n};\n\n/**\n * Get the list of children and grandchildren pids of the given PID.\n * @param PID A PID. If -1 will return all the pids.\n * @param options Optional options object.\n * @param callback Called when the list is ready.\n */\nconst pidtree = <T extends ListOptions | undefined>(\n PID: number | string,\n options: T | ListCallback<T> | undefined,\n callback?: ListCallback<T>\n): void => {\n let normalizedOptions: ListOptions;\n let normalizedCallback: ListCallback<T>;\n\n if (typeof options === 'function') {\n normalizedCallback = options;\n normalizedOptions = {};\n } else {\n normalizedCallback = callback!;\n normalizedOptions = typeof options === 'object' ? options : {};\n }\n\n const parsedPID = parseInt(String(PID), 10);\n if (Number.isNaN(parsedPID) || parsedPID < -1) {\n normalizedCallback(\n new TypeError('The pid provided is invalid') as Error,\n undefined\n );\n return;\n }\n\n getAll((err, processList) => {\n if (err) {\n normalizedCallback(err, undefined);\n return;\n }\n\n if (!processList) {\n normalizedCallback(new Error('Failed to get process list'), undefined);\n return;\n }\n\n // If the user wants the whole list just return it\n if (parsedPID === -1) {\n const result = processList.map(([ppid, pid]) =>\n normalizedOptions.advanced ? { ppid, pid } : pid\n ) as ResultType<T>;\n\n normalizedCallback(null, result);\n return;\n }\n\n let root: ProcessInfo | number | undefined;\n for (let l = 0; l < processList.length; l++) {\n if (processList[l][1] === parsedPID) {\n root = normalizedOptions.advanced\n ? { ppid: processList[l][0], pid: parsedPID }\n : parsedPID;\n break;\n }\n\n if (processList[l][0] === parsedPID) {\n root = normalizedOptions.advanced ? { pid: parsedPID } : parsedPID; // Special pids like 0 on *nix\n }\n }\n\n if (root === undefined) {\n normalizedCallback(new Error('No matching pid found'), undefined);\n return;\n }\n\n // Build the adjacency Hash Map (pid -> [children of pid])\n const tree: Record<number, number[]> = {};\n const listCopy = [...processList];\n while (listCopy.length > 0) {\n const element = listCopy.pop()!;\n if (tree[element[0]]) {\n tree[element[0]].push(element[1]);\n } else {\n tree[element[0]] = [element[1]];\n }\n }\n\n // Starting by the PID provided by the user, traverse the tree using the\n // adjacency Hash Map until the whole subtree is visited.\n // Each pid encountered while visiting is added to the pids array.\n let idx = 0;\n const pids: (ProcessInfo | number)[] = [root];\n while (idx < pids.length) {\n const curpid = normalizedOptions.advanced\n ? (pids[idx++] as ProcessInfo).pid\n : (pids[idx++] as number);\n if (!tree[curpid]) continue;\n const length = tree[curpid].length;\n for (let j = 0; j < length; j++) {\n pids.push(\n normalizedOptions.advanced\n ? { ppid: curpid, pid: tree[curpid][j] }\n : tree[curpid][j]\n );\n }\n\n delete tree[curpid];\n }\n\n if (!normalizedOptions.root) {\n pids.shift(); // Remove root\n }\n\n normalizedCallback(null, pids as ResultType<T>);\n });\n};\n\nconst pify = <T extends ListOptions | undefined>(\n fn: typeof pidtree,\n arg1: number | string,\n arg2: T | undefined\n): Promise<ResultType<T>> => {\n return new Promise((resolve, reject) => {\n fn(arg1, arg2, (err, data) => {\n if (err) return reject(err);\n if (data === undefined) {\n return reject(new Error('No data returned'));\n }\n resolve(data);\n });\n });\n};\n\n// Node versions prior to 4.0.0 do not define have `startsWith`.\n/* istanbul ignore if */\nif (!String.prototype.startsWith) {\n String.prototype.startsWith = function (suffix: string): boolean {\n return this.substring(0, suffix.length) === suffix;\n };\n}\n\n/**\n * Get the list of children pids of the given pid.\n * @param pid A PID. If -1 will return all the pids.\n * @param options Optional options object.\n * @param callback Called when the list is ready. If not provided a promise is returned instead.\n * @returns Only when the callback is not provided.\n */\nexport const list = <T extends ListOptions | undefined>(\n pid: number | string,\n options?: T | ListCallback<T>,\n callback?: ListCallback<T>\n): Promise<ResultType<T>> | undefined => {\n if (typeof options === 'function') {\n pidtree(pid, undefined, options);\n return;\n }\n\n if (typeof callback === 'function') {\n pidtree(pid, options, callback);\n return;\n }\n\n return pify(pidtree, pid, options);\n};\n"],"mappings":"0FAoCA,MAAM,EAA6C,CACjD,OAAQ,KACR,MAAO,KACP,QAAS,KACT,OAAQ,KACR,IAAK,OACL,MAAO,KACP,IAAK,KACN,CAEK,EAA4C,CAChD,KACA,OACD,CAED,IAAI,EAAmBA,EAAG,UAAU,CAChC,EAAS,WAAW,MAAM,GAC5B,EAAW,OAGb,MAAM,EAA6B,EAAiB,GA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,IACf,EAAK,EAAQ,IAAI,KAAK,EAAQ,GAAG,CAEjC,EAAK,EAAQ,IAAM,CAAC,EAAQ,GAAG,CAOnC,IAAI,EAAM,EACJ,EAAiC,CAAC,EAAK,CAC7C,KAAO,EAAM,EAAK,QAAQ,CACxB,IAAM,EAAS,EAAkB,SAC5B,EAAK,KAAuB,IAC5B,EAAK,KACV,GAAI,CAAC,EAAK,GAAS,SACnB,IAAM,EAAS,EAAK,GAAQ,OAC5B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAQ,IAC1B,EAAK,KACH,EAAkB,SACd,CAAE,KAAM,EAAQ,IAAK,EAAK,GAAQ,GAAI,CACtC,EAAK,GAAQ,GAClB,CAGH,OAAO,EAAK,GAGT,EAAkB,MACrB,EAAK,OAAO,CAGd,EAAmB,KAAM,EAAsB,EAC/C,EAGE,GACJ,EACA,EACA,IAEO,IAAI,SAAS,EAAS,IAAW,CACtC,EAAG,EAAM,GAAO,EAAK,IAAS,CAC5B,GAAI,EAAK,OAAO,EAAO,EAAI,CAC3B,GAAI,IAAS,IAAA,GACX,OAAO,EAAW,MAAM,mBAAmB,CAAC,CAE9C,EAAQ,EAAK,EACb,EACF,CAKC,OAAO,UAAU,aACpB,OAAO,UAAU,WAAa,SAAU,EAAyB,CAC/D,OAAO,KAAK,UAAU,EAAG,EAAO,OAAO,GAAK,IAWhD,MAAa,GACX,EACA,EACA,IACuC,CACvC,GAAI,OAAO,GAAY,WAAY,CACjC,EAAQ,EAAK,IAAA,GAAW,EAAQ,CAChC,OAGF,GAAI,OAAO,GAAa,WAAY,CAClC,EAAQ,EAAK,EAAS,EAAS,CAC/B,OAGF,OAAO,EAAK,EAAS,EAAK,EAAQ"}
@@ -1 +1 @@
1
- {"version":3,"file":"ps.mjs","names":[],"sources":["../../../../src/utils/runParallel/ps.ts"],"sourcesContent":["import * as os from 'node:os';\nimport { run } from './bin';\n\ntype ProcessList = [number, number][]; // [PPID, PID][]\ntype ProcessListCallback = (err: Error | null, list?: ProcessList) => void;\n\n/**\n * Gets the list of all the pids of the system through the ps command.\n * @param callback Callback function with error and process list.\n */\nexport const ps = (callback: ProcessListCallback): void => {\n const args = ['-A', '-o', 'ppid,pid'];\n\n run('ps', args, (err, stdout, code) => {\n if (err) {\n callback(err);\n return;\n }\n if (code !== 0) {\n callback(new Error(`pidtree ps command exited with code ${code}`));\n return;\n }\n\n // Example of stdout\n //\n // PPID PID\n // 1 430\n // 430 432\n // 1 727\n // 1 7166\n\n if (!stdout) {\n callback(new Error('No stdout received from ps command'));\n return;\n }\n\n try {\n const lines = stdout.split(os.EOL);\n\n const list: ProcessList = [];\n for (let i = 1; i < lines.length; i++) {\n const trimmed = lines[i].trim();\n if (!trimmed) continue;\n const parts = trimmed.split(/\\s+/);\n const ppid = parseInt(parts[0], 10); // PPID\n const pid = parseInt(parts[1], 10); // PID\n if (!Number.isNaN(ppid) && !Number.isNaN(pid)) {\n list.push([ppid, pid]);\n }\n }\n\n callback(null, list);\n } catch (error) {\n callback(error instanceof Error ? error : new Error(String(error)));\n }\n });\n};\n"],"mappings":"0DAUA,MAAa,EAAM,GAAwC,CAGzD,EAAI,KAFS,CAAC,KAAM,KAAM,WAAW,EAEpB,EAAK,EAAQ,IAAS,CACrC,GAAI,EAAK,CACP,EAAS,EAAI,CACb,OAEF,GAAI,IAAS,EAAG,CACd,EAAa,MAAM,uCAAuC,IAAO,CAAC,CAClE,OAWF,GAAI,CAAC,EAAQ,CACX,EAAa,MAAM,qCAAqC,CAAC,CACzD,OAGF,GAAI,CACF,IAAM,EAAQ,EAAO,MAAM,EAAG,IAAI,CAE5B,EAAoB,EAAE,CAC5B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAAK,CACrC,IAAM,EAAU,EAAM,GAAG,MAAM,CAC/B,GAAI,CAAC,EAAS,SACd,IAAM,EAAQ,EAAQ,MAAM,MAAM,CAC5B,EAAO,SAAS,EAAM,GAAI,GAAG,CAC7B,EAAM,SAAS,EAAM,GAAI,GAAG,CAC9B,CAAC,OAAO,MAAM,EAAK,EAAI,CAAC,OAAO,MAAM,EAAI,EAC3C,EAAK,KAAK,CAAC,EAAM,EAAI,CAAC,CAI1B,EAAS,KAAM,EAAK,OACb,EAAO,CACd,EAAS,aAAiB,MAAQ,EAAY,MAAM,OAAO,EAAM,CAAC,CAAC,GAErE"}
1
+ {"version":3,"file":"ps.mjs","names":["os"],"sources":["../../../../src/utils/runParallel/ps.ts"],"sourcesContent":["import * as os from 'node:os';\nimport { run } from './bin';\n\ntype ProcessList = [number, number][]; // [PPID, PID][]\ntype ProcessListCallback = (err: Error | null, list?: ProcessList) => void;\n\n/**\n * Gets the list of all the pids of the system through the ps command.\n * @param callback Callback function with error and process list.\n */\nexport const ps = (callback: ProcessListCallback): void => {\n const args = ['-A', '-o', 'ppid,pid'];\n\n run('ps', args, (err, stdout, code) => {\n if (err) {\n callback(err);\n return;\n }\n if (code !== 0) {\n callback(new Error(`pidtree ps command exited with code ${code}`));\n return;\n }\n\n // Example of stdout\n //\n // PPID PID\n // 1 430\n // 430 432\n // 1 727\n // 1 7166\n\n if (!stdout) {\n callback(new Error('No stdout received from ps command'));\n return;\n }\n\n try {\n const lines = stdout.split(os.EOL);\n\n const list: ProcessList = [];\n for (let i = 1; i < lines.length; i++) {\n const trimmed = lines[i].trim();\n if (!trimmed) continue;\n const parts = trimmed.split(/\\s+/);\n const ppid = parseInt(parts[0], 10); // PPID\n const pid = parseInt(parts[1], 10); // PID\n if (!Number.isNaN(ppid) && !Number.isNaN(pid)) {\n list.push([ppid, pid]);\n }\n }\n\n callback(null, list);\n } catch (error) {\n callback(error instanceof Error ? error : new Error(String(error)));\n }\n });\n};\n"],"mappings":"0DAUA,MAAa,EAAM,GAAwC,CAGzD,EAAI,KAFS,CAAC,KAAM,KAAM,WAAW,EAEpB,EAAK,EAAQ,IAAS,CACrC,GAAI,EAAK,CACP,EAAS,EAAI,CACb,OAEF,GAAI,IAAS,EAAG,CACd,EAAa,MAAM,uCAAuC,IAAO,CAAC,CAClE,OAWF,GAAI,CAAC,EAAQ,CACX,EAAa,MAAM,qCAAqC,CAAC,CACzD,OAGF,GAAI,CACF,IAAM,EAAQ,EAAO,MAAMA,EAAG,IAAI,CAE5B,EAAoB,EAAE,CAC5B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAAK,CACrC,IAAM,EAAU,EAAM,GAAG,MAAM,CAC/B,GAAI,CAAC,EAAS,SACd,IAAM,EAAQ,EAAQ,MAAM,MAAM,CAC5B,EAAO,SAAS,EAAM,GAAI,GAAG,CAC7B,EAAM,SAAS,EAAM,GAAI,GAAG,CAC9B,CAAC,OAAO,MAAM,EAAK,EAAI,CAAC,OAAO,MAAM,EAAI,EAC3C,EAAK,KAAK,CAAC,EAAM,EAAI,CAAC,CAI1B,EAAS,KAAM,EAAK,OACb,EAAO,CACd,EAAS,aAAiB,MAAQ,EAAY,MAAM,OAAO,EAAM,CAAC,CAAC,GAErE"}
@@ -1 +1 @@
1
- {"version":3,"file":"wmic.mjs","names":[],"sources":["../../../../src/utils/runParallel/wmic.ts"],"sourcesContent":["import type { SpawnOptions } from 'node:child_process';\nimport * as os from 'node:os';\nimport { run } from './bin';\n\ntype ProcessList = [number, number][]; // [PPID, PID][]\ntype ProcessListCallback = (err: Error | null, list?: ProcessList) => void;\n\n/**\n * Gets the list of all the pids of the system through the wmic command.\n * @param callback Callback function with error and process list.\n */\nexport const wmic = (callback: ProcessListCallback): void => {\n const args = ['PROCESS', 'get', 'ParentProcessId,ProcessId'];\n const options: SpawnOptions = {\n windowsHide: true,\n windowsVerbatimArguments: true,\n };\n run('wmic', args, options, (err, stdout, code) => {\n if (err) {\n callback(err);\n return;\n }\n\n if (code !== 0) {\n callback(new Error(`pidtree wmic command exited with code ${code}`));\n return;\n }\n\n // Example of stdout\n //\n // ParentProcessId ProcessId\n // 0 777\n\n if (!stdout) {\n callback(new Error('No stdout received from wmic command'));\n return;\n }\n\n try {\n const lines = stdout.split(os.EOL);\n\n const list: ProcessList = [];\n for (let i = 1; i < lines.length; i++) {\n const trimmed = lines[i].trim();\n if (!trimmed) continue;\n const parts = trimmed.split(/\\s+/);\n const ppid = parseInt(parts[0], 10); // PPID\n const pid = parseInt(parts[1], 10); // PID\n if (!Number.isNaN(ppid) && !Number.isNaN(pid)) {\n list.push([ppid, pid]);\n }\n }\n\n callback(null, list);\n } catch (error) {\n callback(error instanceof Error ? error : new Error(String(error)));\n }\n });\n};\n"],"mappings":"0DAWA,MAAa,EAAQ,GAAwC,CAM3D,EAAI,OALS,CAAC,UAAW,MAAO,4BAA4B,CAC9B,CAC5B,YAAa,GACb,yBAA0B,GAC3B,EAC2B,EAAK,EAAQ,IAAS,CAChD,GAAI,EAAK,CACP,EAAS,EAAI,CACb,OAGF,GAAI,IAAS,EAAG,CACd,EAAa,MAAM,yCAAyC,IAAO,CAAC,CACpE,OAQF,GAAI,CAAC,EAAQ,CACX,EAAa,MAAM,uCAAuC,CAAC,CAC3D,OAGF,GAAI,CACF,IAAM,EAAQ,EAAO,MAAM,EAAG,IAAI,CAE5B,EAAoB,EAAE,CAC5B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAAK,CACrC,IAAM,EAAU,EAAM,GAAG,MAAM,CAC/B,GAAI,CAAC,EAAS,SACd,IAAM,EAAQ,EAAQ,MAAM,MAAM,CAC5B,EAAO,SAAS,EAAM,GAAI,GAAG,CAC7B,EAAM,SAAS,EAAM,GAAI,GAAG,CAC9B,CAAC,OAAO,MAAM,EAAK,EAAI,CAAC,OAAO,MAAM,EAAI,EAC3C,EAAK,KAAK,CAAC,EAAM,EAAI,CAAC,CAI1B,EAAS,KAAM,EAAK,OACb,EAAO,CACd,EAAS,aAAiB,MAAQ,EAAY,MAAM,OAAO,EAAM,CAAC,CAAC,GAErE"}
1
+ {"version":3,"file":"wmic.mjs","names":["os"],"sources":["../../../../src/utils/runParallel/wmic.ts"],"sourcesContent":["import type { SpawnOptions } from 'node:child_process';\nimport * as os from 'node:os';\nimport { run } from './bin';\n\ntype ProcessList = [number, number][]; // [PPID, PID][]\ntype ProcessListCallback = (err: Error | null, list?: ProcessList) => void;\n\n/**\n * Gets the list of all the pids of the system through the wmic command.\n * @param callback Callback function with error and process list.\n */\nexport const wmic = (callback: ProcessListCallback): void => {\n const args = ['PROCESS', 'get', 'ParentProcessId,ProcessId'];\n const options: SpawnOptions = {\n windowsHide: true,\n windowsVerbatimArguments: true,\n };\n run('wmic', args, options, (err, stdout, code) => {\n if (err) {\n callback(err);\n return;\n }\n\n if (code !== 0) {\n callback(new Error(`pidtree wmic command exited with code ${code}`));\n return;\n }\n\n // Example of stdout\n //\n // ParentProcessId ProcessId\n // 0 777\n\n if (!stdout) {\n callback(new Error('No stdout received from wmic command'));\n return;\n }\n\n try {\n const lines = stdout.split(os.EOL);\n\n const list: ProcessList = [];\n for (let i = 1; i < lines.length; i++) {\n const trimmed = lines[i].trim();\n if (!trimmed) continue;\n const parts = trimmed.split(/\\s+/);\n const ppid = parseInt(parts[0], 10); // PPID\n const pid = parseInt(parts[1], 10); // PID\n if (!Number.isNaN(ppid) && !Number.isNaN(pid)) {\n list.push([ppid, pid]);\n }\n }\n\n callback(null, list);\n } catch (error) {\n callback(error instanceof Error ? error : new Error(String(error)));\n }\n });\n};\n"],"mappings":"0DAWA,MAAa,EAAQ,GAAwC,CAM3D,EAAI,OALS,CAAC,UAAW,MAAO,4BAA4B,CAC9B,CAC5B,YAAa,GACb,yBAA0B,GAC3B,EAC2B,EAAK,EAAQ,IAAS,CAChD,GAAI,EAAK,CACP,EAAS,EAAI,CACb,OAGF,GAAI,IAAS,EAAG,CACd,EAAa,MAAM,yCAAyC,IAAO,CAAC,CACpE,OAQF,GAAI,CAAC,EAAQ,CACX,EAAa,MAAM,uCAAuC,CAAC,CAC3D,OAGF,GAAI,CACF,IAAM,EAAQ,EAAO,MAAMA,EAAG,IAAI,CAE5B,EAAoB,EAAE,CAC5B,IAAK,IAAI,EAAI,EAAG,EAAI,EAAM,OAAQ,IAAK,CACrC,IAAM,EAAU,EAAM,GAAG,MAAM,CAC/B,GAAI,CAAC,EAAS,SACd,IAAM,EAAQ,EAAQ,MAAM,MAAM,CAC5B,EAAO,SAAS,EAAM,GAAI,GAAG,CAC7B,EAAM,SAAS,EAAM,GAAI,GAAG,CAC9B,CAAC,OAAO,MAAM,EAAK,EAAI,CAAC,OAAO,MAAM,EAAI,EAC3C,EAAK,KAAK,CAAC,EAAM,EAAI,CAAC,CAI1B,EAAS,KAAM,EAAK,OACb,EAAO,CACd,EAAS,aAAiB,MAAQ,EAAY,MAAM,OAAO,EAAM,CAAC,CAAC,GAErE"}
@@ -1,2 +1,2 @@
1
- import{prepareIntlayer as e}from"./prepareIntlayer.mjs";import{writeContentDeclaration as t}from"./writeContentDeclaration/writeContentDeclaration.mjs";import{handleAdditionalContentDeclarationFile as n}from"./handleAdditionalContentDeclarationFile.mjs";import{handleContentDeclarationFileChange as r}from"./handleContentDeclarationFileChange.mjs";import{handleContentDeclarationFileMoved as i}from"./handleContentDeclarationFileMoved.mjs";import{handleUnlinkedContentDeclarationFile as a}from"./handleUnlinkedContentDeclarationFile.mjs";import{getConfiguration as o,getConfigurationAndFilePath as s}from"@intlayer/config/node";import{readFile as c}from"node:fs/promises";import{basename as l}from"node:path";import{getAppLogger as u}from"@intlayer/config/logger";import{clearAllCache as d,clearModuleCache as f}from"@intlayer/config/utils";import{watch as p}from"chokidar";const m=new Map;let h=Promise.resolve();const g=e=>{h=h.then(async()=>{try{await e()}catch(e){console.error(e)}})},_=o=>{let h=s(o?.configOptions),_=h.configurationFilePath,v=o?.configuration??h.configuration,y=u(v),{watch:b,watchedFilesPatternWithPath:x,fileExtensions:S}=v.content;return p([...Array.isArray(x)?x:[x],..._?[_]:[]],{persistent:b,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:1e3,pollInterval:100},ignored:[`**/node_modules/**`,`**/dist/**`,`**/build/**`,`**/.intlayer/**`],...o}).on(`add`,async e=>{let r=l(e),a=!1,o;for(let[e]of m)if(l(e)===r){o=e;break}if(!o&&m.size===1&&(o=m.keys().next().value),o){let t=m.get(o);t&&(clearTimeout(t.timer),m.delete(o)),a=!0,y(`File moved from ${o} to ${e}`)}g(async()=>{if(a&&o)await i(o,e,v);else{if(await c(e,`utf-8`)===``){let n=S.map(e=>e.replace(/\./g,`\\.`)).join(`|`);await t({key:r.replace(RegExp(`(${n})$`),``),content:{},filePath:e},v)}await n(e,v)}})}).on(`change`,async t=>g(async()=>{if(_&&t===_){y(`Configuration file changed, repreparing Intlayer`),f(_),d();let{configuration:t}=s(o?.configOptions);v=o?.configuration??t,await e(v,{clean:!1})}else await r(t,v)})).on(`unlink`,async e=>{let t=setTimeout(async()=>{m.delete(e),g(async()=>a(e,v))},200);m.set(e,{timer:t,oldPath:e})}).on(`error`,async t=>{y(`Watcher error: ${t}`,{level:`error`}),y(`Restarting watcher`),await e(v)})},v=async t=>{let{skipPrepare:n,...r}=t??{},i=t?.configuration??o(t?.configOptions);n||await e(i,{forceRun:!0}),(i.content.watch||t?.persistent)&&(u(i)(`Watching Intlayer content declarations`),_({...r,configuration:i}))};export{v as buildAndWatchIntlayer,_ as watch};
1
+ import{prepareIntlayer as e}from"./prepareIntlayer.mjs";import{writeContentDeclaration as t}from"./writeContentDeclaration/writeContentDeclaration.mjs";import{handleAdditionalContentDeclarationFile as n}from"./handleAdditionalContentDeclarationFile.mjs";import{handleContentDeclarationFileChange as r}from"./handleContentDeclarationFileChange.mjs";import{handleContentDeclarationFileMoved as i}from"./handleContentDeclarationFileMoved.mjs";import{handleUnlinkedContentDeclarationFile as a}from"./handleUnlinkedContentDeclarationFile.mjs";import{getConfiguration as o,getConfigurationAndFilePath as s}from"@intlayer/config/node";import{readFile as c}from"node:fs/promises";import{basename as l}from"node:path";import{getAppLogger as u}from"@intlayer/config/logger";import{clearAllCache as d,clearModuleCache as f}from"@intlayer/config/utils";import{watch as p}from"chokidar";const m=new Map;let h=Promise.resolve();const g=e=>{h=h.then(async()=>{try{await e()}catch(e){console.error(e)}})},_=o=>{let h=s(o?.configOptions),_=h.configurationFilePath,v=o?.configuration??h.configuration,y=u(v),{watch:b,watchedFilesPatternWithPath:x,fileExtensions:S}=v.content,C=[...Array.isArray(x)?x:[x],..._?[_]:[]];if(v.content.watch)return y(`Watching Intlayer content declarations`),p(C,{persistent:b,ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:1e3,pollInterval:100},ignored:[`**/node_modules/**`,`**/dist/**`,`**/build/**`,`**/.intlayer/**`],...o}).on(`add`,async e=>{let r=l(e),a=!1,o;for(let[e]of m)if(l(e)===r){o=e;break}if(!o&&m.size===1&&(o=m.keys().next().value),o){let t=m.get(o);t&&(clearTimeout(t.timer),m.delete(o)),a=!0,y(`File moved from ${o} to ${e}`)}g(async()=>{if(a&&o)await i(o,e,v);else{if(await c(e,`utf-8`)===``){let n=S.map(e=>e.replace(/\./g,`\\.`)).join(`|`);await t({key:r.replace(RegExp(`(${n})$`),``),content:{},filePath:e},v)}await n(e,v)}})}).on(`change`,async t=>g(async()=>{if(_&&t===_){y(`Configuration file changed, repreparing Intlayer`),f(_),d();let{configuration:t}=s(o?.configOptions);v=o?.configuration??t,await e(v,{clean:!1})}else await r(t,v)})).on(`unlink`,async e=>{let t=setTimeout(async()=>{m.delete(e),g(async()=>a(e,v))},200);m.set(e,{timer:t,oldPath:e})}).on(`error`,async t=>{y(`Watcher error: ${t}`,{level:`error`}),y(`Restarting watcher`),await e(v)})},v=async t=>{let{skipPrepare:n,...r}=t??{},i=t?.configuration??o(t?.configOptions);n||await e(i,{forceRun:!0}),(i.content.watch||t?.persistent)&&_({...r,configuration:i})};export{v as buildAndWatchIntlayer,_ as watch};
2
2
  //# sourceMappingURL=watcher.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"watcher.mjs","names":["chokidarWatch"],"sources":["../../src/watcher.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { basename } from 'node:path';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n getConfigurationAndFilePath,\n} from '@intlayer/config/node';\nimport { clearAllCache, clearModuleCache } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport { handleAdditionalContentDeclarationFile } from './handleAdditionalContentDeclarationFile';\nimport { handleContentDeclarationFileChange } from './handleContentDeclarationFileChange';\nimport { handleContentDeclarationFileMoved } from './handleContentDeclarationFileMoved';\nimport { handleUnlinkedContentDeclarationFile } from './handleUnlinkedContentDeclarationFile';\nimport { prepareIntlayer } from './prepareIntlayer';\nimport { writeContentDeclaration } from './writeContentDeclaration';\n\n// Map to track files that were recently unlinked: oldPath -> { timer, timestamp }\nconst pendingUnlinks = new Map<\n string,\n { timer: NodeJS.Timeout; oldPath: string }\n>();\n\n// Task queue to ensure sequential processing of file events\nlet processingQueue = Promise.resolve();\nconst processEvent = (task: () => Promise<void>) => {\n processingQueue = processingQueue.then(async () => {\n try {\n await task();\n } catch (error) {\n console.error(error);\n }\n });\n};\n\ntype WatchOptions = ChokidarOptions & {\n configuration?: IntlayerConfig;\n configOptions?: GetConfigurationOptions;\n skipPrepare?: boolean;\n};\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const configResult = getConfigurationAndFilePath(options?.configOptions);\n const configurationFilePath = configResult.configurationFilePath;\n let configuration: IntlayerConfig =\n options?.configuration ?? configResult.configuration;\n const appLogger = getAppLogger(configuration);\n\n const {\n watch: isWatchMode,\n watchedFilesPatternWithPath,\n fileExtensions,\n } = configuration.content;\n\n const pathsToWatch = [\n ...(Array.isArray(watchedFilesPatternWithPath)\n ? watchedFilesPatternWithPath\n : [watchedFilesPatternWithPath]),\n ...(configurationFilePath ? [configurationFilePath] : []),\n ];\n\n return chokidarWatch(pathsToWatch, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n awaitWriteFinish: {\n stabilityThreshold: 1000,\n pollInterval: 100,\n },\n ignored: [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/.intlayer/**',\n ],\n ...options,\n })\n .on('add', async (filePath) => {\n const fileName = basename(filePath);\n let isMove = false;\n\n // Check if this Add corresponds to a pending Unlink (Move/Rename detection)\n // Heuristic:\n // - Priority A: Exact basename match (Moved to different folder)\n // - Priority B: Single entry in pendingUnlinks (Renamed file)\n let matchedOldPath: string | undefined;\n\n // Search for basename match\n for (const [oldPath] of pendingUnlinks) {\n if (basename(oldPath) === fileName) {\n matchedOldPath = oldPath;\n break;\n }\n }\n\n // If no basename match, but exactly one file was recently unlinked, assume it's a rename\n if (!matchedOldPath && pendingUnlinks.size === 1) {\n matchedOldPath = pendingUnlinks.keys().next().value;\n }\n\n if (matchedOldPath) {\n // It is a move! Cancel the unlink handler\n const pending = pendingUnlinks.get(matchedOldPath);\n if (pending) {\n clearTimeout(pending.timer);\n pendingUnlinks.delete(matchedOldPath);\n }\n\n isMove = true;\n appLogger(`File moved from ${matchedOldPath} to ${filePath}`);\n }\n\n processEvent(async () => {\n if (isMove && matchedOldPath) {\n await handleContentDeclarationFileMoved(\n matchedOldPath,\n filePath,\n configuration\n );\n } else {\n const fileContent = await readFile(filePath, 'utf-8');\n const isEmpty = fileContent === '';\n\n // Fill template content declaration file if it is empty\n if (isEmpty) {\n const extensionPattern = fileExtensions\n .map((ext) => ext.replace(/\\./g, '\\\\.'))\n .join('|');\n const name = fileName.replace(\n new RegExp(`(${extensionPattern})$`),\n ''\n );\n\n await writeContentDeclaration(\n {\n key: name,\n content: {},\n filePath,\n },\n configuration\n );\n }\n\n await handleAdditionalContentDeclarationFile(filePath, configuration);\n }\n });\n })\n .on('change', async (filePath) =>\n processEvent(async () => {\n if (configurationFilePath && filePath === configurationFilePath) {\n appLogger('Configuration file changed, repreparing Intlayer');\n\n clearModuleCache(configurationFilePath);\n clearAllCache();\n\n const { configuration: newConfiguration } =\n getConfigurationAndFilePath(options?.configOptions);\n\n configuration = options?.configuration ?? newConfiguration;\n\n await prepareIntlayer(configuration, { clean: false });\n } else {\n await handleContentDeclarationFileChange(filePath, configuration);\n }\n })\n )\n .on('unlink', async (filePath) => {\n // Delay unlink processing to see if an 'add' event occurs (indicating a move)\n const timer = setTimeout(async () => {\n // If timer fires, the file was genuinely removed\n pendingUnlinks.delete(filePath);\n processEvent(async () =>\n handleUnlinkedContentDeclarationFile(filePath, configuration)\n );\n }, 200); // 200ms window to catch the 'add' event\n\n pendingUnlinks.set(filePath, { timer, oldPath: filePath });\n })\n .on('error', async (error) => {\n appLogger(`Watcher error: ${error}`, {\n level: 'error',\n });\n\n appLogger('Restarting watcher');\n\n await prepareIntlayer(configuration);\n });\n};\n\nexport const buildAndWatchIntlayer = async (options?: WatchOptions) => {\n const { skipPrepare, ...rest } = options ?? {};\n const configuration =\n options?.configuration ?? getConfiguration(options?.configOptions);\n\n if (!skipPrepare) {\n await prepareIntlayer(configuration, { forceRun: true });\n }\n\n if (configuration.content.watch || options?.persistent) {\n const appLogger = getAppLogger(configuration);\n\n appLogger('Watching Intlayer content declarations');\n watch({ ...rest, configuration });\n }\n};\n"],"mappings":"02BAoBA,MAAM,EAAiB,IAAI,IAM3B,IAAI,EAAkB,QAAQ,SAAS,CACvC,MAAM,EAAgB,GAA8B,CAClD,EAAkB,EAAgB,KAAK,SAAY,CACjD,GAAI,CACF,MAAM,GAAM,OACL,EAAO,CACd,QAAQ,MAAM,EAAM,GAEtB,EAUS,EAAS,GAA2B,CAC/C,IAAM,EAAe,EAA4B,GAAS,cAAc,CAClE,EAAwB,EAAa,sBACvC,EACF,GAAS,eAAiB,EAAa,cACnC,EAAY,EAAa,EAAc,CAEvC,CACJ,MAAO,EACP,8BACA,kBACE,EAAc,QASlB,OAAOA,EAPc,CACnB,GAAI,MAAM,QAAQ,EAA4B,CAC1C,EACA,CAAC,EAA4B,CACjC,GAAI,EAA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AAc,EAEnE,CACH,CACA,GAAG,SAAU,KAAO,IAAa,CAEhC,IAAM,EAAQ,WAAW,SAAY,CAEnC,EAAe,OAAO,EAAS,CAC/B,EAAa,SACX,EAAqC,EAAU,EAAc,CAC9D,EACA,IAAI,CAEP,EAAe,IAAI,EAAU,CAAE,QAAO,QAAS,EAAU,CAAC,EAC1D,CACD,GAAG,QAAS,KAAO,IAAU,CAC5B,EAAU,kBAAkB,IAAS,CACnC,MAAO,QACR,CAAC,CAEF,EAAU,qBAAqB,CAE/B,MAAM,EAAgB,EAAc,EACpC,EAGO,EAAwB,KAAO,IAA2B,CACrE,GAAM,CAAE,cAAa,GAAG,GAAS,GAAW,EAAE,CACxC,EACJ,GAAS,eAAiB,EAAiB,GAAS,cAAc,CAE/D,GACH,MAAM,EAAgB,EAAe,CAAE,SAAU,GAAM,CAAC,EAGtD,EAAc,QAAQ,OAAS,GAAS,cACxB,EAAa,EAAc,CAEnC,yCAAyC,CACnD,EAAM,CAAE,GAAG,EAAM,gBAAe,CAAC"}
1
+ {"version":3,"file":"watcher.mjs","names":["chokidarWatch"],"sources":["../../src/watcher.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { basename } from 'node:path';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n getConfigurationAndFilePath,\n} from '@intlayer/config/node';\nimport { clearAllCache, clearModuleCache } from '@intlayer/config/utils';\nimport type { IntlayerConfig } from '@intlayer/types';\n/** @ts-ignore remove error Module '\"chokidar\"' has no exported member 'ChokidarOptions' */\nimport { type ChokidarOptions, watch as chokidarWatch } from 'chokidar';\nimport { handleAdditionalContentDeclarationFile } from './handleAdditionalContentDeclarationFile';\nimport { handleContentDeclarationFileChange } from './handleContentDeclarationFileChange';\nimport { handleContentDeclarationFileMoved } from './handleContentDeclarationFileMoved';\nimport { handleUnlinkedContentDeclarationFile } from './handleUnlinkedContentDeclarationFile';\nimport { prepareIntlayer } from './prepareIntlayer';\nimport { writeContentDeclaration } from './writeContentDeclaration';\n\n// Map to track files that were recently unlinked: oldPath -> { timer, timestamp }\nconst pendingUnlinks = new Map<\n string,\n { timer: NodeJS.Timeout; oldPath: string }\n>();\n\n// Task queue to ensure sequential processing of file events\nlet processingQueue = Promise.resolve();\nconst processEvent = (task: () => Promise<void>) => {\n processingQueue = processingQueue.then(async () => {\n try {\n await task();\n } catch (error) {\n console.error(error);\n }\n });\n};\n\ntype WatchOptions = ChokidarOptions & {\n configuration?: IntlayerConfig;\n configOptions?: GetConfigurationOptions;\n skipPrepare?: boolean;\n};\n\n// Initialize chokidar watcher (non-persistent)\nexport const watch = (options?: WatchOptions) => {\n const configResult = getConfigurationAndFilePath(options?.configOptions);\n const configurationFilePath = configResult.configurationFilePath;\n let configuration: IntlayerConfig =\n options?.configuration ?? configResult.configuration;\n const appLogger = getAppLogger(configuration);\n\n const {\n watch: isWatchMode,\n watchedFilesPatternWithPath,\n fileExtensions,\n } = configuration.content;\n\n const pathsToWatch = [\n ...(Array.isArray(watchedFilesPatternWithPath)\n ? watchedFilesPatternWithPath\n : [watchedFilesPatternWithPath]),\n ...(configurationFilePath ? [configurationFilePath] : []),\n ];\n\n if (!configuration.content.watch) return;\n\n appLogger('Watching Intlayer content declarations');\n\n return chokidarWatch(pathsToWatch, {\n persistent: isWatchMode, // Make the watcher persistent\n ignoreInitial: true, // Process existing files\n awaitWriteFinish: {\n stabilityThreshold: 1000,\n pollInterval: 100,\n },\n ignored: [\n '**/node_modules/**',\n '**/dist/**',\n '**/build/**',\n '**/.intlayer/**',\n ],\n ...options,\n })\n .on('add', async (filePath) => {\n const fileName = basename(filePath);\n let isMove = false;\n\n // Check if this Add corresponds to a pending Unlink (Move/Rename detection)\n // Heuristic:\n // - Priority A: Exact basename match (Moved to different folder)\n // - Priority B: Single entry in pendingUnlinks (Renamed file)\n let matchedOldPath: string | undefined;\n\n // Search for basename match\n for (const [oldPath] of pendingUnlinks) {\n if (basename(oldPath) === fileName) {\n matchedOldPath = oldPath;\n break;\n }\n }\n\n // If no basename match, but exactly one file was recently unlinked, assume it's a rename\n if (!matchedOldPath && pendingUnlinks.size === 1) {\n matchedOldPath = pendingUnlinks.keys().next().value;\n }\n\n if (matchedOldPath) {\n // It is a move! Cancel the unlink handler\n const pending = pendingUnlinks.get(matchedOldPath);\n if (pending) {\n clearTimeout(pending.timer);\n pendingUnlinks.delete(matchedOldPath);\n }\n\n isMove = true;\n appLogger(`File moved from ${matchedOldPath} to ${filePath}`);\n }\n\n processEvent(async () => {\n if (isMove && matchedOldPath) {\n await handleContentDeclarationFileMoved(\n matchedOldPath,\n filePath,\n configuration\n );\n } else {\n const fileContent = await readFile(filePath, 'utf-8');\n const isEmpty = fileContent === '';\n\n // Fill template content declaration file if it is empty\n if (isEmpty) {\n const extensionPattern = fileExtensions\n .map((ext) => ext.replace(/\\./g, '\\\\.'))\n .join('|');\n const name = fileName.replace(\n new RegExp(`(${extensionPattern})$`),\n ''\n );\n\n await writeContentDeclaration(\n {\n key: name,\n content: {},\n filePath,\n },\n configuration\n );\n }\n\n await handleAdditionalContentDeclarationFile(filePath, configuration);\n }\n });\n })\n .on('change', async (filePath) =>\n processEvent(async () => {\n if (configurationFilePath && filePath === configurationFilePath) {\n appLogger('Configuration file changed, repreparing Intlayer');\n\n clearModuleCache(configurationFilePath);\n clearAllCache();\n\n const { configuration: newConfiguration } =\n getConfigurationAndFilePath(options?.configOptions);\n\n configuration = options?.configuration ?? newConfiguration;\n\n await prepareIntlayer(configuration, { clean: false });\n } else {\n await handleContentDeclarationFileChange(filePath, configuration);\n }\n })\n )\n .on('unlink', async (filePath) => {\n // Delay unlink processing to see if an 'add' event occurs (indicating a move)\n const timer = setTimeout(async () => {\n // If timer fires, the file was genuinely removed\n pendingUnlinks.delete(filePath);\n processEvent(async () =>\n handleUnlinkedContentDeclarationFile(filePath, configuration)\n );\n }, 200); // 200ms window to catch the 'add' event\n\n pendingUnlinks.set(filePath, { timer, oldPath: filePath });\n })\n .on('error', async (error) => {\n appLogger(`Watcher error: ${error}`, {\n level: 'error',\n });\n\n appLogger('Restarting watcher');\n\n await prepareIntlayer(configuration);\n });\n};\n\nexport const buildAndWatchIntlayer = async (options?: WatchOptions) => {\n const { skipPrepare, ...rest } = options ?? {};\n const configuration =\n options?.configuration ?? getConfiguration(options?.configOptions);\n\n if (!skipPrepare) {\n await prepareIntlayer(configuration, { forceRun: true });\n }\n\n if (configuration.content.watch || options?.persistent) {\n watch({ ...rest, configuration });\n }\n};\n"],"mappings":"02BAoBA,MAAM,EAAiB,IAAI,IAM3B,IAAI,EAAkB,QAAQ,SAAS,CACvC,MAAM,EAAgB,GAA8B,CAClD,EAAkB,EAAgB,KAAK,SAAY,CACjD,GAAI,CACF,MAAM,GAAM,OACL,EAAO,CACd,QAAQ,MAAM,EAAM,GAEtB,EAUS,EAAS,GAA2B,CAC/C,IAAM,EAAe,EAA4B,GAAS,cAAc,CAClE,EAAwB,EAAa,sBACvC,EACF,GAAS,eAAiB,EAAa,cACnC,EAAY,EAAa,EAAc,CAEvC,CACJ,MAAO,EACP,8BACA,kBACE,EAAc,QAEZ,EAAe,CACnB,GAAI,MAAM,QAAQ,EAA4B,CAC1C,EACA,CAAC,EAA4B,CACjC,GAAI,EAAwB,CAAC,EAAsB,CAAG,EAAE,CACzD,CAEI,KAAc,QAAQ,MAI3B,OAFA,EAAU,yCAAyC,CAE5CA,EAAc,EAAc,CACjC,WAAY,EACZ,cAAe,GACf,iBAAkB,CAChB,mBAAoB,IACpB,aAAc,IACf,CACD,QAAS,CACP,qBACA,aACA,cACA,kBACD,CACD,GAAG,EACJ,CAAC,CACC,GAAG,MAAO,KAAO,IAAa,CAC7B,IAAM,EAAW,EAAS,EAAS,CAC/B,EAAS,GAMT,EAGJ,IAAK,GAAM,CAAC,KAAY,EACtB,GAAI,EAAS,EAAQ,GAAK,EAAU,CAClC,EAAiB,EACjB,MASJ,GAJI,CAAC,GAAkB,EAAe,OAAS,IAC7C,EAAiB,EAAe,MAAM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a,GAAG,GAAS,GAAW,EAAE,CACxC,EACJ,GAAS,eAAiB,EAAiB,GAAS,cAAc,CAE/D,GACH,MAAM,EAAgB,EAAe,CAAE,SAAU,GAAM,CAAC,EAGtD,EAAc,QAAQ,OAAS,GAAS,aAC1C,EAAM,CAAE,GAAG,EAAM,gBAAe,CAAC"}
@@ -1,3 +1,2 @@
1
- import{getNodeType as e}from"@intlayer/core/dictionaryManipulator";import{NodeType as t}from"@intlayer/types";import{IndentationText as n,NewLineKind as r,Node as i,Project as a,QuoteKind as o,SyntaxKind as s,ts as c}from"ts-morph";const l=(e,t)=>{let n=Object.entries(e).sort(([e],[t])=>e.localeCompare(t)),r=[];for(let[e,t]of n){let n=/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)?e:JSON.stringify(e);if(typeof t==`string`)r.push(`${n}: ${JSON.stringify(t)}`);else if(Array.isArray(t)){let e=t.map(e=>JSON.stringify(e)).join(`, `);r.push(`${n}: [ ${e} ]`)}else r.push(`${n}: ${JSON.stringify(t)}`)}return`t${t??``}({ ${r.join(`, `)} })`},u=(e,t,n)=>{let r={...e,[t]:n},i=n.match(/\d+(?!.*\d)/);if(!i)return r;let a=i[0];for(let[n,i]of Object.entries(e))n!==t&&i.match(/\d+(?!.*\d)/)&&(r[n]=i.replace(/(\d+)(?!.*\d)/,a));return r},d=e=>!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)||e===`true`||e===`false`?JSON.stringify(e):e,f=e=>{let t=[];for(let[n,r]of Object.entries(e)){if(typeof r!=`string`)return``;t.push(`${d(n)}: ${JSON.stringify(r)}`)}return`enu({ ${t.join(`, `)} })`},p=e=>{let t=[];for(let[n,r]of Object.entries(e)){if(typeof r!=`string`)return``;t.push(`${d(n)}: ${JSON.stringify(r)}`)}return`cond({ ${t.join(`, `)} })`},m=e=>{let t=[];for(let[n,r]of Object.entries(e)){if(typeof r!=`string`)return``;t.push(`${d(n)}: ${JSON.stringify(r)}`)}return`gender({ ${t.join(`, `)} })`},h=n=>{if(typeof n==`string`)return`insert(${JSON.stringify(n)})`;if(e(n)===t.Translation){let e=n[t.Translation]??{};return Object.values(e).every(e=>typeof e==`string`)?`insert(${l(e)})`:void 0}},g=e=>{if(typeof e==`string`)return`file(${JSON.stringify(e)})`},_=n=>{if(typeof n==`string`)return`html(${JSON.stringify(n)})`;if(e(n)===t.Translation){let e=n[t.Translation]??{};return Object.values(e).every(e=>typeof e==`string`)?`html(${l(e)})`:void 0}},v=n=>{if(typeof n==`string`)return`md(${JSON.stringify(n)})`;if(e(n)===t.Translation){let e=n[t.Translation]??{};return Object.values(e).every(e=>typeof e==`string`)?`md(${l(e)})`:void 0}if(e(n)===t.File){let e=n[t.File],r=g(e);return r?`md(${r})`:void 0}},y=e=>{if(!(!e||typeof e.dictionaryKey!=`string`))return e.path&&typeof e.path==`string`?`nest(${JSON.stringify(e.dictionaryKey)}, ${JSON.stringify(e.path)})`:`nest(${JSON.stringify(e.dictionaryKey)})`},b=(e,t)=>{let n=e.getProperty(t);if(!n||!i.isPropertyAssignment(n))return;let r=n.getInitializer();if(!r||!i.isCallExpression(r))return;let a=r.getExpression();if(!i.isIdentifier(a)||a.getText()!==`t`)return;let o=r.getArguments()[0];if(!o||!i.isObjectLiteralExpression(o))return;let s={};for(let e of o.getProperties()){if(!i.isPropertyAssignment(e))continue;let t=e.getNameNode().getText().replace(/^['"]|['"]$/g,``),n=e.getInitializer();if(n&&i.isStringLiteral(n))s[t]=n.getLiteralValue();else if(n&&i.isArrayLiteralExpression(n)){let e=[];for(let t of n.getElements()){if(!i.isStringLiteral(t))return;e.push(t.getLiteralValue())}s[t]=e}else return}return s},x=(e,t,n)=>{let r=e.getProperty(t);if(!r||!i.isPropertyAssignment(r))return;let a=r.getInitializer();if(!a||!i.isCallExpression(a))return;let o=a.getExpression();if(!i.isIdentifier(o)||o.getText()!==n)return;let s=a.getArguments()[0];if(!s||!i.isObjectLiteralExpression(s))return;let c={};for(let e of s.getProperties()){if(!i.isPropertyAssignment(e))continue;let t=e.getNameNode().getText().replace(/^['"]|['"]$/g,``),n=e.getInitializer();n&&i.isStringLiteral(n)&&(c[t]=n.getLiteralValue())}return c},S=e=>{try{let t=e.getTypeArguments();return!t||t.length===0?void 0:`<${t.map(e=>e.getText()).join(`, `)}>`}catch{return}},C=(e,t,n)=>{let r=e.getProperty(t);if(!r||!i.isPropertyAssignment(r))return;let a=r.getInitializer();if(!a||!i.isCallExpression(a))return;let o=a.getExpression();if(i.isIdentifier(o)&&o.getText()===n)return S(a);if(n===`t`&&i.isIdentifier(o)&&o.getText()===`md`){let e=a.getArguments()[0];if(e&&i.isCallExpression(e)){let t=e.getExpression();if(i.isIdentifier(t)&&t.getText()===`t`)return S(e)}}},w=(e,t)=>{if(!t)return!1;let n=Object.entries(e).filter(([,e])=>typeof e==`string`);if(n.length!==Object.keys(e).length||n.length!==Object.keys(t).length)return!1;for(let[e,r]of n)if(!(e in t)||t[e]!==r)return!1;return!0},T=(e,t)=>{if(!t)return!1;for(let[n,r]of Object.entries(e)){if(!(n in t))return!1;let e=t[n];if(typeof r==`string`){if(typeof e!=`string`||e!==r)return!1}else if(Array.isArray(r)){if(!Array.isArray(e)||e.length!==r.length)return!1;for(let t=0;t<r.length;t++)if(e[t]!==r[t])return!1}else return!1}return!0},E=e=>{let t=new Set;for(let n of e.getProperties()){if(i.isPropertyAssignment(n)){let e=n.getName();e&&t.add(e.replace(/^['"]|['"]$/g,``));continue}if(i.isShorthandPropertyAssignment(n)){let e=n.getNameNode().getText();e&&t.add(e)}}return t},D=(n,r,a,o,s,c,d)=>{if(!o.has(r)){let e=Y(n,r,d);if(e)return D(e,r,a,E(e),s,c,d)}let f=[],p=!1,m,h=!1,g,_=!1,v=n.getProperty(r);if(v&&i.isPropertyAssignment(v)){let e=v.getInitializer(),t,o=a.every(e=>typeof e==`string`);if(e&&i.isCallExpression(e)&&i.isIdentifier(e.getExpression())&&e.getExpression().getText()===`t`&&o){t=S(e);let o=b(n,r);if(o){let e=l({...o,[s]:a},t);c.add(`t`);let u=n.getProperty(r);return u&&i.isPropertyAssignment(u)&&u.getInitializer()?.getText()!==e?(u.setInitializer(e),!0):!1}}if(e&&i.isArrayLiteralExpression(e)&&(m=e.getElements(),h=e.getElements().some(e=>{if(!i.isCallExpression(e))return!1;let t=e.getExpression();return i.isIdentifier(t)&&t.getText()===`t`}),h)){for(let e of m)if(i.isCallExpression(e)){let t=e.getExpression();if(i.isIdentifier(t)&&t.getText()===`t`&&(g=S(e),g))break}}}for(let n=0;n<a.length;n++){let r=a[n];if(r==null||typeof r==`string`||typeof r==`number`||typeof r==`boolean`){let e=Z(r);if(typeof r==`string`&&m&&n<m.length){let t=m[n];if(i.isCallExpression(t)){let n=t.getExpression();if(i.isIdentifier(n)&&n.getText()===`t`){let n=t.getArguments()[0];if(n&&i.isObjectLiteralExpression(n)){let a={};for(let e of n.getProperties()){if(!i.isPropertyAssignment(e))continue;let t=e.getNameNode().getText().replace(/^['"]|['"]$/g,``),n=e.getInitializer();n&&i.isStringLiteral(n)&&(a[t]=n.getLiteralValue())}e=l(u(a,s,r),S(t)),c.add(`t`)}}}}if(typeof r==`string`&&h&&e&&e.startsWith(`"`)&&(e=l({[s]:r},g),c.add(`t`)),e===void 0){p=!0;break}f.push(e)}else if(typeof r==`object`&&r){if(m&&n<m.length){let e=m[n];if(i.isObjectLiteralExpression(e))B(e,r,s,c,d)&&(_=!0),f.push(e.getText());else{let e=Z(r);if(e===void 0){p=!0;break}f.push(e)}}else{let e=Z(r);if(e===void 0){p=!0;break}f.push(e)}let a=e(r);if(a===t.Translation)c.add(`t`);else if(a===t.Enumeration)c.add(`enu`);else if(a===t.Condition)c.add(`cond`);else if(a===t.Gender)c.add(`gender`);else if(a===t.HTML){c.add(`html`);let n=r[t.HTML];typeof n==`object`&&n&&e(n)===t.Translation&&c.add(`t`)}else if(a===t.Insertion){c.add(`insert`);let n=r[t.Insertion];typeof n==`object`&&n&&e(n)===t.Translation&&c.add(`t`)}else if(a===t.Markdown){c.add(`md`);let n=r[t.Markdown];typeof n==`object`&&n&&e(n)===t.File&&c.add(`file`)}else a===t.File?c.add(`file`):a===t.Nested&&c.add(`nest`)}else{p=!0;break}}if(p)return!1;if(_)return!0;let y=`[ ${f.join(`, `)} ]`;if(!o.has(r))return n.addPropertyAssignment({name:r,initializer:y}),!0;let x=n.getProperty(r);if(x&&i.isPropertyAssignment(x)){let e=X(n,r);if(!(e!==void 0&&e.length===f.length&&e.every((e,t)=>e===f[t])))return x.setInitializer(y),!0}return!1},O=(e,t,n,r,a,o,c)=>{if(typeof n==`string`&&r.has(t)){let r=e.getProperty(t);if(r&&i.isPropertyAssignment(r)){let e=r.getInitializer();if(e&&!i.isStringLiteral(e)&&!i.isCallExpression(e))return console.log(`Skipping update for key "${t}" because existing value is not a string literal`),!1}let s=b(e,t);if(s){let c=l({...s,[a]:n},C(e,t,`t`));return o.add(`t`),r&&i.isPropertyAssignment(r)?(r.setInitializer(c),!0):!1}}if(!r.has(t)){let r=Y(e,t,c);return r?O(r,t,n,E(r),a,o,c):(e.addPropertyAssignment({name:t,initializer:typeof n==`string`?JSON.stringify(n):String(n)}),!0)}let u=e.getProperty(t);if(u&&i.isPropertyAssignment(u)){let e=u.getInitializer(),r=e&&(i.isStringLiteral(e)||i.isNumericLiteral(e)||e.getKind()===s.TrueKeyword||e.getKind()===s.FalseKeyword||i.isNullLiteral(e)||i.isCallExpression(e));if(e&&!r)return console.log(`Skipping update for key "${t}" because existing value is not a primitive literal`),!1;let a=e?.getText(),o=typeof n==`string`?JSON.stringify(n):String(n);if(a!==o)return u.setInitializer(o),!0}return!1},k=(n,r,i,a,o,s,c)=>{switch(e(i)){case t.Translation:return A(n,r,i,a,s,c);case t.Enumeration:return j(n,r,i,a,s,c);case t.Condition:return M(n,r,i,a,s,c);case t.Gender:return N(n,r,i,a,s,c);case t.Insertion:return P(n,r,i,a,s,c);case t.HTML:return F(n,r,i,a,s,c);case t.Markdown:return I(n,r,i,a,o,s,c);case t.File:return L(n,r,i,a,s,c);case t.Nested:return R(n,r,i,a,s,c);default:return!1}},A=(n,r,a,o,s,c)=>{let l=a[t.Translation]??{},u=Object.values(l).every(e=>typeof e==`string`||Array.isArray(e));if(Object.values(l).some(n=>typeof n==`object`&&!!n&&!Array.isArray(n)&&e(n)!==t.Text)&&!u){if(!o.has(r)){let e=Y(n,r,c);if(e)return A(e,r,a,E(e),s,c)}let u=[],d=!1;for(let[n,r]of Object.entries(l)){let i=/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(n)?n:JSON.stringify(n);if(typeof r==`object`&&r&&!Array.isArray(r)){let n=Z(r);if(n===void 0){d=!0;break}u.push(`${i}: ${n}`);let a=e(r);if(a===t.Markdown){s.add(`md`);let n=r[t.Markdown];typeof n==`object`&&n&&e(n)===t.File&&s.add(`file`)}else a===t.File?s.add(`file`):a===t.Insertion?s.add(`insert`):a===t.Enumeration?s.add(`enu`):a===t.Condition?s.add(`cond`):a===t.Gender?s.add(`gender`):a===t.Nested&&s.add(`nest`)}else if(typeof r==`string`)u.push(`${i}: ${JSON.stringify(r)}`);else if(Array.isArray(r)){let e=r.map(e=>JSON.stringify(e)).join(`, `);u.push(`${i}: [ ${e} ]`)}}if(d)return!1;let f=`t${C(n,r,`t`)??``}({ ${u.join(`, `)} })`;if(!o.has(r))return s.add(`t`),n.addPropertyAssignment({name:r,initializer:f}),!0;let p=n.getProperty(r);return p&&i.isPropertyAssignment(p)&&p.getInitializer()?.getText()!==f?(s.add(`t`),p.setInitializer(f),!0):!1}if(!u)return!1;if(!o.has(r)){let e=Y(n,r,c);if(e)return A(e,r,a,E(e),s,c)}let d=[];for(let[e,t]of Object.entries(l)){let n=/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e)?e:JSON.stringify(e);if(typeof t==`string`)d.push(`${n}: ${JSON.stringify(t)}`);else if(Array.isArray(t)){let e=t.map(e=>JSON.stringify(e)).join(`, `);d.push(`${n}: [ ${e} ]`)}}let f=`t${C(n,r,`t`)??``}({ ${d.join(`, `)} })`;if(!o.has(r))return s.add(`t`),n.addPropertyAssignment({name:r,initializer:f}),!0;if(!T(l,b(n,r))){s.add(`t`);let e=n.getProperty(r);if(e&&i.isPropertyAssignment(e))return e.setInitializer(f),!0}return!1},j=(e,n,r,a,o,s)=>{let c=r[t.Enumeration];if(!Object.values(c).every(e=>typeof e==`string`))return!1;let l=f(c);if(!l)return!1;if(!a.has(n)){let t=Y(e,n,s);return t?j(t,n,r,E(t),o,s):(o.add(`enu`),e.addPropertyAssignment({name:n,initializer:l}),!0)}if(!w(c,x(e,n,`enu`))){o.add(`enu`);let t=e.getProperty(n);if(t&&i.isPropertyAssignment(t))return t.setInitializer(l),!0}return!1},M=(n,r,a,o,s,c)=>{let l=a[t.Condition];if(Object.values(l).every(e=>typeof e==`string`)){let e=p(l);if(!e)return!1;if(!o.has(r)){let t=Y(n,r,c);return t?M(t,r,a,E(t),s,c):(s.add(`cond`),n.addPropertyAssignment({name:r,initializer:e}),!0)}if(!w(l,x(n,r,`cond`))){s.add(`cond`);let t=n.getProperty(r);if(t&&i.isPropertyAssignment(t))return t.setInitializer(e),!0}return!1}if(!o.has(r)){let e=Y(n,r,c);return e?M(e,r,a,E(e),s,c):!1}let u=n.getProperty(r);if(!u||!i.isPropertyAssignment(u))return!1;let f=u.getInitializer();if(!f||!i.isCallExpression(f))return!1;let m=f.getExpression();if(!i.isIdentifier(m)||m.getText()!==`cond`)return!1;let h=f.getArguments()[0];if(!h||!i.isObjectLiteralExpression(h))return!1;s.add(`cond`);let g=!1;for(let[n,r]of Object.entries(l)){let a=e(r);if(!a)continue;let o=h.getProperty(n);if(o||=h.getProperty(d(n)),!o||!i.isPropertyAssignment(o))continue;let c=o.getInitializer();if(c&&a===t.Translation){if(!i.isCallExpression(c))continue;let e=c.getExpression();if(!i.isIdentifier(e)||e.getText()!==`t`)continue;let n=c.getArguments()[0];if(!n||!i.isObjectLiteralExpression(n))continue;let a=r[t.Translation];if(!a||typeof a!=`object`)continue;let o={};for(let e of n.getProperties()){if(!i.isPropertyAssignment(e))continue;let t=e.getNameNode().getText().replace(/^['"]|['"]$/g,``),n=e.getInitializer();if(n&&i.isStringLiteral(n))o[t]=n.getLiteralValue();else if(n&&i.isArrayLiteralExpression(n)){let e=[];for(let t of n.getElements())i.isStringLiteral(t)&&e.push(t.getLiteralValue());o[t]=e}}if(!T(a,o)){s.add(`t`);for(let[e,t]of Object.entries(a)){let r=/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(e),a=r?e:JSON.stringify(e),o=n.getProperty(e);if(!o&&!r&&(o=n.getProperty(JSON.stringify(e))),o&&i.isPropertyAssignment(o)){let e=o.getInitializer(),n=Array.isArray(t)?`[${t.map(e=>JSON.stringify(e)).join(`, `)}]`:JSON.stringify(t);e?.getText()!==n&&(o.setInitializer(n),g=!0)}else if(!o){let e=Array.isArray(t)?`[${t.map(e=>JSON.stringify(e)).join(`, `)}]`:JSON.stringify(t);n.addPropertyAssignment({name:a,initializer:e}),g=!0}}}}}return g},N=(e,n,r,a,o,s)=>{let c=r[t.Gender];if(!Object.values(c).every(e=>typeof e==`string`))return!1;let l=m(c);if(!l)return!1;if(!a.has(n)){let t=Y(e,n,s);return t?N(t,n,r,E(t),o,s):(o.add(`gender`),e.addPropertyAssignment({name:n,initializer:l}),!0)}if(!w(c,x(e,n,`gender`))){o.add(`gender`);let t=e.getProperty(n);if(t&&i.isPropertyAssignment(t))return t.setInitializer(l),!0}return!1},P=(e,n,r,a,o,s)=>{let c=r[t.Insertion],l=h(c);if(!l)return!1;if(!a.has(n)){let t=Y(e,n,s);return t?P(t,n,r,E(t),o,s):(o.add(`insert`),e.addPropertyAssignment({name:n,initializer:l}),!0)}let u=e.getProperty(n);return u&&i.isPropertyAssignment(u)&&u.getInitializer()?.getText()!==l?(o.add(`insert`),u.setInitializer(l),!0):!1},F=(e,n,r,a,o,s)=>{let c=r[t.HTML],l=_(c);if(!l)return!1;if(!a.has(n)){let t=Y(e,n,s);return t?F(t,n,r,E(t),o,s):(o.add(`html`),e.addPropertyAssignment({name:n,initializer:l}),!0)}let u=e.getProperty(n);return u&&i.isPropertyAssignment(u)&&u.getInitializer()?.getText()!==l?(o.add(`html`),u.setInitializer(l),!0):!1},I=(n,r,a,o,s,c,u)=>{let d=a[t.Markdown],f=v(d);if(!f)return!1;if(!o.has(r)){let i=Y(n,r,u);if(i)return I(i,r,a,E(i),s,c,u);c.add(`md`);let o=e(d);return o===t.File?c.add(`file`):o===t.Translation&&c.add(`t`),n.addPropertyAssignment({name:r,initializer:f}),!0}let p=e(d),m=V(n,r),h=U(n,r),g=C(n,r,`t`);if(typeof d==`string`&&h&&s){let e={...h,[s]:d};c.add(`md`),c.add(`t`);let t=n.getProperty(r);return t&&i.isPropertyAssignment(t)?(t.setInitializer(`md(${l(e,g)})`),!0):!1}if(p===t.Translation){let e=d[t.Translation];if(!Object.values(e).every(e=>typeof e==`string`))return!1;if(!w(e,h)){c.add(`md`),c.add(`t`);let t=n.getProperty(r);if(t&&i.isPropertyAssignment(t))return t.setInitializer(`md(${l(e,g)})`),!0}return!1}if(!(typeof d==`string`&&m?.kind===`string`&&m.value===d||p===t.File&&m?.kind===`file`&&m.path===d[t.File])){c.add(`md`),p===t.File&&c.add(`file`);let e=n.getProperty(r);if(e&&i.isPropertyAssignment(e))return e.setInitializer(f),!0}return!1},L=(e,n,r,a,o,s)=>{let c=r[t.File],l=g(c);if(!l)return!1;if(!a.has(n)){let t=Y(e,n,s);return t?L(t,n,r,E(t),o,s):(o.add(`file`),e.addPropertyAssignment({name:n,initializer:l}),!0)}if(H(e,n)!==c){o.add(`file`);let t=e.getProperty(n);if(t&&i.isPropertyAssignment(t))return t.setInitializer(l),!0}return!1},R=(e,n,r,a,o,s)=>{let c=r[t.Nested],l=y(c);if(!l)return!1;if(!a.has(n)){let t=Y(e,n,s);return t?R(t,n,r,E(t),o,s):(o.add(`nest`),e.addPropertyAssignment({name:n,initializer:l}),!0)}let u=W(e,n);if(!(c&&u?.dictionaryKey===c.dictionaryKey&&u?.path===c.path)){o.add(`nest`);let t=e.getProperty(n);if(t&&i.isPropertyAssignment(t))return t.setInitializer(l),!0}return!1},z=(e,t,n,r,a,o,c)=>{let l,u=e.getProperty(t);if(u&&i.isPropertyAssignment(u)&&(l=u.getInitializerIfKind(s.ObjectLiteralExpression)),!l){let n=e.getProperty(t);if(n&&i.isShorthandPropertyAssignment(n))l=K(e.getSourceFile(),t);else if(u&&i.isPropertyAssignment(u)){let e=u.getInitializer();e&&(i.isIdentifier(e)?l=K(c,e.getText()):i.isPropertyAccessExpression(e)&&(l=q(c,e)))}}if(!l){let r=Y(e,t,c);if(r)return z(r,t,n,E(r),a,o,c);e.addPropertyAssignment({name:t,initializer:`{ }`});let u=e.getProperty(t);u&&i.isPropertyAssignment(u)&&(l=u.getInitializerIfKind(s.ObjectLiteralExpression))}return l?B(l,n,a,o,c):!1},B=(n,r,i,a,o)=>{let s=!1,c=E(n);for(let[l,u]of Object.entries(r)){if(Array.isArray(u)){D(n,l,u,c,i,a,o)&&(s=!0);continue}if(typeof u==`string`||typeof u==`number`||typeof u==`boolean`||u===null){O(n,l,u,c,i,a,o)&&(s=!0);continue}let r=e(u);if(r!==t.Text&&r!==t.Number&&r!==t.Boolean&&r!==t.Null&&k(n,l,u,c,i,a,o)){s=!0;continue}u&&typeof u==`object`&&!Array.isArray(u)&&!u.nodeType&&z(n,l,u,c,i,a,o)&&(s=!0)}return s},V=(e,t)=>{let n=e.getProperty(t);if(!n||!i.isPropertyAssignment(n))return;let r=n.getInitializer();if(r&&i.isCallExpression(r)){let e=r.getExpression();if(!i.isIdentifier(e))return;if(e.getText()===`md`){let e=r.getArguments()[0];if(!e)return;if(i.isStringLiteral(e))return{kind:`string`,value:e.getLiteralValue()};if(i.isCallExpression(e)){let t=e.getExpression();if(i.isIdentifier(t)&&t.getText()===`file`){let t=e.getArguments()[0];if(t&&i.isStringLiteral(t))return{kind:`file`,path:t.getLiteralValue()}}}}}},H=(e,t)=>{let n=e.getProperty(t);if(!n||!i.isPropertyAssignment(n))return;let r=n.getInitializer();if(!r||!i.isCallExpression(r))return;let a=r.getExpression();if(!i.isIdentifier(a)||a.getText()!==`file`)return;let o=r.getArguments()[0];if(o&&i.isStringLiteral(o))return o.getLiteralValue()},U=(e,t)=>{let n=e.getProperty(t);if(!n||!i.isPropertyAssignment(n))return;let r=n.getInitializer();if(r){if(i.isCallExpression(r)){let e=r.getExpression();if(i.isIdentifier(e)&&e.getText()===`md`){let e=r.getArguments()[0];if(e&&i.isCallExpression(e)){let t=e.getExpression();if(i.isIdentifier(t)&&t.getText()===`t`){let t=e.getArguments()[0];if(t&&i.isObjectLiteralExpression(t)){let e={};for(let n of t.getProperties()){if(!i.isPropertyAssignment(n))continue;let t=n.getNameNode().getText().replace(/^['"]|['"]$/g,``),r=n.getInitializer();if(r&&i.isStringLiteral(r))e[t]=r.getLiteralValue();else return}return e}}}}}if(i.isCallExpression(r)){let e=r.getExpression();if(i.isIdentifier(e)&&e.getText()===`t`){let e=r.getArguments()[0];if(e&&i.isObjectLiteralExpression(e)){let t={};for(let n of e.getProperties()){if(!i.isPropertyAssignment(n))continue;let e=n.getNameNode().getText().replace(/^['"]|['"]$/g,``),r=n.getInitializer();if(r&&i.isCallExpression(r)&&i.isIdentifier(r.getExpression())&&r.getExpression().getText()===`md`){let n=r.getArguments()[0];if(n&&i.isStringLiteral(n))t[e]=n.getLiteralValue();else return}else return}return t}}}}},W=(e,t)=>{let n=e.getProperty(t);if(!n||!i.isPropertyAssignment(n))return;let r=n.getInitializer();if(!r)return;let a=0;for(;a++<5&&!i.isCallExpression(r);){let e=r.getExpression?.();if(e&&typeof e==`object`&&e!==r){r=e;continue}break}if(!i.isCallExpression(r))return;let o=r.getExpression();if(!i.isIdentifier(o)||o.getText()!==`nest`)return;let[s,c]=r.getArguments();if(!s||!i.isStringLiteral(s))return;let l=s.getLiteralValue(),u;return c&&i.isStringLiteral(c)&&(u=c.getLiteralValue()),{dictionaryKey:l,path:u}},G=e=>{if(!e||typeof e!=`object`)return;let t=e,n=0;for(;n++<8;){if(i.isObjectLiteralExpression(t))return t;let e=t?.getExpression?.();if(e&&typeof e==`object`&&e!==t){t=e;continue}break}},K=(e,t)=>{let n=e.getVariableDeclaration(t);if(n){let e=G(n.getInitializer());if(e)return e}let r=e.getDescendants().find(e=>i.isIdentifier(e)&&e.getText()===t)?.getSymbol()?.getDeclarations()?.[0];if(r&&i.isVariableDeclaration(r)){let e=G(r.getInitializer());if(e)return e}},q=(e,t)=>{if(i.isIdentifier(t))return K(e,t.getText());if(i.isPropertyAccessExpression(t)){let n=q(e,t.getExpression());if(!n)return;let r=t.getName(),a=n.getProperty(r);if(a&&i.isPropertyAssignment(a)){let t=a.getInitializer(),n=G(t);if(n)return n;if(t&&i.isIdentifier(t))return K(e,t.getText())}}},J=(e,t)=>{let n=[];for(let r of e.getProperties())if(i.isSpreadAssignment(r)){let e=q(t,r.getExpression());e&&n.push(e)}return n},Y=(e,t,n)=>{let r=J(e,n);for(let e=r.length-1;e>=0;e--){let n=r[e],a=n.getProperty(t);if(a&&i.isPropertyAssignment(a))return n}},X=(e,t)=>{let n=e.getProperty(t);if(!n||!i.isPropertyAssignment(n))return;let r=n.getInitializer();if(!r||!i.isArrayLiteralExpression(r))return;let a=[];for(let e of r.getElements()){if(i.isStringLiteral(e)){a.push(JSON.stringify(e.getLiteralValue()));continue}if(i.isNumericLiteral(e)){a.push(e.getText());continue}if(e.getKind()===s.TrueKeyword||e.getKind()===s.FalseKeyword){a.push(e.getText());continue}if(i.isNullLiteral(e)){a.push(`null`);continue}if(i.isCallExpression(e)){let t=e.getExpression();if(i.isIdentifier(t)&&t.getText()===`t`){let t=e.getArguments()[0];if(t&&i.isObjectLiteralExpression(t)){let e={};for(let n of t.getProperties()){if(!i.isPropertyAssignment(n))return;let t=n.getNameNode().getText().replace(/^['"]|['"]$/g,``),r=n.getInitializer();if(r&&i.isStringLiteral(r))e[t]=r.getLiteralValue();else return}a.push(l(e));continue}}}return}return a},Z=n=>{let r=e(n);if(r===t.Text)return JSON.stringify(n);if(r===t.Number||r===t.Boolean)return String(n);if(r===t.Null)return`null`;if(r===t.Translation){let e=n[t.Translation]??{};return Object.values(e).every(e=>typeof e==`string`)?l(e):void 0}if(r===t.Enumeration){let e=n[t.Enumeration];return f(e)}if(r===t.Condition){let e=n[t.Condition];return p(e)}if(r===t.Gender){let e=n[t.Gender];return m(e)}if(r===t.Insertion){let e=n[t.Insertion];return h(e)}if(r===t.HTML){let e=n[t.HTML];return _(e)}if(r===t.Markdown){let e=n[t.Markdown];return v(e)}if(r===t.File){let e=n[t.File];return g(e)}if(r===t.Nested){let e=n[t.Nested];return y(e)}},Q=e=>{let t=new Set;for(let n of e.getImportDeclarations()){let e=n.getModuleSpecifierValue();if(e===`intlayer`){let e=n.getNamedImports();for(let n of e)t.add(n.getName())}if(e===`intlayer/file`){let e=n.getNamedImports();for(let n of e){let e=n.getAliasNode();t.add(e?e.getText():n.getName())}}}return t},$=(e,t)=>{if(t.size===0)return!1;let n=Q(e),r=[...t].filter(e=>!n.has(e));if(r.length===0)return!1;let i=r.includes(`file`),a=r.filter(e=>e!==`file`);if(a.length>0){let t=e.getImportDeclarations().find(e=>e.getModuleSpecifierValue()===`intlayer`);if(t){let e=t.getNamedImports().map(e=>e.getName()),n=[...new Set([...e,...a])].sort();t.removeNamedImports(),t.addNamedImports(n.map(e=>({name:e})))}else e.insertImportDeclaration(0,{moduleSpecifier:`intlayer`,namedImports:a.sort().map(e=>({name:e}))})}if(i&&!e.getImportDeclarations().find(e=>e.getModuleSpecifierValue()===`intlayer/file`)){let t=e.getImportDeclarations().findIndex(e=>e.getModuleSpecifierValue()===`intlayer`),n=t>=0?t+1:0;e.insertImportDeclaration(n,{moduleSpecifier:`intlayer/file`,namedImports:[{name:`file`}]})}return!0},ee=e=>{if(e.getImportDeclarations().length>0||e.getExportDeclarations().length>0||e.getExportAssignments().length>0)return!1;for(let t of e.getStatements()){if(!i.isExpressionStatement(t))continue;let e=t.getExpression();if(!i.isBinaryExpression(e))continue;let n=e.getLeft();if(!i.isPropertyAccessExpression(n))continue;let r=n.getExpression(),a=n.getName(),o=i.isIdentifier(r)&&r.getText()===`module`&&a===`exports`,s=i.isIdentifier(r)&&r.getText()===`exports`;if(o||s)return!0}return e.getDescendantsOfKind(s.CallExpression).some(e=>{let t=e.getExpression();return i.isIdentifier(t)&&t.getText()===`require`})},te=(e,t)=>{if(t.size===0)return!1;let n=new Set,r=!1;for(let t of e.getVariableDeclarations()){let e=t.getInitializer();if(!e||!i.isCallExpression(e))continue;let a=e.getExpression();if(!i.isIdentifier(a)||a.getText()!==`require`)continue;let o=e.getArguments()[0];if(!o||!i.isStringLiteral(o))continue;let s=o.getLiteralValue(),c=t.getNameNode();if(s===`intlayer`&&i.isObjectBindingPattern(c))for(let e of c.getElements())n.add(e.getNameNode().getText());if(s===`intlayer/file`)if(i.isObjectBindingPattern(c))for(let e of c.getElements())e.getNameNode().getText()===`file`&&(r=!0);else i.isIdentifier(c)&&c.getText()===`file`&&(r=!0)}let a=Array.from(t).filter(e=>e!==`file`).filter(e=>!n.has(e)),o=t.has(`file`)&&!r;if(a.length===0&&!o)return!1;let s=0,c=e.getStatements();for(let e of c){if(i.isExpressionStatement(e)){let t=e.getExpression();if(i.isStringLiteral(t)){s+=1;continue}}break}let l=[];if(a.length>0){let e=Array.from(new Set(a)).sort();l.push(`const { ${e.join(`, `)} } = require('intlayer');`)}return o&&l.push(`const { file } = require('intlayer/file');`),l.length>0?(e.insertStatements(s,l.join(`
2
- `)),!0):!1},ne=e=>Array.isArray(e)?`[${e.map(e=>JSON.stringify(e)).join(`, `)}]`:typeof e==`boolean`||typeof e==`number`?String(e):JSON.stringify(e),re=(e,t,n)=>{let r=e.getProperty(t)||e.getProperty(`'${t}'`)||e.getProperty(`"${t}"`),a=ne(n);if(r&&i.isPropertyAssignment(r)){if(r.getInitializer()?.getText()!==a)return r.setInitializer(a),!0}else if(!r)return e.addPropertyAssignment({name:t,initializer:a}),!0;return!1},ie=(e,t)=>{let n=!1;for(let r of[`id`,`locale`,`filled`,`fill`,`title`,`description`,`tags`,`version`,`priority`,`contentAutoTransformation`]){let i=t[r];i!==void 0&&re(e,r,i)&&(n=!0)}return n},ae=e=>{let t=e.getExportAssignment(e=>!0);if(t){let n=t.getExpression();if(i.isIdentifier(n)){let t=n.getSymbol()?.getDeclarations()?.[0]??e.getVariableDeclaration(n.getText());if(t&&i.isVariableDeclaration(t)){let e=G(t.getInitializer());if(e)return e}}else{let e=G(n);if(e)return e}}let n=e.getVariableDeclaration(e=>{try{return e.getType().getText().includes(`Dictionary`)||e.getName()===`content`||e.getName().toLowerCase().includes(`dictionary`)}catch{return e.getName()===`content`}});if(n){let e=G(n.getInitializer());if(e)return e}for(let t of e.getStatements()){if(!i.isExpressionStatement(t))continue;let e=t.getExpression();if(!i.isBinaryExpression(e)||e.getOperatorToken().getText()!==`=`)continue;let n=e.getLeft();if(!i.isPropertyAccessExpression(n))continue;let r=n.getExpression(),a=n.getName(),o=i.isIdentifier(r)&&r.getText()===`module`&&a===`exports`,s=i.isIdentifier(r)&&r.getText()===`exports`&&a===`default`;if(!o&&!s)continue;let c=e.getRight();if(i.isObjectLiteralExpression(c))return c;if(i.isIdentifier(c)){let e=c.getSymbol()?.getDeclarations()?.[0];if(e&&i.isVariableDeclaration(e)){let t=G(e.getInitializer());if(t)return t}}}},oe=async(t,l,u)=>{try{if(!l||typeof l!=`object`)return t;let d=new a({useInMemoryFileSystem:!0,skipAddingFilesFromTsConfig:!0,skipFileDependencyResolution:!0,compilerOptions:{allowJs:!0,jsx:c.JsxEmit.Preserve},manipulationSettings:{indentationText:n.TwoSpaces,quoteKind:o.Double,newLineKind:r.LineFeed}}).createSourceFile(`file.tsx`,t,{overwrite:!0}),f=ae(d);if(!f)return t;let p=!1,m=new Set;if(ie(f,l)&&(p=!0),l.content){let t=f.getProperty(`content`),n,r=!1,a=!1;if(t&&i.isPropertyAssignment(t)){n=t.getInitializerIfKind(s.ObjectLiteralExpression),r=!!t.getInitializerIfKind(s.ArrayLiteralExpression);let e=t.getInitializer();a=!!e&&i.isCallExpression(e)}let o=u??`en`;if(n&&!Array.isArray(l.content)){let e=l.content??{};B(n,e,o,m,d)&&(p=!0)}else Array.isArray(l.content)&&r?D(f,`content`,l.content??[],E(f),o,m,d)&&(p=!0):a&&e(l.content)&&k(f,`content`,l.content,E(f),o,m,d)&&(p=!0)}return p&&((ee(d)?te(d,m):$(d,m))||p)?d.getFullText():t}catch{return t}};export{oe as transformJSFile};
1
+ import{__require as e}from"../_virtual/_rolldown/runtime.mjs";import{getNodeType as t}from"@intlayer/core/dictionaryManipulator";import{NodeType as n}from"@intlayer/types";import*as r from"recast";const i=r.types.builders,a=r.types.namedTypes,o=e=>{for(;e&&(a.TSSatisfiesExpression?.check(e)||a.TSAsExpression?.check(e)||a.TSTypeAssertion?.check(e)||a.TSNonNullExpression?.check(e));)e=e.expression;return e},s=(e,t)=>e.properties.find(e=>!!((a.Property.check(e)||a.ObjectProperty.check(e))&&(a.Identifier.check(e.key)&&e.key.name===t||a.StringLiteral.check(e.key)&&e.key.value===t||a.Literal.check(e.key)&&e.key.value===t))),c=(e,t,n)=>{let r=n.match(/\d+(?!.*\d)/);if(!r)return;let o=r[0];if(a.ObjectExpression.check(e)){for(let n of e.properties)if(a.Property.check(n)||a.ObjectProperty.check(n)){let e=``;if(a.Identifier.check(n.key)?e=n.key.name:(a.Literal.check(n.key)&&typeof n.key.value==`string`||a.StringLiteral.check(n.key))&&(e=n.key.value),e&&e!==t){if(a.Literal.check(n.value)&&typeof n.value.value==`string`){let e=n.value.value;e.match(/\d+(?!.*\d)/)&&(n.value=i.literal(e.replace(/(\d+)(?!.*\d)/,o)))}else if(a.StringLiteral.check(n.value)){let e=n.value.value;e.match(/\d+(?!.*\d)/)&&(n.value=i.stringLiteral(e.replace(/(\d+)(?!.*\d)/,o)))}}}}},l=e=>{if(typeof e!=`object`||!e||Array.isArray(e))return!1;let r=t(e);if(r===n.Translation)return!0;if(r===n.Markdown||r===n.HTML||r===n.Insertion)return l(e[r]);if(r===n.Enumeration||r===n.Condition||r===n.Gender){let t=e[r];if(t&&typeof t==`object`)return Object.values(t).some(e=>l(e))}return!1},u=(e,r,s,f)=>{if(s&&r&&!l(e)){if(a.CallExpression.check(r)&&a.Identifier.check(r.callee)&&r.callee.name===`t`){let t=o(r.arguments[0]);if(a.ObjectExpression.check(t))return typeof e==`string`&&c(t,s,e),d(t,{[s]:e},s,f),f.add(`t`),r}if((!e||typeof e!=`object`)&&a.CallExpression.check(r)&&a.Identifier.check(r.callee)&&r.callee.name===`md`){let t=r.arguments[0];if(a.CallExpression.check(t)&&a.Identifier.check(t.callee)&&t.callee.name===`t`){let n=o(t.arguments[0]);if(a.ObjectExpression.check(n))return typeof e==`string`&&c(n,s,e),d(n,{[s]:e},s,f),f.add(`md`),f.add(`t`),r}}}if(e===null)return i.literal(null);if(typeof e==`string`||typeof e==`number`||typeof e==`boolean`)return i.literal(e);if(Array.isArray(e)){let t=o(r);if(t&&a.ArrayExpression.check(t)){let n=[...t.elements];return e.forEach((e,t)=>{n[t]=u(e,n[t],s,f)}),n.length>e.length&&(n.length=e.length),t.elements=n,r}else return i.arrayExpression(e.map(e=>u(e,null,s,f)))}let p=e&&typeof e==`object`&&!Array.isArray(e)?t(e):null;if(p&&Object.values(n).includes(p)&&p!==n.Text){let t=e[p],o=``;p===n.Translation?o=`t`:p===n.Enumeration?o=`enu`:p===n.Condition?o=`cond`:p===n.Gender?o=`gender`:p===n.Insertion?o=`insert`:p===n.Markdown?o=`md`:p===n.HTML?o=`html`:p===n.File?o=`file`:p===n.Nested&&(o=`nest`),o&&f.add(o);let c=r&&a.CallExpression.check(r)&&a.Identifier.check(r.callee)&&r.callee.name===o;if([`t`,`enu`,`cond`,`gender`].includes(o)){let e=null;return e=c&&r.arguments.length>0&&a.ObjectExpression.check(r.arguments[0])?r.arguments[0]:i.objectExpression([]),d(e,t,s,f),c?r:i.callExpression(i.identifier(o),[e])}if([`md`,`html`,`insert`,`file`].includes(o)){let e=u(t,c&&r.arguments.length>0?r.arguments[0]:null,s,f);return c?(r.arguments[0]=e,r):i.callExpression(i.identifier(o),[e])}if(o===`nest`){let e=[i.literal(t.dictionaryKey)];return t.path&&e.push(i.literal(t.path)),c?(r.arguments=e,r):i.callExpression(i.identifier(`nest`),e)}}let m=o(r),h=m&&a.ObjectExpression.check(m)?m:i.objectExpression([]);return d(h,e,s,f),r&&m===r?h:r||h},d=(e,t,n,r)=>{for(let[a,o]of Object.entries(t)){if(o===void 0)continue;let t=s(e,a);if(t)t.value=u(o,t.value,n,r);else{let t=/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(a)?i.identifier(a):i.literal(a),s=u(o,null,n,r);e.properties.push(i.property(`init`,t,s))}}},f=(e,t,n)=>{if(t.size===0)return;let o=new Set,s=!1,c=null;r.visit(e,{visitImportDeclaration(e){let t=e.node.source.value;return t===`intlayer`?(c=e,e.node.specifiers?.forEach(e=>{a.ImportSpecifier.check(e)&&typeof e.imported.name==`string`&&o.add(e.imported.name)})):t===`intlayer/file`&&(s=!0),!1},visitVariableDeclaration(e){return e.node.declarations.forEach(e=>{if(a.VariableDeclarator.check(e)&&a.CallExpression.check(e.init)&&a.Identifier.check(e.init.callee)&&e.init.callee.name===`require`){let t=e.init.arguments[0];a.Literal.check(t)&&(t.value===`intlayer`?a.ObjectPattern.check(e.id)&&e.id.properties.forEach(e=>{a.Property.check(e)&&a.Identifier.check(e.key)&&o.add(e.key.name)}):t.value===`intlayer/file`&&(s=!0))}}),!1}});let l=Array.from(t).filter(e=>e!==`file`&&!o.has(e)),u=t.has(`file`)&&!s;if(!(l.length===0&&!u))if(n){if(l.length>0)if(c)l.forEach(e=>{c.node.specifiers.push(i.importSpecifier(i.identifier(e)))}),c.node.specifiers.sort((e,t)=>e.imported.name.localeCompare(t.imported.name));else{let t=l.sort().map(e=>i.importSpecifier(i.identifier(e))),n=i.importDeclaration(t,i.literal(`intlayer`));e.program.body.unshift(n)}if(u){let t=0;e.program.body.forEach((e,n)=>{a.ImportDeclaration.check(e)&&e.source.value===`intlayer`&&(t=n+1)});let n=i.importDeclaration([i.importSpecifier(i.identifier(`file`))],i.literal(`intlayer/file`));e.program.body.splice(t,0,n)}}else{let t=0;e.program.body.length>0&&a.ExpressionStatement.check(e.program.body[0])&&a.Literal.check(e.program.body[0].expression)&&(t=1);let n=[];if(l.length>0){let e=l.sort().map(e=>{let t=i.property(`init`,i.identifier(e),i.identifier(e));return t.shorthand=!0,t});n.push(i.variableDeclaration(`const`,[i.variableDeclarator(i.objectPattern(e),i.callExpression(i.identifier(`require`),[i.literal(`intlayer`)]))]))}if(u){let e=i.property(`init`,i.identifier(`file`),i.identifier(`file`));e.shorthand=!0,n.push(i.variableDeclaration(`const`,[i.variableDeclarator(i.objectPattern([e]),i.callExpression(i.identifier(`require`),[i.literal(`intlayer/file`)]))]))}e.program.body.splice(t,0,...n)}},p=async(t,n,i)=>{if(!n||typeof n!=`object`)return t;let s;try{s=r.parse(t,{parser:e(`recast/parsers/typescript`)})}catch{try{s=r.parse(t)}catch{return t}}let c=null,l=!1;if(r.visit(s,{visitExportDefaultDeclaration(e){return l=!0,!1},visitImportDeclaration(){return l=!0,!1}}),r.visit(s,{visitExportDefaultDeclaration(e){let t=e.node.declaration,n=o(t);if(a.ObjectExpression.check(n))c=n;else if(a.Identifier.check(n)){let e=n.name;r.visit(s,{visitVariableDeclarator(t){let n=o(t.node.init);return a.Identifier.check(t.node.id)&&t.node.id.name===e&&a.ObjectExpression.check(n)&&(c=n),!1}})}return!1},visitAssignmentExpression(e){let t=e.node.left;if(a.MemberExpression.check(t)){if(a.Identifier.check(t.object)&&t.object.name===`module`&&a.Identifier.check(t.property)&&t.property.name===`exports`){let t=o(e.node.right);a.ObjectExpression.check(t)&&(c=t)}if(a.Identifier.check(t.object)&&t.object.name===`exports`&&a.Identifier.check(t.property)&&t.property.name===`default`){let t=o(e.node.right);a.ObjectExpression.check(t)&&(c=t)}}this.traverse(e)}}),c||r.visit(s,{visitVariableDeclarator(e){let t=o(e.node.init);return!c&&a.ObjectExpression.check(t)&&(c=t),!1}}),!c)return t;let u=new Set,p=i??`en`;for(let e of[`id`,`locale`,`filled`,`fill`,`title`,`description`,`tags`,`version`,`priority`,`contentAutoTransformation`])n[e]!==void 0&&d(c,{[e]:n[e]},void 0,u);return n.content!==void 0&&d(c,{content:n.content},p,u),f(s,u,l),r.print(s).code};export{p as transformJSFile};
3
2
  //# sourceMappingURL=transformJSFile.mjs.map