@netlify/build 29.0.1-rc → 29.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (266) hide show
  1. package/bin.js +5 -0
  2. package/lib/core/bin.js +66 -0
  3. package/lib/core/build.js +356 -0
  4. package/lib/core/config.js +121 -0
  5. package/lib/core/constants.js +116 -0
  6. package/lib/core/dev.js +27 -0
  7. package/lib/core/dry.js +21 -0
  8. package/lib/core/feature_flags.js +21 -0
  9. package/lib/core/flags.js +201 -0
  10. package/lib/core/lingering.js +68 -0
  11. package/lib/core/main.js +110 -0
  12. package/lib/core/missing_side_file.js +17 -0
  13. package/lib/core/normalize_flags.js +59 -0
  14. package/lib/core/severity.js +21 -0
  15. package/lib/core/types.js +8 -0
  16. package/lib/core/user_node_version.js +32 -0
  17. package/lib/env/changes.js +43 -0
  18. package/lib/env/main.js +14 -0
  19. package/lib/env/metadata.js +68 -0
  20. package/lib/error/api.js +37 -0
  21. package/lib/error/build.js +36 -0
  22. package/{src → lib}/error/cancel.js +5 -6
  23. package/lib/error/colors.js +9 -0
  24. package/lib/error/handle.js +46 -0
  25. package/lib/error/info.js +37 -0
  26. package/lib/error/monitor/location.js +16 -0
  27. package/lib/error/monitor/normalize.js +86 -0
  28. package/lib/error/monitor/print.js +20 -0
  29. package/lib/error/monitor/report.js +120 -0
  30. package/lib/error/monitor/start.js +61 -0
  31. package/lib/error/parse/clean_stack.js +70 -0
  32. package/lib/error/parse/location.js +50 -0
  33. package/lib/error/parse/normalize.js +24 -0
  34. package/lib/error/parse/parse.js +67 -0
  35. package/lib/error/parse/plugin.js +55 -0
  36. package/lib/error/parse/properties.js +16 -0
  37. package/lib/error/parse/serialize_log.js +34 -0
  38. package/lib/error/parse/serialize_status.js +18 -0
  39. package/lib/error/parse/stack.js +34 -0
  40. package/lib/error/report.js +27 -0
  41. package/lib/error/type.js +177 -0
  42. package/lib/install/functions.js +20 -0
  43. package/lib/install/local.js +45 -0
  44. package/lib/install/main.js +67 -0
  45. package/lib/install/missing.js +54 -0
  46. package/lib/log/colors.js +28 -0
  47. package/lib/log/description.js +21 -0
  48. package/lib/log/header.js +14 -0
  49. package/lib/log/header_func.js +13 -0
  50. package/lib/log/logger.js +140 -0
  51. package/lib/log/messages/compatibility.js +146 -0
  52. package/lib/log/messages/config.js +91 -0
  53. package/lib/log/messages/core.js +51 -0
  54. package/lib/log/messages/core_steps.js +75 -0
  55. package/lib/log/messages/dry.js +41 -0
  56. package/lib/log/messages/install.js +25 -0
  57. package/lib/log/messages/ipc.js +29 -0
  58. package/lib/log/messages/mutations.js +62 -0
  59. package/{src → lib}/log/messages/plugins.js +18 -32
  60. package/lib/log/messages/status.js +14 -0
  61. package/lib/log/messages/steps.js +18 -0
  62. package/lib/log/old_version.js +32 -0
  63. package/lib/log/serialize.js +10 -0
  64. package/lib/log/stream.js +68 -0
  65. package/lib/log/theme.js +27 -0
  66. package/lib/plugins/child/diff.js +46 -0
  67. package/lib/plugins/child/error.js +26 -0
  68. package/lib/plugins/child/lazy.js +15 -0
  69. package/lib/plugins/child/load.js +22 -0
  70. package/lib/plugins/child/logic.js +57 -0
  71. package/lib/plugins/child/main.js +37 -0
  72. package/lib/plugins/child/run.js +19 -0
  73. package/lib/plugins/child/status.js +63 -0
  74. package/lib/plugins/child/typescript.js +28 -0
  75. package/lib/plugins/child/utils.js +42 -0
  76. package/lib/plugins/child/validate.js +31 -0
  77. package/lib/plugins/compatibility.js +104 -0
  78. package/{src → lib}/plugins/error.js +31 -35
  79. package/{src → lib}/plugins/events.js +7 -12
  80. package/lib/plugins/expected_version.js +81 -0
  81. package/lib/plugins/internal.js +10 -0
  82. package/lib/plugins/ipc.js +120 -0
  83. package/lib/plugins/list.js +73 -0
  84. package/lib/plugins/load.js +50 -0
  85. package/lib/plugins/manifest/check.js +85 -0
  86. package/lib/plugins/manifest/load.js +38 -0
  87. package/lib/plugins/manifest/main.js +19 -0
  88. package/lib/plugins/manifest/path.js +24 -0
  89. package/lib/plugins/manifest/validate.js +91 -0
  90. package/lib/plugins/node_version.js +35 -0
  91. package/lib/plugins/options.js +70 -0
  92. package/lib/plugins/pinned_version.js +83 -0
  93. package/lib/plugins/resolve.js +110 -0
  94. package/lib/plugins/spawn.js +58 -0
  95. package/lib/plugins_core/add.js +35 -0
  96. package/lib/plugins_core/build_command.js +50 -0
  97. package/lib/plugins_core/deploy/buildbot_client.js +87 -0
  98. package/lib/plugins_core/deploy/index.js +49 -0
  99. package/{src → lib}/plugins_core/deploy/manifest.yml +0 -0
  100. package/lib/plugins_core/edge_functions/index.js +76 -0
  101. package/{src → lib}/plugins_core/edge_functions/lib/error.js +13 -17
  102. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +21 -0
  103. package/lib/plugins_core/functions/error.js +123 -0
  104. package/lib/plugins_core/functions/feature_flags.js +6 -0
  105. package/lib/plugins_core/functions/index.js +114 -0
  106. package/lib/plugins_core/functions/utils.js +45 -0
  107. package/lib/plugins_core/functions/zisi.js +39 -0
  108. package/{src → lib}/plugins_core/functions_install/index.js +8 -11
  109. package/{src → lib}/plugins_core/functions_install/manifest.yml +0 -0
  110. package/lib/plugins_core/list.js +20 -0
  111. package/lib/report/statsd.js +31 -0
  112. package/lib/status/add.js +30 -0
  113. package/lib/status/colors.js +18 -0
  114. package/lib/status/load_error.js +10 -0
  115. package/lib/status/report.js +83 -0
  116. package/lib/status/success.js +14 -0
  117. package/lib/steps/core_step.js +59 -0
  118. package/lib/steps/error.js +65 -0
  119. package/lib/steps/get.js +43 -0
  120. package/lib/steps/plugin.js +55 -0
  121. package/lib/steps/return.js +25 -0
  122. package/lib/steps/run_core_steps.js +117 -0
  123. package/lib/steps/run_step.js +190 -0
  124. package/lib/steps/run_steps.js +96 -0
  125. package/lib/steps/update_config.js +66 -0
  126. package/lib/telemetry/main.js +97 -0
  127. package/lib/time/aggregate.js +109 -0
  128. package/lib/time/main.js +31 -0
  129. package/lib/time/measure.js +16 -0
  130. package/lib/time/report.js +24 -0
  131. package/lib/utils/errors.js +13 -0
  132. package/lib/utils/json.js +15 -0
  133. package/lib/utils/omit.js +3 -0
  134. package/lib/utils/package.js +24 -0
  135. package/lib/utils/remove_falsy.js +8 -0
  136. package/lib/utils/resolve.js +41 -0
  137. package/lib/utils/runtime.js +5 -0
  138. package/lib/utils/semver.js +28 -0
  139. package/package.json +41 -24
  140. package/types/config/netlify_config.d.ts +4 -4
  141. package/types/netlify_plugin_constants.d.ts +8 -8
  142. package/src/core/bin.js +0 -83
  143. package/src/core/build.js +0 -554
  144. package/src/core/config.js +0 -186
  145. package/src/core/constants.js +0 -156
  146. package/src/core/dev.js +0 -31
  147. package/src/core/dry.js +0 -39
  148. package/src/core/feature_flags.js +0 -22
  149. package/src/core/flags.js +0 -204
  150. package/src/core/lingering.js +0 -85
  151. package/src/core/main.js +0 -165
  152. package/src/core/missing_side_file.js +0 -29
  153. package/src/core/normalize_flags.js +0 -70
  154. package/src/core/severity.js +0 -22
  155. package/src/core/user_node_version.js +0 -41
  156. package/src/env/changes.js +0 -52
  157. package/src/env/main.js +0 -19
  158. package/src/env/metadata.js +0 -81
  159. package/src/error/api.js +0 -46
  160. package/src/error/build.js +0 -50
  161. package/src/error/colors.js +0 -11
  162. package/src/error/handle.js +0 -57
  163. package/src/error/info.js +0 -46
  164. package/src/error/monitor/location.js +0 -21
  165. package/src/error/monitor/normalize.js +0 -96
  166. package/src/error/monitor/print.js +0 -42
  167. package/src/error/monitor/report.js +0 -138
  168. package/src/error/monitor/start.js +0 -69
  169. package/src/error/parse/clean_stack.js +0 -87
  170. package/src/error/parse/location.js +0 -62
  171. package/src/error/parse/normalize.js +0 -29
  172. package/src/error/parse/parse.js +0 -97
  173. package/src/error/parse/plugin.js +0 -70
  174. package/src/error/parse/properties.js +0 -23
  175. package/src/error/parse/serialize_log.js +0 -42
  176. package/src/error/parse/serialize_status.js +0 -23
  177. package/src/error/parse/stack.js +0 -43
  178. package/src/error/type.js +0 -189
  179. package/src/install/functions.js +0 -28
  180. package/src/install/local.js +0 -62
  181. package/src/install/main.js +0 -81
  182. package/src/install/missing.js +0 -67
  183. package/src/log/colors.js +0 -34
  184. package/src/log/description.js +0 -26
  185. package/src/log/header.js +0 -16
  186. package/src/log/header_func.js +0 -17
  187. package/src/log/logger.js +0 -161
  188. package/src/log/messages/compatibility.js +0 -164
  189. package/src/log/messages/config.js +0 -107
  190. package/src/log/messages/core.js +0 -70
  191. package/src/log/messages/core_steps.js +0 -104
  192. package/src/log/messages/dry.js +0 -63
  193. package/src/log/messages/install.js +0 -20
  194. package/src/log/messages/ipc.js +0 -38
  195. package/src/log/messages/mutations.js +0 -82
  196. package/src/log/messages/status.js +0 -16
  197. package/src/log/messages/steps.js +0 -22
  198. package/src/log/old_version.js +0 -41
  199. package/src/log/serialize.js +0 -13
  200. package/src/log/stream.js +0 -85
  201. package/src/log/theme.js +0 -26
  202. package/src/plugins/child/diff.js +0 -55
  203. package/src/plugins/child/error.js +0 -32
  204. package/src/plugins/child/lazy.js +0 -18
  205. package/src/plugins/child/load.js +0 -29
  206. package/src/plugins/child/logic.js +0 -57
  207. package/src/plugins/child/main.js +0 -51
  208. package/src/plugins/child/run.js +0 -28
  209. package/src/plugins/child/status.js +0 -74
  210. package/src/plugins/child/typescript.js +0 -45
  211. package/src/plugins/child/utils.js +0 -56
  212. package/src/plugins/child/validate.js +0 -34
  213. package/src/plugins/compatibility.js +0 -128
  214. package/src/plugins/expected_version.js +0 -119
  215. package/src/plugins/ipc.js +0 -145
  216. package/src/plugins/list.js +0 -86
  217. package/src/plugins/load.js +0 -70
  218. package/src/plugins/manifest/check.js +0 -106
  219. package/src/plugins/manifest/load.js +0 -41
  220. package/src/plugins/manifest/main.js +0 -22
  221. package/src/plugins/manifest/path.js +0 -31
  222. package/src/plugins/manifest/validate.js +0 -108
  223. package/src/plugins/node_version.js +0 -50
  224. package/src/plugins/options.js +0 -88
  225. package/src/plugins/pinned_version.js +0 -131
  226. package/src/plugins/resolve.js +0 -152
  227. package/src/plugins/spawn.js +0 -66
  228. package/src/plugins_core/add.js +0 -49
  229. package/src/plugins_core/build_command.js +0 -75
  230. package/src/plugins_core/deploy/buildbot_client.js +0 -102
  231. package/src/plugins_core/deploy/index.js +0 -73
  232. package/src/plugins_core/edge_functions/index.js +0 -123
  233. package/src/plugins_core/edge_functions/lib/internal_manifest.js +0 -54
  234. package/src/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +0 -89
  235. package/src/plugins_core/functions/error.js +0 -163
  236. package/src/plugins_core/functions/feature_flags.js +0 -6
  237. package/src/plugins_core/functions/index.js +0 -160
  238. package/src/plugins_core/functions/utils.js +0 -66
  239. package/src/plugins_core/functions/zisi.js +0 -53
  240. package/src/plugins_core/list.js +0 -27
  241. package/src/status/add.js +0 -36
  242. package/src/status/colors.js +0 -23
  243. package/src/status/load_error.js +0 -11
  244. package/src/status/report.js +0 -137
  245. package/src/status/success.js +0 -18
  246. package/src/steps/core_step.js +0 -92
  247. package/src/steps/error.js +0 -102
  248. package/src/steps/get.js +0 -51
  249. package/src/steps/plugin.js +0 -85
  250. package/src/steps/return.js +0 -52
  251. package/src/steps/run_core_steps.js +0 -200
  252. package/src/steps/run_step.js +0 -304
  253. package/src/steps/run_steps.js +0 -179
  254. package/src/steps/update_config.js +0 -93
  255. package/src/telemetry/main.js +0 -136
  256. package/src/time/aggregate.js +0 -146
  257. package/src/time/main.js +0 -48
  258. package/src/time/measure.js +0 -22
  259. package/src/time/report.js +0 -59
  260. package/src/utils/errors.js +0 -12
  261. package/src/utils/json.js +0 -19
  262. package/src/utils/omit.js +0 -6
  263. package/src/utils/package.js +0 -23
  264. package/src/utils/remove_falsy.js +0 -10
  265. package/src/utils/resolve.js +0 -46
  266. package/src/utils/semver.js +0 -34
