@netlify/config 18.2.4 → 18.2.5

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.
Files changed (56) hide show
  1. package/bin.js +5 -0
  2. package/lib/api/build_settings.js +20 -33
  3. package/lib/api/client.js +10 -13
  4. package/lib/api/site_info.js +48 -56
  5. package/lib/base.js +10 -18
  6. package/lib/bin/flags.js +134 -142
  7. package/lib/bin/main.js +49 -63
  8. package/lib/build_dir.js +11 -15
  9. package/lib/cached_config.js +14 -17
  10. package/lib/case.js +16 -35
  11. package/lib/context.js +62 -84
  12. package/lib/default.js +18 -22
  13. package/lib/env/envelope.js +23 -23
  14. package/lib/env/git.js +18 -18
  15. package/lib/env/main.js +127 -179
  16. package/lib/error.js +19 -27
  17. package/lib/events.js +18 -19
  18. package/lib/files.js +63 -87
  19. package/lib/functions_config.js +36 -52
  20. package/lib/headers.js +17 -27
  21. package/lib/inline_config.js +6 -7
  22. package/lib/log/cleanup.js +54 -82
  23. package/lib/log/logger.js +25 -36
  24. package/lib/log/main.js +31 -40
  25. package/lib/log/messages.js +56 -95
  26. package/lib/log/options.js +24 -38
  27. package/lib/log/serialize.js +3 -4
  28. package/lib/log/theme.js +10 -11
  29. package/lib/main.js +188 -263
  30. package/lib/merge.js +25 -35
  31. package/lib/merge_normalize.js +17 -24
  32. package/lib/mutations/apply.js +53 -65
  33. package/lib/mutations/config_prop_name.js +6 -8
  34. package/lib/mutations/update.js +79 -98
  35. package/lib/normalize.js +24 -28
  36. package/lib/options/base.js +39 -51
  37. package/lib/options/branch.js +23 -26
  38. package/lib/options/feature_flags.js +7 -10
  39. package/lib/options/main.js +76 -96
  40. package/lib/options/repository_root.js +11 -16
  41. package/lib/origin.js +22 -29
  42. package/lib/parse.js +42 -55
  43. package/lib/path.js +29 -40
  44. package/lib/redirects.js +16 -26
  45. package/lib/simplify.js +66 -92
  46. package/lib/utils/group.js +5 -6
  47. package/lib/utils/remove_falsy.js +9 -13
  48. package/lib/utils/set.js +19 -25
  49. package/lib/utils/toml.js +13 -16
  50. package/lib/validate/context.js +24 -43
  51. package/lib/validate/example.js +20 -27
  52. package/lib/validate/helpers.js +17 -23
  53. package/lib/validate/identical.js +8 -12
  54. package/lib/validate/main.js +83 -127
  55. package/lib/validate/validations.js +243 -257
  56. package/package.json +13 -8
@@ -1,23 +1,16 @@
1
- import isPlainObj from 'is-plain-obj'
2
-
3
- import { isDefined } from './utils/remove_falsy.js'
4
-
5
- export const bundlers = ['esbuild', 'nft', 'zisi']
6
- export const WILDCARD_ALL = '*'
7
-
1
+ import isPlainObj from 'is-plain-obj';
2
+ import { isDefined } from './utils/remove_falsy.js';
3
+ export const bundlers = ['esbuild', 'nft', 'zisi'];
4
+ export const WILDCARD_ALL = '*';
8
5
  // Removing the legacy `functions` from the `build` block.
9
6
  // Looking for a default directory in the `functions` block, separating it
10
7
  // from the rest of the configuration if it exists.
