@inlang/paraglide-js 2.25.4 → 2.27.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 (124) hide show
  1. package/README.md +2 -1
  2. package/dist/bundler-plugins/per-locale-build/vite-environments.test.js +2 -2
  3. package/dist/bundler-plugins/per-locale-build/vite-environments.test.js.map +1 -1
  4. package/dist/cli/commands/init/command.js +19 -1
  5. package/dist/cli/commands/init/command.js.map +1 -1
  6. package/dist/cli/defaults.js +2 -2
  7. package/dist/cli/defaults.js.map +1 -1
  8. package/dist/cli/steps/add-inlang-check.d.ts +19 -0
  9. package/dist/cli/steps/add-inlang-check.js +60 -0
  10. package/dist/cli/steps/add-inlang-check.js.map +1 -0
  11. package/dist/cli/steps/add-inlang-check.test.d.ts +1 -0
  12. package/dist/cli/steps/add-inlang-check.test.js +88 -0
  13. package/dist/cli/steps/add-inlang-check.test.js.map +1 -0
  14. package/dist/cli/steps/agents-md-suggestion.d.ts +11 -0
  15. package/dist/cli/steps/agents-md-suggestion.js +19 -0
  16. package/dist/cli/steps/agents-md-suggestion.js.map +1 -0
  17. package/dist/cli/steps/agents-md-suggestion.test.d.ts +1 -0
  18. package/dist/cli/steps/agents-md-suggestion.test.js +36 -0
  19. package/dist/cli/steps/agents-md-suggestion.test.js.map +1 -0
  20. package/dist/cli/steps/maybe-add-machine-translation.js +3 -2
  21. package/dist/cli/steps/maybe-add-machine-translation.js.map +1 -1
  22. package/dist/cli/steps/maybe-add-sherlock.js +1 -1
  23. package/dist/cli/steps/maybe-add-sherlock.js.map +1 -1
  24. package/dist/cli/utils.d.ts +9 -0
  25. package/dist/cli/utils.js +15 -0
  26. package/dist/cli/utils.js.map +1 -1
  27. package/dist/compiler/compile-annotation.d.ts +48 -1
  28. package/dist/compiler/compile-annotation.js +238 -10
  29. package/dist/compiler/compile-annotation.js.map +1 -1
  30. package/dist/compiler/compile-bundle.d.ts +3 -2
  31. package/dist/compiler/compile-bundle.js +30 -1
  32. package/dist/compiler/compile-bundle.js.map +1 -1
  33. package/dist/compiler/compile-bundle.test.js +18 -18
  34. package/dist/compiler/compile-bundle.test.js.map +1 -1
  35. package/dist/compiler/compile-local-variable.d.ts +3 -0
  36. package/dist/compiler/compile-local-variable.js +5 -2
  37. package/dist/compiler/compile-local-variable.js.map +1 -1
  38. package/dist/compiler/compile-local-variable.test.js +44 -4
  39. package/dist/compiler/compile-local-variable.test.js.map +1 -1
  40. package/dist/compiler/compile-message.d.ts +29 -1
  41. package/dist/compiler/compile-message.exact-number.test.d.ts +1 -0
  42. package/dist/compiler/compile-message.exact-number.test.js +786 -0
  43. package/dist/compiler/compile-message.exact-number.test.js.map +1 -0
  44. package/dist/compiler/compile-message.js +162 -66
  45. package/dist/compiler/compile-message.js.map +1 -1
  46. package/dist/compiler/compile-message.locals.test.d.ts +1 -0
  47. package/dist/compiler/compile-message.locals.test.js +498 -0
  48. package/dist/compiler/compile-message.locals.test.js.map +1 -0
  49. package/dist/compiler/compile-message.test.js +111 -20
  50. package/dist/compiler/compile-message.test.js.map +1 -1
  51. package/dist/compiler/compile-pattern.d.ts +5 -0
  52. package/dist/compiler/compile-pattern.js +6 -18
  53. package/dist/compiler/compile-pattern.js.map +1 -1
  54. package/dist/compiler/compile-pattern.test.js +165 -1
  55. package/dist/compiler/compile-pattern.test.js.map +1 -1
  56. package/dist/compiler/compile-project.js +4 -1
  57. package/dist/compiler/compile-project.js.map +1 -1
  58. package/dist/compiler/compile-project.test.js +1013 -31
  59. package/dist/compiler/compile-project.test.js.map +1 -1
  60. package/dist/compiler/compile.test.js +1 -1
  61. package/dist/compiler/compile.test.js.map +1 -1
  62. package/dist/compiler/create-readme.d.ts +4 -1
  63. package/dist/compiler/create-readme.js +33 -125
  64. package/dist/compiler/create-readme.js.map +1 -1
  65. package/dist/compiler/emit-ts-declarations.interop.test.js +2 -2
  66. package/dist/compiler/emit-ts-declarations.interop.test.js.map +1 -1
  67. package/dist/compiler/emit-ts-declarations.test.js +4 -4
  68. package/dist/compiler/emit-ts-declarations.test.js.map +1 -1
  69. package/dist/compiler/index.d.ts +1 -1
  70. package/dist/compiler/index.js +1 -1
  71. package/dist/compiler/index.js.map +1 -1
  72. package/dist/compiler/input-alias.d.ts +21 -0
  73. package/dist/compiler/input-alias.js +42 -0
  74. package/dist/compiler/input-alias.js.map +1 -0
  75. package/dist/compiler/input-alias.test.d.ts +1 -0
  76. package/dist/compiler/input-alias.test.js +58 -0
  77. package/dist/compiler/input-alias.test.js.map +1 -0
  78. package/dist/compiler/message-locals.d.ts +46 -0
  79. package/dist/compiler/message-locals.js +129 -0
  80. package/dist/compiler/message-locals.js.map +1 -0
  81. package/dist/compiler/output-structure/locale-modules.js +7 -1
  82. package/dist/compiler/output-structure/locale-modules.js.map +1 -1
  83. package/dist/compiler/output-structure/locale-modules.test.js +35 -0
  84. package/dist/compiler/output-structure/locale-modules.test.js.map +1 -1
  85. package/dist/compiler/output-structure/message-modules.js +5 -3
  86. package/dist/compiler/output-structure/message-modules.js.map +1 -1
  87. package/dist/compiler/output-structure/message-modules.test.js +35 -0
  88. package/dist/compiler/output-structure/message-modules.test.js.map +1 -1
  89. package/dist/compiler/registry.d.ts +12 -0
  90. package/dist/compiler/registry.js +97 -28
  91. package/dist/compiler/registry.js.map +1 -1
  92. package/dist/compiler/runtime/create-runtime.js +24 -1
  93. package/dist/compiler/runtime/create-runtime.js.map +1 -1
  94. package/dist/compiler/runtime/extract-locale-from-url.js +11 -4
  95. package/dist/compiler/runtime/extract-locale-from-url.js.map +1 -1
  96. package/dist/compiler/runtime/generate-static-localized-urls.js +5 -3
  97. package/dist/compiler/runtime/generate-static-localized-urls.js.map +1 -1
  98. package/dist/compiler/runtime/localize-url.js +25 -54
  99. package/dist/compiler/runtime/localize-url.js.map +1 -1
  100. package/dist/compiler/runtime/route-strategy.js +9 -3
  101. package/dist/compiler/runtime/route-strategy.js.map +1 -1
  102. package/dist/compiler/runtime/type.test.js +9 -0
  103. package/dist/compiler/runtime/type.test.js.map +1 -1
  104. package/dist/compiler/runtime/url-pattern-cache.d.ts +11 -0
  105. package/dist/compiler/runtime/url-pattern-cache.js +42 -0
  106. package/dist/compiler/runtime/url-pattern-cache.js.map +1 -0
  107. package/dist/compiler/runtime/url-pattern-index.d.ts +24 -0
  108. package/dist/compiler/runtime/url-pattern-index.differential.test.d.ts +1 -0
  109. package/dist/compiler/runtime/url-pattern-index.differential.test.js +152 -0
  110. package/dist/compiler/runtime/url-pattern-index.differential.test.js.map +1 -0
  111. package/dist/compiler/runtime/url-pattern-index.js +168 -0
  112. package/dist/compiler/runtime/url-pattern-index.js.map +1 -0
  113. package/dist/compiler/runtime/url-pattern-index.test.d.ts +1 -0
  114. package/dist/compiler/runtime/url-pattern-index.test.js +262 -0
  115. package/dist/compiler/runtime/url-pattern-index.test.js.map +1 -0
  116. package/dist/compiler/server/create-server-file.js +25 -1
  117. package/dist/compiler/server/create-server-file.js.map +1 -1
  118. package/dist/compiler/server/create-server-file.test.js +20 -2
  119. package/dist/compiler/server/create-server-file.test.js.map +1 -1
  120. package/dist/compiler/server/middleware.js +29 -4
  121. package/dist/compiler/server/middleware.js.map +1 -1
  122. package/dist/services/env-variables/index.js +1 -1
  123. package/dist/services/env-variables/index.js.map +1 -1
  124. package/package.json +3 -3
package/README.md CHANGED
@@ -283,6 +283,7 @@ Paraglide supports locale-aware formatting via declaration formatters:
283
283
  - `plural` (`Intl.PluralRules`) for plural and ordinal categories
284
284
  - `number` (`Intl.NumberFormat`) for numbers, currency, compact notation, and more
285
285
  - `datetime` (`Intl.DateTimeFormat`) for dates/times with locale-aware output
