next-intlayer 7.2.1-canary.0 → 7.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/_virtual/rolldown_runtime.cjs +10 -6
- package/dist/cjs/client/IntlayerClientProvider.cjs +0 -1
- package/dist/cjs/client/IntlayerClientProvider.cjs.map +1 -1
- package/dist/cjs/client/useLocale.cjs +0 -1
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocalePageRouter.cjs +0 -1
- package/dist/cjs/client/useLocalePageRouter.cjs.map +1 -1
- package/dist/cjs/server/withIntlayer.cjs +19 -11
- package/dist/cjs/server/withIntlayer.cjs.map +1 -1
- package/dist/esm/client/IntlayerClientProvider.mjs +0 -1
- package/dist/esm/client/IntlayerClientProvider.mjs.map +1 -1
- package/dist/esm/client/useLocale.mjs +0 -1
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocalePageRouter.mjs +0 -1
- package/dist/esm/client/useLocalePageRouter.mjs.map +1 -1
- package/dist/esm/server/withIntlayer.mjs +19 -11
- package/dist/esm/server/withIntlayer.mjs.map +1 -1
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/server/withIntlayer.d.ts +1 -1
- package/dist/types/server/withIntlayer.d.ts.map +1 -1
- package/package.json +11 -11
|
@@ -6,12 +6,16 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
8
|
var __copyProps = (to, from, except, desc) => {
|
|
9
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
15
19
|
}
|
|
16
20
|
return to;
|
|
17
21
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerClientProvider.cjs","names":["IntlayerClientProvider: FC<IntlayerProviderProps>","useLocale","IntlayerProvider"],"sources":["../../../src/client/IntlayerClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\nimport { IntlayerProvider, type IntlayerProviderProps } from 'react-intlayer';\nimport { useLocale } from './useLocale';\n\nexport type IntlayerClientProviderProps = IntlayerProviderProps;\n\nexport const IntlayerClientProvider: FC<IntlayerProviderProps> = (props) => {\n const { setLocale } = useLocale();\n return <IntlayerProvider setLocale={setLocale} {...props} />;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"IntlayerClientProvider.cjs","names":["IntlayerClientProvider: FC<IntlayerProviderProps>","useLocale","IntlayerProvider"],"sources":["../../../src/client/IntlayerClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\nimport { IntlayerProvider, type IntlayerProviderProps } from 'react-intlayer';\nimport { useLocale } from './useLocale';\n\nexport type IntlayerClientProviderProps = IntlayerProviderProps;\n\nexport const IntlayerClientProvider: FC<IntlayerProviderProps> = (props) => {\n const { setLocale } = useLocale();\n return <IntlayerProvider setLocale={setLocale} {...props} />;\n};\n"],"mappings":";;;;;;;;AAQA,MAAaA,0BAAqD,UAAU;CAC1E,MAAM,EAAE,cAAcC,oCAAW;AACjC,QAAO,2CAACC;EAA4B;EAAW,GAAI;GAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.cjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { getLocalizedUrl, getPathWithoutLocale } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { usePathname, useRouter } from 'next/navigation.js';\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\ntype UseLocaleProps = {\n onChange?: 'replace' | 'push' | ((locale: LocalesValues) => void);\n};\n\nconst usePathWithoutLocale = () => {\n const pathname = usePathname(); // updates on client navigations\n const [fullPath, setFullPath] = useState(pathname);\n\n useEffect(() => {\n // Runs only on client; avoids suspense.\n const search = typeof window !== 'undefined' ? window.location.search : '';\n setFullPath(search ? `${pathname}${search}` : pathname);\n }, [pathname]);\n\n // Your own helper\n return useMemo(() => getPathWithoutLocale(fullPath), [fullPath]);\n};\n\nexport const useLocale = ({ onChange }: UseLocaleProps = {}) => {\n const { replace, push } = useRouter();\n const pathWithoutLocale = usePathWithoutLocale();\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n if (!onChange) return;\n\n if (typeof onChange === 'function') {\n onChange(locale);\n return;\n }\n\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n if (onChange === 'replace') {\n replace(pathWithLocale);\n }\n if (onChange === 'push') {\n push(pathWithLocale);\n }\n },\n [replace, push, pathWithoutLocale, onChange]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocale.cjs","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { getLocalizedUrl, getPathWithoutLocale } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { usePathname, useRouter } from 'next/navigation.js';\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\ntype UseLocaleProps = {\n onChange?: 'replace' | 'push' | ((locale: LocalesValues) => void);\n};\n\nconst usePathWithoutLocale = () => {\n const pathname = usePathname(); // updates on client navigations\n const [fullPath, setFullPath] = useState(pathname);\n\n useEffect(() => {\n // Runs only on client; avoids suspense.\n const search = typeof window !== 'undefined' ? window.location.search : '';\n setFullPath(search ? `${pathname}${search}` : pathname);\n }, [pathname]);\n\n // Your own helper\n return useMemo(() => getPathWithoutLocale(fullPath), [fullPath]);\n};\n\nexport const useLocale = ({ onChange }: UseLocaleProps = {}) => {\n const { replace, push } = useRouter();\n const pathWithoutLocale = usePathWithoutLocale();\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n if (!onChange) return;\n\n if (typeof onChange === 'function') {\n onChange(locale);\n return;\n }\n\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n if (onChange === 'replace') {\n replace(pathWithLocale);\n }\n if (onChange === 'push') {\n push(pathWithLocale);\n }\n },\n [replace, push, pathWithoutLocale, onChange]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":";;;;;;;;;AAYA,MAAM,6BAA6B;CACjC,MAAM,gDAAwB;CAC9B,MAAM,CAAC,UAAU,mCAAwB,SAAS;AAElD,4BAAgB;EAEd,MAAM,SAAS,OAAO,WAAW,cAAc,OAAO,SAAS,SAAS;AACxE,cAAY,SAAS,GAAG,WAAW,WAAW,SAAS;IACtD,CAAC,SAAS,CAAC;AAGd,2EAA0C,SAAS,EAAE,CAAC,SAAS,CAAC;;AAGlE,MAAa,aAAa,EAAE,aAA6B,EAAE,KAAK;CAC9D,MAAM,EAAE,SAAS,4CAAoB;CACrC,MAAM,oBAAoB,sBAAsB;AA2BhD,QAAO;EACL,iCALqC,EACrC,wCArBC,WAA0B;AACzB,OAAI,CAAC,SAAU;AAEf,OAAI,OAAO,aAAa,YAAY;AAClC,aAAS,OAAO;AAChB;;GAGF,MAAM,sDAAiC,mBAAmB,OAAO;AAEjE,OAAI,aAAa,UACf,SAAQ,eAAe;AAEzB,OAAI,aAAa,OACf,MAAK,eAAe;KAGxB;GAAC;GAAS;GAAM;GAAmB;GAAS,CAC7C,EAIA,CAAC;EAIA;EACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalePageRouter.cjs","names":[],"sources":["../../../src/client/useLocalePageRouter.ts"],"sourcesContent":["'use client';\n\nimport { getLocalizedUrl, getPathWithoutLocale } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { useRouter } from 'next/router.js';\nimport { useCallback, useMemo } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\nexport const useLocalePageRouter = () => {\n const { push, pathname, reload } = useRouter();\n const pathWithoutLocale = useMemo(\n () => getPathWithoutLocale(pathname),\n [pathname]\n );\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n push(pathWithLocale);\n\n return reload();\n },\n [pathWithoutLocale]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocalePageRouter.cjs","names":[],"sources":["../../../src/client/useLocalePageRouter.ts"],"sourcesContent":["'use client';\n\nimport { getLocalizedUrl, getPathWithoutLocale } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { useRouter } from 'next/router.js';\nimport { useCallback, useMemo } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\nexport const useLocalePageRouter = () => {\n const { push, pathname, reload } = useRouter();\n const pathWithoutLocale = useMemo(\n () => getPathWithoutLocale(pathname),\n [pathname]\n );\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n push(pathWithLocale);\n\n return reload();\n },\n [pathWithoutLocale]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":";;;;;;;;;AAQA,MAAa,4BAA4B;CACvC,MAAM,EAAE,MAAM,UAAU,0CAAsB;CAC9C,MAAM,uFACuB,SAAS,EACpC,CAAC,SAAS,CACX;AAiBD,QAAO;EACL,iCALqC,EACrC,wCAXC,WAA0B;AAGzB,6CAFuC,mBAAmB,OAAO,CAE7C;AAEpB,UAAO,QAAQ;KAEjB,CAAC,kBAAkB,CACpB,EAIA,CAAC;EAIA;EACD"}
|
|
@@ -30,30 +30,37 @@ const resolvePluginPath = (pluginPath, intlayerConfig, isTurbopackEnabled) => {
|
|
|
30
30
|
if (isTurbopackEnabled) return (0, __intlayer_config.normalizePath)(`./${(0, node_path.relative)(process.cwd(), pluginPathResolved)}`);
|
|
31
31
|
return pluginPathResolved;
|
|
32
32
|
};
|
|
33
|
-
const getPruneConfig = (intlayerConfig) => {
|
|
33
|
+
const getPruneConfig = (intlayerConfig, isBuildCommand, isTurbopackEnabled) => {
|
|
34
34
|
const { optimize, traversePattern, importMode } = intlayerConfig.build;
|
|
35
|
-
const { dictionariesDir, dynamicDictionariesDir, fetchDictionariesDir, mainDir, baseDir } = intlayerConfig.content;
|
|
36
|
-
|
|
35
|
+
const { dictionariesDir, unmergedDictionariesDir, dynamicDictionariesDir, fetchDictionariesDir, mainDir, baseDir } = intlayerConfig.content;
|
|
36
|
+
const logger = (0, __intlayer_config.getAppLogger)(intlayerConfig);
|
|
37
|
+
if (!(optimize ?? isBuildCommand)) return {};
|
|
37
38
|
if (!isGteNext13) return {};
|
|
38
39
|
if (!getIsSwcPluginAvailable(intlayerConfig)) return {};
|
|
39
|
-
|
|
40
|
-
(0, __intlayer_chokidar.runOnce)((0, node_path.join)(baseDir, ".intlayer", "cache", "intlayer-prune-plugin-enabled.lock"), () => logger("Intlayer prune plugin is enabled"), { cacheTimeoutMs: 1e3 * 10 });
|
|
40
|
+
(0, __intlayer_chokidar.runOnce)((0, node_path.join)(baseDir, ".intlayer", "cache", "intlayer-prune-plugin-enabled.lock"), () => logger("Build optimization enabled"), { cacheTimeoutMs: 1e3 * 10 });
|
|
41
41
|
const dictionariesEntryPath = (0, node_path.join)(mainDir, "dictionaries.mjs");
|
|
42
42
|
const dynamicDictionariesEntryPath = (0, node_path.join)(mainDir, "dynamic_dictionaries.mjs");
|
|
43
|
+
const unmergedDictionariesEntryPath = (0, node_path.join)(mainDir, "unmerged_dictionaries.mjs");
|
|
43
44
|
const fetchDictionariesEntryPath = (0, node_path.join)(mainDir, "fetch_dictionaries.mjs");
|
|
44
|
-
const filesList = [
|
|
45
|
+
const filesList = [
|
|
46
|
+
...fast_glob.default.sync(traversePattern, { cwd: baseDir }).map((file) => (0, node_path.join)(baseDir, file)),
|
|
47
|
+
dictionariesEntryPath,
|
|
48
|
+
unmergedDictionariesEntryPath
|
|
49
|
+
];
|
|
45
50
|
const dictionaries = (0, __intlayer_dictionaries_entry.getDictionaries)(intlayerConfig);
|
|
46
51
|
const liveSyncKeys = Object.values(dictionaries).filter((dictionary) => dictionary.live).map((dictionary) => dictionary.key);
|
|
47
|
-
return { experimental: { swcPlugins: [[resolvePluginPath("@intlayer/swc", intlayerConfig), {
|
|
52
|
+
return { experimental: { swcPlugins: [[resolvePluginPath("@intlayer/swc", intlayerConfig, isTurbopackEnabled), {
|
|
48
53
|
dictionariesDir,
|
|
49
54
|
dictionariesEntryPath,
|
|
55
|
+
unmergedDictionariesEntryPath,
|
|
56
|
+
unmergedDictionariesDir,
|
|
50
57
|
dynamicDictionariesDir,
|
|
51
58
|
dynamicDictionariesEntryPath,
|
|
52
59
|
fetchDictionariesDir,
|
|
53
60
|
fetchDictionariesEntryPath,
|
|
54
61
|
importMode,
|
|
55
62
|
filesList,
|
|
56
|
-
replaceDictionaryEntry:
|
|
63
|
+
replaceDictionaryEntry: true,
|
|
57
64
|
liveSyncKeys
|
|
58
65
|
}]] } };
|
|
59
66
|
};
|
|
@@ -80,7 +87,9 @@ const getCommandsEvent = () => {
|
|
|
80
87
|
const withIntlayerSync = (nextConfig = {}, configOptions) => {
|
|
81
88
|
if (typeof nextConfig !== "object") nextConfig = {};
|
|
82
89
|
const intlayerConfig = (0, __intlayer_config.getConfiguration)(configOptions);
|
|
90
|
+
const logger = (0, __intlayer_config.getAppLogger)(intlayerConfig);
|
|
83
91
|
const isTurbopackEnabled = configOptions?.enableTurbopack ?? isTurbopackEnabledFromCommand;
|
|
92
|
+
if (isTurbopackEnabled && typeof nextConfig.webpack !== "undefined") logger("Turbopack is enabled but a custom webpack config is present. It will be ignored.");
|
|
84
93
|
const { isBuildCommand, isDevCommand } = getCommandsEvent();
|
|
85
94
|
const turboConfig = {
|
|
86
95
|
resolveAlias: (0, __intlayer_config.getAlias)({
|
|
@@ -128,6 +137,7 @@ const withIntlayerSync = (nextConfig = {}, configOptions) => {
|
|
|
128
137
|
webpack: (config$1, options) => {
|
|
129
138
|
const { isServer, nextRuntime } = options;
|
|
130
139
|
if (typeof nextConfig.webpack === "function") config$1 = nextConfig.webpack(config$1, options);
|
|
140
|
+
if (config$1.externals === false) config$1.externals = [];
|
|
131
141
|
config$1.externals.push({
|
|
132
142
|
esbuild: "esbuild",
|
|
133
143
|
module: "module",
|
|
@@ -152,9 +162,7 @@ const withIntlayerSync = (nextConfig = {}, configOptions) => {
|
|
|
152
162
|
};
|
|
153
163
|
return config;
|
|
154
164
|
};
|
|
155
|
-
|
|
156
|
-
if (isBuildCommand) pruneConfig = getPruneConfig(intlayerConfig);
|
|
157
|
-
const intlayerNextConfig = (0, deepmerge.default)(pruneConfig, getNewConfig());
|
|
165
|
+
const intlayerNextConfig = (0, deepmerge.default)(getPruneConfig(intlayerConfig, isBuildCommand, isTurbopackEnabled ?? false), getNewConfig());
|
|
158
166
|
return (0, deepmerge.default)(nextConfig, intlayerNextConfig);
|
|
159
167
|
};
|
|
160
168
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withIntlayer.cjs","names":["nextPackageJSON","fg","config: Partial<NextConfig>","config","IntlayerPlugin","pruneConfig: Partial<NextConfig>","intlayerNextConfig: Partial<NextConfig>"],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { join, relative, resolve } from 'node:path';\nimport { prepareIntlayer, runOnce } from '@intlayer/chokidar';\nimport {\n compareVersions,\n type GetConfigurationOptions,\n getAlias,\n getAppLogger,\n getConfiguration,\n getProjectRequire,\n normalizePath,\n} from '@intlayer/config';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { IntlayerPlugin } from '@intlayer/webpack';\nimport merge from 'deepmerge';\nimport fg from 'fast-glob';\nimport type { NextConfig } from 'next';\nimport type { NextJsWebpackConfig } from 'next/dist/server/config-shared';\nimport nextPackageJSON from 'next/package.json' with { type: 'json' };\n\nconst isGteNext13 = compareVersions(nextPackageJSON.version, '≥', '13.0.0');\nconst isGteNext15 = compareVersions(nextPackageJSON.version, '≥', '15.0.0');\nconst isGteNext16 = compareVersions(nextPackageJSON.version, '≥', '16.0.0');\nconst isTurbopackStable = compareVersions(\n nextPackageJSON.version,\n '≥',\n '15.3.0'\n);\n\nconst isTurbopackEnabledFromCommand = isGteNext16\n ? // Next@16 enable turbopack by default, and offer the possibility to disable it if --webpack flag is used\n !process.env.npm_lifecycle_script?.includes('--webpack')\n : // Next@15 use --turbopack flag, Next@14 use --turbo flag\n process.env.npm_lifecycle_script?.includes('--turbo');\n\n// Check if SWC plugin is available\nconst getIsSwcPluginAvailable = (intlayerConfig: IntlayerConfig) => {\n try {\n const requireFunction =\n intlayerConfig.build?.require ?? getProjectRequire();\n requireFunction.resolve('@intlayer/swc');\n return true;\n } catch (_e) {\n return false;\n }\n};\n\nconst resolvePluginPath = (\n pluginPath: string,\n intlayerConfig: IntlayerConfig,\n isTurbopackEnabled: boolean\n): string => {\n const requireFunction = intlayerConfig.build?.require ?? getProjectRequire();\n const pluginPathResolved = requireFunction?.resolve(pluginPath);\n\n if (isTurbopackEnabled)\n // Relative path for turbopack\n return normalizePath(`./${relative(process.cwd(), pluginPathResolved)}`);\n\n // Absolute path for webpack\n return pluginPathResolved;\n};\n\nconst getPruneConfig = (\n intlayerConfig: IntlayerConfig\n): Partial<NextConfig> => {\n const { optimize, traversePattern, importMode } = intlayerConfig.build;\n const {\n dictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n baseDir,\n } = intlayerConfig.content;\n\n if (!optimize) return {};\n\n if (!isGteNext13) return {};\n\n const isSwcPluginAvailable = getIsSwcPluginAvailable(intlayerConfig);\n\n if (!isSwcPluginAvailable) return {};\n\n const logger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(baseDir, '.intlayer', 'cache', 'intlayer-prune-plugin-enabled.lock'),\n () => logger('Intlayer prune plugin is enabled'),\n {\n cacheTimeoutMs: 1000 * 10, // 10 seconds\n }\n );\n\n const dictionariesEntryPath = join(mainDir, 'dictionaries.mjs');\n\n const dynamicDictionariesEntryPath = join(\n mainDir,\n 'dynamic_dictionaries.mjs'\n );\n\n const fetchDictionariesEntryPath = join(mainDir, 'fetch_dictionaries.mjs');\n\n const filesListPattern = fg\n .sync(traversePattern, {\n cwd: baseDir,\n })\n .map((file) => join(baseDir, file));\n\n const filesList = [\n ...filesListPattern,\n dictionariesEntryPath, // should add dictionariesEntryPath to replace it by a empty object if import made dynamic\n ];\n\n const dictionaries = getDictionaries(intlayerConfig);\n\n const liveSyncKeys = Object.values(dictionaries)\n .filter((dictionary) => dictionary.live)\n .map((dictionary) => dictionary.key);\n\n return {\n experimental: {\n swcPlugins: [\n [\n resolvePluginPath('@intlayer/swc', intlayerConfig),\n {\n dictionariesDir,\n dictionariesEntryPath,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n fetchDictionariesDir,\n fetchDictionariesEntryPath,\n importMode,\n filesList,\n replaceDictionaryEntry: false,\n liveSyncKeys,\n } as any,\n ],\n ],\n },\n };\n};\n\nconst getCommandsEvent = () => {\n const lifecycleEvent = process.env.npm_lifecycle_event;\n const lifecycleScript = process.env.npm_lifecycle_script ?? '';\n\n const isDevCommand =\n lifecycleEvent === 'dev' ||\n process.argv.some((arg) => arg === 'dev') ||\n /(^|\\s)(next\\s+)?dev(\\s|$)/.test(lifecycleScript);\n\n const isBuildCommand =\n lifecycleEvent === 'build' ||\n process.argv.some((arg) => arg === 'build') ||\n /(^|\\s)(next\\s+)?build(\\s|$)/.test(lifecycleScript);\n\n const isStartCommand =\n lifecycleEvent === 'start' ||\n process.argv.some((arg) => arg === 'start') ||\n /(^|\\s)(next\\s+)?start(\\s|$)/.test(lifecycleScript);\n\n return {\n isDevCommand,\n isBuildCommand,\n isStartCommand,\n };\n};\n\ntype WebpackParams = Parameters<NextJsWebpackConfig>;\n\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 const isTurbopackEnabled =\n configOptions?.enableTurbopack ?? isTurbopackEnabledFromCommand;\n\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n\n // Only provide turbo-specific config if user explicitly sets it\n const turboConfig = {\n resolveAlias: getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => `./${value}`, // prefix by './' to consider the path as relative to the project root. This is necessary for turbopack to work correctly.\n }),\n\n rules: {\n '*.node': {\n as: '*.node',\n loaders: ['node-loader'],\n },\n },\n };\n\n const serverExternalPackages = [\n 'esbuild',\n 'module',\n 'fs',\n 'chokidar',\n 'fsevents',\n ];\n\n const getNewConfig = (): Partial<NextConfig> => {\n let config: Partial<NextConfig> = {};\n\n if (isGteNext15) {\n config = {\n ...config,\n serverExternalPackages,\n };\n }\n\n if (isGteNext13 && !isGteNext15) {\n config = {\n ...config,\n experimental: {\n ...(config?.experimental ?? {}),\n serverComponentsExternalPackages: serverExternalPackages,\n },\n };\n }\n\n if (isTurbopackEnabled) {\n if (isGteNext15 && isTurbopackStable) {\n config = {\n ...config,\n turbopack: turboConfig,\n };\n } else {\n config = {\n ...config,\n experimental: {\n ...(config?.experimental ?? {}),\n // @ts-ignore exist in next@14\n turbo: turboConfig,\n },\n };\n }\n } else {\n config = {\n ...config,\n webpack: (config: WebpackParams['0'], options: WebpackParams[1]) => {\n // Only add Intlayer plugin on server side (node runtime)\n const { isServer, nextRuntime } = options;\n\n // If the user has defined their own webpack config, call it\n if (typeof nextConfig.webpack === 'function') {\n config = nextConfig.webpack(config, options);\n }\n\n // Mark these modules as externals\n config.externals.push({\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n chokidar: 'chokidar',\n fsevents: 'fsevents',\n });\n\n // Use `node-loader` for any `.node` files\n config.module.rules.push({\n test: /\\.node$/,\n loader: 'node-loader',\n });\n\n // Always alias on the server (node/edge) for stability.\n // On the client, alias only when not using live sync.\n config.resolve.alias = {\n ...config.resolve.alias,\n ...getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => resolve(value), // get absolute path\n }),\n };\n\n // Activate watch mode webpack plugin\n if (isDevCommand && isServer && nextRuntime === 'nodejs') {\n config.plugins.push(new IntlayerPlugin(intlayerConfig));\n }\n\n return config;\n },\n };\n }\n\n return config;\n };\n\n let pruneConfig: Partial<NextConfig> = {};\n\n if (isBuildCommand) {\n pruneConfig = getPruneConfig(intlayerConfig);\n }\n\n const intlayerNextConfig: Partial<NextConfig> = merge(\n pruneConfig,\n getNewConfig()\n );\n\n // Merge the new config with the user's config\n const result = merge(nextConfig, intlayerNextConfig) as NextConfig & T;\n\n return result;\n};\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayer(nextConfig)\n * ```\n *\n * > Node withIntlayer is a promise function. Use withIntlayerSync instead if you want to use it synchronously.\n * > Using the promise allows to prepare the intlayer dictionaries before the build starts.\n *\n */\nexport const withIntlayer = async <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T,\n configOptions?: GetConfigurationOptions\n): Promise<NextConfig & T> => {\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n\n // Only call prepareIntlayer during `dev` or `build` (not during `start`)\n // If prod: clean and rebuild once\n // If dev: rebuild only once if it's more than 1 hour since last rebuild\n if (isDevCommand || isBuildCommand) {\n const intlayerConfig = getConfiguration(configOptions);\n\n // prepareIntlayer use runOnce to ensure to run only once because will run twice on client and server side otherwise\n await prepareIntlayer(intlayerConfig, {\n clean: isBuildCommand,\n cacheTimeoutMs: isBuildCommand\n ? 1000 * 30 // 30 seconds for build (to ensure to rebuild all dictionaries)\n : 1000 * 60 * 60, // 1 hour for dev (default cache timeout)\n });\n }\n\n return withIntlayerSync(nextConfig, configOptions);\n};\n"],"mappings":";;;;;;;;;;;;;;AAoBA,MAAM,qDAA8BA,0BAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,qDAA8BA,0BAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,qDAA8BA,0BAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,2DACJA,0BAAgB,SAChB,KACA,SACD;AAED,MAAM,gCAAgC,cAElC,CAAC,QAAQ,IAAI,sBAAsB,SAAS,YAAY,GAExD,QAAQ,IAAI,sBAAsB,SAAS,UAAU;AAGzD,MAAM,2BAA2B,mBAAmC;AAClE,KAAI;AAGF,GADE,eAAe,OAAO,qDAA8B,EACtC,QAAQ,gBAAgB;AACxC,SAAO;UACA,IAAI;AACX,SAAO;;;AAIX,MAAM,qBACJ,YACA,gBACA,uBACW;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AAC;AAGF,aAAO,OAAO,MAAM,KAAK;KACvB,MAAM;KACN,QAAQ;KACT,CAAC;AAIF,aAAO,QAAQ,QAAQ;KACrB,GAAGA,SAAO,QAAQ;KAClB,mCAAY;MACV,eAAe;MACf,YAAY,iCAA0B,MAAM;MAC7C,CAAC;KACH;AAGD,QAAI,gBAAgB,YAAY,gBAAgB,SAC9C,UAAO,QAAQ,KAAK,IAAIC,kCAAe,eAAe,CAAC;AAGzD,WAAOD;;GAEV;AAGH,SAAO;;CAGT,IAAIE,cAAmC,EAAE;AAEzC,KAAI,eACF,eAAc,eAAe,eAAe;CAG9C,MAAMC,4CACJ,aACA,cAAc,CACf;AAKD,+BAFqB,YAAY,mBAAmB;;;;;;;;;;;;;;;;;AAoBtD,MAAa,eAAe,OAC1B,aAAgB,EAAE,EAClB,kBAC4B;CAC5B,MAAM,EAAE,gBAAgB,iBAAiB,kBAAkB;AAK3D,KAAI,gBAAgB,eAIlB,wFAHwC,cAAc,EAGhB;EACpC,OAAO;EACP,gBAAgB,iBACZ,MAAO,KACP,MAAO,KAAK;EACjB,CAAC;AAGJ,QAAO,iBAAiB,YAAY,cAAc"}
|
|
1
|
+
{"version":3,"file":"withIntlayer.cjs","names":["nextPackageJSON","fg","config: Partial<NextConfig>","config","IntlayerPlugin","intlayerNextConfig: Partial<NextConfig>"],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { join, relative, resolve } from 'node:path';\nimport { prepareIntlayer, runOnce } from '@intlayer/chokidar';\nimport {\n compareVersions,\n type GetConfigurationOptions,\n getAlias,\n getAppLogger,\n getConfiguration,\n getProjectRequire,\n normalizePath,\n} from '@intlayer/config';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { IntlayerPlugin } from '@intlayer/webpack';\nimport merge from 'deepmerge';\nimport fg from 'fast-glob';\nimport type { NextConfig } from 'next';\nimport type { NextJsWebpackConfig } from 'next/dist/server/config-shared';\nimport nextPackageJSON from 'next/package.json' with { type: 'json' };\n\nconst isGteNext13 = compareVersions(nextPackageJSON.version, '≥', '13.0.0');\nconst isGteNext15 = compareVersions(nextPackageJSON.version, '≥', '15.0.0');\nconst isGteNext16 = compareVersions(nextPackageJSON.version, '≥', '16.0.0');\nconst isTurbopackStable = compareVersions(\n nextPackageJSON.version,\n '≥',\n '15.3.0'\n);\n\nconst isTurbopackEnabledFromCommand = isGteNext16\n ? // Next@16 enable turbopack by default, and offer the possibility to disable it if --webpack flag is used\n !process.env.npm_lifecycle_script?.includes('--webpack')\n : // Next@15 use --turbopack flag, Next@14 use --turbo flag\n process.env.npm_lifecycle_script?.includes('--turbo');\n\n// Check if SWC plugin is available\nconst getIsSwcPluginAvailable = (intlayerConfig: IntlayerConfig) => {\n try {\n const requireFunction =\n intlayerConfig.build?.require ?? getProjectRequire();\n requireFunction.resolve('@intlayer/swc');\n return true;\n } catch (_e) {\n return false;\n }\n};\n\nconst resolvePluginPath = (\n pluginPath: string,\n intlayerConfig: IntlayerConfig,\n isTurbopackEnabled: boolean\n): string => {\n const requireFunction = intlayerConfig.build?.require ?? getProjectRequire();\n const pluginPathResolved = requireFunction?.resolve(pluginPath);\n\n if (isTurbopackEnabled)\n // Relative path for turbopack\n return normalizePath(`./${relative(process.cwd(), pluginPathResolved)}`);\n\n // Absolute path for webpack\n return pluginPathResolved;\n};\n\nconst getPruneConfig = (\n intlayerConfig: IntlayerConfig,\n isBuildCommand: boolean,\n isTurbopackEnabled: boolean\n): Partial<NextConfig> => {\n const { optimize, traversePattern, importMode } = intlayerConfig.build;\n const {\n dictionariesDir,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n baseDir,\n } = intlayerConfig.content;\n const logger = getAppLogger(intlayerConfig);\n\n if (!(optimize ?? isBuildCommand)) {\n return {};\n }\n\n if (!isGteNext13) return {};\n\n const isSwcPluginAvailable = getIsSwcPluginAvailable(intlayerConfig);\n\n if (!isSwcPluginAvailable) return {};\n\n runOnce(\n join(baseDir, '.intlayer', 'cache', 'intlayer-prune-plugin-enabled.lock'),\n () => logger('Build optimization enabled'),\n {\n cacheTimeoutMs: 1000 * 10, // 10 seconds\n }\n );\n\n const dictionariesEntryPath = join(mainDir, 'dictionaries.mjs');\n\n const dynamicDictionariesEntryPath = join(\n mainDir,\n 'dynamic_dictionaries.mjs'\n );\n\n const unmergedDictionariesEntryPath = join(\n mainDir,\n 'unmerged_dictionaries.mjs'\n );\n\n const fetchDictionariesEntryPath = join(mainDir, 'fetch_dictionaries.mjs');\n\n const filesListPattern = fg\n .sync(traversePattern, {\n cwd: baseDir,\n })\n .map((file) => join(baseDir, file));\n\n const filesList = [\n ...filesListPattern,\n dictionariesEntryPath, // should add dictionariesEntryPath to replace it by a empty object if import made dynamic\n unmergedDictionariesEntryPath, // should add dictionariesEntryPath to replace it by a empty object if import made dynamic\n ];\n\n const dictionaries = getDictionaries(intlayerConfig);\n\n const liveSyncKeys = Object.values(dictionaries)\n .filter((dictionary) => dictionary.live)\n .map((dictionary) => dictionary.key);\n\n return {\n experimental: {\n swcPlugins: [\n [\n resolvePluginPath(\n '@intlayer/swc',\n intlayerConfig,\n isTurbopackEnabled\n ),\n {\n dictionariesDir,\n dictionariesEntryPath,\n unmergedDictionariesEntryPath,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n fetchDictionariesDir,\n fetchDictionariesEntryPath,\n importMode,\n filesList,\n replaceDictionaryEntry: true,\n liveSyncKeys,\n } as any,\n ],\n ],\n },\n };\n};\n\nconst getCommandsEvent = () => {\n const lifecycleEvent = process.env.npm_lifecycle_event;\n const lifecycleScript = process.env.npm_lifecycle_script ?? '';\n\n const isDevCommand =\n lifecycleEvent === 'dev' ||\n process.argv.some((arg) => arg === 'dev') ||\n /(^|\\s)(next\\s+)?dev(\\s|$)/.test(lifecycleScript);\n\n const isBuildCommand =\n lifecycleEvent === 'build' ||\n process.argv.some((arg) => arg === 'build') ||\n /(^|\\s)(next\\s+)?build(\\s|$)/.test(lifecycleScript);\n\n const isStartCommand =\n lifecycleEvent === 'start' ||\n process.argv.some((arg) => arg === 'start') ||\n /(^|\\s)(next\\s+)?start(\\s|$)/.test(lifecycleScript);\n\n return {\n isDevCommand,\n isBuildCommand,\n isStartCommand,\n };\n};\n\ntype WebpackParams = Parameters<NextJsWebpackConfig>;\n\ntype WithIntlayerOptions = GetConfigurationOptions & {\n enableTurbopack?: boolean;\n};\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayerSync(nextConfig)\n * ```\n */\nexport const withIntlayerSync = <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T,\n configOptions?: WithIntlayerOptions\n): NextConfig & T => {\n if (typeof nextConfig !== 'object') {\n nextConfig = {} as T;\n }\n\n const intlayerConfig = getConfiguration(configOptions);\n const logger = getAppLogger(intlayerConfig);\n\n const isTurbopackEnabled =\n configOptions?.enableTurbopack ?? isTurbopackEnabledFromCommand;\n\n if (isTurbopackEnabled && typeof nextConfig.webpack !== 'undefined') {\n logger(\n 'Turbopack is enabled but a custom webpack config is present. It will be ignored.'\n );\n }\n\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n\n // Only provide turbo-specific config if user explicitly sets it\n const turboConfig = {\n resolveAlias: getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => `./${value}`, // prefix by './' to consider the path as relative to the project root. This is necessary for turbopack to work correctly.\n }),\n\n rules: {\n '*.node': {\n as: '*.node',\n loaders: ['node-loader'],\n },\n },\n };\n\n const serverExternalPackages = [\n 'esbuild',\n 'module',\n 'fs',\n 'chokidar',\n 'fsevents',\n ];\n\n const getNewConfig = (): Partial<NextConfig> => {\n let config: Partial<NextConfig> = {};\n\n if (isGteNext15) {\n config = {\n ...config,\n serverExternalPackages,\n };\n }\n\n if (isGteNext13 && !isGteNext15) {\n config = {\n ...config,\n experimental: {\n ...(config?.experimental ?? {}),\n serverComponentsExternalPackages: serverExternalPackages,\n },\n };\n }\n\n if (isTurbopackEnabled) {\n if (isGteNext15 && isTurbopackStable) {\n config = {\n ...config,\n turbopack: turboConfig,\n };\n } else {\n config = {\n ...config,\n experimental: {\n ...(config?.experimental ?? {}),\n // @ts-ignore exist in next@14\n turbo: turboConfig,\n },\n };\n }\n } else {\n config = {\n ...config,\n webpack: (config: WebpackParams['0'], options: WebpackParams[1]) => {\n // Only add Intlayer plugin on server side (node runtime)\n const { isServer, nextRuntime } = options;\n\n // If the user has defined their own webpack config, call it\n if (typeof nextConfig.webpack === 'function') {\n config = nextConfig.webpack(config, options);\n }\n\n // Rspack set external as false by default\n // Overwrite it to allow pushing the desired externals\n if (config.externals === false) {\n config.externals = [];\n }\n\n // Mark these modules as externals\n config.externals.push({\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n chokidar: 'chokidar',\n fsevents: 'fsevents',\n });\n\n // Use `node-loader` for any `.node` files\n config.module.rules.push({\n test: /\\.node$/,\n loader: 'node-loader',\n });\n\n // Always alias on the server (node/edge) for stability.\n // On the client, alias only when not using live sync.\n config.resolve.alias = {\n ...config.resolve.alias,\n ...getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => resolve(value), // get absolute path\n }),\n };\n\n // Activate watch mode webpack plugin\n if (isDevCommand && isServer && nextRuntime === 'nodejs') {\n // Optional as rspack not support plugin yet\n config.plugins.push(new IntlayerPlugin(intlayerConfig));\n }\n\n return config;\n },\n };\n }\n\n return config;\n };\n\n const pruneConfig: Partial<NextConfig> = getPruneConfig(\n intlayerConfig,\n isBuildCommand,\n isTurbopackEnabled ?? false\n );\n\n const intlayerNextConfig: Partial<NextConfig> = merge(\n pruneConfig,\n getNewConfig()\n );\n\n // Merge the new config with the user's config\n const result = merge(nextConfig, intlayerNextConfig) as NextConfig & T;\n\n return result;\n};\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayer(nextConfig)\n * ```\n *\n * > Node withIntlayer is a promise function. Use withIntlayerSync instead if you want to use it synchronously.\n * > Using the promise allows to prepare the intlayer dictionaries before the build starts.\n *\n */\nexport const withIntlayer = async <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T,\n configOptions?: WithIntlayerOptions\n): Promise<NextConfig & T> => {\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n\n // Only call prepareIntlayer during `dev` or `build` (not during `start`)\n // If prod: clean and rebuild once\n // If dev: rebuild only once if it's more than 1 hour since last rebuild\n if (isDevCommand || isBuildCommand) {\n const intlayerConfig = getConfiguration(configOptions);\n\n // prepareIntlayer use runOnce to ensure to run only once because will run twice on client and server side otherwise\n await prepareIntlayer(intlayerConfig, {\n clean: isBuildCommand,\n cacheTimeoutMs: isBuildCommand\n ? 1000 * 30 // 30 seconds for build (to ensure to rebuild all dictionaries)\n : 1000 * 60 * 60, // 1 hour for dev (default cache timeout)\n });\n }\n\n return withIntlayerSync(nextConfig, configOptions);\n};\n"],"mappings":";;;;;;;;;;;;;;AAoBA,MAAM,qDAA8BA,0BAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,qDAA8BA,0BAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,qDAA8BA,0BAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,2DACJA,0BAAgB,SAChB,KACA,SACD;AAED,MAAM,gCAAgC,cAElC,CAAC,QAAQ,IAAI,sBAAsB,SAAS,YAAY,GAExD,QAAQ,IAAI,sBAAsB,SAAS,UAAU;AAGzD,MAAM,2BAA2B,mBAAmC;AAClE,KAAI;AAGF,GADE,eAAe,OAAO,qDAA8B,EACtC,QAAQ,gBAAgB;AACxC,SAAO;UACA,IAAI;AACX,SAAO;;;AAIX,MAAM,qBACJ,YACA,gBACA,uBACW;CAEX,MAAM,sBADkB,eAAe,OAAO,qDAA8B,GAChC,QAAQ,WAAW;AAE/D,KAAI,mBAEF,6CAAqB,6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vB,UAAO,YAAY,EAAE;AAIvB,aAAO,UAAU,KAAK;KACpB,SAAS;KACT,QAAQ;KACR,IAAI;KACJ,UAAU;KACV,UAAU;KACX,CAAC;AAGF,aAAO,OAAO,MAAM,KAAK;KACvB,MAAM;KACN,QAAQ;KACT,CAAC;AAIF,aAAO,QAAQ,QAAQ;KACrB,GAAGA,SAAO,QAAQ;KAClB,mCAAY;MACV,eAAe;MACf,YAAY,iCAA0B,MAAM;MAC7C,CAAC;KACH;AAGD,QAAI,gBAAgB,YAAY,gBAAgB,SAE9C,UAAO,QAAQ,KAAK,IAAIC,kCAAe,eAAe,CAAC;AAGzD,WAAOD;;GAEV;AAGH,SAAO;;CAST,MAAME,4CANmC,eACvC,gBACA,gBACA,sBAAsB,MACvB,EAIC,cAAc,CACf;AAKD,+BAFqB,YAAY,mBAAmB;;;;;;;;;;;;;;;;;AAoBtD,MAAa,eAAe,OAC1B,aAAgB,EAAE,EAClB,kBAC4B;CAC5B,MAAM,EAAE,gBAAgB,iBAAiB,kBAAkB;AAK3D,KAAI,gBAAgB,eAIlB,wFAHwC,cAAc,EAGhB;EACpC,OAAO;EACP,gBAAgB,iBACZ,MAAO,KACP,MAAO,KAAK;EACjB,CAAC;AAGJ,QAAO,iBAAiB,YAAY,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"IntlayerClientProvider.mjs","names":["IntlayerClientProvider: FC<IntlayerProviderProps>","useLocale"],"sources":["../../../src/client/IntlayerClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\nimport { IntlayerProvider, type IntlayerProviderProps } from 'react-intlayer';\nimport { useLocale } from './useLocale';\n\nexport type IntlayerClientProviderProps = IntlayerProviderProps;\n\nexport const IntlayerClientProvider: FC<IntlayerProviderProps> = (props) => {\n const { setLocale } = useLocale();\n return <IntlayerProvider setLocale={setLocale} {...props} />;\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"IntlayerClientProvider.mjs","names":["IntlayerClientProvider: FC<IntlayerProviderProps>","useLocale"],"sources":["../../../src/client/IntlayerClientProvider.tsx"],"sourcesContent":["'use client';\n\nimport type { FC } from 'react';\nimport { IntlayerProvider, type IntlayerProviderProps } from 'react-intlayer';\nimport { useLocale } from './useLocale';\n\nexport type IntlayerClientProviderProps = IntlayerProviderProps;\n\nexport const IntlayerClientProvider: FC<IntlayerProviderProps> = (props) => {\n const { setLocale } = useLocale();\n return <IntlayerProvider setLocale={setLocale} {...props} />;\n};\n"],"mappings":";;;;;;;AAQA,MAAaA,0BAAqD,UAAU;CAC1E,MAAM,EAAE,cAAcC,aAAW;AACjC,QAAO,oBAAC;EAA4B;EAAW,GAAI;GAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.mjs","names":["useLocaleReact"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { getLocalizedUrl, getPathWithoutLocale } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { usePathname, useRouter } from 'next/navigation.js';\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\ntype UseLocaleProps = {\n onChange?: 'replace' | 'push' | ((locale: LocalesValues) => void);\n};\n\nconst usePathWithoutLocale = () => {\n const pathname = usePathname(); // updates on client navigations\n const [fullPath, setFullPath] = useState(pathname);\n\n useEffect(() => {\n // Runs only on client; avoids suspense.\n const search = typeof window !== 'undefined' ? window.location.search : '';\n setFullPath(search ? `${pathname}${search}` : pathname);\n }, [pathname]);\n\n // Your own helper\n return useMemo(() => getPathWithoutLocale(fullPath), [fullPath]);\n};\n\nexport const useLocale = ({ onChange }: UseLocaleProps = {}) => {\n const { replace, push } = useRouter();\n const pathWithoutLocale = usePathWithoutLocale();\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n if (!onChange) return;\n\n if (typeof onChange === 'function') {\n onChange(locale);\n return;\n }\n\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n if (onChange === 'replace') {\n replace(pathWithLocale);\n }\n if (onChange === 'push') {\n push(pathWithLocale);\n }\n },\n [replace, push, pathWithoutLocale, onChange]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocale.mjs","names":["useLocaleReact"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport { getLocalizedUrl, getPathWithoutLocale } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { usePathname, useRouter } from 'next/navigation.js';\nimport { useCallback, useEffect, useMemo, useState } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\ntype UseLocaleProps = {\n onChange?: 'replace' | 'push' | ((locale: LocalesValues) => void);\n};\n\nconst usePathWithoutLocale = () => {\n const pathname = usePathname(); // updates on client navigations\n const [fullPath, setFullPath] = useState(pathname);\n\n useEffect(() => {\n // Runs only on client; avoids suspense.\n const search = typeof window !== 'undefined' ? window.location.search : '';\n setFullPath(search ? `${pathname}${search}` : pathname);\n }, [pathname]);\n\n // Your own helper\n return useMemo(() => getPathWithoutLocale(fullPath), [fullPath]);\n};\n\nexport const useLocale = ({ onChange }: UseLocaleProps = {}) => {\n const { replace, push } = useRouter();\n const pathWithoutLocale = usePathWithoutLocale();\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n if (!onChange) return;\n\n if (typeof onChange === 'function') {\n onChange(locale);\n return;\n }\n\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n if (onChange === 'replace') {\n replace(pathWithLocale);\n }\n if (onChange === 'push') {\n push(pathWithLocale);\n }\n },\n [replace, push, pathWithoutLocale, onChange]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":";;;;;;;;AAYA,MAAM,6BAA6B;CACjC,MAAM,WAAW,aAAa;CAC9B,MAAM,CAAC,UAAU,eAAe,SAAS,SAAS;AAElD,iBAAgB;EAEd,MAAM,SAAS,OAAO,WAAW,cAAc,OAAO,SAAS,SAAS;AACxE,cAAY,SAAS,GAAG,WAAW,WAAW,SAAS;IACtD,CAAC,SAAS,CAAC;AAGd,QAAO,cAAc,qBAAqB,SAAS,EAAE,CAAC,SAAS,CAAC;;AAGlE,MAAa,aAAa,EAAE,aAA6B,EAAE,KAAK;CAC9D,MAAM,EAAE,SAAS,SAAS,WAAW;CACrC,MAAM,oBAAoB,sBAAsB;AA2BhD,QAAO;EACL,GALsBA,YAAe,EACrC,gBAtB0B,aACzB,WAA0B;AACzB,OAAI,CAAC,SAAU;AAEf,OAAI,OAAO,aAAa,YAAY;AAClC,aAAS,OAAO;AAChB;;GAGF,MAAM,iBAAiB,gBAAgB,mBAAmB,OAAO;AAEjE,OAAI,aAAa,UACf,SAAQ,eAAe;AAEzB,OAAI,aAAa,OACf,MAAK,eAAe;KAGxB;GAAC;GAAS;GAAM;GAAmB;GAAS,CAC7C,EAIA,CAAC;EAIA;EACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalePageRouter.mjs","names":["useLocaleReact"],"sources":["../../../src/client/useLocalePageRouter.ts"],"sourcesContent":["'use client';\n\nimport { getLocalizedUrl, getPathWithoutLocale } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { useRouter } from 'next/router.js';\nimport { useCallback, useMemo } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\nexport const useLocalePageRouter = () => {\n const { push, pathname, reload } = useRouter();\n const pathWithoutLocale = useMemo(\n () => getPathWithoutLocale(pathname),\n [pathname]\n );\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n push(pathWithLocale);\n\n return reload();\n },\n [pathWithoutLocale]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"useLocalePageRouter.mjs","names":["useLocaleReact"],"sources":["../../../src/client/useLocalePageRouter.ts"],"sourcesContent":["'use client';\n\nimport { getLocalizedUrl, getPathWithoutLocale } from '@intlayer/core';\nimport type { LocalesValues } from '@intlayer/types';\nimport { useRouter } from 'next/router.js';\nimport { useCallback, useMemo } from 'react';\nimport { useLocale as useLocaleReact } from 'react-intlayer';\n\nexport const useLocalePageRouter = () => {\n const { push, pathname, reload } = useRouter();\n const pathWithoutLocale = useMemo(\n () => getPathWithoutLocale(pathname),\n [pathname]\n );\n\n const redirectionFunction = useCallback(\n (locale: LocalesValues) => {\n const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);\n\n push(pathWithLocale);\n\n return reload();\n },\n [pathWithoutLocale]\n );\n\n const reactLocaleHook = useLocaleReact({\n onLocaleChange: redirectionFunction,\n });\n\n return {\n ...reactLocaleHook,\n pathWithoutLocale,\n };\n};\n"],"mappings":";;;;;;;;AAQA,MAAa,4BAA4B;CACvC,MAAM,EAAE,MAAM,UAAU,WAAW,WAAW;CAC9C,MAAM,oBAAoB,cAClB,qBAAqB,SAAS,EACpC,CAAC,SAAS,CACX;AAiBD,QAAO;EACL,GALsBA,UAAe,EACrC,gBAZ0B,aACzB,WAA0B;AAGzB,QAFuB,gBAAgB,mBAAmB,OAAO,CAE7C;AAEpB,UAAO,QAAQ;KAEjB,CAAC,kBAAkB,CACpB,EAIA,CAAC;EAIA;EACD"}
|
|
@@ -26,30 +26,37 @@ const resolvePluginPath = (pluginPath, intlayerConfig, isTurbopackEnabled) => {
|
|
|
26
26
|
if (isTurbopackEnabled) return normalizePath(`./${relative(process.cwd(), pluginPathResolved)}`);
|
|
27
27
|
return pluginPathResolved;
|
|
28
28
|
};
|
|
29
|
-
const getPruneConfig = (intlayerConfig) => {
|
|
29
|
+
const getPruneConfig = (intlayerConfig, isBuildCommand, isTurbopackEnabled) => {
|
|
30
30
|
const { optimize, traversePattern, importMode } = intlayerConfig.build;
|
|
31
|
-
const { dictionariesDir, dynamicDictionariesDir, fetchDictionariesDir, mainDir, baseDir } = intlayerConfig.content;
|
|
32
|
-
|
|
31
|
+
const { dictionariesDir, unmergedDictionariesDir, dynamicDictionariesDir, fetchDictionariesDir, mainDir, baseDir } = intlayerConfig.content;
|
|
32
|
+
const logger = getAppLogger(intlayerConfig);
|
|
33
|
+
if (!(optimize ?? isBuildCommand)) return {};
|
|
33
34
|
if (!isGteNext13) return {};
|
|
34
35
|
if (!getIsSwcPluginAvailable(intlayerConfig)) return {};
|
|
35
|
-
|
|
36
|
-
runOnce(join(baseDir, ".intlayer", "cache", "intlayer-prune-plugin-enabled.lock"), () => logger("Intlayer prune plugin is enabled"), { cacheTimeoutMs: 1e3 * 10 });
|
|
36
|
+
runOnce(join(baseDir, ".intlayer", "cache", "intlayer-prune-plugin-enabled.lock"), () => logger("Build optimization enabled"), { cacheTimeoutMs: 1e3 * 10 });
|
|
37
37
|
const dictionariesEntryPath = join(mainDir, "dictionaries.mjs");
|
|
38
38
|
const dynamicDictionariesEntryPath = join(mainDir, "dynamic_dictionaries.mjs");
|
|
39
|
+
const unmergedDictionariesEntryPath = join(mainDir, "unmerged_dictionaries.mjs");
|
|
39
40
|
const fetchDictionariesEntryPath = join(mainDir, "fetch_dictionaries.mjs");
|
|
40
|
-
const filesList = [
|
|
41
|
+
const filesList = [
|
|
42
|
+
...fg.sync(traversePattern, { cwd: baseDir }).map((file) => join(baseDir, file)),
|
|
43
|
+
dictionariesEntryPath,
|
|
44
|
+
unmergedDictionariesEntryPath
|
|
45
|
+
];
|
|
41
46
|
const dictionaries = getDictionaries(intlayerConfig);
|
|
42
47
|
const liveSyncKeys = Object.values(dictionaries).filter((dictionary) => dictionary.live).map((dictionary) => dictionary.key);
|
|
43
|
-
return { experimental: { swcPlugins: [[resolvePluginPath("@intlayer/swc", intlayerConfig), {
|
|
48
|
+
return { experimental: { swcPlugins: [[resolvePluginPath("@intlayer/swc", intlayerConfig, isTurbopackEnabled), {
|
|
44
49
|
dictionariesDir,
|
|
45
50
|
dictionariesEntryPath,
|
|
51
|
+
unmergedDictionariesEntryPath,
|
|
52
|
+
unmergedDictionariesDir,
|
|
46
53
|
dynamicDictionariesDir,
|
|
47
54
|
dynamicDictionariesEntryPath,
|
|
48
55
|
fetchDictionariesDir,
|
|
49
56
|
fetchDictionariesEntryPath,
|
|
50
57
|
importMode,
|
|
51
58
|
filesList,
|
|
52
|
-
replaceDictionaryEntry:
|
|
59
|
+
replaceDictionaryEntry: true,
|
|
53
60
|
liveSyncKeys
|
|
54
61
|
}]] } };
|
|
55
62
|
};
|
|
@@ -76,7 +83,9 @@ const getCommandsEvent = () => {
|
|
|
76
83
|
const withIntlayerSync = (nextConfig = {}, configOptions) => {
|
|
77
84
|
if (typeof nextConfig !== "object") nextConfig = {};
|
|
78
85
|
const intlayerConfig = getConfiguration(configOptions);
|
|
86
|
+
const logger = getAppLogger(intlayerConfig);
|
|
79
87
|
const isTurbopackEnabled = configOptions?.enableTurbopack ?? isTurbopackEnabledFromCommand;
|
|
88
|
+
if (isTurbopackEnabled && typeof nextConfig.webpack !== "undefined") logger("Turbopack is enabled but a custom webpack config is present. It will be ignored.");
|
|
80
89
|
const { isBuildCommand, isDevCommand } = getCommandsEvent();
|
|
81
90
|
const turboConfig = {
|
|
82
91
|
resolveAlias: getAlias({
|
|
@@ -124,6 +133,7 @@ const withIntlayerSync = (nextConfig = {}, configOptions) => {
|
|
|
124
133
|
webpack: (config$1, options) => {
|
|
125
134
|
const { isServer, nextRuntime } = options;
|
|
126
135
|
if (typeof nextConfig.webpack === "function") config$1 = nextConfig.webpack(config$1, options);
|
|
136
|
+
if (config$1.externals === false) config$1.externals = [];
|
|
127
137
|
config$1.externals.push({
|
|
128
138
|
esbuild: "esbuild",
|
|
129
139
|
module: "module",
|
|
@@ -148,9 +158,7 @@ const withIntlayerSync = (nextConfig = {}, configOptions) => {
|
|
|
148
158
|
};
|
|
149
159
|
return config;
|
|
150
160
|
};
|
|
151
|
-
|
|
152
|
-
if (isBuildCommand) pruneConfig = getPruneConfig(intlayerConfig);
|
|
153
|
-
const intlayerNextConfig = merge(pruneConfig, getNewConfig());
|
|
161
|
+
const intlayerNextConfig = merge(getPruneConfig(intlayerConfig, isBuildCommand, isTurbopackEnabled ?? false), getNewConfig());
|
|
154
162
|
return merge(nextConfig, intlayerNextConfig);
|
|
155
163
|
};
|
|
156
164
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withIntlayer.mjs","names":["config: Partial<NextConfig>","config","pruneConfig: Partial<NextConfig>","intlayerNextConfig: Partial<NextConfig>"],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { join, relative, resolve } from 'node:path';\nimport { prepareIntlayer, runOnce } from '@intlayer/chokidar';\nimport {\n compareVersions,\n type GetConfigurationOptions,\n getAlias,\n getAppLogger,\n getConfiguration,\n getProjectRequire,\n normalizePath,\n} from '@intlayer/config';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { IntlayerPlugin } from '@intlayer/webpack';\nimport merge from 'deepmerge';\nimport fg from 'fast-glob';\nimport type { NextConfig } from 'next';\nimport type { NextJsWebpackConfig } from 'next/dist/server/config-shared';\nimport nextPackageJSON from 'next/package.json' with { type: 'json' };\n\nconst isGteNext13 = compareVersions(nextPackageJSON.version, '≥', '13.0.0');\nconst isGteNext15 = compareVersions(nextPackageJSON.version, '≥', '15.0.0');\nconst isGteNext16 = compareVersions(nextPackageJSON.version, '≥', '16.0.0');\nconst isTurbopackStable = compareVersions(\n nextPackageJSON.version,\n '≥',\n '15.3.0'\n);\n\nconst isTurbopackEnabledFromCommand = isGteNext16\n ? // Next@16 enable turbopack by default, and offer the possibility to disable it if --webpack flag is used\n !process.env.npm_lifecycle_script?.includes('--webpack')\n : // Next@15 use --turbopack flag, Next@14 use --turbo flag\n process.env.npm_lifecycle_script?.includes('--turbo');\n\n// Check if SWC plugin is available\nconst getIsSwcPluginAvailable = (intlayerConfig: IntlayerConfig) => {\n try {\n const requireFunction =\n intlayerConfig.build?.require ?? getProjectRequire();\n requireFunction.resolve('@intlayer/swc');\n return true;\n } catch (_e) {\n return false;\n }\n};\n\nconst resolvePluginPath = (\n pluginPath: string,\n intlayerConfig: IntlayerConfig,\n isTurbopackEnabled: boolean\n): string => {\n const requireFunction = intlayerConfig.build?.require ?? getProjectRequire();\n const pluginPathResolved = requireFunction?.resolve(pluginPath);\n\n if (isTurbopackEnabled)\n // Relative path for turbopack\n return normalizePath(`./${relative(process.cwd(), pluginPathResolved)}`);\n\n // Absolute path for webpack\n return pluginPathResolved;\n};\n\nconst getPruneConfig = (\n intlayerConfig: IntlayerConfig\n): Partial<NextConfig> => {\n const { optimize, traversePattern, importMode } = intlayerConfig.build;\n const {\n dictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n baseDir,\n } = intlayerConfig.content;\n\n if (!optimize) return {};\n\n if (!isGteNext13) return {};\n\n const isSwcPluginAvailable = getIsSwcPluginAvailable(intlayerConfig);\n\n if (!isSwcPluginAvailable) return {};\n\n const logger = getAppLogger(intlayerConfig);\n\n runOnce(\n join(baseDir, '.intlayer', 'cache', 'intlayer-prune-plugin-enabled.lock'),\n () => logger('Intlayer prune plugin is enabled'),\n {\n cacheTimeoutMs: 1000 * 10, // 10 seconds\n }\n );\n\n const dictionariesEntryPath = join(mainDir, 'dictionaries.mjs');\n\n const dynamicDictionariesEntryPath = join(\n mainDir,\n 'dynamic_dictionaries.mjs'\n );\n\n const fetchDictionariesEntryPath = join(mainDir, 'fetch_dictionaries.mjs');\n\n const filesListPattern = fg\n .sync(traversePattern, {\n cwd: baseDir,\n })\n .map((file) => join(baseDir, file));\n\n const filesList = [\n ...filesListPattern,\n dictionariesEntryPath, // should add dictionariesEntryPath to replace it by a empty object if import made dynamic\n ];\n\n const dictionaries = getDictionaries(intlayerConfig);\n\n const liveSyncKeys = Object.values(dictionaries)\n .filter((dictionary) => dictionary.live)\n .map((dictionary) => dictionary.key);\n\n return {\n experimental: {\n swcPlugins: [\n [\n resolvePluginPath('@intlayer/swc', intlayerConfig),\n {\n dictionariesDir,\n dictionariesEntryPath,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n fetchDictionariesDir,\n fetchDictionariesEntryPath,\n importMode,\n filesList,\n replaceDictionaryEntry: false,\n liveSyncKeys,\n } as any,\n ],\n ],\n },\n };\n};\n\nconst getCommandsEvent = () => {\n const lifecycleEvent = process.env.npm_lifecycle_event;\n const lifecycleScript = process.env.npm_lifecycle_script ?? '';\n\n const isDevCommand =\n lifecycleEvent === 'dev' ||\n process.argv.some((arg) => arg === 'dev') ||\n /(^|\\s)(next\\s+)?dev(\\s|$)/.test(lifecycleScript);\n\n const isBuildCommand =\n lifecycleEvent === 'build' ||\n process.argv.some((arg) => arg === 'build') ||\n /(^|\\s)(next\\s+)?build(\\s|$)/.test(lifecycleScript);\n\n const isStartCommand =\n lifecycleEvent === 'start' ||\n process.argv.some((arg) => arg === 'start') ||\n /(^|\\s)(next\\s+)?start(\\s|$)/.test(lifecycleScript);\n\n return {\n isDevCommand,\n isBuildCommand,\n isStartCommand,\n };\n};\n\ntype WebpackParams = Parameters<NextJsWebpackConfig>;\n\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 const isTurbopackEnabled =\n configOptions?.enableTurbopack ?? isTurbopackEnabledFromCommand;\n\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n\n // Only provide turbo-specific config if user explicitly sets it\n const turboConfig = {\n resolveAlias: getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => `./${value}`, // prefix by './' to consider the path as relative to the project root. This is necessary for turbopack to work correctly.\n }),\n\n rules: {\n '*.node': {\n as: '*.node',\n loaders: ['node-loader'],\n },\n },\n };\n\n const serverExternalPackages = [\n 'esbuild',\n 'module',\n 'fs',\n 'chokidar',\n 'fsevents',\n ];\n\n const getNewConfig = (): Partial<NextConfig> => {\n let config: Partial<NextConfig> = {};\n\n if (isGteNext15) {\n config = {\n ...config,\n serverExternalPackages,\n };\n }\n\n if (isGteNext13 && !isGteNext15) {\n config = {\n ...config,\n experimental: {\n ...(config?.experimental ?? {}),\n serverComponentsExternalPackages: serverExternalPackages,\n },\n };\n }\n\n if (isTurbopackEnabled) {\n if (isGteNext15 && isTurbopackStable) {\n config = {\n ...config,\n turbopack: turboConfig,\n };\n } else {\n config = {\n ...config,\n experimental: {\n ...(config?.experimental ?? {}),\n // @ts-ignore exist in next@14\n turbo: turboConfig,\n },\n };\n }\n } else {\n config = {\n ...config,\n webpack: (config: WebpackParams['0'], options: WebpackParams[1]) => {\n // Only add Intlayer plugin on server side (node runtime)\n const { isServer, nextRuntime } = options;\n\n // If the user has defined their own webpack config, call it\n if (typeof nextConfig.webpack === 'function') {\n config = nextConfig.webpack(config, options);\n }\n\n // Mark these modules as externals\n config.externals.push({\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n chokidar: 'chokidar',\n fsevents: 'fsevents',\n });\n\n // Use `node-loader` for any `.node` files\n config.module.rules.push({\n test: /\\.node$/,\n loader: 'node-loader',\n });\n\n // Always alias on the server (node/edge) for stability.\n // On the client, alias only when not using live sync.\n config.resolve.alias = {\n ...config.resolve.alias,\n ...getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => resolve(value), // get absolute path\n }),\n };\n\n // Activate watch mode webpack plugin\n if (isDevCommand && isServer && nextRuntime === 'nodejs') {\n config.plugins.push(new IntlayerPlugin(intlayerConfig));\n }\n\n return config;\n },\n };\n }\n\n return config;\n };\n\n let pruneConfig: Partial<NextConfig> = {};\n\n if (isBuildCommand) {\n pruneConfig = getPruneConfig(intlayerConfig);\n }\n\n const intlayerNextConfig: Partial<NextConfig> = merge(\n pruneConfig,\n getNewConfig()\n );\n\n // Merge the new config with the user's config\n const result = merge(nextConfig, intlayerNextConfig) as NextConfig & T;\n\n return result;\n};\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayer(nextConfig)\n * ```\n *\n * > Node withIntlayer is a promise function. Use withIntlayerSync instead if you want to use it synchronously.\n * > Using the promise allows to prepare the intlayer dictionaries before the build starts.\n *\n */\nexport const withIntlayer = async <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T,\n configOptions?: GetConfigurationOptions\n): Promise<NextConfig & T> => {\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n\n // Only call prepareIntlayer during `dev` or `build` (not during `start`)\n // If prod: clean and rebuild once\n // If dev: rebuild only once if it's more than 1 hour since last rebuild\n if (isDevCommand || isBuildCommand) {\n const intlayerConfig = getConfiguration(configOptions);\n\n // prepareIntlayer use runOnce to ensure to run only once because will run twice on client and server side otherwise\n await prepareIntlayer(intlayerConfig, {\n clean: isBuildCommand,\n cacheTimeoutMs: isBuildCommand\n ? 1000 * 30 // 30 seconds for build (to ensure to rebuild all dictionaries)\n : 1000 * 60 * 60, // 1 hour for dev (default cache timeout)\n });\n }\n\n return withIntlayerSync(nextConfig, configOptions);\n};\n"],"mappings":";;;;;;;;;;AAoBA,MAAM,cAAc,gBAAgB,gBAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,cAAc,gBAAgB,gBAAgB,SAAS,KAAK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layer.mjs","names":["config: Partial<NextConfig>","config","intlayerNextConfig: Partial<NextConfig>"],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":["import { join, relative, resolve } from 'node:path';\nimport { prepareIntlayer, runOnce } from '@intlayer/chokidar';\nimport {\n compareVersions,\n type GetConfigurationOptions,\n getAlias,\n getAppLogger,\n getConfiguration,\n getProjectRequire,\n normalizePath,\n} from '@intlayer/config';\nimport { getDictionaries } from '@intlayer/dictionaries-entry';\nimport type { IntlayerConfig } from '@intlayer/types';\nimport { IntlayerPlugin } from '@intlayer/webpack';\nimport merge from 'deepmerge';\nimport fg from 'fast-glob';\nimport type { NextConfig } from 'next';\nimport type { NextJsWebpackConfig } from 'next/dist/server/config-shared';\nimport nextPackageJSON from 'next/package.json' with { type: 'json' };\n\nconst isGteNext13 = compareVersions(nextPackageJSON.version, '≥', '13.0.0');\nconst isGteNext15 = compareVersions(nextPackageJSON.version, '≥', '15.0.0');\nconst isGteNext16 = compareVersions(nextPackageJSON.version, '≥', '16.0.0');\nconst isTurbopackStable = compareVersions(\n nextPackageJSON.version,\n '≥',\n '15.3.0'\n);\n\nconst isTurbopackEnabledFromCommand = isGteNext16\n ? // Next@16 enable turbopack by default, and offer the possibility to disable it if --webpack flag is used\n !process.env.npm_lifecycle_script?.includes('--webpack')\n : // Next@15 use --turbopack flag, Next@14 use --turbo flag\n process.env.npm_lifecycle_script?.includes('--turbo');\n\n// Check if SWC plugin is available\nconst getIsSwcPluginAvailable = (intlayerConfig: IntlayerConfig) => {\n try {\n const requireFunction =\n intlayerConfig.build?.require ?? getProjectRequire();\n requireFunction.resolve('@intlayer/swc');\n return true;\n } catch (_e) {\n return false;\n }\n};\n\nconst resolvePluginPath = (\n pluginPath: string,\n intlayerConfig: IntlayerConfig,\n isTurbopackEnabled: boolean\n): string => {\n const requireFunction = intlayerConfig.build?.require ?? getProjectRequire();\n const pluginPathResolved = requireFunction?.resolve(pluginPath);\n\n if (isTurbopackEnabled)\n // Relative path for turbopack\n return normalizePath(`./${relative(process.cwd(), pluginPathResolved)}`);\n\n // Absolute path for webpack\n return pluginPathResolved;\n};\n\nconst getPruneConfig = (\n intlayerConfig: IntlayerConfig,\n isBuildCommand: boolean,\n isTurbopackEnabled: boolean\n): Partial<NextConfig> => {\n const { optimize, traversePattern, importMode } = intlayerConfig.build;\n const {\n dictionariesDir,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n fetchDictionariesDir,\n mainDir,\n baseDir,\n } = intlayerConfig.content;\n const logger = getAppLogger(intlayerConfig);\n\n if (!(optimize ?? isBuildCommand)) {\n return {};\n }\n\n if (!isGteNext13) return {};\n\n const isSwcPluginAvailable = getIsSwcPluginAvailable(intlayerConfig);\n\n if (!isSwcPluginAvailable) return {};\n\n runOnce(\n join(baseDir, '.intlayer', 'cache', 'intlayer-prune-plugin-enabled.lock'),\n () => logger('Build optimization enabled'),\n {\n cacheTimeoutMs: 1000 * 10, // 10 seconds\n }\n );\n\n const dictionariesEntryPath = join(mainDir, 'dictionaries.mjs');\n\n const dynamicDictionariesEntryPath = join(\n mainDir,\n 'dynamic_dictionaries.mjs'\n );\n\n const unmergedDictionariesEntryPath = join(\n mainDir,\n 'unmerged_dictionaries.mjs'\n );\n\n const fetchDictionariesEntryPath = join(mainDir, 'fetch_dictionaries.mjs');\n\n const filesListPattern = fg\n .sync(traversePattern, {\n cwd: baseDir,\n })\n .map((file) => join(baseDir, file));\n\n const filesList = [\n ...filesListPattern,\n dictionariesEntryPath, // should add dictionariesEntryPath to replace it by a empty object if import made dynamic\n unmergedDictionariesEntryPath, // should add dictionariesEntryPath to replace it by a empty object if import made dynamic\n ];\n\n const dictionaries = getDictionaries(intlayerConfig);\n\n const liveSyncKeys = Object.values(dictionaries)\n .filter((dictionary) => dictionary.live)\n .map((dictionary) => dictionary.key);\n\n return {\n experimental: {\n swcPlugins: [\n [\n resolvePluginPath(\n '@intlayer/swc',\n intlayerConfig,\n isTurbopackEnabled\n ),\n {\n dictionariesDir,\n dictionariesEntryPath,\n unmergedDictionariesEntryPath,\n unmergedDictionariesDir,\n dynamicDictionariesDir,\n dynamicDictionariesEntryPath,\n fetchDictionariesDir,\n fetchDictionariesEntryPath,\n importMode,\n filesList,\n replaceDictionaryEntry: true,\n liveSyncKeys,\n } as any,\n ],\n ],\n },\n };\n};\n\nconst getCommandsEvent = () => {\n const lifecycleEvent = process.env.npm_lifecycle_event;\n const lifecycleScript = process.env.npm_lifecycle_script ?? '';\n\n const isDevCommand =\n lifecycleEvent === 'dev' ||\n process.argv.some((arg) => arg === 'dev') ||\n /(^|\\s)(next\\s+)?dev(\\s|$)/.test(lifecycleScript);\n\n const isBuildCommand =\n lifecycleEvent === 'build' ||\n process.argv.some((arg) => arg === 'build') ||\n /(^|\\s)(next\\s+)?build(\\s|$)/.test(lifecycleScript);\n\n const isStartCommand =\n lifecycleEvent === 'start' ||\n process.argv.some((arg) => arg === 'start') ||\n /(^|\\s)(next\\s+)?start(\\s|$)/.test(lifecycleScript);\n\n return {\n isDevCommand,\n isBuildCommand,\n isStartCommand,\n };\n};\n\ntype WebpackParams = Parameters<NextJsWebpackConfig>;\n\ntype WithIntlayerOptions = GetConfigurationOptions & {\n enableTurbopack?: boolean;\n};\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayerSync(nextConfig)\n * ```\n */\nexport const withIntlayerSync = <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T,\n configOptions?: WithIntlayerOptions\n): NextConfig & T => {\n if (typeof nextConfig !== 'object') {\n nextConfig = {} as T;\n }\n\n const intlayerConfig = getConfiguration(configOptions);\n const logger = getAppLogger(intlayerConfig);\n\n const isTurbopackEnabled =\n configOptions?.enableTurbopack ?? isTurbopackEnabledFromCommand;\n\n if (isTurbopackEnabled && typeof nextConfig.webpack !== 'undefined') {\n logger(\n 'Turbopack is enabled but a custom webpack config is present. It will be ignored.'\n );\n }\n\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n\n // Only provide turbo-specific config if user explicitly sets it\n const turboConfig = {\n resolveAlias: getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => `./${value}`, // prefix by './' to consider the path as relative to the project root. This is necessary for turbopack to work correctly.\n }),\n\n rules: {\n '*.node': {\n as: '*.node',\n loaders: ['node-loader'],\n },\n },\n };\n\n const serverExternalPackages = [\n 'esbuild',\n 'module',\n 'fs',\n 'chokidar',\n 'fsevents',\n ];\n\n const getNewConfig = (): Partial<NextConfig> => {\n let config: Partial<NextConfig> = {};\n\n if (isGteNext15) {\n config = {\n ...config,\n serverExternalPackages,\n };\n }\n\n if (isGteNext13 && !isGteNext15) {\n config = {\n ...config,\n experimental: {\n ...(config?.experimental ?? {}),\n serverComponentsExternalPackages: serverExternalPackages,\n },\n };\n }\n\n if (isTurbopackEnabled) {\n if (isGteNext15 && isTurbopackStable) {\n config = {\n ...config,\n turbopack: turboConfig,\n };\n } else {\n config = {\n ...config,\n experimental: {\n ...(config?.experimental ?? {}),\n // @ts-ignore exist in next@14\n turbo: turboConfig,\n },\n };\n }\n } else {\n config = {\n ...config,\n webpack: (config: WebpackParams['0'], options: WebpackParams[1]) => {\n // Only add Intlayer plugin on server side (node runtime)\n const { isServer, nextRuntime } = options;\n\n // If the user has defined their own webpack config, call it\n if (typeof nextConfig.webpack === 'function') {\n config = nextConfig.webpack(config, options);\n }\n\n // Rspack set external as false by default\n // Overwrite it to allow pushing the desired externals\n if (config.externals === false) {\n config.externals = [];\n }\n\n // Mark these modules as externals\n config.externals.push({\n esbuild: 'esbuild',\n module: 'module',\n fs: 'fs',\n chokidar: 'chokidar',\n fsevents: 'fsevents',\n });\n\n // Use `node-loader` for any `.node` files\n config.module.rules.push({\n test: /\\.node$/,\n loader: 'node-loader',\n });\n\n // Always alias on the server (node/edge) for stability.\n // On the client, alias only when not using live sync.\n config.resolve.alias = {\n ...config.resolve.alias,\n ...getAlias({\n configuration: intlayerConfig,\n formatter: (value: string) => resolve(value), // get absolute path\n }),\n };\n\n // Activate watch mode webpack plugin\n if (isDevCommand && isServer && nextRuntime === 'nodejs') {\n // Optional as rspack not support plugin yet\n config.plugins.push(new IntlayerPlugin(intlayerConfig));\n }\n\n return config;\n },\n };\n }\n\n return config;\n };\n\n const pruneConfig: Partial<NextConfig> = getPruneConfig(\n intlayerConfig,\n isBuildCommand,\n isTurbopackEnabled ?? false\n );\n\n const intlayerNextConfig: Partial<NextConfig> = merge(\n pruneConfig,\n getNewConfig()\n );\n\n // Merge the new config with the user's config\n const result = merge(nextConfig, intlayerNextConfig) as NextConfig & T;\n\n return result;\n};\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayer(nextConfig)\n * ```\n *\n * > Node withIntlayer is a promise function. Use withIntlayerSync instead if you want to use it synchronously.\n * > Using the promise allows to prepare the intlayer dictionaries before the build starts.\n *\n */\nexport const withIntlayer = async <T extends Partial<NextConfig>>(\n nextConfig: T = {} as T,\n configOptions?: WithIntlayerOptions\n): Promise<NextConfig & T> => {\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n\n // Only call prepareIntlayer during `dev` or `build` (not during `start`)\n // If prod: clean and rebuild once\n // If dev: rebuild only once if it's more than 1 hour since last rebuild\n if (isDevCommand || isBuildCommand) {\n const intlayerConfig = getConfiguration(configOptions);\n\n // prepareIntlayer use runOnce to ensure to run only once because will run twice on client and server side otherwise\n await prepareIntlayer(intlayerConfig, {\n clean: isBuildCommand,\n cacheTimeoutMs: isBuildCommand\n ? 1000 * 30 // 30 seconds for build (to ensure to rebuild all dictionaries)\n : 1000 * 60 * 60, // 1 hour for dev (default cache timeout)\n });\n }\n\n return withIntlayerSync(nextConfig, configOptions);\n};\n"],"mappings":";;;;;;;;;;AAoBA,MAAM,cAAc,gBAAgB,gBAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,cAAc,gBAAgB,gBAAgB,SAAS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gBAAgB,eAIlB,OAAM,gBAHiB,iBAAiB,cAAc,EAGhB;EACpC,OAAO;EACP,gBAAgB,iBACZ,MAAO,KACP,MAAO,KAAK;EACjB,CAAC;AAGJ,QAAO,iBAAiB,YAAY,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":[],"mappings":";;;;KAQK,cAAA;4CACuC;;AADvC,cAkBQ,SAlBM,
|
|
1
|
+
{"version":3,"file":"useLocale.d.ts","names":[],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":[],"mappings":";;;;KAQK,cAAA;4CACuC;;AADvC,cAkBQ,SAlBM,EAAA,CACyB;EAAA;AAAa,CAAA,CAAb,EAiBJ,cAjBiB,EAAA,GAAA;EAiB5C,iBAiCZ,EAAA,MAAA;EAjCyB,MAAA,EAAiC,gBAAA,CAAA,eAAjC;EAAc,aAAA,kCAAA;EAAmB,gBAAA,oCAAA"}
|
|
@@ -32,7 +32,7 @@ declare const withIntlayerSync: <T extends Partial<NextConfig>>(nextConfig?: T,
|
|
|
32
32
|
* > Using the promise allows to prepare the intlayer dictionaries before the build starts.
|
|
33
33
|
*
|
|
34
34
|
*/
|
|
35
|
-
declare const withIntlayer: <T extends Partial<NextConfig>>(nextConfig?: T, configOptions?:
|
|
35
|
+
declare const withIntlayer: <T extends Partial<NextConfig>>(nextConfig?: T, configOptions?: WithIntlayerOptions) => Promise<NextConfig & T>;
|
|
36
36
|
//#endregion
|
|
37
37
|
export { withIntlayer, withIntlayerSync };
|
|
38
38
|
//# sourceMappingURL=withIntlayer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withIntlayer.d.ts","names":[],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"withIntlayer.d.ts","names":[],"sources":["../../../src/server/withIntlayer.ts"],"sourcesContent":[],"mappings":";;;;KA0LK,mBAAA,GAAsB;;AA1KY,CAAA;AAyLvC;;;;;;;;AA0KA;;;AACc,cA3KD,gBA2KC,EAAA,CAAA,UA3K6B,OA2K7B,CA3KqC,UA2KrC,CAAA,CAAA,CAAA,UAAA,CAAA,EA1KA,CA0KA,EAAA,aAAA,CAAA,EAzKI,mBAyKJ,EAAA,GAxKX,UAwKW,GAxKE,CAwKF;;;;;;;;;;;;;;;;cADD,yBAAgC,QAAQ,0BACvC,mBACI,wBACf,QAAQ,aAAa"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "next-intlayer",
|
|
3
|
-
"version": "7.2.1
|
|
3
|
+
"version": "7.2.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Simplify internationalization i18n in Next.js with context providers, hooks, locale detection, and multilingual content integration.",
|
|
6
6
|
"keywords": [
|
|
@@ -117,16 +117,16 @@
|
|
|
117
117
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
118
118
|
},
|
|
119
119
|
"dependencies": {
|
|
120
|
-
"@intlayer/chokidar": "7.2.
|
|
121
|
-
"@intlayer/config": "7.2.
|
|
122
|
-
"@intlayer/core": "7.2.
|
|
123
|
-
"@intlayer/dictionaries-entry": "7.2.
|
|
124
|
-
"@intlayer/types": "7.2.
|
|
125
|
-
"@intlayer/webpack": "7.2.
|
|
120
|
+
"@intlayer/chokidar": "7.2.2",
|
|
121
|
+
"@intlayer/config": "7.2.2",
|
|
122
|
+
"@intlayer/core": "7.2.1",
|
|
123
|
+
"@intlayer/dictionaries-entry": "7.2.2",
|
|
124
|
+
"@intlayer/types": "7.2.2",
|
|
125
|
+
"@intlayer/webpack": "7.2.2",
|
|
126
126
|
"deepmerge": "4.3.1",
|
|
127
127
|
"fast-glob": "3.3.3",
|
|
128
128
|
"node-loader": "2.1.0",
|
|
129
|
-
"react-intlayer": "7.2.
|
|
129
|
+
"react-intlayer": "7.2.2"
|
|
130
130
|
},
|
|
131
131
|
"devDependencies": {
|
|
132
132
|
"@types/node": "24.10.1",
|
|
@@ -135,10 +135,10 @@
|
|
|
135
135
|
"@utils/ts-config": "1.0.4",
|
|
136
136
|
"@utils/ts-config-types": "1.0.4",
|
|
137
137
|
"@utils/tsdown-config": "1.0.4",
|
|
138
|
-
"rimraf": "6.1.
|
|
139
|
-
"tsdown": "0.16.
|
|
138
|
+
"rimraf": "6.1.2",
|
|
139
|
+
"tsdown": "0.16.6",
|
|
140
140
|
"typescript": "5.9.3",
|
|
141
|
-
"vitest": "4.0.
|
|
141
|
+
"vitest": "4.0.12"
|
|
142
142
|
},
|
|
143
143
|
"peerDependencies": {
|
|
144
144
|
"next": ">=14.0.0",
|