11
- export const normalizeFunctionsProps = function (
12
- { functions: v1FunctionsDirectory, ...build },
13
- { [WILDCARD_ALL]: wildcardProps, ...functions },
14
- ) {
15
- const functionsA = Object.entries(functions).reduce(normalizeFunctionsProp, { [WILDCARD_ALL]: wildcardProps })
16
- const { directory: functionsDirectory, functions: functionsB } = extractFunctionsDirectory(functionsA)
17
- const functionsDirectoryProps = getFunctionsDirectoryProps({ functionsDirectory, v1FunctionsDirectory })
18
- return { build, functions: functionsB, functionsDirectoryProps }
19
- }
20
-
8
+ export const normalizeFunctionsProps = function ({ functions: v1FunctionsDirectory, ...build }, { [WILDCARD_ALL]: wildcardProps, ...functions }) {
9
+ const functionsA = Object.entries(functions).reduce(normalizeFunctionsProp, { [WILDCARD_ALL]: wildcardProps });
10
+ const { directory: functionsDirectory, functions: functionsB } = extractFunctionsDirectory(functionsA);
11
+ const functionsDirectoryProps = getFunctionsDirectoryProps({ functionsDirectory, v1FunctionsDirectory });
12
+ return { build, functions: functionsB, functionsDirectoryProps };
13
+ };
21
14
  // Normalizes a functions configuration object, so that the first level of keys
22
15
  // represents function expressions mapped to a configuration object.
23
16
  //
@@ -37,47 +30,38 @@ export const normalizeFunctionsProps = function (
37
30
  // that to be the case if the value is an object where all keys are also
38
31
  // config properties. If not, it's simply a function with the same name
39
32
  // as one of the config properties.
40
- const normalizeFunctionsProp = (functions, [propName, propValue]) =>
41
- isConfigProperty(propName) && !isConfigLeaf(propValue)
33
+ const normalizeFunctionsProp = (functions, [propName, propValue]) => isConfigProperty(propName) && !isConfigLeaf(propValue)
42
34
  ? { ...functions, [WILDCARD_ALL]: { [propName]: propValue, ...functions[WILDCARD_ALL] } }
43
- : { ...functions, [propName]: propValue }
44
-
45
- const isConfigLeaf = (functionConfig) =>
46
- isPlainObj(functionConfig) && Object.keys(functionConfig).every(isConfigProperty)
47
-
48
- const isConfigProperty = (propName) => FUNCTION_CONFIG_PROPERTIES.has(propName)
49
-
35
+ : { ...functions, [propName]: propValue };
36
+ const isConfigLeaf = (functionConfig) => isPlainObj(functionConfig) && Object.keys(functionConfig).every(isConfigProperty);
37
+ const isConfigProperty = (propName) => FUNCTION_CONFIG_PROPERTIES.has(propName);
50
38
  export const FUNCTION_CONFIG_PROPERTIES = new Set([
51
- 'directory',
52
- 'external_node_modules',
53
- 'ignored_node_modules',
54
- 'included_files',
55
- 'node_bundler',
56
- 'schedule',
57
- ])
58
-
39
+ 'directory',
40
+ 'external_node_modules',
41
+ 'ignored_node_modules',
42
+ 'included_files',
43
+ 'node_bundler',
44
+ 'schedule',
45
+ ]);
59
46
  // Takes a functions configuration object and looks for the functions directory
60
47
  // definition, returning it under the `directory` key. The rest of the config
61
48
  // object is returned under the `functions` key.
