@netlify/build 27.20.4 → 27.20.6

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 (133) hide show
  1. package/lib/core/bin.js +42 -59
  2. package/lib/core/build.js +333 -536
  3. package/lib/core/config.js +94 -159
  4. package/lib/core/constants.js +95 -135
  5. package/lib/core/dev.js +26 -30
  6. package/lib/core/dry.js +18 -36
  7. package/lib/core/feature_flags.js +13 -16
  8. package/lib/core/flags.js +168 -169
  9. package/lib/core/lingering.js +44 -61
  10. package/lib/core/main.js +94 -136
  11. package/lib/core/missing_side_file.js +12 -24
  12. package/lib/core/normalize_flags.js +52 -63
  13. package/lib/core/severity.js +13 -15
  14. package/lib/core/user_node_version.js +26 -35
  15. package/lib/env/changes.js +29 -37
  16. package/lib/env/main.js +10 -15
  17. package/lib/env/metadata.js +63 -76
  18. package/lib/error/api.js +31 -40
  19. package/lib/error/build.js +27 -38
  20. package/lib/error/cancel.js +5 -6
  21. package/lib/error/colors.js +7 -9
  22. package/lib/error/handle.js +38 -49
  23. package/lib/error/info.js +26 -35
  24. package/lib/error/monitor/location.js +12 -17
  25. package/lib/error/monitor/normalize.js +75 -85
  26. package/lib/error/monitor/print.js +19 -41
  27. package/lib/error/monitor/report.js +102 -121
  28. package/lib/error/monitor/start.js +43 -56
  29. package/lib/error/parse/clean_stack.js +52 -69
  30. package/lib/error/parse/location.js +40 -52
  31. package/lib/error/parse/normalize.js +18 -23
  32. package/lib/error/parse/parse.js +59 -93
  33. package/lib/error/parse/plugin.js +42 -57
  34. package/lib/error/parse/properties.js +13 -20
  35. package/lib/error/parse/serialize_log.js +29 -37
  36. package/lib/error/parse/serialize_status.js +15 -23
  37. package/lib/error/parse/stack.js +29 -38
  38. package/lib/error/type.js +132 -150
  39. package/lib/install/functions.js +16 -24
  40. package/lib/install/local.js +31 -48
  41. package/lib/install/main.js +52 -66
  42. package/lib/install/missing.js +40 -53
  43. package/lib/log/colors.js +15 -22
  44. package/lib/log/description.js +16 -21
  45. package/lib/log/header.js +11 -13
  46. package/lib/log/header_func.js +11 -15
  47. package/lib/log/logger.js +88 -119
  48. package/lib/log/messages/compatibility.js +100 -158
  49. package/lib/log/messages/config.js +76 -92
  50. package/lib/log/messages/core.js +40 -60
  51. package/lib/log/messages/core_steps.js +63 -92
  52. package/lib/log/messages/dry.js +31 -53
  53. package/lib/log/messages/install.js +21 -28
  54. package/lib/log/messages/ipc.js +21 -30
  55. package/lib/log/messages/mutations.js +51 -71
  56. package/lib/log/messages/plugins.js +18 -31
  57. package/lib/log/messages/status.js +12 -14
  58. package/lib/log/messages/steps.js +14 -18
  59. package/lib/log/old_version.js +23 -32
  60. package/lib/log/serialize.js +7 -10
  61. package/lib/log/stream.js +48 -65
  62. package/lib/log/theme.js +22 -23
  63. package/lib/plugins/child/diff.js +31 -40
  64. package/lib/plugins/child/error.js +20 -26
  65. package/lib/plugins/child/lazy.js +11 -14
  66. package/lib/plugins/child/load.js +15 -22
  67. package/lib/plugins/child/logic.js +51 -58
  68. package/lib/plugins/child/main.js +32 -46
  69. package/lib/plugins/child/run.js +18 -27
  70. package/lib/plugins/child/status.js +52 -63
  71. package/lib/plugins/child/typescript.js +19 -36
  72. package/lib/plugins/child/utils.js +36 -49
  73. package/lib/plugins/child/validate.js +25 -28
  74. package/lib/plugins/compatibility.js +64 -92
  75. package/lib/plugins/error.js +29 -35
  76. package/lib/plugins/events.js +7 -12
  77. package/lib/plugins/expected_version.js +61 -99
  78. package/lib/plugins/ipc.js +79 -102
  79. package/lib/plugins/list.js +49 -62
  80. package/lib/plugins/load.js +44 -64
  81. package/lib/plugins/manifest/check.js +64 -85
  82. package/lib/plugins/manifest/load.js +34 -37
  83. package/lib/plugins/manifest/main.js +16 -21
  84. package/lib/plugins/manifest/path.js +18 -25
  85. package/lib/plugins/manifest/validate.js +77 -94
  86. package/lib/plugins/node_version.js +22 -42
  87. package/lib/plugins/options.js +45 -78
  88. package/lib/plugins/pinned_version.js +58 -106
  89. package/lib/plugins/resolve.js +91 -133
  90. package/lib/plugins/spawn.js +43 -61
  91. package/lib/plugins_core/add.js +26 -40
  92. package/lib/plugins_core/build_command.js +47 -72
  93. package/lib/plugins_core/deploy/buildbot_client.js +61 -87
  94. package/lib/plugins_core/deploy/index.js +47 -71
  95. package/lib/plugins_core/edge_functions/index.js +73 -116
  96. package/lib/plugins_core/edge_functions/lib/error.js +13 -17
  97. package/lib/plugins_core/edge_functions/lib/internal_manifest.js +45 -55
  98. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +65 -80
  99. package/lib/plugins_core/functions/error.js +88 -128
  100. package/lib/plugins_core/functions/feature_flags.js +5 -5
  101. package/lib/plugins_core/functions/index.js +98 -145
  102. package/lib/plugins_core/functions/utils.js +36 -57
  103. package/lib/plugins_core/functions/zisi.js +35 -52
  104. package/lib/plugins_core/functions_install/index.js +8 -11
  105. package/lib/plugins_core/list.js +15 -22
  106. package/lib/status/add.js +26 -32
  107. package/lib/status/colors.js +14 -19
  108. package/lib/status/load_error.js +8 -9
  109. package/lib/status/report.js +72 -126
  110. package/lib/status/success.js +10 -14
  111. package/lib/steps/core_step.js +54 -89
  112. package/lib/steps/error.js +50 -87
  113. package/lib/steps/get.js +33 -41
  114. package/lib/steps/plugin.js +53 -83
  115. package/lib/steps/return.js +24 -51
  116. package/lib/steps/run_core_steps.js +119 -171
  117. package/lib/steps/run_step.js +154 -270
  118. package/lib/steps/run_steps.js +91 -174
  119. package/lib/steps/update_config.js +45 -72
  120. package/lib/telemetry/main.js +89 -128
  121. package/lib/time/aggregate.js +84 -110
  122. package/lib/time/main.js +23 -34
  123. package/lib/time/measure.js +11 -15
  124. package/lib/time/report.js +32 -44
  125. package/lib/utils/errors.js +10 -9
  126. package/lib/utils/json.js +11 -15
  127. package/lib/utils/omit.js +3 -4
  128. package/lib/utils/package.js +19 -22
  129. package/lib/utils/remove_falsy.js +5 -7
  130. package/lib/utils/resolve.js +30 -34
  131. package/lib/utils/runtime.js +4 -4
  132. package/lib/utils/semver.js +19 -25
  133. package/package.json +14 -7
