@netlify/build 28.0.1-beta → 28.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (262) hide show
  1. package/bin.js +5 -0
  2. package/lib/core/bin.js +66 -0
  3. package/lib/core/build.js +355 -0
  4. package/lib/core/config.js +121 -0
  5. package/lib/core/constants.js +116 -0
  6. package/lib/core/dev.js +27 -0
  7. package/lib/core/dry.js +21 -0
  8. package/lib/core/feature_flags.js +19 -0
  9. package/lib/core/flags.js +201 -0
  10. package/lib/core/lingering.js +68 -0
  11. package/lib/core/main.js +107 -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 +171 -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/{src → lib}/log/colors.js +15 -22
  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 +120 -0
  52. package/lib/log/messages/config.js +91 -0
  53. package/lib/log/messages/core.js +50 -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 +25 -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 +17 -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 +30 -0
  91. package/lib/plugins/options.js +55 -0
  92. package/lib/plugins/pinned_version.js +83 -0
  93. package/lib/plugins/resolve.js +110 -0
  94. package/lib/plugins/spawn.js +54 -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 +79 -0
  101. package/lib/plugins_core/edge_functions/lib/error.js +17 -0
  102. package/lib/plugins_core/edge_functions/lib/internal_manifest.js +50 -0
  103. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +75 -0
  104. package/lib/plugins_core/functions/error.js +123 -0
  105. package/lib/plugins_core/functions/feature_flags.js +6 -0
  106. package/lib/plugins_core/functions/index.js +114 -0
  107. package/lib/plugins_core/functions/utils.js +45 -0
  108. package/lib/plugins_core/functions/zisi.js +39 -0
  109. package/{src → lib}/plugins_core/functions_install/index.js +8 -11
  110. package/{src → lib}/plugins_core/functions_install/manifest.yml +0 -0
  111. package/lib/plugins_core/list.js +20 -0
  112. package/lib/report/statsd.js +31 -0
  113. package/lib/status/add.js +30 -0
  114. package/lib/status/colors.js +18 -0
  115. package/lib/status/load_error.js +10 -0
  116. package/lib/status/report.js +83 -0
  117. package/lib/status/success.js +14 -0
  118. package/lib/steps/core_step.js +59 -0
  119. package/lib/steps/error.js +65 -0
  120. package/lib/steps/get.js +43 -0
  121. package/lib/steps/plugin.js +55 -0
  122. package/lib/steps/return.js +25 -0
  123. package/lib/steps/run_core_steps.js +126 -0
  124. package/lib/steps/run_step.js +189 -0
  125. package/lib/steps/run_steps.js +96 -0
  126. package/lib/steps/update_config.js +66 -0
  127. package/lib/telemetry/main.js +97 -0
  128. package/lib/time/aggregate.js +109 -0
  129. package/lib/time/main.js +31 -0
  130. package/lib/time/measure.js +18 -0
  131. package/lib/time/report.js +24 -0
  132. package/lib/utils/errors.js +13 -0
  133. package/lib/utils/json.js +15 -0
  134. package/{src → lib}/utils/omit.js +3 -4
  135. package/lib/utils/package.js +22 -0
  136. package/lib/utils/remove_falsy.js +8 -0
  137. package/lib/utils/resolve.js +41 -0
  138. package/lib/utils/runtime.js +5 -0
  139. package/lib/utils/semver.js +28 -0
  140. package/package.json +41 -20
  141. package/types/config/netlify_config.d.ts +4 -4
  142. package/types/netlify_plugin_constants.d.ts +8 -8
  143. package/src/core/bin.js +0 -83
  144. package/src/core/config.js +0 -186
  145. package/src/core/constants.js +0 -156
  146. package/src/core/dry.js +0 -39
  147. package/src/core/feature_flags.js +0 -21
  148. package/src/core/flags.js +0 -194
  149. package/src/core/lingering.js +0 -85
  150. package/src/core/main.js +0 -692
  151. package/src/core/missing_side_file.js +0 -29
  152. package/src/core/normalize_flags.js +0 -69
  153. package/src/core/severity.js +0 -22
  154. package/src/core/user_node_version.js +0 -41
  155. package/src/env/changes.js +0 -52
  156. package/src/env/main.js +0 -19
  157. package/src/env/metadata.js +0 -81
  158. package/src/error/api.js +0 -46
  159. package/src/error/build.js +0 -50
  160. package/src/error/colors.js +0 -11
  161. package/src/error/handle.js +0 -57
  162. package/src/error/info.js +0 -46
  163. package/src/error/monitor/location.js +0 -21
  164. package/src/error/monitor/normalize.js +0 -77
  165. package/src/error/monitor/print.js +0 -42
  166. package/src/error/monitor/report.js +0 -133
  167. package/src/error/monitor/start.js +0 -69
  168. package/src/error/parse/clean_stack.js +0 -87
  169. package/src/error/parse/location.js +0 -58
  170. package/src/error/parse/normalize.js +0 -29
  171. package/src/error/parse/parse.js +0 -97
  172. package/src/error/parse/plugin.js +0 -70
  173. package/src/error/parse/properties.js +0 -23
  174. package/src/error/parse/serialize_log.js +0 -42
  175. package/src/error/parse/serialize_status.js +0 -23
  176. package/src/error/parse/stack.js +0 -43
  177. package/src/error/type.js +0 -182
  178. package/src/install/functions.js +0 -28
  179. package/src/install/local.js +0 -62
  180. package/src/install/main.js +0 -81
  181. package/src/install/missing.js +0 -67
  182. package/src/log/description.js +0 -26
  183. package/src/log/header.js +0 -16
  184. package/src/log/header_func.js +0 -17
  185. package/src/log/logger.js +0 -107
  186. package/src/log/messages/compatibility.js +0 -164
  187. package/src/log/messages/config.js +0 -105
  188. package/src/log/messages/core.js +0 -70
  189. package/src/log/messages/core_steps.js +0 -104
  190. package/src/log/messages/dry.js +0 -63
  191. package/src/log/messages/install.js +0 -20
  192. package/src/log/messages/ipc.js +0 -38
  193. package/src/log/messages/mutations.js +0 -82
  194. package/src/log/messages/status.js +0 -16
  195. package/src/log/messages/steps.js +0 -22
  196. package/src/log/old_version.js +0 -41
  197. package/src/log/serialize.js +0 -13
  198. package/src/log/stream.js +0 -85
  199. package/src/log/theme.js +0 -26
  200. package/src/plugins/child/diff.js +0 -55
  201. package/src/plugins/child/error.js +0 -32
  202. package/src/plugins/child/lazy.js +0 -18
  203. package/src/plugins/child/load.js +0 -29
  204. package/src/plugins/child/logic.js +0 -57
  205. package/src/plugins/child/main.js +0 -51
  206. package/src/plugins/child/run.js +0 -28
  207. package/src/plugins/child/status.js +0 -67
  208. package/src/plugins/child/typescript.js +0 -45
  209. package/src/plugins/child/utils.js +0 -56
  210. package/src/plugins/child/validate.js +0 -34
  211. package/src/plugins/compatibility.js +0 -128
  212. package/src/plugins/expected_version.js +0 -119
  213. package/src/plugins/ipc.js +0 -145
  214. package/src/plugins/list.js +0 -86
  215. package/src/plugins/load.js +0 -70
  216. package/src/plugins/manifest/check.js +0 -106
  217. package/src/plugins/manifest/load.js +0 -41
  218. package/src/plugins/manifest/main.js +0 -22
  219. package/src/plugins/manifest/path.js +0 -31
  220. package/src/plugins/manifest/validate.js +0 -108
  221. package/src/plugins/node_version.js +0 -50
  222. package/src/plugins/options.js +0 -88
  223. package/src/plugins/pinned_version.js +0 -131
  224. package/src/plugins/resolve.js +0 -152
  225. package/src/plugins/spawn.js +0 -66
  226. package/src/plugins_core/add.js +0 -49
  227. package/src/plugins_core/build_command.js +0 -75
  228. package/src/plugins_core/deploy/buildbot_client.js +0 -102
  229. package/src/plugins_core/deploy/index.js +0 -73
  230. package/src/plugins_core/edge_functions/index.js +0 -107
  231. package/src/plugins_core/edge_functions/lib/internal_manifest.js +0 -54
  232. package/src/plugins_core/functions/error.js +0 -163
  233. package/src/plugins_core/functions/feature_flags.js +0 -6
  234. package/src/plugins_core/functions/index.js +0 -160
  235. package/src/plugins_core/functions/utils.js +0 -66
  236. package/src/plugins_core/functions/zisi.js +0 -53
  237. package/src/plugins_core/list.js +0 -27
  238. package/src/status/add.js +0 -36
  239. package/src/status/colors.js +0 -23
  240. package/src/status/load_error.js +0 -11
  241. package/src/status/report.js +0 -128
  242. package/src/status/success.js +0 -18
  243. package/src/steps/core_step.js +0 -90
  244. package/src/steps/error.js +0 -102
  245. package/src/steps/get.js +0 -32
  246. package/src/steps/plugin.js +0 -85
  247. package/src/steps/return.js +0 -52
  248. package/src/steps/run_core_steps.js +0 -194
  249. package/src/steps/run_step.js +0 -300
  250. package/src/steps/run_steps.js +0 -179
  251. package/src/steps/update_config.js +0 -93
  252. package/src/telemetry/main.js +0 -136
  253. package/src/time/aggregate.js +0 -146
  254. package/src/time/main.js +0 -48
  255. package/src/time/measure.js +0 -22
  256. package/src/time/report.js +0 -59
  257. package/src/utils/errors.js +0 -12
  258. package/src/utils/json.js +0 -19
  259. package/src/utils/package.js +0 -23
  260. package/src/utils/remove_falsy.js +0 -10
  261. package/src/utils/resolve.js +0 -46
  262. package/src/utils/semver.js +0 -34