62
49
  const extractFunctionsDirectory = ({ [WILDCARD_ALL]: { directory, ...wildcardFunctionsConfig }, ...functions }) => ({
63
- directory,
64
- functions: { ...functions, [WILDCARD_ALL]: wildcardFunctionsConfig },
65
- })
66
-
50
+ directory,
51
+ functions: { ...functions, [WILDCARD_ALL]: wildcardFunctionsConfig },
52
+ });
67
53
  const getFunctionsDirectoryProps = ({ functionsDirectory, v1FunctionsDirectory }) => {
68
- if (isDefined(functionsDirectory)) {
69
- return {
70
- functionsDirectory,
71
- functionsDirectoryOrigin: 'config',
54
+ if (isDefined(functionsDirectory)) {
55
+ return {
56
+ functionsDirectory,
57
+ functionsDirectoryOrigin: 'config',
58
+ };
72
59
  }
73
- }
74
-
75
- if (isDefined(v1FunctionsDirectory)) {
76
- return {
77
- functionsDirectory: v1FunctionsDirectory,
78
- functionsDirectoryOrigin: 'config-v1',
60
+ if (isDefined(v1FunctionsDirectory)) {
61
+ return {
62
+ functionsDirectory: v1FunctionsDirectory,
63
+ functionsDirectoryOrigin: 'config-v1',
64
+ };
79
65
  }
80
- }
81
-
82
- return {}
83
- }
66
+ return {};
67
+ };
package/lib/headers.js CHANGED
@@ -1,30 +1,20 @@
1
- import { resolve } from 'path'
2
-
3
- import { parseAllHeaders } from 'netlify-headers-parser'
4
-
5
- import { warnHeadersParsing, warnHeadersCaseSensitivity } from './log/messages.js'
6
-
1
+ import { resolve } from 'path';
2
+ import { parseAllHeaders } from 'netlify-headers-parser';
3
+ import { warnHeadersParsing, warnHeadersCaseSensitivity } from './log/messages.js';
7
4
  // Retrieve path to `_headers` file (even if it does not exist yet)
8
5
  export const getHeadersPath = function ({ build: { publish } }) {
9
- return resolve(publish, HEADERS_FILENAME)
10
- }
11
-
12
- const HEADERS_FILENAME = '_headers'
13
-
6
+ return resolve(publish, HEADERS_FILENAME);
7
+ };
8
+ const HEADERS_FILENAME = '_headers';
14
9
  // Add `config.headers`
15
- export const addHeaders = async function ({
16
- config: { headers: configHeaders, ...config },
17
- headersPath,
18
- logs,
19
- featureFlags,
20
- }) {
21
- const { headers, errors } = await parseAllHeaders({
22
- headersFiles: [headersPath],
23
- configHeaders,
24
- minimal: true,
25
- featureFlags,
26
- })
27
- warnHeadersParsing(logs, errors)
28
- warnHeadersCaseSensitivity(logs, headers)
29
- return { ...config, headers }
30
- }
10
+ export const addHeaders = async function ({ config: { headers: configHeaders, ...config }, headersPath, logs, featureFlags, }) {
11
+ const { headers, errors } = await parseAllHeaders({
12
+ headersFiles: [headersPath],
13
+ configHeaders,
14
+ minimal: true,
15
+ featureFlags,
16
+ });
17
+ warnHeadersParsing(logs, errors);
18
+ warnHeadersCaseSensitivity(logs, headers);
19
+ return { ...config, headers };
20
+ };
@@ -1,9 +1,8 @@
1
- import { logInlineConfig } from './log/main.js'
2
- import { applyMutations } from './mutations/apply.js'
3
-
1
+ import { logInlineConfig } from './log/main.js';
2
+ import { applyMutations } from './mutations/apply.js';
4
3
  // Retrieve the `--inlineConfig` CLI flag
5
4
  export const getInlineConfig = function ({ inlineConfig, configMutations, logs, debug }) {
6
- const mutatedInlineConfig = applyMutations(inlineConfig, configMutations)
7
- logInlineConfig(mutatedInlineConfig, { logs, debug })
8
- return mutatedInlineConfig
9
- }
5
+ const mutatedInlineConfig = applyMutations(inlineConfig, configMutations);
6
+ logInlineConfig(mutatedInlineConfig, { logs, debug });
7
+ return mutatedInlineConfig;
8
+ };
@@ -1,92 +1,64 @@
1
- import filterObj from 'filter-obj'
2
-
3
- import { simplifyConfig } from '../simplify.js'
4
-
1
+ import filterObj from 'filter-obj';
2
+ import { simplifyConfig } from '../simplify.js';
5
3
  // Make sure we are not printing secret values. Use an allow list.