@@ -1,146 +1,120 @@
1
- import { createTimer, TOP_PARENT_TAG } from './main.js'
2
-
1
+ import { createTimer, TOP_PARENT_TAG } from './main.js';
3
2
  // Some timers are computed based on others:
4
3
  // - `others` is `total` minus the other timers
5
4
  // - `run_plugins` is the sum of all plugins
6
5
  // - `run_netlify_build_per_type` aggregates timers but per system/plugin/user
7
6
  // - each plugin timer is the sum of its event handlers
8
7
  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
-
8
+ const timersA = addRunPluginsTimer(timers);
9
+ const timersB = addPluginTimers(timersA);
10
+ const timersC = addOthersTimers(timersB);
11
+ const timersD = addTypeTimers(timersC);
12
+ return timersD;
13
+ };
16
14
  // Having a `total` timer is redundant since the buildbot already measures this.
17
15
  // The buildbot measurement is better since it includes the time to load Node.
18
16
  // Instead, we only use `total` to measure what did not get `measureDuration()`.
19
17
  const addOthersTimers = function (timers) {
20
- const totalTimer = timers.find(isTotalTimer)
21
- const timersA = timers.filter((timer) => !isTotalTimer(timer))
22
- const topTimers = timersA.filter(isTopTimer)
23
- const othersTimer = createOthersTimer(topTimers, totalTimer)
24
- return [...timersA, othersTimer]
25
- }
26
-
18
+ const totalTimer = timers.find(isTotalTimer);
19
+ const timersA = timers.filter((timer) => !isTotalTimer(timer));
20
+ const topTimers = timersA.filter(isTopTimer);
21
+ const othersTimer = createOthersTimer(topTimers, totalTimer);
22
+ return [...timersA, othersTimer];
23
+ };
27
24
  const isTotalTimer = function ({ stageTag, parentTag }) {
28
- return stageTag === 'total' && parentTag === 'build_site'
29
- }
30
-
25
+ return stageTag === 'total' && parentTag === 'build_site';
26
+ };
31
27
  const createOthersTimer = function (topTimers, { durationNs: totalTimerDurationNs }) {
32
- const topTimersDurationNs = computeTimersDuration(topTimers)
33
- const otherTimersDurationNs = Math.max(0, totalTimerDurationNs - topTimersDurationNs)
34
- const othersTimer = createTimer(OTHERS_STAGE_TAG, otherTimersDurationNs)
35
- return othersTimer
36
- }
37
-
38
- const OTHERS_STAGE_TAG = 'others'
39
-
28
+ const topTimersDurationNs = computeTimersDuration(topTimers);
29
+ const otherTimersDurationNs = Math.max(0, totalTimerDurationNs - topTimersDurationNs);
30
+ const othersTimer = createTimer(OTHERS_STAGE_TAG, otherTimersDurationNs);
31
+ return othersTimer;
32
+ };
33
+ const OTHERS_STAGE_TAG = 'others';
40
34
  // Measure the total time running plugins
