@inlang/paraglide-js 2.0.0-beta.3 → 2.0.0-beta.30

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 (333) hide show
  1. package/README.md +5 -55
  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 -5
  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 -16
  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 -5
  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 +30 -46
  29. package/dist/cli/defaults.d.ts +1 -1
  30. package/dist/cli/defaults.d.ts.map +1 -1
  31. package/dist/cli/defaults.js +5 -10
  32. package/dist/cli/index.d.ts +0 -9
  33. package/dist/cli/index.d.ts.map +1 -1
  34. package/dist/cli/index.js +2 -9
  35. package/dist/cli/steps/add-vite-plugin.d.ts +10 -0
  36. package/dist/cli/steps/add-vite-plugin.d.ts.map +1 -0
  37. package/dist/cli/steps/add-vite-plugin.js +61 -0
  38. package/dist/cli/steps/add-vite-plugin.test.d.ts +2 -0
  39. package/dist/cli/steps/add-vite-plugin.test.d.ts.map +1 -0
  40. package/dist/cli/steps/add-vite-plugin.test.js +69 -0
  41. package/dist/cli/steps/detect-bundler.d.ts +11 -0
  42. package/dist/cli/steps/detect-bundler.d.ts.map +1 -0
  43. package/dist/cli/steps/detect-bundler.js +21 -0
  44. package/dist/cli/steps/detect-bundler.test.d.ts +2 -0
  45. package/dist/cli/steps/detect-bundler.test.d.ts.map +1 -0
  46. package/dist/cli/steps/detect-bundler.test.js +28 -0
  47. package/dist/cli/steps/initialize-inlang-project.d.ts +1 -11
  48. package/dist/cli/steps/initialize-inlang-project.d.ts.map +1 -1
  49. package/dist/cli/steps/initialize-inlang-project.js +145 -122
  50. package/dist/cli/steps/maybe-add-machine-translation.d.ts +16 -0
  51. package/dist/cli/steps/maybe-add-machine-translation.d.ts.map +1 -0
  52. package/dist/cli/steps/maybe-add-machine-translation.js +48 -0
  53. package/dist/cli/steps/maybe-add-sherlock.d.ts.map +1 -1
  54. package/dist/cli/steps/maybe-add-sherlock.js +13 -14
  55. package/dist/cli/steps/update-ts-config.d.ts +2 -2
  56. package/dist/cli/steps/update-ts-config.d.ts.map +1 -1
  57. package/dist/cli/steps/update-ts-config.js +100 -80
  58. package/dist/compiler/{compileBundle.d.ts → compile-bundle.d.ts} +2 -3
  59. package/dist/compiler/compile-bundle.d.ts.map +1 -0
  60. package/dist/compiler/compile-bundle.js +60 -0
  61. package/dist/compiler/compile-bundle.test.d.ts +2 -0
  62. package/dist/compiler/compile-bundle.test.d.ts.map +1 -0
  63. package/dist/compiler/compile-bundle.test.js +97 -0
  64. package/dist/compiler/compile-local-variable.d.ts +17 -0
  65. package/dist/compiler/compile-local-variable.d.ts.map +1 -0
  66. package/dist/compiler/compile-local-variable.js +38 -0
  67. package/dist/compiler/compile-local-variable.test.d.ts +2 -0
  68. package/dist/compiler/compile-local-variable.test.d.ts.map +1 -0
  69. package/dist/compiler/compile-local-variable.test.js +71 -0
  70. package/dist/compiler/compile-message.d.ts +8 -0
  71. package/dist/compiler/compile-message.d.ts.map +1 -0
  72. package/dist/compiler/compile-message.js +89 -0
  73. package/dist/compiler/compile-message.test.d.ts +2 -0
  74. package/dist/compiler/compile-message.test.d.ts.map +1 -0
  75. package/dist/compiler/compile-message.test.js +308 -0
  76. package/dist/compiler/compile-pattern.d.ts +20 -0
  77. package/dist/compiler/compile-pattern.d.ts.map +1 -0
  78. package/dist/compiler/compile-pattern.js +40 -0
  79. package/dist/compiler/compile-pattern.test.d.ts +2 -0
  80. package/dist/compiler/compile-pattern.test.d.ts.map +1 -0
  81. package/dist/compiler/compile-pattern.test.js +75 -0
  82. package/dist/compiler/compile-project.d.ts +18 -0
  83. package/dist/compiler/compile-project.d.ts.map +1 -0
  84. package/dist/compiler/compile-project.js +92 -0
  85. package/dist/compiler/compile-project.test.d.ts +2 -0
  86. package/dist/compiler/compile-project.test.d.ts.map +1 -0
  87. package/dist/compiler/{compileProject.test.js → compile-project.test.js} +400 -172
  88. package/dist/compiler/compile.bench.d.ts +2 -0
  89. package/dist/compiler/compile.bench.d.ts.map +1 -0
  90. package/dist/compiler/compile.bench.js +39 -0
  91. package/dist/compiler/compile.d.ts +7 -7
  92. package/dist/compiler/compile.d.ts.map +1 -1
  93. package/dist/compiler/compile.js +53 -22
  94. package/dist/compiler/compile.test.js +180 -1
  95. package/dist/compiler/compiler-options.d.ts +232 -0
  96. package/dist/compiler/compiler-options.d.ts.map +1 -0
  97. package/dist/compiler/compiler-options.js +13 -0
  98. package/dist/compiler/index.d.ts +7 -4
  99. package/dist/compiler/index.d.ts.map +1 -1
  100. package/dist/compiler/index.js +5 -4
  101. package/dist/compiler/jsdoc-types.d.ts +15 -0
  102. package/dist/compiler/jsdoc-types.d.ts.map +1 -0
  103. package/dist/compiler/jsdoc-types.js +26 -0
  104. package/dist/compiler/output-structure/locale-modules.d.ts +3 -2
  105. package/dist/compiler/output-structure/locale-modules.d.ts.map +1 -1
  106. package/dist/compiler/output-structure/locale-modules.js +20 -23
  107. package/dist/compiler/output-structure/locale-modules.test.js +3 -5
  108. package/dist/compiler/output-structure/message-modules.d.ts +3 -2
  109. package/dist/compiler/output-structure/message-modules.d.ts.map +1 -1
  110. package/dist/compiler/output-structure/message-modules.js +60 -46
  111. package/dist/compiler/output-structure/message-modules.test.js +44 -5
  112. package/dist/compiler/registry.d.ts +10 -10
  113. package/dist/compiler/registry.d.ts.map +1 -1
  114. package/dist/compiler/registry.js +23 -34
  115. package/dist/compiler/runtime/assert-is-locale.d.ts +9 -0
  116. package/dist/compiler/runtime/assert-is-locale.d.ts.map +1 -0
  117. package/dist/compiler/runtime/assert-is-locale.js +15 -0
  118. package/dist/compiler/runtime/assert-is-locale.test.d.ts +2 -0
  119. package/dist/compiler/runtime/assert-is-locale.test.d.ts.map +1 -0
  120. package/dist/compiler/runtime/assert-is-locale.test.js +26 -0
  121. package/dist/compiler/runtime/create-runtime.d.ts +34 -0
  122. package/dist/compiler/runtime/create-runtime.d.ts.map +1 -0
  123. package/dist/compiler/runtime/create-runtime.js +139 -0
  124. package/dist/compiler/runtime/extract-locale-from-cookie.d.ts +10 -0
  125. package/dist/compiler/runtime/extract-locale-from-cookie.d.ts.map +1 -0
  126. package/dist/compiler/runtime/extract-locale-from-cookie.js +21 -0
  127. package/dist/compiler/runtime/extract-locale-from-cookie.test.d.ts +2 -0
  128. package/dist/compiler/runtime/extract-locale-from-cookie.test.d.ts.map +1 -0
  129. package/dist/compiler/runtime/extract-locale-from-cookie.test.js +45 -0
  130. package/dist/compiler/runtime/extract-locale-from-request.d.ts +17 -0
  131. package/dist/compiler/runtime/extract-locale-from-request.d.ts.map +1 -0
  132. package/dist/compiler/runtime/extract-locale-from-request.js +95 -0
  133. package/dist/compiler/runtime/extract-locale-from-request.test.d.ts +2 -0
  134. package/dist/compiler/runtime/extract-locale-from-request.test.d.ts.map +1 -0
  135. package/dist/compiler/runtime/extract-locale-from-request.test.js +182 -0
  136. package/dist/compiler/runtime/extract-locale-from-url.d.ts +8 -0
  137. package/dist/compiler/runtime/extract-locale-from-url.d.ts.map +1 -0
  138. package/dist/compiler/runtime/extract-locale-from-url.js +47 -0
  139. package/dist/compiler/runtime/extract-locale-from-url.test.d.ts +2 -0
  140. package/dist/compiler/runtime/extract-locale-from-url.test.d.ts.map +1 -0
  141. package/dist/compiler/runtime/extract-locale-from-url.test.js +112 -0
  142. package/dist/compiler/runtime/generate-static-localized-urls.d.ts +24 -0
  143. package/dist/compiler/runtime/generate-static-localized-urls.d.ts.map +1 -0
  144. package/dist/compiler/runtime/generate-static-localized-urls.js +91 -0
  145. package/dist/compiler/runtime/generate-static-localized-urls.test.d.ts +2 -0
  146. package/dist/compiler/runtime/generate-static-localized-urls.test.d.ts.map +1 -0
  147. package/dist/compiler/runtime/generate-static-localized-urls.test.js +169 -0
  148. package/dist/compiler/runtime/get-locale.d.ts +30 -0
  149. package/dist/compiler/runtime/get-locale.d.ts.map +1 -0
  150. package/dist/compiler/runtime/get-locale.js +120 -0
  151. package/dist/compiler/runtime/get-locale.test.d.ts +2 -0
  152. package/dist/compiler/runtime/get-locale.test.d.ts.map +1 -0
  153. package/dist/compiler/runtime/get-locale.test.js +167 -0
  154. package/dist/compiler/runtime/get-url-origin.d.ts +20 -0
  155. package/dist/compiler/runtime/get-url-origin.d.ts.map +1 -0
  156. package/dist/compiler/runtime/get-url-origin.js +30 -0
  157. package/dist/compiler/runtime/get-url-origin.test.d.ts +2 -0
  158. package/dist/compiler/runtime/get-url-origin.test.d.ts.map +1 -0
  159. package/dist/compiler/runtime/get-url-origin.test.js +19 -0
  160. package/dist/compiler/runtime/is-locale.d.ts +15 -0
  161. package/dist/compiler/runtime/is-locale.d.ts.map +1 -0
  162. package/dist/compiler/runtime/is-locale.js +17 -0
  163. package/dist/compiler/runtime/localize-href.d.ts +82 -0
  164. package/dist/compiler/runtime/localize-href.d.ts.map +1 -0
  165. package/dist/compiler/runtime/localize-href.js +108 -0
  166. package/dist/compiler/runtime/localize-href.test.d.ts +2 -0
  167. package/dist/compiler/runtime/localize-href.test.d.ts.map +1 -0
  168. package/dist/compiler/runtime/localize-href.test.js +139 -0
  169. package/dist/compiler/runtime/localize-url.d.ts +85 -0
  170. package/dist/compiler/runtime/localize-url.d.ts.map +1 -0
  171. package/dist/compiler/runtime/localize-url.js +302 -0
  172. package/dist/compiler/runtime/localize-url.test.d.ts +2 -0
  173. package/dist/compiler/runtime/localize-url.test.d.ts.map +1 -0
  174. package/dist/compiler/runtime/localize-url.test.js +436 -0
  175. package/dist/compiler/runtime/set-locale.d.ts +21 -0
  176. package/dist/compiler/runtime/set-locale.d.ts.map +1 -0
  177. package/dist/compiler/runtime/set-locale.js +107 -0
  178. package/dist/compiler/runtime/set-locale.test.d.ts +2 -0
  179. package/dist/compiler/runtime/set-locale.test.d.ts.map +1 -0
  180. package/dist/compiler/runtime/set-locale.test.js +189 -0
  181. package/dist/compiler/runtime/track-message-call.d.ts +6 -0
  182. package/dist/compiler/runtime/track-message-call.d.ts.map +1 -0
  183. package/dist/compiler/runtime/track-message-call.js +13 -0
  184. package/dist/compiler/runtime/track-message-call.test.d.ts +2 -0
  185. package/dist/compiler/runtime/track-message-call.test.d.ts.map +1 -0
  186. package/dist/compiler/runtime/track-message-call.test.js +21 -0
  187. package/dist/compiler/runtime/type.d.ts +33 -0
  188. package/dist/compiler/runtime/type.d.ts.map +1 -0
  189. package/dist/compiler/runtime/type.test.d.ts +2 -0
  190. package/dist/compiler/runtime/type.test.d.ts.map +1 -0
  191. package/dist/compiler/runtime/type.test.js +91 -0
  192. package/dist/compiler/runtime/variables.d.ts +88 -0
  193. package/dist/compiler/runtime/variables.d.ts.map +1 -0
  194. package/dist/compiler/runtime/variables.js +74 -0
  195. package/dist/compiler/safe-module-id.d.ts +8 -0
  196. package/dist/compiler/safe-module-id.d.ts.map +1 -0
  197. package/dist/{services/valid-js-identifier/reservedWords.js → compiler/safe-module-id.js} +22 -1
  198. package/dist/compiler/safe-module-id.test.d.ts +2 -0
  199. package/dist/compiler/safe-module-id.test.d.ts.map +1 -0
  200. package/dist/compiler/safe-module-id.test.js +30 -0
  201. package/dist/compiler/server/create-server-file.d.ts +12 -0
  202. package/dist/compiler/server/create-server-file.d.ts.map +1 -0
  203. package/dist/compiler/server/create-server-file.js +47 -0
  204. package/dist/compiler/server/middleware.d.ts +65 -0
  205. package/dist/compiler/server/middleware.d.ts.map +1 -0
  206. package/dist/compiler/server/middleware.js +158 -0
  207. package/dist/compiler/server/middleware.test.d.ts +2 -0
  208. package/dist/compiler/server/middleware.test.d.ts.map +1 -0
  209. package/dist/compiler/server/middleware.test.js +329 -0
  210. package/dist/compiler/server/type.d.ts +7 -0
  211. package/dist/compiler/server/type.d.ts.map +1 -0
  212. package/dist/compiler/server/type.js +1 -0
  213. package/dist/compiler/types.d.ts +17 -2
  214. package/dist/compiler/types.d.ts.map +1 -1
  215. package/dist/compiler/types.js +1 -28
  216. package/dist/index.d.ts +2 -6
  217. package/dist/index.d.ts.map +1 -1
  218. package/dist/index.js +2 -2
  219. package/dist/services/env-variables/create-index-file.d.ts +2 -0
  220. package/dist/services/env-variables/create-index-file.d.ts.map +1 -0
  221. package/dist/services/env-variables/create-index-file.js +29 -0
  222. package/dist/services/env-variables/index.d.ts +1 -1
  223. package/dist/services/env-variables/index.js +2 -2
  224. package/dist/services/file-handling/write-output.d.ts +7 -1
  225. package/dist/services/file-handling/write-output.d.ts.map +1 -1
  226. package/dist/services/file-handling/write-output.js +103 -27
  227. package/dist/services/file-handling/write-output.test.js +153 -45
  228. package/dist/services/logger/index.d.ts +0 -4
  229. package/dist/services/logger/index.d.ts.map +1 -1
  230. package/dist/services/logger/index.js +11 -14
  231. package/dist/services/telemetry/capture.d.ts +1 -2
  232. package/dist/services/telemetry/capture.d.ts.map +1 -1
  233. package/dist/services/telemetry/stack-detection.d.ts +1 -1
  234. package/dist/services/telemetry/stack-detection.d.ts.map +1 -1
  235. package/dist/services/telemetry/stack-detection.js +3 -8
  236. package/dist/services/telemetry/stack-detection.test.js +9 -12
  237. package/dist/urlpattern-polyfill/index.d.ts +2 -0
  238. package/dist/urlpattern-polyfill/index.d.ts.map +1 -0
  239. package/dist/urlpattern-polyfill/index.js +1 -0
  240. package/dist/utilities/node-normalize-path.d.ts +2 -0
  241. package/dist/utilities/node-normalize-path.d.ts.map +1 -0
  242. package/dist/utilities/node-normalize-path.js +9 -0
  243. package/package.json +34 -40
  244. package/dist/adapter-utils/index.d.ts +0 -6
  245. package/dist/adapter-utils/index.d.ts.map +0 -1
  246. package/dist/adapter-utils/index.js +0 -5
  247. package/dist/adapter-utils/negotiation/language.d.ts +0 -10
  248. package/dist/adapter-utils/negotiation/language.d.ts.map +0 -1
  249. package/dist/adapter-utils/negotiation/language.js +0 -137
  250. package/dist/adapter-utils/negotiation/language.test.d.ts +0 -2
  251. package/dist/adapter-utils/negotiation/language.test.d.ts.map +0 -1
  252. package/dist/adapter-utils/negotiation/language.test.js +0 -24
  253. package/dist/adapter-utils/routing/detectLanguage.d.ts +0 -25
  254. package/dist/adapter-utils/routing/detectLanguage.d.ts.map +0 -1
  255. package/dist/adapter-utils/routing/detectLanguage.js +0 -32
  256. package/dist/adapter-utils/routing/detectLanguage.test.d.ts +0 -2
  257. package/dist/adapter-utils/routing/detectLanguage.test.d.ts.map +0 -1
  258. package/dist/adapter-utils/routing/detectLanguage.test.js +0 -37
  259. package/dist/adapter-utils/routing/resolveUserPathDefinition.test.d.ts +0 -2
  260. package/dist/adapter-utils/routing/resolveUserPathDefinition.test.d.ts.map +0 -1
  261. package/dist/adapter-utils/routing/resolveUserPathDefinition.test.js +0 -35
  262. package/dist/adapter-utils/routing/resolveUserPathDefinitions.d.ts +0 -40
  263. package/dist/adapter-utils/routing/resolveUserPathDefinitions.d.ts.map +0 -1
  264. package/dist/adapter-utils/routing/resolveUserPathDefinitions.js +0 -22
  265. package/dist/adapter-utils/routing/routeDefinitions.d.ts +0 -48
  266. package/dist/adapter-utils/routing/routeDefinitions.d.ts.map +0 -1
  267. package/dist/adapter-utils/routing/routeDefinitions.js +0 -224
  268. package/dist/adapter-utils/routing/routeDefinitions.test.d.ts +0 -2
  269. package/dist/adapter-utils/routing/routeDefinitions.test.d.ts.map +0 -1
  270. package/dist/adapter-utils/routing/routeDefinitions.test.js +0 -234
  271. package/dist/adapter-utils/routing/sortRoutes.d.ts +0 -2
  272. package/dist/adapter-utils/routing/sortRoutes.d.ts.map +0 -1
  273. package/dist/adapter-utils/routing/sortRoutes.js +0 -135
  274. package/dist/adapter-utils/routing/validatePathTranslations.d.ts +0 -15
  275. package/dist/adapter-utils/routing/validatePathTranslations.d.ts.map +0 -1
  276. package/dist/adapter-utils/routing/validatePathTranslations.js +0 -98
  277. package/dist/adapter-utils/routing/validatePathTranslations.test.d.ts +0 -2
  278. package/dist/adapter-utils/routing/validatePathTranslations.test.d.ts.map +0 -1
  279. package/dist/adapter-utils/routing/validatePathTranslations.test.js +0 -121
  280. package/dist/cli/steps/run-compiler.d.ts +0 -9
  281. package/dist/cli/steps/run-compiler.d.ts.map +0 -1
  282. package/dist/cli/steps/run-compiler.js +0 -13
  283. package/dist/compiler/compileBundle.d.ts.map +0 -1
  284. package/dist/compiler/compileBundle.js +0 -55
  285. package/dist/compiler/compileExpression.d.ts +0 -5
  286. package/dist/compiler/compileExpression.d.ts.map +0 -1
  287. package/dist/compiler/compileExpression.js +0 -41
  288. package/dist/compiler/compileMessage.d.ts +0 -12
  289. package/dist/compiler/compileMessage.d.ts.map +0 -1
  290. package/dist/compiler/compileMessage.js +0 -64
  291. package/dist/compiler/compileMessage.test.d.ts +0 -2
  292. package/dist/compiler/compileMessage.test.d.ts.map +0 -1
  293. package/dist/compiler/compileMessage.test.js +0 -74
  294. package/dist/compiler/compilePattern.d.ts +0 -12
  295. package/dist/compiler/compilePattern.d.ts.map +0 -1
  296. package/dist/compiler/compilePattern.js +0 -28
  297. package/dist/compiler/compilePattern.test.d.ts +0 -2
  298. package/dist/compiler/compilePattern.test.d.ts.map +0 -1
  299. package/dist/compiler/compilePattern.test.js +0 -67
  300. package/dist/compiler/compileProject.d.ts +0 -43
  301. package/dist/compiler/compileProject.d.ts.map +0 -1
  302. package/dist/compiler/compileProject.js +0 -110
  303. package/dist/compiler/compileProject.test.d.ts +0 -2
  304. package/dist/compiler/compileProject.test.d.ts.map +0 -1
  305. package/dist/compiler/emit-dts.d.ts +0 -7
  306. package/dist/compiler/emit-dts.d.ts.map +0 -1
  307. package/dist/compiler/emit-dts.js +0 -56
  308. package/dist/compiler/emit-dts.test.d.ts +0 -2
  309. package/dist/compiler/emit-dts.test.d.ts.map +0 -1
  310. package/dist/compiler/emit-dts.test.js +0 -43
  311. package/dist/compiler/jsDocComment.d.ts +0 -9
  312. package/dist/compiler/jsDocComment.d.ts.map +0 -1
  313. package/dist/compiler/jsDocComment.js +0 -30
  314. package/dist/compiler/runtime.d.ts +0 -6
  315. package/dist/compiler/runtime.d.ts.map +0 -1
  316. package/dist/compiler/runtime.js +0 -158
  317. package/dist/services/codegen/identifier.d.ts +0 -6
  318. package/dist/services/codegen/identifier.d.ts.map +0 -1
  319. package/dist/services/codegen/identifier.js +0 -11
  320. package/dist/services/codegen/indentifier.test.d.ts +0 -2
  321. package/dist/services/codegen/indentifier.test.d.ts.map +0 -1
  322. package/dist/services/codegen/indentifier.test.js +0 -8
  323. package/dist/services/telemetry/events.d.ts +0 -7
  324. package/dist/services/telemetry/events.d.ts.map +0 -1
  325. package/dist/services/valid-js-identifier/index.d.ts +0 -6
  326. package/dist/services/valid-js-identifier/index.d.ts.map +0 -1
  327. package/dist/services/valid-js-identifier/index.js +0 -24
  328. package/dist/services/valid-js-identifier/index.test.d.ts +0 -2
  329. package/dist/services/valid-js-identifier/index.test.d.ts.map +0 -1
  330. package/dist/services/valid-js-identifier/index.test.js +0 -30
  331. package/dist/services/valid-js-identifier/reservedWords.d.ts +0 -2
  332. package/dist/services/valid-js-identifier/reservedWords.d.ts.map +0 -1
  333. /package/dist/{services/telemetry/events.js → compiler/runtime/type.js} +0 -0
