1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", {
|
3 | value: true
|
4 | });
|
5 | exports.default = loadConfig;
|
6 | Object.defineProperty(exports, "DomainLocale", {
|
7 | enumerable: true,
|
8 | get: function() {
|
9 | return _configShared.DomainLocale;
|
10 | }
|
11 | });
|
12 | Object.defineProperty(exports, "NextConfig", {
|
13 | enumerable: true,
|
14 | get: function() {
|
15 | return _configShared.NextConfig;
|
16 | }
|
17 | });
|
18 | Object.defineProperty(exports, "normalizeConfig", {
|
19 | enumerable: true,
|
20 | get: function() {
|
21 | return _configShared.normalizeConfig;
|
22 | }
|
23 | });
|
24 | exports.setHttpAgentOptions = setHttpAgentOptions;
|
25 | exports.shouldUseReactRoot = void 0;
|
26 | var _path = require("path");
|
27 | var _url = require("url");
|
28 | var _http = require("http");
|
29 | var _https = require("https");
|
30 | var _semver = _interopRequireDefault(require("next/dist/compiled/semver"));
|
31 | var _findUp = _interopRequireDefault(require("next/dist/compiled/find-up"));
|
32 | var _chalk = _interopRequireDefault(require("../lib/chalk"));
|
33 | var Log = _interopRequireWildcard(require("../build/output/log"));
|
34 | var _constants = require("../shared/lib/constants");
|
35 | var _utils = require("../shared/lib/utils");
|
36 | var _configShared = require("./config-shared");
|
37 | var _configUtils = require("./config-utils");
|
38 | var _imageConfig = require("../shared/lib/image-config");
|
39 | var _env = require("@next/env");
|
40 | var _ciInfo = require("../telemetry/ci-info");
|
41 | async function loadConfig(phase, dir, customConfig) {
|
42 | await (0, _env).loadEnvConfig(dir, phase === _constants.PHASE_DEVELOPMENT_SERVER, Log);
|
43 | await (0, _configUtils).loadWebpackHook();
|
44 | let configFileName = 'next.config.js';
|
45 | if (customConfig) {
|
46 | return assignDefaults({
|
47 | configOrigin: 'server',
|
48 | configFileName,
|
49 | ...customConfig
|
50 | });
|
51 | }
|
52 | const path = await (0, _findUp).default(_constants.CONFIG_FILES, {
|
53 | cwd: dir
|
54 | });
|
55 |
|
56 | if (path === null || path === void 0 ? void 0 : path.length) {
|
57 | var ref;
|
58 | configFileName = (0, _path).basename(path);
|
59 | let userConfigModule;
|
60 | try {
|
61 |
|
62 |
|
63 |
|
64 | if (process.env.__NEXT_TEST_MODE === 'jest') {
|
65 |
|
66 |
|
67 |
|
68 | userConfigModule = require(path);
|
69 | } else {
|
70 | userConfigModule = await import((0, _url).pathToFileURL(path).href);
|
71 | }
|
72 | } catch (err) {
|
73 | Log.error(`Failed to load ${configFileName}, see more info here https://nextjs.org/docs/messages/next-config-error`);
|
74 | throw err;
|
75 | }
|
76 | const userConfig = await (0, _configShared).normalizeConfig(phase, userConfigModule.default || userConfigModule);
|
77 | if (Object.keys(userConfig).length === 0) {
|
78 | Log.warn(`Detected ${configFileName}, no exported configuration found. https://nextjs.org/docs/messages/empty-configuration`);
|
79 | }
|
80 | if (userConfig.target && !targets.includes(userConfig.target)) {
|
81 | throw new Error(`Specified target is invalid. Provided: "${userConfig.target}" should be one of ${targets.join(', ')}`);
|
82 | }
|
83 | if (userConfig.target && userConfig.target !== 'server') {
|
84 | Log.warn('The `target` config is deprecated and will be removed in a future version.\n' + 'See more info here https://nextjs.org/docs/messages/deprecated-target-config');
|
85 | }
|
86 | if ((ref = userConfig.amp) === null || ref === void 0 ? void 0 : ref.canonicalBase) {
|
87 | const { canonicalBase } = userConfig.amp || {};
|
88 | userConfig.amp = userConfig.amp || {};
|
89 | userConfig.amp.canonicalBase = (canonicalBase.endsWith('/') ? canonicalBase.slice(0, -1) : canonicalBase) || '';
|
90 | }
|
91 | if (process.env.NEXT_PRIVATE_TARGET || _ciInfo.hasNextSupport) {
|
92 | userConfig.target = process.env.NEXT_PRIVATE_TARGET || 'server';
|
93 | }
|
94 | return assignDefaults({
|
95 | configOrigin: (0, _path).relative(dir, path),
|
96 | configFile: path,
|
97 | configFileName,
|
98 | ...userConfig
|
99 | });
|
100 | } else {
|
101 | const configBaseName = (0, _path).basename(_constants.CONFIG_FILES[0], (0, _path).extname(_constants.CONFIG_FILES[0]));
|
102 | const nonJsPath = _findUp.default.sync([
|
103 | `${configBaseName}.jsx`,
|
104 | `${configBaseName}.ts`,
|
105 | `${configBaseName}.tsx`,
|
106 | `${configBaseName}.json`,
|
107 | ], {
|
108 | cwd: dir
|
109 | });
|
110 | if (nonJsPath === null || nonJsPath === void 0 ? void 0 : nonJsPath.length) {
|
111 | throw new Error(`Configuring Next.js via '${(0, _path).basename(nonJsPath)}' is not supported. Please replace the file with 'next.config.js' or 'next.config.mjs'.`);
|
112 | }
|
113 | }
|
114 |
|
115 |
|
116 | const completeConfig = assignDefaults(_configShared.defaultConfig);
|
117 | completeConfig.configFileName = configFileName;
|
118 | setHttpAgentOptions(completeConfig.httpAgentOptions);
|
119 | return completeConfig;
|
120 | }
|
121 | function _interopRequireDefault(obj) {
|
122 | return obj && obj.__esModule ? obj : {
|
123 | default: obj
|
124 | };
|
125 | }
|
126 | function _interopRequireWildcard(obj) {
|
127 | if (obj && obj.__esModule) {
|
128 | return obj;
|
129 | } else {
|
130 | var newObj = {};
|
131 | if (obj != null) {
|
132 | for(var key in obj){
|
133 | if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
134 | var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
|
135 | if (desc.get || desc.set) {
|
136 | Object.defineProperty(newObj, key, desc);
|
137 | } else {
|
138 | newObj[key] = obj[key];
|
139 | }
|
140 | }
|
141 | }
|
142 | }
|
143 | newObj.default = obj;
|
144 | return newObj;
|
145 | }
|
146 | }
|
147 | const targets = [
|
148 | 'server',
|
149 | 'serverless',
|
150 | 'experimental-serverless-trace'
|
151 | ];
|
152 | const experimentalWarning = (0, _utils).execOnce(()=>{
|
153 | Log.warn(_chalk.default.bold('You have enabled experimental feature(s).'));
|
154 | Log.warn(`Experimental features are not covered by semver, and may cause unexpected or broken application behavior. ` + `Use them at your own risk.`);
|
155 | console.warn();
|
156 | });
|
157 | function assignDefaults(userConfig) {
|
158 | var ref7, ref1, ref2, ref3;
|
159 | const configFileName = userConfig.configFileName;
|
160 | if (typeof userConfig.exportTrailingSlash !== 'undefined') {
|
161 | console.warn(_chalk.default.yellow.bold('Warning: ') + `The "exportTrailingSlash" option has been renamed to "trailingSlash". Please update your ${configFileName}.`);
|
162 | if (typeof userConfig.trailingSlash === 'undefined') {
|
163 | userConfig.trailingSlash = userConfig.exportTrailingSlash;
|
164 | }
|
165 | delete userConfig.exportTrailingSlash;
|
166 | }
|
167 | if (typeof ((ref7 = userConfig.experimental) === null || ref7 === void 0 ? void 0 : ref7.reactMode) !== 'undefined') {
|
168 | var ref4;
|
169 | console.warn(_chalk.default.yellow.bold('Warning: ') + `The experimental "reactMode" option has been replaced with "reactRoot". Please update your ${configFileName}.`);
|
170 | if (typeof ((ref4 = userConfig.experimental) === null || ref4 === void 0 ? void 0 : ref4.reactRoot) === 'undefined') {
|
171 | userConfig.experimental.reactRoot = [
|
172 | 'concurrent',
|
173 | 'blocking'
|
174 | ].includes(userConfig.experimental.reactMode);
|
175 | }
|
176 | delete userConfig.experimental.reactMode;
|
177 | }
|
178 | const config = Object.keys(userConfig).reduce((currentConfig, key)=>{
|
179 | const value = userConfig[key];
|
180 | if (value === undefined || value === null) {
|
181 | return currentConfig;
|
182 | }
|
183 | if (key === 'experimental' && value !== _configShared.defaultConfig[key] && typeof value === 'object' && Object.keys(value).length > 0) {
|
184 | experimentalWarning();
|
185 | }
|
186 | if (key === 'distDir') {
|
187 | if (typeof value !== 'string') {
|
188 | throw new Error(`Specified distDir is not a string, found type "${typeof value}"`);
|
189 | }
|
190 | const userDistDir = value.trim();
|
191 |
|
192 |
|
193 | if (userDistDir === 'public') {
|
194 | throw new Error(`The 'public' directory is reserved in Next.js and can not be set as the 'distDir'. https://nextjs.org/docs/messages/can-not-output-to-public`);
|
195 | }
|
196 |
|
197 |
|
198 | if (userDistDir.length === 0) {
|
199 | throw new Error(`Invalid distDir provided, distDir can not be an empty string. Please remove this config or set it to undefined`);
|
200 | }
|
201 | }
|
202 | if (key === 'pageExtensions') {
|
203 | if (!Array.isArray(value)) {
|
204 | throw new Error(`Specified pageExtensions is not an array of strings, found "${value}". Please update this config or remove it.`);
|
205 | }
|
206 | if (!value.length) {
|
207 | throw new Error(`Specified pageExtensions is an empty array. Please update it with the relevant extensions or remove it.`);
|
208 | }
|
209 | value.forEach((ext)=>{
|
210 | if (typeof ext !== 'string') {
|
211 | throw new Error(`Specified pageExtensions is not an array of strings, found "${ext}" of type "${typeof ext}". Please update this config or remove it.`);
|
212 | }
|
213 | });
|
214 | }
|
215 | if (!!value && value.constructor === Object) {
|
216 | currentConfig[key] = {
|
217 | ..._configShared.defaultConfig[key],
|
218 | ...Object.keys(value).reduce((c, k)=>{
|
219 | const v = value[k];
|
220 | if (v !== undefined && v !== null) {
|
221 | c[k] = v;
|
222 | }
|
223 | return c;
|
224 | }, {})
|
225 | };
|
226 | } else {
|
227 | currentConfig[key] = value;
|
228 | }
|
229 | return currentConfig;
|
230 | }, {});
|
231 | const result = {
|
232 | ..._configShared.defaultConfig,
|
233 | ...config
|
234 | };
|
235 | if (typeof result.assetPrefix !== 'string') {
|
236 | throw new Error(`Specified assetPrefix is not a string, found type "${typeof result.assetPrefix}" https://nextjs.org/docs/messages/invalid-assetprefix`);
|
237 | }
|
238 | if (typeof result.basePath !== 'string') {
|
239 | throw new Error(`Specified basePath is not a string, found type "${typeof result.basePath}"`);
|
240 | }
|
241 | if (result.basePath !== '') {
|
242 | if (result.basePath === '/') {
|
243 | throw new Error(`Specified basePath /. basePath has to be either an empty string or a path prefix"`);
|
244 | }
|
245 | if (!result.basePath.startsWith('/')) {
|
246 | throw new Error(`Specified basePath has to start with a /, found "${result.basePath}"`);
|
247 | }
|
248 | if (result.basePath !== '/') {
|
249 | var ref5;
|
250 | if (result.basePath.endsWith('/')) {
|
251 | throw new Error(`Specified basePath should not end with /, found "${result.basePath}"`);
|
252 | }
|
253 | if (result.assetPrefix === '') {
|
254 | result.assetPrefix = result.basePath;
|
255 | }
|
256 | if (((ref5 = result.amp) === null || ref5 === void 0 ? void 0 : ref5.canonicalBase) === '') {
|
257 | result.amp.canonicalBase = result.basePath;
|
258 | }
|
259 | }
|
260 | }
|
261 | const hasReactRoot = shouldUseReactRoot();
|
262 | if (hasReactRoot) {
|
263 |
|
264 | result.experimental = result.experimental || {};
|
265 | result.experimental.reactRoot = true;
|
266 | }
|
267 | if (result === null || result === void 0 ? void 0 : result.images) {
|
268 | const images = result.images;
|
269 | if (typeof images !== 'object') {
|
270 | throw new Error(`Specified images should be an object received ${typeof images}.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
|
271 | }
|
272 | if (images.domains) {
|
273 | var ref6;
|
274 | if (!Array.isArray(images.domains)) {
|
275 | throw new Error(`Specified images.domains should be an Array received ${typeof images.domains}.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
|
276 | }
|
277 |
|
278 |
|
279 |
|
280 | if ((ref6 = config.assetPrefix) === null || ref6 === void 0 ? void 0 : ref6.startsWith('http')) {
|
281 | images.domains.push(new URL(config.assetPrefix).hostname);
|
282 | }
|
283 | if (images.domains.length > 50) {
|
284 | throw new Error(`Specified images.domains exceeds length of 50, received length (${images.domains.length}), please reduce the length of the array to continue.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
|
285 | }
|
286 | const invalid = images.domains.filter((d)=>typeof d !== 'string'
|
287 | );
|
288 | if (invalid.length > 0) {
|
289 | throw new Error(`Specified images.domains should be an Array of strings received invalid values (${invalid.join(', ')}).\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
|
290 | }
|
291 | }
|
292 | if (images.deviceSizes) {
|
293 | const { deviceSizes } = images;
|
294 | if (!Array.isArray(deviceSizes)) {
|
295 | throw new Error(`Specified images.deviceSizes should be an Array received ${typeof deviceSizes}.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
|
296 | }
|
297 | if (deviceSizes.length > 25) {
|
298 | throw new Error(`Specified images.deviceSizes exceeds length of 25, received length (${deviceSizes.length}), please reduce the length of the array to continue.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
|
299 | }
|
300 | const invalid = deviceSizes.filter((d)=>{
|
301 | return typeof d !== 'number' || d < 1 || d > 10000;
|
302 | });
|
303 | if (invalid.length > 0) {
|
304 | throw new Error(`Specified images.deviceSizes should be an Array of numbers that are between 1 and 10000, received invalid values (${invalid.join(', ')}).\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
|
305 | }
|
306 | }
|
307 | if (images.imageSizes) {
|
308 | const { imageSizes } = images;
|
309 | if (!Array.isArray(imageSizes)) {
|
310 | throw new Error(`Specified images.imageSizes should be an Array received ${typeof imageSizes}.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
|
311 | }
|
312 | if (imageSizes.length > 25) {
|
313 | throw new Error(`Specified images.imageSizes exceeds length of 25, received length (${imageSizes.length}), please reduce the length of the array to continue.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
|
314 | }
|
315 | const invalid = imageSizes.filter((d)=>{
|
316 | return typeof d !== 'number' || d < 1 || d > 10000;
|
317 | });
|
318 | if (invalid.length > 0) {
|
319 | throw new Error(`Specified images.imageSizes should be an Array of numbers that are between 1 and 10000, received invalid values (${invalid.join(', ')}).\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
|
320 | }
|
321 | }
|
322 | if (!images.loader) {
|
323 | images.loader = 'default';
|
324 | }
|
325 | if (!_imageConfig.VALID_LOADERS.includes(images.loader)) {
|
326 | throw new Error(`Specified images.loader should be one of (${_imageConfig.VALID_LOADERS.join(', ')}), received invalid value (${images.loader}).\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
|
327 | }
|
328 | if (images.loader !== 'default' && images.loader !== 'custom' && images.path === _imageConfig.imageConfigDefault.path) {
|
329 | throw new Error(`Specified images.loader property (${images.loader}) also requires images.path property to be assigned to a URL prefix.\nSee more info here: https://nextjs.org/docs/api-reference/next/image#loader-configuration`);
|
330 | }
|
331 |
|
332 | if (images.path) {
|
333 | if (images.loader !== 'default' && images.path[images.path.length - 1] !== '/' || result.trailingSlash) {
|
334 | images.path += '/';
|
335 | }
|
336 | }
|
337 | if (images.path === _imageConfig.imageConfigDefault.path && result.basePath) {
|
338 | images.path = `${result.basePath}${images.path}`;
|
339 | }
|
340 | if (images.minimumCacheTTL && (!Number.isInteger(images.minimumCacheTTL) || images.minimumCacheTTL < 0)) {
|
341 | throw new Error(`Specified images.minimumCacheTTL should be an integer 0 or more
|
342 | ', '
|
343 | )}), received (${images.minimumCacheTTL}).\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
|
344 | }
|
345 | if (images.formats) {
|
346 | const { formats } = images;
|
347 | if (!Array.isArray(formats)) {
|
348 | throw new Error(`Specified images.formats should be an Array received ${typeof formats}.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
|
349 | }
|
350 | if (formats.length < 1 || formats.length > 2) {
|
351 | throw new Error(`Specified images.formats must be length 1 or 2, received length (${formats.length}), please reduce the length of the array to continue.\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
|
352 | }
|
353 | const invalid = formats.filter((f)=>{
|
354 | return f !== 'image/avif' && f !== 'image/webp';
|
355 | });
|
356 | if (invalid.length > 0) {
|
357 | throw new Error(`Specified images.formats should be an Array of mime type strings, received invalid values (${invalid.join(', ')}).\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
|
358 | }
|
359 | }
|
360 | if (typeof images.dangerouslyAllowSVG !== 'undefined' && typeof images.dangerouslyAllowSVG !== 'boolean') {
|
361 | throw new Error(`Specified images.dangerouslyAllowSVG should be a boolean
|
362 | ', '
|
363 | )}), received (${images.dangerouslyAllowSVG}).\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
|
364 | }
|
365 | if (typeof images.contentSecurityPolicy !== 'undefined' && typeof images.contentSecurityPolicy !== 'string') {
|
366 | throw new Error(`Specified images.contentSecurityPolicy should be a string
|
367 | ', '
|
368 | )}), received (${images.contentSecurityPolicy}).\nSee more info here: https://nextjs.org/docs/messages/invalid-images-config`);
|
369 | }
|
370 | }
|
371 | if (result.webpack5 === false) {
|
372 | throw new Error(`Webpack 4 is no longer supported in Next.js. Please upgrade to webpack 5 by removing "webpack5: false" from ${configFileName}. https://nextjs.org/docs/messages/webpack5`);
|
373 | }
|
374 | if (result.experimental && 'swcMinify' in result.experimental) {
|
375 | Log.warn(`\`swcMinify\` has been moved out of \`experimental\`. Please update your ${configFileName} file accordingly.`);
|
376 | result.swcMinify = result.experimental.swcMinify;
|
377 | }
|
378 | if (result.experimental && 'relay' in result.experimental) {
|
379 | Log.warn(`\`relay\` has been moved out of \`experimental\` and into \`compiler\`. Please update your ${configFileName} file accordingly.`);
|
380 | result.compiler = result.compiler || {};
|
381 | result.compiler.relay = result.experimental.relay;
|
382 | }
|
383 | if (result.experimental && 'styledComponents' in result.experimental) {
|
384 | Log.warn(`\`styledComponents\` has been moved out of \`experimental\` and into \`compiler\`. Please update your ${configFileName} file accordingly.`);
|
385 | result.compiler = result.compiler || {};
|
386 | result.compiler.styledComponents = result.experimental.styledComponents;
|
387 | }
|
388 | if (result.experimental && 'reactRemoveProperties' in result.experimental) {
|
389 | Log.warn(`\`reactRemoveProperties\` has been moved out of \`experimental\` and into \`compiler\`. Please update your ${configFileName} file accordingly.`);
|
390 | result.compiler = result.compiler || {};
|
391 | result.compiler.reactRemoveProperties = result.experimental.reactRemoveProperties;
|
392 | }
|
393 | if (result.experimental && 'removeConsole' in result.experimental) {
|
394 | Log.warn(`\`removeConsole\` has been moved out of \`experimental\` and into \`compiler\`. Please update your ${configFileName} file accordingly.`);
|
395 | result.compiler = result.compiler || {};
|
396 | result.compiler.removeConsole = result.experimental.removeConsole;
|
397 | }
|
398 | if (result.swcMinify) {
|
399 | Log.warn('SWC minify release candidate enabled. https://nextjs.org/docs/messages/swc-minify-enabled');
|
400 | }
|
401 | if (((ref1 = result.experimental) === null || ref1 === void 0 ? void 0 : ref1.outputFileTracingRoot) && !(0, _path).isAbsolute(result.experimental.outputFileTracingRoot)) {
|
402 | result.experimental.outputFileTracingRoot = (0, _path).resolve(result.experimental.outputFileTracingRoot);
|
403 | Log.warn(`experimental.outputFileTracingRoot should be absolute, using: ${result.experimental.outputFileTracingRoot}`);
|
404 | }
|
405 | if (((ref2 = result.experimental) === null || ref2 === void 0 ? void 0 : ref2.outputStandalone) && !result.outputFileTracing) {
|
406 | Log.warn(`experimental.outputStandalone requires outputFileTracing not be disabled please enable it to leverage the standalone build`);
|
407 | result.experimental.outputStandalone = false;
|
408 | }
|
409 |
|
410 |
|
411 | setHttpAgentOptions(result.httpAgentOptions || _configShared.defaultConfig.httpAgentOptions);
|
412 | if (result.i18n) {
|
413 | const { i18n } = result;
|
414 | const i18nType = typeof i18n;
|
415 | if (i18nType !== 'object') {
|
416 | throw new Error(`Specified i18n should be an object received ${i18nType}.\nSee more info here: https://nextjs.org/docs/messages/invalid-i18n-config`);
|
417 | }
|
418 | if (!Array.isArray(i18n.locales)) {
|
419 | throw new Error(`Specified i18n.locales should be an Array received ${typeof i18n.locales}.\nSee more info here: https://nextjs.org/docs/messages/invalid-i18n-config`);
|
420 | }
|
421 | if (i18n.locales.length > 100) {
|
422 | Log.warn(`Received ${i18n.locales.length} i18n.locales items which exceeds the recommended max of 100.\nSee more info here: https://nextjs.org/docs/advanced-features/i18n-routing#how-does-this-work-with-static-generation`);
|
423 | }
|
424 | const defaultLocaleType = typeof i18n.defaultLocale;
|
425 | if (!i18n.defaultLocale || defaultLocaleType !== 'string') {
|
426 | throw new Error(`Specified i18n.defaultLocale should be a string.\nSee more info here: https://nextjs.org/docs/messages/invalid-i18n-config`);
|
427 | }
|
428 | if (typeof i18n.domains !== 'undefined' && !Array.isArray(i18n.domains)) {
|
429 | throw new Error(`Specified i18n.domains must be an array of domain objects e.g. [ { domain: 'example.fr', defaultLocale: 'fr', locales: ['fr'] } ] received ${typeof i18n.domains}.\nSee more info here: https://nextjs.org/docs/messages/invalid-i18n-config`);
|
430 | }
|
431 | if (i18n.domains) {
|
432 | const invalidDomainItems = i18n.domains.filter((item)=>{
|
433 | var ref;
|
434 | if (!item || typeof item !== 'object') return true;
|
435 | if (!item.defaultLocale) return true;
|
436 | if (!item.domain || typeof item.domain !== 'string') return true;
|
437 | const defaultLocaleDuplicate = (ref = i18n.domains) === null || ref === void 0 ? void 0 : ref.find((altItem)=>altItem.defaultLocale === item.defaultLocale && altItem.domain !== item.domain
|
438 | );
|
439 | if (defaultLocaleDuplicate) {
|
440 | console.warn(`Both ${item.domain} and ${defaultLocaleDuplicate.domain} configured the defaultLocale ${item.defaultLocale} but only one can. Change one item's default locale to continue`);
|
441 | return true;
|
442 | }
|
443 | let hasInvalidLocale = false;
|
444 | if (Array.isArray(item.locales)) {
|
445 | for (const locale of item.locales){
|
446 | if (typeof locale !== 'string') hasInvalidLocale = true;
|
447 | for (const domainItem of i18n.domains || []){
|
448 | if (domainItem === item) continue;
|
449 | if (domainItem.locales && domainItem.locales.includes(locale)) {
|
450 | console.warn(`Both ${item.domain} and ${domainItem.domain} configured the locale (${locale}) but only one can. Remove it from one i18n.domains config to continue`);
|
451 | hasInvalidLocale = true;
|
452 | break;
|
453 | }
|
454 | }
|
455 | }
|
456 | }
|
457 | return hasInvalidLocale;
|
458 | });
|
459 | if (invalidDomainItems.length > 0) {
|
460 | throw new Error(`Invalid i18n.domains values:\n${invalidDomainItems.map((item)=>JSON.stringify(item)
|
461 | ).join('\n')}\n\ndomains value must follow format { domain: 'example.fr', defaultLocale: 'fr', locales: ['fr'] }.\nSee more info here: https://nextjs.org/docs/messages/invalid-i18n-config`);
|
462 | }
|
463 | }
|
464 | if (!Array.isArray(i18n.locales)) {
|
465 | throw new Error(`Specified i18n.locales must be an array of locale strings e.g. ["en-US", "nl-NL"] received ${typeof i18n.locales}.\nSee more info here: https://nextjs.org/docs/messages/invalid-i18n-config`);
|
466 | }
|
467 | const invalidLocales = i18n.locales.filter((locale)=>typeof locale !== 'string'
|
468 | );
|
469 | if (invalidLocales.length > 0) {
|
470 | throw new Error(`Specified i18n.locales contains invalid values (${invalidLocales.map(String).join(', ')}), locales must be valid locale tags provided as strings e.g. "en-US".\n` + `See here for list of valid language sub-tags: http://www.iana.org/assignments/language-subtag-registry/language-subtag-registry`);
|
471 | }
|
472 | if (!i18n.locales.includes(i18n.defaultLocale)) {
|
473 | throw new Error(`Specified i18n.defaultLocale should be included in i18n.locales.\nSee more info here: https://nextjs.org/docs/messages/invalid-i18n-config`);
|
474 | }
|
475 |
|
476 | i18n.locales = [
|
477 | i18n.defaultLocale,
|
478 | ...i18n.locales.filter((locale)=>locale !== i18n.defaultLocale
|
479 | ),
|
480 | ];
|
481 | const localeDetectionType = typeof i18n.localeDetection;
|
482 | if (localeDetectionType !== 'boolean' && localeDetectionType !== 'undefined') {
|
483 | throw new Error(`Specified i18n.localeDetection should be undefined or a boolean received ${localeDetectionType}.\nSee more info here: https://nextjs.org/docs/messages/invalid-i18n-config`);
|
484 | }
|
485 | }
|
486 | if ((ref3 = result.experimental) === null || ref3 === void 0 ? void 0 : ref3.serverComponents) {
|
487 | const pageExtensions = [];
|
488 | (result.pageExtensions || []).forEach((ext)=>{
|
489 | pageExtensions.push(ext);
|
490 | pageExtensions.push(`server.${ext}`);
|
491 | pageExtensions.push(`client.${ext}`);
|
492 | });
|
493 | result.pageExtensions = pageExtensions;
|
494 | }
|
495 | return result;
|
496 | }
|
497 | const shouldUseReactRoot = (0, _utils).execOnce(()=>{
|
498 | var ref;
|
499 | const reactDomVersion = require('react-dom').version;
|
500 | const isReactExperimental = Boolean(reactDomVersion && /0\.0\.0-experimental/.test(reactDomVersion));
|
501 | const hasReact18 = Boolean(reactDomVersion) && (_semver.default.gte(reactDomVersion, '18.0.0') || ((ref = _semver.default.coerce(reactDomVersion)) === null || ref === void 0 ? void 0 : ref.version) === '18.0.0');
|
502 | return hasReact18 || isReactExperimental;
|
503 | });
|
504 | exports.shouldUseReactRoot = shouldUseReactRoot;
|
505 | function setHttpAgentOptions(options) {
|
506 | if (global.__NEXT_HTTP_AGENT) {
|
507 |
|
508 |
|
509 | return;
|
510 | }
|
511 | if (!options) {
|
512 | throw new Error('Expected config.httpAgentOptions to be an object');
|
513 | }
|
514 | global.__NEXT_HTTP_AGENT = new _http.Agent(options);
|
515 | global.__NEXT_HTTPS_AGENT = new _https.Agent(options);
|
516 | }
|
517 |
|
518 |
|
\ | No newline at end of file |