@inlang/paraglide-js 2.20.2 → 2.22.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 (161) hide show
  1. package/README.md +7 -1
  2. package/dist/bundler-plugins/index.d.ts +1 -1
  3. package/dist/bundler-plugins/index.d.ts.map +1 -1
  4. package/dist/bundler-plugins/index.js +1 -1
  5. package/dist/bundler-plugins/index.js.map +1 -1
  6. package/dist/bundler-plugins/per-locale-build/constants.d.ts +4 -0
  7. package/dist/bundler-plugins/per-locale-build/constants.d.ts.map +1 -0
  8. package/dist/bundler-plugins/per-locale-build/constants.js +4 -0
  9. package/dist/bundler-plugins/per-locale-build/constants.js.map +1 -0
  10. package/dist/bundler-plugins/per-locale-build/framework-helpers.test.d.ts +2 -0
  11. package/dist/bundler-plugins/per-locale-build/framework-helpers.test.d.ts.map +1 -0
  12. package/dist/bundler-plugins/per-locale-build/framework-helpers.test.js +57 -0
  13. package/dist/bundler-plugins/per-locale-build/framework-helpers.test.js.map +1 -0
  14. package/dist/bundler-plugins/per-locale-build/frameworks/index.d.ts +5 -0
  15. package/dist/bundler-plugins/per-locale-build/frameworks/index.d.ts.map +1 -0
  16. package/dist/bundler-plugins/per-locale-build/frameworks/index.js +21 -0
  17. package/dist/bundler-plugins/per-locale-build/frameworks/index.js.map +1 -0
  18. package/dist/bundler-plugins/per-locale-build/frameworks/sveltekit.d.ts +21 -0
  19. package/dist/bundler-plugins/per-locale-build/frameworks/sveltekit.d.ts.map +1 -0
  20. package/dist/bundler-plugins/per-locale-build/frameworks/sveltekit.js +137 -0
  21. package/dist/bundler-plugins/per-locale-build/frameworks/sveltekit.js.map +1 -0
  22. package/dist/bundler-plugins/per-locale-build/frameworks/tanstack-start.d.ts +23 -0
  23. package/dist/bundler-plugins/per-locale-build/frameworks/tanstack-start.d.ts.map +1 -0
  24. package/dist/bundler-plugins/per-locale-build/frameworks/tanstack-start.js +104 -0
  25. package/dist/bundler-plugins/per-locale-build/frameworks/tanstack-start.js.map +1 -0
  26. package/dist/bundler-plugins/per-locale-build/index.d.ts +7 -0
  27. package/dist/bundler-plugins/per-locale-build/index.d.ts.map +1 -0
  28. package/dist/bundler-plugins/per-locale-build/index.js +76 -0
  29. package/dist/bundler-plugins/per-locale-build/index.js.map +1 -0
  30. package/dist/bundler-plugins/per-locale-build/locale-id.d.ts +9 -0
  31. package/dist/bundler-plugins/per-locale-build/locale-id.d.ts.map +1 -0
  32. package/dist/bundler-plugins/per-locale-build/locale-id.js +13 -0
  33. package/dist/bundler-plugins/per-locale-build/locale-id.js.map +1 -0
  34. package/dist/bundler-plugins/per-locale-build/specialize-bundle.d.ts +18 -0
  35. package/dist/bundler-plugins/per-locale-build/specialize-bundle.d.ts.map +1 -0
  36. package/dist/bundler-plugins/per-locale-build/specialize-bundle.js +184 -0
  37. package/dist/bundler-plugins/per-locale-build/specialize-bundle.js.map +1 -0
  38. package/dist/bundler-plugins/per-locale-build/types.d.ts +42 -0
  39. package/dist/bundler-plugins/per-locale-build/types.d.ts.map +1 -0
  40. package/dist/bundler-plugins/per-locale-build/types.js +2 -0
  41. package/dist/bundler-plugins/per-locale-build/types.js.map +1 -0
  42. package/dist/bundler-plugins/per-locale-build/vite-plugin.d.ts +9 -0
  43. package/dist/bundler-plugins/per-locale-build/vite-plugin.d.ts.map +1 -0
  44. package/dist/bundler-plugins/per-locale-build/vite-plugin.js +87 -0
  45. package/dist/bundler-plugins/per-locale-build/vite-plugin.js.map +1 -0
  46. package/dist/bundler-plugins/per-locale-build/vite-plugin.test.d.ts +2 -0
  47. package/dist/bundler-plugins/per-locale-build/vite-plugin.test.d.ts.map +1 -0
  48. package/dist/bundler-plugins/per-locale-build/vite-plugin.test.js +429 -0
  49. package/dist/bundler-plugins/per-locale-build/vite-plugin.test.js.map +1 -0
  50. package/dist/bundler-plugins/rolldown.d.ts +1 -1
  51. package/dist/bundler-plugins/rollup.d.ts +1 -1
  52. package/dist/bundler-plugins/vite.d.ts +16 -1
  53. package/dist/bundler-plugins/vite.d.ts.map +1 -1
  54. package/dist/bundler-plugins/vite.js +12 -1
  55. package/dist/bundler-plugins/vite.js.map +1 -1
  56. package/dist/bundler-plugins/vite.test.d.ts +2 -0
  57. package/dist/bundler-plugins/vite.test.d.ts.map +1 -0
  58. package/dist/bundler-plugins/vite.test.js +97 -0
  59. package/dist/bundler-plugins/vite.test.js.map +1 -0
  60. package/dist/cli/defaults.d.ts.map +1 -1
  61. package/dist/cli/steps/initialize-inlang-project.d.ts.map +1 -1
  62. package/dist/cli/steps/update-ts-config.d.ts.map +1 -1
  63. package/dist/cli/steps/update-ts-config.js.map +1 -1
  64. package/dist/cli/utils.d.ts.map +1 -1
  65. package/dist/cli/utils.js.map +1 -1
  66. package/dist/compiler/compile-bundle.d.ts +2 -0
  67. package/dist/compiler/compile-bundle.d.ts.map +1 -1
  68. package/dist/compiler/compile-bundle.js +11 -2
  69. package/dist/compiler/compile-bundle.js.map +1 -1
  70. package/dist/compiler/compile-bundle.test.js +64 -4
  71. package/dist/compiler/compile-bundle.test.js.map +1 -1
  72. package/dist/compiler/compile-message.d.ts.map +1 -1
  73. package/dist/compiler/compile-pattern.d.ts.map +1 -1
  74. package/dist/compiler/compile-project.d.ts.map +1 -1
  75. package/dist/compiler/compile-project.js +3 -0
  76. package/dist/compiler/compile-project.js.map +1 -1
  77. package/dist/compiler/compile-project.test.js +35 -1
  78. package/dist/compiler/compile-project.test.js.map +1 -1
  79. package/dist/compiler/compile.bench.js.map +1 -1
  80. package/dist/compiler/compiler-options.d.ts +7 -1
  81. package/dist/compiler/compiler-options.d.ts.map +1 -1
  82. package/dist/compiler/emit-ts-declarations.d.ts.map +1 -1
  83. package/dist/compiler/emit-ts-declarations.interop.test.d.ts +2 -0
  84. package/dist/compiler/emit-ts-declarations.interop.test.d.ts.map +1 -0
  85. package/dist/compiler/emit-ts-declarations.interop.test.js +62 -0
  86. package/dist/compiler/emit-ts-declarations.interop.test.js.map +1 -0
  87. package/dist/compiler/emit-ts-declarations.js +150 -0
  88. package/dist/compiler/emit-ts-declarations.js.map +1 -1
  89. package/dist/compiler/emit-ts-declarations.test.d.ts +2 -0
  90. package/dist/compiler/emit-ts-declarations.test.d.ts.map +1 -0
  91. package/dist/compiler/emit-ts-declarations.test.js +181 -0
  92. package/dist/compiler/emit-ts-declarations.test.js.map +1 -0
  93. package/dist/compiler/output-structure/message-modules.test.js.map +1 -1
  94. package/dist/compiler/per-locale-build.d.ts +3 -0
  95. package/dist/compiler/per-locale-build.d.ts.map +1 -0
  96. package/dist/compiler/per-locale-build.js +3 -0
  97. package/dist/compiler/per-locale-build.js.map +1 -0
  98. package/dist/compiler/resolve-tsc-js-path.d.ts +10 -0
  99. package/dist/compiler/resolve-tsc-js-path.d.ts.map +1 -0
  100. package/dist/compiler/resolve-tsc-js-path.js +23 -0
  101. package/dist/compiler/resolve-tsc-js-path.js.map +1 -0
  102. package/dist/compiler/runtime/check-locale.d.ts +3 -3
  103. package/dist/compiler/runtime/check-locale.d.ts.map +1 -1
  104. package/dist/compiler/runtime/create-runtime.d.ts.map +1 -1
  105. package/dist/compiler/runtime/create-runtime.js +5 -1
  106. package/dist/compiler/runtime/create-runtime.js.map +1 -1
  107. package/dist/compiler/runtime/extract-locale-from-cookie.d.ts +2 -2
  108. package/dist/compiler/runtime/extract-locale-from-cookie.d.ts.map +1 -1
  109. package/dist/compiler/runtime/extract-locale-from-header.d.ts +1 -1
  110. package/dist/compiler/runtime/extract-locale-from-header.d.ts.map +1 -1
  111. package/dist/compiler/runtime/extract-locale-from-navigator.d.ts +1 -1
  112. package/dist/compiler/runtime/extract-locale-from-navigator.d.ts.map +1 -1
  113. package/dist/compiler/runtime/extract-locale-from-request-async.d.ts +33 -2
  114. package/dist/compiler/runtime/extract-locale-from-request-async.d.ts.map +1 -1
  115. package/dist/compiler/runtime/extract-locale-from-request.d.ts +36 -4
  116. package/dist/compiler/runtime/extract-locale-from-request.d.ts.map +1 -1
  117. package/dist/compiler/runtime/extract-locale-from-url.d.ts +1 -1
  118. package/dist/compiler/runtime/extract-locale-from-url.d.ts.map +1 -1
  119. package/dist/compiler/runtime/generate-static-localized-urls.d.ts +1 -1
  120. package/dist/compiler/runtime/generate-static-localized-urls.d.ts.map +1 -1
  121. package/dist/compiler/runtime/get-locale.d.ts +36 -3
  122. package/dist/compiler/runtime/get-locale.d.ts.map +1 -1
  123. package/dist/compiler/runtime/get-text-direction.d.ts +1 -1
  124. package/dist/compiler/runtime/get-text-direction.d.ts.map +1 -1
  125. package/dist/compiler/runtime/get-url-origin.d.ts +10 -2
  126. package/dist/compiler/runtime/get-url-origin.d.ts.map +1 -1
  127. package/dist/compiler/runtime/localize-href.d.ts +3 -3
  128. package/dist/compiler/runtime/localize-href.d.ts.map +1 -1
  129. package/dist/compiler/runtime/localize-url.d.ts +4 -4
  130. package/dist/compiler/runtime/localize-url.d.ts.map +1 -1
  131. package/dist/compiler/runtime/set-locale.d.ts +19 -5
  132. package/dist/compiler/runtime/set-locale.d.ts.map +1 -1
  133. package/dist/compiler/runtime/set-locale.js +7 -1
  134. package/dist/compiler/runtime/set-locale.js.map +1 -1
  135. package/dist/compiler/runtime/set-locale.test.js +31 -0
  136. package/dist/compiler/runtime/set-locale.test.js.map +1 -1
  137. package/dist/compiler/runtime/should-redirect.d.ts +29 -29
  138. package/dist/compiler/runtime/should-redirect.d.ts.map +1 -1
  139. package/dist/compiler/runtime/strategy.d.ts +36 -36
  140. package/dist/compiler/runtime/strategy.d.ts.map +1 -1
  141. package/dist/compiler/runtime/track-message-call.d.ts +1 -1
  142. package/dist/compiler/runtime/track-message-call.d.ts.map +1 -1
  143. package/dist/compiler/runtime/type-definitions.d.ts +144 -43
  144. package/dist/compiler/runtime/type-definitions.d.ts.map +1 -1
  145. package/dist/compiler/runtime/type.test.js.map +1 -1
  146. package/dist/compiler/runtime/variables.d.ts +60 -60
  147. package/dist/compiler/runtime/variables.d.ts.map +1 -1
  148. package/dist/compiler/server/create-server-file.js.map +1 -1
  149. package/dist/compiler/server/middleware.d.ts +1 -1
  150. package/dist/compiler/server/middleware.d.ts.map +1 -1
  151. package/dist/services/codegen/quotes.d.ts.map +1 -1
  152. package/dist/services/env-variables/create-index-file.d.ts +8 -0
  153. package/dist/services/env-variables/create-index-file.d.ts.map +1 -1
  154. package/dist/services/env-variables/create-index-file.js.map +1 -1
  155. package/dist/services/env-variables/index.d.ts.map +1 -1
  156. package/dist/services/env-variables/index.js +1 -1
  157. package/dist/services/file-watching/tracked-fs.js.map +1 -1
  158. package/dist/services/logger/index.d.ts.map +1 -1
  159. package/dist/services/logger/index.js.map +1 -1
  160. package/dist/utilities/detect-json-formatting.d.ts.map +1 -1
  161. package/package.json +8 -2
