@netlify/build 27.18.4 → 27.18.6-rc

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 (135) hide show
  1. package/package.json +8 -7
  2. package/src/core/bin.js +0 -83
  3. package/src/core/build.js +0 -559
  4. package/src/core/config.js +0 -186
  5. package/src/core/constants.js +0 -156
  6. package/src/core/dev.js +0 -31
  7. package/src/core/dry.js +0 -39
  8. package/src/core/feature_flags.js +0 -22
  9. package/src/core/flags.js +0 -204
  10. package/src/core/lingering.js +0 -85
  11. package/src/core/main.js +0 -165
  12. package/src/core/missing_side_file.js +0 -29
  13. package/src/core/normalize_flags.js +0 -70
  14. package/src/core/severity.js +0 -22
  15. package/src/core/user_node_version.js +0 -41
  16. package/src/env/changes.js +0 -52
  17. package/src/env/main.js +0 -19
  18. package/src/env/metadata.js +0 -81
  19. package/src/error/api.js +0 -46
  20. package/src/error/build.js +0 -50
  21. package/src/error/cancel.js +0 -8
  22. package/src/error/colors.js +0 -11
  23. package/src/error/handle.js +0 -57
  24. package/src/error/info.js +0 -46
  25. package/src/error/monitor/location.js +0 -21
  26. package/src/error/monitor/normalize.js +0 -96
  27. package/src/error/monitor/print.js +0 -42
  28. package/src/error/monitor/report.js +0 -138
  29. package/src/error/monitor/start.js +0 -69
  30. package/src/error/parse/clean_stack.js +0 -87
  31. package/src/error/parse/location.js +0 -62
  32. package/src/error/parse/normalize.js +0 -29
  33. package/src/error/parse/parse.js +0 -97
  34. package/src/error/parse/plugin.js +0 -70
  35. package/src/error/parse/properties.js +0 -23
  36. package/src/error/parse/serialize_log.js +0 -42
  37. package/src/error/parse/serialize_status.js +0 -23
  38. package/src/error/parse/stack.js +0 -43
  39. package/src/error/type.js +0 -189
  40. package/src/install/functions.js +0 -28
  41. package/src/install/local.js +0 -62
  42. package/src/install/main.js +0 -81
  43. package/src/install/missing.js +0 -67
  44. package/src/log/colors.js +0 -34
  45. package/src/log/description.js +0 -26
  46. package/src/log/header.js +0 -16
  47. package/src/log/header_func.js +0 -17
  48. package/src/log/logger.js +0 -161
  49. package/src/log/messages/compatibility.js +0 -178
  50. package/src/log/messages/config.js +0 -107
  51. package/src/log/messages/core.js +0 -70
  52. package/src/log/messages/core_steps.js +0 -104
  53. package/src/log/messages/dry.js +0 -63
  54. package/src/log/messages/install.js +0 -32
  55. package/src/log/messages/ipc.js +0 -38
  56. package/src/log/messages/mutations.js +0 -82
  57. package/src/log/messages/plugins.js +0 -39
  58. package/src/log/messages/status.js +0 -16
  59. package/src/log/messages/steps.js +0 -22
  60. package/src/log/old_version.js +0 -41
  61. package/src/log/serialize.js +0 -13
  62. package/src/log/stream.js +0 -85
  63. package/src/log/theme.js +0 -26
  64. package/src/plugins/child/diff.js +0 -55
  65. package/src/plugins/child/error.js +0 -32
  66. package/src/plugins/child/lazy.js +0 -18
  67. package/src/plugins/child/load.js +0 -29
  68. package/src/plugins/child/logic.js +0 -65
  69. package/src/plugins/child/main.js +0 -51
  70. package/src/plugins/child/run.js +0 -28
  71. package/src/plugins/child/status.js +0 -74
  72. package/src/plugins/child/typescript.js +0 -45
  73. package/src/plugins/child/utils.js +0 -56
  74. package/src/plugins/child/validate.js +0 -34
  75. package/src/plugins/compatibility.js +0 -132
  76. package/src/plugins/error.js +0 -50
  77. package/src/plugins/events.js +0 -17
  78. package/src/plugins/expected_version.js +0 -119
  79. package/src/plugins/ipc.js +0 -145
  80. package/src/plugins/list.js +0 -86
  81. package/src/plugins/load.js +0 -70
  82. package/src/plugins/manifest/check.js +0 -106
  83. package/src/plugins/manifest/load.js +0 -41
  84. package/src/plugins/manifest/main.js +0 -22
  85. package/src/plugins/manifest/path.js +0 -31
  86. package/src/plugins/manifest/validate.js +0 -108
  87. package/src/plugins/node_version.js +0 -50
  88. package/src/plugins/options.js +0 -88
  89. package/src/plugins/pinned_version.js +0 -131
  90. package/src/plugins/resolve.js +0 -152
  91. package/src/plugins/spawn.js +0 -72
  92. package/src/plugins_core/add.js +0 -49
  93. package/src/plugins_core/build_command.js +0 -75
  94. package/src/plugins_core/deploy/buildbot_client.js +0 -113
  95. package/src/plugins_core/deploy/index.js +0 -73
  96. package/src/plugins_core/deploy/manifest.yml +0 -1
  97. package/src/plugins_core/edge_functions/index.js +0 -123
  98. package/src/plugins_core/edge_functions/lib/error.js +0 -21
  99. package/src/plugins_core/edge_functions/lib/internal_manifest.js +0 -60
  100. package/src/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +0 -89
  101. package/src/plugins_core/functions/error.js +0 -163
  102. package/src/plugins_core/functions/feature_flags.js +0 -6
  103. package/src/plugins_core/functions/index.js +0 -161
  104. package/src/plugins_core/functions/utils.js +0 -66
  105. package/src/plugins_core/functions/zisi.js +0 -56
  106. package/src/plugins_core/functions_install/index.js +0 -13
  107. package/src/plugins_core/functions_install/manifest.yml +0 -1
  108. package/src/plugins_core/list.js +0 -27
  109. package/src/status/add.js +0 -36
  110. package/src/status/colors.js +0 -23
  111. package/src/status/load_error.js +0 -11
  112. package/src/status/report.js +0 -137
  113. package/src/status/success.js +0 -18
  114. package/src/steps/core_step.js +0 -92
  115. package/src/steps/error.js +0 -102
  116. package/src/steps/get.js +0 -51
  117. package/src/steps/plugin.js +0 -85
  118. package/src/steps/return.js +0 -52
  119. package/src/steps/run_core_steps.js +0 -200
  120. package/src/steps/run_step.js +0 -304
  121. package/src/steps/run_steps.js +0 -179
  122. package/src/steps/update_config.js +0 -93
  123. package/src/telemetry/main.js +0 -136
  124. package/src/time/aggregate.js +0 -146
  125. package/src/time/main.js +0 -48
  126. package/src/time/measure.js +0 -22
  127. package/src/time/report.js +0 -59
  128. package/src/utils/errors.js +0 -12
  129. package/src/utils/json.js +0 -19
  130. package/src/utils/omit.js +0 -6
  131. package/src/utils/package.js +0 -23
  132. package/src/utils/remove_falsy.js +0 -10
  133. package/src/utils/resolve.js +0 -46
  134. package/src/utils/runtime.js +0 -5
  135. package/src/utils/semver.js +0 -34
