@sebbro/paraglide-lite 0.1.1 → 0.1.2

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 (109) hide show
  1. package/dist/bundler-plugins/per-locale-build/index.js +5 -3
  2. package/dist/bundler-plugins/per-locale-build/index.js.map +1 -1
  3. package/dist/bundler-plugins/per-locale-build/vite-environments.js +12 -7
  4. package/dist/bundler-plugins/per-locale-build/vite-environments.js.map +1 -1
  5. package/dist/bundler-plugins/plugin-core.d.ts +38 -2
  6. package/dist/bundler-plugins/plugin-core.js +198 -11
  7. package/dist/bundler-plugins/plugin-core.js.map +1 -1
  8. package/dist/bundler-plugins/rolldown.test.js +15 -6
  9. package/dist/bundler-plugins/rolldown.test.js.map +1 -1
  10. package/dist/bundler-plugins/unplugin.js +5 -0
  11. package/dist/bundler-plugins/unplugin.js.map +1 -1
  12. package/dist/bundler-plugins/unplugin.test.js +67 -0
  13. package/dist/bundler-plugins/unplugin.test.js.map +1 -1
  14. package/dist/bundler-plugins/virtual-modules.test.js +64 -1
  15. package/dist/bundler-plugins/virtual-modules.test.js.map +1 -1
  16. package/dist/cli/commands/compile/command.js +8 -1
  17. package/dist/cli/commands/compile/command.js.map +1 -1
  18. package/dist/cli/commands/compile/command.test.js +51 -0
  19. package/dist/cli/commands/compile/command.test.js.map +1 -1
  20. package/dist/compiler/compile-annotation.d.ts +2 -2
  21. package/dist/compiler/compile-annotation.js +9 -9
  22. package/dist/compiler/compile-annotation.js.map +1 -1
  23. package/dist/compiler/compile-local-variable.d.ts +2 -1
  24. package/dist/compiler/compile-local-variable.js +4 -4
  25. package/dist/compiler/compile-local-variable.js.map +1 -1
  26. package/dist/compiler/compile-local-variable.test.js +82 -0
  27. package/dist/compiler/compile-local-variable.test.js.map +1 -1
  28. package/dist/compiler/compile-message.js +10 -2
  29. package/dist/compiler/compile-message.js.map +1 -1
  30. package/dist/compiler/compile-message.test.js +132 -2
  31. package/dist/compiler/compile-message.test.js.map +1 -1
  32. package/dist/compiler/compile-pattern.js +4 -2
  33. package/dist/compiler/compile-pattern.js.map +1 -1
  34. package/dist/compiler/compile-pattern.test.js +31 -0
  35. package/dist/compiler/compile-pattern.test.js.map +1 -1
  36. package/dist/compiler/compile.bench.js +1 -1
  37. package/dist/compiler/compile.bench.js.map +1 -1
  38. package/dist/compiler/compile.test.js +14 -0
  39. package/dist/compiler/compile.test.js.map +1 -1
  40. package/dist/compiler/compiler-options.d.ts +9 -1
  41. package/dist/compiler/compiler-options.js.map +1 -1
  42. package/dist/compiler/runtime/create-runtime.d.ts +1 -0
  43. package/dist/compiler/runtime/create-runtime.js +11 -0
  44. package/dist/compiler/runtime/create-runtime.js.map +1 -1
  45. package/dist/compiler/runtime/exec-url-pattern.d.ts +9 -0
  46. package/dist/compiler/runtime/exec-url-pattern.js +31 -0
  47. package/dist/compiler/runtime/exec-url-pattern.js.map +1 -0
  48. package/dist/compiler/runtime/extract-locale-from-url.js +9 -4
  49. package/dist/compiler/runtime/extract-locale-from-url.js.map +1 -1
  50. package/dist/compiler/runtime/generate-static-localized-urls.js +13 -6
  51. package/dist/compiler/runtime/generate-static-localized-urls.js.map +1 -1
  52. package/dist/compiler/runtime/generate-static-localized-urls.test.js +38 -0
  53. package/dist/compiler/runtime/generate-static-localized-urls.test.js.map +1 -1
  54. package/dist/compiler/runtime/localize-href.bench.d.ts +1 -0
  55. package/dist/compiler/runtime/localize-href.bench.js +68 -0
  56. package/dist/compiler/runtime/localize-href.bench.js.map +1 -0
  57. package/dist/compiler/runtime/localize-href.test.js +35 -0
  58. package/dist/compiler/runtime/localize-href.test.js.map +1 -1
  59. package/dist/compiler/runtime/localize-url.d.ts +14 -0
  60. package/dist/compiler/runtime/localize-url.js +338 -19
  61. package/dist/compiler/runtime/localize-url.js.map +1 -1
  62. package/dist/compiler/runtime/localize-url.test.js +139 -0
  63. package/dist/compiler/runtime/localize-url.test.js.map +1 -1
  64. package/dist/compiler/runtime/normalize-trailing-slash.d.ts +10 -0
  65. package/dist/compiler/runtime/normalize-trailing-slash.js +23 -0
  66. package/dist/compiler/runtime/normalize-trailing-slash.js.map +1 -0
  67. package/dist/compiler/runtime/route-strategy.js +4 -2
  68. package/dist/compiler/runtime/route-strategy.js.map +1 -1
  69. package/dist/compiler/runtime/should-redirect.js +4 -1
  70. package/dist/compiler/runtime/should-redirect.js.map +1 -1
  71. package/dist/compiler/runtime/should-redirect.test.js +26 -2
  72. package/dist/compiler/runtime/should-redirect.test.js.map +1 -1
  73. package/dist/compiler/runtime/type.d.ts +1 -0
  74. package/dist/compiler/runtime/type.js.map +1 -1
  75. package/dist/compiler/runtime/url-pattern.d.ts +11 -0
  76. package/dist/compiler/runtime/url-pattern.js +39 -1
  77. package/dist/compiler/runtime/url-pattern.js.map +1 -1
  78. package/dist/compiler/runtime/variables.d.ts +6 -0
  79. package/dist/compiler/runtime/variables.js +6 -0
  80. package/dist/compiler/runtime/variables.js.map +1 -1
  81. package/dist/compiler/server/create-server-file.js +18 -4
  82. package/dist/compiler/server/create-server-file.js.map +1 -1
  83. package/dist/compiler/server/create-server-file.test.js +76 -0
  84. package/dist/compiler/server/create-server-file.test.js.map +1 -1
  85. package/dist/compiler/server/middleware.js +6 -2
  86. package/dist/compiler/server/middleware.js.map +1 -1
  87. package/dist/compiler/server/middleware.test.js +30 -0
  88. package/dist/compiler/server/middleware.test.js.map +1 -1
  89. package/dist/compiler/variable-access.d.ts +2 -0
  90. package/dist/compiler/variable-access.js +6 -0
  91. package/dist/compiler/variable-access.js.map +1 -1
  92. package/dist/index.test.d.ts +1 -0
  93. package/dist/index.test.js +9 -0
  94. package/dist/index.test.js.map +1 -0
  95. package/dist/messages/load-messages.js +4 -5
  96. package/dist/messages/load-messages.js.map +1 -1
  97. package/dist/services/env-variables/index.js +1 -1
  98. package/dist/services/env-variables/index.js.map +1 -1
  99. package/dist/services/file-handling/write-output.bench.d.ts +1 -0
  100. package/dist/services/file-handling/write-output.bench.js +24 -0
  101. package/dist/services/file-handling/write-output.bench.js.map +1 -0
  102. package/dist/services/file-handling/write-output.d.ts +5 -0
  103. package/dist/services/file-handling/write-output.js +54 -9
  104. package/dist/services/file-handling/write-output.js.map +1 -1
  105. package/dist/services/file-handling/write-output.test.js +27 -0
  106. package/dist/services/file-handling/write-output.test.js.map +1 -1
  107. package/dist/services/logger/index.js +2 -0
  108. package/dist/services/logger/index.js.map +1 -1
  109. package/package.json +86 -86
