@netlify/build 28.0.0-beta → 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.
- package/bin.js +5 -0
- package/lib/core/bin.js +66 -0
- package/lib/core/build.js +355 -0
- package/lib/core/config.js +121 -0
- package/lib/core/constants.js +116 -0
- package/lib/core/dev.js +27 -0
- package/lib/core/dry.js +21 -0
- package/lib/core/feature_flags.js +19 -0
- package/lib/core/flags.js +201 -0
- package/lib/core/lingering.js +68 -0
- package/lib/core/main.js +123 -0
- package/lib/core/missing_side_file.js +17 -0
- package/lib/core/normalize_flags.js +59 -0
- package/lib/core/severity.js +20 -0
- package/lib/core/user_node_version.js +32 -0
- package/lib/env/changes.js +43 -0
- package/lib/env/main.js +14 -0
- package/lib/env/metadata.js +68 -0
- package/lib/error/api.js +37 -0
- package/lib/error/build.js +36 -0
- package/{src → lib}/error/cancel.js +5 -6
- package/lib/error/colors.js +9 -0
- package/lib/error/handle.js +46 -0
- package/lib/error/info.js +37 -0
- package/lib/error/monitor/location.js +16 -0
- package/lib/error/monitor/normalize.js +86 -0
- package/lib/error/monitor/print.js +20 -0
- package/lib/error/monitor/report.js +120 -0
- package/lib/error/monitor/start.js +58 -0
- package/lib/error/parse/clean_stack.js +70 -0
- package/lib/error/parse/location.js +50 -0
- package/lib/error/parse/normalize.js +24 -0
- package/lib/error/parse/parse.js +67 -0
- package/lib/error/parse/plugin.js +55 -0
- package/lib/error/parse/properties.js +16 -0
- package/lib/error/parse/serialize_log.js +34 -0
- package/lib/error/parse/serialize_status.js +18 -0
- package/lib/error/parse/stack.js +34 -0
- package/lib/error/type.js +171 -0
- package/lib/install/functions.js +20 -0
- package/lib/install/local.js +45 -0
- package/lib/install/main.js +67 -0
- package/lib/install/missing.js +54 -0
- package/{src → lib}/log/colors.js +15 -22
- package/lib/log/description.js +21 -0
- package/lib/log/header.js +14 -0
- package/lib/log/header_func.js +13 -0
- package/lib/log/logger.js +130 -0
- package/lib/log/messages/compatibility.js +120 -0
- package/lib/log/messages/config.js +91 -0
- package/lib/log/messages/core.js +50 -0
- package/lib/log/messages/core_steps.js +75 -0
- package/lib/log/messages/dry.js +41 -0
- package/lib/log/messages/install.js +25 -0
- package/lib/log/messages/ipc.js +29 -0
- package/lib/log/messages/mutations.js +62 -0
- package/{src → lib}/log/messages/plugins.js +18 -32
- package/lib/log/messages/status.js +14 -0
- package/lib/log/messages/steps.js +18 -0
- package/lib/log/old_version.js +32 -0
- package/lib/log/serialize.js +10 -0
- package/lib/log/stream.js +68 -0
- package/lib/log/theme.js +25 -0
- package/lib/plugins/child/diff.js +46 -0
- package/lib/plugins/child/error.js +26 -0
- package/lib/plugins/child/lazy.js +15 -0
- package/lib/plugins/child/load.js +22 -0
- package/lib/plugins/child/logic.js +57 -0
- package/lib/plugins/child/main.js +37 -0
- package/lib/plugins/child/run.js +19 -0
- package/lib/plugins/child/status.js +63 -0
- package/lib/plugins/child/typescript.js +28 -0
- package/lib/plugins/child/utils.js +42 -0
- package/lib/plugins/child/validate.js +31 -0
- package/lib/plugins/compatibility.js +104 -0
- package/{src → lib}/plugins/error.js +31 -35
- package/{src → lib}/plugins/events.js +7 -12
- package/lib/plugins/expected_version.js +81 -0
- package/lib/plugins/ipc.js +120 -0
- package/lib/plugins/list.js +73 -0
- package/lib/plugins/load.js +50 -0
- package/lib/plugins/manifest/check.js +85 -0
- package/lib/plugins/manifest/load.js +38 -0
- package/lib/plugins/manifest/main.js +17 -0
- package/lib/plugins/manifest/path.js +24 -0
- package/lib/plugins/manifest/validate.js +91 -0
- package/lib/plugins/node_version.js +30 -0
- package/lib/plugins/options.js +55 -0
- package/lib/plugins/pinned_version.js +83 -0
- package/lib/plugins/resolve.js +110 -0
- package/lib/plugins/spawn.js +54 -0
- package/lib/plugins_core/add.js +35 -0
- package/lib/plugins_core/build_command.js +50 -0
- package/lib/plugins_core/deploy/buildbot_client.js +87 -0
- package/lib/plugins_core/deploy/index.js +49 -0
- package/{src → lib}/plugins_core/deploy/manifest.yml +0 -0
- package/lib/plugins_core/edge_functions/index.js +79 -0
- package/lib/plugins_core/edge_functions/lib/error.js +17 -0
- package/lib/plugins_core/edge_functions/lib/internal_manifest.js +50 -0
- package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +75 -0
- package/lib/plugins_core/functions/error.js +123 -0
- package/lib/plugins_core/functions/feature_flags.js +6 -0
- package/lib/plugins_core/functions/index.js +114 -0
- package/lib/plugins_core/functions/utils.js +45 -0
- package/lib/plugins_core/functions/zisi.js +39 -0
- package/{src → lib}/plugins_core/functions_install/index.js +8 -11
- package/{src → lib}/plugins_core/functions_install/manifest.yml +0 -0
- package/lib/plugins_core/list.js +20 -0
- package/lib/status/add.js +30 -0
- package/lib/status/colors.js +18 -0
- package/lib/status/load_error.js +10 -0
- package/lib/status/report.js +83 -0
- package/lib/status/success.js +14 -0
- package/lib/steps/core_step.js +57 -0
- package/lib/steps/error.js +65 -0
- package/lib/steps/get.js +43 -0
- package/lib/steps/plugin.js +55 -0
- package/lib/steps/return.js +25 -0
- package/lib/steps/run_core_steps.js +147 -0
- package/lib/steps/run_step.js +188 -0
- package/lib/steps/run_steps.js +96 -0
- package/lib/steps/update_config.js +66 -0
- package/lib/telemetry/main.js +97 -0
- package/lib/time/aggregate.js +120 -0
- package/lib/time/main.js +37 -0
- package/lib/time/measure.js +18 -0
- package/lib/time/report.js +47 -0
- package/lib/utils/errors.js +13 -0
- package/lib/utils/json.js +15 -0
- package/{src → lib}/utils/omit.js +3 -4
- package/lib/utils/package.js +22 -0
- package/lib/utils/remove_falsy.js +8 -0
- package/lib/utils/resolve.js +41 -0
- package/lib/utils/runtime.js +5 -0
- package/lib/utils/semver.js +28 -0
- package/package.json +39 -20
- package/types/config/netlify_config.d.ts +4 -4
- package/types/netlify_plugin_constants.d.ts +8 -8
- package/src/core/bin.js +0 -83
- package/src/core/config.js +0 -186
- package/src/core/constants.js +0 -156
- package/src/core/dry.js +0 -39
- package/src/core/feature_flags.js +0 -21
- package/src/core/flags.js +0 -194
- package/src/core/lingering.js +0 -85
- package/src/core/main.js +0 -692
- package/src/core/missing_side_file.js +0 -29
- package/src/core/normalize_flags.js +0 -69
- package/src/core/severity.js +0 -22
- package/src/core/user_node_version.js +0 -41
- package/src/env/changes.js +0 -52
- package/src/env/main.js +0 -19
- package/src/env/metadata.js +0 -81
- package/src/error/api.js +0 -46
- package/src/error/build.js +0 -50
- package/src/error/colors.js +0 -11
- package/src/error/handle.js +0 -57
- package/src/error/info.js +0 -46
- package/src/error/monitor/location.js +0 -21
- package/src/error/monitor/normalize.js +0 -77
- package/src/error/monitor/print.js +0 -42
- package/src/error/monitor/report.js +0 -133
- package/src/error/monitor/start.js +0 -69
- package/src/error/parse/clean_stack.js +0 -87
- package/src/error/parse/location.js +0 -58
- package/src/error/parse/normalize.js +0 -29
- package/src/error/parse/parse.js +0 -97
- package/src/error/parse/plugin.js +0 -70
- package/src/error/parse/properties.js +0 -23
- package/src/error/parse/serialize_log.js +0 -42
- package/src/error/parse/serialize_status.js +0 -23
- package/src/error/parse/stack.js +0 -43
- package/src/error/type.js +0 -182
- package/src/install/functions.js +0 -28
- package/src/install/local.js +0 -62
- package/src/install/main.js +0 -81
- package/src/install/missing.js +0 -67
- package/src/log/description.js +0 -26
- package/src/log/header.js +0 -16
- package/src/log/header_func.js +0 -17
- package/src/log/logger.js +0 -107
- package/src/log/messages/compatibility.js +0 -164
- package/src/log/messages/config.js +0 -105
- package/src/log/messages/core.js +0 -70
- package/src/log/messages/core_steps.js +0 -104
- package/src/log/messages/dry.js +0 -63
- package/src/log/messages/install.js +0 -20
- package/src/log/messages/ipc.js +0 -38
- package/src/log/messages/mutations.js +0 -82
- package/src/log/messages/status.js +0 -16
- package/src/log/messages/steps.js +0 -22
- package/src/log/old_version.js +0 -41
- package/src/log/serialize.js +0 -13
- package/src/log/stream.js +0 -85
- package/src/log/theme.js +0 -26
- package/src/plugins/child/diff.js +0 -55
- package/src/plugins/child/error.js +0 -32
- package/src/plugins/child/lazy.js +0 -18
- package/src/plugins/child/load.js +0 -29
- package/src/plugins/child/logic.js +0 -57
- package/src/plugins/child/main.js +0 -51
- package/src/plugins/child/run.js +0 -28
- package/src/plugins/child/status.js +0 -67
- package/src/plugins/child/typescript.js +0 -45
- package/src/plugins/child/utils.js +0 -56
- package/src/plugins/child/validate.js +0 -34
- package/src/plugins/compatibility.js +0 -128
- package/src/plugins/expected_version.js +0 -119
- package/src/plugins/ipc.js +0 -145
- package/src/plugins/list.js +0 -86
- package/src/plugins/load.js +0 -70
- package/src/plugins/manifest/check.js +0 -106
- package/src/plugins/manifest/load.js +0 -41
- package/src/plugins/manifest/main.js +0 -22
- package/src/plugins/manifest/path.js +0 -31
- package/src/plugins/manifest/validate.js +0 -108
- package/src/plugins/node_version.js +0 -50
- package/src/plugins/options.js +0 -88
- package/src/plugins/pinned_version.js +0 -131
- package/src/plugins/resolve.js +0 -152
- package/src/plugins/spawn.js +0 -66
- package/src/plugins_core/add.js +0 -49
- package/src/plugins_core/build_command.js +0 -75
- package/src/plugins_core/deploy/buildbot_client.js +0 -102
- package/src/plugins_core/deploy/index.js +0 -73
- package/src/plugins_core/edge_functions/index.js +0 -107
- package/src/plugins_core/edge_functions/lib/internal_manifest.js +0 -54
- package/src/plugins_core/functions/error.js +0 -163
- package/src/plugins_core/functions/feature_flags.js +0 -6
- package/src/plugins_core/functions/index.js +0 -160
- package/src/plugins_core/functions/utils.js +0 -66
- package/src/plugins_core/functions/zisi.js +0 -53
- package/src/plugins_core/list.js +0 -27
- package/src/status/add.js +0 -36
- package/src/status/colors.js +0 -23
- package/src/status/load_error.js +0 -11
- package/src/status/report.js +0 -128
- package/src/status/success.js +0 -18
- package/src/steps/core_step.js +0 -90
- package/src/steps/error.js +0 -102
- package/src/steps/get.js +0 -32
- package/src/steps/plugin.js +0 -85
- package/src/steps/return.js +0 -52
- package/src/steps/run_core_steps.js +0 -194
- package/src/steps/run_step.js +0 -300
- package/src/steps/run_steps.js +0 -179
- package/src/steps/update_config.js +0 -93
- package/src/telemetry/main.js +0 -136
- package/src/time/aggregate.js +0 -146
- package/src/time/main.js +0 -48
- package/src/time/measure.js +0 -22
- package/src/time/report.js +0 -59
- package/src/utils/errors.js +0 -12
- package/src/utils/json.js +0 -19
- package/src/utils/package.js +0 -23
- package/src/utils/remove_falsy.js +0 -10
- package/src/utils/resolve.js +0 -46
- package/src/utils/semver.js +0 -34
package/src/time/aggregate.js
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { createTimer, TOP_PARENT_TAG } from './main.js'
|
|
2
|
-
|
|
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
|
-
|
|
16
|
-
// Having a `total` timer is redundant since the buildbot already measures this.
|
|
17
|
-
// The buildbot measurement is better since it includes the time to load Node.
|
|
18
|
-
// Instead, we only use `total` to measure what did not get `measureDuration()`.
|
|
19
|
-
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
|
-
|
|
27
|
-
const isTotalTimer = function ({ stageTag, parentTag }) {
|
|
28
|
-
return stageTag === 'total' && parentTag === 'build_site'
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
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
|
-
|
|
40
|
-
// Measure the total time running plugins
|
|
41
|
-
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
|
-
|
|
48
|
-
// Retrieve one timer for each plugin, summing all its individual timers
|
|
49
|
-
// (one per event handler)
|
|
50
|
-
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
|
-
|
|
62
|
-
// We only measure plugins maintained by us, not community
|
|
63
|
-
const isCommunityPluginTimer = function (timer) {
|
|
64
|
-
return isPluginTimer(timer) && !isNetlifyMaintainedPlugin(getPluginTimerPackage(timer))
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const isNetlifyMaintainedPlugin = function (pluginPackage) {
|
|
68
|
-
return NETLIFY_MAINTAINED_PLUGINS.has(pluginPackage)
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
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
|
-
|
|
81
|
-
const getPluginPackages = function (pluginsTimers) {
|
|
82
|
-
const pluginPackages = pluginsTimers.map(getPluginTimerPackage)
|
|
83
|
-
return [...new Set(pluginPackages)]
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
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
|
-
|
|
92
|
-
const getPluginTimerPackage = function ({ parentTag }) {
|
|
93
|
-
return parentTag
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Check if a timer relates to a Build plugin
|
|
97
|
-
const isPluginTimer = function ({ category }) {
|
|
98
|
-
return category === 'pluginEvent'
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Reports total time depending on whether it was system, plugin or user
|
|
102
|
-
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
|
-
|
|
108
|
-
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
|
-
|
|
114
|
-
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
|
-
|
|
125
|
-
const isTopTimer = function ({ parentTag }) {
|
|
126
|
-
return parentTag === TOP_PARENT_TAG
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Creates a timer that sums up the duration of several others
|
|
130
|
-
const createSumTimer = function (timers, stageTag, parentTag) {
|
|
131
|
-
const durationNs = computeTimersDuration(timers)
|
|
132
|
-
const timer = createTimer(stageTag, durationNs, { parentTag })
|
|
133
|
-
return timer
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const computeTimersDuration = function (timers) {
|
|
137
|
-
return timers.map(getTimerDuration).reduce(reduceSum, 0)
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const getTimerDuration = function ({ durationNs }) {
|
|
141
|
-
return durationNs
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const reduceSum = function (sum, number) {
|
|
145
|
-
return sum + number
|
|
146
|
-
}
|
package/src/time/main.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import slugify from '@sindresorhus/slugify'
|
|
2
|
-
import keepFuncProps from 'keep-func-props'
|
|
3
|
-
|
|
4
|
-
import { startTimer, endTimer } from './measure.js'
|
|
5
|
-
|
|
6
|
-
// Initialize the `timers` array
|
|
7
|
-
export const initTimers = function () {
|
|
8
|
-
return []
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// Wrap an async function to measure how long it takes.
|
|
12
|
-
// The function must:
|
|
13
|
-
// - take a plain object as first argument. This must contain a `timers`.
|
|
14
|
-
// - return a plain object. This may or may not contain a modified `timers`.
|
|
15
|
-
// The `durationNs` will be returned by the function. A new `timers` with the
|
|
16
|
-
// additional duration timer will be returned as well.
|
|
17
|
-
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
|
-
|
|
29
|
-
// Ensure the wrapped function `name` is not `anonymous` in stack traces
|
|
30
|
-
export const measureDuration = keepFuncProps(kMeasureDuration)
|
|
31
|
-
|
|
32
|
-
// 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
|
-
|
|
44
|
-
// Make sure the timer name does not include special characters.
|
|
45
|
-
// For example, the `packageName` of local plugins includes dots.
|
|
46
|
-
export const normalizeTimerName = function (name) {
|
|
47
|
-
return slugify(name, { separator: '_' })
|
|
48
|
-
}
|
package/src/time/measure.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { hrtime } from 'process'
|
|
2
|
-
|
|
3
|
-
// Starts a timer
|
|
4
|
-
export const startTimer = function () {
|
|
5
|
-
return hrtime()
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
// Stops a timer
|
|
9
|
-
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
|
-
|
|
15
|
-
// statsd expects milliseconds integers.
|
|
16
|
-
// To prevent double rounding errors, rounding should only be applied once.
|
|
17
|
-
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
|
package/src/time/report.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
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
|
-
|
|
8
|
-
// TODO: replace with `timers/promises` after dropping Node < 15.0.0
|
|
9
|
-
const pSetTimeout = promisify(setTimeout)
|
|
10
|
-
|
|
11
|
-
// Record the duration of a build phase, for monitoring.
|
|
12
|
-
// Sends to statsd daemon.
|
|
13
|
-
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
|
-
|
|
22
|
-
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
|
-
|
|
30
|
-
// The socket creation is delayed until the first packet is sent. In our
|
|
31
|
-
// case, this happens just before `client.close()` is called, which is too
|
|
32
|
-
// late and make it not send anything. We need to manually create it using
|
|
33
|
-
// the internal API.
|
|
34
|
-
const startClient = async function (host, port) {
|
|
35
|
-
const client = new StatsdClient({ host, port, socketTimeout: 0 })
|
|
36
|
-
// eslint-disable-next-line no-underscore-dangle
|
|
37
|
-
await promisify(client._socket._createSocket.bind(client._socket))()
|
|
38
|
-
return client
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
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
|
-
|
|
47
|
-
// UDP packets are buffered and flushed at regular intervals by statsd-client.
|
|
48
|
-
// Closing force flushing all of them.
|
|
49
|
-
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
|
-
|
|
58
|
-
// See https://github.com/msiebuhr/node-statsd-client/blob/45a93ee4c94ca72f244a40b06cb542d4bd7c3766/lib/EphemeralSocket.js#L81
|
|
59
|
-
const CLOSE_TIMEOUT = 11
|
package/src/utils/errors.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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
|
-
} catch (error) {
|
|
8
|
-
error.stack = `${message}: ${error.stack}`
|
|
9
|
-
throw error
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
}
|
package/src/utils/json.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
|
|
6
|
-
// TODO: Replace with dynamic `import()` once it is supported without
|
|
7
|
-
// experimental flags
|
|
8
|
-
export const importJsonFile = async function (filePath) {
|
|
9
|
-
const fileContents = await fs.readFile(filePath)
|
|
10
|
-
return JSON.parse(fileContents)
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
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)
|
package/src/utils/package.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { dirname } from 'path'
|
|
2
|
-
|
|
3
|
-
import { readPackageUp } from 'read-pkg-up'
|
|
4
|
-
|
|
5
|
-
// Retrieve `package.json` from a specific directory
|
|
6
|
-
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
|
-
|
|
17
|
-
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
|
-
}
|
package/src/utils/resolve.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'module'
|
|
2
|
-
|
|
3
|
-
import { async as resolveLib } from 'resolve'
|
|
4
|
-
|
|
5
|
-
// TODO: use `import.resolve()` once it is available without any experimental
|
|
6
|
-
// flags
|
|
7
|
-
const require = createRequire(import.meta.url)
|
|
8
|
-
|
|
9
|
-
// Like `resolvePath()` but does not throw
|
|
10
|
-
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
|
-
|
|
19
|
-
// This throws if the package cannot be found
|
|
20
|
-
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
|
-
|
|
31
|
-
// Like `require.resolve()` but as an external library.
|
|
32
|
-
// We need to use `new Promise()` due to a bug with `utils.promisify()` on
|
|
33
|
-
// `resolve`:
|
|
34
|
-
// https://github.com/browserify/resolve/issues/151#issuecomment-368210310
|
|
35
|
-
const resolvePathWithBasedir = function (path, basedir) {
|
|
36
|
-
return new Promise((resolve, reject) => {
|
|
37
|
-
// eslint-disable-next-line promise/prefer-await-to-callbacks
|
|
38
|
-
resolveLib(path, { basedir }, (error, resolvedPath) => {
|
|
39
|
-
if (error) {
|
|
40
|
-
return reject(error)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
resolve(resolvedPath)
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
}
|
package/src/utils/semver.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import semver from 'semver'
|
|
2
|
-
|
|
3
|
-
// Compare two versions by their major versions.
|
|
4
|
-
// Takes into account the special rules for `0.*.*` and `0.0.*` versions.
|
|
5
|
-
export const isPreviousMajor = function (versionA, versionB) {
|
|
6
|
-
return semver.lt(getMajor(versionA), getMajor(versionB))
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// Remove minor/patch numbers
|
|
10
|
-
const getMajor = function (version) {
|
|
11
|
-
return semver.minVersion(getMajorVersion(version)).version
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// According to semver, the second number is the major release number for
|
|
15
|
-
// `0.*.*` versions and the third for `0.0.*`. This is how `^` behaves with the
|
|
16
|
-
// `semver` module which is used by `npm`.
|
|
17
|
-
export const getMajorVersion = function (version) {
|
|
18
|
-
if (!version || semver.clean(version) === null) {
|
|
19
|
-
return
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const majorVersion = semver.major(version)
|
|
23
|
-
if (majorVersion !== 0) {
|
|
24
|
-
return `${majorVersion}`
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const minorVersion = semver.minor(version)
|
|
28
|
-
if (minorVersion !== 0) {
|
|
29
|
-
return `${majorVersion}.${minorVersion}`
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const patchVersion = semver.patch(version)
|
|
33
|
-
return `${majorVersion}.${minorVersion}.${patchVersion}`
|
|
34
|
-
}
|