@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.
- package/bin.js +5 -0
- package/lib/api/build_settings.js +20 -33
- package/lib/api/client.js +10 -13
- package/lib/api/site_info.js +48 -56
- package/lib/base.js +10 -18
- package/lib/bin/flags.js +134 -142
- package/lib/bin/main.js +49 -63
- package/lib/build_dir.js +11 -15
- package/lib/cached_config.js +14 -17
- package/lib/case.js +16 -35
- package/lib/context.js +62 -84
- package/lib/default.js +18 -22
- package/lib/env/envelope.js +23 -23
- package/lib/env/git.js +18 -18
- package/lib/env/main.js +127 -179
- package/lib/error.js +19 -27
- package/lib/events.js +18 -19
- package/lib/files.js +63 -87
- package/lib/functions_config.js +36 -52
- package/lib/headers.js +17 -27
- package/lib/inline_config.js +6 -7
- package/lib/log/cleanup.js +54 -82
- package/lib/log/logger.js +25 -36
- package/lib/log/main.js +31 -40
- package/lib/log/messages.js +56 -95
- package/lib/log/options.js +24 -38
- package/lib/log/serialize.js +3 -4
- package/lib/log/theme.js +10 -11
- package/lib/main.js +188 -263
- package/lib/merge.js +25 -35
- package/lib/merge_normalize.js +17 -24
- package/lib/mutations/apply.js +53 -65
- package/lib/mutations/config_prop_name.js +6 -8
- package/lib/mutations/update.js +79 -98
- package/lib/normalize.js +24 -28
- package/lib/options/base.js +39 -51
- package/lib/options/branch.js +23 -26
- package/lib/options/feature_flags.js +7 -10
- package/lib/options/main.js +76 -96
- package/lib/options/repository_root.js +11 -16
- package/lib/origin.js +22 -29
- package/lib/parse.js +42 -55
- package/lib/path.js +29 -40
- package/lib/redirects.js +16 -26
- package/lib/simplify.js +66 -92
- package/lib/utils/group.js +5 -6
- package/lib/utils/remove_falsy.js +9 -13
- package/lib/utils/set.js +19 -25
- package/lib/utils/toml.js +13 -16
- package/lib/validate/context.js +24 -43
- package/lib/validate/example.js +20 -27
- package/lib/validate/helpers.js +17 -23
- package/lib/validate/identical.js +8 -12
- package/lib/validate/main.js +83 -127
- package/lib/validate/validations.js +243 -257
- package/package.json +13 -8
package/lib/env/main.js
CHANGED
|
@@ -1,202 +1,150 @@
|
|
|
1
|
-
import omit from 'omit.js'
|
|
2
|
-
|
|
3
|
-
import {
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
Object.
|
|
51
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
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
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
153
|
-
}
|
|
154
|
-
|
|
111
|
+
return Object.assign({}, ...addons.map(getAddonEnv));
|
|
112
|
+
};
|
|
155
113
|
const getAddonEnv = function ({ env }) {
|
|
156
|
-
|
|
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
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
118
|
+
return env;
|
|
119
|
+
};
|
|
164
120
|
// Site-specific environment variables set in netlify.toml
|
|
165
|
-
const getConfigFileEnv = function ({
|
|
166
|
-
|
|
167
|
-
|
|
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
|
-
|
|
176
|
-
}
|
|
177
|
-
|
|
126
|
+
return omit.default(userEnv, READONLY_ENV);
|
|
127
|
+
};
|
|
178
128
|
const READONLY_ENV = [
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
25
|
-
|
|
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
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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 {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
import {
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
+
};
|