@@ -1,186 +0,0 @@
1
- import { resolveConfig, updateConfig, restoreConfig } from '@netlify/config'
2
- import mapObj from 'map-obj'
3
-
4
- import { getChildEnv } from '../env/main.js'
5
- import { addApiErrorHandlers } from '../error/api.js'
6
- import { changeErrorType } from '../error/info.js'
7
- import { logBuildDir, logConfigPath, logConfig, logContext } from '../log/messages/config.js'
8
- import { logConfigOnUpload, logHeadersOnUpload, logRedirectsOnUpload } from '../log/messages/mutations.js'
9
- import { measureDuration } from '../time/main.js'
10
- import { getPackageJson } from '../utils/package.js'
11
-
12
- import { getUserNodeVersion } from './user_node_version.js'
13
-
14
- // Retrieve immutable options passed to `@netlify/config`.
15
- // This does not include options which might change during the course of the
16
- // build:
17
- // - `cachedConfig` and `cachedConfigPath` are only used at the beginning of
18
- // the build
19
- // - If plugins change the configuration, `configMutations` is used instead
20
- // In both cases, almost all options should remain the same.
21
- export const getConfigOpts = function ({
22
- config,
23
- defaultConfig,
24
- cwd,
25
- repositoryRoot,
26
- apiHost,
27
- token,
28
- siteId,
29
- context,
30
- branch,
31
- baseRelDir,
32
- envOpt,
33
- mode,
34
- offline,
35
- deployId,
36
- buildId,
37
- testOpts,
38
- featureFlags,
39
- }) {
40
- return {
41
- config,
42
- defaultConfig,
43
- cwd,
44
- repositoryRoot,
45
- context,
46
- branch,
47
- baseRelDir,
48
- host: apiHost,
49
- token,
50
- siteId,
51
- deployId,
52
- buildId,
53
- mode,
54
- offline,
55
- env: envOpt,
56
- testOpts,
57
- featureFlags,
58
- }
59
- }
60
-
61
- // Retrieve configuration object
62
- const tLoadConfig = async function ({ configOpts, cachedConfig, cachedConfigPath, envOpt, debug, logs, nodePath }) {
63
- const {
64
- configPath,
65
- headersPath,
66
- redirectsPath,
67
- buildDir,
68
- repositoryRoot,
69
- config: netlifyConfig,
70
- context: contextA,
71
- branch: branchA,
72
- token: tokenA,
73
- api,
74
- siteInfo,
75
- env,
76
- } = await resolveInitialConfig(configOpts, cachedConfig, cachedConfigPath)
77
- logConfigInfo({ logs, configPath, buildDir, netlifyConfig, context: contextA, debug })
78
-
79
- const apiA = addApiErrorHandlers(api)
80
- const envValues = mapObj(env, (key, { value }) => [key, value])
81
- const childEnv = getChildEnv({ envOpt, env: envValues })
82
- const [{ packageJson }, userNodeVersion] = await Promise.all([getPackageJson(buildDir), getUserNodeVersion(nodePath)])
83
- return {
84
- netlifyConfig,
85
- configPath,
86
- headersPath,
87
- redirectsPath,
88
- buildDir,
89
- repositoryRoot,
90
- packageJson,
91
- userNodeVersion,
92
- childEnv,
93
- context: contextA,
94
- branch: branchA,
95
- token: tokenA,
96
- api: apiA,
97
- siteInfo,
98
- }
99
- }
100
-
101
- export const loadConfig = measureDuration(tLoadConfig, 'resolve_config')
102
-
103
- // Retrieve initial configuration.
104
- // In the buildbot and CLI, we re-use the already parsed `@netlify/config`
105
- // return value which is passed as `cachedConfig`/`cachedConfigPath`.
106
- const resolveInitialConfig = async function (configOpts, cachedConfig, cachedConfigPath) {
107
- return await resolveConfig({ ...configOpts, cachedConfig, cachedConfigPath })
108
- }
109
-
110
- const logConfigInfo = function ({ logs, configPath, buildDir, netlifyConfig, context, debug }) {
111
- logBuildDir(logs, buildDir)
112
- logConfigPath(logs, configPath)
113
- logConfig({ logs, netlifyConfig, debug })
114
- logContext(logs, context)
115
- }
116
-
117
- // Retrieve the configuration after it's been changed.
118
- // This ensures any configuration changes done by plugins is validated and
119
- // normalized.
120
- // We use `debug: false` to avoid any debug logs. Otherwise every configuration
121
- // change would create debug logs which would be too verbose.
122
- // Errors are propagated and assigned to the specific plugin or core step
123
- // which changed the configuration.
124
- export const resolveUpdatedConfig = async function (configOpts, configMutations) {
125
- try {
126
- return await resolveConfig({ ...configOpts, configMutations, debug: false })
127
- } catch (error) {
128
- changeErrorType(error, 'resolveConfig', 'pluginValidation')
129
- throw error
130
- }
131
- }
132
-
133
- // If the configuration was changed, persist it to `netlify.toml`.
134
- // If `netlify.toml` does not exist, create it inside repository root.
135
- // This is only done when `saveConfig` is `true`. This allows performing this
136
- // in the buildbot but not in local builds, since only the latter run in a
137
- // container and we want to avoid saving files on local machines.
138
- export const saveUpdatedConfig = async function ({
139
- configMutations,
140
- buildDir,
141
- repositoryRoot,
142
- configPath = `${repositoryRoot}/netlify.toml`,
143
- headersPath,
144
- redirectsPath,
145
- logs,
146
- featureFlags,
147
- context,
148
- branch,
149
- debug,
150
- saveConfig,
151
- }) {
152
- if (!saveConfig) {
153
- return
154
- }
155
-
156
- await updateConfig(configMutations, {
157
- buildDir,
158
- configPath,
159
- headersPath,
160
- redirectsPath,
161
- context,
162
- branch,
163
- logs,
164
- featureFlags,
165
- })
166
-
167
- await logConfigOnUpload({ logs, configPath, debug })
168
- await logHeadersOnUpload({ logs, headersPath, debug })
169
- await logRedirectsOnUpload({ logs, redirectsPath, debug })
170
- }
171
-
172
- export const restoreUpdatedConfig = async function ({
173
- configMutations,
174
- buildDir,
175
- repositoryRoot,
176
- configPath = `${repositoryRoot}/netlify.toml`,
177
- headersPath,
178
- redirectsPath,
179
- saveConfig,
180
- }) {
181
- if (!saveConfig) {
182
- return
183
- }
184
-
185
- await restoreConfig(configMutations, { buildDir, configPath, headersPath, redirectsPath })
186
- }
@@ -1,156 +0,0 @@
1
- import { relative, normalize } from 'path'
2
-
3
- import { getCacheDir } from '@netlify/cache-utils'
4
- import mapObj from 'map-obj'
5
- import { pathExists } from 'path-exists'
6
-
7
- import { ROOT_PACKAGE_JSON } from '../utils/json.js'
8
-
9
- // Retrieve constants passed to plugins
10
- export const getConstants = async function ({
11
- configPath,
12
- buildDir,
13
- functionsDistDir,
14
- edgeFunctionsDistDir,
15
- cacheDir,
16
- netlifyConfig,
17
- siteInfo: { id: siteId },
18
- apiHost,
19
- token,
20
- mode,
21
- }) {
22
- const isLocal = mode !== 'buildbot'
23
- const normalizedCacheDir = getCacheDir({ cacheDir, cwd: buildDir })
24
-
25
- const constants = {
26
- // Path to the Netlify configuration file
27
- CONFIG_PATH: configPath,
28
- // The directory where built serverless functions are placed before deployment
29
- FUNCTIONS_DIST: functionsDistDir,
30
- // The directory where built Edge Functions are placed before deployment
31
- EDGE_FUNCTIONS_DIST: edgeFunctionsDistDir,
32
- // Path to the Netlify build cache folder
33
- CACHE_DIR: normalizedCacheDir,
34
- // Boolean indicating whether the build was run locally (Netlify CLI) or in the production CI
35
- IS_LOCAL: isLocal,
36
- // The version of Netlify Build
37
- NETLIFY_BUILD_VERSION: ROOT_PACKAGE_JSON.version,
38
- // The Netlify Site ID
39
- SITE_ID: siteId,
40
- // The Netlify API access token
41
- NETLIFY_API_TOKEN: token,
42
- // The Netlify API host
43
- NETLIFY_API_HOST: apiHost,
44
- // The directory where internal functions (i.e. generated programmatically
45
- // via plugins or others) live
46
- INTERNAL_FUNCTIONS_SRC: `${buildDir}/${INTERNAL_FUNCTIONS_SRC}`,
47
- // The directory where internal Edge Functions (i.e. generated programmatically
48
- // via plugins or others) live
49
- INTERNAL_EDGE_FUNCTIONS_SRC: `${buildDir}/${INTERNAL_EDGE_FUNCTIONS_SRC}`,
50
- }
51
- const constantsA = await addMutableConstants({ constants, buildDir, netlifyConfig })
52
- return constantsA
53
- }
54
-
55
- const INTERNAL_EDGE_FUNCTIONS_SRC = '.netlify/edge-functions'
56
- const INTERNAL_FUNCTIONS_SRC = '.netlify/functions-internal'
57
-
58
- // Retrieve constants which might change during the build if a plugin modifies
59
- // `netlifyConfig` or creates some default directories.
60
- // Unlike readonly constants, this is called again before each build step.
61
- export const addMutableConstants = async function ({
62
- constants,
63
- buildDir,
64
- netlifyConfig: {
65
- build: { publish, edge_functions: edgeFunctions },
66
- functionsDirectory,
67
- },
68
- }) {
69
- const constantsA = {
70
- ...constants,
71
- // Directory that contains the deploy-ready HTML files and assets generated by the build
72
- PUBLISH_DIR: publish,
73
- // The directory where function source code lives
74
- FUNCTIONS_SRC: functionsDirectory,
75
- // The directory where Edge Functions source code lives
76
- EDGE_FUNCTIONS_SRC: edgeFunctions,
77
- }
78
- const constantsB = await addDefaultConstants(constantsA, buildDir)
79
- const constantsC = normalizeConstantsPaths(constantsB, buildDir)
80
- return constantsC
81
- }
82
-
83
- // Some `constants` have a default value when a specific file exists.
84
- // Those default values are assigned by `@netlify/config`. However, the build
85
- // command or plugins might create those specific files, in which case, the
86
- // related `constant` should be updated, unless the user has explicitly
87
- // configured it.
88
- const addDefaultConstants = async function (constants, buildDir) {
89
- const newConstants = await Promise.all(
90
- DEFAULT_PATHS.map(({ constantName, defaultPath }) =>
91
- addDefaultConstant({ constants, constantName, defaultPath, buildDir }),
92
- ),
93
- )
94
- return Object.assign({}, constants, ...newConstants)
95
- }
96
-
97
- // The current directory is the build directory, which is correct, so we don't
98
- // need to resolve paths
99
- const DEFAULT_PATHS = [
100
- // @todo Remove once we drop support for the legacy default functions directory.
101
- { constantName: 'FUNCTIONS_SRC', defaultPath: 'netlify-automatic-functions' },
102
- { constantName: 'FUNCTIONS_SRC', defaultPath: 'netlify/functions' },
103
- { constantName: 'EDGE_FUNCTIONS_SRC', defaultPath: 'netlify/edge-functions' },
104
- ]
105
-
106
- const addDefaultConstant = async function ({ constants, constantName, defaultPath, buildDir }) {
107
- // Configuration paths are relative to the build directory.
108
- if (!isEmptyValue(constants[constantName]) || !(await pathExists(`${buildDir}/${defaultPath}`))) {
109
- return {}
110
- }
111
-
112
- // However, the plugin child process' current directory is the build directory,
113
- // so we can pass the relative path instead of the resolved absolute path.
114
- return { [constantName]: defaultPath }
115
- }
116
-
117
- const normalizeConstantsPaths = function (constants, buildDir) {
118
- return mapObj(constants, (key, path) => [key, normalizePath(path, buildDir, key)])
119
- }
120
-
121
- // The current directory is `buildDir`. Most constants are inside this `buildDir`.
122
- // Instead of passing absolute paths, we pass paths relative to `buildDir`, so
123
- // that logs are less verbose.
124
- const normalizePath = function (path, buildDir, key) {
125
- if (isEmptyValue(path) || !CONSTANT_PATHS.has(key)) {
126
- return path
127
- }
128
-
129
- const pathA = normalize(path)
130
-
131
- if (pathA === buildDir) {
132
- return '.'
133
- }
134
-
135
- if (pathA.startsWith(buildDir)) {
136
- return relative(buildDir, pathA)
137
- }
138
-
139
- return pathA
140
- }
141
-
142
- const isEmptyValue = function (path) {
143
- return path === undefined || path === ''
144
- }
145
-
146
- const CONSTANT_PATHS = new Set([
147
- 'CONFIG_PATH',
148
- 'PUBLISH_DIR',
149
- 'FUNCTIONS_SRC',
150
- 'FUNCTIONS_DIST',
151
- 'INTERNAL_EDGE_FUNCTIONS_SRC',
152
- 'INTERNAL_FUNCTIONS_SRC',
153
- 'EDGE_FUNCTIONS_DIST',
154
- 'EDGE_FUNCTIONS_SRC',
155
- 'CACHE_DIR',
156
- ])
package/src/core/dry.js DELETED
@@ -1,39 +0,0 @@
1
- import pFilter from 'p-filter'
2
-
3
- import { logDryRunStart, logDryRunStep, logDryRunEnd } from '../log/messages/dry.js'
4
- import { runsOnlyOnBuildFailure } from '../plugins/events.js'
5
-
6
- // If the `dry` flag is specified, do a dry run
7
- export const doDryRun = async function ({ buildDir, steps, netlifyConfig, constants, buildbotServerSocket, logs }) {
8
- const successSteps = await pFilter(steps, ({ event, condition }) =>
9
- shouldIncludeStep({ buildDir, event, condition, netlifyConfig, constants, buildbotServerSocket }),
10
- )
11
- const eventWidth = Math.max(...successSteps.map(getEventLength))
12
- const stepsCount = successSteps.length
13
-
14
- logDryRunStart({ logs, eventWidth, stepsCount })
15
-
16
- successSteps.forEach((step, index) => {
17
- logDryRunStep({ logs, step, index, netlifyConfig, eventWidth, stepsCount })
18
- })
19
-
20
- logDryRunEnd(logs)
21
- }
22
-
23
- const shouldIncludeStep = async function ({
24
- buildDir,
25
- event,
26
- condition,
27
- netlifyConfig,
28
- constants,
29
- buildbotServerSocket,
30
- }) {
31
- return (
32
- !runsOnlyOnBuildFailure(event) &&
33
- (condition === undefined || (await condition({ buildDir, constants, netlifyConfig, buildbotServerSocket })))
34
- )
35
- }
36
-
37
- const getEventLength = function ({ event }) {
38
- return event.length
39
- }
@@ -1,21 +0,0 @@
1
- // From CLI `--featureFlags=a,b,c` to programmatic `{ a: true, b: true, c: true }`
2
- export const normalizeCliFeatureFlags = function (cliFeatureFlags) {
3
- return Object.assign({}, ...cliFeatureFlags.split(',').filter(isNotEmpty).map(getFeatureFlag))
4
- }
5
-
6
- const isNotEmpty = function (name) {
7
- return name.trim() !== ''
8
- }
9
-
10
- const getFeatureFlag = function (name) {
11
- return { [name]: true }
12
- }
13
-
14
- // Default values for feature flags
15
- export const DEFAULT_FEATURE_FLAGS = {
16
- buildbot_es_modules_esbuild: false,
17
- buildbot_zisi_trace_nft: false,
18
- buildbot_zisi_esbuild_parser: false,
19
- edge_functions_cache_cli: false,
20
- edge_functions_produce_eszip: false,
21
- }
package/src/core/flags.js DELETED
@@ -1,194 +0,0 @@
1
- /* eslint eslint-comments/no-use: off, max-lines: off */
2
-
3
- const jsonParse = function (value) {
4
- return value === undefined ? undefined : JSON.parse(value)
5
- }
6
-
7
- // All CLI flags
8
- export const FLAGS = {
9
- config: {
10
- string: true,
11
- describe: `Path to the configuration file.
12
- Defaults to any netlify.toml in the git repository root directory or the base directory`,
13
- },
14
- defaultConfig: {
15
- string: true,
16
- describe: `JSON configuration object containing default values.
17
- Each configuration default value is used unless overriden through the main configuration file.
18
- Default: none.`,
19
- coerce: jsonParse,
20
- hidden: true,
21
- },
22
- cachedConfig: {
23
- string: true,
24
- describe: `JSON configuration object returned by @netlify/config when --output=/ is used
25
- or when using @netlify/config programmatically.
26
- This is done as a performance optimization to cache the configuration loading logic.
27
- Default: none.`,
28
- coerce: jsonParse,
29
- hidden: true,
30
- },
31
- cachedConfigPath: {
32
- string: true,
33
- describe: `File path to the JSON configuration object returned by @netlify/config
34
- when --output=/path is used.
35
- This is done as a performance optimization to cache the configuration loading logic.
36
- Default: none.`,
37
- hidden: true,
38
- },
39
- cwd: {
40
- string: true,
41
- describe: `Current directory. Used to retrieve the configuration file.
42
- Default: current directory`,
43
- },
44
- repositoryRoot: {
45
- string: true,
46
- describe: `Git repository root directory. Used to retrieve the configuration file.
47
- Default: automatically guessed`,
48
- },
49
- apiHost: {
50
- string: true,
51
- describe: `Netlify API endpoint.
52
- Default: automatically guessed`,
53
- },
54
- token: {
55
- string: true,
56
- describe: `Netlify API token for authentication.
57
- The NETLIFY_AUTH_TOKEN environment variable can be used as well.`,
58
- },
59
- siteId: {
60
- string: true,
61
- describe: `Netlify Site ID.`,
62
- },
63
- deployId: {
64
- string: true,
65
- describe: `Netlify Deploy ID.
66
- Default: automatically guessed`,
67
- },
68
- buildId: {
69
- string: true,
70
- describe: `Netlify Build ID.
71
- Default: automatically guessed`,
72
- },
73
- context: {
74
- string: true,
75
- describe: `Build context.
76
- Default: 'production'`,
77
- },
78
- branch: {
79
- string: true,
80
- describe: `Repository branch.
81
- Default: automatically guessed`,
82
- },
83
- framework: {
84
- string: true,
85
- describe: 'Front-end framework.',
86
- hidden: true,
87
- },
88
- baseRelDir: {
89
- boolean: true,
90
- describe: `Feature flag meant for backward compatibility.
91
- When enabled, if the 'build.base' configuration property is defined, it is used
92
- to try to retrieve a second configuration file and discard the first one.
93
- Default: true`,
94
- hidden: true,
95
- },
96
- dry: {
97
- alias: 'dry-run',
98
- boolean: true,
99
- describe: `Run in dry mode, i.e. printing steps without executing them.
100
- Default: false`,
101
- },
102
- nodePath: {
103
- string: true,
104
- describe: `Path to the Node.js binary to use in the build command and plugins.
105
- Default: Current Node.js binary`,
106
- },
107
- functionsDistDir: {
108
- string: true,
109
- describe: `Path to the directory where packaged functions are kept.
110
- Default: automatically guessed`,
111
- hidden: true,
112
- },
113
- edgeFunctionsDistDir: {
114
- string: true,
115
- describe: `Path to the directory where packaged Edge Functions are kept.
116
- Default: automatically guessed`,
117
- hidden: true,
118
- },
119
- cacheDir: {
120
- string: true,
121
- describe: `Path to the cache directory.
122
- Default: .netlify/cache/`,
123
- hidden: true,
124
- },
125
- buildbotServerSocket: {
126
- string: true,
127
- describe: `Path to the buildbot server socket. This is used to connect to the buildbot to trigger deploys.`,
128
- hidden: true,
129
- },
130
- telemetry: {
131
- boolean: true,
132
- describe: `Enable telemetry.
133
- Default: false`,
134
- },
135
- mode: {
136
- string: true,
137
- describe: `Environment in which this is loaded. Can be:
138
- - 'buildbot': within Netlify Buildbot
139
- - 'cli': within Netlify CLI
140
- - 'require': through import('@netlify/build')`,
141
- hidden: true,
142
- },
143
- debug: {
144
- boolean: true,
145
- describe: 'Print user-facing debugging information',
146
- hidden: true,
147
- },
148
- verbose: {
149
- boolean: true,
150
- describe: 'Print internal debugging information',
151
- hidden: true,
152
- },
153
- sendStatus: {
154
- boolean: true,
155
- describe: 'Whether plugin statuses should be sent to the Netlify API',
156
- hidden: true,
157
- },
158
- saveConfig: {
159
- boolean: true,
160
- describe: 'Whether configuration changes should be saved to netlify.toml',
161
- hidden: true,
162
- },
163
- testOpts: {
164
- describe: 'Options for testing only',
165
- hidden: true,
166
- },
167
- featureFlags: {
168
- describe: 'Comma-separated list of feature flags to enable unreleased features',
169
- hidden: true,
170
- },
171
- statsd: {
172
- describe: 'Statsd-related options, for performance measuring',
173
- hidden: true,
174
- },
175
- 'statsd.host': {
176
- type: 'string',
177
- describe: 'Statsd host',
178
- hidden: true,
179
- },
180
- 'statsd.port': {
181
- type: 'number',
182
- describe: 'Statsd port',
183
- hidden: true,
184
- },
185
- offline: {
186
- boolean: true,
187
- describe: `Do not send requests to the Netlify API to retrieve site settings.
188
- Default: false`,
189
- },
190
- buffer: {
191
- boolean: true,
192
- describe: 'Buffer output instead of printing it',
193
- },
194
- }
@@ -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
- ]