@netlify/build 29.0.1-rc → 29.0.2

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 (266) hide show
  1. package/bin.js +5 -0
  2. package/lib/core/bin.js +66 -0
  3. package/lib/core/build.js +356 -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 +21 -0
  9. package/lib/core/flags.js +201 -0
  10. package/lib/core/lingering.js +68 -0
  11. package/lib/core/main.js +110 -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/report.js +27 -0
  41. package/lib/error/type.js +177 -0
  42. package/lib/install/functions.js +20 -0
  43. package/lib/install/local.js +45 -0
  44. package/lib/install/main.js +67 -0
  45. package/lib/install/missing.js +54 -0
  46. package/lib/log/colors.js +28 -0
  47. package/lib/log/description.js +21 -0
  48. package/lib/log/header.js +14 -0
  49. package/lib/log/header_func.js +13 -0
  50. package/lib/log/logger.js +140 -0
  51. package/lib/log/messages/compatibility.js +146 -0
  52. package/lib/log/messages/config.js +91 -0
  53. package/lib/log/messages/core.js +51 -0
  54. package/lib/log/messages/core_steps.js +75 -0
  55. package/lib/log/messages/dry.js +41 -0
  56. package/lib/log/messages/install.js +25 -0
  57. package/lib/log/messages/ipc.js +29 -0
  58. package/lib/log/messages/mutations.js +62 -0
  59. package/{src → lib}/log/messages/plugins.js +18 -32
  60. package/lib/log/messages/status.js +14 -0
  61. package/lib/log/messages/steps.js +18 -0
  62. package/lib/log/old_version.js +32 -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/{src → lib}/plugins/error.js +31 -35
  79. package/{src → lib}/plugins/events.js +7 -12
  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 +58 -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/{src → lib}/plugins_core/deploy/manifest.yml +0 -0
  100. package/lib/plugins_core/edge_functions/index.js +76 -0
  101. package/{src → lib}/plugins_core/edge_functions/lib/error.js +13 -17
  102. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +21 -0
  103. package/lib/plugins_core/functions/error.js +123 -0
  104. package/lib/plugins_core/functions/feature_flags.js +6 -0
  105. package/lib/plugins_core/functions/index.js +114 -0
  106. package/lib/plugins_core/functions/utils.js +45 -0
  107. package/lib/plugins_core/functions/zisi.js +39 -0
  108. package/{src → lib}/plugins_core/functions_install/index.js +8 -11
  109. package/{src → lib}/plugins_core/functions_install/manifest.yml +0 -0
  110. package/lib/plugins_core/list.js +20 -0
  111. package/lib/report/statsd.js +31 -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 +59 -0
  118. package/lib/steps/error.js +65 -0
  119. package/lib/steps/get.js +43 -0
  120. package/lib/steps/plugin.js +55 -0
  121. package/lib/steps/return.js +25 -0
  122. package/lib/steps/run_core_steps.js +117 -0
  123. package/lib/steps/run_step.js +190 -0
  124. package/lib/steps/run_steps.js +96 -0
  125. package/lib/steps/update_config.js +66 -0
  126. package/lib/telemetry/main.js +97 -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 +24 -0
  131. package/lib/utils/errors.js +13 -0
  132. package/lib/utils/json.js +15 -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 +41 -24
  140. package/types/config/netlify_config.d.ts +4 -4
  141. package/types/netlify_plugin_constants.d.ts +8 -8
  142. package/src/core/bin.js +0 -83
  143. package/src/core/build.js +0 -554
  144. package/src/core/config.js +0 -186
  145. package/src/core/constants.js +0 -156
  146. package/src/core/dev.js +0 -31
  147. package/src/core/dry.js +0 -39
  148. package/src/core/feature_flags.js +0 -22
  149. package/src/core/flags.js +0 -204
  150. package/src/core/lingering.js +0 -85
  151. package/src/core/main.js +0 -165
  152. package/src/core/missing_side_file.js +0 -29
  153. package/src/core/normalize_flags.js +0 -70
  154. package/src/core/severity.js +0 -22
  155. package/src/core/user_node_version.js +0 -41
  156. package/src/env/changes.js +0 -52
  157. package/src/env/main.js +0 -19
  158. package/src/env/metadata.js +0 -81
  159. package/src/error/api.js +0 -46
  160. package/src/error/build.js +0 -50
  161. package/src/error/colors.js +0 -11
  162. package/src/error/handle.js +0 -57
  163. package/src/error/info.js +0 -46
  164. package/src/error/monitor/location.js +0 -21
  165. package/src/error/monitor/normalize.js +0 -96
  166. package/src/error/monitor/print.js +0 -42
  167. package/src/error/monitor/report.js +0 -138
  168. package/src/error/monitor/start.js +0 -69
  169. package/src/error/parse/clean_stack.js +0 -87
  170. package/src/error/parse/location.js +0 -62
  171. package/src/error/parse/normalize.js +0 -29
  172. package/src/error/parse/parse.js +0 -97
  173. package/src/error/parse/plugin.js +0 -70
  174. package/src/error/parse/properties.js +0 -23
  175. package/src/error/parse/serialize_log.js +0 -42
  176. package/src/error/parse/serialize_status.js +0 -23
  177. package/src/error/parse/stack.js +0 -43
  178. package/src/error/type.js +0 -189
  179. package/src/install/functions.js +0 -28
  180. package/src/install/local.js +0 -62
  181. package/src/install/main.js +0 -81
  182. package/src/install/missing.js +0 -67
  183. package/src/log/colors.js +0 -34
  184. package/src/log/description.js +0 -26
  185. package/src/log/header.js +0 -16
  186. package/src/log/header_func.js +0 -17
  187. package/src/log/logger.js +0 -161
  188. package/src/log/messages/compatibility.js +0 -164
  189. package/src/log/messages/config.js +0 -107
  190. package/src/log/messages/core.js +0 -70
  191. package/src/log/messages/core_steps.js +0 -104
  192. package/src/log/messages/dry.js +0 -63
  193. package/src/log/messages/install.js +0 -20
  194. package/src/log/messages/ipc.js +0 -38
  195. package/src/log/messages/mutations.js +0 -82
  196. package/src/log/messages/status.js +0 -16
  197. package/src/log/messages/steps.js +0 -22
  198. package/src/log/old_version.js +0 -41
  199. package/src/log/serialize.js +0 -13
  200. package/src/log/stream.js +0 -85
  201. package/src/log/theme.js +0 -26
  202. package/src/plugins/child/diff.js +0 -55
  203. package/src/plugins/child/error.js +0 -32
  204. package/src/plugins/child/lazy.js +0 -18
  205. package/src/plugins/child/load.js +0 -29
  206. package/src/plugins/child/logic.js +0 -57
  207. package/src/plugins/child/main.js +0 -51
  208. package/src/plugins/child/run.js +0 -28
  209. package/src/plugins/child/status.js +0 -74
  210. package/src/plugins/child/typescript.js +0 -45
  211. package/src/plugins/child/utils.js +0 -56
  212. package/src/plugins/child/validate.js +0 -34
  213. package/src/plugins/compatibility.js +0 -128
  214. package/src/plugins/expected_version.js +0 -119
  215. package/src/plugins/ipc.js +0 -145
  216. package/src/plugins/list.js +0 -86
  217. package/src/plugins/load.js +0 -70
  218. package/src/plugins/manifest/check.js +0 -106
  219. package/src/plugins/manifest/load.js +0 -41
  220. package/src/plugins/manifest/main.js +0 -22
  221. package/src/plugins/manifest/path.js +0 -31
  222. package/src/plugins/manifest/validate.js +0 -108
  223. package/src/plugins/node_version.js +0 -50
  224. package/src/plugins/options.js +0 -88
  225. package/src/plugins/pinned_version.js +0 -131
  226. package/src/plugins/resolve.js +0 -152
  227. package/src/plugins/spawn.js +0 -66
  228. package/src/plugins_core/add.js +0 -49
  229. package/src/plugins_core/build_command.js +0 -75
  230. package/src/plugins_core/deploy/buildbot_client.js +0 -102
  231. package/src/plugins_core/deploy/index.js +0 -73
  232. package/src/plugins_core/edge_functions/index.js +0 -123
  233. package/src/plugins_core/edge_functions/lib/internal_manifest.js +0 -54
  234. package/src/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +0 -89
  235. package/src/plugins_core/functions/error.js +0 -163
  236. package/src/plugins_core/functions/feature_flags.js +0 -6
  237. package/src/plugins_core/functions/index.js +0 -160
  238. package/src/plugins_core/functions/utils.js +0 -66
  239. package/src/plugins_core/functions/zisi.js +0 -53
  240. package/src/plugins_core/list.js +0 -27
  241. package/src/status/add.js +0 -36
  242. package/src/status/colors.js +0 -23
  243. package/src/status/load_error.js +0 -11
  244. package/src/status/report.js +0 -137
  245. package/src/status/success.js +0 -18
  246. package/src/steps/core_step.js +0 -92
  247. package/src/steps/error.js +0 -102
  248. package/src/steps/get.js +0 -51
  249. package/src/steps/plugin.js +0 -85
  250. package/src/steps/return.js +0 -52
  251. package/src/steps/run_core_steps.js +0 -200
  252. package/src/steps/run_step.js +0 -304
  253. package/src/steps/run_steps.js +0 -179
  254. package/src/steps/update_config.js +0 -93
  255. package/src/telemetry/main.js +0 -136
  256. package/src/time/aggregate.js +0 -146
  257. package/src/time/main.js +0 -48
  258. package/src/time/measure.js +0 -22
  259. package/src/time/report.js +0 -59
  260. package/src/utils/errors.js +0 -12
  261. package/src/utils/json.js +0 -19
  262. package/src/utils/omit.js +0 -6
  263. package/src/utils/package.js +0 -23
  264. package/src/utils/remove_falsy.js +0 -10
  265. package/src/utils/resolve.js +0 -46
  266. package/src/utils/semver.js +0 -34
