@intlayer/engine 9.5.12 → 9.7.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 (169) hide show
  1. package/dist/assets/installSkills/skills/cli.md +28 -1
  2. package/dist/assets/installSkills/skills/compat.md +1 -1
  3. package/dist/assets/installSkills/skills/dev-tools.md +8 -6
  4. package/dist/cjs/build.cjs +12 -2
  5. package/dist/cjs/buildIntlayerDictionary/buildIntlayerDictionary.cjs +12 -11
  6. package/dist/cjs/buildIntlayerDictionary/buildIntlayerDictionary.cjs.map +1 -1
  7. package/dist/cjs/buildIntlayerDictionary/index.cjs +4 -1
  8. package/dist/cjs/buildIntlayerDictionary/rebuildUnmergedDictionaries.cjs +23 -0
  9. package/dist/cjs/buildIntlayerDictionary/rebuildUnmergedDictionaries.cjs.map +1 -0
  10. package/dist/cjs/cli.cjs +12 -0
  11. package/dist/cjs/fetchDistantDictionaries.cjs.map +1 -1
  12. package/dist/cjs/handleAdditionalContentDeclarationFile.cjs +1 -1
  13. package/dist/cjs/handleContentDeclarationFileChange.cjs +1 -1
  14. package/dist/cjs/handleUnlinkedContentDeclarationFile.cjs +1 -1
  15. package/dist/cjs/init/cms.cjs +18 -0
  16. package/dist/cjs/init/cms.cjs.map +1 -1
  17. package/dist/cjs/init/index.cjs +23 -10
  18. package/dist/cjs/init/index.cjs.map +1 -1
  19. package/dist/cjs/init/utils/configManipulation.cjs +28 -0
  20. package/dist/cjs/init/utils/configManipulation.cjs.map +1 -1
  21. package/dist/cjs/init/utils/contentLayout.cjs +61 -0
  22. package/dist/cjs/init/utils/contentLayout.cjs.map +1 -0
  23. package/dist/cjs/init/utils/index.cjs +1 -0
  24. package/dist/cjs/init/utils/packageManager.cjs +1 -1
  25. package/dist/cjs/init/utils/packageManager.cjs.map +1 -1
  26. package/dist/cjs/installMCP/installMCP.cjs +35 -25
  27. package/dist/cjs/installMCP/installMCP.cjs.map +1 -1
  28. package/dist/cjs/installSkills/index.cjs +26 -1
  29. package/dist/cjs/installSkills/index.cjs.map +1 -1
  30. package/dist/cjs/listDictionariesPath.cjs +2 -5
  31. package/dist/cjs/listDictionariesPath.cjs.map +1 -1
  32. package/dist/cjs/listGitFiles.cjs +3 -5
  33. package/dist/cjs/listGitFiles.cjs.map +1 -1
  34. package/dist/cjs/listProjects.cjs +1 -2
  35. package/dist/cjs/listProjects.cjs.map +1 -1
  36. package/dist/cjs/loadDictionaries/index.cjs +1 -1
  37. package/dist/cjs/loadDictionaries/loadDictionaries.cjs +1 -1
  38. package/dist/cjs/loadDictionaries/loadRemoteDictionaries.cjs.map +1 -1
  39. package/dist/cjs/utils/buildComponentFilesList.cjs +18 -30
  40. package/dist/cjs/utils/buildComponentFilesList.cjs.map +1 -1
  41. package/dist/cjs/utils/chunkJSON.cjs +1 -1
  42. package/dist/cjs/utils/chunkJSON.cjs.map +1 -1
  43. package/dist/cjs/utils/index.cjs +2 -0
  44. package/dist/cjs/utils/isDirectoryExcluded.cjs +36 -0
  45. package/dist/cjs/utils/isDirectoryExcluded.cjs.map +1 -0
  46. package/dist/cjs/watcher.cjs +5 -2
  47. package/dist/cjs/watcher.cjs.map +1 -1
  48. package/dist/cjs/writeConfiguration/index.cjs +23 -0
  49. package/dist/cjs/writeConfiguration/index.cjs.map +1 -1
  50. package/dist/cjs/writeContentDeclaration/index.cjs +6 -0
  51. package/dist/cjs/writeContentDeclaration/processContentDeclarationContent.cjs +20 -13
  52. package/dist/cjs/writeContentDeclaration/processContentDeclarationContent.cjs.map +1 -1
  53. package/dist/cjs/writeContentDeclaration/renderContentDeclaration.cjs +213 -0
  54. package/dist/cjs/writeContentDeclaration/renderContentDeclaration.cjs.map +1 -0
  55. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +5 -51
  56. package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs.map +1 -1
  57. package/dist/cjs/writeContentDeclaration/writeMarkdownFile.cjs +2 -31
  58. package/dist/cjs/writeContentDeclaration/writeMarkdownFile.cjs.map +1 -1
  59. package/dist/cjs/writeContentDeclaration/writeYamlFile.cjs +2 -8
  60. package/dist/cjs/writeContentDeclaration/writeYamlFile.cjs.map +1 -1
  61. package/dist/esm/build.mjs +7 -5
  62. package/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs +12 -12
  63. package/dist/esm/buildIntlayerDictionary/buildIntlayerDictionary.mjs.map +1 -1
  64. package/dist/esm/buildIntlayerDictionary/index.mjs +3 -2
  65. package/dist/esm/buildIntlayerDictionary/rebuildUnmergedDictionaries.mjs +22 -0
  66. package/dist/esm/buildIntlayerDictionary/rebuildUnmergedDictionaries.mjs.map +1 -0
  67. package/dist/esm/cli.mjs +5 -3
  68. package/dist/esm/fetchDistantDictionaries.mjs.map +1 -1
  69. package/dist/esm/handleAdditionalContentDeclarationFile.mjs +1 -1
  70. package/dist/esm/handleContentDeclarationFileChange.mjs +1 -1
  71. package/dist/esm/handleUnlinkedContentDeclarationFile.mjs +1 -1
  72. package/dist/esm/init/cms.mjs +19 -2
  73. package/dist/esm/init/cms.mjs.map +1 -1
  74. package/dist/esm/init/index.mjs +24 -11
  75. package/dist/esm/init/index.mjs.map +1 -1
  76. package/dist/esm/init/utils/configManipulation.mjs +28 -1
  77. package/dist/esm/init/utils/configManipulation.mjs.map +1 -1
  78. package/dist/esm/init/utils/contentLayout.mjs +58 -0
  79. package/dist/esm/init/utils/contentLayout.mjs.map +1 -0
  80. package/dist/esm/init/utils/index.mjs +2 -2
  81. package/dist/esm/init/utils/packageManager.mjs +1 -1
  82. package/dist/esm/init/utils/packageManager.mjs.map +1 -1
  83. package/dist/esm/installMCP/installMCP.mjs +35 -25
  84. package/dist/esm/installMCP/installMCP.mjs.map +1 -1
  85. package/dist/esm/installSkills/index.mjs +27 -3
  86. package/dist/esm/installSkills/index.mjs.map +1 -1
  87. package/dist/esm/listDictionariesPath.mjs +2 -5
  88. package/dist/esm/listDictionariesPath.mjs.map +1 -1
  89. package/dist/esm/listGitFiles.mjs +1 -1
  90. package/dist/esm/listGitFiles.mjs.map +1 -1
  91. package/dist/esm/listProjects.mjs +1 -1
  92. package/dist/esm/listProjects.mjs.map +1 -1
  93. package/dist/esm/loadDictionaries/index.mjs +1 -1
  94. package/dist/esm/loadDictionaries/loadDictionaries.mjs +1 -1
  95. package/dist/esm/loadDictionaries/loadRemoteDictionaries.mjs.map +1 -1
  96. package/dist/esm/utils/buildComponentFilesList.mjs +19 -31
  97. package/dist/esm/utils/buildComponentFilesList.mjs.map +1 -1
  98. package/dist/esm/utils/chunkJSON.mjs +1 -1
  99. package/dist/esm/utils/chunkJSON.mjs.map +1 -1
  100. package/dist/esm/utils/index.mjs +2 -1
  101. package/dist/esm/utils/isDirectoryExcluded.mjs +35 -0
  102. package/dist/esm/utils/isDirectoryExcluded.mjs.map +1 -0
  103. package/dist/esm/utils/runParallel/pidTree.mjs +3 -3
  104. package/dist/esm/utils/runParallel/pidTree.mjs.map +1 -1
  105. package/dist/esm/utils/runParallel/ps.mjs +2 -2
  106. package/dist/esm/utils/runParallel/ps.mjs.map +1 -1
  107. package/dist/esm/utils/runParallel/wmic.mjs +2 -2
  108. package/dist/esm/utils/runParallel/wmic.mjs.map +1 -1
  109. package/dist/esm/watcher.mjs +5 -2
  110. package/dist/esm/watcher.mjs.map +1 -1
  111. package/dist/esm/writeConfiguration/index.mjs +23 -1
  112. package/dist/esm/writeConfiguration/index.mjs.map +1 -1
  113. package/dist/esm/writeContentDeclaration/index.mjs +2 -1
  114. package/dist/esm/writeContentDeclaration/processContentDeclarationContent.mjs +20 -13
  115. package/dist/esm/writeContentDeclaration/processContentDeclarationContent.mjs.map +1 -1
  116. package/dist/esm/writeContentDeclaration/renderContentDeclaration.mjs +208 -0
  117. package/dist/esm/writeContentDeclaration/renderContentDeclaration.mjs.map +1 -0
  118. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +5 -51
  119. package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs.map +1 -1
  120. package/dist/esm/writeContentDeclaration/writeMarkdownFile.mjs +2 -31
  121. package/dist/esm/writeContentDeclaration/writeMarkdownFile.mjs.map +1 -1
  122. package/dist/esm/writeContentDeclaration/writeYamlFile.mjs +2 -8
  123. package/dist/esm/writeContentDeclaration/writeYamlFile.mjs.map +1 -1
  124. package/dist/types/build.d.ts +5 -3
  125. package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts +6 -0
  126. package/dist/types/buildIntlayerDictionary/buildIntlayerDictionary.d.ts.map +1 -1
  127. package/dist/types/buildIntlayerDictionary/index.d.ts +3 -2
  128. package/dist/types/buildIntlayerDictionary/rebuildUnmergedDictionaries.d.ts +14 -0
  129. package/dist/types/buildIntlayerDictionary/rebuildUnmergedDictionaries.d.ts.map +1 -0
  130. package/dist/types/cli.d.ts +6 -4
  131. package/dist/types/fetchDistantDictionaries.d.ts +1 -1
  132. package/dist/types/fetchDistantDictionaries.d.ts.map +1 -1
  133. package/dist/types/init/cms.d.ts +6 -0
  134. package/dist/types/init/cms.d.ts.map +1 -1
  135. package/dist/types/init/index.d.ts +15 -14
  136. package/dist/types/init/index.d.ts.map +1 -1
  137. package/dist/types/init/utils/configManipulation.d.ts +8 -0
  138. package/dist/types/init/utils/configManipulation.d.ts.map +1 -1
  139. package/dist/types/init/utils/contentLayout.d.ts +42 -0
  140. package/dist/types/init/utils/contentLayout.d.ts.map +1 -0
  141. package/dist/types/init/utils/index.d.ts +2 -2
  142. package/dist/types/init/utils/packageManager.d.ts +9 -3
  143. package/dist/types/init/utils/packageManager.d.ts.map +1 -1
  144. package/dist/types/installMCP/installMCP.d.ts +4 -0
  145. package/dist/types/installMCP/installMCP.d.ts.map +1 -1
  146. package/dist/types/installSkills/index.d.ts +6 -0
  147. package/dist/types/installSkills/index.d.ts.map +1 -1
  148. package/dist/types/listDictionariesPath.d.ts +1 -1
  149. package/dist/types/listDictionariesPath.d.ts.map +1 -1
  150. package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts +1 -1
  151. package/dist/types/loadDictionaries/loadRemoteDictionaries.d.ts.map +1 -1
  152. package/dist/types/utils/buildComponentFilesList.d.ts +6 -6
  153. package/dist/types/utils/buildComponentFilesList.d.ts.map +1 -1
  154. package/dist/types/utils/chunkJSON.d.ts.map +1 -1
  155. package/dist/types/utils/index.d.ts +2 -1
  156. package/dist/types/utils/isDirectoryExcluded.d.ts +15 -0
  157. package/dist/types/utils/isDirectoryExcluded.d.ts.map +1 -0
  158. package/dist/types/watcher.d.ts.map +1 -1
  159. package/dist/types/writeConfiguration/index.d.ts +13 -0
  160. package/dist/types/writeConfiguration/index.d.ts.map +1 -1
  161. package/dist/types/writeContentDeclaration/index.d.ts +2 -1
  162. package/dist/types/writeContentDeclaration/processContentDeclarationContent.d.ts +8 -2
  163. package/dist/types/writeContentDeclaration/processContentDeclarationContent.d.ts.map +1 -1
  164. package/dist/types/writeContentDeclaration/renderContentDeclaration.d.ts +61 -0
  165. package/dist/types/writeContentDeclaration/renderContentDeclaration.d.ts.map +1 -0
  166. package/dist/types/writeContentDeclaration/writeContentDeclaration.d.ts.map +1 -1
  167. package/dist/types/writeContentDeclaration/writeMarkdownFile.d.ts.map +1 -1
  168. package/dist/types/writeContentDeclaration/writeYamlFile.d.ts.map +1 -1
  169. package/package.json +18 -10