41
35
  const addRunPluginsTimer = function (timers) {
42
- const pluginsTimers = timers.filter(isPluginTimer)
43
- return pluginsTimers.length === 0 ? timers : [...timers, createSumTimer(pluginsTimers, RUN_PLUGINS_STAGE_TAG)]
44
- }
45
-
46
- const RUN_PLUGINS_STAGE_TAG = 'run_plugins'
47
-
36
+ const pluginsTimers = timers.filter(isPluginTimer);
37
+ return pluginsTimers.length === 0 ? timers : [...timers, createSumTimer(pluginsTimers, RUN_PLUGINS_STAGE_TAG)];
38
+ };
39
+ const RUN_PLUGINS_STAGE_TAG = 'run_plugins';
48
40
  // Retrieve one timer for each plugin, summing all its individual timers
49
41
  // (one per event handler)
50
42
  const addPluginTimers = function (timers) {
51
- const timersA = timers.filter((timer) => !isCommunityPluginTimer(timer))
52
- const pluginsTimers = timersA.filter(isPluginTimer)
53
- if (pluginsTimers.length === 0) {
54
- return timersA
55
- }
56
-
57
- const pluginPackages = getPluginPackages(pluginsTimers)
58
- const wholePluginsTimers = pluginPackages.map((pluginPackage) => getWholePluginTimer(pluginPackage, pluginsTimers))
59
- return [...timersA, ...wholePluginsTimers]
60
- }
61
-
43
+ const timersA = timers.filter((timer) => !isCommunityPluginTimer(timer));
44
+ const pluginsTimers = timersA.filter(isPluginTimer);
45
+ if (pluginsTimers.length === 0) {
46
+ return timersA;
47
+ }
48
+ const pluginPackages = getPluginPackages(pluginsTimers);
49
+ const wholePluginsTimers = pluginPackages.map((pluginPackage) => getWholePluginTimer(pluginPackage, pluginsTimers));
50
+ return [...timersA, ...wholePluginsTimers];
51
+ };
62
52
  // We only measure plugins maintained by us, not community