@@ -0,0 +1,109 @@
1
+ import { isNetlifyMaintainedPlugin } from '../plugins/internal.js';
2
+ import { createTimer, TOP_PARENT_TAG } from './main.js';
3
+ // Some timers are computed based on others:
4
+ // - `others` is `total` minus the other timers
5
+ // - `run_plugins` is the sum of all plugins
6
+ // - `run_netlify_build_per_type` aggregates timers but per system/plugin/user
7
+ // - each plugin timer is the sum of its event handlers
8
+ export const addAggregatedTimers = function (timers) {
9
+ const timersA = addRunPluginsTimer(timers);
10
+ const timersB = addPluginTimers(timersA);
11
+ const timersC = addOthersTimers(timersB);
12
+ const timersD = addTypeTimers(timersC);
13
+ return timersD;
14
+ };
15
+ // Having a `total` timer is redundant since the buildbot already measures this.
16
+ // The buildbot measurement is better since it includes the time to load Node.
17
+ // Instead, we only use `total` to measure what did not get `measureDuration()`.
18
+ const addOthersTimers = function (timers) {
19
+ const totalTimer = timers.find(isTotalTimer);
20
+ const timersA = timers.filter((timer) => !isTotalTimer(timer));
21
+ const topTimers = timersA.filter(isTopTimer);
22
+ const othersTimer = createOthersTimer(topTimers, totalTimer);
23
+ return [...timersA, othersTimer];
24
+ };
25
+ const isTotalTimer = function ({ stageTag, parentTag }) {
26
+ return stageTag === 'total' && parentTag === 'build_site';
27
+ };
28
+ const createOthersTimer = function (topTimers, { durationNs: totalTimerDurationNs }) {
29
+ const topTimersDurationNs = computeTimersDuration(topTimers);
30
+ const otherTimersDurationNs = Math.max(0, totalTimerDurationNs - topTimersDurationNs);
31
+ const othersTimer = createTimer(OTHERS_STAGE_TAG, otherTimersDurationNs);
32
+ return othersTimer;
33
+ };
34
+ const OTHERS_STAGE_TAG = 'others';
35
+ // Measure the total time running plugins
36
+ const addRunPluginsTimer = function (timers) {
37
+ const pluginsTimers = timers.filter(isPluginTimer);
38
+ return pluginsTimers.length === 0 ? timers : [...timers, createSumTimer(pluginsTimers, RUN_PLUGINS_STAGE_TAG)];
39
+ };
40
+ const RUN_PLUGINS_STAGE_TAG = 'run_plugins';
41
+ // Retrieve one timer for each plugin, summing all its individual timers
42
+ // (one per event handler)
43
+ const addPluginTimers = function (timers) {
44
+ const timersA = timers.filter((timer) => !isCommunityPluginTimer(timer));
45
+ const pluginsTimers = timersA.filter(isPluginTimer);
46
+ if (pluginsTimers.length === 0) {
47
+ return timersA;
48
+ }
49
+ const pluginPackages = getPluginPackages(pluginsTimers);
50
+ const wholePluginsTimers = pluginPackages.map((pluginPackage) => getWholePluginTimer(pluginPackage, pluginsTimers));
51
+ return [...timersA, ...wholePluginsTimers];
52
+ };
53
+ // We only measure plugins maintained by us, not community
54
+ const isCommunityPluginTimer = function (timer) {
55
+ return isPluginTimer(timer) && !isNetlifyMaintainedPlugin(getPluginTimerPackage(timer));
56
+ };
57
+ const getPluginPackages = function (pluginsTimers) {
58
+ const pluginPackages = pluginsTimers.map(getPluginTimerPackage);
59
+ return [...new Set(pluginPackages)];
60
+ };
61
+ const getWholePluginTimer = function (pluginPackage, pluginsTimers) {
62
+ const pluginTimers = pluginsTimers.filter((pluginTimer) => getPluginTimerPackage(pluginTimer) === pluginPackage);
63
+ const wholePluginsTimer = createSumTimer(pluginTimers, pluginPackage, RUN_PLUGINS_STAGE_TAG);
64
+ return wholePluginsTimer;
65
+ };
66
+ const getPluginTimerPackage = function ({ parentTag }) {
67
+ return parentTag;
68
+ };
69
+ // Check if a timer relates to a Build plugin
70
+ const isPluginTimer = function ({ category }) {
71
+ return category === 'pluginEvent';
72
+ };
73
+ // Reports total time depending on whether it was system, plugin or user
74
+ const addTypeTimers = function (timers) {
75
+ const topTimers = timers.filter(isTopTimer);
76
+ const typeTimers = TYPE_TIMERS.map(({ name, stages }) => getTypeTimer(name, stages, topTimers)).filter(Boolean);
77
+ return [...timers, ...typeTimers];
78
+ };
79
+ const TYPE_TIMERS = [
80
+ { name: 'system', stages: ['resolve_config', 'get_plugins_options', 'start_plugins', 'others'] },
81
+ { name: 'plugin', stages: ['load_plugins', 'run_plugins'] },
82
+ { name: 'user', stages: ['build_command', 'edge_functions_bundling', 'functions_bundling', 'deploy_site'] },
83
+ ];
84
+ const getTypeTimer = function (name, stages, topTimers) {
85
+ const topTimersA = topTimers.filter(({ stageTag }) => stages.includes(stageTag));
86
+ if (topTimersA.length === 0) {
87
+ return;
88
+ }
89
+ const typeTimer = createSumTimer(topTimersA, name, 'run_netlify_build_per_type');
90
+ return typeTimer;
91
+ };
92
+ const isTopTimer = function ({ parentTag }) {
93
+ return parentTag === TOP_PARENT_TAG;
94
+ };
95
+ // Creates a timer that sums up the duration of several others
96
+ const createSumTimer = function (timers, stageTag, parentTag) {
97
+ const durationNs = computeTimersDuration(timers);
98
+ const timer = createTimer(stageTag, durationNs, { parentTag });
99
+ return timer;
100
+ };
101
+ const computeTimersDuration = function (timers) {
102
+ return timers.map(getTimerDuration).reduce(reduceSum, 0);
103
+ };
104
+ const getTimerDuration = function ({ durationNs }) {
105
+ return durationNs;
106
+ };
107
+ const reduceSum = function (sum, number) {
108
+ return sum + number;
109
+ };
@@ -0,0 +1,31 @@
1
+ import keepFuncProps from 'keep-func-props';
2
+ import { startTimer, endTimer } from './measure.js';
3
+ const DEFAULT_METRIC_NAME = 'buildbot.build.stage.duration';
4
+ export const TOP_PARENT_TAG = 'run_netlify_build';
5
+ // Initialize the `timers` array
6
+ export const initTimers = function () {
7
+ return [];
8
+ };
9
+ // Wrap an async function to measure how long it takes.
10
+ // The function must:
11
+ // - take a plain object as first argument. This must contain a `timers`.
12
+ // - return a plain object. This may or may not contain a modified `timers`.
13
+ // The `durationNs` will be returned by the function. A new `timers` with the
14
+ // additional duration timer will be returned as well.
15
+ const kMeasureDuration = function (func, stageTag, { parentTag = undefined, category = undefined } = {}) {
16
+ return async function measuredFunc({ timers, ...opts }, ...args) {
17
+ const timerNs = startTimer();
18
+ const { timers: timersA = timers, ...returnObject } = await func({ timers, ...opts }, ...args);
19
+ const { tags = {} } = returnObject;
20
+ const durationNs = endTimer(timerNs);
21
+ const timer = createTimer(stageTag, durationNs, { parentTag, category, tags });
22
+ const timersB = [...timersA, timer];
23
+ return { ...returnObject, timers: timersB, durationNs };
24
+ };
25
+ };
26
+ // Ensure the wrapped function `name` is not `anonymous` in stack traces
27
+ export const measureDuration = keepFuncProps(kMeasureDuration);
28
+ // Create a new object representing a completed timer
29
+ export const createTimer = function (stageTag, durationNs, { metricName = DEFAULT_METRIC_NAME, parentTag = TOP_PARENT_TAG, category = undefined, tags = undefined } = {}) {
30
+ return { metricName, stageTag, parentTag, durationNs, category, tags };
31
+ };
@@ -0,0 +1,16 @@
1
+ import { hrtime } from 'process';
2
+ const NANOSECS_TO_SECS = 1e9;
3
+ const NANOSECS_TO_MSECS = 1e6;
4
+ /** Starts a timer */
5
+ export const startTimer = hrtime;
6
+ /** Stops a timer */
7
+ export const endTimer = ([startSecs, startNsecs]) => {
8
+ const [endSecs, endNsecs] = hrtime();
9
+ const durationNs = (endSecs - startSecs) * NANOSECS_TO_SECS + endNsecs - startNsecs;
10
+ return durationNs;
11
+ };
12
+ /**
13
+ * statsd expects milliseconds integers.
14
+ * To prevent double rounding errors, rounding should only be applied once.
15
+ */
16
+ export const roundTimerToMillisecs = (durationNs) => Math.round(durationNs / NANOSECS_TO_MSECS);
@@ -0,0 +1,24 @@
1
+ import { closeClient, startClient } from '../report/statsd.js';
2
+ import { addAggregatedTimers } from './aggregate.js';
3
+ import { roundTimerToMillisecs } from './measure.js';
4
+ // Record the duration of a build phase, for monitoring.
5
+ // Sends to statsd daemon.
6
+ export const reportTimers = async function ({ timers, statsdOpts: { host, port }, framework }) {
7
+ if (host === undefined) {
8
+ return;
9
+ }
10
+ const timersA = addAggregatedTimers(timers);
11
+ await sendTimers({ timers: timersA, host, port, framework });
12
+ };
13
+ const sendTimers = async function ({ timers, host, port, framework }) {
14
+ const client = await startClient(host, port);
15
+ timers.forEach((timer) => {
16
+ sendTimer({ timer, client, framework });
17
+ });
18
+ await closeClient(client);
19
+ };
20
+ const sendTimer = function ({ timer: { metricName, stageTag, parentTag, durationNs, tags }, client, framework }) {
21
+ const durationMs = roundTimerToMillisecs(durationNs);
22
+ const frameworkTag = framework === undefined ? {} : { framework };
23
+ client.distribution(metricName, durationMs, { stage: stageTag, parent: parentTag, ...tags, ...frameworkTag });
24
+ };
@@ -0,0 +1,13 @@
1
+ // Wrap an async function so it prepends an error message on exceptions.
2
+ // This helps locate errors.
3
+ export const addAsyncErrorMessage = function (asyncFunc, message) {
4
+ return async (...args) => {
5
+ try {
6
+ return await asyncFunc(...args);
7
+ }
8
+ catch (error) {
9
+ error.stack = `${message}: ${error.stack}`;
10
+ throw error;
11
+ }
12
+ };
13
+ };
@@ -0,0 +1,15 @@
1
+ import { promises as fs, readFileSync } from 'fs';
2
+ import { fileURLToPath } from 'url';
3
+ const ROOT_PACKAGE_JSON_PATH = fileURLToPath(new URL('../../package.json', import.meta.url));
4
+ // TODO: Replace with dynamic `import()` once it is supported without
5
+ // experimental flags
6
+ export const importJsonFile = async function (filePath) {
7
+ const fileContents = await fs.readFile(filePath, 'utf-8');
8
+ return JSON.parse(fileContents);
9
+ };
10
+ const importJsonFileSync = function (filePath) {
11
+ // Use sync I/O so it is easier to migrate to `import()` later on
12
+ const fileContents = readFileSync(filePath, 'utf-8');
13
+ return JSON.parse(fileContents);
14
+ };
15
+ export const ROOT_PACKAGE_JSON = importJsonFileSync(ROOT_PACKAGE_JSON_PATH);
@@ -0,0 +1,3 @@
1
+ import filterObj from 'filter-obj';
2
+ // lodash.omit is 1400 lines of codes. filter-obj is much smaller and simpler.
3
+ export const omit = (obj, keys) => filterObj(obj, (key) => !keys.includes(key));
@@ -0,0 +1,24 @@
1
+ import { dirname } from 'path';
2
+ import { readPackageUp } from 'read-pkg-up';
3
+ /**
4
+ * Retrieve `package.json` from a specific directory
5
+ */
6
+ export const getPackageJson = async function (cwd, options = {}) {
7
+ const result = {
8
+ packageJson: {},
9
+ };
10
+ try {
11
+ const readResult = await readPackageUp({
12
+ cwd,
13
+ ...Object.assign({ normalize: true }, options),
14
+ });
15
+ if (readResult) {
16
+ result.packageJson = readResult.packageJson;
17
+ result.packageDir = dirname(readResult.path);
18
+ }
19
+ }
20
+ catch {
21
+ // continue regardless error
22
+ }
23
+ return result;
24
+ };
@@ -0,0 +1,8 @@
1
+ import filterObj from 'filter-obj';
2
+ // Remove falsy values from object
3
+ export const removeFalsy = function (obj) {
4
+ return filterObj(obj, isDefined);
5
+ };
6
+ const isDefined = function (key, value) {
7
+ return value !== undefined && value !== '';
8
+ };
@@ -0,0 +1,41 @@
1
+ import { createRequire } from 'module';
2
+ import { async as resolveLib } from 'resolve';
3
+ // TODO: use `import.resolve()` once it is available without any experimental
4
+ // flags
5
+ const require = createRequire(import.meta.url);
6
+ // Like `resolvePath()` but does not throw
7
+ export const tryResolvePath = async function (path, basedir) {
8
+ try {
9
+ const resolvedPath = await resolvePath(path, basedir);
10
+ return { path: resolvedPath };
11
+ }
12
+ catch (error) {
13
+ return { error };
14
+ }
15
+ };
16
+ // This throws if the package cannot be found
17
+ export const resolvePath = async function (path, basedir) {
18
+ try {
19
+ return await resolvePathWithBasedir(path, basedir);
20
+ // Fallback.
21
+ // `resolve` sometimes gives unhelpful error messages.
22
+ // https://github.com/browserify/resolve/issues/223
23
+ }
24
+ catch {
25
+ return require.resolve(path, { paths: [basedir] });
26
+ }
27
+ };
28
+ // Like `require.resolve()` but as an external library.
29
+ // We need to use `new Promise()` due to a bug with `utils.promisify()` on
30
+ // `resolve`:
31
+ // https://github.com/browserify/resolve/issues/151#issuecomment-368210310
32
+ const resolvePathWithBasedir = function (path, basedir) {
33
+ return new Promise((resolve, reject) => {
34
+ resolveLib(path, { basedir }, (error, resolvedPath) => {
35
+ if (error) {
36
+ return reject(error);
37
+ }
38
+ resolve(resolvedPath);
39
+ });
40
+ });
41
+ };
@@ -0,0 +1,5 @@
1
+ export const isRuntime = function (pluginOption) {
2
+ const { packageName } = pluginOption;
3
+ // Make this a bit more robust in the future
4
+ return ['@netlify/next-runtime', '@netlify/plugin-nextjs'].includes(packageName);
5
+ };
@@ -0,0 +1,28 @@
1
+ import semver from 'semver';
2
+ // Compare two versions by their major versions.
3
+ // Takes into account the special rules for `0.*.*` and `0.0.*` versions.
4
+ export const isPreviousMajor = function (versionA, versionB) {
5
+ return semver.lt(getMajor(versionA), getMajor(versionB));
6
+ };
7
+ // Remove minor/patch numbers
8
+ const getMajor = function (version) {
9
+ return semver.minVersion(getMajorVersion(version)).version;
10
+ };
11
+ // According to semver, the second number is the major release number for
12
+ // `0.*.*` versions and the third for `0.0.*`. This is how `^` behaves with the
13
+ // `semver` module which is used by `npm`.
14
+ export const getMajorVersion = function (version) {
15
+ if (!version || semver.clean(version) === null) {
16
+ return;
17
+ }
18
+ const majorVersion = semver.major(version);
19
+ if (majorVersion !== 0) {
20
+ return `${majorVersion}`;
21
+ }
22
+ const minorVersion = semver.minor(version);
23
+ if (minorVersion !== 0) {
24
+ return `${majorVersion}.${minorVersion}`;
25
+ }
26
+ const patchVersion = semver.patch(version);
27
+ return `${majorVersion}.${minorVersion}.${patchVersion}`;
28
+ };
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "@netlify/build",
3
- "version": "29.0.1-rc",
3
+ "version": "29.0.2",
4
4
  "description": "Netlify build module",