@@ -1 +1 @@
1
- {"version":3,"file":"configManipulation.cjs","names":["typescriptParser","isModuleScopeBinding"],"sources":["../../../../src/init/utils/configManipulation.ts"],"sourcesContent":["import type { RoutingConfig } from '@intlayer/types/config';\nimport * as recast from 'recast';\nimport { typescriptParser } from '../../utils/babelParser';\nimport { isModuleScopeBinding } from './astImports';\nimport type {\n CompatSyncConfig,\n CompatVitePluginConfig,\n} from './packageManager';\n\nconst { builders: b, namedTypes: n } = recast.types;\n\n/** The locale routing strategies supported by the Intlayer configuration. */\nexport type RoutingMode = RoutingConfig['mode'];\n\n/** Narrows an arbitrary recast node to an object expression. */\nconst isObjectExpression = (node: any): boolean =>\n Boolean(node) &&\n (node.type === 'ObjectExpression' || n.ObjectExpression.check(node));\n\n/**\n * Finds a property by key name on an object expression, creating it with the\n * provided default value node when it is absent. Returns the property node so\n * callers can read or mutate its value while preserving any attached comments.\n */\nconst ensureObjectProperty = (\n objExpr: any,\n key: string,\n defaultValueNode: any\n): any => {\n let property = (objExpr.properties as any[]).find((prop: any) => {\n if (!prop?.key) return false;\n return (prop.key.name ?? prop.key.value) === key;\n });\n\n if (!property) {\n property = b.property('init', b.identifier(key), defaultValueNode);\n (objExpr.properties as any[]).push(property);\n }\n\n return property;\n};\n\n/**\n * Sets (or replaces) a property's value on an object expression. When the\n * property already exists only its value node is swapped, which keeps the\n * leading documentation comment in place.\n */\nconst setObjectPropertyValue = (\n objExpr: any,\n key: string,\n valueNode: any\n): void => {\n const property = (objExpr.properties as any[]).find((prop: any) => {\n if (!prop?.key) return false;\n return (prop.key.name ?? prop.key.value) === key;\n });\n\n if (property) {\n property.value = valueNode;\n return;\n }\n\n (objExpr.properties as any[]).push(\n b.property('init', b.identifier(key), valueNode)\n );\n};\n\n/**\n * Adds a `process.env.<envVar>` reference property to an object expression when\n * the property is not already present. Existing values are left untouched.\n */\nconst addEnvReferenceProperty = (\n objExpr: any,\n key: string,\n envVar: string\n): void => {\n const hasProperty = (objExpr.properties as any[]).some((prop: any) => {\n if (!prop?.key) return false;\n return (prop.key.name ?? prop.key.value) === key;\n });\n\n if (hasProperty) return;\n\n (objExpr.properties as any[]).push(\n b.property(\n 'init',\n b.identifier(key),\n b.memberExpression(\n b.memberExpression(b.identifier('process'), b.identifier('env')),\n b.identifier(envVar)\n )\n )\n );\n};\n\n/**\n * Sets `routing.mode` in an Intlayer configuration file to the requested\n * strategy. Idempotent: re-running with the same mode produces identical\n * output. Supports `.ts`, `.mjs`, `.js` and `.cjs` configs; JSON configs are\n * handled with a scoped string replacement since they cannot be parsed by the\n * TypeScript recast parser.\n */\nexport const setIntlayerConfigRoutingMode = (\n content: string,\n extension: string,\n mode: RoutingMode\n): string => {\n if (extension === 'json') {\n return content.replace(\n /(\"mode\"\\s*:\\s*)\"(?:prefix-no-default|prefix-all|no-prefix|search-params)\"/,\n `$1\"${mode}\"`\n );\n }\n\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n genericRecastVisit(ast, (objExpr) => {\n if (!isObjectExpression(objExpr)) return;\n\n const routingProperty = ensureObjectProperty(\n objExpr,\n 'routing',\n b.objectExpression([])\n );\n\n if (!isObjectExpression(routingProperty.value)) return;\n\n setObjectPropertyValue(\n routingProperty.value,\n 'mode',\n b.stringLiteral(mode)\n );\n });\n\n return recast.print(ast).code;\n};\n\n/**\n * Sets `routing.enableProxy` in an Intlayer configuration file. Idempotent and\n * comment-preserving: an existing property only has its value swapped. Supports\n * `.ts`, `.mjs`, `.js`, `.cjs` and `.json` configs.\n */\nexport const setIntlayerConfigEnableProxy = (\n content: string,\n extension: string,\n enableProxy: boolean\n): string => {\n // The JSON template carries comments, so a scoped replacement is used rather\n // than `JSON.parse`.\n if (extension === 'json') {\n return content.replace(\n /(\"enableProxy\"\\s*:\\s*)(?:true|false)/,\n `$1${enableProxy}`\n );\n }\n\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n genericRecastVisit(ast, (objExpr) => {\n if (!isObjectExpression(objExpr)) return;\n\n const routingProperty = ensureObjectProperty(\n objExpr,\n 'routing',\n b.objectExpression([])\n );\n\n if (!isObjectExpression(routingProperty.value)) return;\n\n setObjectPropertyValue(\n routingProperty.value,\n 'enableProxy',\n b.booleanLiteral(enableProxy)\n );\n });\n\n return recast.print(ast).code;\n};\n\n/** Default `routing.storage` written when the routing section is reduced. */\nconst DEFAULT_ROUTING_STORAGE = ['cookie', 'header'] as const;\n\n/**\n * Reduces `routing` in an Intlayer configuration file to its `storage` entry,\n * for projects without URL routing (backend-only, React Native…) where the\n * routing mode and the locale proxy have no effect. An existing `storage`\n * value is kept; otherwise `['cookie', 'header']` is written. JSON configs are\n * returned unchanged.\n */\nexport const setIntlayerConfigRoutingStorageOnly = (\n content: string,\n extension: string\n): string => {\n if (extension === 'json') return content;\n\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n genericRecastVisit(ast, (objExpr) => {\n if (!isObjectExpression(objExpr)) return;\n\n const routingProperty = ensureObjectProperty(\n objExpr,\n 'routing',\n b.objectExpression([])\n );\n\n if (!isObjectExpression(routingProperty.value)) return;\n\n const existingStorageProperty = (\n routingProperty.value.properties as any[]\n ).find((prop: any) => (prop?.key?.name ?? prop?.key?.value) === 'storage');\n\n const storageProperty =\n existingStorageProperty ??\n b.property(\n 'init',\n b.identifier('storage'),\n b.arrayExpression(\n DEFAULT_ROUTING_STORAGE.map((storage) => b.stringLiteral(storage))\n )\n );\n\n routingProperty.value.properties = [storageProperty];\n });\n\n return recast.print(ast, { tabWidth: 2 }).code;\n};\n\n/**\n * Sets `compiler.output` in an Intlayer configuration file to the given path\n * template (the `{{variable}}` string form, e.g.\n * `/locales/{{locale}}/{{key}}.content.json`). Idempotent: re-running with the\n * same template produces identical output. Supports `.ts`, `.mjs`, `.js` and\n * `.cjs` configs; JSON configs are supported too since the template is a plain\n * string.\n */\nexport const setIntlayerConfigCompilerOutput = (\n content: string,\n extension: string,\n outputTemplate: string\n): string => {\n if (extension === 'json') {\n const parsed = JSON.parse(content);\n parsed.compiler = { ...parsed.compiler, output: outputTemplate };\n return JSON.stringify(parsed, null, 2);\n }\n\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n genericRecastVisit(ast, (objExpr) => {\n if (!isObjectExpression(objExpr)) return;\n\n const compilerProperty = ensureObjectProperty(\n objExpr,\n 'compiler',\n b.objectExpression([])\n );\n\n if (!isObjectExpression(compilerProperty.value)) return;\n\n setObjectPropertyValue(\n compilerProperty.value,\n 'output',\n b.stringLiteral(outputTemplate)\n );\n });\n\n return recast.print(ast).code;\n};\n\n/**\n * Enables the Intlayer visual editor in a configuration file: sets\n * `editor.enabled` to `true` and wires `clientId` / `clientSecret` to the\n * `INTLAYER_CLIENT_ID` / `INTLAYER_CLIENT_SECRET` environment variables.\n * Idempotent and non-destructive — existing `clientId` / `clientSecret` values\n * are preserved. Only `.ts`, `.mjs`, `.js` and `.cjs` configs are supported\n * (JSON cannot reference `process.env`).\n */\nexport const enableIntlayerEditorConfig = (content: string): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n genericRecastVisit(ast, (objExpr) => {\n if (!isObjectExpression(objExpr)) return;\n\n const editorProperty = ensureObjectProperty(\n objExpr,\n 'editor',\n b.objectExpression([])\n );\n\n if (!isObjectExpression(editorProperty.value)) return;\n\n const editorObject = editorProperty.value;\n\n setObjectPropertyValue(editorObject, 'enabled', b.booleanLiteral(true));\n addEnvReferenceProperty(editorObject, 'clientId', 'INTLAYER_CLIENT_ID');\n addEnvReferenceProperty(\n editorObject,\n 'clientSecret',\n 'INTLAYER_CLIENT_SECRET'\n );\n });\n\n return recast.print(ast).code;\n};\n\n/**\n * True when `statement` is one of the module's own import statements —\n * `import … from '…'` in ESM, `const … = require('…')` in CJS.\n */\nconst isImportStatement = (statement: any, isCJS: boolean): boolean => {\n if (!isCJS) return n.ImportDeclaration.check(statement);\n\n return (\n n.VariableDeclaration.check(statement) &&\n statement.declarations.some(\n (declarator: any) =>\n n.VariableDeclarator.check(declarator) &&\n n.CallExpression.check(declarator.init) &&\n n.Identifier.check(declarator.init.callee) &&\n declarator.init.callee.name === 'require'\n )\n );\n};\n\n/**\n * Adds `declaration` to the top of the module, after the leading import block\n * so the injected import is grouped with the existing ones.\n *\n * Unshifting blindly would push the file's leading comments down one\n * statement, which silently disables directives that only apply on the first\n * line — `// @ts-check`, present in the config Astro and Vite scaffold.\n */\nconst insertImportDeclaration = (\n ast: any,\n isCJS: boolean,\n declaration: any\n): void => {\n const body = ast.program.body;\n\n let insertionIndex = 0;\n while (\n insertionIndex < body.length &&\n isImportStatement(body[insertionIndex], isCJS)\n ) {\n insertionIndex++;\n }\n\n // No import to group with: keep the file's leading comments on the first\n // line by moving them onto the injected statement.\n if (insertionIndex === 0 && body.length > 0) {\n const leadingComments = (body[0].comments ?? []).filter(\n (comment: any) => comment.leading\n );\n\n if (leadingComments.length > 0) {\n body[0].comments = (body[0].comments ?? []).filter(\n (comment: any) => !comment.leading\n );\n declaration.comments = leadingComments;\n }\n }\n\n body.splice(insertionIndex, 0, declaration);\n};\n\nconst injectImport = (\n ast: any,\n isCJS: boolean,\n importName: string,\n source: string\n) => {\n // Never redeclare an identifier already bound at module scope (e.g. imported\n // from another source or declared locally) — that would be a parse error.\n if (!isCJS && isModuleScopeBinding(ast, importName)) return;\n\n const body = ast.program.body;\n const hasImport = body.some((stmt: any) => {\n if (isCJS) {\n return (\n n.VariableDeclaration.check(stmt) &&\n stmt.declarations.some(\n (decl: any) =>\n n.VariableDeclarator.check(decl) &&\n n.CallExpression.check(decl.init) &&\n n.Identifier.check(decl.init.callee) &&\n decl.init.callee.name === 'require' &&\n n.StringLiteral.check(decl.init.arguments[0]) &&\n decl.init.arguments[0].value === source\n )\n );\n }\n return (\n n.ImportDeclaration.check(stmt) &&\n (stmt.source.value === source ||\n stmt.specifiers?.some(\n (spec: any) =>\n (n.ImportSpecifier.check(spec) &&\n spec.imported.name === importName) ||\n (n.ImportDefaultSpecifier.check(spec) &&\n spec.local?.name === importName)\n ))\n );\n });\n\n if (hasImport) return;\n\n const declaration = isCJS\n ? b.variableDeclaration('const', [\n b.variableDeclarator(\n b.identifier(`{ ${importName} }`),\n b.callExpression(b.identifier('require'), [b.stringLiteral(source)])\n ),\n ])\n : b.importDeclaration(\n [b.importSpecifier(b.identifier(importName))],\n b.stringLiteral(source)\n );\n\n insertImportDeclaration(ast, isCJS, declaration);\n};\n\nconst updatePluginArray = (\n objExpr: any,\n propertyName: string,\n pluginName: string\n) => {\n if (\n !objExpr ||\n (objExpr.type !== 'ObjectExpression' && !n.ObjectExpression.check(objExpr))\n )\n return;\n\n let prop = objExpr.properties.find((p: any) => {\n if (!p?.key) return false;\n const keyName = p.key.name || p.key.value;\n return keyName === propertyName;\n }) as any;\n\n if (!prop) {\n prop = b.property(\n 'init',\n b.identifier(propertyName),\n b.arrayExpression([])\n );\n objExpr.properties.push(prop);\n }\n\n const arrayValue = prop.value;\n\n if (\n arrayValue &&\n (arrayValue.type === 'ArrayExpression' ||\n n.ArrayExpression.check(arrayValue))\n ) {\n const hasPlugin = arrayValue.elements.some((el: any) => {\n const callee = el?.callee;\n if (!callee) return false;\n const name = callee.name || callee.id?.name;\n return name === pluginName || name === 'il';\n });\n\n if (!hasPlugin) {\n arrayValue.elements.push(b.callExpression(b.identifier(pluginName), []));\n }\n }\n};\n\nconst genericRecastVisit = (\n ast: any,\n updateConfigObject: (obj: any) => void,\n callNames: string[] = ['defineConfig']\n) => {\n /**\n * Resolves an identifier reference (e.g. `export default config` /\n * `module.exports = config`) back to the object expression it was declared\n * with, then runs the updater on it.\n */\n const resolveIdentifierConfig = (name: string) => {\n ast.program.body.forEach((stmt: any) => {\n if (n.VariableDeclaration.check(stmt)) {\n stmt.declarations.forEach((vdecl: any) => {\n if (\n n.VariableDeclarator.check(vdecl) &&\n n.Identifier.check(vdecl.id) &&\n vdecl.id.name === name &&\n n.ObjectExpression.check(vdecl.init)\n ) {\n updateConfigObject(vdecl.init);\n }\n });\n }\n });\n };\n\n recast.visit(ast, {\n visitExportDefaultDeclaration(path) {\n const decl = path.node.declaration;\n\n if (n.ObjectExpression.check(decl)) {\n updateConfigObject(decl);\n } else if (\n n.CallExpression.check(decl) &&\n n.Identifier.check(decl.callee) &&\n callNames.includes(decl.callee.name)\n ) {\n if (n.ObjectExpression.check(decl.arguments[0])) {\n updateConfigObject(decl.arguments[0]);\n }\n } else if (n.Identifier.check(decl)) {\n resolveIdentifierConfig(decl.name);\n }\n return false;\n },\n visitAssignmentExpression(path) {\n const { left, right } = path.node;\n\n if (\n n.MemberExpression.check(left) &&\n recast.print(left).code === 'module.exports'\n ) {\n if (n.ObjectExpression.check(right)) {\n updateConfigObject(right);\n } else if (\n n.CallExpression.check(right) &&\n n.Identifier.check(right.callee) &&\n callNames.includes(right.callee.name)\n ) {\n if (n.ObjectExpression.check(right.arguments[0])) {\n updateConfigObject(right.arguments[0]);\n }\n } else if (n.Identifier.check(right)) {\n resolveIdentifierConfig(right.name);\n }\n }\n return false;\n },\n });\n};\n\n/**\n * Detects whether a Vite config already wires in an Intlayer plugin — either the\n * base `vite-intlayer` plugin or one of the compat adapters (e.g.\n * `reactI18nextVitePlugin` from `@intlayer/react-i18next/plugin`). The compat\n * plugins internally wrap `intlayer()`, so a standalone `intlayer()` must not be\n * appended when one is already present, otherwise the plugin runs twice.\n */\nexport const hasIntlayerVitePlugin = (content: string): boolean =>\n content.includes('vite-intlayer') ||\n /@intlayer\\/[^'\"]+\\/plugin/.test(content);\n\nexport const updateViteConfig = (\n content: string,\n extension: string\n): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const isCJSFile =\n extension === 'cjs' ||\n (content.includes('module.exports') && !content.includes('import '));\n\n injectImport(ast, isCJSFile, 'intlayer', 'vite-intlayer');\n\n genericRecastVisit(ast, (obj) =>\n updatePluginArray(obj, 'plugins', 'intlayer')\n );\n\n return recast.print(ast).code;\n};\n\nexport const updateAstroConfig = (\n content: string,\n extension: string\n): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const isCJSFile =\n extension === 'cjs' ||\n (content.includes('module.exports') && !content.includes('import '));\n\n injectImport(ast, isCJSFile, 'intlayer', 'astro-intlayer');\n\n genericRecastVisit(ast, (obj) =>\n updatePluginArray(obj, 'integrations', 'intlayer')\n );\n\n return recast.print(ast).code;\n};\n\nexport const updateNextConfig = (\n content: string,\n extension: string\n): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const isCJSFile = extension === 'cjs' || content.includes('module.exports');\n\n injectImport(ast, isCJSFile, 'withIntlayer', 'next-intlayer/server');\n\n recast.visit(ast, {\n visitExportDefaultDeclaration(path) {\n const declaration = path.node.declaration;\n if (\n n.Expression.check(declaration) &&\n !(\n n.CallExpression.check(declaration) &&\n n.Identifier.check(declaration.callee) &&\n declaration.callee.name === 'withIntlayer'\n )\n ) {\n path\n .get('declaration')\n .replace(\n b.callExpression(b.identifier('withIntlayer'), [declaration as any])\n );\n }\n return false;\n },\n visitAssignmentExpression(path) {\n const { left, right } = path.node;\n\n if (\n n.MemberExpression.check(left) &&\n recast.print(left).code === 'module.exports' &&\n !(\n n.CallExpression.check(right) &&\n n.Identifier.check(right.callee) &&\n right.callee.name === 'withIntlayer'\n )\n ) {\n path\n .get('right')\n .replace(b.callExpression(b.identifier('withIntlayer'), [right]));\n }\n return false;\n },\n });\n\n return recast.print(ast).code;\n};\n\n/**\n * Returns true when the expression looks like an Immediately Invoked Function\n * Expression (e.g. `(async () => { ... })()`). Such custom async exports cannot\n * be safely wrapped with the synchronous Metro helper, so they are skipped.\n */\nconst isImmediatelyInvokedFunction = (node: any): boolean =>\n n.CallExpression.check(node) &&\n (n.ArrowFunctionExpression.check(node.callee) ||\n n.FunctionExpression.check(node.callee));\n\n/**\n * Wraps a React Native Metro config's exported value with\n * `configMetroIntlayerSync` from `react-native-intlayer/metro`, injecting the\n * import. The synchronous helper is used because it wraps a plain config object\n * and needs no IIFE, making it safe to inject into existing configs without\n * restructuring them.\n *\n * Non-destructive: returns the content unchanged when the export is already\n * wrapped, when the Intlayer Metro plugin is already present, or when the export\n * is a custom async IIFE that cannot be wrapped synchronously. Callers should\n * compare the result with the input to detect the skipped case.\n */\nexport const updateMetroConfig = (\n content: string,\n extension: string\n): string => {\n if (content.includes('react-native-intlayer')) {\n return content;\n }\n\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const isCJSFile =\n extension === 'cjs' ||\n (content.includes('module.exports') && !content.includes('import '));\n\n const wrapperName = 'configMetroIntlayerSync';\n\n const isWrappable = (node: any): boolean =>\n n.Expression.check(node) &&\n !isImmediatelyInvokedFunction(node) &&\n !(\n n.CallExpression.check(node) &&\n n.Identifier.check(node.callee) &&\n node.callee.name === wrapperName\n );\n\n let wrapped = false;\n\n recast.visit(ast, {\n visitExportDefaultDeclaration(path) {\n const declaration = path.node.declaration;\n if (isWrappable(declaration)) {\n path\n .get('declaration')\n .replace(\n b.callExpression(b.identifier(wrapperName), [declaration as any])\n );\n wrapped = true;\n }\n return false;\n },\n visitAssignmentExpression(path) {\n const { left, right } = path.node;\n\n if (\n n.MemberExpression.check(left) &&\n recast.print(left).code === 'module.exports' &&\n isWrappable(right)\n ) {\n path\n .get('right')\n .replace(b.callExpression(b.identifier(wrapperName), [right]));\n wrapped = true;\n }\n return false;\n },\n });\n\n // Only inject the import when an export was actually wrapped, so an\n // un-wrappable config is left completely untouched.\n if (!wrapped) {\n return content;\n }\n\n injectImport(ast, isCJSFile, wrapperName, 'react-native-intlayer/metro');\n\n return recast.print(ast).code;\n};\n\n/**\n * Builds the contents of a fresh `metro.config.js` wired with the Intlayer\n * Metro plugin. Uses the async `configMetroIntlayer` helper (which can build\n * dictionaries on server start) and picks the default-config source based on\n * whether the project is an Expo app.\n */\nexport const getMetroConfigTemplate = (isExpo: boolean): string => {\n const defaultConfigSource = isExpo\n ? 'expo/metro-config'\n : '@react-native/metro-config';\n\n return `const { getDefaultConfig } = require(\"${defaultConfigSource}\");\nconst { configMetroIntlayer } = require(\"react-native-intlayer/metro\");\n\nmodule.exports = (async () => {\n const defaultConfig = getDefaultConfig(__dirname);\n\n return await configMetroIntlayer(defaultConfig);\n})();\n`;\n};\n\nexport const updateNuxtConfig = (content: string): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const updateConfigObject = (objExpr: any) => {\n if (\n !objExpr ||\n (objExpr.type !== 'ObjectExpression' &&\n !n.ObjectExpression.check(objExpr))\n )\n return;\n\n let modulesProp = objExpr.properties.find((p: any) => {\n if (!p?.key) return false;\n const keyName = p.key.name || p.key.value;\n return keyName === 'modules';\n }) as any;\n\n if (!modulesProp) {\n modulesProp = b.property(\n 'init',\n b.identifier('modules'),\n b.arrayExpression([])\n );\n objExpr.properties.push(modulesProp);\n }\n\n const modulesValue = modulesProp.value;\n\n if (\n modulesValue &&\n (modulesValue.type === 'ArrayExpression' ||\n n.ArrayExpression.check(modulesValue))\n ) {\n const hasModule = modulesValue.elements.some((el: any) => {\n if (\n n.StringLiteral.check(el) ||\n el.type === 'StringLiteral' ||\n el.type === 'Literal'\n ) {\n return (el.value || el.extra?.rawValue) === 'nuxt-intlayer';\n }\n return false;\n });\n\n if (!hasModule) {\n modulesValue.elements.push(b.stringLiteral('nuxt-intlayer'));\n }\n }\n };\n\n genericRecastVisit(ast, updateConfigObject, ['defineNuxtConfig']);\n\n return recast.print(ast).code;\n};\n\n/**\n * Updates a Vite config for vue-i18n compat: injects `vueI18nVitePlugin` from\n * `@intlayer/vue-i18n/plugin` into the plugins array.\n */\nexport const updateViteConfigForVueI18n = (\n content: string,\n extension: string\n): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const isCJSFile =\n extension === 'cjs' ||\n (content.includes('module.exports') && !content.includes('import '));\n\n injectImport(\n ast,\n isCJSFile,\n 'vueI18nVitePlugin',\n '@intlayer/vue-i18n/plugin'\n );\n\n genericRecastVisit(ast, (obj) =>\n updatePluginArray(obj, 'plugins', 'vueI18nVitePlugin')\n );\n\n return recast.print(ast).code;\n};\n\n/**\n * Generic vite config updater for any compat plugin that uses alias injection.\n * Injects the named import from `pluginPackageSource` and appends the plugin\n * call to the `plugins` array.\n */\nexport const updateViteConfigForCompatPlugin = (\n content: string,\n extension: string,\n pluginConfig: CompatVitePluginConfig\n): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const isCJSFile =\n extension === 'cjs' ||\n (content.includes('module.exports') && !content.includes('import '));\n\n injectImport(\n ast,\n isCJSFile,\n pluginConfig.pluginFunctionName,\n pluginConfig.pluginPackageSource\n );\n\n genericRecastVisit(ast, (obj) =>\n updatePluginArray(obj, 'plugins', pluginConfig.pluginFunctionName)\n );\n\n return recast.print(ast).code;\n};\n\n/**\n * Rewrites the module source of an existing named import in a vite config,\n * keeping the imported binding and its call site untouched. Used when a compat\n * plugin is a drop-in replacement for an i18n library's own vite plugin — e.g.\n * lingui: `import { lingui } from \"@lingui/vite-plugin\"` becomes\n * `import { lingui } from \"@intlayer/lingui/plugin\"`, leaving `lingui()` in the\n * `plugins` array as-is. Returns the content unchanged when no matching import\n * is found.\n */\nexport const replaceViteConfigPluginImportSource = (\n content: string,\n importName: string,\n fromPackageSource: string,\n toPackageSource: string\n): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n let changed = false;\n\n recast.visit(ast, {\n visitImportDeclaration(path) {\n const { source, specifiers } = path.node;\n const importsBinding = (specifiers ?? []).some(\n (specifier) =>\n n.ImportSpecifier.check(specifier) &&\n specifier.imported.name === importName\n );\n\n if (\n n.StringLiteral.check(source) &&\n source.value === fromPackageSource &&\n importsBinding\n ) {\n source.value = toPackageSource;\n changed = true;\n }\n\n return false;\n },\n });\n\n if (!changed) return content;\n return recast.print(ast).code;\n};\n\n/**\n * Generic Next.js config wrapper for compat plugins. Injects the import and\n * wraps the default export / `module.exports` with a HOC call.\n */\nconst wrapNextConfigWithHoc = (\n content: string,\n extension: string,\n hocFunctionName: string,\n pluginPackageSource: string\n): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const isCJSFile = extension === 'cjs' || content.includes('module.exports');\n\n injectImport(ast, isCJSFile, hocFunctionName, pluginPackageSource);\n\n recast.visit(ast, {\n visitExportDefaultDeclaration(path) {\n const declaration = path.node.declaration;\n if (\n n.Expression.check(declaration) &&\n !(\n n.CallExpression.check(declaration) &&\n n.Identifier.check(declaration.callee) &&\n declaration.callee.name === hocFunctionName\n )\n ) {\n path\n .get('declaration')\n .replace(\n b.callExpression(b.identifier(hocFunctionName), [\n declaration as any,\n ])\n );\n }\n return false;\n },\n visitAssignmentExpression(path) {\n const { left, right } = path.node;\n\n if (\n n.MemberExpression.check(left) &&\n recast.print(left).code === 'module.exports' &&\n !(\n n.CallExpression.check(right) &&\n n.Identifier.check(right.callee) &&\n right.callee.name === hocFunctionName\n )\n ) {\n path\n .get('right')\n .replace(b.callExpression(b.identifier(hocFunctionName), [right]));\n }\n return false;\n },\n });\n\n return recast.print(ast).code;\n};\n\n/**\n * Updates a Next.js config for next-translate compat: wraps the default export\n * with `withNextTranslate` from `@intlayer/next-translate/plugin`.\n */\nexport const updateNextConfigForNextTranslate = (\n content: string,\n extension: string\n): string =>\n wrapNextConfigWithHoc(\n content,\n extension,\n 'withNextTranslate',\n '@intlayer/next-translate/plugin'\n );\n\n/**\n * Updates a Nuxt config for nuxtjs-i18n compat: adds `@intlayer/nuxtjs-i18n`\n * to the `modules` array.\n */\nexport const updateNuxtConfigForNuxtjsI18n = (content: string): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const updateConfigObject = (objExpr: any) => {\n if (\n !objExpr ||\n (objExpr.type !== 'ObjectExpression' &&\n !n.ObjectExpression.check(objExpr))\n )\n return;\n\n let modulesProp = (objExpr.properties as any[]).find((p: any) => {\n if (!p?.key) return false;\n const keyName = p.key.name || p.key.value;\n return keyName === 'modules';\n }) as any;\n\n if (!modulesProp) {\n modulesProp = b.property(\n 'init',\n b.identifier('modules'),\n b.arrayExpression([])\n );\n (objExpr.properties as any[]).push(modulesProp);\n }\n\n const modulesValue = modulesProp.value;\n\n if (\n modulesValue &&\n (modulesValue.type === 'ArrayExpression' ||\n n.ArrayExpression.check(modulesValue))\n ) {\n const hasModule = (modulesValue.elements as any[]).some((el: any) => {\n if (\n n.StringLiteral.check(el) ||\n el.type === 'StringLiteral' ||\n el.type === 'Literal'\n ) {\n return (el.value ?? el.extra?.rawValue) === '@intlayer/nuxtjs-i18n';\n }\n return false;\n });\n\n if (!hasModule) {\n (modulesValue.elements as any[]).push(\n b.stringLiteral('@intlayer/nuxtjs-i18n')\n );\n }\n }\n };\n\n genericRecastVisit(ast, updateConfigObject, ['defineNuxtConfig']);\n\n return recast.print(ast).code;\n};\n\n/**\n * Updates a Next.js config for next-i18next compat: wraps the default export\n * with `withI18next` from `@intlayer/next-i18next/plugin`.\n */\nexport const updateNextConfigForNextI18next = (\n content: string,\n extension: string\n): string =>\n wrapNextConfigWithHoc(\n content,\n extension,\n 'withI18next',\n '@intlayer/next-i18next/plugin'\n );\n\n/**\n * Updates a Next.js config for next-intl compat: replaces any existing\n * `next-intl/plugin` import source with `@intlayer/next-intl/plugin`, or\n * injects `createNextIntlPlugin` with a factory-call wrapper when no such\n * import is present.\n */\nexport const updateNextConfigForNextIntl = (\n content: string,\n extension: string\n): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const isCJSFile = extension === 'cjs' || content.includes('module.exports');\n let replacedExistingSource = false;\n\n // Replace 'next-intl/plugin' import source with the compat package.\n recast.visit(ast, {\n visitImportDeclaration(path) {\n if (path.node.source.value === 'next-intl/plugin') {\n path.node.source = b.stringLiteral('@intlayer/next-intl/plugin');\n replacedExistingSource = true;\n }\n return false;\n },\n });\n\n if (replacedExistingSource) {\n return recast.print(ast).code;\n }\n\n // No existing next-intl/plugin import: check whether createNextIntlPlugin is\n // already present from any source before injecting the full factory pattern.\n const hasCreatePlugin = (ast.program.body as any[]).some((stmt: any) => {\n if (!n.ImportDeclaration.check(stmt)) return false;\n return (stmt.specifiers ?? []).some(\n (spec: any) =>\n (n.ImportSpecifier.check(spec) &&\n spec.imported.name === 'createNextIntlPlugin') ||\n (n.ImportDefaultSpecifier.check(spec) &&\n spec.local?.name === 'createNextIntlPlugin')\n );\n });\n\n if (hasCreatePlugin) {\n return recast.print(ast).code;\n }\n\n // Inject the import.\n injectImport(\n ast,\n isCJSFile,\n 'createNextIntlPlugin',\n '@intlayer/next-intl/plugin'\n );\n\n // Insert a factory-call variable declaration after the last import.\n const lastImportIndex = (ast.program.body as any[]).reduce(\n (lastIndex: number, stmt: any, index: number) => {\n if (n.ImportDeclaration.check(stmt)) return index;\n return lastIndex;\n },\n -1\n );\n\n const factoryCallDeclaration = b.variableDeclaration('const', [\n b.variableDeclarator(\n b.identifier('_withNextIntlayer'),\n b.callExpression(b.identifier('createNextIntlPlugin'), [])\n ),\n ]);\n\n (ast.program.body as any[]).splice(\n lastImportIndex + 1,\n 0,\n factoryCallDeclaration\n );\n\n // Wrap the default export with _withNextIntlayer(...).\n recast.visit(ast, {\n visitExportDefaultDeclaration(path) {\n const declaration = path.node.declaration;\n if (\n n.Expression.check(declaration) &&\n !(\n n.CallExpression.check(declaration) &&\n n.Identifier.check(declaration.callee) &&\n declaration.callee.name === '_withNextIntlayer'\n )\n ) {\n path\n .get('declaration')\n .replace(\n b.callExpression(b.identifier('_withNextIntlayer'), [\n declaration as any,\n ])\n );\n }\n return false;\n },\n visitAssignmentExpression(path) {\n const { left, right } = path.node;\n\n if (\n n.MemberExpression.check(left) &&\n recast.print(left).code === 'module.exports' &&\n !(\n n.CallExpression.check(right) &&\n n.Identifier.check(right.callee) &&\n right.callee.name === '_withNextIntlayer'\n )\n ) {\n path\n .get('right')\n .replace(\n b.callExpression(b.identifier('_withNextIntlayer'), [right])\n );\n }\n return false;\n },\n });\n\n return recast.print(ast).code;\n};\n\n/** The sync plugin used to ingest a compat library's catalogs. */\ntype SyncPluginInfo = {\n /** Called function name, e.g. `'syncJSON'`. */\n functionName: string;\n /** Package the function is imported from. */\n packageSource: string;\n};\n\n/** Resolves the sync plugin (function + package) for a compat sync config. */\nconst getSyncPluginInfo = (syncConfig: CompatSyncConfig): SyncPluginInfo =>\n syncConfig.plugin === 'po'\n ? { functionName: 'syncPO', packageSource: '@intlayer/sync-po-plugin' }\n : { functionName: 'syncJSON', packageSource: '@intlayer/sync-json-plugin' };\n\n/**\n * Parses a `syncJSON({ ... })` / `syncPO({ ... })` call expression from a source\n * snippet so it can be injected into a config AST without manually constructing\n * template-literal nodes via builders.\n *\n * The destructuring parameters adapt to whether the source template uses the\n * `key` placeholder (nested pattern) or only `locale` (flat pattern).\n *\n * For `syncJSON` every option is emitted explicitly — `source`, then `format`\n * and `splitKeys` — each preceded by an explanatory JSDoc block, so the\n * generated config self-documents the two knobs a user is most likely to tweak.\n * `syncPO` takes neither `format` (gettext is always the serialization) nor\n * `splitKeys`, so it keeps a bare `source`-only call.\n */\nconst buildSyncCallNode = (syncConfig: CompatSyncConfig): any => {\n const { functionName } = getSyncPluginInfo(syncConfig);\n const usesKey = syncConfig.sourceTemplate.includes('${key}');\n const paramDestructuring = !usesKey\n ? '{ locale }'\n : // `icu` (and PO, which is ICU-dialect) reads `{ key, locale }`; the\n // i18next/vue-i18n JSON dialects keep their established `{ locale, key }`.\n syncConfig.format === 'icu' || syncConfig.plugin === 'po'\n ? '{ key, locale }'\n : '{ locale, key }';\n\n // The sourceTemplate contains ${locale} / ${key} as literal characters;\n // they become proper template expressions once the snippet is parsed by recast.\n const sourceProperty = `source: (${paramDestructuring}) => \\`${syncConfig.sourceTemplate}\\``;\n\n const parseSnippet = (snippet: string): any => {\n const snippetAst = recast.parse(snippet, {\n parser: typescriptParser,\n });\n return (snippetAst.program.body[0] as any).expression;\n };\n\n // `syncPO` always serializes gettext, so it exposes neither `format` nor\n // `splitKeys`: emit a bare `source`-only call.\n if (syncConfig.plugin === 'po') {\n return parseSnippet(`${functionName}({ ${sourceProperty} })`);\n }\n\n // `splitKeys: true` is forced only for the single-file namespace model\n // (next-intl / use-intl); every other library keeps a single dictionary per\n // file. It is now written explicitly (rather than relying on syncJSON's\n // auto-detection) so the generated config documents the choice.\n const splitKeys = Boolean(syncConfig.splitKeys);\n\n // The JSDoc blocks are embedded in the snippet and preserved by recast when\n // the parsed call node is printed back into the config AST.\n const snippet = `${functionName}({\n ${sourceProperty},\n\n /**\n * Parsing of json respecting the syntax\n * Default \\`'intlayer'\\` message format\n */\n format: '${syncConfig.format}',\n\n /**\n * \\`true\\`:\n * \\`en.json\\` -> \\`useTranslation('home')\\` -> \\`t(\"title\")\\`\n *\n * \\`false\\`:\n * \\`en.json\\` -> \\`useTranslation()\\` -> \\`t(\"home.title\")\\`\n */\n splitKeys: ${splitKeys},\n})`;\n\n return parseSnippet(snippet);\n};\n\n/**\n * Injects or ensures `dictionary: { format: '<value>' }` exists in an object\n * expression. Leaves any pre-existing `dictionary` properties untouched —\n * only the `format` sub-property is added when absent.\n */\nconst injectDictionaryFormat = (objExpr: any, format: string): void => {\n if (\n !objExpr ||\n (objExpr.type !== 'ObjectExpression' && !n.ObjectExpression.check(objExpr))\n )\n return;\n\n let dictionaryProp = (objExpr.properties as any[]).find((prop: any) => {\n if (!prop?.key) return false;\n return (prop.key.name ?? prop.key.value) === 'dictionary';\n });\n\n if (!dictionaryProp) {\n dictionaryProp = b.property(\n 'init',\n b.identifier('dictionary'),\n b.objectExpression([])\n );\n (objExpr.properties as any[]).push(dictionaryProp);\n }\n\n const dictionaryObj = dictionaryProp.value;\n if (\n !dictionaryObj ||\n (dictionaryObj.type !== 'ObjectExpression' &&\n !n.ObjectExpression.check(dictionaryObj))\n )\n return;\n\n const hasFormat = (dictionaryObj.properties as any[]).some((prop: any) => {\n if (!prop?.key) return false;\n return (prop.key.name ?? prop.key.value) === 'format';\n });\n\n if (!hasFormat) {\n (dictionaryObj.properties as any[]).push(\n b.property('init', b.identifier('format'), b.stringLiteral(format))\n );\n }\n};\n\n/**\n * Injects the sync plugin import (`syncJSON` / `syncPO`) and a configured\n * `syncJSON(...)` / `syncPO(...)` call into the plugins array of an intlayer\n * config file. Idempotent: skips when the plugin call is already present.\n */\nexport const updateIntlayerConfigWithSyncPlugin = (\n content: string,\n extension: string,\n syncConfig: CompatSyncConfig\n): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const isCJSFile = extension === 'cjs' || content.includes('module.exports');\n\n const { functionName, packageSource } = getSyncPluginInfo(syncConfig);\n\n injectImport(ast, isCJSFile, functionName, packageSource);\n\n const callNode = buildSyncCallNode(syncConfig);\n\n // PO catalogs are serialized as gettext; JSON catalogs carry the dialect.\n const dictionaryFormat =\n syncConfig.plugin === 'po' ? 'po' : syncConfig.format;\n\n genericRecastVisit(ast, (objExpr) => {\n if (\n !objExpr ||\n (objExpr.type !== 'ObjectExpression' &&\n !n.ObjectExpression.check(objExpr))\n )\n return;\n\n // Inject dictionary.format alongside the plugin so intlayer knows how to\n // interpret dictionary content at runtime.\n injectDictionaryFormat(objExpr, dictionaryFormat);\n\n let pluginsProp = (objExpr.properties as any[]).find((prop: any) => {\n if (!prop?.key) return false;\n const keyName = prop.key.name ?? prop.key.value;\n return keyName === 'plugins';\n });\n\n if (!pluginsProp) {\n pluginsProp = b.property(\n 'init',\n b.identifier('plugins'),\n b.arrayExpression([])\n );\n (objExpr.properties as any[]).push(pluginsProp);\n }\n\n const arrayValue = pluginsProp.value;\n\n if (\n arrayValue &&\n (arrayValue.type === 'ArrayExpression' ||\n n.ArrayExpression.check(arrayValue))\n ) {\n const hasSyncPlugin = (arrayValue.elements as any[]).some(\n (element: any) => {\n const callee = element?.callee;\n if (!callee) return false;\n const name: string = callee.name ?? callee.id?.name;\n return name === functionName;\n }\n );\n\n if (!hasSyncPlugin) {\n (arrayValue.elements as any[]).push(callNode);\n }\n }\n });\n\n return recast.print(ast).code;\n};\n"],"mappings":";;;;;;;;AASA,MAAM,EAAE,UAAU,GAAG,YAAY,MAAM,OAAO;;AAM9C,MAAM,sBAAsB,SAC1B,QAAQ,IAAI,MACX,KAAK,SAAS,sBAAsB,EAAE,iBAAiB,MAAM,IAAI;;;;;;AAOpE,MAAM,wBACJ,SACA,KACA,qBACQ;CACR,IAAI,WAAY,QAAQ,WAAqB,MAAM,SAAc;EAC/D,IAAI,CAAC,MAAM,KAAK,OAAO;EACvB,QAAQ,KAAK,IAAI,QAAQ,KAAK,IAAI,WAAW;CAC/C,CAAC;CAED,IAAI,CAAC,UAAU;EACb,WAAW,EAAE,SAAS,QAAQ,EAAE,WAAW,GAAG,GAAG,gBAAgB;EACjE,AAAC,QAAQ,WAAqB,KAAK,QAAQ;CAC7C;CAEA,OAAO;AACT;;;;;;AAOA,MAAM,0BACJ,SACA,KACA,cACS;CACT,MAAM,WAAY,QAAQ,WAAqB,MAA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ATmB,WAAW,SAAmB,MAClD,YAAiB;IAChB,MAAM,SAAS,SAAS;IACxB,IAAI,CAAC,QAAQ,OAAO;IAEpB,QADqB,OAAO,QAAQ,OAAO,IAAI,UAC/B;GAClB,CAGe,GACf,AAAC,WAAW,SAAmB,KAAK,QAAQ;EAC9C;CAEJ,CAAC;CAED,OAAO,OAAO,MAAM,GAAG,CAAC,CAAC;AAC3B"}
1
+ {"version":3,"file":"configManipulation.cjs","names":["typescriptParser","isModuleScopeBinding"],"sources":["../../../../src/init/utils/configManipulation.ts"],"sourcesContent":["import type { RoutingConfig } from '@intlayer/types/config';\nimport * as recast from 'recast';\nimport { typescriptParser } from '../../utils/babelParser';\nimport { isModuleScopeBinding } from './astImports';\nimport type {\n CompatSyncConfig,\n CompatVitePluginConfig,\n} from './packageManager';\n\nconst { builders: b, namedTypes: n } = recast.types;\n\n/** The locale routing strategies supported by the Intlayer configuration. */\nexport type RoutingMode = RoutingConfig['mode'];\n\n/** Narrows an arbitrary recast node to an object expression. */\nconst isObjectExpression = (node: any): boolean =>\n Boolean(node) &&\n (node.type === 'ObjectExpression' || n.ObjectExpression.check(node));\n\n/**\n * Finds a property by key name on an object expression, creating it with the\n * provided default value node when it is absent. Returns the property node so\n * callers can read or mutate its value while preserving any attached comments.\n */\nconst ensureObjectProperty = (\n objExpr: any,\n key: string,\n defaultValueNode: any\n): any => {\n let property = (objExpr.properties as any[]).find((prop: any) => {\n if (!prop?.key) return false;\n return (prop.key.name ?? prop.key.value) === key;\n });\n\n if (!property) {\n property = b.property('init', b.identifier(key), defaultValueNode);\n (objExpr.properties as any[]).push(property);\n }\n\n return property;\n};\n\n/**\n * Sets (or replaces) a property's value on an object expression. When the\n * property already exists only its value node is swapped, which keeps the\n * leading documentation comment in place.\n */\nconst setObjectPropertyValue = (\n objExpr: any,\n key: string,\n valueNode: any\n): void => {\n const property = (objExpr.properties as any[]).find((prop: any) => {\n if (!prop?.key) return false;\n return (prop.key.name ?? prop.key.value) === key;\n });\n\n if (property) {\n property.value = valueNode;\n return;\n }\n\n (objExpr.properties as any[]).push(\n b.property('init', b.identifier(key), valueNode)\n );\n};\n\n/**\n * Adds a `process.env.<envVar>` reference property to an object expression when\n * the property is not already present. Existing values are left untouched.\n */\nconst addEnvReferenceProperty = (\n objExpr: any,\n key: string,\n envVar: string\n): void => {\n const hasProperty = (objExpr.properties as any[]).some((prop: any) => {\n if (!prop?.key) return false;\n return (prop.key.name ?? prop.key.value) === key;\n });\n\n if (hasProperty) return;\n\n (objExpr.properties as any[]).push(\n b.property(\n 'init',\n b.identifier(key),\n b.memberExpression(\n b.memberExpression(b.identifier('process'), b.identifier('env')),\n b.identifier(envVar)\n )\n )\n );\n};\n\n/**\n * Sets `routing.mode` in an Intlayer configuration file to the requested\n * strategy. Idempotent: re-running with the same mode produces identical\n * output. Supports `.ts`, `.mjs`, `.js` and `.cjs` configs; JSON configs are\n * handled with a scoped string replacement since they cannot be parsed by the\n * TypeScript recast parser.\n */\nexport const setIntlayerConfigRoutingMode = (\n content: string,\n extension: string,\n mode: RoutingMode\n): string => {\n if (extension === 'json') {\n return content.replace(\n /(\"mode\"\\s*:\\s*)\"(?:prefix-no-default|prefix-all|no-prefix|search-params)\"/,\n `$1\"${mode}\"`\n );\n }\n\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n genericRecastVisit(ast, (objExpr) => {\n if (!isObjectExpression(objExpr)) return;\n\n const routingProperty = ensureObjectProperty(\n objExpr,\n 'routing',\n b.objectExpression([])\n );\n\n if (!isObjectExpression(routingProperty.value)) return;\n\n setObjectPropertyValue(\n routingProperty.value,\n 'mode',\n b.stringLiteral(mode)\n );\n });\n\n return recast.print(ast).code;\n};\n\n/**\n * Sets `routing.enableProxy` in an Intlayer configuration file. Idempotent and\n * comment-preserving: an existing property only has its value swapped. Supports\n * `.ts`, `.mjs`, `.js`, `.cjs` and `.json` configs.\n */\nexport const setIntlayerConfigEnableProxy = (\n content: string,\n extension: string,\n enableProxy: boolean\n): string => {\n // The JSON template carries comments, so a scoped replacement is used rather\n // than `JSON.parse`.\n if (extension === 'json') {\n return content.replace(\n /(\"enableProxy\"\\s*:\\s*)(?:true|false)/,\n `$1${enableProxy}`\n );\n }\n\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n genericRecastVisit(ast, (objExpr) => {\n if (!isObjectExpression(objExpr)) return;\n\n const routingProperty = ensureObjectProperty(\n objExpr,\n 'routing',\n b.objectExpression([])\n );\n\n if (!isObjectExpression(routingProperty.value)) return;\n\n setObjectPropertyValue(\n routingProperty.value,\n 'enableProxy',\n b.booleanLiteral(enableProxy)\n );\n });\n\n return recast.print(ast).code;\n};\n\n/** Default `routing.storage` written when the routing section is reduced. */\nconst DEFAULT_ROUTING_STORAGE = ['cookie', 'header'] as const;\n\n/**\n * Reduces `routing` in an Intlayer configuration file to its `storage` entry,\n * for projects without URL routing (backend-only, React Native…) where the\n * routing mode and the locale proxy have no effect. An existing `storage`\n * value is kept; otherwise `['cookie', 'header']` is written. JSON configs are\n * returned unchanged.\n */\nexport const setIntlayerConfigRoutingStorageOnly = (\n content: string,\n extension: string\n): string => {\n if (extension === 'json') return content;\n\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n genericRecastVisit(ast, (objExpr) => {\n if (!isObjectExpression(objExpr)) return;\n\n const routingProperty = ensureObjectProperty(\n objExpr,\n 'routing',\n b.objectExpression([])\n );\n\n if (!isObjectExpression(routingProperty.value)) return;\n\n const existingStorageProperty = (\n routingProperty.value.properties as any[]\n ).find((prop: any) => (prop?.key?.name ?? prop?.key?.value) === 'storage');\n\n const storageProperty =\n existingStorageProperty ??\n b.property(\n 'init',\n b.identifier('storage'),\n b.arrayExpression(\n DEFAULT_ROUTING_STORAGE.map((storage) => b.stringLiteral(storage))\n )\n );\n\n routingProperty.value.properties = [storageProperty];\n });\n\n return recast.print(ast, { tabWidth: 2 }).code;\n};\n\n/**\n * Sets `compiler.output` in an Intlayer configuration file to the given path\n * template (the `{{variable}}` string form, e.g.\n * `/locales/{{locale}}/{{key}}.content.json`). Idempotent: re-running with the\n * same template produces identical output. Supports `.ts`, `.mjs`, `.js` and\n * `.cjs` configs; JSON configs are supported too since the template is a plain\n * string.\n */\nexport const setIntlayerConfigCompilerOutput = (\n content: string,\n extension: string,\n outputTemplate: string\n): string => {\n if (extension === 'json') {\n const parsed = JSON.parse(content);\n parsed.compiler = { ...parsed.compiler, output: outputTemplate };\n return JSON.stringify(parsed, null, 2);\n }\n\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n genericRecastVisit(ast, (objExpr) => {\n if (!isObjectExpression(objExpr)) return;\n\n const compilerProperty = ensureObjectProperty(\n objExpr,\n 'compiler',\n b.objectExpression([])\n );\n\n if (!isObjectExpression(compilerProperty.value)) return;\n\n setObjectPropertyValue(\n compilerProperty.value,\n 'output',\n b.stringLiteral(outputTemplate)\n );\n });\n\n return recast.print(ast).code;\n};\n\n/**\n * Sets `dictionary.locale` in an Intlayer configuration file to the configured\n * `internationalization.defaultLocale`, making new content declarations\n * per-locale. The default locale expression is copied as-is (e.g.\n * `Locales.ENGLISH`), falling back to `'en'` when it cannot be read.\n * Idempotent. Supports `.ts`, `.mjs`, `.js`, `.cjs` and `.json` configs.\n */\nexport const setIntlayerConfigDictionaryLocale = (\n content: string,\n extension: string\n): string => {\n if (extension === 'json') {\n const parsed = JSON.parse(content);\n parsed.dictionary = {\n ...parsed.dictionary,\n locale: parsed.internationalization?.defaultLocale ?? 'en',\n };\n return JSON.stringify(parsed, null, 2);\n }\n\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n genericRecastVisit(ast, (objExpr) => {\n if (!isObjectExpression(objExpr)) return;\n\n const internationalizationValue = (objExpr.properties as any[]).find(\n (prop: any) =>\n (prop?.key?.name ?? prop?.key?.value) === 'internationalization'\n )?.value;\n\n const defaultLocaleNode = isObjectExpression(internationalizationValue)\n ? (internationalizationValue.properties as any[]).find(\n (prop: any) =>\n (prop?.key?.name ?? prop?.key?.value) === 'defaultLocale'\n )?.value\n : undefined;\n\n const dictionaryProperty = ensureObjectProperty(\n objExpr,\n 'dictionary',\n b.objectExpression([])\n );\n\n if (!isObjectExpression(dictionaryProperty.value)) return;\n\n setObjectPropertyValue(\n dictionaryProperty.value,\n 'locale',\n defaultLocaleNode ?? b.stringLiteral('en')\n );\n });\n\n return recast.print(ast).code;\n};\n\n/**\n * Enables the Intlayer visual editor in a configuration file: sets\n * `editor.enabled` to `true` and wires `clientId` / `clientSecret` to the\n * `INTLAYER_CLIENT_ID` / `INTLAYER_CLIENT_SECRET` environment variables.\n * Idempotent and non-destructive — existing `clientId` / `clientSecret` values\n * are preserved. Only `.ts`, `.mjs`, `.js` and `.cjs` configs are supported\n * (JSON cannot reference `process.env`).\n */\nexport const enableIntlayerEditorConfig = (content: string): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n genericRecastVisit(ast, (objExpr) => {\n if (!isObjectExpression(objExpr)) return;\n\n const editorProperty = ensureObjectProperty(\n objExpr,\n 'editor',\n b.objectExpression([])\n );\n\n if (!isObjectExpression(editorProperty.value)) return;\n\n const editorObject = editorProperty.value;\n\n setObjectPropertyValue(editorObject, 'enabled', b.booleanLiteral(true));\n addEnvReferenceProperty(editorObject, 'clientId', 'INTLAYER_CLIENT_ID');\n addEnvReferenceProperty(\n editorObject,\n 'clientSecret',\n 'INTLAYER_CLIENT_SECRET'\n );\n });\n\n return recast.print(ast).code;\n};\n\n/**\n * True when `statement` is one of the module's own import statements —\n * `import … from '…'` in ESM, `const … = require('…')` in CJS.\n */\nconst isImportStatement = (statement: any, isCJS: boolean): boolean => {\n if (!isCJS) return n.ImportDeclaration.check(statement);\n\n return (\n n.VariableDeclaration.check(statement) &&\n statement.declarations.some(\n (declarator: any) =>\n n.VariableDeclarator.check(declarator) &&\n n.CallExpression.check(declarator.init) &&\n n.Identifier.check(declarator.init.callee) &&\n declarator.init.callee.name === 'require'\n )\n );\n};\n\n/**\n * Adds `declaration` to the top of the module, after the leading import block\n * so the injected import is grouped with the existing ones.\n *\n * Unshifting blindly would push the file's leading comments down one\n * statement, which silently disables directives that only apply on the first\n * line — `// @ts-check`, present in the config Astro and Vite scaffold.\n */\nconst insertImportDeclaration = (\n ast: any,\n isCJS: boolean,\n declaration: any\n): void => {\n const body = ast.program.body;\n\n let insertionIndex = 0;\n while (\n insertionIndex < body.length &&\n isImportStatement(body[insertionIndex], isCJS)\n ) {\n insertionIndex++;\n }\n\n // No import to group with: keep the file's leading comments on the first\n // line by moving them onto the injected statement.\n if (insertionIndex === 0 && body.length > 0) {\n const leadingComments = (body[0].comments ?? []).filter(\n (comment: any) => comment.leading\n );\n\n if (leadingComments.length > 0) {\n body[0].comments = (body[0].comments ?? []).filter(\n (comment: any) => !comment.leading\n );\n declaration.comments = leadingComments;\n }\n }\n\n body.splice(insertionIndex, 0, declaration);\n};\n\nconst injectImport = (\n ast: any,\n isCJS: boolean,\n importName: string,\n source: string\n) => {\n // Never redeclare an identifier already bound at module scope (e.g. imported\n // from another source or declared locally) — that would be a parse error.\n if (!isCJS && isModuleScopeBinding(ast, importName)) return;\n\n const body = ast.program.body;\n const hasImport = body.some((stmt: any) => {\n if (isCJS) {\n return (\n n.VariableDeclaration.check(stmt) &&\n stmt.declarations.some(\n (decl: any) =>\n n.VariableDeclarator.check(decl) &&\n n.CallExpression.check(decl.init) &&\n n.Identifier.check(decl.init.callee) &&\n decl.init.callee.name === 'require' &&\n n.StringLiteral.check(decl.init.arguments[0]) &&\n decl.init.arguments[0].value === source\n )\n );\n }\n return (\n n.ImportDeclaration.check(stmt) &&\n (stmt.source.value === source ||\n stmt.specifiers?.some(\n (spec: any) =>\n (n.ImportSpecifier.check(spec) &&\n spec.imported.name === importName) ||\n (n.ImportDefaultSpecifier.check(spec) &&\n spec.local?.name === importName)\n ))\n );\n });\n\n if (hasImport) return;\n\n const declaration = isCJS\n ? b.variableDeclaration('const', [\n b.variableDeclarator(\n b.identifier(`{ ${importName} }`),\n b.callExpression(b.identifier('require'), [b.stringLiteral(source)])\n ),\n ])\n : b.importDeclaration(\n [b.importSpecifier(b.identifier(importName))],\n b.stringLiteral(source)\n );\n\n insertImportDeclaration(ast, isCJS, declaration);\n};\n\nconst updatePluginArray = (\n objExpr: any,\n propertyName: string,\n pluginName: string\n) => {\n if (\n !objExpr ||\n (objExpr.type !== 'ObjectExpression' && !n.ObjectExpression.check(objExpr))\n )\n return;\n\n let prop = objExpr.properties.find((p: any) => {\n if (!p?.key) return false;\n const keyName = p.key.name || p.key.value;\n return keyName === propertyName;\n }) as any;\n\n if (!prop) {\n prop = b.property(\n 'init',\n b.identifier(propertyName),\n b.arrayExpression([])\n );\n objExpr.properties.push(prop);\n }\n\n const arrayValue = prop.value;\n\n if (\n arrayValue &&\n (arrayValue.type === 'ArrayExpression' ||\n n.ArrayExpression.check(arrayValue))\n ) {\n const hasPlugin = arrayValue.elements.some((el: any) => {\n const callee = el?.callee;\n if (!callee) return false;\n const name = callee.name || callee.id?.name;\n return name === pluginName || name === 'il';\n });\n\n if (!hasPlugin) {\n arrayValue.elements.push(b.callExpression(b.identifier(pluginName), []));\n }\n }\n};\n\nconst genericRecastVisit = (\n ast: any,\n updateConfigObject: (obj: any) => void,\n callNames: string[] = ['defineConfig']\n) => {\n /**\n * Resolves an identifier reference (e.g. `export default config` /\n * `module.exports = config`) back to the object expression it was declared\n * with, then runs the updater on it.\n */\n const resolveIdentifierConfig = (name: string) => {\n ast.program.body.forEach((stmt: any) => {\n if (n.VariableDeclaration.check(stmt)) {\n stmt.declarations.forEach((vdecl: any) => {\n if (\n n.VariableDeclarator.check(vdecl) &&\n n.Identifier.check(vdecl.id) &&\n vdecl.id.name === name &&\n n.ObjectExpression.check(vdecl.init)\n ) {\n updateConfigObject(vdecl.init);\n }\n });\n }\n });\n };\n\n recast.visit(ast, {\n visitExportDefaultDeclaration(path) {\n const decl = path.node.declaration;\n\n if (n.ObjectExpression.check(decl)) {\n updateConfigObject(decl);\n } else if (\n n.CallExpression.check(decl) &&\n n.Identifier.check(decl.callee) &&\n callNames.includes(decl.callee.name)\n ) {\n if (n.ObjectExpression.check(decl.arguments[0])) {\n updateConfigObject(decl.arguments[0]);\n }\n } else if (n.Identifier.check(decl)) {\n resolveIdentifierConfig(decl.name);\n }\n return false;\n },\n visitAssignmentExpression(path) {\n const { left, right } = path.node;\n\n if (\n n.MemberExpression.check(left) &&\n recast.print(left).code === 'module.exports'\n ) {\n if (n.ObjectExpression.check(right)) {\n updateConfigObject(right);\n } else if (\n n.CallExpression.check(right) &&\n n.Identifier.check(right.callee) &&\n callNames.includes(right.callee.name)\n ) {\n if (n.ObjectExpression.check(right.arguments[0])) {\n updateConfigObject(right.arguments[0]);\n }\n } else if (n.Identifier.check(right)) {\n resolveIdentifierConfig(right.name);\n }\n }\n return false;\n },\n });\n};\n\n/**\n * Detects whether a Vite config already wires in an Intlayer plugin — either the\n * base `vite-intlayer` plugin or one of the compat adapters (e.g.\n * `reactI18nextVitePlugin` from `@intlayer/react-i18next/plugin`). The compat\n * plugins internally wrap `intlayer()`, so a standalone `intlayer()` must not be\n * appended when one is already present, otherwise the plugin runs twice.\n */\nexport const hasIntlayerVitePlugin = (content: string): boolean =>\n content.includes('vite-intlayer') ||\n /@intlayer\\/[^'\"]+\\/plugin/.test(content);\n\nexport const updateViteConfig = (\n content: string,\n extension: string\n): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const isCJSFile =\n extension === 'cjs' ||\n (content.includes('module.exports') && !content.includes('import '));\n\n injectImport(ast, isCJSFile, 'intlayer', 'vite-intlayer');\n\n genericRecastVisit(ast, (obj) =>\n updatePluginArray(obj, 'plugins', 'intlayer')\n );\n\n return recast.print(ast).code;\n};\n\nexport const updateAstroConfig = (\n content: string,\n extension: string\n): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const isCJSFile =\n extension === 'cjs' ||\n (content.includes('module.exports') && !content.includes('import '));\n\n injectImport(ast, isCJSFile, 'intlayer', 'astro-intlayer');\n\n genericRecastVisit(ast, (obj) =>\n updatePluginArray(obj, 'integrations', 'intlayer')\n );\n\n return recast.print(ast).code;\n};\n\nexport const updateNextConfig = (\n content: string,\n extension: string\n): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const isCJSFile = extension === 'cjs' || content.includes('module.exports');\n\n injectImport(ast, isCJSFile, 'withIntlayer', 'next-intlayer/server');\n\n recast.visit(ast, {\n visitExportDefaultDeclaration(path) {\n const declaration = path.node.declaration;\n if (\n n.Expression.check(declaration) &&\n !(\n n.CallExpression.check(declaration) &&\n n.Identifier.check(declaration.callee) &&\n declaration.callee.name === 'withIntlayer'\n )\n ) {\n path\n .get('declaration')\n .replace(\n b.callExpression(b.identifier('withIntlayer'), [declaration as any])\n );\n }\n return false;\n },\n visitAssignmentExpression(path) {\n const { left, right } = path.node;\n\n if (\n n.MemberExpression.check(left) &&\n recast.print(left).code === 'module.exports' &&\n !(\n n.CallExpression.check(right) &&\n n.Identifier.check(right.callee) &&\n right.callee.name === 'withIntlayer'\n )\n ) {\n path\n .get('right')\n .replace(b.callExpression(b.identifier('withIntlayer'), [right]));\n }\n return false;\n },\n });\n\n return recast.print(ast).code;\n};\n\n/**\n * Returns true when the expression looks like an Immediately Invoked Function\n * Expression (e.g. `(async () => { ... })()`). Such custom async exports cannot\n * be safely wrapped with the synchronous Metro helper, so they are skipped.\n */\nconst isImmediatelyInvokedFunction = (node: any): boolean =>\n n.CallExpression.check(node) &&\n (n.ArrowFunctionExpression.check(node.callee) ||\n n.FunctionExpression.check(node.callee));\n\n/**\n * Wraps a React Native Metro config's exported value with\n * `configMetroIntlayerSync` from `react-native-intlayer/metro`, injecting the\n * import. The synchronous helper is used because it wraps a plain config object\n * and needs no IIFE, making it safe to inject into existing configs without\n * restructuring them.\n *\n * Non-destructive: returns the content unchanged when the export is already\n * wrapped, when the Intlayer Metro plugin is already present, or when the export\n * is a custom async IIFE that cannot be wrapped synchronously. Callers should\n * compare the result with the input to detect the skipped case.\n */\nexport const updateMetroConfig = (\n content: string,\n extension: string\n): string => {\n if (content.includes('react-native-intlayer')) {\n return content;\n }\n\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const isCJSFile =\n extension === 'cjs' ||\n (content.includes('module.exports') && !content.includes('import '));\n\n const wrapperName = 'configMetroIntlayerSync';\n\n const isWrappable = (node: any): boolean =>\n n.Expression.check(node) &&\n !isImmediatelyInvokedFunction(node) &&\n !(\n n.CallExpression.check(node) &&\n n.Identifier.check(node.callee) &&\n node.callee.name === wrapperName\n );\n\n let wrapped = false;\n\n recast.visit(ast, {\n visitExportDefaultDeclaration(path) {\n const declaration = path.node.declaration;\n if (isWrappable(declaration)) {\n path\n .get('declaration')\n .replace(\n b.callExpression(b.identifier(wrapperName), [declaration as any])\n );\n wrapped = true;\n }\n return false;\n },\n visitAssignmentExpression(path) {\n const { left, right } = path.node;\n\n if (\n n.MemberExpression.check(left) &&\n recast.print(left).code === 'module.exports' &&\n isWrappable(right)\n ) {\n path\n .get('right')\n .replace(b.callExpression(b.identifier(wrapperName), [right]));\n wrapped = true;\n }\n return false;\n },\n });\n\n // Only inject the import when an export was actually wrapped, so an\n // un-wrappable config is left completely untouched.\n if (!wrapped) {\n return content;\n }\n\n injectImport(ast, isCJSFile, wrapperName, 'react-native-intlayer/metro');\n\n return recast.print(ast).code;\n};\n\n/**\n * Builds the contents of a fresh `metro.config.js` wired with the Intlayer\n * Metro plugin. Uses the async `configMetroIntlayer` helper (which can build\n * dictionaries on server start) and picks the default-config source based on\n * whether the project is an Expo app.\n */\nexport const getMetroConfigTemplate = (isExpo: boolean): string => {\n const defaultConfigSource = isExpo\n ? 'expo/metro-config'\n : '@react-native/metro-config';\n\n return `const { getDefaultConfig } = require(\"${defaultConfigSource}\");\nconst { configMetroIntlayer } = require(\"react-native-intlayer/metro\");\n\nmodule.exports = (async () => {\n const defaultConfig = getDefaultConfig(__dirname);\n\n return await configMetroIntlayer(defaultConfig);\n})();\n`;\n};\n\nexport const updateNuxtConfig = (content: string): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const updateConfigObject = (objExpr: any) => {\n if (\n !objExpr ||\n (objExpr.type !== 'ObjectExpression' &&\n !n.ObjectExpression.check(objExpr))\n )\n return;\n\n let modulesProp = objExpr.properties.find((p: any) => {\n if (!p?.key) return false;\n const keyName = p.key.name || p.key.value;\n return keyName === 'modules';\n }) as any;\n\n if (!modulesProp) {\n modulesProp = b.property(\n 'init',\n b.identifier('modules'),\n b.arrayExpression([])\n );\n objExpr.properties.push(modulesProp);\n }\n\n const modulesValue = modulesProp.value;\n\n if (\n modulesValue &&\n (modulesValue.type === 'ArrayExpression' ||\n n.ArrayExpression.check(modulesValue))\n ) {\n const hasModule = modulesValue.elements.some((el: any) => {\n if (\n n.StringLiteral.check(el) ||\n el.type === 'StringLiteral' ||\n el.type === 'Literal'\n ) {\n return (el.value || el.extra?.rawValue) === 'nuxt-intlayer';\n }\n return false;\n });\n\n if (!hasModule) {\n modulesValue.elements.push(b.stringLiteral('nuxt-intlayer'));\n }\n }\n };\n\n genericRecastVisit(ast, updateConfigObject, ['defineNuxtConfig']);\n\n return recast.print(ast).code;\n};\n\n/**\n * Updates a Vite config for vue-i18n compat: injects `vueI18nVitePlugin` from\n * `@intlayer/vue-i18n/plugin` into the plugins array.\n */\nexport const updateViteConfigForVueI18n = (\n content: string,\n extension: string\n): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const isCJSFile =\n extension === 'cjs' ||\n (content.includes('module.exports') && !content.includes('import '));\n\n injectImport(\n ast,\n isCJSFile,\n 'vueI18nVitePlugin',\n '@intlayer/vue-i18n/plugin'\n );\n\n genericRecastVisit(ast, (obj) =>\n updatePluginArray(obj, 'plugins', 'vueI18nVitePlugin')\n );\n\n return recast.print(ast).code;\n};\n\n/**\n * Generic vite config updater for any compat plugin that uses alias injection.\n * Injects the named import from `pluginPackageSource` and appends the plugin\n * call to the `plugins` array.\n */\nexport const updateViteConfigForCompatPlugin = (\n content: string,\n extension: string,\n pluginConfig: CompatVitePluginConfig\n): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const isCJSFile =\n extension === 'cjs' ||\n (content.includes('module.exports') && !content.includes('import '));\n\n injectImport(\n ast,\n isCJSFile,\n pluginConfig.pluginFunctionName,\n pluginConfig.pluginPackageSource\n );\n\n genericRecastVisit(ast, (obj) =>\n updatePluginArray(obj, 'plugins', pluginConfig.pluginFunctionName)\n );\n\n return recast.print(ast).code;\n};\n\n/**\n * Rewrites the module source of an existing named import in a vite config,\n * keeping the imported binding and its call site untouched. Used when a compat\n * plugin is a drop-in replacement for an i18n library's own vite plugin — e.g.\n * lingui: `import { lingui } from \"@lingui/vite-plugin\"` becomes\n * `import { lingui } from \"@intlayer/lingui/plugin\"`, leaving `lingui()` in the\n * `plugins` array as-is. Returns the content unchanged when no matching import\n * is found.\n */\nexport const replaceViteConfigPluginImportSource = (\n content: string,\n importName: string,\n fromPackageSource: string,\n toPackageSource: string\n): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n let changed = false;\n\n recast.visit(ast, {\n visitImportDeclaration(path) {\n const { source, specifiers } = path.node;\n const importsBinding = (specifiers ?? []).some(\n (specifier) =>\n n.ImportSpecifier.check(specifier) &&\n specifier.imported.name === importName\n );\n\n if (\n n.StringLiteral.check(source) &&\n source.value === fromPackageSource &&\n importsBinding\n ) {\n source.value = toPackageSource;\n changed = true;\n }\n\n return false;\n },\n });\n\n if (!changed) return content;\n return recast.print(ast).code;\n};\n\n/**\n * Generic Next.js config wrapper for compat plugins. Injects the import and\n * wraps the default export / `module.exports` with a HOC call.\n */\nconst wrapNextConfigWithHoc = (\n content: string,\n extension: string,\n hocFunctionName: string,\n pluginPackageSource: string\n): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const isCJSFile = extension === 'cjs' || content.includes('module.exports');\n\n injectImport(ast, isCJSFile, hocFunctionName, pluginPackageSource);\n\n recast.visit(ast, {\n visitExportDefaultDeclaration(path) {\n const declaration = path.node.declaration;\n if (\n n.Expression.check(declaration) &&\n !(\n n.CallExpression.check(declaration) &&\n n.Identifier.check(declaration.callee) &&\n declaration.callee.name === hocFunctionName\n )\n ) {\n path\n .get('declaration')\n .replace(\n b.callExpression(b.identifier(hocFunctionName), [\n declaration as any,\n ])\n );\n }\n return false;\n },\n visitAssignmentExpression(path) {\n const { left, right } = path.node;\n\n if (\n n.MemberExpression.check(left) &&\n recast.print(left).code === 'module.exports' &&\n !(\n n.CallExpression.check(right) &&\n n.Identifier.check(right.callee) &&\n right.callee.name === hocFunctionName\n )\n ) {\n path\n .get('right')\n .replace(b.callExpression(b.identifier(hocFunctionName), [right]));\n }\n return false;\n },\n });\n\n return recast.print(ast).code;\n};\n\n/**\n * Updates a Next.js config for next-translate compat: wraps the default export\n * with `withNextTranslate` from `@intlayer/next-translate/plugin`.\n */\nexport const updateNextConfigForNextTranslate = (\n content: string,\n extension: string\n): string =>\n wrapNextConfigWithHoc(\n content,\n extension,\n 'withNextTranslate',\n '@intlayer/next-translate/plugin'\n );\n\n/**\n * Updates a Nuxt config for nuxtjs-i18n compat: adds `@intlayer/nuxtjs-i18n`\n * to the `modules` array.\n */\nexport const updateNuxtConfigForNuxtjsI18n = (content: string): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const updateConfigObject = (objExpr: any) => {\n if (\n !objExpr ||\n (objExpr.type !== 'ObjectExpression' &&\n !n.ObjectExpression.check(objExpr))\n )\n return;\n\n let modulesProp = (objExpr.properties as any[]).find((p: any) => {\n if (!p?.key) return false;\n const keyName = p.key.name || p.key.value;\n return keyName === 'modules';\n }) as any;\n\n if (!modulesProp) {\n modulesProp = b.property(\n 'init',\n b.identifier('modules'),\n b.arrayExpression([])\n );\n (objExpr.properties as any[]).push(modulesProp);\n }\n\n const modulesValue = modulesProp.value;\n\n if (\n modulesValue &&\n (modulesValue.type === 'ArrayExpression' ||\n n.ArrayExpression.check(modulesValue))\n ) {\n const hasModule = (modulesValue.elements as any[]).some((el: any) => {\n if (\n n.StringLiteral.check(el) ||\n el.type === 'StringLiteral' ||\n el.type === 'Literal'\n ) {\n return (el.value ?? el.extra?.rawValue) === '@intlayer/nuxtjs-i18n';\n }\n return false;\n });\n\n if (!hasModule) {\n (modulesValue.elements as any[]).push(\n b.stringLiteral('@intlayer/nuxtjs-i18n')\n );\n }\n }\n };\n\n genericRecastVisit(ast, updateConfigObject, ['defineNuxtConfig']);\n\n return recast.print(ast).code;\n};\n\n/**\n * Updates a Next.js config for next-i18next compat: wraps the default export\n * with `withI18next` from `@intlayer/next-i18next/plugin`.\n */\nexport const updateNextConfigForNextI18next = (\n content: string,\n extension: string\n): string =>\n wrapNextConfigWithHoc(\n content,\n extension,\n 'withI18next',\n '@intlayer/next-i18next/plugin'\n );\n\n/**\n * Updates a Next.js config for next-intl compat: replaces any existing\n * `next-intl/plugin` import source with `@intlayer/next-intl/plugin`, or\n * injects `createNextIntlPlugin` with a factory-call wrapper when no such\n * import is present.\n */\nexport const updateNextConfigForNextIntl = (\n content: string,\n extension: string\n): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const isCJSFile = extension === 'cjs' || content.includes('module.exports');\n let replacedExistingSource = false;\n\n // Replace 'next-intl/plugin' import source with the compat package.\n recast.visit(ast, {\n visitImportDeclaration(path) {\n if (path.node.source.value === 'next-intl/plugin') {\n path.node.source = b.stringLiteral('@intlayer/next-intl/plugin');\n replacedExistingSource = true;\n }\n return false;\n },\n });\n\n if (replacedExistingSource) {\n return recast.print(ast).code;\n }\n\n // No existing next-intl/plugin import: check whether createNextIntlPlugin is\n // already present from any source before injecting the full factory pattern.\n const hasCreatePlugin = (ast.program.body as any[]).some((stmt: any) => {\n if (!n.ImportDeclaration.check(stmt)) return false;\n return (stmt.specifiers ?? []).some(\n (spec: any) =>\n (n.ImportSpecifier.check(spec) &&\n spec.imported.name === 'createNextIntlPlugin') ||\n (n.ImportDefaultSpecifier.check(spec) &&\n spec.local?.name === 'createNextIntlPlugin')\n );\n });\n\n if (hasCreatePlugin) {\n return recast.print(ast).code;\n }\n\n // Inject the import.\n injectImport(\n ast,\n isCJSFile,\n 'createNextIntlPlugin',\n '@intlayer/next-intl/plugin'\n );\n\n // Insert a factory-call variable declaration after the last import.\n const lastImportIndex = (ast.program.body as any[]).reduce(\n (lastIndex: number, stmt: any, index: number) => {\n if (n.ImportDeclaration.check(stmt)) return index;\n return lastIndex;\n },\n -1\n );\n\n const factoryCallDeclaration = b.variableDeclaration('const', [\n b.variableDeclarator(\n b.identifier('_withNextIntlayer'),\n b.callExpression(b.identifier('createNextIntlPlugin'), [])\n ),\n ]);\n\n (ast.program.body as any[]).splice(\n lastImportIndex + 1,\n 0,\n factoryCallDeclaration\n );\n\n // Wrap the default export with _withNextIntlayer(...).\n recast.visit(ast, {\n visitExportDefaultDeclaration(path) {\n const declaration = path.node.declaration;\n if (\n n.Expression.check(declaration) &&\n !(\n n.CallExpression.check(declaration) &&\n n.Identifier.check(declaration.callee) &&\n declaration.callee.name === '_withNextIntlayer'\n )\n ) {\n path\n .get('declaration')\n .replace(\n b.callExpression(b.identifier('_withNextIntlayer'), [\n declaration as any,\n ])\n );\n }\n return false;\n },\n visitAssignmentExpression(path) {\n const { left, right } = path.node;\n\n if (\n n.MemberExpression.check(left) &&\n recast.print(left).code === 'module.exports' &&\n !(\n n.CallExpression.check(right) &&\n n.Identifier.check(right.callee) &&\n right.callee.name === '_withNextIntlayer'\n )\n ) {\n path\n .get('right')\n .replace(\n b.callExpression(b.identifier('_withNextIntlayer'), [right])\n );\n }\n return false;\n },\n });\n\n return recast.print(ast).code;\n};\n\n/** The sync plugin used to ingest a compat library's catalogs. */\ntype SyncPluginInfo = {\n /** Called function name, e.g. `'syncJSON'`. */\n functionName: string;\n /** Package the function is imported from. */\n packageSource: string;\n};\n\n/** Resolves the sync plugin (function + package) for a compat sync config. */\nconst getSyncPluginInfo = (syncConfig: CompatSyncConfig): SyncPluginInfo =>\n syncConfig.plugin === 'po'\n ? { functionName: 'syncPO', packageSource: '@intlayer/sync-po-plugin' }\n : { functionName: 'syncJSON', packageSource: '@intlayer/sync-json-plugin' };\n\n/**\n * Parses a `syncJSON({ ... })` / `syncPO({ ... })` call expression from a source\n * snippet so it can be injected into a config AST without manually constructing\n * template-literal nodes via builders.\n *\n * The destructuring parameters adapt to whether the source template uses the\n * `key` placeholder (nested pattern) or only `locale` (flat pattern).\n *\n * For `syncJSON` every option is emitted explicitly — `source`, then `format`\n * and `splitKeys` — each preceded by an explanatory JSDoc block, so the\n * generated config self-documents the two knobs a user is most likely to tweak.\n * `syncPO` takes neither `format` (gettext is always the serialization) nor\n * `splitKeys`, so it keeps a bare `source`-only call.\n */\nconst buildSyncCallNode = (syncConfig: CompatSyncConfig): any => {\n const { functionName } = getSyncPluginInfo(syncConfig);\n const usesKey = syncConfig.sourceTemplate.includes('${key}');\n const paramDestructuring = !usesKey\n ? '{ locale }'\n : // `icu` (and PO, which is ICU-dialect) reads `{ key, locale }`; the\n // i18next/vue-i18n JSON dialects keep their established `{ locale, key }`.\n syncConfig.format === 'icu' || syncConfig.plugin === 'po'\n ? '{ key, locale }'\n : '{ locale, key }';\n\n // The sourceTemplate contains ${locale} / ${key} as literal characters;\n // they become proper template expressions once the snippet is parsed by recast.\n const sourceProperty = `source: (${paramDestructuring}) => \\`${syncConfig.sourceTemplate}\\``;\n\n const parseSnippet = (snippet: string): any => {\n const snippetAst = recast.parse(snippet, {\n parser: typescriptParser,\n });\n return (snippetAst.program.body[0] as any).expression;\n };\n\n // `syncPO` always serializes gettext, so it exposes neither `format` nor\n // `splitKeys`: emit a bare `source`-only call.\n if (syncConfig.plugin === 'po') {\n return parseSnippet(`${functionName}({ ${sourceProperty} })`);\n }\n\n // `splitKeys: true` is forced only for the single-file namespace model\n // (next-intl / use-intl); every other library keeps a single dictionary per\n // file. It is now written explicitly (rather than relying on syncJSON's\n // auto-detection) so the generated config documents the choice.\n const splitKeys = Boolean(syncConfig.splitKeys);\n\n // The JSDoc blocks are embedded in the snippet and preserved by recast when\n // the parsed call node is printed back into the config AST.\n const snippet = `${functionName}({\n ${sourceProperty},\n\n /**\n * Parsing of json respecting the syntax\n * Default \\`'intlayer'\\` message format\n */\n format: '${syncConfig.format}',\n\n /**\n * \\`true\\`:\n * \\`en.json\\` -> \\`useTranslation('home')\\` -> \\`t(\"title\")\\`\n *\n * \\`false\\`:\n * \\`en.json\\` -> \\`useTranslation()\\` -> \\`t(\"home.title\")\\`\n */\n splitKeys: ${splitKeys},\n})`;\n\n return parseSnippet(snippet);\n};\n\n/**\n * Injects or ensures `dictionary: { format: '<value>' }` exists in an object\n * expression. Leaves any pre-existing `dictionary` properties untouched —\n * only the `format` sub-property is added when absent.\n */\nconst injectDictionaryFormat = (objExpr: any, format: string): void => {\n if (\n !objExpr ||\n (objExpr.type !== 'ObjectExpression' && !n.ObjectExpression.check(objExpr))\n )\n return;\n\n let dictionaryProp = (objExpr.properties as any[]).find((prop: any) => {\n if (!prop?.key) return false;\n return (prop.key.name ?? prop.key.value) === 'dictionary';\n });\n\n if (!dictionaryProp) {\n dictionaryProp = b.property(\n 'init',\n b.identifier('dictionary'),\n b.objectExpression([])\n );\n (objExpr.properties as any[]).push(dictionaryProp);\n }\n\n const dictionaryObj = dictionaryProp.value;\n if (\n !dictionaryObj ||\n (dictionaryObj.type !== 'ObjectExpression' &&\n !n.ObjectExpression.check(dictionaryObj))\n )\n return;\n\n const hasFormat = (dictionaryObj.properties as any[]).some((prop: any) => {\n if (!prop?.key) return false;\n return (prop.key.name ?? prop.key.value) === 'format';\n });\n\n if (!hasFormat) {\n (dictionaryObj.properties as any[]).push(\n b.property('init', b.identifier('format'), b.stringLiteral(format))\n );\n }\n};\n\n/**\n * Injects the sync plugin import (`syncJSON` / `syncPO`) and a configured\n * `syncJSON(...)` / `syncPO(...)` call into the plugins array of an intlayer\n * config file. Idempotent: skips when the plugin call is already present.\n */\nexport const updateIntlayerConfigWithSyncPlugin = (\n content: string,\n extension: string,\n syncConfig: CompatSyncConfig\n): string => {\n const ast = recast.parse(content, {\n parser: typescriptParser,\n });\n\n const isCJSFile = extension === 'cjs' || content.includes('module.exports');\n\n const { functionName, packageSource } = getSyncPluginInfo(syncConfig);\n\n injectImport(ast, isCJSFile, functionName, packageSource);\n\n const callNode = buildSyncCallNode(syncConfig);\n\n // PO catalogs are serialized as gettext; JSON catalogs carry the dialect.\n const dictionaryFormat =\n syncConfig.plugin === 'po' ? 'po' : syncConfig.format;\n\n genericRecastVisit(ast, (objExpr) => {\n if (\n !objExpr ||\n (objExpr.type !== 'ObjectExpression' &&\n !n.ObjectExpression.check(objExpr))\n )\n return;\n\n // Inject dictionary.format alongside the plugin so intlayer knows how to\n // interpret dictionary content at runtime.\n injectDictionaryFormat(objExpr, dictionaryFormat);\n\n let pluginsProp = (objExpr.properties as any[]).find((prop: any) => {\n if (!prop?.key) return false;\n const keyName = prop.key.name ?? prop.key.value;\n return keyName === 'plugins';\n });\n\n if (!pluginsProp) {\n pluginsProp = b.property(\n 'init',\n b.identifier('plugins'),\n b.arrayExpression([])\n );\n (objExpr.properties as any[]).push(pluginsProp);\n }\n\n const arrayValue = pluginsProp.value;\n\n if (\n arrayValue &&\n (arrayValue.type === 'ArrayExpression' ||\n n.ArrayExpression.check(arrayValue))\n ) {\n const hasSyncPlugin = (arrayValue.elements as any[]).some(\n (element: any) => {\n const callee = element?.callee;\n if (!callee) return false;\n const name: string = callee.name ?? callee.id?.name;\n return name === functionName;\n }\n );\n\n if (!hasSyncPlugin) {\n (arrayValue.elements as any[]).push(callNode);\n }\n }\n });\n\n return recast.print(ast).code;\n};\n"],"mappings":";;;;;;;;AASA,MAAM,EAAE,UAAU,GAAG,YAAY,MAAM,OAAO;;AAM9C,MAAM,sBAAsB,SAC1B,QAAQ,IAAI,MACX,KAAK,SAAS,sBAAsB,EAAE,iBAAiB,MAAM,IAAI;;;;;;AAOpE,MAAM,wBACJ,SACA,KACA,qBACQ;CACR,IAAI,WAAY,QAAQ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,IAAI,CAAC,QAAQ,OAAO;IAEpB,QADqB,OAAO,QAAQ,OAAO,IAAI,UAC/B;GAClB,CAGe,GACf,AAAC,WAAW,SAAmB,KAAK,QAAQ;EAC9C;CAEJ,CAAC;CAED,OAAO,OAAO,MAAM,GAAG,CAAC,CAAC;AAC3B"}
@@ -0,0 +1,61 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ //#region src/init/utils/contentLayout.ts
3
+ /**
4
+ * Message syntax of a JSON catalog (plurals, interpolation…), written to the
5
+ * syncJSON `format` option. Ordered as offered, the first one being the default.
6
+ */
7
+ const CATALOG_MESSAGE_FORMATS = [
8
+ "icu",
9
+ "i18next",
10
+ "vue-i18n",
11
+ "intlayer"
12
+ ];
13
+ /** Formats accepted by each content layout, the first one being the default. */
14
+ const CONTENT_FORMATS_BY_LAYOUT = {
15
+ multilingual: ["ts", "json"],
16
+ "per-locale": ["ts", "json"],
17
+ centralized: ["json", "po"],
18
+ namespaces: ["json", "po"]
19
+ };
20
+ /**
21
+ * Resolves the configuration changes for a content layout and format. A format
22
+ * the layout does not accept falls back to the layout default. The message
23
+ * format only applies to JSON catalogs (centralized / namespaces).
24
+ */
25
+ const getContentLayoutSetup = (layout, format, messageFormat = CATALOG_MESSAGE_FORMATS[0]) => {
26
+ const acceptedFormats = CONTENT_FORMATS_BY_LAYOUT[layout];
27
+ const resolvedFormat = format && acceptedFormats.includes(format) ? format : acceptedFormats[0];
28
+ switch (layout) {
29
+ case "multilingual": return {
30
+ compilerOutput: `./{{fileName}}.content.${resolvedFormat}`,
31
+ isPerLocale: false
32
+ };
33
+ case "per-locale": return {
34
+ compilerOutput: `./{{fileName}}.{{locale}}.content.${resolvedFormat}`,
35
+ isPerLocale: true
36
+ };
37
+ case "centralized": return {
38
+ isPerLocale: false,
39
+ syncConfig: {
40
+ plugin: resolvedFormat === "po" ? "po" : "json",
41
+ format: messageFormat,
42
+ sourceTemplate: `./locales/\${locale}.${resolvedFormat}`,
43
+ splitKeys: resolvedFormat !== "po"
44
+ }
45
+ };
46
+ case "namespaces": return {
47
+ isPerLocale: false,
48
+ syncConfig: {
49
+ plugin: resolvedFormat === "po" ? "po" : "json",
50
+ format: messageFormat,
51
+ sourceTemplate: `./locales/\${locale}/\${key}.${resolvedFormat}`
52
+ }
53
+ };
54
+ }
55
+ };
56
+
57
+ //#endregion
58
+ exports.CATALOG_MESSAGE_FORMATS = CATALOG_MESSAGE_FORMATS;
59
+ exports.CONTENT_FORMATS_BY_LAYOUT = CONTENT_FORMATS_BY_LAYOUT;
60
+ exports.getContentLayoutSetup = getContentLayoutSetup;
61
+ //# sourceMappingURL=contentLayout.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contentLayout.cjs","names":[],"sources":["../../../../src/init/utils/contentLayout.ts"],"sourcesContent":["import type { CompatSyncConfig } from './packageManager';\n\n/**\n * How content declarations are organized in the project:\n * - `multilingual` — `./{fileName}.content.{ts,json}` next to the component,\n * every locale in the same file.\n * - `per-locale` — `./{fileName}.{locale}.content.{ts,json}` next to the\n * component, one file per locale.\n * - `centralized` — a single `/locales/{locale}.{json,po}` catalog per locale,\n * synced through a sync plugin.\n * - `namespaces` — `/locales/{locale}/{namespace}.{json,po}` catalogs, synced\n * through a sync plugin.\n */\nexport type ContentLayout =\n | 'multilingual'\n | 'per-locale'\n | 'centralized'\n | 'namespaces';\n\n/** File format of the content declarations / catalogs. */\nexport type ContentFormat = 'ts' | 'json' | 'po';\n\n/**\n * Message syntax of a JSON catalog (plurals, interpolation…), written to the\n * syncJSON `format` option. Ordered as offered, the first one being the default.\n */\nexport const CATALOG_MESSAGE_FORMATS = [\n 'icu',\n 'i18next',\n 'vue-i18n',\n 'intlayer',\n] as const;\n\n/** Message syntax of a JSON catalog. */\nexport type CatalogMessageFormat = (typeof CATALOG_MESSAGE_FORMATS)[number];\n\n/** Formats accepted by each content layout, the first one being the default. */\nexport const CONTENT_FORMATS_BY_LAYOUT: Record<\n ContentLayout,\n readonly ContentFormat[]\n> = {\n multilingual: ['ts', 'json'],\n 'per-locale': ['ts', 'json'],\n centralized: ['json', 'po'],\n namespaces: ['json', 'po'],\n};\n\n/** Configuration changes implied by a content layout. */\nexport type ContentLayoutSetup = {\n /** `compiler.output` template, for layouts based on `.content` files. */\n compilerOutput?: string;\n /** Whether `dictionary.locale` must be set (per-locale declarations). */\n isPerLocale: boolean;\n /** Sync plugin to register, for layouts based on plain catalogs. */\n syncConfig?: CompatSyncConfig;\n};\n\n/**\n * Resolves the configuration changes for a content layout and format. A format\n * the layout does not accept falls back to the layout default. The message\n * format only applies to JSON catalogs (centralized / namespaces).\n */\nexport const getContentLayoutSetup = (\n layout: ContentLayout,\n format?: ContentFormat,\n messageFormat: CatalogMessageFormat = CATALOG_MESSAGE_FORMATS[0]\n): ContentLayoutSetup => {\n const acceptedFormats = CONTENT_FORMATS_BY_LAYOUT[layout];\n const resolvedFormat =\n format && acceptedFormats.includes(format) ? format : acceptedFormats[0];\n\n switch (layout) {\n case 'multilingual':\n return {\n compilerOutput: `./{{fileName}}.content.${resolvedFormat}`,\n isPerLocale: false,\n };\n case 'per-locale':\n return {\n compilerOutput: `./{{fileName}}.{{locale}}.content.${resolvedFormat}`,\n isPerLocale: true,\n };\n case 'centralized':\n return {\n isPerLocale: false,\n syncConfig: {\n plugin: resolvedFormat === 'po' ? 'po' : 'json',\n format: messageFormat,\n sourceTemplate: `./locales/\\${locale}.${resolvedFormat}`,\n // One file per locale whose first-level keys are namespaces.\n splitKeys: resolvedFormat !== 'po',\n },\n };\n case 'namespaces':\n return {\n isPerLocale: false,\n syncConfig: {\n plugin: resolvedFormat === 'po' ? 'po' : 'json',\n format: messageFormat,\n sourceTemplate: `./locales/\\${locale}/\\${key}.${resolvedFormat}`,\n },\n };\n }\n};\n"],"mappings":";;;;;;AA0BA,MAAa,0BAA0B;CACrC;CACA;CACA;CACA;AACF;;AAMA,MAAa,4BAGT;CACF,cAAc,CAAC,MAAM,MAAM;CAC3B,cAAc,CAAC,MAAM,MAAM;CAC3B,aAAa,CAAC,QAAQ,IAAI;CAC1B,YAAY,CAAC,QAAQ,IAAI;AAC3B;;;;;;AAiBA,MAAa,yBACX,QACA,QACA,gBAAsC,wBAAwB,OACvC;CACvB,MAAM,kBAAkB,0BAA0B;CAClD,MAAM,iBACJ,UAAU,gBAAgB,SAAS,MAAM,IAAI,SAAS,gBAAgB;CAExE,QAAQ,QAAR;EACE,KAAK,gBACH,OAAO;GACL,gBAAgB,0BAA0B;GAC1C,aAAa;EACf;EACF,KAAK,cACH,OAAO;GACL,gBAAgB,qCAAqC;GACrD,aAAa;EACf;EACF,KAAK,eACH,OAAO;GACL,aAAa;GACb,YAAY;IACV,QAAQ,mBAAmB,OAAO,OAAO;IACzC,QAAQ;IACR,gBAAgB,wBAAwB;IAExC,WAAW,mBAAmB;GAChC;EACF;EACF,KAAK,cACH,OAAO;GACL,aAAa;GACb,YAAY;IACV,QAAQ,mBAAmB,OAAO,OAAO;IACzC,QAAQ;IACR,gBAAgB,gCAAgC;GAClD;EACF;CACJ;AACF"}
@@ -59,6 +59,7 @@ exports.replaceViteConfigPluginImportSource = require_init_utils_configManipulat
59
59
  exports.resolveGithubWorkflowsContext = require_init_utils_githubActions.resolveGithubWorkflowsContext;
