@netlify/config 15.7.2 → 15.8.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/package.json +3 -2
- package/src/functions_config.js +1 -0
- package/src/log/messages.js +4 -5
- package/src/main.js +1 -1
- package/src/mutations/update.js +3 -3
- package/src/parse.js +9 -9
- package/src/validate/validations.js +22 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/config",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.8.0",
|
|
4
4
|
"description": "Netlify config module",
|
|
5
5
|
"main": "src/main.js",
|
|
6
6
|
"bin": {
|
|
@@ -52,6 +52,7 @@
|
|
|
52
52
|
"@ungap/from-entries": "^0.2.1",
|
|
53
53
|
"array-flat-polyfill": "^1.0.1",
|
|
54
54
|
"chalk": "^4.1.2",
|
|
55
|
+
"cron-parser": "^4.1.0",
|
|
55
56
|
"deepmerge": "^4.2.2",
|
|
56
57
|
"dot-prop": "^5.3.0",
|
|
57
58
|
"execa": "^5.1.1",
|
|
@@ -64,7 +65,7 @@
|
|
|
64
65
|
"js-yaml": "^4.0.0",
|
|
65
66
|
"make-dir": "^3.1.0",
|
|
66
67
|
"map-obj": "^4.0.0",
|
|
67
|
-
"netlify": "^8.0.
|
|
68
|
+
"netlify": "^8.0.3",
|
|
68
69
|
"netlify-headers-parser": "^4.0.1",
|
|
69
70
|
"netlify-redirect-parser": "^11.0.2",
|
|
70
71
|
"omit.js": "^2.0.2",
|
package/src/functions_config.js
CHANGED
package/src/log/messages.js
CHANGED
|
@@ -4,11 +4,10 @@ const { throwUserError } = require('../error')
|
|
|
4
4
|
|
|
5
5
|
const { logWarning } = require('./logger')
|
|
6
6
|
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
logs,
|
|
7
|
+
const throwOnInvalidTomlSequence = function (invalidSequence) {
|
|
8
|
+
throwUserError(
|
|
10
9
|
`In netlify.toml, the following backslash should be escaped: ${invalidSequence}
|
|
11
|
-
The following
|
|
10
|
+
The following should be used instead: \\${invalidSequence}`,
|
|
12
11
|
)
|
|
13
12
|
}
|
|
14
13
|
|
|
@@ -127,7 +126,7 @@ const getErrorMessage = function ({ message }) {
|
|
|
127
126
|
}
|
|
128
127
|
|
|
129
128
|
module.exports = {
|
|
130
|
-
|
|
129
|
+
throwOnInvalidTomlSequence,
|
|
131
130
|
warnLegacyFunctionsDirectory,
|
|
132
131
|
warnContextPluginConfig,
|
|
133
132
|
throwContextPluginsConfig,
|
package/src/main.js
CHANGED
|
@@ -220,7 +220,7 @@ const getFullConfig = async function ({
|
|
|
220
220
|
const configPath = await getConfigPath({ configOpt, cwd, repositoryRoot, configBase })
|
|
221
221
|
|
|
222
222
|
try {
|
|
223
|
-
const config = await parseConfig(configPath
|
|
223
|
+
const config = await parseConfig(configPath)
|
|
224
224
|
const configA = mergeAndNormalizeConfig({
|
|
225
225
|
config,
|
|
226
226
|
defaultConfig,
|
package/src/mutations/update.js
CHANGED
|
@@ -32,7 +32,7 @@ const updateConfig = async function (
|
|
|
32
32
|
|
|
33
33
|
const inlineConfig = applyMutations({}, configMutations)
|
|
34
34
|
const normalizedInlineConfig = ensureConfigPriority(inlineConfig, context, branch)
|
|
35
|
-
const updatedConfig = await mergeWithConfig(
|
|
35
|
+
const updatedConfig = await mergeWithConfig(normalizedInlineConfig, configPath)
|
|
36
36
|
const configWithHeaders = await addHeaders(updatedConfig, headersPath, logs)
|
|
37
37
|
const finalConfig = await addRedirects(configWithHeaders, redirectsPath, logs)
|
|
38
38
|
const simplifiedConfig = simplifyConfig(finalConfig)
|
|
@@ -45,8 +45,8 @@ const updateConfig = async function (
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
// If `netlify.toml` exists, deeply merges the configuration changes.
|
|
48
|
-
const mergeWithConfig = async function (
|
|
49
|
-
const config = await parseOptionalConfig(configPath
|
|
48
|
+
const mergeWithConfig = async function (normalizedInlineConfig, configPath) {
|
|
49
|
+
const config = await parseOptionalConfig(configPath)
|
|
50
50
|
const updatedConfig = mergeConfigs([config, normalizedInlineConfig])
|
|
51
51
|
return updatedConfig
|
|
52
52
|
}
|
package/src/parse.js
CHANGED
|
@@ -6,13 +6,13 @@ const { promisify } = require('util')
|
|
|
6
6
|
const pathExists = require('path-exists')
|
|
7
7
|
|
|
8
8
|
const { throwUserError } = require('./error')
|
|
9
|
-
const {
|
|
9
|
+
const { throwOnInvalidTomlSequence } = require('./log/messages')
|
|
10
10
|
const { parseToml } = require('./utils/toml')
|
|
11
11
|
|
|
12
12
|
const pReadFile = promisify(readFile)
|
|
13
13
|
|
|
14
14
|
// Load the configuration file and parse it (TOML)
|
|
15
|
-
const parseConfig = async function (configPath
|
|
15
|
+
const parseConfig = async function (configPath) {
|
|
16
16
|
if (configPath === undefined) {
|
|
17
17
|
return {}
|
|
18
18
|
}
|
|
@@ -21,23 +21,23 @@ const parseConfig = async function (configPath, logs) {
|
|
|
21
21
|
throwUserError('Configuration file does not exist')
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
return await readConfigPath(configPath
|
|
24
|
+
return await readConfigPath(configPath)
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
// Same but `configPath` is required and `configPath` might point to a
|
|
28
28
|
// non-existing file.
|
|
29
|
-
const parseOptionalConfig = async function (configPath
|
|
29
|
+
const parseOptionalConfig = async function (configPath) {
|
|
30
30
|
if (!(await pathExists(configPath))) {
|
|
31
31
|
return {}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
return await readConfigPath(configPath
|
|
34
|
+
return await readConfigPath(configPath)
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
const readConfigPath = async function (configPath
|
|
37
|
+
const readConfigPath = async function (configPath) {
|
|
38
38
|
const configString = await readConfig(configPath)
|
|
39
39
|
|
|
40
|
-
validateTomlBlackslashes(
|
|
40
|
+
validateTomlBlackslashes(configString)
|
|
41
41
|
|
|
42
42
|
try {
|
|
43
43
|
return parseToml(configString)
|
|
@@ -55,14 +55,14 @@ const readConfig = async function (configPath) {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
const validateTomlBlackslashes = function (
|
|
58
|
+
const validateTomlBlackslashes = function (configString) {
|
|
59
59
|
const result = INVALID_TOML_BLACKSLASH.exec(configString)
|
|
60
60
|
if (result === null) {
|
|
61
61
|
return
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
const [, invalidTripleSequence, invalidSequence = invalidTripleSequence] = result
|
|
65
|
-
|
|
65
|
+
throwOnInvalidTomlSequence(invalidSequence)
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
// The TOML specification forbids unrecognized backslash sequences. However,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable max-lines */
|
|
2
2
|
'use strict'
|
|
3
3
|
|
|
4
|
+
const CronParser = require('cron-parser')
|
|
4
5
|
const isPlainObj = require('is-plain-obj')
|
|
5
6
|
const validateNpmPackageName = require('validate-npm-package-name')
|
|
6
7
|
|
|
@@ -8,6 +9,19 @@ const { bundlers, WILDCARD_ALL: FUNCTIONS_CONFIG_WILDCARD_ALL } = require('../fu
|
|
|
8
9
|
|
|
9
10
|
const { functionsDirectoryCheck, isArrayOfObjects, isArrayOfStrings, isString, validProperties } = require('./helpers')
|
|
10
11
|
|
|
12
|
+
/**
|
|
13
|
+
* @param {string} cron
|
|
14
|
+
* @returns {boolean}
|
|
15
|
+
*/
|
|
16
|
+
const isValidCronExpression = (cron) => {
|
|
17
|
+
try {
|
|
18
|
+
CronParser.parseExpression(cron)
|
|
19
|
+
return true
|
|
20
|
+
} catch (error) {
|
|
21
|
+
return false
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
11
25
|
// List of validations performed on the configuration file.
|
|
12
26
|
// Validation are performed in order: parent should be before children.
|
|
13
27
|
// Each validation is an object with the following properties:
|
|
@@ -212,6 +226,14 @@ const POST_NORMALIZE_VALIDATIONS = [
|
|
|
212
226
|
functions: { directory: 'my-functions' },
|
|
213
227
|
}),
|
|
214
228
|
},
|
|
229
|
+
{
|
|
230
|
+
property: 'functions.*.schedule',
|
|
231
|
+
check: isValidCronExpression,
|
|
232
|
+
message: 'must be a valid cron expression (see https://ntl.fyi/cron-syntax).',
|
|
233
|
+
example: (value, key, prevPath) => ({
|
|
234
|
+
functions: { [prevPath[1]]: { schedule: '5 4 * * *' } },
|
|
235
|
+
}),
|
|
236
|
+
},
|
|
215
237
|
{
|
|
216
238
|
property: 'functionsDirectory',
|
|
217
239
|
check: isString,
|