@netlify/build 28.0.0-rc → 28.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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 +123 -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 +20 -0
  15. package/lib/core/user_node_version.js +32 -0
  16. package/lib/env/changes.js +43 -0
  17. package/lib/env/main.js +14 -0
  18. package/lib/env/metadata.js +68 -0
  19. package/lib/error/api.js +37 -0
  20. package/lib/error/build.js +36 -0
  21. package/{src → lib}/error/cancel.js +5 -6
  22. package/lib/error/colors.js +9 -0
  23. package/lib/error/handle.js +46 -0
  24. package/lib/error/info.js +37 -0
  25. package/lib/error/monitor/location.js +16 -0
  26. package/lib/error/monitor/normalize.js +86 -0
  27. package/lib/error/monitor/print.js +20 -0
  28. package/lib/error/monitor/report.js +120 -0
  29. package/lib/error/monitor/start.js +58 -0
  30. package/lib/error/parse/clean_stack.js +70 -0
  31. package/lib/error/parse/location.js +50 -0
  32. package/lib/error/parse/normalize.js +24 -0
  33. package/lib/error/parse/parse.js +67 -0
  34. package/lib/error/parse/plugin.js +55 -0
  35. package/lib/error/parse/properties.js +16 -0
  36. package/lib/error/parse/serialize_log.js +34 -0
  37. package/lib/error/parse/serialize_status.js +18 -0
  38. package/lib/error/parse/stack.js +34 -0
  39. package/lib/error/type.js +171 -0
  40. package/lib/install/functions.js +20 -0
  41. package/lib/install/local.js +45 -0
  42. package/lib/install/main.js +67 -0
  43. package/lib/install/missing.js +54 -0
  44. package/{src → lib}/log/colors.js +15 -22
  45. package/lib/log/description.js +21 -0
  46. package/lib/log/header.js +14 -0
  47. package/lib/log/header_func.js +13 -0
  48. package/lib/log/logger.js +130 -0
  49. package/lib/log/messages/compatibility.js +120 -0
  50. package/lib/log/messages/config.js +91 -0
  51. package/lib/log/messages/core.js +50 -0
  52. package/lib/log/messages/core_steps.js +75 -0
  53. package/lib/log/messages/dry.js +41 -0
  54. package/lib/log/messages/install.js +25 -0
  55. package/lib/log/messages/ipc.js +29 -0
  56. package/lib/log/messages/mutations.js +62 -0
  57. package/{src → lib}/log/messages/plugins.js +18 -32
  58. package/lib/log/messages/status.js +14 -0
  59. package/lib/log/messages/steps.js +18 -0
  60. package/lib/log/old_version.js +32 -0
  61. package/lib/log/serialize.js +10 -0
  62. package/lib/log/stream.js +68 -0
  63. package/lib/log/theme.js +25 -0
  64. package/lib/plugins/child/diff.js +46 -0
  65. package/lib/plugins/child/error.js +26 -0
  66. package/lib/plugins/child/lazy.js +15 -0
  67. package/lib/plugins/child/load.js +22 -0
  68. package/lib/plugins/child/logic.js +57 -0
  69. package/lib/plugins/child/main.js +37 -0
  70. package/lib/plugins/child/run.js +19 -0
  71. package/lib/plugins/child/status.js +63 -0
  72. package/lib/plugins/child/typescript.js +28 -0
  73. package/lib/plugins/child/utils.js +42 -0
  74. package/lib/plugins/child/validate.js +31 -0
  75. package/lib/plugins/compatibility.js +104 -0
  76. package/{src → lib}/plugins/error.js +31 -35
  77. package/{src → lib}/plugins/events.js +7 -12
  78. package/lib/plugins/expected_version.js +81 -0
  79. package/lib/plugins/ipc.js +120 -0
  80. package/lib/plugins/list.js +73 -0
  81. package/lib/plugins/load.js +50 -0
  82. package/lib/plugins/manifest/check.js +85 -0
  83. package/lib/plugins/manifest/load.js +38 -0
  84. package/lib/plugins/manifest/main.js +17 -0
  85. package/lib/plugins/manifest/path.js +24 -0
  86. package/lib/plugins/manifest/validate.js +91 -0
  87. package/lib/plugins/node_version.js +30 -0
  88. package/lib/plugins/options.js +55 -0
  89. package/lib/plugins/pinned_version.js +83 -0
  90. package/lib/plugins/resolve.js +110 -0
  91. package/lib/plugins/spawn.js +54 -0
  92. package/lib/plugins_core/add.js +35 -0
  93. package/lib/plugins_core/build_command.js +50 -0
  94. package/lib/plugins_core/deploy/buildbot_client.js +87 -0
  95. package/lib/plugins_core/deploy/index.js +49 -0
  96. package/{src → lib}/plugins_core/deploy/manifest.yml +0 -0
  97. package/lib/plugins_core/edge_functions/index.js +79 -0
  98. package/{src → lib}/plugins_core/edge_functions/lib/error.js +13 -17
  99. package/lib/plugins_core/edge_functions/lib/internal_manifest.js +50 -0
  100. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +75 -0
  101. package/lib/plugins_core/functions/error.js +123 -0
  102. package/lib/plugins_core/functions/feature_flags.js +6 -0
  103. package/lib/plugins_core/functions/index.js +114 -0
  104. package/lib/plugins_core/functions/utils.js +45 -0
  105. package/lib/plugins_core/functions/zisi.js +39 -0
  106. package/{src → lib}/plugins_core/functions_install/index.js +8 -11
  107. package/{src → lib}/plugins_core/functions_install/manifest.yml +0 -0
  108. package/lib/plugins_core/list.js +20 -0
  109. package/lib/status/add.js +30 -0
  110. package/lib/status/colors.js +18 -0
  111. package/lib/status/load_error.js +10 -0
  112. package/lib/status/report.js +83 -0
  113. package/lib/status/success.js +14 -0
  114. package/lib/steps/core_step.js +57 -0
  115. package/lib/steps/error.js +65 -0
  116. package/lib/steps/get.js +43 -0
  117. package/lib/steps/plugin.js +55 -0
  118. package/lib/steps/return.js +25 -0
  119. package/lib/steps/run_core_steps.js +147 -0
  120. package/lib/steps/run_step.js +188 -0
  121. package/lib/steps/run_steps.js +96 -0
  122. package/lib/steps/update_config.js +66 -0
  123. package/lib/telemetry/main.js +97 -0
  124. package/lib/time/aggregate.js +120 -0
  125. package/lib/time/main.js +37 -0
  126. package/lib/time/measure.js +18 -0
  127. package/lib/time/report.js +47 -0
  128. package/lib/utils/errors.js +13 -0
  129. package/lib/utils/json.js +15 -0
  130. package/{src → lib}/utils/omit.js +3 -4
  131. package/lib/utils/package.js +22 -0
  132. package/lib/utils/remove_falsy.js +8 -0
  133. package/lib/utils/resolve.js +41 -0
  134. package/lib/utils/runtime.js +5 -0
  135. package/lib/utils/semver.js +28 -0
  136. package/package.json +37 -20
  137. package/types/config/netlify_config.d.ts +4 -4
  138. package/types/netlify_plugin_constants.d.ts +8 -8
  139. package/src/core/bin.js +0 -83
  140. package/src/core/config.js +0 -186
  141. package/src/core/constants.js +0 -156
  142. package/src/core/dry.js +0 -39
  143. package/src/core/feature_flags.js +0 -21
  144. package/src/core/flags.js +0 -199
  145. package/src/core/lingering.js +0 -85
  146. package/src/core/main.js +0 -703
  147. package/src/core/missing_side_file.js +0 -29
  148. package/src/core/normalize_flags.js +0 -69
  149. package/src/core/severity.js +0 -22
  150. package/src/core/user_node_version.js +0 -41
  151. package/src/env/changes.js +0 -52
  152. package/src/env/main.js +0 -19
  153. package/src/env/metadata.js +0 -81
  154. package/src/error/api.js +0 -46
  155. package/src/error/build.js +0 -50
  156. package/src/error/colors.js +0 -11
  157. package/src/error/handle.js +0 -57
  158. package/src/error/info.js +0 -46
  159. package/src/error/monitor/location.js +0 -21
  160. package/src/error/monitor/normalize.js +0 -96
  161. package/src/error/monitor/print.js +0 -42
  162. package/src/error/monitor/report.js +0 -138
  163. package/src/error/monitor/start.js +0 -69
  164. package/src/error/parse/clean_stack.js +0 -87
  165. package/src/error/parse/location.js +0 -62
  166. package/src/error/parse/normalize.js +0 -29
  167. package/src/error/parse/parse.js +0 -97
  168. package/src/error/parse/plugin.js +0 -70
  169. package/src/error/parse/properties.js +0 -23
  170. package/src/error/parse/serialize_log.js +0 -42
  171. package/src/error/parse/serialize_status.js +0 -23
  172. package/src/error/parse/stack.js +0 -43
  173. package/src/error/type.js +0 -189
  174. package/src/install/functions.js +0 -28
  175. package/src/install/local.js +0 -62
  176. package/src/install/main.js +0 -81
  177. package/src/install/missing.js +0 -67
  178. package/src/log/description.js +0 -26
  179. package/src/log/header.js +0 -16
  180. package/src/log/header_func.js +0 -17
  181. package/src/log/logger.js +0 -142
  182. package/src/log/messages/compatibility.js +0 -164
  183. package/src/log/messages/config.js +0 -105
  184. package/src/log/messages/core.js +0 -70
  185. package/src/log/messages/core_steps.js +0 -104
  186. package/src/log/messages/dry.js +0 -63
  187. package/src/log/messages/install.js +0 -20
  188. package/src/log/messages/ipc.js +0 -38
  189. package/src/log/messages/mutations.js +0 -82
  190. package/src/log/messages/status.js +0 -16
  191. package/src/log/messages/steps.js +0 -22
  192. package/src/log/old_version.js +0 -41
  193. package/src/log/serialize.js +0 -13
  194. package/src/log/stream.js +0 -85
  195. package/src/log/theme.js +0 -26
  196. package/src/plugins/child/diff.js +0 -55
  197. package/src/plugins/child/error.js +0 -32
  198. package/src/plugins/child/lazy.js +0 -18
  199. package/src/plugins/child/load.js +0 -29
  200. package/src/plugins/child/logic.js +0 -57
  201. package/src/plugins/child/main.js +0 -51
  202. package/src/plugins/child/run.js +0 -28
  203. package/src/plugins/child/status.js +0 -74
  204. package/src/plugins/child/typescript.js +0 -45
  205. package/src/plugins/child/utils.js +0 -56
  206. package/src/plugins/child/validate.js +0 -34
  207. package/src/plugins/compatibility.js +0 -128
  208. package/src/plugins/expected_version.js +0 -119
  209. package/src/plugins/ipc.js +0 -145
  210. package/src/plugins/list.js +0 -86
  211. package/src/plugins/load.js +0 -70
  212. package/src/plugins/manifest/check.js +0 -106
  213. package/src/plugins/manifest/load.js +0 -41
  214. package/src/plugins/manifest/main.js +0 -22
  215. package/src/plugins/manifest/path.js +0 -31
  216. package/src/plugins/manifest/validate.js +0 -108
  217. package/src/plugins/node_version.js +0 -50
  218. package/src/plugins/options.js +0 -88
  219. package/src/plugins/pinned_version.js +0 -131
  220. package/src/plugins/resolve.js +0 -152
  221. package/src/plugins/spawn.js +0 -66
  222. package/src/plugins_core/add.js +0 -49
  223. package/src/plugins_core/build_command.js +0 -75
  224. package/src/plugins_core/deploy/buildbot_client.js +0 -102
  225. package/src/plugins_core/deploy/index.js +0 -73
  226. package/src/plugins_core/edge_functions/index.js +0 -122
  227. package/src/plugins_core/edge_functions/lib/internal_manifest.js +0 -54
  228. package/src/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +0 -89
  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 -137
  239. package/src/status/success.js +0 -18
  240. package/src/steps/core_step.js +0 -92
  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 -306
  247. package/src/steps/run_steps.js +0 -181
  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
