@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
package/lib/env/main.js CHANGED
@@ -1,202 +1,150 @@
1
- import omit from 'omit.js'
2
-
3
- import { removeFalsy } from '../utils/remove_falsy.js'
4
-
5
- import { getEnvelope } from './envelope.js'
6
- import { getGitEnv } from './git.js'
7
-
1
+ import omit from 'omit.js';
2
+ import { removeFalsy } from '../utils/remove_falsy.js';
3
+ import { getEnvelope } from './envelope.js';
4
+ import { getGitEnv } from './git.js';
8
5
  // Retrieve this site's environment variable. Also take into account team-wide
9
6
  // environment variables and addons.
10
7
  // The buildbot already has the right environment variables. This is mostly
11
8
  // meant so that local builds can mimic production builds
12
9
  // TODO: add `netlify.toml` `build.environment`, after normalization
13
10
  // TODO: add `CONTEXT` and others
14
- export const getEnv = async function ({
15
- api,
16
- mode,
17
- config,
18
- siteInfo,
19
- accounts,
20
- addons,
21
- buildDir,
22
- branch,
23
- deployId,
24
- buildId,
25
- context,
26
- }) {
27
- if (mode === 'buildbot') {
28
- return {}
29
- }
30
-
31
- const generalEnv = await getGeneralEnv({ siteInfo, buildDir, branch, deployId, buildId, context })
32
- const [accountEnv, addonsEnv, uiEnv, configFileEnv] = await getUserEnv({ api, config, siteInfo, accounts, addons })
33
-
34
- // Sources of environment variables, in descending order of precedence.
35
- const sources = [
36
- { key: 'configFile', values: configFileEnv },
37
- { key: 'ui', values: uiEnv },
38
- { key: 'addons', values: addonsEnv },
39
- { key: 'account', values: accountEnv },
40
- { key: 'general', values: generalEnv },
41
- ]
42
-
43
- // A hash mapping names of environment variables to objects containing the following properties:
44
- // - sources: List of sources where the environment variable was found. The first element is the source that
45
- // actually provided the variable (i.e. the one with the highest precedence).
46
- // - value: The value of the environment variable.
47
- const env = new Map()
48
-
49
- sources.forEach((source) => {
50
- Object.keys(source.values).forEach((key) => {
51
- if (env.has(key)) {
52
- const { sources: envSources, value } = env.get(key)
53
-
54
- env.set(key, {
55
- sources: [...envSources, source.key],
56
- value: convertToString(value),
57
- })
58
- } else {
59
- env.set(key, {
60
- sources: [source.key],
61
- value: convertToString(source.values[key]),
62
- })
63
- }
64
- })
65
- })
66
-
67
- return Object.fromEntries(env)
68
- }
69
-
11
+ export const getEnv = async function ({ api, mode, config, siteInfo, accounts, addons, buildDir, branch, deployId, buildId, context, }) {
12
+ if (mode === 'buildbot') {
13
+ return {};
14
+ }
15
+ const generalEnv = await getGeneralEnv({ siteInfo, buildDir, branch, deployId, buildId, context });
16
+ const [accountEnv, addonsEnv, uiEnv, configFileEnv] = await getUserEnv({ api, config, siteInfo, accounts, addons });
17
+ // Sources of environment variables, in descending order of precedence.
18
+ const sources = [
19
+ { key: 'configFile', values: configFileEnv },
20
+ { key: 'ui', values: uiEnv },
21
+ { key: 'addons', values: addonsEnv },
22
+ { key: 'account', values: accountEnv },
23
+ { key: 'general', values: generalEnv },
24
+ ];
25
+ // A hash mapping names of environment variables to objects containing the following properties:
26
+ // - sources: List of sources where the environment variable was found. The first element is the source that
27
+ // actually provided the variable (i.e. the one with the highest precedence).
28
+ // - value: The value of the environment variable.
29
+ const env = new Map();
30
+ sources.forEach((source) => {
31
+ Object.keys(source.values).forEach((key) => {
32
+ if (env.has(key)) {
33
+ const { sources: envSources, value } = env.get(key);
34
+ env.set(key, {
35
+ sources: [...envSources, source.key],
36
+ value: convertToString(value),
37
+ });
38
+ }
39
+ else {
40
+ env.set(key, {
41
+ sources: [source.key],
42
+ value: convertToString(source.values[key]),
43
+ });
44
+ }
45
+ });
46
+ });
47
+ return Object.fromEntries(env);
48
+ };
70
49
  const convertToString = (value) => {
71
- if (value === null || value === undefined) {
72
- return value
73
- }
74
-
75
- if (typeof value === 'string') {
76
- return value
77
- }
78
-
79
- return value.toString()
80
- }
81
-
50
+ if (value === null || value === undefined) {
51
+ return value;
52
+ }
53
+ if (typeof value === 'string') {
54
+ return value;
55
+ }
56
+ return value.toString();
57
+ };
82
58
  // Environment variables not set by users, but meant to mimic the production
