@inlang/paraglide-js 2.0.0-beta.2 → 2.0.0-beta.21

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 (352) hide show
  1. package/README.md +3 -3
  2. package/dist/adapter-utils/routing/resolveUserPathDefinition.test.js +6 -6
  3. package/dist/adapter-utils/routing/resolveUserPathDefinitions.d.ts +4 -4
  4. package/dist/adapter-utils/routing/resolveUserPathDefinitions.d.ts.map +1 -1
  5. package/dist/adapter-utils/routing/resolveUserPathDefinitions.js +4 -7
  6. package/dist/bundler-plugins/index.d.ts +1 -0
  7. package/dist/bundler-plugins/index.d.ts.map +1 -1
  8. package/dist/bundler-plugins/index.js +1 -0
  9. package/dist/bundler-plugins/rollup.d.ts +1 -5
  10. package/dist/bundler-plugins/rollup.d.ts.map +1 -1
  11. package/dist/bundler-plugins/unplugin.d.ts +2 -16
  12. package/dist/bundler-plugins/unplugin.d.ts.map +1 -1
  13. package/dist/bundler-plugins/unplugin.js +69 -28
  14. package/dist/bundler-plugins/vite.d.ts +1 -5
  15. package/dist/bundler-plugins/vite.d.ts.map +1 -1
  16. package/dist/bundler-plugins/webpack.d.ts +2 -0
  17. package/dist/bundler-plugins/webpack.d.ts.map +1 -0
  18. package/dist/bundler-plugins/webpack.js +3 -0
  19. package/dist/cli/commands/compile/command.d.ts.map +1 -1
  20. package/dist/cli/commands/compile/command.js +21 -22
  21. package/dist/cli/commands/init/command.d.ts.map +1 -1
  22. package/dist/cli/commands/init/command.js +20 -9
  23. package/dist/cli/defaults.d.ts +1 -1
  24. package/dist/cli/defaults.d.ts.map +1 -1
  25. package/dist/cli/defaults.js +5 -10
  26. package/dist/cli/index.d.ts +0 -9
  27. package/dist/cli/index.d.ts.map +1 -1
  28. package/dist/cli/index.js +2 -9
  29. package/dist/cli/steps/add-vite-plugin.d.ts +10 -0
  30. package/dist/cli/steps/add-vite-plugin.d.ts.map +1 -0
  31. package/dist/cli/steps/add-vite-plugin.js +61 -0
  32. package/dist/cli/steps/add-vite-plugin.test.d.ts +2 -0
  33. package/dist/cli/steps/add-vite-plugin.test.d.ts.map +1 -0
  34. package/dist/cli/steps/add-vite-plugin.test.js +69 -0
  35. package/dist/cli/steps/detect-bundler.d.ts +11 -0
  36. package/dist/cli/steps/detect-bundler.d.ts.map +1 -0
  37. package/dist/cli/steps/detect-bundler.js +21 -0
  38. package/dist/cli/steps/detect-bundler.test.d.ts +2 -0
  39. package/dist/cli/steps/detect-bundler.test.d.ts.map +1 -0
  40. package/dist/cli/steps/detect-bundler.test.js +28 -0
  41. package/dist/cli/steps/index.d.ts +9 -0
  42. package/dist/cli/steps/index.d.ts.map +1 -0
  43. package/dist/cli/steps/index.js +8 -0
  44. package/dist/cli/steps/initialize-inlang-project.d.ts +1 -11
  45. package/dist/cli/steps/initialize-inlang-project.d.ts.map +1 -1
  46. package/dist/cli/steps/initialize-inlang-project.js +143 -118
  47. package/dist/cli/steps/maybe-add-sherlock.d.ts.map +1 -1
  48. package/dist/cli/steps/maybe-add-sherlock.js +13 -14
  49. package/dist/cli/steps/run-compiler.d.ts.map +1 -1
  50. package/dist/cli/steps/run-compiler.js +2 -2
  51. package/dist/cli/steps/update-ts-config.d.ts +2 -2
  52. package/dist/cli/steps/update-ts-config.js +5 -5
  53. package/dist/compiler/{compileBundle.d.ts → compile-bundle.d.ts} +1 -3
  54. package/dist/compiler/compile-bundle.d.ts.map +1 -0
  55. package/dist/compiler/compile-bundle.js +55 -0
  56. package/dist/compiler/compile-bundle.test.d.ts +2 -0
  57. package/dist/compiler/compile-bundle.test.d.ts.map +1 -0
  58. package/dist/compiler/compile-bundle.test.js +91 -0
  59. package/dist/compiler/{compileExpression.d.ts → compile-expression.d.ts} +1 -1
  60. package/dist/compiler/compile-expression.d.ts.map +1 -0
  61. package/dist/compiler/compile-local-variable.d.ts +17 -0
  62. package/dist/compiler/compile-local-variable.d.ts.map +1 -0
  63. package/dist/compiler/compile-local-variable.js +38 -0
  64. package/dist/compiler/compile-local-variable.test.d.ts +2 -0
  65. package/dist/compiler/compile-local-variable.test.d.ts.map +1 -0
  66. package/dist/compiler/compile-local-variable.test.js +71 -0
  67. package/dist/compiler/compile-message.d.ts +8 -0
  68. package/dist/compiler/compile-message.d.ts.map +1 -0
  69. package/dist/compiler/compile-message.js +94 -0
  70. package/dist/compiler/compile-message.test.d.ts +2 -0
  71. package/dist/compiler/compile-message.test.d.ts.map +1 -0
  72. package/dist/compiler/compile-message.test.js +279 -0
  73. package/dist/compiler/compile-pattern.d.ts +20 -0
  74. package/dist/compiler/compile-pattern.d.ts.map +1 -0
  75. package/dist/compiler/compile-pattern.js +40 -0
  76. package/dist/compiler/compile-pattern.test.d.ts +2 -0
  77. package/dist/compiler/compile-pattern.test.d.ts.map +1 -0
  78. package/dist/compiler/compile-pattern.test.js +75 -0
  79. package/dist/compiler/compile-project.d.ts +18 -0
  80. package/dist/compiler/compile-project.d.ts.map +1 -0
  81. package/dist/compiler/{compileProject.js → compile-project.js} +13 -50
  82. package/dist/compiler/compile-project.test.d.ts +2 -0
  83. package/dist/compiler/compile-project.test.d.ts.map +1 -0
  84. package/dist/compiler/{compileProject.test.js → compile-project.test.js} +208 -175
  85. package/dist/compiler/compile.bench.d.ts +2 -0
  86. package/dist/compiler/compile.bench.d.ts.map +1 -0
  87. package/dist/compiler/compile.bench.js +39 -0
  88. package/dist/compiler/compile.d.ts +7 -7
  89. package/dist/compiler/compile.d.ts.map +1 -1
  90. package/dist/compiler/compile.js +55 -22
  91. package/dist/compiler/compile.test.js +149 -0
  92. package/dist/compiler/compiler-options.d.ts +172 -0
  93. package/dist/compiler/compiler-options.d.ts.map +1 -0
  94. package/dist/compiler/compiler-options.js +8 -0
  95. package/dist/compiler/index.d.ts +7 -4
  96. package/dist/compiler/index.d.ts.map +1 -1
  97. package/dist/compiler/index.js +5 -4
  98. package/dist/compiler/jsdoc-types.d.ts +15 -0
  99. package/dist/compiler/jsdoc-types.d.ts.map +1 -0
  100. package/dist/compiler/jsdoc-types.js +26 -0
  101. package/dist/compiler/output-structure/locale-modules.d.ts +6 -2
  102. package/dist/compiler/output-structure/locale-modules.d.ts.map +1 -1
  103. package/dist/compiler/output-structure/locale-modules.js +26 -21
  104. package/dist/compiler/output-structure/locale-modules.test.js +3 -2
  105. package/dist/compiler/output-structure/message-modules.d.ts +6 -2
  106. package/dist/compiler/output-structure/message-modules.d.ts.map +1 -1
  107. package/dist/compiler/output-structure/message-modules.js +51 -30
  108. package/dist/compiler/output-structure/message-modules.test.js +50 -1
  109. package/dist/compiler/registry.d.ts +10 -10
  110. package/dist/compiler/registry.d.ts.map +1 -1
  111. package/dist/compiler/registry.js +23 -34
  112. package/dist/compiler/runtime/assert-is-locale.d.ts +9 -0
  113. package/dist/compiler/runtime/assert-is-locale.d.ts.map +1 -0
  114. package/dist/compiler/runtime/assert-is-locale.js +15 -0
  115. package/dist/compiler/runtime/assert-is-locale.test.d.ts +2 -0
  116. package/dist/compiler/runtime/assert-is-locale.test.d.ts.map +1 -0
  117. package/dist/compiler/runtime/assert-is-locale.test.js +26 -0
  118. package/dist/compiler/runtime/base-locale.d.ts +10 -0
  119. package/dist/compiler/runtime/base-locale.d.ts.map +1 -0
  120. package/dist/compiler/runtime/base-locale.js +9 -0
  121. package/dist/compiler/runtime/cookie-name.d.ts +3 -0
  122. package/dist/compiler/runtime/cookie-name.d.ts.map +1 -0
  123. package/dist/compiler/runtime/cookie-name.js +2 -0
  124. package/dist/compiler/runtime/create-runtime.d.ts +29 -0
  125. package/dist/compiler/runtime/create-runtime.d.ts.map +1 -0
  126. package/dist/compiler/runtime/create-runtime.js +110 -0
  127. package/dist/compiler/runtime/de-localize-path.d.ts +27 -0
  128. package/dist/compiler/runtime/de-localize-path.d.ts.map +1 -0
  129. package/dist/compiler/runtime/de-localize-path.js +52 -0
  130. package/dist/compiler/runtime/de-localize-path.test.d.ts +2 -0
  131. package/dist/compiler/runtime/de-localize-path.test.d.ts.map +1 -0
  132. package/dist/compiler/runtime/de-localize-path.test.js +109 -0
  133. package/dist/compiler/runtime/de-localized-path.d.ts +27 -0
  134. package/dist/compiler/runtime/de-localized-path.d.ts.map +1 -0
  135. package/dist/compiler/runtime/de-localized-path.js +32 -0
  136. package/dist/compiler/runtime/de-localized-path.test.d.ts +2 -0
  137. package/dist/compiler/runtime/de-localized-path.test.d.ts.map +1 -0
  138. package/dist/compiler/runtime/de-localized-path.test.js +48 -0
  139. package/dist/compiler/runtime/detect-locale-from-request.d.ts +22 -0
  140. package/dist/compiler/runtime/detect-locale-from-request.d.ts.map +1 -0
  141. package/dist/compiler/runtime/detect-locale-from-request.js +44 -0
  142. package/dist/compiler/runtime/e2e.test.d.ts +2 -0
  143. package/dist/compiler/runtime/e2e.test.d.ts.map +1 -0
  144. package/dist/compiler/runtime/e2e.test.js +50 -0
  145. package/dist/compiler/runtime/extract-locale-from-cookie.d.ts +10 -0
  146. package/dist/compiler/runtime/extract-locale-from-cookie.d.ts.map +1 -0
  147. package/dist/compiler/runtime/extract-locale-from-cookie.js +21 -0
  148. package/dist/compiler/runtime/extract-locale-from-cookie.test.d.ts +2 -0
  149. package/dist/compiler/runtime/extract-locale-from-cookie.test.d.ts.map +1 -0
  150. package/dist/compiler/runtime/extract-locale-from-cookie.test.js +45 -0
  151. package/dist/compiler/runtime/extract-locale-from-pathname.d.ts +13 -0
  152. package/dist/compiler/runtime/extract-locale-from-pathname.d.ts.map +1 -0
  153. package/dist/compiler/runtime/extract-locale-from-pathname.js +35 -0
  154. package/dist/compiler/runtime/extract-locale-from-pathname.test.d.ts +2 -0
  155. package/dist/compiler/runtime/extract-locale-from-pathname.test.d.ts.map +1 -0
  156. package/dist/compiler/runtime/extract-locale-from-pathname.test.js +103 -0
  157. package/dist/compiler/runtime/extract-locale-from-request.d.ts +16 -0
  158. package/dist/compiler/runtime/extract-locale-from-request.d.ts.map +1 -0
  159. package/dist/compiler/runtime/extract-locale-from-request.js +85 -0
  160. package/dist/compiler/runtime/extract-locale-from-request.test.d.ts +2 -0
  161. package/dist/compiler/runtime/extract-locale-from-request.test.d.ts.map +1 -0
  162. package/dist/compiler/runtime/extract-locale-from-request.test.js +100 -0
  163. package/dist/compiler/runtime/extract-locale-from-url.d.ts +8 -0
  164. package/dist/compiler/runtime/extract-locale-from-url.d.ts.map +1 -0
  165. package/dist/compiler/runtime/extract-locale-from-url.js +70 -0
  166. package/dist/compiler/runtime/extract-locale-from-url.test.d.ts +2 -0
  167. package/dist/compiler/runtime/extract-locale-from-url.test.d.ts.map +1 -0
  168. package/dist/compiler/runtime/extract-locale-from-url.test.js +101 -0
  169. package/dist/compiler/runtime/get-locale-from-path.d.ts +13 -0
  170. package/dist/compiler/runtime/get-locale-from-path.d.ts.map +1 -0
  171. package/dist/compiler/runtime/get-locale-from-path.js +17 -0
  172. package/dist/compiler/runtime/get-locale-from-path.test.d.ts +2 -0
  173. package/dist/compiler/runtime/get-locale-from-path.test.d.ts.map +1 -0
  174. package/dist/compiler/runtime/get-locale-from-path.test.js +22 -0
  175. package/dist/compiler/runtime/get-locale.d.ts +30 -0
  176. package/dist/compiler/runtime/get-locale.d.ts.map +1 -0
  177. package/dist/compiler/runtime/get-locale.js +108 -0
  178. package/dist/compiler/runtime/get-locale.test.d.ts +2 -0
  179. package/dist/compiler/runtime/get-locale.test.d.ts.map +1 -0
  180. package/dist/compiler/runtime/get-locale.test.js +114 -0
  181. package/dist/compiler/runtime/get-url-origin.d.ts +20 -0
  182. package/dist/compiler/runtime/get-url-origin.d.ts.map +1 -0
  183. package/dist/compiler/runtime/get-url-origin.js +29 -0
  184. package/dist/compiler/runtime/get-url-origin.test.d.ts +2 -0
  185. package/dist/compiler/runtime/get-url-origin.test.d.ts.map +1 -0
  186. package/dist/compiler/runtime/get-url-origin.test.js +19 -0
  187. package/dist/compiler/runtime/is-locale.d.ts +15 -0
  188. package/dist/compiler/runtime/is-locale.d.ts.map +1 -0
  189. package/dist/compiler/runtime/is-locale.js +17 -0
  190. package/dist/compiler/runtime/jsdoc-runtime.d.ts +2 -0
  191. package/dist/compiler/runtime/jsdoc-runtime.d.ts.map +1 -0
  192. package/dist/compiler/{runtime.js → runtime/jsdoc-runtime.js} +29 -56
  193. package/dist/compiler/runtime/locale-in-path.d.ts +13 -0
  194. package/dist/compiler/runtime/locale-in-path.d.ts.map +1 -0
  195. package/dist/compiler/runtime/locale-in-path.js +17 -0
  196. package/dist/compiler/runtime/locale-in-path.test.d.ts +2 -0
  197. package/dist/compiler/runtime/locale-in-path.test.d.ts.map +1 -0
  198. package/dist/compiler/runtime/locale-in-path.test.js +22 -0
  199. package/dist/compiler/runtime/locales.d.ts +10 -0
  200. package/dist/compiler/runtime/locales.d.ts.map +1 -0
  201. package/dist/compiler/runtime/locales.js +9 -0
  202. package/dist/compiler/runtime/localize-href.d.ts +82 -0
  203. package/dist/compiler/runtime/localize-href.d.ts.map +1 -0
  204. package/dist/compiler/runtime/localize-href.js +108 -0
  205. package/dist/compiler/runtime/localize-href.test.d.ts +2 -0
  206. package/dist/compiler/runtime/localize-href.test.d.ts.map +1 -0
  207. package/dist/compiler/runtime/localize-href.test.js +136 -0
  208. package/dist/compiler/runtime/localize-path.d.ts +32 -0
  209. package/dist/compiler/runtime/localize-path.d.ts.map +1 -0
  210. package/dist/compiler/runtime/localize-path.js +95 -0
  211. package/dist/compiler/runtime/localize-path.test.d.ts +2 -0
  212. package/dist/compiler/runtime/localize-path.test.d.ts.map +1 -0
  213. package/dist/compiler/runtime/localize-path.test.js +220 -0
  214. package/dist/compiler/runtime/localize-url.d.ts +85 -0
  215. package/dist/compiler/runtime/localize-url.d.ts.map +1 -0
  216. package/dist/compiler/runtime/localize-url.js +245 -0
  217. package/dist/compiler/runtime/localize-url.test.d.ts +2 -0
  218. package/dist/compiler/runtime/localize-url.test.d.ts.map +1 -0
  219. package/dist/compiler/runtime/localize-url.test.js +288 -0
  220. package/dist/compiler/runtime/localized-path.d.ts +32 -0
  221. package/dist/compiler/runtime/localized-path.d.ts.map +1 -0
  222. package/dist/compiler/runtime/localized-path.js +44 -0
  223. package/dist/compiler/runtime/localized-path.test.d.ts +2 -0
  224. package/dist/compiler/runtime/localized-path.test.d.ts.map +1 -0
  225. package/dist/compiler/runtime/localized-path.test.js +42 -0
  226. package/dist/compiler/runtime/mock-runtime.d.ts +6 -0
  227. package/dist/compiler/runtime/mock-runtime.d.ts.map +1 -0
  228. package/dist/compiler/runtime/mock-runtime.js +31 -0
  229. package/dist/compiler/runtime/path-to-regexp.d.ts +2 -0
  230. package/dist/compiler/runtime/path-to-regexp.d.ts.map +1 -0
  231. package/dist/compiler/runtime/path-to-regexp.js +1 -0
  232. package/dist/compiler/runtime/pathname-pattern.d.ts +30 -0
  233. package/dist/compiler/runtime/pathname-pattern.d.ts.map +1 -0
  234. package/dist/compiler/runtime/pathname-pattern.js +99 -0
  235. package/dist/compiler/runtime/pathname-pattern.test.d.ts +2 -0
  236. package/dist/compiler/runtime/pathname-pattern.test.d.ts.map +1 -0
  237. package/dist/compiler/runtime/pathname-pattern.test.js +103 -0
  238. package/dist/compiler/runtime/server-middleware.d.ts +50 -0
  239. package/dist/compiler/runtime/server-middleware.d.ts.map +1 -0
  240. package/dist/compiler/runtime/server-middleware.js +85 -0
  241. package/dist/compiler/runtime/server-middleware.test.d.ts +2 -0
  242. package/dist/compiler/runtime/server-middleware.test.d.ts.map +1 -0
  243. package/dist/compiler/runtime/server-middleware.test.js +117 -0
  244. package/dist/compiler/runtime/set-locale.d.ts +11 -0
  245. package/dist/compiler/runtime/set-locale.d.ts.map +1 -0
  246. package/dist/compiler/runtime/set-locale.js +76 -0
  247. package/dist/compiler/runtime/set-locale.test.d.ts +2 -0
  248. package/dist/compiler/runtime/set-locale.test.d.ts.map +1 -0
  249. package/dist/compiler/runtime/set-locale.test.js +100 -0
  250. package/dist/compiler/runtime/strategy.d.ts +5 -0
  251. package/dist/compiler/runtime/strategy.d.ts.map +1 -0
  252. package/dist/compiler/runtime/strategy.js +4 -0
  253. package/dist/compiler/runtime/ts-runtime.d.ts +2 -0
  254. package/dist/compiler/runtime/ts-runtime.d.ts.map +1 -0
  255. package/dist/compiler/runtime/ts-runtime.js +119 -0
  256. package/dist/compiler/runtime/type.d.ts +27 -0
  257. package/dist/compiler/runtime/type.d.ts.map +1 -0
  258. package/dist/compiler/runtime/type.js +1 -0
  259. package/dist/compiler/runtime/type.test.d.ts +2 -0
  260. package/dist/compiler/runtime/type.test.d.ts.map +1 -0
  261. package/dist/compiler/runtime/type.test.js +91 -0
  262. package/dist/compiler/runtime/variables.d.ts +40 -0
  263. package/dist/compiler/runtime/variables.d.ts.map +1 -0
  264. package/dist/compiler/runtime/variables.js +35 -0
  265. package/dist/compiler/safe-module-id.d.ts +8 -0
  266. package/dist/compiler/safe-module-id.d.ts.map +1 -0
  267. package/dist/compiler/safe-module-id.js +71 -0
  268. package/dist/compiler/safe-module-id.test.d.ts +2 -0
  269. package/dist/compiler/safe-module-id.test.d.ts.map +1 -0
  270. package/dist/compiler/safe-module-id.test.js +27 -0
  271. package/dist/compiler/strategy.d.ts +13 -0
  272. package/dist/compiler/strategy.d.ts.map +1 -0
  273. package/dist/compiler/strategy.js +12 -0
  274. package/dist/compiler/strategy.test.d.ts +2 -0
  275. package/dist/compiler/strategy.test.d.ts.map +1 -0
  276. package/dist/compiler/strategy.test.js +9 -0
  277. package/dist/compiler/types.d.ts +17 -2
  278. package/dist/compiler/types.d.ts.map +1 -1
  279. package/dist/compiler/types.js +1 -28
  280. package/dist/compiler/urlpattern-polyfill/index.d.ts +2 -0
  281. package/dist/compiler/urlpattern-polyfill/index.d.ts.map +1 -0
  282. package/dist/compiler/urlpattern-polyfill/index.js +1 -0
  283. package/dist/index.d.ts +2 -6
  284. package/dist/index.d.ts.map +1 -1
  285. package/dist/index.js +2 -2
  286. package/dist/path-to-regexp/index.d.ts +12 -0
  287. package/dist/path-to-regexp/index.d.ts.map +1 -0
  288. package/dist/path-to-regexp/index.js +11 -0
  289. package/dist/playground.d.ts +2 -0
  290. package/dist/playground.d.ts.map +1 -0
  291. package/dist/playground.js +5 -0
  292. package/dist/services/env-variables/create-index-file.d.ts +2 -0
  293. package/dist/services/env-variables/create-index-file.d.ts.map +1 -0
  294. package/dist/services/env-variables/create-index-file.js +29 -0
  295. package/dist/services/env-variables/index.js +1 -1
  296. package/dist/services/file-handling/write-output.d.ts +6 -1
  297. package/dist/services/file-handling/write-output.d.ts.map +1 -1
  298. package/dist/services/file-handling/write-output.js +34 -26
  299. package/dist/services/file-handling/write-output.test.js +93 -45
  300. package/dist/services/logger/index.d.ts +0 -4
  301. package/dist/services/logger/index.d.ts.map +1 -1
  302. package/dist/services/logger/index.js +11 -14
  303. package/dist/services/telemetry/capture.d.ts +1 -2
  304. package/dist/services/telemetry/capture.d.ts.map +1 -1
  305. package/dist/services/telemetry/stack-detection.d.ts +1 -1
  306. package/dist/services/telemetry/stack-detection.d.ts.map +1 -1
  307. package/dist/services/telemetry/stack-detection.js +3 -8
  308. package/dist/services/telemetry/stack-detection.test.js +9 -12
  309. package/dist/services/valid-js-identifier/index.js +1 -1
  310. package/dist/services/valid-js-identifier/reserved-words.d.ts +2 -0
  311. package/dist/services/valid-js-identifier/reserved-words.d.ts.map +1 -0
  312. package/dist/urlpattern-polyfill/index.d.ts +2 -0
  313. package/dist/urlpattern-polyfill/index.d.ts.map +1 -0
  314. package/dist/urlpattern-polyfill/index.js +1 -0
  315. package/dist/utilities/node-normalize-path.d.ts +2 -0
  316. package/dist/utilities/node-normalize-path.d.ts.map +1 -0
  317. package/dist/utilities/node-normalize-path.js +9 -0
  318. package/package.json +34 -41
  319. package/dist/compiler/compileBundle.d.ts.map +0 -1
  320. package/dist/compiler/compileBundle.js +0 -55
  321. package/dist/compiler/compileExpression.d.ts.map +0 -1
  322. package/dist/compiler/compileMessage.d.ts +0 -12
  323. package/dist/compiler/compileMessage.d.ts.map +0 -1
  324. package/dist/compiler/compileMessage.js +0 -64
  325. package/dist/compiler/compileMessage.test.d.ts +0 -2
  326. package/dist/compiler/compileMessage.test.d.ts.map +0 -1
  327. package/dist/compiler/compileMessage.test.js +0 -74
  328. package/dist/compiler/compilePattern.d.ts +0 -12
  329. package/dist/compiler/compilePattern.d.ts.map +0 -1
  330. package/dist/compiler/compilePattern.js +0 -28
  331. package/dist/compiler/compilePattern.test.d.ts +0 -2
  332. package/dist/compiler/compilePattern.test.d.ts.map +0 -1
  333. package/dist/compiler/compilePattern.test.js +0 -67
  334. package/dist/compiler/compileProject.d.ts +0 -43
  335. package/dist/compiler/compileProject.d.ts.map +0 -1
  336. package/dist/compiler/compileProject.test.d.ts +0 -2
  337. package/dist/compiler/compileProject.test.d.ts.map +0 -1
  338. package/dist/compiler/emit-dts.d.ts +0 -7
  339. package/dist/compiler/emit-dts.d.ts.map +0 -1
  340. package/dist/compiler/emit-dts.js +0 -56
  341. package/dist/compiler/emit-dts.test.d.ts +0 -2
  342. package/dist/compiler/emit-dts.test.d.ts.map +0 -1
  343. package/dist/compiler/emit-dts.test.js +0 -43
  344. package/dist/compiler/jsDocComment.d.ts +0 -9
  345. package/dist/compiler/jsDocComment.d.ts.map +0 -1
  346. package/dist/compiler/jsDocComment.js +0 -30
  347. package/dist/compiler/runtime.d.ts +0 -6
  348. package/dist/compiler/runtime.d.ts.map +0 -1
  349. package/dist/services/valid-js-identifier/reservedWords.d.ts +0 -2
  350. package/dist/services/valid-js-identifier/reservedWords.d.ts.map +0 -1
  351. /package/dist/compiler/{compileExpression.js → compile-expression.js} +0 -0
  352. /package/dist/services/valid-js-identifier/{reservedWords.js → reserved-words.js} +0 -0
