next-intlayer 7.5.0-canary.1 → 7.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/client/useLocale.cjs +3 -3
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocalePageRouter.cjs +3 -3
- package/dist/cjs/client/useLocalePageRouter.cjs.map +1 -1
- package/dist/cjs/generateStaticParams.cjs +3 -3
- package/dist/cjs/generateStaticParams.cjs.map +1 -1
- package/dist/cjs/proxy/intlayerProxy.cjs +8 -8
- package/dist/cjs/proxy/intlayerProxy.cjs.map +1 -1
- package/dist/cjs/proxy/localeDetector.cjs +2 -2
- package/dist/cjs/proxy/localeDetector.cjs.map +1 -1
- package/dist/cjs/server/getLocale.cjs +7 -7
- package/dist/cjs/server/getLocale.cjs.map +1 -1
- package/dist/cjs/server/withIntlayer.cjs +26 -26
- package/dist/cjs/server/withIntlayer.cjs.map +1 -1
- package/package.json +10 -10
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
4
4
|
let react_intlayer = require("react-intlayer");
|
|
5
|
-
let
|
|
5
|
+
let _intlayer_core = require("@intlayer/core");
|
|
6
6
|
let next_navigation_js = require("next/navigation.js");
|
|
7
7
|
let react = require("react");
|
|
8
8
|
|
|
@@ -14,7 +14,7 @@ const usePathWithoutLocale = () => {
|
|
|
14
14
|
const search = typeof window !== "undefined" ? window.location.search : "";
|
|
15
15
|
setFullPath(search ? `${pathname}${search}` : pathname);
|
|
16
16
|
}, [pathname]);
|
|
17
|
-
return (0, react.useMemo)(() => (0,
|
|
17
|
+
return (0, react.useMemo)(() => (0, _intlayer_core.getPathWithoutLocale)(fullPath), [fullPath]);
|
|
18
18
|
};
|
|
19
19
|
const useLocale = ({ onChange } = {}) => {
|
|
20
20
|
const { replace, push } = (0, next_navigation_js.useRouter)();
|
|
@@ -26,7 +26,7 @@ const useLocale = ({ onChange } = {}) => {
|
|
|
26
26
|
onChange(locale);
|
|
27
27
|
return;
|
|
28
28
|
}
|
|
29
|
-
const pathWithLocale = (0,
|
|
29
|
+
const pathWithLocale = (0, _intlayer_core.getLocalizedUrl)(pathWithoutLocale, locale);
|
|
30
30
|
if (onChange === "replace") replace(pathWithLocale);
|
|
31
31
|
if (onChange === "push") push(pathWithLocale);
|
|
32
32
|
}, [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.cjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { getLocalizedUrl, getPathWithoutLocale } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { usePathname, useRouter } from 'next/navigation.js';\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\ntype UseLocaleProps = {\n onChange?: 'replace' | 'push' | ((locale: LocalesValues) => void);\n};\n\nconst usePathWithoutLocale = () => {\n const pathname = usePathname(); // updates on client navigations\n const [fullPath, setFullPath] = useState(pathname);\n\n useEffect(() => {\n // Runs only on client; avoids suspense.\n const search = typeof window !== 'undefined' ? window.location.search : '';\n setFullPath(search ? `${pathname}${search}` : pathname);\n }, [pathname]);\n\n // Your own helper\n return useMemo(() => getPathWithoutLocale(fullPath), [fullPath]);\n};\n\nexport const useLocale = ({ onChange }: UseLocaleProps = {}) => {\n const { replace, push } = useRouter();\n const pathWithoutLocale = usePathWithoutLocale();\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n if (!onChange) return;\n\n if (typeof onChange === 'function') {\n onChange(locale);\n return;\n }\n\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n if (onChange === 'replace') {\n replace(pathWithLocale);\n }\n if (onChange === 'push') {\n push(pathWithLocale);\n }\n },\n [replace, push, pathWithoutLocale, onChange]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":";;;;;;;;;AAYA,MAAM,6BAA6B;CACjC,MAAM,gDAAwB;CAC9B,MAAM,CAAC,UAAU,mCAAwB,SAAS;AAElD,4BAAgB;EAEd,MAAM,SAAS,OAAO,WAAW,cAAc,OAAO,SAAS,SAAS;AACxE,cAAY,SAAS,GAAG,WAAW,WAAW,SAAS;IACtD,CAAC,SAAS,CAAC;AAGd,
|
|
1
|
+
{"version":3,"file":"useLocale.cjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { getLocalizedUrl, getPathWithoutLocale } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { usePathname, useRouter } from 'next/navigation.js';\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\ntype UseLocaleProps = {\n onChange?: 'replace' | 'push' | ((locale: LocalesValues) => void);\n};\n\nconst usePathWithoutLocale = () => {\n const pathname = usePathname(); // updates on client navigations\n const [fullPath, setFullPath] = useState(pathname);\n\n useEffect(() => {\n // Runs only on client; avoids suspense.\n const search = typeof window !== 'undefined' ? window.location.search : '';\n setFullPath(search ? `${pathname}${search}` : pathname);\n }, [pathname]);\n\n // Your own helper\n return useMemo(() => getPathWithoutLocale(fullPath), [fullPath]);\n};\n\nexport const useLocale = ({ onChange }: UseLocaleProps = {}) => {\n const { replace, push } = useRouter();\n const pathWithoutLocale = usePathWithoutLocale();\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n if (!onChange) return;\n\n if (typeof onChange === 'function') {\n onChange(locale);\n return;\n }\n\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n if (onChange === 'replace') {\n replace(pathWithLocale);\n }\n if (onChange === 'push') {\n push(pathWithLocale);\n }\n },\n [replace, push, pathWithoutLocale, onChange]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":";;;;;;;;;AAYA,MAAM,6BAA6B;CACjC,MAAM,gDAAwB;CAC9B,MAAM,CAAC,UAAU,mCAAwB,SAAS;AAElD,4BAAgB;EAEd,MAAM,SAAS,OAAO,WAAW,cAAc,OAAO,SAAS,SAAS;AACxE,cAAY,SAAS,GAAG,WAAW,WAAW,SAAS;IACtD,CAAC,SAAS,CAAC;AAGd,0EAA0C,SAAS,EAAE,CAAC,SAAS,CAAC;;AAGlE,MAAa,aAAa,EAAE,aAA6B,EAAE,KAAK;CAC9D,MAAM,EAAE,SAAS,4CAAoB;CACrC,MAAM,oBAAoB,sBAAsB;AA2BhD,QAAO;EACL,iCALqC,EACrC,wCArBC,WAA0B;AACzB,OAAI,CAAC,SAAU;AAEf,OAAI,OAAO,aAAa,YAAY;AAClC,aAAS,OAAO;AAChB;;GAGF,MAAM,qDAAiC,mBAAmB,OAAO;AAEjE,OAAI,aAAa,UACf,SAAQ,eAAe;AAEzB,OAAI,aAAa,OACf,MAAK,eAAe;KAGxB;GAAC;GAAS;GAAM;GAAmB;GAAS,CAC7C,EAIA,CAAC;EAIA;EACD"}
|
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
4
4
|
let react_intlayer = require("react-intlayer");
|
|
5
|
-
let
|
|
5
|
+
let _intlayer_core = require("@intlayer/core");
|
|
6
6
|
let react = require("react");
|
|
7
7
|
let next_router_js = require("next/router.js");
|
|
8
8
|
|
|
9
9
|
//#region src/client/useLocalePageRouter.ts
|
|
10
10
|
const useLocalePageRouter = () => {
|
|
11
11
|
const { push, pathname, reload } = (0, next_router_js.useRouter)();
|
|
12
|
-
const pathWithoutLocale = (0, react.useMemo)(() => (0,
|
|
12
|
+
const pathWithoutLocale = (0, react.useMemo)(() => (0, _intlayer_core.getPathWithoutLocale)(pathname), [pathname]);
|
|
13
13
|
return {
|
|
14
14
|
...(0, react_intlayer.useLocale)({ onLocaleChange: (0, react.useCallback)((locale) => {
|
|
15
|
-
push((0,
|
|
15
|
+
push((0, _intlayer_core.getLocalizedUrl)(pathWithoutLocale, locale));
|
|
16
16
|
return reload();
|
|
17
17
|
}, [pathWithoutLocale]) }),
|
|
18
18
|
pathWithoutLocale
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalePageRouter.cjs","names":[],"sources":["../../../src/client/useLocalePageRouter.ts"],"sourcesContent":["'use client';\n\nimport { getLocalizedUrl, getPathWithoutLocale } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { useRouter } from 'next/router.js';\nimport { useCallback, useMemo } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\nexport const useLocalePageRouter = () => {\n const { push, pathname, reload } = useRouter();\n const pathWithoutLocale = useMemo(\n () => getPathWithoutLocale(pathname),\n [pathname]\n );\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n push(pathWithLocale);\n\n return reload();\n },\n [pathWithoutLocale]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":";;;;;;;;;AAQA,MAAa,4BAA4B;CACvC,MAAM,EAAE,MAAM,UAAU,0CAAsB;CAC9C,MAAM,
|
|
1
|
+
{"version":3,"file":"useLocalePageRouter.cjs","names":[],"sources":["../../../src/client/useLocalePageRouter.ts"],"sourcesContent":["'use client';\n\nimport { getLocalizedUrl, getPathWithoutLocale } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { useRouter } from 'next/router.js';\nimport { useCallback, useMemo } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\nexport const useLocalePageRouter = () => {\n const { push, pathname, reload } = useRouter();\n const pathWithoutLocale = useMemo(\n () => getPathWithoutLocale(pathname),\n [pathname]\n );\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n push(pathWithLocale);\n\n return reload();\n },\n [pathWithoutLocale]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":";;;;;;;;;AAQA,MAAa,4BAA4B;CACvC,MAAM,EAAE,MAAM,UAAU,0CAAsB;CAC9C,MAAM,sFACuB,SAAS,EACpC,CAAC,SAAS,CACX;AAiBD,QAAO;EACL,iCALqC,EACrC,wCAXC,WAA0B;AAGzB,4CAFuC,mBAAmB,OAAO,CAE7C;AAEpB,UAAO,QAAQ;KAEjB,CAAC,kBAAkB,CACpB,EAIA,CAAC;EAIA;EACD"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
3
|
-
|
|
2
|
+
let _intlayer_config_built = require("@intlayer/config/built");
|
|
3
|
+
_intlayer_config_built = require_rolldown_runtime.__toESM(_intlayer_config_built);
|
|
4
4
|
|
|
5
5
|
//#region src/generateStaticParams.ts
|
|
6
|
-
const { locales } =
|
|
6
|
+
const { locales } = _intlayer_config_built.default.internationalization;
|
|
7
7
|
const generateStaticParams = () => locales.map((locale) => ({ locale }));
|
|
8
8
|
|
|
9
9
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateStaticParams.cjs","names":["configuration"],"sources":["../../src/generateStaticParams.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\n\nconst { locales } = configuration.internationalization;\n\nexport const generateStaticParams = () => locales.map((locale) => ({ locale }));\n"],"mappings":";;;;;AAEA,MAAM,EAAE,YAAYA
|
|
1
|
+
{"version":3,"file":"generateStaticParams.cjs","names":["configuration"],"sources":["../../src/generateStaticParams.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\n\nconst { locales } = configuration.internationalization;\n\nexport const generateStaticParams = () => locales.map((locale) => ({ locale }));\n"],"mappings":";;;;;AAEA,MAAM,EAAE,YAAYA,+BAAc;AAElC,MAAa,6BAA6B,QAAQ,KAAK,YAAY,EAAE,QAAQ,EAAE"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_proxy_localeDetector = require('./localeDetector.cjs');
|
|
3
|
-
let
|
|
4
|
-
|
|
5
|
-
let
|
|
6
|
-
let
|
|
3
|
+
let _intlayer_config_built = require("@intlayer/config/built");
|
|
4
|
+
_intlayer_config_built = require_rolldown_runtime.__toESM(_intlayer_config_built);
|
|
5
|
+
let _intlayer_core = require("@intlayer/core");
|
|
6
|
+
let _intlayer_config_client = require("@intlayer/config/client");
|
|
7
7
|
let next_server = require("next/server");
|
|
8
8
|
|
|
9
9
|
//#region src/proxy/intlayerProxy.ts
|
|
10
|
-
const { internationalization, routing } =
|
|
10
|
+
const { internationalization, routing } = _intlayer_config_built.default ?? {};
|
|
11
11
|
const { locales, defaultLocale } = internationalization ?? {};
|
|
12
12
|
const { basePath, mode } = routing ?? {};
|
|
13
|
-
const effectiveMode = mode ??
|
|
13
|
+
const effectiveMode = mode ?? _intlayer_config_client.DefaultValues.Routing.ROUTING_MODE;
|
|
14
14
|
const noPrefix = effectiveMode === "no-prefix" || effectiveMode === "search-params";
|
|
15
15
|
const prefixDefault = effectiveMode === "prefix-all";
|
|
16
16
|
/**
|
|
@@ -75,7 +75,7 @@ const intlayerProxy = (request, _event, _response) => {
|
|
|
75
75
|
* @param request - The incoming Next.js request object.
|
|
76
76
|
* @returns - The locale found in the cookies, or undefined if not found or invalid.
|
|
77
77
|
*/
|
|
78
|
-
const getLocalLocale = (request) => (0,
|
|
78
|
+
const getLocalLocale = (request) => (0, _intlayer_core.getLocaleFromStorage)({
|
|
79
79
|
getCookie: (name) => request.cookies.get(name)?.value ?? null,
|
|
80
80
|
getHeader: (name) => request.headers.get(name) ?? null
|
|
81
81
|
});
|
|
@@ -223,7 +223,7 @@ const rewriteUrl = (request, newPath, locale) => {
|
|
|
223
223
|
const search = request.nextUrl.search;
|
|
224
224
|
const pathWithSearch = search && !newPath.includes("?") ? `${newPath}${search}` : newPath;
|
|
225
225
|
const response = next_server.NextResponse.rewrite(new URL(pathWithSearch, request.url));
|
|
226
|
-
(0,
|
|
226
|
+
(0, _intlayer_core.setLocaleInStorage)(locale, { setHeader: (name, value) => response.headers.set(name, value) });
|
|
227
227
|
return response;
|
|
228
228
|
};
|
|
229
229
|
/**
|
|
@@ -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 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,SAAS,aAFV,cAAc,SAAS,EAEY,SAAS;;;;;;;;AASjE,MAAM,kBAAkB,sDACD;CACnB,YAAY,SAAiB,QAAQ,QAAQ,IAAI,KAAK,EAAE,SAAS;CACj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B,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"}
|
|
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,kCAAiB,EAAE;AAC7D,MAAM,EAAE,SAAS,kBAAkB,wBAAwB,EAAE;AAC7D,MAAM,EAAE,UAAU,SAAS,WAAW,EAAE;AAIxC,MAAM,gBAAgB,QAAQC,sCAAc,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,M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,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,5 +1,5 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
2
|
+
let _intlayer_core = require("@intlayer/core");
|
|
3
3
|
|
|
4
4
|
//#region src/proxy/localeDetector.ts
|
|
5
5
|
/**
|
|
@@ -12,7 +12,7 @@ const localeDetector = (request) => {
|
|
|
12
12
|
request.headers.forEach((value, key) => {
|
|
13
13
|
negotiatorHeaders[key] = value;
|
|
14
14
|
});
|
|
15
|
-
return (0,
|
|
15
|
+
return (0, _intlayer_core.localeDetector)(negotiatorHeaders);
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localeDetector.cjs","names":["negotiatorHeaders: Record<string, string>"],"sources":["../../../src/proxy/localeDetector.ts"],"sourcesContent":["import { localeDetector as localeDetectorCore } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport type { NextRequest } from 'next/server.js';\n\n/**\n * Detects the locale from the request headers\n *\n * Headers are provided by the browser and can be used to determine the user's preferred language\n */\nexport const localeDetector = (request: NextRequest): LocalesValues => {\n const negotiatorHeaders: Record<string, string> = {};\n\n request.headers.forEach((value, key) => {\n negotiatorHeaders[key] = value;\n });\n\n const locale = localeDetectorCore(negotiatorHeaders);\n\n return locale;\n};\n"],"mappings":";;;;;;;;;AASA,MAAa,kBAAkB,YAAwC;CACrE,MAAMA,oBAA4C,EAAE;AAEpD,SAAQ,QAAQ,SAAS,OAAO,QAAQ;AACtC,oBAAkB,OAAO;GACzB;AAIF,
|
|
1
|
+
{"version":3,"file":"localeDetector.cjs","names":["negotiatorHeaders: Record<string, string>"],"sources":["../../../src/proxy/localeDetector.ts"],"sourcesContent":["import { localeDetector as localeDetectorCore } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport type { NextRequest } from 'next/server.js';\n\n/**\n * Detects the locale from the request headers\n *\n * Headers are provided by the browser and can be used to determine the user's preferred language\n */\nexport const localeDetector = (request: NextRequest): LocalesValues => {\n const negotiatorHeaders: Record<string, string> = {};\n\n request.headers.forEach((value, key) => {\n negotiatorHeaders[key] = value;\n });\n\n const locale = localeDetectorCore(negotiatorHeaders);\n\n return locale;\n};\n"],"mappings":";;;;;;;;;AASA,MAAa,kBAAkB,YAAwC;CACrE,MAAMA,oBAA4C,EAAE;AAEpD,SAAQ,QAAQ,SAAS,OAAO,QAAQ;AACtC,oBAAkB,OAAO;GACzB;AAIF,2CAFkC,kBAAkB"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let
|
|
3
|
-
|
|
4
|
-
let
|
|
5
|
-
let
|
|
2
|
+
let _intlayer_config_built = require("@intlayer/config/built");
|
|
3
|
+
_intlayer_config_built = require_rolldown_runtime.__toESM(_intlayer_config_built);
|
|
4
|
+
let _intlayer_core = require("@intlayer/core");
|
|
5
|
+
let _intlayer_types = require("@intlayer/types");
|
|
6
6
|
let next_headers_js = require("next/headers.js");
|
|
7
7
|
|
|
8
8
|
//#region src/server/getLocale.ts
|
|
9
9
|
const getLocale = async () => {
|
|
10
|
-
const defaultLocale =
|
|
10
|
+
const defaultLocale = _intlayer_config_built.default?.internationalization?.defaultLocale ?? _intlayer_types.Locales.ENGLISH;
|
|
11
11
|
const headersList = await (0, next_headers_js.headers)();
|
|
12
12
|
const cookiesList = await (0, next_headers_js.cookies)();
|
|
13
|
-
const storedLocale = (0,
|
|
13
|
+
const storedLocale = (0, _intlayer_core.getLocaleFromStorage)({
|
|
14
14
|
getCookie: (name) => cookiesList.get(name)?.value ?? null,
|
|
15
15
|
getHeader: (name) => headersList.get(name) ?? null
|
|
16
16
|
});
|
|
@@ -19,7 +19,7 @@ const getLocale = async () => {
|
|
|
19
19
|
headersList.forEach((value, key) => {
|
|
20
20
|
negotiatorHeaders[key] = value;
|
|
21
21
|
});
|
|
22
|
-
const userFallbackLocale = (0,
|
|
22
|
+
const userFallbackLocale = (0, _intlayer_core.localeDetector)(negotiatorHeaders);
|
|
23
23
|
if (userFallbackLocale) return userFallbackLocale;
|
|
24
24
|
return defaultLocale;
|
|
25
25
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocale.cjs","names":["configuration","Locales","negotiatorHeaders: Record<string, string>"],"sources":["../../../src/server/getLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { getLocaleFromStorage, localeDetector } from '@intlayer/core';\nimport { type Locale, Locales } from '@intlayer/types';\nimport { cookies, headers } from 'next/headers.js';\n\n// Helper function to extract locale from headers/cookies\nexport const getLocale = async (): Promise<Locale> => {\n const defaultLocale =\n configuration?.internationalization?.defaultLocale ?? Locales.ENGLISH;\n\n // 1 - Try locale from header\n const headersList = await headers();\n const cookiesList = await cookies();\n\n const storedLocale = getLocaleFromStorage({\n getCookie: (name: string) => cookiesList.get(name)?.value ?? null,\n getHeader: (name: string) => headersList.get(name) ?? null,\n });\n\n if (storedLocale) return storedLocale as Locale;\n\n // 3 - Fallback to Accept-Language negotiation\n const negotiatorHeaders: Record<string, string> = {};\n headersList.forEach((value, key) => {\n negotiatorHeaders[key] = value;\n });\n\n const userFallbackLocale = localeDetector(negotiatorHeaders);\n if (userFallbackLocale) return userFallbackLocale as Locale;\n\n // 4 - Default locale\n return defaultLocale;\n};\n"],"mappings":";;;;;;;;AAMA,MAAa,YAAY,YAA6B;CACpD,MAAM,gBACJA,
|
|
1
|
+
{"version":3,"file":"getLocale.cjs","names":["configuration","Locales","negotiatorHeaders: Record<string, string>"],"sources":["../../../src/server/getLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { getLocaleFromStorage, localeDetector } from '@intlayer/core';\nimport { type Locale, Locales } from '@intlayer/types';\nimport { cookies, headers } from 'next/headers.js';\n\n// Helper function to extract locale from headers/cookies\nexport const getLocale = async (): Promise<Locale> => {\n const defaultLocale =\n configuration?.internationalization?.defaultLocale ?? Locales.ENGLISH;\n\n // 1 - Try locale from header\n const headersList = await headers();\n const cookiesList = await cookies();\n\n const storedLocale = getLocaleFromStorage({\n getCookie: (name: string) => cookiesList.get(name)?.value ?? null,\n getHeader: (name: string) => headersList.get(name) ?? null,\n });\n\n if (storedLocale) return storedLocale as Locale;\n\n // 3 - Fallback to Accept-Language negotiation\n const negotiatorHeaders: Record<string, string> = {};\n headersList.forEach((value, key) => {\n negotiatorHeaders[key] = value;\n });\n\n const userFallbackLocale = localeDetector(negotiatorHeaders);\n if (userFallbackLocale) return userFallbackLocale as Locale;\n\n // 4 - Default locale\n return defaultLocale;\n};\n"],"mappings":";;;;;;;;AAMA,MAAa,YAAY,YAA6B;CACpD,MAAM,gBACJA,gCAAe,sBAAsB,iBAAiBC,wBAAQ;CAGhE,MAAM,cAAc,oCAAe;CACnC,MAAM,cAAc,oCAAe;CAEnC,MAAM,wDAAoC;EACxC,YAAY,SAAiB,YAAY,IAAI,KAAK,EAAE,SAAS;EAC7D,YAAY,SAAiB,YAAY,IAAI,KAAK,IAAI;EACvD,CAAC;AAEF,KAAI,aAAc,QAAO;CAGzB,MAAMC,oBAA4C,EAAE;AACpD,aAAY,SAAS,OAAO,QAAQ;AAClC,oBAAkB,OAAO;GACzB;CAEF,MAAM,wDAAoC,kBAAkB;AAC5D,KAAI,mBAAoB,QAAO;AAG/B,QAAO"}
|
|
@@ -1,59 +1,59 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
let node_path = require("node:path");
|
|
3
|
-
let
|
|
4
|
-
let
|
|
5
|
-
let
|
|
6
|
-
let
|
|
3
|
+
let _intlayer_chokidar = require("@intlayer/chokidar");
|
|
4
|
+
let _intlayer_config = require("@intlayer/config");
|
|
5
|
+
let _intlayer_dictionaries_entry = require("@intlayer/dictionaries-entry");
|
|
6
|
+
let _intlayer_webpack = require("@intlayer/webpack");
|
|
7
7
|
let defu = require("defu");
|
|
8
8
|
let next_package_json = require("next/package.json");
|
|
9
9
|
next_package_json = require_rolldown_runtime.__toESM(next_package_json);
|
|
10
10
|
|
|
11
11
|
//#region src/server/withIntlayer.ts
|
|
12
|
-
const isGteNext13 = (0,
|
|
13
|
-
const isGteNext15 = (0,
|
|
14
|
-
const isGteNext16 = (0,
|
|
15
|
-
const isTurbopackStable = (0,
|
|
12
|
+
const isGteNext13 = (0, _intlayer_config.compareVersions)(next_package_json.default.version, "≥", "13.0.0");
|
|
13
|
+
const isGteNext15 = (0, _intlayer_config.compareVersions)(next_package_json.default.version, "≥", "15.0.0");
|
|
14
|
+
const isGteNext16 = (0, _intlayer_config.compareVersions)(next_package_json.default.version, "≥", "16.0.0");
|
|
15
|
+
const isTurbopackStable = (0, _intlayer_config.compareVersions)(next_package_json.default.version, "≥", "15.3.0");
|
|
16
16
|
const isTurbopackEnabledFromCommand = isGteNext16 ? !process.env.npm_lifecycle_script?.includes("--webpack") : process.env.npm_lifecycle_script?.includes("--turbo");
|
|
17
17
|
const getIsSwcPluginAvailable = (intlayerConfig) => {
|
|
18
18
|
try {
|
|
19
|
-
(intlayerConfig.build?.require ?? (0,
|
|
19
|
+
(intlayerConfig.build?.require ?? (0, _intlayer_config.getProjectRequire)()).resolve("@intlayer/swc");
|
|
20
20
|
return true;
|
|
21
21
|
} catch (_e) {
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
25
|
const resolvePluginPath = (pluginPath, intlayerConfig, isTurbopackEnabled) => {
|
|
26
|
-
const pluginPathResolved = (intlayerConfig.build?.require ?? (0,
|
|
27
|
-
if (isTurbopackEnabled) return (0,
|
|
26
|
+
const pluginPathResolved = (intlayerConfig.build?.require ?? (0, _intlayer_config.getProjectRequire)())?.resolve(pluginPath);
|
|
27
|
+
if (isTurbopackEnabled) return (0, _intlayer_config.normalizePath)(`./${(0, node_path.relative)(process.cwd(), pluginPathResolved)}`);
|
|
28
28
|
return pluginPathResolved;
|
|
29
29
|
};
|
|
30
30
|
const getPruneConfig = (intlayerConfig, isBuildCommand, isTurbopackEnabled) => {
|
|
31
31
|
const { optimize, importMode } = intlayerConfig.build;
|
|
32
32
|
const { dictionariesDir, unmergedDictionariesDir, dynamicDictionariesDir, fetchDictionariesDir, mainDir, baseDir } = intlayerConfig.content;
|
|
33
|
-
const logger = (0,
|
|
33
|
+
const logger = (0, _intlayer_config.getAppLogger)(intlayerConfig);
|
|
34
34
|
if (optimize === false) return {};
|
|
35
35
|
if (optimize === void 0 && !isBuildCommand) return {};
|
|
36
36
|
if (!isGteNext13) return {};
|
|
37
37
|
if (!getIsSwcPluginAvailable(intlayerConfig)) {
|
|
38
38
|
logger([
|
|
39
|
-
(0,
|
|
40
|
-
(0,
|
|
41
|
-
(0,
|
|
42
|
-
(0,
|
|
39
|
+
(0, _intlayer_config.colorize)("Recommended: Install", _intlayer_config.ANSIColors.GREY),
|
|
40
|
+
(0, _intlayer_config.colorize)("@intlayer/swc", _intlayer_config.ANSIColors.GREY_LIGHT),
|
|
41
|
+
(0, _intlayer_config.colorize)("package to enable build optimization. See documentation: ", _intlayer_config.ANSIColors.GREY),
|
|
42
|
+
(0, _intlayer_config.colorize)("https://intlayer.org/docs/en/bundle_optimization", _intlayer_config.ANSIColors.GREY_LIGHT)
|
|
43
43
|
]);
|
|
44
44
|
return {};
|
|
45
45
|
}
|
|
46
|
-
(0,
|
|
46
|
+
(0, _intlayer_chokidar.runOnce)((0, node_path.join)(baseDir, ".intlayer", "cache", "intlayer-prune-plugin-enabled.lock"), () => logger("Build optimization enabled"), { cacheTimeoutMs: 1e3 * 10 });
|
|
47
47
|
const dictionariesEntryPath = (0, node_path.join)(mainDir, "dictionaries.mjs");
|
|
48
48
|
const dynamicDictionariesEntryPath = (0, node_path.join)(mainDir, "dynamic_dictionaries.mjs");
|
|
49
49
|
const unmergedDictionariesEntryPath = (0, node_path.join)(mainDir, "unmerged_dictionaries.mjs");
|
|
50
50
|
const fetchDictionariesEntryPath = (0, node_path.join)(mainDir, "fetch_dictionaries.mjs");
|
|
51
51
|
const filesList = [
|
|
52
|
-
...(0,
|
|
52
|
+
...(0, _intlayer_chokidar.getComponentTransformPatternSync)(intlayerConfig),
|
|
53
53
|
dictionariesEntryPath,
|
|
54
54
|
unmergedDictionariesEntryPath
|
|
55
55
|
];
|
|
56
|
-
const dictionaries = (0,
|
|
56
|
+
const dictionaries = (0, _intlayer_dictionaries_entry.getDictionaries)(intlayerConfig);
|
|
57
57
|
const liveSyncKeys = Object.values(dictionaries).filter((dictionary) => dictionary.live).map((dictionary) => dictionary.key);
|
|
58
58
|
return { experimental: { swcPlugins: [[resolvePluginPath("@intlayer/swc", intlayerConfig, isTurbopackEnabled), {
|
|
59
59
|
dictionariesDir,
|
|
@@ -92,13 +92,13 @@ const getCommandsEvent = () => {
|
|
|
92
92
|
*/
|
|
93
93
|
const withIntlayerSync = (nextConfig = {}, configOptions) => {
|
|
94
94
|
if (typeof nextConfig !== "object") nextConfig = {};
|
|
95
|
-
const intlayerConfig = (0,
|
|
96
|
-
const logger = (0,
|
|
95
|
+
const intlayerConfig = (0, _intlayer_config.getConfiguration)(configOptions);
|
|
96
|
+
const logger = (0, _intlayer_config.getAppLogger)(intlayerConfig);
|
|
97
97
|
const isTurbopackEnabled = configOptions?.enableTurbopack ?? isTurbopackEnabledFromCommand;
|
|
98
98
|
if (isTurbopackEnabled && typeof nextConfig.webpack !== "undefined") logger("Turbopack is enabled but a custom webpack config is present. It will be ignored.");
|
|
99
99
|
const { isBuildCommand, isDevCommand } = getCommandsEvent();
|
|
100
100
|
const turboConfig = {
|
|
101
|
-
resolveAlias: (0,
|
|
101
|
+
resolveAlias: (0, _intlayer_config.getAlias)({
|
|
102
102
|
configuration: intlayerConfig,
|
|
103
103
|
formatter: (value) => `./${value}`
|
|
104
104
|
}),
|
|
@@ -157,12 +157,12 @@ const withIntlayerSync = (nextConfig = {}, configOptions) => {
|
|
|
157
157
|
});
|
|
158
158
|
config$1.resolve.alias = {
|
|
159
159
|
...config$1.resolve.alias,
|
|
160
|
-
...(0,
|
|
160
|
+
...(0, _intlayer_config.getAlias)({
|
|
161
161
|
configuration: intlayerConfig,
|
|
162
162
|
formatter: (value) => (0, node_path.resolve)(value)
|
|
163
163
|
})
|
|
164
164
|
};
|
|
165
|
-
if (isDevCommand && isServer && nextRuntime === "nodejs") config$1.plugins.push(new
|
|
165
|
+
if (isDevCommand && isServer && nextRuntime === "nodejs") config$1.plugins.push(new _intlayer_webpack.IntlayerPlugin(intlayerConfig));
|
|
166
166
|
return config$1;
|
|
167
167
|
}
|
|
168
168
|
};
|
|
@@ -188,9 +188,9 @@ const withIntlayerSync = (nextConfig = {}, configOptions) => {
|
|
|
188
188
|
*/
|
|
189
189
|
const withIntlayer = async (nextConfig = {}, configOptions) => {
|
|
190
190
|
const { isBuildCommand, isDevCommand } = getCommandsEvent();
|
|
191
|
-
const intlayerConfig = (0,
|
|
191
|
+
const intlayerConfig = (0, _intlayer_config.getConfiguration)(configOptions);
|
|
192
192
|
const { mode } = intlayerConfig.build;
|
|
193
|
-
if (isDevCommand || isBuildCommand || mode === "auto") await (0,
|
|
193
|
+
if (isDevCommand || isBuildCommand || mode === "auto") await (0, _intlayer_chokidar.prepareIntlayer)(intlayerConfig, {
|
|
194
194
|
clean: isBuildCommand,
|
|
195
195
|
cacheTimeoutMs: isBuildCommand ? 1e3 * 30 : 1e3 * 60 * 60
|
|
196
196
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withIntlayer.cjs","names":["nextPackageJSON","ANSIColors","config: Partial<NextConfig>","config","IntlayerPlugin","pruneConfig: Partial<NextConfig>"],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { join, relative, resolve } from 'node:path';\nimport {\n getComponentTransformPatternSync,\n prepareIntlayer,\n runOnce,\n} 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 { defu } from 'defu';\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, 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 = getComponentTransformPatternSync(intlayerConfig);\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> = defu(\n getNewConfig(),\n pruneConfig\n );\n\n // Merge the new config with the user's config\n const result = defu(intlayerNextConfig, nextConfig) 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 | Promise<T> = {} as T,\n configOptions?: WithIntlayerOptions\n): Promise<NextConfig & T> => {\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n const intlayerConfig = getConfiguration(configOptions);\n\n const { mode } = intlayerConfig.build;\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 || mode === 'auto') {\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 const nextConfigResolved = await nextConfig;\n\n return withIntlayerSync(nextConfigResolved, configOptions);\n};\n"],"mappings":";;;;;;;;;;;AAyBA,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,eAAe,eAAe;CAChD,MAAM,EACJ,iBACA,yBACA,wBACA,sBACA,SACA,YACE,eAAe;CACnB,MAAM,6CAAsB,eAAe;AAE3C,KAAI,aAAa,MACf,QAAO,EAAE;AAEX,KAAI,aAAa,UAAa,CAAC,eAC7B,QAAO,EAAE;AAGX,KAAI,CAAC,YAAa,QAAO,EAAE;AAI3B,KAAI,CAFyB,wBAAwB,eAAe,EAEzC;AACzB,SAAO;mCACI,wBAAwBC,6BAAW,KAAK;mCACxC,iBAAiBA,6BAAW,WAAW;mCAE9C,6DACAA,6BAAW,KACZ;mCAEC,oDACAA,6BAAW,WACZ;GACF,CAAC;AACF,SAAO,EAAE;;AAGX,sDACO,SAAS,aAAa,SAAS,qCAAqC,QACnE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AAUD,sCAPE,cAAc,EACd,YACD,EAGuC,WAAW;;;;;;;;;;;;;;;;;AAoBrD,MAAa,eAAe,OAC1B,aAA6B,EAAE,EAC/B,kBAC4B;CAC5B,MAAM,EAAE,gBAAgB,iBAAiB,kBAAkB;CAC3D,MAAM,yDAAkC,cAAc;CAEtD,MAAM,EAAE,SAAS,eAAe;AAKhC,KAAI,gBAAgB,kBAAkB,SAAS,OAE7C,gDAAsB,gBAAgB;EACpC,OAAO;EACP,gBAAgB,iBACZ,MAAO,KACP,MAAO,KAAK;EACjB,CAAC;AAKJ,QAAO,iBAFoB,MAAM,YAEW,cAAc"}
|
|
1
|
+
{"version":3,"file":"withIntlayer.cjs","names":["nextPackageJSON","ANSIColors","config: Partial<NextConfig>","config","IntlayerPlugin","pruneConfig: Partial<NextConfig>"],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { join, relative, resolve } from 'node:path';\nimport {\n getComponentTransformPatternSync,\n prepareIntlayer,\n runOnce,\n} 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 { defu } from 'defu';\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, 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 = getComponentTransformPatternSync(intlayerConfig);\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> = defu(\n getNewConfig(),\n pruneConfig\n );\n\n // Merge the new config with the user's config\n const result = defu(intlayerNextConfig, nextConfig) 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 | Promise<T> = {} as T,\n configOptions?: WithIntlayerOptions\n): Promise<NextConfig & T> => {\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n const intlayerConfig = getConfiguration(configOptions);\n\n const { mode } = intlayerConfig.build;\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 || mode === 'auto') {\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 const nextConfigResolved = await nextConfig;\n\n return withIntlayerSync(nextConfigResolved, configOptions);\n};\n"],"mappings":";;;;;;;;;;;AAyBA,MAAM,oDAA8BA,0BAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,oDAA8BA,0BAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,oDAA8BA,0BAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,0DACJA,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,oDAA8B,EACtC,QAAQ,gBAAgB;AACxC,SAAO;UACA,IAAI;AACX,SAAO;;;AAIX,MAAM,qBACJ,YACA,gBACA,uBACW;CAEX,MAAM,sBADkB,eAAe,OAAO,oDAA8B,GAChC,QAAQ,WAAW;AAE/D,KAAI,mBAEF,4CAAqB,6BAAc,QAAQ,KAAK,EAAE,mBAAmB,GAAG;AAG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,WAAW,QAAQC,UAAQ,QAAQ;AAK9C,QAAIA,SAAO,cAAc,MACvB,UAAO,YAAY,EAAE;AAIvB,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,kCAAY;MACV,eAAe;MACf,YAAY,iCAA0B,MAAM;MAC7C,CAAC;KACH;AAGD,QAAI,gBAAgB,YAAY,gBAAgB,SAE9C,UAAO,QAAQ,KAAK,IAAIC,iCAAe,eAAe,CAAC;AAGzD,WAAOD;;GAEV;AAGH,SAAO;;CAGT,MAAME,cAAmC,eACvC,gBACA,gBACA,sBAAsB,MACvB;AAUD,sCAPE,cAAc,EACd,YACD,EAGuC,WAAW;;;;;;;;;;;;;;;;;AAoBrD,MAAa,eAAe,OAC1B,aAA6B,EAAE,EAC/B,kBAC4B;CAC5B,MAAM,EAAE,gBAAgB,iBAAiB,kBAAkB;CAC3D,MAAM,wDAAkC,cAAc;CAEtD,MAAM,EAAE,SAAS,eAAe;AAKhC,KAAI,gBAAgB,kBAAkB,SAAS,OAE7C,+CAAsB,gBAAgB;EACpC,OAAO;EACP,gBAAgB,iBACZ,MAAO,KACP,MAAO,KAAK;EACjB,CAAC;AAKJ,QAAO,iBAFoB,MAAM,YAEW,cAAc"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intlayer",
|
|
3
|
-
"version": "7.5.
|
|
3
|
+
"version": "7.5.1",
|
|
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,25 +118,25 @@
|
|
|
118
118
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
119
119
|
},
|
|
120
120
|
"dependencies": {
|
|
121
|
-
"@intlayer/chokidar": "7.5.
|
|
122
|
-
"@intlayer/config": "7.5.
|
|
123
|
-
"@intlayer/core": "7.5.
|
|
124
|
-
"@intlayer/dictionaries-entry": "7.5.
|
|
125
|
-
"@intlayer/types": "7.5.
|
|
126
|
-
"@intlayer/webpack": "7.5.
|
|
121
|
+
"@intlayer/chokidar": "7.5.1",
|
|
122
|
+
"@intlayer/config": "7.5.1",
|
|
123
|
+
"@intlayer/core": "7.5.1",
|
|
124
|
+
"@intlayer/dictionaries-entry": "7.5.1",
|
|
125
|
+
"@intlayer/types": "7.5.1",
|
|
126
|
+
"@intlayer/webpack": "7.5.1",
|
|
127
127
|
"defu": "6.1.4",
|
|
128
128
|
"node-loader": "2.1.0",
|
|
129
|
-
"react-intlayer": "7.5.
|
|
129
|
+
"react-intlayer": "7.5.1"
|
|
130
130
|
},
|
|
131
131
|
"devDependencies": {
|
|
132
|
-
"@types/node": "25.0.
|
|
132
|
+
"@types/node": "25.0.3",
|
|
133
133
|
"@types/react": ">=16.0.0",
|
|
134
134
|
"@types/react-dom": ">=16.0.0",
|
|
135
135
|
"@utils/ts-config": "1.0.4",
|
|
136
136
|
"@utils/ts-config-types": "1.0.4",
|
|
137
137
|
"@utils/tsdown-config": "1.0.4",
|
|
138
138
|
"rimraf": "6.1.2",
|
|
139
|
-
"tsdown": "0.18.
|
|
139
|
+
"tsdown": "0.18.1",
|
|
140
140
|
"typescript": "5.9.3",
|
|
141
141
|
"vitest": "4.0.16"
|
|
142
142
|
},
|