83
59
  // environment.
84
- const getGeneralEnv = async function ({
85
- siteInfo,
86
- siteInfo: { id, name },
87
- buildDir,
88
- branch,
89
- deployId,
90
- buildId,
91
- context,
92
- }) {
93
- const gitEnv = await getGitEnv(buildDir, branch)
94
- const deployUrls = getDeployUrls({ siteInfo, branch, deployId })
95
- return removeFalsy({
96
- SITE_ID: id,
97
- SITE_NAME: name,
98
- DEPLOY_ID: deployId,
99
- BUILD_ID: buildId,
100
- ...deployUrls,
101
- CONTEXT: context,
102
- NETLIFY_LOCAL: 'true',
103
- ...gitEnv,
104
- // Localization
105
- LANG: 'en_US.UTF-8',
106
- LANGUAGE: 'en_US:en',
107
- LC_ALL: 'en_US.UTF-8',
108
- // Disable telemetry of some tools
109
- GATSBY_TELEMETRY_DISABLED: '1',
110
- NEXT_TELEMETRY_DISABLED: '1',
111
- })
112
- }
113
-
114
- const getDeployUrls = function ({
115
- siteInfo: { name = DEFAULT_SITE_NAME, ssl_url: sslUrl, build_settings: { repo_url: REPOSITORY_URL } = {} },
116
- branch,
117
- deployId,
118
- }) {
119
- return {
120
- URL: sslUrl,
121
- REPOSITORY_URL,
122
- DEPLOY_PRIME_URL: `https://${branch}--${name}${NETLIFY_DEFAULT_DOMAIN}`,
123
- DEPLOY_URL: `https://${deployId}--${name}${NETLIFY_DEFAULT_DOMAIN}`,
124
- }
125
- }
126
-
127
- const NETLIFY_DEFAULT_DOMAIN = '.netlify.app'
60
+ const getGeneralEnv = async function ({ siteInfo, siteInfo: { id, name }, buildDir, branch, deployId, buildId, context, }) {
61
+ const gitEnv = await getGitEnv(buildDir, branch);
62
+ const deployUrls = getDeployUrls({ siteInfo, branch, deployId });
63
+ return removeFalsy({
64
+ SITE_ID: id,
65
+ SITE_NAME: name,
66
+ DEPLOY_ID: deployId,
67
+ BUILD_ID: buildId,
68
+ ...deployUrls,
69
+ CONTEXT: context,
70
+ NETLIFY_LOCAL: 'true',
71
+ ...gitEnv,
72
+ // Localization
73
+ LANG: 'en_US.UTF-8',
74
+ LANGUAGE: 'en_US:en',
75
+ LC_ALL: 'en_US.UTF-8',
76
+ // Disable telemetry of some tools
77
+ GATSBY_TELEMETRY_DISABLED: '1',
78
+ NEXT_TELEMETRY_DISABLED: '1',
79
+ });
80
+ };
81
+ const getDeployUrls = function ({ siteInfo: { name = DEFAULT_SITE_NAME, ssl_url: sslUrl, build_settings: { repo_url: REPOSITORY_URL } = {} }, branch, deployId, }) {
82
+ return {
83
+ URL: sslUrl,
84
+ REPOSITORY_URL,
85
+ DEPLOY_PRIME_URL: `https://${branch}--${name}${NETLIFY_DEFAULT_DOMAIN}`,
86
+ DEPLOY_URL: `https://${deployId}--${name}${NETLIFY_DEFAULT_DOMAIN}`,
87
+ };
88
+ };
89
+ const NETLIFY_DEFAULT_DOMAIN = '.netlify.app';
128
90
  // `site.name` is `undefined` when there is no token or siteId