60
60
  exports.runPackageInstall = require_init_utils_packageManager.runPackageInstall;
61
61
  exports.setIntlayerConfigCompilerOutput = require_init_utils_configManipulation.setIntlayerConfigCompilerOutput;
62
+ exports.setIntlayerConfigDictionaryLocale = require_init_utils_configManipulation.setIntlayerConfigDictionaryLocale;
62
63
  exports.setIntlayerConfigEnableProxy = require_init_utils_configManipulation.setIntlayerConfigEnableProxy;
63
64
  exports.setIntlayerConfigRoutingMode = require_init_utils_configManipulation.setIntlayerConfigRoutingMode;
64
65
  exports.setIntlayerConfigRoutingStorageOnly = require_init_utils_configManipulation.setIntlayerConfigRoutingStorageOnly;
@@ -286,7 +286,7 @@ const detectMissingIntlayerPackages = (allDependencies, options = {}) => {
286
286
  if (isInstalled("hono")) addIfMissing("hono-intlayer");
287
287
  if (isInstalled("elysia")) addIfMissing("elysia-intlayer");
288
288
  if (isInstalled("@adonisjs/core")) addIfMissing("adonis-intlayer");
289
- if (hasLintTooling(allDependencies)) addDevIfMissing("eslint-plugin-intlayer");
289
+ if (!options.skipLintPlugin && hasLintTooling(allDependencies)) addDevIfMissing("eslint-plugin-intlayer");
290
290
  if (isInstalled("next-intl") || isInstalled("@intlayer/next-intl")) {
291
291
  markCompatReplacement("next-intl", "@intlayer/next-intl");
292
292
  compatSyncConfig ??= {