@inlang/paraglide-js 2.22.0 → 2.23.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 (97) hide show
  1. package/README.md +6 -3
  2. package/dist/bundler-plugins/per-locale-build/constants.d.ts +0 -1
  3. package/dist/bundler-plugins/per-locale-build/constants.d.ts.map +1 -1
  4. package/dist/bundler-plugins/per-locale-build/constants.js +0 -1
  5. package/dist/bundler-plugins/per-locale-build/constants.js.map +1 -1
  6. package/dist/bundler-plugins/per-locale-build/index.d.ts.map +1 -1
  7. package/dist/bundler-plugins/per-locale-build/index.js +15 -38
  8. package/dist/bundler-plugins/per-locale-build/index.js.map +1 -1
  9. package/dist/bundler-plugins/per-locale-build/types.d.ts +0 -37
  10. package/dist/bundler-plugins/per-locale-build/types.d.ts.map +1 -1
  11. package/dist/bundler-plugins/per-locale-build/vite-environments.d.ts +52 -0
  12. package/dist/bundler-plugins/per-locale-build/vite-environments.d.ts.map +1 -0
  13. package/dist/bundler-plugins/per-locale-build/vite-environments.js +250 -0
  14. package/dist/bundler-plugins/per-locale-build/vite-environments.js.map +1 -0
  15. package/dist/bundler-plugins/per-locale-build/vite-environments.test.d.ts +2 -0
  16. package/dist/bundler-plugins/per-locale-build/vite-environments.test.d.ts.map +1 -0
  17. package/dist/bundler-plugins/per-locale-build/vite-environments.test.js +260 -0
  18. package/dist/bundler-plugins/per-locale-build/vite-environments.test.js.map +1 -0
  19. package/dist/bundler-plugins/vite.d.ts +4 -3
  20. package/dist/bundler-plugins/vite.d.ts.map +1 -1
  21. package/dist/bundler-plugins/vite.js.map +1 -1
  22. package/dist/bundler-plugins/vite.test.js +21 -46
  23. package/dist/bundler-plugins/vite.test.js.map +1 -1
  24. package/dist/compiler/compile-bundle.d.ts.map +1 -1
  25. package/dist/compiler/compile-bundle.js +16 -4
  26. package/dist/compiler/compile-bundle.js.map +1 -1
  27. package/dist/compiler/compile-bundle.test.js +42 -0
  28. package/dist/compiler/compile-bundle.test.js.map +1 -1
  29. package/dist/compiler/compile-project.d.ts.map +1 -1
  30. package/dist/compiler/compile-project.js +7 -6
  31. package/dist/compiler/compile-project.js.map +1 -1
  32. package/dist/compiler/compile-project.test.js +12 -29
  33. package/dist/compiler/compile-project.test.js.map +1 -1
  34. package/dist/compiler/runtime/create-runtime.d.ts.map +1 -1
  35. package/dist/compiler/runtime/create-runtime.js +2 -0
  36. package/dist/compiler/runtime/create-runtime.js.map +1 -1
  37. package/dist/compiler/runtime/extract-locale-from-request-async.d.ts.map +1 -1
  38. package/dist/compiler/runtime/extract-locale-from-request-async.js +1 -1
  39. package/dist/compiler/runtime/extract-locale-from-request-async.js.map +1 -1
  40. package/dist/compiler/runtime/extract-locale-from-request.d.ts.map +1 -1
  41. package/dist/compiler/runtime/extract-locale-from-request.js +2 -1
  42. package/dist/compiler/runtime/extract-locale-from-request.js.map +1 -1
  43. package/dist/compiler/runtime/extract-locale-from-url.js +1 -1
  44. package/dist/compiler/runtime/extract-locale-from-url.js.map +1 -1
  45. package/dist/compiler/runtime/get-locale.js +2 -1
  46. package/dist/compiler/runtime/get-locale.js.map +1 -1
  47. package/dist/compiler/runtime/get-url-origin.d.ts +1 -1
  48. package/dist/compiler/runtime/get-url-origin.js +1 -1
  49. package/dist/compiler/runtime/route-strategy.d.ts +33 -0
  50. package/dist/compiler/runtime/route-strategy.d.ts.map +1 -0
  51. package/dist/compiler/runtime/route-strategy.js +72 -0
  52. package/dist/compiler/runtime/route-strategy.js.map +1 -0
  53. package/dist/compiler/runtime/set-locale.d.ts +6 -3
  54. package/dist/compiler/runtime/set-locale.d.ts.map +1 -1
  55. package/dist/compiler/runtime/set-locale.js +8 -4
  56. package/dist/compiler/runtime/set-locale.js.map +1 -1
  57. package/dist/compiler/runtime/should-redirect.d.ts.map +1 -1
  58. package/dist/compiler/runtime/should-redirect.js +5 -3
  59. package/dist/compiler/runtime/should-redirect.js.map +1 -1
  60. package/dist/compiler/runtime/type.d.ts +2 -2
  61. package/dist/compiler/runtime/type.d.ts.map +1 -1
  62. package/dist/compiler/runtime/variables.d.ts +0 -17
  63. package/dist/compiler/runtime/variables.d.ts.map +1 -1
  64. package/dist/compiler/runtime/variables.js +0 -56
  65. package/dist/compiler/runtime/variables.js.map +1 -1
  66. package/dist/compiler/server/middleware.test.js +27 -0
  67. package/dist/compiler/server/middleware.test.js.map +1 -1
  68. package/dist/services/env-variables/index.js +1 -1
  69. package/package.json +1 -1
  70. package/dist/bundler-plugins/per-locale-build/framework-helpers.test.d.ts +0 -2
  71. package/dist/bundler-plugins/per-locale-build/framework-helpers.test.d.ts.map +0 -1
  72. package/dist/bundler-plugins/per-locale-build/framework-helpers.test.js +0 -57
  73. package/dist/bundler-plugins/per-locale-build/framework-helpers.test.js.map +0 -1
  74. package/dist/bundler-plugins/per-locale-build/frameworks/index.d.ts +0 -5
  75. package/dist/bundler-plugins/per-locale-build/frameworks/index.d.ts.map +0 -1
  76. package/dist/bundler-plugins/per-locale-build/frameworks/index.js +0 -21
  77. package/dist/bundler-plugins/per-locale-build/frameworks/index.js.map +0 -1
  78. package/dist/bundler-plugins/per-locale-build/frameworks/sveltekit.d.ts +0 -21
  79. package/dist/bundler-plugins/per-locale-build/frameworks/sveltekit.d.ts.map +0 -1
  80. package/dist/bundler-plugins/per-locale-build/frameworks/sveltekit.js +0 -137
  81. package/dist/bundler-plugins/per-locale-build/frameworks/sveltekit.js.map +0 -1
  82. package/dist/bundler-plugins/per-locale-build/frameworks/tanstack-start.d.ts +0 -23
  83. package/dist/bundler-plugins/per-locale-build/frameworks/tanstack-start.d.ts.map +0 -1
  84. package/dist/bundler-plugins/per-locale-build/frameworks/tanstack-start.js +0 -104
  85. package/dist/bundler-plugins/per-locale-build/frameworks/tanstack-start.js.map +0 -1
  86. package/dist/bundler-plugins/per-locale-build/specialize-bundle.d.ts +0 -18
  87. package/dist/bundler-plugins/per-locale-build/specialize-bundle.d.ts.map +0 -1
  88. package/dist/bundler-plugins/per-locale-build/specialize-bundle.js +0 -184
  89. package/dist/bundler-plugins/per-locale-build/specialize-bundle.js.map +0 -1
  90. package/dist/bundler-plugins/per-locale-build/vite-plugin.d.ts +0 -9
  91. package/dist/bundler-plugins/per-locale-build/vite-plugin.d.ts.map +0 -1
  92. package/dist/bundler-plugins/per-locale-build/vite-plugin.js +0 -87
  93. package/dist/bundler-plugins/per-locale-build/vite-plugin.js.map +0 -1
  94. package/dist/bundler-plugins/per-locale-build/vite-plugin.test.d.ts +0 -2
  95. package/dist/bundler-plugins/per-locale-build/vite-plugin.test.d.ts.map +0 -1
  96. package/dist/bundler-plugins/per-locale-build/vite-plugin.test.js +0 -429
  97. package/dist/bundler-plugins/per-locale-build/vite-plugin.test.js.map +0 -1
