@netlify/build 27.0.3 → 27.1.0
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/package.json +1 -1
- package/src/core/main.js +2 -0
- package/src/steps/run_core_steps.js +199 -0
package/package.json
CHANGED
package/src/core/main.js
CHANGED
|
@@ -24,6 +24,8 @@ import { warnOnMissingSideFiles } from './missing_side_file.js'
|
|
|
24
24
|
import { normalizeFlags } from './normalize_flags.js'
|
|
25
25
|
import { getSeverity } from './severity.js'
|
|
26
26
|
|
|
27
|
+
export { runCoreSteps } from '../steps/run_core_steps.js'
|
|
28
|
+
|
|
27
29
|
/**
|
|
28
30
|
* Main entry point of Netlify Build.
|
|
29
31
|
* Runs a builds and returns whether it succeeded or not.
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
/* eslint-disable max-lines */
|
|
2
|
+
import { getConfigOpts, loadConfig } from '../core/config.js'
|
|
3
|
+
import { getConstants } from '../core/constants.js'
|
|
4
|
+
import { normalizeFlags } from '../core/normalize_flags.js'
|
|
5
|
+
import { getSeverity } from '../core/severity.js'
|
|
6
|
+
import { handleBuildError } from '../error/handle.js'
|
|
7
|
+
import { getErrorInfo } from '../error/info.js'
|
|
8
|
+
import { startErrorMonitor } from '../error/monitor/start.js'
|
|
9
|
+
import { getBufferLogs } from '../log/logger.js'
|
|
10
|
+
import { logBuildStart } from '../log/messages/core.js'
|
|
11
|
+
import { reportStatuses } from '../status/report.js'
|
|
12
|
+
|
|
13
|
+
import { getSteps } from './get.js'
|
|
14
|
+
import { runSteps } from './run_steps.js'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Runs specific core steps for a build and returns whether it succeeded or not.
|
|
18
|
+
*
|
|
19
|
+
* @param {string[]} [buildSteps] - a string array of build steps to run
|
|
20
|
+
* @param {object} [flags] - build configuration CLI flags
|
|
21
|
+
* @param {string} [flags.config] - Path to the configuration file
|
|
22
|
+
* @param {string} [flags.cwd] - Current directory. Used to retrieve the configuration file
|
|
23
|
+
* @param {string} [flags.repositoryRoot] - Git repository root directory. Used to retrieve the configuration file.
|
|
24
|
+
* @param {string} [flags.apiHost] - Netlify API endpoint
|
|
25
|
+
* @param {string} [flags.token] - Netlify API token for authentication
|
|
26
|
+
* @param {string} [flags.siteId] - Netlify Site ID
|
|
27
|
+
* @param {string} [flags.deployId] - Netlify Deploy ID
|
|
28
|
+
* @param {string} [flags.context] - Build context
|
|
29
|
+
* @param {string} [flags.branch] - Repository branch
|
|
30
|
+
* @param {boolean} [flags.dry=false] - Run in dry mode, i.e. printing steps without executing them
|
|
31
|
+
* @param {string} [flags.nodePath] - Path to the Node.js binary to use in the build command and plugins
|
|
32
|
+
* @param {boolean} [flags.buffer=false] - Buffer output instead of printing it
|
|
33
|
+
*
|
|
34
|
+
* @returns {object} buildResult
|
|
35
|
+
* @returns {boolean} buildResult.success - Whether build succeeded or failed
|
|
36
|
+
* @returns {number} buildResult.severityCode - Build success/failure status among:
|
|
37
|
+
* 0 (success), 1 (build cancelled), 2 (user error), 3 (plugin error), 4 (system error). Can be used as exit code.
|
|
38
|
+
* @returns {string[]} buildResult.logs - When using the `buffer` option, all log messages
|
|
39
|
+
*/
|
|
40
|
+
export const runCoreSteps = async (buildSteps, flags = {}) => {
|
|
41
|
+
const { errorMonitor, mode, logs, debug, ...flagsA } = startBuild(flags)
|
|
42
|
+
const errorParams = { errorMonitor, mode, logs, debug }
|
|
43
|
+
|
|
44
|
+
try {
|
|
45
|
+
const { netlifyConfig: netlifyConfigA, configMutations } = await executeBuildStep({
|
|
46
|
+
...flagsA,
|
|
47
|
+
errorMonitor,
|
|
48
|
+
mode,
|
|
49
|
+
logs,
|
|
50
|
+
debug,
|
|
51
|
+
errorParams,
|
|
52
|
+
buildSteps,
|
|
53
|
+
})
|
|
54
|
+
const { success, severityCode } = getSeverity('success')
|
|
55
|
+
|
|
56
|
+
return { success, severityCode, netlifyConfig: netlifyConfigA, configMutations, logs }
|
|
57
|
+
} catch (error) {
|
|
58
|
+
const { severity } = await handleBuildError(error, errorParams)
|
|
59
|
+
const { success, severityCode } = getSeverity(severity)
|
|
60
|
+
|
|
61
|
+
return { success, severityCode, logs }
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const startBuild = function (flags) {
|
|
66
|
+
const logs = getBufferLogs(flags)
|
|
67
|
+
|
|
68
|
+
logBuildStart(logs)
|
|
69
|
+
|
|
70
|
+
const { bugsnagKey, ...flagsA } = normalizeFlags(flags, logs)
|
|
71
|
+
const errorMonitor = startErrorMonitor({ flags: flagsA, logs, bugsnagKey })
|
|
72
|
+
|
|
73
|
+
return { ...flagsA, errorMonitor, logs }
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const getBuildSteps = function (buildSteps) {
|
|
77
|
+
const allSteps = getSteps([]).steps.filter(({ coreStepId }) => buildSteps.includes(coreStepId))
|
|
78
|
+
|
|
79
|
+
return allSteps
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const executeBuildStep = async function ({
|
|
83
|
+
config,
|
|
84
|
+
defaultConfig,
|
|
85
|
+
cachedConfig,
|
|
86
|
+
debug,
|
|
87
|
+
nodePath,
|
|
88
|
+
functionsDistDir,
|
|
89
|
+
edgeFunctionsDistDir,
|
|
90
|
+
errorMonitor,
|
|
91
|
+
mode,
|
|
92
|
+
logs,
|
|
93
|
+
errorParams,
|
|
94
|
+
featureFlags,
|
|
95
|
+
buildSteps,
|
|
96
|
+
repositoryRoot,
|
|
97
|
+
}) {
|
|
98
|
+
const configOpts = getConfigOpts({
|
|
99
|
+
config,
|
|
100
|
+
defaultConfig,
|
|
101
|
+
featureFlags,
|
|
102
|
+
mode,
|
|
103
|
+
repositoryRoot,
|
|
104
|
+
})
|
|
105
|
+
const {
|
|
106
|
+
netlifyConfig,
|
|
107
|
+
buildDir,
|
|
108
|
+
siteInfo,
|
|
109
|
+
childEnv,
|
|
110
|
+
userNodeVersion,
|
|
111
|
+
repositoryRoot: repositoryRootA,
|
|
112
|
+
} = await loadConfig({
|
|
113
|
+
configOpts,
|
|
114
|
+
cachedConfig,
|
|
115
|
+
debug,
|
|
116
|
+
logs,
|
|
117
|
+
nodePath,
|
|
118
|
+
timers: [],
|
|
119
|
+
})
|
|
120
|
+
const constants = await getConstants({
|
|
121
|
+
buildDir,
|
|
122
|
+
functionsDistDir,
|
|
123
|
+
edgeFunctionsDistDir,
|
|
124
|
+
netlifyConfig,
|
|
125
|
+
siteInfo,
|
|
126
|
+
mode,
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
// eslint-disable-next-line fp/no-mutating-assign
|
|
130
|
+
Object.assign(errorParams, { netlifyConfig, siteInfo, childEnv, userNodeVersion })
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
const { netlifyConfig: netlifyConfigA, configMutations } = await runBuildStep({
|
|
134
|
+
netlifyConfig,
|
|
135
|
+
buildDir,
|
|
136
|
+
nodePath,
|
|
137
|
+
logs,
|
|
138
|
+
debug,
|
|
139
|
+
constants,
|
|
140
|
+
featureFlags,
|
|
141
|
+
childEnv,
|
|
142
|
+
buildSteps,
|
|
143
|
+
repositoryRoot: repositoryRootA,
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
return {
|
|
147
|
+
netlifyConfig: netlifyConfigA,
|
|
148
|
+
configMutations,
|
|
149
|
+
}
|
|
150
|
+
} catch (error) {
|
|
151
|
+
const [{ statuses }] = getErrorInfo(error)
|
|
152
|
+
|
|
153
|
+
await reportStatuses({
|
|
154
|
+
statuses,
|
|
155
|
+
childEnv,
|
|
156
|
+
mode,
|
|
157
|
+
netlifyConfig,
|
|
158
|
+
errorMonitor,
|
|
159
|
+
logs,
|
|
160
|
+
debug,
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
throw error
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const runBuildStep = async function ({
|
|
168
|
+
netlifyConfig,
|
|
169
|
+
buildDir,
|
|
170
|
+
nodePath,
|
|
171
|
+
constants,
|
|
172
|
+
logs,
|
|
173
|
+
debug,
|
|
174
|
+
featureFlags,
|
|
175
|
+
childEnv,
|
|
176
|
+
buildSteps,
|
|
177
|
+
repositoryRoot,
|
|
178
|
+
}) {
|
|
179
|
+
try {
|
|
180
|
+
const { netlifyConfig: netlifyConfigA, configMutations } = await runSteps({
|
|
181
|
+
steps: getBuildSteps(buildSteps),
|
|
182
|
+
buildDir,
|
|
183
|
+
nodePath,
|
|
184
|
+
constants,
|
|
185
|
+
netlifyConfig,
|
|
186
|
+
logs,
|
|
187
|
+
debug,
|
|
188
|
+
timers: [],
|
|
189
|
+
featureFlags,
|
|
190
|
+
childEnv,
|
|
191
|
+
repositoryRoot,
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
return { netlifyConfig: netlifyConfigA, configMutations }
|
|
195
|
+
} catch (error) {
|
|
196
|
+
console.error(error)
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
/* eslint-enable max-lines */
|