@@ -1,85 +0,0 @@
1
- import psList from 'ps-list'
2
-
3
- import { logLingeringProcesses } from '../log/messages/core.js'
4
-
5
- // Print a warning when some build processes are still running.
6
- // We cannot rely on using the process tree:
7
- // - This is because it is impossible to know whether a process was a child of
8
- // of another once its parent process has exited. When that happens, the s
9
- // child becomes inherited by `init`, changing its `ppid`. The information
10
- // about the original parent is then lost.
11
- // - The only way to implement this would be to repeatedly list processes as
12
- // the build command is ongoing. However, this would fail to detect processes
13
- // spawned just before the build commands ends.
14
- // We cannot list processes before and after the build command and use the
15
- // difference.
16
- // - This is because other processes (unrelated to @netlify/build) might be
17
- // running at the same time. This includes OS background processes.
18
- // Therefore, we run this in a controlled environment only (the buildbot) and
19
- // exclude specific processes manually. This is a lesser evil, although still
20
- // quite hacky.
21
- export const warnOnLingeringProcesses = async function ({
22
- mode,
23
- logs,
24
- testOpts: { silentLingeringProcesses = false },
25
- }) {
26
- if (mode !== 'buildbot' || silentLingeringProcesses) {
27
- return
28
- }
29
-
30
- const processes = await psList()
31
-
32
- const commands = processes.map(getCommand).filter(isNotIgnoredCommand)
33
-
34
- if (commands.length === 0) {
35
- return
36
- }
37
-
38
- logLingeringProcesses(logs, commands)
39
- }
40
-
41
- // `cmd` is only available on Unix. Unlike `name`, it includes the arguments.
42
- const getCommand = function ({ name, cmd = name }) {
43
- return cmd
44
- }
45
-
46
- // We ignore any command known to be internal to the buildbot.
47
- // We also ignore commands known not to complete properly in builds if they are
48
- // widely used.
49
- const isNotIgnoredCommand = function (command) {
50
- return !IGNORED_COMMANDS.some((ignoredCommand) => matchesIgnoredCommand(command, ignoredCommand))
51
- }
52
-
53
- const matchesIgnoredCommand = function (command, ignoredCommand) {
54
- if (typeof ignoredCommand === 'string') {
55
- return command.includes(ignoredCommand)
56
- }
57
-
58
- return ignoredCommand.test(command)
59
- }
60
-
61
- const IGNORED_COMMANDS = [
62
- // TODO: Those can most likely be removed
63
- 'ps',
64
- 'grep',
65
- 'bash',
66
-
67
- // Internal buildbot commands
68
- '[build]',
69
- /buildbot.*\[node]/,
70
- // buildbot's main Bash script
71
- '/opt/build-bin/build',
72
- // `@netlify/build` binary itself
73
- 'netlify-build',
74
- // Plugin child processes spawned by @netlify/build
75
- '@netlify/build',
76
- // Shown for parent processes with currently running child processes.
77
- // Happens on `ps` itself.
78
- 'defunct',
79
-
80
- // Processes often left running. We should report those but don't because of
81
- // how common those are in production builds
82
- 'gatsby-telemetry',
83
- 'jest-worker',
84
- 'broccoli-babel-transpiler',
85
- ]
package/src/core/main.js DELETED
@@ -1,165 +0,0 @@
1
- import { handleBuildError } from '../error/handle.js'
2
- import { logTimer, logBuildSuccess } from '../log/messages/core.js'
3
- import { trackBuildComplete } from '../telemetry/main.js'
4
- import { reportTimers } from '../time/report.js'
5
-
6
- import { execBuild, startBuild } from './build.js'
7
- import { getSeverity } from './severity.js'
8
-
9
- export { startDev } from './dev.js'
10
- export { runCoreSteps } from '../steps/run_core_steps.js'
11
-
12
- /**
13
- * Main entry point of Netlify Build.
14
- * Runs a builds and returns whether it succeeded or not.
15
- *
16
- * @param {object} [flags] - build configuration CLI flags
17
- * @param {string} [flags.config] - Path to the configuration file
18
- * @param {string} [flags.cwd] - Current directory. Used to retrieve the configuration file
19
- * @param {string} [flags.repositoryRoot] - Git repository root directory. Used to retrieve the configuration file.
20
- * @param {string} [flags.apiHost] - Netlify API endpoint
21
- * @param {string} [flags.token] - Netlify API token for authentication
22
- * @param {string} [flags.siteId] - Netlify Site ID
23
- * @param {string} [flags.deployId] - Netlify Deploy ID
24
- * @param {string} [flags.context] - Build context
25
- * @param {string} [flags.branch] - Repository branch
26
- * @param {boolean} [flags.dry=false] - Run in dry mode, i.e. printing steps without executing them
27
- * @param {string} [flags.nodePath] - Path to the Node.js binary to use in the build command and plugins
28
- * @param {boolean} [flags.buffer=false] - Buffer output instead of printing it
29
- *
30
- * @returns {object} buildResult
31
- * @returns {boolean} buildResult.success - Whether build succeeded or failed
32
- * @returns {number} buildResult.severityCode - Build success/failure status among:
33
- * 0 (success), 1 (build cancelled), 2 (user error), 3 (plugin error), 4 (system error). Can be used as exit code.
34
- * @returns {string[]} buildResult.logs - When using the `buffer` option, all log messages
35
- */
36
- export default async function buildSite(flags = {}) {
37
- const {
38
- errorMonitor,
39
- framework,
40
- mode,
41
- logs,
42
- debug,
43
- systemLogFile,
44
- testOpts,
45
- statsdOpts,
46
- dry,
47
- telemetry,
48
- buildId,
49
- deployId,
50
- ...flagsA
51
- } = startBuild(flags)
52
- const errorParams = { errorMonitor, mode, logs, debug, testOpts }
53
-
54
- try {
55
- const {
56
- pluginsOptions,
57
- netlifyConfig: netlifyConfigA,
58
- siteInfo,
59
- userNodeVersion,
60
- stepsCount,
61
- timers,
62
- durationNs,
63
- configMutations,
64
- } = await execBuild({
65
- ...flagsA,
66
- buildId,
67
- systemLogFile,
68
- deployId,
69
- dry,
70
- errorMonitor,
71
- mode,
72
- logs,
73
- debug,
74
- testOpts,
75
- errorParams,
76
- })
77
- await handleBuildSuccess({
78
- framework,
79
- dry,
80
- logs,
81
- timers,
82
- durationNs,
83
- statsdOpts,
84
- })
85
- const { success, severityCode, status } = getSeverity('success')
86
- await telemetryReport({
87
- buildId,
88
- deployId,
89
- status,
90
- stepsCount,
91
- pluginsOptions,
92
- durationNs,
93
- siteInfo,
94
- telemetry,
95
- userNodeVersion,
96
- framework,
97
- testOpts,
98
- errorParams,
99
- })
100
- return { success, severityCode, netlifyConfig: netlifyConfigA, logs, configMutations }
101
- } catch (error) {
102
- const { severity } = await handleBuildError(error, errorParams)
103
- const { pluginsOptions, siteInfo, userNodeVersion } = errorParams
104
- const { success, severityCode, status } = getSeverity(severity)
105
- await telemetryReport({
106
- buildId,
107
- deployId,
108
- status,
109
- pluginsOptions,
110
- siteInfo,
111
- telemetry,
112
- userNodeVersion,
113
- framework,
114
- testOpts,
115
- errorParams,
116
- })
117
- return { success, severityCode, logs }
118
- }
119
- }
120
-
121
- // Logs and reports that a build successfully ended
122
- const handleBuildSuccess = async function ({ framework, dry, logs, timers, durationNs, statsdOpts }) {
123
- if (dry) {
124
- return
125
- }
126
-
127
- logBuildSuccess(logs)
128
-
129
- logTimer(logs, durationNs, 'Netlify Build')
130
- await reportTimers({ timers, statsdOpts, framework })
131
- }
132
-
133
- // Handles the calls and errors of telemetry reports
134
- const telemetryReport = async function ({
135
- deployId,
136
- buildId,
137
- status,
138
- stepsCount,
139
- pluginsOptions,
140
- durationNs,
141
- siteInfo,
142
- telemetry,
143
- userNodeVersion,
144
- framework,
145
- testOpts,
146
- errorParams,
147
- }) {
148
- try {
149
- await trackBuildComplete({
150
- deployId,
151
- buildId,
152
- status,
153
- stepsCount,
154
- pluginsOptions,
155
- durationNs,
156
- siteInfo,
157
- telemetry,
158
- userNodeVersion,
159
- framework,
160
- testOpts,
161
- })
162
- } catch (error) {
163
- await handleBuildError(error, errorParams)
164
- }
165
- }
@@ -1,29 +0,0 @@
1
- import { relative } from 'path'
2
-
3
- import { pathExists } from 'path-exists'
4
-
5
- import { logMissingSideFile } from '../log/messages/core.js'
6
-
7
- // Some files like `_headers` and `_redirects` must be copied to the publish
8
- // directory to be used in production. When those are present in the repository
9
- // but not in the publish directory, this most likely indicates that the build
10
- // command accidentally forgot to copy those. We then print a warning message.
11
- export const warnOnMissingSideFiles = async function ({
12
- buildDir,
13
- netlifyConfig: {
14
- build: { publish },
15
- },
16
- logs,
17
- }) {
18
- await Promise.all(SIDE_FILES.map((sideFile) => warnOnMissingSideFile({ logs, sideFile, buildDir, publish })))
19
- }
20
-
21
- const SIDE_FILES = ['_headers', '_redirects']
22
-
23
- const warnOnMissingSideFile = async function ({ logs, sideFile, buildDir, publish }) {
24
- if (!(await pathExists(`${buildDir}/${sideFile}`)) || (await pathExists(`${publish}/${sideFile}`))) {
25
- return
26
- }
27
-
28
- logMissingSideFile(logs, sideFile, relative(buildDir, publish))
29
- }
@@ -1,70 +0,0 @@
1
- import { env, execPath } from 'process'
2
-
3
- import { logFlags } from '../log/messages/config.js'
4
- import { removeFalsy } from '../utils/remove_falsy.js'
5
-
6
- import { DEFAULT_FEATURE_FLAGS } from './feature_flags.js'
7
-
8
- // Normalize CLI flags
9
- export const normalizeFlags = function (flags, logs) {
10
- const rawFlags = removeFalsy(flags)
11
-
12
- // Combine the flags object env with the process.env
13
- const combinedEnv = { ...env, ...rawFlags.env }
14
- const defaultFlags = getDefaultFlags(rawFlags, combinedEnv)
15
-
16
- // The telemetry flag requires specific logic to compute
17
- const telemetryFlag = computeTelemetry(rawFlags, combinedEnv)
18
-
19
- const mergedFlags = {
20
- ...defaultFlags,
21
- ...rawFlags,
22
- ...telemetryFlag,
23
- statsdOpts: { ...defaultFlags.statsd, ...rawFlags.statsd },
24
- featureFlags: { ...defaultFlags.featureFlags, ...rawFlags.featureFlags },
25
- }
26
- const normalizedFlags = removeFalsy(mergedFlags)
27
-
28
- logFlags(logs, rawFlags, normalizedFlags)
29
-
30
- return normalizedFlags
31
- }
32
-
33
- // Default values of CLI flags
34
- const getDefaultFlags = function ({ env: envOpt = {} }, combinedEnv) {
35
- return {
36
- env: envOpt,
37
- nodePath: execPath,
38
- token: combinedEnv.NETLIFY_AUTH_TOKEN,
39
- mode: REQUIRE_MODE,
40
- offline: false,
41
- telemetry: false,
42
- verbose: Boolean(combinedEnv.NETLIFY_BUILD_DEBUG),
43
- functionsDistDir: DEFAULT_FUNCTIONS_DIST,
44
- edgeFunctionsDistDir: DEFAULT_EDGE_FUNCTIONS_DIST,
45
- cacheDir: DEFAULT_CACHE_DIR,
46
- deployId: combinedEnv.DEPLOY_ID,
47
- buildId: combinedEnv.BUILD_ID,
48
- debug: Boolean(combinedEnv.NETLIFY_BUILD_DEBUG),
49
- bugsnagKey: combinedEnv.BUGSNAG_KEY,
50
- sendStatus: false,
51
- saveConfig: false,
52
- apiHost: 'api.netlify.com',
53
- testOpts: {},
54
- featureFlags: DEFAULT_FEATURE_FLAGS,
55
- statsd: { port: DEFAULT_STATSD_PORT },
56
- timeline: 'build',
57
- }
58
- }
59
-
60
- // Compute the telemetry flag, it's disabled by default and we want to always disable it
61
- // if BUILD_TELEMETRY_DISABLED is passed.
62
- const computeTelemetry = function (flags, envOpts) {
63
- return envOpts.BUILD_TELEMETRY_DISABLED ? { telemetry: false } : { telemetry: flags.telemetry }
64
- }
65
-
66
- const REQUIRE_MODE = 'require'
67
- const DEFAULT_EDGE_FUNCTIONS_DIST = '.netlify/edge-functions-dist/'
68
- const DEFAULT_FUNCTIONS_DIST = '.netlify/functions/'
69
- const DEFAULT_CACHE_DIR = '.netlify/cache/'
70
- const DEFAULT_STATSD_PORT = 8125
@@ -1,22 +0,0 @@
1
- // Used to extract exit codes and respective status strings
2
- // 1|2|3 indicate whether this was a user|plugin|system error.
3
- export const getSeverity = function (severity = FALLBACK_SEVERITY) {
4
- const severityEntry = severity in SEVERITY_MAP ? SEVERITY_MAP[severity] : FALLBACK_SEVERITY_ENTRY
5
- const success = severity === SUCCESS_SEVERITY
6
- return { success, ...severityEntry }
7
- }
8
-
9
- // Map error severities to exit codes and status (used for telemetry purposes)
10
- /* eslint-disable no-magic-numbers */
11
- const SEVERITY_MAP = {
12
- success: { severityCode: 0, status: 'success' },
13
- none: { severityCode: 1, status: 'cancelled' },
14
- info: { severityCode: 2, status: 'user-error' },
15
- warning: { severityCode: 3, status: 'plugin-error' },
16
- error: { severityCode: 4, status: 'system-error' },
17
- }
18
- /* eslint-enable no-magic-numbers */
19
- const SUCCESS_SEVERITY = 'success'
20
- // Indicates a bug in our codebase
21
- const FALLBACK_SEVERITY = 'error'
22
- export const FALLBACK_SEVERITY_ENTRY = SEVERITY_MAP[FALLBACK_SEVERITY]
@@ -1,41 +0,0 @@
1
- import { version as currentVersion, execPath } from 'process'
2
-
3
- import { execa } from 'execa'
4
- import semver from 'semver'
5
-
6
- import { addErrorInfo } from '../error/info.js'
7
-
8
- // Retrieve Node.js version if the Node.js path is using nvm.
9
- // `node.exe` on Windows, `bin/node` on Unix.
10
- const NVM_NODE_VERSION_REGEXP = /[/\\]v(\d+\.\d+\.\d+)[/\\](bin[/\\]node|node.exe)$/
11
-
12
- // Retrieve Node.js version from current process
13
- const getCurrentNodeVersion = function () {
14
- return semver.clean(currentVersion)
15
- }
16
-
17
- // Retrieve Node.js version from `--node-path` or fallback to extracting the current Node.js process version
18
- export const getUserNodeVersion = async function (nodePath) {
19
- // No `--node-path` CLI flag, use the current node process version
20
- if (nodePath === execPath) {
21
- return getCurrentNodeVersion()
22
- }
23
-
24
- // Extract version from path
25
- const result = NVM_NODE_VERSION_REGEXP.exec(nodePath)
26
- if (result !== null) {
27
- return result[1]
28
- }
29
-
30
- // Fallback to actually running `node --version` with the given nodePath
31
- const { stdout } = await execa(nodePath, ['--version'], { reject: false })
32
- const version = semver.clean(stdout)
33
-
34
- if (version === null) {
35
- const error = new Error(`Invalid --node-path CLI flag: ${nodePath}`)
36
- addErrorInfo(error, { type: 'resolveConfig' })
37
- throw error
38
- }
39
-
40
- return version
41
- }
@@ -1,52 +0,0 @@
1
- import { env } from 'process'
2
-
3
- import filterObj from 'filter-obj'
4
- import mapObj from 'map-obj'
5
-
6
- // If plugins modify `process.env`, this is propagated in other plugins and in
7
- // `build.command`. Since those are different processes, we figure out when they
8
- // do this and communicate the new `process.env` to other processes.
9
- export const getNewEnvChanges = function (envBefore, netlifyConfig, netlifyConfigCopy) {
10
- const processEnvChanges = diffEnv(envBefore, env)
11
- const netlifyConfigEnvChanges = diffEnv(netlifyConfig.build.environment, netlifyConfigCopy.build.environment)
12
- return { ...processEnvChanges, ...netlifyConfigEnvChanges }
13
- }
14
-
15
- const diffEnv = function (envBefore, envAfter) {
16
- const envChanges = filterObj(envAfter, (name, value) => value !== envBefore[name])
17
- const deletedEnv = filterObj(envBefore, (name) => envAfter[name] === undefined)
18
- const deletedEnvA = mapObj(deletedEnv, setToNull)
19
- return { ...envChanges, ...deletedEnvA }
20
- }
21
-
22
- // `undefined` is not JSON-serializable (which is used in process IPC), so we
23
- // convert it to `null`
24
- // Note: `process.env[name] = undefined` actually does
25
- // `process.env[name] = 'undefined'` in Node.js.
26
- const setToNull = function (name) {
27
- return [name, null]
28
- }
29
-
30
- // Set `process.env` changes from a previous different plugin.
31
- // Can also merge with a `currentEnv` plain object instead of `process.env`.
32
- export const setEnvChanges = function (envChanges, currentEnv = env) {
33
- Object.entries(envChanges).forEach(([name, value]) => {
34
- setEnvChange(name, value, currentEnv)
35
- })
36
- return { ...currentEnv }
37
- }
38
-
39
- const setEnvChange = function (name, value, currentEnv) {
40
- if (currentEnv[name] === value) {
41
- return
42
- }
43
-
44
- if (value === null) {
45
- // `currentEnv` is a mutable variable
46
- // eslint-disable-next-line fp/no-delete
47
- delete currentEnv[name]
48
- return
49
- }
50
-
51
- currentEnv[name] = value
52
- }
package/src/env/main.js DELETED
@@ -1,19 +0,0 @@
1
- import { env } from 'process'
2
-
3
- import filterObj from 'filter-obj'
4
-
5
- import { getParentColorEnv } from '../log/colors.js'
6
-
7
- // Retrieve the environment variables passed to plugins and `build.command`
8
- // When run locally, this tries to emulate the production environment.
9
- export const getChildEnv = function ({ envOpt, env: allConfigEnv }) {
10
- const parentColorEnv = getParentColorEnv()
11
- const parentEnv = { ...env, ...allConfigEnv, ...envOpt, ...parentColorEnv }
12
- return filterObj(parentEnv, shouldKeepEnv)
13
- }
14
-
15
- const shouldKeepEnv = function (key) {
16
- return !REMOVED_PARENT_ENV.has(key.toLowerCase())
17
- }
18
-
19
- const REMOVED_PARENT_ENV = new Set(['bugsnag_key'])
@@ -1,81 +0,0 @@
1
- import { env } from 'process'
2
-
3
- import filterObj from 'filter-obj'
4
-
5
- // Retrieve enviroment variables used in error monitoring
6
- export const getEnvMetadata = function (childEnv = env) {
7
- return filterObj(childEnv, isEnvMetadata)
8
- }
9
-
10
- const isEnvMetadata = function (name) {
11
- return ENVIRONMENT_VARIABLES.has(name)
12
- }
13
-
14
- // This is sorted by most useful in debugging to least
15
- const ENVIRONMENT_VARIABLES = new Set([
16
- // URL and IDs
17
- 'BUILD_ID',
18
- 'DEPLOY_ID',
19
- 'SITE_NAME',
20
- 'SITE_ID',
21
- 'REPOSITORY_URL',
22
- 'URL',
23
- 'DEPLOY_URL',
24
- 'DEPLOY_PRIME_URL',
25
-
26
- // Git
27
- 'HEAD',
28
- 'COMMIT_REF',
29
- 'CACHED_COMMIT_REF',
30
- 'BRANCH',
31
- 'CONTEXT',
32
- 'PULL_REQUEST',
33
- 'REVIEW_ID',
34
-
35
- // Node
36
- 'NODE_VERSION',
37
- 'AWS_LAMBDA_JS_RUNTIME',
38
- 'NPM_VERSION',
39
- 'YARN_VERSION',
40
- 'NPM_FLAGS',
41
- 'YARN_FLAGS',
42
- 'NVM_FLAGS',
43
- 'NODE_ENV',
44
-
45
- // Go
46
- 'GO_VERSION',
47
- 'GO_IMPORT_PATH',
48
- 'GOCACHE',
49
- 'GOPATH',
50
- 'GOROOT',
51
-
52
- // Ruby
53
- 'RUBY_VERSION',
54
- 'GEM_HOME',
55
- 'GEM_PATH',
56
- 'GIMME_GCO_ENABLED',
57
- 'GIMME_ENV_PREFIX',
58
- 'GIMME_GO_PREFIX',
59
- 'GIMME_NO_ENV_ALIAS',
60
- 'GIMME_TYPE',
61
- 'IRBRC',
62
- 'MY_RUBY_HOME',
63
-
64
- // Hugo
65
- 'HUGO_VERSION',
66
-
67
- // Java
68
- 'JAVA_VERSION',
69
-
70
- // PHP
71
- 'PHP_VERSION',
72
-
73
- // Python
74
- 'PIPENV_DEFAULT_PYTHON_VERSION',
75
- 'PIPENV_RUNTIME',
76
- 'PIPENV_VENV_IN_PROJECT',
77
-
78
- // Git LFS
79
- 'GIT_LFS_ENABLED',
80
- 'GIT_LFS_FETCH_INCLUDE',
81
- ])
package/src/error/api.js DELETED
@@ -1,46 +0,0 @@
1
- import isPlainObj from 'is-plain-obj'
2
- import mapObj from 'map-obj'
3
-
4
- import { addErrorInfo } from './info.js'
5
-
6
- // Wrap `api.*` methods so that they add more error information
7
- export const addApiErrorHandlers = function (api) {
8
- if (api === undefined) {
9
- return
10
- }
11
-
12
- return mapObj(api, addErrorHandler)
13
- }
14
-
15
- const addErrorHandler = function (key, value) {
16
- if (typeof value !== 'function') {
17
- return [key, value]
18
- }
19
-
20
- const valueA = apiMethodHandler.bind(null, key, value)
21
- return [key, valueA]
22
- }
23
-
24
- const apiMethodHandler = async function (endpoint, method, parameters, ...args) {
25
- try {
26
- return await method(parameters, ...args)
27
- } catch (error) {
28
- redactError(error)
29
- addErrorInfo(error, { type: 'api', location: { endpoint, parameters } })
30
- throw error
31
- }
32
- }
33
-
34
- // Redact API token from the build logs
35
- const redactError = function (error) {
36
- if (
37
- error instanceof Error &&
38
- isPlainObj(error.data) &&
39
- isPlainObj(error.data.headers) &&
40
- typeof error.data.headers.Authorization === 'string'
41
- ) {
42
- error.data.headers.Authorization = error.data.headers.Authorization.replace(HEX_REGEXP, 'HEX')
43
- }
44
- }
45
-
46
- const HEX_REGEXP = /[\da-f]{6,}/g
@@ -1,50 +0,0 @@
1
- import safeJsonStringify from 'safe-json-stringify'
2
-
3
- import { CUSTOM_ERROR_KEY } from './info.js'
4
-
5
- // Retrieve error information from child process and re-build it in current
6
- // process. We need this since errors static properties are not kept by
7
- // `v8.serialize()`.
8
- export const jsonToError = function ({ name, message, stack, ...errorProps }) {
9
- // eslint-disable-next-line unicorn/error-message
10
- const error = new Error('')
11
-
12
- assignErrorProps(error, { name, message, stack })
13
- // Assign static error properties (if any)
14
- // We need to mutate the `error` directly to preserve its `name`, `stack`, etc.
15
- // eslint-disable-next-line fp/no-mutating-assign
16
- Object.assign(error, errorProps)
17
-
18
- return error
19
- }
20
-
21
- // Make sure `name`, `message` and `stack` are not enumerable
22
- const assignErrorProps = function (error, values) {
23
- ERROR_PROPS.forEach((name) => {
24
- assignErrorProp(error, name, values[name])
25
- })
26
- }
27
-
28
- const ERROR_PROPS = ['name', 'message', 'stack']
29
-
30
- const assignErrorProp = function (error, name, value) {
31
- // `Object.defineProperty()` requires direct mutation
32
- // eslint-disable-next-line fp/no-mutating-methods
33
- Object.defineProperty(error, name, { value, enumerable: false, writable: true, configurable: true })
34
- }
35
-
36
- // Inverse of `jsonToError()`.
37
- export const errorToJson = function (error) {
38
- const { name, message, stack, [CUSTOM_ERROR_KEY]: customError, ...errorProps } = error
39
-
40
- // diagnosticText is not enumerable in TSError so we need to grab it manually. destructuring won't work.
41
- if (error.diagnosticText) {
42
- // eslint-disable-next-line fp/no-mutation
43
- errorProps.diagnosticText = error.diagnosticText
44
- }
45
-
46
- return {
47
- ...safeJsonStringify.ensureProperties(errorProps),
48
- ...safeJsonStringify.ensureProperties({ name, message, stack, [CUSTOM_ERROR_KEY]: customError }),
49
- }
50
- }
@@ -1,8 +0,0 @@
1
- // Cancel builds, for example when a plugin uses `utils.build.cancelBuild()`
2
- export const cancelBuild = async function ({ api, deployId }) {
3
- if (api === undefined || !deployId) {
4
- return
5
- }
6
-
7
- await api.cancelSiteDeploy({ deploy_id: deployId })
8
- }
@@ -1,11 +0,0 @@
1
- import stripAnsi from 'strip-ansi'
2
-
3
- // Remove ANSI sequences from `error.message`
4
- export const removeErrorColors = function (error) {
5
- if (!(error instanceof Error)) {
6
- return
7
- }
8
-
9
- error.message = stripAnsi(error.message)
10
- error.stack = stripAnsi(error.stack)
11
- }