@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.
Files changed (243) hide show
  1. package/bin.js +5 -0
  2. package/lib/core/bin.js +66 -0
  3. package/lib/core/build.js +392 -0
  4. package/lib/core/config.js +124 -0
  5. package/lib/core/constants.js +116 -0
  6. package/lib/core/dev.js +27 -0
  7. package/lib/core/dry.js +21 -0
  8. package/lib/core/feature_flags.js +17 -0
  9. package/lib/core/flags.js +206 -0
  10. package/lib/core/lingering.js +68 -0
  11. package/lib/core/main.js +114 -0
  12. package/lib/core/missing_side_file.js +17 -0
  13. package/lib/core/normalize_flags.js +62 -0
  14. package/lib/core/report_metrics.js +17 -0
  15. package/lib/core/severity.js +21 -0
  16. package/lib/core/types.js +8 -0
  17. package/lib/core/user_node_version.js +32 -0
  18. package/lib/env/changes.js +43 -0
  19. package/lib/env/main.js +14 -0
  20. package/lib/env/metadata.js +68 -0
  21. package/lib/error/api.js +37 -0
  22. package/lib/error/build.js +36 -0
  23. package/lib/error/cancel.js +7 -0
  24. package/lib/error/colors.js +9 -0
  25. package/lib/error/handle.js +44 -0
  26. package/lib/error/info.js +37 -0
  27. package/lib/error/monitor/location.js +16 -0
  28. package/lib/error/monitor/normalize.js +86 -0
  29. package/lib/error/monitor/print.js +20 -0
  30. package/lib/error/monitor/report.js +120 -0
  31. package/lib/error/monitor/start.js +61 -0
  32. package/lib/error/parse/clean_stack.js +70 -0
  33. package/lib/error/parse/location.js +50 -0
  34. package/lib/error/parse/normalize.js +24 -0
  35. package/lib/error/parse/parse.js +67 -0
  36. package/lib/error/parse/plugin.js +55 -0
  37. package/lib/error/parse/properties.js +16 -0
  38. package/lib/error/parse/serialize_log.js +34 -0
  39. package/lib/error/parse/serialize_status.js +18 -0
  40. package/lib/error/parse/stack.js +34 -0
  41. package/lib/error/report.js +29 -0
  42. package/lib/error/type.js +177 -0
  43. package/lib/install/functions.js +20 -0
  44. package/lib/install/local.js +45 -0
  45. package/lib/install/main.js +67 -0
  46. package/lib/install/missing.js +54 -0
  47. package/lib/log/colors.js +28 -0
  48. package/lib/log/description.js +21 -0
  49. package/lib/log/header.js +12 -0
  50. package/lib/log/header_func.js +13 -0
  51. package/lib/log/logger.js +140 -0
  52. package/lib/log/messages/compatibility.js +120 -0
  53. package/lib/log/messages/config.js +91 -0
  54. package/lib/log/messages/core.js +49 -0
  55. package/lib/log/messages/core_steps.js +75 -0
  56. package/lib/log/messages/dry.js +41 -0
  57. package/lib/log/messages/install.js +25 -0
  58. package/lib/log/messages/ipc.js +29 -0
  59. package/lib/log/messages/mutations.js +62 -0
  60. package/lib/log/messages/plugins.js +25 -0
  61. package/lib/log/messages/status.js +14 -0
  62. package/lib/log/messages/steps.js +18 -0
  63. package/lib/log/serialize.js +10 -0
  64. package/lib/log/stream.js +68 -0
  65. package/lib/log/theme.js +27 -0
  66. package/lib/plugins/child/diff.js +46 -0
  67. package/lib/plugins/child/error.js +26 -0
  68. package/lib/plugins/child/lazy.js +15 -0
  69. package/lib/plugins/child/load.js +22 -0
  70. package/lib/plugins/child/logic.js +57 -0
  71. package/lib/plugins/child/main.js +37 -0
  72. package/lib/plugins/child/run.js +19 -0
  73. package/lib/plugins/child/status.js +63 -0
  74. package/lib/plugins/child/typescript.js +28 -0
  75. package/lib/plugins/child/utils.js +42 -0
  76. package/lib/plugins/child/validate.js +31 -0
  77. package/lib/plugins/compatibility.js +104 -0
  78. package/lib/plugins/error.js +46 -0
  79. package/lib/plugins/events.js +12 -0
  80. package/lib/plugins/expected_version.js +81 -0
  81. package/lib/plugins/internal.js +10 -0
  82. package/lib/plugins/ipc.js +120 -0
  83. package/lib/plugins/list.js +73 -0
  84. package/lib/plugins/load.js +50 -0
  85. package/lib/plugins/manifest/check.js +85 -0
  86. package/lib/plugins/manifest/load.js +38 -0
  87. package/lib/plugins/manifest/main.js +19 -0
  88. package/lib/plugins/manifest/path.js +24 -0
  89. package/lib/plugins/manifest/validate.js +91 -0
  90. package/lib/plugins/node_version.js +35 -0
  91. package/lib/plugins/options.js +70 -0
  92. package/lib/plugins/pinned_version.js +83 -0
  93. package/lib/plugins/resolve.js +110 -0
  94. package/lib/plugins/spawn.js +55 -0
  95. package/lib/plugins_core/add.js +35 -0
  96. package/lib/plugins_core/build_command.js +50 -0
  97. package/lib/plugins_core/deploy/buildbot_client.js +87 -0
  98. package/lib/plugins_core/deploy/index.js +49 -0
  99. package/lib/plugins_core/deploy/manifest.yml +1 -0
  100. package/lib/plugins_core/edge_functions/index.js +106 -0
  101. package/lib/plugins_core/edge_functions/lib/error.js +17 -0
  102. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +14 -0
  103. package/lib/plugins_core/functions/error.js +123 -0
  104. package/lib/plugins_core/functions/feature_flags.js +5 -0
  105. package/lib/plugins_core/functions/index.js +137 -0
  106. package/lib/plugins_core/functions/utils.js +45 -0
  107. package/lib/plugins_core/functions/zisi.js +64 -0
  108. package/lib/plugins_core/functions_install/index.js +10 -0
  109. package/lib/plugins_core/list.js +20 -0
  110. package/lib/plugins_core/save_artifacts/index.js +33 -0
  111. package/lib/report/statsd.js +56 -0
  112. package/lib/status/add.js +30 -0
  113. package/lib/status/colors.js +18 -0
  114. package/lib/status/load_error.js +10 -0
  115. package/lib/status/report.js +83 -0
  116. package/lib/status/success.js +14 -0
  117. package/lib/steps/core_step.js +62 -0
  118. package/lib/steps/error.js +65 -0
  119. package/lib/steps/get.js +44 -0
  120. package/lib/steps/plugin.js +55 -0
  121. package/lib/steps/return.js +27 -0
  122. package/lib/steps/run_core_steps.js +117 -0
  123. package/lib/steps/run_step.js +200 -0
  124. package/lib/steps/run_steps.js +102 -0
  125. package/lib/steps/update_config.js +66 -0
  126. package/lib/telemetry/main.js +94 -0
  127. package/lib/time/aggregate.js +109 -0
  128. package/lib/time/main.js +31 -0
  129. package/lib/time/measure.js +16 -0
  130. package/lib/time/report.js +30 -0
  131. package/lib/utils/errors.js +13 -0
  132. package/lib/utils/json.js +10 -0
  133. package/lib/utils/omit.js +3 -0
  134. package/lib/utils/package.js +24 -0
  135. package/lib/utils/remove_falsy.js +8 -0
  136. package/lib/utils/resolve.js +41 -0
  137. package/lib/utils/runtime.js +5 -0
  138. package/lib/utils/semver.js +28 -0
  139. package/package.json +119 -56
  140. package/types/config/build.d.ts +52 -0
  141. package/types/config/functions.d.ts +36 -0
  142. package/types/config/inputs.d.ts +7 -0
  143. package/types/config/netlify_config.d.ts +58 -0
  144. package/types/index.d.ts +7 -0
  145. package/types/netlify_event_handler.d.ts +29 -0
  146. package/types/netlify_plugin.d.ts +29 -0
  147. package/types/netlify_plugin_constants.d.ts +51 -0
  148. package/types/netlify_plugin_options.d.ts +23 -0
  149. package/types/options/index.d.ts +1 -0
  150. package/types/options/netlify_plugin_build_util.d.ts +7 -0
  151. package/types/options/netlify_plugin_cache_util.d.ts +39 -0
  152. package/types/options/netlify_plugin_functions_util.d.ts +32 -0
  153. package/types/options/netlify_plugin_git_util.d.ts +41 -0
  154. package/types/options/netlify_plugin_run_util.d.ts +24 -0
  155. package/types/options/netlify_plugin_status_util.d.ts +24 -0
  156. package/types/options/netlify_plugin_utils.d.ts +15 -0
  157. package/types/utils/json_value.d.ts +1 -0
  158. package/types/utils/many.d.ts +6 -0
  159. package/README.md +0 -3
  160. package/src/core/bin.js +0 -139
  161. package/src/core/commands.js +0 -304
  162. package/src/core/config.js +0 -130
  163. package/src/core/constants.js +0 -88
  164. package/src/core/dry.js +0 -23
  165. package/src/core/main.js +0 -196
  166. package/src/env/changes.js +0 -49
  167. package/src/env/git.js +0 -27
  168. package/src/env/main.js +0 -97
  169. package/src/env/metadata.js +0 -81
  170. package/src/error/api.js +0 -32
  171. package/src/error/build.js +0 -32
  172. package/src/error/cancel.js +0 -22
  173. package/src/error/colors.js +0 -13
  174. package/src/error/info.js +0 -12
  175. package/src/error/monitor/normalize.js +0 -50
  176. package/src/error/monitor/print.js +0 -43
  177. package/src/error/monitor/report.js +0 -140
  178. package/src/error/monitor/start.js +0 -50
  179. package/src/error/parse/clean_stack.js +0 -86
  180. package/src/error/parse/location.js +0 -50
  181. package/src/error/parse/parse.js +0 -87
  182. package/src/error/parse/plugin.js +0 -68
  183. package/src/error/parse/properties.js +0 -20
  184. package/src/error/parse/serialize_log.js +0 -46
  185. package/src/error/parse/serialize_status.js +0 -28
  186. package/src/error/parse/stack.js +0 -45
  187. package/src/error/process.js +0 -13
  188. package/src/error/type.js +0 -143
  189. package/src/install/functions.js +0 -52
  190. package/src/install/local.js +0 -65
  191. package/src/install/main.js +0 -103
  192. package/src/install/missing.js +0 -86
  193. package/src/log/colors.js +0 -59
  194. package/src/log/description.js +0 -38
  195. package/src/log/header.js +0 -19
  196. package/src/log/logger.js +0 -55
  197. package/src/log/main.js +0 -348
  198. package/src/log/old_version.js +0 -45
  199. package/src/log/serialize.js +0 -15
  200. package/src/log/stream.js +0 -15
  201. package/src/log/theme.js +0 -32
  202. package/src/log/timer.js +0 -28
  203. package/src/plugins/child/api.js +0 -59
  204. package/src/plugins/child/error.js +0 -39
  205. package/src/plugins/child/load.js +0 -40
  206. package/src/plugins/child/logic.js +0 -31
  207. package/src/plugins/child/main.js +0 -48
  208. package/src/plugins/child/normalize.js +0 -20
  209. package/src/plugins/child/run.js +0 -34
  210. package/src/plugins/child/status.js +0 -53
  211. package/src/plugins/child/utils.js +0 -43
  212. package/src/plugins/child/validate.js +0 -46
  213. package/src/plugins/error.js +0 -44
  214. package/src/plugins/events.js +0 -77
  215. package/src/plugins/ipc.js +0 -136
  216. package/src/plugins/load.js +0 -66
  217. package/src/plugins/manifest/check.js +0 -80
  218. package/src/plugins/manifest/load.js +0 -47
  219. package/src/plugins/manifest/main.js +0 -28
  220. package/src/plugins/manifest/path.js +0 -12
  221. package/src/plugins/manifest/validate.js +0 -136
  222. package/src/plugins/node_version.js +0 -74
  223. package/src/plugins/options.js +0 -78
  224. package/src/plugins/package.js +0 -17
  225. package/src/plugins/resolve.js +0 -159
  226. package/src/plugins/spawn.js +0 -82
  227. package/src/plugins_core/cache/manifest.yml +0 -1
  228. package/src/plugins_core/cache/plugin.js +0 -75
  229. package/src/plugins_core/functions/manifest.yml +0 -1
  230. package/src/plugins_core/functions/plugin.js +0 -37
  231. package/src/plugins_core/functions_install/plugin.js +0 -14
  232. package/src/plugins_core/main.js +0 -38
  233. package/src/status/add.js +0 -56
  234. package/src/status/colors.js +0 -25
  235. package/src/status/report.js +0 -57
  236. package/src/telemetry/complete.js +0 -49
  237. package/src/telemetry/request.js +0 -28
  238. package/src/telemetry/track.js +0 -33
  239. package/src/utils/omit.js +0 -8
  240. package/src/utils/polyfills.js +0 -3
  241. package/src/utils/remove_falsy.js +0 -12
  242. package/src/utils/resolve.js +0 -39
  243. /package/{src → lib}/plugins_core/functions_install/manifest.yml +0 -0