+ export const getBuildCommandDescription = function (buildCommandOrigin) {
2
+ return BUILD_COMMAND_DESCRIPTIONS[buildCommandOrigin];
3
+ };
4
+ const BUILD_COMMAND_DESCRIPTIONS = {
5
+ ui: 'Build command from Netlify app',
6
+ config: 'build.command from netlify.toml',
7
+ inline: 'build.command from a plugin',
8
+ };
9
+ // Retrieve human-friendly plugin origin
10
+ export const getPluginOrigin = function (loadedFrom, origin) {
11
+ const originName = PLUGIN_ORIGINS[origin];
12
+ if (loadedFrom === 'package.json') {
13
+ return `from ${originName} and package.json`;
14
+ }
15
+ return `from ${originName}`;
16
+ };
17
+ const PLUGIN_ORIGINS = {
18
+ core: 'core',
19
+ ui: 'Netlify app',
20
+ config: 'netlify.toml',
21
+ };
@@ -0,0 +1,14 @@
1
+ import stringWidth from 'string-width';
2
+ // Print a rectangular header
3
+ export const getHeader = function (message) {
4
+ const messageWidth = stringWidth(message);
5
+ const headerWidth = Math.max(HEADER_MIN_WIDTH, messageWidth);
6
+ const line = '─'.repeat(headerWidth + PADDING_WIDTH * 2);
7
+ const paddingLeft = ' '.repeat(PADDING_WIDTH);
8
+ const paddingRight = ' '.repeat(PADDING_WIDTH + headerWidth - messageWidth);
9
+ return `${line}
10
+ ${paddingLeft}${message}${paddingRight}
11
+ ${line}`;
12
+ };
13
+ const HEADER_MIN_WIDTH = 60;
14
+ const PADDING_WIDTH = 2;
@@ -0,0 +1,13 @@
1
+ import { parseErrorInfo } from '../error/parse/parse.js';
2
+ import { logHeader, logErrorHeader } from './logger.js';
3
+ // Retrieve successful or error header depending on whether `error` exists
4
+ export const getLogHeaderFunc = function (error) {
5
+ if (error === undefined) {
6
+ return logHeader;
7
+ }
8
+ const { severity } = parseErrorInfo(error);
9
+ if (severity === 'none') {
10
+ return logHeader;
11
+ }
12
+ return logErrorHeader;
13
+ };
@@ -0,0 +1,130 @@
1
+ import { createWriteStream } from 'fs';
2
+ import figures from 'figures';
3
+ import indentString from 'indent-string';
4
+ import { getHeader } from './header.js';
5
+ import { serializeObject, serializeArray } from './serialize.js';
6
+ import { THEME } from './theme.js';
7
+ // When the `buffer` option is true, we return logs instead of printing them
8
+ // on the console. The logs are accumulated in a `logs` array variable.
9
+ export const getBufferLogs = function ({ buffer = false }) {
10
+ if (!buffer) {
11
+ return;
12
+ }
13
+ return { stdout: [], stderr: [] };
14
+ };
15
+ // Core logging utility, used by the other methods.
16
+ // This should be used instead of `console.log()` as it allows us to instrument
17
+ // how any build logs is being printed.
18
+ export const log = function (logs, string, { indent = false, color } = {}) {
19
+ const stringA = indent ? indentString(string, INDENT_SIZE) : string;
20
+ const stringB = String(stringA).replace(EMPTY_LINES_REGEXP, EMPTY_LINE);
21
+ const stringC = color === undefined ? stringB : color(stringB);
22
+ if (logs !== undefined) {
23
+ // `logs` is a stateful variable
24
+ logs.stdout.push(stringC);
25
+ return;
26
+ }
27
+ console.log(stringC);
28
+ };
29
+ const INDENT_SIZE = 2;
30
+ // We need to add a zero width space character in empty lines. Otherwise the
31
+ // buildbot removes those due to a bug: https://github.com/netlify/buildbot/issues/595
32
+ const EMPTY_LINES_REGEXP = /^\s*$/gm;
33
+ const EMPTY_LINE = '\u{200B}';
34
+ const serializeIndentedArray = function (array) {
35
+ return serializeArray(array.map(serializeIndentedItem));
36
+ };
37
+ const serializeIndentedItem = function (item) {
38
+ return indentString(item, INDENT_SIZE + 1).trimStart();
39
+ };
40
+ export const logError = function (logs, string, opts) {
41
+ log(logs, string, { color: THEME.errorLine, ...opts });
42
+ };
43
+ export const logWarning = function (logs, string, opts) {
44
+ log(logs, string, { color: THEME.warningLine, ...opts });
45
+ };
46
+ // Print a message that is under a header/subheader, i.e. indented
47
+ export const logMessage = function (logs, string, opts) {
48
+ log(logs, string, { indent: true, ...opts });
49
+ };
50
+ // Print an object
51
+ export const logObject = function (logs, object, opts) {
52
+ logMessage(logs, serializeObject(object), opts);
53
+ };
54
+ // Print an array
55
+ export const logArray = function (logs, array, opts) {
56
+ logMessage(logs, serializeIndentedArray(array), { color: THEME.none, ...opts });
57
+ };
58
+ // Print an array of errors
59
+ export const logErrorArray = function (logs, array, opts) {
60
+ logMessage(logs, serializeIndentedArray(array), { color: THEME.errorLine, ...opts });
61
+ };
62
+ // Print an array of warnings
63
+ export const logWarningArray = function (logs, array, opts) {
64
+ logMessage(logs, serializeIndentedArray(array), { color: THEME.warningLine, ...opts });
65
+ };
66
+ // Print a main section header
67
+ export const logHeader = function (logs, string, opts) {
68
+ log(logs, `\n${getHeader(string)}`, { color: THEME.header, ...opts });
69
+ };
70
+ // Print a main section header, when an error happened
71
+ export const logErrorHeader = function (logs, string, opts) {
72
+ logHeader(logs, string, { color: THEME.errorHeader, ...opts });
73
+ };
74
+ // Print a sub-section header
75
+ export const logSubHeader = function (logs, string, opts) {
76
+ log(logs, `\n${figures.pointer} ${string}`, { color: THEME.subHeader, ...opts });
77
+ };
78
+ // Print a sub-section header, when an error happened
79
+ export const logErrorSubHeader = function (logs, string, opts) {
80
+ logSubHeader(logs, string, { color: THEME.errorSubHeader, ...opts });
81
+ };
82
+ // Print a sub-section header, when a warning happened
83
+ export const logWarningSubHeader = function (logs, string, opts) {
84
+ logSubHeader(logs, string, { color: THEME.warningSubHeader, ...opts });
85
+ };
86
+ // Combines an array of elements into a single string, separated by a space,
87
+ // and with basic serialization of non-string types
88
+ const reduceLogLines = function (lines) {
89
+ return lines
90
+ .map((input) => {
91
+ if (input instanceof Error) {
92
+ return `${input.message} ${input.stack}`;
93
+ }
94
+ if (typeof input === 'object') {
95
+ try {
96
+ return JSON.stringify(input);
97
+ }
98
+ catch {
99
+ // Value could not be serialized to JSON, so we return the string
100
+ // representation.
101
+ return String(input);
102
+ }
103
+ }
104
+ return String(input);
105
+ })
106
+ .join(' ');
107
+ };
108
+ // Builds a function for logging data to the system logger (i.e. hidden from
109
+ // the user-facing build logs)
110
+ export const getSystemLogger = function (logs, debug, systemLogFile) {
111
+ // If the `debug` flag is used, we return a function that pipes system logs
112
+ // to the regular logger, as the intention is for them to end up in stdout.
113
+ if (debug) {
114
+ return (...args) => log(logs, reduceLogLines(args));
115
+ }
116
+ // If there's not a file descriptor configured for system logs and `debug`
117
+ // is not set, we return a no-op function that will swallow the errors.
118
+ if (!systemLogFile) {
119
+ return () => {
120
+ // no-op
121
+ };
122
+ }
123
+ // Return a function that writes to the file descriptor configured for system
124
+ // logs.
125
+ const fileDescriptor = createWriteStream(null, { fd: systemLogFile });
126
+ fileDescriptor.on('error', () => {
127
+ logError(logs, 'Could not write to system log file');
128
+ });
129
+ return (...args) => fileDescriptor.write(`${reduceLogLines(args)}\n`);
130
+ };
@@ -0,0 +1,120 @@
1
+ import semver from 'semver';
2
+ import { isRuntime } from '../../utils/runtime.js';
3
+ import { isPreviousMajor } from '../../utils/semver.js';
4
+ import { getPluginOrigin } from '../description.js';
5
+ import { logArray, logSubHeader, logWarningArray, logWarningSubHeader } from '../logger.js';
6
+ import { THEME } from '../theme.js';
7
+ export const logRuntime = (logs, pluginOptions) => {
8
+ const runtimes = pluginOptions.filter(isRuntime);
9
+ // Once we have more runtimes, this hardcoded check should be removed
10
+ if (runtimes.length !== 0) {
11
+ const [nextRuntime] = runtimes;
12
+ logSubHeader(logs, `Using Next.js Runtime - v${nextRuntime.pluginPackageJson.version}`);
13
+ }
14
+ };
15
+ export const logLoadingPlugins = function (logs, pluginsOptions, debug) {
16
+ const loadingPlugins = pluginsOptions
17
+ .filter(isNotCorePlugin)
18
+ // We don't want to show runtimes as plugins
19
+ .filter((plugin) => !isRuntime(plugin))
20
+ .map((pluginOptions) => getPluginDescription(pluginOptions, debug));
21
+ if (loadingPlugins.length === 0) {
22
+ return;
23
+ }
24
+ logSubHeader(logs, 'Loading plugins');
25
+ logArray(logs, loadingPlugins);
26
+ };
27
+ // We only logs plugins explicitly enabled by users
28
+ const isNotCorePlugin = function ({ origin }) {
29
+ return origin !== 'core';
30
+ };
31
+ const getPluginDescription = function ({ packageName, pluginPackageJson: { version }, loadedFrom, origin, pinnedVersion, latestVersion, expectedVersion, compatibleVersion, }, debug) {
32
+ const versionedPackage = getVersionedPackage(packageName, version);
33
+ const pluginOrigin = getPluginOrigin(loadedFrom, origin);
34
+ const description = `${THEME.highlightWords(packageName)}${versionedPackage} ${pluginOrigin}`;
35
+ if (!debug) {
36
+ return description;
37
+ }
38
+ const versions = Object.entries({
39
+ pinned: pinnedVersion,
40
+ latest: latestVersion,
41
+ expected: expectedVersion,
42
+ compatible: compatibleVersion,
43
+ })
44
+ .filter(hasVersion)
45
+ .map(getVersionField);
46
+ if (versions.length === 0) {
47
+ return description;
48
+ }
49
+ return `${description} (${versions.join(', ')})`;
50
+ };
51
+ const hasVersion = function ([, version]) {
52
+ return version !== undefined;
53
+ };
54
+ const getVersionField = function ([versionFieldName, version]) {
55
+ return `${versionFieldName} ${version}`;
56
+ };
57
+ // Print a warning message when old versions plugins are used.
58
+ // This can only happen when they are installed to `package.json`.
59
+ export const logOutdatedPlugins = function (logs, pluginsOptions) {
60
+ const outdatedPlugins = pluginsOptions.filter(hasOutdatedVersion).map(getOutdatedPlugin);
61
+ if (outdatedPlugins.length === 0) {
62
+ return;
63
+ }
64
+ logWarningSubHeader(logs, 'Outdated plugins');
65
+ logWarningArray(logs, outdatedPlugins);
66
+ };
67
+ const hasOutdatedVersion = function ({ pluginPackageJson: { version }, latestVersion }) {
68
+ return version !== undefined && latestVersion !== undefined && semver.lt(version, latestVersion);
69
+ };
70
+ const getOutdatedPlugin = function ({ packageName, pluginPackageJson: { version }, latestVersion, migrationGuide, loadedFrom, origin, }) {
71
+ const versionedPackage = getVersionedPackage(packageName, version);
72
+ const outdatedDescription = getOutdatedDescription({ latestVersion, migrationGuide, loadedFrom, origin });
73
+ return `${THEME.warningHighlightWords(packageName)}${versionedPackage}: ${outdatedDescription}`;
74
+ };
75
+ const getOutdatedDescription = function ({ latestVersion, migrationGuide, loadedFrom, origin }) {
76
+ const upgradeInstruction = getUpgradeInstruction(loadedFrom, origin);
77
+ if (migrationGuide === undefined) {
78
+ return `latest version is ${latestVersion}\n${upgradeInstruction}`;
79
+ }
80
+ return `latest version is ${latestVersion}\nMigration guide: ${migrationGuide}\n${upgradeInstruction}`;
81
+ };
82
+ const getUpgradeInstruction = function (loadedFrom, origin) {
83
+ if (loadedFrom === 'package.json') {
84
+ return 'To upgrade this plugin, please update its version in "package.json"';
85
+ }
86
+ if (origin === 'ui') {
87
+ return 'To upgrade this plugin, please uninstall and re-install it from the Netlify plugins directory (https://app.netlify.com/plugins)';
88
+ }
89
+ return 'To upgrade this plugin, please remove it from "netlify.toml" and install it from the Netlify plugins directory instead (https://app.netlify.com/plugins)';
90
+ };
91
+ // Print a warning message when plugins are using a version that is too recent
92
+ // and does not meet some `compatibility` expectations.
93
+ // This can only happen when they are installed to `package.json`.
94
+ export const logIncompatiblePlugins = function (logs, pluginsOptions) {
95
+ const incompatiblePlugins = pluginsOptions.filter(hasIncompatibleVersion).map(getIncompatiblePlugin);
96
+ if (incompatiblePlugins.length === 0) {
97
+ return;
98
+ }
99
+ logWarningSubHeader(logs, 'Incompatible plugins');
100
+ logWarningArray(logs, incompatiblePlugins);
101
+ };
102
+ const hasIncompatibleVersion = function ({ pluginPackageJson: { version }, compatibleVersion, compatWarning }) {
103
+ return (compatWarning !== '' &&
104
+ version !== undefined &&
105
+ compatibleVersion !== undefined &&
106
+ // Using only the major version prevents printing this warning message when
107
+ // a site is using the right `compatibility` version, but is using the most
108
+ // recent version due to the time gap between `npm publish` and the
109
+ // `plugins.json` update
110
+ isPreviousMajor(compatibleVersion, version));
111
+ };
112
+ const getIncompatiblePlugin = function ({ packageName, pluginPackageJson: { version }, compatibleVersion, compatWarning, }) {
113
+ const versionedPackage = getVersionedPackage(packageName, version);
114
+ return `${THEME.warningHighlightWords(packageName)}${versionedPackage}: version ${compatibleVersion} is the most recent version compatible with ${compatWarning}`;
115
+ };
116
+ // Make sure we handle `package.json` with `version` being either `undefined`
117
+ // or an empty string
118
+ const getVersionedPackage = function (packageName, version = '') {
119
+ return version === '' ? '' : `@${version}`;
120
+ };
@@ -0,0 +1,91 @@
1
+ import { cleanupConfig } from '@netlify/config';
2
+ import { DEFAULT_FEATURE_FLAGS } from '../../core/feature_flags.js';
3
+ import { omit } from '../../utils/omit.js';
4
+ import { logMessage, logObject, logSubHeader } from '../logger.js';
5
+ import { THEME } from '../theme.js';
6
+ export const logFlags = function (logs, flags, { debug }) {
7
+ const flagsA = cleanFeatureFlags(flags);
8
+ const hiddenFlags = debug ? HIDDEN_DEBUG_FLAGS : HIDDEN_FLAGS;
9
+ const flagsB = omit(flagsA, hiddenFlags);
10
+ logSubHeader(logs, 'Flags');
11
+ logObject(logs, flagsB);
12
+ };
13
+ // We only show feature flags related to `@netlify/build`.
14
+ // Also, we only print enabled feature flags.
15
+ const cleanFeatureFlags = function ({ featureFlags = {}, ...flags }) {
16
+ const cleanedFeatureFlags = Object.entries(featureFlags)
17
+ .filter(shouldPrintFeatureFlag)
18
+ .map(([featureFlagName]) => featureFlagName);
19
+ return cleanedFeatureFlags.length === 0 ? flags : { ...flags, featureFlags: cleanedFeatureFlags };
20
+ };
21
+ const shouldPrintFeatureFlag = function ([featureFlagName, enabled]) {
22
+ return enabled && featureFlagName in DEFAULT_FEATURE_FLAGS;
23
+ };
24
+ // Hidden because the value is security-sensitive
25
+ const SECURE_FLAGS = ['token', 'bugsnagKey', 'env', 'cachedConfig', 'defaultConfig'];
26
+ // Hidden because those are used in tests
27
+ const TEST_FLAGS = ['buffer', 'telemetry'];
28
+ // Hidden because those are only used internally
29
+ const INTERNAL_FLAGS = [
30
+ 'nodePath',
31
+ 'functionsDistDir',
32
+ 'edgeFunctionsDistDir',
33
+ 'defaultConfig',
34
+ 'cachedConfigPath',
35
+ 'sendStatus',
36
+ 'saveConfig',
37
+ 'statsd',
38
+ 'framework',
39
+ 'featureFlags',
40
+ 'buildbotServerSocket',
41
+ 'testOpts',
42
+ 'siteId',
43
+ 'context',
44
+ 'branch',
45
+ 'cwd',
46
+ 'repositoryRoot',
47
+ 'mode',
48
+ 'apiHost',
49
+ 'cacheDir',
50
+ 'systemLogFile',
51
+ 'timeline',
52
+ ];
53
+ const HIDDEN_FLAGS = [...SECURE_FLAGS, ...TEST_FLAGS, ...INTERNAL_FLAGS];
54
+ const HIDDEN_DEBUG_FLAGS = [...SECURE_FLAGS, ...TEST_FLAGS];
55
+ export const logBuildDir = function (logs, buildDir) {
56
+ logSubHeader(logs, 'Current directory');
57
+ logMessage(logs, buildDir);
58
+ };
59
+ export const logConfigPath = function (logs, configPath = NO_CONFIG_MESSAGE) {
60
+ logSubHeader(logs, 'Config file');
61
+ logMessage(logs, configPath);
62
+ };
63
+ const NO_CONFIG_MESSAGE = 'No config file was defined: using default values.';
64
+ export const logConfig = function ({ logs, netlifyConfig, debug }) {
65
+ if (!debug) {
66
+ return;
67
+ }
68
+ logSubHeader(logs, 'Resolved config');
69
+ logObject(logs, cleanupConfig(netlifyConfig));
70
+ };
71
+ export const logConfigOnUpdate = function ({ logs, netlifyConfig, debug }) {
72
+ if (!debug) {
73
+ return;
74
+ }
75
+ logSubHeader(logs, 'Updated config');
76
+ logObject(logs, cleanupConfig(netlifyConfig));
77
+ };
78
+ export const logConfigOnError = function ({ logs, netlifyConfig, severity }) {
79
+ if (netlifyConfig === undefined || severity === 'none') {
80
+ return;
81
+ }
82
+ logMessage(logs, THEME.errorSubHeader('Resolved config'));
83
+ logObject(logs, cleanupConfig(netlifyConfig));
84
+ };
85
+ export const logContext = function (logs, context) {
86
+ if (context === undefined) {
87
+ return;
88
+ }
89
+ logSubHeader(logs, 'Context');
90
+ logMessage(logs, context);
91
+ };
@@ -0,0 +1,50 @@
1
+ import ansiEscapes from 'ansi-escapes';
2
+ import prettyMs from 'pretty-ms';
3
+ import { getFullErrorInfo } from '../../error/parse/parse.js';
4
+ import { serializeLogError } from '../../error/parse/serialize_log.js';
5
+ import { roundTimerToMillisecs } from '../../time/measure.js';
6
+ import { ROOT_PACKAGE_JSON } from '../../utils/json.js';
7
+ import { getLogHeaderFunc } from '../header_func.js';
8
+ import { log, logMessage, logWarning, logHeader, logSubHeader, logWarningArray } from '../logger.js';
9
+ import { logOldCliVersionError } from '../old_version.js';
10
+ import { THEME } from '../theme.js';
11
+ import { logConfigOnError } from './config.js';
12
+ export const logBuildStart = function (logs) {
13
+ logHeader(logs, 'Netlify Build');
14
+ logSubHeader(logs, 'Version');
15
+ logMessage(logs, `${ROOT_PACKAGE_JSON.name} ${ROOT_PACKAGE_JSON.version}`);
16
+ };
17
+ export const logBuildError = function ({ error, netlifyConfig, mode, logs, debug, testOpts }) {
18
+ const fullErrorInfo = getFullErrorInfo({ error, colors: true, debug });
19
+ const { severity } = fullErrorInfo;
20
+ const { title, body } = serializeLogError({ fullErrorInfo });
21
+ const logHeaderFunc = getLogHeaderFunc(error);
22
+ logHeaderFunc(logs, title);
23
+ logMessage(logs, `\n${body}\n`);
24
+ logConfigOnError({ logs, netlifyConfig, severity });
25
+ logOldCliVersionError({ mode, testOpts });
26
+ };
27
+ export const logBuildSuccess = function (logs) {
28
+ logHeader(logs, 'Netlify Build Complete');
29
+ logMessage(logs, '');
30
+ };
31
+ export const logTimer = function (logs, durationNs, timerName) {
32
+ const durationMs = roundTimerToMillisecs(durationNs);
33
+ const duration = prettyMs(durationMs);
34
+ log(logs, THEME.dimWords(`(${timerName} completed in ${duration})`));
35
+ };
36
+ export const logMissingSideFile = function (logs, sideFile, publish) {
37
+ logWarning(logs, `
38
+ A "${sideFile}" file is present in the repository but is missing in the publish directory "${publish}".`);
39
+ };
40
+ // @todo use `terminal-link` (https://github.com/sindresorhus/terminal-link)
41
+ // instead of `ansi-escapes` once
42
+ // https://github.com/jamestalmage/supports-hyperlinks/pull/12 is fixed
43
+ export const logLingeringProcesses = function (logs, commands) {
44
+ logWarning(logs, `
45
+ The build completed successfully, but the following processes were still running:
46
+ `);
47
+ logWarningArray(logs, commands);
48
+ logWarning(logs, `
49
+ These processes have been terminated. In case this creates a problem for your build, refer to this ${ansiEscapes.link('article', 'https://answers.netlify.com/t/support-guide-how-to-address-the-warning-message-related-to-terminating-processes-in-builds/35277')} for details about why this process termination happens and how to fix it.`);
50
+ };
@@ -0,0 +1,75 @@
1
+ import path from 'path';
2
+ import { log, logArray, logErrorSubHeader, logWarningSubHeader } from '../logger.js';
3
+ import { THEME } from '../theme.js';
4
+ const logBundleResultFunctions = ({ functions, headerMessage, logs, error }) => {
5
+ const functionNames = functions.map(({ path: functionPath }) => path.basename(functionPath));
6
+ if (error) {
7
+ logErrorSubHeader(logs, headerMessage);
8
+ }
9
+ else {
10
+ logWarningSubHeader(logs, headerMessage);
11
+ }
12
+ logArray(logs, functionNames);
13
+ };
14
+ export const logBundleResults = ({ logs, results = [] }) => {
15
+ const resultsWithErrors = results.filter(({ bundlerErrors }) => bundlerErrors && bundlerErrors.length !== 0);
16
+ const resultsWithWarnings = results.filter(({ bundler, bundlerWarnings }) => bundler === 'esbuild' && bundlerWarnings && bundlerWarnings.length !== 0);
17
+ const modulesWithDynamicImports = [
18
+ ...new Set(results.flatMap((result) => result.nodeModulesWithDynamicImports || [])),
19
+ ];
20
+ if (resultsWithErrors.length !== 0) {
21
+ logBundleResultFunctions({
22
+ functions: resultsWithErrors,
23
+ headerMessage: 'Failed to bundle functions with selected bundler (fallback used):',
24
+ logs,
25
+ error: true,
26
+ });
27
+ }
28
+ if (resultsWithWarnings.length !== 0) {
29
+ logBundleResultFunctions({
30
+ functions: resultsWithWarnings,
31
+ headerMessage: 'Functions bundled with warnings:',
32
+ logs,
33
+ error: false,
34
+ });
35
+ }
36
+ if (modulesWithDynamicImports.length !== 0) {
37
+ logModulesWithDynamicImports({ logs, modulesWithDynamicImports });
38
+ }
39
+ };
40
+ export const logFunctionsNonExistingDir = function (logs, relativeFunctionsSrc) {
41
+ log(logs, `The Netlify Functions setting targets a non-existing directory: ${relativeFunctionsSrc}`);
42
+ };
43
+ // Print the list of Netlify Functions about to be bundled
44
+ export const logFunctionsToBundle = function ({ logs, userFunctions, userFunctionsSrc, userFunctionsSrcExists, internalFunctions, internalFunctionsSrc, type = 'Functions', }) {
45
+ if (internalFunctions.length !== 0) {
46
+ log(logs, `Packaging ${type} from ${THEME.highlightWords(internalFunctionsSrc)} directory:`);
47
+ logArray(logs, internalFunctions, { indent: false });
48
+ }
49
+ if (!userFunctionsSrcExists) {
50
+ return;
51
+ }
52
+ if (userFunctions.length === 0) {
53
+ log(logs, `No ${type} were found in ${THEME.highlightWords(userFunctionsSrc)} directory`);
54
+ return;
55
+ }
56
+ if (internalFunctions.length !== 0) {
57
+ log(logs, '');
58
+ }
59
+ log(logs, `Packaging ${type} from ${THEME.highlightWords(userFunctionsSrc)} directory:`);
60
+ logArray(logs, userFunctions, { indent: false });
61
+ };
62
+ const logModulesWithDynamicImports = ({ logs, modulesWithDynamicImports }) => {
63
+ const externalNodeModules = modulesWithDynamicImports.map((moduleName) => `"${moduleName}"`).join(', ');
64
+ logWarningSubHeader(logs, `The following Node.js modules use dynamic expressions to include files:`);
65
+ logArray(logs, modulesWithDynamicImports);
66
+ log(logs, `\n Because files included with dynamic expressions aren't bundled with your serverless functions by default,
67
+ this may result in an error when invoking a function. To resolve this error, you can mark these Node.js
68
+ modules as external in the [functions] section of your \`netlify.toml\` configuration file:
69
+
70
+ [functions]
71
+ external_node_modules = [${externalNodeModules}]
72
+
73
+ Visit https://ntl.fyi/dynamic-imports for more information.
74
+ `);
75
+ };
@@ -0,0 +1,41 @@
1
+ import figures from 'figures';
2
+ import { logMessage, logSubHeader } from '../logger.js';
3
+ import { THEME } from '../theme.js';
4
+ export const logDryRunStart = function ({ logs, eventWidth, stepsCount }) {
5
+ const columnWidth = getDryColumnWidth(eventWidth, stepsCount);
6
+ const line = '─'.repeat(columnWidth);
7
+ const secondLine = '─'.repeat(columnWidth);
8
+ logSubHeader(logs, 'Netlify Build Commands');
9
+ logMessage(logs, `For more information on build events see the docs https://github.com/netlify/build
10
+
11
+ Running \`netlify build\` will execute this build flow
12
+
13
+ ${THEME.header(`┌─${line}─┬─${secondLine}─┐
14
+ │ ${DRY_HEADER_NAMES[0].padEnd(columnWidth)} │ ${DRY_HEADER_NAMES[1].padEnd(columnWidth)} │
15
+ └─${line}─┴─${secondLine}─┘`)}`);
16
+ };
17
+ export const logDryRunStep = function ({ logs, step: { event, packageName, coreStepDescription }, index, netlifyConfig, eventWidth, stepsCount, }) {
18
+ const columnWidth = getDryColumnWidth(eventWidth, stepsCount);
19
+ const fullName = getFullName(coreStepDescription, netlifyConfig, packageName);
20
+ const line = '─'.repeat(columnWidth);
21
+ const countText = `${index + 1}. `;
22
+ const downArrow = stepsCount === index + 1 ? ' ' : ` ${figures.arrowDown}`;
23
+ const eventWidthA = columnWidth - countText.length - downArrow.length;
24
+ logMessage(logs, `${THEME.header(`┌─${line}─┐`)}
25
+ ${THEME.header(`│ ${countText}${event.padEnd(eventWidthA)}${downArrow} │`)} ${fullName}
26
+ ${THEME.header(`└─${line}─┘ `)}`);
27
+ };
28
+ const getFullName = function (coreStepDescription, netlifyConfig, packageName) {
29
+ return coreStepDescription === undefined
30
+ ? `Plugin ${THEME.highlightWords(packageName)}`
31
+ : coreStepDescription({ netlifyConfig });
32
+ };
33
+ const getDryColumnWidth = function (eventWidth, stepsCount) {
34
+ const symbolsWidth = `${stepsCount}`.length + COLUMN_EXTRA_WIDTH;
35
+ return Math.max(eventWidth + symbolsWidth, DRY_HEADER_NAMES[1].length);
36
+ };
37
+ const COLUMN_EXTRA_WIDTH = 4;
38
+ const DRY_HEADER_NAMES = ['Event', 'Location'];
39
+ export const logDryRunEnd = function (logs) {
40
+ logMessage(logs, `\nIf this looks good to you, run \`netlify build\` to execute the build\n`);
41
+ };
@@ -0,0 +1,25 @@
1
+ import { isRuntime } from '../../utils/runtime.js';
2
+ import { log, logArray, logSubHeader } from '../logger.js';
3
+ export const logInstallMissingPlugins = function (logs, packages) {
4
+ const runtimes = packages.filter((pkg) => isRuntime(pkg));
5
+ const plugins = packages.filter((pkg) => !isRuntime(pkg));
6
+ if (plugins.length !== 0) {
7
+ logSubHeader(logs, 'Installing plugins');
8
+ logArray(logs, packages);
9
+ }
10
+ if (runtimes.length !== 0) {
11
+ const [nextRuntime] = runtimes;
12
+ logSubHeader(logs, `Using Next.js Runtime - v${nextRuntime.pluginPackageJson.version}`);
13
+ }
14
+ };
15
+ export const logInstallLocalPluginsDeps = function (logs, localPluginsOptions) {
16
+ const packages = localPluginsOptions.map(getPackageName);
17
+ logSubHeader(logs, 'Installing local plugins dependencies');
18
+ logArray(logs, packages);
19
+ };
20
+ export const logInstallFunctionDependencies = function () {
21
+ log(undefined, 'Installing functions dependencies');
22
+ };
23
+ const getPackageName = function ({ packageName }) {
24
+ return packageName;
25
+ };
@@ -0,0 +1,29 @@
1
+ import { log } from '../logger.js';
2
+ const logVerbose = function (logs, verbose, message) {
3
+ if (!verbose) {
4
+ return;
5
+ }
6
+ log(logs, message);
7
+ };
8
+ export const logSendingEventToChild = function (logs, verbose) {
9
+ logVerbose(logs, verbose, 'Step starting.');
10
+ };
11
+ export const logSentEventToChild = function (logs, verbose) {
12
+ logVerbose(logs, verbose, 'Step started.');
13
+ };
14
+ export const logPluginMethodStart = function (verbose) {
15
+ logVerbose(undefined, verbose, 'Plugin logic started.');
16
+ };
17
+ export const logPluginMethodEnd = function (verbose) {
18
+ logVerbose(undefined, verbose, 'Plugin logic ended.');
19
+ };
20
+ export const logSendingEventToParent = function (verbose, error) {
21
+ const message = error instanceof Error ? `Step erroring.\n${error.stack}` : 'Stop closing.';
22
+ logVerbose(undefined, verbose, message);
23
+ };
24
+ export const logReceivedEventFromChild = function (logs, verbose) {
25
+ logVerbose(logs, verbose, 'Step ended.');
26
+ };
27
+ export const logStepCompleted = function (logs, verbose) {
28
+ logVerbose(logs, verbose, 'Step completed.');
29
+ };