@@ -1,57 +0,0 @@
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"framework-helpers.test.js","sourceRoot":"","sources":["../../../src/bundler-plugins/per-locale-build/framework-helpers.test.ts"],"names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O,EAAE,gBAAgB,EAAE,MAAM,EAAE;SACvD,CAAC,CAAC;QACH,MAAM,CAAC,mCAAmC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7E,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,4DAA4D,EAAE,GAAG,EAAE;IACvE,MAAM,KAAK,GAAG,4BAA4B,EAAE,CAAC,cAAc,IAAI,EAAE,CAAC;IAClE,MAAM,MAAM,GAAG,KAAK,CAAC,0BAA0B,CAAC,CAAC;IACjD,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,0BAA0B,CAAC,CAAC,CAAC;IACjE,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,sBAAsB,CAAC,CAAC;IACrD,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC;IACzC,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,yBAAyB,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC/D,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC,qCAAqC,CAAC,CAAC;IAChE,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,CACvB,sDAAsD,CACtD,CAAC;AACH,CAAC,CAAC,CAAC"}
@@ -1,5 +0,0 @@
1
- import type { ResolvedConfig, UserConfig } from "vite";
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
@@ -1 +0,0 @@
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"}
@@ -1,21 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,21 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,137 +0,0 @@
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
@@ -1 +0,0 @@
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,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,wBAAwB,CACvC,MAAuC;IAEvC,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,CACtC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,6BAA6B,CACrB,CAAC;IACtC,MAAM,GAAG,GAAG,WAAW,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,CAAC;IAC3C,IAAI,CAAC,GAAG,EAAE,CAAC;QACV,MAAM,IAAI,KAAK,CACd,4HAA4H,CAC5H,CAAC;IACH,CAAC;IACD,IACC,GAAG,CAAC,MAAM,KAAK,MAAM;QACrB,GAAG,CAAC,KAAK,EAAE,IAAI;QACf,GAAG,CAAC,KAAK,EAAE,MAAM;QACjB,GAAG,CAAC,MAAM,EAAE,cAAc,KAAK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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"}
@@ -1,23 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,104 +0,0 @@
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
@@ -1 +0,0 @@
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,CAAC,EAAE,CAAC;AAChF,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,GAAW,EAAE,MAAc;IAClE,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,0BAA0B,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;QAClE,MAAM,IAAI,KAAK,CACd,gGAAgG,CAChG,CAAC;IACH,CAAC;IACD,IAAI,MAAM,KAAK,EAAE;QAAE,OAAO,GAAG,CAAC;IAC9B,OAAO,GAAG,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,mCAAmC,CAAC,OAAgB;IACnE,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IACxC,IAAI,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,KAAK,MAAM;QAAE,OAAO,UAAU,CAAC;IACxE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,SA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ACb,cAAc,CAAC,QAAgB,EAAE,OAA0B;gBAC1D,IAAI,OAAO,CAAC,GAAG;oBAAE,OAAO,IAAI,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,CAAC;gBAC3D,OAAO,EAAE,QAAQ,EAAE,IAAa,EAAE,CAAC;YACpC,CAAC;SACD;KACD,CAAC;AACH,CAAC;AAED,MAAM,0BAA0B,GAAG,MAAM,CAAC,GAAG,CAAA;;;;;;;;;oCAST,yBAAyB,CAAC,QAAQ,EAAE;;0BAE9C,uBAAuB,CAAC,QAAQ,EAAE;yBACnC,uBAAuB,CAAC,QAAQ,EAAE;iCAC1B,mCAAmC,CAAC,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;CA0B9E,CAAC,SAAS,EAAE,CAAC"}
@@ -1,18 +0,0 @@
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
@@ -1 +0,0 @@
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"}
@@ -1,184 +0,0 @@
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