6
- export const cleanupConfig = function ({
7
- build: {
8
- base,
9
- command,
10
- commandOrigin,
11
- environment = {},
12
- edge_functions: edgeFunctions,
13
- ignore,
14
- processing,
15
- publish,
16
- publishOrigin,
17
- } = {},
18
- headers,
19
- headersOrigin,
20
- plugins = [],
21
- redirects,
22
- redirectsOrigin,
23
- baseRelDir,
24
- functions,
25
- functionsDirectory,
26
- }) {
27
- const environmentA = cleanupEnvironment(environment)
28
- const build = {
29
- base,
30
- command,
31
- commandOrigin,
32
- environment: environmentA,
33
- edge_functions: edgeFunctions,
34
- ignore,
35
- processing,
36
- publish,
37
- publishOrigin,
38
- }
39
- const pluginsA = plugins.map(cleanupPlugin)
40
- const netlifyConfig = simplifyConfig({
41
- build,
42
- plugins: pluginsA,
43
- headers,
44
- headersOrigin,
45
- redirects,
46
- redirectsOrigin,
47
- baseRelDir,
48
- functions,
49
- functionsDirectory,
50
- })
51
- const netlifyConfigA = truncateArray(netlifyConfig, 'headers')
52
- const netlifyConfigB = truncateArray(netlifyConfigA, 'redirects')
53
- return netlifyConfigB
54
- }
55
-
4
+ export const cleanupConfig = function ({ build: { base, command, commandOrigin, environment = {}, edge_functions: edgeFunctions, ignore, processing, publish, publishOrigin, } = {}, headers, headersOrigin, plugins = [], redirects, redirectsOrigin, baseRelDir, functions, functionsDirectory, }) {
5
+ const environmentA = cleanupEnvironment(environment);
6
+ const build = {
7
+ base,
8
+ command,
9
+ commandOrigin,
10
+ environment: environmentA,
11
+ edge_functions: edgeFunctions,
12
+ ignore,
13
+ processing,
14
+ publish,
15
+ publishOrigin,
16
+ };
17
+ const pluginsA = plugins.map(cleanupPlugin);
18
+ const netlifyConfig = simplifyConfig({
19
+ build,
20
+ plugins: pluginsA,
21
+ headers,
22
+ headersOrigin,
23
+ redirects,
24
+ redirectsOrigin,
25
+ baseRelDir,
26
+ functions,
27
+ functionsDirectory,
28
+ });
29
+ const netlifyConfigA = truncateArray(netlifyConfig, 'headers');
30
+ const netlifyConfigB = truncateArray(netlifyConfigA, 'redirects');
31
+ return netlifyConfigB;
32
+ };
56
33
  export const cleanupEnvironment = function (environment) {
57
- return Object.keys(environment).filter((key) => !BUILDBOT_ENVIRONMENT.has(key))
58
- }
59
-
34
+ return Object.keys(environment).filter((key) => !BUILDBOT_ENVIRONMENT.has(key));
35
+ };
60
36
  // Added by the buildbot. We only want to print environment variables specified
61
37
  // by the user.
62
38
  const BUILDBOT_ENVIRONMENT = new Set([
63
- 'BRANCH',
64
- 'CONTEXT',
65
- 'DEPLOY_PRIME_URL',
66
- 'DEPLOY_URL',
67
- 'GO_VERSION',
68
- 'NETLIFY_IMAGES_CDN_DOMAIN',
69
- 'SITE_ID',
70
- 'SITE_NAME',
71
- 'URL',
72
- ])
73
-
39
+ 'BRANCH',
40
+ 'CONTEXT',
41
+ 'DEPLOY_PRIME_URL',
42
+ 'DEPLOY_URL',
43
+ 'GO_VERSION',
44
+ 'NETLIFY_IMAGES_CDN_DOMAIN',
45
+ 'SITE_ID',
46
+ 'SITE_NAME',
47
+ 'URL',
48
+ ]);
74
49
  const cleanupPlugin = function ({ package: packageName, origin, inputs = {} }) {
75
- const inputsA = filterObj(inputs, isPublicInput)
76
- return { package: packageName, origin, inputs: inputsA }
77
- }
78
-
50
+ const inputsA = filterObj(inputs, isPublicInput);
51
+ return { package: packageName, origin, inputs: inputsA };
52
+ };
79
53
  const isPublicInput = function (key, input) {
80
- return typeof input === 'boolean'
81
- }
82
-
54
+ return typeof input === 'boolean';
55
+ };
83
56
  // `headers` and `redirects` can be very long, which can take several minutes