129
- const DEFAULT_SITE_NAME = 'site-name'
130
-
91
+ const DEFAULT_SITE_NAME = 'site-name';
131
92
  // Environment variables specified by the user
132
93
  const getUserEnv = async function ({ api, config, siteInfo, accounts, addons }) {
133
- const accountEnv = await getAccountEnv({ api, siteInfo, accounts })
134
- const addonsEnv = getAddonsEnv(addons)
135
- const uiEnv = getUiEnv({ siteInfo })
136
- const configFileEnv = getConfigFileEnv({ config })
137
- return [accountEnv, addonsEnv, uiEnv, configFileEnv].map(cleanUserEnv)
138
- }
139
-
94
+ const accountEnv = await getAccountEnv({ api, siteInfo, accounts });
95
+ const addonsEnv = getAddonsEnv(addons);
96
+ const uiEnv = getUiEnv({ siteInfo });
97
+ const configFileEnv = getConfigFileEnv({ config });
98
+ return [accountEnv, addonsEnv, uiEnv, configFileEnv].map(cleanUserEnv);
99
+ };
140
100
  // Account-wide environment variables
141
101
  const getAccountEnv = async function ({ api, siteInfo, accounts }) {
142
- if (siteInfo.use_envelope) {
143
- const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug })
144
- return envelope
145
- }
146
- const { site_env: siteEnv = {} } = accounts.find(({ slug }) => slug === siteInfo.account_slug) || {}
147
- return siteEnv
148
- }
149
-
102
+ if (siteInfo.use_envelope) {
103
+ const envelope = await getEnvelope({ api, accountId: siteInfo.account_slug });
104
+ return envelope;
105
+ }
106
+ const { site_env: siteEnv = {} } = accounts.find(({ slug }) => slug === siteInfo.account_slug) || {};
107
+ return siteEnv;
108
+ };
150
109
  // Environment variables from addons
151
110
  const getAddonsEnv = function (addons) {
152
- return Object.assign({}, ...addons.map(getAddonEnv))
153
- }
154
-
111
+ return Object.assign({}, ...addons.map(getAddonEnv));
112
+ };
155
113
  const getAddonEnv = function ({ env }) {
156
- return env
157
- }
158
-
114
+ return env;
115
+ };
159
116
  // Site-specific environment variables set in the UI
160
117
  const getUiEnv = function ({ siteInfo: { build_settings: { env = {} } = {} } }) {
161
- return env
162
- }
163
-
118
+ return env;
119
+ };
164
120
  // Site-specific environment variables set in netlify.toml
165
- const getConfigFileEnv = function ({
166
- config: {
167
- build: { environment = {} },
168
- },
169
- }) {
170
- return environment
171
- }
172
-
121
+ const getConfigFileEnv = function ({ config: { build: { environment = {} }, }, }) {
122
+ return environment;
123
+ };
173
124
  // Some environment variables cannot be overridden by configuration
174
125
  const cleanUserEnv = function (userEnv) {
175
- return omit.default(userEnv, READONLY_ENV)
176
- }
177
-
126
+ return omit.default(userEnv, READONLY_ENV);
127
+ };
178
128
  const READONLY_ENV = [
179
- // Set in local builds
180
- 'BRANCH',
181
- 'CACHED_COMMIT_REF',
182
- 'COMMIT_REF',
183
- 'CONTEXT',
184
- 'HEAD',
185
- 'REPOSITORY_URL',
186
- 'URL',
187
-
188
- // CI builds set NETLIFY=true while CLI and programmatic builds set
189
- // NETLIFY_LOCAL=true
190
- 'NETLIFY',
191
- 'NETLIFY_LOCAL',
192
-
193
- // Not set in local builds because there is no CI build/deploy, incoming hooks nor PR
194
- 'INCOMING_HOOK_BODY',
195
- 'INCOMING_HOOK_TITLE',
196
- 'INCOMING_HOOK_URL',
197
- 'NETLIFY_BUILD_BASE',
198
- 'NETLIFY_BUILD_LIFECYCLE_TRIAL',
199
- 'NETLIFY_IMAGES_CDN_DOMAIN',
200
- 'PULL_REQUEST',
201
- 'REVIEW_ID',
202
- ]
129
+ // Set in local builds
130
+ 'BRANCH',
131
+ 'CACHED_COMMIT_REF',
132
+ 'COMMIT_REF',
133
+ 'CONTEXT',
134
+ 'HEAD',
135
+ 'REPOSITORY_URL',
136
+ 'URL',
137
+ // CI builds set NETLIFY=true while CLI and programmatic builds set
138
+ // NETLIFY_LOCAL=true
139
+ 'NETLIFY',
140
+ 'NETLIFY_LOCAL',
141
+ // Not set in local builds because there is no CI build/deploy, incoming hooks nor PR
142
+ 'INCOMING_HOOK_BODY',
143
+ 'INCOMING_HOOK_TITLE',
144
+ 'INCOMING_HOOK_URL',
145
+ 'NETLIFY_BUILD_BASE',
146
+ 'NETLIFY_BUILD_LIFECYCLE_TRIAL',
147
+ 'NETLIFY_IMAGES_CDN_DOMAIN',
148
+ 'PULL_REQUEST',
149
+ 'REVIEW_ID',
150
+ ];
package/lib/error.js CHANGED
@@ -1,36 +1,28 @@
1
1
  // We distinguish between errors thrown intentionally and uncaught exceptions
