@netlify/build 28.0.1-beta → 28.0.1

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 (259) hide show
  1. package/bin.js +5 -0
  2. package/lib/core/bin.js +66 -0
  3. package/lib/core/build.js +355 -0
  4. package/lib/core/config.js +121 -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 +19 -0
  9. package/lib/core/flags.js +201 -0
  10. package/lib/core/lingering.js +68 -0
  11. package/lib/core/main.js +105 -0
  12. package/lib/core/missing_side_file.js +17 -0
  13. package/lib/core/normalize_flags.js +59 -0
  14. package/lib/core/severity.js +21 -0
  15. package/lib/core/types.js +8 -0
  16. package/lib/core/user_node_version.js +32 -0
  17. package/lib/env/changes.js +43 -0
  18. package/lib/env/main.js +14 -0
  19. package/lib/env/metadata.js +68 -0
  20. package/lib/error/api.js +37 -0
  21. package/lib/error/build.js +36 -0
  22. package/{src → lib}/error/cancel.js +5 -6
  23. package/lib/error/colors.js +9 -0
  24. package/lib/error/handle.js +46 -0
  25. package/lib/error/info.js +37 -0
  26. package/lib/error/monitor/location.js +16 -0
  27. package/lib/error/monitor/normalize.js +86 -0
  28. package/lib/error/monitor/print.js +20 -0
  29. package/lib/error/monitor/report.js +120 -0
  30. package/lib/error/monitor/start.js +61 -0
  31. package/lib/error/parse/clean_stack.js +70 -0
  32. package/lib/error/parse/location.js +50 -0
  33. package/lib/error/parse/normalize.js +24 -0
  34. package/lib/error/parse/parse.js +67 -0
  35. package/lib/error/parse/plugin.js +55 -0
  36. package/lib/error/parse/properties.js +16 -0
  37. package/lib/error/parse/serialize_log.js +34 -0
  38. package/lib/error/parse/serialize_status.js +18 -0
  39. package/lib/error/parse/stack.js +34 -0
  40. package/lib/error/type.js +171 -0
  41. package/lib/install/functions.js +20 -0
  42. package/lib/install/local.js +45 -0
  43. package/lib/install/main.js +67 -0
  44. package/lib/install/missing.js +54 -0
  45. package/{src → lib}/log/colors.js +15 -22
  46. package/lib/log/description.js +21 -0
  47. package/lib/log/header.js +14 -0
  48. package/lib/log/header_func.js +13 -0
  49. package/lib/log/logger.js +140 -0
  50. package/lib/log/messages/compatibility.js +120 -0
  51. package/lib/log/messages/config.js +91 -0
  52. package/lib/log/messages/core.js +50 -0
  53. package/lib/log/messages/core_steps.js +75 -0
  54. package/lib/log/messages/dry.js +41 -0
  55. package/lib/log/messages/install.js +25 -0
  56. package/lib/log/messages/ipc.js +29 -0
  57. package/lib/log/messages/mutations.js +62 -0
  58. package/{src → lib}/log/messages/plugins.js +18 -32
  59. package/lib/log/messages/status.js +14 -0
  60. package/lib/log/messages/steps.js +18 -0
  61. package/lib/log/old_version.js +32 -0
  62. package/lib/log/serialize.js +10 -0
  63. package/lib/log/stream.js +68 -0
  64. package/lib/log/theme.js +25 -0
  65. package/lib/plugins/child/diff.js +46 -0
  66. package/lib/plugins/child/error.js +26 -0
  67. package/lib/plugins/child/lazy.js +15 -0
  68. package/lib/plugins/child/load.js +22 -0
  69. package/lib/plugins/child/logic.js +57 -0
  70. package/lib/plugins/child/main.js +37 -0
  71. package/lib/plugins/child/run.js +19 -0
  72. package/lib/plugins/child/status.js +63 -0
  73. package/lib/plugins/child/typescript.js +28 -0
  74. package/lib/plugins/child/utils.js +42 -0
  75. package/lib/plugins/child/validate.js +31 -0
  76. package/lib/plugins/compatibility.js +104 -0
  77. package/{src → lib}/plugins/error.js +31 -35
  78. package/{src → lib}/plugins/events.js +7 -12
  79. package/lib/plugins/expected_version.js +81 -0
  80. package/lib/plugins/ipc.js +120 -0
  81. package/lib/plugins/list.js +73 -0
  82. package/lib/plugins/load.js +50 -0
  83. package/lib/plugins/manifest/check.js +85 -0
  84. package/lib/plugins/manifest/load.js +38 -0
  85. package/lib/plugins/manifest/main.js +17 -0
  86. package/lib/plugins/manifest/path.js +24 -0
  87. package/lib/plugins/manifest/validate.js +91 -0
  88. package/lib/plugins/node_version.js +30 -0
  89. package/lib/plugins/options.js +55 -0
  90. package/lib/plugins/pinned_version.js +83 -0
  91. package/lib/plugins/resolve.js +110 -0
  92. package/lib/plugins/spawn.js +54 -0
  93. package/lib/plugins_core/add.js +35 -0
  94. package/lib/plugins_core/build_command.js +50 -0
  95. package/lib/plugins_core/deploy/buildbot_client.js +87 -0
  96. package/lib/plugins_core/deploy/index.js +49 -0
  97. package/{src → lib}/plugins_core/deploy/manifest.yml +0 -0
  98. package/lib/plugins_core/edge_functions/index.js +79 -0
  99. package/lib/plugins_core/edge_functions/lib/error.js +17 -0
  100. package/lib/plugins_core/edge_functions/lib/internal_manifest.js +50 -0
  101. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +75 -0
  102. package/lib/plugins_core/functions/error.js +123 -0
  103. package/lib/plugins_core/functions/feature_flags.js +6 -0
  104. package/lib/plugins_core/functions/index.js +114 -0
  105. package/lib/plugins_core/functions/utils.js +45 -0
  106. package/lib/plugins_core/functions/zisi.js +39 -0
  107. package/{src → lib}/plugins_core/functions_install/index.js +8 -11
  108. package/{src → lib}/plugins_core/functions_install/manifest.yml +0 -0
  109. package/lib/plugins_core/list.js +20 -0
  110. package/lib/status/add.js +30 -0
  111. package/lib/status/colors.js +18 -0
  112. package/lib/status/load_error.js +10 -0
  113. package/lib/status/report.js +83 -0
  114. package/lib/status/success.js +14 -0
  115. package/lib/steps/core_step.js +57 -0
  116. package/lib/steps/error.js +65 -0
  117. package/lib/steps/get.js +43 -0
  118. package/lib/steps/plugin.js +55 -0
  119. package/lib/steps/return.js +25 -0
  120. package/lib/steps/run_core_steps.js +126 -0
  121. package/lib/steps/run_step.js +188 -0
  122. package/lib/steps/run_steps.js +96 -0
  123. package/lib/steps/update_config.js +66 -0
  124. package/lib/telemetry/main.js +97 -0
  125. package/lib/time/aggregate.js +120 -0
  126. package/lib/time/main.js +37 -0
  127. package/lib/time/measure.js +18 -0
  128. package/lib/time/report.js +47 -0
  129. package/lib/utils/errors.js +13 -0
  130. package/lib/utils/json.js +15 -0
  131. package/{src → lib}/utils/omit.js +3 -4
  132. package/lib/utils/package.js +22 -0
  133. package/lib/utils/remove_falsy.js +8 -0
  134. package/lib/utils/resolve.js +41 -0
  135. package/lib/utils/runtime.js +5 -0
  136. package/lib/utils/semver.js +28 -0
  137. package/package.json +40 -20
  138. package/types/config/netlify_config.d.ts +4 -4
  139. package/types/netlify_plugin_constants.d.ts +8 -8
  140. package/src/core/bin.js +0 -83
  141. package/src/core/config.js +0 -186
  142. package/src/core/constants.js +0 -156
  143. package/src/core/dry.js +0 -39
  144. package/src/core/feature_flags.js +0 -21
  145. package/src/core/flags.js +0 -194
  146. package/src/core/lingering.js +0 -85
  147. package/src/core/main.js +0 -692
  148. package/src/core/missing_side_file.js +0 -29
  149. package/src/core/normalize_flags.js +0 -69
  150. package/src/core/severity.js +0 -22
  151. package/src/core/user_node_version.js +0 -41
  152. package/src/env/changes.js +0 -52
  153. package/src/env/main.js +0 -19
  154. package/src/env/metadata.js +0 -81
  155. package/src/error/api.js +0 -46
  156. package/src/error/build.js +0 -50
  157. package/src/error/colors.js +0 -11
  158. package/src/error/handle.js +0 -57
  159. package/src/error/info.js +0 -46
  160. package/src/error/monitor/location.js +0 -21
  161. package/src/error/monitor/normalize.js +0 -77
  162. package/src/error/monitor/print.js +0 -42
  163. package/src/error/monitor/report.js +0 -133
  164. package/src/error/monitor/start.js +0 -69
  165. package/src/error/parse/clean_stack.js +0 -87
  166. package/src/error/parse/location.js +0 -58
  167. package/src/error/parse/normalize.js +0 -29
  168. package/src/error/parse/parse.js +0 -97
  169. package/src/error/parse/plugin.js +0 -70
  170. package/src/error/parse/properties.js +0 -23
  171. package/src/error/parse/serialize_log.js +0 -42
  172. package/src/error/parse/serialize_status.js +0 -23
  173. package/src/error/parse/stack.js +0 -43
  174. package/src/error/type.js +0 -182
  175. package/src/install/functions.js +0 -28
  176. package/src/install/local.js +0 -62
  177. package/src/install/main.js +0 -81
  178. package/src/install/missing.js +0 -67
  179. package/src/log/description.js +0 -26
  180. package/src/log/header.js +0 -16
  181. package/src/log/header_func.js +0 -17
  182. package/src/log/logger.js +0 -107
  183. package/src/log/messages/compatibility.js +0 -164
  184. package/src/log/messages/config.js +0 -105
  185. package/src/log/messages/core.js +0 -70
  186. package/src/log/messages/core_steps.js +0 -104
  187. package/src/log/messages/dry.js +0 -63
  188. package/src/log/messages/install.js +0 -20
  189. package/src/log/messages/ipc.js +0 -38
  190. package/src/log/messages/mutations.js +0 -82
  191. package/src/log/messages/status.js +0 -16
  192. package/src/log/messages/steps.js +0 -22
  193. package/src/log/old_version.js +0 -41
  194. package/src/log/serialize.js +0 -13
  195. package/src/log/stream.js +0 -85
  196. package/src/log/theme.js +0 -26
  197. package/src/plugins/child/diff.js +0 -55
  198. package/src/plugins/child/error.js +0 -32
  199. package/src/plugins/child/lazy.js +0 -18
  200. package/src/plugins/child/load.js +0 -29
  201. package/src/plugins/child/logic.js +0 -57
  202. package/src/plugins/child/main.js +0 -51
  203. package/src/plugins/child/run.js +0 -28
  204. package/src/plugins/child/status.js +0 -67
  205. package/src/plugins/child/typescript.js +0 -45
  206. package/src/plugins/child/utils.js +0 -56
  207. package/src/plugins/child/validate.js +0 -34
  208. package/src/plugins/compatibility.js +0 -128
  209. package/src/plugins/expected_version.js +0 -119
  210. package/src/plugins/ipc.js +0 -145
  211. package/src/plugins/list.js +0 -86
  212. package/src/plugins/load.js +0 -70
  213. package/src/plugins/manifest/check.js +0 -106
  214. package/src/plugins/manifest/load.js +0 -41
  215. package/src/plugins/manifest/main.js +0 -22
  216. package/src/plugins/manifest/path.js +0 -31
  217. package/src/plugins/manifest/validate.js +0 -108
  218. package/src/plugins/node_version.js +0 -50
  219. package/src/plugins/options.js +0 -88
  220. package/src/plugins/pinned_version.js +0 -131
  221. package/src/plugins/resolve.js +0 -152
  222. package/src/plugins/spawn.js +0 -66
  223. package/src/plugins_core/add.js +0 -49
  224. package/src/plugins_core/build_command.js +0 -75
  225. package/src/plugins_core/deploy/buildbot_client.js +0 -102
  226. package/src/plugins_core/deploy/index.js +0 -73
  227. package/src/plugins_core/edge_functions/index.js +0 -107
  228. package/src/plugins_core/edge_functions/lib/internal_manifest.js +0 -54
  229. package/src/plugins_core/functions/error.js +0 -163
  230. package/src/plugins_core/functions/feature_flags.js +0 -6
  231. package/src/plugins_core/functions/index.js +0 -160
  232. package/src/plugins_core/functions/utils.js +0 -66
  233. package/src/plugins_core/functions/zisi.js +0 -53
  234. package/src/plugins_core/list.js +0 -27
  235. package/src/status/add.js +0 -36
  236. package/src/status/colors.js +0 -23
  237. package/src/status/load_error.js +0 -11
  238. package/src/status/report.js +0 -128
  239. package/src/status/success.js +0 -18
  240. package/src/steps/core_step.js +0 -90
  241. package/src/steps/error.js +0 -102
  242. package/src/steps/get.js +0 -32
  243. package/src/steps/plugin.js +0 -85
  244. package/src/steps/return.js +0 -52
  245. package/src/steps/run_core_steps.js +0 -194
  246. package/src/steps/run_step.js +0 -300
  247. package/src/steps/run_steps.js +0 -179
  248. package/src/steps/update_config.js +0 -93
  249. package/src/telemetry/main.js +0 -136
  250. package/src/time/aggregate.js +0 -146
  251. package/src/time/main.js +0 -48
  252. package/src/time/measure.js +0 -22
  253. package/src/time/report.js +0 -59
  254. package/src/utils/errors.js +0 -12
  255. package/src/utils/json.js +0 -19
  256. package/src/utils/package.js +0 -23
  257. package/src/utils/remove_falsy.js +0 -10
  258. package/src/utils/resolve.js +0 -46
  259. package/src/utils/semver.js +0 -34