5
5
  "type": "module",
6
- "exports": "./src/core/main.js",
7
- "main": "./src/core/main.js",
8
- "types": "types/index.d.ts",
6
+ "exports": "./lib/core/main.js",
7
+ "main": "./lib/core/main.js",
8
+ "types": "./types/index.d.ts",
9
9
  "bin": {
10
- "netlify-build": "./src/core/bin.js"
10
+ "netlify-build": "./bin.js"
11
11
  },
12
12
  "files": [
13
- "src/**/*.js",
14
- "src/**/*.yml",
13
+ "bin.js",
14
+ "lib/**/*.js",
15
+ "lib/**/*.yml",
15
16
  "types/**/*.d.ts"
16
17
  ],
17
18
  "author": "Netlify Inc.",
@@ -20,7 +21,14 @@
20
21
  "Swyx <swyx@netlify.com> (https://www.swyx.io)"
21
22
  ],
22
23
  "scripts": {
23
- "prepublishOnly": "cd ../../ && npm run prepublishOnly"
24
+ "prebuild": "rm -rf lib",
25
+ "postbuild": "npx copyfiles \"src/**/*.yml\" lib/ -u 1",
26
+ "build": "tsc",
27
+ "pretest": "tsd .",
28
+ "test": "ava",
29
+ "test:dev": "ava -w",
30
+ "test:ci": "c8 -r lcovonly -r text -r json ava",
31
+ "test:measure": "../../tools/tests-duration.js"
24
32
  },