286
+ - `date`, `time` and `icu:pound` for ICU MessageFormat 1 `{d, date}`, `{d, time}` and `#`, see [Formatting](https://paraglidejs.com/formatting#icu-messageformat-1-styles)
286
287
  - `relativetime` (`Intl.RelativeTimeFormat`) for values like "yesterday", "in 2 days", or "3 hr. ago"
287
288
 
288
289
  Gender and custom selects are supported via the variants system.
@@ -374,7 +375,7 @@ Paraglide compiles messages from [inlang](https://github.com/opral/inlang), the
374
375
  | Tool | Description |
375
376
  | ----------------------------------------------------------------------- | ------------------------------------------------ |
376
377
  | [Sherlock](https://inlang.com/m/r7kp499g/app-inlang-ideExtension) | VS Code extension for inline translation editing |
377
- | [CLI](https://inlang.com/m/2qj2w8pu/app-inlang-cli) | Machine translate from the terminal |
378
+ | [CLI](https://inlang.com/m/2qj2w8pu/app-inlang-cli) | Machine translate and check translations in CI |
378
379
  | [Fink](https://inlang.com/m/tdozzpar/app-inlang-finkLocalizationEditor) | Translation editor for non-developers |
379
380
  | [Parrot](https://inlang.com/m/gkrpgoir/app-parrot-figmaPlugin) | Manage translations in Figma |
380
381
 
@@ -229,13 +229,13 @@ test("keeps compiled Paraglide translations out of other locale source maps", as
229
229
  function createMessage(locale, value) {
230
230
  return {
231
231
  id: `greeting-${locale}`,
232
- bundleId: "greeting",
232
+ bundle_id: "greeting",
233
233
  locale,
234
234
  selectors: [],
235
235
  variants: [
236
236
  {
237
237
  id: `greeting-${locale}-variant`,
238
- messageId: `greeting-${locale}`,
238
+ message_id: `greeting-${locale}`,
239
239
  matches: [],
240
240
  pattern: [{ type: "text", value }],
241
241
  },
@@ -1 +1 @@
1
- {"version":3,"file":"vite-environments.test.js","sourceRoot":"","sources":["../../../src/bundler-plugins/per-locale-build/vite-environments.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,EACN,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,GAEV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,oCAAoC,EAAE,MAAM,oC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CAAC,CAAC,IAAI,EAAE,EAAE,CACb,MAAM,CAAC,QAAQ,CACd,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,EAC1D,MAAM,CACN,CACD,CACF,CACD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC","sourcesContent":["import nodeFs from \"node:fs/promises\";\nimport nodeOs from \"node:os\";\nimport nodePath from \"node:path\";\nimport {\n\tinsertBundleNested,\n\tloadProjectInMemory,\n\tnewProject,\n\ttype BundleNested,\n} from \"@inlang/sdk\";\nimport { createBuilder } from \"vite\";\nimport { expect, test } from \"vitest\";\nimport { compileProject } from \"../../compiler/compile-project.js\";\nimport { perLocaleBuildStaticLocaleExpression } from \"../../compiler/per-locale-build.js\";\nimport {\n\tcreateViteLocaleBuildPlan,\n\tcreateViteLocaleEnvironmentPlugin,\n\ttype ViteLocaleBuildManifest,\n\tVITE_LOCALE_BUILD_MANIFEST,\n} from \"./vite-environments.js\";\n\ntest(\"creates deterministic locale environment names and output directories\", () => {\n\texpect(\n\t\tcreateViteLocaleBuildPlan({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"zh-Hant\"],\n\t\t\t},\n\t\t\toutputDirectory: \"build\",\n\t\t})\n\t).toEqual({\n\t\toutputDirectory: \"build\",\n\t\tvariants: [\n\t\t\t{\n\t\t\t\tlocale: \"en\",\n\t\t\t\tenvironmentName: \"paraglide_client_en_656e\",\n\t\t\t\tdirectory: \"__paraglide/en-656e\",\n\t\t\t\toutputDirectory: \"build/__paraglide/en-656e\",\n\t\t\t\tdefine: {\n\t\t\t\t\t\"globalThis.__PARAGLIDE_STATIC_LOCALE__\": '\"en\"',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tlocale: \"zh-Hant\",\n\t\t\t\tenvironmentName: \"paraglide_client_zh_Hant_7a682d48616e74\",\n\t\t\t\tdirectory: \"__paraglide/zh-Hant-7a682d48616e74\",\n\t\t\t\toutputDirectory: \"build/__paraglide/zh-Hant-7a682d48616e74\",\n\t\t\t\tdefine: {\n\t\t\t\t\t\"globalThis.__PARAGLIDE_STATIC_LOCALE__\": '\"zh-Hant\"',\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t});\n\texpect(() =>\n\t\tcreateViteLocaleBuildPlan({\n\t\t\tsettings: { baseLocale: \"en\", locales: [\"en\"] },\n\t\t\toutputDirectory: \"../outside\",\n\t\t})\n\t).toThrow(\"must be a project-relative directory\");\n});\n\ntest(\"builds closed, source-mapped Rolldown graphs without post-processing\", async () => {\n\tconst temporaryRoot = await nodeFs.mkdtemp(\n\t\tnodePath.join(nodeOs.tmpdir(), \"paraglide-vite-environments-\")\n\t);\n\tconst root = await nodeFs.realpath(temporaryRoot);\n\ttry {\n\t\tawait nodeFs.mkdir(nodePath.join(root, \"src/messages\"), {\n\t\t\trecursive: true,\n\t\t});\n\t\tawait Promise.all([\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"index.html\"),\n\t\t\t\t'<main id=\"app\"></main><script type=\"module\" src=\"./src/main.js\"></script>\\n'\n\t\t\t),\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"src/main.js\"),\n\t\t\t\t[\n\t\t\t\t\t'import \"./style.css\";',\n\t\t\t\t\t'import \"external-dependency\";',\n\t\t\t\t\t'import { message, loadLazy } from \"./messages/_index.js\";',\n\t\t\t\t\t'document.querySelector(\"#app\").textContent = message;',\n\t\t\t\t\t\"loadLazy().then((module) => module.mount());\",\n\t\t\t\t\t\"\",\n\t\t\t\t].join(\"\\n\")\n\t\t\t),\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"src/messages/_index.js\"),\n\t\t\t\t[\n\t\t\t\t\t\" const locale = globalThis.__PARAGLIDE_STATIC_LOCALE__;\",\n\t\t\t\t\t'import * as en from \"./en.js\";',\n\t\t\t\t\t'import * as de from \"./de.js\";',\n\t\t\t\t\t\"export const message = locale === 'en' ? en.message : de.message;\",\n\t\t\t\t\t\"export const loadLazy = locale === 'en'\",\n\t\t\t\t\t' ? () => import(\"./en-lazy.js\")',\n\t\t\t\t\t' : () => import(\"./de-lazy.js\");',\n\t\t\t\t\t\"\",\n\t\t\t\t].join(\"\\n\")\n\t\t\t),\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"src/messages/en.js\"),\n\t\t\t\t'export const message = \"EN_ONLY_MESSAGE\";\\n'\n\t\t\t),\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"src/messages/de.js\"),\n\t\t\t\t'export const message = \"DE_ONLY_MESSAGE\";\\n'\n\t\t\t),\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"src/messages/en-lazy.js\"),\n\t\t\t\t'export function mount() { document.body.dataset.lazy = \"EN_ONLY_LAZY\"; }\\n'\n\t\t\t),\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"src/messages/de-lazy.js\"),\n\t\t\t\t'export function mount() { document.body.dataset.lazy = \"DE_ONLY_LAZY\"; }\\n'\n\t\t\t),\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"src/style.css\"),\n\t\t\t\t\"#app { color: rebeccapurple; }\\n\"\n\t\t\t),\n\t\t]);\n\t\tawait nodeFs.mkdir(\n\t\t\tnodePath.join(root, \"build/__paraglide/removed-locale\"),\n\t\t\t{ recursive: true }\n\t\t);\n\t\tawait Promise.all([\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"build/__paraglide/removed-locale/stale.js\"),\n\t\t\t\t\"stale\"\n\t\t\t),\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"build\", VITE_LOCALE_BUILD_MANIFEST),\n\t\t\t\t'{\"stale\":true}\\n'\n\t\t\t),\n\t\t]);\n\n\t\tlet renderBuiltUrlCalls = 0;\n\t\tconst builder = await createBuilder({\n\t\t\tconfigFile: false,\n\t\t\troot,\n\t\t\tbase: \"./\",\n\t\t\tlogLevel: \"silent\",\n\t\t\texperimental: {\n\t\t\t\trenderBuiltUrl() {\n\t\t\t\t\trenderBuiltUrlCalls += 1;\n\t\t\t\t\treturn { relative: true };\n\t\t\t\t},\n\t\t\t},\n\t\t\tbuild: {\n\t\t\t\toutDir: \"build\",\n\t\t\t\tminify: false,\n\t\t\t\tsourcemap: true,\n\t\t\t\trolldownOptions: {\n\t\t\t\t\texternal: [\"external-dependency\"],\n\t\t\t\t\toutput: {\n\t\t\t\t\t\tentryFileNames: \"custom/[name]-[hash].js\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tplugins: [\n\t\t\t\tcreateViteLocaleEnvironmentPlugin({\n\t\t\t\t\tsettings: async () => ({\n\t\t\t\t\t\tbaseLocale: \"en\",\n\t\t\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t],\n\t\t});\n\t\tawait builder.buildApp();\n\n\t\tconst outputRoot = nodePath.join(root, \"build\");\n\t\tconst manifest = JSON.parse(\n\t\t\tawait nodeFs.readFile(\n\t\t\t\tnodePath.join(outputRoot, VITE_LOCALE_BUILD_MANIFEST),\n\t\t\t\t\"utf8\"\n\t\t\t)\n\t\t) as ViteLocaleBuildManifest;\n\t\texpect(manifest.backend).toBe(\"vite-rolldown-environments\");\n\t\texpect(Object.keys(manifest.locales)).toEqual([\"en\", \"de\"]);\n\t\texpect(renderBuiltUrlCalls).toBeGreaterThan(0);\n\t\tawait expect(\n\t\t\tnodeFs.access(\n\t\t\t\tnodePath.join(outputRoot, \"__paraglide/removed-locale/stale.js\")\n\t\t\t)\n\t\t).rejects.toThrow();\n\n\t\tfor (const locale of [\"en\", \"de\"] as const) {\n\t\t\tconst localeManifest = manifest.locales[locale]!;\n\t\t\texpect(localeManifest.directory).toMatch(\n\t\t\t\tnew RegExp(`^__paraglide/${locale}-`)\n\t\t\t);\n\t\t\texpect(localeManifest.files.some((file) => file.entry)).toBe(true);\n\t\t\texpect(\n\t\t\t\tlocaleManifest.files.some(\n\t\t\t\t\t(file) => file.entry && file.fileName.startsWith(\"custom/\")\n\t\t\t\t)\n\t\t\t).toBe(true);\n\t\t\texpect(\n\t\t\t\tlocaleManifest.files.some((file) =>\n\t\t\t\t\tfile.externalImports?.includes(\"external-dependency\")\n\t\t\t\t)\n\t\t\t).toBe(true);\n\t\t\texpect(\n\t\t\t\tlocaleManifest.files.some((file) => file.fileName.endsWith(\".map\"))\n\t\t\t).toBe(true);\n\n\t\t\tconst names = new Set(localeManifest.files.map((file) => file.fileName));\n\t\t\tfor (const file of localeManifest.files) {\n\t\t\t\tfor (const imported of [\n\t\t\t\t\t...(file.imports ?? []),\n\t\t\t\t\t...(file.dynamicImports ?? []),\n\t\t\t\t]) {\n\t\t\t\t\texpect(names.has(imported)).toBe(true);\n\t\t\t\t}\n\t\t\t\tconst bytes = (\n\t\t\t\t\tawait nodeFs.readFile(\n\t\t\t\t\t\tnodePath.join(outputRoot, localeManifest.directory, file.fileName)\n\t\t\t\t\t)\n\t\t\t\t).byteLength;\n\t\t\t\texpect(bytes).toBe(file.bytes);\n\t\t\t}\n\t\t}\n\n\t\tconst enJavaScript = await readJavaScriptGraph(\n\t\t\toutputRoot,\n\t\t\tmanifest.locales.en!\n\t\t);\n\t\tconst deJavaScript = await readJavaScriptGraph(\n\t\t\toutputRoot,\n\t\t\tmanifest.locales.de!\n\t\t);\n\t\texpect(enJavaScript).toContain(\"EN_ONLY_MESSAGE\");\n\t\texpect(enJavaScript).toContain(\"EN_ONLY_LAZY\");\n\t\texpect(enJavaScript).not.toContain(\"DE_ONLY_MESSAGE\");\n\t\texpect(enJavaScript).not.toContain(\"DE_ONLY_LAZY\");\n\t\texpect(deJavaScript).toContain(\"DE_ONLY_MESSAGE\");\n\t\texpect(deJavaScript).toContain(\"DE_ONLY_LAZY\");\n\t\texpect(deJavaScript).not.toContain(\"EN_ONLY_MESSAGE\");\n\t\texpect(deJavaScript).not.toContain(\"EN_ONLY_LAZY\");\n\n\t\tconst enSourceMaps = await readSourceMaps(outputRoot, manifest.locales.en!);\n\t\tconst deSourceMaps = await readSourceMaps(outputRoot, manifest.locales.de!);\n\t\texpect(enSourceMaps).not.toContain(\"DE_ONLY_MESSAGE\");\n\t\texpect(enSourceMaps).not.toContain(\"DE_ONLY_LAZY\");\n\t\texpect(deSourceMaps).not.toContain(\"EN_ONLY_MESSAGE\");\n\t\texpect(deSourceMaps).not.toContain(\"EN_ONLY_LAZY\");\n\t} finally {\n\t\tawait nodeFs.rm(temporaryRoot, { recursive: true, force: true });\n\t}\n});\n\ntest(\"keeps compiled Paraglide translations out of other locale source maps\", async () => {\n\tconst temporaryRoot = await nodeFs.mkdtemp(\n\t\tnodePath.join(nodeOs.tmpdir(), \"paraglide-vite-compiled-\")\n\t);\n\tconst root = await nodeFs.realpath(temporaryRoot);\n\tconst project = await loadProjectInMemory({\n\t\tblob: await newProject({\n\t\t\tsettings: { baseLocale: \"en\", locales: [\"en\", \"de\"] },\n\t\t}),\n\t});\n\ttry {\n\t\tawait insertBundleNested(project.db, {\n\t\t\tid: \"greeting\",\n\t\t\tdeclarations: [],\n\t\t\tmessages: [\n\t\t\t\tcreateMessage(\"en\", \"EN_COMPILED_TRANSLATION\"),\n\t\t\t\tcreateMessage(\"de\", \"DE_COMPILED_TRANSLATION\"),\n\t\t\t],\n\t\t} satisfies BundleNested);\n\t\tconst generated = await compileProject({\n\t\t\tproject,\n\t\t\tcompilerOptions: {\n\t\t\t\toutputStructure: \"locale-modules\",\n\t\t\t\texperimentalStaticLocale: perLocaleBuildStaticLocaleExpression,\n\t\t\t\temitGitIgnore: false,\n\t\t\t\temitPrettierIgnore: false,\n\t\t\t\temitReadme: false,\n\t\t\t},\n\t\t});\n\t\tconst generatedRoot = nodePath.join(root, \"src/paraglide\");\n\t\tfor (const [fileName, source] of Object.entries(generated)) {\n\t\t\tconst path = nodePath.join(generatedRoot, fileName);\n\t\t\tawait nodeFs.mkdir(nodePath.dirname(path), { recursive: true });\n\t\t\tawait nodeFs.writeFile(path, source);\n\t\t}\n\t\tawait Promise.all([\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"index.html\"),\n\t\t\t\t'<script type=\"module\" src=\"./src/main.js\"></script>\\n'\n\t\t\t),\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"src/main.js\"),\n\t\t\t\t'import { greeting } from \"./paraglide/messages.js\";\\ndocument.body.textContent = greeting();\\n'\n\t\t\t),\n\t\t]);\n\n\t\tconst builder = await createBuilder({\n\t\t\tconfigFile: false,\n\t\t\troot,\n\t\t\tbase: \"./\",\n\t\t\tlogLevel: \"silent\",\n\t\t\tbuild: { minify: false, sourcemap: true },\n\t\t\tplugins: [\n\t\t\t\tcreateViteLocaleEnvironmentPlugin({\n\t\t\t\t\tsettings: async () => ({\n\t\t\t\t\t\tbaseLocale: \"en\",\n\t\t\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t],\n\t\t});\n\t\tawait builder.buildApp();\n\n\t\tconst outputRoot = nodePath.join(root, \"dist\");\n\t\tconst manifest = JSON.parse(\n\t\t\tawait nodeFs.readFile(\n\t\t\t\tnodePath.join(outputRoot, VITE_LOCALE_BUILD_MANIFEST),\n\t\t\t\t\"utf8\"\n\t\t\t)\n\t\t) as ViteLocaleBuildManifest;\n\t\tconst enGraph = await readGraphText(outputRoot, manifest.locales.en!);\n\t\tconst deGraph = await readGraphText(outputRoot, manifest.locales.de!);\n\t\texpect(enGraph).toContain(\"EN_COMPILED_TRANSLATION\");\n\t\texpect(enGraph).not.toContain(\"DE_COMPILED_TRANSLATION\");\n\t\texpect(deGraph).toContain(\"DE_COMPILED_TRANSLATION\");\n\t\texpect(deGraph).not.toContain(\"EN_COMPILED_TRANSLATION\");\n\t} finally {\n\t\tawait project.close();\n\t\tawait nodeFs.rm(temporaryRoot, { recursive: true, force: true });\n\t}\n});\n\nfunction createMessage(locale: \"en\" | \"de\", value: string) {\n\treturn {\n\t\tid: `greeting-${locale}`,\n\t\tbundleId: \"greeting\",\n\t\tlocale,\n\t\tselectors: [],\n\t\tvariants: [\n\t\t\t{\n\t\t\t\tid: `greeting-${locale}-variant`,\n\t\t\t\tmessageId: `greeting-${locale}`,\n\t\t\t\tmatches: [],\n\t\t\t\tpattern: [{ type: \"text\" as const, value }],\n\t\t\t},\n\t\t],\n\t};\n}\n\nasync function readJavaScriptGraph(\n\toutputRoot: string,\n\tlocale: ViteLocaleBuildManifest[\"locales\"][string]\n): Promise<string> {\n\tconst chunks = locale.files.filter(\n\t\t(file) => file.type === \"chunk\" && file.fileName.endsWith(\".js\")\n\t);\n\treturn (\n\t\tawait Promise.all(\n\t\t\tchunks.map((chunk) =>\n\t\t\t\tnodeFs.readFile(\n\t\t\t\t\tnodePath.join(outputRoot, locale.directory, chunk.fileName),\n\t\t\t\t\t\"utf8\"\n\t\t\t\t)\n\t\t\t)\n\t\t)\n\t).join(\"\\n\");\n}\n\nasync function readSourceMaps(\n\toutputRoot: string,\n\tlocale: ViteLocaleBuildManifest[\"locales\"][string]\n): Promise<string> {\n\treturn (\n\t\tawait Promise.all(\n\t\t\tlocale.files\n\t\t\t\t.filter((file) => file.fileName.endsWith(\".map\"))\n\t\t\t\t.map((file) =>\n\t\t\t\t\tnodeFs.readFile(\n\t\t\t\t\t\tnodePath.join(outputRoot, locale.directory, file.fileName),\n\t\t\t\t\t\t\"utf8\"\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t)\n\t).join(\"\\n\");\n}\n\nasync function readGraphText(\n\toutputRoot: string,\n\tlocale: ViteLocaleBuildManifest[\"locales\"][string]\n): Promise<string> {\n\treturn (\n\t\tawait Promise.all(\n\t\t\tlocale.files\n\t\t\t\t.filter(\n\t\t\t\t\t(file) =>\n\t\t\t\t\t\t(file.type === \"chunk\" && file.fileName.endsWith(\".js\")) ||\n\t\t\t\t\t\tfile.fileName.endsWith(\".map\")\n\t\t\t\t)\n\t\t\t\t.map((file) =>\n\t\t\t\t\tnodeFs.readFile(\n\t\t\t\t\t\tnodePath.join(outputRoot, locale.directory, file.fileName),\n\t\t\t\t\t\t\"utf8\"\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t)\n\t).join(\"\\n\");\n}\n"]}
1
+ {"version":3,"file":"vite-environments.test.js","sourceRoot":"","sources":["../../../src/bundler-plugins/per-locale-build/vite-environments.test.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,kBAAkB,CAAC;AACtC,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,QAAQ,MAAM,WAAW,CAAC;AACjC,OAAO,EACN,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,GAEV,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,mCAAmC,CAAC;AACnE,OAAO,EAAE,oCAAoC,EAAE,MAAM,oCAAoC,CAAC;AAC1F,OAAO,EACN,yBAAyB,EACzB,iCAAiC,EAEjC,0BAA0B,GAC1B,MAAM,wBAAwB,CAAC;AAEhC,IAAI,CAAC,uEAAuE,EAAE,GAAG,EAAE;IAClF,MAAM,CACL,yBAAyB,CAAC;QACzB,QAAQ,EAAE;YACT,UAAU,EAAE,IAAI;YAChB,OAAO,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC;SAC1B;QACD,eAAe,EAAE,OAAO;KACxB,CAAC,CACF,CAAC,OAAO,CAAC;QACT,eAAe,EAAE,OAAO;QACxB,QAAQ,EAAE;YACT;gBACC,MAAM,EAAE,IAAI;gBACZ,eAAe,EAAE,0BAA0B;gBAC3C,SAAS,EAAE,qBAAqB;gBAChC,eAAe,EAAE,2BAA2B;gBAC5C,MAAM,EAAE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CACN,MAAM,OAAO,CAAC,GAAG,CAChB,MAAM,CAAC,KAAK;SACV,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;SAChD,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACb,MAAM,CAAC,QAAQ,CACd,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,EAC1D,MAAM,CACN,CACD,CACF,CACD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC;AAED,KAAK,UAAU,aAAa,CAC3B,UAAkB,EAClB,MAAkD;IAElD,OAAO,CACN,MAAM,OAAO,CAAC,GAAG,CAChB,MAAM,CAAC,KAAK;SACV,MAAM,CACN,CAAC,IAAI,EAAE,EAAE,CACR,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACxD,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAC/B;SACA,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CACb,MAAM,CAAC,QAAQ,CACd,QAAQ,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,QAAQ,CAAC,EAC1D,MAAM,CACN,CACD,CACF,CACD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC","sourcesContent":["import nodeFs from \"node:fs/promises\";\nimport nodeOs from \"node:os\";\nimport nodePath from \"node:path\";\nimport {\n\tinsertBundleNested,\n\tloadProjectInMemory,\n\tnewProject,\n\ttype BundleNested,\n} from \"@inlang/sdk\";\nimport { createBuilder } from \"vite\";\nimport { expect, test } from \"vitest\";\nimport { compileProject } from \"../../compiler/compile-project.js\";\nimport { perLocaleBuildStaticLocaleExpression } from \"../../compiler/per-locale-build.js\";\nimport {\n\tcreateViteLocaleBuildPlan,\n\tcreateViteLocaleEnvironmentPlugin,\n\ttype ViteLocaleBuildManifest,\n\tVITE_LOCALE_BUILD_MANIFEST,\n} from \"./vite-environments.js\";\n\ntest(\"creates deterministic locale environment names and output directories\", () => {\n\texpect(\n\t\tcreateViteLocaleBuildPlan({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"zh-Hant\"],\n\t\t\t},\n\t\t\toutputDirectory: \"build\",\n\t\t})\n\t).toEqual({\n\t\toutputDirectory: \"build\",\n\t\tvariants: [\n\t\t\t{\n\t\t\t\tlocale: \"en\",\n\t\t\t\tenvironmentName: \"paraglide_client_en_656e\",\n\t\t\t\tdirectory: \"__paraglide/en-656e\",\n\t\t\t\toutputDirectory: \"build/__paraglide/en-656e\",\n\t\t\t\tdefine: {\n\t\t\t\t\t\"globalThis.__PARAGLIDE_STATIC_LOCALE__\": '\"en\"',\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tlocale: \"zh-Hant\",\n\t\t\t\tenvironmentName: \"paraglide_client_zh_Hant_7a682d48616e74\",\n\t\t\t\tdirectory: \"__paraglide/zh-Hant-7a682d48616e74\",\n\t\t\t\toutputDirectory: \"build/__paraglide/zh-Hant-7a682d48616e74\",\n\t\t\t\tdefine: {\n\t\t\t\t\t\"globalThis.__PARAGLIDE_STATIC_LOCALE__\": '\"zh-Hant\"',\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t});\n\texpect(() =>\n\t\tcreateViteLocaleBuildPlan({\n\t\t\tsettings: { baseLocale: \"en\", locales: [\"en\"] },\n\t\t\toutputDirectory: \"../outside\",\n\t\t})\n\t).toThrow(\"must be a project-relative directory\");\n});\n\ntest(\"builds closed, source-mapped Rolldown graphs without post-processing\", async () => {\n\tconst temporaryRoot = await nodeFs.mkdtemp(\n\t\tnodePath.join(nodeOs.tmpdir(), \"paraglide-vite-environments-\")\n\t);\n\tconst root = await nodeFs.realpath(temporaryRoot);\n\ttry {\n\t\tawait nodeFs.mkdir(nodePath.join(root, \"src/messages\"), {\n\t\t\trecursive: true,\n\t\t});\n\t\tawait Promise.all([\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"index.html\"),\n\t\t\t\t'<main id=\"app\"></main><script type=\"module\" src=\"./src/main.js\"></script>\\n'\n\t\t\t),\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"src/main.js\"),\n\t\t\t\t[\n\t\t\t\t\t'import \"./style.css\";',\n\t\t\t\t\t'import \"external-dependency\";',\n\t\t\t\t\t'import { message, loadLazy } from \"./messages/_index.js\";',\n\t\t\t\t\t'document.querySelector(\"#app\").textContent = message;',\n\t\t\t\t\t\"loadLazy().then((module) => module.mount());\",\n\t\t\t\t\t\"\",\n\t\t\t\t].join(\"\\n\")\n\t\t\t),\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"src/messages/_index.js\"),\n\t\t\t\t[\n\t\t\t\t\t\" const locale = globalThis.__PARAGLIDE_STATIC_LOCALE__;\",\n\t\t\t\t\t'import * as en from \"./en.js\";',\n\t\t\t\t\t'import * as de from \"./de.js\";',\n\t\t\t\t\t\"export const message = locale === 'en' ? en.message : de.message;\",\n\t\t\t\t\t\"export const loadLazy = locale === 'en'\",\n\t\t\t\t\t' ? () => import(\"./en-lazy.js\")',\n\t\t\t\t\t' : () => import(\"./de-lazy.js\");',\n\t\t\t\t\t\"\",\n\t\t\t\t].join(\"\\n\")\n\t\t\t),\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"src/messages/en.js\"),\n\t\t\t\t'export const message = \"EN_ONLY_MESSAGE\";\\n'\n\t\t\t),\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"src/messages/de.js\"),\n\t\t\t\t'export const message = \"DE_ONLY_MESSAGE\";\\n'\n\t\t\t),\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"src/messages/en-lazy.js\"),\n\t\t\t\t'export function mount() { document.body.dataset.lazy = \"EN_ONLY_LAZY\"; }\\n'\n\t\t\t),\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"src/messages/de-lazy.js\"),\n\t\t\t\t'export function mount() { document.body.dataset.lazy = \"DE_ONLY_LAZY\"; }\\n'\n\t\t\t),\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"src/style.css\"),\n\t\t\t\t\"#app { color: rebeccapurple; }\\n\"\n\t\t\t),\n\t\t]);\n\t\tawait nodeFs.mkdir(\n\t\t\tnodePath.join(root, \"build/__paraglide/removed-locale\"),\n\t\t\t{ recursive: true }\n\t\t);\n\t\tawait Promise.all([\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"build/__paraglide/removed-locale/stale.js\"),\n\t\t\t\t\"stale\"\n\t\t\t),\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"build\", VITE_LOCALE_BUILD_MANIFEST),\n\t\t\t\t'{\"stale\":true}\\n'\n\t\t\t),\n\t\t]);\n\n\t\tlet renderBuiltUrlCalls = 0;\n\t\tconst builder = await createBuilder({\n\t\t\tconfigFile: false,\n\t\t\troot,\n\t\t\tbase: \"./\",\n\t\t\tlogLevel: \"silent\",\n\t\t\texperimental: {\n\t\t\t\trenderBuiltUrl() {\n\t\t\t\t\trenderBuiltUrlCalls += 1;\n\t\t\t\t\treturn { relative: true };\n\t\t\t\t},\n\t\t\t},\n\t\t\tbuild: {\n\t\t\t\toutDir: \"build\",\n\t\t\t\tminify: false,\n\t\t\t\tsourcemap: true,\n\t\t\t\trolldownOptions: {\n\t\t\t\t\texternal: [\"external-dependency\"],\n\t\t\t\t\toutput: {\n\t\t\t\t\t\tentryFileNames: \"custom/[name]-[hash].js\",\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tplugins: [\n\t\t\t\tcreateViteLocaleEnvironmentPlugin({\n\t\t\t\t\tsettings: async () => ({\n\t\t\t\t\t\tbaseLocale: \"en\",\n\t\t\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t],\n\t\t});\n\t\tawait builder.buildApp();\n\n\t\tconst outputRoot = nodePath.join(root, \"build\");\n\t\tconst manifest = JSON.parse(\n\t\t\tawait nodeFs.readFile(\n\t\t\t\tnodePath.join(outputRoot, VITE_LOCALE_BUILD_MANIFEST),\n\t\t\t\t\"utf8\"\n\t\t\t)\n\t\t) as ViteLocaleBuildManifest;\n\t\texpect(manifest.backend).toBe(\"vite-rolldown-environments\");\n\t\texpect(Object.keys(manifest.locales)).toEqual([\"en\", \"de\"]);\n\t\texpect(renderBuiltUrlCalls).toBeGreaterThan(0);\n\t\tawait expect(\n\t\t\tnodeFs.access(\n\t\t\t\tnodePath.join(outputRoot, \"__paraglide/removed-locale/stale.js\")\n\t\t\t)\n\t\t).rejects.toThrow();\n\n\t\tfor (const locale of [\"en\", \"de\"] as const) {\n\t\t\tconst localeManifest = manifest.locales[locale]!;\n\t\t\texpect(localeManifest.directory).toMatch(\n\t\t\t\tnew RegExp(`^__paraglide/${locale}-`)\n\t\t\t);\n\t\t\texpect(localeManifest.files.some((file) => file.entry)).toBe(true);\n\t\t\texpect(\n\t\t\t\tlocaleManifest.files.some(\n\t\t\t\t\t(file) => file.entry && file.fileName.startsWith(\"custom/\")\n\t\t\t\t)\n\t\t\t).toBe(true);\n\t\t\texpect(\n\t\t\t\tlocaleManifest.files.some((file) =>\n\t\t\t\t\tfile.externalImports?.includes(\"external-dependency\")\n\t\t\t\t)\n\t\t\t).toBe(true);\n\t\t\texpect(\n\t\t\t\tlocaleManifest.files.some((file) => file.fileName.endsWith(\".map\"))\n\t\t\t).toBe(true);\n\n\t\t\tconst names = new Set(localeManifest.files.map((file) => file.fileName));\n\t\t\tfor (const file of localeManifest.files) {\n\t\t\t\tfor (const imported of [\n\t\t\t\t\t...(file.imports ?? []),\n\t\t\t\t\t...(file.dynamicImports ?? []),\n\t\t\t\t]) {\n\t\t\t\t\texpect(names.has(imported)).toBe(true);\n\t\t\t\t}\n\t\t\t\tconst bytes = (\n\t\t\t\t\tawait nodeFs.readFile(\n\t\t\t\t\t\tnodePath.join(outputRoot, localeManifest.directory, file.fileName)\n\t\t\t\t\t)\n\t\t\t\t).byteLength;\n\t\t\t\texpect(bytes).toBe(file.bytes);\n\t\t\t}\n\t\t}\n\n\t\tconst enJavaScript = await readJavaScriptGraph(\n\t\t\toutputRoot,\n\t\t\tmanifest.locales.en!\n\t\t);\n\t\tconst deJavaScript = await readJavaScriptGraph(\n\t\t\toutputRoot,\n\t\t\tmanifest.locales.de!\n\t\t);\n\t\texpect(enJavaScript).toContain(\"EN_ONLY_MESSAGE\");\n\t\texpect(enJavaScript).toContain(\"EN_ONLY_LAZY\");\n\t\texpect(enJavaScript).not.toContain(\"DE_ONLY_MESSAGE\");\n\t\texpect(enJavaScript).not.toContain(\"DE_ONLY_LAZY\");\n\t\texpect(deJavaScript).toContain(\"DE_ONLY_MESSAGE\");\n\t\texpect(deJavaScript).toContain(\"DE_ONLY_LAZY\");\n\t\texpect(deJavaScript).not.toContain(\"EN_ONLY_MESSAGE\");\n\t\texpect(deJavaScript).not.toContain(\"EN_ONLY_LAZY\");\n\n\t\tconst enSourceMaps = await readSourceMaps(outputRoot, manifest.locales.en!);\n\t\tconst deSourceMaps = await readSourceMaps(outputRoot, manifest.locales.de!);\n\t\texpect(enSourceMaps).not.toContain(\"DE_ONLY_MESSAGE\");\n\t\texpect(enSourceMaps).not.toContain(\"DE_ONLY_LAZY\");\n\t\texpect(deSourceMaps).not.toContain(\"EN_ONLY_MESSAGE\");\n\t\texpect(deSourceMaps).not.toContain(\"EN_ONLY_LAZY\");\n\t} finally {\n\t\tawait nodeFs.rm(temporaryRoot, { recursive: true, force: true });\n\t}\n});\n\ntest(\"keeps compiled Paraglide translations out of other locale source maps\", async () => {\n\tconst temporaryRoot = await nodeFs.mkdtemp(\n\t\tnodePath.join(nodeOs.tmpdir(), \"paraglide-vite-compiled-\")\n\t);\n\tconst root = await nodeFs.realpath(temporaryRoot);\n\tconst project = await loadProjectInMemory({\n\t\tblob: await newProject({\n\t\t\tsettings: { baseLocale: \"en\", locales: [\"en\", \"de\"] },\n\t\t}),\n\t});\n\ttry {\n\t\tawait insertBundleNested(project.db, {\n\t\t\tid: \"greeting\",\n\t\t\tdeclarations: [],\n\t\t\tmessages: [\n\t\t\t\tcreateMessage(\"en\", \"EN_COMPILED_TRANSLATION\"),\n\t\t\t\tcreateMessage(\"de\", \"DE_COMPILED_TRANSLATION\"),\n\t\t\t],\n\t\t} satisfies BundleNested);\n\t\tconst generated = await compileProject({\n\t\t\tproject,\n\t\t\tcompilerOptions: {\n\t\t\t\toutputStructure: \"locale-modules\",\n\t\t\t\texperimentalStaticLocale: perLocaleBuildStaticLocaleExpression,\n\t\t\t\temitGitIgnore: false,\n\t\t\t\temitPrettierIgnore: false,\n\t\t\t\temitReadme: false,\n\t\t\t},\n\t\t});\n\t\tconst generatedRoot = nodePath.join(root, \"src/paraglide\");\n\t\tfor (const [fileName, source] of Object.entries(generated)) {\n\t\t\tconst path = nodePath.join(generatedRoot, fileName);\n\t\t\tawait nodeFs.mkdir(nodePath.dirname(path), { recursive: true });\n\t\t\tawait nodeFs.writeFile(path, source);\n\t\t}\n\t\tawait Promise.all([\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"index.html\"),\n\t\t\t\t'<script type=\"module\" src=\"./src/main.js\"></script>\\n'\n\t\t\t),\n\t\t\tnodeFs.writeFile(\n\t\t\t\tnodePath.join(root, \"src/main.js\"),\n\t\t\t\t'import { greeting } from \"./paraglide/messages.js\";\\ndocument.body.textContent = greeting();\\n'\n\t\t\t),\n\t\t]);\n\n\t\tconst builder = await createBuilder({\n\t\t\tconfigFile: false,\n\t\t\troot,\n\t\t\tbase: \"./\",\n\t\t\tlogLevel: \"silent\",\n\t\t\tbuild: { minify: false, sourcemap: true },\n\t\t\tplugins: [\n\t\t\t\tcreateViteLocaleEnvironmentPlugin({\n\t\t\t\t\tsettings: async () => ({\n\t\t\t\t\t\tbaseLocale: \"en\",\n\t\t\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t\t\t}),\n\t\t\t\t}),\n\t\t\t],\n\t\t});\n\t\tawait builder.buildApp();\n\n\t\tconst outputRoot = nodePath.join(root, \"dist\");\n\t\tconst manifest = JSON.parse(\n\t\t\tawait nodeFs.readFile(\n\t\t\t\tnodePath.join(outputRoot, VITE_LOCALE_BUILD_MANIFEST),\n\t\t\t\t\"utf8\"\n\t\t\t)\n\t\t) as ViteLocaleBuildManifest;\n\t\tconst enGraph = await readGraphText(outputRoot, manifest.locales.en!);\n\t\tconst deGraph = await readGraphText(outputRoot, manifest.locales.de!);\n\t\texpect(enGraph).toContain(\"EN_COMPILED_TRANSLATION\");\n\t\texpect(enGraph).not.toContain(\"DE_COMPILED_TRANSLATION\");\n\t\texpect(deGraph).toContain(\"DE_COMPILED_TRANSLATION\");\n\t\texpect(deGraph).not.toContain(\"EN_COMPILED_TRANSLATION\");\n\t} finally {\n\t\tawait project.close();\n\t\tawait nodeFs.rm(temporaryRoot, { recursive: true, force: true });\n\t}\n});\n\nfunction createMessage(locale: \"en\" | \"de\", value: string) {\n\treturn {\n\t\tid: `greeting-${locale}`,\n\t\tbundle_id: \"greeting\",\n\t\tlocale,\n\t\tselectors: [],\n\t\tvariants: [\n\t\t\t{\n\t\t\t\tid: `greeting-${locale}-variant`,\n\t\t\t\tmessage_id: `greeting-${locale}`,\n\t\t\t\tmatches: [],\n\t\t\t\tpattern: [{ type: \"text\" as const, value }],\n\t\t\t},\n\t\t],\n\t};\n}\n\nasync function readJavaScriptGraph(\n\toutputRoot: string,\n\tlocale: ViteLocaleBuildManifest[\"locales\"][string]\n): Promise<string> {\n\tconst chunks = locale.files.filter(\n\t\t(file) => file.type === \"chunk\" && file.fileName.endsWith(\".js\")\n\t);\n\treturn (\n\t\tawait Promise.all(\n\t\t\tchunks.map((chunk) =>\n\t\t\t\tnodeFs.readFile(\n\t\t\t\t\tnodePath.join(outputRoot, locale.directory, chunk.fileName),\n\t\t\t\t\t\"utf8\"\n\t\t\t\t)\n\t\t\t)\n\t\t)\n\t).join(\"\\n\");\n}\n\nasync function readSourceMaps(\n\toutputRoot: string,\n\tlocale: ViteLocaleBuildManifest[\"locales\"][string]\n): Promise<string> {\n\treturn (\n\t\tawait Promise.all(\n\t\t\tlocale.files\n\t\t\t\t.filter((file) => file.fileName.endsWith(\".map\"))\n\t\t\t\t.map((file) =>\n\t\t\t\t\tnodeFs.readFile(\n\t\t\t\t\t\tnodePath.join(outputRoot, locale.directory, file.fileName),\n\t\t\t\t\t\t\"utf8\"\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t)\n\t).join(\"\\n\");\n}\n\nasync function readGraphText(\n\toutputRoot: string,\n\tlocale: ViteLocaleBuildManifest[\"locales\"][string]\n): Promise<string> {\n\treturn (\n\t\tawait Promise.all(\n\t\t\tlocale.files\n\t\t\t\t.filter(\n\t\t\t\t\t(file) =>\n\t\t\t\t\t\t(file.type === \"chunk\" && file.fileName.endsWith(\".js\")) ||\n\t\t\t\t\t\tfile.fileName.endsWith(\".map\")\n\t\t\t\t)\n\t\t\t\t.map((file) =>\n\t\t\t\t\tnodeFs.readFile(\n\t\t\t\t\t\tnodePath.join(outputRoot, locale.directory, file.fileName),\n\t\t\t\t\t\t\"utf8\"\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t)\n\t).join(\"\\n\");\n}\n"]}
@@ -14,6 +14,9 @@ import { detectBundler } from "../../steps/detect-bundler.js";
14
14
  import { addVitePlugin } from "../../steps/add-vite-plugin.js";
15
15
  import { compile } from "../../../compiler/compile.js";
16
16
  import { maybeAddMachineTranslation } from "../../steps/maybe-add-machine-translation.js";
17
+ import { addInlangCheck } from "../../steps/add-inlang-check.js";
18
+ import { agentsMdSuggestion } from "../../steps/agents-md-suggestion.js";
19
+ import { getNewProjectTemplate } from "../../defaults.js";
17
20
  export const initCommand = new Command()
18
21
  .name("init")
19
22
  .summary("Initializes Paraglide-JS.")
@@ -40,6 +43,7 @@ export const initCommand = new Command()
40
43
  }
41
44
  const ctx7 = await maybeUpdateTsConfig(ctx6);
42
45
  const ctx8 = await maybeAddSherlock(ctx7);
46
+ await addInlangCheck(ctx8);
43
47
  const ctx9 = await maybeAddMachineTranslation(ctx8);
44
48
  try {
45
49
  await compile({
@@ -59,7 +63,21 @@ export const initCommand = new Command()
59
63
  "https://github.com/opral/paraglide-js/issues",
60
64
  ].join("\n");
61
65
  ctx.logger.box(successMessage);
62
- process.exit(0);
66
+ const settings = await ctx9.project.settings.get();
67
+ const pathPattern = settings["plugin.inlang.messageFormat"]?.pathPattern;
68
+ // Written directly: the logger renders `code` spans and drops the
69
+ // backticks, which the AGENTS.md snippet needs when copied.
70
+ process.stdout.write(agentsMdSuggestion({
71
+ root: ctx9.root,
72
+ projectPath: ctx9.projectPath,
73
+ pathPattern: typeof pathPattern === "string"
74
+ ? pathPattern
75
+ : getNewProjectTemplate()["plugin.inlang.messageFormat"]
76
+ .pathPattern,
77
+ outdir: ctx9.outdir,
78
+ }) + "\n\n",
79
+ // exit once the write is flushed, stdout to a pipe is async
80
+ () => process.exit(0));
63
81
  });
64
82
  const addParaglideJsToDevDependencies = async (ctx) => {
65
83
  const ctx1 = await updatePackageJson({
@@ -1 +1 @@
1
- {"version":3,"file":"command.js","sourceRoot":"","sources":["../../../../src/cli/commands/init/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,KAAK,QAAQ,MAAM,WAAW,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,0CAA0C,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,MAAM,6CAA6C,CAAC;AACzF,OAAO,EAAE,uBAAuB,EAA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AAO,CAAC,KAAK,GAAG,kCAAkC,WAAW,aAAa,MAAM,OAAO,OAAO,CAAC,KAAK,EAAE,CAAC;YACxG,CAAC;iBAAM,CAAC;gBACP,OAAO,OAAO,CAAC;YAChB,CAAC;YAED,GAAG,CAAC,MAAM,CAAC,OAAO,CACjB,8DAA8D,CAC9D,CAAC;YACF,GAAG,CAAC,MAAM,CAAC,IAAI,CACd,wEAAwE,CACxE,CAAC;YACF,OAAO,OAAO,CAAC;QAChB,CAAC;KACD,CAAC,CAAC,GAAG,CAAC,CAAC;IAER,OAAO,GAAG,CAAC;AACZ,CAAC,CAAC","sourcesContent":["import { Command } from \"commander\";\nimport * as nodePath from \"node:path\";\nimport { Logger } from \"../../../services/logger/index.js\";\nimport { findPackageJson } from \"../../../services/environment/package.js\";\nimport { checkForUncommittedChanges } from \"../../steps/check-for-uncomitted-changes.js\";\nimport { initializeInlangProject } from \"../../steps/initialize-inlang-project.js\";\nimport { maybeAddSherlock } from \"../../steps/maybe-add-sherlock.js\";\nimport { maybeUpdateTsConfig } from \"../../steps/update-ts-config.js\";\nimport { promptForOutdir } from \"../../steps/prompt-for-outdir.js\";\nimport { updatePackageJson } from \"../../steps/update-package-json.js\";\nimport type { CliStep } from \"../../utils.js\";\nimport nodeFs from \"node:fs\";\nimport { ENV_VARIABLES } from \"../../../services/env-variables/index.js\";\nimport { detectBundler } from \"../../steps/detect-bundler.js\";\nimport { addVitePlugin } from \"../../steps/add-vite-plugin.js\";\nimport { compile } from \"../../../compiler/compile.js\";\nimport { maybeAddMachineTranslation } from \"../../steps/maybe-add-machine-translation.js\";\n\nexport const initCommand = new Command()\n\t.name(\"init\")\n\t.summary(\"Initializes Paraglide-JS.\")\n\t.action(async () => {\n\t\tconst logger = new Logger({ silent: false, prefix: false });\n\n\t\tlogger.box(\"Welcome to Paraglide JS 🪂\");\n\n\t\tconst ctx = {\n\t\t\tlogger,\n\t\t\tfs: nodeFs.promises,\n\t\t\tsyncFs: nodeFs,\n\t\t\troot: process.cwd(),\n\t\t} as const;\n\n\t\tconst ctx1 = await checkForUncommittedChanges(ctx);\n\t\tconst ctx2 = await enforcePackageJsonExists(ctx1);\n\t\tconst ctx3 = await initializeInlangProject(ctx2);\n\t\tconst ctx4 = await promptForOutdir(ctx3);\n\t\tconst ctx5 = await addParaglideJsToDevDependencies(ctx4);\n\t\tconst ctx6 = await detectBundler(ctx5);\n\n\t\tif (ctx6.bundler === \"vite\") {\n\t\t\tawait addVitePlugin(ctx6);\n\t\t} else {\n\t\t\tawait addCompileStepToPackageJSON(ctx6);\n\t\t}\n\n\t\tconst ctx7 = await maybeUpdateTsConfig(ctx6);\n\t\tconst ctx8 = await maybeAddSherlock(ctx7);\n\t\tconst ctx9 = await maybeAddMachineTranslation(ctx8);\n\n\t\ttry {\n\t\t\tawait compile({\n\t\t\t\tproject: ctx9.projectPath,\n\t\t\t\toutdir: ctx9.outdir,\n\t\t\t});\n\t\t\tctx.logger.success(\"Ran the paraglide compiler\");\n\t\t} catch {\n\t\t\tctx.logger.warn(\n\t\t\t\t\"Failed to compile project automatically. You will need to run the compiler manually\"\n\t\t\t);\n\t\t}\n\n\t\tconst successMessage = [\n\t\t\t\"Setup complete! Run `npm install` and then `npm run build`.\",\n\t\t\t`Docs: https://paraglidejs.com/basics`,\n\t\t\t\"\\n\",\n\t\t\t\"For questions and feedback, visit\",\n\t\t\t\"https://github.com/opral/paraglide-js/issues\",\n\t\t].join(\"\\n\");\n\t\tctx.logger.box(successMessage);\n\t\tprocess.exit(0);\n\t});\n\nconst addParaglideJsToDevDependencies: CliStep<\n\t{\n\t\tfs: typeof import(\"node:fs/promises\");\n\t\tlogger: Logger;\n\t\tpackageJsonPath: string;\n\t},\n\tunknown\n> = async (ctx) => {\n\tconst ctx1 = await updatePackageJson({\n\t\tdevDependencies: async (devDeps) => ({\n\t\t\t...devDeps,\n\t\t\t\"@inlang/paraglide-js\": `^${ENV_VARIABLES.PARJS_PACKAGE_VERSION}`,\n\t\t}),\n\t})(ctx);\n\tctx.logger.success(\n\t\t\"Added @inlang/paraglide-js to the devDependencies in package.json.\"\n\t);\n\treturn ctx1;\n};\n\nconst enforcePackageJsonExists: CliStep<\n\t{ logger: Logger; fs: typeof import(\"node:fs/promises\") },\n\t{ packageJsonPath: string }\n> = async (ctx) => {\n\tconst packageJsonPath = await findPackageJson(ctx.fs, process.cwd());\n\tif (!packageJsonPath) {\n\t\tctx.logger.warn(\n\t\t\t\"No package.json found in the current working directory. Please change the working directory to the directory with a package.json file.\"\n\t\t);\n\t\treturn process.exit(0);\n\t}\n\treturn { ...ctx, packageJsonPath };\n};\n\nconst addCompileStepToPackageJSON: CliStep<\n\t{\n\t\tfs: typeof import(\"node:fs/promises\");\n\t\tlogger: Logger;\n\t\tprojectPath: string;\n\t\toutdir: string;\n\t\tpackageJsonPath: string;\n\t},\n\tunknown\n> = async (ctx) => {\n\tconst projectPath = \"./\" + nodePath.relative(process.cwd(), ctx.projectPath);\n\tconst outdir = \"./\" + nodePath.relative(process.cwd(), ctx.outdir);\n\n\tctx = await updatePackageJson({\n\t\tscripts: async (scripts) => {\n\t\t\tif (scripts.build === undefined) {\n\t\t\t\tscripts.build = `paraglide-js compile --project ${projectPath} --outdir ${outdir}`;\n\t\t\t} else if (scripts.build.includes(\"paraglide-js compile\") === false) {\n\t\t\t\tscripts.build = `paraglide-js compile --project ${projectPath} --outdir ${outdir} && ${scripts.build}`;\n\t\t\t} else {\n\t\t\t\treturn scripts;\n\t\t\t}\n\n\t\t\tctx.logger.success(\n\t\t\t\t\"Added the compile command to the build step in package.json.\"\n\t\t\t);\n\t\t\tctx.logger.info(\n\t\t\t\t`Visit https://paraglidejs.com/compiling-messages for more information.`\n\t\t\t);\n\t\t\treturn scripts;\n\t\t},\n\t})(ctx);\n\n\treturn ctx;\n};\n"]}
1
+ {"version":3,"file":"command.js","sourceRoot":"","sources":["../../../../src/cli/commands/init/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CA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AwE,CACxE,CAAC;YACF,OAAO,OAAO,CAAC;QAChB,CAAC;KACD,CAAC,CAAC,GAAG,CAAC,CAAC;IAER,OAAO,GAAG,CAAC;AACZ,CAAC,CAAC","sourcesContent":["import { Command } from \"commander\";\nimport * as nodePath from \"node:path\";\nimport { Logger } from \"../../../services/logger/index.js\";\nimport { findPackageJson } from \"../../../services/environment/package.js\";\nimport { checkForUncommittedChanges } from \"../../steps/check-for-uncomitted-changes.js\";\nimport { initializeInlangProject } from \"../../steps/initialize-inlang-project.js\";\nimport { maybeAddSherlock } from \"../../steps/maybe-add-sherlock.js\";\nimport { maybeUpdateTsConfig } from \"../../steps/update-ts-config.js\";\nimport { promptForOutdir } from \"../../steps/prompt-for-outdir.js\";\nimport { updatePackageJson } from \"../../steps/update-package-json.js\";\nimport type { CliStep } from \"../../utils.js\";\nimport nodeFs from \"node:fs\";\nimport { ENV_VARIABLES } from \"../../../services/env-variables/index.js\";\nimport { detectBundler } from \"../../steps/detect-bundler.js\";\nimport { addVitePlugin } from \"../../steps/add-vite-plugin.js\";\nimport { compile } from \"../../../compiler/compile.js\";\nimport { maybeAddMachineTranslation } from \"../../steps/maybe-add-machine-translation.js\";\nimport { addInlangCheck } from \"../../steps/add-inlang-check.js\";\nimport { agentsMdSuggestion } from \"../../steps/agents-md-suggestion.js\";\nimport { getNewProjectTemplate } from \"../../defaults.js\";\n\nexport const initCommand = new Command()\n\t.name(\"init\")\n\t.summary(\"Initializes Paraglide-JS.\")\n\t.action(async () => {\n\t\tconst logger = new Logger({ silent: false, prefix: false });\n\n\t\tlogger.box(\"Welcome to Paraglide JS 🪂\");\n\n\t\tconst ctx = {\n\t\t\tlogger,\n\t\t\tfs: nodeFs.promises,\n\t\t\tsyncFs: nodeFs,\n\t\t\troot: process.cwd(),\n\t\t} as const;\n\n\t\tconst ctx1 = await checkForUncommittedChanges(ctx);\n\t\tconst ctx2 = await enforcePackageJsonExists(ctx1);\n\t\tconst ctx3 = await initializeInlangProject(ctx2);\n\t\tconst ctx4 = await promptForOutdir(ctx3);\n\t\tconst ctx5 = await addParaglideJsToDevDependencies(ctx4);\n\t\tconst ctx6 = await detectBundler(ctx5);\n\n\t\tif (ctx6.bundler === \"vite\") {\n\t\t\tawait addVitePlugin(ctx6);\n\t\t} else {\n\t\t\tawait addCompileStepToPackageJSON(ctx6);\n\t\t}\n\n\t\tconst ctx7 = await maybeUpdateTsConfig(ctx6);\n\t\tconst ctx8 = await maybeAddSherlock(ctx7);\n\t\tawait addInlangCheck(ctx8);\n\t\tconst ctx9 = await maybeAddMachineTranslation(ctx8);\n\n\t\ttry {\n\t\t\tawait compile({\n\t\t\t\tproject: ctx9.projectPath,\n\t\t\t\toutdir: ctx9.outdir,\n\t\t\t});\n\t\t\tctx.logger.success(\"Ran the paraglide compiler\");\n\t\t} catch {\n\t\t\tctx.logger.warn(\n\t\t\t\t\"Failed to compile project automatically. You will need to run the compiler manually\"\n\t\t\t);\n\t\t}\n\n\t\tconst successMessage = [\n\t\t\t\"Setup complete! Run `npm install` and then `npm run build`.\",\n\t\t\t`Docs: https://paraglidejs.com/basics`,\n\t\t\t\"\\n\",\n\t\t\t\"For questions and feedback, visit\",\n\t\t\t\"https://github.com/opral/paraglide-js/issues\",\n\t\t].join(\"\\n\");\n\t\tctx.logger.box(successMessage);\n\n\t\tconst settings = await ctx9.project.settings.get();\n\t\tconst pathPattern = settings[\"plugin.inlang.messageFormat\"]?.pathPattern;\n\t\t// Written directly: the logger renders `code` spans and drops the\n\t\t// backticks, which the AGENTS.md snippet needs when copied.\n\t\tprocess.stdout.write(\n\t\t\tagentsMdSuggestion({\n\t\t\t\troot: ctx9.root,\n\t\t\t\tprojectPath: ctx9.projectPath,\n\t\t\t\tpathPattern:\n\t\t\t\t\ttypeof pathPattern === \"string\"\n\t\t\t\t\t\t? pathPattern\n\t\t\t\t\t\t: getNewProjectTemplate()[\"plugin.inlang.messageFormat\"]\n\t\t\t\t\t\t\t\t.pathPattern,\n\t\t\t\toutdir: ctx9.outdir,\n\t\t\t}) + \"\\n\\n\",\n\t\t\t// exit once the write is flushed, stdout to a pipe is async\n\t\t\t() => process.exit(0)\n\t\t);\n\t});\n\nconst addParaglideJsToDevDependencies: CliStep<\n\t{\n\t\tfs: typeof import(\"node:fs/promises\");\n\t\tlogger: Logger;\n\t\tpackageJsonPath: string;\n\t},\n\tunknown\n> = async (ctx) => {\n\tconst ctx1 = await updatePackageJson({\n\t\tdevDependencies: async (devDeps) => ({\n\t\t\t...devDeps,\n\t\t\t\"@inlang/paraglide-js\": `^${ENV_VARIABLES.PARJS_PACKAGE_VERSION}`,\n\t\t}),\n\t})(ctx);\n\tctx.logger.success(\n\t\t\"Added @inlang/paraglide-js to the devDependencies in package.json.\"\n\t);\n\treturn ctx1;\n};\n\nconst enforcePackageJsonExists: CliStep<\n\t{ logger: Logger; fs: typeof import(\"node:fs/promises\") },\n\t{ packageJsonPath: string }\n> = async (ctx) => {\n\tconst packageJsonPath = await findPackageJson(ctx.fs, process.cwd());\n\tif (!packageJsonPath) {\n\t\tctx.logger.warn(\n\t\t\t\"No package.json found in the current working directory. Please change the working directory to the directory with a package.json file.\"\n\t\t);\n\t\treturn process.exit(0);\n\t}\n\treturn { ...ctx, packageJsonPath };\n};\n\nconst addCompileStepToPackageJSON: CliStep<\n\t{\n\t\tfs: typeof import(\"node:fs/promises\");\n\t\tlogger: Logger;\n\t\tprojectPath: string;\n\t\toutdir: string;\n\t\tpackageJsonPath: string;\n\t},\n\tunknown\n> = async (ctx) => {\n\tconst projectPath = \"./\" + nodePath.relative(process.cwd(), ctx.projectPath);\n\tconst outdir = \"./\" + nodePath.relative(process.cwd(), ctx.outdir);\n\n\tctx = await updatePackageJson({\n\t\tscripts: async (scripts) => {\n\t\t\tif (scripts.build === undefined) {\n\t\t\t\tscripts.build = `paraglide-js compile --project ${projectPath} --outdir ${outdir}`;\n\t\t\t} else if (scripts.build.includes(\"paraglide-js compile\") === false) {\n\t\t\t\tscripts.build = `paraglide-js compile --project ${projectPath} --outdir ${outdir} && ${scripts.build}`;\n\t\t\t} else {\n\t\t\t\treturn scripts;\n\t\t\t}\n\n\t\t\tctx.logger.success(\n\t\t\t\t\"Added the compile command to the build step in package.json.\"\n\t\t\t);\n\t\t\tctx.logger.info(\n\t\t\t\t`Visit https://paraglidejs.com/compiling-messages for more information.`\n\t\t\t);\n\t\t\treturn scripts;\n\t\t},\n\t})(ctx);\n\n\treturn ctx;\n};\n"]}
@@ -7,8 +7,8 @@ const defaultProjectSettings = {
7
7
  baseLocale: "en",
8
8
  locales: ["en", "de"],
9
9
  modules: [
10
- "https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@4.4.0/dist/index.js",
11
- "https://cdn.jsdelivr.net/npm/@inlang/plugin-m-function-matcher@2.2.6/dist/index.js",
10
+ "https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@4.5.0/dist/index.js",
11
+ "https://cdn.jsdelivr.net/npm/@inlang/plugin-m-function-matcher@2.3.0/dist/index.js",
12
12
  ],
13
13
  "plugin.inlang.messageFormat": {
14
14
  pathPattern: "./messages/{locale}.json",
@@ -1 +1 @@
1
- {"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/cli/defaults.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,sBAAsB,GAAG;IAC9B,OAAO,EAAE,4CAA4C;IACrD,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;IACrB,OAAO,EAAE;QACR,gFAAgF;QAChF,oFAAoF;KACpF;IACD,6BAA6B,EAAE;QAC9B,WAAW,EAAE,0BAA0B;KACvC;CACyB,CAAC;AAE5B;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACpC,OAAO,eAAe,CAAC,sBAAsB,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import type { ProjectSettings } from \"@inlang/sdk\";\n\n/**\n * Default project settings for createNewProject\n * from paraglide-js/src/cli/commands/init/defaults.ts\n */\nconst defaultProjectSettings = {\n\t$schema: \"https://inlang.com/schema/project-settings\",\n\tbaseLocale: \"en\",\n\tlocales: [\"en\", \"de\"],\n\tmodules: [\n\t\t\"https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@4.4.0/dist/index.js\",\n\t\t\"https://cdn.jsdelivr.net/npm/@inlang/plugin-m-function-matcher@2.2.6/dist/index.js\",\n\t],\n\t\"plugin.inlang.messageFormat\": {\n\t\tpathPattern: \"./messages/{locale}.json\",\n\t},\n} satisfies ProjectSettings;\n\n/**\n * @returns A new copy of the default project template that is safe to mutate.\n */\nexport function getNewProjectTemplate() {\n\treturn structuredClone(defaultProjectSettings);\n}\n"]}
1
+ {"version":3,"file":"defaults.js","sourceRoot":"","sources":["../../src/cli/defaults.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,sBAAsB,GAAG;IAC9B,OAAO,EAAE,4CAA4C;IACrD,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC;IACrB,OAAO,EAAE;QACR,gFAAgF;QAChF,oFAAoF;KACpF;IACD,6BAA6B,EAAE;QAC9B,WAAW,EAAE,0BAA0B;KACvC;CACyB,CAAC;AAE5B;;GAEG;AACH,MAAM,UAAU,qBAAqB;IACpC,OAAO,eAAe,CAAC,sBAAsB,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import type { ProjectSettings } from \"@inlang/sdk\";\n\n/**\n * Default project settings for createNewProject\n * from paraglide-js/src/cli/commands/init/defaults.ts\n */\nconst defaultProjectSettings = {\n\t$schema: \"https://inlang.com/schema/project-settings\",\n\tbaseLocale: \"en\",\n\tlocales: [\"en\", \"de\"],\n\tmodules: [\n\t\t\"https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@4.5.0/dist/index.js\",\n\t\t\"https://cdn.jsdelivr.net/npm/@inlang/plugin-m-function-matcher@2.3.0/dist/index.js\",\n\t],\n\t\"plugin.inlang.messageFormat\": {\n\t\tpathPattern: \"./messages/{locale}.json\",\n\t},\n} satisfies ProjectSettings;\n\n/**\n * @returns A new copy of the default project template that is safe to mutate.\n */\nexport function getNewProjectTemplate() {\n\treturn structuredClone(defaultProjectSettings);\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import type { Logger } from "../../services/logger/index.js";
2
+ import { type CliStep } from "../utils.js";
3
+ /**
4
+ * The `@inlang/cli` range `init` adds. 3.4.0 introduced `inlang check`.
5
+ */
6
+ export declare const INLANG_CLI_VERSION_RANGE = "^3.4.0";
7
+ export declare const CHECK_SCRIPT_NAME = "check:i18n";
8
+ /**
9
+ * Adds `@inlang/cli` to the devDependencies (if not present) and a
10
+ * `check:i18n` script that runs `inlang check` (if no script of that name
11
+ * exists).
12
+ */
13
+ export declare const addInlangCheck: CliStep<{
14
+ fs: typeof import("node:fs/promises");
15
+ logger: Logger;
16
+ projectPath: string;
17
+ root: string;
18
+ packageJsonPath: string;
19
+ }, unknown>;
@@ -0,0 +1,60 @@
1
+ import { toRelativeDisplayPath } from "../utils.js";
2
+ import { updatePackageJson } from "./update-package-json.js";
3
+ /**
4
+ * The `@inlang/cli` range `init` adds. 3.4.0 introduced `inlang check`.
5
+ */
6
+ export const INLANG_CLI_VERSION_RANGE = "^3.4.0";
7
+ export const CHECK_SCRIPT_NAME = "check:i18n";
8
+ /**
9
+ * Adds `@inlang/cli` to the devDependencies (if not present) and a
10
+ * `check:i18n` script that runs `inlang check` (if no script of that name
11
+ * exists).
12
+ */
13
+ export const addInlangCheck = async (ctx) => {
14
+ const projectPath = toRelativeDisplayPath(ctx.root, ctx.projectPath);
15
+ let existingCli;
16
+ let addedCli = false;
17
+ let addedScript = false;
18
+ await updatePackageJson({
19
+ devDependencies: async (devDeps) => {
20
+ existingCli = devDeps["@inlang/cli"];
21
+ if (existingCli !== undefined)
22
+ return devDeps;
23
+ addedCli = true;
24
+ return { ...devDeps, "@inlang/cli": INLANG_CLI_VERSION_RANGE };
25
+ },
26
+ scripts: async (scripts) => {
27
+ if (scripts[CHECK_SCRIPT_NAME] !== undefined)
28
+ return scripts;
29
+ addedScript = true;
30
+ return {
31
+ ...scripts,
32
+ [CHECK_SCRIPT_NAME]: `inlang check --project ./${projectPath}`,
33
+ };
34
+ },
35
+ })(ctx);
36
+ if (addedCli) {
37
+ ctx.logger.success(`Added @inlang/cli ${INLANG_CLI_VERSION_RANGE} to the devDependencies in package.json.`);
38
+ }
39
+ if (addedScript) {
40
+ ctx.logger.success(`Added a ${CHECK_SCRIPT_NAME} script that checks the translations to package.json.`);
41
+ }
42
+ if (existingCli !== undefined && mayBeOlderThan3_4(existingCli)) {
43
+ ctx.logger.warn(`\`inlang check\` needs @inlang/cli 3.4.0 or later. Your package.json has "${existingCli}". Update it to "${INLANG_CLI_VERSION_RANGE}".`);
44
+ }
45
+ return ctx;
46
+ };
47
+ /**
48
+ * Whether a version range may resolve to an `@inlang/cli` before 3.4.0,
49
+ * judged by the first version it names (`^3.0.0`, `3.2.0`, `~2.1.0`).
50
+ * Ranges without a version (`latest`, `*`, `workspace:*`) are trusted.
51
+ */
52
+ function mayBeOlderThan3_4(range) {
53
+ const match = range.match(/(\d+)\.(\d+)/);
54
+ if (!match)
55
+ return false;
56
+ const major = Number(match[1]);
57
+ const minor = Number(match[2]);
58
+ return major < 3 || (major === 3 && minor < 4);
59
+ }
60
+ //# sourceMappingURL=add-inlang-check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-inlang-check.js","sourceRoot":"","sources":["../../../src/cli/steps/add-inlang-check.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAgB,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAE7D;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,QAAQ,CAAC;AAEjD,MAAM,CAAC,MAAM,iBAAiB,GAAG,YAAY,CAAC;AAE9C;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GASvB,KAAK,EAAE,GAAG,EAAE,EAAE;IACjB,MAA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AIG;AACH,SAAS,iBAAiB,CAAC,KAAa;IACvC,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;IAC1C,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAC;IACzB,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/B,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IAC/B,OAAO,KAAK,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC;AAChD,CAAC","sourcesContent":["import type { Logger } from \"../../services/logger/index.js\";\nimport { toRelativeDisplayPath, type CliStep } from \"../utils.js\";\nimport { updatePackageJson } from \"./update-package-json.js\";\n\n/**\n * The `@inlang/cli` range `init` adds. 3.4.0 introduced `inlang check`.\n */\nexport const INLANG_CLI_VERSION_RANGE = \"^3.4.0\";\n\nexport const CHECK_SCRIPT_NAME = \"check:i18n\";\n\n/**\n * Adds `@inlang/cli` to the devDependencies (if not present) and a\n * `check:i18n` script that runs `inlang check` (if no script of that name\n * exists).\n */\nexport const addInlangCheck: CliStep<\n\t{\n\t\tfs: typeof import(\"node:fs/promises\");\n\t\tlogger: Logger;\n\t\tprojectPath: string;\n\t\troot: string;\n\t\tpackageJsonPath: string;\n\t},\n\tunknown\n> = async (ctx) => {\n\tconst projectPath = toRelativeDisplayPath(ctx.root, ctx.projectPath);\n\tlet existingCli: string | undefined;\n\tlet addedCli = false;\n\tlet addedScript = false;\n\n\tawait updatePackageJson({\n\t\tdevDependencies: async (devDeps) => {\n\t\t\texistingCli = devDeps[\"@inlang/cli\"];\n\t\t\tif (existingCli !== undefined) return devDeps;\n\t\t\taddedCli = true;\n\t\t\treturn { ...devDeps, \"@inlang/cli\": INLANG_CLI_VERSION_RANGE };\n\t\t},\n\t\tscripts: async (scripts) => {\n\t\t\tif (scripts[CHECK_SCRIPT_NAME] !== undefined) return scripts;\n\t\t\taddedScript = true;\n\t\t\treturn {\n\t\t\t\t...scripts,\n\t\t\t\t[CHECK_SCRIPT_NAME]: `inlang check --project ./${projectPath}`,\n\t\t\t};\n\t\t},\n\t})(ctx);\n\n\tif (addedCli) {\n\t\tctx.logger.success(\n\t\t\t`Added @inlang/cli ${INLANG_CLI_VERSION_RANGE} to the devDependencies in package.json.`\n\t\t);\n\t}\n\tif (addedScript) {\n\t\tctx.logger.success(\n\t\t\t`Added a ${CHECK_SCRIPT_NAME} script that checks the translations to package.json.`\n\t\t);\n\t}\n\tif (existingCli !== undefined && mayBeOlderThan3_4(existingCli)) {\n\t\tctx.logger.warn(\n\t\t\t`\\`inlang check\\` needs @inlang/cli 3.4.0 or later. Your package.json has \"${existingCli}\". Update it to \"${INLANG_CLI_VERSION_RANGE}\".`\n\t\t);\n\t}\n\n\treturn ctx;\n};\n\n/**\n * Whether a version range may resolve to an `@inlang/cli` before 3.4.0,\n * judged by the first version it names (`^3.0.0`, `3.2.0`, `~2.1.0`).\n * Ranges without a version (`latest`, `*`, `workspace:*`) are trusted.\n */\nfunction mayBeOlderThan3_4(range: string): boolean {\n\tconst match = range.match(/(\\d+)\\.(\\d+)/);\n\tif (!match) return false;\n\tconst major = Number(match[1]);\n\tconst minor = Number(match[2]);\n\treturn major < 3 || (major === 3 && minor < 4);\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,88 @@
1
+ import { afterEach, beforeEach, expect, test, vi } from "vitest";
2
+ import { memfs } from "memfs";
3
+ import { addInlangCheck } from "./add-inlang-check.js";
4
+ import { Logger } from "../../services/logger/index.js";
5
+ const originalCwd = process.cwd;
6
+ beforeEach(() => {
7
+ process.cwd = (() => "/");
8
+ });
9
+ afterEach(() => {
10
+ process.cwd = originalCwd;
11
+ });
12
+ async function runAddInlangCheck(packageJson) {
13
+ const fs = memfs({ "/package.json": JSON.stringify(packageJson, null, 2) })
14
+ .fs;
15
+ const logger = new Logger({ silent: true, prefix: false });
16
+ const success = vi.spyOn(logger, "success");
17
+ const warn = vi.spyOn(logger, "warn");
18
+ await addInlangCheck({
19
+ fs: fs.promises,
20
+ logger,
21
+ projectPath: "./project.inlang",
22
+ root: "/",
23
+ packageJsonPath: "/package.json",
24
+ });
25
+ return {
26
+ pkg: JSON.parse(await fs.promises.readFile("/package.json", "utf-8")),
27
+ logged: success.mock.calls.map(([message]) => message),
28
+ warned: warn.mock.calls.map(([message]) => String(message)),
29
+ };
30
+ }
31
+ test("adds @inlang/cli and a check:i18n script", async () => {
32
+ const { pkg, logged, warned } = await runAddInlangCheck({
33
+ scripts: { build: "vite build" },
34
+ devDependencies: { vite: "^6.0.0" },
35
+ });
36
+ expect(pkg.devDependencies).toEqual({
37
+ vite: "^6.0.0",
38
+ "@inlang/cli": "^3.4.0",
39
+ });
40
+ expect(pkg.scripts).toEqual({
41
+ build: "vite build",
42
+ "check:i18n": "inlang check --project ./project.inlang",
43
+ });
44
+ expect(logged).toHaveLength(2);
45
+ expect(warned).toEqual([]);
46
+ });
47
+ test("adds devDependencies and scripts to a package.json without them", async () => {
48
+ const { pkg } = await runAddInlangCheck({ name: "app" });
49
+ expect(pkg.devDependencies).toEqual({ "@inlang/cli": "^3.4.0" });
50
+ expect(pkg.scripts).toEqual({
51
+ "check:i18n": "inlang check --project ./project.inlang",
52
+ });
53
+ });
54
+ test("keeps an existing @inlang/cli version and check:i18n script", async () => {
55
+ const { pkg, logged, warned } = await runAddInlangCheck({
56
+ scripts: { "check:i18n": "my-own-check" },
57
+ devDependencies: { "@inlang/cli": "3.5.0" },
58
+ });
59
+ expect(pkg.devDependencies).toEqual({ "@inlang/cli": "3.5.0" });
60
+ expect(pkg.scripts).toEqual({ "check:i18n": "my-own-check" });
61
+ expect(logged).toEqual([]);
62
+ expect(warned).toEqual([]);
63
+ });
64
+ test("adds only the script when @inlang/cli is present, and warns about a CLI before 3.4.0", async () => {
65
+ const { pkg, logged, warned } = await runAddInlangCheck({
66
+ devDependencies: { "@inlang/cli": "3.2.0" },
67
+ });
68
+ expect(pkg.devDependencies).toEqual({ "@inlang/cli": "3.2.0" });
69
+ expect(pkg.scripts).toEqual({
70
+ "check:i18n": "inlang check --project ./project.inlang",
71
+ });
72
+ expect(logged).toEqual([
73
+ "Added a check:i18n script that checks the translations to package.json.",
74
+ ]);
75
+ expect(warned).toHaveLength(1);
76
+ expect(warned[0]).toContain("needs @inlang/cli 3.4.0 or later");
77
+ });
78
+ test("adds only @inlang/cli when the check:i18n script exists", async () => {
79
+ const { pkg, logged } = await runAddInlangCheck({
80
+ scripts: { "check:i18n": "my-own-check" },
81
+ });
82
+ expect(pkg.devDependencies).toEqual({ "@inlang/cli": "^3.4.0" });
83
+ expect(pkg.scripts).toEqual({ "check:i18n": "my-own-check" });
84
+ expect(logged).toEqual([
85
+ "Added @inlang/cli ^3.4.0 to the devDependencies in package.json.",
86
+ ]);
87
+ });
88
+ //# sourceMappingURL=add-inlang-check.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-inlang-check.test.js","sourceRoot":"","sources":["../../../src/cli/steps/add-inlang-check.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAExD,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;AAChC,UAAU,CAAC,GAAG,EAAE;IACf,OAAO,CAAC,GAAG,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAuB,CAAC;AACjD,CAAC,CAAC,CAAC;AACH,SAAS,CAAC,GAAG,EAAE;IACd,OAAO,CAAC,GAAG,GAAG,WAAW,CAAC;AAC3B,CAAC,CAAC,CAAC;AAE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AE,YAAY,EAAE,cAAc,EAAE,CAAC,CAAC;IAC9D,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;QACtB,kEAAkE;KAClE,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { afterEach, beforeEach, expect, test, vi } from \"vitest\";\nimport { memfs } from \"memfs\";\nimport { addInlangCheck } from \"./add-inlang-check.js\";\nimport { Logger } from \"../../services/logger/index.js\";\n\nconst originalCwd = process.cwd;\nbeforeEach(() => {\n\tprocess.cwd = (() => \"/\") as typeof process.cwd;\n});\nafterEach(() => {\n\tprocess.cwd = originalCwd;\n});\n\nasync function runAddInlangCheck(packageJson: Record<string, unknown>) {\n\tconst fs = memfs({ \"/package.json\": JSON.stringify(packageJson, null, 2) })\n\t\t.fs as unknown as typeof import(\"node:fs\");\n\tconst logger = new Logger({ silent: true, prefix: false });\n\tconst success = vi.spyOn(logger, \"success\");\n\tconst warn = vi.spyOn(logger, \"warn\");\n\tawait addInlangCheck({\n\t\tfs: fs.promises,\n\t\tlogger,\n\t\tprojectPath: \"./project.inlang\",\n\t\troot: \"/\",\n\t\tpackageJsonPath: \"/package.json\",\n\t});\n\treturn {\n\t\tpkg: JSON.parse(await fs.promises.readFile(\"/package.json\", \"utf-8\")),\n\t\tlogged: success.mock.calls.map(([message]) => message),\n\t\twarned: warn.mock.calls.map(([message]) => String(message)),\n\t};\n}\n\ntest(\"adds @inlang/cli and a check:i18n script\", async () => {\n\tconst { pkg, logged, warned } = await runAddInlangCheck({\n\t\tscripts: { build: \"vite build\" },\n\t\tdevDependencies: { vite: \"^6.0.0\" },\n\t});\n\n\texpect(pkg.devDependencies).toEqual({\n\t\tvite: \"^6.0.0\",\n\t\t\"@inlang/cli\": \"^3.4.0\",\n\t});\n\texpect(pkg.scripts).toEqual({\n\t\tbuild: \"vite build\",\n\t\t\"check:i18n\": \"inlang check --project ./project.inlang\",\n\t});\n\texpect(logged).toHaveLength(2);\n\texpect(warned).toEqual([]);\n});\n\ntest(\"adds devDependencies and scripts to a package.json without them\", async () => {\n\tconst { pkg } = await runAddInlangCheck({ name: \"app\" });\n\n\texpect(pkg.devDependencies).toEqual({ \"@inlang/cli\": \"^3.4.0\" });\n\texpect(pkg.scripts).toEqual({\n\t\t\"check:i18n\": \"inlang check --project ./project.inlang\",\n\t});\n});\n\ntest(\"keeps an existing @inlang/cli version and check:i18n script\", async () => {\n\tconst { pkg, logged, warned } = await runAddInlangCheck({\n\t\tscripts: { \"check:i18n\": \"my-own-check\" },\n\t\tdevDependencies: { \"@inlang/cli\": \"3.5.0\" },\n\t});\n\n\texpect(pkg.devDependencies).toEqual({ \"@inlang/cli\": \"3.5.0\" });\n\texpect(pkg.scripts).toEqual({ \"check:i18n\": \"my-own-check\" });\n\texpect(logged).toEqual([]);\n\texpect(warned).toEqual([]);\n});\n\ntest(\"adds only the script when @inlang/cli is present, and warns about a CLI before 3.4.0\", async () => {\n\tconst { pkg, logged, warned } = await runAddInlangCheck({\n\t\tdevDependencies: { \"@inlang/cli\": \"3.2.0\" },\n\t});\n\n\texpect(pkg.devDependencies).toEqual({ \"@inlang/cli\": \"3.2.0\" });\n\texpect(pkg.scripts).toEqual({\n\t\t\"check:i18n\": \"inlang check --project ./project.inlang\",\n\t});\n\texpect(logged).toEqual([\n\t\t\"Added a check:i18n script that checks the translations to package.json.\",\n\t]);\n\texpect(warned).toHaveLength(1);\n\texpect(warned[0]).toContain(\"needs @inlang/cli 3.4.0 or later\");\n});\n\ntest(\"adds only @inlang/cli when the check:i18n script exists\", async () => {\n\tconst { pkg, logged } = await runAddInlangCheck({\n\t\tscripts: { \"check:i18n\": \"my-own-check\" },\n\t});\n\n\texpect(pkg.devDependencies).toEqual({ \"@inlang/cli\": \"^3.4.0\" });\n\texpect(pkg.scripts).toEqual({ \"check:i18n\": \"my-own-check\" });\n\texpect(logged).toEqual([\n\t\t\"Added @inlang/cli ^3.4.0 to the devDependencies in package.json.\",\n\t]);\n});\n"]}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * The localization section `init` suggests adding to AGENTS.md. `init` only
3
+ * prints it and never writes AGENTS.md.
4
+ */
5
+ export declare function agentsMdSuggestion(args: {
6
+ root: string;
7
+ projectPath: string;
8
+ /** The message files, e.g. `./messages/{locale}.json`. */
9
+ pathPattern: string;
10
+ outdir: string;
11
+ }): string;
@@ -0,0 +1,19 @@
1
+ import { toRelativeDisplayPath } from "../utils.js";
2
+ /**
3
+ * The localization section `init` suggests adding to AGENTS.md. `init` only
4
+ * prints it and never writes AGENTS.md.
5
+ */
6
+ export function agentsMdSuggestion(args) {
7
+ const projectPath = toRelativeDisplayPath(args.root, args.projectPath);
8
+ const pathPattern = toRelativeDisplayPath(args.root, args.pathPattern);
9
+ // an outdir of `./` is the root itself
10
+ const outdir = toRelativeDisplayPath(args.root, args.outdir) || ".";
11
+ return [
12
+ "If you use coding agents, consider adding this to your AGENTS.md:",
13
+ "",
14
+ "## Localization",
15
+ `- Translations are an inlang project. Before localization work, read \`${projectPath}/README.md\`. It covers checks, machine translation and editors. It is git-ignored, so search tools may skip it.`,
16
+ `- Edit messages in \`${pathPattern}\`. Never edit \`${outdir}/\`: Paraglide JS generates it.`,
17
+ ].join("\n");
18
+ }
19
+ //# sourceMappingURL=agents-md-suggestion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agents-md-suggestion.js","sourceRoot":"","sources":["../../../src/cli/steps/agents-md-suggestion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAEpD;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAMlC;IACA,MAAM,WAAW,GAAG,qBAAqB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IACvE,MAAM,WAAW,GAAG,qBAAqB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IACvE,uCAAuC;IACvC,MAAM,MAAM,GAAG,qBAAqB,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC;IACpE,OAAO;QACN,mEAAmE;QACnE,EAAE;QACF,iBAAiB;QACjB,0EAA0E,WAAW,kHAAkH;QACvM,wBAAwB,WAAW,oBAAoB,MAAM,iCAAiC;KAC9F,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACd,CAAC","sourcesContent":["import { toRelativeDisplayPath } from \"../utils.js\";\n\n/**\n * The localization section `init` suggests adding to AGENTS.md. `init` only\n * prints it and never writes AGENTS.md.\n */\nexport function agentsMdSuggestion(args: {\n\troot: string;\n\tprojectPath: string;\n\t/** The message files, e.g. `./messages/{locale}.json`. */\n\tpathPattern: string;\n\toutdir: string;\n}): string {\n\tconst projectPath = toRelativeDisplayPath(args.root, args.projectPath);\n\tconst pathPattern = toRelativeDisplayPath(args.root, args.pathPattern);\n\t// an outdir of `./` is the root itself\n\tconst outdir = toRelativeDisplayPath(args.root, args.outdir) || \".\";\n\treturn [\n\t\t\"If you use coding agents, consider adding this to your AGENTS.md:\",\n\t\t\"\",\n\t\t\"## Localization\",\n\t\t`- Translations are an inlang project. Before localization work, read \\`${projectPath}/README.md\\`. It covers checks, machine translation and editors. It is git-ignored, so search tools may skip it.`,\n\t\t`- Edit messages in \\`${pathPattern}\\`. Never edit \\`${outdir}/\\`: Paraglide JS generates it.`,\n\t].join(\"\\n\");\n}\n"]}
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,36 @@
1
+ import { expect, test } from "vitest";
2
+ import { agentsMdSuggestion } from "./agents-md-suggestion.js";
3
+ test("the AGENTS.md suggestion names the project, message files and outdir", () => {
4
+ expect(agentsMdSuggestion({
5
+ root: "/app",
6
+ projectPath: "./project.inlang",
7
+ pathPattern: "./messages/{locale}.json",
8
+ outdir: "./src/paraglide",
9
+ })).toBe([
10
+ "If you use coding agents, consider adding this to your AGENTS.md:",
11
+ "",
12
+ "## Localization",
13
+ "- Translations are an inlang project. Before localization work, read `project.inlang/README.md`. It covers checks, machine translation and editors. It is git-ignored, so search tools may skip it.",
14
+ "- Edit messages in `messages/{locale}.json`. Never edit `src/paraglide/`: Paraglide JS generates it.",
15
+ ].join("\n"));
16
+ });
17
+ test("the AGENTS.md suggestion uses custom paths relative to the root", () => {
18
+ const suggestion = agentsMdSuggestion({
19
+ root: "/app",
20
+ projectPath: "/app/i18n/project.inlang",
21
+ pathPattern: "./i18n/{locale}/common.json",
22
+ outdir: "./lib/paraglide/",
23
+ });
24
+ expect(suggestion).toContain("`i18n/project.inlang/README.md`");
25
+ expect(suggestion).toContain("`i18n/{locale}/common.json`");
26
+ expect(suggestion).toContain("Never edit `lib/paraglide/`");
27
+ });
28
+ test("the AGENTS.md suggestion handles an outdir at the root", () => {
29
+ expect(agentsMdSuggestion({
30
+ root: "/app",
31
+ projectPath: "./project.inlang",
32
+ pathPattern: "./messages/{locale}.json",
33
+ outdir: "./",
34
+ })).toContain("Never edit `./`");
35
+ });
36
+ //# sourceMappingURL=agents-md-suggestion.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agents-md-suggestion.test.js","sourceRoot":"","sources":["../../../src/cli/steps/agents-md-suggestion.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAE/D,IAAI,CAAC,sEAAsE,EAAE,GAAG,EAAE;IACjF,MAAM,CACL,kBAAkB,CAAC;QAClB,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,kBAAkB;QAC/B,WAAW,EAAE,0BAA0B;QACvC,MAAM,EAAE,iBAAiB;KACzB,CAAC,CACF,CAAC,IAAI,CACL;QACC,mEAAmE;QACnE,EAAE;QACF,iBAAiB;QACjB,qMAAqM;QACrM,sGAAsG;KACtG,CAAC,IAAI,CAAC,IAAI,CAAC,CACZ,CAAC;AACH,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,iEAAiE,EAAE,GAAG,EAAE;IAC5E,MAAM,UAAU,GAAG,kBAAkB,CAAC;QACrC,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,0BAA0B;QACvC,WAAW,EAAE,6BAA6B;QAC1C,MAAM,EAAE,kBAAkB;KAC1B,CAAC,CAAC;IAEH,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,iCAAiC,CAAC,CAAC;IAChE,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,6BAA6B,CAAC,CAAC;IAC5D,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,6BAA6B,CAAC,CAAC;AAC7D,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,wDAAwD,EAAE,GAAG,EAAE;IACnE,MAAM,CACL,kBAAkB,CAAC;QAClB,IAAI,EAAE,MAAM;QACZ,WAAW,EAAE,kBAAkB;QAC/B,WAAW,EAAE,0BAA0B;QACvC,MAAM,EAAE,IAAI;KACZ,CAAC,CACF,CAAC,SAAS,CAAC,iBAAiB,CAAC,CAAC;AAChC,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"vitest\";\nimport { agentsMdSuggestion } from \"./agents-md-suggestion.js\";\n\ntest(\"the AGENTS.md suggestion names the project, message files and outdir\", () => {\n\texpect(\n\t\tagentsMdSuggestion({\n\t\t\troot: \"/app\",\n\t\t\tprojectPath: \"./project.inlang\",\n\t\t\tpathPattern: \"./messages/{locale}.json\",\n\t\t\toutdir: \"./src/paraglide\",\n\t\t})\n\t).toBe(\n\t\t[\n\t\t\t\"If you use coding agents, consider adding this to your AGENTS.md:\",\n\t\t\t\"\",\n\t\t\t\"## Localization\",\n\t\t\t\"- Translations are an inlang project. Before localization work, read `project.inlang/README.md`. It covers checks, machine translation and editors. It is git-ignored, so search tools may skip it.\",\n\t\t\t\"- Edit messages in `messages/{locale}.json`. Never edit `src/paraglide/`: Paraglide JS generates it.\",\n\t\t].join(\"\\n\")\n\t);\n});\n\ntest(\"the AGENTS.md suggestion uses custom paths relative to the root\", () => {\n\tconst suggestion = agentsMdSuggestion({\n\t\troot: \"/app\",\n\t\tprojectPath: \"/app/i18n/project.inlang\",\n\t\tpathPattern: \"./i18n/{locale}/common.json\",\n\t\toutdir: \"./lib/paraglide/\",\n\t});\n\n\texpect(suggestion).toContain(\"`i18n/project.inlang/README.md`\");\n\texpect(suggestion).toContain(\"`i18n/{locale}/common.json`\");\n\texpect(suggestion).toContain(\"Never edit `lib/paraglide/`\");\n});\n\ntest(\"the AGENTS.md suggestion handles an outdir at the root\", () => {\n\texpect(\n\t\tagentsMdSuggestion({\n\t\t\troot: \"/app\",\n\t\t\tprojectPath: \"./project.inlang\",\n\t\t\tpathPattern: \"./messages/{locale}.json\",\n\t\t\toutdir: \"./\",\n\t\t})\n\t).toContain(\"Never edit `./`\");\n});\n"]}
@@ -1,6 +1,7 @@
1
1
  import { prompt } from "../utils.js";
2
2
  import { updatePackageJson } from "./update-package-json.js";
3
3
  import path from "node:path";
4
+ import { INLANG_CLI_VERSION_RANGE } from "./add-inlang-check.js";
4
5
  export const maybeAddMachineTranslation = async (ctx) => {
5
6
  // Prompt for machine translation
6
7
  const useMachineTranslation = await prompt(`Do you want to set up machine translations?`, {
@@ -21,7 +22,7 @@ export const maybeAddMachineTranslation = async (ctx) => {
21
22
  return devDeps;
22
23
  return {
23
24
  ...devDeps,
24
- "@inlang/cli": "^3.0.0",
25
+ "@inlang/cli": INLANG_CLI_VERSION_RANGE,
25
26
  };
26
27
  },
27
28
  scripts: async (scripts) => {
@@ -34,7 +35,7 @@ export const maybeAddMachineTranslation = async (ctx) => {
34
35
  };
35
36
  },
36
37
  })(ctx);
37
- ctx.logger.success("Added @inlang/cli and machine-translate script to package.json");
38
+ ctx.logger.success("Added a machine-translate script to package.json.");
38
39
  }
39
40
  catch (error) {
40
41
  ctx.logger.error([