@inlang/paraglide-js 2.0.0-beta.9 → 2.0.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 (314) hide show
  1. package/README.md +7 -56
  2. package/dist/bundler-plugins/esbuild.d.ts +2 -0
  3. package/dist/bundler-plugins/esbuild.d.ts.map +1 -0
  4. package/dist/bundler-plugins/esbuild.js +3 -0
  5. package/dist/bundler-plugins/index.d.ts +5 -1
  6. package/dist/bundler-plugins/index.d.ts.map +1 -1
  7. package/dist/bundler-plugins/index.js +5 -1
  8. package/dist/bundler-plugins/rolldown.d.ts +2 -0
  9. package/dist/bundler-plugins/rolldown.d.ts.map +1 -0
  10. package/dist/bundler-plugins/rolldown.js +3 -0
  11. package/dist/bundler-plugins/rollup.d.ts +1 -1
  12. package/dist/bundler-plugins/rollup.d.ts.map +1 -1
  13. package/dist/bundler-plugins/rspack.d.ts +2 -0
  14. package/dist/bundler-plugins/rspack.d.ts.map +1 -0
  15. package/dist/bundler-plugins/rspack.js +3 -0
  16. package/dist/bundler-plugins/unplugin.d.ts +2 -2
  17. package/dist/bundler-plugins/unplugin.d.ts.map +1 -1
  18. package/dist/bundler-plugins/unplugin.js +91 -28
  19. package/dist/bundler-plugins/vite.d.ts +1 -1
  20. package/dist/bundler-plugins/vite.d.ts.map +1 -1
  21. package/dist/bundler-plugins/webpack.d.ts +2 -0
  22. package/dist/bundler-plugins/webpack.d.ts.map +1 -0
  23. package/dist/bundler-plugins/webpack.js +3 -0
  24. package/dist/cli/commands/compile/command.d.ts.map +1 -1
  25. package/dist/cli/commands/compile/command.js +23 -24
  26. package/dist/cli/commands/init/command.d.ts +0 -20
  27. package/dist/cli/commands/init/command.d.ts.map +1 -1
  28. package/dist/cli/commands/init/command.js +18 -42
  29. package/dist/cli/defaults.js +2 -2
  30. package/dist/cli/index.d.ts +0 -9
  31. package/dist/cli/index.d.ts.map +1 -1
  32. package/dist/cli/index.js +0 -9
  33. package/dist/cli/steps/initialize-inlang-project.d.ts.map +1 -1
  34. package/dist/cli/steps/initialize-inlang-project.js +2 -3
  35. package/dist/cli/steps/maybe-add-machine-translation.d.ts +16 -0
  36. package/dist/cli/steps/maybe-add-machine-translation.d.ts.map +1 -0
  37. package/dist/cli/steps/maybe-add-machine-translation.js +48 -0
  38. package/dist/cli/steps/update-ts-config.d.ts +2 -2
  39. package/dist/cli/steps/update-ts-config.d.ts.map +1 -1
  40. package/dist/cli/steps/update-ts-config.js +100 -80
  41. package/dist/compiler/{compileBundle.d.ts → compile-bundle.d.ts} +2 -4
  42. package/dist/compiler/compile-bundle.d.ts.map +1 -0
  43. package/dist/compiler/compile-bundle.js +60 -0
  44. package/dist/compiler/compile-bundle.test.d.ts +2 -0
  45. package/dist/compiler/compile-bundle.test.d.ts.map +1 -0
  46. package/dist/compiler/compile-bundle.test.js +97 -0
  47. package/dist/compiler/compile-local-variable.d.ts +17 -0
  48. package/dist/compiler/compile-local-variable.d.ts.map +1 -0
  49. package/dist/compiler/compile-local-variable.js +38 -0
  50. package/dist/compiler/compile-local-variable.test.d.ts +2 -0
  51. package/dist/compiler/compile-local-variable.test.d.ts.map +1 -0
  52. package/dist/compiler/compile-local-variable.test.js +71 -0
  53. package/dist/compiler/compile-message.d.ts +8 -0
  54. package/dist/compiler/compile-message.d.ts.map +1 -0
  55. package/dist/compiler/compile-message.js +89 -0
  56. package/dist/compiler/compile-message.test.d.ts +2 -0
  57. package/dist/compiler/compile-message.test.d.ts.map +1 -0
  58. package/dist/compiler/compile-message.test.js +308 -0
  59. package/dist/compiler/compile-pattern.d.ts +20 -0
  60. package/dist/compiler/compile-pattern.d.ts.map +1 -0
  61. package/dist/compiler/compile-pattern.js +40 -0
  62. package/dist/compiler/compile-pattern.test.d.ts +2 -0
  63. package/dist/compiler/compile-pattern.test.d.ts.map +1 -0
  64. package/dist/compiler/compile-pattern.test.js +75 -0
  65. package/dist/compiler/compile-project.d.ts +18 -0
  66. package/dist/compiler/compile-project.d.ts.map +1 -0
  67. package/dist/compiler/compile-project.js +92 -0
  68. package/dist/compiler/compile-project.test.d.ts +2 -0
  69. package/dist/compiler/compile-project.test.d.ts.map +1 -0
  70. package/dist/compiler/{compileProject.test.js → compile-project.test.js} +380 -102
  71. package/dist/compiler/compile.d.ts +6 -27
  72. package/dist/compiler/compile.d.ts.map +1 -1
  73. package/dist/compiler/compile.js +53 -23
  74. package/dist/compiler/compile.test.js +156 -1
  75. package/dist/compiler/compiler-options.d.ts +232 -0
  76. package/dist/compiler/compiler-options.d.ts.map +1 -0
  77. package/dist/compiler/compiler-options.js +13 -0
  78. package/dist/compiler/create-paraglide.d.ts +37 -0
  79. package/dist/compiler/create-paraglide.d.ts.map +1 -0
  80. package/dist/compiler/create-paraglide.js +97 -0
  81. package/dist/compiler/create-paraglide.test.d.ts +2 -0
  82. package/dist/compiler/create-paraglide.test.d.ts.map +1 -0
  83. package/dist/compiler/create-paraglide.test.js +75 -0
  84. package/dist/compiler/index.d.ts +9 -6
  85. package/dist/compiler/index.d.ts.map +1 -1
  86. package/dist/compiler/index.js +6 -4
  87. package/dist/compiler/jsdoc-types.d.ts +9 -3
  88. package/dist/compiler/jsdoc-types.d.ts.map +1 -1
  89. package/dist/compiler/jsdoc-types.js +16 -13
  90. package/dist/compiler/output-structure/locale-modules.d.ts +3 -2
  91. package/dist/compiler/output-structure/locale-modules.d.ts.map +1 -1
  92. package/dist/compiler/output-structure/locale-modules.js +21 -26
  93. package/dist/compiler/output-structure/locale-modules.test.js +3 -9
  94. package/dist/compiler/output-structure/message-modules.d.ts +3 -2
  95. package/dist/compiler/output-structure/message-modules.d.ts.map +1 -1
  96. package/dist/compiler/output-structure/message-modules.js +60 -49
  97. package/dist/compiler/output-structure/message-modules.test.js +44 -7
  98. package/dist/compiler/registry.d.ts +11 -11
  99. package/dist/compiler/registry.d.ts.map +1 -1
  100. package/dist/compiler/registry.js +24 -66
  101. package/dist/compiler/runtime/assert-is-locale.d.ts +9 -0
  102. package/dist/compiler/runtime/assert-is-locale.d.ts.map +1 -0
  103. package/dist/compiler/runtime/assert-is-locale.js +15 -0
  104. package/dist/compiler/runtime/assert-is-locale.test.d.ts +2 -0
  105. package/dist/compiler/runtime/assert-is-locale.test.d.ts.map +1 -0
  106. package/dist/compiler/runtime/assert-is-locale.test.js +39 -0
  107. package/dist/compiler/runtime/create-runtime.d.ts +18 -0
  108. package/dist/compiler/runtime/create-runtime.d.ts.map +1 -0
  109. package/dist/compiler/runtime/create-runtime.js +103 -0
  110. package/dist/compiler/runtime/extract-locale-from-cookie.d.ts +10 -0
  111. package/dist/compiler/runtime/extract-locale-from-cookie.d.ts.map +1 -0
  112. package/dist/compiler/runtime/extract-locale-from-cookie.js +21 -0
  113. package/dist/compiler/runtime/extract-locale-from-cookie.test.d.ts +2 -0
  114. package/dist/compiler/runtime/extract-locale-from-cookie.test.d.ts.map +1 -0
  115. package/dist/compiler/runtime/extract-locale-from-cookie.test.js +58 -0
  116. package/dist/compiler/runtime/extract-locale-from-request.d.ts +17 -0
  117. package/dist/compiler/runtime/extract-locale-from-request.d.ts.map +1 -0
  118. package/dist/compiler/runtime/extract-locale-from-request.js +91 -0
  119. package/dist/compiler/runtime/extract-locale-from-request.test.d.ts +2 -0
  120. package/dist/compiler/runtime/extract-locale-from-request.test.d.ts.map +1 -0
  121. package/dist/compiler/runtime/extract-locale-from-request.test.js +260 -0
  122. package/dist/compiler/runtime/extract-locale-from-url.d.ts +8 -0
  123. package/dist/compiler/runtime/extract-locale-from-url.d.ts.map +1 -0
  124. package/dist/compiler/runtime/extract-locale-from-url.js +47 -0
  125. package/dist/compiler/runtime/extract-locale-from-url.test.d.ts +2 -0
  126. package/dist/compiler/runtime/extract-locale-from-url.test.d.ts.map +1 -0
  127. package/dist/compiler/runtime/extract-locale-from-url.test.js +137 -0
  128. package/dist/compiler/runtime/generate-static-localized-urls.d.ts +24 -0
  129. package/dist/compiler/runtime/generate-static-localized-urls.d.ts.map +1 -0
  130. package/dist/compiler/runtime/generate-static-localized-urls.js +91 -0
  131. package/dist/compiler/runtime/generate-static-localized-urls.test.d.ts +2 -0
  132. package/dist/compiler/runtime/generate-static-localized-urls.test.d.ts.map +1 -0
  133. package/dist/compiler/runtime/generate-static-localized-urls.test.js +190 -0
  134. package/dist/compiler/runtime/get-locale.d.ts +30 -0
  135. package/dist/compiler/runtime/get-locale.d.ts.map +1 -0
  136. package/dist/compiler/runtime/get-locale.js +120 -0
  137. package/dist/compiler/runtime/get-locale.test.d.ts +2 -0
  138. package/dist/compiler/runtime/get-locale.test.d.ts.map +1 -0
  139. package/dist/compiler/runtime/get-locale.test.js +200 -0
  140. package/dist/compiler/runtime/get-url-origin.d.ts +20 -0
  141. package/dist/compiler/runtime/get-url-origin.d.ts.map +1 -0
  142. package/dist/compiler/runtime/get-url-origin.js +30 -0
  143. package/dist/compiler/runtime/get-url-origin.test.d.ts +2 -0
  144. package/dist/compiler/runtime/get-url-origin.test.d.ts.map +1 -0
  145. package/dist/compiler/runtime/get-url-origin.test.js +28 -0
  146. package/dist/compiler/runtime/is-locale.d.ts +15 -0
  147. package/dist/compiler/runtime/is-locale.d.ts.map +1 -0
  148. package/dist/compiler/runtime/is-locale.js +17 -0
  149. package/dist/compiler/runtime/localize-href.d.ts +82 -0
  150. package/dist/compiler/runtime/localize-href.d.ts.map +1 -0
  151. package/dist/compiler/runtime/localize-href.js +108 -0
  152. package/dist/compiler/runtime/localize-href.test.d.ts +2 -0
  153. package/dist/compiler/runtime/localize-href.test.d.ts.map +1 -0
  154. package/dist/compiler/runtime/localize-href.test.js +160 -0
  155. package/dist/compiler/runtime/localize-url.d.ts +85 -0
  156. package/dist/compiler/runtime/localize-url.d.ts.map +1 -0
  157. package/dist/compiler/runtime/localize-url.js +311 -0
  158. package/dist/compiler/runtime/localize-url.test.d.ts +2 -0
  159. package/dist/compiler/runtime/localize-url.test.d.ts.map +1 -0
  160. package/dist/compiler/runtime/localize-url.test.js +617 -0
  161. package/dist/compiler/runtime/set-locale.d.ts +21 -0
  162. package/dist/compiler/runtime/set-locale.d.ts.map +1 -0
  163. package/dist/compiler/runtime/set-locale.js +107 -0
  164. package/dist/compiler/runtime/set-locale.test.d.ts +2 -0
  165. package/dist/compiler/runtime/set-locale.test.d.ts.map +1 -0
  166. package/dist/compiler/runtime/set-locale.test.js +215 -0
  167. package/dist/compiler/runtime/track-message-call.d.ts +6 -0
  168. package/dist/compiler/runtime/track-message-call.d.ts.map +1 -0
  169. package/dist/compiler/runtime/track-message-call.js +13 -0
  170. package/dist/compiler/runtime/track-message-call.test.d.ts +2 -0
  171. package/dist/compiler/runtime/track-message-call.test.d.ts.map +1 -0
  172. package/dist/compiler/runtime/track-message-call.test.js +26 -0
  173. package/dist/compiler/runtime/type.d.ts +33 -0
  174. package/dist/compiler/runtime/type.d.ts.map +1 -0
  175. package/dist/compiler/runtime/type.test.d.ts +2 -0
  176. package/dist/compiler/runtime/type.test.d.ts.map +1 -0
  177. package/dist/compiler/runtime/type.test.js +91 -0
  178. package/dist/compiler/runtime/variables.d.ts +88 -0
  179. package/dist/compiler/runtime/variables.d.ts.map +1 -0
  180. package/dist/compiler/runtime/variables.js +74 -0
  181. package/dist/compiler/safe-module-id.d.ts +8 -0
  182. package/dist/compiler/safe-module-id.d.ts.map +1 -0
  183. package/dist/{services/valid-js-identifier/reservedWords.js → compiler/safe-module-id.js} +22 -1
  184. package/dist/compiler/safe-module-id.test.d.ts +2 -0
  185. package/dist/compiler/safe-module-id.test.d.ts.map +1 -0
  186. package/dist/compiler/safe-module-id.test.js +30 -0
  187. package/dist/compiler/server/create-server-file.d.ts +12 -0
  188. package/dist/compiler/server/create-server-file.d.ts.map +1 -0
  189. package/dist/compiler/server/create-server-file.js +47 -0
  190. package/dist/compiler/server/middleware.d.ts +66 -0
  191. package/dist/compiler/server/middleware.d.ts.map +1 -0
  192. package/dist/compiler/server/middleware.js +185 -0
  193. package/dist/compiler/server/middleware.test.d.ts +2 -0
  194. package/dist/compiler/server/middleware.test.d.ts.map +1 -0
  195. package/dist/compiler/server/middleware.test.js +435 -0
  196. package/dist/compiler/server/type.d.ts +7 -0
  197. package/dist/compiler/server/type.d.ts.map +1 -0
  198. package/dist/compiler/server/type.js +1 -0
  199. package/dist/compiler/types.d.ts +6 -8
  200. package/dist/compiler/types.d.ts.map +1 -1
  201. package/dist/compiler/types.js +1 -28
  202. package/dist/services/env-variables/create-index-file.d.ts +2 -0
  203. package/dist/services/env-variables/create-index-file.d.ts.map +1 -0
  204. package/dist/services/env-variables/create-index-file.js +29 -0
  205. package/dist/services/env-variables/index.js +1 -1
  206. package/dist/services/file-handling/write-output.d.ts +7 -1
  207. package/dist/services/file-handling/write-output.d.ts.map +1 -1
  208. package/dist/services/file-handling/write-output.js +103 -21
  209. package/dist/services/file-handling/write-output.test.js +126 -16
  210. package/dist/services/logger/index.d.ts.map +1 -1
  211. package/dist/services/logger/index.js +11 -5
  212. package/dist/services/telemetry/capture.d.ts +1 -2
  213. package/dist/services/telemetry/capture.d.ts.map +1 -1
  214. package/dist/services/telemetry/stack-detection.d.ts +1 -1
  215. package/dist/services/telemetry/stack-detection.d.ts.map +1 -1
  216. package/dist/services/telemetry/stack-detection.js +3 -8
  217. package/dist/services/telemetry/stack-detection.test.js +9 -12
  218. package/dist/urlpattern-polyfill/index.d.ts +2 -0
  219. package/dist/urlpattern-polyfill/index.d.ts.map +1 -0
  220. package/dist/urlpattern-polyfill/index.js +1 -0
  221. package/dist/utilities/node-normalize-path.d.ts +2 -0
  222. package/dist/utilities/node-normalize-path.d.ts.map +1 -0
  223. package/dist/utilities/node-normalize-path.js +9 -0
  224. package/package.json +21 -29
  225. package/dist/adapter-utils/index.d.ts +0 -6
  226. package/dist/adapter-utils/index.d.ts.map +0 -1
  227. package/dist/adapter-utils/index.js +0 -5
  228. package/dist/adapter-utils/negotiation/language.d.ts +0 -10
  229. package/dist/adapter-utils/negotiation/language.d.ts.map +0 -1
  230. package/dist/adapter-utils/negotiation/language.js +0 -137
  231. package/dist/adapter-utils/negotiation/language.test.d.ts +0 -2
  232. package/dist/adapter-utils/negotiation/language.test.d.ts.map +0 -1
  233. package/dist/adapter-utils/negotiation/language.test.js +0 -24
  234. package/dist/adapter-utils/routing/detectLanguage.d.ts +0 -25
  235. package/dist/adapter-utils/routing/detectLanguage.d.ts.map +0 -1
  236. package/dist/adapter-utils/routing/detectLanguage.js +0 -32
  237. package/dist/adapter-utils/routing/detectLanguage.test.d.ts +0 -2
  238. package/dist/adapter-utils/routing/detectLanguage.test.d.ts.map +0 -1
  239. package/dist/adapter-utils/routing/detectLanguage.test.js +0 -37
  240. package/dist/adapter-utils/routing/resolveUserPathDefinition.test.d.ts +0 -2
  241. package/dist/adapter-utils/routing/resolveUserPathDefinition.test.d.ts.map +0 -1
  242. package/dist/adapter-utils/routing/resolveUserPathDefinition.test.js +0 -35
  243. package/dist/adapter-utils/routing/resolveUserPathDefinitions.d.ts +0 -40
  244. package/dist/adapter-utils/routing/resolveUserPathDefinitions.d.ts.map +0 -1
  245. package/dist/adapter-utils/routing/resolveUserPathDefinitions.js +0 -19
  246. package/dist/adapter-utils/routing/routeDefinitions.d.ts +0 -48
  247. package/dist/adapter-utils/routing/routeDefinitions.d.ts.map +0 -1
  248. package/dist/adapter-utils/routing/routeDefinitions.js +0 -224
  249. package/dist/adapter-utils/routing/routeDefinitions.test.d.ts +0 -2
  250. package/dist/adapter-utils/routing/routeDefinitions.test.d.ts.map +0 -1
  251. package/dist/adapter-utils/routing/routeDefinitions.test.js +0 -234
  252. package/dist/adapter-utils/routing/sortRoutes.d.ts +0 -2
  253. package/dist/adapter-utils/routing/sortRoutes.d.ts.map +0 -1
  254. package/dist/adapter-utils/routing/sortRoutes.js +0 -135
  255. package/dist/adapter-utils/routing/validatePathTranslations.d.ts +0 -15
  256. package/dist/adapter-utils/routing/validatePathTranslations.d.ts.map +0 -1
  257. package/dist/adapter-utils/routing/validatePathTranslations.js +0 -98
  258. package/dist/adapter-utils/routing/validatePathTranslations.test.d.ts +0 -2
  259. package/dist/adapter-utils/routing/validatePathTranslations.test.d.ts.map +0 -1
  260. package/dist/adapter-utils/routing/validatePathTranslations.test.js +0 -121
  261. package/dist/cli/steps/run-compiler.d.ts +0 -9
  262. package/dist/cli/steps/run-compiler.d.ts.map +0 -1
  263. package/dist/cli/steps/run-compiler.js +0 -13
  264. package/dist/compiler/compileBundle.d.ts.map +0 -1
  265. package/dist/compiler/compileBundle.js +0 -81
  266. package/dist/compiler/compileBundle.test.d.ts +0 -2
  267. package/dist/compiler/compileBundle.test.d.ts.map +0 -1
  268. package/dist/compiler/compileBundle.test.js +0 -57
  269. package/dist/compiler/compileExpression.d.ts +0 -5
  270. package/dist/compiler/compileExpression.d.ts.map +0 -1
  271. package/dist/compiler/compileExpression.js +0 -41
  272. package/dist/compiler/compileMessage.d.ts +0 -12
  273. package/dist/compiler/compileMessage.d.ts.map +0 -1
  274. package/dist/compiler/compileMessage.js +0 -64
  275. package/dist/compiler/compileMessage.test.d.ts +0 -2
  276. package/dist/compiler/compileMessage.test.d.ts.map +0 -1
  277. package/dist/compiler/compileMessage.test.js +0 -74
  278. package/dist/compiler/compilePattern.d.ts +0 -12
  279. package/dist/compiler/compilePattern.d.ts.map +0 -1
  280. package/dist/compiler/compilePattern.js +0 -28
  281. package/dist/compiler/compilePattern.test.d.ts +0 -2
  282. package/dist/compiler/compilePattern.test.d.ts.map +0 -1
  283. package/dist/compiler/compilePattern.test.js +0 -67
  284. package/dist/compiler/compileProject.d.ts +0 -61
  285. package/dist/compiler/compileProject.d.ts.map +0 -1
  286. package/dist/compiler/compileProject.js +0 -77
  287. package/dist/compiler/compileProject.test.d.ts +0 -2
  288. package/dist/compiler/compileProject.test.d.ts.map +0 -1
  289. package/dist/compiler/emit-dts.d.ts +0 -7
  290. package/dist/compiler/emit-dts.d.ts.map +0 -1
  291. package/dist/compiler/emit-dts.js +0 -56
  292. package/dist/compiler/jsDocComment.d.ts +0 -9
  293. package/dist/compiler/jsDocComment.d.ts.map +0 -1
  294. package/dist/compiler/jsDocComment.js +0 -30
  295. package/dist/compiler/runtime.d.ts +0 -6
  296. package/dist/compiler/runtime.d.ts.map +0 -1
  297. package/dist/compiler/runtime.js +0 -257
  298. package/dist/services/codegen/identifier.d.ts +0 -6
  299. package/dist/services/codegen/identifier.d.ts.map +0 -1
  300. package/dist/services/codegen/identifier.js +0 -11
  301. package/dist/services/codegen/indentifier.test.d.ts +0 -2
  302. package/dist/services/codegen/indentifier.test.d.ts.map +0 -1
  303. package/dist/services/codegen/indentifier.test.js +0 -8
  304. package/dist/services/telemetry/events.d.ts +0 -7
  305. package/dist/services/telemetry/events.d.ts.map +0 -1
  306. package/dist/services/valid-js-identifier/index.d.ts +0 -6
  307. package/dist/services/valid-js-identifier/index.d.ts.map +0 -1
  308. package/dist/services/valid-js-identifier/index.js +0 -24
  309. package/dist/services/valid-js-identifier/index.test.d.ts +0 -2
  310. package/dist/services/valid-js-identifier/index.test.d.ts.map +0 -1
  311. package/dist/services/valid-js-identifier/index.test.js +0 -30
  312. package/dist/services/valid-js-identifier/reservedWords.d.ts +0 -2
  313. package/dist/services/valid-js-identifier/reservedWords.d.ts.map +0 -1
  314. /package/dist/{services/telemetry/events.js → compiler/runtime/type.js} +0 -0