63
53
  const isCommunityPluginTimer = function (timer) {
64
- return isPluginTimer(timer) && !isNetlifyMaintainedPlugin(getPluginTimerPackage(timer))
65
- }
66
-
54
+ return isPluginTimer(timer) && !isNetlifyMaintainedPlugin(getPluginTimerPackage(timer));
55
+ };
67
56
  const isNetlifyMaintainedPlugin = function (pluginPackage) {
68
- return NETLIFY_MAINTAINED_PLUGINS.has(pluginPackage)
69
- }
70
-
57
+ return NETLIFY_MAINTAINED_PLUGINS.has(pluginPackage);
58
+ };
71
59
  const NETLIFY_MAINTAINED_PLUGINS = new Set([
72
- 'netlify_plugin_gatsby_cache',
73
- 'netlify_plugin_sitemap',
74
- 'netlify_plugin_debug_cache',
75
- 'netlify_plugin_is_website_vulnerable',
76
- 'netlify_plugin_lighthouse',
77
- 'netlify_plugin_nextjs',
78
- 'netlify_plugin_gatsby',
79
- ])
80
-
60
+ 'netlify_plugin_gatsby_cache',
61
+ 'netlify_plugin_sitemap',
62
+ 'netlify_plugin_debug_cache',
63
+ 'netlify_plugin_is_website_vulnerable',
64
+ 'netlify_plugin_lighthouse',
65
+ 'netlify_plugin_nextjs',
66
+ 'netlify_plugin_gatsby',
67
+ ]);
81
68
  const getPluginPackages = function (pluginsTimers) {
82
- const pluginPackages = pluginsTimers.map(getPluginTimerPackage)
83
- return [...new Set(pluginPackages)]
84
- }
85
-
69
+ const pluginPackages = pluginsTimers.map(getPluginTimerPackage);
70
+ return [...new Set(pluginPackages)];
71
+ };
86
72
  const getWholePluginTimer = function (pluginPackage, pluginsTimers) {
87
- const pluginTimers = pluginsTimers.filter((pluginTimer) => getPluginTimerPackage(pluginTimer) === pluginPackage)
88
- const wholePluginsTimer = createSumTimer(pluginTimers, pluginPackage, RUN_PLUGINS_STAGE_TAG)
89
- return wholePluginsTimer
90
- }
91
-
73
+ const pluginTimers = pluginsTimers.filter((pluginTimer) => getPluginTimerPackage(pluginTimer) === pluginPackage);
74
+ const wholePluginsTimer = createSumTimer(pluginTimers, pluginPackage, RUN_PLUGINS_STAGE_TAG);
75
+ return wholePluginsTimer;
76
+ };
92
77
  const getPluginTimerPackage = function ({ parentTag }) {
93
- return parentTag
94
- }
95
-
78
+ return parentTag;
79
+ };
96
80
  // Check if a timer relates to a Build plugin
97
81
  const isPluginTimer = function ({ category }) {
98
- return category === 'pluginEvent'
99
- }
100
-
82
+ return category === 'pluginEvent';
83
+ };
101
84
  // Reports total time depending on whether it was system, plugin or user
102
85
  const addTypeTimers = function (timers) {
103
- const topTimers = timers.filter(isTopTimer)
104
- const typeTimers = TYPE_TIMERS.map(({ name, stages }) => getTypeTimer(name, stages, topTimers)).filter(Boolean)
105
- return [...timers, ...typeTimers]
106
- }
107
-
86
+ const topTimers = timers.filter(isTopTimer);
87
+ const typeTimers = TYPE_TIMERS.map(({ name, stages }) => getTypeTimer(name, stages, topTimers)).filter(Boolean);
88
+ return [...timers, ...typeTimers];
89
+ };
108
90
  const TYPE_TIMERS = [
109
- { name: 'system', stages: ['resolve_config', 'get_plugins_options', 'start_plugins', 'others'] },
110
- { name: 'plugin', stages: ['load_plugins', 'run_plugins'] },
111
- { name: 'user', stages: ['build_command', 'functions_bundling', 'deploy_site'] },
112
- ]
113
-
91
+ { name: 'system', stages: ['resolve_config', 'get_plugins_options', 'start_plugins', 'others'] },
92
+ { name: 'plugin', stages: ['load_plugins', 'run_plugins'] },
93
+ { name: 'user', stages: ['build_command', 'functions_bundling', 'deploy_site'] },
94
+ ];
114
95
  const getTypeTimer = function (name, stages, topTimers) {
115
- const topTimersA = topTimers.filter(({ stageTag }) => stages.includes(stageTag))
116
-
117
- if (topTimersA.length === 0) {
118
- return
119
- }
120
-
121
- const typeTimer = createSumTimer(topTimersA, name, 'run_netlify_build_per_type')
122
- return typeTimer
123
- }
124
-
96
+ const topTimersA = topTimers.filter(({ stageTag }) => stages.includes(stageTag));
97
+ if (topTimersA.length === 0) {
98
+ return;
99
+ }
100
+ const typeTimer = createSumTimer(topTimersA, name, 'run_netlify_build_per_type');
101
+ return typeTimer;
102
+ };
125
103
  const isTopTimer = function ({ parentTag }) {
126
- return parentTag === TOP_PARENT_TAG
127
- }
128
-
104
+ return parentTag === TOP_PARENT_TAG;
105
+ };
129
106
  // Creates a timer that sums up the duration of several others