@@ -0,0 +1,116 @@
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';
6
+ // Retrieve constants passed to plugins
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';
41
+ // Retrieve constants which might change during the build if a plugin modifies
42
+ // `netlifyConfig` or creates some default directories.
43
+ // Unlike readonly constants, this is called again before each build step.
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
+ };
58
+ // Some `constants` have a default value when a specific file exists.
59
+ // Those default values are assigned by `@netlify/config`. However, the build
60
+ // command or plugins might create those specific files, in which case, the
61
+ // related `constant` should be updated, unless the user has explicitly
62
+ // configured it.
63
+ const addDefaultConstants = async function (constants, buildDir) {
64
+ const newConstants = await Promise.all(DEFAULT_PATHS.map(({ constantName, defaultPath }) => addDefaultConstant({ constants, constantName, defaultPath, buildDir })));
65
+ return Object.assign({}, constants, ...newConstants);
66
+ };
67
+ // The current directory is the build directory, which is correct, so we don't
68
+ // need to resolve paths
69
+ const DEFAULT_PATHS = [
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
+ ];
75
+ const addDefaultConstant = async function ({ constants, constantName, defaultPath, buildDir }) {
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
+ };
84
+ const normalizeConstantsPaths = function (constants, buildDir) {
85
+ return mapObj(constants, (key, path) => [key, normalizePath(path, buildDir, key)]);
86
+ };
87
+ // The current directory is `buildDir`. Most constants are inside this `buildDir`.
88
+ // Instead of passing absolute paths, we pass paths relative to `buildDir`, so
89
+ // that logs are less verbose.
90
+ const normalizePath = function (path, buildDir, key) {
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
+ };
103
+ const isEmptyValue = function (path) {
104
+ return path === undefined || path === '';
105
+ };
106
+ const CONSTANT_PATHS = new Set([
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
+ ]);
@@ -0,0 +1,27 @@
1
+ import { handleBuildError } from '../error/handle.js';
2
+ import { execBuild, startBuild } from './build.js';
3
+ import { getSeverity } from './severity.js';
4
+ export const startDev = async (devCommand, flags = {}) => {
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
+ };
@@ -0,0 +1,21 @@
1
+ import pFilter from 'p-filter';
2
+ import { logDryRunStart, logDryRunStep, logDryRunEnd } from '../log/messages/dry.js';
3
+ import { runsOnlyOnBuildFailure } from '../plugins/events.js';
4
+ // If the `dry` flag is specified, do a dry run
5
+ export const doDryRun = async function ({ buildDir, steps, netlifyConfig, constants, buildbotServerSocket, logs }) {
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
+ };
19
+ const getEventLength = function ({ event }) {
20
+ return event.length;
21
+ };
@@ -0,0 +1,17 @@
1
+ // From CLI `--featureFlags=a,b,c` to programmatic `{ a: true, b: true, c: true }`
2
+ export const normalizeCliFeatureFlags = function (cliFeatureFlags) {
3
+ return Object.assign({}, ...cliFeatureFlags.split(',').filter(isNotEmpty).map(getFeatureFlag));
4
+ };
5
+ const isNotEmpty = function (name) {
6
+ return name.trim() !== '';
7
+ };
8
+ const getFeatureFlag = function (name) {
9
+ return { [name]: true };
10
+ };
11
+ // Default values for feature flags
12
+ export const DEFAULT_FEATURE_FLAGS = {
13
+ buildbot_zisi_trace_nft: false,
14
+ buildbot_zisi_esbuild_parser: false,
15
+ edge_functions_cache_cli: false,
16
+ edge_functions_system_logger: false,
17
+ };
@@ -0,0 +1,206 @@
1
+ const jsonParse = function (value) {
2
+ return value === undefined ? undefined : JSON.parse(value);
3
+ };
4
+ // All CLI flags
5
+ export const FLAGS = {
6
+ config: {
7
+ string: true,
8
+ describe: `Path to the configuration file.
9
+ Defaults to any netlify.toml in the git repository root directory or the base directory`,
10
+ },
11
+ defaultConfig: {
12
+ string: true,
13
+ describe: `JSON configuration object containing default values.
14
+ Each configuration default value is used unless overridden through the main configuration file.
15
+ Default: none.`,
16
+ coerce: jsonParse,
17
+ hidden: true,
18
+ },
19
+ cachedConfig: {
20
+ string: true,
21
+ describe: `JSON configuration object returned by @netlify/config when --output=/ is used
22
+ or when using @netlify/config programmatically.
23
+ This is done as a performance optimization to cache the configuration loading logic.
24
+ Default: none.`,
25
+ coerce: jsonParse,
26
+ hidden: true,
27
+ },
28
+ cachedConfigPath: {
29
+ string: true,
30
+ describe: `File path to the JSON configuration object returned by @netlify/config
31
+ when --output=/path is used.
32
+ This is done as a performance optimization to cache the configuration loading logic.
33
+ Default: none.`,
34
+ hidden: true,
35
+ },
36
+ cwd: {
37
+ string: true,
38
+ describe: `Current directory. Used to retrieve the configuration file.
39
+ Default: current directory`,
40
+ },
41
+ repositoryRoot: {
42
+ string: true,
43
+ describe: `Git repository root directory. Used to retrieve the configuration file.
44
+ Default: automatically guessed`,
45
+ },
46
+ apiHost: {
47
+ string: true,
48
+ describe: `Netlify API endpoint.
49
+ Default: automatically guessed`,
50
+ },
51
+ token: {
52
+ string: true,
53
+ describe: `Netlify API token for authentication.
54
+ The NETLIFY_AUTH_TOKEN environment variable can be used as well.`,
55
+ },
56
+ siteId: {
57
+ string: true,
58
+ describe: `Netlify Site ID.`,
59
+ },
60
+ deployId: {
61
+ string: true,
62
+ describe: `Netlify Deploy ID.
63
+ Default: automatically guessed`,
64
+ },
65
+ buildId: {
66
+ string: true,
67
+ describe: `Netlify Build ID.
68
+ Default: automatically guessed`,
69
+ },
70
+ context: {
71
+ string: true,
72
+ describe: `Build context.
73
+ Default: 'production'`,
74
+ },
75
+ branch: {
76
+ string: true,
77
+ describe: `Repository branch.
78
+ Default: automatically guessed`,
79
+ },
80
+ framework: {
81
+ string: true,
82
+ describe: 'Front-end framework.',
83
+ hidden: true,
84
+ },
85
+ baseRelDir: {
86
+ boolean: true,
87
+ describe: `Feature flag meant for backward compatibility.
88
+ When enabled, if the 'build.base' configuration property is defined, it is used
89
+ to try to retrieve a second configuration file and discard the first one.
90
+ Default: true`,
91
+ hidden: true,
92
+ },
93
+ dry: {
94
+ alias: 'dry-run',
95
+ boolean: true,
96
+ describe: `Run in dry mode, i.e. printing steps without executing them.
97
+ Default: false`,
98
+ },
99
+ nodePath: {
100
+ string: true,
101
+ describe: `Path to the Node.js binary to use in the build command and plugins.
102
+ Default: Current Node.js binary`,
103
+ },
104
+ functionsDistDir: {
105
+ string: true,
106
+ describe: `Path to the directory where packaged functions are kept.
107
+ Default: automatically guessed`,
108
+ hidden: true,
109
+ },
110
+ edgeFunctionsDistDir: {
111
+ string: true,
112
+ describe: `Path to the directory where packaged Edge Functions are kept.
113
+ Default: automatically guessed`,
114
+ hidden: true,
115
+ },
116
+ cacheDir: {
117
+ string: true,
118
+ describe: `Path to the cache directory.
119
+ Default: .netlify/cache/`,
120
+ hidden: true,
121
+ },
122
+ buildbotServerSocket: {
123
+ string: true,
124
+ describe: `Path to the buildbot server socket. This is used to connect to the buildbot to trigger deploys.`,
125
+ hidden: true,
126
+ },
127
+ telemetry: {
128
+ boolean: true,
129
+ describe: `Enable telemetry.
130
+ Default: false`,
131
+ },
132
+ mode: {
133
+ string: true,
134
+ describe: `Environment in which this is loaded. Can be:
135
+ - 'buildbot': within Netlify Buildbot
136
+ - 'cli': within Netlify CLI
137
+ - 'require': through import('@netlify/build')`,
138
+ hidden: true,
139
+ },
140
+ debug: {
141
+ boolean: true,
142
+ describe: 'Print user-facing debugging information',
143
+ hidden: true,
144
+ },
145
+ systemLogFile: {
146
+ type: 'number',
147
+ describe: 'File descriptor to where system logs should be piped',
148
+ hidden: true,
149
+ },
150
+ verbose: {
151
+ boolean: true,
152
+ describe: 'Print internal debugging information',
153
+ hidden: true,
154
+ },
155
+ sendStatus: {
156
+ boolean: true,
157
+ describe: 'Whether plugin statuses should be sent to the Netlify API',
158
+ hidden: true,
159
+ },
160
+ saveConfig: {
161
+ boolean: true,
162
+ describe: 'Whether configuration changes should be saved to netlify.toml',
163
+ hidden: true,
164
+ },
165
+ outputConfigPath: {
166
+ type: 'string',
167
+ describe: 'Path where to save the netlify.toml resulting from configuration changes. Only applicable if `saveConfig` is set. Defaults to "netlify.toml" in the root directory.',
168
+ hidden: true,
169
+ },
170
+ testOpts: {
171
+ describe: 'Options for testing only',
172
+ hidden: true,
173
+ },
174
+ featureFlags: {
175
+ describe: 'Comma-separated list of feature flags to enable unreleased features',
176
+ hidden: true,
177
+ },
178
+ statsd: {
179
+ describe: 'Statsd-related options, for performance measuring',
180
+ hidden: true,
181
+ },
182
+ 'statsd.host': {
183
+ type: 'string',
184
+ describe: 'Statsd host',
185
+ hidden: true,
186
+ },
187
+ 'statsd.port': {
188
+ type: 'number',
189
+ describe: 'Statsd port',
190
+ hidden: true,
191
+ },
192
+ offline: {
193
+ boolean: true,
194
+ describe: `Do not send requests to the Netlify API to retrieve site settings.
195
+ Default: false`,
196
+ },
197
+ buffer: {
198
+ boolean: true,
199
+ describe: 'Buffer output instead of printing it',
200
+ },
201
+ timeline: {
202
+ string: true,
203
+ describe: 'The sequence of lifecycle events to run',
204
+ hidden: true,
205
+ },
206
+ };
@@ -0,0 +1,68 @@
1
+ import psList from 'ps-list';
2
+ import { logLingeringProcesses } from '../log/messages/core.js';
3
+ // Print a warning when some build processes are still running.
4
+ // We cannot rely on using the process tree:
5
+ // - This is because it is impossible to know whether a process was a child of
6
+ // another once its parent process has exited. When that happens, the s
7
+ // child becomes inherited by `init`, changing its `ppid`. The information
8
+ // about the original parent is then lost.
9
+ // - The only way to implement this would be to repeatedly list processes as
10
+ // the build command is ongoing. However, this would fail to detect processes
11
+ // spawned just before the build commands ends.
12
+ // We cannot list processes before and after the build command and use the
13
+ // difference.
14
+ // - This is because other processes (unrelated to @netlify/build) might be
15
+ // running at the same time. This includes OS background processes.
16
+ // Therefore, we run this in a controlled environment only (the buildbot) and
17
+ // exclude specific processes manually. This is a lesser evil, although still
18
+ // quite hacky.
19
+ export const warnOnLingeringProcesses = async function ({ mode, logs, testOpts: { silentLingeringProcesses = false }, }) {
20
+ if (mode !== 'buildbot' || silentLingeringProcesses) {
21
+ return;
22
+ }
23
+ const processes = await psList();
24
+ const commands = processes.map(getCommand).filter(isNotIgnoredCommand);
25
+ if (commands.length === 0) {
26
+ return;
27
+ }
28
+ logLingeringProcesses(logs, commands);
29
+ };
30
+ // `cmd` is only available on Unix. Unlike `name`, it includes the arguments.
31
+ const getCommand = function ({ name, cmd = name }) {
32
+ return cmd;
33
+ };
34
+ // We ignore any command known to be internal to the buildbot.
35
+ // We also ignore commands known not to complete properly in builds if they are
36
+ // widely used.
37
+ const isNotIgnoredCommand = function (command) {
38
+ return !IGNORED_COMMANDS.some((ignoredCommand) => matchesIgnoredCommand(command, ignoredCommand));
39
+ };
40
+ const matchesIgnoredCommand = function (command, ignoredCommand) {
41
+ if (typeof ignoredCommand === 'string') {
42
+ return command.includes(ignoredCommand);
43
+ }
44
+ return ignoredCommand.test(command);
45
+ };
46
+ const IGNORED_COMMANDS = [
47
+ // TODO: Those can most likely be removed
48
+ 'ps',
49
+ 'grep',
50
+ 'bash',
51
+ // Internal buildbot commands
52
+ '[build]',
53
+ /buildbot.*\[node]/,
54
+ // buildbot's main Bash script
55
+ '/opt/build-bin/build',
56
+ // `@netlify/build` binary itself
57
+ 'netlify-build',
58
+ // Plugin child processes spawned by @netlify/build
59
+ '@netlify/build',
60
+ // Shown for parent processes with currently running child processes.
61
+ // Happens on `ps` itself.
62
+ 'defunct',
63
+ // Processes often left running. We should report those but don't because of
64
+ // how common those are in production builds
65
+ 'gatsby-telemetry',
66
+ 'jest-worker',
67
+ 'broccoli-babel-transpiler',
68
+ ];
@@ -0,0 +1,114 @@
1
+ import { handleBuildError } from '../error/handle.js';
2
+ import { reportError } from '../error/report.js';
3
+ import { getSystemLogger } from '../log/logger.js';
4
+ import { logTimer, logBuildSuccess } from '../log/messages/core.js';
5
+ import { trackBuildComplete } from '../telemetry/main.js';
6
+ import { reportTimers } from '../time/report.js';
7
+ import { execBuild, startBuild } from './build.js';
8
+ import { reportMetrics } from './report_metrics.js';
9
+ import { getSeverity } from './severity.js';
10
+ export { startDev } from './dev.js';
11
+ export { runCoreSteps } from '../steps/run_core_steps.js';
12
+ /**
13
+ * Main entry point of Netlify Build.
14
+ * Runs a builds and returns whether it succeeded or not.
15
+ *
16
+ * @param flags - build configuration CLI flags
17
+ */
18
+ export default async function buildSite(flags = {}) {
19
+ const { errorMonitor, framework, mode, logs, debug, systemLogFile, testOpts, statsdOpts, dry, telemetry, buildId, deployId, ...flagsA } = startBuild(flags);
20
+ const errorParams = { errorMonitor, mode, logs, debug, testOpts };
21
+ const systemLog = getSystemLogger(logs, debug, systemLogFile);
22
+ try {
23
+ const { pluginsOptions, netlifyConfig: netlifyConfigA, siteInfo, userNodeVersion, stepsCount, timers, durationNs, configMutations, metrics, } = await execBuild({
24
+ ...flagsA,
25
+ buildId,
26
+ systemLogFile,
27
+ deployId,
28
+ dry,
29
+ errorMonitor,
30
+ mode,
31
+ logs,
32
+ debug,
33
+ testOpts,
34
+ errorParams,
35
+ framework,
36
+ });
37
+ await handleBuildSuccess({
38
+ framework,
39
+ dry,
40
+ logs,
41
+ timers,
42
+ durationNs,
43
+ statsdOpts,
44
+ systemLog,
45
+ metrics,
46
+ });
47
+ const { success, severityCode, status } = getSeverity('success');
48
+ await telemetryReport({
49
+ buildId,
50
+ deployId,
51
+ status,
52
+ stepsCount,
53
+ pluginsOptions,
54
+ durationNs,
55
+ siteInfo,
56
+ telemetry,
57
+ userNodeVersion,
58
+ framework,
59
+ testOpts,
60
+ errorParams,
61
+ });
62
+ return { success, severityCode, netlifyConfig: netlifyConfigA, logs, configMutations };
63
+ }
64
+ catch (error) {
65
+ const { severity } = await handleBuildError(error, errorParams);
66
+ const { pluginsOptions, siteInfo, userNodeVersion } = errorParams;
67
+ const { success, severityCode, status } = getSeverity(severity);
68
+ await telemetryReport({
69
+ buildId,
70
+ deployId,
71
+ status,
72
+ pluginsOptions,
73
+ siteInfo,
74
+ telemetry,
75
+ userNodeVersion,
76
+ framework,
77
+ testOpts,
78
+ errorParams,
79
+ });
80
+ await reportError(error, statsdOpts, framework);
81
+ return { success, severityCode, logs };
82
+ }
83
+ }
84
+ // Logs and reports that a build successfully ended
85
+ const handleBuildSuccess = async function ({ framework, dry, logs, timers, durationNs, statsdOpts, systemLog, metrics, }) {
86
+ if (dry) {
87
+ return;
88
+ }
89
+ logBuildSuccess(logs);
90
+ logTimer(logs, durationNs, 'Netlify Build', systemLog);
91
+ await reportTimers(timers, statsdOpts, framework);
92
+ await reportMetrics(statsdOpts, metrics);
93
+ };
94
+ // Handles the calls and errors of telemetry reports
95
+ const telemetryReport = async function ({ deployId, buildId, status, stepsCount, pluginsOptions, durationNs, siteInfo, telemetry, userNodeVersion, framework, testOpts, errorParams, }) {
96
+ try {
97
+ await trackBuildComplete({
98
+ deployId,
99
+ buildId,
100
+ status,
101
+ stepsCount,
102
+ pluginsOptions,
103
+ durationNs,
104
+ siteInfo,
105
+ telemetry,
106
+ userNodeVersion,
107
+ framework,
108
+ testOpts,
109
+ });
110
+ }
111
+ catch (error) {
112
+ await handleBuildError(error, errorParams);
113
+ }
114
+ };
@@ -0,0 +1,17 @@
1
+ import { relative } from 'path';
2
+ import { pathExists } from 'path-exists';
3
+ import { logMissingSideFile } from '../log/messages/core.js';
4
+ // Some files like `_headers` and `_redirects` must be copied to the publishing
5
+ // directory to be used in production. When those are present in the repository
6
+ // but not in the publish directory, this most likely indicates that the build
7
+ // command accidentally forgot to copy those. We then print a warning message.
8
+ export const warnOnMissingSideFiles = async function ({ buildDir, netlifyConfig: { build: { publish }, }, logs, }) {
9
+ await Promise.all(SIDE_FILES.map((sideFile) => warnOnMissingSideFile({ logs, sideFile, buildDir, publish })));
10
+ };
11
+ const SIDE_FILES = ['_headers', '_redirects'];
12
+ const warnOnMissingSideFile = async function ({ logs, sideFile, buildDir, publish }) {
13
+ if (!(await pathExists(`${buildDir}/${sideFile}`)) || (await pathExists(`${publish}/${sideFile}`))) {
14
+ return;
15
+ }
16
+ logMissingSideFile(logs, sideFile, relative(buildDir, publish));
17
+ };
@@ -0,0 +1,62 @@
1
+ import { env, execPath } from 'process';
2
+ import { logFlags } from '../log/messages/config.js';
3
+ import { removeFalsy } from '../utils/remove_falsy.js';
4
+ import { DEFAULT_FEATURE_FLAGS } from './feature_flags.js';
5
+ const REQUIRE_MODE = 'require';
6
+ const DEFAULT_EDGE_FUNCTIONS_DIST = '.netlify/edge-functions-dist/';
7
+ const DEFAULT_FUNCTIONS_DIST = '.netlify/functions/';
8
+ const DEFAULT_CACHE_DIR = '.netlify/cache/';
9
+ const DEFAULT_STATSD_PORT = 8125;
10
+ /** Normalize CLI flags */
11
+ export const normalizeFlags = function (flags, logs) {
12
+ const rawFlags = removeFalsy(flags);
13
+ // Combine the flags object env with the process.env
14
+ const combinedEnv = { ...env, ...rawFlags.env };
15
+ const defaultFlags = getDefaultFlags(rawFlags, combinedEnv);
16
+ // The telemetry flag requires specific logic to compute
17
+ const telemetryFlag = computeTelemetry(rawFlags, combinedEnv);
18
+ const mergedFlags = {
19
+ ...defaultFlags,
20
+ ...rawFlags,
21
+ ...telemetryFlag,
22
+ statsdOpts: { ...defaultFlags.statsd, ...rawFlags.statsd },
23
+ featureFlags: { ...defaultFlags.featureFlags, ...rawFlags.featureFlags },
24
+ };
25
+ const normalizedFlags = removeFalsy(mergedFlags);
26
+ if (!flags.quiet) {
27
+ logFlags(logs, rawFlags, normalizedFlags);
28
+ }
29
+ return normalizedFlags;
30
+ };
31
+ // Default values of CLI flags
32
+ const getDefaultFlags = function ({ env: envOpt = {} }, combinedEnv) {
33
+ return {
34
+ env: envOpt,
35
+ nodePath: execPath,
36
+ token: combinedEnv.NETLIFY_AUTH_TOKEN,
37
+ mode: REQUIRE_MODE,
38
+ offline: false,
39
+ telemetry: false,
40
+ verbose: Boolean(combinedEnv.NETLIFY_BUILD_DEBUG),
41
+ functionsDistDir: DEFAULT_FUNCTIONS_DIST,
42
+ edgeFunctionsDistDir: DEFAULT_EDGE_FUNCTIONS_DIST,
43
+ cacheDir: DEFAULT_CACHE_DIR,
44
+ deployId: combinedEnv.DEPLOY_ID,
45
+ buildId: combinedEnv.BUILD_ID,
46
+ debug: Boolean(combinedEnv.NETLIFY_BUILD_DEBUG),
47
+ bugsnagKey: combinedEnv.BUGSNAG_KEY,
48
+ sendStatus: false,
49
+ saveConfig: false,
50
+ apiHost: 'api.netlify.com',
51
+ testOpts: {},
52
+ featureFlags: DEFAULT_FEATURE_FLAGS,
53
+ statsd: { port: DEFAULT_STATSD_PORT },
54
+ timeline: 'build',
55
+ quiet: false,
56
+ };
57
+ };
58
+ // Compute the telemetry flag, it's disabled by default, and we want to always disable it
59
+ // if BUILD_TELEMETRY_DISABLED is passed.
60
+ const computeTelemetry = function (flags, envOpts) {
61
+ return envOpts.BUILD_TELEMETRY_DISABLED ? { telemetry: false } : { telemetry: flags.telemetry };
62
+ };
@@ -0,0 +1,17 @@
1
+ import { closeClient, formatTags, startClient, validateStatsDOptions } from '../report/statsd.js';
2
+ /**
3
+ * Record number of functions build and differentiate between autogenerated and user generated.
4
+ * Sends to statsd daemon.
5
+ */
6
+ export const reportMetrics = async function (statsdOpts, metrics) {
7
+ if (!validateStatsDOptions(statsdOpts) || metrics.length === 0) {
8
+ return;
9
+ }
10
+ const client = await startClient(statsdOpts);
11
+ metrics.forEach((metric) => {
12
+ if (typeof client[metric.type] === 'function') {
13
+ client[metric.type](metric.name, metric.value, formatTags(metric.tags));
14
+ }
15
+ });
16
+ await closeClient(client);
17
+ };