package/README.md CHANGED
@@ -1,63 +1,14 @@
1
1
  [![Inlang-ecosystem compatibility badge](https://cdn.jsdelivr.net/gh/opral/monorepo@main/inlang/assets/md-badges/inlang.svg)](https://inlang.com)
2
2
 
3
- # Getting started
3
+ [![NPM Downloads](https://img.shields.io/npm/dw/%40inlang%2Fparaglide-js?logo=npm&logoColor=red&label=npm%20downloads)](https://www.npmjs.com/package/@inlang/paraglide-js)
4
+ [![Closed github issues](https://img.shields.io/github/issues-closed/opral/paraglide-js?logo=github&color=purple)](https://github.com/opral/inlang-paraglide-js/issues)
5
+ [![Monorepo contributors](https://img.shields.io/github/contributors/opral/monorepo?logo=github)](https://github.com/opral/monorepo/graphs/contributors)
4
6
 
5
- To auto setup Paraglide JS, run the following command:
6
7
 
7
- ```bash
8
- npx @inlang/paraglide-js@latest init
9
- ```
8
+ A compiler-based i18n library that emits tree-shakable message functions. This means that only the messages you actually use are loaded without asynchronous waterfalls.
10
9
 
11
- This will:
10
+ Visit https://inlang.com/m/gerre34r/library-inlang-paraglideJs to learn more.
12
11
 
13
- - Create an [inlang project](https://inlang.com/documentation/concept/project)
14
- - Install necessary dependencies
15
- - Generate a `messages/` folder where your translation files live
12
+ ## Contributing
16
13
 
17
- ## Adding and editing Messages
18
-
19
- Messages are stored in `messages/{locale}.json` as key-value pairs. You can add parameters with curly braces.
20
-
21
- ```diff
22
- // messages/en.json
23
- {
24
- + "greeting": "Hello {name}!"
25
- }
26
- ```
27
-
28
- Run the compiler via the CLI to generate the message functions.
29
-
30
- ```bash
31
- npx @inlang/paraglide-js compile --project ./project.inlang --outdir ./src/paraglide
32
- ```
33
-
34
- _If you are using a Bundler use one of the [Bundler Plugins](usage#usage-with-a-bundler) to recompile automatically._
35
-
36
- ## Using messages in code
37
-
38
- After running the compiler import the messages with `import * as m from "./paraglide/messages"`. By convention, a wildcard import is used.
39
-
40
- ```js
41
- import * as m from "./paraglide/messages.js";
42
-
43
- m.greeting({ name: "Samuel" }); // Hello Samuel!
44
- ```
45
-
46
- ## Changing the locale
47
-
48
- To change the locale, use the `setLocale` function.
49
-
50
- ```js
51
- import { setLocale } from "./paraglide/runtime.js";
52
- import * as m from "./paraglide/messages.js";
53
-
54
- m.greeting({ name: "Samuel" }); // Hello Samuel!
55
-
56
- setLocale("de");
57
-
58
- m.greeting({ name: "Samuel" }); // Guten Tag Samuel!
59
- ```
60
-
61
- ## Define your strategy
62
-
63
- In the last step, you need to define what strategy you want to use to resolve the locale. Visit the [strategy documentation](https://inlang.com/m/gerre34r/library-inlang-paraglideJs/strategy) to learn more.
14
+ Read the [CONTRIBUTING.md](https://github.com/opral/monorepo/blob/main/inlang/packages/paraglide/paraglide-js/CONTRIBUTING.md) file to learn more on how to contribute.
@@ -0,0 +1,2 @@
1
+ export declare const paraglideEsbuildPlugin: (options: import("../index.js").CompilerOptions) => import("unplugin").EsbuildPlugin;
2
+ //# sourceMappingURL=esbuild.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"esbuild.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/esbuild.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,sBAAsB,sFAAuC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { createEsbuildPlugin } from "unplugin";
2
+ import { unpluginFactory } from "./unplugin.js";
3
+ export const paraglideEsbuildPlugin = createEsbuildPlugin(unpluginFactory);
@@ -1,3 +1,7 @@
1
- export { paraglideVitePlugin } from "./vite.js";
1
+ export { paraglideEsbuildPlugin } from "./esbuild.js";
2
+ export { paraglideRolldownPlugin } from "./rolldown.js";
2
3
  export { paraglideRollupPlugin } from "./rollup.js";
4
+ export { paraglideRspackPlugin } from "./rspack.js";
5
+ export { paraglideVitePlugin } from "./vite.js";
6
+ export { paraglideWebpackPlugin } from "./webpack.js";
3
7
  //# 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,sBAAsB,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,eAAe,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC"}
@@ -1,2 +1,6 @@
1
- export { paraglideVitePlugin } from "./vite.js";
1
+ export { paraglideEsbuildPlugin } from "./esbuild.js";
2
+ export { paraglideRolldownPlugin } from "./rolldown.js";
2
3
  export { paraglideRollupPlugin } from "./rollup.js";
4
+ export { paraglideRspackPlugin } from "./rspack.js";
5
+ export { paraglideVitePlugin } from "./vite.js";
6
+ export { paraglideWebpackPlugin } from "./webpack.js";
@@ -0,0 +1,2 @@
1
+ export declare const paraglideRolldownPlugin: (options: import("../index.js").CompilerOptions) => import("unplugin").RolldownPlugin<any> | import("unplugin").RolldownPlugin<any>[];
2
+ //# sourceMappingURL=rolldown.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rolldown.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/rolldown.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,uBAAuB,uIAAwC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { createRolldownPlugin } from "unplugin";
2
+ import { unpluginFactory } from "./unplugin.js";
3
+ export const paraglideRolldownPlugin = createRolldownPlugin(unpluginFactory);
@@ -1,2 +1,2 @@
1
- export declare const paraglideRollupPlugin: (options: import("../index.js").CompilerArgs) => import("unplugin").RollupPlugin<any> | import("unplugin").RollupPlugin<any>[];
1
+ export declare const paraglideRollupPlugin: (options: import("../index.js").CompilerOptions) => import("unplugin").RollupPlugin<any> | import("unplugin").RollupPlugin<any>[];
2
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,gIAAsC,CAAC"}
1
+ {"version":3,"file":"rollup.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/rollup.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB,mIAAsC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const paraglideRspackPlugin: (options: import("../index.js").CompilerOptions) => RspackPluginInstance;
2
+ //# sourceMappingURL=rspack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rspack.d.ts","sourceRoot":"","sources":["../../src/bundler-plugins/rspack.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB,0EAAsC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { createRspackPlugin } from "unplugin";
2
+ import { unpluginFactory } from "./unplugin.js";
3
+ export const paraglideRspackPlugin = createRspackPlugin(unpluginFactory);
@@ -1,4 +1,4 @@
1
1
  import type { UnpluginFactory } from "unplugin";
2
- import { type CompilerArgs } from "../compiler/compile.js";
3
- export declare const unpluginFactory: UnpluginFactory<CompilerArgs>;
2
+ import type { CompilerOptions } from "../compiler/compiler-options.js";
3
+ export declare const unpluginFactory: UnpluginFactory<CompilerOptions>;
4
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,EAAW,KAAK,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAMpE,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,YAAY,CAwCxD,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;AAavE,eAAO,MAAM,eAAe,EAAE,eAAe,CAAC,eAAe,CAmG3D,CAAC"}
@@ -1,66 +1,129 @@
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
+ /**
9
+ * Default isServer which differs per bundler.
10
+ */
11
+ let isServer;
12
+ let previousCompilation;
5
13
  export const unpluginFactory = (args) => ({
6
14
  name: PLUGIN_NAME,
7
15
  enforce: "pre",
8
16
  async buildStart() {
9
- console.log("Paraglide JS: Compiling inlang project...");
10
- await compile({
11
- project: args.project,
12
- outdir: args.outdir,
13
- compilerOptions: args.compilerOptions,
14
- fs: wrappedFs,
15
- });
16
- for (const path of Array.from(readFiles)) {
17
- this.addWatchFile(path);
17
+ logger.info("Compiling inlang project...");
18
+ try {
19
+ previousCompilation = await compile({
20
+ fs: wrappedFs,
21
+ previousCompilation,
22
+ // webpack invokes the `buildStart` api in watch mode,
23
+ // to avoid cleaning the output directory in watch mode,
24
+ // we only clean the output directory if there was no previous compilation
25
+ cleanOutdir: previousCompilation === undefined,
26
+ isServer,
27
+ ...args,
28
+ });
29
+ logger.success("Compilation complete");
30
+ }
31
+ catch (error) {
32
+ logger.error("Failed to compile project:", error.message);
33
+ logger.info("Please check your translation files for syntax errors.");
34
+ }
35
+ finally {
36
+ // in any case add the files to watch
37
+ for (const path of Array.from(readFiles)) {
38
+ this.addWatchFile(path);
39
+ }
18
40
  }
19
41
  },
20
42
  async watchChange(path) {
21
- if (readFiles.has(path)) {
22
- console.log(`Paraglide JS: Recompiling inlang project...`);
43
+ const shouldCompile = readFiles.has(path) && !path.includes("cache");
44
+ if (shouldCompile === false) {
45
+ return;
46
+ }
47
+ const previouslyReadFiles = new Set(readFiles);
48
+ try {
49
+ logger.info(`Re-compiling inlang project... File "${relative(process.cwd(), path)}" has changed.`);
50
+ // Clear readFiles to track fresh file reads
23
51
  readFiles.clear();
24
- await compile({
25
- project: args.project,
26
- outdir: args.outdir,
27
- compilerOptions: args.compilerOptions,
52
+ previousCompilation = await compile({
28
53
  fs: wrappedFs,
54
+ previousCompilation,
55
+ cleanOutdir: false,
56
+ isServer,
57
+ ...args,
29
58
  });
59
+ logger.success("Re-compilation complete");
60
+ // Add any new files to watch
61
+ for (const filePath of Array.from(readFiles)) {
62
+ this.addWatchFile(filePath);
63
+ }
30
64
  }
65
+ catch (e) {
66
+ readFiles = previouslyReadFiles;
67
+ // Reset compilation result on error
68
+ previousCompilation = undefined;
69
+ logger.warn("Failed to re-compile project:", e.message);
70
+ }
71
+ },
72
+ vite: {
73
+ config: {
74
+ handler: () => {
75
+ isServer = "import.meta.env?.SSR ?? typeof window === 'undefined'";
76
+ },
77
+ },
31
78
  },
32
79
  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
80
+ compiler.options.resolve = {
81
+ ...compiler.options.resolve,
82
+ fallback: {
83
+ ...compiler.options.resolve?.fallback,
84
+ // https://stackoverflow.com/a/72989932
85
+ async_hooks: false,
86
+ },
87
+ };
35
88
  compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, async () => {
36
- await compile({
37
- project: args.project,
38
- outdir: args.outdir,
39
- compilerOptions: args.compilerOptions,
40
- fs: wrappedFs,
41
- });
89
+ try {
90
+ previousCompilation = await compile({
91
+ fs: wrappedFs,
92
+ previousCompilation,
93
+ // clean dir needs to be false. otherwise webpack get's into a race condition
94
+ // of deleting the output directory and writing files at the same time for
95
+ // multi environment builds
96
+ cleanOutdir: false,
97
+ ...args,
98
+ });
99
+ logger.success("Compilation complete");
100
+ }
101
+ catch (error) {
102
+ logger.warn("Failed to compile project:", error.message);
103
+ logger.warn("Please check your translation files for syntax errors.");
104
+ }
42
105
  });
43
106
  },
44
107
  });
45
- const readFiles = new Set();
108
+ let readFiles = new Set();
46
109
  // Create a wrapper around the fs object to intercept and store read files
47
110
  const wrappedFs = {
48
111
  ...fs,
49
112
  // @ts-expect-error - Node's fs has too many overloads
50
113
  readFile: (path, options, callback) => {
51
- readFiles.add(resolve(process.cwd(), path.toString()));
114
+ readFiles.add(nodeNormalizePath(resolve(process.cwd(), path.toString())));
52
115
  return fs.readFile(path, options, callback);
53
116
  },
54
117
  // @ts-expect-error - Node's fs has too many overloads
55
118
  readFileSync: (path, options) => {
56
- readFiles.add(resolve(process.cwd(), path.toString()));
119
+ readFiles.add(nodeNormalizePath(resolve(process.cwd(), path.toString())));
57
120
  return fs.readFileSync(path, options);
58
121
  },
59
122
  promises: {
60
123
  ...fs.promises,
61
124
  // @ts-expect-error - Node's fs.promises has too many overloads
62
125
  readFile: async (path, options) => {
63
- readFiles.add(resolve(process.cwd(), path.toString()));
126
+ readFiles.add(nodeNormalizePath(resolve(process.cwd(), path.toString())));
64
127
  return fs.promises.readFile(path, options);
65
128
  },
66
129
  },
@@ -1,2 +1,2 @@
1
- export declare const paraglideVitePlugin: (options: import("../index.js").CompilerArgs) => import("vite").Plugin<any> | import("vite").Plugin<any>[];
1
+ export declare const paraglideVitePlugin: (options: import("../index.js").CompilerOptions) => import("vite").Plugin<any> | import("vite").Plugin<any>[];
2
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,4GAAoC,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) => import("unplugin").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,8FAAuC,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,SAmDzB,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
- import { DEFAULT_OUTDIR } from "../../defaults.js";
7
- import { loadProjectFromDirectory } from "@inlang/sdk";
8
- import { ENV_VARIABLES } from "../../../services/env-variables/index.js";
4
+ import { DEFAULT_OUTDIR, DEFAULT_PROJECT_PATH } from "../../defaults.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
- .requiredOption("--project <path>", 'The path to the inlang project. Example: "./project.inlang"')
10
+ .requiredOption("--project <path>", 'The path to the inlang project. Example: "./project.inlang"', DEFAULT_PROJECT_PATH)
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.error(`${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,23 +1,3 @@
1
1
  import { Command } from "commander";
2
- import { Logger } from "../../../services/logger/index.js";
3
- import type { CliStep } from "../../utils.js";
4
2
  export declare const initCommand: Command;
5
- export declare const addParaglideJsToDevDependencies: CliStep<{
6
- fs: typeof import("node:fs/promises");
7
- logger: Logger;
8
- packageJsonPath: string;
9
- }, unknown>;
10
- export declare const enforcePackageJsonExists: CliStep<{
11
- logger: Logger;
12
- fs: typeof import("node:fs/promises");
13
- }, {
14
- packageJsonPath: string;
15
- }>;
16
- export declare const addCompileStepToPackageJSON: CliStep<{
17
- fs: typeof import("node:fs/promises");
18
- logger: Logger;
19
- projectPath: string;
20
- outdir: string;
21
- packageJsonPath: string;
22
- }, unknown>;
23
3
  //# sourceMappingURL=command.d.ts.map
@@ -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;AAM9C,eAAO,MAAM,WAAW,SA8DrB,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;AAkBpC,eAAO,MAAM,WAAW,SAwDrB,CAAC"}
@@ -1,19 +1,19 @@
1
1
  import { Command } from "commander";
2
- import consola from "consola";
3
2
  import * as nodePath from "node:path";
4
3
  import { Logger } from "../../../services/logger/index.js";
5
4
  import { findPackageJson } from "../../../services/environment/package.js";
6
5
  import { checkForUncommittedChanges } from "../../steps/check-for-uncomitted-changes.js";
7
6
  import { initializeInlangProject } from "../../steps/initialize-inlang-project.js";
8
7
  import { maybeAddSherlock } from "../../steps/maybe-add-sherlock.js";
9
- import { maybeChangeTsConfig } from "../../steps/update-ts-config.js";
8
+ import { maybeUpdateTsConfig } from "../../steps/update-ts-config.js";
10
9
  import { promptForOutdir } from "../../steps/prompt-for-outdir.js";
11
10
  import { updatePackageJson } from "../../steps/update-package-json.js";
12
- import { runCompiler } from "../../steps/run-compiler.js";
13
11
  import nodeFs from "node:fs";
14
12
  import { ENV_VARIABLES } from "../../../services/env-variables/index.js";
15
13
  import { detectBundler } from "../../steps/detect-bundler.js";
16
14
  import { addVitePlugin } from "../../steps/add-vite-plugin.js";
15
+ import { compile } from "../../../compiler/compile.js";
16
+ import { maybeAddMachineTranslation } from "../../steps/maybe-add-machine-translation.js";
17
17
  export const initCommand = new Command()
18
18
  .name("init")
19
19
  .summary("Initializes inlang Paraglide-JS.")
@@ -38,24 +38,25 @@ export const initCommand = new Command()
38
38
  else {
39
39
  await addCompileStepToPackageJSON(ctx6);
40
40
  }
41
- const ctx7 = await maybeChangeTsConfig(ctx6);
41
+ const ctx7 = await maybeUpdateTsConfig(ctx6);
42
42
  const ctx8 = await maybeAddSherlock(ctx7);
43
+ const ctx9 = await maybeAddMachineTranslation(ctx8);
43
44
  try {
44
- await runCompiler(ctx8);
45
- ctx.logger.success("Run paraglide compiler");
45
+ await compile({
46
+ project: ctx9.projectPath,
47
+ outdir: ctx9.outdir,
48
+ });
49
+ ctx.logger.success("Ran the paraglide compiler");
46
50
  }
47
51
  catch {
48
52
  ctx.logger.warn("Failed to compile project automatically. You will need to run the compiler manually");
49
53
  }
50
- const absoluteSettingsPath = nodePath.resolve(ctx8.projectPath, "settings.json");
51
- const relativeSettingsFilePath = absoluteSettingsPath.replace(process.cwd(), ".");
52
54
  const successMessage = [
53
55
  `inlang Paraglide-JS has been set up sucessfully.`,
54
56
  "\n",
55
57
  `1. Run your install command (npm i, yarn install, etc)`,
56
58
  `2. Run the build script (npm run build, or similar.)`,
57
- `3. Define the locales in ${relativeSettingsFilePath}`,
58
- "\n",
59
+ `3. Visit https://inlang.com/m/gerre34r/library-inlang-paraglideJs/basics to get started.`,
59
60
  "\n",
60
61
  `For questions and feedback, visit`,
61
62
  `https://github.com/opral/inlang-paraglide-js/issues`,
@@ -63,7 +64,7 @@ export const initCommand = new Command()
63
64
  ctx.logger.box(successMessage);
64
65
  process.exit(0);
65
66
  });
66
- export const addParaglideJsToDevDependencies = async (ctx) => {
67
+ const addParaglideJsToDevDependencies = async (ctx) => {
67
68
  const ctx1 = await updatePackageJson({
68
69
  devDependencies: async (devDeps) => ({
69
70
  ...devDeps,
@@ -73,7 +74,7 @@ export const addParaglideJsToDevDependencies = async (ctx) => {
73
74
  ctx.logger.success("Added @inlang/paraglide-js to the devDependencies in package.json.");
74
75
  return ctx1;
75
76
  };
76
- export const enforcePackageJsonExists = async (ctx) => {
77
+ const enforcePackageJsonExists = async (ctx) => {
77
78
  const packageJsonPath = await findPackageJson(ctx.fs, process.cwd());
78
79
  if (!packageJsonPath) {
79
80
  ctx.logger.warn("No package.json found in the current working directory. Please change the working directory to the directory with a package.json file.");
@@ -81,19 +82,11 @@ export const enforcePackageJsonExists = async (ctx) => {
81
82
  }
82
83
  return { ...ctx, packageJsonPath };
83
84
  };
84
- export const addCompileStepToPackageJSON = async (ctx) => {
85
+ const addCompileStepToPackageJSON = async (ctx) => {
85
86
  const projectPath = "./" + nodePath.relative(process.cwd(), ctx.projectPath);
86
87
  const outdir = "./" + nodePath.relative(process.cwd(), ctx.outdir);
87
- let shouldExit = false;
88
88
  ctx = await updatePackageJson({
89
89
  scripts: async (scripts) => {
90
- // add the compile command to the postinstall script
91
- // this isn't super important, so we won't interrupt the user if it fails
92
- if (!scripts.postinstall?.includes("paraglide-js compile")) {
93
- scripts.postinstall =
94
- `paraglide-js compile --project ${projectPath} --outdir ${outdir}` +
95
- (scripts.postinstall ? " && " + scripts.postinstall : "");
96
- }
97
90
  if (scripts.build === undefined) {
98
91
  scripts.build = `paraglide-js compile --project ${projectPath} --outdir ${outdir}`;
99
92
  }
@@ -101,30 +94,13 @@ export const addCompileStepToPackageJSON = async (ctx) => {
101
94
  scripts.build = `paraglide-js compile --project ${projectPath} --outdir ${outdir} && ${scripts.build}`;
102
95
  }
103
96
  else {
104
- ctx.logger
105
- .warn(`The "build" script in the \`package.json\` already contains a "paraglide-js compile" command.
106
-
107
- Please add the following command to your build script manually:
108
-
109
- \`paraglide-js compile --project ${ctx.projectPath}`);
110
- const response = await consola.prompt("Have you added the compile command to your build script?", {
111
- type: "confirm",
112
- initial: false,
113
- });
114
- if (response === false) {
115
- ctx.logger.log("Please add the paraglide-js compile to your build script and try again.");
116
- shouldExit = true;
117
- throw new Error("Skip write");
118
- }
119
- else {
120
- throw new Error("Skip write");
121
- }
97
+ return scripts;
122
98
  }
123
- ctx.logger.success("Successfully added the compile command to the build step in package.json.");
99
+ ctx.logger.success("Added the compile command to the build step in package.json.");
100
+ ctx.logger.info(`If you use a bundler like Vite, Rolldown, or Webpack, you can use a bundler plugin instead and remove the compile command from the build script.`);
101
+ ctx.logger.info(`Visit https://inlang.com/m/gerre34r/library-inlang-paraglideJs/compiling-messages for more information.`);
124
102
  return scripts;
125
103
  },
126
104
  })(ctx);
127
- if (shouldExit)
128
- process.exit(1);
129
105
  return ctx;
130
106
  };
@@ -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@3/dist/index.js",
11
- "https://cdn.jsdelivr.net/npm/@inlang/plugin-m-function-matcher@1/dist/index.js",
10
+ "https://cdn.jsdelivr.net/npm/@inlang/plugin-message-format@4/dist/index.js",
11
+ "https://cdn.jsdelivr.net/npm/@inlang/plugin-m-function-matcher@2/dist/index.js",
12
12
  ],
13
13
  "plugin.inlang.messageFormat": {
14
14
  pathPattern: "./messages/{locale}.json",
@@ -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;AAKpC,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,SAK8B,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
@@ -2,18 +2,9 @@ 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
4
  import { initCommand } from "./commands/init/command.js";
5
- export { checkForUncommittedChanges } from "./steps/check-for-uncomitted-changes.js";
6
- export { initializeInlangProject } from "./steps/initialize-inlang-project.js";
7
- export { maybeAddSherlock } from "./steps/maybe-add-sherlock.js";
8
- export { maybeChangeTsConfig } from "./steps/update-ts-config.js";
9
- export { promptForOutdir } from "./steps/prompt-for-outdir.js";
10
- export { updatePackageJson } from "./steps/update-package-json.js";
11
- export { runCompiler } from "./steps/run-compiler.js";
12
5
  export const cli = new Command()
13
6
  .name("paraglide-js")
14
7
  .addCommand(compileCommand)
15
8
  .addCommand(initCommand)
16
9
  .showHelpAfterError()
17
10
  .version(ENV_VARIABLES.PARJS_PACKAGE_VERSION);
18
- export * as Utils from "./utils.js";
19
- export * as Defaults from "./defaults.js";
@@ -1 +1 @@
1
- {"version":3,"file":"initialize-inlang-project.d.ts","sourceRoot":"","sources":["../../../src/cli/steps/initialize-inlang-project.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,KAAK,aAAa,EAClB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,EAAE,MAAM,SAAS,CAAC;AAGzB,eAAO,MAAM,uBAAuB,EAAE,OAAO,CAC5C;IACC,EAAE,EAAE,OAAO,EAAE,CAAC,QAAQ,CAAC;IACvB,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACb,EACD;IACC,OAAO,EAAE,aAAa,CAAC;IACvB,mCAAmC;IACnC,WAAW,EAAE,MAAM,CAAC;CACpB,CA2BD,CAAC;AAgHF,eAAO,MAAM,oBAAoB,QAAe;IAC/C,EAAE,EAAE,OAAO,EAAE,CAAC,QAAQ,CAAC;IACvB,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CACf,KAAG,OAAO,CAAC;IACX,OAAO,EAAE,aAAa,CAAC;IACvB,8CAA8C;IAC9C,WAAW,EAAE,MAAM,CAAC;CACpB,CA4EA,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAazD;AAcD;;GAEG;AACH,eAAO,MAAM,OAAO,sbACga,CAAC"}
1
+ {"version":3,"file":"initialize-inlang-project.d.ts","sourceRoot":"","sources":["../../../src/cli/steps/initialize-inlang-project.ts"],"names":[],"mappings":"AAAA,OAAO,EAKN,KAAK,aAAa,EAClB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAG3C,OAAO,EAAE,MAAM,SAAS,CAAC;AAGzB,eAAO,MAAM,uBAAuB,EAAE,OAAO,CAC5C;IACC,EAAE,EAAE,OAAO,EAAE,CAAC,QAAQ,CAAC;IACvB,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACb,EACD;IACC,OAAO,EAAE,aAAa,CAAC;IACvB,mCAAmC;IACnC,WAAW,EAAE,MAAM,CAAC;CACpB,CA2BD,CAAC;AAgHF,eAAO,MAAM,oBAAoB,QAAe;IAC/C,EAAE,EAAE,OAAO,EAAE,CAAC,QAAQ,CAAC;IACvB,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CACf,KAAG,OAAO,CAAC;IACX,OAAO,EAAE,aAAa,CAAC;IACvB,8CAA8C;IAC9C,WAAW,EAAE,MAAM,CAAC;CACpB,CAwEA,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAazD;AAcD;;GAEG;AACH,eAAO,MAAM,OAAO,sbACga,CAAC"}