next-intlayer 8.2.2 → 8.2.3
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/IntlayerClientProvider.cjs.map +1 -1
- package/dist/cjs/server/index.cjs +1 -1
- package/dist/cjs/server/useDictionary.cjs +2 -0
- package/dist/cjs/server/useDictionary.cjs.map +1 -0
- package/dist/cjs/server/useDictionaryAsync.cjs +2 -0
- package/dist/cjs/server/useDictionaryAsync.cjs.map +1 -0
- package/dist/cjs/server/useDictionaryDynamic.cjs +2 -0
- package/dist/cjs/server/useDictionaryDynamic.cjs.map +1 -0
- package/dist/cjs/server/useIntlayer.cjs +2 -0
- package/dist/cjs/server/useIntlayer.cjs.map +1 -0
- package/dist/cjs/server/withIntlayer.cjs +1 -1
- package/dist/cjs/server/withIntlayer.cjs.map +1 -1
- package/dist/esm/client/IntlayerClientProvider.mjs.map +1 -1
- package/dist/esm/server/index.mjs +1 -1
- package/dist/esm/server/useDictionary.mjs +2 -0
- package/dist/esm/server/useDictionary.mjs.map +1 -0
- package/dist/esm/server/useDictionaryAsync.mjs +2 -0
- package/dist/esm/server/useDictionaryAsync.mjs.map +1 -0
- package/dist/esm/server/useDictionaryDynamic.mjs +2 -0
- package/dist/esm/server/useDictionaryDynamic.mjs.map +1 -0
- package/dist/esm/server/useIntlayer.mjs +2 -0
- package/dist/esm/server/useIntlayer.mjs.map +1 -0
- package/dist/esm/server/withIntlayer.mjs +1 -1
- package/dist/esm/server/withIntlayer.mjs.map +1 -1
- package/dist/types/server/index.d.ts +2 -3
- package/dist/types/server/useDictionary.d.ts +13 -0
- package/dist/types/server/useDictionary.d.ts.map +1 -0
- package/dist/types/server/useDictionaryAsync.d.ts +13 -0
- package/dist/types/server/useDictionaryAsync.d.ts.map +1 -0
- package/dist/types/server/useDictionaryDynamic.d.ts +13 -0
- package/dist/types/server/useDictionaryDynamic.d.ts.map +1 -0
- package/dist/types/server/useIntlayer.d.ts +14 -0
- package/dist/types/server/useIntlayer.d.ts.map +1 -0
- package/dist/types/server/withIntlayer.d.ts.map +1 -1
- package/package.json +10 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerClientProvider.cjs","names":["IntlayerProvider"],"sources":["../../../src/client/IntlayerClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\n\nimport { IntlayerProvider, type IntlayerProviderProps } from 'react-intlayer';\n\nexport type IntlayerClientProviderProps = IntlayerProviderProps;\n\n/**\n * Provider for client-side components in Next.js.\n *\n * This component wraps the `IntlayerProvider` from `react-intlayer` and is intended\n * to be used within Next.js App Router client components.\n *\n * @param props - The provider props.\n * @returns The provider component.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import { IntlayerClientProvider } from 'next-intlayer';\n *\n * export default function ClientLayout({ children, locale }) {\n * return (\n * <IntlayerClientProvider locale={locale}>\n * {children}\n * </IntlayerClientProvider>\n * );\n * }\n * ```\n */\nexport const IntlayerClientProvider: FC<IntlayerProviderProps> = (props) => (\n <IntlayerProvider {...props} />\n);\n"],"mappings":"4LAgCA,MAAa,EAAqD,IAChE,EAAA,EAAA,KAACA,EAAAA,
|
|
1
|
+
{"version":3,"file":"IntlayerClientProvider.cjs","names":["IntlayerProvider"],"sources":["../../../src/client/IntlayerClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\n\nimport { IntlayerProvider, type IntlayerProviderProps } from 'react-intlayer';\n\nexport type IntlayerClientProviderProps = IntlayerProviderProps;\n\n/**\n * Provider for client-side components in Next.js.\n *\n * This component wraps the `IntlayerProvider` from `react-intlayer` and is intended\n * to be used within Next.js App Router client components.\n *\n * @param props - The provider props.\n * @returns The provider component.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import { IntlayerClientProvider } from 'next-intlayer';\n *\n * export default function ClientLayout({ children, locale }) {\n * return (\n * <IntlayerClientProvider locale={locale}>\n * {children}\n * </IntlayerClientProvider>\n * );\n * }\n * ```\n */\nexport const IntlayerClientProvider: FC<IntlayerProviderProps> = (props) => (\n <IntlayerProvider {...props} />\n);\n"],"mappings":"4LAgCA,MAAa,EAAqD,IAChE,EAAA,EAAA,KAACA,EAAAA,iBAAD,CAAkB,GAAI,EAAS,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./withIntlayer.cjs`);let t=require(`react-intlayer/server`);Object.defineProperty(exports,`IntlayerServerProvider`,{enumerable:!0,get:function(){return t.IntlayerServerProvider}}),Object.defineProperty(exports,`locale`,{enumerable:!0,get:function(){return t.locale}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return t.t}}),Object.defineProperty(exports,`useDictionary`,{enumerable:!0,get:function(){return t.useDictionary}}),Object.defineProperty(exports,`useDictionaryAsync`,{enumerable:!0,get:function(){return t.useDictionaryAsync}}),Object.defineProperty(exports,`useDictionaryDynamic`,{enumerable:!0,get:function(){return t.useDictionaryDynamic}}),Object.defineProperty(exports,`useI18n`,{enumerable:!0,get:function(){return t.useI18n}}),Object.defineProperty(exports,`useIntl`,{enumerable:!0,get:function(){return t.useIntl}}),Object.defineProperty(exports,`useIntlayer`,{enumerable:!0,get:function(){return t.useIntlayer}}),Object.defineProperty(exports,`useLoadDynamic`,{enumerable:!0,get:function(){return t.useLoadDynamic}}),Object.defineProperty(exports,`useLocale`,{enumerable:!0,get:function(){return t.useLocale}}),exports.withIntlayer=e.withIntlayer,exports.withIntlayerSync=e.withIntlayerSync;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./useIntlayer.cjs`);let t=require(`react-intlayer/server`);const n=(n,r)=>(0,t.useDictionary)(n,r,e.safeUseLocale());exports.useDictionary=n;
|
|
2
|
+
//# sourceMappingURL=useDictionary.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDictionary.cjs","names":["safeUseLocale"],"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type { DeclaredLocales, Dictionary } from '@intlayer/types';\nimport { useDictionary as useDictionaryBase } from 'react-intlayer/server';\nimport { safeUseLocale } from './useIntlayer';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends DeclaredLocales = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n): ReturnType<typeof useDictionaryBase<T, L>> => {\n const storedLocale = safeUseLocale();\n\n return useDictionaryBase<T, L>(dictionary, locale, storedLocale);\n};\n"],"mappings":"4LASA,MAAa,GAIX,EACA,KAIA,EAAA,EAAA,eAA+B,EAAY,EAFtBA,EAAAA,eAAe,CAE4B"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./getLocale.cjs`);let t=require(`react-intlayer/server`);const n=async(n,r)=>(0,t.useDictionaryAsync)(n,r,await e.getLocale());exports.useDictionaryAsync=n;
|
|
2
|
+
//# sourceMappingURL=useDictionaryAsync.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.cjs","names":["getLocale"],"sources":["../../../src/server/useDictionaryAsync.ts"],"sourcesContent":["import type {\n DeclaredLocales,\n Dictionary,\n StrictModeLocaleMap,\n} from '@intlayer/types';\nimport { useDictionaryAsync as useDictionaryAsyncBase } from 'react-intlayer/server';\nimport { getLocale } from './getLocale';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryAsync = async <\n T extends Dictionary,\n L extends DeclaredLocales = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L\n): ReturnType<typeof useDictionaryAsyncBase<T, L>> => {\n const storedLocale = await getLocale();\n\n return useDictionaryAsyncBase<T, L>(dictionaryPromise, locale, storedLocale);\n};\n"],"mappings":"0LAaA,MAAa,EAAqB,MAIhC,EACA,KAIA,EAAA,EAAA,oBAAoC,EAAmB,EAFlC,MAAMA,EAAAA,WAAW,CAEsC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./useIntlayer.cjs`);let t=require(`react-intlayer/server`);const n=(n,r,i)=>(0,t.useDictionaryDynamic)(n,r,i,e.safeUseLocale());exports.useDictionaryDynamic=n;
|
|
2
|
+
//# sourceMappingURL=useDictionaryDynamic.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.cjs","names":["safeUseLocale"],"sources":["../../../src/server/useDictionaryDynamic.ts"],"sourcesContent":["import type {\n DeclaredLocales,\n Dictionary,\n StrictModeLocaleMap,\n} from '@intlayer/types';\nimport { useDictionaryDynamic as useDictionaryDynamicBase } from 'react-intlayer/server';\nimport { safeUseLocale } from './useIntlayer';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n L extends DeclaredLocales = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: string,\n locale?: L\n): ReturnType<typeof useDictionaryDynamicBase<T, L>> => {\n const storedLocale = safeUseLocale();\n\n return useDictionaryDynamicBase<T, L>(\n dictionaryPromise,\n key,\n locale,\n storedLocale\n );\n};\n"],"mappings":"4LAaA,MAAa,GAIX,EACA,EACA,KAIA,EAAA,EAAA,sBACE,EACA,EACA,EALmBA,EAAAA,eAAe,CAOnC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`./getLocale.cjs`);let n=require(`react`);n=e.__toESM(n);let r=require(`react-intlayer/server`);const i=typeof n.default.cache==`function`?n.default.cache(t.getLocale):t.getLocale,a=()=>{let e=i();return e instanceof Promise?typeof n.default.use==`function`?n.default.use(e):void 0:e},o=(e,t)=>(0,r.useIntlayer)(e,t,a());exports.safeUseLocale=a,exports.useIntlayer=o;
|
|
2
|
+
//# sourceMappingURL=useIntlayer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIntlayer.cjs","names":["React","getLocale"],"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { DeclaredLocales, DictionaryKeys, Locale } from '@intlayer/types';\nimport React from 'react';\nimport { useIntlayer as useIntlayerBase } from 'react-intlayer/server';\nimport { getLocale } from './getLocale';\n\nconst getCachedLocale =\n typeof React.cache === 'function' ? React.cache(getLocale) : getLocale;\n\nexport const safeUseLocale = (): Locale | undefined => {\n // getLocale returns a Promise based on your TS error\n const localeData = getCachedLocale() as Promise<Locale> | Locale;\n\n if (localeData instanceof Promise) {\n if (typeof React.use === 'function') {\n return React.use(localeData); // Safely unwraps in React 19+\n }\n\n // React < 19 cannot synchronously unwrap Promises in hooks.\n // Return undefined to trigger the localeTarget fallback.\n return undefined;\n }\n\n return localeData;\n};\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useIntlayer = <\n T extends DictionaryKeys,\n L extends DeclaredLocales = DeclaredLocales,\n>(\n key: T,\n locale?: L\n): ReturnType<typeof useIntlayerBase<T, L>> => {\n const storedLocale = safeUseLocale();\n\n return useIntlayerBase<T, L>(key, locale, storedLocale);\n};\n"],"mappings":"kOAKA,MAAM,EACJ,OAAOA,EAAAA,QAAM,OAAU,WAAaA,EAAAA,QAAM,MAAMC,EAAAA,UAAU,CAAGA,EAAAA,UAElD,MAA0C,CAErD,IAAM,EAAa,GAAiB,CAYpC,OAVI,aAAsB,QACpB,OAAOD,EAAAA,QAAM,KAAQ,WAChBA,EAAAA,QAAM,IAAI,EAAW,CAK9B,OAGK,GAQI,GAIX,EACA,KAIA,EAAA,EAAA,aAA6B,EAAK,EAFb,GAAe,CAEmB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`);let t=require(`@intlayer/config/client`),n=require(`node:path`),r=require(`@intlayer/chokidar/build`),i=require(`@intlayer/chokidar/
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`);let t=require(`@intlayer/config/client`),n=require(`node:path`),r=require(`@intlayer/chokidar/build`),i=require(`@intlayer/chokidar/cli`),a=require(`@intlayer/chokidar/utils`),o=require(`@intlayer/config/logger`),s=require(`@intlayer/config/node`),c=require(`@intlayer/config/utils`),l=require(`@intlayer/dictionaries-entry`),u=require(`@intlayer/webpack`),d=require(`defu`),f=require(`next/package.json`);f=e.__toESM(f);const p=(0,c.compareVersions)(f.default.version,`≥`,`13.0.0`),m=(0,c.compareVersions)(f.default.version,`≥`,`15.0.0`),h=(0,c.compareVersions)(f.default.version,`≥`,`16.0.0`),g=(0,c.compareVersions)(f.default.version,`≥`,`15.3.0`),_=h?!process.env.npm_lifecycle_script?.includes(`--webpack`):process.env.npm_lifecycle_script?.includes(`--turbo`),v=e=>{try{return(e.build?.require??(0,c.getProjectRequire)()).resolve(`@intlayer/swc`),!0}catch{return!1}},y=e=>{try{return(e.build?.require??(0,c.getProjectRequire)()).resolve(`@intlayer/babel`),!0}catch{return!1}},b=(e,t,r)=>{let i=(t.build?.require??(0,c.getProjectRequire)())?.resolve(e);return r?(0,c.normalizePath)(`./${(0,n.relative)(process.cwd(),i)}`):i},x=(e,r,i,s)=>{let{optimize:c}=e.build,u=e.build.importMode??e.dictionary?.importMode,{dictionariesDir:d,unmergedDictionariesDir:f,dynamicDictionariesDir:m,fetchDictionariesDir:h,mainDir:g}=e.system,{baseDir:_}=e.content,x=(0,o.getAppLogger)(e);if(c===!1||c===void 0&&!r||!p)return{};let S=v(e);if((0,a.runOnce)((0,n.join)(_,`.intlayer`,`cache`,`intlayer-prune-plugin-enabled.lock`),()=>{x(S?`Build optimization enabled`:[(0,o.colorize)(`Recommended: Install`,o.ANSIColors.GREY),(0,o.colorize)(`@intlayer/swc`,o.ANSIColors.GREY_LIGHT),(0,o.colorize)(`package to enable build optimization. See documentation: `,o.ANSIColors.GREY),(0,o.colorize)(`https://intlayer.org/docs/bundle-optimization`,o.ANSIColors.GREY_LIGHT)])},{cacheTimeoutMs:1e3*30}),(0,a.runOnce)((0,n.join)(_,`.intlayer`,`cache`,`intlayer-compiler-plugin-enabled.lock`),()=>{if(y(e)){let t=e.compiler?.enabled??!0;t===`build-only`&&(t=!s),x(t?`Intlayer compiler enabled`:`Intlayer compiler disabled`)}},{cacheTimeoutMs:1e3*30}),!S)return{};let C=(0,n.join)(g,`dictionaries.mjs`),w=(0,n.join)(g,`dynamic_dictionaries.mjs`),T=(0,n.join)(g,`unmerged_dictionaries.mjs`),E=(0,n.join)(g,`fetch_dictionaries.mjs`),D=[...(0,a.getComponentTransformPatternSync)(e),C,T],O=(0,l.getDictionaries)(e),k={};return Object.values(O).forEach(e=>{k[e.key]=e.importMode??u??t.DefaultValues.Dictionary.IMPORT_MODE}),{experimental:{swcPlugins:[[b(`@intlayer/swc`,e,i),{dictionariesDir:d,dictionariesEntryPath:C,unmergedDictionariesEntryPath:T,unmergedDictionariesDir:f,dynamicDictionariesDir:m,dynamicDictionariesEntryPath:w,fetchDictionariesDir:h,fetchDictionariesEntryPath:E,importMode:u,filesList:D,replaceDictionaryEntry:!0,dictionaryModeMap:k}]]}}},S=()=>{let e=process.env.npm_lifecycle_event,t=process.env.npm_lifecycle_script??``;return{isDevCommand:e===`dev`||process.argv.some(e=>e===`dev`)||/(^|\s)(next\s+)?dev(\s|$)/.test(t),isBuildCommand:e===`build`||process.argv.some(e=>e===`build`)||/(^|\s)(next\s+)?build(\s|$)/.test(t),isStartCommand:e===`start`||process.argv.some(e=>e===`start`)||/(^|\s)(next\s+)?start(\s|$)/.test(t)}},C=(e={},t)=>{typeof e!=`object`&&(e={});let r=(0,s.getConfiguration)(t);(0,i.logConfigDetails)(t);let a=(0,o.getAppLogger)(r),l=t?.enableTurbopack??_;l&&e.webpack!==void 0&&a(`Turbopack is enabled but a custom webpack config is present. It will be ignored.`);let{isBuildCommand:f,isDevCommand:h}=S(),v={resolveAlias:(0,c.getAlias)({configuration:r,formatter:e=>`./${e}`}),rules:{"*.node":{as:`*.node`,loaders:[`node-loader`]}}},y=[`esbuild`,`module`,`fs`,`chokidar`,`fsevents`],b=()=>{let t={};return m&&(t={...t,serverExternalPackages:y}),p&&!m&&(t={...t,experimental:{...t?.experimental??{},serverComponentsExternalPackages:y}}),t=l?m&&g?{...t,turbopack:v}:{...t,experimental:{...t?.experimental??{},turbo:v}}:{...t,webpack:(t,i)=>{let{isServer:a,nextRuntime:o}=i;return typeof e.webpack==`function`&&(t=e.webpack(t,i)),t.externals===!1&&(t.externals=[]),t.externals.push({esbuild:`esbuild`,module:`module`,fs:`fs`,chokidar:`chokidar`,fsevents:`fsevents`}),t.module.rules.push({test:/\.node$/,loader:`node-loader`}),t.resolve.alias={...t.resolve.alias,...(0,c.getAlias)({configuration:r,formatter:e=>(0,n.resolve)(e)})},h&&a&&o===`nodejs`&&t.plugins.push(new u.IntlayerPlugin(r)),t}},t},C=x(r,f,l??!1,h);return(0,d.defu)((0,d.defu)(b(),C),e)},w=async(e={},t)=>{let{isBuildCommand:n,isDevCommand:i,isStartCommand:a}=S();process.env.INTLAYER_IS_DEV_COMMAND=i?`true`:`false`;let o=(0,s.getConfiguration)(t),{mode:c}=o.build;return!a&&(i||n||c===`auto`)&&await(0,r.prepareIntlayer)(o,{clean:n,cacheTimeoutMs:n?1e3*30:1e3*60*60}),C(await e,t)};exports.withIntlayer=w,exports.withIntlayerSync=C;
|
|
2
2
|
//# sourceMappingURL=withIntlayer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withIntlayer.cjs","names":["nextPackageJSON","ANSIColors","DefaultValues","IntlayerPlugin"],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { join, relative, resolve } from 'node:path';\nimport { prepareIntlayer } from '@intlayer/chokidar/build';\nimport {\n getComponentTransformPatternSync,\n runOnce,\n} from '@intlayer/chokidar/utils';\nimport { DefaultValues } from '@intlayer/config/client';\nimport { ANSIColors, colorize, getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport {\n compareVersions,\n getAlias,\n getProjectRequire,\n normalizePath,\n} from '@intlayer/config/utils';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Dictionary, 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\n// Check if Babel plugin is available\nconst getIsBabelExtractPluginAvailable = (intlayerConfig: IntlayerConfig) => {\n try {\n const requireFunction =\n intlayerConfig.build?.require ?? getProjectRequire();\n requireFunction.resolve('@intlayer/babel');\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 isDevCommand: boolean\n): Partial<NextConfig> => {\n const { optimize } = intlayerConfig.build;\n const importMode =\n intlayerConfig.build.importMode ?? intlayerConfig.dictionary?.importMode;\n const {\n dictionariesDir,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n } = intlayerConfig.system;\n const { baseDir } = 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 runOnce(\n join(baseDir, '.intlayer', 'cache', 'intlayer-prune-plugin-enabled.lock'),\n () => {\n if (isSwcPluginAvailable) {\n logger('Build optimization enabled');\n } else {\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/bundle-optimization',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n }\n },\n {\n cacheTimeoutMs: 1000 * 30, // 30 seconds\n }\n );\n\n runOnce(\n join(\n baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-compiler-plugin-enabled.lock'\n ),\n () => {\n const isBabelExtractPluginAvailable =\n getIsBabelExtractPluginAvailable(intlayerConfig);\n\n if (isBabelExtractPluginAvailable) {\n let isEnabled = intlayerConfig.compiler?.enabled ?? true;\n\n if (isEnabled === 'build-only') {\n isEnabled = !isDevCommand;\n }\n\n if (isEnabled) {\n logger('Intlayer compiler enabled');\n } else {\n logger('Intlayer compiler disabled');\n }\n }\n },\n {\n cacheTimeoutMs: 1000 * 30, // 30 seconds\n }\n );\n\n if (!isSwcPluginAvailable) {\n return {};\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 dictionaryModeMap: Record<string, 'static' | 'dynamic' | 'fetch'> = {};\n\n (Object.values(dictionaries) as Dictionary[]).forEach((dictionary) => {\n dictionaryModeMap[dictionary.key] =\n dictionary.importMode ??\n importMode ??\n DefaultValues.Dictionary.IMPORT_MODE;\n });\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 dictionaryModeMap,\n },\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 isDevCommand\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, isStartCommand } = getCommandsEvent();\n\n process.env.INTLAYER_IS_DEV_COMMAND = isDevCommand ? 'true' : 'false';\n\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 (!isStartCommand && (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":"yfA0BA,MAAM,GAAA,EAAA,EAAA,iBAA8BA,EAAAA,QAAgB,QAAS,IAAK,SAAS,CACrE,GAAA,EAAA,EAAA,iBAA8BA,EAAAA,QAAgB,QAAS,IAAK,SAAS,CACrE,GAAA,EAAA,EAAA,iBAA8BA,EAAAA,QAAgB,QAAS,IAAK,SAAS,CACrE,GAAA,EAAA,EAAA,iBACJA,EAAAA,QAAgB,QAChB,IACA,SACD,CAEK,EAAgC,EAElC,CAAC,QAAQ,IAAI,sBAAsB,SAAS,YAAY,CAExD,QAAQ,IAAI,sBAAsB,SAAS,UAAU,CAGnD,EAA2B,GAAmC,CAClE,GAAI,CAIF,OAFE,EAAe,OAAO,UAAA,EAAA,EAAA,oBAA8B,EACtC,QAAQ,gBAAgB,CACjC,QACI,CACX,MAAO,KAKL,EAAoC,GAAmC,CAC3E,GAAI,CAIF,OAFE,EAAe,OAAO,UAAA,EAAA,EAAA,oBAA8B,EACtC,QAAQ,kBAAkB,CACnC,QACI,CACX,MAAO,KAIL,GACJ,EACA,EACA,IACW,CAEX,IAAM,GADkB,EAAe,OAAO,UAAA,EAAA,EAAA,oBAA8B,GAChC,QAAQ,EAAW,CAO/D,OALI,GAEF,EAAA,EAAA,eAAqB,MAAA,EAAA,EAAA,UAAc,QAAQ,KAAK,CAAE,EAAmB,GAAG,CAGnE,GAGH,GACJ,EACA,EACA,EACA,IACwB,CACxB,GAAM,CAAE,YAAa,EAAe,MAC9B,EACJ,EAAe,MAAM,YAAc,EAAe,YAAY,WAC1D,CACJ,kBACA,0BACA,yBACA,uBACA,WACE,EAAe,OACb,CAAE,WAAY,EAAe,QAC7B,GAAA,EAAA,EAAA,cAAsB,EAAe,CAS3C,GAPI,IAAa,IAGb,IAAa,IAAA,IAAa,CAAC,GAI3B,CAAC,EAAa,MAAO,EA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,eAAgB,EA4ClC,OAzCI,OAAO,EAAW,SAAY,aAChC,EAAS,EAAW,QAAQ,EAAQ,EAAQ,EAK1C,EAAO,YAAc,KACvB,EAAO,UAAY,EAAE,EAIvB,EAAO,UAAU,KAAK,CACpB,QAAS,UACT,OAAQ,SACR,GAAI,KACJ,SAAU,WACV,SAAU,WACX,CAAC,CAGF,EAAO,OAAO,MAAM,KAAK,CACvB,KAAM,UACN,OAAQ,cACT,CAAC,CAIF,EAAO,QAAQ,MAAQ,CACrB,GAAG,EAAO,QAAQ,MAClB,IAAA,EAAA,EAAA,UAAY,CACV,cAAe,EACf,UAAY,IAAA,EAAA,EAAA,SAA0B,EAAM,CAC7C,CAAC,CACH,CAGG,GAAgB,GAAY,IAAgB,UAE9C,EAAO,QAAQ,KAAK,IAAIC,EAAAA,eAAe,EAAe,CAAC,CAGlD,GAEV,CAGI,GAGH,EAAmC,EACvC,EACA,EACA,GAAsB,GACtB,EACD,CAUD,OAAA,EAAA,EAAA,OAAA,EAAA,EAAA,MAPE,GAAc,CACd,EACD,CAGuC,EAAW,EAoBxC,EAAe,MAC1B,EAA6B,EAAE,CAC/B,IAC4B,CAC5B,GAAM,CAAE,iBAAgB,eAAc,kBAAmB,GAAkB,CAE3E,QAAQ,IAAI,wBAA0B,EAAe,OAAS,QAE9D,IAAM,GAAA,EAAA,EAAA,kBAAkC,EAAc,CAEhD,CAAE,QAAS,EAAe,MAiBhC,MAZI,CAAC,IAAmB,GAAgB,GAAkB,IAAS,SAEjE,MAAA,EAAA,EAAA,iBAAsB,EAAgB,CACpC,MAAO,EACP,eAAgB,EACZ,IAAO,GACP,IAAO,GAAK,GACjB,CAAC,CAKG,EAFoB,MAAM,EAEW,EAAc"}
|
|
1
|
+
{"version":3,"file":"withIntlayer.cjs","names":["nextPackageJSON","ANSIColors","DefaultValues","IntlayerPlugin"],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { join, relative, resolve } from 'node:path';\nimport { prepareIntlayer } from '@intlayer/chokidar/build';\nimport { logConfigDetails } from '@intlayer/chokidar/cli';\nimport {\n getComponentTransformPatternSync,\n runOnce,\n} from '@intlayer/chokidar/utils';\nimport { DefaultValues } from '@intlayer/config/client';\nimport { ANSIColors, colorize, getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport {\n compareVersions,\n getAlias,\n getProjectRequire,\n normalizePath,\n} from '@intlayer/config/utils';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Dictionary, 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\n// Check if Babel plugin is available\nconst getIsBabelExtractPluginAvailable = (intlayerConfig: IntlayerConfig) => {\n try {\n const requireFunction =\n intlayerConfig.build?.require ?? getProjectRequire();\n requireFunction.resolve('@intlayer/babel');\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 isDevCommand: boolean\n): Partial<NextConfig> => {\n const { optimize } = intlayerConfig.build;\n const importMode =\n intlayerConfig.build.importMode ?? intlayerConfig.dictionary?.importMode;\n const {\n dictionariesDir,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n } = intlayerConfig.system;\n const { baseDir } = 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 runOnce(\n join(baseDir, '.intlayer', 'cache', 'intlayer-prune-plugin-enabled.lock'),\n () => {\n if (isSwcPluginAvailable) {\n logger('Build optimization enabled');\n } else {\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/bundle-optimization',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n }\n },\n {\n cacheTimeoutMs: 1000 * 30, // 30 seconds\n }\n );\n\n runOnce(\n join(\n baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-compiler-plugin-enabled.lock'\n ),\n () => {\n const isBabelExtractPluginAvailable =\n getIsBabelExtractPluginAvailable(intlayerConfig);\n\n if (isBabelExtractPluginAvailable) {\n let isEnabled = intlayerConfig.compiler?.enabled ?? true;\n\n if (isEnabled === 'build-only') {\n isEnabled = !isDevCommand;\n }\n\n if (isEnabled) {\n logger('Intlayer compiler enabled');\n } else {\n logger('Intlayer compiler disabled');\n }\n }\n },\n {\n cacheTimeoutMs: 1000 * 30, // 30 seconds\n }\n );\n\n if (!isSwcPluginAvailable) {\n return {};\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 dictionaryModeMap: Record<string, 'static' | 'dynamic' | 'fetch'> = {};\n\n (Object.values(dictionaries) as Dictionary[]).forEach((dictionary) => {\n dictionaryModeMap[dictionary.key] =\n dictionary.importMode ??\n importMode ??\n DefaultValues.Dictionary.IMPORT_MODE;\n });\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 dictionaryModeMap,\n },\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\n logConfigDetails(configOptions);\n\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 isDevCommand\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, isStartCommand } = getCommandsEvent();\n\n process.env.INTLAYER_IS_DEV_COMMAND = isDevCommand ? 'true' : 'false';\n\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 (!isStartCommand && (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":"6hBA2BA,MAAM,GAAA,EAAA,EAAA,iBAA8BA,EAAAA,QAAgB,QAAS,IAAK,SAAS,CACrE,GAAA,EAAA,EAAA,iBAA8BA,EAAAA,QAAgB,QAAS,IAAK,SAAS,CACrE,GAAA,EAAA,EAAA,iBAA8BA,EAAAA,QAAgB,QAAS,IAAK,SAA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CAAC,CAIF,EAAO,QAAQ,MAAQ,CACrB,GAAG,EAAO,QAAQ,MAClB,IAAA,EAAA,EAAA,UAAY,CACV,cAAe,EACf,UAAY,IAAA,EAAA,EAAA,SAA0B,EAAM,CAC7C,CAAC,CACH,CAGG,GAAgB,GAAY,IAAgB,UAE9C,EAAO,QAAQ,KAAK,IAAIC,EAAAA,eAAe,EAAe,CAAC,CAGlD,GAEV,CAGI,GAGH,EAAmC,EACvC,EACA,EACA,GAAsB,GACtB,EACD,CAUD,OAAA,EAAA,EAAA,OAAA,EAAA,EAAA,MAPE,GAAc,CACd,EACD,CAGuC,EAAW,EAoBxC,EAAe,MAC1B,EAA6B,EAAE,CAC/B,IAC4B,CAC5B,GAAM,CAAE,iBAAgB,eAAc,kBAAmB,GAAkB,CAE3E,QAAQ,IAAI,wBAA0B,EAAe,OAAS,QAE9D,IAAM,GAAA,EAAA,EAAA,kBAAkC,EAAc,CAEhD,CAAE,QAAS,EAAe,MAiBhC,MAZI,CAAC,IAAmB,GAAgB,GAAkB,IAAS,SAEjE,MAAA,EAAA,EAAA,iBAAsB,EAAgB,CACpC,MAAO,EACP,eAAgB,EACZ,IAAO,GACP,IAAO,GAAK,GACjB,CAAC,CAKG,EAFoB,MAAM,EAEW,EAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerClientProvider.mjs","names":[],"sources":["../../../src/client/IntlayerClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\n\nimport { IntlayerProvider, type IntlayerProviderProps } from 'react-intlayer';\n\nexport type IntlayerClientProviderProps = IntlayerProviderProps;\n\n/**\n * Provider for client-side components in Next.js.\n *\n * This component wraps the `IntlayerProvider` from `react-intlayer` and is intended\n * to be used within Next.js App Router client components.\n *\n * @param props - The provider props.\n * @returns The provider component.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import { IntlayerClientProvider } from 'next-intlayer';\n *\n * export default function ClientLayout({ children, locale }) {\n * return (\n * <IntlayerClientProvider locale={locale}>\n * {children}\n * </IntlayerClientProvider>\n * );\n * }\n * ```\n */\nexport const IntlayerClientProvider: FC<IntlayerProviderProps> = (props) => (\n <IntlayerProvider {...props} />\n);\n"],"mappings":"uGAgCA,MAAa,EAAqD,GAChE,EAAC,
|
|
1
|
+
{"version":3,"file":"IntlayerClientProvider.mjs","names":[],"sources":["../../../src/client/IntlayerClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\n\nimport { IntlayerProvider, type IntlayerProviderProps } from 'react-intlayer';\n\nexport type IntlayerClientProviderProps = IntlayerProviderProps;\n\n/**\n * Provider for client-side components in Next.js.\n *\n * This component wraps the `IntlayerProvider` from `react-intlayer` and is intended\n * to be used within Next.js App Router client components.\n *\n * @param props - The provider props.\n * @returns The provider component.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import { IntlayerClientProvider } from 'next-intlayer';\n *\n * export default function ClientLayout({ children, locale }) {\n * return (\n * <IntlayerClientProvider locale={locale}>\n * {children}\n * </IntlayerClientProvider>\n * );\n * }\n * ```\n */\nexport const IntlayerClientProvider: FC<IntlayerProviderProps> = (props) => (\n <IntlayerProvider {...props} />\n);\n"],"mappings":"uGAgCA,MAAa,EAAqD,GAChE,EAAC,EAAD,CAAkB,GAAI,EAAS,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{withIntlayer as e,withIntlayerSync as t}from"./withIntlayer.mjs";import{IntlayerServerProvider as n,locale as r,t as i,useDictionary as a,useDictionaryAsync as o,useDictionaryDynamic as s,useI18n as c,useIntl as l,useIntlayer as u,useLoadDynamic as d,useLocale as f}from"react-intlayer/server";export{n as IntlayerServerProvider,r as locale,i as t,a as useDictionary,o as useDictionaryAsync,s as useDictionaryDynamic,c as useI18n,l as useIntl,u as useIntlayer,d as useLoadDynamic,f as useLocale,e as withIntlayer,t as withIntlayerSync};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDictionary.mjs","names":["useDictionaryBase"],"sources":["../../../src/server/useDictionary.ts"],"sourcesContent":["import type { DeclaredLocales, Dictionary } from '@intlayer/types';\nimport { useDictionary as useDictionaryBase } from 'react-intlayer/server';\nimport { safeUseLocale } from './useIntlayer';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionary = <\n T extends Dictionary,\n L extends DeclaredLocales = DeclaredLocales,\n>(\n dictionary: T,\n locale?: L\n): ReturnType<typeof useDictionaryBase<T, L>> => {\n const storedLocale = safeUseLocale();\n\n return useDictionaryBase<T, L>(dictionary, locale, storedLocale);\n};\n"],"mappings":"wGASA,MAAa,GAIX,EACA,IAIOA,EAAwB,EAAY,EAFtB,GAAe,CAE4B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.mjs","names":["useDictionaryAsyncBase"],"sources":["../../../src/server/useDictionaryAsync.ts"],"sourcesContent":["import type {\n DeclaredLocales,\n Dictionary,\n StrictModeLocaleMap,\n} from '@intlayer/types';\nimport { useDictionaryAsync as useDictionaryAsyncBase } from 'react-intlayer/server';\nimport { getLocale } from './getLocale';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryAsync = async <\n T extends Dictionary,\n L extends DeclaredLocales = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n locale?: L\n): ReturnType<typeof useDictionaryAsyncBase<T, L>> => {\n const storedLocale = await getLocale();\n\n return useDictionaryAsyncBase<T, L>(dictionaryPromise, locale, storedLocale);\n};\n"],"mappings":"uGAaA,MAAa,EAAqB,MAIhC,EACA,IAIOA,EAA6B,EAAmB,EAFlC,MAAM,GAAW,CAEsC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.mjs","names":["useDictionaryDynamicBase"],"sources":["../../../src/server/useDictionaryDynamic.ts"],"sourcesContent":["import type {\n DeclaredLocales,\n Dictionary,\n StrictModeLocaleMap,\n} from '@intlayer/types';\nimport { useDictionaryDynamic as useDictionaryDynamicBase } from 'react-intlayer/server';\nimport { safeUseLocale } from './useIntlayer';\n\n/**\n * On the server side, Hook that transform a dictionary and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useDictionaryDynamic = <\n T extends Dictionary,\n L extends DeclaredLocales = DeclaredLocales,\n>(\n dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>,\n key: string,\n locale?: L\n): ReturnType<typeof useDictionaryDynamicBase<T, L>> => {\n const storedLocale = safeUseLocale();\n\n return useDictionaryDynamicBase<T, L>(\n dictionaryPromise,\n key,\n locale,\n storedLocale\n );\n};\n"],"mappings":"+GAaA,MAAa,GAIX,EACA,EACA,IAIOA,EACL,EACA,EACA,EALmB,GAAe,CAOnC"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{getLocale as e}from"./getLocale.mjs";import t from"react";import{useIntlayer as n}from"react-intlayer/server";const r=typeof t.cache==`function`?t.cache(e):e,i=()=>{let e=r();return e instanceof Promise?typeof t.use==`function`?t.use(e):void 0:e},a=(e,t)=>n(e,t,i());export{i as safeUseLocale,a as useIntlayer};
|
|
2
|
+
//# sourceMappingURL=useIntlayer.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIntlayer.mjs","names":["useIntlayerBase"],"sources":["../../../src/server/useIntlayer.ts"],"sourcesContent":["import type { DeclaredLocales, DictionaryKeys, Locale } from '@intlayer/types';\nimport React from 'react';\nimport { useIntlayer as useIntlayerBase } from 'react-intlayer/server';\nimport { getLocale } from './getLocale';\n\nconst getCachedLocale =\n typeof React.cache === 'function' ? React.cache(getLocale) : getLocale;\n\nexport const safeUseLocale = (): Locale | undefined => {\n // getLocale returns a Promise based on your TS error\n const localeData = getCachedLocale() as Promise<Locale> | Locale;\n\n if (localeData instanceof Promise) {\n if (typeof React.use === 'function') {\n return React.use(localeData); // Safely unwraps in React 19+\n }\n\n // React < 19 cannot synchronously unwrap Promises in hooks.\n // Return undefined to trigger the localeTarget fallback.\n return undefined;\n }\n\n return localeData;\n};\n\n/**\n * On the server side, Hook that picking one dictionary by its key and return the content\n *\n * If the locale is not provided, it will use the locale from the server context\n */\nexport const useIntlayer = <\n T extends DictionaryKeys,\n L extends DeclaredLocales = DeclaredLocales,\n>(\n key: T,\n locale?: L\n): ReturnType<typeof useIntlayerBase<T, L>> => {\n const storedLocale = safeUseLocale();\n\n return useIntlayerBase<T, L>(key, locale, storedLocale);\n};\n"],"mappings":"qHAKA,MAAM,EACJ,OAAO,EAAM,OAAU,WAAa,EAAM,MAAM,EAAU,CAAG,EAElD,MAA0C,CAErD,IAAM,EAAa,GAAiB,CAYpC,OAVI,aAAsB,QACpB,OAAO,EAAM,KAAQ,WAChB,EAAM,IAAI,EAAW,CAK9B,OAGK,GAQI,GAIX,EACA,IAIOA,EAAsB,EAAK,EAFb,GAAe,CAEmB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{DefaultValues as e}from"@intlayer/config/client";import{join as t,relative as n,resolve as r}from"node:path";import{prepareIntlayer as i}from"@intlayer/chokidar/build";import{getComponentTransformPatternSync as
|
|
1
|
+
import{DefaultValues as e}from"@intlayer/config/client";import{join as t,relative as n,resolve as r}from"node:path";import{prepareIntlayer as i}from"@intlayer/chokidar/build";import{logConfigDetails as a}from"@intlayer/chokidar/cli";import{getComponentTransformPatternSync as o,runOnce as s}from"@intlayer/chokidar/utils";import{ANSIColors as c,colorize as l,getAppLogger as u}from"@intlayer/config/logger";import{getConfiguration as d}from"@intlayer/config/node";import{compareVersions as f,getAlias as p,getProjectRequire as m,normalizePath as h}from"@intlayer/config/utils";import{getDictionaries as g}from"@intlayer/dictionaries-entry";import{IntlayerPlugin as _}from"@intlayer/webpack";import{defu as v}from"defu";import y from"next/package.json"with{type:"json"};const b=f(y.version,`≥`,`13.0.0`),x=f(y.version,`≥`,`15.0.0`),S=f(y.version,`≥`,`16.0.0`),C=f(y.version,`≥`,`15.3.0`),w=S?!process.env.npm_lifecycle_script?.includes(`--webpack`):process.env.npm_lifecycle_script?.includes(`--turbo`),T=e=>{try{return(e.build?.require??m()).resolve(`@intlayer/swc`),!0}catch{return!1}},E=e=>{try{return(e.build?.require??m()).resolve(`@intlayer/babel`),!0}catch{return!1}},D=(e,t,r)=>{let i=(t.build?.require??m())?.resolve(e);return r?h(`./${n(process.cwd(),i)}`):i},O=(n,r,i,a)=>{let{optimize:d}=n.build,f=n.build.importMode??n.dictionary?.importMode,{dictionariesDir:p,unmergedDictionariesDir:m,dynamicDictionariesDir:h,fetchDictionariesDir:_,mainDir:v}=n.system,{baseDir:y}=n.content,x=u(n);if(d===!1||d===void 0&&!r||!b)return{};let S=T(n);if(s(t(y,`.intlayer`,`cache`,`intlayer-prune-plugin-enabled.lock`),()=>{x(S?`Build optimization enabled`:[l(`Recommended: Install`,c.GREY),l(`@intlayer/swc`,c.GREY_LIGHT),l(`package to enable build optimization. See documentation: `,c.GREY),l(`https://intlayer.org/docs/bundle-optimization`,c.GREY_LIGHT)])},{cacheTimeoutMs:1e3*30}),s(t(y,`.intlayer`,`cache`,`intlayer-compiler-plugin-enabled.lock`),()=>{if(E(n)){let e=n.compiler?.enabled??!0;e===`build-only`&&(e=!a),x(e?`Intlayer compiler enabled`:`Intlayer compiler disabled`)}},{cacheTimeoutMs:1e3*30}),!S)return{};let C=t(v,`dictionaries.mjs`),w=t(v,`dynamic_dictionaries.mjs`),O=t(v,`unmerged_dictionaries.mjs`),k=t(v,`fetch_dictionaries.mjs`),A=[...o(n),C,O],j=g(n),M={};return Object.values(j).forEach(t=>{M[t.key]=t.importMode??f??e.Dictionary.IMPORT_MODE}),{experimental:{swcPlugins:[[D(`@intlayer/swc`,n,i),{dictionariesDir:p,dictionariesEntryPath:C,unmergedDictionariesEntryPath:O,unmergedDictionariesDir:m,dynamicDictionariesDir:h,dynamicDictionariesEntryPath:w,fetchDictionariesDir:_,fetchDictionariesEntryPath:k,importMode:f,filesList:A,replaceDictionaryEntry:!0,dictionaryModeMap:M}]]}}},k=()=>{let e=process.env.npm_lifecycle_event,t=process.env.npm_lifecycle_script??``;return{isDevCommand:e===`dev`||process.argv.some(e=>e===`dev`)||/(^|\s)(next\s+)?dev(\s|$)/.test(t),isBuildCommand:e===`build`||process.argv.some(e=>e===`build`)||/(^|\s)(next\s+)?build(\s|$)/.test(t),isStartCommand:e===`start`||process.argv.some(e=>e===`start`)||/(^|\s)(next\s+)?start(\s|$)/.test(t)}},A=(e={},t)=>{typeof e!=`object`&&(e={});let n=d(t);a(t);let i=u(n),o=t?.enableTurbopack??w;o&&e.webpack!==void 0&&i(`Turbopack is enabled but a custom webpack config is present. It will be ignored.`);let{isBuildCommand:s,isDevCommand:c}=k(),l={resolveAlias:p({configuration:n,formatter:e=>`./${e}`}),rules:{"*.node":{as:`*.node`,loaders:[`node-loader`]}}},f=[`esbuild`,`module`,`fs`,`chokidar`,`fsevents`],m=()=>{let t={};return x&&(t={...t,serverExternalPackages:f}),b&&!x&&(t={...t,experimental:{...t?.experimental??{},serverComponentsExternalPackages:f}}),t=o?x&&C?{...t,turbopack:l}:{...t,experimental:{...t?.experimental??{},turbo:l}}:{...t,webpack:(t,i)=>{let{isServer:a,nextRuntime:o}=i;return typeof e.webpack==`function`&&(t=e.webpack(t,i)),t.externals===!1&&(t.externals=[]),t.externals.push({esbuild:`esbuild`,module:`module`,fs:`fs`,chokidar:`chokidar`,fsevents:`fsevents`}),t.module.rules.push({test:/\.node$/,loader:`node-loader`}),t.resolve.alias={...t.resolve.alias,...p({configuration:n,formatter:e=>r(e)})},c&&a&&o===`nodejs`&&t.plugins.push(new _(n)),t}},t},h=O(n,s,o??!1,c);return v(v(m(),h),e)},j=async(e={},t)=>{let{isBuildCommand:n,isDevCommand:r,isStartCommand:a}=k();process.env.INTLAYER_IS_DEV_COMMAND=r?`true`:`false`;let o=d(t),{mode:s}=o.build;return!a&&(r||n||s===`auto`)&&await i(o,{clean:n,cacheTimeoutMs:n?1e3*30:1e3*60*60}),A(await e,t)};export{j as withIntlayer,A as withIntlayerSync};
|
|
2
2
|
//# sourceMappingURL=withIntlayer.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withIntlayer.mjs","names":[],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { join, relative, resolve } from 'node:path';\nimport { prepareIntlayer } from '@intlayer/chokidar/build';\nimport {\n getComponentTransformPatternSync,\n runOnce,\n} from '@intlayer/chokidar/utils';\nimport { DefaultValues } from '@intlayer/config/client';\nimport { ANSIColors, colorize, getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport {\n compareVersions,\n getAlias,\n getProjectRequire,\n normalizePath,\n} from '@intlayer/config/utils';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Dictionary, 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\n// Check if Babel plugin is available\nconst getIsBabelExtractPluginAvailable = (intlayerConfig: IntlayerConfig) => {\n try {\n const requireFunction =\n intlayerConfig.build?.require ?? getProjectRequire();\n requireFunction.resolve('@intlayer/babel');\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 isDevCommand: boolean\n): Partial<NextConfig> => {\n const { optimize } = intlayerConfig.build;\n const importMode =\n intlayerConfig.build.importMode ?? intlayerConfig.dictionary?.importMode;\n const {\n dictionariesDir,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n } = intlayerConfig.system;\n const { baseDir } = 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 runOnce(\n join(baseDir, '.intlayer', 'cache', 'intlayer-prune-plugin-enabled.lock'),\n () => {\n if (isSwcPluginAvailable) {\n logger('Build optimization enabled');\n } else {\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/bundle-optimization',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n }\n },\n {\n cacheTimeoutMs: 1000 * 30, // 30 seconds\n }\n );\n\n runOnce(\n join(\n baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-compiler-plugin-enabled.lock'\n ),\n () => {\n const isBabelExtractPluginAvailable =\n getIsBabelExtractPluginAvailable(intlayerConfig);\n\n if (isBabelExtractPluginAvailable) {\n let isEnabled = intlayerConfig.compiler?.enabled ?? true;\n\n if (isEnabled === 'build-only') {\n isEnabled = !isDevCommand;\n }\n\n if (isEnabled) {\n logger('Intlayer compiler enabled');\n } else {\n logger('Intlayer compiler disabled');\n }\n }\n },\n {\n cacheTimeoutMs: 1000 * 30, // 30 seconds\n }\n );\n\n if (!isSwcPluginAvailable) {\n return {};\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 dictionaryModeMap: Record<string, 'static' | 'dynamic' | 'fetch'> = {};\n\n (Object.values(dictionaries) as Dictionary[]).forEach((dictionary) => {\n dictionaryModeMap[dictionary.key] =\n dictionary.importMode ??\n importMode ??\n DefaultValues.Dictionary.IMPORT_MODE;\n });\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 dictionaryModeMap,\n },\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 isDevCommand\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, isStartCommand } = getCommandsEvent();\n\n process.env.INTLAYER_IS_DEV_COMMAND = isDevCommand ? 'true' : 'false';\n\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 (!isStartCommand && (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 withIntlay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GAAY,IAAgB,UAE9C,EAAO,QAAQ,KAAK,IAAI,EAAe,EAAe,CAAC,CAGlD,GAEV,CAGI,GAGH,EAAmC,EACvC,EACA,EACA,GAAsB,GACtB,EACD,CAUD,OAFe,EANiC,EAC9C,GAAc,CACd,EACD,CAGuC,EAAW,EAoBxC,EAAe,MAC1B,EAA6B,EAAE,CAC/B,IAC4B,CAC5B,GAAM,CAAE,iBAAgB,eAAc,kBAAmB,GAAkB,CAE3E,QAAQ,IAAI,wBAA0B,EAAe,OAAS,QAE9D,IAAM,EAAiB,EAAiB,EAAc,CAEhD,CAAE,QAAS,EAAe,MAiBhC,MAZI,CAAC,IAAmB,GAAgB,GAAkB,IAAS,SAEjE,MAAM,EAAgB,EAAgB,CACpC,MAAO,EACP,eAAgB,EACZ,IAAO,GACP,IAAO,GAAK,GACjB,CAAC,CAKG,EAFoB,MAAM,EAEW,EAAc"}
|
|
1
|
+
{"version":3,"file":"withIntlayer.mjs","names":[],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { join, relative, resolve } from 'node:path';\nimport { prepareIntlayer } from '@intlayer/chokidar/build';\nimport { logConfigDetails } from '@intlayer/chokidar/cli';\nimport {\n getComponentTransformPatternSync,\n runOnce,\n} from '@intlayer/chokidar/utils';\nimport { DefaultValues } from '@intlayer/config/client';\nimport { ANSIColors, colorize, getAppLogger } from '@intlayer/config/logger';\nimport {\n type GetConfigurationOptions,\n getConfiguration,\n} from '@intlayer/config/node';\nimport {\n compareVersions,\n getAlias,\n getProjectRequire,\n normalizePath,\n} from '@intlayer/config/utils';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { Dictionary, 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\n// Check if Babel plugin is available\nconst getIsBabelExtractPluginAvailable = (intlayerConfig: IntlayerConfig) => {\n try {\n const requireFunction =\n intlayerConfig.build?.require ?? getProjectRequire();\n requireFunction.resolve('@intlayer/babel');\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 isDevCommand: boolean\n): Partial<NextConfig> => {\n const { optimize } = intlayerConfig.build;\n const importMode =\n intlayerConfig.build.importMode ?? intlayerConfig.dictionary?.importMode;\n const {\n dictionariesDir,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n } = intlayerConfig.system;\n const { baseDir } = 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 runOnce(\n join(baseDir, '.intlayer', 'cache', 'intlayer-prune-plugin-enabled.lock'),\n () => {\n if (isSwcPluginAvailable) {\n logger('Build optimization enabled');\n } else {\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/bundle-optimization',\n ANSIColors.GREY_LIGHT\n ),\n ]);\n }\n },\n {\n cacheTimeoutMs: 1000 * 30, // 30 seconds\n }\n );\n\n runOnce(\n join(\n baseDir,\n '.intlayer',\n 'cache',\n 'intlayer-compiler-plugin-enabled.lock'\n ),\n () => {\n const isBabelExtractPluginAvailable =\n getIsBabelExtractPluginAvailable(intlayerConfig);\n\n if (isBabelExtractPluginAvailable) {\n let isEnabled = intlayerConfig.compiler?.enabled ?? true;\n\n if (isEnabled === 'build-only') {\n isEnabled = !isDevCommand;\n }\n\n if (isEnabled) {\n logger('Intlayer compiler enabled');\n } else {\n logger('Intlayer compiler disabled');\n }\n }\n },\n {\n cacheTimeoutMs: 1000 * 30, // 30 seconds\n }\n );\n\n if (!isSwcPluginAvailable) {\n return {};\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 dictionaryModeMap: Record<string, 'static' | 'dynamic' | 'fetch'> = {};\n\n (Object.values(dictionaries) as Dictionary[]).forEach((dictionary) => {\n dictionaryModeMap[dictionary.key] =\n dictionary.importMode ??\n importMode ??\n DefaultValues.Dictionary.IMPORT_MODE;\n });\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 dictionaryModeMap,\n },\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\n logConfigDetails(configOptions);\n\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 isDevCommand\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, isStartCommand } = getCommandsEvent();\n\n process.env.INTLAYER_IS_DEV_COMMAND = isDevCommand ? 'true' : 'false';\n\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 (!isStartCommand && (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":"iwBA2BA,MAAM,EAAc,EAAgB,EAAgB,QAAS,IAAK,SAAS,CACrE,EAAc,EAAgB,EAAgB,QAAS,IAAK,SAAS,CACrE,EAAc,EAAgB,EAAgB,QAAS,IAAK,SAAS,CACrE,EAAoB,EACxB,EAAgB,QAChB,IACA,SACD,CAEK,EAAgC,EAElC,CAAC,QAAQ,IAAI,sBAAsB,SAAS,YAAY,CAExD,QAAQ,IAAI,sBAAsB,SAAS,UAAU,CAGnD,EAA2B,GAAmC,CAClE,GAAI,CAIF,OAFE,EAAe,OAAO,SAAW,GAAmB,EACtC,QAAQ,gBAAgB,CACjC,QACI,CACX,MAAO,KAKL,EAAoC,GAAmC,CAC3E,GAAI,CAIF,OAFE,EAAe,OAAO,SAAW,GAAmB,EACtC,QAAQ,kBAAkB,CACnC,QACI,CACX,MAAO,KAIL,GACJ,EACA,EACA,IACW,CAEX,IAAM,GADkB,EAAe,OAAO,SAAW,GAAmB,GAChC,QAAQ,EAAW,CAO/D,OALI,EAEK,EAAc,KAAK,EAAS,QAAQ,KAAK,CAAE,EAAmB,GAAG,CAGnE,GAGH,GACJ,EACA,EACA,EACA,IACwB,CACxB,GAAM,CAAE,YAAa,EAAe,MAC9B,EACJ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,SAAU,EAA4B,IAA8B,CAElE,GAAM,CAAE,WAAU,eAAgB,EA4ClC,OAzCI,OAAO,EAAW,SAAY,aAChC,EAAS,EAAW,QAAQ,EAAQ,EAAQ,EAK1C,EAAO,YAAc,KACvB,EAAO,UAAY,EAAE,EAIvB,EAAO,UAAU,KAAK,CACpB,QAAS,UACT,OAAQ,SACR,GAAI,KACJ,SAAU,WACV,SAAU,WACX,CAAC,CAGF,EAAO,OAAO,MAAM,KAAK,CACvB,KAAM,UACN,OAAQ,cACT,CAAC,CAIF,EAAO,QAAQ,MAAQ,CACrB,GAAG,EAAO,QAAQ,MAClB,GAAG,EAAS,CACV,cAAe,EACf,UAAY,GAAkB,EAAQ,EAAM,CAC7C,CAAC,CACH,CAGG,GAAgB,GAAY,IAAgB,UAE9C,EAAO,QAAQ,KAAK,IAAI,EAAe,EAAe,CAAC,CAGlD,GAEV,CAGI,GAGH,EAAmC,EACvC,EACA,EACA,GAAsB,GACtB,EACD,CAUD,OAFe,EANiC,EAC9C,GAAc,CACd,EACD,CAGuC,EAAW,EAoBxC,EAAe,MAC1B,EAA6B,EAAE,CAC/B,IAC4B,CAC5B,GAAM,CAAE,iBAAgB,eAAc,kBAAmB,GAAkB,CAE3E,QAAQ,IAAI,wBAA0B,EAAe,OAAS,QAE9D,IAAM,EAAiB,EAAiB,EAAc,CAEhD,CAAE,QAAS,EAAe,MAiBhC,MAZI,CAAC,IAAmB,GAAgB,GAAkB,IAAS,SAEjE,MAAM,EAAgB,EAAgB,CACpC,MAAO,EACP,eAAgB,EACZ,IAAO,GACP,IAAO,GAAK,GACjB,CAAC,CAKG,EAFoB,MAAM,EAEW,EAAc"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { getLocale } from "./getLocale.js";
|
|
2
1
|
import { withIntlayer, withIntlayerSync } from "./withIntlayer.js";
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
2
|
+
import { IntlayerServerProvider, IntlayerServerProviderProps, locale, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useI18n, useIntl, useIntlayer, useLoadDynamic, useLocale } from "react-intlayer/server";
|
|
3
|
+
export { IntlayerServerProvider, type IntlayerServerProviderProps, locale, t, useDictionary, useDictionaryAsync, useDictionaryDynamic, useI18n, useIntl, useIntlayer, useLoadDynamic, useLocale, withIntlayer, withIntlayerSync };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DeclaredLocales, Dictionary } from "@intlayer/types";
|
|
2
|
+
import { useDictionary as useDictionary$1 } from "react-intlayer/server";
|
|
3
|
+
|
|
4
|
+
//#region src/server/useDictionary.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* On the server side, Hook that transform a dictionary and return the content
|
|
7
|
+
*
|
|
8
|
+
* If the locale is not provided, it will use the locale from the server context
|
|
9
|
+
*/
|
|
10
|
+
declare const useDictionary: <T extends Dictionary, L extends DeclaredLocales = DeclaredLocales>(dictionary: T, locale?: L) => ReturnType<typeof useDictionary$1<T, L>>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { useDictionary };
|
|
13
|
+
//# sourceMappingURL=useDictionary.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDictionary.d.ts","names":[],"sources":["../../../src/server/useDictionary.ts"],"mappings":";;;;;;AASA;;;cAAa,aAAA,aACD,UAAA,YACA,eAAA,GAAkB,eAAA,EAE5B,UAAA,EAAY,CAAA,EACZ,MAAA,GAAS,CAAA,KACR,UAAA,QAAkB,eAAA,CAAkB,CAAA,EAAG,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DeclaredLocales, Dictionary, StrictModeLocaleMap } from "@intlayer/types";
|
|
2
|
+
import { useDictionaryAsync as useDictionaryAsync$1 } from "react-intlayer/server";
|
|
3
|
+
|
|
4
|
+
//#region src/server/useDictionaryAsync.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* On the server side, Hook that transform a dictionary and return the content
|
|
7
|
+
*
|
|
8
|
+
* If the locale is not provided, it will use the locale from the server context
|
|
9
|
+
*/
|
|
10
|
+
declare const useDictionaryAsync: <T extends Dictionary, L extends DeclaredLocales = DeclaredLocales>(dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>, locale?: L) => ReturnType<typeof useDictionaryAsync$1<T, L>>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { useDictionaryAsync };
|
|
13
|
+
//# sourceMappingURL=useDictionaryAsync.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDictionaryAsync.d.ts","names":[],"sources":["../../../src/server/useDictionaryAsync.ts"],"mappings":";;;;;;AAaA;;;cAAa,kBAAA,aACD,UAAA,YACA,eAAA,GAAkB,eAAA,EAE5B,iBAAA,EAAmB,mBAAA,OAA0B,OAAA,CAAQ,CAAA,IACrD,MAAA,GAAS,CAAA,KACR,UAAA,QAAkB,oBAAA,CAAuB,CAAA,EAAG,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DeclaredLocales, Dictionary, StrictModeLocaleMap } from "@intlayer/types";
|
|
2
|
+
import { useDictionaryDynamic as useDictionaryDynamic$1 } from "react-intlayer/server";
|
|
3
|
+
|
|
4
|
+
//#region src/server/useDictionaryDynamic.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* On the server side, Hook that transform a dictionary and return the content
|
|
7
|
+
*
|
|
8
|
+
* If the locale is not provided, it will use the locale from the server context
|
|
9
|
+
*/
|
|
10
|
+
declare const useDictionaryDynamic: <T extends Dictionary, L extends DeclaredLocales = DeclaredLocales>(dictionaryPromise: StrictModeLocaleMap<() => Promise<T>>, key: string, locale?: L) => ReturnType<typeof useDictionaryDynamic$1<T, L>>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { useDictionaryDynamic };
|
|
13
|
+
//# sourceMappingURL=useDictionaryDynamic.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDictionaryDynamic.d.ts","names":[],"sources":["../../../src/server/useDictionaryDynamic.ts"],"mappings":";;;;;;AAaA;;;cAAa,oBAAA,aACD,UAAA,YACA,eAAA,GAAkB,eAAA,EAE5B,iBAAA,EAAmB,mBAAA,OAA0B,OAAA,CAAQ,CAAA,IACrD,GAAA,UACA,MAAA,GAAS,CAAA,KACR,UAAA,QAAkB,sBAAA,CAAyB,CAAA,EAAG,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { DeclaredLocales, DictionaryKeys, Locale } from "@intlayer/types";
|
|
2
|
+
import { useIntlayer as useIntlayer$1 } from "react-intlayer/server";
|
|
3
|
+
|
|
4
|
+
//#region src/server/useIntlayer.d.ts
|
|
5
|
+
declare const safeUseLocale: () => Locale | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* On the server side, Hook that picking one dictionary by its key and return the content
|
|
8
|
+
*
|
|
9
|
+
* If the locale is not provided, it will use the locale from the server context
|
|
10
|
+
*/
|
|
11
|
+
declare const useIntlayer: <T extends DictionaryKeys, L extends DeclaredLocales = DeclaredLocales>(key: T, locale?: L) => ReturnType<typeof useIntlayer$1<T, L>>;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { safeUseLocale, useIntlayer };
|
|
14
|
+
//# sourceMappingURL=useIntlayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIntlayer.d.ts","names":[],"sources":["../../../src/server/useIntlayer.ts"],"mappings":";;;;cAQa,aAAA,QAAoB,MAAA;;AAAjC;;;;cAsBa,WAAA,aACD,cAAA,YACA,eAAA,GAAkB,eAAA,EAE5B,GAAA,EAAK,CAAA,EACL,MAAA,GAAS,CAAA,KACR,UAAA,QAAkB,aAAA,CAAgB,CAAA,EAAG,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withIntlayer.d.ts","names":[],"sources":["../../../src/server/withIntlayer.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"withIntlayer.d.ts","names":[],"sources":["../../../src/server/withIntlayer.ts"],"mappings":";;;;KAqQK,mBAAA,GAAsB,uBAAA;EACzB,eAAA;AAAA;;;;;AAcF;;;;;;;cAAa,gBAAA,aAA8B,OAAA,CAAQ,UAAA,GACjD,UAAA,GAAY,CAAA,EACZ,aAAA,GAAgB,mBAAA,KACf,UAAA,GAAa,CAAA;;;;;;;;;;;;;;;AA2KhB;cAAa,YAAA,aAAgC,OAAA,CAAQ,UAAA,GACnD,UAAA,GAAY,CAAA,GAAI,OAAA,CAAQ,CAAA,GACxB,aAAA,GAAgB,mBAAA,KACf,OAAA,CAAQ,UAAA,GAAa,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intlayer",
|
|
3
|
-
"version": "8.2.
|
|
3
|
+
"version": "8.2.3",
|
|
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": [
|
|
@@ -124,25 +124,25 @@
|
|
|
124
124
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
125
125
|
},
|
|
126
126
|
"dependencies": {
|
|
127
|
-
"@intlayer/chokidar": "8.2.
|
|
128
|
-
"@intlayer/config": "8.2.
|
|
129
|
-
"@intlayer/core": "8.2.
|
|
130
|
-
"@intlayer/dictionaries-entry": "8.2.
|
|
131
|
-
"@intlayer/types": "8.2.
|
|
132
|
-
"@intlayer/webpack": "8.2.
|
|
127
|
+
"@intlayer/chokidar": "8.2.3",
|
|
128
|
+
"@intlayer/config": "8.2.3",
|
|
129
|
+
"@intlayer/core": "8.2.3",
|
|
130
|
+
"@intlayer/dictionaries-entry": "8.2.3",
|
|
131
|
+
"@intlayer/types": "8.2.3",
|
|
132
|
+
"@intlayer/webpack": "8.2.3",
|
|
133
133
|
"defu": "6.1.4",
|
|
134
134
|
"node-loader": "2.1.0",
|
|
135
|
-
"react-intlayer": "8.2.
|
|
135
|
+
"react-intlayer": "8.2.3"
|
|
136
136
|
},
|
|
137
137
|
"devDependencies": {
|
|
138
|
-
"@types/node": "25.3.
|
|
138
|
+
"@types/node": "25.3.5",
|
|
139
139
|
"@types/react": ">=16.0.0",
|
|
140
140
|
"@types/react-dom": ">=16.0.0",
|
|
141
141
|
"@utils/ts-config": "1.0.4",
|
|
142
142
|
"@utils/ts-config-types": "1.0.4",
|
|
143
143
|
"@utils/tsdown-config": "1.0.4",
|
|
144
144
|
"rimraf": "6.1.3",
|
|
145
|
-
"tsdown": "0.
|
|
145
|
+
"tsdown": "0.21.0",
|
|
146
146
|
"typescript": "5.9.3",
|
|
147
147
|
"vitest": "4.0.18"
|
|
148
148
|
},
|