130
107
  const createSumTimer = function (timers, stageTag, parentTag) {
131
- const durationNs = computeTimersDuration(timers)
132
- const timer = createTimer(stageTag, durationNs, { parentTag })
133
- return timer
134
- }
135
-
108
+ const durationNs = computeTimersDuration(timers);
109
+ const timer = createTimer(stageTag, durationNs, { parentTag });
110
+ return timer;
111
+ };
136
112
  const computeTimersDuration = function (timers) {
137
- return timers.map(getTimerDuration).reduce(reduceSum, 0)
138
- }
139
-
113
+ return timers.map(getTimerDuration).reduce(reduceSum, 0);
114
+ };
140
115
  const getTimerDuration = function ({ durationNs }) {
141
- return durationNs
142
- }
143
-
116
+ return durationNs;
117
+ };
144
118
  const reduceSum = function (sum, number) {
145
- return sum + number
146
- }
119
+ return sum + number;
120
+ };
package/lib/time/main.js CHANGED
@@ -1,13 +1,10 @@
1
- import slugify from '@sindresorhus/slugify'
2
- import keepFuncProps from 'keep-func-props'
3
-
4
- import { startTimer, endTimer } from './measure.js'
5
-
1
+ import slugify from '@sindresorhus/slugify';
2
+ import keepFuncProps from 'keep-func-props';
3
+ import { startTimer, endTimer } from './measure.js';
6
4
  // Initialize the `timers` array
7
5
  export const initTimers = function () {
8
- return []
9
- }
10
-
6
+ return [];
7
+ };
11
8
  // Wrap an async function to measure how long it takes.
12
9
  // The function must:
13
10
  // - take a plain object as first argument. This must contain a `timers`.
@@ -15,34 +12,26 @@ export const initTimers = function () {
15
12
  // The `durationNs` will be returned by the function. A new `timers` with the
16
13
  // additional duration timer will be returned as well.
17
14
  const kMeasureDuration = function (func, stageTag, { parentTag, category } = {}) {
18
- return async function measuredFunc({ timers, ...opts }, ...args) {
19
- const timerNs = startTimer()
20
- const { timers: timersA = timers, ...returnObject } = await func({ timers, ...opts }, ...args)
21
- const { tags = {} } = returnObject
22
- const durationNs = endTimer(timerNs)
23
- const timer = createTimer(stageTag, durationNs, { parentTag, category, tags })
24
- const timersB = [...timersA, timer]
25
- return { ...returnObject, timers: timersB, durationNs }
26
- }
27
- }
28
-
15
+ return async function measuredFunc({ timers, ...opts }, ...args) {
16
+ const timerNs = startTimer();
17
+ const { timers: timersA = timers, ...returnObject } = await func({ timers, ...opts }, ...args);
18
+ const { tags = {} } = returnObject;
19
+ const durationNs = endTimer(timerNs);
20
+ const timer = createTimer(stageTag, durationNs, { parentTag, category, tags });
21
+ const timersB = [...timersA, timer];
22
+ return { ...returnObject, timers: timersB, durationNs };
23
+ };
24
+ };
29
25
  // Ensure the wrapped function `name` is not `anonymous` in stack traces
30
- export const measureDuration = keepFuncProps(kMeasureDuration)
31
-
26
+ export const measureDuration = keepFuncProps(kMeasureDuration);
32
27
  // Create a new object representing a completed timer
33
- export const createTimer = function (
34
- stageTag,
35
- durationNs,
36
- { metricName = DEFAULT_METRIC_NAME, parentTag = TOP_PARENT_TAG, category, tags } = {},
37
- ) {
38
- return { metricName, stageTag, parentTag, durationNs, category, tags }
39
- }
40
-
41
- const DEFAULT_METRIC_NAME = 'buildbot.build.stage.duration'
42
- export const TOP_PARENT_TAG = 'run_netlify_build'
43
-
28
+ export const createTimer = function (stageTag, durationNs, { metricName = DEFAULT_METRIC_NAME, parentTag = TOP_PARENT_TAG, category, tags } = {}) {
29
+ return { metricName, stageTag, parentTag, durationNs, category, tags };
30
+ };
31
+ const DEFAULT_METRIC_NAME = 'buildbot.build.stage.duration';
32
+ export const TOP_PARENT_TAG = 'run_netlify_build';
44
33
  // Make sure the timer name does not include special characters.