package/README.md CHANGED
@@ -114,11 +114,17 @@ import { paraglideVitePlugin } from "@inlang/paraglide-js";
114
114
  export default defineConfig({
115
115
  plugins: [
116
116
  react(),
117
- paraglideVitePlugin({ project: "./project.inlang", outdir: "./src/paraglide" }),
117
+ paraglideVitePlugin({
118
+ project: "./project.inlang",
119
+ outdir: "./src/paraglide",
120
+ emitTsDeclarations: true,
121
+ }),
118
122
  ],
119
123
  });
120
124
  ```
121
125
 
126
+ `emitTsDeclarations` requires TypeScript 5.6 or newer and keeps editor types in sync when message files change. Set it to `false` to use the faster JavaScript/JSDoc inference path instead.
127
+
122
128
  The `Greeting` component shown above is all the app code you need. `setLocale()` reloads the page by default so every message re-renders — a deliberate design choice: a user switches language once, so a reload keeps things simple and avoids framework-specific state/scroll-preservation logic (the same approach YouTube and others take). Pass `setLocale("de", { reload: false })` to drive re-rendering yourself.
123
129
 
124
130
  **[Full React + Vite example →](https://github.com/opral/paraglide-js/tree/main/examples/react)** · **[React Router (SSR) guide →](https://paraglidejs.com/react-router)**
@@ -2,6 +2,6 @@ export { paraglideEsbuildPlugin } from "./esbuild.js";
2
2
  export { paraglideRolldownPlugin } from "./rolldown.js";
3
3
  export { paraglideRollupPlugin } from "./rollup.js";
4
4
  export { paraglideRspackPlugin } from "./rspack.js";
5
- export { paraglideVitePlugin } from "./vite.js";
5
+ export { paraglideVitePlugin, type ParaglideVitePluginOptions, } from "./vite.js";
6
6
  export { paraglideWebpackPlugin } from "./webpack.js";
7
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,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
+ {"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,EACN,mBAAmB,EACnB,KAAK,0BAA0B,GAC/B,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC"}
@@ -2,6 +2,6 @@ export { paraglideEsbuildPlugin } from "./esbuild.js";
2
2
  export { paraglideRolldownPlugin } from "./rolldown.js";
3
3
  export { paraglideRollupPlugin } from "./rollup.js";
4
4
  export { paraglideRspackPlugin } from "./rspack.js";
5
- export { paraglideVitePlugin } from "./vite.js";
5
+ export { paraglideVitePlugin, } from "./vite.js";
6
6
  export { paraglideWebpackPlugin } from "./webpack.js";
7
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","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
+ {"version":3,"file":"index.js","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,EACN,mBAAmB,GAEnB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,sBAAsB,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const PER_LOCALE_BUILD_MANIFEST = "paraglide-per-locale.json";
2
+ export declare const PER_LOCALE_BUILD_MARKER = "__PARAGLIDE_STATIC_LOCALE__";
3
+ export declare const PER_LOCALE_BUILD_DEFINE = "globalThis.__PARAGLIDE_STATIC_LOCALE__";
4
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/bundler-plugins/per-locale-build/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,yBAAyB,8BAA8B,CAAC;AACrE,eAAO,MAAM,uBAAuB,gCAAgC,CAAC;AACrE,eAAO,MAAM,uBAAuB,2CAA0C,CAAC"}
@@ -0,0 +1,4 @@
1
+ export const PER_LOCALE_BUILD_MANIFEST = "paraglide-per-locale.json";
2
+ export const PER_LOCALE_BUILD_MARKER = "__PARAGLIDE_STATIC_LOCALE__";
3
+ export const PER_LOCALE_BUILD_DEFINE = `globalThis.${PER_LOCALE_BUILD_MARKER}`;
4
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/bundler-plugins/per-locale-build/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,yBAAyB,GAAG,2BAA2B,CAAC;AACrE,MAAM,CAAC,MAAM,uBAAuB,GAAG,6BAA6B,CAAC;AACrE,MAAM,CAAC,MAAM,uBAAuB,GAAG,cAAc,uBAAuB,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=framework-helpers.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"framework-helpers.test.d.ts","sourceRoot":"","sources":["../../../src/bundler-plugins/per-locale-build/framework-helpers.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,57 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { createTanStackStartFramework, getTanStackStartEffectiveRequestUrl, getPerLocaleBuildPrefix, prefixPerLocaleAssetUrl, } from "./frameworks/tanstack-start.js";
3
+ import { getPerLocaleBuildLocaleId } from "./locale-id.js";
4
+ describe("per-locale build paths", () => {
5
+ test("locale ids are readable, filesystem safe, and collision free", () => {
6
+ expect(getPerLocaleBuildLocaleId("de")).toBe("de-6465");
7
+ expect(getPerLocaleBuildLocaleId("pt-BR")).toBe("pt-BR-70742d4252");
8
+ expect(getPerLocaleBuildLocaleId("中文")).toBe("__-e4b8ade69687");
9
+ expect(getPerLocaleBuildLocaleId("en/us")).not.toBe(getPerLocaleBuildLocaleId("en?us"));
10
+ expect(getPerLocaleBuildPrefix("de")).toBe("/__paraglide/de-6465");
11
+ });
12
+ test("prefixes same-origin asset URLs and rejects CDN URLs", () => {
13
+ const prefix = getPerLocaleBuildPrefix("de");
14
+ expect(prefixPerLocaleAssetUrl("/assets/app.js?v=1", prefix)).toBe("/__paraglide/de-6465/assets/app.js?v=1");
15
+ expect(prefixPerLocaleAssetUrl("assets/app.js", prefix)).toBe("/__paraglide/de-6465/assets/app.js");
16
+ expect(() => prefixPerLocaleAssetUrl("https://cdn.example/assets/app.js", prefix)).toThrow("root-relative and relative");
17
+ expect(() => prefixPerLocaleAssetUrl("//cdn.example/assets/app.js", prefix)).toThrow("root-relative and relative");
18
+ expect(prefixPerLocaleAssetUrl("/assets/app.js", "")).toBe("/assets/app.js");
19
+ });
20
+ });
21
+ describe("TanStack Start request locale propagation", () => {
22
+ test("uses a same-origin Referer for a TanStack server-function request", () => {
23
+ const request = new Request("https://example.com/_serverFn/example", {
24
+ headers: {
25
+ Referer: "https://example.com/de/produkte?from=server-fn",
26
+ "x-tsr-serverFn": "true",
27
+ },
28
+ });
29
+ expect(getTanStackStartEffectiveRequestUrl(request).href).toBe("https://example.com/de/produkte?from=server-fn");
30
+ });
31
+ test("does not use Referer for an unmarked navigation without Fetch Metadata", () => {
32
+ const request = new Request("https://example.com/en/products", {
33
+ headers: { Referer: "https://example.com/de/produkte" },
34
+ });
35
+ expect(getTanStackStartEffectiveRequestUrl(request).href).toBe(request.url);
36
+ });
37
+ test.each([
38
+ ["a cross-origin Referer", "https://attacker.example/de"],
39
+ ["an invalid Referer", "not a url"],
40
+ ])("ignores %s", (_label, referer) => {
41
+ const request = new Request("https://example.com/_serverFn/example", {
42
+ headers: { Referer: referer, "x-tsr-serverFn": "true" },
43
+ });
44
+ expect(getTanStackStartEffectiveRequestUrl(request).href).toBe(request.url);
45
+ });
46
+ });
47
+ test("generates one self-contained TanStack Start server adapter", () => {
48
+ const files = createTanStackStartFramework().generatedFiles ?? {};
49
+ const server = files["tanstack-start.server.js"];
50
+ expect(Object.keys(files)).toEqual(["tanstack-start.server.js"]);
51
+ expect(server).not.toContain("@inlang/paraglide-js");
52
+ expect(server).toContain("cache: false");
53
+ expect(server).toContain(getPerLocaleBuildLocaleId.toString());
54
+ expect(server).toContain('from "@tanstack/react-start/server"');
55
+ expect(server).toContain("effectiveRequestUrl: getEffectiveRequestUrl(request)");
56
+ });
57
+ //# sourceMappingURL=framework-helpers.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"framework-helpers.test.js","sourceRoot":"","sources":["../../../src/bundler-plugins/per-locale-build/framework-helpers.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAChD,OAAO,EACN,4BAA4B,EAC5B,mCAAmC,EACnC,uBAAuB,EACvB,uBAAuB,GACvB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,yBAAyB,EAAE,MAAM,gBAAgB,CAAC;AAE3D,QAAQ,CAAC,wBAAwB,EAAE,GAAG,EAAE;IACvC,IAAI,CAAC,8DAA8D,EAAE,GAAG,EAAE;QACzE,MAAM,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACxD,MAAM,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACpE,MAAM,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;QAChE,MAAM,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAClD,yBAAyB,CAAC,OAAO,CAAC,CAClC,CAAC;QACF,MAAM,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IACpE,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,sDAAsD,EAAE,GAAG,EAAE;QACjE,MAAM,MAAM,GAAG,uBAAuB,CAAC,IAAI,CAAC,CAAC;QAC7C,MAAM,CAA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ite";
2
+ import type { PerLocaleBuildFramework } from "../types.js";
3
+ export declare function configurePerLocaleBuild(config: UserConfig): {};
4
+ export declare function detectPerLocaleBuildFramework(config: Pick<ResolvedConfig, "plugins" | "define">): PerLocaleBuildFramework;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/bundler-plugins/per-locale-build/frameworks/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AACvD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAY3D,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,UAAU,MAKzD;AAED,wBAAgB,6BAA6B,CAC5C,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,SAAS,GAAG,QAAQ,CAAC,GAChD,uBAAuB,CAazB"}
@@ -0,0 +1,21 @@
1
+ import { createSvelteKitFramework, hasSvelteKitConfig, hasSvelteKitSetupPlugin, } from "./sveltekit.js";
2
+ import { configureTanStackStartBuild, createTanStackStartFramework, isTanStackStartConfig, } from "./tanstack-start.js";
3
+ export function configurePerLocaleBuild(config) {
4
+ if (hasSvelteKitConfig(config)) {
5
+ return {};
6
+ }
7
+ return configureTanStackStartBuild(config);
8
+ }
9
+ export function detectPerLocaleBuildFramework(config) {
10
+ const hasTanStackStart = isTanStackStartConfig(config);
11
+ const hasSvelteKit = hasSvelteKitSetupPlugin(config);
12
+ if (hasTanStackStart && hasSvelteKit) {
13
+ throw new Error("experimentalPerLocaleBuild found both TanStack Start and SvelteKit Vite plugins. Use it with exactly one supported framework.");
14
+ }
15
+ if (hasTanStackStart)
16
+ return createTanStackStartFramework();
17
+ if (hasSvelteKit)
18
+ return createSvelteKitFramework(config);
19
+ throw new Error("experimentalPerLocaleBuild supports TanStack Start and SvelteKit. Add one of their Vite plugins, or disable this flag.");
20
+ }
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/bundler-plugins/per-locale-build/frameworks/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACN,wBAAwB,EACxB,kBAAkB,EAClB,uBAAuB,GACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,2BAA2B,EAC3B,4BAA4B,EAC5B,qBAAqB,GACrB,MAAM,qBAAqB,CAAC;AAE7B,MAAM,UAAU,uBAAuB,CAAC,MAAkB;IACzD,IAAI,kBAAkB,CAAC,MAAM,CAAC,EAAE,CAAC;QAChC,OAAO,EAAE,CAAC;IACX,CAAC;IACD,OAAO,2BAA2B,CAAC,MAAM,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC5C,MAAkD;IAElD,MAAM,gBAAgB,GAAG,qBAAqB,CAAC,MAAM,CAAC,CAAC;IACvD,MAAM,YAAY,GAAG,uBAAuB,CAAC,MAAM,CAAC,CAAC;IACrD,IAAI,gBAAgB,IAAI,YAAY,EAAE,CAAC;QACtC,MAAM,IAAI,KAAK,CACd,+HAA+H,CAC/H,CAAC;IACH,CAAC;IACD,IAAI,gBAAgB;QAAE,OAAO,4BAA4B,EAAE,CAAC;IAC5D,IAAI,YAAY;QAAE,OAAO,wBAAwB,CAAC,MAAM,CAAC,CAAC;IAC1D,MAAM,IAAI,KAAK,CACd,wHAAwH,CACxH,CAAC;AACH,CAAC"}
@@ -0,0 +1,21 @@
1
+ import type { ResolvedConfig } from "vite";
2
+ import type { PerLocaleBuildFramework, PerLocaleBuildLayout, PerLocaleBuildServerIntegration } from "../types.js";
3
+ export declare const SVELTEKIT_VIRTUAL_MODULE_ID = "virtual:paraglide-per-locale-build/sveltekit";
4
+ export declare const RESOLVED_SVELTEKIT_VIRTUAL_MODULE_ID = "\0virtual:paraglide-per-locale-build/sveltekit";
5
+ export declare function hasSvelteKitSetupPlugin(config: Pick<ResolvedConfig, "plugins">): boolean;
6
+ /** Early config-hook detection before SvelteKit's validated plugin API is available. */
7
+ export declare function hasSvelteKitConfig(config: {
8
+ define?: Record<string, unknown>;
9
+ }): boolean;
10
+ export declare function createSvelteKitFramework(config: Pick<ResolvedConfig, "plugins">): PerLocaleBuildFramework;
11
+ export declare function createSvelteKitLayout(): PerLocaleBuildLayout;
12
+ export declare function createSvelteKitServerIntegration(args: {
13
+ root: string;
14
+ generatedDirectory: string;
15
+ }): PerLocaleBuildServerIntegration;
16
+ export declare function createSvelteKitVirtualModuleSource(args: {
17
+ root: string;
18
+ generatedDirectory: string;
19
+ }): string;
20
+ export declare function patchSvelteKitRenderModule(code: string): string;
21
+ //# sourceMappingURL=sveltekit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sveltekit.d.ts","sourceRoot":"","sources":["../../../../src/bundler-plugins/per-locale-build/frameworks/sveltekit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,cAAc,EAAE,MAAM,MAAM,CAAC;AAGnD,OAAO,KAAK,EACX,uBAAuB,EACvB,oBAAoB,EACpB,+BAA+B,EAC/B,MAAM,aAAa,CAAC;AAGrB,eAAO,MAAM,2BAA2B,iDACO,CAAC;AAChD,eAAO,MAAM,oCAAoC,mDACA,CAAC;AAgBlD,wBAAgB,uBAAuB,CACtC,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,GACrC,OAAO,CAIT;AAED,wFAAwF;AACxF,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IAC1C,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC,GAAG,OAAO,CAEV;AAED,wBAAgB,wBAAwB,CACvC,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,GACrC,uBAAuB,CA+BzB;AAED,wBAAgB,qBAAqB,IAAI,oBAAoB,CAsB5D;AAED,wBAAgB,gCAAgC,CAAC,IAAI,EAAE;IACtD,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB,EAAE,MAAM,CAAC;CAC3B,GAAG,+BAA+B,CAoClC;AAED,wBAAgB,kCAAkC,CAAC,IAAI,EAAE;IACxD,IAAI,EAAE,MAAM,CAAC;IACb,kBAAkB,EAAE,MAAM,CAAC;CAC3B,GAAG,MAAM,CAyBT;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAkB/D"}
@@ -0,0 +1,137 @@
1
+ import nodeFs from "node:fs";
2
+ import path from "node:path";
3
+ import { getPerLocaleBuildLocaleId } from "../locale-id.js";
4
+ export const SVELTEKIT_VIRTUAL_MODULE_ID = "virtual:paraglide-per-locale-build/sveltekit";
5
+ export const RESOLVED_SVELTEKIT_VIRTUAL_MODULE_ID = "\0virtual:paraglide-per-locale-build/sveltekit";
6
+ export function hasSvelteKitSetupPlugin(config) {
7
+ return config.plugins.some((plugin) => plugin.name === "vite-plugin-sveltekit-setup");
8
+ }
9
+ /** Early config-hook detection before SvelteKit's validated plugin API is available. */
10
+ export function hasSvelteKitConfig(config) {
11
+ return Object.hasOwn(config.define ?? {}, "__SVELTEKIT_APP_DIR__");
12
+ }
13
+ export function createSvelteKitFramework(config) {
14
+ const setupPlugin = config.plugins.find((plugin) => plugin.name === "vite-plugin-sveltekit-setup");
15
+ const kit = setupPlugin?.api?.options?.kit;
16
+ if (!kit) {
17
+ throw new Error("experimentalPerLocaleBuild is currently tested with SvelteKit 2.69.x and requires its validated Vite plugin configuration.");
18
+ }
19
+ if (kit.appDir !== "_app" ||
20
+ kit.paths?.base ||
21
+ kit.paths?.assets ||
22
+ kit.output?.bundleStrategy !== "split" ||
23
+ kit.router?.resolution !== "client" ||
24
+ (kit.files?.serviceWorker && svelteKitEntryExists(kit.files.serviceWorker))) {
25
+ throw new Error('experimentalPerLocaleBuild currently supports only the tested SvelteKit 2.69.x defaults: kit.appDir="_app", empty kit.paths.base/assets, kit.output.bundleStrategy="split", kit.router.resolution="client", and no service worker.');
26
+ }
27
+ return {
28
+ layout: createSvelteKitLayout(),
29
+ createServerIntegration({ root, generatedDirectory }) {
30
+ return createSvelteKitServerIntegration({
31
+ root,
32
+ generatedDirectory,
33
+ });
34
+ },
35
+ };
36
+ }
37
+ export function createSvelteKitLayout() {
38
+ const immutablePrefix = "_app/immutable/";
39
+ return {
40
+ validateOutput(fileName, type) {
41
+ if (type === "chunk" && !fileName.startsWith(immutablePrefix)) {
42
+ throw new Error(`experimentalPerLocaleBuild expected every SvelteKit client chunk below ${JSON.stringify(immutablePrefix)}, but found ${JSON.stringify(fileName)}. Only the tested SvelteKit 2.69.x default client output is supported.`);
43
+ }
44
+ },
45
+ getLocalePrefix(locale, baseLocale) {
46
+ return locale === baseLocale
47
+ ? ""
48
+ : `/_app/immutable/__paraglide/${getPerLocaleBuildLocaleId(locale)}`;
49
+ },
50
+ getLocalizedFileName(fileName, locale, baseLocale) {
51
+ if (locale === baseLocale || !fileName.startsWith(immutablePrefix)) {
52
+ return fileName;
53
+ }
54
+ return `${immutablePrefix}__paraglide/${getPerLocaleBuildLocaleId(locale)}/${fileName.slice(immutablePrefix.length)}`;
55
+ },
56
+ };
57
+ }
58
+ export function createSvelteKitServerIntegration(args) {
59
+ let renderPatched = false;
60
+ return {
61
+ resolveId(id) {
62
+ return id === SVELTEKIT_VIRTUAL_MODULE_ID
63
+ ? RESOLVED_SVELTEKIT_VIRTUAL_MODULE_ID
64
+ : undefined;
65
+ },
66
+ load(id) {
67
+ if (id !== RESOLVED_SVELTEKIT_VIRTUAL_MODULE_ID)
68
+ return;
69
+ return createSvelteKitVirtualModuleSource(args);
70
+ },
71
+ transform(code, id) {
72
+ const normalizedId = normalizeModuleId(id.split("?", 1)[0] ?? id);
73
+ if (normalizedId.endsWith("/@sveltejs/kit/src/runtime/server/page/render.js")) {
74
+ renderPatched = true;
75
+ return { code: patchSvelteKitRenderModule(code), map: null };
76
+ }
77
+ return undefined;
78
+ },
79
+ assertPatched() {
80
+ if (!renderPatched) {
81
+ throw new Error("experimentalPerLocaleBuild could not integrate with SvelteKit because its tested 2.69.x server rendering internals were not found.");
82
+ }
83
+ },
84
+ };
85
+ }
86
+ export function createSvelteKitVirtualModuleSource(args) {
87
+ const generatedDirectory = path.resolve(args.root, args.generatedDirectory);
88
+ const runtimeModule = normalizeModuleId(path.join(generatedDirectory, "runtime.js"));
89
+ return [
90
+ `import { baseLocale, getLocale, locales } from ${JSON.stringify(runtimeModule)};`,
91
+ `const getLocaleId = ${getPerLocaleBuildLocaleId.toString()};`,
92
+ "export function localizeSvelteKitAssetPath(path) {",
93
+ "\tconst locale = getLocale();",
94
+ "\tif (locale === baseLocale) return path;",
95
+ '\tconst marker = "_app/immutable/";',
96
+ "\tif (!path.includes(marker)) return path;",
97
+ '\tconst localizedMarker = marker + "__paraglide/" + getLocaleId(locale) + "/";',
98
+ "\treturn path.includes(localizedMarker)",
99
+ "\t\t? path",
100
+ "\t\t: path.replace(marker, localizedMarker);",
101
+ "}",
102
+ "export function assertSvelteKitPerLocaleFallbackSupported(fallback) {",
103
+ "\tif (fallback && locales.length > 1) {",
104
+ '\t\tthrow new Error("experimentalPerLocaleBuild does not support SvelteKit SPA fallback pages because one fallback cannot select a request-locale client graph. Use SSR or prerender every locale-specific page.");',
105
+ "\t}",
106
+ "}",
107
+ "",
108
+ ].join("\n");
109
+ }
110
+ export function patchSvelteKitRenderModule(code) {
111
+ const marker = "const prefixed = (path) => {";
112
+ const renderResponseMarker = "}) {\n\tif (state.prerendering) {";
113
+ assertSingleSvelteKitMarker(code, marker, "server/page/render.js");
114
+ assertSingleSvelteKitMarker(code, renderResponseMarker, "server/page/render.js");
115
+ return `${svelteKitVirtualImport}\n${code
116
+ .replace(renderResponseMarker, `}) {\n\t__paraglideAssertSvelteKitPerLocaleFallbackSupported(state.prerendering?.fallback);\n\n\tif (state.prerendering) {`)
117
+ .replace(marker, `${marker}\n\t\tpath = __paraglideLocalizeSvelteKitAssetPath(path);`)}`;
118
+ }
119
+ const svelteKitVirtualImport = `import { assertSvelteKitPerLocaleFallbackSupported as __paraglideAssertSvelteKitPerLocaleFallbackSupported, localizeSvelteKitAssetPath as __paraglideLocalizeSvelteKitAssetPath } from ${JSON.stringify(SVELTEKIT_VIRTUAL_MODULE_ID)};`;
120
+ function assertSingleSvelteKitMarker(code, marker, moduleName) {
121
+ if (code.split(marker).length !== 2) {
122
+ throw new Error(`experimentalPerLocaleBuild cannot patch this SvelteKit ${moduleName}; its internal asset rendering differs from the tested SvelteKit 2.69.x implementation.`);
123
+ }
124
+ }
125
+ function normalizeModuleId(id) {
126
+ return id.replaceAll("\\", "/");
127
+ }
128
+ function svelteKitEntryExists(entry) {
129
+ return [
130
+ entry,
131
+ `${entry}.js`,
132
+ `${entry}.ts`,
133
+ path.join(entry, "index.js"),
134
+ path.join(entry, "index.ts"),
135
+ ].some((candidate) => nodeFs.existsSync(candidate) && nodeFs.statSync(candidate).isFile());
136
+ }
137
+ //# sourceMappingURL=sveltekit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sveltekit.js","sourceRoot":"","sources":["../../../../src/bundler-plugins/per-locale-build/frameworks/sveltekit.ts"],"names":[],"mappings":"AACA,OAAO,MAAM,MAAM,SAAS,CAAC;AAC7B,OAAO,IAAI,MAAM,WAAW,CAAC;AAM7B,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,MAAM,CAAC,MAAM,2BAA2B,GACvC,8CAA8C,CAAC;AAChD,MAAM,CAAC,MAAM,oCAAoC,GAChD,gDAAgD,CAAC;AAgBlD,MAAM,UAAU,uBAAuB,CACtC,MAAuC;IAEvC,OAAO,MAAM,CAAC,OAAO,CAAC,IAAI,CACzB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,6BAA6B,CACzD,CAAC;AACH,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,kBAAkB,CAAC,MAElC;IACA,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,IAAI,EAAE,EAAE,uBAAuB,C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N,GAAG,MAAM,2DAA2D,CACpE,EAAE,CAAC;AACN,CAAC;AAED,MAAM,sBAAsB,GAAG,0LAA0L,IAAI,CAAC,SAAS,CAAC,2BAA2B,CAAC,GAAG,CAAC;AAExQ,SAAS,2BAA2B,CACnC,IAAY,EACZ,MAAc,EACd,UAAkB;IAElB,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACrC,MAAM,IAAI,KAAK,CACd,0DAA0D,UAAU,yFAAyF,CAC7J,CAAC;IACH,CAAC;AACF,CAAC;AAED,SAAS,iBAAiB,CAAC,EAAU;IACpC,OAAO,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACjC,CAAC;AAED,SAAS,oBAAoB,CAAC,KAAa;IAC1C,OAAO;QACN,KAAK;QACL,GAAG,KAAK,KAAK;QACb,GAAG,KAAK,KAAK;QACb,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC;QAC5B,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,UAAU,CAAC;KAC5B,CAAC,IAAI,CACL,CAAC,SAAS,EAAE,EAAE,CACb,MAAM,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC,MAAM,EAAE,CACpE,CAAC;AACH,CAAC"}
@@ -0,0 +1,23 @@
1
+ import type { ResolvedConfig } from "vite";
2
+ import type { PerLocaleBuildFramework } from "../types.js";
3
+ export declare const PER_LOCALE_BUILD_ASSET_PREFIX = "/__paraglide";
4
+ export declare function getPerLocaleBuildPrefix(locale: string): string;
5
+ export declare function prefixPerLocaleAssetUrl(url: string, prefix: string): string;
6
+ export declare function getTanStackStartEffectiveRequestUrl(request: Request): URL;
7
+ export declare function isTanStackStartConfig(config: Pick<ResolvedConfig, "plugins">): boolean;
8
+ export declare function createTanStackStartFramework(): PerLocaleBuildFramework;
9
+ export declare function configureTanStackStartBuild(config: {
10
+ experimental?: {
11
+ renderBuiltUrl?: unknown;
12
+ };
13
+ }): {
14
+ base: string;
15
+ experimental: {
16
+ renderBuiltUrl(filename: string, context: {
17
+ ssr?: boolean;
18
+ }): string | {
19
+ relative: true;
20
+ };
21
+ };
22
+ };
23
+ //# sourceMappingURL=tanstack-start.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tanstack-start.d.ts","sourceRoot":"","sources":["../../../../src/bundler-plugins/per-locale-build/frameworks/tanstack-start.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAG3D,eAAO,MAAM,6BAA6B,iBAAiB,CAAC;AAE5D,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAE9D;AAED,wBAAgB,uBAAuB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAQ3E;AAED,wBAAgB,mCAAmC,CAAC,OAAO,EAAE,OAAO,GAAG,GAAG,CAWzE;AAED,wBAAgB,qBAAqB,CACpC,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,SAAS,CAAC,GACrC,OAAO,CAIT;AAED,wBAAgB,4BAA4B,IAAI,uBAAuB,CAetE;AAED,wBAAgB,2BAA2B,CAAC,MAAM,EAAE;IACnD,YAAY,CAAC,EAAE;QAAE,cAAc,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CAC5C;IAOC,IAAI;IACJ,YAAY;QACX,cAAc,WAAW,MAAM,WAAW;YAAE,GAAG,CAAC,EAAE,OAAO,CAAA;SAAE;;;;EAM7D"}
@@ -0,0 +1,104 @@
1
+ import { getPerLocaleBuildLocaleId } from "../locale-id.js";
2
+ export const PER_LOCALE_BUILD_ASSET_PREFIX = "/__paraglide";
3
+ export function getPerLocaleBuildPrefix(locale) {
4
+ return `${PER_LOCALE_BUILD_ASSET_PREFIX}/${getPerLocaleBuildLocaleId(locale)}`;
5
+ }
6
+ export function prefixPerLocaleAssetUrl(url, prefix) {
7
+ if (url.startsWith("//") || /^[A-Za-z][A-Za-z\d+.-]*:/.test(url)) {
8
+ throw new Error("experimentalPerLocaleBuild supports only root-relative and relative TanStack Start asset URLs.");
9
+ }
10
+ if (prefix === "")
11
+ return url;
12
+ return `${prefix}/${url.replace(/^\/+/, "")}`;
13
+ }
14
+ export function getTanStackStartEffectiveRequestUrl(request) {
15
+ const requestUrl = new URL(request.url);
16
+ if (request.headers.get("x-tsr-serverFn") !== "true")
17
+ return requestUrl;
18
+ const referer = request.headers.get("Referer");
19
+ if (referer === null)
20
+ return requestUrl;
21
+ try {
22
+ const refererUrl = new URL(referer);
23
+ return refererUrl.origin === requestUrl.origin ? refererUrl : requestUrl;
24
+ }
25
+ catch {
26
+ return requestUrl;
27
+ }
28
+ }
29
+ export function isTanStackStartConfig(config) {
30
+ return config.plugins.some((plugin) => plugin.name === "tanstack-start-core:config");
31
+ }
32
+ export function createTanStackStartFramework() {
33
+ return {
34
+ generatedFiles: {
35
+ "tanstack-start.server.js": tanstackStartServerRuntime,
36
+ },
37
+ layout: {
38
+ getLocalePrefix(locale, baseLocale) {
39
+ return locale === baseLocale ? "" : getPerLocaleBuildPrefix(locale);
40
+ },
41
+ getLocalizedFileName(fileName, locale, baseLocale) {
42
+ if (locale === baseLocale)
43
+ return fileName;
44
+ return `${getPerLocaleBuildPrefix(locale).replace(/^\//, "")}/${fileName}`;
45
+ },
46
+ },
47
+ };
48
+ }
49
+ export function configureTanStackStartBuild(config) {
50
+ if (config.experimental?.renderBuiltUrl) {
51
+ throw new Error("experimentalPerLocaleBuild cannot be combined with experimental.renderBuiltUrl because locale asset trees require relative client URLs and canonical SSR URLs.");
52
+ }
53
+ return {
54
+ base: "",
55
+ experimental: {
56
+ renderBuiltUrl(filename, context) {
57
+ if (context.ssr)
58
+ return `/${filename.replace(/^\/+/, "")}`;
59
+ return { relative: true };
60
+ },
61
+ },
62
+ };
63
+ }
64
+ const tanstackStartServerRuntime = String.raw `
65
+ // @ts-nocheck -- generated only for experimentalPerLocaleBuild on TanStack Start
66
+ import {
67
+ createStartHandler,
68
+ defaultStreamHandler,
69
+ } from "@tanstack/react-start/server";
70
+ import { baseLocale, getLocale } from "./runtime.js";
71
+ import { paraglideMiddleware } from "./server.js";
72
+
73
+ const getPerLocaleBuildLocaleId = ${getPerLocaleBuildLocaleId.toString()};
74
+ const PER_LOCALE_BUILD_ASSET_PREFIX = "/__paraglide";
75
+ const getLocalePrefix = ${getPerLocaleBuildPrefix.toString()};
76
+ const prefixAssetUrl = ${prefixPerLocaleAssetUrl.toString()};
77
+ const getEffectiveRequestUrl = ${getTanStackStartEffectiveRequestUrl.toString()};
78
+
79
+ const fetch = createStartHandler({
80
+ handler: defaultStreamHandler,
81
+ transformAssets: {
82
+ cache: false,
83
+ createTransform() {
84
+ const locale = getLocale();
85
+ const prefix =
86
+ import.meta.env?.PROD === true && locale !== baseLocale
87
+ ? getLocalePrefix(locale)
88
+ : "";
89
+ return ({ url }) => prefixAssetUrl(url, prefix);
90
+ },
91
+ },
92
+ });
93
+
94
+ export default {
95
+ fetch(request, ...args) {
96
+ return paraglideMiddleware(
97
+ request,
98
+ () => fetch(request, ...args),
99
+ { effectiveRequestUrl: getEffectiveRequestUrl(request) },
100
+ );
101
+ },
102
+ };
103
+ `.trimStart();
104
+ //# sourceMappingURL=tanstack-start.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tanstack-start.js","sourceRoot":"","sources":["../../../../src/bundler-plugins/per-locale-build/frameworks/tanstack-start.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AAE5D,MAAM,CAAC,MAAM,6BAA6B,GAAG,cAAc,CAAC;AAE5D,MAAM,UAAU,uBAAuB,CAAC,MAAc;IACrD,OAAO,GAAG,6BAA6B,IAAI,yBAAyB,CAAC,MAAM,CAA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ions } from "../../compiler/compiler-options.js";
3
+ export declare function createPerLocaleBuildPlugins(args: {
4
+ compilerOptions: CompilerOptions;
5
+ createCompilerPlugin: (options: CompilerOptions) => Plugin;
6
+ }): Plugin[];
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/bundler-plugins/per-locale-build/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAK1E,wBAAgB,2BAA2B,CAAC,IAAI,EAAE;IACjD,eAAe,EAAE,eAAe,CAAC;IACjC,oBAAoB,EAAE,CAAC,OAAO,EAAE,eAAe,KAAK,MAAM,CAAC;CAC3D,GAAG,MAAM,EAAE,CAgCX"}
@@ -0,0 +1,76 @@
1
+ import nodeFs from "node:fs";
2
+ import { loadProjectFromDirectory } from "@inlang/sdk";
3
+ import { perLocaleBuildStaticLocaleExpression } from "../../compiler/per-locale-build.js";
4
+ import { createPerLocaleBuildVitePlugin } from "./vite-plugin.js";
5
+ export function createPerLocaleBuildPlugins(args) {
6
+ const { compilerOptions } = args;
7
+ validateCompilerOptions(compilerOptions);
8
+ const perLocaleCompilerOptions = {
9
+ ...compilerOptions,
10
+ outputStructure: compilerOptions.outputStructure ?? "message-modules",
11
+ experimentalStaticLocale: perLocaleBuildStaticLocaleExpression,
12
+ additionalFiles: {
13
+ ...compilerOptions.additionalFiles,
14
+ },
15
+ };
16
+ return [
17
+ args.createCompilerPlugin(perLocaleCompilerOptions),
18
+ createPerLocaleBuildVitePlugin({
19
+ // Reload settings for every client build so Vite build --watch picks up
20
+ // locale additions/removals instead of reusing the first build's project.
21
+ settings: () => loadSettings(perLocaleCompilerOptions),
22
+ generatedDirectory: perLocaleCompilerOptions.outdir,
23
+ onFrameworkDetected(frameworkFiles) {
24
+ assertGeneratedFilesAvailable(frameworkFiles, compilerOptions.additionalFiles);
25
+ perLocaleCompilerOptions.additionalFiles = {
26
+ ...perLocaleCompilerOptions.additionalFiles,
27
+ ...frameworkFiles,
28
+ };
29
+ },
30
+ }),
31
+ ];
32
+ }
33
+ function validateCompilerOptions(options) {
34
+ if (options.strategy !== undefined &&
35
+ options.strategy[0] !== "url" &&
36
+ options.strategy[0] !== "cookie") {
37
+ throw new Error('experimentalPerLocaleBuild requires the first locale strategy to be "url" or "cookie".');
38
+ }
39
+ if (options.routeStrategies !== undefined) {
40
+ throw new Error("experimentalPerLocaleBuild does not support routeStrategies.");
41
+ }
42
+ if (options.experimentalStaticLocale !== undefined) {
43
+ throw new Error("experimentalPerLocaleBuild cannot be combined with experimentalStaticLocale because it controls the compiler's static locale expression.");
44
+ }
45
+ if (options.experimentalMiddlewareLocaleSplitting) {
46
+ throw new Error("experimentalPerLocaleBuild cannot be combined with experimentalMiddlewareLocaleSplitting.");
47
+ }
48
+ if (options.outputStructure !== undefined &&
49
+ options.outputStructure !== "message-modules") {
50
+ throw new Error('experimentalPerLocaleBuild currently requires outputStructure: "message-modules".');
51
+ }
52
+ }
53
+ function assertGeneratedFilesAvailable(generatedFiles, additionalFiles) {
54
+ for (const fileName of Object.keys(generatedFiles)) {
55
+ if (Object.hasOwn(additionalFiles ?? {}, fileName)) {
56
+ throw new Error(`experimentalPerLocaleBuild needs to generate ${JSON.stringify(fileName)}, but additionalFiles already defines that path.`);
57
+ }
58
+ }
59
+ }
60
+ async function loadSettings(options) {
61
+ const project = await loadProjectFromDirectory({
62
+ path: options.project,
63
+ fs: options.fs ?? nodeFs,
64
+ });
65
+ try {
66
+ const settings = await project.settings.get();
67
+ return {
68
+ baseLocale: settings.baseLocale,
69
+ locales: [...settings.locales],
70
+ };
71
+ }
72
+ finally {
73
+ await project.close();
74
+ }
75
+ }
76
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/bundler-plugins/per-locale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,CAAC;SAC9B,CAAC;IACH,CAAC;YAAS,CAAC;QACV,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;IACvB,CAAC;AACF,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Returns a readable, filesystem-safe, collision-free identifier for a locale.
3
+ *
4
+ * The readable part is only for diagnostics. The complete UTF-8 hex suffix is
5
+ * what guarantees that two different locale strings never share an output
6
+ * directory, including locales which differ only by punctuation or Unicode.
7
+ */
8
+ export declare function getPerLocaleBuildLocaleId(locale: string): string;
9
+ //# sourceMappingURL=locale-id.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale-id.d.ts","sourceRoot":"","sources":["../../../src/bundler-plugins/per-locale-build/locale-id.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAMhE"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Returns a readable, filesystem-safe, collision-free identifier for a locale.
3
+ *
4
+ * The readable part is only for diagnostics. The complete UTF-8 hex suffix is
5
+ * what guarantees that two different locale strings never share an output
6
+ * directory, including locales which differ only by punctuation or Unicode.
7
+ */
8
+ export function getPerLocaleBuildLocaleId(locale) {
9
+ const readable = locale.replace(/[^A-Za-z0-9_-]/g, "_") || "locale";
10
+ const hex = Array.from(new TextEncoder().encode(locale), (byte) => byte.toString(16).padStart(2, "0")).join("");
11
+ return `${readable}-${hex}`;
12
+ }
13
+ //# sourceMappingURL=locale-id.js.map