84
57
  // to print in the build logs. We truncate them before logging.
85
58
  const truncateArray = function (netlifyConfig, propName) {
86
- const array = netlifyConfig[propName]
87
- return Array.isArray(array) && array.length > MAX_ARRAY_LENGTH
88
- ? { ...netlifyConfig, [propName]: array.slice(0, MAX_ARRAY_LENGTH) }
89
- : netlifyConfig
90
- }
91
-
92
- const MAX_ARRAY_LENGTH = 100
59
+ const array = netlifyConfig[propName];
60
+ return Array.isArray(array) && array.length > MAX_ARRAY_LENGTH
61
+ ? { ...netlifyConfig, [propName]: array.slice(0, MAX_ARRAY_LENGTH) }
62
+ : netlifyConfig;
63
+ };
64
+ const MAX_ARRAY_LENGTH = 100;
package/lib/log/logger.js CHANGED
@@ -1,47 +1,36 @@
1
- import figures from 'figures'
2
-
3
- import { serializeObject } from './serialize.js'
4
- import { THEME } from './theme.js'
5
-
1
+ import figures from 'figures';
2
+ import { serializeObject } from './serialize.js';
3
+ import { THEME } from './theme.js';
6
4
  // When the `buffer` option is true, we return logs instead of printing them
7
5
  // on the console. The logs are accumulated in a `logs` array variable.
8
6
  export const getBufferLogs = function ({ buffer }) {
9
- if (!buffer) {
10
- return
11
- }
12
-
13
- return { stdout: [], stderr: [] }
14
- }
15
-
7
+ if (!buffer) {
8
+ return;
9
+ }
10
+ return { stdout: [], stderr: [] };
11
+ };
16
12
  // This should be used instead of `console.log()`
17
13
  // Printed on stderr because stdout is reserved for the JSON output
18
14
  export const log = function (logs, string, { color } = {}) {
19
- const stringA = String(string).replace(EMPTY_LINES_REGEXP, EMPTY_LINE)
20
- const stringB = color === undefined ? stringA : color(stringA)
21
-
22
- if (logs !== undefined) {
23
- // `logs` is a stateful variable
24
- // eslint-disable-next-line fp/no-mutating-methods
25
- logs.stderr.push(stringB)
26
- return
27
- }
28
-
29
- console.warn(stringB)
30
- }
31
-
15
+ const stringA = String(string).replace(EMPTY_LINES_REGEXP, EMPTY_LINE);
16
+ const stringB = color === undefined ? stringA : color(stringA);
17
+ if (logs !== undefined) {
18
+ // `logs` is a stateful variable
19
+ logs.stderr.push(stringB);
20
+ return;
21
+ }
22
+ console.warn(stringB);
23
+ };
32
24
  // We need to add a zero width space character in empty lines. Otherwise the
33
25
  // buildbot removes those due to a bug: https://github.com/netlify/buildbot/issues/595
