@netlify/build 0.4.48 → 1.0.0-dl-test
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/core/bin.js +66 -0
- package/lib/core/build.js +392 -0
- package/lib/core/config.js +124 -0
- package/lib/core/constants.js +116 -0
- package/lib/core/dev.js +27 -0
- package/lib/core/dry.js +21 -0
- package/lib/core/feature_flags.js +17 -0
- package/lib/core/flags.js +206 -0
- package/lib/core/lingering.js +68 -0
- package/lib/core/main.js +114 -0
- package/lib/core/missing_side_file.js +17 -0
- package/lib/core/normalize_flags.js +62 -0
- package/lib/core/report_metrics.js +17 -0
- package/lib/core/severity.js +21 -0
- package/lib/core/types.js +8 -0
- package/lib/core/user_node_version.js +32 -0
- package/lib/env/changes.js +43 -0
- package/lib/env/main.js +14 -0
- package/lib/env/metadata.js +68 -0
- package/lib/error/api.js +37 -0
- package/lib/error/build.js +36 -0
- package/lib/error/cancel.js +7 -0
- package/lib/error/colors.js +9 -0
- package/lib/error/handle.js +44 -0
- package/lib/error/info.js +37 -0
- package/lib/error/monitor/location.js +16 -0
- package/lib/error/monitor/normalize.js +86 -0
- package/lib/error/monitor/print.js +20 -0
- package/lib/error/monitor/report.js +120 -0
- package/lib/error/monitor/start.js +61 -0
- package/lib/error/parse/clean_stack.js +70 -0
- package/lib/error/parse/location.js +50 -0
- package/lib/error/parse/normalize.js +24 -0
- package/lib/error/parse/parse.js +67 -0
- package/lib/error/parse/plugin.js +55 -0
- package/lib/error/parse/properties.js +16 -0
- package/lib/error/parse/serialize_log.js +34 -0
- package/lib/error/parse/serialize_status.js +18 -0
- package/lib/error/parse/stack.js +34 -0
- package/lib/error/report.js +29 -0
- package/lib/error/type.js +177 -0
- package/lib/install/functions.js +20 -0
- package/lib/install/local.js +45 -0
- package/lib/install/main.js +67 -0
- package/lib/install/missing.js +54 -0
- package/lib/log/colors.js +28 -0
- package/lib/log/description.js +21 -0
- package/lib/log/header.js +12 -0
- package/lib/log/header_func.js +13 -0
- package/lib/log/logger.js +140 -0
- package/lib/log/messages/compatibility.js +120 -0
- package/lib/log/messages/config.js +91 -0
- package/lib/log/messages/core.js +49 -0
- package/lib/log/messages/core_steps.js +75 -0
- package/lib/log/messages/dry.js +41 -0
- package/lib/log/messages/install.js +25 -0
- package/lib/log/messages/ipc.js +29 -0
- package/lib/log/messages/mutations.js +62 -0
- package/lib/log/messages/plugins.js +25 -0
- package/lib/log/messages/status.js +14 -0
- package/lib/log/messages/steps.js +18 -0
- package/lib/log/serialize.js +10 -0
- package/lib/log/stream.js +68 -0
- package/lib/log/theme.js +27 -0
- package/lib/plugins/child/diff.js +46 -0
- package/lib/plugins/child/error.js +26 -0
- package/lib/plugins/child/lazy.js +15 -0
- package/lib/plugins/child/load.js +22 -0
- package/lib/plugins/child/logic.js +57 -0
- package/lib/plugins/child/main.js +37 -0
- package/lib/plugins/child/run.js +19 -0
- package/lib/plugins/child/status.js +63 -0
- package/lib/plugins/child/typescript.js +28 -0
- package/lib/plugins/child/utils.js +42 -0
- package/lib/plugins/child/validate.js +31 -0
- package/lib/plugins/compatibility.js +104 -0
- package/lib/plugins/error.js +46 -0
- package/lib/plugins/events.js +12 -0
- package/lib/plugins/expected_version.js +81 -0
- package/lib/plugins/internal.js +10 -0
- package/lib/plugins/ipc.js +120 -0
- package/lib/plugins/list.js +73 -0
- package/lib/plugins/load.js +50 -0
- package/lib/plugins/manifest/check.js +85 -0
- package/lib/plugins/manifest/load.js +38 -0
- package/lib/plugins/manifest/main.js +19 -0
- package/lib/plugins/manifest/path.js +24 -0
- package/lib/plugins/manifest/validate.js +91 -0
- package/lib/plugins/node_version.js +35 -0
- package/lib/plugins/options.js +70 -0
- package/lib/plugins/pinned_version.js +83 -0
- package/lib/plugins/resolve.js +110 -0
- package/lib/plugins/spawn.js +55 -0
- package/lib/plugins_core/add.js +35 -0
- package/lib/plugins_core/build_command.js +50 -0
- package/lib/plugins_core/deploy/buildbot_client.js +87 -0
- package/lib/plugins_core/deploy/index.js +49 -0
- package/lib/plugins_core/deploy/manifest.yml +1 -0
- package/lib/plugins_core/edge_functions/index.js +106 -0
- package/lib/plugins_core/edge_functions/lib/error.js +17 -0
- package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +14 -0
- package/lib/plugins_core/functions/error.js +123 -0
- package/lib/plugins_core/functions/feature_flags.js +5 -0
- package/lib/plugins_core/functions/index.js +137 -0
- package/lib/plugins_core/functions/utils.js +45 -0
- package/lib/plugins_core/functions/zisi.js +64 -0
- package/lib/plugins_core/functions_install/index.js +10 -0
- package/lib/plugins_core/list.js +20 -0
- package/lib/plugins_core/save_artifacts/index.js +33 -0
- package/lib/report/statsd.js +56 -0
- package/lib/status/add.js +30 -0
- package/lib/status/colors.js +18 -0
- package/lib/status/load_error.js +10 -0
- package/lib/status/report.js +83 -0
- package/lib/status/success.js +14 -0
- package/lib/steps/core_step.js +62 -0
- package/lib/steps/error.js +65 -0
- package/lib/steps/get.js +44 -0
- package/lib/steps/plugin.js +55 -0
- package/lib/steps/return.js +27 -0
- package/lib/steps/run_core_steps.js +117 -0
- package/lib/steps/run_step.js +200 -0
- package/lib/steps/run_steps.js +102 -0
- package/lib/steps/update_config.js +66 -0
- package/lib/telemetry/main.js +94 -0
- package/lib/time/aggregate.js +109 -0
- package/lib/time/main.js +31 -0
- package/lib/time/measure.js +16 -0
- package/lib/time/report.js +30 -0
- package/lib/utils/errors.js +13 -0
- package/lib/utils/json.js +10 -0
- package/lib/utils/omit.js +3 -0
- package/lib/utils/package.js +24 -0
- package/lib/utils/remove_falsy.js +8 -0
- package/lib/utils/resolve.js +41 -0
- package/lib/utils/runtime.js +5 -0
- package/lib/utils/semver.js +28 -0
- package/package.json +119 -56
- package/types/config/build.d.ts +52 -0
- package/types/config/functions.d.ts +36 -0
- package/types/config/inputs.d.ts +7 -0
- package/types/config/netlify_config.d.ts +58 -0
- package/types/index.d.ts +7 -0
- package/types/netlify_event_handler.d.ts +29 -0
- package/types/netlify_plugin.d.ts +29 -0
- package/types/netlify_plugin_constants.d.ts +51 -0
- package/types/netlify_plugin_options.d.ts +23 -0
- package/types/options/index.d.ts +1 -0
- package/types/options/netlify_plugin_build_util.d.ts +7 -0
- package/types/options/netlify_plugin_cache_util.d.ts +39 -0
- package/types/options/netlify_plugin_functions_util.d.ts +32 -0
- package/types/options/netlify_plugin_git_util.d.ts +41 -0
- package/types/options/netlify_plugin_run_util.d.ts +24 -0
- package/types/options/netlify_plugin_status_util.d.ts +24 -0
- package/types/options/netlify_plugin_utils.d.ts +15 -0
- package/types/utils/json_value.d.ts +1 -0
- package/types/utils/many.d.ts +6 -0
- package/README.md +0 -3
- package/src/core/bin.js +0 -139
- package/src/core/commands.js +0 -304
- package/src/core/config.js +0 -130
- package/src/core/constants.js +0 -88
- package/src/core/dry.js +0 -23
- package/src/core/main.js +0 -196
- package/src/env/changes.js +0 -49
- package/src/env/git.js +0 -27
- package/src/env/main.js +0 -97
- package/src/env/metadata.js +0 -81
- package/src/error/api.js +0 -32
- package/src/error/build.js +0 -32
- package/src/error/cancel.js +0 -22
- package/src/error/colors.js +0 -13
- package/src/error/info.js +0 -12
- package/src/error/monitor/normalize.js +0 -50
- package/src/error/monitor/print.js +0 -43
- package/src/error/monitor/report.js +0 -140
- package/src/error/monitor/start.js +0 -50
- package/src/error/parse/clean_stack.js +0 -86
- package/src/error/parse/location.js +0 -50
- package/src/error/parse/parse.js +0 -87
- package/src/error/parse/plugin.js +0 -68
- package/src/error/parse/properties.js +0 -20
- package/src/error/parse/serialize_log.js +0 -46
- package/src/error/parse/serialize_status.js +0 -28
- package/src/error/parse/stack.js +0 -45
- package/src/error/process.js +0 -13
- package/src/error/type.js +0 -143
- package/src/install/functions.js +0 -52
- package/src/install/local.js +0 -65
- package/src/install/main.js +0 -103
- package/src/install/missing.js +0 -86
- package/src/log/colors.js +0 -59
- package/src/log/description.js +0 -38
- package/src/log/header.js +0 -19
- package/src/log/logger.js +0 -55
- package/src/log/main.js +0 -348
- package/src/log/old_version.js +0 -45
- package/src/log/serialize.js +0 -15
- package/src/log/stream.js +0 -15
- package/src/log/theme.js +0 -32
- package/src/log/timer.js +0 -28
- package/src/plugins/child/api.js +0 -59
- package/src/plugins/child/error.js +0 -39
- package/src/plugins/child/load.js +0 -40
- package/src/plugins/child/logic.js +0 -31
- package/src/plugins/child/main.js +0 -48
- package/src/plugins/child/normalize.js +0 -20
- package/src/plugins/child/run.js +0 -34
- package/src/plugins/child/status.js +0 -53
- package/src/plugins/child/utils.js +0 -43
- package/src/plugins/child/validate.js +0 -46
- package/src/plugins/error.js +0 -44
- package/src/plugins/events.js +0 -77
- package/src/plugins/ipc.js +0 -136
- package/src/plugins/load.js +0 -66
- package/src/plugins/manifest/check.js +0 -80
- package/src/plugins/manifest/load.js +0 -47
- package/src/plugins/manifest/main.js +0 -28
- package/src/plugins/manifest/path.js +0 -12
- package/src/plugins/manifest/validate.js +0 -136
- package/src/plugins/node_version.js +0 -74
- package/src/plugins/options.js +0 -78
- package/src/plugins/package.js +0 -17
- package/src/plugins/resolve.js +0 -159
- package/src/plugins/spawn.js +0 -82
- package/src/plugins_core/cache/manifest.yml +0 -1
- package/src/plugins_core/cache/plugin.js +0 -75
- package/src/plugins_core/functions/manifest.yml +0 -1
- package/src/plugins_core/functions/plugin.js +0 -37
- package/src/plugins_core/functions_install/plugin.js +0 -14
- package/src/plugins_core/main.js +0 -38
- package/src/status/add.js +0 -56
- package/src/status/colors.js +0 -25
- package/src/status/report.js +0 -57
- package/src/telemetry/complete.js +0 -49
- package/src/telemetry/request.js +0 -28
- package/src/telemetry/track.js +0 -33
- package/src/utils/omit.js +0 -8
- package/src/utils/polyfills.js +0 -3
- package/src/utils/remove_falsy.js +0 -12
- package/src/utils/resolve.js +0 -39
- /package/{src → lib}/plugins_core/functions_install/manifest.yml +0 -0
package/bin.js
ADDED
package/lib/core/bin.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import process from 'process';
|
|
3
|
+
import filterObj from 'filter-obj';
|
|
4
|
+
import yargs from 'yargs';
|
|
5
|
+
import { hideBin } from 'yargs/helpers';
|
|
6
|
+
import { normalizeCliFeatureFlags } from './feature_flags.js';
|
|
7
|
+
import { FLAGS } from './flags.js';
|
|
8
|
+
import build from './main.js';
|
|
9
|
+
import { FALLBACK_SEVERITY_ENTRY } from './severity.js';
|
|
10
|
+
// CLI entry point.
|
|
11
|
+
// Before adding logic to this file, please consider adding it to the main
|
|
12
|
+
// programmatic command instead, so that the new logic is available when run
|
|
13
|
+
// programmatically as well. This file should only contain logic that makes
|
|
14
|
+
// sense only in CLI, such as CLI flags parsing and exit code.
|
|
15
|
+
const runCli = async function () {
|
|
16
|
+
const flags = parseFlags();
|
|
17
|
+
const flagsA = filterObj(flags, isUserFlag);
|
|
18
|
+
const state = { done: false };
|
|
19
|
+
process.on('exit', onExit.bind(undefined, state));
|
|
20
|
+
const { severityCode, logs } = await build(flagsA);
|
|
21
|
+
printLogs(logs);
|
|
22
|
+
process.exitCode = severityCode;
|
|
23
|
+
state.done = true;
|
|
24
|
+
};
|
|
25
|
+
const parseFlags = function () {
|
|
26
|
+
const { featureFlags: cliFeatureFlags = '', ...flags } = yargs(hideBin(process.argv))
|
|
27
|
+
.options(FLAGS)
|
|
28
|
+
.usage(USAGE)
|
|
29
|
+
.parse();
|
|
30
|
+
const featureFlags = normalizeCliFeatureFlags(cliFeatureFlags);
|
|
31
|
+
return { ...flags, featureFlags };
|
|
32
|
+
};
|
|
33
|
+
const USAGE = `netlify-build [OPTIONS...]
|
|
34
|
+
|
|
35
|
+
Run Netlify Build system locally.
|
|
36
|
+
|
|
37
|
+
Options can also be specified as environment variables prefixed with
|
|
38
|
+
NETLIFY_BUILD_. For example the environment variable NETLIFY_BUILD_DRY=true can
|
|
39
|
+
be used instead of the CLI flag --dry.`;
|
|
40
|
+
// Remove `yargs`-specific options, shortcuts, dash-cased and aliases
|
|
41
|
+
const isUserFlag = function (key, value) {
|
|
42
|
+
return value !== undefined && !INTERNAL_KEYS.has(key) && key.length !== 1 && !key.includes('-');
|
|
43
|
+
};
|
|
44
|
+
const INTERNAL_KEYS = new Set(['help', 'version', '_', '$0', 'dryRun']);
|
|
45
|
+
// Used mostly for testing
|
|
46
|
+
const printLogs = function (logs) {
|
|
47
|
+
if (logs === undefined) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const allLogs = [logs.stdout.join('\n'), logs.stderr.join('\n')].filter(Boolean).join('\n\n');
|
|
51
|
+
console.log(allLogs);
|
|
52
|
+
};
|
|
53
|
+
// In theory, the main process should not exit until the main `build()` function
|
|
54
|
+
// has completed. In practice, this might happen due to bugs.
|
|
55
|
+
// Making the exit code not 0 in that case ensures the caller knows that the
|
|
56
|
+
// build has completed when the exit code is 0. This `exit` event handlers
|
|
57
|
+
// guarantees this.
|
|
58
|
+
const onExit = function ({ done }, exitCode) {
|
|
59
|
+
if (done || exitCode !== 0) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const [, processName] = process.argv;
|
|
63
|
+
console.log(`${processName} exited with exit code ${exitCode} without finishing the build.`);
|
|
64
|
+
process.exitCode = FALLBACK_SEVERITY_ENTRY.severityCode;
|
|
65
|
+
};
|
|
66
|
+
runCli();
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { supportedRuntimes } from '@netlify/framework-info';
|
|
2
|
+
import { getErrorInfo } from '../error/info.js';
|
|
3
|
+
import { startErrorMonitor } from '../error/monitor/start.js';
|
|
4
|
+
import { getBufferLogs, getSystemLogger } from '../log/logger.js';
|
|
5
|
+
import { logBuildStart } from '../log/messages/core.js';
|
|
6
|
+
import { loadPlugins } from '../plugins/load.js';
|
|
7
|
+
import { getPluginsOptions } from '../plugins/options.js';
|
|
8
|
+
import { pinPlugins } from '../plugins/pinned_version.js';
|
|
9
|
+
import { startPlugins, stopPlugins } from '../plugins/spawn.js';
|
|
10
|
+
import { addCorePlugins } from '../plugins_core/add.js';
|
|
11
|
+
import { reportStatuses } from '../status/report.js';
|
|
12
|
+
import { getDevSteps, getSteps } from '../steps/get.js';
|
|
13
|
+
import { runSteps } from '../steps/run_steps.js';
|
|
14
|
+
import { initTimers, measureDuration } from '../time/main.js';
|
|
15
|
+
import { getConfigOpts, loadConfig } from './config.js';
|
|
16
|
+
import { getConstants } from './constants.js';
|
|
17
|
+
import { doDryRun } from './dry.js';
|
|
18
|
+
import { warnOnLingeringProcesses } from './lingering.js';
|
|
19
|
+
import { warnOnMissingSideFiles } from './missing_side_file.js';
|
|
20
|
+
import { normalizeFlags } from './normalize_flags.js';
|
|
21
|
+
// Performed on build start. Must be kept small and unlikely to fail since it
|
|
22
|
+
// does not have proper error handling. Error handling relies on `errorMonitor`
|
|
23
|
+
// being built, which relies itself on flags being normalized.
|
|
24
|
+
export const startBuild = function (flags) {
|
|
25
|
+
const timers = initTimers();
|
|
26
|
+
const logs = getBufferLogs(flags);
|
|
27
|
+
if (!flags.quiet) {
|
|
28
|
+
logBuildStart(logs);
|
|
29
|
+
}
|
|
30
|
+
const { bugsnagKey, ...flagsA } = normalizeFlags(flags, logs);
|
|
31
|
+
const errorMonitor = startErrorMonitor({ flags: flagsA, logs, bugsnagKey });
|
|
32
|
+
return { ...flagsA, errorMonitor, logs, timers };
|
|
33
|
+
};
|
|
34
|
+
const tExecBuild = async function ({ config, defaultConfig, cachedConfig, cachedConfigPath, outputConfigPath, cwd, repositoryRoot, apiHost, token, siteId, context, branch, baseRelDir, env: envOpt, debug, systemLogFile, verbose, nodePath, functionsDistDir, edgeFunctionsDistDir, cacheDir, dry, mode, offline, deployId, buildId, testOpts, errorMonitor, errorParams, logs, timers, buildbotServerSocket, sendStatus, saveConfig, featureFlags, timeline, devCommand, quiet, framework, }) {
|
|
35
|
+
const configOpts = getConfigOpts({
|
|
36
|
+
config,
|
|
37
|
+
defaultConfig,
|
|
38
|
+
cwd,
|
|
39
|
+
repositoryRoot,
|
|
40
|
+
apiHost,
|
|
41
|
+
token,
|
|
42
|
+
siteId,
|
|
43
|
+
context,
|
|
44
|
+
branch,
|
|
45
|
+
baseRelDir,
|
|
46
|
+
envOpt,
|
|
47
|
+
mode,
|
|
48
|
+
offline,
|
|
49
|
+
deployId,
|
|
50
|
+
buildId,
|
|
51
|
+
testOpts,
|
|
52
|
+
featureFlags,
|
|
53
|
+
});
|
|
54
|
+
const { netlifyConfig, configPath, headersPath, redirectsPath, buildDir, repositoryRoot: repositoryRootA, packageJson, userNodeVersion, childEnv, context: contextA, branch: branchA, token: tokenA, api, siteInfo, timers: timersA, } = await loadConfig({
|
|
55
|
+
configOpts,
|
|
56
|
+
cachedConfig,
|
|
57
|
+
cachedConfigPath,
|
|
58
|
+
envOpt,
|
|
59
|
+
debug,
|
|
60
|
+
logs,
|
|
61
|
+
nodePath,
|
|
62
|
+
timers,
|
|
63
|
+
quiet,
|
|
64
|
+
});
|
|
65
|
+
if (featureFlags.build_automatic_runtime && framework) {
|
|
66
|
+
const runtime = supportedRuntimes[framework];
|
|
67
|
+
if (runtime !== undefined) {
|
|
68
|
+
const skip = childEnv[runtime.skipFlag] === 'true';
|
|
69
|
+
const installed = netlifyConfig.plugins.some((plugin) => plugin.package === runtime.package);
|
|
70
|
+
if (!installed && !skip) {
|
|
71
|
+
netlifyConfig.plugins.push({ package: runtime.package });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const constants = await getConstants({
|
|
76
|
+
configPath,
|
|
77
|
+
buildDir,
|
|
78
|
+
functionsDistDir,
|
|
79
|
+
edgeFunctionsDistDir,
|
|
80
|
+
cacheDir,
|
|
81
|
+
netlifyConfig,
|
|
82
|
+
siteInfo,
|
|
83
|
+
apiHost,
|
|
84
|
+
token: tokenA,
|
|
85
|
+
mode,
|
|
86
|
+
testOpts,
|
|
87
|
+
});
|
|
88
|
+
const systemLog = getSystemLogger(logs, debug, systemLogFile);
|
|
89
|
+
const pluginsOptions = addCorePlugins({ netlifyConfig, constants });
|
|
90
|
+
// `errorParams` is purposely stateful
|
|
91
|
+
Object.assign(errorParams, { netlifyConfig, pluginsOptions, siteInfo, childEnv, userNodeVersion });
|
|
92
|
+
const { pluginsOptions: pluginsOptionsA, netlifyConfig: netlifyConfigA, stepsCount, timers: timersB, configMutations, metrics, } = await runAndReportBuild({
|
|
93
|
+
pluginsOptions,
|
|
94
|
+
netlifyConfig,
|
|
95
|
+
configOpts,
|
|
96
|
+
siteInfo,
|
|
97
|
+
configPath,
|
|
98
|
+
outputConfigPath,
|
|
99
|
+
headersPath,
|
|
100
|
+
redirectsPath,
|
|
101
|
+
buildDir,
|
|
102
|
+
repositoryRoot: repositoryRootA,
|
|
103
|
+
nodePath,
|
|
104
|
+
packageJson,
|
|
105
|
+
userNodeVersion,
|
|
106
|
+
childEnv,
|
|
107
|
+
context: contextA,
|
|
108
|
+
branch: branchA,
|
|
109
|
+
dry,
|
|
110
|
+
mode,
|
|
111
|
+
api,
|
|
112
|
+
errorMonitor,
|
|
113
|
+
deployId,
|
|
114
|
+
errorParams,
|
|
115
|
+
logs,
|
|
116
|
+
debug,
|
|
117
|
+
systemLog,
|
|
118
|
+
verbose,
|
|
119
|
+
timers: timersA,
|
|
120
|
+
sendStatus,
|
|
121
|
+
saveConfig,
|
|
122
|
+
testOpts,
|
|
123
|
+
buildbotServerSocket,
|
|
124
|
+
constants,
|
|
125
|
+
featureFlags,
|
|
126
|
+
timeline,
|
|
127
|
+
devCommand,
|
|
128
|
+
quiet,
|
|
129
|
+
});
|
|
130
|
+
return {
|
|
131
|
+
pluginsOptions: pluginsOptionsA,
|
|
132
|
+
netlifyConfig: netlifyConfigA,
|
|
133
|
+
siteInfo,
|
|
134
|
+
userNodeVersion,
|
|
135
|
+
stepsCount,
|
|
136
|
+
timers: timersB,
|
|
137
|
+
configMutations,
|
|
138
|
+
metrics,
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
export const execBuild = measureDuration(tExecBuild, 'total', { parentTag: 'build_site' });
|
|
142
|
+
// Runs a build then report any plugin statuses
|
|
143
|
+
export const runAndReportBuild = async function ({ pluginsOptions, netlifyConfig, configOpts, siteInfo, configPath, outputConfigPath, headersPath, redirectsPath, buildDir, repositoryRoot, nodePath, packageJson, userNodeVersion, childEnv, context, branch, buildbotServerSocket, constants, dry, mode, api, errorMonitor, deployId, errorParams, logs, debug, systemLog, verbose, timers, sendStatus, saveConfig, testOpts, featureFlags, timeline, devCommand, quiet, }) {
|
|
144
|
+
try {
|
|
145
|
+
const { stepsCount, netlifyConfig: netlifyConfigA, statuses, pluginsOptions: pluginsOptionsA, failedPlugins, timers: timersA, configMutations, metrics, } = await initAndRunBuild({
|
|
146
|
+
pluginsOptions,
|
|
147
|
+
netlifyConfig,
|
|
148
|
+
configOpts,
|
|
149
|
+
siteInfo,
|
|
150
|
+
configPath,
|
|
151
|
+
outputConfigPath,
|
|
152
|
+
headersPath,
|
|
153
|
+
redirectsPath,
|
|
154
|
+
buildDir,
|
|
155
|
+
repositoryRoot,
|
|
156
|
+
nodePath,
|
|
157
|
+
packageJson,
|
|
158
|
+
userNodeVersion,
|
|
159
|
+
childEnv,
|
|
160
|
+
context,
|
|
161
|
+
branch,
|
|
162
|
+
dry,
|
|
163
|
+
mode,
|
|
164
|
+
api,
|
|
165
|
+
errorMonitor,
|
|
166
|
+
deployId,
|
|
167
|
+
errorParams,
|
|
168
|
+
logs,
|
|
169
|
+
debug,
|
|
170
|
+
systemLog,
|
|
171
|
+
verbose,
|
|
172
|
+
timers,
|
|
173
|
+
sendStatus,
|
|
174
|
+
saveConfig,
|
|
175
|
+
testOpts,
|
|
176
|
+
buildbotServerSocket,
|
|
177
|
+
constants,
|
|
178
|
+
featureFlags,
|
|
179
|
+
timeline,
|
|
180
|
+
devCommand,
|
|
181
|
+
quiet,
|
|
182
|
+
});
|
|
183
|
+
await Promise.all([
|
|
184
|
+
reportStatuses({
|
|
185
|
+
statuses,
|
|
186
|
+
childEnv,
|
|
187
|
+
api,
|
|
188
|
+
mode,
|
|
189
|
+
pluginsOptions: pluginsOptionsA,
|
|
190
|
+
netlifyConfig: netlifyConfigA,
|
|
191
|
+
errorMonitor,
|
|
192
|
+
deployId,
|
|
193
|
+
logs,
|
|
194
|
+
debug,
|
|
195
|
+
sendStatus,
|
|
196
|
+
testOpts,
|
|
197
|
+
}),
|
|
198
|
+
pinPlugins({
|
|
199
|
+
pluginsOptions: pluginsOptionsA,
|
|
200
|
+
failedPlugins,
|
|
201
|
+
api,
|
|
202
|
+
siteInfo,
|
|
203
|
+
childEnv,
|
|
204
|
+
mode,
|
|
205
|
+
netlifyConfig: netlifyConfigA,
|
|
206
|
+
errorMonitor,
|
|
207
|
+
logs,
|
|
208
|
+
debug,
|
|
209
|
+
testOpts,
|
|
210
|
+
sendStatus,
|
|
211
|
+
}),
|
|
212
|
+
]);
|
|
213
|
+
return {
|
|
214
|
+
pluginsOptions: pluginsOptionsA,
|
|
215
|
+
netlifyConfig: netlifyConfigA,
|
|
216
|
+
stepsCount,
|
|
217
|
+
timers: timersA,
|
|
218
|
+
configMutations,
|
|
219
|
+
metrics,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
const [{ statuses }] = getErrorInfo(error);
|
|
224
|
+
await reportStatuses({
|
|
225
|
+
statuses,
|
|
226
|
+
childEnv,
|
|
227
|
+
api,
|
|
228
|
+
mode,
|
|
229
|
+
pluginsOptions,
|
|
230
|
+
netlifyConfig,
|
|
231
|
+
errorMonitor,
|
|
232
|
+
deployId,
|
|
233
|
+
logs,
|
|
234
|
+
debug,
|
|
235
|
+
sendStatus,
|
|
236
|
+
testOpts,
|
|
237
|
+
});
|
|
238
|
+
throw error;
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
// Initialize plugin processes then runs a build
|
|
242
|
+
const initAndRunBuild = async function ({ pluginsOptions, netlifyConfig, configOpts, siteInfo, configPath, outputConfigPath, headersPath, redirectsPath, buildDir, repositoryRoot, nodePath, packageJson, userNodeVersion, childEnv, context, branch, dry, mode, api, errorMonitor, deployId, errorParams, logs, debug, systemLog, verbose, sendStatus, saveConfig, timers, testOpts, buildbotServerSocket, constants, featureFlags, timeline, devCommand, quiet, }) {
|
|
243
|
+
const { pluginsOptions: pluginsOptionsA, timers: timersA } = await getPluginsOptions({
|
|
244
|
+
pluginsOptions,
|
|
245
|
+
netlifyConfig,
|
|
246
|
+
siteInfo,
|
|
247
|
+
buildDir,
|
|
248
|
+
nodePath,
|
|
249
|
+
packageJson,
|
|
250
|
+
userNodeVersion,
|
|
251
|
+
mode,
|
|
252
|
+
api,
|
|
253
|
+
logs,
|
|
254
|
+
debug,
|
|
255
|
+
sendStatus,
|
|
256
|
+
timers,
|
|
257
|
+
testOpts,
|
|
258
|
+
featureFlags,
|
|
259
|
+
});
|
|
260
|
+
errorParams.pluginsOptions = pluginsOptionsA;
|
|
261
|
+
const { childProcesses, timers: timersB } = await startPlugins({
|
|
262
|
+
pluginsOptions: pluginsOptionsA,
|
|
263
|
+
buildDir,
|
|
264
|
+
childEnv,
|
|
265
|
+
logs,
|
|
266
|
+
debug,
|
|
267
|
+
timers: timersA,
|
|
268
|
+
featureFlags,
|
|
269
|
+
quiet,
|
|
270
|
+
});
|
|
271
|
+
try {
|
|
272
|
+
const { stepsCount, netlifyConfig: netlifyConfigA, statuses, failedPlugins, timers: timersC, configMutations, metrics, } = await runBuild({
|
|
273
|
+
childProcesses,
|
|
274
|
+
pluginsOptions: pluginsOptionsA,
|
|
275
|
+
netlifyConfig,
|
|
276
|
+
configOpts,
|
|
277
|
+
packageJson,
|
|
278
|
+
configPath,
|
|
279
|
+
outputConfigPath,
|
|
280
|
+
userNodeVersion,
|
|
281
|
+
headersPath,
|
|
282
|
+
redirectsPath,
|
|
283
|
+
buildDir,
|
|
284
|
+
repositoryRoot,
|
|
285
|
+
nodePath,
|
|
286
|
+
childEnv,
|
|
287
|
+
context,
|
|
288
|
+
branch,
|
|
289
|
+
dry,
|
|
290
|
+
buildbotServerSocket,
|
|
291
|
+
constants,
|
|
292
|
+
mode,
|
|
293
|
+
api,
|
|
294
|
+
errorMonitor,
|
|
295
|
+
deployId,
|
|
296
|
+
errorParams,
|
|
297
|
+
logs,
|
|
298
|
+
debug,
|
|
299
|
+
systemLog,
|
|
300
|
+
verbose,
|
|
301
|
+
saveConfig,
|
|
302
|
+
timers: timersB,
|
|
303
|
+
testOpts,
|
|
304
|
+
featureFlags,
|
|
305
|
+
timeline,
|
|
306
|
+
devCommand,
|
|
307
|
+
quiet,
|
|
308
|
+
});
|
|
309
|
+
await Promise.all([
|
|
310
|
+
warnOnMissingSideFiles({ buildDir, netlifyConfig: netlifyConfigA, logs }),
|
|
311
|
+
warnOnLingeringProcesses({ mode, logs, testOpts }),
|
|
312
|
+
]);
|
|
313
|
+
return {
|
|
314
|
+
stepsCount,
|
|
315
|
+
netlifyConfig: netlifyConfigA,
|
|
316
|
+
statuses,
|
|
317
|
+
pluginsOptions: pluginsOptionsA,
|
|
318
|
+
failedPlugins,
|
|
319
|
+
timers: timersC,
|
|
320
|
+
configMutations,
|
|
321
|
+
metrics,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
finally {
|
|
325
|
+
// Terminate the child processes of plugins so that they don't linger after
|
|
326
|
+
// the build is finished. The exception is when running in the dev timeline
|
|
327
|
+
// since those are long-running events by nature.
|
|
328
|
+
if (timeline !== 'dev') {
|
|
329
|
+
stopPlugins(childProcesses);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
// Load plugin main files, retrieve their event handlers then runs them,
|
|
334
|
+
// together with the build command
|
|
335
|
+
const runBuild = async function ({ childProcesses, pluginsOptions, netlifyConfig, configOpts, packageJson, configPath, outputConfigPath, userNodeVersion, headersPath, redirectsPath, buildDir, repositoryRoot, nodePath, childEnv, context, branch, dry, buildbotServerSocket, constants, mode, api, errorMonitor, deployId, errorParams, logs, debug, systemLog, verbose, saveConfig, timers, testOpts, featureFlags, timeline, devCommand, quiet, }) {
|
|
336
|
+
const { pluginsSteps, timers: timersA } = await loadPlugins({
|
|
337
|
+
pluginsOptions,
|
|
338
|
+
childProcesses,
|
|
339
|
+
packageJson,
|
|
340
|
+
timers,
|
|
341
|
+
logs,
|
|
342
|
+
debug,
|
|
343
|
+
verbose,
|
|
344
|
+
});
|
|
345
|
+
const { steps, events } = timeline === 'dev' ? getDevSteps(devCommand, pluginsSteps) : getSteps(pluginsSteps);
|
|
346
|
+
if (dry) {
|
|
347
|
+
await doDryRun({ buildDir, steps, netlifyConfig, constants, buildbotServerSocket, logs });
|
|
348
|
+
return { netlifyConfig };
|
|
349
|
+
}
|
|
350
|
+
const { stepsCount, netlifyConfig: netlifyConfigA, statuses, failedPlugins, timers: timersB, configMutations, metrics, } = await runSteps({
|
|
351
|
+
steps,
|
|
352
|
+
buildbotServerSocket,
|
|
353
|
+
events,
|
|
354
|
+
configPath,
|
|
355
|
+
outputConfigPath,
|
|
356
|
+
headersPath,
|
|
357
|
+
redirectsPath,
|
|
358
|
+
buildDir,
|
|
359
|
+
repositoryRoot,
|
|
360
|
+
nodePath,
|
|
361
|
+
childEnv,
|
|
362
|
+
context,
|
|
363
|
+
branch,
|
|
364
|
+
constants,
|
|
365
|
+
mode,
|
|
366
|
+
api,
|
|
367
|
+
errorMonitor,
|
|
368
|
+
deployId,
|
|
369
|
+
errorParams,
|
|
370
|
+
netlifyConfig,
|
|
371
|
+
configOpts,
|
|
372
|
+
logs,
|
|
373
|
+
debug,
|
|
374
|
+
systemLog,
|
|
375
|
+
verbose,
|
|
376
|
+
saveConfig,
|
|
377
|
+
timers: timersA,
|
|
378
|
+
testOpts,
|
|
379
|
+
featureFlags,
|
|
380
|
+
quiet,
|
|
381
|
+
userNodeVersion,
|
|
382
|
+
});
|
|
383
|
+
return {
|
|
384
|
+
stepsCount,
|
|
385
|
+
netlifyConfig: netlifyConfigA,
|
|
386
|
+
statuses,
|
|
387
|
+
failedPlugins,
|
|
388
|
+
timers: timersB,
|
|
389
|
+
configMutations,
|
|
390
|
+
metrics,
|
|
391
|
+
};
|
|
392
|
+
};
|
|
@@ -0,0 +1,124 @@
|
|
|
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';
|
|
11
|
+
// Retrieve immutable options passed to `@netlify/config`.
|
|
12
|
+
// This does not include options which might change during the course of the
|
|
13
|
+
// build:
|
|
14
|
+
// - `cachedConfig` and `cachedConfigPath` are only used at the beginning of
|
|
15
|
+
// the build
|
|
16
|
+
// - If plugins change the configuration, `configMutations` is used instead
|
|
17
|
+
// In both cases, almost all options should remain the same.
|
|
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
|
+
};
|
|
39
|
+
// Retrieve configuration object
|
|
40
|
+
const tLoadConfig = async function ({ configOpts, cachedConfig, cachedConfigPath, envOpt, debug, logs, nodePath, quiet, }) {
|
|
41
|
+
const { configPath, headersPath, redirectsPath, buildDir, repositoryRoot, config: netlifyConfig, context: contextA, branch: branchA, token: tokenA, api, siteInfo, env, } = await resolveInitialConfig(configOpts, cachedConfig, cachedConfigPath);
|
|
42
|
+
if (!quiet) {
|
|
43
|
+
logConfigInfo({ logs, configPath, buildDir, netlifyConfig, context: contextA, debug });
|
|
44
|
+
}
|
|
45
|
+
const apiA = addApiErrorHandlers(api);
|
|
46
|
+
const envValues = mapObj(env, (key, { value }) => [key, value]);
|
|
47
|
+
const childEnv = getChildEnv({ envOpt, env: envValues });
|
|
48
|
+
const [{ packageJson }, userNodeVersion] = await Promise.all([getPackageJson(buildDir), getUserNodeVersion(nodePath)]);
|
|
49
|
+
return {
|
|
50
|
+
netlifyConfig,
|
|
51
|
+
configPath,
|
|
52
|
+
headersPath,
|
|
53
|
+
redirectsPath,
|
|
54
|
+
buildDir,
|
|
55
|
+
repositoryRoot,
|
|
56
|
+
packageJson,
|
|
57
|
+
userNodeVersion,
|
|
58
|
+
childEnv,
|
|
59
|
+
context: contextA,
|
|
60
|
+
branch: branchA,
|
|
61
|
+
token: tokenA,
|
|
62
|
+
api: apiA,
|
|
63
|
+
siteInfo,
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
export const loadConfig = measureDuration(tLoadConfig, 'resolve_config');
|
|
67
|
+
// Retrieve initial configuration.
|
|
68
|
+
// In the buildbot and CLI, we re-use the already parsed `@netlify/config`
|
|
69
|
+
// return value which is passed as `cachedConfig`/`cachedConfigPath`.
|
|
70
|
+
const resolveInitialConfig = async function (configOpts, cachedConfig, cachedConfigPath) {
|
|
71
|
+
return await resolveConfig({ ...configOpts, cachedConfig, cachedConfigPath });
|
|
72
|
+
};
|
|
73
|
+
const logConfigInfo = function ({ logs, configPath, buildDir, netlifyConfig, context, debug }) {
|
|
74
|
+
logBuildDir(logs, buildDir);
|
|
75
|
+
logConfigPath(logs, configPath);
|
|
76
|
+
logConfig({ logs, netlifyConfig, debug });
|
|
77
|
+
logContext(logs, context);
|
|
78
|
+
};
|
|
79
|
+
// Retrieve the configuration after it's been changed.
|
|
80
|
+
// This ensures any configuration changes done by plugins is validated and
|
|
81
|
+
// normalized.
|
|
82
|
+
// We use `debug: false` to avoid any debug logs. Otherwise, every configuration
|
|
83
|
+
// change would create debug logs which would be too verbose.
|
|
84
|
+
// Errors are propagated and assigned to the specific plugin or core step
|
|
85
|
+
// which changed the configuration.
|
|
86
|
+
export const resolveUpdatedConfig = async function (configOpts, configMutations) {
|
|
87
|
+
try {
|
|
88
|
+
return await resolveConfig({ ...configOpts, configMutations, debug: false });
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
changeErrorType(error, 'resolveConfig', 'pluginValidation');
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
// If the configuration was changed, persist it to `netlify.toml`.
|
|
96
|
+
// If `netlify.toml` does not exist, create it inside repository root.
|
|
97
|
+
// This is only done when `saveConfig` is `true`. This allows performing this
|
|
98
|
+
// in the buildbot but not in local builds, since only the latter run in a
|
|
99
|
+
// container, and we want to avoid saving files on local machines.
|
|
100
|
+
export const saveUpdatedConfig = async function ({ configMutations, buildDir, repositoryRoot, configPath = `${repositoryRoot}/netlify.toml`, outputConfigPath = configPath, headersPath, redirectsPath, logs, featureFlags, context, branch, debug, saveConfig, }) {
|
|
101
|
+
if (!saveConfig) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
await updateConfig(configMutations, {
|
|
105
|
+
buildDir,
|
|
106
|
+
configPath,
|
|
107
|
+
outputConfigPath,
|
|
108
|
+
headersPath,
|
|
109
|
+
redirectsPath,
|
|
110
|
+
context,
|
|
111
|
+
branch,
|
|
112
|
+
logs,
|
|
113
|
+
featureFlags,
|
|
114
|
+
});
|
|
115
|
+
await logConfigOnUpload({ logs, configPath, debug });
|
|
116
|
+
await logHeadersOnUpload({ logs, headersPath, debug });
|
|
117
|
+
await logRedirectsOnUpload({ logs, redirectsPath, debug });
|
|
118
|
+
};
|
|
119
|
+
export const restoreUpdatedConfig = async function ({ configMutations, buildDir, repositoryRoot, configPath = `${repositoryRoot}/netlify.toml`, headersPath, redirectsPath, saveConfig, }) {
|
|
120
|
+
if (!saveConfig) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
await restoreConfig(configMutations, { buildDir, configPath, headersPath, redirectsPath });
|
|
124
|
+
};
|