package/README.md CHANGED
@@ -1,63 +1,13 @@
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) [![Discord](https://img.shields.io/discord/897438559458430986?style=flat&logo=discord&labelColor=white)](https://discord.gg/MZ48XgXKkk)
4
4
 
5
- To auto setup Paraglide JS, run the following command:
6
5
 
7
- ```bash
8
- npx @inlang/paraglide-js@latest init
9
- ```
10
6
 
11
- This will:
7
+ 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.
12
8
 
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
9
+ Visit https://inlang.com/m/gerre34r/library-inlang-paraglideJs to learn more.
16
10
 
17
- ## Adding and editing Messages
11
+ ## Contributing
18
12
 
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.
13
+ 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,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("unplugin").RollupPlugin<any> | import("unplugin").RollupPlugin<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,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,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;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
- options: args.options,
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
- options: args.options,
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
- options: args.options,
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,6 +1,2 @@
1
- export declare const paraglideVitePlugin: (options: {
2
- project: string;
3
- outdir: string;
4
- options?: import("../compiler/compileProject.js").ParaglideCompilerOptions;
5
- }) => 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>[];
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;;;;+DAAoC,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.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,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;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;AAkBpC,eAAO,MAAM,WAAW,SAwDrB,CAAC"}
@@ -1,23 +1,25 @@
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";
13
+ import { detectBundler } from "../../steps/detect-bundler.js";
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";
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,33 +31,40 @@ 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);
43
+ const ctx9 = await maybeAddMachineTranslation(ctx8);
35
44
  try {
36
- await runCompiler(ctx8);
37
- 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");
38
50
  }
39
51
  catch {
40
52
  ctx.logger.warn("Failed to compile project automatically. You will need to run the compiler manually");
41
53
  }
42
- const absoluteSettingsPath = nodePath.resolve(ctx8.projectPath, "settings.json");
43
- const relativeSettingsFilePath = absoluteSettingsPath.replace(process.cwd(), ".");
44
54
  const successMessage = [
45
55
  `inlang Paraglide-JS has been set up sucessfully.`,
46
56
  "\n",
47
57
  `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 🪂`,
51
- "\n",
58
+ `2. Run the build script (npm run build, or similar.)`,
59
+ `3. Visit https://inlang.com/m/gerre34r/library-inlang-paraglideJs/basics to get started.`,
52
60
  "\n",
53
61
  `For questions and feedback, visit`,
54
62
  `https://github.com/opral/inlang-paraglide-js/issues`,
55
63
  ].join("\n");
56
64
  ctx.logger.box(successMessage);
65
+ process.exit(0);
57
66
  });