34
- const EMPTY_LINES_REGEXP = /^\s*$/gm
35
- const EMPTY_LINE = '\u{200B}'
36
-
26
+ const EMPTY_LINES_REGEXP = /^\s*$/gm;
27
+ const EMPTY_LINE = '\u{200B}';
37
28
  export const logWarning = function (logs, string, opts) {
38
- log(logs, string, { color: THEME.warningLine, ...opts })
39
- }
40
-
29
+ log(logs, string, { color: THEME.warningLine, ...opts });
30
+ };
41
31
  export const logObject = function (logs, object, opts) {
42
- log(logs, serializeObject(object), opts)
43
- }
44
-
32
+ log(logs, serializeObject(object), opts);
33
+ };
45
34
  export const logSubHeader = function (logs, string, opts) {
46
- log(logs, `\n${figures.pointer} ${string}`, { color: THEME.subHeader, ...opts })
47
- }
35
+ log(logs, `\n${figures.pointer} ${string}`, { color: THEME.subHeader, ...opts });
36
+ };
package/lib/log/main.js CHANGED
@@ -1,48 +1,39 @@
1
- import { cleanupConfig, cleanupEnvironment } from './cleanup.js'
2
- import { logObject, logSubHeader } from './logger.js'
3
- import { cleanupConfigOpts } from './options.js'
4
-
1
+ import { cleanupConfig, cleanupEnvironment } from './cleanup.js';
2
+ import { logObject, logSubHeader } from './logger.js';
3
+ import { cleanupConfigOpts } from './options.js';
5
4
  // Log options in debug mode.
6
5
  export const logOpts = function (opts, { logs, debug, cachedConfig, cachedConfigPath }) {
7
- // In production, print those in the first call to `@netlify/config`, not the
8
- // second one done inside `@netlify/build`
9
- if (!debug || cachedConfig !== undefined || cachedConfigPath !== undefined) {
10
- return
11
- }
12
-
13
- logSubHeader(logs, 'Initial build environment')
14
- logObject(logs, cleanupConfigOpts(opts))
15
- }
16
-
6
+ // In production, print those in the first call to `@netlify/config`, not the
7
+ // second one done inside `@netlify/build`
8
+ if (!debug || cachedConfig !== undefined || cachedConfigPath !== undefined) {
9
+ return;
10
+ }
11
+ logSubHeader(logs, 'Initial build environment');
12
+ logObject(logs, cleanupConfigOpts(opts));
13
+ };
17
14
  // Log `defaultConfig` option in debug mode
18
15
  export const logDefaultConfig = function (defaultConfig, { logs, debug, baseRelDir }) {
19
- if (!debug || defaultConfig === undefined) {
20
- return
21
- }
22
-
23
- logSubHeader(logs, 'UI build settings')
24
- logObject(logs, cleanupConfig({ ...defaultConfig, baseRelDir }))
25
- }
26
-
16
+ if (!debug || defaultConfig === undefined) {
17
+ return;
18
+ }
19
+ logSubHeader(logs, 'UI build settings');
20
+ logObject(logs, cleanupConfig({ ...defaultConfig, baseRelDir }));
21
+ };
27
22
  // Log `inlineConfig` option in debug mode
28
23
  export const logInlineConfig = function (initialConfig, { logs, debug }) {
29
- if (!debug || Object.keys(initialConfig).length === 0) {
30
- return
31
- }
32
-
33
- logSubHeader(logs, 'Configuration override')
34
- logObject(logs, cleanupConfig(initialConfig))
35
- }
36
-
24
+ if (!debug || Object.keys(initialConfig).length === 0) {
25
+ return;
26
+ }
27
+ logSubHeader(logs, 'Configuration override');
28
+ logObject(logs, cleanupConfig(initialConfig));
29
+ };
37
30
  // Log return value of `@netlify/config` in debug mode