2
2
  // (such as bugs) with a `customErrorInfo.type` property.
3
3
  export const throwUserError = function (messageOrError, error) {
4
- const errorA = getError(messageOrError, error)
5
- errorA[CUSTOM_ERROR_KEY] = { type: USER_ERROR_TYPE }
6
- throw errorA
7
- }
8
-
4
+ const errorA = getError(messageOrError, error);
5
+ errorA[CUSTOM_ERROR_KEY] = { type: USER_ERROR_TYPE };
6
+ throw errorA;
7
+ };
9
8
  // Can pass either `message`, `error` or `message, error`
10
9
  const getError = function (messageOrError, error) {
11
- if (messageOrError instanceof Error) {
12
- return messageOrError
13
- }
14
-
15
- if (error === undefined) {
16
- return new Error(messageOrError)
17
- }
18
-
19
- error.message = `${messageOrError}\n${error.message}`
20
- return error
21
- }
22
-
10
+ if (messageOrError instanceof Error) {
11
+ return messageOrError;
12
+ }
13
+ if (error === undefined) {
14
+ return new Error(messageOrError);
15
+ }
16
+ error.message = `${messageOrError}\n${error.message}`;
17
+ return error;
18
+ };
23
19
  export const isUserError = function (error) {
24
- return (
25
- canHaveErrorInfo(error) && error[CUSTOM_ERROR_KEY] !== undefined && error[CUSTOM_ERROR_KEY].type === USER_ERROR_TYPE
26
- )
27
- }
28
-
20
+ return (canHaveErrorInfo(error) && error[CUSTOM_ERROR_KEY] !== undefined && error[CUSTOM_ERROR_KEY].type === USER_ERROR_TYPE);
21
+ };
29
22
  // Exceptions that are not objects (including `Error` instances) cannot have an
30
23
  // `CUSTOM_ERROR_KEY` property
31
24
  const canHaveErrorInfo = function (error) {
32
- return error != null
33
- }
34
-
35
- const CUSTOM_ERROR_KEY = 'customErrorInfo'
36
- const USER_ERROR_TYPE = 'resolveConfig'
25
+ return error != null;
26
+ };
27
+ const CUSTOM_ERROR_KEY = 'customErrorInfo';
28
+ const USER_ERROR_TYPE = 'resolveConfig';
package/lib/events.js CHANGED
@@ -1,22 +1,21 @@
1
1
  // List of build plugins events