45
34
  // For example, the `packageName` of local plugins includes dots.
46
35
  export const normalizeTimerName = function (name) {
47
- return slugify(name, { separator: '_' })
48
- }
36
+ return slugify(name, { separator: '_' });
37
+ };
@@ -1,22 +1,18 @@
1
- import { hrtime } from 'process'
2
-
1
+ import { hrtime } from 'process';
3
2
  // Starts a timer
4
3
  export const startTimer = function () {
5
- return hrtime()
6
- }
7
-
4
+ return hrtime();
5
+ };
8
6
  // Stops a timer
9
7
  export const endTimer = function ([startSecs, startNsecs]) {
10
- const [endSecs, endNsecs] = hrtime()
11
- const durationNs = (endSecs - startSecs) * NANOSECS_TO_SECS + endNsecs - startNsecs
12
- return durationNs
13
- }
14
-
8
+ const [endSecs, endNsecs] = hrtime();
9
+ const durationNs = (endSecs - startSecs) * NANOSECS_TO_SECS + endNsecs - startNsecs;
10
+ return durationNs;
11
+ };
15
12
  // statsd expects milliseconds integers.
16
13
  // To prevent double rounding errors, rounding should only be applied once.
17
14
  export const roundTimerToMillisecs = function (durationNs) {
18
- return Math.round(durationNs / NANOSECS_TO_MSECS)
19
- }
20
-
21
- const NANOSECS_TO_SECS = 1e9
22
- const NANOSECS_TO_MSECS = 1e6
15
+ return Math.round(durationNs / NANOSECS_TO_MSECS);
16
+ };
17
+ const NANOSECS_TO_SECS = 1e9;
18
+ const NANOSECS_TO_MSECS = 1e6;
@@ -1,59 +1,47 @@
1
- import { promisify } from 'util'
2
-
3
- import StatsdClient from 'statsd-client'
4
-
5
- import { addAggregatedTimers } from './aggregate.js'
6
- import { roundTimerToMillisecs } from './measure.js'
7
-
1
+ import { promisify } from 'util';
2
+ import StatsdClient from 'statsd-client';
3
+ import { addAggregatedTimers } from './aggregate.js';
4
+ import { roundTimerToMillisecs } from './measure.js';
8
5
  // TODO: replace with `timers/promises` after dropping Node < 15.0.0
9
- const pSetTimeout = promisify(setTimeout)
10
-
6
+ const pSetTimeout = promisify(setTimeout);
11
7
  // Record the duration of a build phase, for monitoring.
12
8
  // Sends to statsd daemon.
13
9
  export const reportTimers = async function ({ timers, statsdOpts: { host, port }, framework }) {
14
- if (host === undefined) {
15
- return
16
- }
17
-
18
- const timersA = addAggregatedTimers(timers)
19
- await sendTimers({ timers: timersA, host, port, framework })
20
- }
21
-
10
+ if (host === undefined) {
11
+ return;
12
+ }
13
+ const timersA = addAggregatedTimers(timers);
14
+ await sendTimers({ timers: timersA, host, port, framework });
15
+ };
22
16
  const sendTimers = async function ({ timers, host, port, framework }) {
23
- const client = await startClient(host, port)
24
- timers.forEach((timer) => {
25
- sendTimer({ timer, client, framework })
26
- })
27
- await closeClient(client)
28
- }
29
-
17
+ const client = await startClient(host, port);
18
+ timers.forEach((timer) => {
19
+ sendTimer({ timer, client, framework });
20
+ });
21
+ await closeClient(client);
22
+ };
30
23
  // The socket creation is delayed until the first packet is sent. In our
31
24
  // case, this happens just before `client.close()` is called, which is too
32
25
  // late and make it not send anything. We need to manually create it using
33
26
  // the internal API.