@@ -1 +1 @@
1
- {"version":3,"file":"compile-pattern.test.js","sourceRoot":"","sources":["../../src/compiler/compile-pattern.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGtD,IAAI,CAAC,oCAAoC,EAAE,GAAG,EAAE;IAC/C,MAAM,OAAO,GAAY,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;IAC5D,MAAM,EAAE,IAAI,EAAE,GAAG,cAAc,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,CAAC;IAC/D,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AAC9B,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,4DAA4D,EAAE,GAAG,EAAE;IACvE,MAAM,OAAO,GAAY;QACxB,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE;QACjC;YACC,IAAI,EAAE,YAAY;YAClB,GAAG,EAAE;gBACJ,IAAI,EAAE,oBAAoB;gBAC1B,IAAI,EAAE,MAAM;aACZ;SACD;QACD,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE;QACtC,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;QAC1E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C,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;KAChE,CAAC,CAAC;IAEH,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAChB,+ZAA+Z,CAC/Z,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { test, expect } from \"vitest\";\nimport { compilePattern } from \"./compile-pattern.js\";\nimport type { Pattern } from \"../messages/ast.js\";\n\ntest(\"should compile a text only pattern\", () => {\n\tconst pattern: Pattern = [{ type: \"text\", value: \"Hello\" }];\n\tconst { code } = compilePattern({ pattern, declarations: [] });\n\texpect(code).toBe(\"`Hello`\");\n});\n\ntest(\"should compile a pattern with multiple VariableReference's\", () => {\n\tconst pattern: Pattern = [\n\t\t{ type: \"text\", value: \"Hello \" },\n\t\t{\n\t\t\ttype: \"expression\",\n\t\t\targ: {\n\t\t\t\ttype: \"variable-reference\",\n\t\t\t\tname: \"name\",\n\t\t\t},\n\t\t},\n\t\t{ type: \"text\", value: \"! You have \" },\n\t\t{ type: \"expression\", arg: { type: \"variable-reference\", name: \"count\" } },\n\t\t{ type: \"text\", value: \" messages.\" },\n\t];\n\n\tconst { code } = compilePattern({\n\t\tpattern,\n\t\tdeclarations: [\n\t\t\t{ type: \"input-variable\", name: \"name\" },\n\t\t\t{ type: \"input-variable\", name: \"count\" },\n\t\t],\n\t});\n\n\texpect(code).toBe(\"`Hello ${i?.name}! You have ${i?.count} messages.`\");\n});\n\ntest(\"uses bracket notation for input variables with non-identifier names\", () => {\n\tconst pattern: Pattern = [\n\t\t{ type: \"text\", value: \"Half \" },\n\t\t{\n\t\t\ttype: \"expression\",\n\t\t\targ: {\n\t\t\t\ttype: \"variable-reference\",\n\t\t\t\tname: \"half!\",\n\t\t\t},\n\t\t},\n\t];\n\n\tconst { code } = compilePattern({\n\t\tpattern,\n\t\tdeclarations: [{ type: \"input-variable\", name: \"half!\" }],\n\t});\n\n\texpect(code).toBe('`Half ${i?.[\"half!\"]}`');\n});\n\ntest(\"should escape backticks\", () => {\n\tconst pattern: Pattern = [{ type: \"text\", value: \"`Hello world`\" }];\n\tconst { code } = compilePattern({ pattern, declarations: [] });\n\texpect(code).toBe(\"`\\\\`Hello world\\\\``\");\n});\n\ntest(\"should escape backslashes\", () => {\n\tconst pattern: Pattern = [{ type: \"text\", value: \"\\\\Hello world\\\\\" }];\n\tconst { code } = compilePattern({ pattern, declarations: [] });\n\n\texpect(code).toBe(\"`\\\\\\\\Hello world\\\\\\\\`\");\n});\n\ntest(\"should escape escaped backticks\", () => {\n\tconst pattern: Pattern = [{ type: \"text\", value: \"\\\\`Hello world\\\\`\" }];\n\tconst { code } = compilePattern({ pattern, declarations: [] });\n\n\texpect(code).toBe(\"`\\\\\\\\\\\\`Hello world\\\\\\\\\\\\``\");\n});\n\ntest(\"should escape variable interpolation ( ${} )\", () => {\n\tconst pattern: Pattern = [{ type: \"text\", value: \"${name\" }];\n\tconst { code } = compilePattern({ pattern, declarations: [] });\n\n\texpect(code).toBe(\"`\\\\${name`\");\n});\n\ntest(\"it can reference local variables\", () => {\n\tconst { code } = compilePattern({\n\t\tpattern: [\n\t\t\t{ type: \"text\", value: \"Hello \" },\n\t\t\t{\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: {\n\t\t\t\t\ttype: \"variable-reference\",\n\t\t\t\t\tname: \"name\",\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tdeclarations: [\n\t\t\t{\n\t\t\t\ttype: \"local-variable\",\n\t\t\t\tname: \"name\",\n\t\t\t\tvalue: {\n\t\t\t\t\ttype: \"expression\",\n\t\t\t\t\targ: { type: \"literal\", value: \"Peter\" },\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t});\n\n\texpect(code).toBe(\"`Hello ${name}`\");\n});\n\ntest(\"plain string mode strips markup wrappers\", () => {\n\tconst pattern: Pattern = [\n\t\t{ type: \"text\", value: \"Hello \" },\n\t\t{ type: \"markup-start\", name: \"b\" },\n\t\t{ type: \"expression\", arg: { type: \"variable-reference\", name: \"name\" } },\n\t\t{ type: \"markup-end\", name: \"b\" },\n\t\t{ type: \"text\", value: \"!\" },\n\t];\n\n\tconst { code } = compilePattern({\n\t\tpattern,\n\t\tdeclarations: [{ type: \"input-variable\", name: \"name\" }],\n\t});\n\n\texpect(code).toBe(\"`Hello ${i?.name}!`\");\n});\n\ntest(\"compiles a pattern expression annotation to a registry call\", () => {\n\t// https://github.com/opral/paraglide-js/issues/694\n\tconst pattern: Pattern = [\n\t\t{\n\t\t\ttype: \"expression\",\n\t\t\targ: { type: \"variable-reference\", name: \"count\" },\n\t\t\tannotation: { type: \"function-reference\", name: \"number\", options: [] },\n\t\t},\n\t\t{ type: \"text\", value: \" views\" },\n\t];\n\n\tconst { code } = compilePattern({\n\t\tpattern,\n\t\tdeclarations: [{ type: \"input-variable\", name: \"count\" }],\n\t\tlocale: \"en\",\n\t});\n\n\texpect(code).toBe('`${registry.number(\"en\", i?.count, {})} views`');\n});\n\ntest(\"compiles pattern expression annotation options like local variable annotations\", () => {\n\tconst pattern: Pattern = [\n\t\t{\n\t\t\ttype: \"expression\",\n\t\t\targ: { type: \"variable-reference\", name: \"price\" },\n\t\t\tannotation: {\n\t\t\t\ttype: \"function-reference\",\n\t\t\t\tname: \"number\",\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"minimumFractionDigits\",\n\t\t\t\t\t\tvalue: { type: \"literal\", value: \"2\" },\n\t\t\t\t\t},\n\t\t\t\t\t{ name: \"style\", value: { type: \"literal\", value: \"percent\" } },\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t];\n\n\tconst { code } = compilePattern({\n\t\tpattern,\n\t\tdeclarations: [{ type: \"input-variable\", name: \"price\" }],\n\t\tlocale: \"de\",\n\t});\n\n\texpect(code).toBe(\n\t\t'`${registry.number(\"de\", i?.price, { minimumFractionDigits: 2, style: \"percent\" })}`'\n\t);\n});\n\ntest(\"parts mode compiles pattern expression annotations to registry calls\", () => {\n\tconst pattern: Pattern = [\n\t\t{\n\t\t\ttype: \"expression\",\n\t\t\targ: { type: \"variable-reference\", name: \"count\" },\n\t\t\tannotation: { type: \"function-reference\", name: \"number\", options: [] },\n\t\t},\n\t\t{ type: \"text\", value: \" views\" },\n\t];\n\n\tconst { code } = compilePattern({\n\t\tmode: \"parts\",\n\t\tpattern,\n\t\tdeclarations: [{ type: \"input-variable\", name: \"count\" }],\n\t\tlocale: \"en\",\n\t});\n\n\texpect(code).toBe(\n\t\t'[{ type: \"text\", value: String(registry.number(\"en\", i?.count, {})) }, { type: \"text\", value: \" views\" }]'\n\t);\n});\n\ntest(\"falls back to plain interpolation for unknown formatters\", () => {\n\tconst pattern: Pattern = [\n\t\t{\n\t\t\ttype: \"expression\",\n\t\t\targ: { type: \"variable-reference\", name: \"name\" },\n\t\t\tannotation: {\n\t\t\t\ttype: \"function-reference\",\n\t\t\t\tname: \"uppercase\",\n\t\t\t\toptions: [],\n\t\t\t},\n\t\t},\n\t];\n\n\tconst { code } = compilePattern({\n\t\tpattern,\n\t\tdeclarations: [{ type: \"input-variable\", name: \"name\" }],\n\t\tlocale: \"en\",\n\t});\n\n\texpect(code).toBe(\"`${i?.name}`\");\n});\n\ntest(\"throws when a pattern annotation is compiled without a locale\", () => {\n\tconst pattern: Pattern = [\n\t\t{\n\t\t\ttype: \"expression\",\n\t\t\targ: { type: \"variable-reference\", name: \"count\" },\n\t\t\tannotation: { type: \"function-reference\", name: \"number\", options: [] },\n\t\t},\n\t];\n\n\texpect(() =>\n\t\tcompilePattern({\n\t\t\tpattern,\n\t\t\tdeclarations: [{ type: \"input-variable\", name: \"count\" }],\n\t\t})\n\t).toThrow('requires a locale to compile the formatter \"number\"');\n});\n\ntest(\"validates relativetime options on pattern annotations\", () => {\n\tconst pattern: Pattern = [\n\t\t{\n\t\t\ttype: \"expression\",\n\t\t\targ: { type: \"variable-reference\", name: \"days\" },\n\t\t\tannotation: {\n\t\t\t\ttype: \"function-reference\",\n\t\t\t\tname: \"relativetime\",\n\t\t\t\toptions: [],\n\t\t\t},\n\t\t},\n\t];\n\n\texpect(() =>\n\t\tcompilePattern({\n\t\t\tpattern,\n\t\t\tdeclarations: [{ type: \"input-variable\", name: \"days\" }],\n\t\t\tlocale: \"en\",\n\t\t})\n\t).toThrow('The \"relativetime\" formatter requires a \"unit\" option.');\n});\n\ntest(\"parts mode compiles text, markup, options and attributes\", () => {\n\tconst pattern: Pattern = [\n\t\t{ type: \"text\", value: \"Read \" },\n\t\t{\n\t\t\ttype: \"markup-start\",\n\t\t\tname: \"link\",\n\t\t\toptions: [\n\t\t\t\t{ name: \"to\", value: { type: \"literal\", value: \"/docs\" } },\n\t\t\t\t{\n\t\t\t\t\tname: \"rel\",\n\t\t\t\t\tvalue: { type: \"variable-reference\", name: \"relationship\" },\n\t\t\t\t},\n\t\t\t],\n\t\t\tattributes: [\n\t\t\t\t{ name: \"track\", value: true },\n\t\t\t\t{ name: \"variant\", value: { type: \"literal\", value: \"hero\" } },\n\t\t\t],\n\t\t},\n\t\t{ type: \"text\", value: \"docs\" },\n\t\t{\n\t\t\ttype: \"markup-end\",\n\t\t\tname: \"link\",\n\t\t\toptions: [{ name: \"to\", value: { type: \"literal\", value: \"/docs\" } }],\n\t\t\tattributes: [{ name: \"track\", value: true }],\n\t\t},\n\t\t{\n\t\t\ttype: \"markup-standalone\",\n\t\t\tname: \"icon\",\n\t\t\toptions: [{ name: \"name\", value: { type: \"literal\", value: \"arrow\" } }],\n\t\t\tattributes: [{ name: \"filled\", value: true }],\n\t\t},\n\t];\n\n\tconst { code } = compilePattern({\n\t\tmode: \"parts\",\n\t\tpattern,\n\t\tdeclarations: [{ type: \"input-variable\", name: \"relationship\" }],\n\t});\n\n\texpect(code).toBe(\n\t\t'[{ type: \"text\", value: \"Read \" }, { type: \"markup-start\", name: \"link\", options: { \"to\": \"/docs\", \"rel\": i?.relationship }, attributes: { \"track\": true, \"variant\": \"hero\" } }, { type: \"text\", value: \"docs\" }, { type: \"markup-end\", name: \"link\", options: { \"to\": \"/docs\" }, attributes: { \"track\": true } }, { type: \"markup-standalone\", name: \"icon\", options: { \"name\": \"arrow\" }, attributes: { \"filled\": true } }]'\n\t);\n});\n"]}
1
+ {"version":3,"file":"compile-pattern.test.js","sourceRoot":"","sources":["../../src/compiler/compile-pattern.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGtD,IAAI,CAAC,oCAAoC,EAAE,GAAG,EAAE;IAC/C,MAAM,OAAO,GAAY,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAC;IAC5D,MAAM,EAAE,IAAI,EAAE,GAAG,cAAc,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,CAAC;IAC/D,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AAC9B,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,4DAA4D,EAAE,GAAG,EAAE;IACvE,MAAM,OAAO,GAAY;QACxB,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE;QACjC;YACC,IAAI,EAAE,YAAY;YAClB,GAAG,EAAE;gBACJ,IAAI,EAAE,oBAAoB;gBAC1B,IAAI,EAAE,MAAM;aACZ;SACD;QACD,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE;QACtC,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,oBAAoB,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;QAC1E,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,EAAE;KACrC,CAAC;IAEF,MAAM,EAAE,IAAI,EAAE,GAAG,cAAc,CAAC;QAC/B,OAAO;QACP,YAAY,EAAE;YACb,EAAE,IAAI,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AAM,EAAE,KAAK,EAAE,MAAM,EAAE;QAC/B;YACC,IAAI,EAAE,YAAY;YAClB,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC;YACrE,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;SAC5C;QACD;YACC,IAAI,EAAE,mBAAmB;YACzB,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,CAAC;YACvE,UAAU,EAAE,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;SAC7C;KACD,CAAC;IAEF,MAAM,EAAE,IAAI,EAAE,GAAG,cAAc,CAAC;QAC/B,IAAI,EAAE,OAAO;QACb,OAAO;QACP,YAAY,EAAE,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;KAChE,CAAC,CAAC;IAEH,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAChB,+ZAA+Z,CAC/Z,CAAC;AACH,CAAC,CAAC,CAAC","sourcesContent":["import { test, expect } from \"vitest\";\nimport { compilePattern } from \"./compile-pattern.js\";\nimport type { Pattern } from \"../messages/ast.js\";\n\ntest(\"should compile a text only pattern\", () => {\n\tconst pattern: Pattern = [{ type: \"text\", value: \"Hello\" }];\n\tconst { code } = compilePattern({ pattern, declarations: [] });\n\texpect(code).toBe(\"`Hello`\");\n});\n\ntest(\"should compile a pattern with multiple VariableReference's\", () => {\n\tconst pattern: Pattern = [\n\t\t{ type: \"text\", value: \"Hello \" },\n\t\t{\n\t\t\ttype: \"expression\",\n\t\t\targ: {\n\t\t\t\ttype: \"variable-reference\",\n\t\t\t\tname: \"name\",\n\t\t\t},\n\t\t},\n\t\t{ type: \"text\", value: \"! You have \" },\n\t\t{ type: \"expression\", arg: { type: \"variable-reference\", name: \"count\" } },\n\t\t{ type: \"text\", value: \" messages.\" },\n\t];\n\n\tconst { code } = compilePattern({\n\t\tpattern,\n\t\tdeclarations: [\n\t\t\t{ type: \"input-variable\", name: \"name\" },\n\t\t\t{ type: \"input-variable\", name: \"count\" },\n\t\t],\n\t});\n\n\texpect(code).toBe(\"`Hello ${i?.name}! You have ${i?.count} messages.`\");\n});\n\ntest(\"uses bracket notation for input variables with non-identifier names\", () => {\n\tconst pattern: Pattern = [\n\t\t{ type: \"text\", value: \"Half \" },\n\t\t{\n\t\t\ttype: \"expression\",\n\t\t\targ: {\n\t\t\t\ttype: \"variable-reference\",\n\t\t\t\tname: \"half!\",\n\t\t\t},\n\t\t},\n\t];\n\n\tconst { code } = compilePattern({\n\t\tpattern,\n\t\tdeclarations: [{ type: \"input-variable\", name: \"half!\" }],\n\t});\n\n\texpect(code).toBe('`Half ${i?.[\"half!\"]}`');\n});\n\ntest(\"should escape backticks\", () => {\n\tconst pattern: Pattern = [{ type: \"text\", value: \"`Hello world`\" }];\n\tconst { code } = compilePattern({ pattern, declarations: [] });\n\texpect(code).toBe(\"`\\\\`Hello world\\\\``\");\n});\n\ntest(\"should escape backslashes\", () => {\n\tconst pattern: Pattern = [{ type: \"text\", value: \"\\\\Hello world\\\\\" }];\n\tconst { code } = compilePattern({ pattern, declarations: [] });\n\n\texpect(code).toBe(\"`\\\\\\\\Hello world\\\\\\\\`\");\n});\n\ntest(\"should escape escaped backticks\", () => {\n\tconst pattern: Pattern = [{ type: \"text\", value: \"\\\\`Hello world\\\\`\" }];\n\tconst { code } = compilePattern({ pattern, declarations: [] });\n\n\texpect(code).toBe(\"`\\\\\\\\\\\\`Hello world\\\\\\\\\\\\``\");\n});\n\ntest(\"should escape variable interpolation ( ${} )\", () => {\n\tconst pattern: Pattern = [{ type: \"text\", value: \"${name\" }];\n\tconst { code } = compilePattern({ pattern, declarations: [] });\n\n\texpect(code).toBe(\"`\\\\${name`\");\n});\n\ntest(\"it can reference local variables\", () => {\n\tconst { code } = compilePattern({\n\t\tpattern: [\n\t\t\t{ type: \"text\", value: \"Hello \" },\n\t\t\t{\n\t\t\t\ttype: \"expression\",\n\t\t\t\targ: {\n\t\t\t\t\ttype: \"variable-reference\",\n\t\t\t\t\tname: \"name\",\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tdeclarations: [\n\t\t\t{\n\t\t\t\ttype: \"local-variable\",\n\t\t\t\tname: \"name\",\n\t\t\t\tvalue: {\n\t\t\t\t\ttype: \"expression\",\n\t\t\t\t\targ: { type: \"literal\", value: \"Peter\" },\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t});\n\n\texpect(code).toBe(\"`Hello ${name}`\");\n});\n\ntest(\"plain string mode strips markup wrappers\", () => {\n\tconst pattern: Pattern = [\n\t\t{ type: \"text\", value: \"Hello \" },\n\t\t{ type: \"markup-start\", name: \"b\" },\n\t\t{ type: \"expression\", arg: { type: \"variable-reference\", name: \"name\" } },\n\t\t{ type: \"markup-end\", name: \"b\" },\n\t\t{ type: \"text\", value: \"!\" },\n\t];\n\n\tconst { code } = compilePattern({\n\t\tpattern,\n\t\tdeclarations: [{ type: \"input-variable\", name: \"name\" }],\n\t});\n\n\texpect(code).toBe(\"`Hello ${i?.name}!`\");\n});\n\ntest(\"compiles a pattern expression annotation to a registry call\", () => {\n\t// https://github.com/opral/paraglide-js/issues/694\n\tconst pattern: Pattern = [\n\t\t{\n\t\t\ttype: \"expression\",\n\t\t\targ: { type: \"variable-reference\", name: \"count\" },\n\t\t\tannotation: { type: \"function-reference\", name: \"number\", options: [] },\n\t\t},\n\t\t{ type: \"text\", value: \" views\" },\n\t];\n\n\tconst { code } = compilePattern({\n\t\tpattern,\n\t\tdeclarations: [{ type: \"input-variable\", name: \"count\" }],\n\t\tlocale: \"en\",\n\t});\n\n\texpect(code).toBe('`${registry.number(\"en\", i?.count, {})} views`');\n});\n\ntest(\"compiles pattern expression annotation options like local variable annotations\", () => {\n\tconst pattern: Pattern = [\n\t\t{\n\t\t\ttype: \"expression\",\n\t\t\targ: { type: \"variable-reference\", name: \"price\" },\n\t\t\tannotation: {\n\t\t\t\ttype: \"function-reference\",\n\t\t\t\tname: \"number\",\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"minimumFractionDigits\",\n\t\t\t\t\t\tvalue: { type: \"literal\", value: \"2\" },\n\t\t\t\t\t},\n\t\t\t\t\t{ name: \"style\", value: { type: \"literal\", value: \"percent\" } },\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t];\n\n\tconst { code } = compilePattern({\n\t\tpattern,\n\t\tdeclarations: [{ type: \"input-variable\", name: \"price\" }],\n\t\tlocale: \"de\",\n\t});\n\n\texpect(code).toBe(\n\t\t'`${registry.number(\"de\", i?.price, { minimumFractionDigits: 2, style: \"percent\" })}`'\n\t);\n});\n\ntest(\"compiles pattern annotation options that reference local variables\", () => {\n\tconst pattern: Pattern = [\n\t\t{\n\t\t\ttype: \"expression\",\n\t\t\targ: { type: \"variable-reference\", name: \"price\" },\n\t\t\tannotation: {\n\t\t\t\ttype: \"function-reference\",\n\t\t\t\tname: \"number\",\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: \"minimumFractionDigits\",\n\t\t\t\t\t\tvalue: { type: \"variable-reference\", name: \"digits\" },\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t];\n\n\tconst { code } = compilePattern({\n\t\tpattern,\n\t\tdeclarations: [\n\t\t\t{ type: \"input-variable\", name: \"price\" },\n\t\t\t{\n\t\t\t\ttype: \"local-variable\",\n\t\t\t\tname: \"digits\",\n\t\t\t\tvalue: { type: \"expression\", arg: { type: \"literal\", value: \"2\" } },\n\t\t\t},\n\t\t],\n\t\tlocale: \"en\",\n\t});\n\n\texpect(code).toBe(\n\t\t'`${registry.number(\"en\", i?.price, { minimumFractionDigits: digits })}`'\n\t);\n});\n\ntest(\"parts mode compiles pattern expression annotations to registry calls\", () => {\n\tconst pattern: Pattern = [\n\t\t{\n\t\t\ttype: \"expression\",\n\t\t\targ: { type: \"variable-reference\", name: \"count\" },\n\t\t\tannotation: { type: \"function-reference\", name: \"number\", options: [] },\n\t\t},\n\t\t{ type: \"text\", value: \" views\" },\n\t];\n\n\tconst { code } = compilePattern({\n\t\tmode: \"parts\",\n\t\tpattern,\n\t\tdeclarations: [{ type: \"input-variable\", name: \"count\" }],\n\t\tlocale: \"en\",\n\t});\n\n\texpect(code).toBe(\n\t\t'[{ type: \"text\", value: String(registry.number(\"en\", i?.count, {})) }, { type: \"text\", value: \" views\" }]'\n\t);\n});\n\ntest(\"falls back to plain interpolation for unknown formatters\", () => {\n\tconst pattern: Pattern = [\n\t\t{\n\t\t\ttype: \"expression\",\n\t\t\targ: { type: \"variable-reference\", name: \"name\" },\n\t\t\tannotation: {\n\t\t\t\ttype: \"function-reference\",\n\t\t\t\tname: \"uppercase\",\n\t\t\t\toptions: [],\n\t\t\t},\n\t\t},\n\t];\n\n\tconst { code } = compilePattern({\n\t\tpattern,\n\t\tdeclarations: [{ type: \"input-variable\", name: \"name\" }],\n\t\tlocale: \"en\",\n\t});\n\n\texpect(code).toBe(\"`${i?.name}`\");\n});\n\ntest(\"throws when a pattern annotation is compiled without a locale\", () => {\n\tconst pattern: Pattern = [\n\t\t{\n\t\t\ttype: \"expression\",\n\t\t\targ: { type: \"variable-reference\", name: \"count\" },\n\t\t\tannotation: { type: \"function-reference\", name: \"number\", options: [] },\n\t\t},\n\t];\n\n\texpect(() =>\n\t\tcompilePattern({\n\t\t\tpattern,\n\t\t\tdeclarations: [{ type: \"input-variable\", name: \"count\" }],\n\t\t})\n\t).toThrow('requires a locale to compile the formatter \"number\"');\n});\n\ntest(\"validates relativetime options on pattern annotations\", () => {\n\tconst pattern: Pattern = [\n\t\t{\n\t\t\ttype: \"expression\",\n\t\t\targ: { type: \"variable-reference\", name: \"days\" },\n\t\t\tannotation: {\n\t\t\t\ttype: \"function-reference\",\n\t\t\t\tname: \"relativetime\",\n\t\t\t\toptions: [],\n\t\t\t},\n\t\t},\n\t];\n\n\texpect(() =>\n\t\tcompilePattern({\n\t\t\tpattern,\n\t\t\tdeclarations: [{ type: \"input-variable\", name: \"days\" }],\n\t\t\tlocale: \"en\",\n\t\t})\n\t).toThrow('The \"relativetime\" formatter requires a \"unit\" option.');\n});\n\ntest(\"parts mode compiles text, markup, options and attributes\", () => {\n\tconst pattern: Pattern = [\n\t\t{ type: \"text\", value: \"Read \" },\n\t\t{\n\t\t\ttype: \"markup-start\",\n\t\t\tname: \"link\",\n\t\t\toptions: [\n\t\t\t\t{ name: \"to\", value: { type: \"literal\", value: \"/docs\" } },\n\t\t\t\t{\n\t\t\t\t\tname: \"rel\",\n\t\t\t\t\tvalue: { type: \"variable-reference\", name: \"relationship\" },\n\t\t\t\t},\n\t\t\t],\n\t\t\tattributes: [\n\t\t\t\t{ name: \"track\", value: true },\n\t\t\t\t{ name: \"variant\", value: { type: \"literal\", value: \"hero\" } },\n\t\t\t],\n\t\t},\n\t\t{ type: \"text\", value: \"docs\" },\n\t\t{\n\t\t\ttype: \"markup-end\",\n\t\t\tname: \"link\",\n\t\t\toptions: [{ name: \"to\", value: { type: \"literal\", value: \"/docs\" } }],\n\t\t\tattributes: [{ name: \"track\", value: true }],\n\t\t},\n\t\t{\n\t\t\ttype: \"markup-standalone\",\n\t\t\tname: \"icon\",\n\t\t\toptions: [{ name: \"name\", value: { type: \"literal\", value: \"arrow\" } }],\n\t\t\tattributes: [{ name: \"filled\", value: true }],\n\t\t},\n\t];\n\n\tconst { code } = compilePattern({\n\t\tmode: \"parts\",\n\t\tpattern,\n\t\tdeclarations: [{ type: \"input-variable\", name: \"relationship\" }],\n\t});\n\n\texpect(code).toBe(\n\t\t'[{ type: \"text\", value: \"Read \" }, { type: \"markup-start\", name: \"link\", options: { \"to\": \"/docs\", \"rel\": i?.relationship }, attributes: { \"track\": true, \"variant\": \"hero\" } }, { type: \"text\", value: \"docs\" }, { type: \"markup-end\", name: \"link\", options: { \"to\": \"/docs\" }, attributes: { \"track\": true } }, { type: \"markup-standalone\", name: \"icon\", options: { \"name\": \"arrow\" }, attributes: { \"filled\": true } }]'\n\t);\n});\n"]}
@@ -76,7 +76,7 @@ for (const { messages, locales: localeCount, compareBaseline } of SCALES) {
76
76
  // Upstream inlang SDK baseline is ~20s/iter at 10k×10 — keep it only at
77
77
  // the small scale where the comparison is still practical.
78
78
  if (compareBaseline) {
79
- bench(`published @inlang/paraglide-js@2.23.1 (${label}, inlang SDK)`, async () => {
79
+ bench(`published @inlang/paraglide-js@2.25.0 (${label}, inlang SDK)`, async () => {
80
80
  const fs = createBaselineProjectFs(messages, locales);
81
81
  await compileBaseline({
82
82
  project: "/project.inlang",
@@ -1 +1 @@
1
- {"version":3,"file":"compile.bench.js","sourceRoot":"","sources":["../../src/compiler/compile.bench.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C,SAAS,kBAAkB,CAAC,WAAmB,EAAE,MAAc;IAC9D,OAAO,MAAM,CAAC,WAAW,CACxB,KAAK,CAAC,IAAI,CAAC,EA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QAAQ,EAAE,OAAO,CAAC,CAAC;QAEnD,MAAM,YAAY,CAAC;YAClB,QAAQ,EAAE,gBAAgB;YAC1B,OAAO;YACP,UAAU,EAAE,OAAO,CAAC,CAAC,CAAE;YACvB,MAAM,EAAE,mBAAmB,QAAQ,IAAI,WAAW,EAAE;YACpD,SAAS,EAAE,KAAK;YAChB,EAAE;SACF,CAAC,CAAC;IACJ,CAAC,EACD,EAAE,IAAI,EAAE,CACR,CAAC;IAEF,wEAAwE;IACxE,2DAA2D;IAC3D,IAAI,eAAe,EAAE,CAAC;QACrB,KAAK,CACJ,0CAA0C,KAAK,eAAe,EAC9D,KAAK,IAAI,EAAE;YACV,MAAM,EAAE,GAAG,uBAAuB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAEtD,MAAM,eAAe,CAAC;gBACrB,OAAO,EAAE,iBAAiB;gBAC1B,MAAM,EAAE,oBAAoB,QAAQ,IAAI,WAAW,EAAE;gBACrD,EAAE;aACF,CAAC,CAAC;QACJ,CAAC,EACD,EAAE,IAAI,EAAE,CACR,CAAC;IACH,CAAC;AACF,CAAC","sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { bench } from \"vitest\";\nimport { memfs } from \"memfs\";\nimport { compile as compileLocal } from \"./compile.js\";\nimport { compile as compileBaseline } from \"@inlang/paraglide-js-baseline\";\nimport { createTestFsWithMessages } from \"./test-helpers.js\";\n\nconst require = createRequire(import.meta.url);\n\nfunction createMockMessages(numMessages: number, locale: string) {\n\treturn Object.fromEntries(\n\t\tArray.from({ length: numMessages }, (_, i) => [\n\t\t\t`message_${i}`,\n\t\t\t`Hello world {username} (${locale})`,\n\t\t])\n\t);\n}\n\nfunction createLocales(count: number): string[] {\n\treturn Array.from({ length: count }, (_, i) =>\n\t\ti === 0 ? \"en\" : `l${String(i).padStart(2, \"0\")}`\n\t);\n}\n\nfunction createBaselineProjectFs(numMessages: number, locales: string[]) {\n\tconst pluginPath = require.resolve(\"@inlang/plugin-message-format\");\n\tconst pluginSource = readFileSync(pluginPath, \"utf8\");\n\tconst files: Record<string, string> = {\n\t\t\"/plugin.js\": pluginSource,\n\t\t\"/project.inlang/settings.json\": JSON.stringify({\n\t\t\tbaseLocale: locales[0],\n\t\t\tlocales,\n\t\t\tmodules: [\"/plugin.js\"],\n\t\t\t\"plugin.inlang.messageFormat\": {\n\t\t\t\tpathPattern: \"/{locale}.json\",\n\t\t\t},\n\t\t}),\n\t};\n\tfor (const locale of locales) {\n\t\tfiles[`/${locale}.json`] = JSON.stringify(\n\t\t\tcreateMockMessages(numMessages, locale)\n\t\t);\n\t}\n\n\treturn memfs(files).fs as unknown as typeof import(\"node:fs\");\n}\n\nfunction createLocalMessageFs(numMessages: number, locales: string[]) {\n\treturn createTestFsWithMessages({\n\t\tmessages: Object.fromEntries(\n\t\t\tlocales.map((locale) => [\n\t\t\t\tlocale,\n\t\t\t\tcreateMockMessages(numMessages, locale),\n\t\t\t])\n\t\t),\n\t\tpathPattern: \"/{locale}.json\",\n\t});\n}\n\nconst SCALES = [\n\t{ messages: 1_000, locales: 1, compareBaseline: true },\n\t{ messages: 10_000, locales: 10, compareBaseline: false },\n] as const;\n\nfor (const { messages, locales: localeCount, compareBaseline } of SCALES) {\n\tconst locales = createLocales(localeCount);\n\tconst label = `${messages} messages × ${localeCount} locales`;\n\t// Fewer samples at the large scale so the suite stays practical.\n\tconst time = localeCount === 1 ? 1500 : 3000;\n\n\tbench(\n\t\t`local compile (${label}, emitFiles: true)`,\n\t\tasync () => {\n\t\t\tconst fs = createLocalMessageFs(messages, locales);\n\n\t\t\tawait compileLocal({\n\t\t\t\tmessages: \"/{locale}.json\",\n\t\t\t\tlocales,\n\t\t\t\tbaseLocale: locales[0]!,\n\t\t\t\toutdir: `/output-local-${messages}-${localeCount}`,\n\t\t\t\tfs,\n\t\t\t});\n\t\t},\n\t\t{ time }\n\t);\n\n\tbench(\n\t\t`local compile (${label}, emitFiles: false / virtual)`,\n\t\tasync () => {\n\t\t\tconst fs = createLocalMessageFs(messages, locales);\n\n\t\t\tawait compileLocal({\n\t\t\t\tmessages: \"/{locale}.json\",\n\t\t\t\tlocales,\n\t\t\t\tbaseLocale: locales[0]!,\n\t\t\t\toutdir: `/output-virtual-${messages}-${localeCount}`,\n\t\t\t\temitFiles: false,\n\t\t\t\tfs,\n\t\t\t});\n\t\t},\n\t\t{ time }\n\t);\n\n\t// Upstream inlang SDK baseline is ~20s/iter at 10k×10 — keep it only at\n\t// the small scale where the comparison is still practical.\n\tif (compareBaseline) {\n\t\tbench(\n\t\t\t`published @inlang/paraglide-js@2.23.1 (${label}, inlang SDK)`,\n\t\t\tasync () => {\n\t\t\t\tconst fs = createBaselineProjectFs(messages, locales);\n\n\t\t\t\tawait compileBaseline({\n\t\t\t\t\tproject: \"/project.inlang\",\n\t\t\t\t\toutdir: `/output-baseline-${messages}-${localeCount}`,\n\t\t\t\t\tfs,\n\t\t\t\t});\n\t\t\t},\n\t\t\t{ time }\n\t\t);\n\t}\n}\n"]}
1
+ {"version":3,"file":"compile.bench.js","sourceRoot":"","sources":["../../src/compiler/compile.bench.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,QAAQ,CAAC;AAC/B,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C,SAAS,kBAAkB,CAAC,WAAmB,EAAE,MAAc;IAC9D,OAAO,MAAM,CAAC,WA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ACV,MAAM,EAAE,GAAG,oBAAoB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAEnD,MAAM,YAAY,CAAC;YAClB,QAAQ,EAAE,gBAAgB;YAC1B,OAAO;YACP,UAAU,EAAE,OAAO,CAAC,CAAC,CAAE;YACvB,MAAM,EAAE,mBAAmB,QAAQ,IAAI,WAAW,EAAE;YACpD,SAAS,EAAE,KAAK;YAChB,EAAE;SACF,CAAC,CAAC;IACJ,CAAC,EACD,EAAE,IAAI,EAAE,CACR,CAAC;IAEF,wEAAwE;IACxE,2DAA2D;IAC3D,IAAI,eAAe,EAAE,CAAC;QACrB,KAAK,CACJ,0CAA0C,KAAK,eAAe,EAC9D,KAAK,IAAI,EAAE;YACV,MAAM,EAAE,GAAG,uBAAuB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAEtD,MAAM,eAAe,CAAC;gBACrB,OAAO,EAAE,iBAAiB;gBAC1B,MAAM,EAAE,oBAAoB,QAAQ,IAAI,WAAW,EAAE;gBACrD,EAAE;aACF,CAAC,CAAC;QACJ,CAAC,EACD,EAAE,IAAI,EAAE,CACR,CAAC;IACH,CAAC;AACF,CAAC","sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { bench } from \"vitest\";\nimport { memfs } from \"memfs\";\nimport { compile as compileLocal } from \"./compile.js\";\nimport { compile as compileBaseline } from \"@inlang/paraglide-js-baseline\";\nimport { createTestFsWithMessages } from \"./test-helpers.js\";\n\nconst require = createRequire(import.meta.url);\n\nfunction createMockMessages(numMessages: number, locale: string) {\n\treturn Object.fromEntries(\n\t\tArray.from({ length: numMessages }, (_, i) => [\n\t\t\t`message_${i}`,\n\t\t\t`Hello world {username} (${locale})`,\n\t\t])\n\t);\n}\n\nfunction createLocales(count: number): string[] {\n\treturn Array.from({ length: count }, (_, i) =>\n\t\ti === 0 ? \"en\" : `l${String(i).padStart(2, \"0\")}`\n\t);\n}\n\nfunction createBaselineProjectFs(numMessages: number, locales: string[]) {\n\tconst pluginPath = require.resolve(\"@inlang/plugin-message-format\");\n\tconst pluginSource = readFileSync(pluginPath, \"utf8\");\n\tconst files: Record<string, string> = {\n\t\t\"/plugin.js\": pluginSource,\n\t\t\"/project.inlang/settings.json\": JSON.stringify({\n\t\t\tbaseLocale: locales[0],\n\t\t\tlocales,\n\t\t\tmodules: [\"/plugin.js\"],\n\t\t\t\"plugin.inlang.messageFormat\": {\n\t\t\t\tpathPattern: \"/{locale}.json\",\n\t\t\t},\n\t\t}),\n\t};\n\tfor (const locale of locales) {\n\t\tfiles[`/${locale}.json`] = JSON.stringify(\n\t\t\tcreateMockMessages(numMessages, locale)\n\t\t);\n\t}\n\n\treturn memfs(files).fs as unknown as typeof import(\"node:fs\");\n}\n\nfunction createLocalMessageFs(numMessages: number, locales: string[]) {\n\treturn createTestFsWithMessages({\n\t\tmessages: Object.fromEntries(\n\t\t\tlocales.map((locale) => [\n\t\t\t\tlocale,\n\t\t\t\tcreateMockMessages(numMessages, locale),\n\t\t\t])\n\t\t),\n\t\tpathPattern: \"/{locale}.json\",\n\t});\n}\n\nconst SCALES = [\n\t{ messages: 1_000, locales: 1, compareBaseline: true },\n\t{ messages: 10_000, locales: 10, compareBaseline: false },\n] as const;\n\nfor (const { messages, locales: localeCount, compareBaseline } of SCALES) {\n\tconst locales = createLocales(localeCount);\n\tconst label = `${messages} messages × ${localeCount} locales`;\n\t// Fewer samples at the large scale so the suite stays practical.\n\tconst time = localeCount === 1 ? 1500 : 3000;\n\n\tbench(\n\t\t`local compile (${label}, emitFiles: true)`,\n\t\tasync () => {\n\t\t\tconst fs = createLocalMessageFs(messages, locales);\n\n\t\t\tawait compileLocal({\n\t\t\t\tmessages: \"/{locale}.json\",\n\t\t\t\tlocales,\n\t\t\t\tbaseLocale: locales[0]!,\n\t\t\t\toutdir: `/output-local-${messages}-${localeCount}`,\n\t\t\t\tfs,\n\t\t\t});\n\t\t},\n\t\t{ time }\n\t);\n\n\tbench(\n\t\t`local compile (${label}, emitFiles: false / virtual)`,\n\t\tasync () => {\n\t\t\tconst fs = createLocalMessageFs(messages, locales);\n\n\t\t\tawait compileLocal({\n\t\t\t\tmessages: \"/{locale}.json\",\n\t\t\t\tlocales,\n\t\t\t\tbaseLocale: locales[0]!,\n\t\t\t\toutdir: `/output-virtual-${messages}-${localeCount}`,\n\t\t\t\temitFiles: false,\n\t\t\t\tfs,\n\t\t\t});\n\t\t},\n\t\t{ time }\n\t);\n\n\t// Upstream inlang SDK baseline is ~20s/iter at 10k×10 — keep it only at\n\t// the small scale where the comparison is still practical.\n\tif (compareBaseline) {\n\t\tbench(\n\t\t\t`published @inlang/paraglide-js@2.25.0 (${label}, inlang SDK)`,\n\t\t\tasync () => {\n\t\t\t\tconst fs = createBaselineProjectFs(messages, locales);\n\n\t\t\t\tawait compileBaseline({\n\t\t\t\t\tproject: \"/project.inlang\",\n\t\t\t\t\toutdir: `/output-baseline-${messages}-${localeCount}`,\n\t\t\t\t\tfs,\n\t\t\t\t});\n\t\t\t},\n\t\t\t{ time }\n\t\t);\n\t}\n}\n"]}
@@ -63,4 +63,18 @@ test("applies strategy from compiler options to runtime output", async () => {
63
63
  expect(runtime).toContain('"url"');
64
64
  expect(runtime).toContain('"cookie"');
65
65
  });
66
+ test("runtime output strips sourcemap references", async () => {
67
+ const fs = createTestFsWithMessages({
68
+ messages: { en: { hello: "Hello" }, de: { hello: "Hallo" } },
69
+ });
70
+ await compile({
71
+ ...defaultCompileOptions,
72
+ outdir: "/output",
73
+ fs,
74
+ });
75
+ const runtimeFile = await fs.promises.readFile("/output/runtime.js", "utf8");
76
+ const serverFile = await fs.promises.readFile("/output/server.js", "utf8");
77
+ expect(runtimeFile).not.toMatch(/sourceMappingURL=/);
78
+ expect(serverFile).not.toMatch(/sourceMappingURL=/);
79
+ });
66
80
  //# sourceMappingURL=compile.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"compile.test.js","sourceRoot":"","sources":["../../src/compiler/compile.test.ts"],"names":[],"mapp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AE,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;KAC5D,CAAC,CAAC;IAEH,MAAM,OAAO,CAAC;QACb,GAAG,qBAAqB;QACxB,MAAM,EAAE,SAAS;QACjB,EAAE;QACF,QAAQ,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,YAAY,CAAwB;KAChE,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;IACzE,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACnC,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;AACvC,CAAC,CAAC,CAAC","sourcesContent":["import { memfs } from \"memfs\";\nimport { test, expect, vi } from \"vitest\";\nimport { compile } from \"./compile.js\";\nimport type { Runtime } from \"./runtime/type.js\";\nimport { createTestFsWithMessages, defaultCompileOptions } from \"./test-helpers.js\";\nimport consola from \"consola\";\n\ntest(\"loads message files and compiles them\", async () => {\n\tconst fs = createTestFsWithMessages({\n\t\tmessages: {\n\t\t\ten: { hello: \"Hello\" },\n\t\t\tde: { hello: \"Hallo\" },\n\t\t\tfr: { hello: \"Bonjour\" },\n\t\t},\n\t});\n\n\tawait compile({\n\t\tmessages: defaultCompileOptions.messages,\n\t\tlocales: [\"en\", \"de\", \"fr\"],\n\t\tbaseLocale: \"en\",\n\t\toutdir: \"/output\",\n\t\tfs,\n\t});\n\n\tconst files = await fs.promises.readdir(\"/output\");\n\texpect(files).toEqual(\n\t\texpect.arrayContaining([\"runtime.js\", \"server.js\", \"messages.js\"])\n\t);\n});\n\ntest(\"cleans the output directory\", async () => {\n\tconst fs = memfs({\n\t\t\"/output/old-file.js\": \"old\",\n\t\t\"/messages/en.json\": JSON.stringify({ hello: \"Hello\" }),\n\t\t\"/messages/de.json\": JSON.stringify({ hello: \"Hallo\" }),\n\t}).fs as unknown as typeof import(\"node:fs\");\n\n\tawait compile({\n\t\tmessages: \"/messages/{locale}.json\",\n\t\tlocales: [\"en\", \"de\"],\n\t\tbaseLocale: \"en\",\n\t\toutdir: \"/output\",\n\t\tfs,\n\t\tcleanOutdir: true,\n\t});\n\n\tawait expect(fs.promises.readFile(\"/output/old-file.js\", \"utf8\")).rejects.toThrow();\n});\n\ntest(\"deduplicates concurrent compilations\", async () => {\n\tconst fs = createTestFsWithMessages({\n\t\tmessages: { en: { hello: \"Hello\" }, de: { hello: \"Hallo\" } },\n\t});\n\n\tconst compileSpy = vi.fn(compile);\n\tconsola.mockTypes(() => vi.fn());\n\n\tawait Promise.all([\n\t\tcompile({ ...defaultCompileOptions, outdir: \"/output\", fs }),\n\t\tcompile({ ...defaultCompileOptions, outdir: \"/output\", fs }),\n\t]);\n\n\tvoid compileSpy;\n});\n\ntest(\"applies strategy from compiler options to runtime output\", async () => {\n\tconst fs = createTestFsWithMessages({\n\t\tmessages: { en: { hello: \"Hello\" }, de: { hello: \"Hallo\" } },\n\t});\n\n\tawait compile({\n\t\t...defaultCompileOptions,\n\t\toutdir: \"/output\",\n\t\tfs,\n\t\tstrategy: [\"url\", \"cookie\", \"baseLocale\"] as Runtime[\"strategy\"],\n\t});\n\n\tconst runtime = await fs.promises.readFile(\"/output/runtime.js\", \"utf8\");\n\texpect(runtime).toContain('\"url\"');\n\texpect(runtime).toContain('\"cookie\"');\n});\n"]}
1
+ {"version":3,"file":"compile.test.js","sourceRoot":"","sources":["../../src/compiler/compile.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AACpF,OA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H,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;IACzE,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;IACnC,MAAM,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;AACvC,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,4CAA4C,EAAE,KAAK,IAAI,EAAE;IAC7D,MAAM,EAAE,GAAG,wBAAwB,CAAC;QACnC,QAAQ,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;KAC5D,CAAC,CAAC;IAEH,MAAM,OAAO,CAAC;QACb,GAAG,qBAAqB;QACxB,MAAM,EAAE,SAAS;QACjB,EAAE;KACF,CAAC,CAAC;IAEH,MAAM,WAAW,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,oBAAoB,EAAE,MAAM,CAAC,CAAC;IAC7E,MAAM,UAAU,GAAG,MAAM,EAAE,CAAC,QAAQ,CAAC,QAAQ,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;IAE3E,MAAM,CAAC,WAAW,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACrD,MAAM,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;AACrD,CAAC,CAAC,CAAC","sourcesContent":["import { memfs } from \"memfs\";\nimport { test, expect, vi } from \"vitest\";\nimport { compile } from \"./compile.js\";\nimport type { Runtime } from \"./runtime/type.js\";\nimport { createTestFsWithMessages, defaultCompileOptions } from \"./test-helpers.js\";\nimport consola from \"consola\";\n\ntest(\"loads message files and compiles them\", async () => {\n\tconst fs = createTestFsWithMessages({\n\t\tmessages: {\n\t\t\ten: { hello: \"Hello\" },\n\t\t\tde: { hello: \"Hallo\" },\n\t\t\tfr: { hello: \"Bonjour\" },\n\t\t},\n\t});\n\n\tawait compile({\n\t\tmessages: defaultCompileOptions.messages,\n\t\tlocales: [\"en\", \"de\", \"fr\"],\n\t\tbaseLocale: \"en\",\n\t\toutdir: \"/output\",\n\t\tfs,\n\t});\n\n\tconst files = await fs.promises.readdir(\"/output\");\n\texpect(files).toEqual(\n\t\texpect.arrayContaining([\"runtime.js\", \"server.js\", \"messages.js\"])\n\t);\n});\n\ntest(\"cleans the output directory\", async () => {\n\tconst fs = memfs({\n\t\t\"/output/old-file.js\": \"old\",\n\t\t\"/messages/en.json\": JSON.stringify({ hello: \"Hello\" }),\n\t\t\"/messages/de.json\": JSON.stringify({ hello: \"Hallo\" }),\n\t}).fs as unknown as typeof import(\"node:fs\");\n\n\tawait compile({\n\t\tmessages: \"/messages/{locale}.json\",\n\t\tlocales: [\"en\", \"de\"],\n\t\tbaseLocale: \"en\",\n\t\toutdir: \"/output\",\n\t\tfs,\n\t\tcleanOutdir: true,\n\t});\n\n\tawait expect(fs.promises.readFile(\"/output/old-file.js\", \"utf8\")).rejects.toThrow();\n});\n\ntest(\"deduplicates concurrent compilations\", async () => {\n\tconst fs = createTestFsWithMessages({\n\t\tmessages: { en: { hello: \"Hello\" }, de: { hello: \"Hallo\" } },\n\t});\n\n\tconst compileSpy = vi.fn(compile);\n\tconsola.mockTypes(() => vi.fn());\n\n\tawait Promise.all([\n\t\tcompile({ ...defaultCompileOptions, outdir: \"/output\", fs }),\n\t\tcompile({ ...defaultCompileOptions, outdir: \"/output\", fs }),\n\t]);\n\n\tvoid compileSpy;\n});\n\ntest(\"applies strategy from compiler options to runtime output\", async () => {\n\tconst fs = createTestFsWithMessages({\n\t\tmessages: { en: { hello: \"Hello\" }, de: { hello: \"Hallo\" } },\n\t});\n\n\tawait compile({\n\t\t...defaultCompileOptions,\n\t\toutdir: \"/output\",\n\t\tfs,\n\t\tstrategy: [\"url\", \"cookie\", \"baseLocale\"] as Runtime[\"strategy\"],\n\t});\n\n\tconst runtime = await fs.promises.readFile(\"/output/runtime.js\", \"utf8\");\n\texpect(runtime).toContain('\"url\"');\n\texpect(runtime).toContain('\"cookie\"');\n});\n\ntest(\"runtime output strips sourcemap references\", async () => {\n\tconst fs = createTestFsWithMessages({\n\t\tmessages: { en: { hello: \"Hello\" }, de: { hello: \"Hallo\" } },\n\t});\n\n\tawait compile({\n\t\t...defaultCompileOptions,\n\t\toutdir: \"/output\",\n\t\tfs,\n\t});\n\n\tconst runtimeFile = await fs.promises.readFile(\"/output/runtime.js\", \"utf8\");\n\tconst serverFile = await fs.promises.readFile(\"/output/server.js\", \"utf8\");\n\n\texpect(runtimeFile).not.toMatch(/sourceMappingURL=/);\n\texpect(serverFile).not.toMatch(/sourceMappingURL=/);\n});\n"]}
@@ -122,7 +122,7 @@ export type CompilerOptions = {
122
122
  * server-side takes the globalVariable (because cookie is unavailable),
123
123
  * whereas both fallback to the base locale if not available.
124
124
  *
125
- * Custom strategies with the pattern `custom-[A-Za-z0-9]+` are supported.
125
+ * Custom strategies with the pattern `custom-[A-Za-z0-9_-]+` are supported.
126
126
  *
127
127
  * @default ["cookie", "globalVariable", "baseLocale"]
128
128
  */
@@ -367,6 +367,14 @@ export type CompilerOptions = {
367
367
  * @see RoutingConfig
368
368
  */
369
369
  routing?: RoutingConfig;
370
+ /**
371
+ * Controls trailing slash canonicalization for localized URLs.
372
+ *
373
+ * Canonicalization happens before URL pattern matching and after URL
374
+ * localization. If omitted, Paraglide keeps its existing trailing slash
375
+ * behavior.
376
+ */
377
+ trailingSlash?: "always" | "never";
370
378
  /**
371
379
  * Whether to include an eslint-disable comment at the top of each .js file.
372
380
  *
@@ -1 +1 @@
1
- {"version":3,"file":"compiler-options.js","sourceRoot":"","sources":["../../src/compiler/compiler-options.ts"],"names":[],"mappings":"AAgCA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACrC,QAAQ,EAAE,0BAA0B;IACpC,OAAO,EAAE,CAAC,IAAI,CAAC;IACf,UAAU,EAAE,IAAI;IAChB,eAAe,EAAE,iBAAiB;IAClC,aAAa,EAAE,IAAI;IACnB,2BAA2B,EAAE,IAAI;IACjC,kBAAkB,EAAE,IAAI;IACxB,UAAU,EAAE,IAAI;IAChB,kBAAkB,EAAE,KAAK;IACzB,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,IAAI;IACjB,wBAAwB,EAAE,KAAK;IAC/B,qCAAqC,EAAE,KAAK;IAC5C,eAAe,EAAE,kBAAkB;IACnC,QAAQ,EAAE,+BAA+B;IACzC,QAAQ,EAAE,CAAC,QAAQ,EAAE,gBAAgB,EAAE,YAAY,CAAC;IACpD,UAAU,EAAE,kBAAkB;IAC9B,YAAY,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG;IAChC,YAAY,EAAE,EAAE;CAC4B,CAAC","sourcesContent":["import type { Runtime } from \"./runtime/type.js\";\n\nexport type RouteStrategy =\n\t| {\n\t\t\t/**\n\t\t\t * URLPattern-compatible matcher.\n\t\t\t */\n\t\t\tmatch: string;\n\t\t\t/**\n\t\t\t * Strategy override for matching requests.\n\t\t\t */\n\t\t\tstrategy: Runtime[\"strategy\"];\n\t\t\t/**\n\t\t\t * Prevent mutually exclusive configuration (`exclude` + `strategy`).\n\t\t\t */\n\t\t\texclude?: never;\n\t }\n\t| {\n\t\t\t/**\n\t\t\t * URLPattern-compatible matcher.\n\t\t\t */\n\t\t\tmatch: string;\n\t\t\t/**\n\t\t\t * Exclude matching requests from i18n middleware behavior.\n\t\t\t */\n\t\t\texclude: true;\n\t\t\t/**\n\t\t\t * Prevent mutually exclusive configuration (`exclude` + `strategy`).\n\t\t\t */\n\t\t\tstrategy?: never;\n\t };\n\nexport const defaultCompilerOptions = {\n\tmessages: \"./messages/{locale}.json\",\n\tlocales: [\"en\"],\n\tbaseLocale: \"en\",\n\toutputStructure: \"message-modules\",\n\temitGitIgnore: true,\n\tincludeEslintDisableComment: true,\n\temitPrettierIgnore: true,\n\temitReadme: true,\n\temitTsDeclarations: false,\n\temitFiles: true,\n\tcleanOutdir: true,\n\tdisableAsyncLocalStorage: false,\n\texperimentalMiddlewareLocaleSplitting: false,\n\tlocalStorageKey: \"PARAGLIDE_LOCALE\",\n\tisServer: \"typeof window === 'undefined'\",\n\tstrategy: [\"cookie\", \"globalVariable\", \"baseLocale\"],\n\tcookieName: \"PARAGLIDE_LOCALE\",\n\tcookieMaxAge: 60 * 60 * 24 * 400,\n\tcookieDomain: \"\",\n} as const satisfies Partial<CompilerOptions>;\n\n/**\n * Per-host URL routing rule.\n *\n * Path shape is always `/{locale}/{path}`, except the host `baseLocale`\n * which is bare (`/{path}`).\n */\nexport type HostRoutingRule = {\n\t/**\n\t * Locale served without a path prefix on this host.\n\t *\n\t * @example\n\t * // fin.example.com/ → fi, fin.example.com/en → en\n\t * baseLocale: \"fi\"\n\t */\n\tbaseLocale?: string;\n\t/**\n\t * Locales allowed on this host. Defaults to all project locales.\n\t */\n\tlocales?: string[];\n};\n\n/**\n * Hostname → routing rule map.\n *\n * Use `\"*\"` as the fallback for hosts that are not listed.\n *\n * @example\n * ```ts\n * routing: {\n * \"fin.example.com\": { baseLocale: \"fi\" },\n * \"app.example.com\": { baseLocale: \"sv\", locales: [\"sv\", \"en\", \"pt-PT\"] },\n * \"*\": { baseLocale: \"en\" },\n * }\n * ```\n */\nexport type RoutingConfig = Record<string, HostRoutingRule>;\n\nexport type CompilerOptions = {\n\t/**\n\t * Path pattern to locale message files. Must contain `{locale}`.\n\t *\n\t * @example \"./messages/{locale}.json\"\n\t */\n\tmessages: string;\n\t/**\n\t * Locales to compile.\n\t */\n\tlocales: string[];\n\t/**\n\t * Default locale used for fallbacks.\n\t */\n\tbaseLocale: string;\n\t/**\n\t * The path to the output directory.\n\t *\n\t * @example\n\t * ```diff\n\t * await compile({\n\t * messages: \"./messages/{locale}.json\",\n\t * + outdir: \"./src/paraglide\"\n\t * })\n\t * ```\n\t */\n\toutdir: string;\n\t/**\n\t * The strategy to use for getting the locale.\n\t *\n\t * The order of the strategy defines the precedence of matches.\n\t *\n\t * For example, in `['url', 'cookie', 'baseLocale']`, the locale will be\n\t * first tried to be detected in the url, then in a cookie, and finally\n\t * fallback to the base locale.\n\t *\n\t * The default ensures that the browser takes a cookie approach,\n\t * server-side takes the globalVariable (because cookie is unavailable),\n\t * whereas both fallback to the base locale if not available.\n\t *\n\t * Custom strategies with the pattern `custom-[A-Za-z0-9]+` are supported.\n\t *\n\t * @default [\"cookie\", \"globalVariable\", \"baseLocale\"]\n\t */\n\tstrategy?: Runtime[\"strategy\"];\n\t/**\n\t * Route-level strategy overrides.\n\t *\n\t * Routes are matched in declaration order. The first matching rule wins.\n\t * `match` uses URLPattern syntax and therefore requires the global URLPattern API\n\t * (polyfill older targets; see https://paraglidejs.com/i18n-routing#urlpattern-compatibility).\n\t *\n\t * - `strategy`: Override locale resolution for the matched route.\n\t * - `exclude: true`: Skip i18n middleware behavior for the matched route.\n\t *\n\t * @example\n\t * ```ts\n\t * routeStrategies: [\n\t * { match: \"/dashboard/:path(.*)?\", strategy: [\"cookie\", \"baseLocale\"] },\n\t * { match: \"/api/:path(.*)?\", exclude: true }\n\t * ]\n\t * ```\n\t */\n\trouteStrategies?: RouteStrategy[];\n\t/**\n\t * Whether or not to use experimental middleware locale splitting.\n\t *\n\t * ⚠️ This feature is experimental and only works in SSR/SSG environment\n\t * without client-side routing. Do not rely on this feature for production.\n\t *\n\t * This feature is part of the exploration of per locale splitting. The\n\t * issue is ongoing and can be followed here [#88](https://github.com/opral/inlang-paraglide-js/issues/88).\n\t *\n\t * - The client bundle will tree-shake all messages (have close to 0kb JS).\n\t * - The server middleware will inject the used messages into the HTML.\n\t * - The client will re-trieve the messages from the injected HTML.\n\t *\n\t * @default false\n\t */\n\texperimentalMiddlewareLocaleSplitting?: boolean;\n\t/**\n\t * The name of the localStorage key to use for the localStorage strategy.\n\t *\n\t * @default 'PARAGLIDE_LOCALE'\n\t */\n\tlocalStorageKey?: string;\n\t/**\n\t * Tree-shaking flag if the code is running on the server.\n\t *\n\t * Dependent on the bundler, this flag must be adapted to\n\t * enable tree-shaking.\n\t *\n\t * @example\n\t * // vite\n\t * isServer: \"import.meta.env.SSR\"\n\t *\n\t * @default typeof window === \"undefined\"\n\t */\n\tisServer?: string;\n\t/**\n\t * Compile-time locale constant used for per-locale tree-shaking.\n\t *\n\t * This is experimental and opt-in. It should be a JavaScript expression\n\t * (not a quoted literal) that resolves to a locale or `undefined` at build time.\n\t * You can pass a string literal (e.g. `\"de\"`) for programmatic builds, or an\n\t * injected env/define expression for bundler-driven builds.\n\t *\n\t * High-level flow for per-locale builds:\n\t *\n\t * client request (/)\n\t * |\n\t * v\n\t * +----------------------+\n\t * | detect locale |\n\t * | (cookie/Accept-L) |\n\t * | pick build prefix |\n\t * +----------------------+\n\t * | if \"de\"\n\t * v\n\t * serve dist/de/... <----> serve dist/en/...\n\t * (HTML + assets) (HTML + assets)\n\t *\n\t * @see https://github.com/opral/paraglide-js/issues/88#issuecomment-3634754638\n\t *\n\t * @example\n\t * // Vite define\n\t * experimentalStaticLocale: \"typeof __PARAGLIDE_STATIC_LOCALE__ === 'undefined' ? undefined : __PARAGLIDE_STATIC_LOCALE__\"\n\t *\n\t * @example\n\t * // Programmatic compile (literal)\n\t * experimentalStaticLocale: '\"de\"'\n\t */\n\texperimentalStaticLocale?: string;\n\t/**\n\t * The name of the cookie to use for the cookie strategy.\n\t *\n\t * @default 'PARAGLIDE_LOCALE'\n\t */\n\tcookieName?: string;\n\t/**\n\t * The max-age in seconds of the cookie until it expires.\n\t *\n\t * @default 60 * 60 * 24 * 400\n\t */\n\tcookieMaxAge?: number;\n\t/**\n\t * The host to which the cookie will be sent.\n\t * If undefined or empty, the domain attribute is omitted from the cookie, scoping it to the exact current domain only (no subdomains).\n\t * If specified, the cookie will be available to the specified domain and all its subdomains.\n\t *\n\t * Use this when you need cookies to be shared across subdomains (e.g., between `app.example.com` and `api.example.com`).\n\t * The default behavior (no domain) ensures better compatibility with server-side cookies that don't specify a domain attribute.\n\t *\n\t * @example\n\t * ```ts\n\t * // Default: exact domain only (compatible with server-side cookies)\n\t * cookieDomain: undefined // Cookie: \"PARAGLIDE_LOCALE=en; path=/; max-age=34560000\"\n\t *\n\t * // Subdomain sharing: available across all subdomains\n\t * cookieDomain: \"example.com\" // Cookie: \"PARAGLIDE_LOCALE=en; path=/; max-age=34560000; domain=example.com\"\n\t * ```\n\t *\n\t * @default \"\" (no domain attribute, exact domain only)\n\t */\n\tcookieDomain?: string;\n\t/**\n\t * The `additionalFiles` option is an array of paths to additional files that should be copied to the output directory.\n\t *\n\t * @example\n\t *\n\t * ```diff\n\t * await compile({\n\t * project: \"./project.inlang\",\n\t * outdir: \"./src/paraglide\",\n\t * additionalFiles: [\n\t * + \"my-file.js\": \"console.log('hello')\"\n\t * ]\n\t * })\n\t * ```\n\t *\n\t * The output will look like this:\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - my-file.js\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t */\n\tadditionalFiles?: Record<string, string>;\n\t/**\n\t * If `emitPrettierIgnore` is set to `true` a `.prettierignore` file will be emitted in the output directory. Defaults to `true`.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - .prettierignore\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * @default true\n\t */\n\temitPrettierIgnore?: boolean;\n\t/**\n\t * If `emitReadme` is set to `true` a `README.md` file will be emitted in the output directory. Defaults to `true`.\n\t *\n\t * The README helps LLMs understand the compiled output.\n\t * See https://llmstxt.org/ for format guidelines.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - README.md\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * @default true\n\t */\n\temitReadme?: boolean;\n\t/**\n\t * Emit `.d.ts` files for the generated output using the TypeScript compiler.\n\t *\n\t * Useful when `allowJs: true` cannot be set in your `tsconfig.json`\n\t * (e.g., due to project constraints or conflicting compiler options), or when\n\t * an editor language server caches stale JSDoc types for generated messages.\n\t *\n\t * Requires `typescript` to be resolvable in your toolchain.\n\t *\n\t * **Note:** Enabling this option reduces compiler speed because TypeScript\n\t * needs to generate declaration files for all output modules.\n\t *\n\t * **Note:** With TypeScript 5/6 the declarations are generated in-process.\n\t * TypeScript 7+ no longer provides the compiler API, so its `tsc` CLI is\n\t * invoked in a child process instead; the emitted declarations are\n\t * semantically equivalent but differ cosmetically between the two.\n\t *\n\t * @example\n\t * ```ts\n\t * await compile({\n\t * project: \"./project.inlang\",\n\t * outdir: \"./src/paraglide\",\n\t * emitTsDeclarations: true,\n\t * });\n\t * ```\n\t *\n\t * @default false\n\t */\n\temitTsDeclarations?: boolean;\n\t/**\n\t * Controls which compiled files are written to `outdir`.\n\t *\n\t * - `true` — write the full output tree (default). Required for the CLI\n\t * and for bundlers that cannot load virtual modules (webpack, etc.).\n\t * - `\"types\"` — write `.d.ts` plus meta files (`.gitignore`,\n\t * `.prettierignore`, `README.md`, `messages/package.json`). Generated\n\t * `.js` is served from memory by the Vite/Rolldown plugins.\n\t * - `false` — write nothing except `.d.ts` when `emitTsDeclarations` is\n\t * enabled. Generated `.js` is virtual only.\n\t *\n\t * @default true\n\t */\n\temitFiles?: true | false | \"types\";\n\t/**\n\t * Custom URL patterns for advanced i18n routing (translated pathnames, domains, etc.).\n\t *\n\t * Uses the global [URLPattern](https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API) API.\n\t * Default locale-prefix routing and {@link CompilerOptions.routing} do not need URLPattern.\n\t * For older browsers/runtimes, load a polyfill (e.g. `import \"urlpattern-polyfill\"`) before the\n\t * generated runtime. See https://paraglidejs.com/i18n-routing#urlpattern-compatibility\n\t *\n\t * https://paraglidejs.com/strategy#url\n\t */\n\turlPatterns?: Runtime[\"urlPatterns\"];\n\t/**\n\t * Fast per-host locale prefix routing (no URLPattern).\n\t *\n\t * When set, Paraglide uses string path ops instead of `urlPatterns`.\n\t * Do not combine with `urlPatterns`.\n\t *\n\t * @see RoutingConfig\n\t */\n\trouting?: RoutingConfig;\n\t/**\n\t * Whether to include an eslint-disable comment at the top of each .js file.\n\t *\n\t * @default true\n\t */\n\tincludeEslintDisableComment?: boolean;\n\t/**\n\t * Replaces AsyncLocalStorage with a synchronous implementation.\n\t *\n\t * Leave AsyncLocalStorage enabled by default. This option is a\n\t * compatibility fallback for runtimes that do not provide\n\t * AsyncLocalStorage or `node:async_hooks`.\n\t *\n\t * ⚠️ WARNING: Only use this option when your runtime also guarantees\n\t * request isolation. Disabling AsyncLocalStorage in multi-request\n\t * server environments risks cross-request pollution where state from\n\t * one request could leak into another concurrent request.\n\t */\n\tdisableAsyncLocalStorage?: boolean;\n\t/**\n\t * If `emitGitIgnore` is set to `true` a `.gitignore` file will be emitted in the output directory. Defaults to `true`.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - .gitignore\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * @default true\n\t */\n\temitGitIgnore?: boolean;\n\t/**\n\t * The `outputStructure` defines how modules are structured in the output.\n\t *\n\t * - `message-modules` - Each module is a message. This is the default.\n\t * - `locale-modules` - Each module is a locale.\n\t *\n\t * It is recommended to use `locale-modules` for development and `message-modules` for production.\n\t * Bundlers speed up the dev mode by bypassing bundling which can lead to many http requests\n\t * during the dev mode with `message-modules`. See https://github.com/opral/inlang-paraglide-js/issues/486.\n\t *\n\t * **`message-modules`**\n\t *\n\t * Messages have their own module which eases tree-shaking for bundlers.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - blue_elephant_tree/\n\t * + - index.js\n\t * + - en.js\n\t * + - fr.js\n\t * + - sky_phone_bottle/\n\t * + - index.js\n\t * + - en.js\n\t * + - fr.js\n\t * - ...\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * **`locale-modules`**\n\t *\n\t * Messages are bundled in a per locale module. Bundlers often struggle with tree-shaking this structure,\n\t * which can lead to more inefficient tree-shaking and larger bundle sizes compared to `message-modules`.\n\t *\n\t * The benefit are substantially fewer files which is needed in large projects.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - de.js\n\t * + - en.js\n\t * + - fr.js\n\t * - ...\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * @default \"message-modules\"\n\t */\n\toutputStructure?: \"locale-modules\" | \"message-modules\";\n\t/**\n\t * Whether to clean the output directory before writing the new files.\n\t *\n\t * @default true\n\t */\n\tcleanOutdir?: boolean;\n\n\t/**\n\t * The file system to use. Defaults to `await import('node:fs')`.\n\t *\n\t * Useful for testing the paraglide compiler by mocking the fs.\n\t */\n\tfs?: any;\n};\n"]}
1
+ {"version":3,"file":"compiler-options.js","sourceRoot":"","sources":["../../src/compiler/compiler-options.ts"],"names":[],"mappings":"AAgCA,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACrC,QAAQ,EAAE,0BAA0B;IACpC,OAAO,EAAE,CAAC,IAAI,CAAC;IACf,UAAU,EAAE,IAAI;IAChB,eAAe,EAAE,iBAAiB;IAClC,aAAa,EAAE,IAAI;IACnB,2BAA2B,EAAE,IAAI;IACjC,kBAAkB,EAAE,IAAI;IACxB,UAAU,EAAE,IAAI;IAChB,kBAAkB,EAAE,KAAK;IACzB,SAAS,EAAE,IAAI;IACf,WAAW,EAAE,IAAI;IACjB,wBAAwB,EAAE,KAAK;IAC/B,qCAAqC,EAAE,KAAK;IAC5C,eAAe,EAAE,kBAAkB;IACnC,QAAQ,EAAE,+BAA+B;IACzC,QAAQ,EAAE,CAAC,QAAQ,EAAE,gBAAgB,EAAE,YAAY,CAAC;IACpD,UAAU,EAAE,kBAAkB;IAC9B,YAAY,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,GAAG;IAChC,YAAY,EAAE,EAAE;CAC4B,CAAC","sourcesContent":["import type { Runtime } from \"./runtime/type.js\";\n\nexport type RouteStrategy =\n\t| {\n\t\t\t/**\n\t\t\t * URLPattern-compatible matcher.\n\t\t\t */\n\t\t\tmatch: string;\n\t\t\t/**\n\t\t\t * Strategy override for matching requests.\n\t\t\t */\n\t\t\tstrategy: Runtime[\"strategy\"];\n\t\t\t/**\n\t\t\t * Prevent mutually exclusive configuration (`exclude` + `strategy`).\n\t\t\t */\n\t\t\texclude?: never;\n\t }\n\t| {\n\t\t\t/**\n\t\t\t * URLPattern-compatible matcher.\n\t\t\t */\n\t\t\tmatch: string;\n\t\t\t/**\n\t\t\t * Exclude matching requests from i18n middleware behavior.\n\t\t\t */\n\t\t\texclude: true;\n\t\t\t/**\n\t\t\t * Prevent mutually exclusive configuration (`exclude` + `strategy`).\n\t\t\t */\n\t\t\tstrategy?: never;\n\t };\n\nexport const defaultCompilerOptions = {\n\tmessages: \"./messages/{locale}.json\",\n\tlocales: [\"en\"],\n\tbaseLocale: \"en\",\n\toutputStructure: \"message-modules\",\n\temitGitIgnore: true,\n\tincludeEslintDisableComment: true,\n\temitPrettierIgnore: true,\n\temitReadme: true,\n\temitTsDeclarations: false,\n\temitFiles: true,\n\tcleanOutdir: true,\n\tdisableAsyncLocalStorage: false,\n\texperimentalMiddlewareLocaleSplitting: false,\n\tlocalStorageKey: \"PARAGLIDE_LOCALE\",\n\tisServer: \"typeof window === 'undefined'\",\n\tstrategy: [\"cookie\", \"globalVariable\", \"baseLocale\"],\n\tcookieName: \"PARAGLIDE_LOCALE\",\n\tcookieMaxAge: 60 * 60 * 24 * 400,\n\tcookieDomain: \"\",\n} as const satisfies Partial<CompilerOptions>;\n\n/**\n * Per-host URL routing rule.\n *\n * Path shape is always `/{locale}/{path}`, except the host `baseLocale`\n * which is bare (`/{path}`).\n */\nexport type HostRoutingRule = {\n\t/**\n\t * Locale served without a path prefix on this host.\n\t *\n\t * @example\n\t * // fin.example.com/ → fi, fin.example.com/en → en\n\t * baseLocale: \"fi\"\n\t */\n\tbaseLocale?: string;\n\t/**\n\t * Locales allowed on this host. Defaults to all project locales.\n\t */\n\tlocales?: string[];\n};\n\n/**\n * Hostname → routing rule map.\n *\n * Use `\"*\"` as the fallback for hosts that are not listed.\n *\n * @example\n * ```ts\n * routing: {\n * \"fin.example.com\": { baseLocale: \"fi\" },\n * \"app.example.com\": { baseLocale: \"sv\", locales: [\"sv\", \"en\", \"pt-PT\"] },\n * \"*\": { baseLocale: \"en\" },\n * }\n * ```\n */\nexport type RoutingConfig = Record<string, HostRoutingRule>;\n\nexport type CompilerOptions = {\n\t/**\n\t * Path pattern to locale message files. Must contain `{locale}`.\n\t *\n\t * @example \"./messages/{locale}.json\"\n\t */\n\tmessages: string;\n\t/**\n\t * Locales to compile.\n\t */\n\tlocales: string[];\n\t/**\n\t * Default locale used for fallbacks.\n\t */\n\tbaseLocale: string;\n\t/**\n\t * The path to the output directory.\n\t *\n\t * @example\n\t * ```diff\n\t * await compile({\n\t * messages: \"./messages/{locale}.json\",\n\t * + outdir: \"./src/paraglide\"\n\t * })\n\t * ```\n\t */\n\toutdir: string;\n\t/**\n\t * The strategy to use for getting the locale.\n\t *\n\t * The order of the strategy defines the precedence of matches.\n\t *\n\t * For example, in `['url', 'cookie', 'baseLocale']`, the locale will be\n\t * first tried to be detected in the url, then in a cookie, and finally\n\t * fallback to the base locale.\n\t *\n\t * The default ensures that the browser takes a cookie approach,\n\t * server-side takes the globalVariable (because cookie is unavailable),\n\t * whereas both fallback to the base locale if not available.\n\t *\n\t * Custom strategies with the pattern `custom-[A-Za-z0-9_-]+` are supported.\n\t *\n\t * @default [\"cookie\", \"globalVariable\", \"baseLocale\"]\n\t */\n\tstrategy?: Runtime[\"strategy\"];\n\t/**\n\t * Route-level strategy overrides.\n\t *\n\t * Routes are matched in declaration order. The first matching rule wins.\n\t * `match` uses URLPattern syntax and therefore requires the global URLPattern API\n\t * (polyfill older targets; see https://paraglidejs.com/i18n-routing#urlpattern-compatibility).\n\t *\n\t * - `strategy`: Override locale resolution for the matched route.\n\t * - `exclude: true`: Skip i18n middleware behavior for the matched route.\n\t *\n\t * @example\n\t * ```ts\n\t * routeStrategies: [\n\t * { match: \"/dashboard/:path(.*)?\", strategy: [\"cookie\", \"baseLocale\"] },\n\t * { match: \"/api/:path(.*)?\", exclude: true }\n\t * ]\n\t * ```\n\t */\n\trouteStrategies?: RouteStrategy[];\n\t/**\n\t * Whether or not to use experimental middleware locale splitting.\n\t *\n\t * ⚠️ This feature is experimental and only works in SSR/SSG environment\n\t * without client-side routing. Do not rely on this feature for production.\n\t *\n\t * This feature is part of the exploration of per locale splitting. The\n\t * issue is ongoing and can be followed here [#88](https://github.com/opral/inlang-paraglide-js/issues/88).\n\t *\n\t * - The client bundle will tree-shake all messages (have close to 0kb JS).\n\t * - The server middleware will inject the used messages into the HTML.\n\t * - The client will re-trieve the messages from the injected HTML.\n\t *\n\t * @default false\n\t */\n\texperimentalMiddlewareLocaleSplitting?: boolean;\n\t/**\n\t * The name of the localStorage key to use for the localStorage strategy.\n\t *\n\t * @default 'PARAGLIDE_LOCALE'\n\t */\n\tlocalStorageKey?: string;\n\t/**\n\t * Tree-shaking flag if the code is running on the server.\n\t *\n\t * Dependent on the bundler, this flag must be adapted to\n\t * enable tree-shaking.\n\t *\n\t * @example\n\t * // vite\n\t * isServer: \"import.meta.env.SSR\"\n\t *\n\t * @default typeof window === \"undefined\"\n\t */\n\tisServer?: string;\n\t/**\n\t * Compile-time locale constant used for per-locale tree-shaking.\n\t *\n\t * This is experimental and opt-in. It should be a JavaScript expression\n\t * (not a quoted literal) that resolves to a locale or `undefined` at build time.\n\t * You can pass a string literal (e.g. `\"de\"`) for programmatic builds, or an\n\t * injected env/define expression for bundler-driven builds.\n\t *\n\t * High-level flow for per-locale builds:\n\t *\n\t * client request (/)\n\t * |\n\t * v\n\t * +----------------------+\n\t * | detect locale |\n\t * | (cookie/Accept-L) |\n\t * | pick build prefix |\n\t * +----------------------+\n\t * | if \"de\"\n\t * v\n\t * serve dist/de/... <----> serve dist/en/...\n\t * (HTML + assets) (HTML + assets)\n\t *\n\t * @see https://github.com/opral/paraglide-js/issues/88#issuecomment-3634754638\n\t *\n\t * @example\n\t * // Vite define\n\t * experimentalStaticLocale: \"typeof __PARAGLIDE_STATIC_LOCALE__ === 'undefined' ? undefined : __PARAGLIDE_STATIC_LOCALE__\"\n\t *\n\t * @example\n\t * // Programmatic compile (literal)\n\t * experimentalStaticLocale: '\"de\"'\n\t */\n\texperimentalStaticLocale?: string;\n\t/**\n\t * The name of the cookie to use for the cookie strategy.\n\t *\n\t * @default 'PARAGLIDE_LOCALE'\n\t */\n\tcookieName?: string;\n\t/**\n\t * The max-age in seconds of the cookie until it expires.\n\t *\n\t * @default 60 * 60 * 24 * 400\n\t */\n\tcookieMaxAge?: number;\n\t/**\n\t * The host to which the cookie will be sent.\n\t * If undefined or empty, the domain attribute is omitted from the cookie, scoping it to the exact current domain only (no subdomains).\n\t * If specified, the cookie will be available to the specified domain and all its subdomains.\n\t *\n\t * Use this when you need cookies to be shared across subdomains (e.g., between `app.example.com` and `api.example.com`).\n\t * The default behavior (no domain) ensures better compatibility with server-side cookies that don't specify a domain attribute.\n\t *\n\t * @example\n\t * ```ts\n\t * // Default: exact domain only (compatible with server-side cookies)\n\t * cookieDomain: undefined // Cookie: \"PARAGLIDE_LOCALE=en; path=/; max-age=34560000\"\n\t *\n\t * // Subdomain sharing: available across all subdomains\n\t * cookieDomain: \"example.com\" // Cookie: \"PARAGLIDE_LOCALE=en; path=/; max-age=34560000; domain=example.com\"\n\t * ```\n\t *\n\t * @default \"\" (no domain attribute, exact domain only)\n\t */\n\tcookieDomain?: string;\n\t/**\n\t * The `additionalFiles` option is an array of paths to additional files that should be copied to the output directory.\n\t *\n\t * @example\n\t *\n\t * ```diff\n\t * await compile({\n\t * project: \"./project.inlang\",\n\t * outdir: \"./src/paraglide\",\n\t * additionalFiles: [\n\t * + \"my-file.js\": \"console.log('hello')\"\n\t * ]\n\t * })\n\t * ```\n\t *\n\t * The output will look like this:\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - my-file.js\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t */\n\tadditionalFiles?: Record<string, string>;\n\t/**\n\t * If `emitPrettierIgnore` is set to `true` a `.prettierignore` file will be emitted in the output directory. Defaults to `true`.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - .prettierignore\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * @default true\n\t */\n\temitPrettierIgnore?: boolean;\n\t/**\n\t * If `emitReadme` is set to `true` a `README.md` file will be emitted in the output directory. Defaults to `true`.\n\t *\n\t * The README helps LLMs understand the compiled output.\n\t * See https://llmstxt.org/ for format guidelines.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - README.md\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * @default true\n\t */\n\temitReadme?: boolean;\n\t/**\n\t * Emit `.d.ts` files for the generated output using the TypeScript compiler.\n\t *\n\t * Useful when `allowJs: true` cannot be set in your `tsconfig.json`\n\t * (e.g., due to project constraints or conflicting compiler options), or when\n\t * an editor language server caches stale JSDoc types for generated messages.\n\t *\n\t * Requires `typescript` to be resolvable in your toolchain.\n\t *\n\t * **Note:** Enabling this option reduces compiler speed because TypeScript\n\t * needs to generate declaration files for all output modules.\n\t *\n\t * **Note:** With TypeScript 5/6 the declarations are generated in-process.\n\t * TypeScript 7+ no longer provides the compiler API, so its `tsc` CLI is\n\t * invoked in a child process instead; the emitted declarations are\n\t * semantically equivalent but differ cosmetically between the two.\n\t *\n\t * @example\n\t * ```ts\n\t * await compile({\n\t * project: \"./project.inlang\",\n\t * outdir: \"./src/paraglide\",\n\t * emitTsDeclarations: true,\n\t * });\n\t * ```\n\t *\n\t * @default false\n\t */\n\temitTsDeclarations?: boolean;\n\t/**\n\t * Controls which compiled files are written to `outdir`.\n\t *\n\t * - `true` — write the full output tree (default). Required for the CLI\n\t * and for bundlers that cannot load virtual modules (webpack, etc.).\n\t * - `\"types\"` — write `.d.ts` plus meta files (`.gitignore`,\n\t * `.prettierignore`, `README.md`, `messages/package.json`). Generated\n\t * `.js` is served from memory by the Vite/Rolldown plugins.\n\t * - `false` — write nothing except `.d.ts` when `emitTsDeclarations` is\n\t * enabled. Generated `.js` is virtual only.\n\t *\n\t * @default true\n\t */\n\temitFiles?: true | false | \"types\";\n\t/**\n\t * Custom URL patterns for advanced i18n routing (translated pathnames, domains, etc.).\n\t *\n\t * Uses the global [URLPattern](https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API) API.\n\t * Default locale-prefix routing and {@link CompilerOptions.routing} do not need URLPattern.\n\t * For older browsers/runtimes, load a polyfill (e.g. `import \"urlpattern-polyfill\"`) before the\n\t * generated runtime. See https://paraglidejs.com/i18n-routing#urlpattern-compatibility\n\t *\n\t * https://paraglidejs.com/strategy#url\n\t */\n\turlPatterns?: Runtime[\"urlPatterns\"];\n\t/**\n\t * Fast per-host locale prefix routing (no URLPattern).\n\t *\n\t * When set, Paraglide uses string path ops instead of `urlPatterns`.\n\t * Do not combine with `urlPatterns`.\n\t *\n\t * @see RoutingConfig\n\t */\n\trouting?: RoutingConfig;\n\t/**\n\t * Controls trailing slash canonicalization for localized URLs.\n\t *\n\t * Canonicalization happens before URL pattern matching and after URL\n\t * localization. If omitted, Paraglide keeps its existing trailing slash\n\t * behavior.\n\t */\n\ttrailingSlash?: \"always\" | \"never\";\n\t/**\n\t * Whether to include an eslint-disable comment at the top of each .js file.\n\t *\n\t * @default true\n\t */\n\tincludeEslintDisableComment?: boolean;\n\t/**\n\t * Replaces AsyncLocalStorage with a synchronous implementation.\n\t *\n\t * Leave AsyncLocalStorage enabled by default. This option is a\n\t * compatibility fallback for runtimes that do not provide\n\t * AsyncLocalStorage or `node:async_hooks`.\n\t *\n\t * ⚠️ WARNING: Only use this option when your runtime also guarantees\n\t * request isolation. Disabling AsyncLocalStorage in multi-request\n\t * server environments risks cross-request pollution where state from\n\t * one request could leak into another concurrent request.\n\t */\n\tdisableAsyncLocalStorage?: boolean;\n\t/**\n\t * If `emitGitIgnore` is set to `true` a `.gitignore` file will be emitted in the output directory. Defaults to `true`.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - .gitignore\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * @default true\n\t */\n\temitGitIgnore?: boolean;\n\t/**\n\t * The `outputStructure` defines how modules are structured in the output.\n\t *\n\t * - `message-modules` - Each module is a message. This is the default.\n\t * - `locale-modules` - Each module is a locale.\n\t *\n\t * It is recommended to use `locale-modules` for development and `message-modules` for production.\n\t * Bundlers speed up the dev mode by bypassing bundling which can lead to many http requests\n\t * during the dev mode with `message-modules`. See https://github.com/opral/inlang-paraglide-js/issues/486.\n\t *\n\t * **`message-modules`**\n\t *\n\t * Messages have their own module which eases tree-shaking for bundlers.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - blue_elephant_tree/\n\t * + - index.js\n\t * + - en.js\n\t * + - fr.js\n\t * + - sky_phone_bottle/\n\t * + - index.js\n\t * + - en.js\n\t * + - fr.js\n\t * - ...\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * **`locale-modules`**\n\t *\n\t * Messages are bundled in a per locale module. Bundlers often struggle with tree-shaking this structure,\n\t * which can lead to more inefficient tree-shaking and larger bundle sizes compared to `message-modules`.\n\t *\n\t * The benefit are substantially fewer files which is needed in large projects.\n\t *\n\t * ```diff\n\t * - outdir/\n\t * - messages/\n\t * + - de.js\n\t * + - en.js\n\t * + - fr.js\n\t * - ...\n\t * - messages.js\n\t * - runtime.js\n\t * ```\n\t *\n\t * @default \"message-modules\"\n\t */\n\toutputStructure?: \"locale-modules\" | \"message-modules\";\n\t/**\n\t * Whether to clean the output directory before writing the new files.\n\t *\n\t * @default true\n\t */\n\tcleanOutdir?: boolean;\n\n\t/**\n\t * The file system to use. Defaults to `await import('node:fs')`.\n\t *\n\t * Useful for testing the paraglide compiler by mocking the fs.\n\t */\n\tfs?: any;\n};\n"]}
@@ -25,6 +25,7 @@ export declare function createRuntimeFile(args: {
25
25
  cookieDomain: CompilerOptions["cookieDomain"];
26
26
  urlPatterns?: CompilerOptions["urlPatterns"];
27
27
  routing?: CompilerOptions["routing"];
28
+ trailingSlash?: CompilerOptions["trailingSlash"];
28
29
  experimentalMiddlewareLocaleSplitting: CompilerOptions["experimentalMiddlewareLocaleSplitting"];
29
30
  isServer: CompilerOptions["isServer"];
30
31
  experimentalStaticLocale?: CompilerOptions["experimentalStaticLocale"];
@@ -102,6 +102,9 @@ ${injectCode("./variables.js")
102
102
  .replace(`export const TREE_SHAKE_PREFERRED_LANGUAGE_STRATEGY_USED = false;`, `const TREE_SHAKE_PREFERRED_LANGUAGE_STRATEGY_USED = ${allUsedStrategies.has("preferredLanguage")};`)
103
103
  .replace(`export const urlPatterns = [];`, `export const urlPatterns = ${JSON.stringify(urlPatterns, null, 2)};`)
104
104
  .replace(`export const routing = {};`, `export const routing = ${JSON.stringify(hostRouting ?? {}, null, 2)};`)
105
+ .replace(`export const trailingSlash = undefined;`, `export const trailingSlash = ${args.compilerOptions.trailingSlash === undefined
106
+ ? "undefined"
107
+ : JSON.stringify(args.compilerOptions.trailingSlash)};`)
105
108
  .replace(`export const disableAsyncLocalStorage = false;`, `export const disableAsyncLocalStorage = ${args.compilerOptions.disableAsyncLocalStorage};`)
106
109
  .replace(`export const TREE_SHAKE_DEFAULT_URL_PATTERN_USED = false;`, `const TREE_SHAKE_DEFAULT_URL_PATTERN_USED = ${defaultUrlPatternUsed};`)
107
110
  .replace(`export const TREE_SHAKE_HOST_ROUTING_USED = false;`, `const TREE_SHAKE_HOST_ROUTING_USED = ${hostRoutingUsed};`)
@@ -131,6 +134,14 @@ ${injectCode("./get-url-origin.js")}
131
134
 
132
135
  ${injectCode("./check-locale.js")}
133
136
 
137
+ ${injectCode("./normalize-trailing-slash.js", {
138
+ privateExports: ["normalizeTrailingSlash"],
139
+ })}
140
+
141
+ ${injectCode("./exec-url-pattern.js", {
142
+ privateExports: ["execUrlPattern"],
143
+ })}
144
+
134
145
  ${injectCode("./extract-locale-from-request.js")}
135
146
 
136
147
  ${injectCode("./extract-locale-from-request-async.js")}
@@ -1 +1 @@
1
- {"version":3,"file":"create-runtime.js","sourceRoot":"","sources":["../../../src/compiler/runtime/create-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAKzB,OAAO,EAAE,oCAAoC,EAAE,MAAM,wBAAwB,CAAC;AAO9E;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAIhC;IACA,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAChC,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,MAAM,QAAQ,GAAwB,EAAE,CAAC;IAEzC,KAAK,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7D,MAAM,cAAc,GAAG,IAAI,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC;QAC1D,MAAM,WAAW,GAAG,IAAI,CAAC,OAAO,IAAI,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,CAAC;QAEtD,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;YAC5C,MAAM,IAAI,KAAK,CACd,uBAAuB,cAAc,iBAAiB,QAAQ,mEAAmE,CACjI,CAAC;QACH,CAAC;QAED,KAAK,MAAM,MAAM,IAAI,WAAW,EAAE,CAAC;YAClC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;gBACpC,MAAM,IAAI,KAAK,CACd,mBAAmB,MAAM,iBAAiB,QAAQ,2EAA2E,CAC7H,CAAC;YACH,CAAC;QACF,CAAC;QAED,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;YAC3C,MAAM,IAAI,KAAK,C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\n} from \"../compiler-options.js\";\nimport { perLocaleBuildStaticLocaleExpression } from \"../per-locale-build.js\";\n\ntype ResolvedHostRouting = Record<\n\tstring,\n\t{ baseLocale: string; locales: string[] }\n>;\n\n/**\n * Normalize and validate host routing config for the generated runtime.\n */\nexport function normalizeRouting(args: {\n\trouting: RoutingConfig | undefined;\n\tlocales: string[];\n\tbaseLocale: string;\n}): ResolvedHostRouting | undefined {\n\tif (args.routing === undefined) {\n\t\treturn undefined;\n\t}\n\n\tconst resolved: ResolvedHostRouting = {};\n\n\tfor (const [hostname, rule] of Object.entries(args.routing)) {\n\t\tconst hostBaseLocale = rule.baseLocale ?? args.baseLocale;\n\t\tconst hostLocales = rule.locales ?? [...args.locales];\n\n\t\tif (!args.locales.includes(hostBaseLocale)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid baseLocale \"${hostBaseLocale}\" in routing[\"${hostname}\"]. It must be one of the locales defined in the \"locales\" array.`\n\t\t\t);\n\t\t}\n\n\t\tfor (const locale of hostLocales) {\n\t\t\tif (!args.locales.includes(locale)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid locale \"${locale}\" in routing[\"${hostname}\"].locales. It must be one of the locales defined in the \"locales\" array.`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (!hostLocales.includes(hostBaseLocale)) {\n\t\t\tthrow new Error(\n\t\t\t\t`routing[\"${hostname}\"].baseLocale \"${hostBaseLocale}\" must be included in routing[\"${hostname}\"].locales.`\n\t\t\t);\n\t\t}\n\n\t\tresolved[hostname] = {\n\t\t\tbaseLocale: hostBaseLocale,\n\t\t\tlocales: hostLocales,\n\t\t};\n\t}\n\n\tif (resolved[\"*\"] === undefined) {\n\t\tresolved[\"*\"] = {\n\t\t\tbaseLocale: args.baseLocale,\n\t\t\tlocales: [...args.locales],\n\t\t};\n\t}\n\n\treturn resolved;\n}\n\n/**\n * Returns the code for the `runtime.js` module\n */\nexport function createRuntimeFile(args: {\n\tbaseLocale: string;\n\tlocales: string[];\n\tcompilerOptions: {\n\t\tstrategy: NonNullable<CompilerOptions[\"strategy\"]>;\n\t\trouteStrategies?: CompilerOptions[\"routeStrategies\"];\n\t\tcookieName: NonNullable<CompilerOptions[\"cookieName\"]>;\n\t\tcookieMaxAge: NonNullable<CompilerOptions[\"cookieMaxAge\"]>;\n\t\tcookieDomain: CompilerOptions[\"cookieDomain\"];\n\t\turlPatterns?: CompilerOptions[\"urlPatterns\"];\n\t\trouting?: CompilerOptions[\"routing\"];\n\t\texperimentalMiddlewareLocaleSplitting: CompilerOptions[\"experimentalMiddlewareLocaleSplitting\"];\n\t\tisServer: CompilerOptions[\"isServer\"];\n\t\texperimentalStaticLocale?: CompilerOptions[\"experimentalStaticLocale\"];\n\t\tlocalStorageKey: CompilerOptions[\"localStorageKey\"];\n\t\tdisableAsyncLocalStorage: NonNullable<\n\t\t\tCompilerOptions[\"disableAsyncLocalStorage\"]\n\t\t>;\n\t};\n}): string {\n\tif (\n\t\targs.compilerOptions.routing !== undefined &&\n\t\targs.compilerOptions.urlPatterns !== undefined\n\t) {\n\t\tthrow new Error(\n\t\t\t`Cannot set both \"routing\" and \"urlPatterns\". Use \"routing\" for per-host locale prefixes, or \"urlPatterns\" for custom URLPattern rules.`\n\t\t);\n\t}\n\n\tconst hostRouting = normalizeRouting({\n\t\trouting: args.compilerOptions.routing,\n\t\tlocales: args.locales,\n\t\tbaseLocale: args.baseLocale,\n\t});\n\tconst hostRoutingUsed = hostRouting !== undefined;\n\n\tconst urlPatterns = args.compilerOptions.urlPatterns ?? [];\n\tconst routeStrategies = args.compilerOptions.routeStrategies ?? [];\n\n\tlet defaultUrlPatternUsed = false;\n\n\t// Default string-prefix router when neither routing nor custom urlPatterns are set.\n\tif (\n\t\t!hostRoutingUsed &&\n\t\targs.compilerOptions.urlPatterns === undefined\n\t) {\n\t\tdefaultUrlPatternUsed = true;\n\t\turlPatterns.push({\n\t\t\tpattern: `:protocol://:domain(.*)::port?/:path(.*)?`,\n\t\t\tlocalized: [],\n\t\t});\n\t\tfor (const locale of args.locales) {\n\t\t\tif (locale === args.baseLocale) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\turlPatterns[0]?.localized.push([\n\t\t\t\tlocale,\n\t\t\t\t`:protocol://:domain(.*)::port?/${locale}/:path(.*)?`,\n\t\t\t]);\n\t\t}\n\t\turlPatterns[0]?.localized.push([\n\t\t\targs.baseLocale,\n\t\t\t`:protocol://:domain(.*)::port?/:path(.*)?`,\n\t\t]);\n\t}\n\tconst strategiesUsedByRoutes = routeStrategies.flatMap((routeStrategy) =>\n\t\t\"strategy\" in routeStrategy ? routeStrategy.strategy : []\n\t);\n\tconst allUsedStrategies = new Set([\n\t\t...args.compilerOptions.strategy,\n\t\t...strategiesUsedByRoutes,\n\t]);\n\t// verify that urlPatterns' locales are valid\n\tfor (const urlPattern of urlPatterns) {\n\t\tfor (const [locale] of urlPattern.localized) {\n\t\t\tif (!args.locales.includes(locale)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid locale \"${locale}\" in urlPatterns. It must be one of the locales defined in the \"locales\" array.`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst code = `\n${injectCode(\"./variables.js\")\n\t.replace(\n\t\t`export const baseLocale = \"en\";`,\n\t\t`export const baseLocale = \"${args.baseLocale}\";`\n\t)\n\t.replace(\n\t\t`export const locales = /** @type {readonly string[]} */ ([\"en\", \"de\"]);`,\n\t\t`export const locales = /** @type {const} */ (${JSON.stringify(args.locales)});`\n\t)\n\t.replace(\n\t\t`export const strategy = [\"globalVariable\"];`,\n\t\t`export const strategy = ${JSON.stringify(args.compilerOptions.strategy, null, 2)};`\n\t)\n\t.replace(`<cookie-name>`, `${args.compilerOptions.cookieName}`)\n\t.replace(`60 * 60 * 24 * 400`, `${args.compilerOptions.cookieMaxAge}`)\n\t.replace(`<cookie-domain>`, `${args.compilerOptions.cookieDomain}`)\n\t.replace(\n\t\t`export const routeStrategies = [];`,\n\t\t`export const routeStrategies = ${JSON.stringify(routeStrategies, null, 2)};`\n\t)\n\t.replace(\n\t\t`export const TREE_SHAKE_COOKIE_STRATEGY_USED = false;`,\n\t\t`const TREE_SHAKE_COOKIE_STRATEGY_USED = ${allUsedStrategies.has(\"cookie\")};`\n\t)\n\t.replace(\n\t\t`export const TREE_SHAKE_URL_STRATEGY_USED = false;`,\n\t\t`const TREE_SHAKE_URL_STRATEGY_USED = ${allUsedStrategies.has(\"url\")};`\n\t)\n\t.replace(\n\t\t`export const TREE_SHAKE_GLOBAL_VARIABLE_STRATEGY_USED = false;`,\n\t\t`const TREE_SHAKE_GLOBAL_VARIABLE_STRATEGY_USED = ${allUsedStrategies.has(\"globalVariable\")};`\n\t)\n\t.replace(\n\t\t`export const TREE_SHAKE_PREFERRED_LANGUAGE_STRATEGY_USED = false;`,\n\t\t`const TREE_SHAKE_PREFERRED_LANGUAGE_STRATEGY_USED = ${allUsedStrategies.has(\"preferredLanguage\")};`\n\t)\n\t.replace(\n\t\t`export const urlPatterns = [];`,\n\t\t`export const urlPatterns = ${JSON.stringify(urlPatterns, null, 2)};`\n\t)\n\t.replace(\n\t\t`export const routing = {};`,\n\t\t`export const routing = ${JSON.stringify(hostRouting ?? {}, null, 2)};`\n\t)\n\t.replace(\n\t\t`export const disableAsyncLocalStorage = false;`,\n\t\t`export const disableAsyncLocalStorage = ${args.compilerOptions.disableAsyncLocalStorage};`\n\t)\n\t.replace(\n\t\t`export const TREE_SHAKE_DEFAULT_URL_PATTERN_USED = false;`,\n\t\t`const TREE_SHAKE_DEFAULT_URL_PATTERN_USED = ${defaultUrlPatternUsed};`\n\t)\n\t.replace(\n\t\t`export const TREE_SHAKE_HOST_ROUTING_USED = false;`,\n\t\t`const TREE_SHAKE_HOST_ROUTING_USED = ${hostRoutingUsed};`\n\t)\n\t.replace(\n\t\t`export const experimentalMiddlewareLocaleSplitting = false;`,\n\t\t`export const experimentalMiddlewareLocaleSplitting = ${args.compilerOptions.experimentalMiddlewareLocaleSplitting};`\n\t)\n\t.replace(\n\t\t`export const isServer = typeof window === \"undefined\";`,\n\t\t`export const isServer = ${args.compilerOptions.isServer};`\n\t)\n\t.replace(\n\t\t`export const experimentalStaticLocale = undefined;`,\n\t\targs.compilerOptions.experimentalStaticLocale\n\t\t\t? `export const experimentalStaticLocale = ${\n\t\t\t\t\targs.compilerOptions.experimentalStaticLocale ===\n\t\t\t\t\tperLocaleBuildStaticLocaleExpression\n\t\t\t\t\t\t? args.compilerOptions.experimentalStaticLocale\n\t\t\t\t\t\t: `assertIsLocale(${args.compilerOptions.experimentalStaticLocale})`\n\t\t\t\t};`\n\t\t\t: `export const experimentalStaticLocale = undefined;`\n\t)\n\t.replace(\n\t\t`export const localStorageKey = \"PARAGLIDE_LOCALE\";`,\n\t\t`export const localStorageKey = \"${args.compilerOptions.localStorageKey}\";`\n\t)\n\t.replace(\n\t\t`export const TREE_SHAKE_LOCAL_STORAGE_STRATEGY_USED = false;`,\n\t\t`const TREE_SHAKE_LOCAL_STORAGE_STRATEGY_USED = ${allUsedStrategies.has(\"localStorage\")};`\n\t)}\n\n/** @type {any} */ (globalThis).__paraglide =\n\t/** @type {any} */ (globalThis).__paraglide ?? {};\n/** @type {any} */ (globalThis).__paraglide.ssr =\n\t/** @type {any} */ (globalThis).__paraglide.ssr ?? {};\n\n${injectCode(\"./get-locale.js\")}\n\n${injectCode(\"./get-text-direction.js\")}\n\n${injectCode(\"./set-locale.js\")}\n\n${injectCode(\"./get-url-origin.js\")}\n\n${injectCode(\"./check-locale.js\")}\n\n${injectCode(\"./extract-locale-from-request.js\")}\n\n${injectCode(\"./extract-locale-from-request-async.js\")}\n\n${injectCode(\"./extract-locale-from-cookie.js\", {\n\tprivateExports: [\"clearLocaleCookieCache\"],\n})}\n\n${injectCode(\"./extract-locale-from-header.js\")}\n\n${injectCode(\"./extract-locale-from-navigator.js\")}\n\n${injectCode(\"./url-pattern.js\")}\n\n${injectCode(\"./host-routing.js\")}\n\n${injectCode(\"./extract-locale-from-url.js\")}\n\n${injectCode(\"./localize-url.js\")}\n\n${injectCode(\"./route-strategy.js\")}\n\n${injectCode(\"./should-redirect.js\")}\n\n${injectCode(\"./localize-href.js\")}\n\n${injectCode(\"./track-message-call.js\")}\n\n${injectCode(\"./generate-static-localized-urls.js\")}\n\n${injectCode(\"./strategy.js\")}\n\n${injectCode(\"./type-definitions.js\").replace(\n\t`@typedef {string} Locale`,\n\t`@typedef {typeof locales[number]} Locale`\n)}\n`;\n\n\treturn code;\n}\n\n/**\n * Load a file from the current directory.\n *\n * Prunes the imports on top of the file as the runtime is\n * self-contained.\n *\n * @param {string} path\n * @param {{ privateExports?: string[] }} [options]\n * @returns {string}\n */\nfunction injectCode(\n\tpath: string,\n\toptions?: { privateExports?: string[] }\n): string {\n\tconst code = fs.readFileSync(new URL(path, import.meta.url), \"utf-8\");\n\t// Regex to match single-line and multi-line imports\n\tconst importRegex = /import\\s+[\\s\\S]*?from\\s+['\"][^'\"]+['\"]\\s*;?/g;\n\tconst sourceMapRegex = /\\/\\/# sourceMappingURL=.*$/gm;\n\tconst blockSourceMapRegex = /\\/\\*# sourceMappingURL=.*?\\*\\//g;\n\tlet injected = code\n\t\t.replace(importRegex, \"\")\n\t\t.replace(sourceMapRegex, \"\")\n\t\t.replace(blockSourceMapRegex, \"\")\n\t\t.trim();\n\tfor (const exportName of options?.privateExports ?? []) {\n\t\tinjected = injected.replace(\n\t\t\tnew RegExp(`\\\\bexport\\\\s+function\\\\s+${exportName}\\\\b`, \"g\"),\n\t\t\t`function ${exportName}`\n\t\t);\n\t}\n\treturn injected;\n}\n"]}
1
+ {"version":3,"file":"create-runtime.js","sourceRoot":"","sources":["../../../src/compiler/runtime/create-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AAKzB,OAAO,EAAE,oCAAoC,EAAE,MAAM,wBAAwB,CAAC;AAO9E;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAIhC;IACA,IAAI,IAAI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ions,\n\tRoutingConfig,\n} from \"../compiler-options.js\";\nimport { perLocaleBuildStaticLocaleExpression } from \"../per-locale-build.js\";\n\ntype ResolvedHostRouting = Record<\n\tstring,\n\t{ baseLocale: string; locales: string[] }\n>;\n\n/**\n * Normalize and validate host routing config for the generated runtime.\n */\nexport function normalizeRouting(args: {\n\trouting: RoutingConfig | undefined;\n\tlocales: string[];\n\tbaseLocale: string;\n}): ResolvedHostRouting | undefined {\n\tif (args.routing === undefined) {\n\t\treturn undefined;\n\t}\n\n\tconst resolved: ResolvedHostRouting = {};\n\n\tfor (const [hostname, rule] of Object.entries(args.routing)) {\n\t\tconst hostBaseLocale = rule.baseLocale ?? args.baseLocale;\n\t\tconst hostLocales = rule.locales ?? [...args.locales];\n\n\t\tif (!args.locales.includes(hostBaseLocale)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid baseLocale \"${hostBaseLocale}\" in routing[\"${hostname}\"]. It must be one of the locales defined in the \"locales\" array.`\n\t\t\t);\n\t\t}\n\n\t\tfor (const locale of hostLocales) {\n\t\t\tif (!args.locales.includes(locale)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid locale \"${locale}\" in routing[\"${hostname}\"].locales. It must be one of the locales defined in the \"locales\" array.`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tif (!hostLocales.includes(hostBaseLocale)) {\n\t\t\tthrow new Error(\n\t\t\t\t`routing[\"${hostname}\"].baseLocale \"${hostBaseLocale}\" must be included in routing[\"${hostname}\"].locales.`\n\t\t\t);\n\t\t}\n\n\t\tresolved[hostname] = {\n\t\t\tbaseLocale: hostBaseLocale,\n\t\t\tlocales: hostLocales,\n\t\t};\n\t}\n\n\tif (resolved[\"*\"] === undefined) {\n\t\tresolved[\"*\"] = {\n\t\t\tbaseLocale: args.baseLocale,\n\t\t\tlocales: [...args.locales],\n\t\t};\n\t}\n\n\treturn resolved;\n}\n\n/**\n * Returns the code for the `runtime.js` module\n */\nexport function createRuntimeFile(args: {\n\tbaseLocale: string;\n\tlocales: string[];\n\tcompilerOptions: {\n\t\tstrategy: NonNullable<CompilerOptions[\"strategy\"]>;\n\t\trouteStrategies?: CompilerOptions[\"routeStrategies\"];\n\t\tcookieName: NonNullable<CompilerOptions[\"cookieName\"]>;\n\t\tcookieMaxAge: NonNullable<CompilerOptions[\"cookieMaxAge\"]>;\n\t\tcookieDomain: CompilerOptions[\"cookieDomain\"];\n\t\turlPatterns?: CompilerOptions[\"urlPatterns\"];\n\t\trouting?: CompilerOptions[\"routing\"];\n\t\ttrailingSlash?: CompilerOptions[\"trailingSlash\"];\n\t\texperimentalMiddlewareLocaleSplitting: CompilerOptions[\"experimentalMiddlewareLocaleSplitting\"];\n\t\tisServer: CompilerOptions[\"isServer\"];\n\t\texperimentalStaticLocale?: CompilerOptions[\"experimentalStaticLocale\"];\n\t\tlocalStorageKey: CompilerOptions[\"localStorageKey\"];\n\t\tdisableAsyncLocalStorage: NonNullable<\n\t\t\tCompilerOptions[\"disableAsyncLocalStorage\"]\n\t\t>;\n\t};\n}): string {\n\tif (\n\t\targs.compilerOptions.routing !== undefined &&\n\t\targs.compilerOptions.urlPatterns !== undefined\n\t) {\n\t\tthrow new Error(\n\t\t\t`Cannot set both \"routing\" and \"urlPatterns\". Use \"routing\" for per-host locale prefixes, or \"urlPatterns\" for custom URLPattern rules.`\n\t\t);\n\t}\n\n\tconst hostRouting = normalizeRouting({\n\t\trouting: args.compilerOptions.routing,\n\t\tlocales: args.locales,\n\t\tbaseLocale: args.baseLocale,\n\t});\n\tconst hostRoutingUsed = hostRouting !== undefined;\n\n\tconst urlPatterns = args.compilerOptions.urlPatterns ?? [];\n\tconst routeStrategies = args.compilerOptions.routeStrategies ?? [];\n\n\tlet defaultUrlPatternUsed = false;\n\n\t// Default string-prefix router when neither routing nor custom urlPatterns are set.\n\tif (\n\t\t!hostRoutingUsed &&\n\t\targs.compilerOptions.urlPatterns === undefined\n\t) {\n\t\tdefaultUrlPatternUsed = true;\n\t\turlPatterns.push({\n\t\t\tpattern: `:protocol://:domain(.*)::port?/:path(.*)?`,\n\t\t\tlocalized: [],\n\t\t});\n\t\tfor (const locale of args.locales) {\n\t\t\tif (locale === args.baseLocale) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\turlPatterns[0]?.localized.push([\n\t\t\t\tlocale,\n\t\t\t\t`:protocol://:domain(.*)::port?/${locale}/:path(.*)?`,\n\t\t\t]);\n\t\t}\n\t\turlPatterns[0]?.localized.push([\n\t\t\targs.baseLocale,\n\t\t\t`:protocol://:domain(.*)::port?/:path(.*)?`,\n\t\t]);\n\t}\n\tconst strategiesUsedByRoutes = routeStrategies.flatMap((routeStrategy) =>\n\t\t\"strategy\" in routeStrategy ? routeStrategy.strategy : []\n\t);\n\tconst allUsedStrategies = new Set([\n\t\t...args.compilerOptions.strategy,\n\t\t...strategiesUsedByRoutes,\n\t]);\n\t// verify that urlPatterns' locales are valid\n\tfor (const urlPattern of urlPatterns) {\n\t\tfor (const [locale] of urlPattern.localized) {\n\t\t\tif (!args.locales.includes(locale)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Invalid locale \"${locale}\" in urlPatterns. It must be one of the locales defined in the \"locales\" array.`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tconst code = `\n${injectCode(\"./variables.js\")\n\t.replace(\n\t\t`export const baseLocale = \"en\";`,\n\t\t`export const baseLocale = \"${args.baseLocale}\";`\n\t)\n\t.replace(\n\t\t`export const locales = /** @type {readonly string[]} */ ([\"en\", \"de\"]);`,\n\t\t`export const locales = /** @type {const} */ (${JSON.stringify(args.locales)});`\n\t)\n\t.replace(\n\t\t`export const strategy = [\"globalVariable\"];`,\n\t\t`export const strategy = ${JSON.stringify(args.compilerOptions.strategy, null, 2)};`\n\t)\n\t.replace(`<cookie-name>`, `${args.compilerOptions.cookieName}`)\n\t.replace(`60 * 60 * 24 * 400`, `${args.compilerOptions.cookieMaxAge}`)\n\t.replace(`<cookie-domain>`, `${args.compilerOptions.cookieDomain}`)\n\t.replace(\n\t\t`export const routeStrategies = [];`,\n\t\t`export const routeStrategies = ${JSON.stringify(routeStrategies, null, 2)};`\n\t)\n\t.replace(\n\t\t`export const TREE_SHAKE_COOKIE_STRATEGY_USED = false;`,\n\t\t`const TREE_SHAKE_COOKIE_STRATEGY_USED = ${allUsedStrategies.has(\"cookie\")};`\n\t)\n\t.replace(\n\t\t`export const TREE_SHAKE_URL_STRATEGY_USED = false;`,\n\t\t`const TREE_SHAKE_URL_STRATEGY_USED = ${allUsedStrategies.has(\"url\")};`\n\t)\n\t.replace(\n\t\t`export const TREE_SHAKE_GLOBAL_VARIABLE_STRATEGY_USED = false;`,\n\t\t`const TREE_SHAKE_GLOBAL_VARIABLE_STRATEGY_USED = ${allUsedStrategies.has(\"globalVariable\")};`\n\t)\n\t.replace(\n\t\t`export const TREE_SHAKE_PREFERRED_LANGUAGE_STRATEGY_USED = false;`,\n\t\t`const TREE_SHAKE_PREFERRED_LANGUAGE_STRATEGY_USED = ${allUsedStrategies.has(\"preferredLanguage\")};`\n\t)\n\t.replace(\n\t\t`export const urlPatterns = [];`,\n\t\t`export const urlPatterns = ${JSON.stringify(urlPatterns, null, 2)};`\n\t)\n\t.replace(\n\t\t`export const routing = {};`,\n\t\t`export const routing = ${JSON.stringify(hostRouting ?? {}, null, 2)};`\n\t)\n\t.replace(\n\t\t`export const trailingSlash = undefined;`,\n\t\t`export const trailingSlash = ${\n\t\t\targs.compilerOptions.trailingSlash === undefined\n\t\t\t\t? \"undefined\"\n\t\t\t\t: JSON.stringify(args.compilerOptions.trailingSlash)\n\t\t};`\n\t)\n\t.replace(\n\t\t`export const disableAsyncLocalStorage = false;`,\n\t\t`export const disableAsyncLocalStorage = ${args.compilerOptions.disableAsyncLocalStorage};`\n\t)\n\t.replace(\n\t\t`export const TREE_SHAKE_DEFAULT_URL_PATTERN_USED = false;`,\n\t\t`const TREE_SHAKE_DEFAULT_URL_PATTERN_USED = ${defaultUrlPatternUsed};`\n\t)\n\t.replace(\n\t\t`export const TREE_SHAKE_HOST_ROUTING_USED = false;`,\n\t\t`const TREE_SHAKE_HOST_ROUTING_USED = ${hostRoutingUsed};`\n\t)\n\t.replace(\n\t\t`export const experimentalMiddlewareLocaleSplitting = false;`,\n\t\t`export const experimentalMiddlewareLocaleSplitting = ${args.compilerOptions.experimentalMiddlewareLocaleSplitting};`\n\t)\n\t.replace(\n\t\t`export const isServer = typeof window === \"undefined\";`,\n\t\t`export const isServer = ${args.compilerOptions.isServer};`\n\t)\n\t.replace(\n\t\t`export const experimentalStaticLocale = undefined;`,\n\t\targs.compilerOptions.experimentalStaticLocale\n\t\t\t? `export const experimentalStaticLocale = ${\n\t\t\t\t\targs.compilerOptions.experimentalStaticLocale ===\n\t\t\t\t\tperLocaleBuildStaticLocaleExpression\n\t\t\t\t\t\t? args.compilerOptions.experimentalStaticLocale\n\t\t\t\t\t\t: `assertIsLocale(${args.compilerOptions.experimentalStaticLocale})`\n\t\t\t\t};`\n\t\t\t: `export const experimentalStaticLocale = undefined;`\n\t)\n\t.replace(\n\t\t`export const localStorageKey = \"PARAGLIDE_LOCALE\";`,\n\t\t`export const localStorageKey = \"${args.compilerOptions.localStorageKey}\";`\n\t)\n\t.replace(\n\t\t`export const TREE_SHAKE_LOCAL_STORAGE_STRATEGY_USED = false;`,\n\t\t`const TREE_SHAKE_LOCAL_STORAGE_STRATEGY_USED = ${allUsedStrategies.has(\"localStorage\")};`\n\t)}\n\n/** @type {any} */ (globalThis).__paraglide =\n\t/** @type {any} */ (globalThis).__paraglide ?? {};\n/** @type {any} */ (globalThis).__paraglide.ssr =\n\t/** @type {any} */ (globalThis).__paraglide.ssr ?? {};\n\n${injectCode(\"./get-locale.js\")}\n\n${injectCode(\"./get-text-direction.js\")}\n\n${injectCode(\"./set-locale.js\")}\n\n${injectCode(\"./get-url-origin.js\")}\n\n${injectCode(\"./check-locale.js\")}\n\n${injectCode(\"./normalize-trailing-slash.js\", {\n\tprivateExports: [\"normalizeTrailingSlash\"],\n})}\n\n${injectCode(\"./exec-url-pattern.js\", {\n\tprivateExports: [\"execUrlPattern\"],\n})}\n\n${injectCode(\"./extract-locale-from-request.js\")}\n\n${injectCode(\"./extract-locale-from-request-async.js\")}\n\n${injectCode(\"./extract-locale-from-cookie.js\", {\n\tprivateExports: [\"clearLocaleCookieCache\"],\n})}\n\n${injectCode(\"./extract-locale-from-header.js\")}\n\n${injectCode(\"./extract-locale-from-navigator.js\")}\n\n${injectCode(\"./url-pattern.js\")}\n\n${injectCode(\"./host-routing.js\")}\n\n${injectCode(\"./extract-locale-from-url.js\")}\n\n${injectCode(\"./localize-url.js\")}\n\n${injectCode(\"./route-strategy.js\")}\n\n${injectCode(\"./should-redirect.js\")}\n\n${injectCode(\"./localize-href.js\")}\n\n${injectCode(\"./track-message-call.js\")}\n\n${injectCode(\"./generate-static-localized-urls.js\")}\n\n${injectCode(\"./strategy.js\")}\n\n${injectCode(\"./type-definitions.js\").replace(\n\t`@typedef {string} Locale`,\n\t`@typedef {typeof locales[number]} Locale`\n)}\n`;\n\n\treturn code;\n}\n\n/**\n * Load a file from the current directory.\n *\n * Prunes the imports on top of the file as the runtime is\n * self-contained.\n *\n * @param {string} path\n * @param {{ privateExports?: string[] }} [options]\n * @returns {string}\n */\nfunction injectCode(\n\tpath: string,\n\toptions?: { privateExports?: string[] }\n): string {\n\tconst code = fs.readFileSync(new URL(path, import.meta.url), \"utf-8\");\n\t// Regex to match single-line and multi-line imports\n\tconst importRegex = /import\\s+[\\s\\S]*?from\\s+['\"][^'\"]+['\"]\\s*;?/g;\n\tconst sourceMapRegex = /\\/\\/# sourceMappingURL=.*$/gm;\n\tconst blockSourceMapRegex = /\\/\\*# sourceMappingURL=.*?\\*\\//g;\n\tlet injected = code\n\t\t.replace(importRegex, \"\")\n\t\t.replace(sourceMapRegex, \"\")\n\t\t.replace(blockSourceMapRegex, \"\")\n\t\t.trim();\n\tfor (const exportName of options?.privateExports ?? []) {\n\t\tinjected = injected.replace(\n\t\t\tnew RegExp(`\\\\bexport\\\\s+function\\\\s+${exportName}\\\\b`, \"g\"),\n\t\t\t`function ${exportName}`\n\t\t);\n\t}\n\treturn injected;\n}\n"]}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Matches a canonical URL while allowing configured patterns to retain their
3
+ * existing trailing slash style.
4
+ *
5
+ * @param {URLPattern} pattern
6
+ * @param {URL} url
7
+ * @returns {any}
8
+ */
9
+ export declare function execUrlPattern(pattern: URLPattern, url: URL): any;
@@ -0,0 +1,31 @@
1
+ import { trailingSlash } from "./variables.js";
2
+ /**
3
+ * Matches a canonical URL while allowing configured patterns to retain their
4
+ * existing trailing slash style.
5
+ *
6
+ * @param {URLPattern} pattern
7
+ * @param {URL} url
8
+ * @returns {any}
9
+ */
10
+ export function execUrlPattern(pattern, url) {
11
+ if (trailingSlash === undefined || url.pathname === "/") {
12
+ return pattern.exec(url.href);
13
+ }
14
+ const alias = new URL(url);
15
+ if (trailingSlash === "always") {
16
+ alias.pathname = alias.pathname.replace(/\/+$/, "") || "/";
17
+ // Prefer the slashless alias so the canonical slash does not become part
18
+ // of a terminal wildcard capture.
19
+ return pattern.exec(alias.href) ?? pattern.exec(url.href);
20
+ }
21
+ else if (trailingSlash === "never") {
22
+ const match = pattern.exec(url.href);
23
+ if (match) {
24
+ return match;
25
+ }
26
+ alias.pathname = alias.pathname.replace(/\/+$/, "") + "/";
27
+ return pattern.exec(alias.href);
28
+ }
29
+ return pattern.exec(url.href);
30
+ }
31
+ //# sourceMappingURL=exec-url-pattern.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exec-url-pattern.js","sourceRoot":"","sources":["../../../src/compiler/runtime/exec-url-pattern.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAAC,OAAO,EAAE,GAAG;IAC1C,IAAI,aAAa,KAAK,SAAS,IAAI,GAAG,CAAC,QAAQ,KAAK,GAAG,EAAE,CAAC;QACzD,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/B,CAAC;IAED,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IAC3B,IAAI,aAAa,KAAK,QAAQ,EAAE,CAAC;QAChC,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC;QAC3D,yEAAyE;QACzE,kCAAkC;QAClC,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC3D,CAAC;SAAM,IAAI,aAAa,KAAK,OAAO,EAAE,CAAC;QACtC,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACrC,IAAI,KAAK,EAAE,CAAC;YACX,OAAO,KAAK,CAAC;QACd,CAAC;QACD,KAAK,CAAC,QAAQ,GAAG,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC;QAC1D,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC","sourcesContent":["import { trailingSlash } from \"./variables.js\";\n\n/**\n * Matches a canonical URL while allowing configured patterns to retain their\n * existing trailing slash style.\n *\n * @param {URLPattern} pattern\n * @param {URL} url\n * @returns {any}\n */\nexport function execUrlPattern(pattern, url) {\n\tif (trailingSlash === undefined || url.pathname === \"/\") {\n\t\treturn pattern.exec(url.href);\n\t}\n\n\tconst alias = new URL(url);\n\tif (trailingSlash === \"always\") {\n\t\talias.pathname = alias.pathname.replace(/\\/+$/, \"\") || \"/\";\n\t\t// Prefer the slashless alias so the canonical slash does not become part\n\t\t// of a terminal wildcard capture.\n\t\treturn pattern.exec(alias.href) ?? pattern.exec(url.href);\n\t} else if (trailingSlash === \"never\") {\n\t\tconst match = pattern.exec(url.href);\n\t\tif (match) {\n\t\t\treturn match;\n\t\t}\n\t\talias.pathname = alias.pathname.replace(/\\/+$/, \"\") + \"/\";\n\t\treturn pattern.exec(alias.href);\n\t}\n\treturn pattern.exec(url.href);\n}\n"]}
@@ -1,7 +1,9 @@
1
1
  import { toLocale } from "./check-locale.js";
2
- import { getCompiledUrlPattern } from "./url-pattern.js";
2
+ import { getUrlPattern } from "./url-pattern.js";
3
3
  import { extractLocaleFromUrlHostRouting } from "./host-routing.js";
4
4
  import { baseLocale, TREE_SHAKE_DEFAULT_URL_PATTERN_USED, TREE_SHAKE_HOST_ROUTING_USED, urlPatterns, } from "./variables.js";
5
+ import { normalizeTrailingSlash } from "./normalize-trailing-slash.js";
6
+ import { execUrlPattern } from "./exec-url-pattern.js";
5
7
  /**
6
8
  * If extractLocaleFromUrl is called many times on the same page and the URL
7
9
  * hasn't changed, we don't need to recompute it every time which can get expensive.
@@ -33,14 +35,17 @@ export function extractLocaleFromUrl(url) {
33
35
  result = extractLocaleFromUrlHostRouting(url);
34
36
  }
35
37
  else if (TREE_SHAKE_DEFAULT_URL_PATTERN_USED) {
36
- result = defaultUrlPatternExtractLocale(url);
38
+ const urlObj = typeof url === "string"
39
+ ? new URL(url, "http://example.com")
40
+ : new URL(url);
41
+ result = defaultUrlPatternExtractLocale(normalizeTrailingSlash(urlObj));
37
42
  }
38
43
  else {
39
- const urlObj = typeof url === "string" ? new URL(url) : url;
44
+ const urlObj = normalizeTrailingSlash(typeof url === "string" ? new URL(url) : new URL(url));
40
45
  // Iterate over URL patterns
41
46
  for (const element of urlPatterns) {
42
47
  for (const [locale, localizedPattern] of element.localized) {
43
- const match = getCompiledUrlPattern(localizedPattern).exec(urlObj.href);
48
+ const match = execUrlPattern(getUrlPattern(localizedPattern, urlObj), urlObj);
44
49
  if (match) {
45
50
  result = locale;
46
51
  break;
@@ -1 +1 @@
1
- {"version":3,"file":"extract-locale-from-url.js","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-url.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,+BAA+B,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EACN,UAAU,EACV,mCAAmC,EACnC,4BAA4B,EAC5B,WAAW,GACX,MAAM,gBAAgB,CAAC;AAExB;;;;;GAKG;AACH,+BAA+B;AAC/B,IAAI,SAAS,CAAC;AACd,+BAA+B;AAC/B,IAAI,YAAY,CAAC;AAEjB;;;;;;;;;GASG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAG;IACvC,MAAM,SAAS,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;IAE3D,IAAI,SAAS,KAAK,SAAS,EAAE,CAAC;QAC7B,OAAO,YAAY,CAAC;IACrB,CAAC;IAED,iCAAiC;IACjC,IAAI,MAAM,CAAC;IACX,IAAI,4BAA4B,EAAE,CAAC;QAClC,MAAM,GAAG,+BAA+B,CAAC,GAAG,CAAC,CAAC;IAC/C,CAAC;SAAM,IAAI,mCAAmC,EAAE,CAAC;QAChD,MAAM,GAAG,8BAA8B,CAAC,GAAG,CAAC,CAAC;IAC9C,CAAC;SAAM,CAAC;QACP,MAAM,MAAM,GAAG,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QAE5D,4BAA4B;QAC5B,KAAK,MAAM,OAAO,IAAI,WAAW,EAAE,CAAC;YACnC,KAAK,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;gBAC5D,MAAM,KAAK,GAAG,qBAAqB,CAAC,gBAAgB,CAAC,CAAC,IAAI,CACzD,MAAM,CAAC,IAAI,CACX,CAAC;gBAEF,IAAI,KAAK,EAAE,CAAC;oBACX,MAAM,GAAG,MAAM,CAAC;oBAChB,MAAM;gBACP,CAAC;YACF,CAAC;YACD,IAAI,MAAM;gBAAE,MAAM;QACnB,CAAC;IACF,CAAC;IAED,SAAS,GAAG,SAAS,CAAC;IACtB,YAAY,GAAG,MAAM,CAAC;IACtB,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;;;;GAKG;AACH,SAAS,8BAA8B,CAAC,GAAG;IAC1C,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC;IAClD,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAChE,OAAO,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC;AAChD,CAAC","sourcesContent":["import { toLocale } from \"./check-locale.js\";\nimport { getCompiledUrlPattern } from \"./url-pattern.js\";\nimport { extractLocaleFromUrlHostRouting } from \"./host-routing.js\";\nimport {\n\tbaseLocale,\n\tTREE_SHAKE_DEFAULT_URL_PATTERN_USED,\n\tTREE_SHAKE_HOST_ROUTING_USED,\n\turlPatterns,\n} from \"./variables.js\";\n\n/**\n * If extractLocaleFromUrl is called many times on the same page and the URL\n * hasn't changed, we don't need to recompute it every time which can get expensive.\n * We might use a LRU cache if needed, but for now storing only the last result is enough.\n * https://github.com/opral/monorepo/pull/3575#discussion_r2066731243\n */\n/** @type {string|undefined} */\nlet cachedUrl;\n/** @type {Locale|undefined} */\nlet cachedLocale;\n\n/**\n * Extracts the locale from a given URL using native URLPattern.\n *\n * The built-in default `/:locale/...` routing is case-insensitive because it\n * canonicalizes the first path segment with `toLocale()`. Custom `urlPatterns`\n * keep URLPattern's normal exact matching semantics for path segments.\n *\n * @param {URL|string} url - The full URL from which to extract the locale.\n * @returns {Locale|undefined} The extracted locale, or undefined if no locale is found.\n */\nexport function extractLocaleFromUrl(url) {\n\tconst urlString = typeof url === \"string\" ? url : url.href;\n\n\tif (cachedUrl === urlString) {\n\t\treturn cachedLocale;\n\t}\n\n\t/** @type {Locale | undefined} */\n\tlet result;\n\tif (TREE_SHAKE_HOST_ROUTING_USED) {\n\t\tresult = extractLocaleFromUrlHostRouting(url);\n\t} else if (TREE_SHAKE_DEFAULT_URL_PATTERN_USED) {\n\t\tresult = defaultUrlPatternExtractLocale(url);\n\t} else {\n\t\tconst urlObj = typeof url === \"string\" ? new URL(url) : url;\n\n\t\t// Iterate over URL patterns\n\t\tfor (const element of urlPatterns) {\n\t\t\tfor (const [locale, localizedPattern] of element.localized) {\n\t\t\t\tconst match = getCompiledUrlPattern(localizedPattern).exec(\n\t\t\t\t\turlObj.href\n\t\t\t\t);\n\n\t\t\t\tif (match) {\n\t\t\t\t\tresult = locale;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (result) break;\n\t\t}\n\t}\n\n\tcachedUrl = urlString;\n\tcachedLocale = result;\n\treturn result;\n}\n\n/**\n * https://github.com/opral/inlang-paraglide-js/issues/381\n *\n * @param {URL | string} url - The full URL from which to extract the locale.\n * @returns {Locale | undefined} The extracted locale, or undefined if no locale is found.\n */\nfunction defaultUrlPatternExtractLocale(url) {\n\tconst urlObj = new URL(url, \"http://example.com\");\n\tconst pathSegments = urlObj.pathname.split(\"/\").filter(Boolean);\n\treturn toLocale(pathSegments[0]) || baseLocale;\n}\n"]}
1
+ {"version":3,"file":"extract-locale-from-url.js","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-url.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C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AAC;QAEF,4BAA4B;QAC5B,KAAK,MAAM,OAAO,IAAI,WAAW,EAAE,CAAC;YACnC,KAAK,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;gBAC5D,MAAM,KAAK,GAAG,cAAc,CAC3B,aAAa,CAAC,gBAAgB,EAAE,MAAM,CAAC,EACvC,MAAM,CACN,CAAC;gBAEF,IAAI,KAAK,EAAE,CAAC;oBACX,MAAM,GAAG,MAAM,CAAC;oBAChB,MAAM;gBACP,CAAC;YACF,CAAC;YACD,IAAI,MAAM;gBAAE,MAAM;QACnB,CAAC;IACF,CAAC;IAED,SAAS,GAAG,SAAS,CAAC;IACtB,YAAY,GAAG,MAAM,CAAC;IACtB,OAAO,MAAM,CAAC;AACf,CAAC;AAED;;;;;GAKG;AACH,SAAS,8BAA8B,CAAC,GAAG;IAC1C,MAAM,MAAM,GAAG,IAAI,GAAG,CAAC,GAAG,EAAE,oBAAoB,CAAC,CAAC;IAClD,MAAM,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAChE,OAAO,QAAQ,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,IAAI,UAAU,CAAC;AAChD,CAAC","sourcesContent":["import { toLocale } from \"./check-locale.js\";\nimport { getUrlPattern } from \"./url-pattern.js\";\nimport { extractLocaleFromUrlHostRouting } from \"./host-routing.js\";\nimport {\n\tbaseLocale,\n\tTREE_SHAKE_DEFAULT_URL_PATTERN_USED,\n\tTREE_SHAKE_HOST_ROUTING_USED,\n\turlPatterns,\n} from \"./variables.js\";\nimport { normalizeTrailingSlash } from \"./normalize-trailing-slash.js\";\nimport { execUrlPattern } from \"./exec-url-pattern.js\";\n\n/**\n * If extractLocaleFromUrl is called many times on the same page and the URL\n * hasn't changed, we don't need to recompute it every time which can get expensive.\n * We might use a LRU cache if needed, but for now storing only the last result is enough.\n * https://github.com/opral/monorepo/pull/3575#discussion_r2066731243\n */\n/** @type {string|undefined} */\nlet cachedUrl;\n/** @type {Locale|undefined} */\nlet cachedLocale;\n\n/**\n * Extracts the locale from a given URL using native URLPattern.\n *\n * The built-in default `/:locale/...` routing is case-insensitive because it\n * canonicalizes the first path segment with `toLocale()`. Custom `urlPatterns`\n * keep URLPattern's normal exact matching semantics for path segments.\n *\n * @param {URL|string} url - The full URL from which to extract the locale.\n * @returns {Locale|undefined} The extracted locale, or undefined if no locale is found.\n */\nexport function extractLocaleFromUrl(url) {\n\tconst urlString = typeof url === \"string\" ? url : url.href;\n\n\tif (cachedUrl === urlString) {\n\t\treturn cachedLocale;\n\t}\n\n\t/** @type {Locale | undefined} */\n\tlet result;\n\tif (TREE_SHAKE_HOST_ROUTING_USED) {\n\t\tresult = extractLocaleFromUrlHostRouting(url);\n\t} else if (TREE_SHAKE_DEFAULT_URL_PATTERN_USED) {\n\t\tconst urlObj =\n\t\t\ttypeof url === \"string\"\n\t\t\t\t? new URL(url, \"http://example.com\")\n\t\t\t\t: new URL(url);\n\t\tresult = defaultUrlPatternExtractLocale(normalizeTrailingSlash(urlObj));\n\t} else {\n\t\tconst urlObj = normalizeTrailingSlash(\n\t\t\ttypeof url === \"string\" ? new URL(url) : new URL(url)\n\t\t);\n\n\t\t// Iterate over URL patterns\n\t\tfor (const element of urlPatterns) {\n\t\t\tfor (const [locale, localizedPattern] of element.localized) {\n\t\t\t\tconst match = execUrlPattern(\n\t\t\t\t\tgetUrlPattern(localizedPattern, urlObj),\n\t\t\t\t\turlObj\n\t\t\t\t);\n\n\t\t\t\tif (match) {\n\t\t\t\t\tresult = locale;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (result) break;\n\t\t}\n\t}\n\n\tcachedUrl = urlString;\n\tcachedLocale = result;\n\treturn result;\n}\n\n/**\n * https://github.com/opral/inlang-paraglide-js/issues/381\n *\n * @param {URL | string} url - The full URL from which to extract the locale.\n * @returns {Locale | undefined} The extracted locale, or undefined if no locale is found.\n */\nfunction defaultUrlPatternExtractLocale(url) {\n\tconst urlObj = new URL(url, \"http://example.com\");\n\tconst pathSegments = urlObj.pathname.split(\"/\").filter(Boolean);\n\treturn toLocale(pathSegments[0]) || baseLocale;\n}\n"]}
@@ -1,5 +1,8 @@
1
1
  import { localizeUrl } from "./localize-url.js";
2
- import { locales, baseLocale, TREE_SHAKE_DEFAULT_URL_PATTERN_USED, TREE_SHAKE_HOST_ROUTING_USED, urlPatterns, } from "./variables.js";
2
+ import { normalizeTrailingSlash } from "./normalize-trailing-slash.js";
3
+ import { execUrlPattern } from "./exec-url-pattern.js";
4
+ import { getUrlPattern } from "./url-pattern.js";
5
+ import { locales, baseLocale, TREE_SHAKE_DEFAULT_URL_PATTERN_USED, TREE_SHAKE_HOST_ROUTING_USED, trailingSlash, urlPatterns, } from "./variables.js";
3
6
  import { getRoutingRule } from "./host-routing.js";
4
7
  /**
5
8
  * Generates localized URL variants for all provided URLs based on your configured locales and URL patterns.
@@ -50,9 +53,12 @@ export function generateStaticLocalizedUrls(urls) {
50
53
  // For default URL pattern, we can optimize the generation
51
54
  if (TREE_SHAKE_DEFAULT_URL_PATTERN_USED) {
52
55
  for (const urlInput of urls) {
53
- const url = urlInput instanceof URL
56
+ const originalUrl = urlInput instanceof URL
54
57
  ? urlInput
55
58
  : new URL(urlInput, "http://localhost");
59
+ const url = trailingSlash === undefined
60
+ ? originalUrl
61
+ : normalizeTrailingSlash(new URL(originalUrl));
56
62
  // Base locale doesn't get a prefix
57
63
  localizedUrls.add(url);
58
64
  // Other locales get their code as prefix
@@ -60,7 +66,7 @@ export function generateStaticLocalizedUrls(urls) {
60
66
  if (locale !== baseLocale) {
61
67
  const localizedPath = `/${locale}${url.pathname}${url.search}${url.hash}`;
62
68
  const localizedUrl = new URL(localizedPath, url.origin);
63
- localizedUrls.add(localizedUrl);
69
+ localizedUrls.add(normalizeTrailingSlash(localizedUrl));
64
70
  }
65
71
  }
66
72
  }
@@ -86,15 +92,16 @@ export function generateStaticLocalizedUrls(urls) {
86
92
  }
87
93
  // For custom URL patterns, we need to use localizeUrl for each URL and locale
88
94
  for (const urlInput of urls) {
89
- const url = urlInput instanceof URL
95
+ const originalUrl = urlInput instanceof URL
90
96
  ? urlInput
91
97
  : new URL(urlInput, "http://localhost");
98
+ const url = normalizeTrailingSlash(new URL(originalUrl));
92
99
  // Try each URL pattern to find one that matches
93
100
  let patternFound = false;
94
101
  for (const pattern of urlPatterns) {
95
102
  try {
96
103
  // Try to match the unlocalized pattern
97
- const unlocalizedMatch = new URLPattern(pattern.pattern, url.href).exec(url.href);
104
+ const unlocalizedMatch = execUrlPattern(getUrlPattern(pattern.pattern, url), url);
98
105
  if (!unlocalizedMatch)
99
106
  continue;
100
107
  patternFound = true;
@@ -125,7 +132,7 @@ export function generateStaticLocalizedUrls(urls) {
125
132
  }
126
133
  // If no pattern matched, use the URL as is
127
134
  if (!patternFound) {
128
- localizedUrls.add(url);
135
+ localizedUrls.add(originalUrl);
129
136
  }
130
137
  }
131
138
  return Array.from(localizedUrls);