@netlify/config 16.0.6 → 17.0.2
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/README.md +4 -4
- package/package.json +6 -5
- package/src/api/build_settings.js +2 -6
- package/src/api/client.js +3 -9
- package/src/api/site_info.js +2 -6
- package/src/base.js +4 -8
- package/src/bin/flags.js +5 -8
- package/src/bin/main.js +12 -13
- package/src/build_dir.js +3 -7
- package/src/cached_config.js +3 -7
- package/src/case.js +1 -5
- package/src/context.js +9 -13
- package/src/default.js +3 -7
- package/src/env/git.js +3 -7
- package/src/env/main.js +5 -9
- package/src/error.js +2 -6
- package/src/events.js +1 -5
- package/src/files.js +11 -15
- package/src/functions_config.js +6 -10
- package/src/headers.js +5 -9
- package/src/inline_config.js +3 -7
- package/src/log/cleanup.js +4 -8
- package/src/log/logger.js +9 -13
- package/src/log/main.js +7 -11
- package/src/log/messages.js +9 -21
- package/src/log/options.js +4 -8
- package/src/log/serialize.js +2 -6
- package/src/log/theme.js +6 -15
- package/src/main.js +24 -33
- package/src/merge.js +5 -9
- package/src/merge_normalize.js +8 -15
- package/src/mutations/apply.js +6 -10
- package/src/mutations/config_prop_name.js +1 -5
- package/src/mutations/update.js +14 -18
- package/src/normalize.js +5 -9
- package/src/options/base.js +5 -9
- package/src/options/branch.js +2 -6
- package/src/options/feature_flags.js +2 -6
- package/src/options/main.js +13 -17
- package/src/options/repository_root.js +3 -7
- package/src/origin.js +6 -10
- package/src/parse.js +8 -12
- package/src/path.js +5 -9
- package/src/redirects.js +5 -11
- package/src/simplify.js +6 -10
- package/src/utils/group.js +1 -5
- package/src/utils/remove_falsy.js +5 -9
- package/src/utils/set.js +2 -6
- package/src/utils/toml.js +4 -8
- package/src/validate/context.js +3 -7
- package/src/validate/example.js +4 -8
- package/src/validate/helpers.js +6 -16
- package/src/validate/identical.js +2 -6
- package/src/validate/main.js +10 -20
- package/src/validate/validations.js +10 -19
package/src/log/logger.js
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import figures from 'figures'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { serializeObject } = require('./serialize')
|
|
6
|
-
const { THEME } = require('./theme')
|
|
3
|
+
import { serializeObject } from './serialize.js'
|
|
4
|
+
import { THEME } from './theme.js'
|
|
7
5
|
|
|
8
6
|
// When the `buffer` option is true, we return logs instead of printing them
|
|
9
7
|
// on the console. The logs are accumulated in a `logs` array variable.
|
|
10
|
-
const getBufferLogs = function ({ buffer }) {
|
|
8
|
+
export const getBufferLogs = function ({ buffer }) {
|
|
11
9
|
if (!buffer) {
|
|
12
10
|
return
|
|
13
11
|
}
|
|
@@ -17,7 +15,7 @@ const getBufferLogs = function ({ buffer }) {
|
|
|
17
15
|
|
|
18
16
|
// This should be used instead of `console.log()`
|
|
19
17
|
// Printed on stderr because stdout is reserved for the JSON output
|
|
20
|
-
const log = function (logs, string, { color } = {}) {
|
|
18
|
+
export const log = function (logs, string, { color } = {}) {
|
|
21
19
|
const stringA = String(string).replace(EMPTY_LINES_REGEXP, EMPTY_LINE)
|
|
22
20
|
const stringB = color === undefined ? stringA : color(stringA)
|
|
23
21
|
|
|
@@ -36,16 +34,14 @@ const log = function (logs, string, { color } = {}) {
|
|
|
36
34
|
const EMPTY_LINES_REGEXP = /^\s*$/gm
|
|
37
35
|
const EMPTY_LINE = '\u{200B}'
|
|
38
36
|
|
|
39
|
-
const logWarning = function (logs, string, opts) {
|
|
37
|
+
export const logWarning = function (logs, string, opts) {
|
|
40
38
|
log(logs, string, { color: THEME.warningLine, ...opts })
|
|
41
39
|
}
|
|
42
40
|
|
|
43
|
-
const logObject = function (logs, object, opts) {
|
|
41
|
+
export const logObject = function (logs, object, opts) {
|
|
44
42
|
log(logs, serializeObject(object), opts)
|
|
45
43
|
}
|
|
46
44
|
|
|
47
|
-
const logSubHeader = function (logs, string, opts) {
|
|
48
|
-
log(logs, `\n${pointer} ${string}`, { color: THEME.subHeader, ...opts })
|
|
45
|
+
export const logSubHeader = function (logs, string, opts) {
|
|
46
|
+
log(logs, `\n${figures.pointer} ${string}`, { color: THEME.subHeader, ...opts })
|
|
49
47
|
}
|
|
50
|
-
|
|
51
|
-
module.exports = { getBufferLogs, log, logWarning, logObject, logSubHeader }
|
package/src/log/main.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const { logObject, logSubHeader } = require('./logger')
|
|
5
|
-
const { cleanupConfigOpts } = require('./options')
|
|
1
|
+
import { cleanupConfig, cleanupEnvironment } from './cleanup.js'
|
|
2
|
+
import { logObject, logSubHeader } from './logger.js'
|
|
3
|
+
import { cleanupConfigOpts } from './options.js'
|
|
6
4
|
|
|
7
5
|
// Log options in debug mode.
|
|
8
|
-
const logOpts = function (opts, { logs, debug, cachedConfig, cachedConfigPath }) {
|
|
6
|
+
export const logOpts = function (opts, { logs, debug, cachedConfig, cachedConfigPath }) {
|
|
9
7
|
// In production, print those in the first call to `@netlify/config`, not the
|
|
10
8
|
// second one done inside `@netlify/build`
|
|
11
9
|
if (!debug || cachedConfig !== undefined || cachedConfigPath !== undefined) {
|
|
@@ -17,7 +15,7 @@ const logOpts = function (opts, { logs, debug, cachedConfig, cachedConfigPath })
|
|
|
17
15
|
}
|
|
18
16
|
|
|
19
17
|
// Log `defaultConfig` option in debug mode
|
|
20
|
-
const logDefaultConfig = function (defaultConfig, { logs, debug, baseRelDir }) {
|
|
18
|
+
export const logDefaultConfig = function (defaultConfig, { logs, debug, baseRelDir }) {
|
|
21
19
|
if (!debug || defaultConfig === undefined) {
|
|
22
20
|
return
|
|
23
21
|
}
|
|
@@ -27,7 +25,7 @@ const logDefaultConfig = function (defaultConfig, { logs, debug, baseRelDir }) {
|
|
|
27
25
|
}
|
|
28
26
|
|
|
29
27
|
// Log `inlineConfig` option in debug mode
|
|
30
|
-
const logInlineConfig = function (initialConfig, { logs, debug }) {
|
|
28
|
+
export const logInlineConfig = function (initialConfig, { logs, debug }) {
|
|
31
29
|
if (!debug || Object.keys(initialConfig).length === 0) {
|
|
32
30
|
return
|
|
33
31
|
}
|
|
@@ -37,7 +35,7 @@ const logInlineConfig = function (initialConfig, { logs, debug }) {
|
|
|
37
35
|
}
|
|
38
36
|
|
|
39
37
|
// Log return value of `@netlify/config` in debug mode
|
|
40
|
-
const logResult = function ({ configPath, buildDir, config, context, branch, env }, { logs, debug }) {
|
|
38
|
+
export const logResult = function ({ configPath, buildDir, config, context, branch, env }, { logs, debug }) {
|
|
41
39
|
if (!debug) {
|
|
42
40
|
return
|
|
43
41
|
}
|
|
@@ -48,5 +46,3 @@ const logResult = function ({ configPath, buildDir, config, context, branch, env
|
|
|
48
46
|
logSubHeader(logs, 'Resolved config')
|
|
49
47
|
logObject(logs, cleanupConfig(config))
|
|
50
48
|
}
|
|
51
|
-
|
|
52
|
-
module.exports = { logOpts, logDefaultConfig, logInlineConfig, logResult }
|
package/src/log/messages.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
import { throwUserError } from '../error.js'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import { logWarning } from './logger.js'
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const throwOnInvalidTomlSequence = function (invalidSequence) {
|
|
5
|
+
export const throwOnInvalidTomlSequence = function (invalidSequence) {
|
|
8
6
|
throwUserError(
|
|
9
7
|
`In netlify.toml, the following backslash should be escaped: ${invalidSequence}
|
|
10
8
|
The following should be used instead: \\${invalidSequence}`,
|
|
11
9
|
)
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
const warnLegacyFunctionsDirectory = ({ config = {}, logs }) => {
|
|
12
|
+
export const warnLegacyFunctionsDirectory = ({ config = {}, logs }) => {
|
|
15
13
|
const { functionsDirectory, functionsDirectoryOrigin } = config
|
|
16
14
|
|
|
17
15
|
if (functionsDirectoryOrigin !== 'config-v1') {
|
|
@@ -29,7 +27,7 @@ We recommend updating netlify.toml to set the functions directory under [functio
|
|
|
29
27
|
)
|
|
30
28
|
}
|
|
31
29
|
|
|
32
|
-
const warnContextPluginConfig = function (logs, packageName, context) {
|
|
30
|
+
export const warnContextPluginConfig = function (logs, packageName, context) {
|
|
33
31
|
logWarning(
|
|
34
32
|
logs,
|
|
35
33
|
`
|
|
@@ -38,7 +36,7 @@ To run "${packageName}" in the ${context} context only, uninstall the plugin fro
|
|
|
38
36
|
)
|
|
39
37
|
}
|
|
40
38
|
|
|
41
|
-
const throwContextPluginsConfig = function (packageName, context) {
|
|
39
|
+
export const throwContextPluginsConfig = function (packageName, context) {
|
|
42
40
|
throwUserError(
|
|
43
41
|
`
|
|
44
42
|
"${packageName}" is installed in the UI, which means that it runs in all deploy contexts, regardless of file-based configuration.
|
|
@@ -51,7 +49,7 @@ To run "${packageName}" in all contexts, please remove the following section fro
|
|
|
51
49
|
)
|
|
52
50
|
}
|
|
53
51
|
|
|
54
|
-
const warnHeadersParsing = function (logs, errors) {
|
|
52
|
+
export const warnHeadersParsing = function (logs, errors) {
|
|
55
53
|
if (errors.length === 0) {
|
|
56
54
|
return
|
|
57
55
|
}
|
|
@@ -69,7 +67,7 @@ ${errorMessage}`,
|
|
|
69
67
|
// Headers with different cases are not currently the way users probably
|
|
70
68
|
// intend them to be, so we print a warning message.
|
|
71
69
|
// See issue at https://github.com/netlify/build/issues/2290
|
|
72
|
-
const warnHeadersCaseSensitivity = function (logs, headers) {
|
|
70
|
+
export const warnHeadersCaseSensitivity = function (logs, headers) {
|
|
73
71
|
const headersA = headers.flatMap(getHeaderNames).filter(isNotDuplicateHeaderName).map(addHeaderLowerCase)
|
|
74
72
|
const differentCaseHeader = headersA.find(hasHeaderCaseDuplicate)
|
|
75
73
|
if (differentCaseHeader === undefined) {
|
|
@@ -106,7 +104,7 @@ const isHeaderCaseDuplicate = function ({ headerName, lowerHeaderName }, differe
|
|
|
106
104
|
return differentCaseHeader.headerName !== headerName && differentCaseHeader.lowerHeaderName === lowerHeaderName
|
|
107
105
|
}
|
|
108
106
|
|
|
109
|
-
const warnRedirectsParsing = function (logs, errors) {
|
|
107
|
+
export const warnRedirectsParsing = function (logs, errors) {
|
|
110
108
|
if (errors.length === 0) {
|
|
111
109
|
return
|
|
112
110
|
}
|
|
@@ -124,13 +122,3 @@ ${errorMessage}`,
|
|
|
124
122
|
const getErrorMessage = function ({ message }) {
|
|
125
123
|
return message
|
|
126
124
|
}
|
|
127
|
-
|
|
128
|
-
module.exports = {
|
|
129
|
-
throwOnInvalidTomlSequence,
|
|
130
|
-
warnLegacyFunctionsDirectory,
|
|
131
|
-
warnContextPluginConfig,
|
|
132
|
-
throwContextPluginsConfig,
|
|
133
|
-
warnHeadersParsing,
|
|
134
|
-
warnHeadersCaseSensitivity,
|
|
135
|
-
warnRedirectsParsing,
|
|
136
|
-
}
|
package/src/log/options.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const { removeEmptyArray } = require('../simplify')
|
|
5
|
-
const { removeFalsy } = require('../utils/remove_falsy')
|
|
1
|
+
import { DEFAULT_FEATURE_FLAGS } from '../options/feature_flags.js'
|
|
2
|
+
import { removeEmptyArray } from '../simplify.js'
|
|
3
|
+
import { removeFalsy } from '../utils/remove_falsy.js'
|
|
6
4
|
|
|
7
5
|
// Use an allowlist to prevent printing confidential values.
|
|
8
|
-
const cleanupConfigOpts = function ({
|
|
6
|
+
export const cleanupConfigOpts = function ({
|
|
9
7
|
config,
|
|
10
8
|
cwd,
|
|
11
9
|
context,
|
|
@@ -43,5 +41,3 @@ const cleanFeatureFlags = function (featureFlags) {
|
|
|
43
41
|
const shouldPrintFeatureFlag = function ([featureFlagName, enabled]) {
|
|
44
42
|
return enabled && featureFlagName in DEFAULT_FEATURE_FLAGS
|
|
45
43
|
}
|
|
46
|
-
|
|
47
|
-
module.exports = { cleanupConfigOpts }
|
package/src/log/serialize.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { dump } from 'js-yaml'
|
|
2
2
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
const serializeObject = function (object) {
|
|
3
|
+
export const serializeObject = function (object) {
|
|
6
4
|
return dump(object, { noRefs: true, sortKeys: true, lineWidth: Number.POSITIVE_INFINITY }).trimRight()
|
|
7
5
|
}
|
|
8
|
-
|
|
9
|
-
module.exports = { serializeObject }
|
package/src/log/theme.js
CHANGED
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
cyan: { bold: cyanBold },
|
|
5
|
-
cyan,
|
|
6
|
-
red: { bold: redBold },
|
|
7
|
-
yellowBright,
|
|
8
|
-
} = require('chalk')
|
|
1
|
+
import chalk from 'chalk'
|
|
9
2
|
|
|
10
3
|
// Color theme. Please use this instead of requiring chalk directly, to ensure
|
|
11
4
|
// consistent colors.
|
|
12
|
-
const THEME = {
|
|
5
|
+
export const THEME = {
|
|
13
6
|
// Single lines used as subheaders
|
|
14
|
-
subHeader:
|
|
7
|
+
subHeader: chalk.cyan.bold,
|
|
15
8
|
// Single lines used as subheaders indicating an error
|
|
16
|
-
errorSubHeader:
|
|
9
|
+
errorSubHeader: chalk.red.bold,
|
|
17
10
|
// Same for warnings
|
|
18
|
-
warningLine: yellowBright,
|
|
11
|
+
warningLine: chalk.yellowBright,
|
|
19
12
|
// One of several words that should be highlighted inside a line
|
|
20
|
-
highlightWords: cyan,
|
|
13
|
+
highlightWords: chalk.cyan,
|
|
21
14
|
}
|
|
22
|
-
|
|
23
|
-
module.exports = { THEME }
|
package/src/main.js
CHANGED
|
@@ -1,38 +1,37 @@
|
|
|
1
1
|
/* eslint-disable max-lines */
|
|
2
|
-
|
|
2
|
+
import { getApiClient } from './api/client.js'
|
|
3
|
+
import { getSiteInfo } from './api/site_info.js'
|
|
4
|
+
import { getInitialBase, getBase, addBase } from './base.js'
|
|
5
|
+
import { getBuildDir } from './build_dir.js'
|
|
6
|
+
import { getCachedConfig } from './cached_config.js'
|
|
7
|
+
import { normalizeContextProps, mergeContext } from './context.js'
|
|
8
|
+
import { parseDefaultConfig } from './default.js'
|
|
9
|
+
import { getEnv } from './env/main.js'
|
|
10
|
+
import { resolveConfigPaths } from './files.js'
|
|
11
|
+
import { getHeadersPath, addHeaders } from './headers.js'
|
|
12
|
+
import { getInlineConfig } from './inline_config.js'
|
|
13
|
+
import { logResult } from './log/main.js'
|
|
14
|
+
import { mergeConfigs } from './merge.js'
|
|
15
|
+
import { normalizeBeforeConfigMerge, normalizeAfterConfigMerge } from './merge_normalize.js'
|
|
16
|
+
import { addDefaultOpts, normalizeOpts } from './options/main.js'
|
|
17
|
+
import { UI_ORIGIN, CONFIG_ORIGIN, INLINE_ORIGIN } from './origin.js'
|
|
18
|
+
import { parseConfig } from './parse.js'
|
|
19
|
+
import { getConfigPath } from './path.js'
|
|
20
|
+
import { getRedirectsPath, addRedirects } from './redirects.js'
|
|
3
21
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const { getInitialBase, getBase, addBase } = require('./base')
|
|
7
|
-
const { getBuildDir } = require('./build_dir')
|
|
8
|
-
const { getCachedConfig } = require('./cached_config')
|
|
9
|
-
const { normalizeContextProps, mergeContext } = require('./context')
|
|
10
|
-
const { parseDefaultConfig } = require('./default')
|
|
11
|
-
const { getEnv } = require('./env/main')
|
|
12
|
-
const { EVENTS } = require('./events')
|
|
13
|
-
const { resolveConfigPaths } = require('./files')
|
|
14
|
-
const { getHeadersPath, addHeaders } = require('./headers')
|
|
15
|
-
const { getInlineConfig } = require('./inline_config')
|
|
16
|
-
const { cleanupConfig } = require('./log/cleanup')
|
|
17
|
-
const { logResult } = require('./log/main')
|
|
18
|
-
const { mergeConfigs } = require('./merge')
|
|
19
|
-
const { normalizeBeforeConfigMerge, normalizeAfterConfigMerge } = require('./merge_normalize')
|
|
20
|
-
const { updateConfig, restoreConfig } = require('./mutations/update')
|
|
21
|
-
const { addDefaultOpts, normalizeOpts } = require('./options/main')
|
|
22
|
-
const { UI_ORIGIN, CONFIG_ORIGIN, INLINE_ORIGIN } = require('./origin')
|
|
23
|
-
const { parseConfig } = require('./parse')
|
|
24
|
-
const { getConfigPath } = require('./path')
|
|
22
|
+
export { EVENTS } from './events.js'
|
|
23
|
+
export { cleanupConfig } from './log/cleanup.js'
|
|
25
24
|
// eslint-disable-next-line import/max-dependencies
|
|
26
|
-
|
|
25
|
+
export { updateConfig, restoreConfig } from './mutations/update.js'
|
|
27
26
|
|
|
28
27
|
// Load the configuration file.
|
|
29
28
|
// Takes an optional configuration file path as input and return the resolved
|
|
30
29
|
// `config` together with related properties such as the `configPath`.
|
|
31
|
-
const resolveConfig = async function (opts) {
|
|
30
|
+
export const resolveConfig = async function (opts) {
|
|
32
31
|
const { cachedConfig, cachedConfigPath, host, scheme, pathPrefix, testOpts, token, offline, ...optsA } =
|
|
33
32
|
addDefaultOpts(opts)
|
|
34
33
|
// `api` is not JSON-serializable, so we cannot cache it inside `cachedConfig`
|
|
35
|
-
const api =
|
|
34
|
+
const api = getApiClient({ token, offline, host, scheme, pathPrefix, testOpts })
|
|
36
35
|
|
|
37
36
|
const parsedCachedConfig = await getCachedConfig({ cachedConfig, cachedConfigPath, token, api })
|
|
38
37
|
if (parsedCachedConfig !== undefined) {
|
|
@@ -278,12 +277,4 @@ const resolveFiles = async function ({ config, repositoryRoot, base, baseRelDir
|
|
|
278
277
|
const configB = addBase(configA, baseA)
|
|
279
278
|
return { config: configB, buildDir, base: baseA }
|
|
280
279
|
}
|
|
281
|
-
|
|
282
|
-
module.exports = resolveConfig
|
|
283
|
-
// TODO: on next major release, export a single object instead of mutating the
|
|
284
|
-
// top-level function
|
|
285
|
-
module.exports.cleanupConfig = cleanupConfig
|
|
286
|
-
module.exports.updateConfig = updateConfig
|
|
287
|
-
module.exports.restoreConfig = restoreConfig
|
|
288
|
-
module.exports.EVENTS = EVENTS
|
|
289
280
|
/* eslint-enable max-lines */
|
package/src/merge.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
import deepmerge from 'deepmerge'
|
|
2
|
+
import isPlainObj from 'is-plain-obj'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const { groupBy } = require('./utils/group')
|
|
7
|
-
const { removeUndefined } = require('./utils/remove_falsy')
|
|
4
|
+
import { groupBy } from './utils/group.js'
|
|
5
|
+
import { removeUndefined } from './utils/remove_falsy.js'
|
|
8
6
|
|
|
9
7
|
// Merge an array of configuration objects.
|
|
10
8
|
// Last items have higher priority.
|
|
11
9
|
// Configuration objects are deeply merged.
|
|
12
10
|
// - Arrays are overridden, not concatenated.
|
|
13
|
-
const mergeConfigs = function (configs) {
|
|
11
|
+
export const mergeConfigs = function (configs) {
|
|
14
12
|
const cleanedConfigs = configs.map(removeUndefinedProps)
|
|
15
13
|
return deepmerge.all(cleanedConfigs, { arrayMerge })
|
|
16
14
|
}
|
|
@@ -53,5 +51,3 @@ const mergePluginConfigs = function (plugins) {
|
|
|
53
51
|
const mergePluginsPair = function (pluginA, pluginB) {
|
|
54
52
|
return deepmerge(pluginA, pluginB, { arrayMerge })
|
|
55
53
|
}
|
|
56
|
-
|
|
57
|
-
module.exports = { mergeConfigs }
|
package/src/merge_normalize.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const { validateIdenticalPlugins } = require('./validate/identical')
|
|
7
|
-
const {
|
|
1
|
+
import { normalizeConfigCase } from './case.js'
|
|
2
|
+
import { normalizeConfig } from './normalize.js'
|
|
3
|
+
import { addOrigins } from './origin.js'
|
|
4
|
+
import { validateIdenticalPlugins } from './validate/identical.js'
|
|
5
|
+
import {
|
|
8
6
|
validatePreCaseNormalize,
|
|
9
7
|
validatePreMergeConfig,
|
|
10
8
|
validatePreNormalizeConfig,
|
|
11
9
|
validatePostNormalizeConfig,
|
|
12
|
-
}
|
|
10
|
+
} from './validate/main.js'
|
|
13
11
|
|
|
14
12
|
// Perform validation and normalization logic to apply to all of:
|
|
15
13
|
// - config, defaultConfig, inlineConfig
|
|
16
14
|
// - context-specific configs
|
|
17
15
|
// Therefore, this is performing before merging those together.
|
|
18
|
-
const normalizeBeforeConfigMerge = function (config, origin) {
|
|
16
|
+
export const normalizeBeforeConfigMerge = function (config, origin) {
|
|
19
17
|
validatePreCaseNormalize(config)
|
|
20
18
|
const configA = normalizeConfigCase(config)
|
|
21
19
|
validatePreMergeConfig(configA)
|
|
@@ -25,14 +23,9 @@ const normalizeBeforeConfigMerge = function (config, origin) {
|
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
// Validation and normalization logic performed after merging
|
|
28
|
-
const normalizeAfterConfigMerge = function (config) {
|
|
26
|
+
export const normalizeAfterConfigMerge = function (config) {
|
|
29
27
|
validatePreNormalizeConfig(config)
|
|
30
28
|
const configA = normalizeConfig(config)
|
|
31
29
|
validatePostNormalizeConfig(configA)
|
|
32
30
|
return configA
|
|
33
31
|
}
|
|
34
|
-
|
|
35
|
-
module.exports = {
|
|
36
|
-
normalizeBeforeConfigMerge,
|
|
37
|
-
normalizeAfterConfigMerge,
|
|
38
|
-
}
|
package/src/mutations/apply.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { throwUserError } from '../error.js'
|
|
2
|
+
import { EVENTS } from '../events.js'
|
|
3
|
+
import { WILDCARD_ALL, FUNCTION_CONFIG_PROPERTIES } from '../functions_config.js'
|
|
4
|
+
import { setProp } from '../utils/set.js'
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
const { EVENTS } = require('../events')
|
|
5
|
-
const { WILDCARD_ALL, FUNCTION_CONFIG_PROPERTIES } = require('../functions_config')
|
|
6
|
-
const { setProp } = require('../utils/set')
|
|
7
|
-
|
|
8
|
-
const { getPropName } = require('./config_prop_name')
|
|
6
|
+
import { getPropName } from './config_prop_name.js'
|
|
9
7
|
|
|
10
8
|
// Apply a series of mutations to `inlineConfig`.
|
|
11
9
|
// Meant to be used to apply configuration changes at build time.
|
|
@@ -13,7 +11,7 @@ const { getPropName } = require('./config_prop_name')
|
|
|
13
11
|
// normalization. Therefore, this function also denormalizes (reverts that
|
|
14
12
|
// normalization) so that the final `config` object can be serialized back to
|
|
15
13
|
// a `netlify.toml`.
|
|
16
|
-
const applyMutations = function (inlineConfig, configMutations) {
|
|
14
|
+
export const applyMutations = function (inlineConfig, configMutations) {
|
|
17
15
|
return configMutations.reduce(applyMutation, inlineConfig)
|
|
18
16
|
}
|
|
19
17
|
|
|
@@ -78,5 +76,3 @@ const MUTABLE_PROPS = {
|
|
|
78
76
|
headers: { lastEvent: 'onPostBuild' },
|
|
79
77
|
redirects: { lastEvent: 'onPostBuild' },
|
|
80
78
|
}
|
|
81
|
-
|
|
82
|
-
module.exports = { applyMutations }
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
1
|
// Retrieve normalized property name
|
|
4
|
-
const getPropName = function (keys) {
|
|
2
|
+
export const getPropName = function (keys) {
|
|
5
3
|
return keys.reduce(normalizeDynamicProp, '')
|
|
6
4
|
}
|
|
7
5
|
|
|
@@ -16,5 +14,3 @@ const normalizeDynamicProp = function (propName, key) {
|
|
|
16
14
|
|
|
17
15
|
// Properties with dynamic children
|
|
18
16
|
const DYNAMIC_OBJECT_PROPS = new Set(['build.services', 'build.environment', 'functions', 'functions.*'])
|
|
19
|
-
|
|
20
|
-
module.exports = { getPropName }
|
package/src/mutations/update.js
CHANGED
|
@@ -1,20 +1,18 @@
|
|
|
1
|
-
|
|
1
|
+
import { writeFile, unlink, copyFile } from 'fs'
|
|
2
|
+
import { promisify } from 'util'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
4
|
+
import makeDir from 'make-dir'
|
|
5
|
+
import pathExists from 'path-exists'
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
import { ensureConfigPriority } from '../context.js'
|
|
8
|
+
import { addHeaders } from '../headers.js'
|
|
9
|
+
import { mergeConfigs } from '../merge.js'
|
|
10
|
+
import { parseOptionalConfig } from '../parse.js'
|
|
11
|
+
import { addRedirects } from '../redirects.js'
|
|
12
|
+
import { simplifyConfig } from '../simplify.js'
|
|
13
|
+
import { serializeToml } from '../utils/toml.js'
|
|
8
14
|
|
|
9
|
-
|
|
10
|
-
const { addHeaders } = require('../headers')
|
|
11
|
-
const { mergeConfigs } = require('../merge')
|
|
12
|
-
const { parseOptionalConfig } = require('../parse')
|
|
13
|
-
const { addRedirects } = require('../redirects')
|
|
14
|
-
const { simplifyConfig } = require('../simplify')
|
|
15
|
-
const { serializeToml } = require('../utils/toml')
|
|
16
|
-
|
|
17
|
-
const { applyMutations } = require('./apply')
|
|
15
|
+
import { applyMutations } from './apply.js'
|
|
18
16
|
|
|
19
17
|
const pWriteFile = promisify(writeFile)
|
|
20
18
|
const pUnlink = promisify(unlink)
|
|
@@ -22,7 +20,7 @@ const pCopyFile = promisify(copyFile)
|
|
|
22
20
|
|
|
23
21
|
// Persist configuration changes to `netlify.toml`.
|
|
24
22
|
// If `netlify.toml` does not exist, creates it. Otherwise, merges the changes.
|
|
25
|
-
const updateConfig = async function (
|
|
23
|
+
export const updateConfig = async function (
|
|
26
24
|
configMutations,
|
|
27
25
|
{ buildDir, configPath, headersPath, redirectsPath, context, branch, logs },
|
|
28
26
|
) {
|
|
@@ -81,7 +79,7 @@ const backupConfig = async function ({ buildDir, configPath, headersPath, redire
|
|
|
81
79
|
])
|
|
82
80
|
}
|
|
83
81
|
|
|
84
|
-
const restoreConfig = async function (configMutations, { buildDir, configPath, headersPath, redirectsPath }) {
|
|
82
|
+
export const restoreConfig = async function (configMutations, { buildDir, configPath, headersPath, redirectsPath }) {
|
|
85
83
|
if (configMutations.length === 0) {
|
|
86
84
|
return
|
|
87
85
|
}
|
|
@@ -123,5 +121,3 @@ const copyOrDelete = async function (src, dest) {
|
|
|
123
121
|
|
|
124
122
|
await deleteNoError(dest)
|
|
125
123
|
}
|
|
126
|
-
|
|
127
|
-
module.exports = { updateConfig, restoreConfig }
|
package/src/normalize.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const { DEFAULT_ORIGIN } = require('./origin')
|
|
6
|
-
const { removeFalsy } = require('./utils/remove_falsy')
|
|
1
|
+
import { normalizeFunctionsProps, WILDCARD_ALL } from './functions_config.js'
|
|
2
|
+
import { mergeConfigs } from './merge.js'
|
|
3
|
+
import { DEFAULT_ORIGIN } from './origin.js'
|
|
4
|
+
import { removeFalsy } from './utils/remove_falsy.js'
|
|
7
5
|
|
|
8
6
|
// Normalize configuration object
|
|
9
|
-
const normalizeConfig = function (config) {
|
|
7
|
+
export const normalizeConfig = function (config) {
|
|
10
8
|
const configA = removeEmpty(config)
|
|
11
9
|
const { build, functions, plugins, ...configB } = mergeConfigs([DEFAULT_CONFIG, configA])
|
|
12
10
|
const { build: buildA, functions: functionsA, functionsDirectoryProps } = normalizeFunctionsProps(build, functions)
|
|
@@ -36,5 +34,3 @@ const DEFAULT_CONFIG = {
|
|
|
36
34
|
const normalizePlugin = function ({ inputs = {}, ...plugin }) {
|
|
37
35
|
return removeFalsy({ ...plugin, inputs })
|
|
38
36
|
}
|
|
39
|
-
|
|
40
|
-
module.exports = { normalizeConfig }
|
package/src/options/base.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
import { realpath } from 'fs'
|
|
2
|
+
import { dirname, relative, sep } from 'path'
|
|
3
|
+
import { promisify } from 'util'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
const { dirname, relative, sep } = require('path')
|
|
5
|
-
const { promisify } = require('util')
|
|
6
|
-
|
|
7
|
-
const pathExists = require('path-exists')
|
|
5
|
+
import pathExists from 'path-exists'
|
|
8
6
|
|
|
9
7
|
const pRealpath = promisify(realpath)
|
|
10
8
|
|
|
@@ -13,7 +11,7 @@ const pRealpath = promisify(realpath)
|
|
|
13
11
|
// `cwd` that has a `.netlify` or `netlify.toml`. This allows Netlify CLI users
|
|
14
12
|
// to `cd` into monorepo directories to change their base and build directories.
|
|
15
13
|
// Do all checks in parallel for speed
|
|
16
|
-
const getBaseOverride = async function ({ repositoryRoot, cwd }) {
|
|
14
|
+
export const getBaseOverride = async function ({ repositoryRoot, cwd }) {
|
|
17
15
|
// Performance optimization
|
|
18
16
|
if (repositoryRoot === cwd) {
|
|
19
17
|
return {}
|
|
@@ -69,5 +67,3 @@ const returnIfExists = async function (path) {
|
|
|
69
67
|
|
|
70
68
|
return path
|
|
71
69
|
}
|
|
72
|
-
|
|
73
|
-
module.exports = { getBaseOverride }
|
package/src/options/branch.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const execa = require('execa')
|
|
1
|
+
import execa from 'execa'
|
|
4
2
|
|
|
5
3
|
// Find out git branch among (in priority order):
|
|
6
4
|
// - `branch` option
|
|
@@ -8,7 +6,7 @@ const execa = require('execa')
|
|
|
8
6
|
// - `HEAD` branch (using `git`)
|
|
9
7
|
// - `main` (using `git`)
|
|
10
8
|
// - 'master' (fallback)
|
|
11
|
-
const getBranch = async function ({ branch, repositoryRoot }) {
|
|
9
|
+
export const getBranch = async function ({ branch, repositoryRoot }) {
|
|
12
10
|
if (branch) {
|
|
13
11
|
return branch
|
|
14
12
|
}
|
|
@@ -34,5 +32,3 @@ const getGitBranch = async function (repositoryRoot, gitRef) {
|
|
|
34
32
|
}
|
|
35
33
|
|
|
36
34
|
const FALLBACK_BRANCH = 'master'
|
|
37
|
-
|
|
38
|
-
module.exports = { getBranch }
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
1
|
// From CLI `--featureFlags=a,b,c` to programmatic `{ a: true, b: true, c: true }`
|
|
4
|
-
const normalizeCliFeatureFlags = function (cliFeatureFlags) {
|
|
2
|
+
export const normalizeCliFeatureFlags = function (cliFeatureFlags) {
|
|
5
3
|
return Object.assign({}, ...cliFeatureFlags.split(',').filter(isNotEmpty).map(getFeatureFlag))
|
|
6
4
|
}
|
|
7
5
|
|
|
@@ -14,6 +12,4 @@ const getFeatureFlag = function (name) {
|
|
|
14
12
|
}
|
|
15
13
|
|
|
16
14
|
// Default values for feature flags
|
|
17
|
-
const DEFAULT_FEATURE_FLAGS = {}
|
|
18
|
-
|
|
19
|
-
module.exports = { normalizeCliFeatureFlags, DEFAULT_FEATURE_FLAGS }
|
|
15
|
+
export const DEFAULT_FEATURE_FLAGS = {}
|
package/src/options/main.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
|
-
|
|
1
|
+
import { resolve } from 'path'
|
|
2
|
+
import process from 'process'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
const process = require('process')
|
|
4
|
+
import { isDirectory } from 'path-type'
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
import { throwUserError } from '../error.js'
|
|
7
|
+
import { getBufferLogs } from '../log/logger.js'
|
|
8
|
+
import { logOpts } from '../log/main.js'
|
|
9
|
+
import { removeFalsy } from '../utils/remove_falsy.js'
|
|
7
10
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const { getBaseOverride } = require('./base')
|
|
14
|
-
const { getBranch } = require('./branch')
|
|
15
|
-
const { DEFAULT_FEATURE_FLAGS } = require('./feature_flags')
|
|
16
|
-
const { getRepositoryRoot } = require('./repository_root')
|
|
11
|
+
import { getBaseOverride } from './base.js'
|
|
12
|
+
import { getBranch } from './branch.js'
|
|
13
|
+
import { DEFAULT_FEATURE_FLAGS } from './feature_flags.js'
|
|
14
|
+
import { getRepositoryRoot } from './repository_root.js'
|
|
17
15
|
|
|
18
16
|
// Assign default options
|
|
19
|
-
const addDefaultOpts = function (opts = {}) {
|
|
17
|
+
export const addDefaultOpts = function (opts = {}) {
|
|
20
18
|
const rawOpts = removeFalsy(opts)
|
|
21
19
|
|
|
22
20
|
const defaultOpts = getDefaultOpts(rawOpts)
|
|
@@ -74,7 +72,7 @@ const getDefaultCwd = function (cwdOpt) {
|
|
|
74
72
|
}
|
|
75
73
|
|
|
76
74
|
// Normalize options
|
|
77
|
-
const normalizeOpts = async function (opts) {
|
|
75
|
+
export const normalizeOpts = async function (opts) {
|
|
78
76
|
const repositoryRoot = await getRepositoryRoot(opts)
|
|
79
77
|
const optsA = { ...opts, repositoryRoot }
|
|
80
78
|
|
|
@@ -106,5 +104,3 @@ const normalizeDir = async function (opts, optName) {
|
|
|
106
104
|
}
|
|
107
105
|
return { [optName]: resolvedPath }
|
|
108
106
|
}
|
|
109
|
-
|
|
110
|
-
module.exports = { addDefaultOpts, normalizeOpts }
|