34
27
  const startClient = async function (host, port) {
35
- const client = new StatsdClient({ host, port, socketTimeout: 0 })
36
-
37
- await promisify(client._socket._createSocket.bind(client._socket))()
38
- return client
39
- }
40
-
28
+ const client = new StatsdClient({ host, port, socketTimeout: 0 });
29
+ await promisify(client._socket._createSocket.bind(client._socket))();
30
+ return client;
31
+ };
41
32
  const sendTimer = function ({ timer: { metricName, stageTag, parentTag, durationNs, tags }, client, framework }) {
42
- const durationMs = roundTimerToMillisecs(durationNs)
43
- const frameworkTag = framework === undefined ? {} : { framework }
44
- client.distribution(metricName, durationMs, { stage: stageTag, parent: parentTag, ...tags, ...frameworkTag })
45
- }
46
-
33
+ const durationMs = roundTimerToMillisecs(durationNs);
34
+ const frameworkTag = framework === undefined ? {} : { framework };
35
+ client.distribution(metricName, durationMs, { stage: stageTag, parent: parentTag, ...tags, ...frameworkTag });
36
+ };
47
37
  // UDP packets are buffered and flushed at regular intervals by statsd-client.
48
38
  // Closing force flushing all of them.
49
39
  const closeClient = async function (client) {
50
- client.close()
51
-
52
- // statsd-clent does not provide with a way of knowing when the socket is done
53
- // closing, so we need to use the following hack.
54
- await pSetTimeout(CLOSE_TIMEOUT)
55
- await pSetTimeout(CLOSE_TIMEOUT)
56
- }
57
-
40
+ client.close();
41
+ // statsd-clent does not provide with a way of knowing when the socket is done
42
+ // closing, so we need to use the following hack.
43
+ await pSetTimeout(CLOSE_TIMEOUT);
44
+ await pSetTimeout(CLOSE_TIMEOUT);
45
+ };
58
46
  // See https://github.com/msiebuhr/node-statsd-client/blob/45a93ee4c94ca72f244a40b06cb542d4bd7c3766/lib/EphemeralSocket.js#L81
59
- const CLOSE_TIMEOUT = 11
47
+ const CLOSE_TIMEOUT = 11;
@@ -1,12 +1,13 @@
1
1
  // Wrap an async function so it prepends an error message on exceptions.
2
2
  // This helps locate errors.
3
3
  export const addAsyncErrorMessage = function (asyncFunc, message) {
4
- return async (...args) => {
5
- try {
6
- return await asyncFunc(...args)
7
- } catch (error) {
8
- error.stack = `${message}: ${error.stack}`
9
- throw error
10
- }
11
- }
12
- }
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
+ };
package/lib/utils/json.js CHANGED
@@ -1,19 +1,15 @@
1
- import { promises as fs, readFileSync } from 'fs'
2
- import { fileURLToPath } from 'url'
3
-
4
- const ROOT_PACKAGE_JSON_PATH = fileURLToPath(new URL('../../package.json', import.meta.url))
5
-
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));
6
4
  // TODO: Replace with dynamic `import()` once it is supported without
7
5
  // experimental flags
8
6
  export const importJsonFile = async function (filePath) {
9
- const fileContents = await fs.readFile(filePath)
10
- return JSON.parse(fileContents)
11
- }
12
-
7
+ const fileContents = await fs.readFile(filePath);
8
+ return JSON.parse(fileContents);
9
+ };
13
10
  const importJsonFileSync = function (filePath) {
14
- // Use sync I/O so it is easier to migrate to `import()` later on
15
- const fileContents = readFileSync(filePath, 'utf8')
16
- return JSON.parse(fileContents)
17
- }
18
-
19
- export const ROOT_PACKAGE_JSON = importJsonFileSync(ROOT_PACKAGE_JSON_PATH)
11
+ // Use sync I/O so it is easier to migrate to `import()` later on
12
+ const fileContents = readFileSync(filePath, 'utf8');
13
+ return JSON.parse(fileContents);
14
+ };
15
+ export const ROOT_PACKAGE_JSON = importJsonFileSync(ROOT_PACKAGE_JSON_PATH);
package/lib/utils/omit.js CHANGED
@@ -1,6 +1,5 @@
1
- import filterObj from 'filter-obj'
2
-
1
+ import filterObj from 'filter-obj';
3
2
  // lodash.omit is 1400 lines of codes. filter-obj is much smaller and simpler.
