vite-intlayer 9.5.4 → 9.5.5
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 +2 -1
- package/dist/esm/index.mjs +2 -2
- package/dist/esm/intlayerProxyPlugin.mjs +13 -2
- package/dist/esm/intlayerProxyPlugin.mjs.map +1 -1
- package/dist/types/index.d.ts +2 -2
- package/dist/types/intlayerProxyPlugin.d.ts +10 -0
- package/dist/types/intlayerProxyPlugin.d.ts.map +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -188,7 +188,8 @@ Explore our comprehensive documentation to get started with Intlayer and learn h
|
|
|
188
188
|
<li><a href="https://intlayer.org/doc/environment/create-react-app" rel=''>React CRA</a></li>
|
|
189
189
|
<li><a href="https://intlayer.org/doc/environment/vite-and-react" rel=''>Vite + React</a></li>
|
|
190
190
|
<li><a href="https://intlayer.org/doc/environment/vite-and-react" rel=''>Vite + React using Compiler</a></li>
|
|
191
|
-
<li><a href="https://intlayer.org/doc/environment/vite-and-react/
|
|
191
|
+
<li><a href="https://intlayer.org/doc/environment/vite-and-react/react-router-v7" rel=''>React-router-v7</a></li>
|
|
192
|
+
<li><a href="https://intlayer.org/doc/environment/remix-3" rel=''>Remix 3</a></li>
|
|
192
193
|
<li><a href="https://intlayer.org/doc/environment/tanstack-start" rel=''>Tanstack start</a>
|
|
193
194
|
<ul>
|
|
194
195
|
<li><a href="https://intlayer.org/doc/environment/tanstack-start/solid" rel=''>Solid</a></li>
|
package/dist/esm/index.mjs
CHANGED
|
@@ -3,8 +3,8 @@ import { createDictionaryModuleParser, intlayerChunk, resolveBoundaries, toBound
|
|
|
3
3
|
import { intlayerMinify } from "./intlayerMinifyPlugin.mjs";
|
|
4
4
|
import { intlayerOptimize } from "./intlayerOptimizePlugin.mjs";
|
|
5
5
|
import { intlayerPreload } from "./intlayerPreloadPlugin.mjs";
|
|
6
|
-
import { createIntlayerProxyHandler, intLayerMiddlewarePlugin, intlayerMiddleware, intlayerProxy } from "./intlayerProxyPlugin.mjs";
|
|
6
|
+
import { createIntlayerProxyHandler, intLayerMiddlewarePlugin, intlayerMiddleware, intlayerProxy, resolveNitroHandlerPath } from "./intlayerProxyPlugin.mjs";
|
|
7
7
|
import { intlayerPrune } from "./intlayerPrunePlugin.mjs";
|
|
8
8
|
import { INTLAYER_NO_EXTERNAL_PATTERN, intLayerPlugin, intlayer, intlayerPlugin } from "./intlayerPlugin.mjs";
|
|
9
9
|
|
|
10
|
-
export { INTLAYER_NO_EXTERNAL_PATTERN, createDictionaryModuleParser, createIntlayerProxyHandler, intLayerMiddlewarePlugin, intLayerPlugin, intlayer, intlayerChunk, intlayerCompiler, intlayerMiddleware, intlayerMinify, intlayerOptimize, intlayerPlugin, intlayerPreload, intlayerProxy, intlayerPrune, resolveBoundaries, toBoundaryName };
|
|
10
|
+
export { INTLAYER_NO_EXTERNAL_PATTERN, createDictionaryModuleParser, createIntlayerProxyHandler, intLayerMiddlewarePlugin, intLayerPlugin, intlayer, intlayerChunk, intlayerCompiler, intlayerMiddleware, intlayerMinify, intlayerOptimize, intlayerPlugin, intlayerPreload, intlayerProxy, intlayerPrune, resolveBoundaries, resolveNitroHandlerPath, toBoundaryName };
|
|
@@ -2,6 +2,7 @@ import { createPrimaryInstanceGuard } from "./dedupePlugin.mjs";
|
|
|
2
2
|
import { createProxyHandler } from "./intlayerProxyHandler.mjs";
|
|
3
3
|
import { getAppLogger } from "@intlayer/config/logger";
|
|
4
4
|
import { getConfiguration } from "@intlayer/config/node";
|
|
5
|
+
import { normalizePath } from "@intlayer/config/utils";
|
|
5
6
|
import { formatProxyEnabledMessage, isProxyStorageLocaleEnabled, resolveProxyMode } from "@intlayer/core/localization";
|
|
6
7
|
import { fileURLToPath } from "node:url";
|
|
7
8
|
|
|
@@ -81,6 +82,16 @@ const createIntlayerProxyHandler = (options) => createProxyHandler({
|
|
|
81
82
|
*
|
|
82
83
|
* @deprecated Since Intlayer v9, `intlayerProxy()` is bundled directly into the `intlayer()` plugin and enabled by default through the `routing.enableProxy` option (unset by default, which selects auto mode). Registering it separately as shown below is now optional.
|
|
83
84
|
*/
|
|
85
|
+
/**
|
|
86
|
+
* Absolute path of the built Nitro middleware, relative to this module.
|
|
87
|
+
*
|
|
88
|
+
* Nitro inlines the path as an import specifier in its virtual routing module,
|
|
89
|
+
* so Windows backslashes must become forward slashes or the import breaks.
|
|
90
|
+
*
|
|
91
|
+
* @param moduleUrl - `import.meta.url` of the calling module
|
|
92
|
+
* @param toPath - `file:` URL to path converter (overridable for tests)
|
|
93
|
+
*/
|
|
94
|
+
const resolveNitroHandlerPath = (moduleUrl, toPath = fileURLToPath) => normalizePath(toPath(new URL("./intlayerNitroHandler.mjs", moduleUrl)));
|
|
84
95
|
const intlayerProxy = (options) => {
|
|
85
96
|
const handler = createIntlayerProxyHandler({
|
|
86
97
|
...options,
|
|
@@ -106,7 +117,7 @@ const intlayerProxy = (options) => {
|
|
|
106
117
|
name: "intlayer-proxy",
|
|
107
118
|
setup(nitro) {
|
|
108
119
|
if (nitro.options.dev) return;
|
|
109
|
-
const handlerPath =
|
|
120
|
+
const handlerPath = resolveNitroHandlerPath(import.meta.url);
|
|
110
121
|
if (nitro.options.handlers.some((existingHandler) => existingHandler.handler === handlerPath)) return;
|
|
111
122
|
nitro.options.handlers.push({
|
|
112
123
|
route: "/**",
|
|
@@ -158,5 +169,5 @@ const intlayerMiddleware = intlayerProxy;
|
|
|
158
169
|
const intLayerMiddlewarePlugin = intlayerProxy;
|
|
159
170
|
|
|
160
171
|
//#endregion
|
|
161
|
-
export { createIntlayerProxyHandler, intLayerMiddlewarePlugin, intlayerMiddleware, intlayerProxy };
|
|
172
|
+
export { createIntlayerProxyHandler, intLayerMiddlewarePlugin, intlayerMiddleware, intlayerProxy, resolveNitroHandlerPath };
|
|
162
173
|
//# sourceMappingURL=intlayerProxyPlugin.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerProxyPlugin.mjs","names":[],"sources":["../../src/intlayerProxyPlugin.ts"],"sourcesContent":["import type { IncomingMessage } from 'node:http';\nimport { fileURLToPath } from 'node:url';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport {\n formatProxyEnabledMessage,\n isProxyStorageLocaleEnabled,\n resolveProxyMode,\n} from '@intlayer/core/localization';\n/* @ts-ignore - Vite types error */\nimport type { Plugin } from 'vite';\nimport { createPrimaryInstanceGuard } from './dedupePlugin';\nimport {\n createProxyHandler,\n type NodeMiddleware,\n} from './intlayerProxyHandler';\n\nconst PROXY_PLUGIN_NAME = 'vite-intlayer-middleware-plugin';\n\n/**\n * Name of the Vite plugin `nitro/vite` registers in preview mode. It mounts the\n * built Nitro server — which already carries the Intlayer proxy as a Nitro\n * middleware — inside the Vite preview server.\n */\nconst NITRO_PREVIEW_PLUGIN_NAME = 'nitro:preview';\n\nexport type IntlayerProxyPluginOptions = {\n /**\n * A function that allows you to ignore specific requests from the intlayer proxy.\n *\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [ intlayerProxy({ ignore: (req) => req.url?.startsWith('/api') }) ],\n * });\n * ```\n *\n * @param req - The incoming request.\n * @returns A boolean value indicating whether to ignore the request.\n */\n ignore?: (req: IncomingMessage) => boolean | undefined;\n /**\n * Optional Intlayer configuration overrides forwarded to `getConfiguration`.\n *\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [ intlayerProxy({ configOptions: { override: { ... } } }) ],\n * });\n * ```\n */\n configOptions?: GetConfigurationOptions;\n /**\n * Whether a development or preview server is serving the app.\n *\n * Set internally by the plugin from `configureServer` /\n * `configurePreviewServer`. It only matters in the proxy's auto mode, where\n * a dev server keeps locale routing URL-driven by ignoring the stored locale\n * as a redirect source.\n *\n * Defaults to `false` so that mounting `createIntlayerProxyHandler()`\n * manually — the documented production Nitro setup — keeps full behaviour.\n *\n * @default false\n */\n isDevServer?: boolean;\n};\n\n/**\n * Creates a standalone, framework-agnostic locale-routing middleware.\n *\n * It loads the Intlayer configuration and hands it to the runtime handler in\n * `intlayerProxyHandler`, so it can be used in every environment:\n *\n * - **Dev**: wired up automatically by `intlayerProxy` via `configureServer`\n * - **Preview**: wired up automatically by `intlayerProxy` via `configurePreviewServer`\n * - **Production (Nitro / TanStack Start)**: create `server/middleware/intlayerProxy.ts`:\n *\n * @example\n * ```ts\n * // server/middleware/intlayerProxy.ts\n * import { fromNodeMiddleware } from 'h3';\n * import { createIntlayerProxyHandler } from 'vite-intlayer';\n *\n * export default fromNodeMiddleware(createIntlayerProxyHandler());\n * ```\n *\n * @param options - Plugin-specific options, such as path ignoring and Intlayer configuration overrides.\n * @returns A Connect-compatible `(req, res, next) => void` middleware.\n */\nexport const createIntlayerProxyHandler = (\n options?: IntlayerProxyPluginOptions\n): NodeMiddleware =>\n createProxyHandler({\n configuration: getConfiguration(options?.configOptions),\n ignore: options?.ignore,\n isDevServer: options?.isDevServer ?? false,\n });\n\n/**\n * Vite plugin that provides locale-based routing middleware for **all environments**:\n * development, preview, and production SSR (Nitro / TanStack Start).\n *\n * - **Dev** (`vite dev`): registered via `configureServer`.\n * - **Preview** (`vite preview`): registered via `configurePreviewServer`.\n * - **Production Nitro** (`vite build`): automatically injected via the `.nitro` module\n * property that `nitro/vite` reads and pushes into `nitroConfig.modules`. The module\n * registers `intlayerNitroHandler` as a Nitro server middleware — no extra user config\n * needed.\n *\n * If you need custom config options or an `ignore` predicate in production, bypass\n * auto-injection and create a server middleware file manually:\n *\n * ```ts\n * // server/middleware/intlayerProxy.ts\n * import { fromNodeMiddleware } from 'h3';\n * import { createIntlayerProxyHandler } from 'vite-intlayer';\n *\n * export default fromNodeMiddleware(\n * createIntlayerProxyHandler({\n * ignore: (req) => req.url?.startsWith('/api'),\n * configOptions: myConfig,\n * })\n * );\n * ```\n *\n * @param options - Plugin-specific options, like ignoring certain paths and Intlayer configuration overrides.\n * @returns A Vite plugin.\n *\n * @example\n * ```ts\n * import { intlayerProxy } from 'vite-intlayer';\n *\n * export default defineConfig({\n * plugins: [intlayerProxy()],\n * });\n * ```\n *\n * @deprecated Since Intlayer v9, `intlayerProxy()` is bundled directly into the `intlayer()` plugin and enabled by default through the `routing.enableProxy` option (unset by default, which selects auto mode). Registering it separately as shown below is now optional.\n */\nexport const intlayerProxy = (options?: IntlayerProxyPluginOptions): Plugin => {\n // Dev and preview servers run the same handler; both are \"dev servers\" as far\n // as auto mode is concerned, so a single instance covers both hooks.\n const handler = createIntlayerProxyHandler({ ...options, isDevServer: true });\n const intlayerConfig = getConfiguration(options?.configOptions);\n const logger = getAppLogger(intlayerConfig);\n\n // Both hooks below serve a dev or preview server, hence the hard-coded true.\n const isStorageLocaleSuppressed = !isProxyStorageLocaleEnabled(\n resolveProxyMode(intlayerConfig.routing.enableProxy),\n true\n );\n\n /**\n * Logs that the proxy is serving requests, spelling out when auto mode has\n * suppressed the stored locale so the reported state matches the behaviour.\n */\n const logProxyEnabled = () =>\n logger(formatProxyEnabledMessage(isStorageLocaleSuppressed), {\n level: 'info',\n });\n\n // Ensures the proxy registers its middleware only once, even when it is\n // registered both via `intlayer()` (which now bundles it) and a manual\n // `intlayerProxy()` call.\n const guard = createPrimaryInstanceGuard(PROXY_PLUGIN_NAME);\n\n // Set during `configResolved`: `nitro/vite` serves the *built* Nitro server\n // from inside the preview server, and that build already carries the proxy as\n // a Nitro middleware (see `nitroModule` below).\n let isNitroServingPreview = false;\n\n /**\n * Nitro module injected automatically by `nitro/vite`.\n *\n * When a Vite plugin carries a `.nitro` property, `nitro/vite` pushes it into\n * `nitroConfig.modules` during the build phase. The module's `setup` hook adds\n * our locale-routing handler to Nitro's server pipeline, making locale detection\n * work in production SSR builds (TanStack Start, Nuxt, etc.) without any extra\n * user configuration.\n *\n * @see https://github.com/nitrojs/nitro (nitro/vite source, line ~402)\n */\n const nitroModule = {\n name: 'intlayer-proxy',\n setup(nitro: {\n options: {\n dev: boolean;\n handlers: {\n route: string;\n handler: string;\n middleware: boolean;\n }[];\n };\n }) {\n // In dev mode, locale routing is already handled by configureServer (Vite dev server).\n // The Nitro dev server uses h3 v2's Web Fetch API event model which is incompatible\n // with fromNodeMiddleware (h3 v1) and would cause double-execution anyway.\n // Only inject for production builds where Nitro is the actual HTTP server.\n if (nitro.options.dev) return;\n\n const handlerPath = fileURLToPath(\n new URL('./intlayerNitroHandler.mjs', import.meta.url)\n );\n\n // Skip if an identical handler was already registered by another instance\n // (e.g. both `intlayer()` and a manual `intlayerProxy()`).\n const alreadyRegistered = nitro.options.handlers.some(\n (existingHandler) => existingHandler.handler === handlerPath\n );\n if (alreadyRegistered) return;\n\n nitro.options.handlers.push({\n route: '/**',\n handler: handlerPath,\n middleware: true,\n });\n },\n };\n\n const plugin = {\n name: PROXY_PLUGIN_NAME,\n // Decide whether this is the primary instance before registering middleware.\n configResolved: (config: { plugins: readonly { name: string }[] }) => {\n guard.resolve(config);\n isNitroServingPreview = config.plugins.some(\n (registeredPlugin) =>\n registeredPlugin.name === NITRO_PREVIEW_PLUGIN_NAME\n );\n },\n // Injected into nitroConfig.modules by the `nitro/vite` plugin so the\n // locale-routing middleware is registered in the production Nitro server.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n nitro: nitroModule as any,\n // Vite dev server\n configureServer: (server) => {\n if (!guard.isPrimary) return;\n logProxyEnabled();\n server.middlewares.use(handler);\n },\n // Vite preview server\n configurePreviewServer: (server) => {\n if (!guard.isPrimary) return;\n // With Nitro, the preview server forwards every request to the built\n // Nitro server, whose pipeline already starts with this proxy. Adding a\n // second layer here would run locale resolution twice on the same\n // request: the first pass rewrites `req.url` (and the locale request\n // header), the second pass reads that rewritten URL as if it came from\n // the browser and can redirect it back — the redirect ping-pong that\n // shows up as \"max redirects reached\" while prerendering.\n if (isNitroServingPreview) return;\n logProxyEnabled();\n server.middlewares.use(handler);\n },\n } as Plugin;\n\n // Register the plugin object so the dedupe guard can identify the primary\n // instance by reference during `configResolved`.\n guard.setPlugin(plugin);\n\n return plugin;\n};\n\n/**\n * @deprecated Rename to intlayerProxy instead\n *\n * A Vite plugin that integrates a logic similar to the Next.js intlayer middleware.\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayerMiddleware() ],\n * });\n * ```\n */\nexport const intlayerMiddleware = intlayerProxy;\n\n/**\n * @deprecated Rename to intlayerProxy instead\n *\n * A Vite plugin that integrates a logic similar to the Next.js intlayer middleware.\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayerMiddleware() ],\n * });\n * ```\n */\nexport const intLayerMiddlewarePlugin = intlayerProxy;\n"],"mappings":";;;;;;;;AAoBA,MAAM,oBAAoB;;;;;;AAO1B,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;AAkElC,MAAa,8BACX,YAEA,mBAAmB;CACjB,eAAe,iBAAiB,SAAS,aAAa;CACtD,QAAQ,SAAS;CACjB,aAAa,SAAS,eAAe;AACvC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CH,MAAa,iBAAiB,YAAiD;CAG7E,MAAM,UAAU,2BAA2B;EAAE,GAAG;EAAS,aAAa;CAAK,CAAC;CAC5E,MAAM,iBAAiB,iBAAiB,SAAS,aAAa;CAC9D,MAAM,SAAS,aAAa,cAAc;CAG1C,MAAM,4BAA4B,CAAC,4BACjC,iBAAiB,eAAe,QAAQ,WAAW,GACnD,IACF;;;;;CAMA,MAAM,wBACJ,OAAO,0BAA0B,yBAAyB,GAAG,EAC3D,OAAO,OACT,CAAC;CAKH,MAAM,QAAQ,2BAA2B,iBAAiB;CAK1D,IAAI,wBAAwB;CAkD5B,MAAM,SAAS;EACb,MAAM;EAEN,iBAAiB,WAAqD;GACpE,MAAM,QAAQ,MAAM;GACpB,wBAAwB,OAAO,QAAQ,MACpC,qBACC,iBAAiB,SAAS,yBAC9B;EACF;EAIA,OAAO;GAjDP,MAAM;GACN,MAAM,OASH;IAKD,IAAI,MAAM,QAAQ,KAAK;IAEvB,MAAM,cAAc,cAClB,IAAI,IAAI,8BAA8B,YAAY,GAAG,CACvD;IAOA,IAH0B,MAAM,QAAQ,SAAS,MAC9C,oBAAoB,gBAAgB,YAAY,WAE/B,GAAG;IAEvB,MAAM,QAAQ,SAAS,KAAK;KAC1B,OAAO;KACP,SAAS;KACT,YAAY;IACd,CAAC;GACH;EAgBiB;EAEjB,kBAAkB,WAAW;GAC3B,IAAI,CAAC,MAAM,WAAW;GACtB,gBAAgB;GAChB,OAAO,YAAY,IAAI,OAAO;EAChC;EAEA,yBAAyB,WAAW;GAClC,IAAI,CAAC,MAAM,WAAW;GAQtB,IAAI,uBAAuB;GAC3B,gBAAgB;GAChB,OAAO,YAAY,IAAI,OAAO;EAChC;CACF;CAIA,MAAM,UAAU,MAAM;CAEtB,OAAO;AACT;;;;;;;;;;;;;AAcA,MAAa,qBAAqB;;;;;;;;;;;;;AAclC,MAAa,2BAA2B"}
|
|
1
|
+
{"version":3,"file":"intlayerProxyPlugin.mjs","names":[],"sources":["../../src/intlayerProxyPlugin.ts"],"sourcesContent":["import type { IncomingMessage } from 'node:http';\nimport { fileURLToPath } from 'node:url';\nimport { getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport { normalizePath } from '@intlayer/config/utils';\nimport {\n formatProxyEnabledMessage,\n isProxyStorageLocaleEnabled,\n resolveProxyMode,\n} from '@intlayer/core/localization';\n/* @ts-ignore - Vite types error */\nimport type { Plugin } from 'vite';\nimport { createPrimaryInstanceGuard } from './dedupePlugin';\nimport {\n createProxyHandler,\n type NodeMiddleware,\n} from './intlayerProxyHandler';\n\nconst PROXY_PLUGIN_NAME = 'vite-intlayer-middleware-plugin';\n\n/**\n * Name of the Vite plugin `nitro/vite` registers in preview mode. It mounts the\n * built Nitro server — which already carries the Intlayer proxy as a Nitro\n * middleware — inside the Vite preview server.\n */\nconst NITRO_PREVIEW_PLUGIN_NAME = 'nitro:preview';\n\nexport type IntlayerProxyPluginOptions = {\n /**\n * A function that allows you to ignore specific requests from the intlayer proxy.\n *\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [ intlayerProxy({ ignore: (req) => req.url?.startsWith('/api') }) ],\n * });\n * ```\n *\n * @param req - The incoming request.\n * @returns A boolean value indicating whether to ignore the request.\n */\n ignore?: (req: IncomingMessage) => boolean | undefined;\n /**\n * Optional Intlayer configuration overrides forwarded to `getConfiguration`.\n *\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [ intlayerProxy({ configOptions: { override: { ... } } }) ],\n * });\n * ```\n */\n configOptions?: GetConfigurationOptions;\n /**\n * Whether a development or preview server is serving the app.\n *\n * Set internally by the plugin from `configureServer` /\n * `configurePreviewServer`. It only matters in the proxy's auto mode, where\n * a dev server keeps locale routing URL-driven by ignoring the stored locale\n * as a redirect source.\n *\n * Defaults to `false` so that mounting `createIntlayerProxyHandler()`\n * manually — the documented production Nitro setup — keeps full behaviour.\n *\n * @default false\n */\n isDevServer?: boolean;\n};\n\n/**\n * Creates a standalone, framework-agnostic locale-routing middleware.\n *\n * It loads the Intlayer configuration and hands it to the runtime handler in\n * `intlayerProxyHandler`, so it can be used in every environment:\n *\n * - **Dev**: wired up automatically by `intlayerProxy` via `configureServer`\n * - **Preview**: wired up automatically by `intlayerProxy` via `configurePreviewServer`\n * - **Production (Nitro / TanStack Start)**: create `server/middleware/intlayerProxy.ts`:\n *\n * @example\n * ```ts\n * // server/middleware/intlayerProxy.ts\n * import { fromNodeMiddleware } from 'h3';\n * import { createIntlayerProxyHandler } from 'vite-intlayer';\n *\n * export default fromNodeMiddleware(createIntlayerProxyHandler());\n * ```\n *\n * @param options - Plugin-specific options, such as path ignoring and Intlayer configuration overrides.\n * @returns A Connect-compatible `(req, res, next) => void` middleware.\n */\nexport const createIntlayerProxyHandler = (\n options?: IntlayerProxyPluginOptions\n): NodeMiddleware =>\n createProxyHandler({\n configuration: getConfiguration(options?.configOptions),\n ignore: options?.ignore,\n isDevServer: options?.isDevServer ?? false,\n });\n\n/**\n * Vite plugin that provides locale-based routing middleware for **all environments**:\n * development, preview, and production SSR (Nitro / TanStack Start).\n *\n * - **Dev** (`vite dev`): registered via `configureServer`.\n * - **Preview** (`vite preview`): registered via `configurePreviewServer`.\n * - **Production Nitro** (`vite build`): automatically injected via the `.nitro` module\n * property that `nitro/vite` reads and pushes into `nitroConfig.modules`. The module\n * registers `intlayerNitroHandler` as a Nitro server middleware — no extra user config\n * needed.\n *\n * If you need custom config options or an `ignore` predicate in production, bypass\n * auto-injection and create a server middleware file manually:\n *\n * ```ts\n * // server/middleware/intlayerProxy.ts\n * import { fromNodeMiddleware } from 'h3';\n * import { createIntlayerProxyHandler } from 'vite-intlayer';\n *\n * export default fromNodeMiddleware(\n * createIntlayerProxyHandler({\n * ignore: (req) => req.url?.startsWith('/api'),\n * configOptions: myConfig,\n * })\n * );\n * ```\n *\n * @param options - Plugin-specific options, like ignoring certain paths and Intlayer configuration overrides.\n * @returns A Vite plugin.\n *\n * @example\n * ```ts\n * import { intlayerProxy } from 'vite-intlayer';\n *\n * export default defineConfig({\n * plugins: [intlayerProxy()],\n * });\n * ```\n *\n * @deprecated Since Intlayer v9, `intlayerProxy()` is bundled directly into the `intlayer()` plugin and enabled by default through the `routing.enableProxy` option (unset by default, which selects auto mode). Registering it separately as shown below is now optional.\n */\n/**\n * Absolute path of the built Nitro middleware, relative to this module.\n *\n * Nitro inlines the path as an import specifier in its virtual routing module,\n * so Windows backslashes must become forward slashes or the import breaks.\n *\n * @param moduleUrl - `import.meta.url` of the calling module\n * @param toPath - `file:` URL to path converter (overridable for tests)\n */\nexport const resolveNitroHandlerPath = (\n moduleUrl: string,\n toPath: (url: URL) => string = fileURLToPath\n): string =>\n normalizePath(toPath(new URL('./intlayerNitroHandler.mjs', moduleUrl)));\n\nexport const intlayerProxy = (options?: IntlayerProxyPluginOptions): Plugin => {\n // Dev and preview servers run the same handler; both are \"dev servers\" as far\n // as auto mode is concerned, so a single instance covers both hooks.\n const handler = createIntlayerProxyHandler({ ...options, isDevServer: true });\n const intlayerConfig = getConfiguration(options?.configOptions);\n const logger = getAppLogger(intlayerConfig);\n\n // Both hooks below serve a dev or preview server, hence the hard-coded true.\n const isStorageLocaleSuppressed = !isProxyStorageLocaleEnabled(\n resolveProxyMode(intlayerConfig.routing.enableProxy),\n true\n );\n\n /**\n * Logs that the proxy is serving requests, spelling out when auto mode has\n * suppressed the stored locale so the reported state matches the behaviour.\n */\n const logProxyEnabled = () =>\n logger(formatProxyEnabledMessage(isStorageLocaleSuppressed), {\n level: 'info',\n });\n\n // Ensures the proxy registers its middleware only once, even when it is\n // registered both via `intlayer()` (which now bundles it) and a manual\n // `intlayerProxy()` call.\n const guard = createPrimaryInstanceGuard(PROXY_PLUGIN_NAME);\n\n // Set during `configResolved`: `nitro/vite` serves the *built* Nitro server\n // from inside the preview server, and that build already carries the proxy as\n // a Nitro middleware (see `nitroModule` below).\n let isNitroServingPreview = false;\n\n /**\n * Nitro module injected automatically by `nitro/vite`.\n *\n * When a Vite plugin carries a `.nitro` property, `nitro/vite` pushes it into\n * `nitroConfig.modules` during the build phase. The module's `setup` hook adds\n * our locale-routing handler to Nitro's server pipeline, making locale detection\n * work in production SSR builds (TanStack Start, Nuxt, etc.) without any extra\n * user configuration.\n *\n * @see https://github.com/nitrojs/nitro (nitro/vite source, line ~402)\n */\n const nitroModule = {\n name: 'intlayer-proxy',\n setup(nitro: {\n options: {\n dev: boolean;\n handlers: {\n route: string;\n handler: string;\n middleware: boolean;\n }[];\n };\n }) {\n // In dev mode, locale routing is already handled by configureServer (Vite dev server).\n // The Nitro dev server uses h3 v2's Web Fetch API event model which is incompatible\n // with fromNodeMiddleware (h3 v1) and would cause double-execution anyway.\n // Only inject for production builds where Nitro is the actual HTTP server.\n if (nitro.options.dev) return;\n\n const handlerPath = resolveNitroHandlerPath(import.meta.url);\n\n // Skip if an identical handler was already registered by another instance\n // (e.g. both `intlayer()` and a manual `intlayerProxy()`).\n const alreadyRegistered = nitro.options.handlers.some(\n (existingHandler) => existingHandler.handler === handlerPath\n );\n if (alreadyRegistered) return;\n\n nitro.options.handlers.push({\n route: '/**',\n handler: handlerPath,\n middleware: true,\n });\n },\n };\n\n const plugin = {\n name: PROXY_PLUGIN_NAME,\n // Decide whether this is the primary instance before registering middleware.\n configResolved: (config: { plugins: readonly { name: string }[] }) => {\n guard.resolve(config);\n isNitroServingPreview = config.plugins.some(\n (registeredPlugin) =>\n registeredPlugin.name === NITRO_PREVIEW_PLUGIN_NAME\n );\n },\n // Injected into nitroConfig.modules by the `nitro/vite` plugin so the\n // locale-routing middleware is registered in the production Nitro server.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n nitro: nitroModule as any,\n // Vite dev server\n configureServer: (server) => {\n if (!guard.isPrimary) return;\n logProxyEnabled();\n server.middlewares.use(handler);\n },\n // Vite preview server\n configurePreviewServer: (server) => {\n if (!guard.isPrimary) return;\n // With Nitro, the preview server forwards every request to the built\n // Nitro server, whose pipeline already starts with this proxy. Adding a\n // second layer here would run locale resolution twice on the same\n // request: the first pass rewrites `req.url` (and the locale request\n // header), the second pass reads that rewritten URL as if it came from\n // the browser and can redirect it back — the redirect ping-pong that\n // shows up as \"max redirects reached\" while prerendering.\n if (isNitroServingPreview) return;\n logProxyEnabled();\n server.middlewares.use(handler);\n },\n } as Plugin;\n\n // Register the plugin object so the dedupe guard can identify the primary\n // instance by reference during `configResolved`.\n guard.setPlugin(plugin);\n\n return plugin;\n};\n\n/**\n * @deprecated Rename to intlayerProxy instead\n *\n * A Vite plugin that integrates a logic similar to the Next.js intlayer middleware.\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayerMiddleware() ],\n * });\n * ```\n */\nexport const intlayerMiddleware = intlayerProxy;\n\n/**\n * @deprecated Rename to intlayerProxy instead\n *\n * A Vite plugin that integrates a logic similar to the Next.js intlayer middleware.\n *\n * ```ts\n * // Example usage of the plugin in a Vite configuration\n * export default defineConfig({\n * plugins: [ intlayerMiddleware() ],\n * });\n * ```\n */\nexport const intLayerMiddlewarePlugin = intlayerProxy;\n"],"mappings":";;;;;;;;;AAqBA,MAAM,oBAAoB;;;;;;AAO1B,MAAM,4BAA4B;;;;;;;;;;;;;;;;;;;;;;;AAkElC,MAAa,8BACX,YAEA,mBAAmB;CACjB,eAAe,iBAAiB,SAAS,aAAa;CACtD,QAAQ,SAAS;CACjB,aAAa,SAAS,eAAe;AACvC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDH,MAAa,2BACX,WACA,SAA+B,kBAE/B,cAAc,OAAO,IAAI,IAAI,8BAA8B,SAAS,CAAC,CAAC;AAExE,MAAa,iBAAiB,YAAiD;CAG7E,MAAM,UAAU,2BAA2B;EAAE,GAAG;EAAS,aAAa;CAAK,CAAC;CAC5E,MAAM,iBAAiB,iBAAiB,SAAS,aAAa;CAC9D,MAAM,SAAS,aAAa,cAAc;CAG1C,MAAM,4BAA4B,CAAC,4BACjC,iBAAiB,eAAe,QAAQ,WAAW,GACnD,IACF;;;;;CAMA,MAAM,wBACJ,OAAO,0BAA0B,yBAAyB,GAAG,EAC3D,OAAO,OACT,CAAC;CAKH,MAAM,QAAQ,2BAA2B,iBAAiB;CAK1D,IAAI,wBAAwB;CAgD5B,MAAM,SAAS;EACb,MAAM;EAEN,iBAAiB,WAAqD;GACpE,MAAM,QAAQ,MAAM;GACpB,wBAAwB,OAAO,QAAQ,MACpC,qBACC,iBAAiB,SAAS,yBAC9B;EACF;EAIA,OAAO;GA/CP,MAAM;GACN,MAAM,OASH;IAKD,IAAI,MAAM,QAAQ,KAAK;IAEvB,MAAM,cAAc,wBAAwB,YAAY,GAAG;IAO3D,IAH0B,MAAM,QAAQ,SAAS,MAC9C,oBAAoB,gBAAgB,YAAY,WAE/B,GAAG;IAEvB,MAAM,QAAQ,SAAS,KAAK;KAC1B,OAAO;KACP,SAAS;KACT,YAAY;IACd,CAAC;GACH;EAgBiB;EAEjB,kBAAkB,WAAW;GAC3B,IAAI,CAAC,MAAM,WAAW;GACtB,gBAAgB;GAChB,OAAO,YAAY,IAAI,OAAO;EAChC;EAEA,yBAAyB,WAAW;GAClC,IAAI,CAAC,MAAM,WAAW;GAQtB,IAAI,uBAAuB;GAC3B,gBAAgB;GAChB,OAAO,YAAY,IAAI,OAAO;EAChC;CACF;CAIA,MAAM,UAAU,MAAM;CAEtB,OAAO;AACT;;;;;;;;;;;;;AAcA,MAAa,qBAAqB;;;;;;;;;;;;;AAclC,MAAa,2BAA2B"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import { IntlayerCompilerOptions, intlayerCompiler } from "./IntlayerCompilerPlu
|
|
|
2
2
|
import { ChunkingContext, DictionaryModule, ModuleGraphNode, createDictionaryModuleParser, intlayerChunk, resolveBoundaries, toBoundaryName } from "./intlayerChunkPlugin.js";
|
|
3
3
|
import { intlayerMinify } from "./intlayerMinifyPlugin.js";
|
|
4
4
|
import { intlayerOptimize } from "./intlayerOptimizePlugin.js";
|
|
5
|
-
import { IntlayerProxyPluginOptions, createIntlayerProxyHandler, intLayerMiddlewarePlugin, intlayerMiddleware, intlayerProxy } from "./intlayerProxyPlugin.js";
|
|
5
|
+
import { IntlayerProxyPluginOptions, createIntlayerProxyHandler, intLayerMiddlewarePlugin, intlayerMiddleware, intlayerProxy, resolveNitroHandlerPath } from "./intlayerProxyPlugin.js";
|
|
6
6
|
import { INTLAYER_NO_EXTERNAL_PATTERN, IntlayerPluginOptions, intLayerPlugin, intlayer, intlayerPlugin } from "./intlayerPlugin.js";
|
|
7
7
|
import { intlayerPreload } from "./intlayerPreloadPlugin.js";
|
|
8
8
|
import { intlayerPrune } from "./intlayerPrunePlugin.js";
|
|
9
|
-
export { ChunkingContext, DictionaryModule, INTLAYER_NO_EXTERNAL_PATTERN, IntlayerCompilerOptions, IntlayerPluginOptions, IntlayerProxyPluginOptions, ModuleGraphNode, createDictionaryModuleParser, createIntlayerProxyHandler, intLayerMiddlewarePlugin, intLayerPlugin, intlayer, intlayerChunk, intlayerCompiler, intlayerMiddleware, intlayerMinify, intlayerOptimize, intlayerPlugin, intlayerPreload, intlayerProxy, intlayerPrune, resolveBoundaries, toBoundaryName };
|
|
9
|
+
export { ChunkingContext, DictionaryModule, INTLAYER_NO_EXTERNAL_PATTERN, IntlayerCompilerOptions, IntlayerPluginOptions, IntlayerProxyPluginOptions, ModuleGraphNode, createDictionaryModuleParser, createIntlayerProxyHandler, intLayerMiddlewarePlugin, intLayerPlugin, intlayer, intlayerChunk, intlayerCompiler, intlayerMiddleware, intlayerMinify, intlayerOptimize, intlayerPlugin, intlayerPreload, intlayerProxy, intlayerPrune, resolveBoundaries, resolveNitroHandlerPath, toBoundaryName };
|
|
@@ -108,6 +108,16 @@ export declare const createIntlayerProxyHandler: (options?: IntlayerProxyPluginO
|
|
|
108
108
|
*
|
|
109
109
|
* @deprecated Since Intlayer v9, `intlayerProxy()` is bundled directly into the `intlayer()` plugin and enabled by default through the `routing.enableProxy` option (unset by default, which selects auto mode). Registering it separately as shown below is now optional.
|
|
110
110
|
*/
|
|
111
|
+
/**
|
|
112
|
+
* Absolute path of the built Nitro middleware, relative to this module.
|
|
113
|
+
*
|
|
114
|
+
* Nitro inlines the path as an import specifier in its virtual routing module,
|
|
115
|
+
* so Windows backslashes must become forward slashes or the import breaks.
|
|
116
|
+
*
|
|
117
|
+
* @param moduleUrl - `import.meta.url` of the calling module
|
|
118
|
+
* @param toPath - `file:` URL to path converter (overridable for tests)
|
|
119
|
+
*/
|
|
120
|
+
export declare const resolveNitroHandlerPath: (moduleUrl: string, toPath?: (url: URL) => string) => string;
|
|
111
121
|
export declare const intlayerProxy: (options?: IntlayerProxyPluginOptions) => Plugin;
|
|
112
122
|
/**
|
|
113
123
|
* @deprecated Rename to intlayerProxy instead
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerProxyPlugin.d.ts","names":[],"sources":["../../src/intlayerProxyPlugin.ts"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"intlayerProxyPlugin.d.ts","names":[],"sources":["../../src/intlayerProxyPlugin.ts"],"mappings":";;;;;YA8BY;;;;;;;;;;;;;;EAcV,UAAU,KAAK;;;;;;;;;;;EAWf,gBAAgB;;;;;;;;;;;;;;EAchB;;;;;;;;;;;;;;;;;;;;;;;;qBAyBW,6BAA0B,UAC3B,+BACT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAyDU,0BAAuB,mBACjB,UACR,KAAK;qBAIH,gBAAa,UAAc,+BAA6B;;;;;;;;;;;;;qBAqIxD,2BAAkB;;;;;;;;;;;;;qBAclB,iCAAwB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vite-intlayer",
|
|
3
|
-
"version": "9.5.
|
|
3
|
+
"version": "9.5.5",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "A Vite plugin for seamless internationalization (i18n), providing locale detection, redirection, and environment-based configuration",
|
|
6
6
|
"keywords": [
|
|
@@ -82,12 +82,12 @@
|
|
|
82
82
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
83
83
|
},
|
|
84
84
|
"dependencies": {
|
|
85
|
-
"@intlayer/babel": "9.5.
|
|
86
|
-
"@intlayer/config": "9.5.
|
|
87
|
-
"@intlayer/core": "9.5.
|
|
88
|
-
"@intlayer/dictionaries-entry": "9.5.
|
|
89
|
-
"@intlayer/engine": "9.5.
|
|
90
|
-
"@intlayer/types": "9.5.
|
|
85
|
+
"@intlayer/babel": "9.5.5",
|
|
86
|
+
"@intlayer/config": "9.5.5",
|
|
87
|
+
"@intlayer/core": "9.5.5",
|
|
88
|
+
"@intlayer/dictionaries-entry": "9.5.5",
|
|
89
|
+
"@intlayer/engine": "9.5.5",
|
|
90
|
+
"@intlayer/types": "9.5.5"
|
|
91
91
|
},
|
|
92
92
|
"devDependencies": {
|
|
93
93
|
"@types/node": "^22",
|
|
@@ -101,8 +101,8 @@
|
|
|
101
101
|
},
|
|
102
102
|
"peerDependencies": {
|
|
103
103
|
"@babel/core": ">=6.0.0",
|
|
104
|
-
"@intlayer/svelte-compiler": "9.5.
|
|
105
|
-
"@intlayer/vue-compiler": "9.5.
|
|
104
|
+
"@intlayer/svelte-compiler": "9.5.5",
|
|
105
|
+
"@intlayer/vue-compiler": "9.5.5",
|
|
106
106
|
"h3": ">=1.0.0",
|
|
107
107
|
"vite": ">=4.0.0"
|
|
108
108
|
},
|