next-intlayer 7.0.0-canary.2 → 7.0.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/dist/cjs/client/useLocale.cjs +10 -2
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/proxy/intlayerProxy.cjs +62 -42
- package/dist/cjs/proxy/intlayerProxy.cjs.map +1 -1
- package/dist/cjs/proxy/multipleProxies.cjs +4 -4
- package/dist/cjs/proxy/multipleProxies.cjs.map +1 -1
- package/dist/cjs/server/withIntlayer.cjs +3 -4
- package/dist/cjs/server/withIntlayer.cjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +11 -3
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/proxy/intlayerProxy.mjs +62 -43
- package/dist/esm/proxy/intlayerProxy.mjs.map +1 -1
- package/dist/esm/proxy/multipleProxies.mjs +4 -4
- package/dist/esm/proxy/multipleProxies.mjs.map +1 -1
- package/dist/esm/server/withIntlayer.mjs +4 -5
- package/dist/esm/server/withIntlayer.mjs.map +1 -1
- package/dist/types/client/useLocale.d.ts +4 -4
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/generateStaticParams.d.ts +2 -2
- package/dist/types/generateStaticParams.d.ts.map +1 -1
- package/dist/types/proxy/intlayerProxy.d.ts.map +1 -1
- package/dist/types/server/withIntlayer.d.ts.map +1 -1
- package/package.json +21 -18
- package/dist/cjs/middleware/index.cjs +0 -7
- package/dist/cjs/middleware/intlayerMiddleware.cjs +0 -227
- package/dist/cjs/middleware/intlayerMiddleware.cjs.map +0 -1
- package/dist/cjs/middleware/localeDetector.cjs +0 -21
- package/dist/cjs/middleware/localeDetector.cjs.map +0 -1
- package/dist/cjs/middleware/multipleMiddlewares.cjs +0 -58
- package/dist/cjs/middleware/multipleMiddlewares.cjs.map +0 -1
- package/dist/cjs/proxy/multipleProxy.cjs +0 -60
- package/dist/cjs/proxy/multipleProxy.cjs.map +0 -1
- package/dist/esm/middleware/index.mjs +0 -5
- package/dist/esm/middleware/intlayerMiddleware.mjs +0 -223
- package/dist/esm/middleware/intlayerMiddleware.mjs.map +0 -1
- package/dist/esm/middleware/localeDetector.mjs +0 -19
- package/dist/esm/middleware/localeDetector.mjs.map +0 -1
- package/dist/esm/middleware/multipleMiddlewares.mjs +0 -56
- package/dist/esm/middleware/multipleMiddlewares.mjs.map +0 -1
- package/dist/esm/proxy/multipleProxy.mjs +0 -57
- package/dist/esm/proxy/multipleProxy.mjs.map +0 -1
- package/dist/types/middleware/index.d.ts +0 -4
- package/dist/types/middleware/intlayerMiddleware.d.ts +0 -31
- package/dist/types/middleware/intlayerMiddleware.d.ts.map +0 -1
- package/dist/types/middleware/localeDetector.d.ts +0 -14
- package/dist/types/middleware/localeDetector.d.ts.map +0 -1
- package/dist/types/middleware/multipleMiddlewares.d.ts +0 -33
- package/dist/types/middleware/multipleMiddlewares.d.ts.map +0 -1
- package/dist/types/proxy/multipleProxy.d.ts +0 -34
- package/dist/types/proxy/multipleProxy.d.ts.map +0 -1
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { localeDetector as localeDetector$1 } from "./localeDetector.mjs";
|
|
2
2
|
import configuration from "@intlayer/config/built";
|
|
3
|
-
import { getLocaleFromStorage } from "@intlayer/core";
|
|
3
|
+
import { getLocaleFromStorage, setLocaleInStorage } from "@intlayer/core";
|
|
4
|
+
import { DefaultValues } from "@intlayer/config";
|
|
4
5
|
import { NextResponse } from "next/server";
|
|
5
6
|
|
|
6
7
|
//#region src/proxy/intlayerProxy.ts
|
|
7
8
|
const { internationalization, routing } = configuration ?? {};
|
|
8
9
|
const { locales, defaultLocale } = internationalization ?? {};
|
|
9
|
-
const {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
10
|
+
const { basePath, mode } = routing ?? {};
|
|
11
|
+
const effectiveMode = mode ?? DefaultValues.Routing.ROUTING_MODE;
|
|
12
|
+
const noPrefix = effectiveMode === "no-prefix" || effectiveMode === "search-params";
|
|
13
|
+
const prefixDefault = effectiveMode === "prefix-all";
|
|
12
14
|
/**
|
|
13
15
|
* Detects if the request is a prefetch request from Next.js.
|
|
14
16
|
*
|
|
@@ -31,7 +33,7 @@ const isPrefetchRequest = (request) => {
|
|
|
31
33
|
return purpose === "prefetch" || nextRouterPrefetch === "1" || !!nextUrl || !!xNextjsData;
|
|
32
34
|
};
|
|
33
35
|
const appendLocaleSearchIfNeeded = (search, locale) => {
|
|
34
|
-
if (
|
|
36
|
+
if (effectiveMode !== "search-params") return search;
|
|
35
37
|
const params = new URLSearchParams(search ?? "");
|
|
36
38
|
params.set("locale", locale);
|
|
37
39
|
return `?${params.toString()}`;
|
|
@@ -61,10 +63,9 @@ const appendLocaleSearchIfNeeded = (search, locale) => {
|
|
|
61
63
|
*/
|
|
62
64
|
const intlayerProxy = (request, _event, _response) => {
|
|
63
65
|
const pathname = request.nextUrl.pathname;
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return handlePrefix(request, cookieLocale, getPathLocale(pathname), pathname, basePathTrailingSlash);
|
|
66
|
+
const localLocale = getLocalLocale(request);
|
|
67
|
+
if (noPrefix) return handleNoPrefix(request, localLocale, pathname);
|
|
68
|
+
return handlePrefix(request, localLocale, getPathLocale(pathname), pathname);
|
|
68
69
|
};
|
|
69
70
|
/**
|
|
70
71
|
* Retrieves the locale from the request cookies if available and valid.
|
|
@@ -72,19 +73,34 @@ const intlayerProxy = (request, _event, _response) => {
|
|
|
72
73
|
* @param request - The incoming Next.js request object.
|
|
73
74
|
* @returns - The locale found in the cookies, or undefined if not found or invalid.
|
|
74
75
|
*/
|
|
75
|
-
const
|
|
76
|
+
const getLocalLocale = (request) => getLocaleFromStorage({
|
|
77
|
+
getCookie: (name) => request.cookies.get(name)?.value ?? null,
|
|
78
|
+
getHeader: (name) => request.headers.get(name) ?? null
|
|
79
|
+
});
|
|
76
80
|
/**
|
|
77
81
|
* Handles the case where URLs do not have locale prefixes.
|
|
78
82
|
*
|
|
79
83
|
* @param request - The incoming Next.js request object.
|
|
80
|
-
* @param
|
|
84
|
+
* @param localLocale - The locale from the cookie.
|
|
81
85
|
* @param pathname - The pathname from the request URL.
|
|
82
|
-
* @param basePathTrailingSlash - Indicates if the basePath ends with a slash.
|
|
83
86
|
* @returns - The rewritten response with the locale applied.
|
|
84
87
|
*/
|
|
85
|
-
const handleNoPrefix = (request,
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
+
const handleNoPrefix = (request, localLocale, pathname) => {
|
|
89
|
+
const pathLocale = getPathLocale(pathname);
|
|
90
|
+
if (pathLocale) {
|
|
91
|
+
const pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) || "/";
|
|
92
|
+
const search$1 = appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale);
|
|
93
|
+
return redirectUrl(request, search$1 ? `${pathWithoutLocale}${search$1}` : `${pathWithoutLocale}${request.nextUrl.search ?? ""}`);
|
|
94
|
+
}
|
|
95
|
+
const locale = localLocale ?? defaultLocale;
|
|
96
|
+
if (effectiveMode === "search-params") {
|
|
97
|
+
if (new URLSearchParams(request.nextUrl.search).get("locale") === locale) return rewriteUrl(request, `${`/${locale}${pathname}`}${request.nextUrl.search ?? ""}`, locale);
|
|
98
|
+
const search$1 = appendLocaleSearchIfNeeded(request.nextUrl.search, locale);
|
|
99
|
+
return redirectUrl(request, search$1 ? `${pathname}${search$1}` : `${pathname}${request.nextUrl.search ?? ""}`);
|
|
100
|
+
}
|
|
101
|
+
const internalPath = `/${locale}${pathname}`;
|
|
102
|
+
const search = appendLocaleSearchIfNeeded(request.nextUrl.search, locale);
|
|
103
|
+
return rewriteUrl(request, search ? `${internalPath}${search}` : `${internalPath}${request.nextUrl.search ?? ""}`, locale);
|
|
88
104
|
};
|
|
89
105
|
/**
|
|
90
106
|
* Extracts the locale from the URL pathname if present.
|
|
@@ -97,47 +113,46 @@ const getPathLocale = (pathname) => locales.find((locale) => pathname.startsWith
|
|
|
97
113
|
* Handles the case where URLs have locale prefixes.
|
|
98
114
|
*
|
|
99
115
|
* @param request - The incoming Next.js request object.
|
|
100
|
-
* @param
|
|
116
|
+
* @param localLocale - The locale from the cookie.
|
|
101
117
|
* @param pathLocale - The locale extracted from the pathname.
|
|
102
118
|
* @param pathname - The pathname from the request URL.
|
|
103
119
|
* @param basePathTrailingSlash - Indicates if the basePath ends with a slash.
|
|
104
120
|
* @returns - The response to be returned to the client.
|
|
105
121
|
*/
|
|
106
|
-
const handlePrefix = (request,
|
|
122
|
+
const handlePrefix = (request, localLocale, pathLocale, pathname) => {
|
|
107
123
|
if (!pathLocale) {
|
|
108
|
-
if (isPrefetchRequest(request) &&
|
|
109
|
-
return handleMissingPathLocale(request,
|
|
124
|
+
if (isPrefetchRequest(request) && true) return handleMissingPathLocale(request, defaultLocale, pathname);
|
|
125
|
+
return handleMissingPathLocale(request, localLocale, pathname);
|
|
110
126
|
}
|
|
111
|
-
return handleExistingPathLocale(request,
|
|
127
|
+
return handleExistingPathLocale(request, localLocale, pathLocale, pathname);
|
|
112
128
|
};
|
|
113
129
|
/**
|
|
114
130
|
* Handles requests where the locale is missing from the URL pathname.
|
|
115
131
|
*
|
|
116
132
|
* @param request - The incoming Next.js request object.
|
|
117
|
-
* @param
|
|
133
|
+
* @param localLocale - The locale from the cookie.
|
|
118
134
|
* @param pathname - The pathname from the request URL.
|
|
119
135
|
* @param basePathTrailingSlash - Indicates if the basePath ends with a slash.
|
|
120
136
|
* @returns - The response to be returned to the client.
|
|
121
137
|
*/
|
|
122
|
-
const handleMissingPathLocale = (request,
|
|
123
|
-
let locale =
|
|
138
|
+
const handleMissingPathLocale = (request, localLocale, pathname) => {
|
|
139
|
+
let locale = localLocale ?? localeDetector$1?.(request) ?? defaultLocale;
|
|
124
140
|
if (!locales.includes(locale)) locale = defaultLocale;
|
|
125
|
-
const newPath = constructPath(locale, pathname, basePath,
|
|
141
|
+
const newPath = constructPath(locale, pathname, basePath, appendLocaleSearchIfNeeded(request.nextUrl.search, locale));
|
|
126
142
|
return prefixDefault || locale !== defaultLocale ? redirectUrl(request, newPath) : rewriteUrl(request, newPath, locale);
|
|
127
143
|
};
|
|
128
144
|
/**
|
|
129
145
|
* Handles requests where the locale exists in the URL pathname.
|
|
130
146
|
*
|
|
131
147
|
* @param request - The incoming Next.js request object.
|
|
132
|
-
* @param
|
|
148
|
+
* @param localLocale - The locale from the cookie.
|
|
133
149
|
* @param pathLocale - The locale extracted from the pathname.
|
|
134
150
|
* @param pathname - The pathname from the request URL.
|
|
135
|
-
* @param basePathTrailingSlash - Indicates if the basePath ends with a slash.
|
|
136
151
|
* @returns - The response to be returned to the client.
|
|
137
152
|
*/
|
|
138
|
-
const handleExistingPathLocale = (request,
|
|
139
|
-
if (
|
|
140
|
-
return handleDefaultLocaleRedirect(request, pathLocale, pathname
|
|
153
|
+
const handleExistingPathLocale = (request, localLocale, pathLocale, pathname) => {
|
|
154
|
+
if (localLocale && localLocale !== pathLocale) return redirectUrl(request, handleCookieLocaleMismatch(request, pathname, pathLocale, localLocale, basePath));
|
|
155
|
+
return handleDefaultLocaleRedirect(request, pathLocale, pathname);
|
|
141
156
|
};
|
|
142
157
|
/**
|
|
143
158
|
* Handles the scenario where the locale in the cookie does not match the locale in the URL pathname.
|
|
@@ -145,13 +160,12 @@ const handleExistingPathLocale = (request, cookieLocale, pathLocale, pathname, b
|
|
|
145
160
|
* @param request - The incoming Next.js request object.
|
|
146
161
|
* @param pathname - The pathname from the request URL.
|
|
147
162
|
* @param pathLocale - The locale extracted from the pathname.
|
|
148
|
-
* @param
|
|
163
|
+
* @param localLocale - The locale from the cookie.
|
|
149
164
|
* @param basePath - The base path of the application.
|
|
150
|
-
* @param basePathTrailingSlash - Indicates if the basePath ends with a slash.
|
|
151
165
|
* @returns - The new URL path with the correct locale.
|
|
152
166
|
*/
|
|
153
|
-
const handleCookieLocaleMismatch = (request, pathname, pathLocale,
|
|
154
|
-
return constructPath(
|
|
167
|
+
const handleCookieLocaleMismatch = (request, pathname, pathLocale, localLocale, basePath$1) => {
|
|
168
|
+
return constructPath(localLocale, pathname.replace(`/${pathLocale}`, `/${localLocale}`), basePath$1, appendLocaleSearchIfNeeded(request.nextUrl.search, localLocale));
|
|
155
169
|
};
|
|
156
170
|
/**
|
|
157
171
|
* Handles redirection when the default locale is used and prefixing is not required.
|
|
@@ -159,13 +173,12 @@ const handleCookieLocaleMismatch = (request, pathname, pathLocale, cookieLocale,
|
|
|
159
173
|
* @param request - The incoming Next.js request object.
|
|
160
174
|
* @param pathLocale - The locale extracted from the pathname.
|
|
161
175
|
* @param pathname - The pathname from the request URL.
|
|
162
|
-
* @param basePathTrailingSlash - Indicates if the basePath ends with a slash.
|
|
163
176
|
* @returns - The rewritten response without the locale prefix.
|
|
164
177
|
*/
|
|
165
|
-
const handleDefaultLocaleRedirect = (request, pathLocale, pathname
|
|
178
|
+
const handleDefaultLocaleRedirect = (request, pathLocale, pathname) => {
|
|
166
179
|
if (!prefixDefault && pathLocale === defaultLocale) {
|
|
167
180
|
let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) ?? "/";
|
|
168
|
-
if (
|
|
181
|
+
if (basePath.endsWith("/")) pathWithoutLocale = pathWithoutLocale.slice(1);
|
|
169
182
|
const searchWithLocale$1 = appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale);
|
|
170
183
|
if (searchWithLocale$1) pathWithoutLocale += searchWithLocale$1;
|
|
171
184
|
else if (request.nextUrl.search) pathWithoutLocale += request.nextUrl.search;
|
|
@@ -180,15 +193,21 @@ const handleDefaultLocaleRedirect = (request, pathLocale, pathname, basePathTrai
|
|
|
180
193
|
* @param locale - The locale to include in the path.
|
|
181
194
|
* @param path - The original path from the request.
|
|
182
195
|
* @param basePath - The base path of the application.
|
|
183
|
-
* @param basePathTrailingSlash - Indicates if the basePath ends with a slash.
|
|
184
196
|
* @param [search] - The query string from the request URL (optional).
|
|
185
197
|
* @returns - The constructed new path.
|
|
186
198
|
*/
|
|
187
|
-
const constructPath = (locale, path, basePath$1,
|
|
188
|
-
const
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
199
|
+
const constructPath = (locale, path, basePath$1, search) => {
|
|
200
|
+
const pathWithoutPrefix = path.startsWith(`/${locale}`) ? path.slice(`/${locale}`.length) || "/" : path;
|
|
201
|
+
if (effectiveMode === "no-prefix") {
|
|
202
|
+
if (search) return `${pathWithoutPrefix}?${search}`;
|
|
203
|
+
return pathWithoutPrefix;
|
|
204
|
+
}
|
|
205
|
+
if (effectiveMode === "search-params") {
|
|
206
|
+
if (search) return `${pathWithoutPrefix}?${search}`;
|
|
207
|
+
return pathWithoutPrefix;
|
|
208
|
+
}
|
|
209
|
+
const pathWithLocalePrefix = path.startsWith(`/${locale}`) ? path : `${locale}${path}`;
|
|
210
|
+
return `${basePath$1}${basePath$1.endsWith("/") ? "" : "/"}${pathWithLocalePrefix}`;
|
|
192
211
|
};
|
|
193
212
|
/**
|
|
194
213
|
* Rewrites the URL to the new path and sets the locale header.
|
|
@@ -202,7 +221,7 @@ const rewriteUrl = (request, newPath, locale) => {
|
|
|
202
221
|
const search = request.nextUrl.search;
|
|
203
222
|
const pathWithSearch = search && !newPath.includes("?") ? `${newPath}${search}` : newPath;
|
|
204
223
|
const response = NextResponse.rewrite(new URL(pathWithSearch, request.url));
|
|
205
|
-
response.headers.set(
|
|
224
|
+
setLocaleInStorage(locale, { setHeader: (name, value) => response.headers.set(name, value) });
|
|
206
225
|
return response;
|
|
207
226
|
};
|
|
208
227
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerProxy.mjs","names":["localeDetector","basePath","searchWithLocale"],"sources":["../../../src/proxy/intlayerProxy.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { getLocaleFromStorage } from '@intlayer/core';\nimport type { Locale } from '@intlayer/types';\nimport {\n type NextFetchEvent,\n type NextRequest,\n NextResponse,\n} from 'next/server';\nimport { localeDetector } from './localeDetector';\n\nconst { internationalization, routing } = configuration ?? {};\nconst { locales, defaultLocale } = internationalization ?? {};\nconst { headerName, basePath, detectLocaleOnPrefetchNoPrefix, mode } =\n routing ?? {};\n// Note: cookie names are resolved inside LocaleStorage based on configuration\n\n// Derived flags from routing.mode\nconst noPrefix = mode === 'no-prefix' || mode === 'search-params';\nconst prefixDefault = mode === 'prefix-all';\n\n/**\n * Detects if the request is a prefetch request from Next.js.\n *\n * Next.js prefetch requests can be identified by several headers:\n * - purpose: 'prefetch' (standard prefetch header)\n * - next-router-prefetch: '1' (Next.js router prefetch)\n * - next-url: present (Next.js internal navigation)\n *\n * During prefetch, we should ignore cookie-based locale detection\n * to prevent unwanted redirects when users are switching locales.\n *\n * @param request - The incoming Next.js request object.\n * @returns - True if the request is a prefetch request, false otherwise.\n */\nconst isPrefetchRequest = (request: NextRequest): boolean => {\n const purpose = request.headers.get('purpose');\n const nextRouterPrefetch = request.headers.get('next-router-prefetch');\n const nextUrl = request.headers.get('next-url');\n const xNextjsData = request.headers.get('x-nextjs-data');\n\n return (\n purpose === 'prefetch' ||\n nextRouterPrefetch === '1' ||\n !!nextUrl ||\n !!xNextjsData\n );\n};\n\n// Ensure locale is reflected in search params when routing mode is 'search-params'\nconst appendLocaleSearchIfNeeded = (\n search: string | undefined,\n locale: Locale\n): string | undefined => {\n if (mode !== 'search-params') return search;\n\n const params = new URLSearchParams(search ?? '');\n\n params.set('locale', locale);\n return `?${params.toString()}`;\n};\n\n/**\n * Proxy that handles the internationalization layer\n *\n * Usage:\n *\n * ```ts\n * // ./src/proxy.ts\n *\n * export { intlayerProxy as proxy } from '@intlayer/next/proxy';\n *\n * // applies this proxy only to files in the app directory\n * export const config = {\n * matcher: '/((?!api|static|.*\\\\..*|_next).*)',\n * };\n * ```\n *\n * Main proxy function for handling internationalization.\n *\n * @param request - The incoming Next.js request object.\n * @param event - The Next.js fetch event (optional).\n * @param response - The Next.js response object (optional).\n * @returns - The response to be returned to the client.\n */\nexport const intlayerProxy = (\n request: NextRequest,\n _event?: NextFetchEvent,\n _response?: NextResponse\n): NextResponse => {\n const pathname = request.nextUrl.pathname;\n\n const cookieLocale = getCookieLocale(request);\n const basePathTrailingSlash = basePath.endsWith('/');\n\n if (\n noPrefix // If the application is configured not to use locale prefixes in URLs\n ) {\n return handleNoPrefix(\n request,\n cookieLocale,\n pathname,\n basePathTrailingSlash\n );\n }\n\n const pathLocale = getPathLocale(pathname);\n\n return handlePrefix(\n request,\n cookieLocale,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\n};\n\n/**\n * Retrieves the locale from the request cookies if available and valid.\n *\n * @param request - The incoming Next.js request object.\n * @returns - The locale found in the cookies, or undefined if not found or invalid.\n */\nconst getCookieLocale = (request: NextRequest): Locale | undefined =>\n getLocaleFromStorage({\n getCookie: (name: string) => request.cookies.get(name)?.value ?? null,\n });\n\n/**\n * Handles the case where URLs do not have locale prefixes.\n *\n * @param request - The incoming Next.js request object.\n * @param cookieLocale - The locale from the cookie.\n * @param pathname - The pathname from the request URL.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The rewritten response with the locale applied.\n */\nconst handleNoPrefix = (\n request: NextRequest,\n cookieLocale: Locale | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n const locale = cookieLocale ?? defaultLocale;\n\n const newPath = constructPath(\n locale,\n pathname,\n basePath,\n basePathTrailingSlash,\n appendLocaleSearchIfNeeded(request.nextUrl.search, locale)\n );\n return rewriteUrl(request, newPath, locale);\n};\n\n/**\n * Extracts the locale from the URL pathname if present.\n *\n * @param pathname - The pathname from the request URL.\n * @returns - The locale found in the pathname, or undefined if not found.\n */\nconst getPathLocale = (pathname: string): Locale | undefined =>\n locales.find(\n (locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`\n );\n\n/**\n * Handles the case where URLs have locale prefixes.\n *\n * @param request - The incoming Next.js request object.\n * @param cookieLocale - The locale from the cookie.\n * @param pathLocale - The locale extracted from the pathname.\n * @param pathname - The pathname from the request URL.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The response to be returned to the client.\n */\nconst handlePrefix = (\n request: NextRequest,\n cookieLocale: Locale | undefined,\n pathLocale: Locale | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\n !pathLocale // If the URL does not contain a locale prefix\n ) {\n const isPrefetch = isPrefetchRequest(request);\n\n if (isPrefetch && !detectLocaleOnPrefetchNoPrefix) {\n return handleMissingPathLocale(\n request,\n defaultLocale,\n pathname,\n basePathTrailingSlash\n );\n }\n\n return handleMissingPathLocale(\n request,\n cookieLocale,\n pathname,\n basePathTrailingSlash\n );\n }\n\n // If the URL contains a locale prefix\n return handleExistingPathLocale(\n request,\n cookieLocale,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\n};\n\n/**\n * Handles requests where the locale is missing from the URL pathname.\n *\n * @param request - The incoming Next.js request object.\n * @param cookieLocale - The locale from the cookie.\n * @param pathname - The pathname from the request URL.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The response to be returned to the client.\n */\nconst handleMissingPathLocale = (\n request: NextRequest,\n cookieLocale: Locale | undefined,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n let locale = (cookieLocale ??\n localeDetector?.(request) ??\n defaultLocale) as Locale;\n if (!locales.includes(locale)) {\n locale = defaultLocale;\n }\n\n const newPath = constructPath(\n locale,\n pathname,\n basePath,\n basePathTrailingSlash,\n appendLocaleSearchIfNeeded(request.nextUrl.search, locale)\n );\n\n return prefixDefault || locale !== defaultLocale\n ? redirectUrl(request, newPath)\n : rewriteUrl(request, newPath, locale);\n};\n\n/**\n * Handles requests where the locale exists in the URL pathname.\n *\n * @param request - The incoming Next.js request object.\n * @param cookieLocale - The locale from the cookie.\n * @param pathLocale - The locale extracted from the pathname.\n * @param pathname - The pathname from the request URL.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The response to be returned to the client.\n */\nconst handleExistingPathLocale = (\n request: NextRequest,\n cookieLocale: Locale | undefined,\n pathLocale: Locale,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\n // If the cookie locale is set and differs from the locale in the URL\n cookieLocale &&\n cookieLocale !== pathLocale\n ) {\n const newPath = handleCookieLocaleMismatch(\n request,\n pathname,\n pathLocale,\n cookieLocale,\n basePath,\n basePathTrailingSlash\n );\n return redirectUrl(request, newPath);\n }\n\n // If the cookie locale matches the path locale, or cookie locale is not set, or serverSetCookie is 'always'\n return handleDefaultLocaleRedirect(\n request,\n pathLocale,\n pathname,\n basePathTrailingSlash\n );\n};\n\n/**\n * Handles the scenario where the locale in the cookie does not match the locale in the URL pathname.\n *\n * @param request - The incoming Next.js request object.\n * @param pathname - The pathname from the request URL.\n * @param pathLocale - The locale extracted from the pathname.\n * @param cookieLocale - The locale from the cookie.\n * @param basePath - The base path of the application.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The new URL path with the correct locale.\n */\nconst handleCookieLocaleMismatch = (\n request: NextRequest,\n pathname: string,\n pathLocale: Locale,\n cookieLocale: Locale,\n basePath: string,\n basePathTrailingSlash: boolean\n): string => {\n // Replace the pathLocale in the pathname with the cookieLocale\n const newPath = pathname.replace(`/${pathLocale}`, `/${cookieLocale}`);\n\n return constructPath(\n cookieLocale,\n newPath,\n basePath,\n basePathTrailingSlash,\n appendLocaleSearchIfNeeded(request.nextUrl.search, cookieLocale)\n );\n};\n\n/**\n * Handles redirection when the default locale is used and prefixing is not required.\n *\n * @param request - The incoming Next.js request object.\n * @param pathLocale - The locale extracted from the pathname.\n * @param pathname - The pathname from the request URL.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The rewritten response without the locale prefix.\n */\nconst handleDefaultLocaleRedirect = (\n request: NextRequest,\n pathLocale: Locale,\n pathname: string,\n basePathTrailingSlash: boolean\n): NextResponse => {\n if (\n // If default locale should not be prefixed and the pathLocale is the defaultLocale\n !prefixDefault &&\n pathLocale === defaultLocale\n ) {\n let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) ?? '/';\n\n if (basePathTrailingSlash) {\n pathWithoutLocale = pathWithoutLocale.slice(1);\n }\n\n const searchWithLocale = appendLocaleSearchIfNeeded(\n request.nextUrl.search,\n pathLocale\n );\n if (searchWithLocale) {\n pathWithoutLocale += searchWithLocale;\n } else if (request.nextUrl.search) {\n pathWithoutLocale += request.nextUrl.search;\n }\n\n return rewriteUrl(request, `${basePath}${pathWithoutLocale}`, pathLocale);\n }\n\n // If prefixing default locale is required or pathLocale is not the defaultLocale\n\n const searchWithLocale = appendLocaleSearchIfNeeded(\n request.nextUrl.search,\n pathLocale\n );\n const newPath = searchWithLocale\n ? `${pathname}${searchWithLocale}`\n : pathname;\n return rewriteUrl(request, newPath, pathLocale);\n};\n\n/**\n * Constructs a new path by combining the locale, path, basePath, and search parameters.\n *\n * @param locale - The locale to include in the path.\n * @param path - The original path from the request.\n * @param basePath - The base path of the application.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @param [search] - The query string from the request URL (optional).\n * @returns - The constructed new path.\n */\nconst constructPath = (\n locale: Locale,\n path: string,\n basePath: string,\n basePathTrailingSlash: boolean,\n search?: string\n): string => {\n // In 'search-params' mode, we do not prefix the path with the locale\n const pathWithLocalePrefix =\n mode === 'search-params' ? path : `${locale}${path}`;\n\n let newPath = `${basePath}${basePathTrailingSlash ? '' : '/'}${pathWithLocalePrefix}`;\n if (search) {\n newPath += search;\n }\n return newPath;\n};\n\n/**\n * Rewrites the URL to the new path and sets the locale header.\n *\n * @param request - The incoming Next.js request object.\n * @param newPath - The new path to rewrite to.\n * @param locale - The locale to set in the response header.\n * @returns - The rewritten response.\n */\nconst rewriteUrl = (\n request: NextRequest,\n newPath: string,\n locale: Locale\n): NextResponse => {\n // Ensure we preserve the original search params if they were present and not explicitly included in newPath\n const search = request.nextUrl.search;\n const pathWithSearch =\n search && !newPath.includes('?') ? `${newPath}${search}` : newPath;\n\n const response = NextResponse.rewrite(new URL(pathWithSearch, request.url));\n response.headers.set(headerName, locale);\n return response;\n};\n\n/**\n * Redirects the request to the new path.\n *\n * @param request - The incoming Next.js request object.\n * @param newPath - The new path to redirect to.\n * @returns - The redirect response.\n */\nconst redirectUrl = (request: NextRequest, newPath: string): NextResponse => {\n // Ensure we preserve the original search params if they were present and not explicitly included in newPath\n const search = request.nextUrl.search;\n const pathWithSearch =\n search && !newPath.includes('?') ? `${newPath}${search}` : newPath;\n\n return NextResponse.redirect(new URL(pathWithSearch, request.url));\n};\n\n/**\n * Middleware that handles the internationalization layer\n *\n * Usage:\n *\n * ```ts\n * // ./src/middleware.ts\n *\n * export { intlayerMiddleware as middleware } from '@intlayer/next/middleware';\n *\n * // applies this middleware only to files in the app directory\n * export const config = {\n * matcher: '/((?!api|static|.*\\\\..*|_next).*)',\n * };\n * ```\n *\n * Main middleware function for handling internationalization.\n *\n * @param request - The incoming Next.js request object.\n * @param event - The Next.js fetch event (optional).\n * @param response - The Next.js response object (optional).\n * @returns - The response to be returned to the client.\n */\nexport const intlayerMiddleware = intlayerProxy;\n"],"mappings":";;;;;;AAUA,MAAM,EAAE,sBAAsB,YAAY,iBAAiB,EAAE;AAC7D,MAAM,EAAE,SAAS,kBAAkB,wBAAwB,EAAE;AAC7D,MAAM,EAAE,YAAY,UAAU,gCAAgC,SAC5D,WAAW,EAAE;AAIf,MAAM,WAAW,SAAS,eAAe,SAAS;AAClD,MAAM,gBAAgB,SAAS;;;;;;;;;;;;;;;AAgB/B,MAAM,qBAAqB,YAAkC;CAC3D,MAAM,UAAU,QAAQ,QAAQ,IAAI,UAAU;CAC9C,MAAM,qBAAqB,QAAQ,QAAQ,IAAI,uBAAuB;CACtE,MAAM,UAAU,QAAQ,QAAQ,IAAI,WAAW;CAC/C,MAAM,cAAc,QAAQ,QAAQ,IAAI,gBAAgB;AAExD,QACE,YAAY,cACZ,uBAAuB,OACvB,CAAC,CAAC,WACF,CAAC,CAAC;;AAKN,MAAM,8BACJ,QACA,WACuB;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;;AAWT,MAAM,cACJ,SACA,SACA,WACiB;CAEjB,MAAM,SAAS,QAAQ,QAAQ;CAC/B,MAAM,iBACJ,UAAU,CAAC,QAAQ,SAAS,IAAI,GAAG,GAAG,UAAU,WAAW;CAE7D,MAAM,WAAW,aAAa,QAAQ,IAAI,IAAI,gBAAgB,QAAQ,IAAI,CAAC;AAC3E,UAAS,QAAQ,IAAI,YAAY,OAAO;AACxC,QAAO;;;;;;;;;AAUT,MAAM,eAAe,SAAsB,YAAkC;CAE3E,MAAM,SAAS,QAAQ,QAAQ;CAC/B,MAAM,iBACJ,UAAU,CAAC,QAAQ,SAAS,IAAI,GAAG,GAAG,UAAU,WAAW;AAE7D,QAAO,aAAa,SAAS,IAAI,IAAI,gBAAgB,QAAQ,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;AA0BpE,MAAa,qBAAqB"}
|
|
1
|
+
{"version":3,"file":"intlayerProxy.mjs","names":["search","localeDetector","basePath","searchWithLocale"],"sources":["../../../src/proxy/intlayerProxy.ts"],"sourcesContent":["import { DefaultValues } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport { getLocaleFromStorage, setLocaleInStorage } from '@intlayer/core';\nimport type { Locale } from '@intlayer/types';\nimport {\n type NextFetchEvent,\n type NextRequest,\n NextResponse,\n} from 'next/server';\nimport { localeDetector } from './localeDetector';\n\n/**\n * Controls whether locale detection occurs during Next.js prefetch requests\n * - true: Detect and apply locale during prefetch\n * - false: Use default locale during prefetch (recommended)\n *\n * This setting affects how Next.js handles locale prefetching:\n *\n * Example scenario:\n * - User's browser language is 'fr'\n * - Current page is /fr/about\n * - Link prefetches /about\n *\n * With `detectLocaleOnPrefetchNoPrefix:true`\n * - Prefetch detects 'fr' locale from browser\n * - Redirects prefetch to /fr/about\n *\n * With `detectLocaleOnPrefetchNoPrefix:false` (default)\n * - Prefetch uses default locale\n * - Redirects prefetch to /en/about (assuming 'en' is default)\n *\n * When to use true:\n * - Your app uses non-localized internal links (e.g. <a href=\"/about\">)\n * - You want consistent locale detection behavior between regular and prefetch requests\n *\n * When to use false (default):\n * - Your app uses locale-prefixed links (e.g. <a href=\"/fr/about\">)\n * - You want to optimize prefetching performance\n * - You want to avoid potential redirect loops\n */\nconst DEFAULT_DETECT_LOCALE_ON_PREFETCH_NO_PREFIX = false;\n\nconst { internationalization, routing } = configuration ?? {};\nconst { locales, defaultLocale } = internationalization ?? {};\nconst { basePath, mode } = routing ?? {};\n// Note: cookie names are resolved inside LocaleStorage based on configuration\n\n// Derived flags from routing.mode\nconst effectiveMode = mode ?? DefaultValues.Routing.ROUTING_MODE;\nconst noPrefix =\n effectiveMode === 'no-prefix' || effectiveMode === 'search-params';\nconst prefixDefault = effectiveMode === 'prefix-all';\n\n/**\n * Detects if the request is a prefetch request from Next.js.\n *\n * Next.js prefetch requests can be identified by several headers:\n * - purpose: 'prefetch' (standard prefetch header)\n * - next-router-prefetch: '1' (Next.js router prefetch)\n * - next-url: present (Next.js internal navigation)\n *\n * During prefetch, we should ignore cookie-based locale detection\n * to prevent unwanted redirects when users are switching locales.\n *\n * @param request - The incoming Next.js request object.\n * @returns - True if the request is a prefetch request, false otherwise.\n */\nconst isPrefetchRequest = (request: NextRequest): boolean => {\n const purpose = request.headers.get('purpose');\n const nextRouterPrefetch = request.headers.get('next-router-prefetch');\n const nextUrl = request.headers.get('next-url');\n const xNextjsData = request.headers.get('x-nextjs-data');\n\n return (\n purpose === 'prefetch' ||\n nextRouterPrefetch === '1' ||\n !!nextUrl ||\n !!xNextjsData\n );\n};\n\n// Ensure locale is reflected in search params when routing mode is 'search-params'\nconst appendLocaleSearchIfNeeded = (\n search: string | undefined,\n locale: Locale\n): string | undefined => {\n if (effectiveMode !== 'search-params') return search;\n\n const params = new URLSearchParams(search ?? '');\n\n params.set('locale', locale);\n\n return `?${params.toString()}`;\n};\n\n/**\n * Proxy that handles the internationalization layer\n *\n * Usage:\n *\n * ```ts\n * // ./src/proxy.ts\n *\n * export { intlayerProxy as proxy } from '@intlayer/next/proxy';\n *\n * // applies this proxy only to files in the app directory\n * export const config = {\n * matcher: '/((?!api|static|.*\\\\..*|_next).*)',\n * };\n * ```\n *\n * Main proxy function for handling internationalization.\n *\n * @param request - The incoming Next.js request object.\n * @param event - The Next.js fetch event (optional).\n * @param response - The Next.js response object (optional).\n * @returns - The response to be returned to the client.\n */\nexport const intlayerProxy = (\n request: NextRequest,\n _event?: NextFetchEvent,\n _response?: NextResponse\n): NextResponse => {\n const pathname = request.nextUrl.pathname;\n\n const localLocale = getLocalLocale(request);\n\n if (\n noPrefix // If the application is configured not to use locale prefixes in URLs\n ) {\n return handleNoPrefix(request, localLocale, pathname);\n }\n\n const pathLocale = getPathLocale(pathname);\n\n return handlePrefix(request, localLocale, pathLocale, pathname);\n};\n\n/**\n * Retrieves the locale from the request cookies if available and valid.\n *\n * @param request - The incoming Next.js request object.\n * @returns - The locale found in the cookies, or undefined if not found or invalid.\n */\nconst getLocalLocale = (request: NextRequest): Locale | undefined =>\n getLocaleFromStorage({\n getCookie: (name: string) => request.cookies.get(name)?.value ?? null,\n getHeader: (name: string) => request.headers.get(name) ?? null,\n });\n\n/**\n * Handles the case where URLs do not have locale prefixes.\n *\n * @param request - The incoming Next.js request object.\n * @param localLocale - The locale from the cookie.\n * @param pathname - The pathname from the request URL.\n * @returns - The rewritten response with the locale applied.\n */\nconst handleNoPrefix = (\n request: NextRequest,\n localLocale: Locale | undefined,\n pathname: string\n): NextResponse => {\n // Check if pathname has a locale prefix (even though we're in no-prefix mode)\n const pathLocale = getPathLocale(pathname);\n\n // If a locale prefix is detected in the URL, redirect to remove it\n if (pathLocale) {\n // Strip the locale prefix from the pathname\n const pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) || '/';\n\n // Build redirect URL without locale prefix but with search params if needed\n const search = appendLocaleSearchIfNeeded(\n request.nextUrl.search,\n pathLocale\n );\n const redirectPath = search\n ? `${pathWithoutLocale}${search}`\n : `${pathWithoutLocale}${request.nextUrl.search ?? ''}`;\n\n // Redirect to the path without locale prefix (URL changes in browser)\n return redirectUrl(request, redirectPath);\n }\n\n // If no locale prefix in URL, determine locale and rewrite internally\n const locale = localLocale ?? defaultLocale;\n\n // In search-params mode, we need to redirect to add the locale search param\n if (effectiveMode === 'search-params') {\n // Check if locale search param already exists and matches the detected locale\n const existingSearchParams = new URLSearchParams(request.nextUrl.search);\n const existingLocale = existingSearchParams.get('locale');\n\n // If the existing locale matches the detected locale, no redirect needed\n if (existingLocale === locale) {\n // For internal routing, we need to add the locale prefix so Next.js can match [locale] param\n const internalPath = `/${locale}${pathname}`;\n const rewritePath = `${internalPath}${request.nextUrl.search ?? ''}`;\n\n // Rewrite internally (URL stays the same in browser, but Next.js routes to /[locale]/path)\n return rewriteUrl(request, rewritePath, locale);\n }\n\n const search = appendLocaleSearchIfNeeded(request.nextUrl.search, locale);\n const redirectPath = search\n ? `${pathname}${search}`\n : `${pathname}${request.nextUrl.search ?? ''}`;\n\n // Redirect to add/update the locale search param (URL changes in browser)\n return redirectUrl(request, redirectPath);\n }\n\n // For internal routing, we need to add the locale prefix so Next.js can match [locale] param\n const internalPath = `/${locale}${pathname}`;\n\n // Add search params if needed\n const search = appendLocaleSearchIfNeeded(request.nextUrl.search, locale);\n const rewritePath = search\n ? `${internalPath}${search}`\n : `${internalPath}${request.nextUrl.search ?? ''}`;\n\n // Rewrite internally (URL stays the same in browser, but Next.js routes to /[locale]/path)\n return rewriteUrl(request, rewritePath, locale);\n};\n\n/**\n * Extracts the locale from the URL pathname if present.\n *\n * @param pathname - The pathname from the request URL.\n * @returns - The locale found in the pathname, or undefined if not found.\n */\nconst getPathLocale = (pathname: string): Locale | undefined =>\n locales.find(\n (locale) => pathname.startsWith(`/${locale}/`) || pathname === `/${locale}`\n );\n\n/**\n * Handles the case where URLs have locale prefixes.\n *\n * @param request - The incoming Next.js request object.\n * @param localLocale - The locale from the cookie.\n * @param pathLocale - The locale extracted from the pathname.\n * @param pathname - The pathname from the request URL.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The response to be returned to the client.\n */\nconst handlePrefix = (\n request: NextRequest,\n localLocale: Locale | undefined,\n pathLocale: Locale | undefined,\n pathname: string\n): NextResponse => {\n if (\n !pathLocale // If the URL does not contain a locale prefix\n ) {\n const isPrefetch = isPrefetchRequest(request);\n\n if (isPrefetch && !DEFAULT_DETECT_LOCALE_ON_PREFETCH_NO_PREFIX) {\n return handleMissingPathLocale(request, defaultLocale, pathname);\n }\n\n return handleMissingPathLocale(request, localLocale, pathname);\n }\n\n // If the URL contains a locale prefix\n return handleExistingPathLocale(request, localLocale, pathLocale, pathname);\n};\n\n/**\n * Handles requests where the locale is missing from the URL pathname.\n *\n * @param request - The incoming Next.js request object.\n * @param localLocale - The locale from the cookie.\n * @param pathname - The pathname from the request URL.\n * @param basePathTrailingSlash - Indicates if the basePath ends with a slash.\n * @returns - The response to be returned to the client.\n */\nconst handleMissingPathLocale = (\n request: NextRequest,\n localLocale: Locale | undefined,\n pathname: string\n): NextResponse => {\n let locale = (localLocale ??\n localeDetector?.(request) ??\n defaultLocale) as Locale;\n if (!locales.includes(locale)) {\n locale = defaultLocale;\n }\n\n const newPath = constructPath(\n locale,\n pathname,\n basePath,\n appendLocaleSearchIfNeeded(request.nextUrl.search, locale)\n );\n\n return prefixDefault || locale !== defaultLocale\n ? redirectUrl(request, newPath)\n : rewriteUrl(request, newPath, locale);\n};\n\n/**\n * Handles requests where the locale exists in the URL pathname.\n *\n * @param request - The incoming Next.js request object.\n * @param localLocale - The locale from the cookie.\n * @param pathLocale - The locale extracted from the pathname.\n * @param pathname - The pathname from the request URL.\n * @returns - The response to be returned to the client.\n */\nconst handleExistingPathLocale = (\n request: NextRequest,\n localLocale: Locale | undefined,\n pathLocale: Locale,\n pathname: string\n): NextResponse => {\n if (\n // If the cookie locale is set and differs from the locale in the URL\n localLocale &&\n localLocale !== pathLocale\n ) {\n const newPath = handleCookieLocaleMismatch(\n request,\n pathname,\n pathLocale,\n localLocale,\n basePath\n );\n return redirectUrl(request, newPath);\n }\n\n // If the cookie locale matches the path locale, or cookie locale is not set, or serverSetCookie is 'always'\n return handleDefaultLocaleRedirect(request, pathLocale, pathname);\n};\n\n/**\n * Handles the scenario where the locale in the cookie does not match the locale in the URL pathname.\n *\n * @param request - The incoming Next.js request object.\n * @param pathname - The pathname from the request URL.\n * @param pathLocale - The locale extracted from the pathname.\n * @param localLocale - The locale from the cookie.\n * @param basePath - The base path of the application.\n * @returns - The new URL path with the correct locale.\n */\nconst handleCookieLocaleMismatch = (\n request: NextRequest,\n pathname: string,\n pathLocale: Locale,\n localLocale: Locale,\n basePath: string\n): string => {\n // Replace the pathLocale in the pathname with the localLocale\n const newPath = pathname.replace(`/${pathLocale}`, `/${localLocale}`);\n\n return constructPath(\n localLocale,\n newPath,\n basePath,\n appendLocaleSearchIfNeeded(request.nextUrl.search, localLocale)\n );\n};\n\n/**\n * Handles redirection when the default locale is used and prefixing is not required.\n *\n * @param request - The incoming Next.js request object.\n * @param pathLocale - The locale extracted from the pathname.\n * @param pathname - The pathname from the request URL.\n * @returns - The rewritten response without the locale prefix.\n */\nconst handleDefaultLocaleRedirect = (\n request: NextRequest,\n pathLocale: Locale,\n pathname: string\n): NextResponse => {\n if (\n // If default locale should not be prefixed and the pathLocale is the defaultLocale\n !prefixDefault &&\n pathLocale === defaultLocale\n ) {\n let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) ?? '/';\n\n const basePathTrailingSlash = basePath.endsWith('/');\n\n if (basePathTrailingSlash) {\n pathWithoutLocale = pathWithoutLocale.slice(1);\n }\n\n const searchWithLocale = appendLocaleSearchIfNeeded(\n request.nextUrl.search,\n pathLocale\n );\n if (searchWithLocale) {\n pathWithoutLocale += searchWithLocale;\n } else if (request.nextUrl.search) {\n pathWithoutLocale += request.nextUrl.search;\n }\n\n return rewriteUrl(request, `${basePath}${pathWithoutLocale}`, pathLocale);\n }\n\n // If prefixing default locale is required or pathLocale is not the defaultLocale\n\n const searchWithLocale = appendLocaleSearchIfNeeded(\n request.nextUrl.search,\n pathLocale\n );\n const newPath = searchWithLocale\n ? `${pathname}${searchWithLocale}`\n : pathname;\n return rewriteUrl(request, newPath, pathLocale);\n};\n\n/**\n * Constructs a new path by combining the locale, path, basePath, and search parameters.\n *\n * @param locale - The locale to include in the path.\n * @param path - The original path from the request.\n * @param basePath - The base path of the application.\n * @param [search] - The query string from the request URL (optional).\n * @returns - The constructed new path.\n */\nconst constructPath = (\n locale: Locale,\n path: string,\n basePath: string,\n search?: string\n): string => {\n // In 'search-params' and 'no-prefix' modes, do not prefix the path with the locale\n // Also, strip any incoming locale prefix if present\n const pathWithoutPrefix = path.startsWith(`/${locale}`)\n ? path.slice(`/${locale}`.length) || '/'\n : path;\n\n if (effectiveMode === 'no-prefix') {\n if (search) {\n return `${pathWithoutPrefix}?${search}`;\n }\n\n return pathWithoutPrefix;\n }\n\n if (effectiveMode === 'search-params') {\n if (search) {\n return `${pathWithoutPrefix}?${search}`;\n }\n\n return pathWithoutPrefix;\n }\n\n const pathWithLocalePrefix = path.startsWith(`/${locale}`)\n ? path\n : `${locale}${path}`;\n\n const basePathTrailingSlash = basePath.endsWith('/');\n\n const newPath = `${basePath}${basePathTrailingSlash ? '' : '/'}${pathWithLocalePrefix}`;\n\n return newPath;\n};\n\n/**\n * Rewrites the URL to the new path and sets the locale header.\n *\n * @param request - The incoming Next.js request object.\n * @param newPath - The new path to rewrite to.\n * @param locale - The locale to set in the response header.\n * @returns - The rewritten response.\n */\nconst rewriteUrl = (\n request: NextRequest,\n newPath: string,\n locale: Locale\n): NextResponse => {\n // Ensure we preserve the original search params if they were present and not explicitly included in newPath\n const search = request.nextUrl.search;\n const pathWithSearch =\n search && !newPath.includes('?') ? `${newPath}${search}` : newPath;\n\n const response = NextResponse.rewrite(new URL(pathWithSearch, request.url));\n\n setLocaleInStorage(locale, {\n setHeader: (name: string, value: string) =>\n response.headers.set(name, value),\n });\n\n return response;\n};\n\n/**\n * Redirects the request to the new path.\n *\n * @param request - The incoming Next.js request object.\n * @param newPath - The new path to redirect to.\n * @returns - The redirect response.\n */\nconst redirectUrl = (request: NextRequest, newPath: string): NextResponse => {\n // Ensure we preserve the original search params if they were present and not explicitly included in newPath\n const search = request.nextUrl.search;\n const pathWithSearch =\n search && !newPath.includes('?') ? `${newPath}${search}` : newPath;\n\n return NextResponse.redirect(new URL(pathWithSearch, request.url));\n};\n\n/**\n * Middleware that handles the internationalization layer\n *\n * Usage:\n *\n * ```ts\n * // ./src/middleware.ts\n *\n * export { intlayerMiddleware as middleware } from '@intlayer/next/middleware';\n *\n * // applies this middleware only to files in the app directory\n * export const config = {\n * matcher: '/((?!api|static|.*\\\\..*|_next).*)',\n * };\n * ```\n *\n * Main middleware function for handling internationalization.\n *\n * @param request - The incoming Next.js request object.\n * @param event - The Next.js fetch event (optional).\n * @param response - The Next.js response object (optional).\n * @returns - The response to be returned to the client.\n */\nexport const intlayerMiddleware = intlayerProxy;\n"],"mappings":";;;;;;;AA0CA,MAAM,EAAE,sBAAsB,YAAY,iBAAiB,EAAE;AAC7D,MAAM,EAAE,SAAS,kBAAkB,wBAAwB,EAAE;AAC7D,MAAM,EAAE,UAAU,SAAS,WAAW,EAAE;AAIxC,MAAM,gBAAgB,QAAQ,cAAc,QAAQ;AACpD,MAAM,WACJ,kBAAkB,eAAe,kBAAkB;AACrD,MAAM,gBAAgB,kBAAkB;;;;;;;;;;;;;;;AAgBxC,MAAM,qBAAqB,YAAkC;CAC3D,MAAM,UAAU,QAAQ,QAAQ,IAAI,UAAU;CAC9C,MAAM,qBAAqB,QAAQ,QAAQ,IAAI,uBAAuB;CACtE,MAAM,UAAU,QAAQ,QAAQ,IAAI,WAAW;CAC/C,MAAM,cAAc,QAAQ,QAAQ,IAAI,gBAAgB;AAExD,QACE,YAAY,cACZ,uBAAuB,OACvB,CAAC,CAAC,WACF,CAAC,CAAC;;AAKN,MAAM,8BACJ,QACA,WACuB;AACvB,KAAI,kBAAkB,gBAAiB,QAAO;CAE9C,MA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,MAAM,iBACJ,UAAU,CAAC,QAAQ,SAAS,IAAI,GAAG,GAAG,UAAU,WAAW;AAE7D,QAAO,aAAa,SAAS,IAAI,IAAI,gBAAgB,QAAQ,IAAI,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;AA0BpE,MAAa,qBAAqB"}
|
|
@@ -38,15 +38,15 @@ const multipleProxies = (proxies) => async (req, event, response) => {
|
|
|
38
38
|
proxyHeader.forEach((header) => {
|
|
39
39
|
for (const [key, value] of header.entries()) {
|
|
40
40
|
mergedHeaders.append(key, value);
|
|
41
|
-
if (key.startsWith("x-
|
|
42
|
-
const fixedKey = key.replace("x-
|
|
41
|
+
if (key.startsWith("x-middleware-request-")) {
|
|
42
|
+
const fixedKey = key.replace("x-middleware-request-", "");
|
|
43
43
|
transmittedHeaders.append(fixedKey, value);
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
|
-
const redirect = mergedHeaders.get("x-
|
|
47
|
+
const redirect = mergedHeaders.get("x-middleware-request-redirect");
|
|
48
48
|
if (redirect) return NextResponse.redirect(new URL(redirect, req.url), { status: 307 });
|
|
49
|
-
const rewrite = mergedHeaders.get("x-
|
|
49
|
+
const rewrite = mergedHeaders.get("x-middleware-rewrite");
|
|
50
50
|
if (rewrite) return NextResponse.rewrite(new URL(rewrite, req.url), { request: { headers: transmittedHeaders } });
|
|
51
51
|
return NextResponse.next({ request: { headers: transmittedHeaders } });
|
|
52
52
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multipleProxies.mjs","names":["proxyHeader: Headers[]"],"sources":["../../../src/proxy/multipleProxies.ts"],"sourcesContent":["import {\n type NextFetchEvent,\n type NextRequest,\n NextResponse,\n} from 'next/server';\n\n/**\n * Utility to combine multiple Next.js proxies into one.\n *\n * It executes proxies in order, merges headers, and correctly handles\n * redirects and rewrites.\n *\n * @example\n * import { multipleProxies, intlayerProxy } from \"next-intlayer/proxy\";\n * import { NextResponse } from \"next/server\";\n *\n * const authMiddleware = (req: NextRequest) => {\n * if (!req.cookies.get(\"token\")) {\n * return NextResponse.redirect(new URL(\"/login\", req.url));\n * }\n * return NextResponse.next();\n * };\n *\n * export default multipleProxies([\n * intlayerProxy,\n * authMiddleware,\n * ]);\n *\n * @param proxies - An array of proxy functions to execute in order.\n * @returns A single proxy function that runs all provided proxies.\n */\nexport const multipleProxies =\n (\n proxies: ((\n req: NextRequest,\n event?: NextFetchEvent,\n response?: NextResponse\n ) => NextResponse | Promise<NextResponse>)[]\n ) =>\n async (req: NextRequest, event?: NextFetchEvent, response?: NextResponse) => {\n // Array to store proxy headers\n const proxyHeader: Headers[] = [];\n\n // Loop through proxy functions\n for (const proxy of proxies) {\n // Execute proxy function and await the result\n const result = await proxy(req, event, response);\n\n // Check if the result is not okay and return it\n if (!result.ok) {\n return result;\n }\n\n // Push proxy headers to the array\n proxyHeader.push(result.headers);\n }\n\n // Merge all the headers to check if there is a redirection or rewrite\n const mergedHeaders = new Headers();\n\n // Merge all the custom headers added by the proxies\n const transmittedHeaders = new Headers();\n\n // Merge headers\n proxyHeader.forEach((header) => {\n for (const [key, value] of header.entries()) {\n mergedHeaders.append(key, value);\n\n // check if it's a custom header added by one of the proxies\n if (key.startsWith('x-
|
|
1
|
+
{"version":3,"file":"multipleProxies.mjs","names":["proxyHeader: Headers[]"],"sources":["../../../src/proxy/multipleProxies.ts"],"sourcesContent":["import {\n type NextFetchEvent,\n type NextRequest,\n NextResponse,\n} from 'next/server';\n\n/**\n * Utility to combine multiple Next.js proxies into one.\n *\n * It executes proxies in order, merges headers, and correctly handles\n * redirects and rewrites.\n *\n * @example\n * import { multipleProxies, intlayerProxy } from \"next-intlayer/proxy\";\n * import { NextResponse } from \"next/server\";\n *\n * const authMiddleware = (req: NextRequest) => {\n * if (!req.cookies.get(\"token\")) {\n * return NextResponse.redirect(new URL(\"/login\", req.url));\n * }\n * return NextResponse.next();\n * };\n *\n * export default multipleProxies([\n * intlayerProxy,\n * authMiddleware,\n * ]);\n *\n * @param proxies - An array of proxy functions to execute in order.\n * @returns A single proxy function that runs all provided proxies.\n */\nexport const multipleProxies =\n (\n proxies: ((\n req: NextRequest,\n event?: NextFetchEvent,\n response?: NextResponse\n ) => NextResponse | Promise<NextResponse>)[]\n ) =>\n async (req: NextRequest, event?: NextFetchEvent, response?: NextResponse) => {\n // Array to store proxy headers\n const proxyHeader: Headers[] = [];\n\n // Loop through proxy functions\n for (const proxy of proxies) {\n // Execute proxy function and await the result\n const result = await proxy(req, event, response);\n\n // Check if the result is not okay and return it\n if (!result.ok) {\n return result;\n }\n\n // Push proxy headers to the array\n proxyHeader.push(result.headers);\n }\n\n // Merge all the headers to check if there is a redirection or rewrite\n const mergedHeaders = new Headers();\n\n // Merge all the custom headers added by the proxies\n const transmittedHeaders = new Headers();\n\n // Merge headers\n proxyHeader.forEach((header) => {\n for (const [key, value] of header.entries()) {\n mergedHeaders.append(key, value);\n\n // check if it's a custom header added by one of the proxies\n if (key.startsWith('x-middleware-request-')) {\n // remove the prefix to get the original key\n const fixedKey = key.replace('x-middleware-request-', '');\n\n // add the original key to the transmitted headers\n transmittedHeaders.append(fixedKey, value);\n }\n }\n });\n\n // Look for the 'x-middleware-request-redirect' header\n const redirect = mergedHeaders.get('x-middleware-request-redirect');\n\n // If a redirection is required based on the proxy headers\n if (redirect) {\n // Perform the redirection\n return NextResponse.redirect(new URL(redirect, req.url), {\n status: 307, // Temporary redirect\n });\n }\n\n // Look for the 'x-middleware-rewrite' header\n const rewrite = mergedHeaders.get('x-middleware-rewrite');\n if (rewrite) {\n // Perform the rewrite\n return NextResponse.rewrite(new URL(rewrite, req.url), {\n request: {\n headers: transmittedHeaders,\n },\n });\n }\n\n // Default: continue to next proxy\n return NextResponse.next({\n request: {\n headers: transmittedHeaders,\n },\n });\n };\n\nexport const multipleMiddlewares = multipleProxies;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,mBAET,YAMF,OAAO,KAAkB,OAAwB,aAA4B;CAE3E,MAAMA,cAAyB,EAAE;AAGjC,MAAK,MAAM,SAAS,SAAS;EAE3B,MAAM,SAAS,MAAM,MAAM,KAAK,OAAO,SAAS;AAGhD,MAAI,CAAC,OAAO,GACV,QAAO;AAIT,cAAY,KAAK,OAAO,QAAQ;;CAIlC,MAAM,gBAAgB,IAAI,SAAS;CAGnC,MAAM,qBAAqB,IAAI,SAAS;AAGxC,aAAY,SAAS,WAAW;AAC9B,OAAK,MAAM,CAAC,KAAK,UAAU,OAAO,SAAS,EAAE;AAC3C,iBAAc,OAAO,KAAK,MAAM;AAGhC,OAAI,IAAI,WAAW,wBAAwB,EAAE;IAE3C,MAAM,WAAW,IAAI,QAAQ,yBAAyB,GAAG;AAGzD,uBAAmB,OAAO,UAAU,MAAM;;;GAG9C;CAGF,MAAM,WAAW,cAAc,IAAI,gCAAgC;AAGnE,KAAI,SAEF,QAAO,aAAa,SAAS,IAAI,IAAI,UAAU,IAAI,IAAI,EAAE,EACvD,QAAQ,KACT,CAAC;CAIJ,MAAM,UAAU,cAAc,IAAI,uBAAuB;AACzD,KAAI,QAEF,QAAO,aAAa,QAAQ,IAAI,IAAI,SAAS,IAAI,IAAI,EAAE,EACrD,SAAS,EACP,SAAS,oBACV,EACF,CAAC;AAIJ,QAAO,aAAa,KAAK,EACvB,SAAS,EACP,SAAS,oBACV,EACF,CAAC;;AAGN,MAAa,sBAAsB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { compareVersions } from "./compareVersion.mjs";
|
|
2
|
-
import { getAlias, getAppLogger, getConfiguration, normalizePath } from "@intlayer/config";
|
|
2
|
+
import { ESMxCJSRequire, getAlias, getAppLogger, getConfiguration, normalizePath } from "@intlayer/config";
|
|
3
3
|
import { join, relative, resolve } from "node:path";
|
|
4
4
|
import { prepareIntlayer, runOnce } from "@intlayer/chokidar";
|
|
5
5
|
import { getDictionaries } from "@intlayer/dictionaries-entry";
|
|
@@ -11,19 +11,18 @@ import nextPackageJSON from "next/package.json" with { type: "json" };
|
|
|
11
11
|
//#region src/server/withIntlayer.ts
|
|
12
12
|
const isGteNext13 = compareVersions(nextPackageJSON.version, "≥", "13.0.0");
|
|
13
13
|
const isGteNext15 = compareVersions(nextPackageJSON.version, "≥", "15.0.0");
|
|
14
|
-
const
|
|
15
|
-
const isTurbopackEnabled = !isGteNext16 && process.env.npm_lifecycle_script?.includes("--turbo") || isGteNext16 && !process.env.npm_lifecycle_script?.includes("--webpack");
|
|
14
|
+
const isTurbopackEnabled = compareVersions(nextPackageJSON.version, "≥", "16.0.0") ? !process.env.npm_lifecycle_script?.includes("--webpack") : process.env.npm_lifecycle_script?.includes("--turbo");
|
|
16
15
|
const isTurbopackStable = compareVersions(nextPackageJSON.version, "≥", "15.3.0");
|
|
17
16
|
const getIsSwcPluginAvailable = (intlayerConfig) => {
|
|
18
17
|
try {
|
|
19
|
-
intlayerConfig.build
|
|
18
|
+
(intlayerConfig.build?.require ?? ESMxCJSRequire).resolve("@intlayer/swc");
|
|
20
19
|
return true;
|
|
21
20
|
} catch (_e) {
|
|
22
21
|
return false;
|
|
23
22
|
}
|
|
24
23
|
};
|
|
25
24
|
const resolvePluginPath = (pluginPath, intlayerConfig) => {
|
|
26
|
-
const pluginPathResolved = intlayerConfig.build
|
|
25
|
+
const pluginPathResolved = (intlayerConfig.build?.require ?? ESMxCJSRequire)?.resolve(pluginPath);
|
|
27
26
|
if (isTurbopackEnabled) return normalizePath(`./${relative(process.cwd(), pluginPathResolved)}`);
|
|
28
27
|
return pluginPathResolved;
|
|
29
28
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withIntlayer.mjs","names":["config: Partial<NextConfig>","config","pruneConfig: Partial<NextConfig>","intlayerNextConfig: Partial<NextConfig>"],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { join, relative, resolve } from 'node:path';\nimport { prepareIntlayer, runOnce } from '@intlayer/chokidar';\nimport {\n type GetConfigurationOptions,\n getAlias,\n getAppLogger,\n getConfiguration,\n normalizePath,\n} from '@intlayer/config';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { IntlayerPlugin } from '@intlayer/webpack';\nimport merge from 'deepmerge';\nimport fg from 'fast-glob';\nimport type { NextConfig } from 'next';\nimport type { NextJsWebpackConfig } from 'next/dist/server/config-shared';\nimport nextPackageJSON from 'next/package.json' with { type: 'json' };\nimport { compareVersions } from './compareVersion';\n\n// Extract from the start script if --turbo or --turbopack flag is used\nconst isGteNext13 = compareVersions(nextPackageJSON.version, '≥', '13.0.0');\nconst isGteNext15 = compareVersions(nextPackageJSON.version, '≥', '15.0.0');\nconst isGteNext16 = compareVersions(nextPackageJSON.version, '≥', '16.0.0');\nconst isTurbopackEnabled =\n (!isGteNext16 && process.env.npm_lifecycle_script?.includes('--turbo')) ||\n (isGteNext16 && !process.env.npm_lifecycle_script?.includes('--webpack'));\n\nconst isTurbopackStable = compareVersions(\n nextPackageJSON.version,\n '≥',\n '15.3.0'\n);\n\n// Check if SWC plugin is available\nconst getIsSwcPluginAvailable = (intlayerConfig: IntlayerConfig) => {\n try {\n intlayerConfig.build.require.resolve('@intlayer/swc');\n return true;\n } catch (_e) {\n return false;\n }\n};\n\nconst resolvePluginPath = (\n pluginPath: string,\n intlayerConfig: IntlayerConfig\n): string => {\n const pluginPathResolved = intlayerConfig.build.require.resolve(pluginPath);\n\n if (isTurbopackEnabled)\n // Relative path for turbopack\n return normalizePath(`./${relative(process.cwd(), pluginPathResolved)}`);\n\n // Absolute path for webpack\n return pluginPathResolved;\n};\n\nconst getPruneConfig = (\n intlayerConfig: IntlayerConfig\n): Partial<NextConfig> => {\n const { optimize, traversePattern, importMode } = intlayerConfig.build;\n const {\n dictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n baseDir,\n } = intlayerConfig.content;\n\n if (!optimize) return {};\n\n if (!isGteNext13) return {};\n\n const isSwcPluginAvailable = getIsSwcPluginAvailable(intlayerConfig);\n\n if (!isSwcPluginAvailable) return {};\n\n const logger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(baseDir, '.intlayer', 'cache', 'intlayer-prune-plugin-enabled.lock'),\n () => logger('Intlayer prune plugin is enabled'),\n {\n cacheTimeoutMs: 1000 * 10, // 10 seconds\n }\n );\n\n const dictionariesEntryPath = join(mainDir, 'dictionaries.mjs');\n\n const dynamicDictionariesEntryPath = join(\n mainDir,\n 'dynamic_dictionaries.mjs'\n );\n\n const fetchDictionariesEntryPath = join(mainDir, 'fetch_dictionaries.mjs');\n\n const filesListPattern = fg\n .sync(traversePattern, {\n cwd: baseDir,\n })\n .map((file) => join(baseDir, file));\n\n const filesList = [\n ...filesListPattern,\n dictionariesEntryPath, // should add dictionariesEntryPath to replace it by a empty object if import made dynamic\n ];\n\n const dictionaries = getDictionaries(intlayerConfig);\n\n const liveSyncKeys = Object.values(dictionaries)\n .filter((dictionary) => dictionary.live)\n .map((dictionary) => dictionary.key);\n\n return {\n experimental: {\n swcPlugins: [\n [\n resolvePluginPath('@intlayer/swc', intlayerConfig),\n {\n dictionariesDir,\n dictionariesEntryPath,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n fetchDictionariesDir,\n fetchDictionariesEntryPath,\n importMode,\n filesList,\n replaceDictionaryEntry: false,\n liveSyncKeys,\n } as any,\n ],\n ],\n },\n };\n};\n\nconst getCommandsEvent = () => {\n const lifecycleEvent = process.env.npm_lifecycle_event;\n const lifecycleScript = process.env.npm_lifecycle_script ?? '';\n\n const isDevCommand =\n lifecycleEvent === 'dev' ||\n process.argv.some((arg) => arg === 'dev') ||\n /(^|\\s)(next\\s+)?dev(\\s|$)/.test(lifecycleScript);\n\n const isBuildCommand =\n lifecycleEvent === 'build' ||\n process.argv.some((arg) => arg === 'build') ||\n /(^|\\s)(next\\s+)?build(\\s|$)/.test(lifecycleScript);\n\n const isStartCommand =\n lifecycleEvent === 'start' ||\n process.argv.some((arg) => arg === 'start') ||\n /(^|\\s)(next\\s+)?start(\\s|$)/.test(lifecycleScript);\n\n return {\n isDevCommand,\n isBuildCommand,\n isStartCommand,\n };\n};\n\ntype WebpackParams = Parameters<NextJsWebpackConfig>;\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayerSync(nextConfig)\n * ```\n */\nexport const withIntlayerSync = <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T,\n configOptions?: GetConfigurationOptions\n): NextConfig & T => {\n if (typeof nextConfig !== 'object') {\n nextConfig = {} as T;\n }\n\n const intlayerConfig = getConfiguration(configOptions);\n\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n\n // Only provide turbo-specific config if user explicitly sets it\n const turboConfig = {\n resolveAlias: getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => `./${value}`, // prefix by './' to consider the path as relative to the project root. This is necessary for turbopack to work correctly.\n }),\n\n rules: {\n '*.node': {\n as: '*.node',\n loaders: ['node-loader'],\n },\n },\n };\n\n const serverExternalPackages = [\n 'esbuild',\n 'module',\n 'fs',\n 'chokidar',\n 'fsevents',\n ];\n\n const getNewConfig = (): Partial<NextConfig> => {\n let config: Partial<NextConfig> = {};\n\n if (isGteNext15) {\n config = {\n ...config,\n serverExternalPackages,\n };\n }\n\n if (isGteNext13 && !isGteNext15) {\n config = {\n ...config,\n experimental: {\n ...(config?.experimental ?? {}),\n serverComponentsExternalPackages: serverExternalPackages,\n },\n };\n }\n\n if (isTurbopackEnabled) {\n if (isGteNext15 && isTurbopackStable) {\n config = {\n ...config,\n turbopack: turboConfig,\n };\n } else {\n config = {\n ...config,\n experimental: {\n ...(config?.experimental ?? {}),\n // @ts-ignore exist in next@14\n turbo: turboConfig,\n },\n };\n }\n } else {\n config = {\n ...config,\n webpack: (config: WebpackParams['0'], options: WebpackParams[1]) => {\n // Only add Intlayer plugin on server side (node runtime)\n const { isServer, nextRuntime } = options;\n\n // If the user has defined their own webpack config, call it\n if (typeof nextConfig.webpack === 'function') {\n config = nextConfig.webpack(config, options);\n }\n\n // Mark these modules as externals\n config.externals.push({\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n chokidar: 'chokidar',\n fsevents: 'fsevents',\n });\n\n // Use `node-loader` for any `.node` files\n config.module.rules.push({\n test: /\\.node$/,\n loader: 'node-loader',\n });\n\n // Always alias on the server (node/edge) for stability.\n // On the client, alias only when not using live sync.\n config.resolve.alias = {\n ...config.resolve.alias,\n ...getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => resolve(value), // get absolute path\n }),\n };\n\n // Activate watch mode webpack plugin\n if (isDevCommand && isServer && nextRuntime === 'nodejs') {\n config.plugins.push(new IntlayerPlugin(intlayerConfig));\n }\n\n return config;\n },\n };\n }\n\n return config;\n };\n\n let pruneConfig: Partial<NextConfig> = {};\n\n if (isBuildCommand) {\n pruneConfig = getPruneConfig(intlayerConfig);\n }\n\n const intlayerNextConfig: Partial<NextConfig> = merge(\n pruneConfig,\n getNewConfig()\n );\n\n // Merge the new config with the user's config\n const result = merge(nextConfig, intlayerNextConfig) as NextConfig & T;\n\n return result;\n};\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayer(nextConfig)\n * ```\n *\n * > Node withIntlayer is a promise function. Use withIntlayerSync instead if you want to use it synchronously.\n * > Using the promise allows to prepare the intlayer dictionaries before the build starts.\n *\n */\nexport const withIntlayer = async <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T,\n configOptions?: GetConfigurationOptions\n): Promise<NextConfig & T> => {\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n\n // Only call prepareIntlayer during `dev` or `build` (not during `start`)\n if (isBuildCommand || isDevCommand) {\n const intlayerConfig = getConfiguration(configOptions);\n await prepareIntlayer(intlayerConfig);\n }\n\n return withIntlayerSync(nextConfig, configOptions);\n};\n"],"mappings":";;;;;;;;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>","config","pruneConfig: Partial<NextConfig>","intlayerNextConfig: Partial<NextConfig>"],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { join, relative, resolve } from 'node:path';\nimport { prepareIntlayer, runOnce } from '@intlayer/chokidar';\nimport {\n ESMxCJSRequire,\n type GetConfigurationOptions,\n getAlias,\n getAppLogger,\n getConfiguration,\n normalizePath,\n} from '@intlayer/config';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { IntlayerPlugin } from '@intlayer/webpack';\nimport merge from 'deepmerge';\nimport fg from 'fast-glob';\nimport type { NextConfig } from 'next';\nimport type { NextJsWebpackConfig } from 'next/dist/server/config-shared';\nimport nextPackageJSON from 'next/package.json' with { type: 'json' };\nimport { compareVersions } from './compareVersion';\n\nconst isGteNext13 = compareVersions(nextPackageJSON.version, '≥', '13.0.0');\nconst isGteNext15 = compareVersions(nextPackageJSON.version, '≥', '15.0.0');\nconst isGteNext16 = compareVersions(nextPackageJSON.version, '≥', '16.0.0');\n\nconst isTurbopackEnabled = isGteNext16\n ? // Next@16 enable turbopack by default, and offer the possibility to disable it if --webpack flag is used\n !process.env.npm_lifecycle_script?.includes('--webpack')\n : // Next@15 use --turbopack flag, Next@14 use --turbo flag\n process.env.npm_lifecycle_script?.includes('--turbo');\n\nconst isTurbopackStable = compareVersions(\n nextPackageJSON.version,\n '≥',\n '15.3.0'\n);\n\n// Check if SWC plugin is available\nconst getIsSwcPluginAvailable = (intlayerConfig: IntlayerConfig) => {\n try {\n const requireFunction = intlayerConfig.build?.require ?? ESMxCJSRequire;\n requireFunction.resolve('@intlayer/swc');\n return true;\n } catch (_e) {\n return false;\n }\n};\n\nconst resolvePluginPath = (\n pluginPath: string,\n intlayerConfig: IntlayerConfig\n): string => {\n const requireFunction = intlayerConfig.build?.require ?? ESMxCJSRequire;\n const pluginPathResolved = requireFunction?.resolve(pluginPath);\n\n if (isTurbopackEnabled)\n // Relative path for turbopack\n return normalizePath(`./${relative(process.cwd(), pluginPathResolved)}`);\n\n // Absolute path for webpack\n return pluginPathResolved;\n};\n\nconst getPruneConfig = (\n intlayerConfig: IntlayerConfig\n): Partial<NextConfig> => {\n const { optimize, traversePattern, importMode } = intlayerConfig.build;\n const {\n dictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n baseDir,\n } = intlayerConfig.content;\n\n if (!optimize) return {};\n\n if (!isGteNext13) return {};\n\n const isSwcPluginAvailable = getIsSwcPluginAvailable(intlayerConfig);\n\n if (!isSwcPluginAvailable) return {};\n\n const logger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(baseDir, '.intlayer', 'cache', 'intlayer-prune-plugin-enabled.lock'),\n () => logger('Intlayer prune plugin is enabled'),\n {\n cacheTimeoutMs: 1000 * 10, // 10 seconds\n }\n );\n\n const dictionariesEntryPath = join(mainDir, 'dictionaries.mjs');\n\n const dynamicDictionariesEntryPath = join(\n mainDir,\n 'dynamic_dictionaries.mjs'\n );\n\n const fetchDictionariesEntryPath = join(mainDir, 'fetch_dictionaries.mjs');\n\n const filesListPattern = fg\n .sync(traversePattern, {\n cwd: baseDir,\n })\n .map((file) => join(baseDir, file));\n\n const filesList = [\n ...filesListPattern,\n dictionariesEntryPath, // should add dictionariesEntryPath to replace it by a empty object if import made dynamic\n ];\n\n const dictionaries = getDictionaries(intlayerConfig);\n\n const liveSyncKeys = Object.values(dictionaries)\n .filter((dictionary) => dictionary.live)\n .map((dictionary) => dictionary.key);\n\n return {\n experimental: {\n swcPlugins: [\n [\n resolvePluginPath('@intlayer/swc', intlayerConfig),\n {\n dictionariesDir,\n dictionariesEntryPath,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n fetchDictionariesDir,\n fetchDictionariesEntryPath,\n importMode,\n filesList,\n replaceDictionaryEntry: false,\n liveSyncKeys,\n } as any,\n ],\n ],\n },\n };\n};\n\nconst getCommandsEvent = () => {\n const lifecycleEvent = process.env.npm_lifecycle_event;\n const lifecycleScript = process.env.npm_lifecycle_script ?? '';\n\n const isDevCommand =\n lifecycleEvent === 'dev' ||\n process.argv.some((arg) => arg === 'dev') ||\n /(^|\\s)(next\\s+)?dev(\\s|$)/.test(lifecycleScript);\n\n const isBuildCommand =\n lifecycleEvent === 'build' ||\n process.argv.some((arg) => arg === 'build') ||\n /(^|\\s)(next\\s+)?build(\\s|$)/.test(lifecycleScript);\n\n const isStartCommand =\n lifecycleEvent === 'start' ||\n process.argv.some((arg) => arg === 'start') ||\n /(^|\\s)(next\\s+)?start(\\s|$)/.test(lifecycleScript);\n\n return {\n isDevCommand,\n isBuildCommand,\n isStartCommand,\n };\n};\n\ntype WebpackParams = Parameters<NextJsWebpackConfig>;\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayerSync(nextConfig)\n * ```\n */\nexport const withIntlayerSync = <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T,\n configOptions?: GetConfigurationOptions\n): NextConfig & T => {\n if (typeof nextConfig !== 'object') {\n nextConfig = {} as T;\n }\n\n const intlayerConfig = getConfiguration(configOptions);\n\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n\n // Only provide turbo-specific config if user explicitly sets it\n const turboConfig = {\n resolveAlias: getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => `./${value}`, // prefix by './' to consider the path as relative to the project root. This is necessary for turbopack to work correctly.\n }),\n\n rules: {\n '*.node': {\n as: '*.node',\n loaders: ['node-loader'],\n },\n },\n };\n\n const serverExternalPackages = [\n 'esbuild',\n 'module',\n 'fs',\n 'chokidar',\n 'fsevents',\n ];\n\n const getNewConfig = (): Partial<NextConfig> => {\n let config: Partial<NextConfig> = {};\n\n if (isGteNext15) {\n config = {\n ...config,\n serverExternalPackages,\n };\n }\n\n if (isGteNext13 && !isGteNext15) {\n config = {\n ...config,\n experimental: {\n ...(config?.experimental ?? {}),\n serverComponentsExternalPackages: serverExternalPackages,\n },\n };\n }\n\n if (isTurbopackEnabled) {\n if (isGteNext15 && isTurbopackStable) {\n config = {\n ...config,\n turbopack: turboConfig,\n };\n } else {\n config = {\n ...config,\n experimental: {\n ...(config?.experimental ?? {}),\n // @ts-ignore exist in next@14\n turbo: turboConfig,\n },\n };\n }\n } else {\n config = {\n ...config,\n webpack: (config: WebpackParams['0'], options: WebpackParams[1]) => {\n // Only add Intlayer plugin on server side (node runtime)\n const { isServer, nextRuntime } = options;\n\n // If the user has defined their own webpack config, call it\n if (typeof nextConfig.webpack === 'function') {\n config = nextConfig.webpack(config, options);\n }\n\n // Mark these modules as externals\n config.externals.push({\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n chokidar: 'chokidar',\n fsevents: 'fsevents',\n });\n\n // Use `node-loader` for any `.node` files\n config.module.rules.push({\n test: /\\.node$/,\n loader: 'node-loader',\n });\n\n // Always alias on the server (node/edge) for stability.\n // On the client, alias only when not using live sync.\n config.resolve.alias = {\n ...config.resolve.alias,\n ...getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => resolve(value), // get absolute path\n }),\n };\n\n // Activate watch mode webpack plugin\n if (isDevCommand && isServer && nextRuntime === 'nodejs') {\n config.plugins.push(new IntlayerPlugin(intlayerConfig));\n }\n\n return config;\n },\n };\n }\n\n return config;\n };\n\n let pruneConfig: Partial<NextConfig> = {};\n\n if (isBuildCommand) {\n pruneConfig = getPruneConfig(intlayerConfig);\n }\n\n const intlayerNextConfig: Partial<NextConfig> = merge(\n pruneConfig,\n getNewConfig()\n );\n\n // Merge the new config with the user's config\n const result = merge(nextConfig, intlayerNextConfig) as NextConfig & T;\n\n return result;\n};\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayer(nextConfig)\n * ```\n *\n * > Node withIntlayer is a promise function. Use withIntlayerSync instead if you want to use it synchronously.\n * > Using the promise allows to prepare the intlayer dictionaries before the build starts.\n *\n */\nexport const withIntlayer = async <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T,\n configOptions?: GetConfigurationOptions\n): Promise<NextConfig & T> => {\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n\n // Only call prepareIntlayer during `dev` or `build` (not during `start`)\n if (isBuildCommand || isDevCommand) {\n const intlayerConfig = getConfiguration(configOptions);\n await prepareIntlayer(intlayerConfig);\n }\n\n return withIntlayerSync(nextConfig, configOptions);\n};\n"],"mappings":";;;;;;;;;;;AAoBA,MAAM,cAAc,gBAAgB,gBAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,cAAc,gBAAgB,gBAAgB,SAAS,KAAK,SAAS;AAG3E,MAAM,qBAFc,gBAAgB,gBAAgB,SAAS,KAAK,SAAS,GAIvE,CAAC,QAAQ,IAAI,sBAAsB,SAAS,YAAY,GAExD,QAAQ,IAAI,sBAAsB,SAAS,UAAU;AAEzD,MAAM,oBAAoB,gBACxB,gBAAgB,SAChB,KACA,SACD;AAGD,MAAM,2BAA2B,mBAAmC;AAClE,KAAI;AAEF,GADwB,eAAe,OAAO,WAAW,gBACzC,QAAQ,gBAAgB;AACxC,SAAO;UACA,IAAI;AACX,SAAO;;;AAIX,MAAM,qBACJ,YACA,mBACW;CAEX,MAAM,sBADkB,eAAe,OAAO,WAAW,iBACb,QAAQ,WAAW;AAE/D,KAAI,mBAEF,QAAO,cAAc,KAAK,SAAS,QAAQ,KAAK,EAAE,mBAAmB,GAAG;AAG1E,QAAO;;AAGT,MAAM,kBACJ,mBACwB;CACxB,MAAM,EAAE,UAAU,iBAAiB,eAAe,eAAe;CACjE,MAAM,EACJ,iBACA,wBACA,sBACA,SACA,YACE,eAAe;AAEnB,KAAI,CAAC,SAAU,QAAO,EAAE;AAExB,KAAI,CAAC,YAAa,QAAO,EAAE;AAI3B,KAAI,CAFyB,wBAAwB,eAAe,CAEzC,QAAO,EAAE;CAEpC,MAAM,SAAS,aAAa,eAAe;AAE3C,SACE,KAA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f;AAKD,QAFe,MAAM,YAAY,mBAAmB;;;;;;;;;;;;;;;;;AAoBtD,MAAa,eAAe,OAC1B,aAAgB,EAAE,EAClB,kBAC4B;CAC5B,MAAM,EAAE,gBAAgB,iBAAiB,kBAAkB;AAG3D,KAAI,kBAAkB,aAEpB,OAAM,gBADiB,iBAAiB,cAAc,CACjB;AAGvC,QAAO,iBAAiB,YAAY,cAAc"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _intlayer_types3 from "@intlayer/types";
|
|
2
2
|
import { LocalesValues } from "@intlayer/types";
|
|
3
3
|
|
|
4
4
|
//#region src/client/useLocale.d.ts
|
|
@@ -9,9 +9,9 @@ declare const useLocale: ({
|
|
|
9
9
|
onChange
|
|
10
10
|
}?: UseLocaleProps) => {
|
|
11
11
|
pathWithoutLocale: string;
|
|
12
|
-
locale:
|
|
13
|
-
defaultLocale:
|
|
14
|
-
availableLocales:
|
|
12
|
+
locale: _intlayer_types3.DeclaredLocales;
|
|
13
|
+
defaultLocale: _intlayer_types3.DeclaredLocales;
|
|
14
|
+
availableLocales: _intlayer_types3.DeclaredLocales[];
|
|
15
15
|
setLocale: (locale: LocalesValues) => void;
|
|
16
16
|
};
|
|
17
17
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":[],"mappings":";;;;KAQK,cAAA;4CACuC;;AADvC,
|
|
1
|
+
{"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":[],"mappings":";;;;KAQK,cAAA;4CACuC;;AADvC,cAkBQ,SAlBM,EACyB,CAAA;EAAA;AAAa,CAAA,CAAA,EAiBjB,cAjBiB,EAAA,GAAA;EAiB5C,iBAiCZ,EAAA,MAAA;EAjCyB,MAAA,EAAiC,gBAAA,CAAA,eAAjC;EAAc,aAAA,kCAAA;EAAmB,gBAAA,oCAAA"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _intlayer_types0 from "@intlayer/types";
|
|
2
2
|
|
|
3
3
|
//#region src/generateStaticParams.d.ts
|
|
4
4
|
declare const generateStaticParams: () => {
|
|
5
|
-
locale:
|
|
5
|
+
locale: _intlayer_types0.Locale;
|
|
6
6
|
}[];
|
|
7
7
|
//#endregion
|
|
8
8
|
export { generateStaticParams };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateStaticParams.d.ts","names":[],"sources":["../../src/generateStaticParams.ts"],"sourcesContent":[],"mappings":";;;cAIa;UAAkE,
|
|
1
|
+
{"version":3,"file":"generateStaticParams.d.ts","names":[],"sources":["../../src/generateStaticParams.ts"],"sourcesContent":[],"mappings":";;;cAIa;UAAkE,gBAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerProxy.d.ts","names":[],"sources":["../../../src/proxy/intlayerProxy.ts"],"sourcesContent":[],"mappings":";;;;;;
|
|
1
|
+
{"version":3,"file":"intlayerProxy.d.ts","names":[],"sources":["../../../src/proxy/intlayerProxy.ts"],"sourcesContent":[],"mappings":";;;;;;AAsHA;;;;;;AA2ZA;;;;;;;;;;;;;;;cA3Za,yBACF,sBACA,4BACG,iBACX;;;;;;;;;;;;;;;;;;;;;;;;cAuZU,8BA1ZF,sBACA,4BACG,iBACX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withIntlayer.d.ts","names":[],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":[],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"withIntlayer.d.ts","names":[],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":[],"mappings":";;;;;;;AAoLA;;;;;;;;AAyJA;AAAqD,cAzJxC,gBAyJwC,EAAA,CAAA,UAzJV,OAyJU,CAzJF,UAyJE,CAAA,CAAA,CAAA,UAAA,CAAA,EAxJvC,CAwJuC,EAAA,aAAA,CAAA,EAvJnC,uBAuJmC,EAAA,GAtJlD,UAsJkD,GAtJrC,CAsJqC;;;;;;;;;;;;;;;;cAAxC,yBAAgC,QAAQ,0BACvC,mBACI,4BACf,QAAQ,aAAa"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intlayer",
|
|
3
|
-
"version": "7.0.0
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Simplify internationalization i18n in Next.js with context providers, hooks, locale detection, and multilingual content integration.",
|
|
6
6
|
"keywords": [
|
|
@@ -78,8 +78,11 @@
|
|
|
78
78
|
"format": [
|
|
79
79
|
"./dist/types/client/format/index.d.ts"
|
|
80
80
|
],
|
|
81
|
+
"proxy": [
|
|
82
|
+
"./dist/types/proxy/index.d.ts"
|
|
83
|
+
],
|
|
81
84
|
"middleware": [
|
|
82
|
-
"./dist/types/
|
|
85
|
+
"./dist/types/proxy/index.d.ts"
|
|
83
86
|
],
|
|
84
87
|
"server": [
|
|
85
88
|
"./dist/types/server/index.d.ts"
|
|
@@ -111,39 +114,39 @@
|
|
|
111
114
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
112
115
|
},
|
|
113
116
|
"dependencies": {
|
|
114
|
-
"@intlayer/chokidar": "7.0.0
|
|
115
|
-
"@intlayer/config": "7.0.0
|
|
116
|
-
"@intlayer/core": "7.0.0
|
|
117
|
-
"@intlayer/dictionaries-entry": "7.0.0
|
|
118
|
-
"@intlayer/types": "7.0.0
|
|
119
|
-
"@intlayer/webpack": "7.0.0
|
|
117
|
+
"@intlayer/chokidar": "7.0.0",
|
|
118
|
+
"@intlayer/config": "7.0.0",
|
|
119
|
+
"@intlayer/core": "7.0.0",
|
|
120
|
+
"@intlayer/dictionaries-entry": "7.0.0",
|
|
121
|
+
"@intlayer/types": "7.0.0",
|
|
122
|
+
"@intlayer/webpack": "7.0.0",
|
|
120
123
|
"deepmerge": "4.3.1",
|
|
121
124
|
"fast-glob": "3.3.3",
|
|
122
125
|
"node-loader": "2.1.0",
|
|
123
|
-
"react-intlayer": "7.0.0
|
|
126
|
+
"react-intlayer": "7.0.0"
|
|
124
127
|
},
|
|
125
128
|
"devDependencies": {
|
|
126
129
|
"@types/node": "24.9.1",
|
|
127
130
|
"@types/react": ">=16.0.0",
|
|
128
131
|
"@types/react-dom": ">=16.0.0",
|
|
129
|
-
"@utils/ts-config": "7.0.0
|
|
130
|
-
"@utils/ts-config-types": "7.0.0
|
|
131
|
-
"@utils/tsdown-config": "7.0.0
|
|
132
|
+
"@utils/ts-config": "7.0.0",
|
|
133
|
+
"@utils/ts-config-types": "7.0.0",
|
|
134
|
+
"@utils/tsdown-config": "7.0.0",
|
|
132
135
|
"rimraf": "6.0.1",
|
|
133
136
|
"tsdown": "0.15.9",
|
|
134
137
|
"typescript": "5.9.3",
|
|
135
138
|
"vitest": "4.0.3"
|
|
136
139
|
},
|
|
137
140
|
"peerDependencies": {
|
|
138
|
-
"@intlayer/config": "7.0.0
|
|
139
|
-
"@intlayer/core": "7.0.0
|
|
140
|
-
"@intlayer/dictionaries-entry": "7.0.0
|
|
141
|
-
"@intlayer/types": "7.0.0
|
|
142
|
-
"@intlayer/webpack": "7.0.0
|
|
141
|
+
"@intlayer/config": "7.0.0",
|
|
142
|
+
"@intlayer/core": "7.0.0",
|
|
143
|
+
"@intlayer/dictionaries-entry": "7.0.0",
|
|
144
|
+
"@intlayer/types": "7.0.0",
|
|
145
|
+
"@intlayer/webpack": "7.0.0",
|
|
143
146
|
"next": ">=14.0.0",
|
|
144
147
|
"react": ">=16.0.0",
|
|
145
148
|
"react-dom": ">=16.0.0",
|
|
146
|
-
"react-intlayer": "7.0.0
|
|
149
|
+
"react-intlayer": "7.0.0"
|
|
147
150
|
},
|
|
148
151
|
"engines": {
|
|
149
152
|
"node": ">=14.18"
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
const require_middleware_localeDetector = require('./localeDetector.cjs');
|
|
2
|
-
const require_middleware_intlayerMiddleware = require('./intlayerMiddleware.cjs');
|
|
3
|
-
const require_middleware_multipleMiddlewares = require('./multipleMiddlewares.cjs');
|
|
4
|
-
|
|
5
|
-
exports.intlayerMiddleware = require_middleware_intlayerMiddleware.intlayerMiddleware;
|
|
6
|
-
exports.localeDetector = require_middleware_localeDetector.localeDetector;
|
|
7
|
-
exports.multipleMiddlewares = require_middleware_multipleMiddlewares.multipleMiddlewares;
|