next-intlayer 7.3.3 → 7.3.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/dist/cjs/proxy/intlayerProxy.cjs +2 -2
- package/dist/cjs/proxy/intlayerProxy.cjs.map +1 -1
- package/dist/cjs/server/withIntlayer.cjs +1 -1
- package/dist/cjs/server/withIntlayer.cjs.map +1 -1
- package/dist/esm/proxy/intlayerProxy.mjs +2 -2
- package/dist/esm/proxy/intlayerProxy.mjs.map +1 -1
- package/dist/esm/server/withIntlayer.mjs +1 -1
- 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/client/useLocalePageRouter.d.ts +4 -4
- package/dist/types/server/withIntlayer.d.ts.map +1 -1
- package/package.json +8 -8
|
@@ -179,12 +179,12 @@ const handleCookieLocaleMismatch = (request, pathname, pathLocale, localLocale,
|
|
|
179
179
|
*/
|
|
180
180
|
const handleDefaultLocaleRedirect = (request, pathLocale, pathname) => {
|
|
181
181
|
if (!prefixDefault && pathLocale === defaultLocale) {
|
|
182
|
-
let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length)
|
|
182
|
+
let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) || "/";
|
|
183
183
|
if (basePath.endsWith("/")) pathWithoutLocale = pathWithoutLocale.slice(1);
|
|
184
184
|
const searchWithLocale$1 = appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale);
|
|
185
185
|
if (searchWithLocale$1) pathWithoutLocale += searchWithLocale$1;
|
|
186
186
|
else if (request.nextUrl.search) pathWithoutLocale += request.nextUrl.search;
|
|
187
|
-
return
|
|
187
|
+
return redirectUrl(request, `${basePath}${pathWithoutLocale}`);
|
|
188
188
|
}
|
|
189
189
|
const searchWithLocale = appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale);
|
|
190
190
|
return rewriteUrl(request, searchWithLocale ? `${pathname}${searchWithLocale}` : pathname, pathLocale);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerProxy.cjs","names":["configuration","DefaultValues","search","localeDetector","basePath","searchWithLocale","NextResponse"],"sources":["../../../src/proxy/intlayerProxy.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\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"],"mappings":";;;;;;;;;AA0CA,MAAM,EAAE,sBAAsB,YAAYA,mCAAiB,EAAE;AAC7D,MAAM,EAAE,SAAS,kBAAkB,wBAAwB,EAAE;AAC7D,MAAM,EAAE,UAAU,SAAS,WAAW,EAAE;AAIxC,MAAM,gBAAgB,QAAQC,uCAAc,QAAQ;AACpD,MAAM,WAC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E,KAAK,MAAM;;;;;;;;;;AAanE,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,WAAWE,yBAAa,QAAQ,IAAI,IAAI,gBAAgB,QAAQ,IAAI,CAAC;AAE3E,yCAAmB,QAAQ,EACzB,YAAY,MAAc,UACxB,SAAS,QAAQ,IAAI,MAAM,MAAM,EACpC,CAAC;AAEF,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,QAAOA,yBAAa,SAAS,IAAI,IAAI,gBAAgB,QAAQ,IAAI,CAAC"}
|
|
1
|
+
{"version":3,"file":"intlayerProxy.cjs","names":["configuration","DefaultValues","search","localeDetector","basePath","searchWithLocale","NextResponse"],"sources":["../../../src/proxy/intlayerProxy.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\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 redirectUrl(request, `${basePath}${pathWithoutLocale}`);\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"],"mappings":";;;;;;;;;AA0CA,MAAM,EAAE,sBAAsB,YAAYA,mCAAiB,EAAE;AAC7D,MAAM,EAAE,SAAS,kBAAkB,wBAAwB,EAAE;AAC7D,MAAM,EAAE,UAAU,SAAS,WAAW,EAAE;AAIxC,MAAM,gBAAgB,QAAQC,uCAAc,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,MAAM,SAAS,IAAI,gBAAgB,UAAU,GAAG;AAEhD,QAAO,IAAI,UAAU,OAAO;AAE5B,QAAO,IAAI,OAAO,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;AA0B9B,MAAa,iBACX,SACA,QACA,cACiB;CACjB,MAAM,WAAW,QAAQ,QAAQ;CAEjC,MAAM,cAAc,eAAe,QAAQ;AAE3C,KACE,SAEA,QAAO,eAAe,SAAS,aAAa,SAAS;AAKvD,QAAO,aAAa,S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;AAID,QAAO,WAAW,SAHF,mBACZ,GAAG,WAAW,qBACd,UACgC,WAAW;;;;;;;;;;;AAYjD,MAAM,iBACJ,QACA,MACA,YACA,WACW;CAGX,MAAM,oBAAoB,KAAK,WAAW,IAAI,SAAS,GACnD,KAAK,MAAM,IAAI,SAAS,OAAO,IAAI,MACnC;AAEJ,KAAI,kBAAkB,aAAa;AACjC,MAAI,OACF,QAAO,GAAG,kBAAkB,GAAG;AAGjC,SAAO;;AAGT,KAAI,kBAAkB,iBAAiB;AACrC,MAAI,OACF,QAAO,GAAG,kBAAkB,GAAG;AAGjC,SAAO;;CAGT,MAAM,uBAAuB,KAAK,WAAW,IAAI,SAAS,GACtD,OACA,GAAG,SAAS;AAMhB,QAFgB,GAAGD,aAFWA,WAAS,SAAS,IAAI,GAEE,KAAK,MAAM;;;;;;;;;;AAanE,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,WAAWE,yBAAa,QAAQ,IAAI,IAAI,gBAAgB,QAAQ,IAAI,CAAC;AAE3E,yCAAmB,QAAQ,EACzB,YAAY,MAAc,UACxB,SAAS,QAAQ,IAAI,MAAM,MAAM,EACpC,CAAC;AAEF,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,QAAOA,yBAAa,SAAS,IAAI,IAAI,gBAAgB,QAAQ,IAAI,CAAC"}
|
|
@@ -52,7 +52,7 @@ const getPruneConfig = (intlayerConfig, isBuildCommand, isTurbopackEnabled) => {
|
|
|
52
52
|
const unmergedDictionariesEntryPath = (0, node_path.join)(mainDir, "unmerged_dictionaries.mjs");
|
|
53
53
|
const fetchDictionariesEntryPath = (0, node_path.join)(mainDir, "fetch_dictionaries.mjs");
|
|
54
54
|
const filesList = [
|
|
55
|
-
...fast_glob.default.sync(traversePattern, { cwd: baseDir })
|
|
55
|
+
...fast_glob.default.sync(traversePattern, { cwd: baseDir }),
|
|
56
56
|
dictionariesEntryPath,
|
|
57
57
|
unmergedDictionariesEntryPath
|
|
58
58
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withIntlayer.cjs","names":["nextPackageJSON","ANSIColors","fg","config: Partial<NextConfig>","config","IntlayerPlugin","intlayerNextConfig: Partial<NextConfig>"],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { join, relative, resolve } from 'node:path';\nimport { prepareIntlayer, runOnce } from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colorize,\n compareVersions,\n type GetConfigurationOptions,\n getAlias,\n getAppLogger,\n getConfiguration,\n getProjectRequire,\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' };\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');\nconst isTurbopackStable = compareVersions(\n nextPackageJSON.version,\n '≥',\n '15.3.0'\n);\n\nconst isTurbopackEnabledFromCommand = 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\n// Check if SWC plugin is available\nconst getIsSwcPluginAvailable = (intlayerConfig: IntlayerConfig) => {\n try {\n const requireFunction =\n intlayerConfig.build?.require ?? getProjectRequire();\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 isTurbopackEnabled: boolean\n): string => {\n const requireFunction = intlayerConfig.build?.require ?? getProjectRequire();\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 isBuildCommand: boolean,\n isTurbopackEnabled: boolean\n): Partial<NextConfig> => {\n const { optimize, traversePattern, importMode } = intlayerConfig.build;\n const {\n dictionariesDir,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n baseDir,\n } = intlayerConfig.content;\n const logger = getAppLogger(intlayerConfig);\n\n if (optimize === false) {\n return {};\n }\n if (optimize === undefined && !isBuildCommand) {\n return {};\n }\n\n if (!isGteNext13) return {};\n\n const isSwcPluginAvailable = getIsSwcPluginAvailable(intlayerConfig);\n\n if (!isSwcPluginAvailable) {\n logger([\n colorize('Recommended: Install', ANSIColors.GREY),\n colorize('@intlayer/swc', ANSIColors.GREY_LIGHT),\n colorize(\n 'package to enable build optimization. See documentation: ',\n ANSIColors.GREY\n ),\n colorize(\n 'https://intlayer.org/docs/en/bundle_optimization',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n return {};\n }\n\n runOnce(\n join(baseDir, '.intlayer', 'cache', 'intlayer-prune-plugin-enabled.lock'),\n () => logger('Build optimization 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 unmergedDictionariesEntryPath = join(\n mainDir,\n 'unmerged_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 unmergedDictionariesEntryPath, // 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(\n '@intlayer/swc',\n intlayerConfig,\n isTurbopackEnabled\n ),\n {\n dictionariesDir,\n dictionariesEntryPath,\n unmergedDictionariesEntryPath,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n fetchDictionariesDir,\n fetchDictionariesEntryPath,\n importMode,\n filesList,\n replaceDictionaryEntry: true,\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\ntype WithIntlayerOptions = GetConfigurationOptions & {\n enableTurbopack?: boolean;\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 withIntlayerSync(nextConfig)\n * ```\n */\nexport const withIntlayerSync = <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T,\n configOptions?: WithIntlayerOptions\n): NextConfig & T => {\n if (typeof nextConfig !== 'object') {\n nextConfig = {} as T;\n }\n\n const intlayerConfig = getConfiguration(configOptions);\n const logger = getAppLogger(intlayerConfig);\n\n const isTurbopackEnabled =\n configOptions?.enableTurbopack ?? isTurbopackEnabledFromCommand;\n\n if (isTurbopackEnabled && typeof nextConfig.webpack !== 'undefined') {\n logger(\n 'Turbopack is enabled but a custom webpack config is present. It will be ignored.'\n );\n }\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 // Rspack set external as false by default\n // Overwrite it to allow pushing the desired externals\n if (config.externals === false) {\n config.externals = [];\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 // Optional as rspack not support plugin yet\n config.plugins.push(new IntlayerPlugin(intlayerConfig));\n }\n\n return config;\n },\n };\n }\n\n return config;\n };\n\n const pruneConfig: Partial<NextConfig> = getPruneConfig(\n intlayerConfig,\n isBuildCommand,\n isTurbopackEnabled ?? false\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?: WithIntlayerOptions\n): Promise<NextConfig & T> => {\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n\n // Only call prepareIntlayer during `dev` or `build` (not during `start`)\n // If prod: clean and rebuild once\n // If dev: rebuild only once if it's more than 1 hour since last rebuild\n if (isDevCommand || isBuildCommand) {\n const intlayerConfig = getConfiguration(configOptions);\n\n // prepareIntlayer use runOnce to ensure to run only once because will run twice on client and server side otherwise\n await prepareIntlayer(intlayerConfig, {\n clean: isBuildCommand,\n cacheTimeoutMs: isBuildCommand\n ? 1000 * 30 // 30 seconds for build (to ensure to rebuild all dictionaries)\n : 1000 * 60 * 60, // 1 hour for dev (default cache timeout)\n });\n }\n\n return withIntlayerSync(nextConfig, configOptions);\n};\n"],"mappings":";;;;;;;;;;;;;;AAsBA,MAAM,qDAA8BA,0BAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,qDAA8BA,0BAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,qDAA8BA,0BAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,2DACJA,0BAAgB,SAChB,KACA,SACD;AAED,MAAM,gCAAgC,cAElC,CAAC,QAAQ,IAAI,sBAAsB,SAAS,YAAY,GAExD,QAAQ,IAAI,sBAAsB,SAAS,UAAU;AAGzD,MAAM,2BAA2B,mBAAmC;AAClE,KAAI;AAGF,GADE,eAAe,OAAO,qDAA8B,EACtC,QAAQ,gBAAgB;AACxC,SAAO;UACA,IAAI;AACX,SAAO;;;AAIX,MAAM,qBACJ,YACA,gBACA,uBACW;CAEX,MAAM,sBADkB,eAAe,OAAO,qDAA8B,GAChC,QAAQ,WAAW;AAE/D,KAAI,mBAEF,6CAAqB,6BAAc,QAAQ,KAAK,EAAE,mBAAmB,GAAG;AAG1E,QAAO;;AAGT,MAAM,kBACJ,gBACA,gBACA,uBACwB;CACxB,MAAM,EAAE,UAAU,iBAAiB,eAAe,eAAe;CACjE,MAAM,EACJ,iBACA,yBACA,wBACA,sBACA,SACA,YACE,eAAe;CACnB,MAAM,6CAA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,aAAO,UAAU,KAAK;KACpB,SAAS;KACT,QAAQ;KACR,IAAI;KACJ,UAAU;KACV,UAAU;KACX,CAAC;AAGF,aAAO,OAAO,MAAM,KAAK;KACvB,MAAM;KACN,QAAQ;KACT,CAAC;AAIF,aAAO,QAAQ,QAAQ;KACrB,GAAGA,SAAO,QAAQ;KAClB,mCAAY;MACV,eAAe;MACf,YAAY,iCAA0B,MAAM;MAC7C,CAAC;KACH;AAGD,QAAI,gBAAgB,YAAY,gBAAgB,SAE9C,UAAO,QAAQ,KAAK,IAAIC,kCAAe,eAAe,CAAC;AAGzD,WAAOD;;GAEV;AAGH,SAAO;;CAST,MAAME,4CANmC,eACvC,gBACA,gBACA,sBAAsB,MACvB,EAIC,cAAc,CACf;AAKD,+BAFqB,YAAY,mBAAmB;;;;;;;;;;;;;;;;;AAoBtD,MAAa,eAAe,OAC1B,aAAgB,EAAE,EAClB,kBAC4B;CAC5B,MAAM,EAAE,gBAAgB,iBAAiB,kBAAkB;AAK3D,KAAI,gBAAgB,eAIlB,wFAHwC,cAAc,EAGhB;EACpC,OAAO;EACP,gBAAgB,iBACZ,MAAO,KACP,MAAO,KAAK;EACjB,CAAC;AAGJ,QAAO,iBAAiB,YAAY,cAAc"}
|
|
1
|
+
{"version":3,"file":"withIntlayer.cjs","names":["nextPackageJSON","ANSIColors","fg","config: Partial<NextConfig>","config","IntlayerPlugin","intlayerNextConfig: Partial<NextConfig>"],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { join, relative, resolve } from 'node:path';\nimport { prepareIntlayer, runOnce } from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colorize,\n compareVersions,\n type GetConfigurationOptions,\n getAlias,\n getAppLogger,\n getConfiguration,\n getProjectRequire,\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' };\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');\nconst isTurbopackStable = compareVersions(\n nextPackageJSON.version,\n '≥',\n '15.3.0'\n);\n\nconst isTurbopackEnabledFromCommand = 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\n// Check if SWC plugin is available\nconst getIsSwcPluginAvailable = (intlayerConfig: IntlayerConfig) => {\n try {\n const requireFunction =\n intlayerConfig.build?.require ?? getProjectRequire();\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 isTurbopackEnabled: boolean\n): string => {\n const requireFunction = intlayerConfig.build?.require ?? getProjectRequire();\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 isBuildCommand: boolean,\n isTurbopackEnabled: boolean\n): Partial<NextConfig> => {\n const { optimize, traversePattern, importMode } = intlayerConfig.build;\n const {\n dictionariesDir,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n baseDir,\n } = intlayerConfig.content;\n const logger = getAppLogger(intlayerConfig);\n\n if (optimize === false) {\n return {};\n }\n if (optimize === undefined && !isBuildCommand) {\n return {};\n }\n\n if (!isGteNext13) return {};\n\n const isSwcPluginAvailable = getIsSwcPluginAvailable(intlayerConfig);\n\n if (!isSwcPluginAvailable) {\n logger([\n colorize('Recommended: Install', ANSIColors.GREY),\n colorize('@intlayer/swc', ANSIColors.GREY_LIGHT),\n colorize(\n 'package to enable build optimization. See documentation: ',\n ANSIColors.GREY\n ),\n colorize(\n 'https://intlayer.org/docs/en/bundle_optimization',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n return {};\n }\n\n runOnce(\n join(baseDir, '.intlayer', 'cache', 'intlayer-prune-plugin-enabled.lock'),\n () => logger('Build optimization 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 unmergedDictionariesEntryPath = join(\n mainDir,\n 'unmerged_dictionaries.mjs'\n );\n\n const fetchDictionariesEntryPath = join(mainDir, 'fetch_dictionaries.mjs');\n\n const filesListPattern = fg.sync(traversePattern, {\n cwd: baseDir,\n });\n\n const filesList = [\n ...filesListPattern,\n dictionariesEntryPath, // should add dictionariesEntryPath to replace it by a empty object if import made dynamic\n unmergedDictionariesEntryPath, // 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(\n '@intlayer/swc',\n intlayerConfig,\n isTurbopackEnabled\n ),\n {\n dictionariesDir,\n dictionariesEntryPath,\n unmergedDictionariesEntryPath,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n fetchDictionariesDir,\n fetchDictionariesEntryPath,\n importMode,\n filesList,\n replaceDictionaryEntry: true,\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\ntype WithIntlayerOptions = GetConfigurationOptions & {\n enableTurbopack?: boolean;\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 withIntlayerSync(nextConfig)\n * ```\n */\nexport const withIntlayerSync = <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T,\n configOptions?: WithIntlayerOptions\n): NextConfig & T => {\n if (typeof nextConfig !== 'object') {\n nextConfig = {} as T;\n }\n\n const intlayerConfig = getConfiguration(configOptions);\n const logger = getAppLogger(intlayerConfig);\n\n const isTurbopackEnabled =\n configOptions?.enableTurbopack ?? isTurbopackEnabledFromCommand;\n\n if (isTurbopackEnabled && typeof nextConfig.webpack !== 'undefined') {\n logger(\n 'Turbopack is enabled but a custom webpack config is present. It will be ignored.'\n );\n }\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 // Rspack set external as false by default\n // Overwrite it to allow pushing the desired externals\n if (config.externals === false) {\n config.externals = [];\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 // Optional as rspack not support plugin yet\n config.plugins.push(new IntlayerPlugin(intlayerConfig));\n }\n\n return config;\n },\n };\n }\n\n return config;\n };\n\n const pruneConfig: Partial<NextConfig> = getPruneConfig(\n intlayerConfig,\n isBuildCommand,\n isTurbopackEnabled ?? false\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?: WithIntlayerOptions\n): Promise<NextConfig & T> => {\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n\n // Only call prepareIntlayer during `dev` or `build` (not during `start`)\n // If prod: clean and rebuild once\n // If dev: rebuild only once if it's more than 1 hour since last rebuild\n if (isDevCommand || isBuildCommand) {\n const intlayerConfig = getConfiguration(configOptions);\n\n // prepareIntlayer use runOnce to ensure to run only once because will run twice on client and server side otherwise\n await prepareIntlayer(intlayerConfig, {\n clean: isBuildCommand,\n cacheTimeoutMs: isBuildCommand\n ? 1000 * 30 // 30 seconds for build (to ensure to rebuild all dictionaries)\n : 1000 * 60 * 60, // 1 hour for dev (default cache timeout)\n });\n }\n\n return withIntlayerSync(nextConfig, configOptions);\n};\n"],"mappings":";;;;;;;;;;;;;;AAsBA,MAAM,qDAA8BA,0BAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,qDAA8BA,0BAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,qDAA8BA,0BAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,2DACJA,0BAAgB,SAChB,KACA,SACD;AAED,MAAM,gCAAgC,cAElC,CAAC,QAAQ,IAAI,sBAAsB,SAAS,YAAY,GAExD,QAAQ,IA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 +177,12 @@ const handleCookieLocaleMismatch = (request, pathname, pathLocale, localLocale,
|
|
|
177
177
|
*/
|
|
178
178
|
const handleDefaultLocaleRedirect = (request, pathLocale, pathname) => {
|
|
179
179
|
if (!prefixDefault && pathLocale === defaultLocale) {
|
|
180
|
-
let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length)
|
|
180
|
+
let pathWithoutLocale = pathname.slice(`/${pathLocale}`.length) || "/";
|
|
181
181
|
if (basePath.endsWith("/")) pathWithoutLocale = pathWithoutLocale.slice(1);
|
|
182
182
|
const searchWithLocale$1 = appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale);
|
|
183
183
|
if (searchWithLocale$1) pathWithoutLocale += searchWithLocale$1;
|
|
184
184
|
else if (request.nextUrl.search) pathWithoutLocale += request.nextUrl.search;
|
|
185
|
-
return
|
|
185
|
+
return redirectUrl(request, `${basePath}${pathWithoutLocale}`);
|
|
186
186
|
}
|
|
187
187
|
const searchWithLocale = appendLocaleSearchIfNeeded(request.nextUrl.search, pathLocale);
|
|
188
188
|
return rewriteUrl(request, searchWithLocale ? `${pathname}${searchWithLocale}` : pathname, pathLocale);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"intlayerProxy.mjs","names":["search","localeDetector","basePath","searchWithLocale"],"sources":["../../../src/proxy/intlayerProxy.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\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"],"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,MAAM,SAAS,IAAI,gBAAgB,UAAU,GAAG;AAEhD,QAAO,IAAI,UAAU,OAAO;AAE5B,QAAO,IAAI,OAAO,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;AA0B9B,MAAa,iBACX,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
{"version":3,"file":"intlayerProxy.mjs","names":["search","localeDetector","basePath","searchWithLocale"],"sources":["../../../src/proxy/intlayerProxy.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\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 redirectUrl(request, `${basePath}${pathWithoutLocale}`);\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"],"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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,MAAM,iBACJ,UAAU,CAAC,QAAQ,SAAS,IAAI,GAAG,GAAG,UAAU,WAAW;CAE7D,MAAM,WAAW,aAAa,QAAQ,IAAI,IAAI,gBAAgB,QAAQ,IAAI,CAAC;AAE3E,oBAAmB,QAAQ,EACzB,YAAY,MAAc,UACxB,SAAS,QAAQ,IAAI,MAAM,MAAM,EACpC,CAAC;AAEF,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"}
|
|
@@ -48,7 +48,7 @@ const getPruneConfig = (intlayerConfig, isBuildCommand, isTurbopackEnabled) => {
|
|
|
48
48
|
const unmergedDictionariesEntryPath = join(mainDir, "unmerged_dictionaries.mjs");
|
|
49
49
|
const fetchDictionariesEntryPath = join(mainDir, "fetch_dictionaries.mjs");
|
|
50
50
|
const filesList = [
|
|
51
|
-
...fg.sync(traversePattern, { cwd: baseDir })
|
|
51
|
+
...fg.sync(traversePattern, { cwd: baseDir }),
|
|
52
52
|
dictionariesEntryPath,
|
|
53
53
|
unmergedDictionariesEntryPath
|
|
54
54
|
];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withIntlayer.mjs","names":["config: Partial<NextConfig>","config","intlayerNextConfig: Partial<NextConfig>"],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { join, relative, resolve } from 'node:path';\nimport { prepareIntlayer, runOnce } from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colorize,\n compareVersions,\n type GetConfigurationOptions,\n getAlias,\n getAppLogger,\n getConfiguration,\n getProjectRequire,\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' };\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');\nconst isTurbopackStable = compareVersions(\n nextPackageJSON.version,\n '≥',\n '15.3.0'\n);\n\nconst isTurbopackEnabledFromCommand = 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\n// Check if SWC plugin is available\nconst getIsSwcPluginAvailable = (intlayerConfig: IntlayerConfig) => {\n try {\n const requireFunction =\n intlayerConfig.build?.require ?? getProjectRequire();\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 isTurbopackEnabled: boolean\n): string => {\n const requireFunction = intlayerConfig.build?.require ?? getProjectRequire();\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 isBuildCommand: boolean,\n isTurbopackEnabled: boolean\n): Partial<NextConfig> => {\n const { optimize, traversePattern, importMode } = intlayerConfig.build;\n const {\n dictionariesDir,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n baseDir,\n } = intlayerConfig.content;\n const logger = getAppLogger(intlayerConfig);\n\n if (optimize === false) {\n return {};\n }\n if (optimize === undefined && !isBuildCommand) {\n return {};\n }\n\n if (!isGteNext13) return {};\n\n const isSwcPluginAvailable = getIsSwcPluginAvailable(intlayerConfig);\n\n if (!isSwcPluginAvailable) {\n logger([\n colorize('Recommended: Install', ANSIColors.GREY),\n colorize('@intlayer/swc', ANSIColors.GREY_LIGHT),\n colorize(\n 'package to enable build optimization. See documentation: ',\n ANSIColors.GREY\n ),\n colorize(\n 'https://intlayer.org/docs/en/bundle_optimization',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n return {};\n }\n\n runOnce(\n join(baseDir, '.intlayer', 'cache', 'intlayer-prune-plugin-enabled.lock'),\n () => logger('Build optimization 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 unmergedDictionariesEntryPath = join(\n mainDir,\n 'unmerged_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 unmergedDictionariesEntryPath, // 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(\n '@intlayer/swc',\n intlayerConfig,\n isTurbopackEnabled\n ),\n {\n dictionariesDir,\n dictionariesEntryPath,\n unmergedDictionariesEntryPath,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n fetchDictionariesDir,\n fetchDictionariesEntryPath,\n importMode,\n filesList,\n replaceDictionaryEntry: true,\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\ntype WithIntlayerOptions = GetConfigurationOptions & {\n enableTurbopack?: boolean;\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 withIntlayerSync(nextConfig)\n * ```\n */\nexport const withIntlayerSync = <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T,\n configOptions?: WithIntlayerOptions\n): NextConfig & T => {\n if (typeof nextConfig !== 'object') {\n nextConfig = {} as T;\n }\n\n const intlayerConfig = getConfiguration(configOptions);\n const logger = getAppLogger(intlayerConfig);\n\n const isTurbopackEnabled =\n configOptions?.enableTurbopack ?? isTurbopackEnabledFromCommand;\n\n if (isTurbopackEnabled && typeof nextConfig.webpack !== 'undefined') {\n logger(\n 'Turbopack is enabled but a custom webpack config is present. It will be ignored.'\n );\n }\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 // Rspack set external as false by default\n // Overwrite it to allow pushing the desired externals\n if (config.externals === false) {\n config.externals = [];\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 // Optional as rspack not support plugin yet\n config.plugins.push(new IntlayerPlugin(intlayerConfig));\n }\n\n return config;\n },\n };\n }\n\n return config;\n };\n\n const pruneConfig: Partial<NextConfig> = getPruneConfig(\n intlayerConfig,\n isBuildCommand,\n isTurbopackEnabled ?? false\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?: WithIntlayerOptions\n): Promise<NextConfig & T> => {\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n\n // Only call prepareIntlayer during `dev` or `build` (not during `start`)\n // If prod: clean and rebuild once\n // If dev: rebuild only once if it's more than 1 hour since last rebuild\n if (isDevCommand || isBuildCommand) {\n const intlayerConfig = getConfiguration(configOptions);\n\n // prepareIntlayer use runOnce to ensure to run only once because will run twice on client and server side otherwise\n await prepareIntlayer(intlayerConfig, {\n clean: isBuildCommand,\n cacheTimeoutMs: isBuildCommand\n ? 1000 * 30 // 30 seconds for build (to ensure to rebuild all dictionaries)\n : 1000 * 60 * 60, // 1 hour for dev (default cache timeout)\n });\n }\n\n return withIntlayerSync(nextConfig, configOptions);\n};\n"],"mappings":";;;;;;;;;;AAsBA,MAAM,cAAc,gBAAgB,gBAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,cAAc,gBAAgB,gBAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,cAAc,gBAAgB,gBAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,oBAAoB,gBACxB,gBAAgB,SACh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B,EAAE,EAClB,kBAC4B;CAC5B,MAAM,EAAE,gBAAgB,iBAAiB,kBAAkB;AAK3D,KAAI,gBAAgB,eAIlB,OAAM,gBAHiB,iBAAiB,cAAc,EAGhB;EACpC,OAAO;EACP,gBAAgB,iBACZ,MAAO,KACP,MAAO,KAAK;EACjB,CAAC;AAGJ,QAAO,iBAAiB,YAAY,cAAc"}
|
|
1
|
+
{"version":3,"file":"withIntlayer.mjs","names":["config: Partial<NextConfig>","config","intlayerNextConfig: Partial<NextConfig>"],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { join, relative, resolve } from 'node:path';\nimport { prepareIntlayer, runOnce } from '@intlayer/chokidar';\nimport {\n ANSIColors,\n colorize,\n compareVersions,\n type GetConfigurationOptions,\n getAlias,\n getAppLogger,\n getConfiguration,\n getProjectRequire,\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' };\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');\nconst isTurbopackStable = compareVersions(\n nextPackageJSON.version,\n '≥',\n '15.3.0'\n);\n\nconst isTurbopackEnabledFromCommand = 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\n// Check if SWC plugin is available\nconst getIsSwcPluginAvailable = (intlayerConfig: IntlayerConfig) => {\n try {\n const requireFunction =\n intlayerConfig.build?.require ?? getProjectRequire();\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 isTurbopackEnabled: boolean\n): string => {\n const requireFunction = intlayerConfig.build?.require ?? getProjectRequire();\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 isBuildCommand: boolean,\n isTurbopackEnabled: boolean\n): Partial<NextConfig> => {\n const { optimize, traversePattern, importMode } = intlayerConfig.build;\n const {\n dictionariesDir,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n baseDir,\n } = intlayerConfig.content;\n const logger = getAppLogger(intlayerConfig);\n\n if (optimize === false) {\n return {};\n }\n if (optimize === undefined && !isBuildCommand) {\n return {};\n }\n\n if (!isGteNext13) return {};\n\n const isSwcPluginAvailable = getIsSwcPluginAvailable(intlayerConfig);\n\n if (!isSwcPluginAvailable) {\n logger([\n colorize('Recommended: Install', ANSIColors.GREY),\n colorize('@intlayer/swc', ANSIColors.GREY_LIGHT),\n colorize(\n 'package to enable build optimization. See documentation: ',\n ANSIColors.GREY\n ),\n colorize(\n 'https://intlayer.org/docs/en/bundle_optimization',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n return {};\n }\n\n runOnce(\n join(baseDir, '.intlayer', 'cache', 'intlayer-prune-plugin-enabled.lock'),\n () => logger('Build optimization 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 unmergedDictionariesEntryPath = join(\n mainDir,\n 'unmerged_dictionaries.mjs'\n );\n\n const fetchDictionariesEntryPath = join(mainDir, 'fetch_dictionaries.mjs');\n\n const filesListPattern = fg.sync(traversePattern, {\n cwd: baseDir,\n });\n\n const filesList = [\n ...filesListPattern,\n dictionariesEntryPath, // should add dictionariesEntryPath to replace it by a empty object if import made dynamic\n unmergedDictionariesEntryPath, // 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(\n '@intlayer/swc',\n intlayerConfig,\n isTurbopackEnabled\n ),\n {\n dictionariesDir,\n dictionariesEntryPath,\n unmergedDictionariesEntryPath,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n fetchDictionariesDir,\n fetchDictionariesEntryPath,\n importMode,\n filesList,\n replaceDictionaryEntry: true,\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\ntype WithIntlayerOptions = GetConfigurationOptions & {\n enableTurbopack?: boolean;\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 withIntlayerSync(nextConfig)\n * ```\n */\nexport const withIntlayerSync = <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T,\n configOptions?: WithIntlayerOptions\n): NextConfig & T => {\n if (typeof nextConfig !== 'object') {\n nextConfig = {} as T;\n }\n\n const intlayerConfig = getConfiguration(configOptions);\n const logger = getAppLogger(intlayerConfig);\n\n const isTurbopackEnabled =\n configOptions?.enableTurbopack ?? isTurbopackEnabledFromCommand;\n\n if (isTurbopackEnabled && typeof nextConfig.webpack !== 'undefined') {\n logger(\n 'Turbopack is enabled but a custom webpack config is present. It will be ignored.'\n );\n }\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 // Rspack set external as false by default\n // Overwrite it to allow pushing the desired externals\n if (config.externals === false) {\n config.externals = [];\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 // Optional as rspack not support plugin yet\n config.plugins.push(new IntlayerPlugin(intlayerConfig));\n }\n\n return config;\n },\n };\n }\n\n return config;\n };\n\n const pruneConfig: Partial<NextConfig> = getPruneConfig(\n intlayerConfig,\n isBuildCommand,\n isTurbopackEnabled ?? false\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?: WithIntlayerOptions\n): Promise<NextConfig & T> => {\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n\n // Only call prepareIntlayer during `dev` or `build` (not during `start`)\n // If prod: clean and rebuild once\n // If dev: rebuild only once if it's more than 1 hour since last rebuild\n if (isDevCommand || isBuildCommand) {\n const intlayerConfig = getConfiguration(configOptions);\n\n // prepareIntlayer use runOnce to ensure to run only once because will run twice on client and server side otherwise\n await prepareIntlayer(intlayerConfig, {\n clean: isBuildCommand,\n cacheTimeoutMs: isBuildCommand\n ? 1000 * 30 // 30 seconds for build (to ensure to rebuild all dictionaries)\n : 1000 * 60 * 60, // 1 hour for dev (default cache timeout)\n });\n }\n\n return withIntlayerSync(nextConfig, configOptions);\n};\n"],"mappings":";;;;;;;;;;AAsBA,MAAM,cAAc,gBAAgB,gBAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,cAAc,gBAAgB,gBAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,cAAc,gBAAgB,gBAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,oBAAoB,gBACxB,gBAAgB,SAChB,KACA,SACD;AAED,MAAM,gCAAgC,cAElC,CAAC,QAAQ,IAAI,sBAAsB,SAAS,YAAY,GAExD,QAAQ,IAAI,sBAAsB,SAAS,UAAU;AAGzD,MAAM,2BAA2B,mBAAmC;AAClE,KAAI;AAGF,GADE,eAAe,OAAO,WAAW,mBAAmB,EACtC,QAAQ,gBAAgB;AACxC,SAAO;UACA,IAAI;AACX,SAAO;;;AAIX,MAAM,qBACJ,YACA,gBACA,uBACW;CAEX,MAAM,sBADkB,eAAe,OAAO,WAAW,mBAAmB,GAChC,QAAQ,WAAW;AAE/D,KAAI,mBAEF,QAAO,cAAc,KAAK,SAAS,QAAQ,KAAK,EAAE,mBAAmB,GAAG;AAG1E,QAAO;;AAGT,MAAM,kBACJ,gBACA,gBACA,uBACwB;CACxB,MAAM,EAAE,UAAU,iBAAiB,eAAe,eAAe;CACjE,MAAM,EACJ,iBACA,yBACA,wBACA,sBACA,SACA,YACE,eAAe;CACnB,MAAM,SAAS,aAAa,eAAe;AAE3C,KAAI,aAAa,M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KAAK;KACpB,SAAS;KACT,QAAQ;KACR,IAAI;KACJ,UAAU;KACV,UAAU;KACX,CAAC;AAGF,aAAO,OAAO,MAAM,KAAK;KACvB,MAAM;KACN,QAAQ;KACT,CAAC;AAIF,aAAO,QAAQ,QAAQ;KACrB,GAAGA,SAAO,QAAQ;KAClB,GAAG,SAAS;MACV,eAAe;MACf,YAAY,UAAkB,QAAQ,MAAM;MAC7C,CAAC;KACH;AAGD,QAAI,gBAAgB,YAAY,gBAAgB,SAE9C,UAAO,QAAQ,KAAK,IAAI,eAAe,eAAe,CAAC;AAGzD,WAAOA;;GAEV;AAGH,SAAO;;CAST,MAAMC,qBAA0C,MANP,eACvC,gBACA,gBACA,sBAAsB,MACvB,EAIC,cAAc,CACf;AAKD,QAFe,MAAM,YAAY,mBAAmB;;;;;;;;;;;;;;;;;AAoBtD,MAAa,eAAe,OAC1B,aAAgB,EAAE,EAClB,kBAC4B;CAC5B,MAAM,EAAE,gBAAgB,iBAAiB,kBAAkB;AAK3D,KAAI,gBAAgB,eAIlB,OAAM,gBAHiB,iBAAiB,cAAc,EAGhB;EACpC,OAAO;EACP,gBAAgB,iBACZ,MAAO,KACP,MAAO,KAAK;EACjB,CAAC;AAGJ,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,cAkBQ,SAlBM,
|
|
1
|
+
{"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":[],"mappings":";;;;KAQK,cAAA;4CACuC;;AADvC,cAkBQ,SAlBM,EAAA,CACyB;EAAA;AAAa,CAAA,CAAb,EAiBJ,cAjBiB,EAAA,GAAA;EAiB5C,iBAiCZ,EAAA,MAAA;EAjCyB,MAAA,EAAiC,gBAAA,CAAA,eAAjC;EAAc,aAAA,kCAAA;EAAmB,gBAAA,oCAAA"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as _intlayer_types0 from "@intlayer/types";
|
|
2
2
|
import { LocalesValues } from "@intlayer/types";
|
|
3
3
|
|
|
4
4
|
//#region src/client/useLocalePageRouter.d.ts
|
|
5
5
|
declare const useLocalePageRouter: () => {
|
|
6
6
|
pathWithoutLocale: string;
|
|
7
|
-
locale:
|
|
8
|
-
defaultLocale:
|
|
9
|
-
availableLocales:
|
|
7
|
+
locale: _intlayer_types0.DeclaredLocales;
|
|
8
|
+
defaultLocale: _intlayer_types0.DeclaredLocales;
|
|
9
|
+
availableLocales: _intlayer_types0.DeclaredLocales[];
|
|
10
10
|
setLocale: (locale: LocalesValues) => void;
|
|
11
11
|
};
|
|
12
12
|
//#endregion
|
|
@@ -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":";;;;KA2MK,mBAAA,GAAsB;;AAzLY,CAAA;AAwMvC;;;;;;;;AA0KA;;;AACc,cA3KD,gBA2KC,EAAA,CAAA,UA3K6B,OA2K7B,CA3KqC,UA2KrC,CAAA,CAAA,CAAA,UAAA,CAAA,EA1KA,CA0KA,EAAA,aAAA,CAAA,EAzKI,mBAyKJ,EAAA,GAxKX,UAwKW,GAxKE,CAwKF;;;;;;;;;;;;;;;;cADD,yBAAgC,QAAQ,0BACvC,mBACI,wBACf,QAAQ,aAAa"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intlayer",
|
|
3
|
-
"version": "7.3.
|
|
3
|
+
"version": "7.3.5",
|
|
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": [
|
|
@@ -118,16 +118,16 @@
|
|
|
118
118
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
119
119
|
},
|
|
120
120
|
"dependencies": {
|
|
121
|
-
"@intlayer/chokidar": "7.3.
|
|
122
|
-
"@intlayer/config": "7.3.
|
|
123
|
-
"@intlayer/core": "7.3.
|
|
124
|
-
"@intlayer/dictionaries-entry": "7.3.
|
|
125
|
-
"@intlayer/types": "7.3.
|
|
126
|
-
"@intlayer/webpack": "7.3.
|
|
121
|
+
"@intlayer/chokidar": "7.3.5",
|
|
122
|
+
"@intlayer/config": "7.3.5",
|
|
123
|
+
"@intlayer/core": "7.3.5",
|
|
124
|
+
"@intlayer/dictionaries-entry": "7.3.5",
|
|
125
|
+
"@intlayer/types": "7.3.5",
|
|
126
|
+
"@intlayer/webpack": "7.3.5",
|
|
127
127
|
"deepmerge": "4.3.1",
|
|
128
128
|
"fast-glob": "3.3.3",
|
|
129
129
|
"node-loader": "2.1.0",
|
|
130
|
-
"react-intlayer": "7.3.
|
|
130
|
+
"react-intlayer": "7.3.5"
|
|
131
131
|
},
|
|
132
132
|
"devDependencies": {
|
|
133
133
|
"@types/node": "24.10.1",
|