@netlify/config 25.2.7 → 25.3.0
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/lib/normalize.js +20 -3
- package/lib/validate/validations.d.ts +47 -0
- package/lib/validate/validations.js +41 -0
- package/package.json +3 -3
package/lib/normalize.js
CHANGED
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
import { normalizeFunctionsProps, WILDCARD_ALL } from './functions_config.js';
|
|
2
2
|
import { mergeConfigs } from './merge.js';
|
|
3
3
|
import { DEFAULT_ORIGIN } from './origin.js';
|
|
4
|
-
import { removeFalsy } from './utils/remove_falsy.js';
|
|
4
|
+
import { removeFalsy, removeUndefined } from './utils/remove_falsy.js';
|
|
5
5
|
/**
|
|
6
6
|
* Normalize configuration object
|
|
7
7
|
*/
|
|
8
8
|
export const normalizeConfig = function (config, packagePath) {
|
|
9
9
|
const configA = removeEmpty(config);
|
|
10
|
-
const { build, functions, plugins, ...configB } = mergeConfigs([
|
|
10
|
+
const { build, functions, plugins, server, ...configB } = mergeConfigs([
|
|
11
|
+
DEFAULT_CONFIG(packagePath),
|
|
12
|
+
configA,
|
|
13
|
+
]);
|
|
11
14
|
const { build: buildA, functions: functionsA, functionsDirectoryProps } = normalizeFunctionsProps(build, functions);
|
|
12
15
|
const pluginsA = plugins.map(normalizePlugin);
|
|
13
|
-
|
|
16
|
+
const serverProps = server === undefined ? {} : { server: normalizeServer(server) };
|
|
17
|
+
return {
|
|
18
|
+
...configB,
|
|
19
|
+
build: buildA,
|
|
20
|
+
functions: functionsA,
|
|
21
|
+
plugins: pluginsA,
|
|
22
|
+
...serverProps,
|
|
23
|
+
...functionsDirectoryProps,
|
|
24
|
+
};
|
|
14
25
|
};
|
|
15
26
|
/**
|
|
16
27
|
* Remove empty strings.
|
|
@@ -34,3 +45,9 @@ const DEFAULT_CONFIG = (packagePath) => ({
|
|
|
34
45
|
const normalizePlugin = function ({ inputs = {}, ...plugin }) {
|
|
35
46
|
return removeFalsy({ ...plugin, inputs });
|
|
36
47
|
};
|
|
48
|
+
const lowerCase = (value) => (typeof value === 'string' ? value.toLowerCase() : value);
|
|
49
|
+
// `region` and `size` take a fixed set of values, which can be written in any
|
|
50
|
+
// case.
|
|
51
|
+
const normalizeServer = function ({ region, size, ...server }) {
|
|
52
|
+
return removeUndefined({ ...server, region: lowerCase(region), size: lowerCase(size) });
|
|
53
|
+
};
|
|
@@ -118,6 +118,16 @@ export const PRE_NORMALIZE_VALIDATIONS: ({
|
|
|
118
118
|
};
|
|
119
119
|
};
|
|
120
120
|
};
|
|
121
|
+
} | {
|
|
122
|
+
property: string;
|
|
123
|
+
check: typeof isPlainObj;
|
|
124
|
+
message: string;
|
|
125
|
+
example: () => {
|
|
126
|
+
server: {
|
|
127
|
+
path: string;
|
|
128
|
+
size: string;
|
|
129
|
+
};
|
|
130
|
+
};
|
|
121
131
|
})[];
|
|
122
132
|
export const POST_NORMALIZE_VALIDATIONS: ({
|
|
123
133
|
example: () => {
|
|
@@ -367,5 +377,42 @@ export const POST_NORMALIZE_VALIDATIONS: ({
|
|
|
367
377
|
};
|
|
368
378
|
};
|
|
369
379
|
};
|
|
380
|
+
} | {
|
|
381
|
+
property: string;
|
|
382
|
+
check: (value: any) => boolean;
|
|
383
|
+
message: string;
|
|
384
|
+
example: () => {
|
|
385
|
+
server: {
|
|
386
|
+
path: string[];
|
|
387
|
+
};
|
|
388
|
+
};
|
|
389
|
+
} | {
|
|
390
|
+
property: string;
|
|
391
|
+
check: (value: any) => boolean;
|
|
392
|
+
message: string;
|
|
393
|
+
example: () => {
|
|
394
|
+
server: {
|
|
395
|
+
path: string;
|
|
396
|
+
excludedPath: string[];
|
|
397
|
+
};
|
|
398
|
+
};
|
|
399
|
+
} | {
|
|
400
|
+
property: string;
|
|
401
|
+
check: (value: any) => boolean;
|
|
402
|
+
message: string;
|
|
403
|
+
example: () => {
|
|
404
|
+
server: {
|
|
405
|
+
region: string;
|
|
406
|
+
};
|
|
407
|
+
};
|
|
408
|
+
} | {
|
|
409
|
+
property: string;
|
|
410
|
+
check: (value: any) => boolean;
|
|
411
|
+
message: string;
|
|
412
|
+
example: () => {
|
|
413
|
+
server: {
|
|
414
|
+
size: string;
|
|
415
|
+
};
|
|
416
|
+
};
|
|
370
417
|
})[];
|
|
371
418
|
import isPlainObj from 'is-plain-obj';
|
|
@@ -31,6 +31,11 @@ const isValidFunctionMemory = (value) => {
|
|
|
31
31
|
}
|
|
32
32
|
return Number.isInteger(megabytes) && megabytes >= FUNCTION_MEMORY_MIN_MB && megabytes <= FUNCTION_MEMORY_MAX_MB;
|
|
33
33
|
};
|
|
34
|
+
const SERVER_PROPERTIES = ['excludedPath', 'path', 'region', 'size'];
|
|
35
|
+
const SERVER_REGIONS = ['cmh', 'fra'];
|
|
36
|
+
const SERVER_SIZES = ['small', 'medium', 'large'];
|
|
37
|
+
const isServerPath = (value) => isString(value) && value.startsWith('/');
|
|
38
|
+
const isServerPaths = (value) => isServerPath(value) || (Array.isArray(value) && value.every(isServerPath));
|
|
34
39
|
// List of validations performed on the configuration file.
|
|
35
40
|
// Validation are performed in order: parent should be before children.
|
|
36
41
|
// Each validation is an object with the following properties:
|
|
@@ -148,6 +153,12 @@ export const PRE_NORMALIZE_VALIDATIONS = [
|
|
|
148
153
|
message: 'must be a plain object.',
|
|
149
154
|
example: () => ({ database: { migrations: { path: 'netlify/database/migrations' } } }),
|
|
150
155
|
},
|
|
156
|
+
{
|
|
157
|
+
property: 'server',
|
|
158
|
+
check: isPlainObj,
|
|
159
|
+
message: 'must be a plain object.',
|
|
160
|
+
example: () => ({ server: { path: '/api/*', size: 'small' } }),
|
|
161
|
+
},
|
|
151
162
|
];
|
|
152
163
|
const EXAMPLE_PORT = 80;
|
|
153
164
|
// Validations done after normalization
|
|
@@ -340,5 +351,35 @@ export const POST_NORMALIZE_VALIDATIONS = [
|
|
|
340
351
|
message: 'must be a string.',
|
|
341
352
|
example: () => ({ database: { migrations: { path: 'netlify/database/migrations' } } }),
|
|
342
353
|
},
|
|
354
|
+
{
|
|
355
|
+
property: 'server',
|
|
356
|
+
...validProperties(SERVER_PROPERTIES, []),
|
|
357
|
+
example: () => ({ server: { path: '/api/*', size: 'small' } }),
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
property: 'server.path',
|
|
361
|
+
check: isServerPaths,
|
|
362
|
+
message: 'must be a path starting with "/", or an array of them.',
|
|
363
|
+
example: () => ({ server: { path: ['/api/*', '/auth/callback'] } }),
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
property: 'server.excludedPath',
|
|
367
|
+
check: isServerPaths,
|
|
368
|
+
message: 'must be a path starting with "/", or an array of them.',
|
|
369
|
+
example: () => ({ server: { path: '/api/*', excludedPath: ['/api/internal', '/api/admin/*'] } }),
|
|
370
|
+
},
|
|
371
|
+
// Region and size are lowercased during normalization.
|
|
372
|
+
{
|
|
373
|
+
property: 'server.region',
|
|
374
|
+
check: (value) => SERVER_REGIONS.includes(value),
|
|
375
|
+
message: `must be one of: ${SERVER_REGIONS.join(', ')}`,
|
|
376
|
+
example: () => ({ server: { region: SERVER_REGIONS[0] } }),
|
|
377
|
+
},
|
|
378
|
+
{
|
|
379
|
+
property: 'server.size',
|
|
380
|
+
check: (value) => SERVER_SIZES.includes(value),
|
|
381
|
+
message: `must be one of: ${SERVER_SIZES.join(', ')}`,
|
|
382
|
+
example: () => ({ server: { size: SERVER_SIZES[0] } }),
|
|
383
|
+
},
|
|
343
384
|
...edgeFunctionValidations,
|
|
344
385
|
];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/config",
|
|
3
|
-
"version": "25.
|
|
3
|
+
"version": "25.3.0",
|
|
4
4
|
"description": "Netlify config module",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./lib/index.js",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
},
|
|
59
59
|
"license": "MIT",
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@netlify/api": "^15.1.
|
|
61
|
+
"@netlify/api": "^15.1.3",
|
|
62
62
|
"@netlify/headers-parser": "^10.1.1",
|
|
63
63
|
"@netlify/redirect-parser": "^16.1.1",
|
|
64
64
|
"chalk": "^6.0.0",
|
|
@@ -94,5 +94,5 @@
|
|
|
94
94
|
"engines": {
|
|
95
95
|
"node": ">=22.12.0"
|
|
96
96
|
},
|
|
97
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "19447a3826a8d26af1bcdc704754e8a8586597f1"
|
|
98
98
|
}
|