@netlify/build 27.20.4 → 27.20.6
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/lib/core/bin.js +42 -59
- package/lib/core/build.js +333 -536
- package/lib/core/config.js +94 -159
- package/lib/core/constants.js +95 -135
- package/lib/core/dev.js +26 -30
- package/lib/core/dry.js +18 -36
- package/lib/core/feature_flags.js +13 -16
- package/lib/core/flags.js +168 -169
- package/lib/core/lingering.js +44 -61
- package/lib/core/main.js +94 -136
- package/lib/core/missing_side_file.js +12 -24
- package/lib/core/normalize_flags.js +52 -63
- package/lib/core/severity.js +13 -15
- package/lib/core/user_node_version.js +26 -35
- package/lib/env/changes.js +29 -37
- package/lib/env/main.js +10 -15
- package/lib/env/metadata.js +63 -76
- package/lib/error/api.js +31 -40
- package/lib/error/build.js +27 -38
- package/lib/error/cancel.js +5 -6
- package/lib/error/colors.js +7 -9
- package/lib/error/handle.js +38 -49
- package/lib/error/info.js +26 -35
- package/lib/error/monitor/location.js +12 -17
- package/lib/error/monitor/normalize.js +75 -85
- package/lib/error/monitor/print.js +19 -41
- package/lib/error/monitor/report.js +102 -121
- package/lib/error/monitor/start.js +43 -56
- package/lib/error/parse/clean_stack.js +52 -69
- package/lib/error/parse/location.js +40 -52
- package/lib/error/parse/normalize.js +18 -23
- package/lib/error/parse/parse.js +59 -93
- package/lib/error/parse/plugin.js +42 -57
- package/lib/error/parse/properties.js +13 -20
- package/lib/error/parse/serialize_log.js +29 -37
- package/lib/error/parse/serialize_status.js +15 -23
- package/lib/error/parse/stack.js +29 -38
- package/lib/error/type.js +132 -150
- package/lib/install/functions.js +16 -24
- package/lib/install/local.js +31 -48
- package/lib/install/main.js +52 -66
- package/lib/install/missing.js +40 -53
- package/lib/log/colors.js +15 -22
- package/lib/log/description.js +16 -21
- package/lib/log/header.js +11 -13
- package/lib/log/header_func.js +11 -15
- package/lib/log/logger.js +88 -119
- package/lib/log/messages/compatibility.js +100 -158
- package/lib/log/messages/config.js +76 -92
- package/lib/log/messages/core.js +40 -60
- package/lib/log/messages/core_steps.js +63 -92
- package/lib/log/messages/dry.js +31 -53
- package/lib/log/messages/install.js +21 -28
- package/lib/log/messages/ipc.js +21 -30
- package/lib/log/messages/mutations.js +51 -71
- package/lib/log/messages/plugins.js +18 -31
- package/lib/log/messages/status.js +12 -14
- package/lib/log/messages/steps.js +14 -18
- package/lib/log/old_version.js +23 -32
- package/lib/log/serialize.js +7 -10
- package/lib/log/stream.js +48 -65
- package/lib/log/theme.js +22 -23
- package/lib/plugins/child/diff.js +31 -40
- package/lib/plugins/child/error.js +20 -26
- package/lib/plugins/child/lazy.js +11 -14
- package/lib/plugins/child/load.js +15 -22
- package/lib/plugins/child/logic.js +51 -58
- package/lib/plugins/child/main.js +32 -46
- package/lib/plugins/child/run.js +18 -27
- package/lib/plugins/child/status.js +52 -63
- package/lib/plugins/child/typescript.js +19 -36
- package/lib/plugins/child/utils.js +36 -49
- package/lib/plugins/child/validate.js +25 -28
- package/lib/plugins/compatibility.js +64 -92
- package/lib/plugins/error.js +29 -35
- package/lib/plugins/events.js +7 -12
- package/lib/plugins/expected_version.js +61 -99
- package/lib/plugins/ipc.js +79 -102
- package/lib/plugins/list.js +49 -62
- package/lib/plugins/load.js +44 -64
- package/lib/plugins/manifest/check.js +64 -85
- package/lib/plugins/manifest/load.js +34 -37
- package/lib/plugins/manifest/main.js +16 -21
- package/lib/plugins/manifest/path.js +18 -25
- package/lib/plugins/manifest/validate.js +77 -94
- package/lib/plugins/node_version.js +22 -42
- package/lib/plugins/options.js +45 -78
- package/lib/plugins/pinned_version.js +58 -106
- package/lib/plugins/resolve.js +91 -133
- package/lib/plugins/spawn.js +43 -61
- package/lib/plugins_core/add.js +26 -40
- package/lib/plugins_core/build_command.js +47 -72
- package/lib/plugins_core/deploy/buildbot_client.js +61 -87
- package/lib/plugins_core/deploy/index.js +47 -71
- package/lib/plugins_core/edge_functions/index.js +73 -116
- package/lib/plugins_core/edge_functions/lib/error.js +13 -17
- package/lib/plugins_core/edge_functions/lib/internal_manifest.js +45 -55
- package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +65 -80
- package/lib/plugins_core/functions/error.js +88 -128
- package/lib/plugins_core/functions/feature_flags.js +5 -5
- package/lib/plugins_core/functions/index.js +98 -145
- package/lib/plugins_core/functions/utils.js +36 -57
- package/lib/plugins_core/functions/zisi.js +35 -52
- package/lib/plugins_core/functions_install/index.js +8 -11
- package/lib/plugins_core/list.js +15 -22
- package/lib/status/add.js +26 -32
- package/lib/status/colors.js +14 -19
- package/lib/status/load_error.js +8 -9
- package/lib/status/report.js +72 -126
- package/lib/status/success.js +10 -14
- package/lib/steps/core_step.js +54 -89
- package/lib/steps/error.js +50 -87
- package/lib/steps/get.js +33 -41
- package/lib/steps/plugin.js +53 -83
- package/lib/steps/return.js +24 -51
- package/lib/steps/run_core_steps.js +119 -171
- package/lib/steps/run_step.js +154 -270
- package/lib/steps/run_steps.js +91 -174
- package/lib/steps/update_config.js +45 -72
- package/lib/telemetry/main.js +89 -128
- package/lib/time/aggregate.js +84 -110
- package/lib/time/main.js +23 -34
- package/lib/time/measure.js +11 -15
- package/lib/time/report.js +32 -44
- package/lib/utils/errors.js +10 -9
- package/lib/utils/json.js +11 -15
- package/lib/utils/omit.js +3 -4
- package/lib/utils/package.js +19 -22
- package/lib/utils/remove_falsy.js +5 -7
- package/lib/utils/resolve.js +30 -34
- package/lib/utils/runtime.js +4 -4
- package/lib/utils/semver.js +19 -25
- package/package.json +14 -7
package/lib/core/config.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { resolveConfig, updateConfig, restoreConfig } from '@netlify/config'
|
|
2
|
-
import mapObj from 'map-obj'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
import { getUserNodeVersion } from './user_node_version.js'
|
|
13
|
-
|
|
1
|
+
import { resolveConfig, updateConfig, restoreConfig } from '@netlify/config';
|
|
2
|
+
import mapObj from 'map-obj';
|
|
3
|
+
import { getChildEnv } from '../env/main.js';
|
|
4
|
+
import { addApiErrorHandlers } from '../error/api.js';
|
|
5
|
+
import { changeErrorType } from '../error/info.js';
|
|
6
|
+
import { logBuildDir, logConfigPath, logConfig, logContext } from '../log/messages/config.js';
|
|
7
|
+
import { logConfigOnUpload, logHeadersOnUpload, logRedirectsOnUpload } from '../log/messages/mutations.js';
|
|
8
|
+
import { measureDuration } from '../time/main.js';
|
|
9
|
+
import { getPackageJson } from '../utils/package.js';
|
|
10
|
+
import { getUserNodeVersion } from './user_node_version.js';
|
|
14
11
|
// Retrieve immutable options passed to `@netlify/config`.
|
|
15
12
|
// This does not include options which might change during the course of the
|
|
16
13
|
// build:
|
|
@@ -18,102 +15,65 @@ import { getUserNodeVersion } from './user_node_version.js'
|
|
|
18
15
|
// the build
|
|
19
16
|
// - If plugins change the configuration, `configMutations` is used instead
|
|
20
17
|
// In both cases, almost all options should remain the same.
|
|
21
|
-
export const getConfigOpts = function ({
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
defaultConfig,
|
|
43
|
-
cwd,
|
|
44
|
-
repositoryRoot,
|
|
45
|
-
context,
|
|
46
|
-
branch,
|
|
47
|
-
baseRelDir,
|
|
48
|
-
host: apiHost,
|
|
49
|
-
token,
|
|
50
|
-
siteId,
|
|
51
|
-
deployId,
|
|
52
|
-
buildId,
|
|
53
|
-
mode,
|
|
54
|
-
offline,
|
|
55
|
-
env: envOpt,
|
|
56
|
-
testOpts,
|
|
57
|
-
featureFlags,
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
18
|
+
export const getConfigOpts = function ({ config, defaultConfig, cwd, repositoryRoot, apiHost, token, siteId, context, branch, baseRelDir, envOpt, mode, offline, deployId, buildId, testOpts, featureFlags, }) {
|
|
19
|
+
return {
|
|
20
|
+
config,
|
|
21
|
+
defaultConfig,
|
|
22
|
+
cwd,
|
|
23
|
+
repositoryRoot,
|
|
24
|
+
context,
|
|
25
|
+
branch,
|
|
26
|
+
baseRelDir,
|
|
27
|
+
host: apiHost,
|
|
28
|
+
token,
|
|
29
|
+
siteId,
|
|
30
|
+
deployId,
|
|
31
|
+
buildId,
|
|
32
|
+
mode,
|
|
33
|
+
offline,
|
|
34
|
+
env: envOpt,
|
|
35
|
+
testOpts,
|
|
36
|
+
featureFlags,
|
|
37
|
+
};
|
|
38
|
+
};
|
|
61
39
|
// Retrieve configuration object
|
|
62
40
|
const tLoadConfig = async function ({ configOpts, cachedConfig, cachedConfigPath, envOpt, debug, logs, nodePath }) {
|
|
63
|
-
|
|
64
|
-
configPath,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
redirectsPath,
|
|
88
|
-
buildDir,
|
|
89
|
-
repositoryRoot,
|
|
90
|
-
packageJson,
|
|
91
|
-
userNodeVersion,
|
|
92
|
-
childEnv,
|
|
93
|
-
context: contextA,
|
|
94
|
-
branch: branchA,
|
|
95
|
-
token: tokenA,
|
|
96
|
-
api: apiA,
|
|
97
|
-
siteInfo,
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export const loadConfig = measureDuration(tLoadConfig, 'resolve_config')
|
|
102
|
-
|
|
41
|
+
const { configPath, headersPath, redirectsPath, buildDir, repositoryRoot, config: netlifyConfig, context: contextA, branch: branchA, token: tokenA, api, siteInfo, env, } = await resolveInitialConfig(configOpts, cachedConfig, cachedConfigPath);
|
|
42
|
+
logConfigInfo({ logs, configPath, buildDir, netlifyConfig, context: contextA, debug });
|
|
43
|
+
const apiA = addApiErrorHandlers(api);
|
|
44
|
+
const envValues = mapObj(env, (key, { value }) => [key, value]);
|
|
45
|
+
const childEnv = getChildEnv({ envOpt, env: envValues });
|
|
46
|
+
const [{ packageJson }, userNodeVersion] = await Promise.all([getPackageJson(buildDir), getUserNodeVersion(nodePath)]);
|
|
47
|
+
return {
|
|
48
|
+
netlifyConfig,
|
|
49
|
+
configPath,
|
|
50
|
+
headersPath,
|
|
51
|
+
redirectsPath,
|
|
52
|
+
buildDir,
|
|
53
|
+
repositoryRoot,
|
|
54
|
+
packageJson,
|
|
55
|
+
userNodeVersion,
|
|
56
|
+
childEnv,
|
|
57
|
+
context: contextA,
|
|
58
|
+
branch: branchA,
|
|
59
|
+
token: tokenA,
|
|
60
|
+
api: apiA,
|
|
61
|
+
siteInfo,
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
export const loadConfig = measureDuration(tLoadConfig, 'resolve_config');
|
|
103
65
|
// Retrieve initial configuration.
|
|
104
66
|
// In the buildbot and CLI, we re-use the already parsed `@netlify/config`
|
|
105
67
|
// return value which is passed as `cachedConfig`/`cachedConfigPath`.
|
|
106
68
|
const resolveInitialConfig = async function (configOpts, cachedConfig, cachedConfigPath) {
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
|
|
69
|
+
return await resolveConfig({ ...configOpts, cachedConfig, cachedConfigPath });
|
|
70
|
+
};
|
|
110
71
|
const logConfigInfo = function ({ logs, configPath, buildDir, netlifyConfig, context, debug }) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
72
|
+
logBuildDir(logs, buildDir);
|
|
73
|
+
logConfigPath(logs, configPath);
|
|
74
|
+
logConfig({ logs, netlifyConfig, debug });
|
|
75
|
+
logContext(logs, context);
|
|
76
|
+
};
|
|
117
77
|
// Retrieve the configuration after it's been changed.
|
|
118
78
|
// This ensures any configuration changes done by plugins is validated and
|
|
119
79
|
// normalized.
|
|
@@ -122,65 +82,40 @@ const logConfigInfo = function ({ logs, configPath, buildDir, netlifyConfig, con
|
|
|
122
82
|
// Errors are propagated and assigned to the specific plugin or core step
|
|
123
83
|
// which changed the configuration.
|
|
124
84
|
export const resolveUpdatedConfig = async function (configOpts, configMutations) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
132
|
-
|
|
85
|
+
try {
|
|
86
|
+
return await resolveConfig({ ...configOpts, configMutations, debug: false });
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
changeErrorType(error, 'resolveConfig', 'pluginValidation');
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
133
93
|
// If the configuration was changed, persist it to `netlify.toml`.
|
|
134
94
|
// If `netlify.toml` does not exist, create it inside repository root.
|
|
135
95
|
// This is only done when `saveConfig` is `true`. This allows performing this
|
|
136
96
|
// in the buildbot but not in local builds, since only the latter run in a
|
|
137
97
|
// container and we want to avoid saving files on local machines.
|
|
138
|
-
export const saveUpdatedConfig = async function ({
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
redirectsPath
|
|
161
|
-
|
|
162
|
-
branch,
|
|
163
|
-
logs,
|
|
164
|
-
featureFlags,
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
await logConfigOnUpload({ logs, configPath, debug })
|
|
168
|
-
await logHeadersOnUpload({ logs, headersPath, debug })
|
|
169
|
-
await logRedirectsOnUpload({ logs, redirectsPath, debug })
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export const restoreUpdatedConfig = async function ({
|
|
173
|
-
configMutations,
|
|
174
|
-
buildDir,
|
|
175
|
-
repositoryRoot,
|
|
176
|
-
configPath = `${repositoryRoot}/netlify.toml`,
|
|
177
|
-
headersPath,
|
|
178
|
-
redirectsPath,
|
|
179
|
-
saveConfig,
|
|
180
|
-
}) {
|
|
181
|
-
if (!saveConfig) {
|
|
182
|
-
return
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
await restoreConfig(configMutations, { buildDir, configPath, headersPath, redirectsPath })
|
|
186
|
-
}
|
|
98
|
+
export const saveUpdatedConfig = async function ({ configMutations, buildDir, repositoryRoot, configPath = `${repositoryRoot}/netlify.toml`, headersPath, redirectsPath, logs, featureFlags, context, branch, debug, saveConfig, }) {
|
|
99
|
+
if (!saveConfig) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
await updateConfig(configMutations, {
|
|
103
|
+
buildDir,
|
|
104
|
+
configPath,
|
|
105
|
+
headersPath,
|
|
106
|
+
redirectsPath,
|
|
107
|
+
context,
|
|
108
|
+
branch,
|
|
109
|
+
logs,
|
|
110
|
+
featureFlags,
|
|
111
|
+
});
|
|
112
|
+
await logConfigOnUpload({ logs, configPath, debug });
|
|
113
|
+
await logHeadersOnUpload({ logs, headersPath, debug });
|
|
114
|
+
await logRedirectsOnUpload({ logs, redirectsPath, debug });
|
|
115
|
+
};
|
|
116
|
+
export const restoreUpdatedConfig = async function ({ configMutations, buildDir, repositoryRoot, configPath = `${repositoryRoot}/netlify.toml`, headersPath, redirectsPath, saveConfig, }) {
|
|
117
|
+
if (!saveConfig) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
await restoreConfig(configMutations, { buildDir, configPath, headersPath, redirectsPath });
|
|
121
|
+
};
|
package/lib/core/constants.js
CHANGED
|
@@ -1,156 +1,116 @@
|
|
|
1
|
-
import { relative, normalize } from 'path'
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import { ROOT_PACKAGE_JSON } from '../utils/json.js'
|
|
8
|
-
|
|
1
|
+
import { relative, normalize } from 'path';
|
|
2
|
+
import { getCacheDir } from '@netlify/cache-utils';
|
|
3
|
+
import mapObj from 'map-obj';
|
|
4
|
+
import { pathExists } from 'path-exists';
|
|
5
|
+
import { ROOT_PACKAGE_JSON } from '../utils/json.js';
|
|
9
6
|
// Retrieve constants passed to plugins
|
|
10
|
-
export const getConstants = async function ({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
// The directory where internal functions (i.e. generated programmatically
|
|
45
|
-
// via plugins or others) live
|
|
46
|
-
INTERNAL_FUNCTIONS_SRC: `${buildDir}/${INTERNAL_FUNCTIONS_SRC}`,
|
|
47
|
-
// The directory where internal Edge Functions (i.e. generated programmatically
|
|
48
|
-
// via plugins or others) live
|
|
49
|
-
INTERNAL_EDGE_FUNCTIONS_SRC: `${buildDir}/${INTERNAL_EDGE_FUNCTIONS_SRC}`,
|
|
50
|
-
}
|
|
51
|
-
const constantsA = await addMutableConstants({ constants, buildDir, netlifyConfig })
|
|
52
|
-
return constantsA
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const INTERNAL_EDGE_FUNCTIONS_SRC = '.netlify/edge-functions'
|
|
56
|
-
const INTERNAL_FUNCTIONS_SRC = '.netlify/functions-internal'
|
|
57
|
-
|
|
7
|
+
export const getConstants = async function ({ configPath, buildDir, functionsDistDir, edgeFunctionsDistDir, cacheDir, netlifyConfig, siteInfo: { id: siteId }, apiHost, token, mode, }) {
|
|
8
|
+
const isLocal = mode !== 'buildbot';
|
|
9
|
+
const normalizedCacheDir = getCacheDir({ cacheDir, cwd: buildDir });
|
|
10
|
+
const constants = {
|
|
11
|
+
// Path to the Netlify configuration file
|
|
12
|
+
CONFIG_PATH: configPath,
|
|
13
|
+
// The directory where built serverless functions are placed before deployment
|
|
14
|
+
FUNCTIONS_DIST: functionsDistDir,
|
|
15
|
+
// The directory where built Edge Functions are placed before deployment
|
|
16
|
+
EDGE_FUNCTIONS_DIST: edgeFunctionsDistDir,
|
|
17
|
+
// Path to the Netlify build cache folder
|
|
18
|
+
CACHE_DIR: normalizedCacheDir,
|
|
19
|
+
// Boolean indicating whether the build was run locally (Netlify CLI) or in the production CI
|
|
20
|
+
IS_LOCAL: isLocal,
|
|
21
|
+
// The version of Netlify Build
|
|
22
|
+
NETLIFY_BUILD_VERSION: ROOT_PACKAGE_JSON.version,
|
|
23
|
+
// The Netlify Site ID
|
|
24
|
+
SITE_ID: siteId,
|
|
25
|
+
// The Netlify API access token
|
|
26
|
+
NETLIFY_API_TOKEN: token,
|
|
27
|
+
// The Netlify API host
|
|
28
|
+
NETLIFY_API_HOST: apiHost,
|
|
29
|
+
// The directory where internal functions (i.e. generated programmatically
|
|
30
|
+
// via plugins or others) live
|
|
31
|
+
INTERNAL_FUNCTIONS_SRC: `${buildDir}/${INTERNAL_FUNCTIONS_SRC}`,
|
|
32
|
+
// The directory where internal Edge Functions (i.e. generated programmatically
|
|
33
|
+
// via plugins or others) live
|
|
34
|
+
INTERNAL_EDGE_FUNCTIONS_SRC: `${buildDir}/${INTERNAL_EDGE_FUNCTIONS_SRC}`,
|
|
35
|
+
};
|
|
36
|
+
const constantsA = await addMutableConstants({ constants, buildDir, netlifyConfig });
|
|
37
|
+
return constantsA;
|
|
38
|
+
};
|
|
39
|
+
const INTERNAL_EDGE_FUNCTIONS_SRC = '.netlify/edge-functions';
|
|
40
|
+
const INTERNAL_FUNCTIONS_SRC = '.netlify/functions-internal';
|
|
58
41
|
// Retrieve constants which might change during the build if a plugin modifies
|
|
59
42
|
// `netlifyConfig` or creates some default directories.
|
|
60
43
|
// Unlike readonly constants, this is called again before each build step.
|
|
61
|
-
export const addMutableConstants = async function ({
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
// The directory where Edge Functions source code lives
|
|
76
|
-
EDGE_FUNCTIONS_SRC: edgeFunctions,
|
|
77
|
-
}
|
|
78
|
-
const constantsB = await addDefaultConstants(constantsA, buildDir)
|
|
79
|
-
const constantsC = normalizeConstantsPaths(constantsB, buildDir)
|
|
80
|
-
return constantsC
|
|
81
|
-
}
|
|
82
|
-
|
|
44
|
+
export const addMutableConstants = async function ({ constants, buildDir, netlifyConfig: { build: { publish, edge_functions: edgeFunctions }, functionsDirectory, }, }) {
|
|
45
|
+
const constantsA = {
|
|
46
|
+
...constants,
|
|
47
|
+
// Directory that contains the deploy-ready HTML files and assets generated by the build
|
|
48
|
+
PUBLISH_DIR: publish,
|
|
49
|
+
// The directory where function source code lives
|
|
50
|
+
FUNCTIONS_SRC: functionsDirectory,
|
|
51
|
+
// The directory where Edge Functions source code lives
|
|
52
|
+
EDGE_FUNCTIONS_SRC: edgeFunctions,
|
|
53
|
+
};
|
|
54
|
+
const constantsB = await addDefaultConstants(constantsA, buildDir);
|
|
55
|
+
const constantsC = normalizeConstantsPaths(constantsB, buildDir);
|
|
56
|
+
return constantsC;
|
|
57
|
+
};
|
|
83
58
|
// Some `constants` have a default value when a specific file exists.
|
|
84
59
|
// Those default values are assigned by `@netlify/config`. However, the build
|
|
85
60
|
// command or plugins might create those specific files, in which case, the
|
|
86
61
|
// related `constant` should be updated, unless the user has explicitly
|
|
87
62
|
// configured it.
|
|
88
63
|
const addDefaultConstants = async function (constants, buildDir) {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
),
|
|
93
|
-
)
|
|
94
|
-
return Object.assign({}, constants, ...newConstants)
|
|
95
|
-
}
|
|
96
|
-
|
|
64
|
+
const newConstants = await Promise.all(DEFAULT_PATHS.map(({ constantName, defaultPath }) => addDefaultConstant({ constants, constantName, defaultPath, buildDir })));
|
|
65
|
+
return Object.assign({}, constants, ...newConstants);
|
|
66
|
+
};
|
|
97
67
|
// The current directory is the build directory, which is correct, so we don't
|
|
98
68
|
// need to resolve paths
|
|
99
69
|
const DEFAULT_PATHS = [
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
]
|
|
105
|
-
|
|
70
|
+
// @todo Remove once we drop support for the legacy default functions directory.
|
|
71
|
+
{ constantName: 'FUNCTIONS_SRC', defaultPath: 'netlify-automatic-functions' },
|
|
72
|
+
{ constantName: 'FUNCTIONS_SRC', defaultPath: 'netlify/functions' },
|
|
73
|
+
{ constantName: 'EDGE_FUNCTIONS_SRC', defaultPath: 'netlify/edge-functions' },
|
|
74
|
+
];
|
|
106
75
|
const addDefaultConstant = async function ({ constants, constantName, defaultPath, buildDir }) {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
|
|
76
|
+
// Configuration paths are relative to the build directory.
|
|
77
|
+
if (!isEmptyValue(constants[constantName]) || !(await pathExists(`${buildDir}/${defaultPath}`))) {
|
|
78
|
+
return {};
|
|
79
|
+
}
|
|
80
|
+
// However, the plugin child process' current directory is the build directory,
|
|
81
|
+
// so we can pass the relative path instead of the resolved absolute path.
|
|
82
|
+
return { [constantName]: defaultPath };
|
|
83
|
+
};
|
|
117
84
|
const normalizeConstantsPaths = function (constants, buildDir) {
|
|
118
|
-
|
|
119
|
-
}
|
|
120
|
-
|
|
85
|
+
return mapObj(constants, (key, path) => [key, normalizePath(path, buildDir, key)]);
|
|
86
|
+
};
|
|
121
87
|
// The current directory is `buildDir`. Most constants are inside this `buildDir`.
|
|
122
88
|
// Instead of passing absolute paths, we pass paths relative to `buildDir`, so
|
|
123
89
|
// that logs are less verbose.
|
|
124
90
|
const normalizePath = function (path, buildDir, key) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return pathA
|
|
140
|
-
}
|
|
141
|
-
|
|
91
|
+
if (isEmptyValue(path) || !CONSTANT_PATHS.has(key)) {
|
|
92
|
+
return path;
|
|
93
|
+
}
|
|
94
|
+
const pathA = normalize(path);
|
|
95
|
+
if (pathA === buildDir) {
|
|
96
|
+
return '.';
|
|
97
|
+
}
|
|
98
|
+
if (pathA.startsWith(buildDir)) {
|
|
99
|
+
return relative(buildDir, pathA);
|
|
100
|
+
}
|
|
101
|
+
return pathA;
|
|
102
|
+
};
|
|
142
103
|
const isEmptyValue = function (path) {
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
104
|
+
return path === undefined || path === '';
|
|
105
|
+
};
|
|
146
106
|
const CONSTANT_PATHS = new Set([
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
])
|
|
107
|
+
'CONFIG_PATH',
|
|
108
|
+
'PUBLISH_DIR',
|
|
109
|
+
'FUNCTIONS_SRC',
|
|
110
|
+
'FUNCTIONS_DIST',
|
|
111
|
+
'INTERNAL_EDGE_FUNCTIONS_SRC',
|
|
112
|
+
'INTERNAL_FUNCTIONS_SRC',
|
|
113
|
+
'EDGE_FUNCTIONS_DIST',
|
|
114
|
+
'EDGE_FUNCTIONS_SRC',
|
|
115
|
+
'CACHE_DIR',
|
|
116
|
+
]);
|
package/lib/core/dev.js
CHANGED
|
@@ -1,31 +1,27 @@
|
|
|
1
|
-
import { handleBuildError } from '../error/handle.js'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import { getSeverity } from './severity.js'
|
|
5
|
-
|
|
1
|
+
import { handleBuildError } from '../error/handle.js';
|
|
2
|
+
import { execBuild, startBuild } from './build.js';
|
|
3
|
+
import { getSeverity } from './severity.js';
|
|
6
4
|
export const startDev = async (devCommand, flags = {}) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
}
|
|
5
|
+
const { errorMonitor, mode, logs, debug, testOpts, ...normalizedFlags } = startBuild(flags);
|
|
6
|
+
const errorParams = { errorMonitor, mode, logs, debug, testOpts };
|
|
7
|
+
try {
|
|
8
|
+
const { netlifyConfig: netlifyConfigA, configMutations } = await execBuild({
|
|
9
|
+
...normalizedFlags,
|
|
10
|
+
errorMonitor,
|
|
11
|
+
errorParams,
|
|
12
|
+
mode,
|
|
13
|
+
logs,
|
|
14
|
+
debug,
|
|
15
|
+
testOpts,
|
|
16
|
+
timeline: 'dev',
|
|
17
|
+
devCommand,
|
|
18
|
+
});
|
|
19
|
+
const { success, severityCode } = getSeverity('success');
|
|
20
|
+
return { success, severityCode, netlifyConfig: netlifyConfigA, logs, configMutations };
|
|
21
|
+
}
|
|
22
|
+
catch (error) {
|
|
23
|
+
const { severity, message, stack } = await handleBuildError(error, errorParams);
|
|
24
|
+
const { success, severityCode } = getSeverity(severity);
|
|
25
|
+
return { success, severityCode, logs, error: { message, stack } };
|
|
26
|
+
}
|
|
27
|
+
};
|
package/lib/core/dry.js
CHANGED
|
@@ -1,39 +1,21 @@
|
|
|
1
|
-
import pFilter from 'p-filter'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
import { runsOnlyOnBuildFailure } from '../plugins/events.js'
|
|
5
|
-
|
|
1
|
+
import pFilter from 'p-filter';
|
|
2
|
+
import { logDryRunStart, logDryRunStep, logDryRunEnd } from '../log/messages/dry.js';
|
|
3
|
+
import { runsOnlyOnBuildFailure } from '../plugins/events.js';
|
|
6
4
|
// If the `dry` flag is specified, do a dry run
|
|
7
5
|
export const doDryRun = async function ({ buildDir, steps, netlifyConfig, constants, buildbotServerSocket, logs }) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const shouldIncludeStep = async function ({
|
|
24
|
-
buildDir,
|
|
25
|
-
event,
|
|
26
|
-
condition,
|
|
27
|
-
netlifyConfig,
|
|
28
|
-
constants,
|
|
29
|
-
buildbotServerSocket,
|
|
30
|
-
}) {
|
|
31
|
-
return (
|
|
32
|
-
!runsOnlyOnBuildFailure(event) &&
|
|
33
|
-
(condition === undefined || (await condition({ buildDir, constants, netlifyConfig, buildbotServerSocket })))
|
|
34
|
-
)
|
|
35
|
-
}
|
|
36
|
-
|
|
6
|
+
const successSteps = await pFilter(steps, ({ event, condition }) => shouldIncludeStep({ buildDir, event, condition, netlifyConfig, constants, buildbotServerSocket }));
|
|
7
|
+
const eventWidth = Math.max(...successSteps.map(getEventLength));
|
|
8
|
+
const stepsCount = successSteps.length;
|
|
9
|
+
logDryRunStart({ logs, eventWidth, stepsCount });
|
|
10
|
+
successSteps.forEach((step, index) => {
|
|
11
|
+
logDryRunStep({ logs, step, index, netlifyConfig, eventWidth, stepsCount });
|
|
12
|
+
});
|
|
13
|
+
logDryRunEnd(logs);
|
|
14
|
+
};
|
|
15
|
+
const shouldIncludeStep = async function ({ buildDir, event, condition, netlifyConfig, constants, buildbotServerSocket, }) {
|
|
16
|
+
return (!runsOnlyOnBuildFailure(event) &&
|
|
17
|
+
(condition === undefined || (await condition({ buildDir, constants, netlifyConfig, buildbotServerSocket }))));
|
|
18
|
+
};
|
|
37
19
|
const getEventLength = function ({ event }) {
|
|
38
|
-
|
|
39
|
-
}
|
|
20
|
+
return event.length;
|
|
21
|
+
};
|