@@ -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,19 @@
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_es_modules_esbuild: false,
14
+ buildbot_zisi_trace_nft: false,
15
+ buildbot_zisi_esbuild_parser: false,
16
+ edge_functions_cache_cli: false,
17
+ edge_functions_produce_eszip: false,
18
+ edge_functions_system_logger: false,
19
+ };
@@ -0,0 +1,201 @@
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 overriden 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
+ testOpts: {
166
+ describe: 'Options for testing only',
167
+ hidden: true,
168
+ },
169
+ featureFlags: {
170
+ describe: 'Comma-separated list of feature flags to enable unreleased features',
171
+ hidden: true,
172
+ },
173
+ statsd: {
174
+ describe: 'Statsd-related options, for performance measuring',
175
+ hidden: true,
176
+ },
177
+ 'statsd.host': {
178
+ type: 'string',
179
+ describe: 'Statsd host',
180
+ hidden: true,
181
+ },
182
+ 'statsd.port': {
183
+ type: 'number',
184
+ describe: 'Statsd port',
185
+ hidden: true,
186
+ },
187
+ offline: {
188
+ boolean: true,
189
+ describe: `Do not send requests to the Netlify API to retrieve site settings.
190
+ Default: false`,
191
+ },
192
+ buffer: {
193
+ boolean: true,
194
+ describe: 'Buffer output instead of printing it',
195
+ },
196
+ timeline: {
197
+ string: true,
198
+ describe: 'The sequence of lifecycle events to run',
199
+ hidden: true,
200
+ },
201
+ };
@@ -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
+ // of 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,105 @@
1
+ import { handleBuildError } from '../error/handle.js';
2
+ import { logTimer, logBuildSuccess } from '../log/messages/core.js';
3
+ import { trackBuildComplete } from '../telemetry/main.js';
4
+ import { reportTimers } from '../time/report.js';
5
+ import { execBuild, startBuild } from './build.js';
6
+ import { getSeverity } from './severity.js';
7
+ export { startDev } from './dev.js';
8
+ export { runCoreSteps } from '../steps/run_core_steps.js';
9
+ /**
10
+ * Main entry point of Netlify Build.
11
+ * Runs a builds and returns whether it succeeded or not.
12
+ *
13
+ * @param flags - build configuration CLI flags
14
+ */
15
+ export default async function buildSite(flags = {}) {
16
+ const { errorMonitor, framework, mode, logs, debug, systemLogFile, testOpts, statsdOpts, dry, telemetry, buildId, deployId, ...flagsA } = startBuild(flags);
17
+ const errorParams = { errorMonitor, mode, logs, debug, testOpts };
18
+ try {
19
+ const { pluginsOptions, netlifyConfig: netlifyConfigA, siteInfo, userNodeVersion, stepsCount, timers, durationNs, configMutations, } = await execBuild({
20
+ ...flagsA,
21
+ buildId,
22
+ systemLogFile,
23
+ deployId,
24
+ dry,
25
+ errorMonitor,
26
+ mode,
27
+ logs,
28
+ debug,
29
+ testOpts,
30
+ errorParams,
31
+ });
32
+ await handleBuildSuccess({
33
+ framework,
34
+ dry,
35
+ logs,
36
+ timers,
37
+ durationNs,
38
+ statsdOpts,
39
+ });
40
+ const { success, severityCode, status } = getSeverity('success');
41
+ await telemetryReport({
42
+ buildId,
43
+ deployId,
44
+ status,
45
+ stepsCount,
46
+ pluginsOptions,
47
+ durationNs,
48
+ siteInfo,
49
+ telemetry,
50
+ userNodeVersion,
51
+ framework,
52
+ testOpts,
53
+ errorParams,
54
+ });
55
+ return { success, severityCode, netlifyConfig: netlifyConfigA, logs, configMutations };
56
+ }
57
+ catch (error) {
58
+ const { severity } = await handleBuildError(error, errorParams);
59
+ const { pluginsOptions, siteInfo, userNodeVersion } = errorParams;
60
+ const { success, severityCode, status } = getSeverity(severity);
61
+ await telemetryReport({
62
+ buildId,
63
+ deployId,
64
+ status,
65
+ pluginsOptions,
66
+ siteInfo,
67
+ telemetry,
68
+ userNodeVersion,
69
+ framework,
70
+ testOpts,
71
+ errorParams,
72
+ });
73
+ return { success, severityCode, logs };
74
+ }
75
+ }
76
+ // Logs and reports that a build successfully ended
77
+ const handleBuildSuccess = async function ({ framework, dry, logs, timers, durationNs, statsdOpts }) {
78
+ if (dry) {
79
+ return;
80
+ }
81
+ logBuildSuccess(logs);
82
+ logTimer(logs, durationNs, 'Netlify Build');
83
+ await reportTimers({ timers, statsdOpts, framework });
84
+ };
85
+ // Handles the calls and errors of telemetry reports
86
+ const telemetryReport = async function ({ deployId, buildId, status, stepsCount, pluginsOptions, durationNs, siteInfo, telemetry, userNodeVersion, framework, testOpts, errorParams, }) {
87
+ try {
88
+ await trackBuildComplete({
89
+ deployId,
90
+ buildId,
91
+ status,
92
+ stepsCount,
93
+ pluginsOptions,
94
+ durationNs,
95
+ siteInfo,
96
+ telemetry,
97
+ userNodeVersion,
98
+ framework,
99
+ testOpts,
100
+ });
101
+ }
102
+ catch (error) {
103
+ await handleBuildError(error, errorParams);
104
+ }
105
+ };
@@ -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 publish
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,59 @@
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
+ // Normalize CLI flags
6
+ export const normalizeFlags = function (flags, logs) {
7
+ const rawFlags = removeFalsy(flags);
8
+ // Combine the flags object env with the process.env
9
+ const combinedEnv = { ...env, ...rawFlags.env };
10
+ const defaultFlags = getDefaultFlags(rawFlags, combinedEnv);
11
+ // The telemetry flag requires specific logic to compute
12
+ const telemetryFlag = computeTelemetry(rawFlags, combinedEnv);
13
+ const mergedFlags = {
14
+ ...defaultFlags,
15
+ ...rawFlags,
16
+ ...telemetryFlag,
17
+ statsdOpts: { ...defaultFlags.statsd, ...rawFlags.statsd },
18
+ featureFlags: { ...defaultFlags.featureFlags, ...rawFlags.featureFlags },
19
+ };
20
+ const normalizedFlags = removeFalsy(mergedFlags);
21
+ logFlags(logs, rawFlags, normalizedFlags);
22
+ return normalizedFlags;
23
+ };
24
+ // Default values of CLI flags
25
+ const getDefaultFlags = function ({ env: envOpt = {} }, combinedEnv) {
26
+ return {
27
+ env: envOpt,
28
+ nodePath: execPath,
29
+ token: combinedEnv.NETLIFY_AUTH_TOKEN,
30
+ mode: REQUIRE_MODE,
31
+ offline: false,
32
+ telemetry: false,
33
+ verbose: Boolean(combinedEnv.NETLIFY_BUILD_DEBUG),
34
+ functionsDistDir: DEFAULT_FUNCTIONS_DIST,
35
+ edgeFunctionsDistDir: DEFAULT_EDGE_FUNCTIONS_DIST,
36
+ cacheDir: DEFAULT_CACHE_DIR,
37
+ deployId: combinedEnv.DEPLOY_ID,
38
+ buildId: combinedEnv.BUILD_ID,
39
+ debug: Boolean(combinedEnv.NETLIFY_BUILD_DEBUG),
40
+ bugsnagKey: combinedEnv.BUGSNAG_KEY,
41
+ sendStatus: false,
42
+ saveConfig: false,
43
+ apiHost: 'api.netlify.com',
44
+ testOpts: {},
45
+ featureFlags: DEFAULT_FEATURE_FLAGS,
46
+ statsd: { port: DEFAULT_STATSD_PORT },
47
+ timeline: 'build',
48
+ };
49
+ };
50
+ // Compute the telemetry flag, it's disabled by default and we want to always disable it
51
+ // if BUILD_TELEMETRY_DISABLED is passed.
52
+ const computeTelemetry = function (flags, envOpts) {
53
+ return envOpts.BUILD_TELEMETRY_DISABLED ? { telemetry: false } : { telemetry: flags.telemetry };
54
+ };
55
+ const REQUIRE_MODE = 'require';
56
+ const DEFAULT_EDGE_FUNCTIONS_DIST = '.netlify/edge-functions-dist/';
57
+ const DEFAULT_FUNCTIONS_DIST = '.netlify/functions/';
58
+ const DEFAULT_CACHE_DIR = '.netlify/cache/';
59
+ const DEFAULT_STATSD_PORT = 8125;
@@ -0,0 +1,21 @@
1
+ const SEVERITY_MAP = {
2
+ success: { severityCode: 0, status: 'success' },
3
+ none: { severityCode: 1, status: 'cancelled' },
4
+ info: { severityCode: 2, status: 'user-error' },
5
+ warning: { severityCode: 3, status: 'plugin-error' },
6
+ error: { severityCode: 4, status: 'system-error' },
7
+ };
8
+ const SUCCESS_SEVERITY = 'success';
9
+ /** Indicates a bug in our codebase */
10
+ const FALLBACK_SEVERITY = 'error';
11
+ /** Map error severities to exit codes and status (used for telemetry purposes) */
12
+ export const FALLBACK_SEVERITY_ENTRY = SEVERITY_MAP[FALLBACK_SEVERITY];
13
+ /**
14
+ * Used to extract exit codes and respective status strings
15
+ * 1|2|3 indicate whether this was a user|plugin|system error.
16
+ */
17
+ export const getSeverity = (severity = FALLBACK_SEVERITY) => {
18
+ const severityEntry = severity in SEVERITY_MAP ? SEVERITY_MAP[severity] : FALLBACK_SEVERITY_ENTRY;
19
+ const success = severity === SUCCESS_SEVERITY;
20
+ return { success, ...severityEntry };
21
+ };
@@ -0,0 +1,8 @@
1
+ export var SeverityCode;
2
+ (function (SeverityCode) {
3
+ SeverityCode[SeverityCode["success"] = 1] = "success";
4
+ SeverityCode[SeverityCode["buildCancelled"] = 2] = "buildCancelled";
5
+ SeverityCode[SeverityCode["userError"] = 3] = "userError";
6
+ SeverityCode[SeverityCode["pluginError"] = 4] = "pluginError";
7
+ SeverityCode[SeverityCode["systemError"] = 5] = "systemError";
8
+ })(SeverityCode = SeverityCode || (SeverityCode = {}));
@@ -0,0 +1,32 @@
1
+ import { version as currentVersion, execPath } from 'process';
2
+ import { execa } from 'execa';
3
+ import semver from 'semver';
4
+ import { addErrorInfo } from '../error/info.js';
5
+ // Retrieve Node.js version if the Node.js path is using nvm.
6
+ // `node.exe` on Windows, `bin/node` on Unix.
7
+ const NVM_NODE_VERSION_REGEXP = /[/\\]v(\d+\.\d+\.\d+)[/\\](bin[/\\]node|node.exe)$/;
8
+ // Retrieve Node.js version from current process
9
+ const getCurrentNodeVersion = function () {
10
+ return semver.clean(currentVersion);
11
+ };
12
+ // Retrieve Node.js version from `--node-path` or fallback to extracting the current Node.js process version
13
+ export const getUserNodeVersion = async function (nodePath) {
14
+ // No `--node-path` CLI flag, use the current node process version
15
+ if (nodePath === execPath) {
16
+ return getCurrentNodeVersion();
17
+ }
18
+ // Extract version from path
19
+ const result = NVM_NODE_VERSION_REGEXP.exec(nodePath);
20
+ if (result !== null) {
21
+ return result[1];
22
+ }
23
+ // Fallback to actually running `node --version` with the given nodePath
24
+ const { stdout } = await execa(nodePath, ['--version'], { reject: false });
25
+ const version = semver.clean(stdout);
26
+ if (version === null) {
27
+ const error = new Error(`Invalid --node-path CLI flag: ${nodePath}`);
28
+ addErrorInfo(error, { type: 'resolveConfig' });
29
+ throw error;
30
+ }
31
+ return version;
32
+ };
@@ -0,0 +1,43 @@
1
+ import { env } from 'process';
2
+ import filterObj from 'filter-obj';
3
+ import mapObj from 'map-obj';
4
+ // If plugins modify `process.env`, this is propagated in other plugins and in
5
+ // `build.command`. Since those are different processes, we figure out when they
6
+ // do this and communicate the new `process.env` to other processes.
7
+ export const getNewEnvChanges = function (envBefore, netlifyConfig, netlifyConfigCopy) {
8
+ const processEnvChanges = diffEnv(envBefore, env);
9
+ const netlifyConfigEnvChanges = diffEnv(netlifyConfig.build.environment, netlifyConfigCopy.build.environment);
10
+ return { ...processEnvChanges, ...netlifyConfigEnvChanges };
11
+ };
12
+ const diffEnv = function (envBefore, envAfter) {
13
+ const envChanges = filterObj(envAfter, (name, value) => value !== envBefore[name]);
14
+ const deletedEnv = filterObj(envBefore, (name) => envAfter[name] === undefined);
15
+ const deletedEnvA = mapObj(deletedEnv, setToNull);
16
+ return { ...envChanges, ...deletedEnvA };
17
+ };
18
+ // `undefined` is not JSON-serializable (which is used in process IPC), so we
19
+ // convert it to `null`
20
+ // Note: `process.env[name] = undefined` actually does
21
+ // `process.env[name] = 'undefined'` in Node.js.
22
+ const setToNull = function (name) {
23
+ return [name, null];
24
+ };
25
+ // Set `process.env` changes from a previous different plugin.
26
+ // Can also merge with a `currentEnv` plain object instead of `process.env`.
27
+ export const setEnvChanges = function (envChanges, currentEnv = env) {
28
+ Object.entries(envChanges).forEach(([name, value]) => {
29
+ setEnvChange(name, value, currentEnv);
30
+ });
31
+ return { ...currentEnv };
32
+ };
33
+ const setEnvChange = function (name, value, currentEnv) {
34
+ if (currentEnv[name] === value) {
35
+ return;
36
+ }
37
+ if (value === null) {
38
+ // `currentEnv` is a mutable variable
39
+ delete currentEnv[name];
40
+ return;
41
+ }
42
+ currentEnv[name] = value;
43
+ };
@@ -0,0 +1,14 @@
1
+ import { env } from 'process';
2
+ import filterObj from 'filter-obj';
3
+ import { getParentColorEnv } from '../log/colors.js';
4
+ // Retrieve the environment variables passed to plugins and `build.command`
5
+ // When run locally, this tries to emulate the production environment.
6
+ export const getChildEnv = function ({ envOpt, env: allConfigEnv }) {
7
+ const parentColorEnv = getParentColorEnv();
8
+ const parentEnv = { ...env, ...allConfigEnv, ...envOpt, ...parentColorEnv };
9
+ return filterObj(parentEnv, shouldKeepEnv);
10
+ };
11
+ const shouldKeepEnv = function (key) {
12
+ return !REMOVED_PARENT_ENV.has(key.toLowerCase());
13
+ };
14
+ const REMOVED_PARENT_ENV = new Set(['bugsnag_key']);