package/README.md CHANGED
@@ -35,10 +35,10 @@ _If you are using a Bundler use one of the [Bundler Plugins](usage#usage-with-a-
35
35
 
36
36
  ## Using messages in code
37
37
 
38
- After running the compiler import the messages with `import * as m from "./paraglide/messages"`. By convention, a wildcard import is used.
38
+ After running the compiler import the messages with `import { m } from "./paraglide/messages"`. By convention, a wildcard import is used.
39
39
 
40
40
  ```js
41
- import * as m from "./paraglide/messages.js";
41
+ import { m } from "./paraglide/messages.js";
42
42
 
43
43
  m.greeting({ name: "Samuel" }); // Hello Samuel!
44
44
  ```
@@ -49,7 +49,7 @@ To change the locale, use the `setLocale` function.
49
49
 
50
50
  ```js
51
51
  import { setLocale } from "./paraglide/runtime.js";
52
- import * as m from "./paraglide/messages.js";
52
+ import { m } from "./paraglide/messages.js";
53
53
 
54
54
  m.greeting({ name: "Samuel" }); // Hello Samuel!
55
55
 
@@ -8,14 +8,14 @@ describe("resolvePathTranslations", () => {
8
8
  de: "/ueber-uns",
9
9
  },
10
10
  };
11
- const availableLanguageTags = ["en", "de"];
12
- const result = resolveUserPathDefinitions(userTranslations, availableLanguageTags);
11
+ const availableLocales = ["en", "de"];
12
+ const result = resolveUserPathDefinitions(userTranslations, availableLocales);
13
13
  expect(result).toEqual(userTranslations);
14
14
  });
15
15
  it("resolves message translations", () => {
16
16
  const userTranslations = {
17
- "/about": (_, { languageTag }) => {
18
- switch (languageTag) {
17
+ "/about": (_, { locale }) => {
18
+ switch (locale) {
19
19
  case "en":
20
20
  return "/about";
21
21
  case "de":
@@ -23,8 +23,8 @@ describe("resolvePathTranslations", () => {
23
23
  }
24
24
  },
25
25
  };
26
- const availableLanguageTags = ["en", "de"];
27
- const result = resolveUserPathDefinitions(userTranslations, availableLanguageTags);
26
+ const availableLocales = ["en", "de"];
27
+ const result = resolveUserPathDefinitions(userTranslations, availableLocales);
28
28
  expect(result).toEqual({
29
29
  "/about": {
30
30
  en: "/about",
@@ -1,4 +1,4 @@
1
- import type { MessageIndexFunction } from "../../index.js";
1
+ import type { MessageBundleFunction } from "../../compiler/types.js";
2
2
  import type { PathDefinitionTranslations } from "./routeDefinitions.js";
3
3
  /**
4
4
  * Maps canonical paths to translations for each language.
@@ -22,7 +22,7 @@ import type { PathDefinitionTranslations } from "./routeDefinitions.js";
22
22
  * ```
23
23
  */
24
24
  export type UserPathDefinitionTranslations<T extends string = string> = {
25
- [canonicalPath: `/${string}`]: Record<T, `/${string}`> | MessageIndexFunction<T>;
25
+ [canonicalPath: `/${string}`]: Record<T, `/${string}`> | MessageBundleFunction<T>;
26
26
  };
27
27
  /**
28
28
  * For UX purpouses we let users pass messages as pathnames.
@@ -33,8 +33,8 @@ export type UserPathDefinitionTranslations<T extends string = string> = {
33
33
  * Does NOT perform any validation on if the user-provided path translation configuration is valid.
34
34
  *
35
35
  * @param userTranslations The user-provided path translation configuration.
36
- * @param availableLanguageTags The available language tags.
36
+ * @param availableLocales The available language tags.
37
37
  * @returns The resolved path translations.
38
38
  */
39
- export declare const resolveUserPathDefinitions: <T extends string>(userTranslations: UserPathDefinitionTranslations<T>, availableLanguageTags: readonly T[]) => PathDefinitionTranslations<T>;
39
+ export declare const resolveUserPathDefinitions: <T extends string>(userTranslations: UserPathDefinitionTranslations<T>, availableLocales: readonly T[]) => PathDefinitionTranslations<T>;
40
40
  //# sourceMappingURL=resolveUserPathDefinitions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolveUserPathDefinitions.d.ts","sourceRoot":"","sources":["../../../src/adapter-utils/routing/resolveUserPathDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,8BAA8B,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI;IACvE,CAAC,aAAa,EAAE,IAAI,MAAM,EAAE,GACzB,MAAM,CAAC,CAAC,EAAE,IAAI,MAAM,EAAE,CAAC,GACvB,oBAAoB,CAAC,CAAC,CAAC,CAAC;CAC3B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,0BAA0B,GAAI,CAAC,SAAS,MAAM,oBACxC,8BAA8B,CAAC,CAAC,CAAC,yBAC5B,SAAS,CAAC,EAAE,KACjC,0BAA0B,CAAC,CAAC,CAQ7B,CAAC"}
1
+ {"version":3,"file":"resolveUserPathDefinitions.d.ts","sourceRoot":"","sources":["../../../src/adapter-utils/routing/resolveUserPathDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AACrE,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,MAAM,8BAA8B,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM,IAAI;IACvE,CAAC,aAAa,EAAE,IAAI,MAAM,EAAE,GACzB,MAAM,CAAC,CAAC,EAAE,IAAI,MAAM,EAAE,CAAC,GACvB,qBAAqB,CAAC,CAAC,CAAC,CAAC;CAC5B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,0BAA0B,GAAI,CAAC,SAAS,MAAM,oBACxC,8BAA8B,CAAC,CAAC,CAAC,oBACjC,SAAS,CAAC,EAAE,KAC5B,0BAA0B,CAAC,CAAC,CAQ7B,CAAC"}
@@ -7,16 +7,13 @@
7
7
  * Does NOT perform any validation on if the user-provided path translation configuration is valid.
8
8
  *
9
9
  * @param userTranslations The user-provided path translation configuration.
10
- * @param availableLanguageTags The available language tags.
10
+ * @param availableLocales The available language tags.
11
11
  * @returns The resolved path translations.
12
12
  */
13
- export const resolveUserPathDefinitions = (userTranslations, availableLanguageTags) => Object.fromEntries(Object.entries(userTranslations).map(([path, translation]) => [
13
+ export const resolveUserPathDefinitions = (userTranslations, availableLocales) => Object.fromEntries(Object.entries(userTranslations).map(([path, translation]) => [
14
14
  path,
15
15
  typeof translation === "object"
16
16
  ? translation
17
- : fromMessage(translation, availableLanguageTags),
18
- ]));
19
- const fromMessage = (message, availableLanguageTags) => Object.fromEntries(availableLanguageTags.map((languageTag) => [
20
- languageTag,
21
- message({}, { languageTag }),
17
+ : fromMessage(translation, availableLocales),
22
18
  ]));
19
+ const fromMessage = (message, availableLocales) => Object.fromEntries(availableLocales.map((locale) => [locale, message({}, { locale })]));
@@ -1,3 +1,4 @@
1
1
  export { paraglideVitePlugin } from "./vite.js";
2
2
  export { paraglideRollupPlugin } from "./rollup.js";
3
+ export { paraglideWebpackPlugin } from "./webpack.js";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export { paraglideVitePlugin } from "./vite.js";
2
2
  export { paraglideRollupPlugin } from "./rollup.js";
3
+ export { paraglideWebpackPlugin } from "./webpack.js";
@@ -1,6 +1,2 @@
1
- export declare const paraglideRollupPlugin: (options: {
2
- project: string;
3
- outdir: string;
4
- options?: import("../compiler/compileProject.js").ParaglideCompilerOptions;
5
- }) => import("rollup").Plugin<any> | import("rollup").Plugin<any>[];
1
+ export declare const paraglideRollupPlugin: (options: import("../index.js").CompilerOptions) => import("rollup").Plugin<any> | import("rollup").Plugin<any>[];
6
2
  //# sourceMappingURL=rollup.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rollup.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/rollup.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB;;;;mEAAsC,CAAC"}
1
+ {"version":3,"file":"rollup.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/rollup.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB,mHAAsC,CAAC"}
@@ -1,18 +1,4 @@
1
1
  import type { UnpluginFactory } from "unplugin";
2
- import type { ParaglideCompilerOptions } from "../compiler/compileProject.js";
3
- export declare const unpluginFactory: UnpluginFactory<{
4
- /**
5
- * The path to the inlang project.
6
- *
7
- * @example "./project.inlang"
8
- */
9
- project: string;
10
- /**
11
- * The path to the output directory.
12
- *
13
- * @example "./src/paraglide"
14
- */
15
- outdir: string;
16
- options?: ParaglideCompilerOptions;
17
- }>;
2
+ import type { CompilerOptions } from "../compiler/compiler-options.js";
3
+ export declare const unpluginFactory: UnpluginFactory<CompilerOptions>;
18
4
  //# sourceMappingURL=unplugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"unplugin.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/unplugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAChD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAO9E,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC;IAC7C;;;;OAIG;IACH,OAAO,EAAE,MAAM,CAAC;IAChB;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,wBAAwB,CAAC;CACnC,CAwCC,CAAC"}
1
+ {"version":3,"file":"unplugin.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/unplugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAMhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAQvE,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,eAAe,CAiF3D,CAAC"}
@@ -1,66 +1,107 @@
1
1
  import { compile } from "../compiler/compile.js";
2
2
  import fs from "node:fs";
3
- import { resolve } from "node:path";
3
+ import { resolve, relative } from "node:path";
4
+ import { nodeNormalizePath } from "../utilities/node-normalize-path.js";
5
+ import { Logger } from "../services/logger/index.js";
4
6
  const PLUGIN_NAME = "unplugin-paraglide-js";
7
+ const logger = new Logger();
8
+ let previousCompilation;
5
9
  export const unpluginFactory = (args) => ({
6
10
  name: PLUGIN_NAME,
7
11
  enforce: "pre",
8
12
  async buildStart() {
9
- console.log("Paraglide JS: Compiling inlang project...");
10
- await compile({
11
- project: args.project,
12
- outdir: args.outdir,
13
- options: args.options,
14
- fs: wrappedFs,
15
- });
16
- for (const path of Array.from(readFiles)) {
17
- this.addWatchFile(path);
13
+ logger.info("Compiling inlang project...");
14
+ try {
15
+ previousCompilation = await compile({
16
+ fs: wrappedFs,
17
+ previousCompilation,
18
+ ...args,
19
+ });
20
+ logger.success("Compilation complete");
21
+ }
22
+ catch (error) {
23
+ logger.error("Failed to compile project:", error.message);
24
+ logger.info("Please check your translation files for syntax errors.");
25
+ }
26
+ finally {
27
+ // in any case add the files to watch
28
+ for (const path of Array.from(readFiles)) {
29
+ this.addWatchFile(path);
30
+ }
18
31
  }
19
32
  },
20
33
  async watchChange(path) {
21
- if (readFiles.has(path)) {
22
- console.log(`Paraglide JS: Recompiling inlang project...`);
34
+ const shouldCompile = readFiles.has(path) && !path.includes("cache");
35
+ if (shouldCompile === false) {
36
+ return;
37
+ }
38
+ const previouslyReadFiles = new Set(readFiles);
39
+ try {
40
+ logger.info(`Re-compiling inlang project... File "${relative(process.cwd(), path)}" has changed.`);
41
+ // Clear readFiles to track fresh file reads
23
42
  readFiles.clear();
24
- await compile({
25
- project: args.project,
26
- outdir: args.outdir,
27
- options: args.options,
43
+ previousCompilation = await compile({
28
44
  fs: wrappedFs,
45
+ previousCompilation,
46
+ ...args,
29
47
  });
48
+ logger.success("Compilation complete");
49
+ // Add any new files to watch
50
+ for (const filePath of Array.from(readFiles)) {
51
+ this.addWatchFile(filePath);
52
+ }
53
+ }
54
+ catch (e) {
55
+ readFiles = previouslyReadFiles;
56
+ // Reset compilation result on error
57
+ previousCompilation = undefined;
58
+ logger.warn("Failed to re-compile project:", e.message);
30
59
  }
31
60
  },
32
61
  webpack(compiler) {
33
- //we need the compiler to run before the build so that the message-modules will be present
34
- //In the other bundlers `buildStart` already runs before the build. In webpack it's a race condition
62
+ compiler.options.resolve = {
63
+ ...compiler.options.resolve,
64
+ fallback: {
65
+ ...compiler.options.resolve?.fallback,
66
+ // https://stackoverflow.com/a/72989932
67
+ async_hooks: false,
68
+ },
69
+ };
35
70
  compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
36
- await compile({
37
- project: args.project,
38
- outdir: args.outdir,
39
- options: args.options,
40
- fs: wrappedFs,
41
- });
71
+ try {
72
+ previousCompilation = await compile({
73
+ fs: wrappedFs,
74
+ previousCompilation,
75
+ ...args,
76
+ });
77
+ logger.success("Compilation complete");
78
+ }
79
+ catch (error) {
80
+ logger.warn("Failed to compile project:", error.message);
81
+ logger.warn("Please check your translation files for syntax errors.");
82
+ }
42
83
  });
43
84
  },
44
85
  });
45
- const readFiles = new Set();
86
+ let readFiles = new Set();
46
87
  // Create a wrapper around the fs object to intercept and store read files
47
88
  const wrappedFs = {
48
89
  ...fs,
49
90
  // @ts-expect-error - Node's fs has too many overloads
50
91
  readFile: (path, options, callback) => {
51
- readFiles.add(resolve(process.cwd(), path.toString()));
92
+ readFiles.add(nodeNormalizePath(resolve(process.cwd(), path.toString())));
52
93
  return fs.readFile(path, options, callback);
53
94
  },
54
95
  // @ts-expect-error - Node's fs has too many overloads
55
96
  readFileSync: (path, options) => {
56
- readFiles.add(resolve(process.cwd(), path.toString()));
97
+ readFiles.add(nodeNormalizePath(resolve(process.cwd(), path.toString())));
57
98
  return fs.readFileSync(path, options);
58
99
  },
59
100
  promises: {
60
101
  ...fs.promises,
61
102
  // @ts-expect-error - Node's fs.promises has too many overloads
62
103
  readFile: async (path, options) => {
63
- readFiles.add(resolve(process.cwd(), path.toString()));
104
+ readFiles.add(nodeNormalizePath(resolve(process.cwd(), path.toString())));
64
105
  return fs.promises.readFile(path, options);
65
106
  },
66
107
  },
@@ -1,6 +1,2 @@
1
- export declare const paraglideVitePlugin: (options: {
2
- project: string;
3
- outdir: string;
4
- options?: import("../compiler/compileProject.js").ParaglideCompilerOptions;
5
- }) => import("unplugin").VitePlugin<any> | import("unplugin").VitePlugin<any>[];
1
+ export declare const paraglideVitePlugin: (options: import("../index.js").CompilerOptions) => import("vite").Plugin<any> | import("vite").Plugin<any>[];
6
2
  //# sourceMappingURL=vite.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/vite.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB;;;;+EAAoC,CAAC"}
1
+ {"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/vite.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,+GAAoC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const paraglideWebpackPlugin: (options: import("../index.js").CompilerOptions) => WebpackPluginInstance;
2
+ //# sourceMappingURL=webpack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/webpack.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,sBAAsB,2EAAuC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { createWebpackPlugin } from "unplugin";
2
+ import { unpluginFactory } from "./unplugin.js";
3
+ export const paraglideWebpackPlugin = createWebpackPlugin(unpluginFactory);
@@ -1 +1 @@
1
- {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/compile/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AASpC,eAAO,MAAM,cAAc,SAoDzB,CAAC"}
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/compile/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAUpC,eAAO,MAAM,cAAc,SAkDzB,CAAC"}
@@ -1,38 +1,37 @@
1
1
  import { Command } from "commander";
2
- import fs from "node:fs";
3
2
  import { resolve } from "node:path";
4
3
  import { Logger } from "../../../services/logger/index.js";
5
- import { runCompiler } from "../../steps/run-compiler.js";
6
4
  import { DEFAULT_OUTDIR } from "../../defaults.js";
7
- import { loadProjectFromDirectory } from "@inlang/sdk";
8
- import { ENV_VARIABLES } from "../../../services/env-variables/index.js";
5
+ import { compile } from "../../../compiler/compile.js";
6
+ import { defaultCompilerOptions, } from "../../../compiler/compiler-options.js";
9
7
  export const compileCommand = new Command()
10
8
  .name("compile")
11
9
  .summary("Compiles inlang Paraglide-JS")
12
10
  .requiredOption("--project <path>", 'The path to the inlang project. Example: "./project.inlang"')
13
11
  .requiredOption("--outdir <path>", 'The path to the output directory. Example: "./src/paraglide"', DEFAULT_OUTDIR)
12
+ .option("--strategy <items...>", [
13
+ "The strategy to be used.",
14
+ "",
15
+ "Example: --strategy cookie globalVariable baseLocale",
16
+ "Read more on https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy",
17
+ ].join("\n"))
14
18
  .requiredOption("--silent", "Only log errors to the console", false)
15
19
  .action(async (options) => {
16
20
  const logger = new Logger({ silent: options.silent, prefix: true });
17
21
  const path = resolve(process.cwd(), options.project);
18
- logger.info(`Compiling inlang project at "${options.project}".`);
19
- const project = await loadProjectFromDirectory({
20
- path,
21
- fs,
22
- appId: ENV_VARIABLES.PARJS_APP_ID,
23
- });
24
- await runCompiler({
25
- project,
26
- fs: fs.promises,
27
- outdir: options.outdir,
28
- });
29
- logger.success("Successfully compiled the project.");
30
- const errors = await project.errors.get();
31
- if (errors.length > 0) {
32
- logger.warn(`But the project reported the following warnings and/or errors that might have influenced compilation:`);
33
- for (const error of errors) {
34
- logger.log(`${error}`);
35
- }
22
+ logger.info(`Compiling inlang project ...`);
23
+ try {
24
+ await compile({
25
+ project: path,
26
+ outdir: options.outdir,
27
+ strategy: options.strategy ?? defaultCompilerOptions.strategy,
28
+ });
36
29
  }
30
+ catch (e) {
31
+ logger.error("Error while compiling inlang project.");
32
+ logger.error(e);
33
+ process.exit(1);
34
+ }
35
+ logger.success(`Successfully compiled inlang project.`);
37
36
  process.exit(0);
38
37
  });
@@ -1 +1 @@
1
- {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/init/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAS3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAI9C,eAAO,MAAM,WAAW,SA0DrB,CAAC;AAEJ,eAAO,MAAM,+BAA+B,EAAE,OAAO,CACpD;IACC,EAAE,EAAE,cAAc,kBAAkB,CAAC,CAAC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;CACxB,EACD,OAAO,CAYP,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,OAAO,CAC7C;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,cAAc,kBAAkB,CAAC,CAAA;CAAE,EACzD;IAAE,eAAe,EAAE,MAAM,CAAA;CAAE,CAU3B,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,OAAO,CAChD;IACC,EAAE,EAAE,cAAc,kBAAkB,CAAC,CAAC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;CACxB,EACD,OAAO,CAuDP,CAAC"}
1
+ {"version":3,"file":"command.d.ts","sourceRoot":"","sources":["../../../../src/cli/commands/init/command.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,OAAO,EAAE,MAAM,EAAE,MAAM,mCAAmC,CAAC;AAQ3D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAO9C,eAAO,MAAM,WAAW,SAiErB,CAAC;AAEJ,eAAO,MAAM,+BAA+B,EAAE,OAAO,CACpD;IACC,EAAE,EAAE,cAAc,kBAAkB,CAAC,CAAC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;CACxB,EACD,OAAO,CAYP,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,OAAO,CAC7C;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,cAAc,kBAAkB,CAAC,CAAA;CAAE,EACzD;IAAE,eAAe,EAAE,MAAM,CAAA;CAAE,CAU3B,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,OAAO,CAChD;IACC,EAAE,EAAE,cAAc,kBAAkB,CAAC,CAAC;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,eAAe,EAAE,MAAM,CAAC;CACxB,EACD,OAAO,CAuDP,CAAC"}
@@ -6,18 +6,20 @@ import { findPackageJson } from "../../../services/environment/package.js";
6
6
  import { checkForUncommittedChanges } from "../../steps/check-for-uncomitted-changes.js";
7
7
  import { initializeInlangProject } from "../../steps/initialize-inlang-project.js";
8
8
  import { maybeAddSherlock } from "../../steps/maybe-add-sherlock.js";
9
- import { maybeChangeTsConfig } from "../../steps/update-ts-config.js";
9
+ import { maybeUpdateTsConfig } from "../../steps/update-ts-config.js";
10
10
  import { promptForOutdir } from "../../steps/prompt-for-outdir.js";
11
11
  import { updatePackageJson } from "../../steps/update-package-json.js";
12
- import { runCompiler } from "../../steps/run-compiler.js";
13
12
  import nodeFs from "node:fs";
14
13
  import { ENV_VARIABLES } from "../../../services/env-variables/index.js";
14
+ import { detectBundler } from "../../steps/detect-bundler.js";
15
+ import { addVitePlugin } from "../../steps/add-vite-plugin.js";
16
+ import { compile } from "../../../compiler/compile.js";
15
17
  export const initCommand = new Command()
16
18
  .name("init")
17
19
  .summary("Initializes inlang Paraglide-JS.")
18
20
  .action(async () => {
19
21
  const logger = new Logger({ silent: false, prefix: false });
20
- logger.box("Welcome to inlang Paraglide-JS 🪂");
22
+ logger.box("Welcome to inlang Paraglide JS 🪂");
21
23
  const ctx = {
22
24
  logger,
23
25
  fs: nodeFs.promises,
@@ -29,11 +31,20 @@ export const initCommand = new Command()
29
31
  const ctx3 = await initializeInlangProject(ctx2);
30
32
  const ctx4 = await promptForOutdir(ctx3);
31
33
  const ctx5 = await addParaglideJsToDevDependencies(ctx4);
32
- const ctx6 = await addCompileStepToPackageJSON(ctx5);
33
- const ctx7 = await maybeChangeTsConfig(ctx6);
34
+ const ctx6 = await detectBundler(ctx5);
35
+ if (ctx6.bundler === "vite") {
36
+ await addVitePlugin(ctx6);
37
+ }
38
+ else {
39
+ await addCompileStepToPackageJSON(ctx6);
40
+ }
41
+ const ctx7 = await maybeUpdateTsConfig(ctx6);
34
42
  const ctx8 = await maybeAddSherlock(ctx7);
35
43
  try {
36
- await runCompiler(ctx8);
44
+ await compile({
45
+ project: ctx8.projectPath,
46
+ outdir: ctx8.outdir,
47
+ });
37
48
  ctx.logger.success("Run paraglide compiler");
38
49
  }
39
50
  catch {
@@ -45,15 +56,15 @@ export const initCommand = new Command()
45
56
  `inlang Paraglide-JS has been set up sucessfully.`,
46
57
  "\n",
47
58
  `1. Run your install command (npm i, yarn install, etc)`,
48
- `2. Register all your languages in ${relativeSettingsFilePath}`,
49
- `3. Run the build script (npm run build, or similar.)`,
50
- `4. Done :) Happy paragliding 🪂`,
59
+ `2. Run the build script (npm run build, or similar.)`,
60
+ `3. Define the locales in ${relativeSettingsFilePath}`,
51
61
  "\n",
52
62
  "\n",
53
63
  `For questions and feedback, visit`,
54
64
  `https://github.com/opral/inlang-paraglide-js/issues`,
55
65
  ].join("\n");
56
66
  ctx.logger.box(successMessage);
67
+ process.exit(0);
57
68
  });
58
69
  export const addParaglideJsToDevDependencies = async (ctx) => {
59
70
  const ctx1 = await updatePackageJson({
@@ -5,7 +5,7 @@ export declare function getNewProjectTemplate(): {
5
5
  $schema: "https://inlang.com/schema/project-settings";
6
6
  baseLocale: string;
7
7
  locales: string[];
8
- modules: never[];
8
+ modules: string[];
9
9
  "plugin.inlang.messageFormat": {
10
10
  pathPattern: string;
11
11
  };
@@ -1 +1 @@
1
- {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/cli/defaults.ts"],"names":[],"mappings":"AAgBA;;GAEG;AACH,wBAAgB,qBAAqB;;;;;;;;EAapC;AAED,eAAO,MAAM,oBAAoB,qBAAqB,CAAC;AACvD,eAAO,MAAM,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../../src/cli/defaults.ts"],"names":[],"mappings":"AAmBA;;GAEG;AACH,wBAAgB,qBAAqB;;;;;;;;EAEpC;AAED,eAAO,MAAM,oBAAoB,qBAAqB,CAAC;AACvD,eAAO,MAAM,cAAc,oBAAoB,CAAC"}
@@ -5,8 +5,11 @@
5
5
  const defaultProjectSettings = {
6
6
  $schema: "https://inlang.com/schema/project-settings",
7
7
  baseLocale: "en",
8
- locales: ["en"],
9
- modules: [],
8
+ locales: ["en", "de"],
9
+ modules: [
10
+ "https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@3/dist/index.js",
11
+ "https://cdn.jsdelivr.net/npm/@inlang/plugin-m-function-matcher@1/dist/index.js",
12
+ ],
10
13
  "plugin.inlang.messageFormat": {
11
14
  pathPattern: "./messages/{locale}.json",
12
15
  },
@@ -15,14 +18,6 @@ const defaultProjectSettings = {
15
18
  * @returns A new copy of the default project template that is safe to mutate.
16
19
  */
17
20
  export function getNewProjectTemplate() {
18
- if (!("structuredClone" in globalThis)) {
19
- try {
20
- return JSON.parse(JSON.stringify(defaultProjectSettings));
21
- }
22
- catch {
23
- throw new Error("structuredClone is not supported in your Node Version. Please use version 17 or higher");
24
- }
25
- }
26
21
  return structuredClone(defaultProjectSettings);
27
22
  }
28
23
  export const DEFAULT_PROJECT_PATH = "./project.inlang";
@@ -1,12 +1,3 @@
1
1
  import { Command } from "commander";
2
- export { checkForUncommittedChanges } from "./steps/check-for-uncomitted-changes.js";
3
- export { initializeInlangProject } from "./steps/initialize-inlang-project.js";
4
- export { maybeAddSherlock } from "./steps/maybe-add-sherlock.js";
5
- export { maybeChangeTsConfig } from "./steps/update-ts-config.js";
6
- export { promptForOutdir } from "./steps/prompt-for-outdir.js";
7
- export { updatePackageJson } from "./steps/update-package-json.js";
8
- export { runCompiler } from "./steps/run-compiler.js";
9
2
  export declare const cli: Command;
10
- export * as Utils from "./utils.js";
11
- export * as Defaults from "./defaults.js";
12
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,eAAO,MAAM,GAAG,SAI8B,CAAC;AAE/C,OAAO,KAAK,KAAK,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,QAAQ,MAAM,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/cli/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,eAAO,MAAM,GAAG,SAK8B,CAAC"}
package/dist/cli/index.js CHANGED
@@ -1,17 +1,10 @@
1
1
  import { Command } from "commander";
2
2
  import { compileCommand } from "./commands/compile/command.js";
3
3
  import { ENV_VARIABLES } from "../services/env-variables/index.js";
4
- export { checkForUncommittedChanges } from "./steps/check-for-uncomitted-changes.js";
5
- export { initializeInlangProject } from "./steps/initialize-inlang-project.js";
6
- export { maybeAddSherlock } from "./steps/maybe-add-sherlock.js";
7
- export { maybeChangeTsConfig } from "./steps/update-ts-config.js";
8
- export { promptForOutdir } from "./steps/prompt-for-outdir.js";
9
- export { updatePackageJson } from "./steps/update-package-json.js";
10
- export { runCompiler } from "./steps/run-compiler.js";
4
+ import { initCommand } from "./commands/init/command.js";
11
5
  export const cli = new Command()
12
6
  .name("paraglide-js")
13
7
  .addCommand(compileCommand)
8
+ .addCommand(initCommand)
14
9
  .showHelpAfterError()
15
10
  .version(ENV_VARIABLES.PARJS_PACKAGE_VERSION);
16
- export * as Utils from "./utils.js";
17
- export * as Defaults from "./defaults.js";
@@ -0,0 +1,10 @@
1
+ import type { Logger } from "../../services/logger/index.js";
2
+ import type { CliStep } from "../utils.js";
3
+ export declare const addVitePlugin: CliStep<{
4
+ fs: typeof import("node:fs/promises");
5
+ projectPath: string;
6
+ outdir: string;
7
+ logger?: Logger;
8
+ configPath: string;
9
+ }, unknown>;
10
+ //# sourceMappingURL=add-vite-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"add-vite-plugin.d.ts","sourceRoot":"","sources":["../../../src/cli/steps/add-vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,eAAO,MAAM,aAAa,EAAE,OAAO,CAClC;IACC,EAAE,EAAE,cAAc,kBAAkB,CAAC,CAAC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;CACnB,EACD,OAAO,CAoCP,CAAC"}
@@ -0,0 +1,61 @@
1
+ export const addVitePlugin = async (ctx) => {
2
+ try {
3
+ const fileContent = await ctx.fs.readFile(ctx.configPath, {
4
+ encoding: "utf-8",
5
+ });
6
+ const result = updateViteConfig({
7
+ config: fileContent,
8
+ projectPath: ctx.projectPath,
9
+ outdir: ctx.outdir,
10
+ });
11
+ if (result.ok) {
12
+ await ctx.fs.writeFile(ctx.configPath, result.updated);
13
+ ctx.logger?.success("Added the Paraglide JS vite plugin to the vite config.");
14
+ }
15
+ else {
16
+ const msg = [
17
+ "Failed to add the Paraglide JS vite plugin in vite.config.js.",
18
+ "Reason: " + result.reason,
19
+ "",
20
+ "Please add the plugin manually.",
21
+ ].join("\n");
22
+ ctx.logger?.warn(msg);
23
+ return ctx;
24
+ }
25
+ }
26
+ catch {
27
+ ctx.logger?.error(`Failed to add the Paraglide JS vite plugin to ${ctx.configPath}.`);
28
+ process.exit(1);
29
+ }
30
+ return ctx;
31
+ };
32
+ /**
33
+ * @private Only exported for testings
34
+ */
35
+ function updateViteConfig(args) {
36
+ if (args.config.includes("@inlang/paraglide-js")) {
37
+ return {
38
+ ok: false,
39
+ reason: "Already present",
40
+ };
41
+ }
42
+ const PLUGINS_REGEX = /plugins\s*:\s*\[/g;
43
+ const match = PLUGINS_REGEX.exec(args.config);
44
+ if (!match) {
45
+ return {
46
+ ok: false,
47
+ reason: "Could not find the plugins array",
48
+ };
49
+ }
50
+ const endIndex = match.index + match[0].length;
51
+ const before = args.config.slice(0, endIndex);
52
+ const after = args.config.slice(endIndex);
53
+ const updatedConfig = "import { paraglideVitePlugin } from '@inlang/paraglide-js'\n" +
54
+ before +
55
+ `paraglideVitePlugin({ project: '${args.projectPath}', outdir: '${args.outdir}' }),` +
56
+ after;
57
+ return {
58
+ ok: true,
59
+ updated: updatedConfig,
60
+ };
61
+ }