@inlang/paraglide-js 2.27.0 → 2.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/bundler-plugins/per-locale-build/index.js +14 -7
- package/dist/bundler-plugins/per-locale-build/index.js.map +1 -1
- package/dist/bundler-plugins/per-locale-build/vite-environments.test.js +235 -2
- package/dist/bundler-plugins/per-locale-build/vite-environments.test.js.map +1 -1
- package/dist/bundler-plugins/unplugin.d.ts +1 -1
- package/dist/bundler-plugins/unplugin.js +79 -10
- package/dist/bundler-plugins/unplugin.js.map +1 -1
- package/dist/bundler-plugins/unplugin.test.js +334 -1
- package/dist/bundler-plugins/unplugin.test.js.map +1 -1
- package/dist/bundler-plugins/vite.js +2 -1
- package/dist/bundler-plugins/vite.js.map +1 -1
- package/dist/bundler-plugins/vite.test.js +1 -1
- package/dist/bundler-plugins/vite.test.js.map +1 -1
- package/dist/cli/commands/compile/command.js +13 -0
- package/dist/cli/commands/compile/command.js.map +1 -1
- package/dist/cli/commands/compile/command.test.js +87 -3
- package/dist/cli/commands/compile/command.test.js.map +1 -1
- package/dist/cli/commands/init/command.d.ts +5 -0
- package/dist/cli/commands/init/command.js +213 -59
- package/dist/cli/commands/init/command.js.map +1 -1
- package/dist/cli/commands/init/command.test.d.ts +1 -0
- package/dist/cli/commands/init/command.test.js +123 -0
- package/dist/cli/commands/init/command.test.js.map +1 -0
- package/dist/cli/init-options.d.ts +11 -0
- package/dist/cli/init-options.js +2 -0
- package/dist/cli/init-options.js.map +1 -0
- package/dist/cli/steps/add-inlang-check.js +2 -2
- package/dist/cli/steps/add-inlang-check.js.map +1 -1
- package/dist/cli/steps/add-message-lint.d.ts +34 -0
- package/dist/cli/steps/add-message-lint.js +105 -0
- package/dist/cli/steps/add-message-lint.js.map +1 -0
- package/dist/cli/steps/add-message-lint.test.d.ts +1 -0
- package/dist/cli/steps/add-message-lint.test.js +74 -0
- package/dist/cli/steps/add-message-lint.test.js.map +1 -0
- package/dist/cli/steps/add-vite-plugin.d.ts +18 -0
- package/dist/cli/steps/add-vite-plugin.js +34 -6
- package/dist/cli/steps/add-vite-plugin.js.map +1 -1
- package/dist/cli/steps/add-vite-plugin.test.js +25 -9
- package/dist/cli/steps/add-vite-plugin.test.js.map +1 -1
- package/dist/cli/steps/check-for-uncomitted-changes.d.ts +3 -0
- package/dist/cli/steps/check-for-uncomitted-changes.js +15 -3
- package/dist/cli/steps/check-for-uncomitted-changes.js.map +1 -1
- package/dist/cli/steps/detect-bundler.d.ts +1 -0
- package/dist/cli/steps/detect-bundler.js +7 -1
- package/dist/cli/steps/detect-bundler.js.map +1 -1
- package/dist/cli/steps/initialize-inlang-project.d.ts +4 -3
- package/dist/cli/steps/initialize-inlang-project.js +60 -157
- package/dist/cli/steps/initialize-inlang-project.js.map +1 -1
- package/dist/cli/steps/maybe-add-machine-translation.d.ts +4 -0
- package/dist/cli/steps/maybe-add-machine-translation.js +11 -6
- package/dist/cli/steps/maybe-add-machine-translation.js.map +1 -1
- package/dist/cli/steps/maybe-add-sherlock.d.ts +2 -0
- package/dist/cli/steps/maybe-add-sherlock.js +12 -6
- package/dist/cli/steps/maybe-add-sherlock.js.map +1 -1
- package/dist/cli/steps/maybe-add-sherlock.test.d.ts +1 -0
- package/dist/cli/steps/maybe-add-sherlock.test.js +44 -0
- package/dist/cli/steps/maybe-add-sherlock.test.js.map +1 -0
- package/dist/cli/steps/prompt-for-outdir.d.ts +2 -0
- package/dist/cli/steps/prompt-for-outdir.js +4 -0
- package/dist/cli/steps/prompt-for-outdir.js.map +1 -1
- package/dist/cli/steps/update-package-json.js +8 -13
- package/dist/cli/steps/update-package-json.js.map +1 -1
- package/dist/cli/steps/update-ts-config.d.ts +6 -0
- package/dist/cli/steps/update-ts-config.js +27 -4
- package/dist/cli/steps/update-ts-config.js.map +1 -1
- package/dist/cli/utils.d.ts +2 -0
- package/dist/cli/utils.js +6 -0
- package/dist/cli/utils.js.map +1 -1
- package/dist/cli/utils.test.d.ts +1 -0
- package/dist/cli/utils.test.js +16 -0
- package/dist/cli/utils.test.js.map +1 -0
- package/dist/compiler/compile-annotation.js +6 -1
- package/dist/compiler/compile-annotation.js.map +1 -1
- package/dist/compiler/compile-bundle.d.ts +4 -0
- package/dist/compiler/compile-bundle.js +67 -2
- package/dist/compiler/compile-bundle.js.map +1 -1
- package/dist/compiler/compile-bundle.test.js +214 -1
- package/dist/compiler/compile-bundle.test.js.map +1 -1
- package/dist/compiler/compile-lifecycle.test.d.ts +1 -0
- package/dist/compiler/compile-lifecycle.test.js +69 -0
- package/dist/compiler/compile-lifecycle.test.js.map +1 -0
- package/dist/compiler/compile-local-variable.test.js +14 -14
- package/dist/compiler/compile-local-variable.test.js.map +1 -1
- package/dist/compiler/compile-message.exact-number.test.js +1 -1
- package/dist/compiler/compile-message.exact-number.test.js.map +1 -1
- package/dist/compiler/compile-message.locals.test.js +1 -1
- package/dist/compiler/compile-message.locals.test.js.map +1 -1
- package/dist/compiler/compile-message.test.js +2 -2
- package/dist/compiler/compile-message.test.js.map +1 -1
- package/dist/compiler/compile-pattern.test.js +5 -5
- package/dist/compiler/compile-pattern.test.js.map +1 -1
- package/dist/compiler/compile-project.js +1 -0
- package/dist/compiler/compile-project.js.map +1 -1
- package/dist/compiler/compile-project.test.js +94 -1
- package/dist/compiler/compile-project.test.js.map +1 -1
- package/dist/compiler/compile.js +36 -17
- package/dist/compiler/compile.js.map +1 -1
- package/dist/compiler/compile.test.js +70 -0
- package/dist/compiler/compile.test.js.map +1 -1
- package/dist/compiler/compiler-options.d.ts +41 -0
- package/dist/compiler/compiler-options.js.map +1 -1
- package/dist/compiler/output-structure/message-modules.js +1 -1
- package/dist/compiler/output-structure/message-modules.js.map +1 -1
- package/dist/compiler/registry.js +71 -13
- package/dist/compiler/registry.js.map +1 -1
- package/dist/compiler/registry.test.d.ts +1 -0
- package/dist/compiler/registry.test.js +291 -0
- package/dist/compiler/registry.test.js.map +1 -0
- package/dist/compiler/runtime/create-runtime.d.ts +2 -0
- package/dist/compiler/runtime/create-runtime.js +9 -0
- package/dist/compiler/runtime/create-runtime.js.map +1 -1
- package/dist/compiler/runtime/extract-locale-from-cookie.js +8 -1
- package/dist/compiler/runtime/extract-locale-from-cookie.js.map +1 -1
- package/dist/compiler/runtime/extract-locale-from-cookie.test.js +26 -0
- package/dist/compiler/runtime/extract-locale-from-cookie.test.js.map +1 -1
- package/dist/compiler/runtime/extract-locale-from-header.js +47 -5
- package/dist/compiler/runtime/extract-locale-from-header.js.map +1 -1
- package/dist/compiler/runtime/extract-locale-from-header.test.js +58 -0
- package/dist/compiler/runtime/extract-locale-from-header.test.js.map +1 -1
- package/dist/compiler/runtime/get-locale.js +7 -1
- package/dist/compiler/runtime/get-locale.js.map +1 -1
- package/dist/compiler/runtime/get-locale.test.js +95 -0
- package/dist/compiler/runtime/get-locale.test.js.map +1 -1
- package/dist/compiler/runtime/localize-href.d.ts +8 -0
- package/dist/compiler/runtime/localize-href.js +60 -0
- package/dist/compiler/runtime/localize-href.js.map +1 -1
- package/dist/compiler/runtime/localize-href.test.js +227 -1
- package/dist/compiler/runtime/localize-href.test.js.map +1 -1
- package/dist/compiler/runtime/set-locale.js +24 -6
- package/dist/compiler/runtime/set-locale.js.map +1 -1
- package/dist/compiler/runtime/set-locale.test.js +182 -0
- package/dist/compiler/runtime/set-locale.test.js.map +1 -1
- package/dist/compiler/runtime/type.d.ts +2 -0
- package/dist/compiler/runtime/type.js.map +1 -1
- package/dist/compiler/runtime/type.test.js +34 -0
- package/dist/compiler/runtime/type.test.js.map +1 -1
- package/dist/compiler/runtime/variables.d.ts +2 -0
- package/dist/compiler/runtime/variables.js +7 -0
- package/dist/compiler/runtime/variables.js.map +1 -1
- package/dist/compiler/server/middleware.d.ts +8 -2
- package/dist/compiler/server/middleware.js +175 -7
- package/dist/compiler/server/middleware.js.map +1 -1
- package/dist/compiler/server/middleware.test.js +750 -3
- package/dist/compiler/server/middleware.test.js.map +1 -1
- package/dist/eslint/index.d.ts +4 -0
- package/dist/eslint/index.js +8 -0
- package/dist/eslint/index.js.map +1 -0
- package/dist/eslint/no-dynamic-message-access.d.ts +3 -0
- package/dist/eslint/no-dynamic-message-access.js +150 -0
- package/dist/eslint/no-dynamic-message-access.js.map +1 -0
- package/dist/eslint/no-dynamic-message-access.test.d.ts +1 -0
- package/dist/eslint/no-dynamic-message-access.test.js +126 -0
- package/dist/eslint/no-dynamic-message-access.test.js.map +1 -0
- package/dist/eslint/oxlint.test.d.ts +1 -0
- package/dist/eslint/oxlint.test.js +64 -0
- package/dist/eslint/oxlint.test.js.map +1 -0
- package/dist/services/config/config-schema.d.ts +2 -0
- package/dist/services/config/config-schema.js +2 -0
- package/dist/services/config/config-schema.js.map +1 -1
- package/dist/services/config/load-paraglide-config.test.js +12 -0
- package/dist/services/config/load-paraglide-config.test.js.map +1 -1
- package/dist/services/env-variables/index.js +1 -1
- package/dist/services/env-variables/index.js.map +1 -1
- package/dist/services/file-handling/write-output.bench.js +51 -11
- package/dist/services/file-handling/write-output.bench.js.map +1 -1
- package/dist/services/file-handling/write-output.js +60 -20
- package/dist/services/file-handling/write-output.js.map +1 -1
- package/dist/services/file-handling/write-output.test.js +175 -0
- package/dist/services/file-handling/write-output.test.js.map +1 -1
- package/package.json +14 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-locale.js","sourceRoot":"","sources":["../../../src/compiler/runtime/set-locale.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EACN,YAAY,EACZ,YAAY,EACZ,UAAU,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;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,EAAE,EAAE,EAAE;IACxC,SAAS,GAAG,EAAE,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { getLocale } from \"./get-locale.js\";\nimport { clearLocaleCookieCache } from \"./extract-locale-from-cookie.js\";\nimport { localizeUrl } from \"./localize-url.js\";\nimport { getStrategyForUrl } from \"./route-strategy.js\";\nimport { customClientStrategies, isCustomStrategy } from \"./strategy.js\";\nimport {\n\tcookieDomain,\n\tcookieMaxAge,\n\tcookieName,\n\tisServer,\n\tlocalStorageKey,\n\texperimentalStaticLocale,\n\tstrategy,\n\tTREE_SHAKE_COOKIE_STRATEGY_USED,\n\tTREE_SHAKE_GLOBAL_VARIABLE_STRATEGY_USED,\n\tTREE_SHAKE_LOCAL_STORAGE_STRATEGY_USED,\n\tTREE_SHAKE_URL_STRATEGY_USED,\n} from \"./variables.js\";\n\n/**\n * Navigates to the localized URL, or reloads the current page\n *\n * @param {string} [newLocation] The new location\n */\nconst navigateOrReload = (newLocation) => {\n\tif (newLocation) {\n\t\t// reload the page by navigating to the new url\n\t\twindow.location.href = newLocation;\n\t} else {\n\t\t// reload the page to reflect the new locale\n\t\twindow.location.reload();\n\t}\n};\n\n/**\n * @typedef {(newLocale: Locale, options?: { reload?: boolean }) => void | Promise<void>} SetLocaleFn\n */\n\n/**\n * Set the locale.\n *\n * Updates the locale using your configured strategies (cookie, localStorage, URL, etc.).\n * By default, this navigates the client to the localized URL or reloads the current\n * document to reflect the new locale. `reload: false` is a narrow browser-only escape\n * hatch for a fully client-rendered, non-URL-routed surface that owns its reactive\n * updates and document state. It does not re-render the UI or update the document.\n * Do not use it for normal locale pickers, URL-routed pages, or switching an SSR,\n * SSG, or hydrated document. It is incompatible with per-locale builds.\n *\n * If any custom strategy's `setLocale` function is async, then this function\n * will become async as well.\n *\n * @see https://paraglidejs.com/strategy\n *\n * @example\n * setLocale('en');\n *\n * @example\n * setLocale('en', { reload: false });\n *\n * @type {SetLocaleFn}\n */\nexport let setLocale = (newLocale, options) => {\n\tconst optionsWithDefaults = {\n\t\treload: true,\n\t\t...options,\n\t};\n\tif (\n\t\texperimentalStaticLocale !== undefined &&\n\t\tnewLocale !== experimentalStaticLocale &&\n\t\toptionsWithDefaults.reload === false\n\t) {\n\t\tconsole.warn(\n\t\t\t`Paraglide: setLocale(${JSON.stringify(newLocale)}, { reload: false }) cannot switch away from the statically built locale ${JSON.stringify(experimentalStaticLocale)}. A document navigation is required; reload has been forced to true.`\n\t\t);\n\t\toptionsWithDefaults.reload = true;\n\t}\n\t// locale is already set\n\t// https://github.com/opral/inlang-paraglide-js/issues/430\n\t/** @type {Locale | undefined} */\n\tlet currentLocale;\n\ttry {\n\t\tcurrentLocale = getLocale();\n\t} catch {\n\t\t// do nothing, no locale has been set yet.\n\t}\n\t/** @type {Array<Promise<void>>} */\n\tconst customSetLocalePromises = [];\n\t/** @type {string | undefined} */\n\tlet newLocation = undefined;\n\tlet strategyToUse = strategy;\n\tif (!isServer && typeof window !== \"undefined\" && window.location?.href) {\n\t\tstrategyToUse = getStrategyForUrl(window.location.href);\n\t}\n\tfor (const strat of strategyToUse) {\n\t\tif (\n\t\t\tTREE_SHAKE_GLOBAL_VARIABLE_STRATEGY_USED &&\n\t\t\tstrat === \"globalVariable\"\n\t\t) {\n\t\t\t// a default for a custom strategy to get started quickly\n\t\t\t// is likely overwritten by `defineSetLocale()`\n\t\t\t_locale = newLocale;\n\t\t} else if (TREE_SHAKE_COOKIE_STRATEGY_USED && strat === \"cookie\") {\n\t\t\tif (\n\t\t\t\tisServer ||\n\t\t\t\ttypeof document === \"undefined\" ||\n\t\t\t\ttypeof window === \"undefined\"\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// set the cookie\n\t\t\tconst cookieString = `${cookieName}=${newLocale}; path=/; max-age=${cookieMaxAge}`;\n\t\t\tdocument.cookie = cookieDomain\n\t\t\t\t? `${cookieString}; domain=${cookieDomain}`\n\t\t\t\t: cookieString;\n\t\t\tclearLocaleCookieCache();\n\t\t} else if (strat === \"baseLocale\") {\n\t\t\t// nothing to be set here. baseLocale is only a fallback\n\t\t\tcontinue;\n\t\t} else if (\n\t\t\tTREE_SHAKE_URL_STRATEGY_USED &&\n\t\t\tstrat === \"url\" &&\n\t\t\ttypeof window !== \"undefined\"\n\t\t) {\n\t\t\t// route to the new url\n\t\t\t//\n\t\t\t// this triggers a page reload but a user rarely\n\t\t\t// switches locales, so this should be fine.\n\t\t\t//\n\t\t\t// if the behavior is not desired, the implementation\n\t\t\t// can be overwritten by `defineSetLocale()` to avoid\n\t\t\t// a full page reload.\n\t\t\tnewLocation = localizeUrl(window.location.href, {\n\t\t\t\tlocale: newLocale,\n\t\t\t}).href;\n\t\t} else if (\n\t\t\tTREE_SHAKE_LOCAL_STORAGE_STRATEGY_USED &&\n\t\t\tstrat === \"localStorage\" &&\n\t\t\ttypeof window !== \"undefined\"\n\t\t) {\n\t\t\t// set the localStorage\n\t\t\tlocalStorage.setItem(localStorageKey, newLocale);\n\t\t} else if (isCustomStrategy(strat) && customClientStrategies.has(strat)) {\n\t\t\tconst handler = customClientStrategies.get(strat);\n\t\t\tif (handler) {\n\t\t\t\tlet result = handler.setLocale(newLocale);\n\t\t\t\t// Handle async setLocale\n\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\tresult = result.catch((error) => {\n\t\t\t\t\t\tthrow new Error(`Custom strategy \"${strat}\" setLocale failed.`, {\n\t\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t\tcustomSetLocalePromises.push(result);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst runReload = () => {\n\t\tif (\n\t\t\t!isServer &&\n\t\t\toptionsWithDefaults.reload &&\n\t\t\twindow.location &&\n\t\t\tnewLocale !== currentLocale\n\t\t) {\n\t\t\tnavigateOrReload(newLocation);\n\t\t}\n\t};\n\n\tif (customSetLocalePromises.length) {\n\t\treturn Promise.all(customSetLocalePromises).then(() => {\n\t\t\trunReload();\n\t\t});\n\t}\n\n\trunReload();\n\n\treturn;\n};\n\n/**\n * Overwrite the `setLocale()` function.\n *\n * Use this function to overwrite how the locale is set. For example,\n * modify a cookie, env variable, or a user's preference.\n *\n * @example\n * overwriteSetLocale((newLocale) => {\n * // set the locale in a cookie\n * return Cookies.set('locale', newLocale)\n * });\n *\n * @param {SetLocaleFn} fn\n */\nexport const overwriteSetLocale = (fn) => {\n\tsetLocale = fn;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"set-locale.js","sourceRoot":"","sources":["../../../src/compiler/runtime/set-locale.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EACN,YAAY,EACZ,YAAY,EACZ,UAAU,EACV,cAAc,EACd,YAAY,EACZ,QAAQ,EACR,eAAe,EACf,wBAAwB,EACxB,QAAQ,EACR,+BAA+B,EAC/B,wCAAwC,EACxC,sCAAsC,EACtC,4BAA4B,GAC5B,MAAM,gBAAgB,CAAC;AAExB;;;;GAIG;AACH,MAAM,gBAAgB,GAAG,CAAC,WAAW,EAAE,EAAE;IACxC,IAAI,WAAW,EAAE,CAAC;QACjB,+CAA+C;QAC/C,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,WAAW,CAAC;IACpC,CAAC;SAAM,CAAC;QACP,4CAA4C;QAC5C,MAAM,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;IAC1B,CAAC;AACF,CAAC,CAAC;AAEF;;GAEG;AAEH;;;;;;;;;;;;;;;;;;;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AAkB,GAAG,CAAC,EAAE,EAAE,EAAE;IACxC,SAAS,GAAG,EAAE,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { getLocale } from \"./get-locale.js\";\nimport { clearLocaleCookieCache } from \"./extract-locale-from-cookie.js\";\nimport { localizeUrl } from \"./localize-url.js\";\nimport { getStrategyForUrl } from \"./route-strategy.js\";\nimport { customClientStrategies, isCustomStrategy } from \"./strategy.js\";\nimport {\n\tcookieDomain,\n\tcookieMaxAge,\n\tcookieName,\n\tcookieSameSite,\n\tcookieSecure,\n\tisServer,\n\tlocalStorageKey,\n\texperimentalStaticLocale,\n\tstrategy,\n\tTREE_SHAKE_COOKIE_STRATEGY_USED,\n\tTREE_SHAKE_GLOBAL_VARIABLE_STRATEGY_USED,\n\tTREE_SHAKE_LOCAL_STORAGE_STRATEGY_USED,\n\tTREE_SHAKE_URL_STRATEGY_USED,\n} from \"./variables.js\";\n\n/**\n * Navigates to the localized URL, or reloads the current page\n *\n * @param {string} [newLocation] The new location\n */\nconst navigateOrReload = (newLocation) => {\n\tif (newLocation) {\n\t\t// reload the page by navigating to the new url\n\t\twindow.location.href = newLocation;\n\t} else {\n\t\t// reload the page to reflect the new locale\n\t\twindow.location.reload();\n\t}\n};\n\n/**\n * @typedef {(newLocale: Locale, options?: { reload?: boolean }) => void | Promise<void>} SetLocaleFn\n */\n\n/**\n * Set the locale.\n *\n * Updates the locale using your configured strategies (cookie, localStorage, URL, etc.).\n * By default, this navigates the client to the localized URL or reloads the current\n * document to reflect the new locale. `reload: false` is a narrow browser-only escape\n * hatch for a fully client-rendered, non-URL-routed surface that owns its reactive\n * updates and document state. It does not re-render the UI or update the document.\n * Do not use it for normal locale pickers, URL-routed pages, or switching an SSR,\n * SSG, or hydrated document. It is incompatible with per-locale builds.\n *\n * If any custom strategy's `setLocale` function is async, then this function\n * will become async as well.\n *\n * @see https://paraglidejs.com/strategy\n *\n * @example\n * setLocale('en');\n *\n * @example\n * setLocale('en', { reload: false });\n *\n * @type {SetLocaleFn}\n */\nexport let setLocale = (newLocale, options) => {\n\tconst optionsWithDefaults = {\n\t\treload: true,\n\t\t...options,\n\t};\n\tif (\n\t\texperimentalStaticLocale !== undefined &&\n\t\tnewLocale !== experimentalStaticLocale &&\n\t\toptionsWithDefaults.reload === false\n\t) {\n\t\tconsole.warn(\n\t\t\t`Paraglide: setLocale(${JSON.stringify(newLocale)}, { reload: false }) cannot switch away from the statically built locale ${JSON.stringify(experimentalStaticLocale)}. A document navigation is required; reload has been forced to true.`\n\t\t);\n\t\toptionsWithDefaults.reload = true;\n\t}\n\t// locale is already set\n\t// https://github.com/opral/inlang-paraglide-js/issues/430\n\t/** @type {Locale | undefined} */\n\tlet currentLocale;\n\ttry {\n\t\tcurrentLocale = getLocale();\n\t} catch {\n\t\t// do nothing, no locale has been set yet.\n\t}\n\t/** @type {Array<Promise<void>>} */\n\tconst customSetLocalePromises = [];\n\t/** @type {string | undefined} */\n\tlet newLocation = undefined;\n\tlet strategyToUse = strategy;\n\tif (!isServer && typeof window !== \"undefined\" && window.location?.href) {\n\t\tstrategyToUse = getStrategyForUrl(window.location.href);\n\t}\n\tfor (const strat of strategyToUse) {\n\t\tif (\n\t\t\tTREE_SHAKE_GLOBAL_VARIABLE_STRATEGY_USED &&\n\t\t\tstrat === \"globalVariable\"\n\t\t) {\n\t\t\t// a default for a custom strategy to get started quickly\n\t\t\t// is likely overwritten by `defineSetLocale()`\n\t\t\t_locale = newLocale;\n\t\t} else if (TREE_SHAKE_COOKIE_STRATEGY_USED && strat === \"cookie\") {\n\t\t\tif (\n\t\t\t\tisServer ||\n\t\t\t\ttypeof document === \"undefined\" ||\n\t\t\t\ttypeof window === \"undefined\"\n\t\t\t) {\n\t\t\t\tcontinue;\n\t\t\t}\n\n\t\t\t// set the cookie\n\t\t\tlet cookieString = `${cookieName}=${newLocale}; path=/; max-age=${cookieMaxAge}`;\n\t\t\tif (cookieDomain) {\n\t\t\t\tcookieString += `; domain=${cookieDomain}`;\n\t\t\t}\n\t\t\tif (cookieSameSite) {\n\t\t\t\tcookieString += `; samesite=${cookieSameSite}`;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tcookieSecure === true ||\n\t\t\t\t(cookieSecure === \"auto\" && window.location?.protocol === \"https:\")\n\t\t\t) {\n\t\t\t\tcookieString += \"; secure\";\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tdocument.cookie = cookieString;\n\t\t\t} catch {\n\t\t\t\t// document.cookie throws in sandboxed iframes and other opaque origins\n\t\t\t}\n\n\t\t\tclearLocaleCookieCache();\n\t\t} else if (strat === \"baseLocale\") {\n\t\t\t// nothing to be set here. baseLocale is only a fallback\n\t\t\tcontinue;\n\t\t} else if (\n\t\t\tTREE_SHAKE_URL_STRATEGY_USED &&\n\t\t\tstrat === \"url\" &&\n\t\t\ttypeof window !== \"undefined\"\n\t\t) {\n\t\t\t// route to the new url\n\t\t\t//\n\t\t\t// this triggers a page reload but a user rarely\n\t\t\t// switches locales, so this should be fine.\n\t\t\t//\n\t\t\t// if the behavior is not desired, the implementation\n\t\t\t// can be overwritten by `defineSetLocale()` to avoid\n\t\t\t// a full page reload.\n\t\t\tnewLocation = localizeUrl(window.location.href, {\n\t\t\t\tlocale: newLocale,\n\t\t\t}).href;\n\t\t} else if (\n\t\t\tTREE_SHAKE_LOCAL_STORAGE_STRATEGY_USED &&\n\t\t\tstrat === \"localStorage\" &&\n\t\t\ttypeof window !== \"undefined\"\n\t\t) {\n\t\t\t// set the localStorage\n\t\t\ttry {\n\t\t\t\tlocalStorage.setItem(localStorageKey, newLocale);\n\t\t\t} catch {\n\t\t\t\t// localStorage throws when storage access is denied\n\t\t\t}\n\t\t} else if (isCustomStrategy(strat) && customClientStrategies.has(strat)) {\n\t\t\tconst handler = customClientStrategies.get(strat);\n\t\t\tif (handler) {\n\t\t\t\tlet result = handler.setLocale(newLocale);\n\t\t\t\t// Handle async setLocale\n\t\t\t\tif (result instanceof Promise) {\n\t\t\t\t\tresult = result.catch((error) => {\n\t\t\t\t\t\tthrow new Error(`Custom strategy \"${strat}\" setLocale failed.`, {\n\t\t\t\t\t\t\tcause: error,\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t\tcustomSetLocalePromises.push(result);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tconst runReload = () => {\n\t\tif (\n\t\t\t!isServer &&\n\t\t\toptionsWithDefaults.reload &&\n\t\t\twindow.location &&\n\t\t\tnewLocale !== currentLocale\n\t\t) {\n\t\t\tnavigateOrReload(newLocation);\n\t\t}\n\t};\n\n\tif (customSetLocalePromises.length) {\n\t\treturn Promise.all(customSetLocalePromises).then(() => {\n\t\t\trunReload();\n\t\t});\n\t}\n\n\trunReload();\n\n\treturn;\n};\n\n/**\n * Overwrite the `setLocale()` function.\n *\n * Use this function to overwrite how the locale is set. For example,\n * modify a cookie, env variable, or a user's preference.\n *\n * @example\n * overwriteSetLocale((newLocale) => {\n * // set the locale in a cookie\n * return Cookies.set('locale', newLocale)\n * });\n *\n * @param {SetLocaleFn} fn\n */\nexport const overwriteSetLocale = (fn) => {\n\tsetLocale = fn;\n};\n"]}
|
|
@@ -78,6 +78,91 @@ test("sets the cookie with explicit domain to a different locale navigating doma
|
|
|
78
78
|
// reloads the site if window is available
|
|
79
79
|
expect(globalThis.window.location.reload).toBeCalled();
|
|
80
80
|
});
|
|
81
|
+
test("sets the cookie with samesite and secure attributes", async () => {
|
|
82
|
+
// @ts-expect-error - global variable definition
|
|
83
|
+
globalThis.document = {};
|
|
84
|
+
// @ts-expect-error - global variable definition
|
|
85
|
+
globalThis.window = {};
|
|
86
|
+
// @ts-expect-error - global variable definition
|
|
87
|
+
globalThis.window.location = { hostname: "example.com" };
|
|
88
|
+
globalThis.window.location.reload = vi.fn();
|
|
89
|
+
const runtime = await createParaglide({
|
|
90
|
+
blob: await newProject({
|
|
91
|
+
settings: {
|
|
92
|
+
baseLocale: "en",
|
|
93
|
+
locales: ["en", "de"],
|
|
94
|
+
},
|
|
95
|
+
}),
|
|
96
|
+
strategy: ["cookie"],
|
|
97
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
98
|
+
cookieDomain: "example.com",
|
|
99
|
+
cookieSameSite: "strict",
|
|
100
|
+
cookieSecure: true,
|
|
101
|
+
});
|
|
102
|
+
globalThis.document.cookie = "PARAGLIDE_LOCALE=en";
|
|
103
|
+
runtime.setLocale("de");
|
|
104
|
+
expect(globalThis.document.cookie).toBe("PARAGLIDE_LOCALE=de; path=/; max-age=34560000; domain=example.com; samesite=strict; secure");
|
|
105
|
+
// exported so server code can write the cookie with the same attributes
|
|
106
|
+
expect(runtime.cookieSameSite).toBe("strict");
|
|
107
|
+
expect(runtime.cookieSecure).toBe(true);
|
|
108
|
+
});
|
|
109
|
+
test.each([true, "auto"])("sets samesite=none with secure on https pages (cookieSecure: %s)", async (cookieSecure) => {
|
|
110
|
+
// @ts-expect-error - global variable definition
|
|
111
|
+
globalThis.document = {};
|
|
112
|
+
// @ts-expect-error - global variable definition
|
|
113
|
+
globalThis.window = {};
|
|
114
|
+
// @ts-expect-error - global variable definition
|
|
115
|
+
globalThis.window.location = {
|
|
116
|
+
hostname: "example.com",
|
|
117
|
+
protocol: "https:",
|
|
118
|
+
};
|
|
119
|
+
globalThis.window.location.reload = vi.fn();
|
|
120
|
+
const runtime = await createParaglide({
|
|
121
|
+
blob: await newProject({
|
|
122
|
+
settings: {
|
|
123
|
+
baseLocale: "en",
|
|
124
|
+
locales: ["en", "de"],
|
|
125
|
+
},
|
|
126
|
+
}),
|
|
127
|
+
strategy: ["cookie"],
|
|
128
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
129
|
+
cookieSameSite: "none",
|
|
130
|
+
cookieSecure,
|
|
131
|
+
});
|
|
132
|
+
globalThis.document.cookie = "PARAGLIDE_LOCALE=en";
|
|
133
|
+
runtime.setLocale("de");
|
|
134
|
+
expect(globalThis.document.cookie).toBe("PARAGLIDE_LOCALE=de; path=/; max-age=34560000; samesite=none; secure");
|
|
135
|
+
});
|
|
136
|
+
test("cookieSecure 'auto' only sets the secure attribute on https pages", async () => {
|
|
137
|
+
// @ts-expect-error - global variable definition
|
|
138
|
+
globalThis.document = {};
|
|
139
|
+
// @ts-expect-error - global variable definition
|
|
140
|
+
globalThis.window = {};
|
|
141
|
+
// @ts-expect-error - global variable definition
|
|
142
|
+
globalThis.window.location = {
|
|
143
|
+
hostname: "example.com",
|
|
144
|
+
protocol: "https:",
|
|
145
|
+
};
|
|
146
|
+
globalThis.window.location.reload = vi.fn();
|
|
147
|
+
const runtime = await createParaglide({
|
|
148
|
+
blob: await newProject({
|
|
149
|
+
settings: {
|
|
150
|
+
baseLocale: "en",
|
|
151
|
+
locales: ["en", "de"],
|
|
152
|
+
},
|
|
153
|
+
}),
|
|
154
|
+
strategy: ["cookie"],
|
|
155
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
156
|
+
cookieSameSite: "lax",
|
|
157
|
+
cookieSecure: "auto",
|
|
158
|
+
});
|
|
159
|
+
globalThis.document.cookie = "PARAGLIDE_LOCALE=en";
|
|
160
|
+
runtime.setLocale("de");
|
|
161
|
+
expect(globalThis.document.cookie).toBe("PARAGLIDE_LOCALE=de; path=/; max-age=34560000; samesite=lax; secure");
|
|
162
|
+
globalThis.window.location.protocol = "http:";
|
|
163
|
+
runtime.setLocale("en");
|
|
164
|
+
expect(globalThis.document.cookie).toBe("PARAGLIDE_LOCALE=en; path=/; max-age=34560000; samesite=lax");
|
|
165
|
+
});
|
|
81
166
|
test("url pattern strategy sets the window location", async () => {
|
|
82
167
|
// @ts-expect-error - global variable definition
|
|
83
168
|
globalThis.window = {};
|
|
@@ -628,4 +713,101 @@ test("custom strategy setLocale integrates with URL strategy", async () => {
|
|
|
628
713
|
expect(globalThis.window.location.href).toBe("https://example.com/de/page");
|
|
629
714
|
expect(customStoredLocale).toBe("de");
|
|
630
715
|
});
|
|
716
|
+
// sandboxed iframes without allow-same-origin have an opaque origin and throw
|
|
717
|
+
// a SecurityError on document.cookie and localStorage access
|
|
718
|
+
test("navigates to the localized url when document.cookie throws", async () => {
|
|
719
|
+
const runtime = await createParaglide({
|
|
720
|
+
blob: await newProject({
|
|
721
|
+
settings: {
|
|
722
|
+
baseLocale: "en",
|
|
723
|
+
locales: ["en", "de"],
|
|
724
|
+
},
|
|
725
|
+
}),
|
|
726
|
+
strategy: ["url", "cookie", "baseLocale"],
|
|
727
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
728
|
+
isServer: "false",
|
|
729
|
+
urlPatterns: [
|
|
730
|
+
{
|
|
731
|
+
pattern: "https://example.com/:path*",
|
|
732
|
+
localized: [
|
|
733
|
+
["en", "https://example.com/en/:path*"],
|
|
734
|
+
["de", "https://example.com/de/:path*"],
|
|
735
|
+
],
|
|
736
|
+
},
|
|
737
|
+
],
|
|
738
|
+
});
|
|
739
|
+
/** @ts-expect-error - client side api */
|
|
740
|
+
globalThis.document = {
|
|
741
|
+
get cookie() {
|
|
742
|
+
throw new DOMException("The operation is insecure.", "SecurityError");
|
|
743
|
+
},
|
|
744
|
+
set cookie(_value) {
|
|
745
|
+
throw new DOMException("The operation is insecure.", "SecurityError");
|
|
746
|
+
},
|
|
747
|
+
};
|
|
748
|
+
globalThis.window = {
|
|
749
|
+
location: new URL("https://example.com/en/some-path"),
|
|
750
|
+
};
|
|
751
|
+
runtime.setLocale("de");
|
|
752
|
+
expect(globalThis.window.location.href).toBe("https://example.com/de/some-path");
|
|
753
|
+
});
|
|
754
|
+
test("reloads when document.cookie throws", async () => {
|
|
755
|
+
const runtime = await createParaglide({
|
|
756
|
+
blob: await newProject({
|
|
757
|
+
settings: {
|
|
758
|
+
baseLocale: "en",
|
|
759
|
+
locales: ["en", "de"],
|
|
760
|
+
},
|
|
761
|
+
}),
|
|
762
|
+
strategy: ["cookie", "baseLocale"],
|
|
763
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
764
|
+
isServer: "false",
|
|
765
|
+
});
|
|
766
|
+
/** @ts-expect-error - client side api */
|
|
767
|
+
globalThis.document = {
|
|
768
|
+
get cookie() {
|
|
769
|
+
throw new DOMException("The operation is insecure.", "SecurityError");
|
|
770
|
+
},
|
|
771
|
+
set cookie(_value) {
|
|
772
|
+
throw new DOMException("The operation is insecure.", "SecurityError");
|
|
773
|
+
},
|
|
774
|
+
};
|
|
775
|
+
globalThis.window = {
|
|
776
|
+
location: {
|
|
777
|
+
href: "https://example.com/page",
|
|
778
|
+
reload: vi.fn(),
|
|
779
|
+
},
|
|
780
|
+
};
|
|
781
|
+
runtime.setLocale("de");
|
|
782
|
+
expect(globalThis.window.location.reload).toBeCalled();
|
|
783
|
+
});
|
|
784
|
+
test("reloads when localStorage throws", async () => {
|
|
785
|
+
const runtime = await createParaglide({
|
|
786
|
+
blob: await newProject({
|
|
787
|
+
settings: {
|
|
788
|
+
baseLocale: "en",
|
|
789
|
+
locales: ["en", "de"],
|
|
790
|
+
},
|
|
791
|
+
}),
|
|
792
|
+
strategy: ["localStorage", "baseLocale"],
|
|
793
|
+
isServer: "false",
|
|
794
|
+
});
|
|
795
|
+
// @ts-expect-error - global variable definition
|
|
796
|
+
globalThis.localStorage = {
|
|
797
|
+
getItem: () => {
|
|
798
|
+
throw new DOMException("The operation is insecure.", "SecurityError");
|
|
799
|
+
},
|
|
800
|
+
setItem: () => {
|
|
801
|
+
throw new DOMException("The operation is insecure.", "SecurityError");
|
|
802
|
+
},
|
|
803
|
+
};
|
|
804
|
+
globalThis.window = {
|
|
805
|
+
location: {
|
|
806
|
+
href: "https://example.com/page",
|
|
807
|
+
reload: vi.fn(),
|
|
808
|
+
},
|
|
809
|
+
};
|
|
810
|
+
runtime.setLocale("de");
|
|
811
|
+
expect(globalThis.window.location.reload).toBeCalled();
|
|
812
|
+
});
|
|
631
813
|
//# sourceMappingURL=set-locale.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-locale.test.js","sourceRoot":"","sources":["../../../src/compiler/runtime/set-locale.test.ts"],"names":[],"mappings":"AAAA,OAAO,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GAAG,MAAM,eAAe,CAAC;QACrC,IAAI,EAAE,MAAM,UAAU,CAAC;YACtB,QAAQ,EAAE;gBACT,UAAU,EAAE,IAAI;gBAChB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;aAC3B;SACD,CAAC;QACF,QAAQ,EAAE,CAAC,KAAK,EAAE,uBAAuB,EAAE,YAAY,CAAC;QACxD,WAAW,EAAE;YACZ;gBACC,OAAO,EAAE,oCAAoC;gBAC7C,SAAS,EAAE;oBACV,CAAC,IAAI,EAAE,+BAA+B,CAAC;oBACvC,CAAC,IAAI,EAAE,+BAA+B,CAAC;oBACvC,CAAC,IAAI,EAAE,+BAA+B,CAAC;iBACvC;aACD;SACD;QACD,QAAQ,EAAE,OAAO;KACjB,CAAC,CAAC;IAEH,OAAO,CAAC,0BAA0B,CAAC,uBAAuB,EAAE;QAC3D,SAAS,EAAE,GAAG,EAAE,CAAC,kBAAkB;QACnC,SAAS,EAAE,CAAC,MAAM,EAAE,EAAE;YACrB,kBAAkB,GAAG,MAAM,CAAC;QAC7B,CAAC;KACD,CAAC,CAAC;IAEH,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAExB,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;IAC5E,MAAM,CAAC,kBAAkB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACvC,CAAC,CAAC,CAAC","sourcesContent":["import { newProject } from \"@inlang/sdk\";\nimport { expect, test, vi } from \"vitest\";\nimport { createParaglide } from \"../create-paraglide.js\";\n\ntest(\"sets the cookie to a different locale\", async () => {\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window.location = { hostname: \"example.com\" };\n\tglobalThis.window.location.reload = vi.fn();\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t});\n\n\tglobalThis.document.cookie = \"PARAGLIDE_LOCALE=en\";\n\n\truntime.setLocale(\"de\");\n\n\t// set the locale\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=de; path=/; max-age=34560000\"\n\t);\n\t// reloads the site if window is available\n\texpect(globalThis.window.location.reload).toBeCalled();\n});\n\ntest(\"sets the cookie with explicit domain to a different locale navigating subdomain\", async () => {\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window.location = { hostname: \"web.example.com\" };\n\tglobalThis.window.location.reload = vi.fn();\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t\tcookieDomain: \"example.com\",\n\t});\n\n\tglobalThis.document.cookie = \"PARAGLIDE_LOCALE=en\";\n\n\truntime.setLocale(\"de\");\n\n\t// set the locale\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=de; path=/; max-age=34560000; domain=example.com\"\n\t);\n\t// reloads the site if window is available\n\texpect(globalThis.window.location.reload).toBeCalled();\n});\n\ntest(\"sets the cookie with explicit domain to a different locale navigating domain\", async () => {\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window.location = { hostname: \"example.com\" };\n\tglobalThis.window.location.reload = vi.fn();\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t\tcookieDomain: \"example.com\",\n\t});\n\n\tglobalThis.document.cookie = \"PARAGLIDE_LOCALE=en\";\n\n\truntime.setLocale(\"de\");\n\n\t// set the locale\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=de; path=/; max-age=34560000; domain=example.com\"\n\t);\n\t// reloads the site if window is available\n\texpect(globalThis.window.location.reload).toBeCalled();\n});\n\ntest(\"url pattern strategy sets the window location\", async () => {\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window.location = {};\n\tglobalThis.window.location.hostname = \"example.com\";\n\tglobalThis.window.location.reload = vi.fn();\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: { baseLocale: \"en\", locales: [\"en\", \"de\"] },\n\t\t}),\n\t\tstrategy: [\"url\"],\n\t\turlPatterns: [\n\t\t\t{\n\t\t\t\tpattern: \"https://example.:tld/:path*\",\n\t\t\t\tlocalized: [\n\t\t\t\t\t[\"en\", \"https://example.com/:path*\"],\n\t\t\t\t\t[\"de\", \"https://example.de/:path*\"],\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t});\n\n\tglobalThis.window.location.href = \"https://example.com/page\";\n\n\truntime.setLocale(\"de\");\n\n\texpect(globalThis.window.location.href).toBe(\"https://example.de/page\");\n\t// setting window.location.hostname automatically reloads the page\n\texpect(globalThis.window.location.reload).not.toBeCalled();\n});\n\ntest(\"url strategy setLocale normalizes mixed-case explicit locales\", async () => {\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window.location = {};\n\tglobalThis.window.location.hostname = \"example.com\";\n\tglobalThis.window.location.reload = vi.fn();\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: { baseLocale: \"en\", locales: [\"en\", \"de\"] },\n\t\t}),\n\t\tstrategy: [\"url\"],\n\t\turlPatterns: [\n\t\t\t{\n\t\t\t\tpattern: \"https://example.:tld/:path*\",\n\t\t\t\tlocalized: [\n\t\t\t\t\t[\"en\", \"https://example.com/:path*\"],\n\t\t\t\t\t[\"de\", \"https://example.de/:path*\"],\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t});\n\n\tglobalThis.window.location.href = \"https://example.com/page\";\n\n\truntime.setLocale(\"DE\" as any);\n\n\texpect(globalThis.window.location.href).toBe(\"https://example.de/page\");\n\t// setting window.location.hostname automatically reloads the page\n\texpect(globalThis.window.location.reload).not.toBeCalled();\n});\n\ntest(\"routeStrategies can disable url navigation on matching routes\", async () => {\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window.location = {\n\t\thref: \"https://example.com/dashboard\",\n\t\thostname: \"example.com\",\n\t\treload: vi.fn(),\n\t};\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: { baseLocale: \"en\", locales: [\"en\", \"fr\"] },\n\t\t}),\n\t\tstrategy: [\"url\", \"cookie\", \"baseLocale\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t\trouteStrategies: [\n\t\t\t{\n\t\t\t\tmatch: \"/dashboard/:path(.*)?\",\n\t\t\t\tstrategy: [\"cookie\", \"baseLocale\"],\n\t\t\t},\n\t\t],\n\t});\n\n\tglobalThis.document.cookie = \"PARAGLIDE_LOCALE=en\";\n\truntime.setLocale(\"fr\");\n\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=fr; path=/; max-age=34560000\"\n\t);\n\texpect(globalThis.window.location.href).toBe(\"https://example.com/dashboard\");\n\texpect(globalThis.window.location.reload).toBeCalled();\n});\n\n// `!document.cookie` was used which returned false for an empty string\ntest(\"sets the cookie when it's an empty string\", async () => {\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t});\n\n\t/** @ts-expect-error - client side api */\n\tglobalThis.document = { cookie: \"\" };\n\n\truntime.setLocale(\"en\");\n\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=en; path=/; max-age=34560000\"\n\t);\n});\n\ntest(\"when strategy precedes URL, it should set the locale and re-direct to the URL\", async () => {\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"cookie\", \"url\", \"baseLocale\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t\tisServer: \"false\",\n\t\turlPatterns: [\n\t\t\t{\n\t\t\t\tpattern: \"https://example.com/en/:path(.*)?\",\n\t\t\t\tlocalized: [\n\t\t\t\t\t[\"en\", \"https://example.com/en/:path(.*)?\"],\n\t\t\t\t\t[\"fr\", \"https://example.com/fr/:path(.*)?\"],\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t});\n\n\t/** @ts-expect-error - client side api */\n\tglobalThis.document = { cookie: \"PARAGLIDE_LOCALE=fr\" };\n\tglobalThis.window = {\n\t\tlocation: new URL(\"https://example.com/fr/some-path\"),\n\t} as any;\n\n\t// Cookie strategy should determine locale as French\n\texpect(runtime.getLocale()).toBe(\"fr\");\n\n\truntime.setLocale(\"en\");\n\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=en; path=/; max-age=34560000\"\n\t);\n\texpect(globalThis.window.location.href).toBe(\n\t\t\"https://example.com/en/some-path\"\n\t);\n});\n\ntest(\"overwriteSetLocale receives the options object\", async () => {\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t});\n\n\t// Provide minimal browser globals to avoid strategy branches failing.\n\t/** @ts-expect-error - browser shim for tests */\n\tglobalThis.document = { cookie: \"\" };\n\tglobalThis.window = {\n\t\tlocation: {\n\t\t\thref: \"https://example.com/en\",\n\t\t\treload: vi.fn(),\n\t\t},\n\t} as any;\n\n\tconst spy = vi.fn();\n\truntime.overwriteSetLocale(spy);\n\n\truntime.setLocale(\"fr\", { reload: false });\n\n\texpect(spy).toHaveBeenCalledWith(\"fr\", { reload: false });\n});\n\n// https://github.com/opral/inlang-paraglide-js/issues/430\ntest(\"should not reload when setting locale to current locale\", async () => {\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window.location = { hostname: \"example.com\" };\n\tglobalThis.window.location.reload = vi.fn();\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t});\n\n\tglobalThis.document.cookie = \"PARAGLIDE_LOCALE=en; path=/\";\n\n\t// Setting to the current locale (en)\n\truntime.setLocale(\"en\");\n\n\t// Cookie should remain unchanged\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=en; path=/; max-age=34560000\"\n\t);\n\t// Should not trigger a reload\n\texpect(globalThis.window.location.reload).not.toBeCalled();\n\n\t// Setting to a different locale should still work\n\truntime.setLocale(\"de\");\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=de; path=/; max-age=34560000\"\n\t);\n\texpect(globalThis.window.location.reload).toBeCalled();\n});\n\ntest(\"static locale builds force a document reload when switching locales\", async () => {\n\t// @ts-expect-error - browser shim for tests\n\tglobalThis.document = { cookie: \"\" };\n\tglobalThis.window = {\n\t\tlocation: {\n\t\t\thref: \"https://example.com/en\",\n\t\t\thostname: \"example.com\",\n\t\t\treload: vi.fn(),\n\t\t},\n\t} as any;\n\tconst warn = vi.spyOn(console, \"warn\").mockImplementation(() => undefined);\n\n\ttry {\n\t\tconst runtime = await createParaglide({\n\t\t\tblob: await newProject({\n\t\t\t\tsettings: {\n\t\t\t\t\tbaseLocale: \"en\",\n\t\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t\t},\n\t\t\t}),\n\t\t\tstrategy: [\"cookie\"],\n\t\t\tisServer: \"false\",\n\t\t\texperimentalStaticLocale: JSON.stringify(\"en\"),\n\t\t});\n\n\t\truntime.setLocale(\"de\", { reload: false });\n\n\t\texpect(warn).toHaveBeenCalledOnce();\n\t\texpect(globalThis.window.location.reload).toHaveBeenCalledOnce();\n\t} finally {\n\t\twarn.mockRestore();\n\t}\n});\n\ntest(\"sets the locale to localStorage\", async () => {\n\t// @ts-expect-error - global variable definition\n\tglobalThis.localStorage = {\n\t\tsetItem: vi.fn(),\n\t\tgetItem: () => \"en\",\n\t};\n\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"localStorage\"],\n\t});\n\n\truntime.setLocale(\"de\");\n\n\texpect(globalThis.localStorage.setItem).toHaveBeenCalledWith(\n\t\t\"PARAGLIDE_LOCALE\",\n\t\t\"de\"\n\t);\n});\n\n// Test that all strategies set their respective storage mechanisms\ntest(\"should set locale in all configured storage mechanisms regardless of which strategy resolved the locale\", async () => {\n\t// Setup global objects\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = { cookie: \"\" };\n\t// @ts-expect-error - global variable definition\n\tglobalThis.localStorage = {\n\t\tsetItem: vi.fn(),\n\t\tgetItem: () => null,\n\t};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window.location = {};\n\tglobalThis.window.location.hostname = \"example.com\";\n\tglobalThis.window.location.href = \"https://example.com/en/page\";\n\tglobalThis.window.location.reload = vi.fn();\n\n\t// Create runtime with multiple strategies\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"de\", \"fr\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"url\", \"localStorage\", \"cookie\", \"baseLocale\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t\turlPatterns: [\n\t\t\t{\n\t\t\t\tpattern: \"https://example.com/:locale/:path*\",\n\t\t\t\tlocalized: [\n\t\t\t\t\t[\"en\", \"https://example.com/en/:path*\"],\n\t\t\t\t\t[\"de\", \"https://example.com/de/:path*\"],\n\t\t\t\t\t[\"fr\", \"https://example.com/fr/:path*\"],\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t});\n\n\t// Call setLocale\n\truntime.setLocale(\"fr\");\n\n\t// Verify that all storage mechanisms are updated\n\texpect(globalThis.window.location.href).toBe(\"https://example.com/fr/page\");\n\texpect(globalThis.localStorage.setItem).toHaveBeenCalledWith(\n\t\t\"PARAGLIDE_LOCALE\",\n\t\t\"fr\"\n\t);\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=fr; path=/; max-age=34560000\"\n\t);\n});\n\ntest(\"calls setLocale on custom strategy\", async () => {\n\tlet customLocale = \"en\";\n\tlet setLocaleCalled = false;\n\n\tglobalThis.window = {\n\t\tlocation: { reload: vi.fn() },\n\t} as any;\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"custom-setter\", \"baseLocale\"],\n\t\tisServer: \"false\",\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-setter\", {\n\t\tgetLocale: () => customLocale,\n\t\tsetLocale: (locale) => {\n\t\t\tcustomLocale = locale;\n\t\t\tsetLocaleCalled = true;\n\t\t},\n\t});\n\n\truntime.setLocale(\"fr\");\n\n\texpect(setLocaleCalled).toBe(true);\n\texpect(customLocale).toBe(\"fr\");\n\texpect(globalThis.window.location.reload).toHaveBeenCalled();\n});\n\ntest(\"calls setLocale on multiple custom strategies\", async () => {\n\tlet customLocale1 = \"en\";\n\tlet customLocale2 = \"en\";\n\tlet setLocaleCalled1 = false;\n\tlet setLocaleCalled2 = false;\n\n\tglobalThis.window = {\n\t\tlocation: { reload: vi.fn() },\n\t} as any;\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"custom-multi1\", \"custom-multi2\", \"baseLocale\"],\n\t\tisServer: \"false\",\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-multi1\", {\n\t\tgetLocale: () => customLocale1,\n\t\tsetLocale: (locale) => {\n\t\t\tcustomLocale1 = locale;\n\t\t\tsetLocaleCalled1 = true;\n\t\t},\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-multi2\", {\n\t\tgetLocale: () => customLocale2,\n\t\tsetLocale: (locale) => {\n\t\t\tcustomLocale2 = locale;\n\t\t\tsetLocaleCalled2 = true;\n\t\t},\n\t});\n\n\truntime.setLocale(\"de\");\n\n\texpect(setLocaleCalled1).toBe(true);\n\texpect(setLocaleCalled2).toBe(true);\n\texpect(customLocale1).toBe(\"de\");\n\texpect(customLocale2).toBe(\"de\");\n});\n\ntest(\"setLocale should return a promise if any custom setLocale function is async\", async () => {\n\tlet customLocale1 = \"en\";\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"custom-async\", \"baseLocale\"],\n\t\tisServer: \"false\",\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-async\", {\n\t\tgetLocale: () => customLocale1,\n\t\tsetLocale: async (locale) => {\n\t\t\tcustomLocale1 = locale;\n\t\t},\n\t});\n\n\tconst setLocalePromise = runtime.setLocale(\"de\");\n\tconst setLocalePromiseWithoutReload = runtime.setLocale(\"de\", {\n\t\treload: false,\n\t});\n\n\texpect(setLocalePromise).toBeInstanceOf(Promise);\n\texpect(setLocalePromiseWithoutReload).toBeInstanceOf(Promise);\n});\n\ntest(\"awaits async setLocale functions to resolve in custom strategy\", async () => {\n\tlet customLocale1 = \"en\";\n\n\tglobalThis.window = {\n\t\tlocation: {\n\t\t\treload: vi.fn(),\n\t\t},\n\t} as any;\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"custom-async\", \"baseLocale\"],\n\t\tisServer: \"false\",\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-async\", {\n\t\tgetLocale: () => customLocale1,\n\t\tsetLocale: async (locale) => {\n\t\t\tcustomLocale1 = locale;\n\t\t},\n\t});\n\n\tconst setLocalePromise = runtime.setLocale(\"de\");\n\texpect(window.location.reload).not.toHaveBeenCalled();\n\n\tawait setLocalePromise;\n\n\t// Verify that setLocale resolved before reload was called\n\texpect(window.location.reload).toHaveBeenCalledTimes(1);\n\texpect(customLocale1).toBe(\"de\");\n});\n\ntest(\"awaits async setLocale functions to resolve in multiple custom strategies\", async () => {\n\tlet customLocale1 = \"en\";\n\tlet customLocale2 = \"en\";\n\n\tglobalThis.window = {\n\t\tlocation: {\n\t\t\treload: vi.fn(),\n\t\t},\n\t} as any;\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"custom-async1\", \"custom-async2\", \"baseLocale\"],\n\t\tisServer: \"false\",\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-async1\", {\n\t\tgetLocale: () => customLocale1,\n\t\tsetLocale: async (locale) => {\n\t\t\tcustomLocale1 = locale;\n\t\t},\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-async2\", {\n\t\tgetLocale: () => customLocale2,\n\t\tsetLocale: async (locale) => {\n\t\t\tcustomLocale2 = locale;\n\t\t},\n\t});\n\n\tconst setLocalePromise = runtime.setLocale(\"de\");\n\texpect(window.location.reload).not.toHaveBeenCalled();\n\n\tawait setLocalePromise;\n\n\t// Verify that setLocale resolved before reload was called\n\texpect(window.location.reload).toHaveBeenCalledTimes(1);\n\texpect(customLocale1).toBe(\"de\");\n\texpect(customLocale2).toBe(\"de\");\n});\n\ntest(\"reload should not run if async setLocale function rejects in custom strategy\", async () => {\n\tconst customLocale1 = \"en\";\n\n\tglobalThis.window = {\n\t\tlocation: {\n\t\t\treload: vi.fn(),\n\t\t},\n\t} as any;\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"custom-async\", \"baseLocale\"],\n\t\tisServer: \"false\",\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-async\", {\n\t\tgetLocale: () => customLocale1,\n\t\tsetLocale: async () => {\n\t\t\tthrow new Error(\"fetch error\");\n\t\t},\n\t});\n\n\tconst error = expect(() => runtime.setLocale(\"de\")).rejects;\n\tawait error.toThrowError(`Custom strategy \"custom-async\" setLocale failed.`);\n\tawait error.toMatchObject({ cause: { message: \"fetch error\" } });\n\n\t// Verify that reload was never called\n\texpect(window.location.reload).toHaveBeenCalledTimes(0);\n\texpect(customLocale1).toBe(\"en\");\n});\n\ntest(\"custom strategy setLocale works with cookie and localStorage\", async () => {\n\tlet customData = \"en\";\n\n\tglobalThis.document = { cookie: \"\" } as any;\n\tglobalThis.localStorage = {\n\t\tsetItem: vi.fn(),\n\t\tgetItem: () => null,\n\t} as any;\n\tglobalThis.window = {\n\t\tlocation: {\n\t\t\thostname: \"example.com\",\n\t\t\treload: vi.fn(),\n\t\t},\n\t} as any;\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"custom-api\", \"localStorage\", \"cookie\", \"baseLocale\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t\tisServer: \"false\",\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-api\", {\n\t\tgetLocale: () => customData,\n\t\tsetLocale: (locale) => {\n\t\t\tcustomData = locale;\n\t\t},\n\t});\n\n\truntime.setLocale(\"fr\");\n\n\texpect(customData).toBe(\"fr\");\n\texpect(globalThis.localStorage.setItem).toHaveBeenCalledWith(\n\t\t\"PARAGLIDE_LOCALE\",\n\t\t\"fr\"\n\t);\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=fr; path=/; max-age=34560000\"\n\t);\n});\n\ntest(\"custom strategy setLocale integrates with URL strategy\", async () => {\n\tlet customStoredLocale = \"en\";\n\n\tglobalThis.window = {\n\t\tlocation: {\n\t\t\thostname: \"example.com\",\n\t\t\thref: \"https://example.com/en/page\",\n\t\t\treload: vi.fn(),\n\t\t},\n\t} as any;\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"url\", \"custom-urlIntegration\", \"baseLocale\"],\n\t\turlPatterns: [\n\t\t\t{\n\t\t\t\tpattern: \"https://example.com/:locale/:path*\",\n\t\t\t\tlocalized: [\n\t\t\t\t\t[\"en\", \"https://example.com/en/:path*\"],\n\t\t\t\t\t[\"fr\", \"https://example.com/fr/:path*\"],\n\t\t\t\t\t[\"de\", \"https://example.com/de/:path*\"],\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t\tisServer: \"false\",\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-urlIntegration\", {\n\t\tgetLocale: () => customStoredLocale,\n\t\tsetLocale: (locale) => {\n\t\t\tcustomStoredLocale = locale;\n\t\t},\n\t});\n\n\truntime.setLocale(\"de\");\n\n\texpect(globalThis.window.location.href).toBe(\"https://example.com/de/page\");\n\texpect(customStoredLocale).toBe(\"de\");\n});\n"]}
|
|
1
|
+
{"version":3,"file":"set-locale.test.js","sourceRoot":"","sources":["../../../src/compiler/runtime/set-locale.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,IAA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,CAAC;aACrB;SACD,CAAC;QACF,QAAQ,EAAE,CAAC,cAAc,EAAE,YAAY,CAAC;QACxC,QAAQ,EAAE,OAAO;KACjB,CAAC,CAAC;IAEH,gDAAgD;IAChD,UAAU,CAAC,YAAY,GAAG;QACzB,OAAO,EAAE,GAAG,EAAE;YACb,MAAM,IAAI,YAAY,CAAC,4BAA4B,EAAE,eAAe,CAAC,CAAC;QACvE,CAAC;QACD,OAAO,EAAE,GAAG,EAAE;YACb,MAAM,IAAI,YAAY,CAAC,4BAA4B,EAAE,eAAe,CAAC,CAAC;QACvE,CAAC;KACD,CAAC;IACF,UAAU,CAAC,MAAM,GAAG;QACnB,QAAQ,EAAE;YACT,IAAI,EAAE,0BAA0B;YAChC,MAAM,EAAE,EAAE,CAAC,EAAE,EAAE;SACf;KACM,CAAC;IAET,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;IAExB,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,UAAU,EAAE,CAAC;AACxD,CAAC,CAAC,CAAC","sourcesContent":["import { newProject } from \"@inlang/sdk\";\nimport { expect, test, vi } from \"vitest\";\nimport { createParaglide } from \"../create-paraglide.js\";\n\ntest(\"sets the cookie to a different locale\", async () => {\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window.location = { hostname: \"example.com\" };\n\tglobalThis.window.location.reload = vi.fn();\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t});\n\n\tglobalThis.document.cookie = \"PARAGLIDE_LOCALE=en\";\n\n\truntime.setLocale(\"de\");\n\n\t// set the locale\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=de; path=/; max-age=34560000\"\n\t);\n\t// reloads the site if window is available\n\texpect(globalThis.window.location.reload).toBeCalled();\n});\n\ntest(\"sets the cookie with explicit domain to a different locale navigating subdomain\", async () => {\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window.location = { hostname: \"web.example.com\" };\n\tglobalThis.window.location.reload = vi.fn();\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t\tcookieDomain: \"example.com\",\n\t});\n\n\tglobalThis.document.cookie = \"PARAGLIDE_LOCALE=en\";\n\n\truntime.setLocale(\"de\");\n\n\t// set the locale\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=de; path=/; max-age=34560000; domain=example.com\"\n\t);\n\t// reloads the site if window is available\n\texpect(globalThis.window.location.reload).toBeCalled();\n});\n\ntest(\"sets the cookie with explicit domain to a different locale navigating domain\", async () => {\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window.location = { hostname: \"example.com\" };\n\tglobalThis.window.location.reload = vi.fn();\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t\tcookieDomain: \"example.com\",\n\t});\n\n\tglobalThis.document.cookie = \"PARAGLIDE_LOCALE=en\";\n\n\truntime.setLocale(\"de\");\n\n\t// set the locale\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=de; path=/; max-age=34560000; domain=example.com\"\n\t);\n\t// reloads the site if window is available\n\texpect(globalThis.window.location.reload).toBeCalled();\n});\n\ntest(\"sets the cookie with samesite and secure attributes\", async () => {\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window.location = { hostname: \"example.com\" };\n\tglobalThis.window.location.reload = vi.fn();\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t\tcookieDomain: \"example.com\",\n\t\tcookieSameSite: \"strict\",\n\t\tcookieSecure: true,\n\t});\n\n\tglobalThis.document.cookie = \"PARAGLIDE_LOCALE=en\";\n\n\truntime.setLocale(\"de\");\n\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=de; path=/; max-age=34560000; domain=example.com; samesite=strict; secure\"\n\t);\n\t// exported so server code can write the cookie with the same attributes\n\texpect(runtime.cookieSameSite).toBe(\"strict\");\n\texpect(runtime.cookieSecure).toBe(true);\n});\n\ntest.each([true, \"auto\"] as const)(\n\t\"sets samesite=none with secure on https pages (cookieSecure: %s)\",\n\tasync (cookieSecure) => {\n\t\t// @ts-expect-error - global variable definition\n\t\tglobalThis.document = {};\n\t\t// @ts-expect-error - global variable definition\n\t\tglobalThis.window = {};\n\t\t// @ts-expect-error - global variable definition\n\t\tglobalThis.window.location = {\n\t\t\thostname: \"example.com\",\n\t\t\tprotocol: \"https:\",\n\t\t};\n\t\tglobalThis.window.location.reload = vi.fn();\n\n\t\tconst runtime = await createParaglide({\n\t\t\tblob: await newProject({\n\t\t\t\tsettings: {\n\t\t\t\t\tbaseLocale: \"en\",\n\t\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t\t},\n\t\t\t}),\n\t\t\tstrategy: [\"cookie\"],\n\t\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t\t\tcookieSameSite: \"none\",\n\t\t\tcookieSecure,\n\t\t});\n\n\t\tglobalThis.document.cookie = \"PARAGLIDE_LOCALE=en\";\n\n\t\truntime.setLocale(\"de\");\n\n\t\texpect(globalThis.document.cookie).toBe(\n\t\t\t\"PARAGLIDE_LOCALE=de; path=/; max-age=34560000; samesite=none; secure\"\n\t\t);\n\t}\n);\n\ntest(\"cookieSecure 'auto' only sets the secure attribute on https pages\", async () => {\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window.location = {\n\t\thostname: \"example.com\",\n\t\tprotocol: \"https:\",\n\t};\n\tglobalThis.window.location.reload = vi.fn();\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t\tcookieSameSite: \"lax\",\n\t\tcookieSecure: \"auto\",\n\t});\n\n\tglobalThis.document.cookie = \"PARAGLIDE_LOCALE=en\";\n\n\truntime.setLocale(\"de\");\n\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=de; path=/; max-age=34560000; samesite=lax; secure\"\n\t);\n\n\tglobalThis.window.location.protocol = \"http:\";\n\n\truntime.setLocale(\"en\");\n\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=en; path=/; max-age=34560000; samesite=lax\"\n\t);\n});\n\ntest(\"url pattern strategy sets the window location\", async () => {\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window.location = {};\n\tglobalThis.window.location.hostname = \"example.com\";\n\tglobalThis.window.location.reload = vi.fn();\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: { baseLocale: \"en\", locales: [\"en\", \"de\"] },\n\t\t}),\n\t\tstrategy: [\"url\"],\n\t\turlPatterns: [\n\t\t\t{\n\t\t\t\tpattern: \"https://example.:tld/:path*\",\n\t\t\t\tlocalized: [\n\t\t\t\t\t[\"en\", \"https://example.com/:path*\"],\n\t\t\t\t\t[\"de\", \"https://example.de/:path*\"],\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t});\n\n\tglobalThis.window.location.href = \"https://example.com/page\";\n\n\truntime.setLocale(\"de\");\n\n\texpect(globalThis.window.location.href).toBe(\"https://example.de/page\");\n\t// setting window.location.hostname automatically reloads the page\n\texpect(globalThis.window.location.reload).not.toBeCalled();\n});\n\ntest(\"url strategy setLocale normalizes mixed-case explicit locales\", async () => {\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window.location = {};\n\tglobalThis.window.location.hostname = \"example.com\";\n\tglobalThis.window.location.reload = vi.fn();\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: { baseLocale: \"en\", locales: [\"en\", \"de\"] },\n\t\t}),\n\t\tstrategy: [\"url\"],\n\t\turlPatterns: [\n\t\t\t{\n\t\t\t\tpattern: \"https://example.:tld/:path*\",\n\t\t\t\tlocalized: [\n\t\t\t\t\t[\"en\", \"https://example.com/:path*\"],\n\t\t\t\t\t[\"de\", \"https://example.de/:path*\"],\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t});\n\n\tglobalThis.window.location.href = \"https://example.com/page\";\n\n\truntime.setLocale(\"DE\" as any);\n\n\texpect(globalThis.window.location.href).toBe(\"https://example.de/page\");\n\t// setting window.location.hostname automatically reloads the page\n\texpect(globalThis.window.location.reload).not.toBeCalled();\n});\n\ntest(\"routeStrategies can disable url navigation on matching routes\", async () => {\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window.location = {\n\t\thref: \"https://example.com/dashboard\",\n\t\thostname: \"example.com\",\n\t\treload: vi.fn(),\n\t};\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: { baseLocale: \"en\", locales: [\"en\", \"fr\"] },\n\t\t}),\n\t\tstrategy: [\"url\", \"cookie\", \"baseLocale\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t\trouteStrategies: [\n\t\t\t{\n\t\t\t\tmatch: \"/dashboard/:path(.*)?\",\n\t\t\t\tstrategy: [\"cookie\", \"baseLocale\"],\n\t\t\t},\n\t\t],\n\t});\n\n\tglobalThis.document.cookie = \"PARAGLIDE_LOCALE=en\";\n\truntime.setLocale(\"fr\");\n\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=fr; path=/; max-age=34560000\"\n\t);\n\texpect(globalThis.window.location.href).toBe(\"https://example.com/dashboard\");\n\texpect(globalThis.window.location.reload).toBeCalled();\n});\n\n// `!document.cookie` was used which returned false for an empty string\ntest(\"sets the cookie when it's an empty string\", async () => {\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t});\n\n\t/** @ts-expect-error - client side api */\n\tglobalThis.document = { cookie: \"\" };\n\n\truntime.setLocale(\"en\");\n\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=en; path=/; max-age=34560000\"\n\t);\n});\n\ntest(\"when strategy precedes URL, it should set the locale and re-direct to the URL\", async () => {\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"cookie\", \"url\", \"baseLocale\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t\tisServer: \"false\",\n\t\turlPatterns: [\n\t\t\t{\n\t\t\t\tpattern: \"https://example.com/en/:path(.*)?\",\n\t\t\t\tlocalized: [\n\t\t\t\t\t[\"en\", \"https://example.com/en/:path(.*)?\"],\n\t\t\t\t\t[\"fr\", \"https://example.com/fr/:path(.*)?\"],\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t});\n\n\t/** @ts-expect-error - client side api */\n\tglobalThis.document = { cookie: \"PARAGLIDE_LOCALE=fr\" };\n\tglobalThis.window = {\n\t\tlocation: new URL(\"https://example.com/fr/some-path\"),\n\t} as any;\n\n\t// Cookie strategy should determine locale as French\n\texpect(runtime.getLocale()).toBe(\"fr\");\n\n\truntime.setLocale(\"en\");\n\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=en; path=/; max-age=34560000\"\n\t);\n\texpect(globalThis.window.location.href).toBe(\n\t\t\"https://example.com/en/some-path\"\n\t);\n});\n\ntest(\"overwriteSetLocale receives the options object\", async () => {\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t});\n\n\t// Provide minimal browser globals to avoid strategy branches failing.\n\t/** @ts-expect-error - browser shim for tests */\n\tglobalThis.document = { cookie: \"\" };\n\tglobalThis.window = {\n\t\tlocation: {\n\t\t\thref: \"https://example.com/en\",\n\t\t\treload: vi.fn(),\n\t\t},\n\t} as any;\n\n\tconst spy = vi.fn();\n\truntime.overwriteSetLocale(spy);\n\n\truntime.setLocale(\"fr\", { reload: false });\n\n\texpect(spy).toHaveBeenCalledWith(\"fr\", { reload: false });\n});\n\n// https://github.com/opral/inlang-paraglide-js/issues/430\ntest(\"should not reload when setting locale to current locale\", async () => {\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window.location = { hostname: \"example.com\" };\n\tglobalThis.window.location.reload = vi.fn();\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t});\n\n\tglobalThis.document.cookie = \"PARAGLIDE_LOCALE=en; path=/\";\n\n\t// Setting to the current locale (en)\n\truntime.setLocale(\"en\");\n\n\t// Cookie should remain unchanged\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=en; path=/; max-age=34560000\"\n\t);\n\t// Should not trigger a reload\n\texpect(globalThis.window.location.reload).not.toBeCalled();\n\n\t// Setting to a different locale should still work\n\truntime.setLocale(\"de\");\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=de; path=/; max-age=34560000\"\n\t);\n\texpect(globalThis.window.location.reload).toBeCalled();\n});\n\ntest(\"static locale builds force a document reload when switching locales\", async () => {\n\t// @ts-expect-error - browser shim for tests\n\tglobalThis.document = { cookie: \"\" };\n\tglobalThis.window = {\n\t\tlocation: {\n\t\t\thref: \"https://example.com/en\",\n\t\t\thostname: \"example.com\",\n\t\t\treload: vi.fn(),\n\t\t},\n\t} as any;\n\tconst warn = vi.spyOn(console, \"warn\").mockImplementation(() => undefined);\n\n\ttry {\n\t\tconst runtime = await createParaglide({\n\t\t\tblob: await newProject({\n\t\t\t\tsettings: {\n\t\t\t\t\tbaseLocale: \"en\",\n\t\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t\t},\n\t\t\t}),\n\t\t\tstrategy: [\"cookie\"],\n\t\t\tisServer: \"false\",\n\t\t\texperimentalStaticLocale: JSON.stringify(\"en\"),\n\t\t});\n\n\t\truntime.setLocale(\"de\", { reload: false });\n\n\t\texpect(warn).toHaveBeenCalledOnce();\n\t\texpect(globalThis.window.location.reload).toHaveBeenCalledOnce();\n\t} finally {\n\t\twarn.mockRestore();\n\t}\n});\n\ntest(\"sets the locale to localStorage\", async () => {\n\t// @ts-expect-error - global variable definition\n\tglobalThis.localStorage = {\n\t\tsetItem: vi.fn(),\n\t\tgetItem: () => \"en\",\n\t};\n\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"localStorage\"],\n\t});\n\n\truntime.setLocale(\"de\");\n\n\texpect(globalThis.localStorage.setItem).toHaveBeenCalledWith(\n\t\t\"PARAGLIDE_LOCALE\",\n\t\t\"de\"\n\t);\n});\n\n// Test that all strategies set their respective storage mechanisms\ntest(\"should set locale in all configured storage mechanisms regardless of which strategy resolved the locale\", async () => {\n\t// Setup global objects\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = { cookie: \"\" };\n\t// @ts-expect-error - global variable definition\n\tglobalThis.localStorage = {\n\t\tsetItem: vi.fn(),\n\t\tgetItem: () => null,\n\t};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window = {};\n\t// @ts-expect-error - global variable definition\n\tglobalThis.window.location = {};\n\tglobalThis.window.location.hostname = \"example.com\";\n\tglobalThis.window.location.href = \"https://example.com/en/page\";\n\tglobalThis.window.location.reload = vi.fn();\n\n\t// Create runtime with multiple strategies\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"de\", \"fr\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"url\", \"localStorage\", \"cookie\", \"baseLocale\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t\turlPatterns: [\n\t\t\t{\n\t\t\t\tpattern: \"https://example.com/:locale/:path*\",\n\t\t\t\tlocalized: [\n\t\t\t\t\t[\"en\", \"https://example.com/en/:path*\"],\n\t\t\t\t\t[\"de\", \"https://example.com/de/:path*\"],\n\t\t\t\t\t[\"fr\", \"https://example.com/fr/:path*\"],\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t});\n\n\t// Call setLocale\n\truntime.setLocale(\"fr\");\n\n\t// Verify that all storage mechanisms are updated\n\texpect(globalThis.window.location.href).toBe(\"https://example.com/fr/page\");\n\texpect(globalThis.localStorage.setItem).toHaveBeenCalledWith(\n\t\t\"PARAGLIDE_LOCALE\",\n\t\t\"fr\"\n\t);\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=fr; path=/; max-age=34560000\"\n\t);\n});\n\ntest(\"calls setLocale on custom strategy\", async () => {\n\tlet customLocale = \"en\";\n\tlet setLocaleCalled = false;\n\n\tglobalThis.window = {\n\t\tlocation: { reload: vi.fn() },\n\t} as any;\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"custom-setter\", \"baseLocale\"],\n\t\tisServer: \"false\",\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-setter\", {\n\t\tgetLocale: () => customLocale,\n\t\tsetLocale: (locale) => {\n\t\t\tcustomLocale = locale;\n\t\t\tsetLocaleCalled = true;\n\t\t},\n\t});\n\n\truntime.setLocale(\"fr\");\n\n\texpect(setLocaleCalled).toBe(true);\n\texpect(customLocale).toBe(\"fr\");\n\texpect(globalThis.window.location.reload).toHaveBeenCalled();\n});\n\ntest(\"calls setLocale on multiple custom strategies\", async () => {\n\tlet customLocale1 = \"en\";\n\tlet customLocale2 = \"en\";\n\tlet setLocaleCalled1 = false;\n\tlet setLocaleCalled2 = false;\n\n\tglobalThis.window = {\n\t\tlocation: { reload: vi.fn() },\n\t} as any;\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"custom-multi1\", \"custom-multi2\", \"baseLocale\"],\n\t\tisServer: \"false\",\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-multi1\", {\n\t\tgetLocale: () => customLocale1,\n\t\tsetLocale: (locale) => {\n\t\t\tcustomLocale1 = locale;\n\t\t\tsetLocaleCalled1 = true;\n\t\t},\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-multi2\", {\n\t\tgetLocale: () => customLocale2,\n\t\tsetLocale: (locale) => {\n\t\t\tcustomLocale2 = locale;\n\t\t\tsetLocaleCalled2 = true;\n\t\t},\n\t});\n\n\truntime.setLocale(\"de\");\n\n\texpect(setLocaleCalled1).toBe(true);\n\texpect(setLocaleCalled2).toBe(true);\n\texpect(customLocale1).toBe(\"de\");\n\texpect(customLocale2).toBe(\"de\");\n});\n\ntest(\"setLocale should return a promise if any custom setLocale function is async\", async () => {\n\tlet customLocale1 = \"en\";\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"custom-async\", \"baseLocale\"],\n\t\tisServer: \"false\",\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-async\", {\n\t\tgetLocale: () => customLocale1,\n\t\tsetLocale: async (locale) => {\n\t\t\tcustomLocale1 = locale;\n\t\t},\n\t});\n\n\tconst setLocalePromise = runtime.setLocale(\"de\");\n\tconst setLocalePromiseWithoutReload = runtime.setLocale(\"de\", {\n\t\treload: false,\n\t});\n\n\texpect(setLocalePromise).toBeInstanceOf(Promise);\n\texpect(setLocalePromiseWithoutReload).toBeInstanceOf(Promise);\n});\n\ntest(\"awaits async setLocale functions to resolve in custom strategy\", async () => {\n\tlet customLocale1 = \"en\";\n\n\tglobalThis.window = {\n\t\tlocation: {\n\t\t\treload: vi.fn(),\n\t\t},\n\t} as any;\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"custom-async\", \"baseLocale\"],\n\t\tisServer: \"false\",\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-async\", {\n\t\tgetLocale: () => customLocale1,\n\t\tsetLocale: async (locale) => {\n\t\t\tcustomLocale1 = locale;\n\t\t},\n\t});\n\n\tconst setLocalePromise = runtime.setLocale(\"de\");\n\texpect(window.location.reload).not.toHaveBeenCalled();\n\n\tawait setLocalePromise;\n\n\t// Verify that setLocale resolved before reload was called\n\texpect(window.location.reload).toHaveBeenCalledTimes(1);\n\texpect(customLocale1).toBe(\"de\");\n});\n\ntest(\"awaits async setLocale functions to resolve in multiple custom strategies\", async () => {\n\tlet customLocale1 = \"en\";\n\tlet customLocale2 = \"en\";\n\n\tglobalThis.window = {\n\t\tlocation: {\n\t\t\treload: vi.fn(),\n\t\t},\n\t} as any;\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"custom-async1\", \"custom-async2\", \"baseLocale\"],\n\t\tisServer: \"false\",\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-async1\", {\n\t\tgetLocale: () => customLocale1,\n\t\tsetLocale: async (locale) => {\n\t\t\tcustomLocale1 = locale;\n\t\t},\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-async2\", {\n\t\tgetLocale: () => customLocale2,\n\t\tsetLocale: async (locale) => {\n\t\t\tcustomLocale2 = locale;\n\t\t},\n\t});\n\n\tconst setLocalePromise = runtime.setLocale(\"de\");\n\texpect(window.location.reload).not.toHaveBeenCalled();\n\n\tawait setLocalePromise;\n\n\t// Verify that setLocale resolved before reload was called\n\texpect(window.location.reload).toHaveBeenCalledTimes(1);\n\texpect(customLocale1).toBe(\"de\");\n\texpect(customLocale2).toBe(\"de\");\n});\n\ntest(\"reload should not run if async setLocale function rejects in custom strategy\", async () => {\n\tconst customLocale1 = \"en\";\n\n\tglobalThis.window = {\n\t\tlocation: {\n\t\t\treload: vi.fn(),\n\t\t},\n\t} as any;\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"custom-async\", \"baseLocale\"],\n\t\tisServer: \"false\",\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-async\", {\n\t\tgetLocale: () => customLocale1,\n\t\tsetLocale: async () => {\n\t\t\tthrow new Error(\"fetch error\");\n\t\t},\n\t});\n\n\tconst error = expect(() => runtime.setLocale(\"de\")).rejects;\n\tawait error.toThrowError(`Custom strategy \"custom-async\" setLocale failed.`);\n\tawait error.toMatchObject({ cause: { message: \"fetch error\" } });\n\n\t// Verify that reload was never called\n\texpect(window.location.reload).toHaveBeenCalledTimes(0);\n\texpect(customLocale1).toBe(\"en\");\n});\n\ntest(\"custom strategy setLocale works with cookie and localStorage\", async () => {\n\tlet customData = \"en\";\n\n\tglobalThis.document = { cookie: \"\" } as any;\n\tglobalThis.localStorage = {\n\t\tsetItem: vi.fn(),\n\t\tgetItem: () => null,\n\t} as any;\n\tglobalThis.window = {\n\t\tlocation: {\n\t\t\thostname: \"example.com\",\n\t\t\treload: vi.fn(),\n\t\t},\n\t} as any;\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"custom-api\", \"localStorage\", \"cookie\", \"baseLocale\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t\tisServer: \"false\",\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-api\", {\n\t\tgetLocale: () => customData,\n\t\tsetLocale: (locale) => {\n\t\t\tcustomData = locale;\n\t\t},\n\t});\n\n\truntime.setLocale(\"fr\");\n\n\texpect(customData).toBe(\"fr\");\n\texpect(globalThis.localStorage.setItem).toHaveBeenCalledWith(\n\t\t\"PARAGLIDE_LOCALE\",\n\t\t\"fr\"\n\t);\n\texpect(globalThis.document.cookie).toBe(\n\t\t\"PARAGLIDE_LOCALE=fr; path=/; max-age=34560000\"\n\t);\n});\n\ntest(\"custom strategy setLocale integrates with URL strategy\", async () => {\n\tlet customStoredLocale = \"en\";\n\n\tglobalThis.window = {\n\t\tlocation: {\n\t\t\thostname: \"example.com\",\n\t\t\thref: \"https://example.com/en/page\",\n\t\t\treload: vi.fn(),\n\t\t},\n\t} as any;\n\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"fr\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"url\", \"custom-urlIntegration\", \"baseLocale\"],\n\t\turlPatterns: [\n\t\t\t{\n\t\t\t\tpattern: \"https://example.com/:locale/:path*\",\n\t\t\t\tlocalized: [\n\t\t\t\t\t[\"en\", \"https://example.com/en/:path*\"],\n\t\t\t\t\t[\"fr\", \"https://example.com/fr/:path*\"],\n\t\t\t\t\t[\"de\", \"https://example.com/de/:path*\"],\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t\tisServer: \"false\",\n\t});\n\n\truntime.defineCustomClientStrategy(\"custom-urlIntegration\", {\n\t\tgetLocale: () => customStoredLocale,\n\t\tsetLocale: (locale) => {\n\t\t\tcustomStoredLocale = locale;\n\t\t},\n\t});\n\n\truntime.setLocale(\"de\");\n\n\texpect(globalThis.window.location.href).toBe(\"https://example.com/de/page\");\n\texpect(customStoredLocale).toBe(\"de\");\n});\n\n// sandboxed iframes without allow-same-origin have an opaque origin and throw\n// a SecurityError on document.cookie and localStorage access\ntest(\"navigates to the localized url when document.cookie throws\", async () => {\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"url\", \"cookie\", \"baseLocale\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t\tisServer: \"false\",\n\t\turlPatterns: [\n\t\t\t{\n\t\t\t\tpattern: \"https://example.com/:path*\",\n\t\t\t\tlocalized: [\n\t\t\t\t\t[\"en\", \"https://example.com/en/:path*\"],\n\t\t\t\t\t[\"de\", \"https://example.com/de/:path*\"],\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t});\n\n\t/** @ts-expect-error - client side api */\n\tglobalThis.document = {\n\t\tget cookie(): string {\n\t\t\tthrow new DOMException(\"The operation is insecure.\", \"SecurityError\");\n\t\t},\n\t\tset cookie(_value) {\n\t\t\tthrow new DOMException(\"The operation is insecure.\", \"SecurityError\");\n\t\t},\n\t};\n\tglobalThis.window = {\n\t\tlocation: new URL(\"https://example.com/en/some-path\"),\n\t} as any;\n\n\truntime.setLocale(\"de\");\n\n\texpect(globalThis.window.location.href).toBe(\n\t\t\"https://example.com/de/some-path\"\n\t);\n});\n\ntest(\"reloads when document.cookie throws\", async () => {\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"cookie\", \"baseLocale\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t\tisServer: \"false\",\n\t});\n\n\t/** @ts-expect-error - client side api */\n\tglobalThis.document = {\n\t\tget cookie(): string {\n\t\t\tthrow new DOMException(\"The operation is insecure.\", \"SecurityError\");\n\t\t},\n\t\tset cookie(_value) {\n\t\t\tthrow new DOMException(\"The operation is insecure.\", \"SecurityError\");\n\t\t},\n\t};\n\tglobalThis.window = {\n\t\tlocation: {\n\t\t\thref: \"https://example.com/page\",\n\t\t\treload: vi.fn(),\n\t\t},\n\t} as any;\n\n\truntime.setLocale(\"de\");\n\n\texpect(globalThis.window.location.reload).toBeCalled();\n});\n\ntest(\"reloads when localStorage throws\", async () => {\n\tconst runtime = await createParaglide({\n\t\tblob: await newProject({\n\t\t\tsettings: {\n\t\t\t\tbaseLocale: \"en\",\n\t\t\t\tlocales: [\"en\", \"de\"],\n\t\t\t},\n\t\t}),\n\t\tstrategy: [\"localStorage\", \"baseLocale\"],\n\t\tisServer: \"false\",\n\t});\n\n\t// @ts-expect-error - global variable definition\n\tglobalThis.localStorage = {\n\t\tgetItem: () => {\n\t\t\tthrow new DOMException(\"The operation is insecure.\", \"SecurityError\");\n\t\t},\n\t\tsetItem: () => {\n\t\t\tthrow new DOMException(\"The operation is insecure.\", \"SecurityError\");\n\t\t},\n\t};\n\tglobalThis.window = {\n\t\tlocation: {\n\t\t\thref: \"https://example.com/page\",\n\t\t\treload: vi.fn(),\n\t\t},\n\t} as any;\n\n\truntime.setLocale(\"de\");\n\n\texpect(globalThis.window.location.reload).toBeCalled();\n});\n"]}
|
|
@@ -8,6 +8,8 @@ export type Runtime = {
|
|
|
8
8
|
routeStrategies: typeof import("./variables.js").routeStrategies;
|
|
9
9
|
cookieName: typeof import("./variables.js").cookieName;
|
|
10
10
|
cookieMaxAge: typeof import("./variables.js").cookieMaxAge;
|
|
11
|
+
cookieSameSite: typeof import("./variables.js").cookieSameSite;
|
|
12
|
+
cookieSecure: typeof import("./variables.js").cookieSecure;
|
|
11
13
|
urlPatterns: typeof import("./variables.js").urlPatterns;
|
|
12
14
|
trailingSlash: typeof import("./variables.js").trailingSlash;
|
|
13
15
|
disableAsyncLocalStorage: typeof import("./variables.js").disableAsyncLocalStorage;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/compiler/runtime/type.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * The Paraglide runtime API.\n */\nexport type Runtime = {\n\tbaseLocale: typeof import(\"./variables.js\").baseLocale;\n\tlocales: typeof import(\"./variables.js\").locales;\n\tstrategy: typeof import(\"./variables.js\").strategy;\n\trouteStrategies: typeof import(\"./variables.js\").routeStrategies;\n\tcookieName: typeof import(\"./variables.js\").cookieName;\n\tcookieMaxAge: typeof import(\"./variables.js\").cookieMaxAge;\n\turlPatterns: typeof import(\"./variables.js\").urlPatterns;\n\ttrailingSlash: typeof import(\"./variables.js\").trailingSlash;\n\tdisableAsyncLocalStorage: typeof import(\"./variables.js\").disableAsyncLocalStorage;\n\tserverAsyncLocalStorage: typeof import(\"./variables.js\").serverAsyncLocalStorage;\n\tgetServerAsyncLocalStorage: typeof import(\"./variables.js\").getServerAsyncLocalStorage;\n\texperimentalMiddlewareLocaleSplitting: typeof import(\"./variables.js\").experimentalMiddlewareLocaleSplitting;\n\tisServer: typeof import(\"./variables.js\").isServer;\n\texperimentalStaticLocale: typeof import(\"./variables.js\").experimentalStaticLocale;\n\tgetLocale: typeof import(\"./get-locale.js\").getLocale;\n\tgetTextDirection: typeof import(\"./get-text-direction.js\").getTextDirection;\n\tsetLocale: typeof import(\"./set-locale.js\").setLocale;\n\tgetUrlOrigin: typeof import(\"./get-url-origin.js\").getUrlOrigin;\n\toverwriteGetLocale: typeof import(\"./get-locale.js\").overwriteGetLocale;\n\toverwriteSetLocale: typeof import(\"./set-locale.js\").overwriteSetLocale;\n\toverwriteGetUrlOrigin: typeof import(\"./get-url-origin.js\").overwriteGetUrlOrigin;\n\toverwriteServerAsyncLocalStorage: typeof import(\"./variables.js\").overwriteServerAsyncLocalStorage;\n\ttoLocale: typeof import(\"./check-locale.js\").toLocale;\n\tassertIsLocale: typeof import(\"./check-locale.js\").assertIsLocale;\n\tisLocale: typeof import(\"./check-locale.js\").isLocale;\n\tlocalizeHref: typeof import(\"./localize-href.js\").localizeHref;\n\tdeLocalizeHref: typeof import(\"./localize-href.js\").deLocalizeHref;\n\tlocalizeUrl: typeof import(\"./localize-url.js\").localizeUrl;\n\tdeLocalizeUrl: typeof import(\"./localize-url.js\").deLocalizeUrl;\n\tshouldRedirect: typeof import(\"./should-redirect.js\").shouldRedirect;\n\textractLocaleFromUrl: typeof import(\"./extract-locale-from-url.js\").extractLocaleFromUrl;\n\textractLocaleFromRequest: typeof import(\"./extract-locale-from-request.js\").extractLocaleFromRequest;\n\textractLocaleFromRequestAsync: typeof import(\"./extract-locale-from-request-async.js\").extractLocaleFromRequestAsync;\n\textractLocaleFromCookie: typeof import(\"./extract-locale-from-cookie.js\").extractLocaleFromCookie;\n\textractLocaleFromHeader: typeof import(\"./extract-locale-from-header.js\").extractLocaleFromHeader;\n\textractLocaleFromNavigator: typeof import(\"./extract-locale-from-navigator.js\").extractLocaleFromNavigator;\n\tgenerateStaticLocalizedUrls: typeof import(\"./generate-static-localized-urls.js\").generateStaticLocalizedUrls;\n\ttrackMessageCall: typeof import(\"./track-message-call.js\").trackMessageCall;\n\tgetStrategyForUrl: typeof import(\"./route-strategy.js\").getStrategyForUrl;\n\tisExcludedByRouteStrategy: typeof import(\"./route-strategy.js\").isExcludedByRouteStrategy;\n\tdefineCustomServerStrategy: typeof import(\"./strategy.js\").defineCustomServerStrategy;\n\tdefineCustomClientStrategy: typeof import(\"./strategy.js\").defineCustomClientStrategy;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/compiler/runtime/type.ts"],"names":[],"mappings":"","sourcesContent":["/**\n * The Paraglide runtime API.\n */\nexport type Runtime = {\n\tbaseLocale: typeof import(\"./variables.js\").baseLocale;\n\tlocales: typeof import(\"./variables.js\").locales;\n\tstrategy: typeof import(\"./variables.js\").strategy;\n\trouteStrategies: typeof import(\"./variables.js\").routeStrategies;\n\tcookieName: typeof import(\"./variables.js\").cookieName;\n\tcookieMaxAge: typeof import(\"./variables.js\").cookieMaxAge;\n\tcookieSameSite: typeof import(\"./variables.js\").cookieSameSite;\n\tcookieSecure: typeof import(\"./variables.js\").cookieSecure;\n\turlPatterns: typeof import(\"./variables.js\").urlPatterns;\n\ttrailingSlash: typeof import(\"./variables.js\").trailingSlash;\n\tdisableAsyncLocalStorage: typeof import(\"./variables.js\").disableAsyncLocalStorage;\n\tserverAsyncLocalStorage: typeof import(\"./variables.js\").serverAsyncLocalStorage;\n\tgetServerAsyncLocalStorage: typeof import(\"./variables.js\").getServerAsyncLocalStorage;\n\texperimentalMiddlewareLocaleSplitting: typeof import(\"./variables.js\").experimentalMiddlewareLocaleSplitting;\n\tisServer: typeof import(\"./variables.js\").isServer;\n\texperimentalStaticLocale: typeof import(\"./variables.js\").experimentalStaticLocale;\n\tgetLocale: typeof import(\"./get-locale.js\").getLocale;\n\tgetTextDirection: typeof import(\"./get-text-direction.js\").getTextDirection;\n\tsetLocale: typeof import(\"./set-locale.js\").setLocale;\n\tgetUrlOrigin: typeof import(\"./get-url-origin.js\").getUrlOrigin;\n\toverwriteGetLocale: typeof import(\"./get-locale.js\").overwriteGetLocale;\n\toverwriteSetLocale: typeof import(\"./set-locale.js\").overwriteSetLocale;\n\toverwriteGetUrlOrigin: typeof import(\"./get-url-origin.js\").overwriteGetUrlOrigin;\n\toverwriteServerAsyncLocalStorage: typeof import(\"./variables.js\").overwriteServerAsyncLocalStorage;\n\ttoLocale: typeof import(\"./check-locale.js\").toLocale;\n\tassertIsLocale: typeof import(\"./check-locale.js\").assertIsLocale;\n\tisLocale: typeof import(\"./check-locale.js\").isLocale;\n\tlocalizeHref: typeof import(\"./localize-href.js\").localizeHref;\n\tdeLocalizeHref: typeof import(\"./localize-href.js\").deLocalizeHref;\n\tlocalizeUrl: typeof import(\"./localize-url.js\").localizeUrl;\n\tdeLocalizeUrl: typeof import(\"./localize-url.js\").deLocalizeUrl;\n\tshouldRedirect: typeof import(\"./should-redirect.js\").shouldRedirect;\n\textractLocaleFromUrl: typeof import(\"./extract-locale-from-url.js\").extractLocaleFromUrl;\n\textractLocaleFromRequest: typeof import(\"./extract-locale-from-request.js\").extractLocaleFromRequest;\n\textractLocaleFromRequestAsync: typeof import(\"./extract-locale-from-request-async.js\").extractLocaleFromRequestAsync;\n\textractLocaleFromCookie: typeof import(\"./extract-locale-from-cookie.js\").extractLocaleFromCookie;\n\textractLocaleFromHeader: typeof import(\"./extract-locale-from-header.js\").extractLocaleFromHeader;\n\textractLocaleFromNavigator: typeof import(\"./extract-locale-from-navigator.js\").extractLocaleFromNavigator;\n\tgenerateStaticLocalizedUrls: typeof import(\"./generate-static-localized-urls.js\").generateStaticLocalizedUrls;\n\ttrackMessageCall: typeof import(\"./track-message-call.js\").trackMessageCall;\n\tgetStrategyForUrl: typeof import(\"./route-strategy.js\").getStrategyForUrl;\n\tisExcludedByRouteStrategy: typeof import(\"./route-strategy.js\").isExcludedByRouteStrategy;\n\tdefineCustomServerStrategy: typeof import(\"./strategy.js\").defineCustomServerStrategy;\n\tdefineCustomClientStrategy: typeof import(\"./strategy.js\").defineCustomClientStrategy;\n};\n"]}
|
|
@@ -37,6 +37,40 @@ test("createRuntimeFile throws if urlPatterns contains an unknown locale", () =>
|
|
|
37
37
|
},
|
|
38
38
|
})).toThrow('Invalid locale "fr" in urlPatterns. It must be one of the locales defined in the "locales" array.');
|
|
39
39
|
});
|
|
40
|
+
test("createRuntimeFile throws if cookieSameSite is 'none' without cookieSecure", () => {
|
|
41
|
+
const create = (cookieSecure) => createRuntimeFile({
|
|
42
|
+
baseLocale: "en",
|
|
43
|
+
locales: ["en", "de"],
|
|
44
|
+
compilerOptions: {
|
|
45
|
+
...defaultCompilerOptions,
|
|
46
|
+
cookieSameSite: "none",
|
|
47
|
+
cookieSecure,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
expect(() => create()).toThrow('cookieSameSite "none" requires cookieSecure to be true or "auto". Browsers reject SameSite=None cookies without the Secure attribute.');
|
|
51
|
+
expect(() => create(false)).toThrow();
|
|
52
|
+
expect(() => create(true)).not.toThrow();
|
|
53
|
+
expect(() => create("auto")).not.toThrow();
|
|
54
|
+
});
|
|
55
|
+
test("runtime with cookie attributes passes checkJs", async () => {
|
|
56
|
+
const project = await typescriptProject({
|
|
57
|
+
useInMemoryFileSystem: true,
|
|
58
|
+
compilerOptions: superStrictRuleOutAnyErrorTsSettings,
|
|
59
|
+
});
|
|
60
|
+
project.createSourceFile("./runtime.js", createRuntimeFile({
|
|
61
|
+
baseLocale: "en",
|
|
62
|
+
locales: ["en", "de"],
|
|
63
|
+
compilerOptions: {
|
|
64
|
+
...defaultCompilerOptions,
|
|
65
|
+
cookieSameSite: "lax",
|
|
66
|
+
cookieSecure: "auto",
|
|
67
|
+
},
|
|
68
|
+
}));
|
|
69
|
+
const diagnostics = ts
|
|
70
|
+
.getPreEmitDiagnostics(project.createProgram())
|
|
71
|
+
.map((d) => ts.flattenDiagnosticMessageText(d.messageText, "\n"));
|
|
72
|
+
expect(diagnostics).toEqual([]);
|
|
73
|
+
});
|
|
40
74
|
test("cookie cache clearer remains internal in the generated runtime", () => {
|
|
41
75
|
const jsdocRuntime = createRuntimeFile({
|
|
42
76
|
baseLocale: "en",
|