@inlang/paraglide-js 2.0.10 → 2.0.12

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 (32) hide show
  1. package/dist/compiler/compiler-options.d.ts +9 -0
  2. package/dist/compiler/compiler-options.d.ts.map +1 -1
  3. package/dist/compiler/compiler-options.js +1 -0
  4. package/dist/compiler/create-paraglide.d.ts +20 -14
  5. package/dist/compiler/create-paraglide.d.ts.map +1 -1
  6. package/dist/compiler/create-paraglide.js +18 -14
  7. package/dist/compiler/create-paraglide.test.js +7 -11
  8. package/dist/compiler/index.d.ts +1 -1
  9. package/dist/compiler/index.d.ts.map +1 -1
  10. package/dist/compiler/index.js +1 -1
  11. package/dist/compiler/runtime/assert-is-locale.test.js +3 -3
  12. package/dist/compiler/runtime/create-runtime.d.ts +1 -0
  13. package/dist/compiler/runtime/create-runtime.d.ts.map +1 -1
  14. package/dist/compiler/runtime/create-runtime.js +1 -0
  15. package/dist/compiler/runtime/extract-locale-from-cookie.test.js +7 -11
  16. package/dist/compiler/runtime/extract-locale-from-request.test.js +57 -77
  17. package/dist/compiler/runtime/extract-locale-from-url.test.js +51 -61
  18. package/dist/compiler/runtime/generate-static-localized-urls.test.js +48 -58
  19. package/dist/compiler/runtime/get-locale.test.js +54 -69
  20. package/dist/compiler/runtime/get-url-origin.test.js +2 -4
  21. package/dist/compiler/runtime/localize-href.test.js +48 -58
  22. package/dist/compiler/runtime/localize-url.test.js +258 -294
  23. package/dist/compiler/runtime/set-locale.d.ts.map +1 -1
  24. package/dist/compiler/runtime/set-locale.js +6 -3
  25. package/dist/compiler/runtime/set-locale.test.js +108 -70
  26. package/dist/compiler/runtime/track-message-call.test.js +1 -1
  27. package/dist/compiler/runtime/variables.d.ts +2 -0
  28. package/dist/compiler/runtime/variables.d.ts.map +1 -1
  29. package/dist/compiler/runtime/variables.js +2 -0
  30. package/dist/compiler/server/middleware.test.js +85 -109
  31. package/dist/services/env-variables/index.js +1 -1
  32. package/package.json +5 -5
@@ -3,15 +3,13 @@ import { createParaglide } from "../create-paraglide.js";
3
3
  import { newProject } from "@inlang/sdk";