58
- export const addParaglideJsToDevDependencies = async (ctx) => {
67
+ const addParaglideJsToDevDependencies = async (ctx) => {
59
68
  const ctx1 = await updatePackageJson({
60
69
  devDependencies: async (devDeps) => ({
61
70
  ...devDeps,
@@ -65,7 +74,7 @@ export const addParaglideJsToDevDependencies = async (ctx) => {
65
74
  ctx.logger.success("Added @inlang/paraglide-js to the devDependencies in package.json.");
66
75
  return ctx1;
67
76
  };
68
- export const enforcePackageJsonExists = async (ctx) => {
77
+ const enforcePackageJsonExists = async (ctx) => {
69
78
  const packageJsonPath = await findPackageJson(ctx.fs, process.cwd());
70
79
  if (!packageJsonPath) {
71
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.");
@@ -73,19 +82,11 @@ export const enforcePackageJsonExists = async (ctx) => {
73
82
  }
74
83
  return { ...ctx, packageJsonPath };
75
84
  };
76
- export const addCompileStepToPackageJSON = async (ctx) => {
85
+ const addCompileStepToPackageJSON = async (ctx) => {
77
86
  const projectPath = "./" + nodePath.relative(process.cwd(), ctx.projectPath);
78
87
  const outdir = "./" + nodePath.relative(process.cwd(), ctx.outdir);
79
- let shouldExit = false;
80
88
  ctx = await updatePackageJson({
81
89
  scripts: async (scripts) => {
82
- // add the compile command to the postinstall script
83
- // this isn't super important, so we won't interrupt the user if it fails
84
- if (!scripts.postinstall?.includes("paraglide-js compile")) {
85
- scripts.postinstall =
86
- `paraglide-js compile --project ${projectPath} --outdir ${outdir}` +
87
- (scripts.postinstall ? " && " + scripts.postinstall : "");
88
- }
89
90
  if (scripts.build === undefined) {
90
91
  scripts.build = `paraglide-js compile --project ${projectPath} --outdir ${outdir}`;
91
92
  }
@@ -93,30 +94,13 @@ export const addCompileStepToPackageJSON = async (ctx) => {
93
94
  scripts.build = `paraglide-js compile --project ${projectPath} --outdir ${outdir} && ${scripts.build}`;
94
95
  }
95
96
  else {
96
- ctx.logger
97
- .warn(`The "build" script in the \`package.json\` already contains a "paraglide-js compile" command.
98
-
99
- Please add the following command to your build script manually:
100
-
101
- \`paraglide-js compile --project ${ctx.projectPath}`);
102
- const response = await consola.prompt("Have you added the compile command to your build script?", {
103
- type: "confirm",
104
- initial: false,
105
- });
106
- if (response === false) {
107
- ctx.logger.log("Please add the paraglide-js compile to your build script and try again.");
108
- shouldExit = true;
109
- throw new Error("Skip write");
110
- }
111
- else {
112
- throw new Error("Skip write");
113
- }
97
+ return scripts;
114
98
  }
115
- 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.`);
116
102
  return scripts;
117
103
  },
118
104
  })(ctx);
119
- if (shouldExit)
120
- process.exit(1);
121
105
  return ctx;
122
106
  };
@@ -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"}