25
33
  "keywords": [
26
34
  "nodejs",
@@ -56,18 +64,15 @@
56
64
  "license": "MIT",
57
65
  "dependencies": {
58
66
  "@bugsnag/js": "^7.0.0",
59
- "@netlify/edge-bundler": "^1.12.1",
60
- "@netlify/cache-utils": "^4.0.0",
61
- "@netlify/config": "^18.1.4",
62
- "@netlify/functions-utils": "^4.2.3",
63
- "@netlify/git-utils": "^4.0.0",
64
- "@netlify/plugins-list": "^6.36.0",
65
- "@netlify/run-utils": "^4.0.0",
66
- "@netlify/zip-it-and-ship-it": "5.13.4",
67
+ "@netlify/cache-utils": "^5.0.2",
68
+ "@netlify/config": "^20.0.2",
69
+ "@netlify/edge-bundler": "5.3.2",
70
+ "@netlify/functions-utils": "^5.0.5",
71
+ "@netlify/git-utils": "^5.0.2",
72
+ "@netlify/plugins-list": "^6.58.0",
73
+ "@netlify/run-utils": "^5.0.2",
74
+ "@netlify/zip-it-and-ship-it": "^7.1.3",
67
75
  "@sindresorhus/slugify": "^2.0.0",
68
- "@types/node": "^16.0.0",
69
- "ajv": "^8.11.0",
70
- "ajv-errors": "^3.0.0",
71
76
  "ansi-escapes": "^5.0.0",
72
77
  "chalk": "^5.0.0",
73
78
  "clean-stack": "^4.0.0",
@@ -104,17 +109,22 @@
104
109
  "string-width": "^5.0.0",
105
110
  "strip-ansi": "^7.0.0",
106
111
  "supports-color": "^9.0.0",
112
+ "terminal-link": "^3.0.0",
107
113
  "tmp-promise": "^3.0.2",
108
114
  "ts-node": "^10.6.0",
109
- "typescript": "^4.5.4",
115
+ "typescript": "^4.8.4",
110
116
  "update-notifier": "^5.0.0",
111
117
  "uuid": "^8.0.0",
112
- "yargs": "^17.3.1"
118
+ "yargs": "^17.6.0"
113
119
  },
114
120
  "devDependencies": {
115
- "@netlify/nock-udp": "^1.0.0",
121
+ "@netlify/nock-udp": "^3.0.1",
122
+ "@types/node": "^14.18.31",
123
+ "@types/statsd-client": "^0.4.3",
116
124
  "atob": "^2.1.2",
117
125
  "ava": "^4.0.0",
126
+ "c8": "^7.12.0",
127
+ "copyfiles": "^2.4.1",
118
128
  "cpy": "^8.1.0",
119
129
  "del": "^6.0.0",
120
130
  "fast-safe-stringify": "^2.0.7",
@@ -128,9 +138,16 @@
128
138
  "path-key": "^4.0.0",
129
139
  "process-exists": "^5.0.0",
130
140
  "sinon": "^13.0.0",
141
+ "tsd": "^0.24.1",
131
142
  "yarn": "^1.22.4"
132
143
  },
133
144
  "engines": {
134
- "node": "^12.20.0 || ^14.14.0 || >=16.0.0"
135
- }
145
+ "node": "^14.16.0 || >=16.0.0"
146
+ },
147
+ "tsd": {
148
+ "compilerOptions": {
149
+ "module": "commonjs"
150
+ }
151
+ },
152
+ "gitHead": "60dd08db0498f62bf087428679444014f5b464f7"
136
153
  }