4
4
  test("sets the locale and origin", async () => {
5
5
  const runtime = await createParaglide({
6
- project: await newProject({
6
+ blob: await newProject({
7
7
  settings: {
8
8
  baseLocale: "en",
9
9
  locales: ["en", "de", "fr"],
10
10
  },
11
11
  }),
12
- compilerOptions: {
13
- strategy: ["url", "globalVariable"],
14
- },
12
+ strategy: ["url", "globalVariable"],
15
13
  });
16
14
  // setting the global variable to fr to assure that
17
15
  runtime.setLocale("fr");
@@ -37,15 +35,13 @@ test("sets the locale and origin", async () => {
37
35
  });
38
36
  test("delocalizes the url if the url strategy is used and returns the locale", async () => {
39
37
  const runtime = await createParaglide({
40
- project: await newProject({
38
+ blob: await newProject({
41
39
  settings: {
42
40
  baseLocale: "en",
43
41
  locales: ["en", "de"],
44
42
  },
45
43
  }),
46
- compilerOptions: {
47
- strategy: ["url"],
48
- },
44
+ strategy: ["url"],
49
45
  });
50
46
  const request = new Request(new URL("https://example.com/de/page"), {
51
47
  headers: { "Sec-Fetch-Dest": "document" },
@@ -59,15 +55,13 @@ test("delocalizes the url if the url strategy is used and returns the locale", a
59
55
  });
60
56
  test("does not delocalize the url if the url strategy is not used", async () => {
61
57
  const runtime = await createParaglide({
62
- project: await newProject({
58
+ blob: await newProject({
63
59
  settings: {
64
60
  baseLocale: "en",
65
61
  locales: ["en", "de"],
66
62
  },
67
63
  }),
68
- compilerOptions: {
69
- strategy: ["globalVariable", "baseLocale"],
70
- },
64
+ strategy: ["globalVariable", "baseLocale"],
71
65
  });
72
66
  const request = new Request(new URL("https://example.com/de/page"), {
73
67
  headers: { "Sec-Fetch-Dest": "document" },
@@ -81,25 +75,23 @@ test("does not delocalize the url if the url strategy is not used", async () =>
81
75
  });
82
76
  test("redirects to localized URL when non-URL strategy determines locale", async () => {
83
77
  const runtime = await createParaglide({
84
- project: await newProject({
78
+ blob: await newProject({
85
79
  settings: {
86
80
  baseLocale: "en",
87
81
  locales: ["en", "fr"],
88
82
  },
89
83
  }),
90
- compilerOptions: {
91
- strategy: ["cookie", "url"],
92
- cookieName: "PARAGLIDE_LOCALE",
93
- urlPatterns: [
94
- {
95
- pattern: "https://example.com/:path(.*)?",
96
- localized: [
97
- ["en", "https://example.com/en/:path(.*)?"],
98
- ["fr", "https://example.com/fr/:path(.*)?"],
99
- ],
100
- },
101
- ],
102
- },
84
+ strategy: ["cookie", "url"],
85
+ cookieName: "PARAGLIDE_LOCALE",
86
+ urlPatterns: [
87
+ {
88
+ pattern: "https://example.com/:path(.*)?",
89
+ localized: [
90
+ ["en", "https://example.com/en/:path(.*)?"],
91
+ ["fr", "https://example.com/fr/:path(.*)?"],
92
+ ],
93
+ },
94
+ ],
103
95
  });
104
96
  // Request to URL in en with cookie specifying French
105
97
  const request = new Request("https://example.com/en/some-path", {
@@ -119,25 +111,23 @@ test("redirects to localized URL when non-URL strategy determines locale", async
119
111
  });
120
112
  test("does not redirect if URL already matches determined locale", async () => {
121
113
  const runtime = await createParaglide({
122
- project: await newProject({
114
+ blob: await newProject({
123
115
  settings: {
124
116
  baseLocale: "en",
125
117
  locales: ["en", "fr"],
126
118
  },
127
119
  }),
128
- compilerOptions: {
129
- strategy: ["cookie", "url"],
130
- cookieName: "PARAGLIDE_LOCALE",
131
- urlPatterns: [
132
- {
133
- pattern: "https://example.com/:path(.*)?",
134
- localized: [
135
- ["en", "https://example.com/en/:path(.*)?"],
136
- ["fr", "https://example.com/fr/:path(.*)?"],
137
- ],
138
- },
139
- ],
140
- },
120
+ strategy: ["cookie", "url"],
121
+ cookieName: "PARAGLIDE_LOCALE",
122
+ urlPatterns: [
123
+ {
124
+ pattern: "https://example.com/:path(.*)?",
125
+ localized: [
126
+ ["en", "https://example.com/en/:path(.*)?"],
127
+ ["fr", "https://example.com/fr/:path(.*)?"],
128
+ ],
129
+ },
130
+ ],
141
131
  });
142
132
  // Request to already localized URL matching cookie locale
143
133
  const request = new Request("https://example.com/fr/some-path", {
@@ -155,16 +145,14 @@ test("does not redirect if URL already matches determined locale", async () => {
155
145
  });
156
146
  test("works with disableAsyncLocalStorage option", async () => {
157
147
  const runtime = await createParaglide({
158
- project: await newProject({
148
+ blob: await newProject({
159
149
  settings: {
160
150
  baseLocale: "en",
161
151
  locales: ["en", "de", "fr"],
162
152
  },
163
153
  }),
164
- compilerOptions: {
165
- strategy: ["url", "globalVariable"],
166
- disableAsyncLocalStorage: true,
167
- },
154
+ strategy: ["url", "globalVariable"],
155
+ disableAsyncLocalStorage: true,
168
156
  });
169
157
  // Set a global locale to verify it doesn't interfere with request processing
170
158
  runtime.setLocale("fr");
@@ -189,15 +177,13 @@ test("works with disableAsyncLocalStorage option", async () => {
189
177
  });
190
178
  test("works with sequential parallel requests using disableAsyncLocalStorage", async () => {
191
179
  const runtime = await createParaglide({
192
- project: await newProject({
180
+ blob: await newProject({
193
181
  settings: {
194
182
  baseLocale: "en",
195
183
  locales: ["en", "de", "fr"],
196
184
  },
197
185
  }),
198
- compilerOptions: {
199
- strategy: ["url", "globalVariable"],
200
- },
186
+ strategy: ["url", "globalVariable"],
201
187
  });
202
188
  // setting the global variable to fr to assure that
203
189
  runtime.setLocale("fr");
@@ -224,25 +210,23 @@ test("works with sequential parallel requests using disableAsyncLocalStorage", a
224
210
  // https://github.com/opral/inlang-paraglide-js/issues/442
225
211
  test("falls back to next strategy when cookie contains invalid locale", async () => {
226
212
  const runtime = await createParaglide({
227
- project: await newProject({
213
+ blob: await newProject({
228
214
  settings: {
229
215
  baseLocale: "en",
230
216
  locales: ["en", "fr"],
231
217
  },
232
218
  }),
233
- compilerOptions: {
234
- strategy: ["cookie", "url", "baseLocale"],
235
- cookieName: "PARAGLIDE_LOCALE",
236
- urlPatterns: [
237
- {
238
- pattern: "https://example.com/:path(.*)?",
239
- localized: [
240
- ["en", "https://example.com/en/:path(.*)?"],
241
- ["fr", "https://example.com/fr/:path(.*)?"],
242
- ],
243
- },
244
- ],
245
- },
219
+ strategy: ["cookie", "url", "baseLocale"],
220
+ cookieName: "PARAGLIDE_LOCALE",
221
+ urlPatterns: [
222
+ {
223
+ pattern: "https://example.com/:path(.*)?",
224
+ localized: [
225
+ ["en", "https://example.com/en/:path(.*)?"],
226
+ ["fr", "https://example.com/fr/:path(.*)?"],
227
+ ],
228
+ },
229
+ ],
246
230
  });
247
231
  // Request with an invalid locale in cookie
248
232
  const request = new Request("https://example.com/fr/some-path", {
@@ -276,25 +260,23 @@ test("falls back to next strategy when cookie contains invalid locale", async ()
276
260
  test("prevents redirect loops by normalizing URLs with trailing slashes in different scenarios", async () => {
277
261
  // Create two different runtimes to test different strategy configurations
278
262
  const runtime = await createParaglide({
279
- project: await newProject({
263
+ blob: await newProject({
280
264
  settings: {
281
265
  baseLocale: "en",
282
266
  locales: ["en", "fr"],
283
267
  },
284
268
  }),
285
- compilerOptions: {
286
- strategy: ["cookie", "url"],
287
- cookieName: "PARAGLIDE_LOCALE",
288
- urlPatterns: [
289
- {
290
- pattern: "https://example.com/:path(.*)?",
291
- localized: [
292
- ["en", "https://example.com/en/:path(.*)?"],
293
- ["fr", "https://example.com/fr/:path(.*)?"],
294
- ],
295
- },
296
- ],
297
- },
269
+ strategy: ["cookie", "url"],
270
+ cookieName: "PARAGLIDE_LOCALE",
271
+ urlPatterns: [
272
+ {
273
+ pattern: "https://example.com/:path(.*)?",
274
+ localized: [
275
+ ["en", "https://example.com/en/:path(.*)?"],
276
+ ["fr", "https://example.com/fr/:path(.*)?"],
277
+ ],
278
+ },
279
+ ],
298
280
  });
299
281
  // SCENARIO 1: Basic trailing slash normalization with cookie strategy
300
282
  // Case 1A: Request URL has trailing slash, but localized URL might not
@@ -342,25 +324,23 @@ test("prevents redirect loops by normalizing URLs with trailing slashes in diffe
342
324
  // strategy: ["cookie", "url"]
343
325
  test.skip("doesn't redirect if disableUrlRedirect is true", async () => {
344
326
  const runtime = await createParaglide({
345
- project: await newProject({
327
+ blob: await newProject({
346
328
  settings: {
347
329
  baseLocale: "en",
348
330
  locales: ["en", "fr"],
349
331
  },
350
332
  }),
351
- compilerOptions: {
352
- cookieName: "PARAGLIDE_LOCALE",
353
- strategy: ["cookie", "url"],
354
- urlPatterns: [
355
- {
356
- pattern: "https://example.com/:path(.*)?",
357
- localized: [
358
- ["en", "https://example.com/en/:path(.*)?"],
359
- ["fr", "https://example.com/fr/:path(.*)?"],
360
- ],
361
- },
362
- ],
363
- },
333
+ cookieName: "PARAGLIDE_LOCALE",
334
+ strategy: ["cookie", "url"],
335
+ urlPatterns: [
336
+ {
337
+ pattern: "https://example.com/:path(.*)?",
338
+ localized: [
339
+ ["en", "https://example.com/en/:path(.*)?"],
340
+ ["fr", "https://example.com/fr/:path(.*)?"],
341
+ ],
342
+ },
343
+ ],
364
344
  });
365
345
  // Create a request that would normally be redirected
366
346
  const request = new Request("https://example.com/en/some-path", {
@@ -382,25 +362,23 @@ test.skip("doesn't redirect if disableUrlRedirect is true", async () => {
382
362
  });
383
363
  test("only redirects if the request.headers.get('Sec-Fetch-Dest') === 'document'", async () => {
384
364
  const runtime = await createParaglide({
385
- project: await newProject({
365
+ blob: await newProject({
386
366
  settings: {
387
367
  baseLocale: "en",
388
368
  locales: ["en", "fr"],
389
369
  },
390
370
  }),
391
- compilerOptions: {
392
- strategy: ["cookie", "url"],
393
- cookieName: "PARAGLIDE_LOCALE",
394
- urlPatterns: [
395
- {
396
- pattern: "https://example.com/:path(.*)?",
397
- localized: [
398
- ["en", "https://example.com/en/:path(.*)?"],
399
- ["fr", "https://example.com/fr/:path(.*)?"],
400
- ],
401
- },
402
- ],
403
- },
371
+ strategy: ["cookie", "url"],
372
+ cookieName: "PARAGLIDE_LOCALE",
373
+ urlPatterns: [
374
+ {
375
+ pattern: "https://example.com/:path(.*)?",
376
+ localized: [
377
+ ["en", "https://example.com/en/:path(.*)?"],
378
+ ["fr", "https://example.com/fr/:path(.*)?"],
379
+ ],
380
+ },
381
+ ],
404
382
  });
405
383
  // Test with Sec-Fetch-Dest = document (should redirect)
406
384
  const documentRequest = new Request("https://example.com/en/some-path", {
@@ -436,15 +414,13 @@ test("only redirects if the request.headers.get('Sec-Fetch-Dest') === 'document'
436
414
  // https://github.com/opral/inlang-paraglide-js/issues/477
437
415
  test("does not catch errors thrown by downstream resolve call", async () => {
438
416
  const runtime = await createParaglide({
439
- project: await newProject({
417
+ blob: await newProject({
440
418
  settings: {
441
419
  baseLocale: "en",
442
420
  locales: ["en"],
443
421
  },
444
422
  }),
445
- compilerOptions: {
446
- strategy: ["url"],
447
- },
423
+ strategy: ["url"],
448
424
  });
449
425
  await expect(() => runtime.paraglideMiddleware(new Request(new URL("https://example.com/page"), {
450
426
  headers: { "Sec-Fetch-Dest": "document" },
@@ -1,5 +1,5 @@
1
1
  export const ENV_VARIABLES = {
2
2
  PARJS_APP_ID: "library.inlang.paraglideJs",
3
3
  PARJS_POSTHOG_TOKEN: "phc_m5yJZCxjOGxF8CJvP5sQ3H0d76xpnLrsmiZHduT4jDz",
4
- PARJS_PACKAGE_VERSION: "2.0.10",
4
+ PARJS_PACKAGE_VERSION: "2.0.12",
5
5
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@inlang/paraglide-js",
3
3
  "type": "module",
4
- "version": "2.0.10",
4
+ "version": "2.0.12",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
7
7
  "access": "public",
@@ -31,8 +31,8 @@
31
31
  "json5": "2.2.3",
32
32
  "unplugin": "^2.1.2",
33
33
  "urlpattern-polyfill": "^10.0.0",
34
- "@inlang/recommend-sherlock": "0.2.1",
35
- "@inlang/sdk": "2.4.7"
34
+ "@inlang/sdk": "2.4.8",
35
+ "@inlang/recommend-sherlock": "0.2.1"
36
36
  },
37
37
  "devDependencies": {
38
38
  "@eslint/js": "^9.18.0",
@@ -50,9 +50,9 @@
50
50
  "typescript": "^5.7.3",
51
51
  "typescript-eslint": "^8.20.0",
52
52
  "vitest": "2.1.8",
53
+ "@inlang/paraglide-js": "2.0.12",
53
54
  "@inlang/plugin-message-format": "4.0.0",
54
- "@opral/tsconfig": "1.1.0",
55
- "@inlang/paraglide-js": "2.0.10"
55
+ "@opral/tsconfig": "1.1.0"
56
56
  },
57
57
  "keywords": [
58
58
  "inlang",