@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"locale-id.js","sourceRoot":"","sources":["../../../src/bundler-plugins/per-locale-build/locale-id.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,UAAU,yBAAyB,CAAC,MAAc;IACvD,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,EAAE,GAAG,CAAC,IAAI,QAAQ,CAAC;IACpE,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CACjE,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAClC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACX,OAAO,GAAG,QAAQ,IAAI,GAAG,EAAE,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { OutputBundle } from "rolldown";
2
+ import type { PerLocaleBuildLayout, PerLocaleBuildManifest, PerLocaleBuildSettings, ViteOxcApi } from "./types.js";
3
+ export declare function specializePerLocaleBundle(args: {
4
+ bundle: OutputBundle;
5
+ layout: PerLocaleBuildLayout;
6
+ settings: PerLocaleBuildSettings;
7
+ vite: ViteOxcApi;
8
+ }): Promise<{
9
+ manifest: PerLocaleBuildManifest;
10
+ assets: Array<{
11
+ fileName: string;
12
+ source: string | Uint8Array;
13
+ }>;
14
+ }>;
15
+ export declare function loadViteOxcApi(): Promise<ViteOxcApi>;
16
+ export declare function assertVite8OxcApi(vite: Partial<ViteOxcApi>): asserts vite is ViteOxcApi;
17
+ export declare function validatePerLocaleBuildSettings(settings: PerLocaleBuildSettings): PerLocaleBuildSettings;
18
+ //# sourceMappingURL=specialize-bundle.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"specialize-bundle.d.ts","sourceRoot":"","sources":["../../../src/bundler-plugins/per-locale-build/specialize-bundle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAO7C,OAAO,KAAK,EACX,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,EACtB,UAAU,EACV,MAAM,YAAY,CAAC;AAEpB,wBAAsB,yBAAyB,CAAC,IAAI,EAAE;IACrD,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,oBAAoB,CAAC;IAC7B,QAAQ,EAAE,sBAAsB,CAAC;IACjC,IAAI,EAAE,UAAU,CAAC;CACjB,GAAG,OAAO,CAAC;IACX,QAAQ,EAAE,sBAAsB,CAAC;IACjC,MAAM,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAA;KAAE,CAAC,CAAC;CACjE,CAAC,CAsGD;AAuGD,wBAAsB,cAAc,IAAI,OAAO,CAAC,UAAU,CAAC,CAS1D;AAED,wBAAgB,iBAAiB,CAChC,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,GACvB,OAAO,CAAC,IAAI,IAAI,UAAU,CAY5B;AAED,wBAAgB,8BAA8B,CAC7C,QAAQ,EAAE,sBAAsB,GAC9B,sBAAsB,CAsBxB"}
@@ -0,0 +1,184 @@
1
+ import path from "node:path";
2
+ import { PER_LOCALE_BUILD_DEFINE, PER_LOCALE_BUILD_MANIFEST, PER_LOCALE_BUILD_MARKER, } from "./constants.js";
3
+ export async function specializePerLocaleBundle(args) {
4
+ const settings = validatePerLocaleBuildSettings(args.settings);
5
+ assertVite8OxcApi(args.vite);
6
+ const originals = Object.entries(args.bundle)
7
+ .filter(([fileName]) => fileName !== PER_LOCALE_BUILD_MANIFEST)
8
+ .sort(([left], [right]) => left.localeCompare(right))
9
+ .map(([fileName, output]) => ({
10
+ fileName,
11
+ output,
12
+ // Base-locale specialization mutates the canonical OutputChunk. Every
13
+ // locale must nevertheless start from this immutable source graph.
14
+ code: output.type === "chunk" ? output.code : undefined,
15
+ }));
16
+ const originalFileNames = originals.map(({ fileName }) => fileName);
17
+ const originalFileNameSet = new Set(originalFileNames);
18
+ for (const { fileName, output } of originals) {
19
+ args.layout.validateOutput?.(fileName, output.type);
20
+ }
21
+ for (const { fileName, output } of originals) {
22
+ if (output.type !== "asset" || !fileName.endsWith(".css"))
23
+ continue;
24
+ output.source = rewriteCssPublicAssetReferences({
25
+ source: output.source,
26
+ fileName,
27
+ originalFileNames: originalFileNameSet,
28
+ });
29
+ }
30
+ const manifest = {
31
+ version: 1,
32
+ baseLocale: settings.baseLocale,
33
+ locales: {},
34
+ };
35
+ for (const locale of settings.locales) {
36
+ manifest.locales[locale] = {
37
+ prefix: args.layout.getLocalePrefix(locale, settings.baseLocale),
38
+ assets: Object.fromEntries(originalFileNames.map((fileName) => [
39
+ `/${fileName}`,
40
+ `/${args.layout.getLocalizedFileName(fileName, locale, settings.baseLocale)}`,
41
+ ])),
42
+ };
43
+ }
44
+ const localizedAssets = [];
45
+ const emittedFileNames = new Set(Object.keys(args.bundle));
46
+ for (const locale of settings.locales) {
47
+ const specializedChunks = new Map();
48
+ await Promise.all(originals.map(async ({ fileName, output, code }) => {
49
+ if (output.type !== "chunk")
50
+ return;
51
+ specializedChunks.set(fileName, await specializeChunk({
52
+ code: code,
53
+ fileName,
54
+ locale,
55
+ vite: args.vite,
56
+ }));
57
+ }));
58
+ for (const { fileName, output } of originals) {
59
+ const specializedCode = output.type === "chunk" ? specializedChunks.get(fileName) : undefined;
60
+ if (output.type === "chunk" && specializedCode === undefined) {
61
+ throw new Error(`Failed to specialize Vite chunk ${fileName}.`);
62
+ }
63
+ if (locale === settings.baseLocale) {
64
+ if (output.type === "chunk") {
65
+ output.code = specializedCode;
66
+ output.map = null;
67
+ }
68
+ continue;
69
+ }
70
+ const localizedFileName = args.layout.getLocalizedFileName(fileName, locale, settings.baseLocale);
71
+ if (localizedFileName === fileName)
72
+ continue;
73
+ if (emittedFileNames.has(localizedFileName)) {
74
+ throw new Error(`experimentalPerLocaleBuild cannot emit ${localizedFileName} because another Vite plugin already emitted that file.`);
75
+ }
76
+ emittedFileNames.add(localizedFileName);
77
+ localizedAssets.push({
78
+ fileName: localizedFileName,
79
+ source: output.type === "chunk" ? specializedCode : output.source,
80
+ });
81
+ }
82
+ }
83
+ return { manifest, assets: localizedAssets };
84
+ }
85
+ function rewriteCssPublicAssetReferences(args) {
86
+ let css;
87
+ if (typeof args.source === "string") {
88
+ css = args.source;
89
+ }
90
+ else {
91
+ css = new TextDecoder().decode(args.source);
92
+ }
93
+ const rewrite = (reference) => {
94
+ if (!isRelativeCssReference(reference))
95
+ return reference;
96
+ const suffixIndex = reference.search(/[?#]/);
97
+ const pathname = suffixIndex === -1 ? reference : reference.slice(0, suffixIndex);
98
+ const suffix = suffixIndex === -1 ? "" : reference.slice(suffixIndex);
99
+ const canonicalPath = path.posix.normalize(path.posix.join("/", path.posix.dirname(args.fileName), pathname));
100
+ if (args.originalFileNames.has(canonicalPath.replace(/^\//, ""))) {
101
+ return reference;
102
+ }
103
+ return `${canonicalPath}${suffix}`;
104
+ };
105
+ css = css.replace(/url\(\s*(?:(["'])(.*?)\1|([^"')]+))\s*\)/g, (full, quote, quoted, unquoted) => {
106
+ const reference = (quote ? quoted : unquoted).trim();
107
+ const rewritten = rewrite(reference);
108
+ return rewritten === reference
109
+ ? full
110
+ : `url(${quote ?? ""}${rewritten}${quote ?? ""})`;
111
+ });
112
+ css = css.replace(/@import\s+(["'])(.*?)\1/g, (full, quote, reference) => {
113
+ const rewritten = rewrite(reference);
114
+ return rewritten === reference
115
+ ? full
116
+ : `@import ${quote}${rewritten}${quote}`;
117
+ });
118
+ return typeof args.source === "string" ? css : new TextEncoder().encode(css);
119
+ }
120
+ function isRelativeCssReference(reference) {
121
+ return (reference !== "" &&
122
+ !reference.startsWith("/") &&
123
+ !reference.startsWith("#") &&
124
+ !reference.startsWith("?") &&
125
+ !reference.startsWith("//") &&
126
+ !reference.startsWith("var(") &&
127
+ !reference.startsWith("data:") &&
128
+ !/^[A-Za-z][A-Za-z\d+.-]*:/.test(reference));
129
+ }
130
+ async function specializeChunk(args) {
131
+ const transformed = await args.vite.transformWithOxc(args.code, args.fileName, {
132
+ lang: "js",
133
+ sourceType: "module",
134
+ define: {
135
+ [PER_LOCALE_BUILD_DEFINE]: JSON.stringify(args.locale),
136
+ },
137
+ sourcemap: false,
138
+ });
139
+ const minified = await args.vite.minify(args.fileName, transformed.code, {
140
+ module: true,
141
+ compress: true,
142
+ mangle: true,
143
+ });
144
+ if (minified.errors.length > 0) {
145
+ throw new Error(`Oxc failed to minify ${args.fileName} for locale ${JSON.stringify(args.locale)}: ${minified.errors.map((error) => error.message).join("\n")}`);
146
+ }
147
+ if (minified.code.includes(PER_LOCALE_BUILD_MARKER)) {
148
+ throw new Error(`Oxc left ${PER_LOCALE_BUILD_MARKER} in ${args.fileName} for locale ${JSON.stringify(args.locale)}.`);
149
+ }
150
+ return minified.code;
151
+ }
152
+ export async function loadViteOxcApi() {
153
+ try {
154
+ return await import("vite");
155
+ }
156
+ catch (error) {
157
+ throw new Error("experimentalPerLocaleBuild requires Vite 8 to be installed in the application.", { cause: error });
158
+ }
159
+ }
160
+ export function assertVite8OxcApi(vite) {
161
+ const major = Number.parseInt(vite.version?.split(".")[0] ?? "", 10);
162
+ if (!Number.isFinite(major) ||
163
+ major !== 8 ||
164
+ typeof vite.transformWithOxc !== "function" ||
165
+ typeof vite.minify !== "function") {
166
+ throw new Error(`experimentalPerLocaleBuild requires Vite 8 with the Oxc transform and minify APIs (received ${vite.version ?? "an unknown version"}).`);
167
+ }
168
+ }
169
+ export function validatePerLocaleBuildSettings(settings) {
170
+ if (!settings.baseLocale) {
171
+ throw new Error("experimentalPerLocaleBuild requires the inlang project to define a baseLocale.");
172
+ }
173
+ if (!Array.isArray(settings.locales) || settings.locales.length === 0) {
174
+ throw new Error("experimentalPerLocaleBuild requires the inlang project to define at least one locale.");
175
+ }
176
+ if (!settings.locales.includes(settings.baseLocale)) {
177
+ throw new Error(`experimentalPerLocaleBuild baseLocale ${JSON.stringify(settings.baseLocale)} is not present in the project's locales.`);
178
+ }
179
+ if (new Set(settings.locales).size !== settings.locales.length) {
180
+ throw new Error("experimentalPerLocaleBuild requires every project locale to be unique.");
181
+ }
182
+ return settings;
183
+ }
184
+ //# sourceMappingURL=specialize-bundle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"specialize-bundle.js","sourceRoot":"","sources":["../../../src/bundler-plugins/per-locale-build/specialize-bundle.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACN,uBAAuB,EACvB,yBAAyB,EACzB,uBAAuB,GACvB,MAAM,gBAAgB,CAAC;AAQxB,MAAM,CAAC,KAAK,UAAU,yBAAyB,CAAC,IAK/C;IAIA,MAAM,QAAQ,GAAG,8BAA8B,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC/D,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE7B,MAAM,SAAS,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;SAC3C,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC,QAAQ,KAAK,yBAAyB,CAAC;SAC9D,IAAI,C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AI,KAAK,CACd,wEAAwE,CACxE,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC;AACjB,CAAC"}
@@ -0,0 +1,42 @@
1
+ export type PerLocaleBuildSettings = {
2
+ baseLocale: string;
3
+ locales: string[];
4
+ };
5
+ export type PerLocaleBuildManifest = {
6
+ version: 1;
7
+ baseLocale: string;
8
+ locales: Record<string, {
9
+ /** Public URL prefix. Empty for the canonical/base-locale build. */
10
+ prefix: string;
11
+ /** Canonical public URL to locale-specific public URL. */
12
+ assets: Record<string, string>;
13
+ }>;
14
+ };
15
+ export type ViteOxcApi = Pick<typeof import("vite"), "version" | "transformWithOxc" | "minify">;
16
+ /** Framework-neutral description of a client bundle's output namespace. */
17
+ export type PerLocaleBuildLayout = {
18
+ /** Reject unsupported framework output before specialization begins. */
19
+ validateOutput?: (fileName: string, type: "asset" | "chunk") => void;
20
+ getLocalePrefix: (locale: string, baseLocale: string) => string;
21
+ /** Returning the original filename keeps that output locale-neutral. */
22
+ getLocalizedFileName: (fileName: string, locale: string, baseLocale: string) => string;
23
+ };
24
+ export type PerLocaleBuildServerIntegration = {
25
+ resolveId: (id: string) => string | undefined;
26
+ load: (id: string) => string | undefined;
27
+ transform: (code: string, id: string) => {
28
+ code: string;
29
+ map: null;
30
+ } | undefined;
31
+ assertPatched: () => void;
32
+ };
33
+ /** Framework policy consumed by the Vite lifecycle orchestrator. */
34
+ export type PerLocaleBuildFramework = {
35
+ layout: PerLocaleBuildLayout;
36
+ generatedFiles?: Record<string, string>;
37
+ createServerIntegration?: (args: {
38
+ root: string;
39
+ generatedDirectory: string;
40
+ }) => PerLocaleBuildServerIntegration;
41
+ };
42
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/bundler-plugins/per-locale-build/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,sBAAsB,GAAG;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EA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uB,GAAG;IACrC,MAAM,EAAE,oBAAoB,CAAC;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACxC,uBAAuB,CAAC,EAAE,CAAC,IAAI,EAAE;QAChC,IAAI,EAAE,MAAM,CAAC;QACb,kBAAkB,EAAE,MAAM,CAAC;KAC3B,KAAK,+BAA+B,CAAC;CACtC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/bundler-plugins/per-locale-build/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ import type { Plugin } from "vite";
2
+ import type { PerLocaleBuildSettings, ViteOxcApi } from "./types.js";
3
+ export declare function createPerLocaleBuildVitePlugin(args: {
4
+ settings: () => Promise<PerLocaleBuildSettings>;
5
+ generatedDirectory: string;
6
+ loadVite?: () => Promise<ViteOxcApi>;
7
+ onFrameworkDetected?: (generatedFiles: Record<string, string>) => void;
8
+ }): Plugin;
9
+ //# sourceMappingURL=vite-plugin.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../../../src/bundler-plugins/per-locale-build/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AAanC,OAAO,KAAK,EAGX,sBAAsB,EACtB,UAAU,EACV,MAAM,YAAY,CAAC;AAEpB,wBAAgB,8BAA8B,CAAC,IAAI,EAAE;IACpD,QAAQ,EAAE,MAAM,OAAO,CAAC,sBAAsB,CAAC,CAAC;IAChD,kBAAkB,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IACrC,mBAAmB,CAAC,EAAE,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;CACvE,GAAG,MAAM,CAsFT"}
@@ -0,0 +1,87 @@
1
+ import { PER_LOCALE_BUILD_DEFINE, PER_LOCALE_BUILD_MANIFEST, } from "./constants.js";
2
+ import { configurePerLocaleBuild, detectPerLocaleBuildFramework, } from "./frameworks/index.js";
3
+ import { loadViteOxcApi, specializePerLocaleBundle, } from "./specialize-bundle.js";
4
+ export function createPerLocaleBuildVitePlugin(args) {
5
+ let framework;
6
+ let serverIntegration;
7
+ return {
8
+ name: "paraglide-per-locale-build",
9
+ enforce: "post",
10
+ config(config, env) {
11
+ if (env.command !== "build")
12
+ return;
13
+ if (![undefined, "", "/", "./"].includes(config.base)) {
14
+ throw new Error("experimentalPerLocaleBuild does not support a custom Vite base.");
15
+ }
16
+ assertSupportedClientBuild(config.build);
17
+ return configurePerLocaleBuild(config);
18
+ },
19
+ configEnvironment(name, config, env) {
20
+ const isClient = env.command === "build" &&
21
+ (config.consumer === "client" || name === "client");
22
+ if (!isClient) {
23
+ return {
24
+ define: { [PER_LOCALE_BUILD_DEFINE]: "undefined" },
25
+ };
26
+ }
27
+ assertSupportedClientBuild(config.build);
28
+ return { build: { minify: false, sourcemap: false } };
29
+ },
30
+ configResolved(config) {
31
+ framework = detectPerLocaleBuildFramework(config);
32
+ args.onFrameworkDetected?.(framework.generatedFiles ?? {});
33
+ serverIntegration = framework.createServerIntegration?.({
34
+ root: config.root,
35
+ generatedDirectory: args.generatedDirectory,
36
+ });
37
+ },
38
+ resolveId(id) {
39
+ return serverIntegration?.resolveId(id);
40
+ },
41
+ load(id) {
42
+ return serverIntegration?.load(id);
43
+ },
44
+ transform(code, id, options) {
45
+ if (!serverIntegration || options?.ssr === false)
46
+ return;
47
+ return serverIntegration.transform(code, id);
48
+ },
49
+ generateBundle: {
50
+ order: "post",
51
+ async handler(_outputOptions, bundle) {
52
+ const isClient = this.environment.config.consumer === "client";
53
+ if (!isClient) {
54
+ serverIntegration?.assertPatched();
55
+ return;
56
+ }
57
+ if (!framework) {
58
+ throw new Error("experimentalPerLocaleBuild could not identify the active framework.");
59
+ }
60
+ const specialized = await specializePerLocaleBundle({
61
+ bundle,
62
+ layout: framework.layout,
63
+ settings: await args.settings(),
64
+ vite: await (args.loadVite ?? loadViteOxcApi)(),
65
+ });
66
+ for (const asset of specialized.assets) {
67
+ this.emitFile({
68
+ type: "asset",
69
+ fileName: asset.fileName,
70
+ source: asset.source,
71
+ });
72
+ }
73
+ this.emitFile({
74
+ type: "asset",
75
+ fileName: PER_LOCALE_BUILD_MANIFEST,
76
+ source: JSON.stringify(specialized.manifest, undefined, "\t") + "\n",
77
+ });
78
+ },
79
+ },
80
+ };
81
+ }
82
+ function assertSupportedClientBuild(build) {
83
+ if (build?.minify === false || build?.sourcemap) {
84
+ throw new Error("experimentalPerLocaleBuild requires client minification and does not support client sourcemaps.");
85
+ }
86
+ }
87
+ //# sourceMappingURL=vite-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../../../src/bundler-plugins/per-locale-build/vite-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EACN,uBAAuB,EACvB,yBAAyB,GACzB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACN,uBAAuB,EACvB,6BAA6B,GAC7B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACN,cAAc,EACd,yBAAyB,GACzB,MAAM,wBAAwB,CAAC;AAQhC,MAAM,UAAU,8BAA8B,CAAC,IAK9C;IACA,IAAI,SAA8C,CAAC;IACnD,IAAI,iBAA8D,CAAC;IAEnE,OAAO;QACN,IAAI,EAAE,4BAA4B;QAClC,OAAO,EAAE,MAAM;QACf,MAAM,CAAC,MAAM,EAAE,GAAG;YACjB,IAAI,GAAG,CAAC,OAAO,KAAK,OAAO;gBAAE,OAAO;YACpC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CA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B,CAClC,KAKY;IAEZ,IAAI,KAAK,EAAE,MAAM,KAAK,KAAK,IAAI,KAAK,EAAE,SAAS,EAAE,CAAC;QACjD,MAAM,IAAI,KAAK,CACd,iGAAiG,CACjG,CAAC;IACH,CAAC;AACF,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=vite-plugin.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vite-plugin.test.d.ts","sourceRoot":"","sources":["../../../src/bundler-plugins/per-locale-build/vite-plugin.test.ts"],"names":[],"mappings":""}