@@ -22,9 +22,9 @@ interface Header {
22
22
  values: Partial<Record<string, Many<string, 'mutable'>>>
23
23
  }
24
24
 
25
- interface EdgeHandler {
25
+ interface EdgeFunction {
26
26
  path?: `/${string}`
27
- handler: string
27
+ function: string
28
28
  }
29
29
 
30
30
  interface NetlifyPlugin {
@@ -44,9 +44,9 @@ interface NetlifyConfig {
44
44
  */
45
45
  headers: Header[]
46
46
  /**
47
- * array of Edge Handlers with their modifiable options
47
+ * array of Edge Functions with their modifiable options
48
48
  */
49
- edge_handlers: EdgeHandler[]
49
+ edge_functions: EdgeFunction[]
50
50
  /**
51
51
  * object with options for modifying [functions](https://docs.netlify.com/configure-builds/file-based-configuration/#functions)
52
52
  */
@@ -14,10 +14,10 @@ export interface NetlifyPluginConstants {
14
14
  */
15
15
  FUNCTIONS_SRC?: string
16
16
  /**
17
- * the directory where internal Edge Handlers source code lives. This is where build plugins should place auto-generated handlers.
18
- * `undefined` if the version of @netlify/build does not support internal Edge Handlers
17
+ * the directory where internal Edge Functions source code lives. This is where build plugins should place auto-generated functions.
18
+ * `undefined` if the version of @netlify/build does not support internal Edge Functions
19
19
  */
20
- INTERNAL_EDGE_HANDLERS_SRC?: string
20
+ INTERNAL_EDGE_FUNCTIONS_SRC?: string
21
21
  /**
22
22
  * the directory where internal function source code lives. This is where build plugins should place auto-generated functions.
23
23
  * `undefined` if the version of @netlify/build does not support internal functions
@@ -28,14 +28,14 @@ export interface NetlifyPluginConstants {
28
28
  */
29
29
  FUNCTIONS_DIST: string
30
30
  /**
31
- * the directory where built Edge Handlers are placed before deployment. Its value is always defined, but the target might not have been created yet.
31
+ * the directory where built Edge Functions are placed before deployment. Its value is always defined, but the target might not have been created yet.
32
32
  */
33
- EDGE_HANDLERS_DIST: string
33
+ EDGE_FUNCTIONS_DIST: string
34
34
  /**
35
- * the directory where Edge Handlers source code lives.
36
- * `undefined` if no `netlify/edge-handlers` directory exists in the base directory and if not specified in `netlify.toml`.
35
+ * the directory where Edge Functions source code lives.
36
+ * `undefined` if no `netlify/edge-functions` directory exists.
37
37
  */
38
- EDGE_HANDLERS_SRC?: string
38
+ EDGE_FUNCTIONS_SRC?: string
39
39
  /**
40
40
  * boolean indicating whether the build was [run locally](https://docs.netlify.com/cli/get-started/#run-builds-locally) or on Netlify
41
41
  */
package/src/core/bin.js DELETED
@@ -1,83 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import process from 'process'
4
-
5
- import filterObj from 'filter-obj'
6
- import yargs from 'yargs'
7
- import { hideBin } from 'yargs/helpers'
8
-
9
- import { normalizeCliFeatureFlags } from './feature_flags.js'
10
- import { FLAGS } from './flags.js'
11
- import build from './main.js'
12
- import { FALLBACK_SEVERITY_ENTRY } from './severity.js'
13
-
14
- // CLI entry point.
15
- // Before adding logic to this file, please consider adding it to the main
16
- // programmatic command instead, so that the new logic is available when run
17
- // programmatically as well. This file should only contain logic that makes
18
- // sense only in CLI, such as CLI flags parsing and exit code.
19
- const runCli = async function () {
20
- const flags = parseFlags()
21
- const flagsA = filterObj(flags, isUserFlag)
22
-
23
- const state = { done: false }
24
- process.on('exit', onExit.bind(undefined, state))
25
-
26
- const { severityCode, logs } = await build(flagsA)
27
- printLogs(logs)
28
- process.exitCode = severityCode
29
-
30
- state.done = true
31
- }
32
-
33
- const parseFlags = function () {
34
- const { featureFlags: cliFeatureFlags = '', ...flags } = yargs(hideBin(process.argv))
35
- .options(FLAGS)
36
- .usage(USAGE)
37
- .parse()
38
- const featureFlags = normalizeCliFeatureFlags(cliFeatureFlags)
39
- return { ...flags, featureFlags }
40
- }
41
-
42
- const USAGE = `netlify-build [OPTIONS...]
43
-
44
- Run Netlify Build system locally.
45
-
46
- Options can also be specified as environment variables prefixed with
47
- NETLIFY_BUILD_. For example the environment variable NETLIFY_BUILD_DRY=true can
48
- be used instead of the CLI flag --dry.`
49
-
50
- // Remove `yargs`-specific options, shortcuts, dash-cased and aliases
51
- const isUserFlag = function (key, value) {
52
- return value !== undefined && !INTERNAL_KEYS.has(key) && key.length !== 1 && !key.includes('-')
53
- }
54
-
55
- const INTERNAL_KEYS = new Set(['help', 'version', '_', '$0', 'dryRun'])
56
-
57
- // Used mostly for testing
58
- const printLogs = function (logs) {
59
- if (logs === undefined) {
60
- return
61
- }
62
-
63
- const allLogs = [logs.stdout.join('\n'), logs.stderr.join('\n')].filter(Boolean).join('\n\n')
64
- console.log(allLogs)
65
- }
66
-
67
- // In theory, the main process should not exit until the main `build()` function
68
- // has completed. In practice, this might happen due to bugs.
69
- // Making the exit code not 0 in that case ensures the caller knows that the
70
- // build has completed when the exit code is 0. This `exit` event handlers
71
- // guarantees this.
72
- const onExit = function ({ done }, exitCode) {
73
- if (done || exitCode !== 0) {
74
- return
75
- }
76
-
77
- const [, processName] = process.argv
78
- console.log(`${processName} exited with exit code ${exitCode} without finishing the build.`)
79
-
80
- process.exitCode = FALLBACK_SEVERITY_ENTRY.severityCode
81
- }
82
-
83
- runCli()