4
3
  export const omit = function (obj, keys) {
5
- return filterObj(obj, (key) => !keys.includes(key))
6
- }
4
+ return filterObj(obj, (key) => !keys.includes(key));
5
+ };
@@ -1,25 +1,22 @@
1
- import { dirname } from 'path'
2
-
3
- import { readPackageUp } from 'read-pkg-up'
4
-
1
+ import { dirname } from 'path';
2
+ import { readPackageUp } from 'read-pkg-up';
5
3
  // Retrieve `package.json` from a specific directory
6
4
  export const getPackageJson = async function (cwd, { normalize } = {}) {
7
- const packageObj = await getPackageObj({ cwd, normalize })
8
- if (packageObj === undefined) {
9
- return { packageJson: {} }
10
- }
11
-
12
- const { path, packageJson } = packageObj
13
- const packageDir = dirname(path)
14
- return { packageDir, packageJson }
15
- }
16
-
5
+ const packageObj = await getPackageObj({ cwd, normalize });
6
+ if (packageObj === undefined) {
7
+ return { packageJson: {} };
8
+ }
9
+ const { path, packageJson } = packageObj;
10
+ const packageDir = dirname(path);
11
+ return { packageDir, packageJson };
12
+ };
17
13
  const getPackageObj = async function ({ cwd, normalize = true }) {
18
- try {
19
- return await readPackageUp({ cwd, normalize })
20
- // If the `package.json` is invalid and `normalize` is `true`, an error is
21
- // thrown. We return `undefined` then.
22
- } catch {
23
- // continue regardless error
24
- }
25
- }
14
+ try {
15
+ return await readPackageUp({ cwd, normalize });
16
+ // If the `package.json` is invalid and `normalize` is `true`, an error is
17
+ // thrown. We return `undefined` then.
18
+ }
19
+ catch {
20
+ // continue regardless error
21
+ }
22
+ };
@@ -1,10 +1,8 @@
1
- import filterObj from 'filter-obj'
2
-
1
+ import filterObj from 'filter-obj';
3
2
  // Remove falsy values from object
4
3
  export const removeFalsy = function (obj) {
5
- return filterObj(obj, isDefined)
6
- }
7
-
4
+ return filterObj(obj, isDefined);
5
+ };
8
6
  const isDefined = function (key, value) {
9
- return value !== undefined && value !== ''
10
- }
7
+ return value !== undefined && value !== '';
8
+ };
@@ -1,45 +1,41 @@
1
- import { createRequire } from 'module'
2
-
3
- import { async as resolveLib } from 'resolve'
4
-
1
+ import { createRequire } from 'module';
2
+ import { async as resolveLib } from 'resolve';
5
3
  // TODO: use `import.resolve()` once it is available without any experimental
6
4
  // flags
7
- const require = createRequire(import.meta.url)
8
-
5
+ const require = createRequire(import.meta.url);
9
6
  // Like `resolvePath()` but does not throw
10
7
  export const tryResolvePath = async function (path, basedir) {
11
- try {
12
- const resolvedPath = await resolvePath(path, basedir)
13
- return { path: resolvedPath }
14
- } catch (error) {
15
- return { error }
16
- }
17
- }
18
-
8
+ try {
9
+ const resolvedPath = await resolvePath(path, basedir);
10
+ return { path: resolvedPath };
11
+ }
12
+ catch (error) {
13
+ return { error };
14
+ }
15
+ };
19
16
  // This throws if the package cannot be found
20
17
  export const resolvePath = async function (path, basedir) {
21
- try {
22
- return await resolvePathWithBasedir(path, basedir)
23
- // Fallback.
24
- // `resolve` sometimes gives unhelpful error messages.
25
- // https://github.com/browserify/resolve/issues/223
26
- } catch {
27
- return require.resolve(path, { paths: [basedir] })
28
- }
29
- }
30
-
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
+ };
31
28
  // Like `require.resolve()` but as an external library.
32
29
  // We need to use `new Promise()` due to a bug with `utils.promisify()` on
33
30
  // `resolve`:
34
31
  // https://github.com/browserify/resolve/issues/151#issuecomment-368210310
35
32
  const resolvePathWithBasedir = function (path, basedir) {
36
- return new Promise((resolve, reject) => {
37
- resolveLib(path, { basedir }, (error, resolvedPath) => {
38
- if (error) {
39
- return reject(error)
40
- }
41
-
42
- resolve(resolvedPath)
43
- })
44
- })
45
- }
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
+ };
@@ -1,5 +1,5 @@
1
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
- }
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
+ };