@@ -1,152 +0,0 @@
1
- import { addErrorInfo } from '../error/info.js'
2
- import { installMissingPlugins } from '../install/missing.js'
3
- import { resolvePath, tryResolvePath } from '../utils/resolve.js'
4
-
5
- import { addExpectedVersions } from './expected_version.js'
6
- import { addPluginsNodeVersion } from './node_version.js'
7
- import { addPinnedVersions } from './pinned_version.js'
8
-
9
- // Try to find plugins in four places, by priority order:
10
- // - already loaded (core plugins)
11
- // - local plugin
12
- // - external plugin already installed in `node_modules`, most likely through `package.json`
13
- // - automatically installed by us, to `.netlify/plugins/`
14
- export const resolvePluginsPath = async function ({
15
- pluginsOptions,
16
- siteInfo,
17
- buildDir,
18
- nodePath,
19
- packageJson,
20
- userNodeVersion,
21
- mode,
22
- api,
23
- logs,
24
- debug,
25
- sendStatus,
26
- testOpts,
27
- featureFlags,
28
- }) {
29
- const autoPluginsDir = getAutoPluginsDir(buildDir)
30
- const pluginsOptionsA = await Promise.all(
31
- pluginsOptions.map((pluginOptions) => resolvePluginPath({ pluginOptions, buildDir, autoPluginsDir })),
32
- )
33
- const pluginsOptionsB = addPluginsNodeVersion({
34
- pluginsOptions: pluginsOptionsA,
35
- nodePath,
36
- userNodeVersion,
37
- logs,
38
- })
39
- const pluginsOptionsC = await addPinnedVersions({ pluginsOptions: pluginsOptionsB, api, siteInfo, sendStatus })
40
- const pluginsOptionsD = await addExpectedVersions({
41
- pluginsOptions: pluginsOptionsC,
42
- autoPluginsDir,
43
- packageJson,
44
- debug,
45
- logs,
46
- buildDir,
47
- testOpts,
48
- featureFlags,
49
- })
50
- const pluginsOptionsE = await handleMissingPlugins({
51
- pluginsOptions: pluginsOptionsD,
52
- autoPluginsDir,
53
- mode,
54
- logs,
55
- })
56
- return pluginsOptionsE
57
- }
58
-
59
- // Find the path to the directory used to install plugins automatically.
60
- // It is a subdirectory of `buildDir`, so that the plugin can require the
61
- // project's dependencies (peer dependencies).
62
- const getAutoPluginsDir = function (buildDir) {
63
- return `${buildDir}/${AUTO_PLUGINS_DIR}`
64
- }
65
-
66
- const AUTO_PLUGINS_DIR = '.netlify/plugins/'
67
-
68
- const resolvePluginPath = async function ({
69
- pluginOptions,
70
- pluginOptions: { packageName, loadedFrom },
71
- buildDir,
72
- autoPluginsDir,
73
- }) {
74
- // Core plugins
75
- if (loadedFrom !== undefined) {
76
- return pluginOptions
77
- }
78
-
79
- const localPackageName = normalizeLocalPackageName(packageName)
80
-
81
- // Local plugins
82
- if (localPackageName.startsWith('.')) {
83
- const { path: localPath, error } = await tryResolvePath(localPackageName, buildDir)
84
- validateLocalPluginPath(error, localPackageName)
85
- return { ...pluginOptions, pluginPath: localPath, loadedFrom: 'local' }
86
- }
87
-
88
- // Plugin added to `package.json`
89
- const { path: manualPath } = await tryResolvePath(packageName, buildDir)
90
- if (manualPath !== undefined) {
91
- return { ...pluginOptions, pluginPath: manualPath, loadedFrom: 'package.json' }
92
- }
93
-
94
- // Previously automatically installed
95
- const { path: automaticPath } = await tryResolvePath(packageName, autoPluginsDir)
96
- if (automaticPath !== undefined) {
97
- return { ...pluginOptions, pluginPath: automaticPath, loadedFrom: 'auto_install' }
98
- }
99
-
100
- // Happens if the plugin:
101
- // - name is mispelled
102
- // - is not in our official list
103
- // - is in our official list but has not been installed by this site yet
104
- return { ...pluginOptions, loadedFrom: 'auto_install' }
105
- }
106
-
107
- // `packageName` starting with `/` are relative to the build directory
108
- const normalizeLocalPackageName = function (packageName) {
109
- if (packageName.startsWith('/')) {
110
- return `.${packageName}`
111
- }
112
-
113
- return packageName
114
- }
115
-
116
- // When requiring a local plugin with an invalid file path
117
- const validateLocalPluginPath = function (error, localPackageName) {
118
- if (error !== undefined) {
119
- error.message = `Plugin could not be found using local path: ${localPackageName}\n${error.message}`
120
- addErrorInfo(error, { type: 'resolveConfig' })
121
- throw error
122
- }
123
- }
124
-
125
- // Install plugins from the official list that have not been previously installed.
126
- // Print a warning if they have not been installed through the UI.
127
- const handleMissingPlugins = async function ({ pluginsOptions, autoPluginsDir, mode, logs }) {
128
- const missingPlugins = pluginsOptions.filter(isMissingPlugin)
129
-
130
- if (missingPlugins.length === 0) {
131
- return pluginsOptions
132
- }
133
-
134
- await installMissingPlugins({ missingPlugins, autoPluginsDir, mode, logs })
135
- return await Promise.all(
136
- pluginsOptions.map((pluginOptions) => resolveMissingPluginPath({ pluginOptions, autoPluginsDir })),
137
- )
138
- }
139
-
140
- // Resolve the plugins that just got automatically installed
141
- const resolveMissingPluginPath = async function ({ pluginOptions, pluginOptions: { packageName }, autoPluginsDir }) {
142
- if (!isMissingPlugin(pluginOptions)) {
143
- return pluginOptions
144
- }
145
-
146
- const pluginPath = await resolvePath(packageName, autoPluginsDir)
147
- return { ...pluginOptions, pluginPath }
148
- }
149
-
150
- const isMissingPlugin = function ({ isMissing }) {
151
- return isMissing
152
- }
@@ -1,66 +0,0 @@
1
- import { fileURLToPath } from 'url'
2
-
3
- import { execaNode } from 'execa'
4
-
5
- import { addErrorInfo } from '../error/info.js'
6
- import { logLoadingPlugins, logOutdatedPlugins, logIncompatiblePlugins } from '../log/messages/compatibility.js'
7
- import { measureDuration } from '../time/main.js'
8
-
9
- import { getEventFromChild } from './ipc.js'
10
- import { getSpawnInfo } from './options.js'
11
-
12
- const CHILD_MAIN_FILE = fileURLToPath(new URL('child/main.js', import.meta.url))
13
-
14
- // Start child processes used by all plugins
15
- // We fire plugins through child processes so that:
16
- // - each plugin is sandboxed, e.g. cannot access/modify its parent `process`
17
- // (for both security and safety reasons)
18
- // - logs can be buffered which allows manipulating them for log shipping,
19
- // transforming and parallel plugins
20
- const tStartPlugins = async function ({ pluginsOptions, buildDir, childEnv, logs, debug }) {
21
- logLoadingPlugins(logs, pluginsOptions, debug)
22
- logOutdatedPlugins(logs, pluginsOptions)
23
- logIncompatiblePlugins(logs, pluginsOptions)
24
-
25
- const childProcesses = await Promise.all(
26
- pluginsOptions.map(({ pluginDir, nodePath }) => startPlugin({ pluginDir, nodePath, buildDir, childEnv })),
27
- )
28
- return { childProcesses }
29
- }
30
-
31
- export const startPlugins = measureDuration(tStartPlugins, 'start_plugins')
32
-
33
- const startPlugin = async function ({ pluginDir, nodePath, buildDir, childEnv }) {
34
- const childProcess = execaNode(CHILD_MAIN_FILE, {
35
- cwd: buildDir,
36
- preferLocal: true,
37
- localDir: pluginDir,
38
- nodePath,
39
- execPath: nodePath,
40
- env: childEnv,
41
- extendEnv: false,
42
- serialization: 'advanced',
43
- })
44
-
45
- try {
46
- await getEventFromChild(childProcess, 'ready')
47
- return { childProcess }
48
- } catch (error) {
49
- const spawnInfo = getSpawnInfo()
50
- addErrorInfo(error, spawnInfo)
51
- throw error
52
- }
53
- }
54
-
55
- // Stop all plugins child processes
56
- export const stopPlugins = function (childProcesses) {
57
- childProcesses.forEach(stopPlugin)
58
- }
59
-
60
- const stopPlugin = function ({ childProcess }) {
61
- if (childProcess.connected) {
62
- childProcess.disconnect()
63
- }
64
-
65
- childProcess.kill()
66
- }
@@ -1,49 +0,0 @@
1
- import { listCorePlugins, isCorePlugin } from './list.js'
2
-
3
- // Add core plugins and user plugins together.
4
- // Do not allow user override of core plugins.
5
- export const addCorePlugins = function ({ netlifyConfig: { plugins }, constants }) {
6
- const corePlugins = listCorePlugins(constants)
7
- const allCorePlugins = corePlugins
8
- .map((corePlugin) => addCoreProperties(corePlugin, plugins))
9
- .filter((corePlugin) => !isOptionalCore(corePlugin, plugins))
10
- const userPlugins = plugins.filter(isUserPlugin)
11
- const allPlugins = [...userPlugins, ...allCorePlugins]
12
- const pluginsOptions = allPlugins.map(normalizePluginOptions)
13
- return pluginsOptions
14
- }
15
-
16
- const addCoreProperties = function (corePlugin, plugins) {
17
- const inputs = getCorePluginInputs(corePlugin, plugins)
18
- return { ...corePlugin, inputs, loadedFrom: 'core', origin: 'core' }
19
- }
20
-
21
- // Core plugins can get inputs too
22
- const getCorePluginInputs = function (corePlugin, plugins) {
23
- const configuredCorePlugin = plugins.find((plugin) => plugin.package === corePlugin.package)
24
- if (configuredCorePlugin === undefined) {
25
- return {}
26
- }
27
-
28
- return configuredCorePlugin.inputs
29
- }
30
-
31
- // Optional core plugins requires user opt-in
32
- const isOptionalCore = function (pluginA, plugins) {
33
- return pluginA.optional && plugins.every((pluginB) => pluginB.package !== pluginA.package)
34
- }
35
-
36
- const isUserPlugin = function (plugin) {
37
- return !isCorePlugin(plugin.package)
38
- }
39
-
40
- const normalizePluginOptions = function ({
41
- package: packageName,
42
- pluginPath,
43
- pinned_version: pinnedVersion,
44
- loadedFrom,
45
- origin,
46
- inputs,
47
- }) {
48
- return { packageName, pluginPath, pinnedVersion, loadedFrom, origin, inputs }
49
- }
@@ -1,75 +0,0 @@
1
- import { platform } from 'process'
2
-
3
- import { execa } from 'execa'
4
-
5
- import { addErrorInfo } from '../error/info.js'
6
- import { getBuildCommandDescription } from '../log/description.js'
7
- import { logBuildCommandStart } from '../log/messages/steps.js'
8
- import { getBuildCommandStdio, handleBuildCommandOutput } from '../log/stream.js'
9
-
10
- // Fire `build.command`
11
- const coreStep = async function ({
12
- configPath,
13
- buildDir,
14
- nodePath,
15
- childEnv,
16
- logs,
17
- netlifyConfig: {
18
- build: { command: buildCommand, commandOrigin: buildCommandOrigin },
19
- },
20
- }) {
21
- logBuildCommandStart(logs, buildCommand)
22
-
23
- const stdio = getBuildCommandStdio(logs)
24
- const childProcess = execa(buildCommand, {
25
- shell: SHELL,
26
- cwd: buildDir,
27
- preferLocal: true,
28
- execPath: nodePath,
29
- env: childEnv,
30
- extendEnv: false,
31
- stdio,
32
- })
33
-
34
- try {
35
- const buildCommandOutput = await childProcess
36
- handleBuildCommandOutput(buildCommandOutput, logs)
37
- return {}
38
- } catch (error) {
39
- // In our test environment we use `stdio: 'pipe'` on the build command, meaning our `stdout/stderr` output are
40
- // buffered and consequently added to `error.message`. To avoid this and end up with duplicated output in our
41
- // logs/snapshots we need to rely on `error.shortMessage`.
42
- error.message = error.shortMessage
43
- handleBuildCommandOutput(error, logs)
44
- addErrorInfo(error, { type: 'buildCommand', location: { buildCommand, buildCommandOrigin, configPath } })
45
- throw error
46
- }
47
- }
48
-
49
- // We use Bash on Unix and `cmd.exe` on Windows
50
- const SHELL = platform === 'win32' ? true : 'bash'
51
-
52
- const coreStepDescription = function ({
53
- netlifyConfig: {
54
- build: { commandOrigin: buildCommandOrigin },
55
- },
56
- }) {
57
- return getBuildCommandDescription(buildCommandOrigin)
58
- }
59
-
60
- const hasBuildCommand = function ({
61
- netlifyConfig: {
62
- build: { command: buildCommand },
63
- },
64
- }) {
65
- return buildCommand !== undefined && buildCommand !== ''
66
- }
67
-
68
- export const buildCommandCore = {
69
- event: 'onBuild',
70
- coreStep,
71
- coreStepId: 'build_command',
72
- coreStepName: 'build.command',
73
- coreStepDescription,
74
- condition: hasBuildCommand,
75
- }
@@ -1,102 +0,0 @@
1
- import net from 'net'
2
- import { normalize, resolve, relative } from 'path'
3
- import { promisify } from 'util'
4
-
5
- import { pEvent } from 'p-event'
6
-
7
- import { addErrorInfo } from '../../error/info.js'
8
- import { runsAfterDeploy } from '../../plugins/events.js'
9
- import { addAsyncErrorMessage } from '../../utils/errors.js'
10
-
11
- export const createBuildbotClient = function (buildbotServerSocket) {
12
- const connectionOpts = getConnectionOpts(buildbotServerSocket)
13
- const client = net.createConnection(connectionOpts)
14
- return client
15
- }
16
-
17
- // Windows does not support Unix sockets well, so we also support `host:port`
18
- const getConnectionOpts = function (buildbotServerSocket) {
19
- if (!buildbotServerSocket.includes(':')) {
20
- return { path: buildbotServerSocket }
21
- }
22
-
23
- const [host, port] = buildbotServerSocket.split(':')
24
- return { host, port }
25
- }
26
-
27
- const eConnectBuildbotClient = async function (client) {
28
- await pEvent(client, 'connect')
29
- }
30
-
31
- export const connectBuildbotClient = addAsyncErrorMessage(eConnectBuildbotClient, 'Could not connect to buildbot')
32
-
33
- export const closeBuildbotClient = async function (client) {
34
- if (client.destroyed) {
35
- return
36
- }
37
-
38
- await promisify(client.end.bind(client))()
39
- }
40
-
41
- const cWritePayload = async function (buildbotClient, payload) {
42
- await promisify(buildbotClient.write.bind(buildbotClient))(JSON.stringify(payload))
43
- }
44
-
45
- const writePayload = addAsyncErrorMessage(cWritePayload, 'Could not send payload to buildbot')
46
-
47
- const cGetNextParsedResponsePromise = async function (buildbotClient) {
48
- const data = await pEvent(buildbotClient, 'data')
49
- return JSON.parse(data)
50
- }
51
-
52
- const getNextParsedResponsePromise = addAsyncErrorMessage(
53
- cGetNextParsedResponsePromise,
54
- 'Invalid response from buildbot',
55
- )
56
-
57
- export const deploySiteWithBuildbotClient = async function ({ client, events, buildDir, repositoryRoot, constants }) {
58
- const action = shouldWaitForPostProcessing(events) ? 'deploySiteAndAwaitLive' : 'deploySite'
59
- const deployDir = getDeployDir({ buildDir, repositoryRoot, constants })
60
- const payload = { action, deployDir }
61
-
62
- const [{ succeeded, values: { error, error_type: errorType } = {} }] = await Promise.all([
63
- getNextParsedResponsePromise(client),
64
- writePayload(client, payload),
65
- ])
66
-
67
- if (!succeeded) {
68
- return handleDeployError(error, errorType)
69
- }
70
- }
71
-
72
- // The file paths in the buildbot are relative to the repository root.
73
- // However, the file paths in Build plugins, including `constants.PUBLISH_DIR`
74
- // are relative to the build directory, which is different when there is a
75
- // base directory. This converts it.
76
- // We need to call `normalize()` in case the publish directory is the
77
- // repository root, so `deployDir` is "." not ""
78
- const getDeployDir = function ({ buildDir, repositoryRoot, constants: { PUBLISH_DIR } }) {
79
- const absolutePublishDir = resolve(buildDir, PUBLISH_DIR)
80
- const relativePublishDir = relative(repositoryRoot, absolutePublishDir)
81
- const deployDir = normalize(relativePublishDir)
82
- return deployDir
83
- }
84
-
85
- // We distinguish between user errors and system errors during deploys
86
- const handleDeployError = function (error, errorType) {
87
- const errorA = new Error(`Deploy did not succeed: ${error}`)
88
- const errorInfo =
89
- errorType === 'user' ? { type: 'resolveConfig' } : { type: 'coreStep', location: { coreStepName: 'Deploy site' } }
90
- addErrorInfo(errorA, errorInfo)
91
- throw errorA
92
- }
93
-
94
- // We only wait for post-processing (last stage before site deploy) if the build
95
- // has some plugins that do post-deploy logic
96
- const shouldWaitForPostProcessing = function (events) {
97
- return events.some(hasPostDeployLogic)
98
- }
99
-
100
- const hasPostDeployLogic = function (event) {
101
- return runsAfterDeploy(event)
102
- }
@@ -1,73 +0,0 @@
1
- import { saveUpdatedConfig, restoreUpdatedConfig } from '../../core/config.js'
2
- import { logDeploySuccess } from '../../log/messages/plugins.js'
3
-
4
- import {
5
- createBuildbotClient,
6
- connectBuildbotClient,
7
- closeBuildbotClient,
8
- deploySiteWithBuildbotClient,
9
- } from './buildbot_client.js'
10
-
11
- const coreStep = async function ({
12
- buildDir,
13
- configPath,
14
- repositoryRoot,
15
- constants,
16
- buildbotServerSocket,
17
- events,
18
- logs,
19
- featureFlags,
20
- context,
21
- branch,
22
- configMutations,
23
- headersPath,
24
- redirectsPath,
25
- debug,
26
- saveConfig,
27
- }) {
28
- const client = createBuildbotClient(buildbotServerSocket)
29
- try {
30
- await connectBuildbotClient(client)
31
- await saveUpdatedConfig({
32
- configMutations,
33
- buildDir,
34
- repositoryRoot,
35
- configPath,
36
- headersPath,
37
- redirectsPath,
38
- logs,
39
- featureFlags,
40
- context,
41
- branch,
42
- debug,
43
- saveConfig,
44
- })
45
- await deploySiteWithBuildbotClient({ client, events, buildDir, repositoryRoot, constants })
46
- await restoreUpdatedConfig({
47
- configMutations,
48
- buildDir,
49
- repositoryRoot,
50
- configPath,
51
- headersPath,
52
- redirectsPath,
53
- saveConfig,
54
- })
55
- logDeploySuccess(logs)
56
- return {}
57
- } finally {
58
- await closeBuildbotClient(client)
59
- }
60
- }
61
-
62
- const shouldDeploy = function ({ buildbotServerSocket }) {
63
- return buildbotServerSocket !== undefined
64
- }
65
-
66
- export const deploySite = {
67
- event: 'onPostBuild',
68
- coreStep,
69
- coreStepId: 'deploy_site',
70
- coreStepName: 'Deploy site',
71
- coreStepDescription: () => 'Deploy site',
72
- condition: shouldDeploy,
73
- }
@@ -1,123 +0,0 @@
1
- import { promises as fs } from 'fs'
2
- import { dirname, join, resolve } from 'path'
3
-
4
- import { bundle, find } from '@netlify/edge-bundler'
5
- import { pathExists } from 'path-exists'
6
-
7
- import { logFunctionsToBundle } from '../../log/messages/core_steps.js'
8
-
9
- import { tagBundlingError } from './lib/error.js'
10
- import { parseManifest } from './lib/internal_manifest.js'
11
- import { validateEdgeFunctionsManifest } from './validate_manifest/validate_edge_functions_manifest.js'
12
-
13
- // TODO: Replace this with a custom cache directory.
14
- const DENO_CLI_CACHE_DIRECTORY = '.netlify/plugins/deno-cli'
15
- const IMPORT_MAP_FILENAME = 'edge-functions-import-map.json'
16
-
17
- // eslint-disable-next-line complexity, max-statements
18
- const coreStep = async function ({
19
- buildDir,
20
- constants: {
21
- EDGE_FUNCTIONS_DIST: distDirectory,
22
- EDGE_FUNCTIONS_SRC: srcDirectory,
23
- INTERNAL_EDGE_FUNCTIONS_SRC: internalSrcDirectory,
24
- IS_LOCAL: isRunningLocally,
25
- },
26
- debug,
27
- systemLog,
28
- featureFlags,
29
- logs,
30
- netlifyConfig,
31
- }) {
32
- const { edge_functions: configDeclarations = [] } = netlifyConfig
33
- const distPath = resolve(buildDir, distDirectory)
34
- const internalSrcPath = resolve(buildDir, internalSrcDirectory)
35
- const distImportMapPath = join(dirname(internalSrcPath), IMPORT_MAP_FILENAME)
36
- const srcPath = srcDirectory ? resolve(buildDir, srcDirectory) : undefined
37
- const sourcePaths = [internalSrcPath, srcPath].filter(Boolean)
38
-
39
- logFunctions({ internalSrcDirectory, internalSrcPath, logs, srcDirectory, srcPath })
40
-
41
- const { declarations: internalDeclarations, importMap } = await parseManifest(internalSrcPath)
42
- const declarations = [...configDeclarations, ...internalDeclarations]
43
-
44
- // If we're running in buildbot and the feature flag is enabled, we set the
45
- // Deno cache dir to a directory that is persisted between builds.
46
- const cacheDirectory =
47
- !isRunningLocally && featureFlags.edge_functions_cache_cli ? resolve(buildDir, DENO_CLI_CACHE_DIRECTORY) : undefined
48
-
49
- // Edge Bundler expects the dist directory to exist.
50
- await fs.mkdir(distPath, { recursive: true })
51
-
52
- try {
53
- const { manifest } = await bundle(sourcePaths, distPath, declarations, {
54
- basePath: buildDir,
55
- cacheDirectory,
56
- debug,
57
- distImportMapPath,
58
- featureFlags,
59
- importMaps: [importMap].filter(Boolean),
60
- systemLogger: featureFlags.edge_functions_system_logger ? systemLog : undefined,
61
- })
62
-
63
- systemLog('Edge Functions manifest:', manifest)
64
- } catch (error) {
65
- tagBundlingError(error)
66
-
67
- throw error
68
- }
69
-
70
- await validateEdgeFunctionsManifest({ buildDir, constants: { EDGE_FUNCTIONS_DIST: distDirectory } })
71
-
72
- return {}
73
- }
74
-
75
- // We run this core step if at least one of the functions directories (the
76
- // one configured by the user or the internal one) exists. We use a dynamic
77
- // `condition` because the directories might be created by the build command
78
- // or plugins.
79
- const hasEdgeFunctionsDirectories = async function ({
80
- buildDir,
81
- constants: { INTERNAL_EDGE_FUNCTIONS_SRC, EDGE_FUNCTIONS_SRC },
82
- }) {
83
- const hasFunctionsSrc = EDGE_FUNCTIONS_SRC !== undefined && EDGE_FUNCTIONS_SRC !== ''
84
-
85
- if (hasFunctionsSrc) {
86
- return true
87
- }
88
-
89
- const internalFunctionsSrc = resolve(buildDir, INTERNAL_EDGE_FUNCTIONS_SRC)
90
-
91
- return await pathExists(internalFunctionsSrc)
92
- }
93
-
94
- const logFunctions = async ({
95
- internalSrcDirectory,
96
- internalSrcPath,
97
- logs,
98
- srcDirectory: userFunctionsSrc,
99
- srcPath,
100
- }) => {
101
- const [userFunctions, internalFunctions] = await Promise.all([find([srcPath]), find([internalSrcPath])])
102
- const userFunctionsSrcExists = await pathExists(srcPath)
103
- const internalFunctionsSrc = internalSrcDirectory
104
-
105
- logFunctionsToBundle({
106
- logs,
107
- userFunctions: userFunctions.map(({ name }) => name),
108
- userFunctionsSrc,
109
- userFunctionsSrcExists,
110
- internalFunctions: internalFunctions.map(({ name }) => name),
111
- internalFunctionsSrc,
112
- type: 'Edge Functions',
113
- })
114
- }
115
-
116
- export const bundleEdgeFunctions = {
117
- event: 'onBuild',
118
- coreStep,
119
- coreStepId: 'edge_functions_bundling',
120
- coreStepName: 'Edge Functions bundling',
121
- coreStepDescription: () => 'Edge Functions bundling',
122
- condition: hasEdgeFunctionsDirectories,
123
- }
@@ -1,54 +0,0 @@
1
- import { promises as fs } from 'fs'
2
- import { dirname, join, resolve } from 'path'
3
-
4
- const parseManifest = async (internalSourceDirectory) => {
5
- const manifestPath = join(internalSourceDirectory, 'manifest.json')
6
-
7
- try {
8
- const data = await fs.readFile(manifestPath)
9
- const manifest = JSON.parse(data)
10
-
11
- if (manifest.version !== 1) {
12
- throw new Error('Unsupported manifest version')
13
- }
14
-
15
- const result = {
16
- declarations: manifest.functions,
17
- }
18
-
19
- if (manifest.import_map) {
20
- const importMapPath = resolve(dirname(manifestPath), manifest.import_map)
21
- const importMap = await readImportMap(importMapPath)
22
-
23
- return {
24
- ...result,
25
- importMap,
26
- }
27
- }
28
-
29
- return result
30
- } catch {
31
- // no-op
32
- }
33
-
34
- return {
35
- declarations: [],
36
- }
37
- }
38
-
39
- const readImportMap = async (path) => {
40
- try {
41
- const data = await fs.readFile(path)
42
- const importMap = JSON.parse(data)
43
-
44
- return importMap
45
- } catch {
46
- // no-op
47
- }
48
-
49
- return {
50
- imports: {},
51
- }
52
- }
53
-
54
- export { parseManifest }