2
2
  export const EVENTS = [
3
- // Before build command
4
- 'onPreBuild',
5
- // After build command, before Functions bundling
6
- 'onBuild',
7
- // After Functions bundling
8
- 'onPostBuild',
9
- // After build success
10
- 'onSuccess',
11
- // After build error
12
- 'onError',
13
- // After build error or success
14
- 'onEnd',
15
- ]
16
-
3
+ // Before build command
4
+ 'onPreBuild',
5
+ // After build command, before Functions bundling
6
+ 'onBuild',
7
+ // After Functions bundling
8
+ 'onPostBuild',
9
+ // After build success
10
+ 'onSuccess',
11
+ // After build error
12
+ 'onError',
13
+ // After build error or success
14
+ 'onEnd',
15
+ ];
17
16
  export const DEV_EVENTS = [
18
- // Before dev command
19
- 'onPreDev',
20
- // The dev command
21
- 'onDev',
22
- ]
17
+ // Before dev command
18
+ 'onPreDev',
19
+ // The dev command
20
+ 'onDev',
21
+ ];
package/lib/files.js CHANGED
@@ -1,107 +1,83 @@
1
- import { resolve, relative, parse } from 'path'
2
-
3
- import { getProperty, setProperty, deleteProperty } from 'dot-prop'
4
- import { pathExists } from 'path-exists'
5
-
6
- import { throwUserError } from './error.js'
7
- import { mergeConfigs } from './merge.js'
8
- import { isTruthy } from './utils/remove_falsy.js'
9
-
1
+ import { resolve, relative, parse } from 'path';
2
+ import { getProperty, setProperty, deleteProperty } from 'dot-prop';
3
+ import { pathExists } from 'path-exists';
4
+ import { throwUserError } from './error.js';
5
+ import { mergeConfigs } from './merge.js';
6
+ import { isTruthy } from './utils/remove_falsy.js';
10
7
  // Make configuration paths relative to `buildDir` and converts them to
11
8
  // absolute paths
12
9
  export const resolveConfigPaths = async function ({ config, repositoryRoot, buildDir, baseRelDir }) {
13
- const baseRel = baseRelDir ? buildDir : repositoryRoot
14
- const configA = resolvePaths(config, FILE_PATH_CONFIG_PROPS, baseRel, repositoryRoot)
15
- const configB = await addDefaultPaths(configA, repositoryRoot, baseRel)
16
- return configB
17
- }
18
-
10
+ const baseRel = baseRelDir ? buildDir : repositoryRoot;
11
+ const configA = resolvePaths(config, FILE_PATH_CONFIG_PROPS, baseRel, repositoryRoot);
12
+ const configB = await addDefaultPaths(configA, repositoryRoot, baseRel);
13
+ return configB;
14
+ };
19
15
  // All file paths in the configuration file are are relative to `buildDir`
20
16
  // (if `baseRelDir` is `true`).
21
- const FILE_PATH_CONFIG_PROPS = ['functionsDirectory', 'build.publish', 'build.edge_functions']
22
-
17
+ const FILE_PATH_CONFIG_PROPS = ['functionsDirectory', 'build.publish', 'build.edge_functions'];
23
18
  const resolvePaths = function (config, propNames, baseRel, repositoryRoot) {
24
- return propNames.reduce((configA, propName) => resolvePathProp(configA, propName, baseRel, repositoryRoot), config)
25
- }
26
-
19
+ return propNames.reduce((configA, propName) => resolvePathProp(configA, propName, baseRel, repositoryRoot), config);
20
+ };
27
21
  const resolvePathProp = function (config, propName, baseRel, repositoryRoot) {
28
- const path = getProperty(config, propName)
29
-
30
- if (!isTruthy(path)) {
31
- deleteProperty(config, propName)
32
- return config
33
- }
34
-
35
- return setProperty(config, propName, resolvePath(repositoryRoot, baseRel, path, propName))
36
- }
37
-
22
+ const path = getProperty(config, propName);
23
+ if (!isTruthy(path)) {
24
+ deleteProperty(config, propName);
25
+ return config;
26
+ }
27
+ return setProperty(config, propName, resolvePath(repositoryRoot, baseRel, path, propName));
28
+ };
38
29
  export const resolvePath = function (repositoryRoot, baseRel, originalPath, propName) {
39
- if (!isTruthy(originalPath)) {
40
- return
41
- }
42
-
43
- const path = originalPath.replace(LEADING_SLASH_REGEXP, '')
44
- const pathA = resolve(baseRel, path)
45
- validateInsideRoot(originalPath, pathA, repositoryRoot, propName)
46
- return pathA
47
- }
48
-
30
+ if (!isTruthy(originalPath)) {
31
+ return;
32
+ }
33
+ const path = originalPath.replace(LEADING_SLASH_REGEXP, '');
34
+ const pathA = resolve(baseRel, path);
35
+ validateInsideRoot(originalPath, pathA, repositoryRoot, propName);
36
+ return pathA;
37
+ };
49
38
  // We allow paths in configuration file to start with /
50
39
  // In that case, those are actually relative paths not absolute.
51
- const LEADING_SLASH_REGEXP = /^\/+/
52
-
40
+ const LEADING_SLASH_REGEXP = /^\/+/;
53
41
  // We ensure all file paths are within the repository root directory.