38
31
  export const logResult = function ({ configPath, buildDir, config, context, branch, env }, { logs, debug }) {
39
- if (!debug) {
40
- return
41
- }
42
-
43
- logSubHeader(logs, 'Resolved build environment')
44
- logObject(logs, { configPath, buildDir, context, branch, env: cleanupEnvironment(env) })
45
-
46
- logSubHeader(logs, 'Resolved config')
47
- logObject(logs, cleanupConfig(config))
48
- }
32
+ if (!debug) {
33
+ return;
34
+ }
35
+ logSubHeader(logs, 'Resolved build environment');
36
+ logObject(logs, { configPath, buildDir, context, branch, env: cleanupEnvironment(env) });
37
+ logSubHeader(logs, 'Resolved config');
38
+ logObject(logs, cleanupConfig(config));
39
+ };
@@ -1,126 +1,87 @@
1
- import { throwUserError } from '../error.js'
2
-
3
- import { logWarning } from './logger.js'
4
-
5
- export const ERROR_CALL_TO_ACTION = `Double-check your login status with 'netlify status' or contact support with details of your error.`
6
-
1
+ import { throwUserError } from '../error.js';
2
+ import { logWarning } from './logger.js';
3
+ export const ERROR_CALL_TO_ACTION = `Double-check your login status with 'netlify status' or contact support with details of your error.`;
7
4
  export const throwOnInvalidTomlSequence = function (invalidSequence) {
8
- throwUserError(
9
- `In netlify.toml, the following backslash should be escaped: ${invalidSequence}
10
- The following should be used instead: \\${invalidSequence}`,
11
- )
12
- }
13
-
5
+ throwUserError(`In netlify.toml, the following backslash should be escaped: ${invalidSequence}
6
+ The following should be used instead: \\${invalidSequence}`);
7
+ };
14
8
  export const warnLegacyFunctionsDirectory = ({ config = {}, logs }) => {
15
- const { functionsDirectory, functionsDirectoryOrigin } = config
16
-
17
- if (functionsDirectoryOrigin !== 'config-v1') {
18
- return
19
- }
20
-
21
- logWarning(
22
- logs,
23
- `
9
+ const { functionsDirectory, functionsDirectoryOrigin } = config;
10
+ if (functionsDirectoryOrigin !== 'config-v1') {
11
+ return;
12
+ }
13
+ logWarning(logs, `
24
14
  Detected functions directory configuration in netlify.toml under [build] settings.
25
15
  We recommend updating netlify.toml to set the functions directory under [functions] settings using the directory property. For example,
26
16
 
27
17
  [functions]
28
- directory = "${functionsDirectory}"`,
29
- )
30
- }
31
-
18
+ directory = "${functionsDirectory}"`);
19
+ };
32
20
  export const warnContextPluginConfig = function (logs, packageName, context) {
33
- logWarning(
34
- logs,
35
- `
21
+ logWarning(logs, `
36
22
  "${packageName}" is installed in the UI, which means that it runs in all deploy contexts, regardless of file-based configuration.
37
- To run "${packageName}" in the ${context} context only, uninstall the plugin from the site plugins list.`,
38
- )
39
- }
40
-
23
+ To run "${packageName}" in the ${context} context only, uninstall the plugin from the site plugins list.`);
24
+ };
41
25
  export const throwContextPluginsConfig = function (packageName, context) {
42
- throwUserError(
43
- `
26
+ throwUserError(`
44
27
  "${packageName}" is installed in the UI, which means that it runs in all deploy contexts, regardless of file-based configuration.
45
28
  To run "${packageName}" in the ${context} context only, uninstall the plugin from the site plugins list.
46
29
  To run "${packageName}" in all contexts, please remove the following section from "netlify.toml".
47
30
 
48
31
  [[context.${context}.plugins]]
49
32
  package = "${packageName}"
50
- `,
51
- )
52
- }
53
-
33
+ `);
34
+ };
54
35
  export const warnHeadersParsing = function (logs, errors) {
55
- if (errors.length === 0) {
56
- return
57
- }
58
-
59
- const errorMessage = errors.map(getErrorMessage).join('\n\n')
60
- logWarning(
61
- logs,
62
- `
36
+ if (errors.length === 0) {
37
+ return;
38
+ }
39
+ const errorMessage = errors.map(getErrorMessage).join('\n\n');
40
+ logWarning(logs, `
63
41
  Warning: some headers have syntax errors:
64
42
 
65
- ${errorMessage}`,
66
- )
67
- }
68
-
43
+ ${errorMessage}`);
44
+ };
69
45
  // Headers with different cases are not currently the way users probably
70
46
  // intend them to be, so we print a warning message.
71
47
  // See issue at https://github.com/netlify/build/issues/2290
