next-intlayer 8.1.2 → 8.1.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/_virtual/_rolldown/runtime.cjs +1 -29
- package/dist/cjs/client/IntlayerClientProvider.cjs +1 -36
- package/dist/cjs/client/IntlayerClientProvider.cjs.map +1 -1
- package/dist/cjs/client/format/index.cjs +1 -9
- package/dist/cjs/client/index.cjs +1 -16
- package/dist/cjs/client/useLocale.cjs +1 -68
- package/dist/cjs/client/useLocale.cjs.map +1 -1
- package/dist/cjs/client/useLocalePageRouter.cjs +1 -45
- package/dist/cjs/client/useLocalePageRouter.cjs.map +1 -1
- package/dist/cjs/client/useRewriteURL.cjs +1 -12
- package/dist/cjs/generateStaticParams.cjs +1 -29
- package/dist/cjs/generateStaticParams.cjs.map +1 -1
- package/dist/cjs/index.cjs +1 -132
- package/dist/cjs/proxy/index.cjs +1 -8
- package/dist/cjs/proxy/intlayerProxy.cjs +1 -246
- package/dist/cjs/proxy/intlayerProxy.cjs.map +1 -1
- package/dist/cjs/proxy/localeDetector.cjs +1 -20
- package/dist/cjs/proxy/localeDetector.cjs.map +1 -1
- package/dist/cjs/proxy/middleware.cjs +1 -37
- package/dist/cjs/proxy/middleware.cjs.map +1 -1
- package/dist/cjs/proxy/multipleProxies.cjs +1 -57
- package/dist/cjs/proxy/multipleProxies.cjs.map +1 -1
- package/dist/cjs/server/format/index.cjs +1 -9
- package/dist/cjs/server/getLocale.cjs +1 -47
- package/dist/cjs/server/getLocale.cjs.map +1 -1
- package/dist/cjs/server/index.cjs +1 -75
- package/dist/cjs/server/withIntlayer.cjs +1 -210
- package/dist/cjs/server/withIntlayer.cjs.map +1 -1
- package/dist/esm/client/IntlayerClientProvider.mjs +1 -34
- package/dist/esm/client/IntlayerClientProvider.mjs.map +1 -1
- package/dist/esm/client/format/index.mjs +1 -1
- package/dist/esm/client/index.mjs +1 -6
- package/dist/esm/client/useLocale.mjs +1 -66
- package/dist/esm/client/useLocale.mjs.map +1 -1
- package/dist/esm/client/useLocalePageRouter.mjs +1 -43
- package/dist/esm/client/useLocalePageRouter.mjs.map +1 -1
- package/dist/esm/client/useRewriteURL.mjs +1 -5
- package/dist/esm/generateStaticParams.mjs +1 -26
- package/dist/esm/generateStaticParams.mjs.map +1 -1
- package/dist/esm/index.mjs +1 -8
- package/dist/esm/proxy/index.mjs +1 -5
- package/dist/esm/proxy/intlayerProxy.mjs +1 -243
- package/dist/esm/proxy/intlayerProxy.mjs.map +1 -1
- package/dist/esm/proxy/localeDetector.mjs +1 -18
- package/dist/esm/proxy/localeDetector.mjs.map +1 -1
- package/dist/esm/proxy/middleware.mjs +1 -35
- package/dist/esm/proxy/middleware.mjs.map +1 -1
- package/dist/esm/proxy/multipleProxies.mjs +1 -55
- package/dist/esm/proxy/multipleProxies.mjs.map +1 -1
- package/dist/esm/server/format/index.mjs +1 -1
- package/dist/esm/server/getLocale.mjs +1 -44
- package/dist/esm/server/getLocale.mjs.map +1 -1
- package/dist/esm/server/index.mjs +1 -5
- package/dist/esm/server/withIntlayer.mjs +1 -206
- package/dist/esm/server/withIntlayer.mjs.map +1 -1
- package/dist/types/client/useLocale.d.ts.map +1 -1
- package/dist/types/client/useLocalePageRouter.d.ts.map +1 -1
- package/dist/types/proxy/intlayerProxy.d.ts.map +1 -1
- package/dist/types/server/getLocale.d.ts.map +1 -1
- package/dist/types/server/withIntlayer.d.ts +1 -1
- package/package.json +8 -8
|
@@ -1,75 +1 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
const require_server_getLocale = require('./getLocale.cjs');
|
|
4
|
-
const require_server_withIntlayer = require('./withIntlayer.cjs');
|
|
5
|
-
let react_intlayer_server = require("react-intlayer/server");
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, 'IntlayerServer', {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return react_intlayer_server.IntlayerServer;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
Object.defineProperty(exports, 'IntlayerServerProvider', {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () {
|
|
16
|
-
return react_intlayer_server.IntlayerServerProvider;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
exports.getLocale = require_server_getLocale.getLocale;
|
|
20
|
-
Object.defineProperty(exports, 'locale', {
|
|
21
|
-
enumerable: true,
|
|
22
|
-
get: function () {
|
|
23
|
-
return react_intlayer_server.locale;
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
Object.defineProperty(exports, 't', {
|
|
27
|
-
enumerable: true,
|
|
28
|
-
get: function () {
|
|
29
|
-
return react_intlayer_server.t;
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
Object.defineProperty(exports, 'useDictionary', {
|
|
33
|
-
enumerable: true,
|
|
34
|
-
get: function () {
|
|
35
|
-
return react_intlayer_server.useDictionary;
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
Object.defineProperty(exports, 'useDictionaryDynamic', {
|
|
39
|
-
enumerable: true,
|
|
40
|
-
get: function () {
|
|
41
|
-
return react_intlayer_server.useDictionaryDynamic;
|
|
42
|
-
}
|
|
43
|
-
});
|
|
44
|
-
Object.defineProperty(exports, 'useI18n', {
|
|
45
|
-
enumerable: true,
|
|
46
|
-
get: function () {
|
|
47
|
-
return react_intlayer_server.useI18n;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
Object.defineProperty(exports, 'useIntl', {
|
|
51
|
-
enumerable: true,
|
|
52
|
-
get: function () {
|
|
53
|
-
return react_intlayer_server.useIntl;
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
Object.defineProperty(exports, 'useIntlayer', {
|
|
57
|
-
enumerable: true,
|
|
58
|
-
get: function () {
|
|
59
|
-
return react_intlayer_server.useIntlayer;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
Object.defineProperty(exports, 'useLoadDynamic', {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
get: function () {
|
|
65
|
-
return react_intlayer_server.useLoadDynamic;
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
Object.defineProperty(exports, 'useLocale', {
|
|
69
|
-
enumerable: true,
|
|
70
|
-
get: function () {
|
|
71
|
-
return react_intlayer_server.useLocale;
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
exports.withIntlayer = require_server_withIntlayer.withIntlayer;
|
|
75
|
-
exports.withIntlayerSync = require_server_withIntlayer.withIntlayerSync;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`./getLocale.cjs`),t=require(`./withIntlayer.cjs`);let n=require(`react-intlayer/server`);Object.defineProperty(exports,`IntlayerServer`,{enumerable:!0,get:function(){return n.IntlayerServer}}),Object.defineProperty(exports,`IntlayerServerProvider`,{enumerable:!0,get:function(){return n.IntlayerServerProvider}}),exports.getLocale=e.getLocale,Object.defineProperty(exports,`locale`,{enumerable:!0,get:function(){return n.locale}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return n.t}}),Object.defineProperty(exports,`useDictionary`,{enumerable:!0,get:function(){return n.useDictionary}}),Object.defineProperty(exports,`useDictionaryDynamic`,{enumerable:!0,get:function(){return n.useDictionaryDynamic}}),Object.defineProperty(exports,`useI18n`,{enumerable:!0,get:function(){return n.useI18n}}),Object.defineProperty(exports,`useIntl`,{enumerable:!0,get:function(){return n.useIntl}}),Object.defineProperty(exports,`useIntlayer`,{enumerable:!0,get:function(){return n.useIntlayer}}),Object.defineProperty(exports,`useLoadDynamic`,{enumerable:!0,get:function(){return n.useLoadDynamic}}),Object.defineProperty(exports,`useLocale`,{enumerable:!0,get:function(){return n.useLocale}}),exports.withIntlayer=t.withIntlayer,exports.withIntlayerSync=t.withIntlayerSync;
|
|
@@ -1,211 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,
|
|
2
|
-
const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
let node_path = require("node:path");
|
|
4
|
-
let _intlayer_chokidar_build = require("@intlayer/chokidar/build");
|
|
5
|
-
let _intlayer_chokidar_utils = require("@intlayer/chokidar/utils");
|
|
6
|
-
let _intlayer_config = require("@intlayer/config");
|
|
7
|
-
let _intlayer_dictionaries_entry = require("@intlayer/dictionaries-entry");
|
|
8
|
-
let _intlayer_webpack = require("@intlayer/webpack");
|
|
9
|
-
let defu = require("defu");
|
|
10
|
-
let next_package_json = require("next/package.json");
|
|
11
|
-
next_package_json = require_runtime.__toESM(next_package_json);
|
|
12
|
-
|
|
13
|
-
//#region src/server/withIntlayer.ts
|
|
14
|
-
const isGteNext13 = (0, _intlayer_config.compareVersions)(next_package_json.default.version, "≥", "13.0.0");
|
|
15
|
-
const isGteNext15 = (0, _intlayer_config.compareVersions)(next_package_json.default.version, "≥", "15.0.0");
|
|
16
|
-
const isGteNext16 = (0, _intlayer_config.compareVersions)(next_package_json.default.version, "≥", "16.0.0");
|
|
17
|
-
const isTurbopackStable = (0, _intlayer_config.compareVersions)(next_package_json.default.version, "≥", "15.3.0");
|
|
18
|
-
const isTurbopackEnabledFromCommand = isGteNext16 ? !process.env.npm_lifecycle_script?.includes("--webpack") : process.env.npm_lifecycle_script?.includes("--turbo");
|
|
19
|
-
const getIsSwcPluginAvailable = (intlayerConfig) => {
|
|
20
|
-
try {
|
|
21
|
-
(intlayerConfig.build?.require ?? (0, _intlayer_config.getProjectRequire)()).resolve("@intlayer/swc");
|
|
22
|
-
return true;
|
|
23
|
-
} catch (_e) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
const resolvePluginPath = (pluginPath, intlayerConfig, isTurbopackEnabled) => {
|
|
28
|
-
const pluginPathResolved = (intlayerConfig.build?.require ?? (0, _intlayer_config.getProjectRequire)())?.resolve(pluginPath);
|
|
29
|
-
if (isTurbopackEnabled) return (0, _intlayer_config.normalizePath)(`./${(0, node_path.relative)(process.cwd(), pluginPathResolved)}`);
|
|
30
|
-
return pluginPathResolved;
|
|
31
|
-
};
|
|
32
|
-
const getPruneConfig = (intlayerConfig, isBuildCommand, isTurbopackEnabled) => {
|
|
33
|
-
const { optimize } = intlayerConfig.build;
|
|
34
|
-
const importMode = intlayerConfig.build.importMode ?? intlayerConfig.dictionary?.importMode;
|
|
35
|
-
const { dictionariesDir, unmergedDictionariesDir, dynamicDictionariesDir, fetchDictionariesDir, mainDir } = intlayerConfig.system;
|
|
36
|
-
const { baseDir } = intlayerConfig.content;
|
|
37
|
-
const logger = (0, _intlayer_config.getAppLogger)(intlayerConfig);
|
|
38
|
-
if (optimize === false) return {};
|
|
39
|
-
if (optimize === void 0 && !isBuildCommand) return {};
|
|
40
|
-
if (!isGteNext13) return {};
|
|
41
|
-
const isSwcPluginAvailable = getIsSwcPluginAvailable(intlayerConfig);
|
|
42
|
-
(0, _intlayer_chokidar_utils.runOnce)((0, node_path.join)(baseDir, ".intlayer", "cache", "intlayer-prune-plugin-enabled.lock"), () => {
|
|
43
|
-
if (isSwcPluginAvailable) logger("Build optimization enabled");
|
|
44
|
-
else logger([
|
|
45
|
-
(0, _intlayer_config.colorize)("Recommended: Install", _intlayer_config.ANSIColors.GREY),
|
|
46
|
-
(0, _intlayer_config.colorize)("@intlayer/swc", _intlayer_config.ANSIColors.GREY_LIGHT),
|
|
47
|
-
(0, _intlayer_config.colorize)("package to enable build optimization. See documentation: ", _intlayer_config.ANSIColors.GREY),
|
|
48
|
-
(0, _intlayer_config.colorize)("https://intlayer.org/docs/en/bundle_optimization", _intlayer_config.ANSIColors.GREY_LIGHT)
|
|
49
|
-
]);
|
|
50
|
-
}, { cacheTimeoutMs: 1e3 * 30 });
|
|
51
|
-
if (!isSwcPluginAvailable) return {};
|
|
52
|
-
const dictionariesEntryPath = (0, node_path.join)(mainDir, "dictionaries.mjs");
|
|
53
|
-
const dynamicDictionariesEntryPath = (0, node_path.join)(mainDir, "dynamic_dictionaries.mjs");
|
|
54
|
-
const unmergedDictionariesEntryPath = (0, node_path.join)(mainDir, "unmerged_dictionaries.mjs");
|
|
55
|
-
const fetchDictionariesEntryPath = (0, node_path.join)(mainDir, "fetch_dictionaries.mjs");
|
|
56
|
-
const filesList = [
|
|
57
|
-
...(0, _intlayer_chokidar_utils.getComponentTransformPatternSync)(intlayerConfig),
|
|
58
|
-
dictionariesEntryPath,
|
|
59
|
-
unmergedDictionariesEntryPath
|
|
60
|
-
];
|
|
61
|
-
const dictionaries = (0, _intlayer_dictionaries_entry.getDictionaries)(intlayerConfig);
|
|
62
|
-
const dictionaryModeMap = {};
|
|
63
|
-
Object.values(dictionaries).forEach((dictionary) => {
|
|
64
|
-
dictionaryModeMap[dictionary.key] = dictionary.importMode ?? importMode ?? _intlayer_config.DefaultValues.Dictionary.IMPORT_MODE;
|
|
65
|
-
});
|
|
66
|
-
return { experimental: { swcPlugins: [[resolvePluginPath("@intlayer/swc", intlayerConfig, isTurbopackEnabled), {
|
|
67
|
-
dictionariesDir,
|
|
68
|
-
dictionariesEntryPath,
|
|
69
|
-
unmergedDictionariesEntryPath,
|
|
70
|
-
unmergedDictionariesDir,
|
|
71
|
-
dynamicDictionariesDir,
|
|
72
|
-
dynamicDictionariesEntryPath,
|
|
73
|
-
fetchDictionariesDir,
|
|
74
|
-
fetchDictionariesEntryPath,
|
|
75
|
-
importMode,
|
|
76
|
-
filesList,
|
|
77
|
-
replaceDictionaryEntry: true,
|
|
78
|
-
dictionaryModeMap
|
|
79
|
-
}]] } };
|
|
80
|
-
};
|
|
81
|
-
const getCommandsEvent = () => {
|
|
82
|
-
const lifecycleEvent = process.env.npm_lifecycle_event;
|
|
83
|
-
const lifecycleScript = process.env.npm_lifecycle_script ?? "";
|
|
84
|
-
return {
|
|
85
|
-
isDevCommand: lifecycleEvent === "dev" || process.argv.some((arg) => arg === "dev") || /(^|\s)(next\s+)?dev(\s|$)/.test(lifecycleScript),
|
|
86
|
-
isBuildCommand: lifecycleEvent === "build" || process.argv.some((arg) => arg === "build") || /(^|\s)(next\s+)?build(\s|$)/.test(lifecycleScript),
|
|
87
|
-
isStartCommand: lifecycleEvent === "start" || process.argv.some((arg) => arg === "start") || /(^|\s)(next\s+)?start(\s|$)/.test(lifecycleScript)
|
|
88
|
-
};
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* A Next.js plugin that adds the intlayer configuration to the webpack configuration
|
|
92
|
-
* and sets the environment variables
|
|
93
|
-
*
|
|
94
|
-
* Usage:
|
|
95
|
-
*
|
|
96
|
-
* ```ts
|
|
97
|
-
* // next.config.js
|
|
98
|
-
* export default withIntlayerSync(nextConfig)
|
|
99
|
-
* ```
|
|
100
|
-
*/
|
|
101
|
-
const withIntlayerSync = (nextConfig = {}, configOptions) => {
|
|
102
|
-
if (typeof nextConfig !== "object") nextConfig = {};
|
|
103
|
-
const intlayerConfig = (0, _intlayer_config.getConfiguration)(configOptions);
|
|
104
|
-
const logger = (0, _intlayer_config.getAppLogger)(intlayerConfig);
|
|
105
|
-
const isTurbopackEnabled = configOptions?.enableTurbopack ?? isTurbopackEnabledFromCommand;
|
|
106
|
-
if (isTurbopackEnabled && typeof nextConfig.webpack !== "undefined") logger("Turbopack is enabled but a custom webpack config is present. It will be ignored.");
|
|
107
|
-
const { isBuildCommand, isDevCommand } = getCommandsEvent();
|
|
108
|
-
const turboConfig = {
|
|
109
|
-
resolveAlias: (0, _intlayer_config.getAlias)({
|
|
110
|
-
configuration: intlayerConfig,
|
|
111
|
-
formatter: (value) => `./${value}`
|
|
112
|
-
}),
|
|
113
|
-
rules: { "*.node": {
|
|
114
|
-
as: "*.node",
|
|
115
|
-
loaders: ["node-loader"]
|
|
116
|
-
} }
|
|
117
|
-
};
|
|
118
|
-
const serverExternalPackages = [
|
|
119
|
-
"esbuild",
|
|
120
|
-
"module",
|
|
121
|
-
"fs",
|
|
122
|
-
"chokidar",
|
|
123
|
-
"fsevents"
|
|
124
|
-
];
|
|
125
|
-
const getNewConfig = () => {
|
|
126
|
-
let config = {};
|
|
127
|
-
if (isGteNext15) config = {
|
|
128
|
-
...config,
|
|
129
|
-
serverExternalPackages
|
|
130
|
-
};
|
|
131
|
-
if (isGteNext13 && !isGteNext15) config = {
|
|
132
|
-
...config,
|
|
133
|
-
experimental: {
|
|
134
|
-
...config?.experimental ?? {},
|
|
135
|
-
serverComponentsExternalPackages: serverExternalPackages
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
if (isTurbopackEnabled) if (isGteNext15 && isTurbopackStable) config = {
|
|
139
|
-
...config,
|
|
140
|
-
turbopack: turboConfig
|
|
141
|
-
};
|
|
142
|
-
else config = {
|
|
143
|
-
...config,
|
|
144
|
-
experimental: {
|
|
145
|
-
...config?.experimental ?? {},
|
|
146
|
-
turbo: turboConfig
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
else config = {
|
|
150
|
-
...config,
|
|
151
|
-
webpack: (config, options) => {
|
|
152
|
-
const { isServer, nextRuntime } = options;
|
|
153
|
-
if (typeof nextConfig.webpack === "function") config = nextConfig.webpack(config, options);
|
|
154
|
-
if (config.externals === false) config.externals = [];
|
|
155
|
-
config.externals.push({
|
|
156
|
-
esbuild: "esbuild",
|
|
157
|
-
module: "module",
|
|
158
|
-
fs: "fs",
|
|
159
|
-
chokidar: "chokidar",
|
|
160
|
-
fsevents: "fsevents"
|
|
161
|
-
});
|
|
162
|
-
config.module.rules.push({
|
|
163
|
-
test: /\.node$/,
|
|
164
|
-
loader: "node-loader"
|
|
165
|
-
});
|
|
166
|
-
config.resolve.alias = {
|
|
167
|
-
...config.resolve.alias,
|
|
168
|
-
...(0, _intlayer_config.getAlias)({
|
|
169
|
-
configuration: intlayerConfig,
|
|
170
|
-
formatter: (value) => (0, node_path.resolve)(value)
|
|
171
|
-
})
|
|
172
|
-
};
|
|
173
|
-
if (isDevCommand && isServer && nextRuntime === "nodejs") config.plugins.push(new _intlayer_webpack.IntlayerPlugin(intlayerConfig));
|
|
174
|
-
return config;
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
return config;
|
|
178
|
-
};
|
|
179
|
-
const pruneConfig = getPruneConfig(intlayerConfig, isBuildCommand, isTurbopackEnabled ?? false);
|
|
180
|
-
return (0, defu.defu)((0, defu.defu)(getNewConfig(), pruneConfig), nextConfig);
|
|
181
|
-
};
|
|
182
|
-
/**
|
|
183
|
-
* A Next.js plugin that adds the intlayer configuration to the webpack configuration
|
|
184
|
-
* and sets the environment variables
|
|
185
|
-
*
|
|
186
|
-
* Usage:
|
|
187
|
-
*
|
|
188
|
-
* ```ts
|
|
189
|
-
* // next.config.js
|
|
190
|
-
* export default withIntlayer(nextConfig)
|
|
191
|
-
* ```
|
|
192
|
-
*
|
|
193
|
-
* > Node withIntlayer is a promise function. Use withIntlayerSync instead if you want to use it synchronously.
|
|
194
|
-
* > Using the promise allows to prepare the intlayer dictionaries before the build starts.
|
|
195
|
-
*
|
|
196
|
-
*/
|
|
197
|
-
const withIntlayer = async (nextConfig = {}, configOptions) => {
|
|
198
|
-
const { isBuildCommand, isDevCommand } = getCommandsEvent();
|
|
199
|
-
const intlayerConfig = (0, _intlayer_config.getConfiguration)(configOptions);
|
|
200
|
-
const { mode } = intlayerConfig.build;
|
|
201
|
-
if (isDevCommand || isBuildCommand || mode === "auto") await (0, _intlayer_chokidar_build.prepareIntlayer)(intlayerConfig, {
|
|
202
|
-
clean: isBuildCommand,
|
|
203
|
-
cacheTimeoutMs: isBuildCommand ? 1e3 * 30 : 1e3 * 60 * 60
|
|
204
|
-
});
|
|
205
|
-
return withIntlayerSync(await nextConfig, configOptions);
|
|
206
|
-
};
|
|
207
|
-
|
|
208
|
-
//#endregion
|
|
209
|
-
exports.withIntlayer = withIntlayer;
|
|
210
|
-
exports.withIntlayerSync = withIntlayerSync;
|
|
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/utils`),a=require(`@intlayer/config/logger`),o=require(`@intlayer/config/node`),s=require(`@intlayer/config/utils`),c=require(`@intlayer/dictionaries-entry`),l=require(`@intlayer/webpack`),u=require(`defu`),d=require(`next/package.json`);d=e.__toESM(d);const f=(0,s.compareVersions)(d.default.version,`≥`,`13.0.0`),p=(0,s.compareVersions)(d.default.version,`≥`,`15.0.0`),m=(0,s.compareVersions)(d.default.version,`≥`,`16.0.0`),h=(0,s.compareVersions)(d.default.version,`≥`,`15.3.0`),g=m?!process.env.npm_lifecycle_script?.includes(`--webpack`):process.env.npm_lifecycle_script?.includes(`--turbo`),_=e=>{try{return(e.build?.require??(0,s.getProjectRequire)()).resolve(`@intlayer/swc`),!0}catch{return!1}},v=(e,t,r)=>{let i=(t.build?.require??(0,s.getProjectRequire)())?.resolve(e);return r?(0,s.normalizePath)(`./${(0,n.relative)(process.cwd(),i)}`):i},y=(e,r,o)=>{let{optimize:s}=e.build,l=e.build.importMode??e.dictionary?.importMode,{dictionariesDir:u,unmergedDictionariesDir:d,dynamicDictionariesDir:p,fetchDictionariesDir:m,mainDir:h}=e.system,{baseDir:g}=e.content,y=(0,a.getAppLogger)(e);if(s===!1||s===void 0&&!r||!f)return{};let b=_(e);if((0,i.runOnce)((0,n.join)(g,`.intlayer`,`cache`,`intlayer-prune-plugin-enabled.lock`),()=>{y(b?`Build optimization enabled`:[(0,a.colorize)(`Recommended: Install`,a.ANSIColors.GREY),(0,a.colorize)(`@intlayer/swc`,a.ANSIColors.GREY_LIGHT),(0,a.colorize)(`package to enable build optimization. See documentation: `,a.ANSIColors.GREY),(0,a.colorize)(`https://intlayer.org/docs/en/bundle_optimization`,a.ANSIColors.GREY_LIGHT)])},{cacheTimeoutMs:1e3*30}),!b)return{};let x=(0,n.join)(h,`dictionaries.mjs`),S=(0,n.join)(h,`dynamic_dictionaries.mjs`),C=(0,n.join)(h,`unmerged_dictionaries.mjs`),w=(0,n.join)(h,`fetch_dictionaries.mjs`),T=[...(0,i.getComponentTransformPatternSync)(e),x,C],E=(0,c.getDictionaries)(e),D={};return Object.values(E).forEach(e=>{D[e.key]=e.importMode??l??t.DefaultValues.Dictionary.IMPORT_MODE}),{experimental:{swcPlugins:[[v(`@intlayer/swc`,e,o),{dictionariesDir:u,dictionariesEntryPath:x,unmergedDictionariesEntryPath:C,unmergedDictionariesDir:d,dynamicDictionariesDir:p,dynamicDictionariesEntryPath:S,fetchDictionariesDir:m,fetchDictionariesEntryPath:w,importMode:l,filesList:T,replaceDictionaryEntry:!0,dictionaryModeMap:D}]]}}},b=()=>{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)}},x=(e={},t)=>{typeof e!=`object`&&(e={});let r=(0,o.getConfiguration)(t),i=(0,a.getAppLogger)(r),c=t?.enableTurbopack??g;c&&e.webpack!==void 0&&i(`Turbopack is enabled but a custom webpack config is present. It will be ignored.`);let{isBuildCommand:d,isDevCommand:m}=b(),_={resolveAlias:(0,s.getAlias)({configuration:r,formatter:e=>`./${e}`}),rules:{"*.node":{as:`*.node`,loaders:[`node-loader`]}}},v=[`esbuild`,`module`,`fs`,`chokidar`,`fsevents`],x=()=>{let t={};return p&&(t={...t,serverExternalPackages:v}),f&&!p&&(t={...t,experimental:{...t?.experimental??{},serverComponentsExternalPackages:v}}),t=c?p&&h?{...t,turbopack:_}:{...t,experimental:{...t?.experimental??{},turbo:_}}:{...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,s.getAlias)({configuration:r,formatter:e=>(0,n.resolve)(e)})},m&&a&&o===`nodejs`&&t.plugins.push(new l.IntlayerPlugin(r)),t}},t},S=y(r,d,c??!1);return(0,u.defu)((0,u.defu)(x(),S),e)},S=async(e={},t)=>{let{isBuildCommand:n,isDevCommand:i}=b(),a=(0,o.getConfiguration)(t),{mode:s}=a.build;return(i||n||s===`auto`)&&await(0,r.prepareIntlayer)(a,{clean:n,cacheTimeoutMs:n?1e3*30:1e3*60*60}),x(await e,t)};exports.withIntlayer=S,exports.withIntlayerSync=x;
|
|
211
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 {\n ANSIColors,\n colorize,\n compareVersions,\n DefaultValues,\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 { 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\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 } = 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/en/bundle_optimization',\n ANSIColors.GREY_LIGHT\n ),\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 );\n\n const intlayerNextConfig: Partial<NextConfig> = defu(\n getNewConfig(),\n pruneConfig\n );\n\n // Merge the new config with the user's config\n const result = defu(intlayerNextConfig, nextConfig) as NextConfig & T;\n\n return result;\n};\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayer(nextConfig)\n * ```\n *\n * > Node withIntlayer is a promise function. Use withIntlayerSync instead if you want to use it synchronously.\n * > Using the promise allows to prepare the intlayer dictionaries before the build starts.\n *\n */\nexport const withIntlayer = async <T extends Partial<NextConfig>>(\n nextConfig: T | Promise<T> = {} as T,\n configOptions?: WithIntlayerOptions\n): Promise<NextConfig & T> => {\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n const intlayerConfig = getConfiguration(configOptions);\n\n const { mode } = intlayerConfig.build;\n\n // Only call prepareIntlayer during `dev` or `build` (not during `start`)\n // If prod: clean and rebuild once\n // If dev: rebuild only once if it's more than 1 hour since last rebuild\n if (isDevCommand || isBuildCommand || mode === 'auto') {\n // prepareIntlayer use runOnce to ensure to run only once because will run twice on client and server side otherwise\n await prepareIntlayer(intlayerConfig, {\n clean: isBuildCommand,\n cacheTimeoutMs: isBuildCommand\n ? 1000 * 30 // 30 seconds for build (to ensure to rebuild all dictionaries)\n : 1000 * 60 * 60, // 1 hour for dev (default cache timeout)\n });\n }\n\n const nextConfigResolved = await nextConfig;\n\n return withIntlayerSync(nextConfigResolved, configOptions);\n};\n"],"mappings":";;;;;;;;;;;;;AA0BA,MAAM,oDAA8BA,0BAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,oDAA8BA,0BAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,oDAA8BA,0BAAgB,SAAS,KAAK,SAAS;AAC3E,MAAM,0DACJA,0BAAgB,SAChB,KACA,SACD;AAED,MAAM,gCAAgC,cAElC,CAAC,QAAQ,IA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AM,EAAE,SAAS,eAAe;AAKhC,KAAI,gBAAgB,kBAAkB,SAAS,OAE7C,qDAAsB,gBAAgB;EACpC,OAAO;EACP,gBAAgB,iBACZ,MAAO,KACP,MAAO,KAAK;EACjB,CAAC;AAKJ,QAAO,iBAFoB,MAAM,YAEW,cAAc"}
|
|
1
|
+
{"version":3,"file":"withIntlayer.cjs","names":["nextPackageJSON","ANSIColors","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\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 } = 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/en/bundle_optimization',\n ANSIColors.GREY_LIGHT\n ),\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 );\n\n const intlayerNextConfig: Partial<NextConfig> = defu(\n getNewConfig(),\n pruneConfig\n );\n\n // Merge the new config with the user's config\n const result = defu(intlayerNextConfig, nextConfig) as NextConfig & T;\n\n return result;\n};\n\n/**\n * A Next.js plugin that adds the intlayer configuration to the webpack configuration\n * and sets the environment variables\n *\n * Usage:\n *\n * ```ts\n * // next.config.js\n * export default withIntlayer(nextConfig)\n * ```\n *\n * > Node withIntlayer is a promise function. Use withIntlayerSync instead if you want to use it synchronously.\n * > Using the promise allows to prepare the intlayer dictionaries before the build starts.\n *\n */\nexport const withIntlayer = async <T extends Partial<NextConfig>>(\n nextConfig: T | Promise<T> = {} as T,\n configOptions?: WithIntlayerOptions\n): Promise<NextConfig & T> => {\n const { isBuildCommand, isDevCommand } = getCommandsEvent();\n const intlayerConfig = getConfiguration(configOptions);\n\n const { mode } = intlayerConfig.build;\n\n // Only call prepareIntlayer during `dev` or `build` (not during `start`)\n // If prod: clean and rebuild once\n // If dev: rebuild only once if it's more than 1 hour since last rebuild\n if (isDevCommand || isBuildCommand || mode === 'auto') {\n // prepareIntlayer use runOnce to ensure to run only once because will run twice on client and server side otherwise\n await prepareIntlayer(intlayerConfig, {\n clean: isBuildCommand,\n cacheTimeoutMs: isBuildCommand\n ? 1000 * 30 // 30 seconds for build (to ensure to rebuild all dictionaries)\n : 1000 * 60 * 60, // 1 hour for dev (default cache timeout)\n });\n }\n\n const nextConfigResolved = await nextConfig;\n\n return withIntlayerSync(nextConfigResolved, configOptions);\n};\n"],"mappings":"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,KAIL,GACJ,EACA,EACA,IACW,CAEX,IAAM,GADkB,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
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { IntlayerProvider } from "react-intlayer";
|
|
4
|
-
import { jsx } from "react/jsx-runtime";
|
|
5
|
-
|
|
6
|
-
//#region src/client/IntlayerClientProvider.tsx
|
|
7
|
-
/**
|
|
8
|
-
* Provider for client-side components in Next.js.
|
|
9
|
-
*
|
|
10
|
-
* This component wraps the `IntlayerProvider` from `react-intlayer` and is intended
|
|
11
|
-
* to be used within Next.js App Router client components.
|
|
12
|
-
*
|
|
13
|
-
* @param props - The provider props.
|
|
14
|
-
* @returns The provider component.
|
|
15
|
-
*
|
|
16
|
-
* @example
|
|
17
|
-
* ```tsx
|
|
18
|
-
* 'use client';
|
|
19
|
-
*
|
|
20
|
-
* import { IntlayerClientProvider } from 'next-intlayer';
|
|
21
|
-
*
|
|
22
|
-
* export default function ClientLayout({ children, locale }) {
|
|
23
|
-
* return (
|
|
24
|
-
* <IntlayerClientProvider locale={locale}>
|
|
25
|
-
* {children}
|
|
26
|
-
* </IntlayerClientProvider>
|
|
27
|
-
* );
|
|
28
|
-
* }
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
const IntlayerClientProvider = (props) => /* @__PURE__ */ jsx(IntlayerProvider, { ...props });
|
|
32
|
-
|
|
33
|
-
//#endregion
|
|
34
|
-
export { IntlayerClientProvider };
|
|
1
|
+
"use client";import{IntlayerProvider as e}from"react-intlayer";import{jsx as t}from"react/jsx-runtime";const n=n=>t(e,{...n});export{n as IntlayerClientProvider};
|
|
35
2
|
//# sourceMappingURL=IntlayerClientProvider.mjs.map
|
|
@@ -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":"
|
|
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,EAAA,CAAiB,GAAI,EAAA,CAAS"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export*from"react-intlayer/format";
|
|
@@ -1,6 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useLocale } from "./useLocale.mjs";
|
|
3
|
-
import { useLocalePageRouter } from "./useLocalePageRouter.mjs";
|
|
4
|
-
import { useRewriteURL } from "./useRewriteURL.mjs";
|
|
5
|
-
|
|
6
|
-
export { IntlayerClientProvider, useLocale, useLocalePageRouter, useRewriteURL };
|
|
1
|
+
import{IntlayerClientProvider as e}from"./IntlayerClientProvider.mjs";import{useLocale as t}from"./useLocale.mjs";import{useLocalePageRouter as n}from"./useLocalePageRouter.mjs";import{useRewriteURL as r}from"./useRewriteURL.mjs";export{e as IntlayerClientProvider,t as useLocale,n as useLocalePageRouter,r as useRewriteURL};
|
|
@@ -1,67 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { useLocale as useLocale$1 } from "react-intlayer";
|
|
4
|
-
import { getLocalizedUrl, getPathWithoutLocale } from "@intlayer/core";
|
|
5
|
-
import { usePathname, useRouter } from "next/navigation.js";
|
|
6
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
7
|
-
|
|
8
|
-
//#region src/client/useLocale.ts
|
|
9
|
-
const usePathWithoutLocale = () => {
|
|
10
|
-
const pathname = usePathname();
|
|
11
|
-
const [fullPath, setFullPath] = useState(pathname);
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
const search = typeof window !== "undefined" ? window.location.search : "";
|
|
14
|
-
setFullPath(search ? `${pathname}${search}` : pathname);
|
|
15
|
-
}, [pathname]);
|
|
16
|
-
return useMemo(() => getPathWithoutLocale(fullPath), [fullPath]);
|
|
17
|
-
};
|
|
18
|
-
/**
|
|
19
|
-
* Hook to manage the current locale in Next.js App Router.
|
|
20
|
-
*
|
|
21
|
-
* This hook extends the base `useLocale` from `react-intlayer` by adding
|
|
22
|
-
* Next.js-specific navigation logic for locale changes.
|
|
23
|
-
*
|
|
24
|
-
* @param props - Optional properties to configure locale change behavior.
|
|
25
|
-
* @returns An object containing the current locale, path without locale, and functions to update the locale.
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```tsx
|
|
29
|
-
* 'use client';
|
|
30
|
-
*
|
|
31
|
-
* import { useLocale } from 'next-intlayer';
|
|
32
|
-
*
|
|
33
|
-
* const LocaleSwitcher = () => {
|
|
34
|
-
* const { setLocale } = useLocale({ onChange: 'push' });
|
|
35
|
-
*
|
|
36
|
-
* return (
|
|
37
|
-
* <button onClick={() => setLocale('fr')}>Switch to French</button>
|
|
38
|
-
* );
|
|
39
|
-
* };
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
const useLocale = ({ onChange = "replace" } = {}) => {
|
|
43
|
-
const { replace, push } = useRouter();
|
|
44
|
-
const pathWithoutLocale = usePathWithoutLocale();
|
|
45
|
-
return {
|
|
46
|
-
...useLocale$1({ onLocaleChange: useCallback((locale) => {
|
|
47
|
-
if (!onChange) return;
|
|
48
|
-
if (typeof onChange === "function") {
|
|
49
|
-
onChange(locale);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
const pathWithLocale = getLocalizedUrl(pathWithoutLocale, locale);
|
|
53
|
-
if (onChange === "replace") replace(pathWithLocale);
|
|
54
|
-
if (onChange === "push") push(pathWithLocale);
|
|
55
|
-
}, [
|
|
56
|
-
replace,
|
|
57
|
-
push,
|
|
58
|
-
pathWithoutLocale,
|
|
59
|
-
onChange
|
|
60
|
-
]) }),
|
|
61
|
-
pathWithoutLocale
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
//#endregion
|
|
66
|
-
export { useLocale };
|
|
1
|
+
"use client";import{useLocale as e}from"react-intlayer";import{getLocalizedUrl as t,getPathWithoutLocale as n}from"@intlayer/core/localization";import{usePathname as r,useRouter as i}from"next/navigation.js";import{useCallback as a,useEffect as o,useMemo as s,useState as c}from"react";const l=()=>{let e=r(),[t,i]=c(e);return o(()=>{let t=typeof window<`u`?window.location.search:``;i(t?`${e}${t}`:e)},[e]),s(()=>n(t),[t])},u=({onChange:n=`replace`}={})=>{let{replace:r,push:o}=i(),s=l();return{...e({onLocaleChange:a(e=>{if(!n)return;if(typeof n==`function`){n(e);return}let i=t(s,e);n===`replace`&&r(i),n===`push`&&o(i)},[r,o,s,n])}),pathWithoutLocale:s}};export{u as useLocale};
|
|
67
2
|
//# sourceMappingURL=useLocale.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocale.mjs","names":["useLocaleReact"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"file":"useLocale.mjs","names":["useLocaleReact"],"sources":["../../../src/client/useLocale.ts"],"sourcesContent":["'use client';\n\nimport {\n getLocalizedUrl,\n getPathWithoutLocale,\n} from '@intlayer/core/localization';\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' | 'none' | ((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\n/**\n * Hook to manage the current locale in Next.js App Router.\n *\n * This hook extends the base `useLocale` from `react-intlayer` by adding\n * Next.js-specific navigation logic for locale changes.\n *\n * @param props - Optional properties to configure locale change behavior.\n * @returns An object containing the current locale, path without locale, and functions to update the locale.\n *\n * @example\n * ```tsx\n * 'use client';\n *\n * import { useLocale } from 'next-intlayer';\n *\n * const LocaleSwitcher = () => {\n * const { setLocale } = useLocale({ onChange: 'push' });\n *\n * return (\n * <button onClick={() => setLocale('fr')}>Switch to French</button>\n * );\n * };\n * ```\n */\nexport const useLocale = ({ onChange = 'replace' }: 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":"8RAeA,MAAM,MAA6B,CACjC,IAAM,EAAW,GAAa,CACxB,CAAC,EAAU,GAAe,EAAS,EAAS,CASlD,OAPA,MAAgB,CAEd,IAAM,EAAS,OAAO,OAAW,IAAc,OAAO,SAAS,OAAS,GACxE,EAAY,EAAS,GAAG,IAAW,IAAW,EAAS,EACtD,CAAC,EAAS,CAAC,CAGP,MAAc,EAAqB,EAAS,CAAE,CAAC,EAAS,CAAC,EA2BrD,GAAa,CAAE,WAAW,WAA8B,EAAE,GAAK,CAC1E,GAAM,CAAE,UAAS,QAAS,GAAW,CAC/B,EAAoB,GAAsB,CA2BhD,MAAO,CACL,GALsBA,EAAe,CACrC,eAtB0B,EACzB,GAA0B,CACzB,GAAI,CAAC,EAAU,OAEf,GAAI,OAAO,GAAa,WAAY,CAClC,EAAS,EAAO,CAChB,OAGF,IAAM,EAAiB,EAAgB,EAAmB,EAAO,CAE7D,IAAa,WACf,EAAQ,EAAe,CAErB,IAAa,QACf,EAAK,EAAe,EAGxB,CAAC,EAAS,EAAM,EAAmB,EAAS,CAC7C,CAIA,CAAC,CAIA,oBACD"}
|
|
@@ -1,44 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { useLocale } from "react-intlayer";
|
|
4
|
-
import { getLocalizedUrl, getPathWithoutLocale } from "@intlayer/core";
|
|
5
|
-
import { useCallback, useMemo } from "react";
|
|
6
|
-
import { useRouter } from "next/router.js";
|
|
7
|
-
|
|
8
|
-
//#region src/client/useLocalePageRouter.ts
|
|
9
|
-
/**
|
|
10
|
-
* Hook to manage the current locale in Next.js Page Router.
|
|
11
|
-
*
|
|
12
|
-
* This hook provides locale management functionality tailored for the Next.js Page Router,
|
|
13
|
-
* handling redirections and page reloads upon locale changes.
|
|
14
|
-
*
|
|
15
|
-
* @returns An object containing the current locale, path without locale, and functions to update the locale.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```tsx
|
|
19
|
-
* import { useLocalePageRouter } from 'next-intlayer';
|
|
20
|
-
*
|
|
21
|
-
* const MyComponent = () => {
|
|
22
|
-
* const { setLocale } = useLocalePageRouter();
|
|
23
|
-
*
|
|
24
|
-
* return (
|
|
25
|
-
* <button onClick={() => setLocale('fr')}>Switch to French</button>
|
|
26
|
-
* );
|
|
27
|
-
* };
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
const useLocalePageRouter = () => {
|
|
31
|
-
const { push, pathname, reload } = useRouter();
|
|
32
|
-
const pathWithoutLocale = useMemo(() => getPathWithoutLocale(pathname), [pathname]);
|
|
33
|
-
return {
|
|
34
|
-
...useLocale({ onLocaleChange: useCallback((locale) => {
|
|
35
|
-
push(getLocalizedUrl(pathWithoutLocale, locale));
|
|
36
|
-
return reload();
|
|
37
|
-
}, [pathWithoutLocale]) }),
|
|
38
|
-
pathWithoutLocale
|
|
39
|
-
};
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
//#endregion
|
|
43
|
-
export { useLocalePageRouter };
|
|
1
|
+
"use client";import{useLocale as e}from"react-intlayer";import{getLocalizedUrl as t,getPathWithoutLocale as n}from"@intlayer/core/localization";import{useCallback as r,useMemo as i}from"react";import{useRouter as a}from"next/router.js";const o=()=>{let{push:o,pathname:s,reload:c}=a(),l=i(()=>n(s),[s]);return{...e({onLocaleChange:r(e=>(o(t(l,e)),c()),[l])}),pathWithoutLocale:l}};export{o as useLocalePageRouter};
|
|
44
2
|
//# sourceMappingURL=useLocalePageRouter.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useLocalePageRouter.mjs","names":["useLocaleReact"],"sources":["../../../src/client/useLocalePageRouter.ts"],"sourcesContent":["'use client';\n\nimport {
|
|
1
|
+
{"version":3,"file":"useLocalePageRouter.mjs","names":["useLocaleReact"],"sources":["../../../src/client/useLocalePageRouter.ts"],"sourcesContent":["'use client';\n\nimport {\n getLocalizedUrl,\n getPathWithoutLocale,\n} from '@intlayer/core/localization';\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\n/**\n * Hook to manage the current locale in Next.js Page Router.\n *\n * This hook provides locale management functionality tailored for the Next.js Page Router,\n * handling redirections and page reloads upon locale changes.\n *\n * @returns An object containing the current locale, path without locale, and functions to update the locale.\n *\n * @example\n * ```tsx\n * import { useLocalePageRouter } from 'next-intlayer';\n *\n * const MyComponent = () => {\n * const { setLocale } = useLocalePageRouter();\n *\n * return (\n * <button onClick={() => setLocale('fr')}>Switch to French</button>\n * );\n * };\n * ```\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":"4OAgCA,MAAa,MAA4B,CACvC,GAAM,CAAE,OAAM,WAAU,UAAW,GAAW,CACxC,EAAoB,MAClB,EAAqB,EAAS,CACpC,CAAC,EAAS,CACX,CAiBD,MAAO,CACL,GALsBA,EAAe,CACrC,eAZ0B,EACzB,IAGC,EAFuB,EAAgB,EAAmB,EAAO,CAE7C,CAEb,GAAQ,EAEjB,CAAC,EAAkB,CACpB,CAIA,CAAC,CAIA,oBACD"}
|
|
@@ -1,27 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//#region src/generateStaticParams.ts
|
|
4
|
-
const { locales } = configuration.internationalization;
|
|
5
|
-
/**
|
|
6
|
-
* Generates static parameters for Next.js's dynamic routes based on the configured locales.
|
|
7
|
-
*
|
|
8
|
-
* This function is typically used in Next.js App Router for `generateStaticParams`
|
|
9
|
-
* to ensure all supported locales are pre-rendered at build time.
|
|
10
|
-
*
|
|
11
|
-
* @returns An array of objects containing the `locale` parameter for each configured locale.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* ```tsx
|
|
15
|
-
* // app/[locale]/layout.tsx
|
|
16
|
-
* export { generateStaticParams } from 'next-intlayer';
|
|
17
|
-
*
|
|
18
|
-
* export default async function RootLayout({ children, params }) {
|
|
19
|
-
* // ...
|
|
20
|
-
* }
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
const generateStaticParams = () => locales.map((locale) => ({ locale }));
|
|
24
|
-
|
|
25
|
-
//#endregion
|
|
26
|
-
export { generateStaticParams };
|
|
1
|
+
import e from"@intlayer/config/built";const{locales:t}=e.internationalization,n=()=>t.map(e=>({locale:e}));export{n as generateStaticParams};
|
|
27
2
|
//# sourceMappingURL=generateStaticParams.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateStaticParams.mjs","names":[],"sources":["../../src/generateStaticParams.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\n\nconst { locales } = configuration.internationalization;\n\n/**\n * Generates static parameters for Next.js's dynamic routes based on the configured locales.\n *\n * This function is typically used in Next.js App Router for `generateStaticParams`\n * to ensure all supported locales are pre-rendered at build time.\n *\n * @returns An array of objects containing the `locale` parameter for each configured locale.\n *\n * @example\n * ```tsx\n * // app/[locale]/layout.tsx\n * export { generateStaticParams } from 'next-intlayer';\n *\n * export default async function RootLayout({ children, params }) {\n * // ...\n * }\n * ```\n */\nexport const generateStaticParams = () => locales.map((locale) => ({ locale }));\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"generateStaticParams.mjs","names":[],"sources":["../../src/generateStaticParams.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\n\nconst { locales } = configuration.internationalization;\n\n/**\n * Generates static parameters for Next.js's dynamic routes based on the configured locales.\n *\n * This function is typically used in Next.js App Router for `generateStaticParams`\n * to ensure all supported locales are pre-rendered at build time.\n *\n * @returns An array of objects containing the `locale` parameter for each configured locale.\n *\n * @example\n * ```tsx\n * // app/[locale]/layout.tsx\n * export { generateStaticParams } from 'next-intlayer';\n *\n * export default async function RootLayout({ children, params }) {\n * // ...\n * }\n * ```\n */\nexport const generateStaticParams = () => locales.map((locale) => ({ locale }));\n"],"mappings":"sCAEA,KAAM,CAAE,WAAY,EAAc,qBAoBrB,MAA6B,EAAQ,IAAK,IAAY,CAAE,SAAQ,EAAE"}
|