54
42
  // However we allow file paths to be outside of the build directory, since this
55
43
  // can be convenient in monorepo setups.
56
44
  const validateInsideRoot = function (originalPath, path, repositoryRoot, propName) {
57
- if (relative(repositoryRoot, path).startsWith('..') || getWindowsDrive(repositoryRoot) !== getWindowsDrive(path)) {
58
- throwUserError(
59
- `Configuration property "${propName}" "${originalPath}" must be inside the repository root directory.`,
60
- )
61
- }
62
- }
63
-
45
+ if (relative(repositoryRoot, path).startsWith('..') || getWindowsDrive(repositoryRoot) !== getWindowsDrive(path)) {
46
+ throwUserError(`Configuration property "${propName}" "${originalPath}" must be inside the repository root directory.`);
47
+ }
48
+ };
64
49
  const getWindowsDrive = function (path) {
65
- return parse(path).root
66
- }
67
-
50
+ return parse(path).root;
51
+ };
68
52
  // Some configuration properties have default values that are only set if a
69
53
  // specific directory/file exists in the build directory
70
54
  const addDefaultPaths = async function (config, repositoryRoot, baseRel) {
71
- const defaultPathsConfigs = await Promise.all(
72
- DEFAULT_PATHS.map(({ defaultPath, getConfig, propName }) =>
73
- addDefaultPath({ repositoryRoot, baseRel, defaultPath, getConfig, propName }),
74
- ),
75
- )
76
- const defaultPathsConfigsA = defaultPathsConfigs.filter(Boolean)
77
- return mergeConfigs([...defaultPathsConfigsA, config])
78
- }
79
-
55
+ const defaultPathsConfigs = await Promise.all(DEFAULT_PATHS.map(({ defaultPath, getConfig, propName }) => addDefaultPath({ repositoryRoot, baseRel, defaultPath, getConfig, propName })));
56
+ const defaultPathsConfigsA = defaultPathsConfigs.filter(Boolean);
57
+ return mergeConfigs([...defaultPathsConfigsA, config]);
58
+ };
80
59
  const DEFAULT_PATHS = [
81
- // @todo Remove once we drop support for the legacy default functions directory.
82
- {
83
- getConfig: (directory) => ({ functionsDirectory: directory, functionsDirectoryOrigin: 'default-v1' }),
84
- defaultPath: 'netlify-automatic-functions',
85
- propName: 'functions.directory',
86
- },
87
- {
88
- getConfig: (directory) => ({ functionsDirectory: directory, functionsDirectoryOrigin: 'default' }),
89
- defaultPath: 'netlify/functions',
90
- propName: 'functions.directory',
91
- },
92
- {
93
- getConfig: (directory) => ({ build: { edge_functions: directory } }),
94
- defaultPath: 'netlify/edge-functions',
95
- propName: 'build.edge_functions',
96
- },
97
- ]
98
-
60
+ // @todo Remove once we drop support for the legacy default functions directory.
61
+ {
62
+ getConfig: (directory) => ({ functionsDirectory: directory, functionsDirectoryOrigin: 'default-v1' }),
63
+ defaultPath: 'netlify-automatic-functions',
64
+ propName: 'functions.directory',
65
+ },
66
+ {
67
+ getConfig: (directory) => ({ functionsDirectory: directory, functionsDirectoryOrigin: 'default' }),
68
+ defaultPath: 'netlify/functions',
69
+ propName: 'functions.directory',
70
+ },
71
+ {
72
+ getConfig: (directory) => ({ build: { edge_functions: directory } }),
73
+ defaultPath: 'netlify/edge-functions',
74
+ propName: 'build.edge_functions',
75
+ },
76
+ ];
99
77
  const addDefaultPath = async function ({ repositoryRoot, baseRel, defaultPath, getConfig, propName }) {
100
- const absolutePath = resolvePath(repositoryRoot, baseRel, defaultPath, propName)
101
-
102
- if (!(await pathExists(absolutePath))) {
103
- return
104
- }
105
-
106
- return getConfig(absolutePath)
107
- }
78
+ const absolutePath = resolvePath(repositoryRoot, baseRel, defaultPath, propName);
79
+ if (!(await pathExists(absolutePath))) {
80
+ return;
81
+ }
82
+ return getConfig(absolutePath);
83
+ };