72
48
  export const warnHeadersCaseSensitivity = function (logs, headers) {
73
- const headersA = headers.flatMap(getHeaderNames).filter(isNotDuplicateHeaderName).map(addHeaderLowerCase)
74
- const differentCaseHeader = headersA.find(hasHeaderCaseDuplicate)
75
- if (differentCaseHeader === undefined) {
76
- return
77
- }
78
-
79
- const { forPath, headerName } = headersA.find((header) => isHeaderCaseDuplicate(header, differentCaseHeader))
80
- const sameForPath = forPath === differentCaseHeader.forPath ? ` for "${forPath}"` : ''
81
- logWarning(
82
- logs,
83
- `
84
- Warning: the same header is set twice with different cases${sameForPath}: "${headerName}" and "${differentCaseHeader.headerName}"`,
85
- )
86
- }
87
-
49
+ const headersA = headers.flatMap(getHeaderNames).filter(isNotDuplicateHeaderName).map(addHeaderLowerCase);
50
+ const differentCaseHeader = headersA.find(hasHeaderCaseDuplicate);
51
+ if (differentCaseHeader === undefined) {
52
+ return;
53
+ }
54
+ const { forPath, headerName } = headersA.find((header) => isHeaderCaseDuplicate(header, differentCaseHeader));
55
+ const sameForPath = forPath === differentCaseHeader.forPath ? ` for "${forPath}"` : '';
56
+ logWarning(logs, `
57
+ Warning: the same header is set twice with different cases${sameForPath}: "${headerName}" and "${differentCaseHeader.headerName}"`);
58
+ };
88
59
  const getHeaderNames = function ({ for: forPath, values = {} }) {
89
- return Object.keys(values).map((headerName) => ({ forPath, headerName }))
90
- }
91
-
60
+ return Object.keys(values).map((headerName) => ({ forPath, headerName }));
61
+ };
92
62
  const isNotDuplicateHeaderName = function ({ headerName }, index, headers) {
93
- return headers.slice(index + 1).every((header) => header.headerName !== headerName)
94
- }
95
-
63
+ return headers.slice(index + 1).every((header) => header.headerName !== headerName);
64
+ };
96
65
  const addHeaderLowerCase = function ({ forPath, headerName }) {
97
- const lowerHeaderName = headerName.toLowerCase()
98
- return { forPath, headerName, lowerHeaderName }
99
- }
100
-
66
+ const lowerHeaderName = headerName.toLowerCase();
67
+ return { forPath, headerName, lowerHeaderName };
68
+ };
101
69
  const hasHeaderCaseDuplicate = function ({ lowerHeaderName }, index, headers) {
102
- return headers.slice(index + 1).some((header) => header.lowerHeaderName === lowerHeaderName)
103
- }
104
-
70
+ return headers.slice(index + 1).some((header) => header.lowerHeaderName === lowerHeaderName);
71
+ };
105
72
  const isHeaderCaseDuplicate = function ({ headerName, lowerHeaderName }, differentCaseHeader) {
106
- return differentCaseHeader.headerName !== headerName && differentCaseHeader.lowerHeaderName === lowerHeaderName
107
- }
108
-
73
+ return differentCaseHeader.headerName !== headerName && differentCaseHeader.lowerHeaderName === lowerHeaderName;
74
+ };
109
75
  export const warnRedirectsParsing = function (logs, errors) {
110
- if (errors.length === 0) {
111
- return
112
- }
113
-
114
- const errorMessage = errors.map(getErrorMessage).join('\n\n')
115
- logWarning(
116
- logs,
117
- `
76
+ if (errors.length === 0) {
77
+ return;
78
+ }
79
+ const errorMessage = errors.map(getErrorMessage).join('\n\n');
80
+ logWarning(logs, `
118
81
  Warning: some redirects have syntax errors:
119
82
 
120
- ${errorMessage}`,
121
- )
122
- }
123
-
83
+ ${errorMessage}`);
84
+ };
124
85
  const getErrorMessage = function ({ message }) {
125
- return message
126
- }
86
+ return message;
87
+ };