@netlify/build 28.0.0-rc → 28.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) 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 +123 -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 +20 -0
  15. package/lib/core/user_node_version.js +32 -0
  16. package/lib/env/changes.js +43 -0
  17. package/lib/env/main.js +14 -0
  18. package/lib/env/metadata.js +68 -0
  19. package/lib/error/api.js +37 -0
  20. package/lib/error/build.js +36 -0
  21. package/{src → lib}/error/cancel.js +5 -6
  22. package/lib/error/colors.js +9 -0
  23. package/lib/error/handle.js +46 -0
  24. package/lib/error/info.js +37 -0
  25. package/lib/error/monitor/location.js +16 -0
  26. package/lib/error/monitor/normalize.js +86 -0
  27. package/lib/error/monitor/print.js +20 -0
  28. package/lib/error/monitor/report.js +120 -0
  29. package/lib/error/monitor/start.js +58 -0
  30. package/lib/error/parse/clean_stack.js +70 -0
  31. package/lib/error/parse/location.js +50 -0
  32. package/lib/error/parse/normalize.js +24 -0
  33. package/lib/error/parse/parse.js +67 -0
  34. package/lib/error/parse/plugin.js +55 -0
  35. package/lib/error/parse/properties.js +16 -0
  36. package/lib/error/parse/serialize_log.js +34 -0
  37. package/lib/error/parse/serialize_status.js +18 -0
  38. package/lib/error/parse/stack.js +34 -0
  39. package/lib/error/type.js +171 -0
  40. package/lib/install/functions.js +20 -0
  41. package/lib/install/local.js +45 -0
  42. package/lib/install/main.js +67 -0
  43. package/lib/install/missing.js +54 -0
  44. package/{src → lib}/log/colors.js +15 -22
  45. package/lib/log/description.js +21 -0
  46. package/lib/log/header.js +14 -0
  47. package/lib/log/header_func.js +13 -0
  48. package/lib/log/logger.js +130 -0
  49. package/lib/log/messages/compatibility.js +120 -0
  50. package/lib/log/messages/config.js +91 -0
  51. package/lib/log/messages/core.js +50 -0
  52. package/lib/log/messages/core_steps.js +75 -0
  53. package/lib/log/messages/dry.js +41 -0
  54. package/lib/log/messages/install.js +25 -0
  55. package/lib/log/messages/ipc.js +29 -0
  56. package/lib/log/messages/mutations.js +62 -0
  57. package/{src → lib}/log/messages/plugins.js +18 -32
  58. package/lib/log/messages/status.js +14 -0
  59. package/lib/log/messages/steps.js +18 -0
  60. package/lib/log/old_version.js +32 -0
  61. package/lib/log/serialize.js +10 -0
  62. package/lib/log/stream.js +68 -0
  63. package/lib/log/theme.js +25 -0
  64. package/lib/plugins/child/diff.js +46 -0
  65. package/lib/plugins/child/error.js +26 -0
  66. package/lib/plugins/child/lazy.js +15 -0
  67. package/lib/plugins/child/load.js +22 -0
  68. package/lib/plugins/child/logic.js +57 -0
  69. package/lib/plugins/child/main.js +37 -0
  70. package/lib/plugins/child/run.js +19 -0
  71. package/lib/plugins/child/status.js +63 -0
  72. package/lib/plugins/child/typescript.js +28 -0
  73. package/lib/plugins/child/utils.js +42 -0
  74. package/lib/plugins/child/validate.js +31 -0
  75. package/lib/plugins/compatibility.js +104 -0
  76. package/{src → lib}/plugins/error.js +31 -35
  77. package/{src → lib}/plugins/events.js +7 -12
  78. package/lib/plugins/expected_version.js +81 -0
  79. package/lib/plugins/ipc.js +120 -0
  80. package/lib/plugins/list.js +73 -0
  81. package/lib/plugins/load.js +50 -0
  82. package/lib/plugins/manifest/check.js +85 -0
  83. package/lib/plugins/manifest/load.js +38 -0
  84. package/lib/plugins/manifest/main.js +17 -0
  85. package/lib/plugins/manifest/path.js +24 -0
  86. package/lib/plugins/manifest/validate.js +91 -0
  87. package/lib/plugins/node_version.js +30 -0
  88. package/lib/plugins/options.js +55 -0
  89. package/lib/plugins/pinned_version.js +83 -0
  90. package/lib/plugins/resolve.js +110 -0
  91. package/lib/plugins/spawn.js +54 -0
  92. package/lib/plugins_core/add.js +35 -0
  93. package/lib/plugins_core/build_command.js +50 -0
  94. package/lib/plugins_core/deploy/buildbot_client.js +87 -0
  95. package/lib/plugins_core/deploy/index.js +49 -0
  96. package/{src → lib}/plugins_core/deploy/manifest.yml +0 -0
  97. package/lib/plugins_core/edge_functions/index.js +79 -0
  98. package/{src → lib}/plugins_core/edge_functions/lib/error.js +13 -17
  99. package/lib/plugins_core/edge_functions/lib/internal_manifest.js +50 -0
  100. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +75 -0
  101. package/lib/plugins_core/functions/error.js +123 -0
  102. package/lib/plugins_core/functions/feature_flags.js +6 -0
  103. package/lib/plugins_core/functions/index.js +114 -0
  104. package/lib/plugins_core/functions/utils.js +45 -0
  105. package/lib/plugins_core/functions/zisi.js +39 -0
  106. package/{src → lib}/plugins_core/functions_install/index.js +8 -11
  107. package/{src → lib}/plugins_core/functions_install/manifest.yml +0 -0
  108. package/lib/plugins_core/list.js +20 -0
  109. package/lib/status/add.js +30 -0
  110. package/lib/status/colors.js +18 -0
  111. package/lib/status/load_error.js +10 -0
  112. package/lib/status/report.js +83 -0
  113. package/lib/status/success.js +14 -0
  114. package/lib/steps/core_step.js +57 -0
  115. package/lib/steps/error.js +65 -0
  116. package/lib/steps/get.js +43 -0
  117. package/lib/steps/plugin.js +55 -0
  118. package/lib/steps/return.js +25 -0
  119. package/lib/steps/run_core_steps.js +147 -0
  120. package/lib/steps/run_step.js +188 -0
  121. package/lib/steps/run_steps.js +96 -0
  122. package/lib/steps/update_config.js +66 -0
  123. package/lib/telemetry/main.js +97 -0
  124. package/lib/time/aggregate.js +120 -0
  125. package/lib/time/main.js +37 -0
  126. package/lib/time/measure.js +18 -0
  127. package/lib/time/report.js +47 -0
  128. package/lib/utils/errors.js +13 -0
  129. package/lib/utils/json.js +15 -0
  130. package/{src → lib}/utils/omit.js +3 -4
  131. package/lib/utils/package.js +22 -0
  132. package/lib/utils/remove_falsy.js +8 -0
  133. package/lib/utils/resolve.js +41 -0
  134. package/lib/utils/runtime.js +5 -0
  135. package/lib/utils/semver.js +28 -0
  136. package/package.json +37 -20
  137. package/types/config/netlify_config.d.ts +4 -4
  138. package/types/netlify_plugin_constants.d.ts +8 -8
  139. package/src/core/bin.js +0 -83
  140. package/src/core/config.js +0 -186
  141. package/src/core/constants.js +0 -156
  142. package/src/core/dry.js +0 -39
  143. package/src/core/feature_flags.js +0 -21
  144. package/src/core/flags.js +0 -199
  145. package/src/core/lingering.js +0 -85
  146. package/src/core/main.js +0 -703
  147. package/src/core/missing_side_file.js +0 -29
  148. package/src/core/normalize_flags.js +0 -69
  149. package/src/core/severity.js +0 -22
  150. package/src/core/user_node_version.js +0 -41
  151. package/src/env/changes.js +0 -52
  152. package/src/env/main.js +0 -19
  153. package/src/env/metadata.js +0 -81
  154. package/src/error/api.js +0 -46
  155. package/src/error/build.js +0 -50
  156. package/src/error/colors.js +0 -11
  157. package/src/error/handle.js +0 -57
  158. package/src/error/info.js +0 -46
  159. package/src/error/monitor/location.js +0 -21
  160. package/src/error/monitor/normalize.js +0 -96
  161. package/src/error/monitor/print.js +0 -42
  162. package/src/error/monitor/report.js +0 -138
  163. package/src/error/monitor/start.js +0 -69
  164. package/src/error/parse/clean_stack.js +0 -87
  165. package/src/error/parse/location.js +0 -62
  166. package/src/error/parse/normalize.js +0 -29
  167. package/src/error/parse/parse.js +0 -97
  168. package/src/error/parse/plugin.js +0 -70
  169. package/src/error/parse/properties.js +0 -23
  170. package/src/error/parse/serialize_log.js +0 -42
  171. package/src/error/parse/serialize_status.js +0 -23
  172. package/src/error/parse/stack.js +0 -43
  173. package/src/error/type.js +0 -189
  174. package/src/install/functions.js +0 -28
  175. package/src/install/local.js +0 -62
  176. package/src/install/main.js +0 -81
  177. package/src/install/missing.js +0 -67
  178. package/src/log/description.js +0 -26
  179. package/src/log/header.js +0 -16
  180. package/src/log/header_func.js +0 -17
  181. package/src/log/logger.js +0 -142
  182. package/src/log/messages/compatibility.js +0 -164
  183. package/src/log/messages/config.js +0 -105
  184. package/src/log/messages/core.js +0 -70
  185. package/src/log/messages/core_steps.js +0 -104
  186. package/src/log/messages/dry.js +0 -63
  187. package/src/log/messages/install.js +0 -20
  188. package/src/log/messages/ipc.js +0 -38
  189. package/src/log/messages/mutations.js +0 -82
  190. package/src/log/messages/status.js +0 -16
  191. package/src/log/messages/steps.js +0 -22
  192. package/src/log/old_version.js +0 -41
  193. package/src/log/serialize.js +0 -13
  194. package/src/log/stream.js +0 -85
  195. package/src/log/theme.js +0 -26
  196. package/src/plugins/child/diff.js +0 -55
  197. package/src/plugins/child/error.js +0 -32
  198. package/src/plugins/child/lazy.js +0 -18
  199. package/src/plugins/child/load.js +0 -29
  200. package/src/plugins/child/logic.js +0 -57
  201. package/src/plugins/child/main.js +0 -51
  202. package/src/plugins/child/run.js +0 -28
  203. package/src/plugins/child/status.js +0 -74
  204. package/src/plugins/child/typescript.js +0 -45
  205. package/src/plugins/child/utils.js +0 -56
  206. package/src/plugins/child/validate.js +0 -34
  207. package/src/plugins/compatibility.js +0 -128
  208. package/src/plugins/expected_version.js +0 -119
  209. package/src/plugins/ipc.js +0 -145
  210. package/src/plugins/list.js +0 -86
  211. package/src/plugins/load.js +0 -70
  212. package/src/plugins/manifest/check.js +0 -106
  213. package/src/plugins/manifest/load.js +0 -41
  214. package/src/plugins/manifest/main.js +0 -22
  215. package/src/plugins/manifest/path.js +0 -31
  216. package/src/plugins/manifest/validate.js +0 -108
  217. package/src/plugins/node_version.js +0 -50
  218. package/src/plugins/options.js +0 -88
  219. package/src/plugins/pinned_version.js +0 -131
  220. package/src/plugins/resolve.js +0 -152
  221. package/src/plugins/spawn.js +0 -66
  222. package/src/plugins_core/add.js +0 -49
  223. package/src/plugins_core/build_command.js +0 -75
  224. package/src/plugins_core/deploy/buildbot_client.js +0 -102
  225. package/src/plugins_core/deploy/index.js +0 -73
  226. package/src/plugins_core/edge_functions/index.js +0 -122
  227. package/src/plugins_core/edge_functions/lib/internal_manifest.js +0 -54
  228. package/src/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +0 -89
  229. package/src/plugins_core/functions/error.js +0 -163
  230. package/src/plugins_core/functions/feature_flags.js +0 -6
  231. package/src/plugins_core/functions/index.js +0 -160
  232. package/src/plugins_core/functions/utils.js +0 -66
  233. package/src/plugins_core/functions/zisi.js +0 -53
  234. package/src/plugins_core/list.js +0 -27
  235. package/src/status/add.js +0 -36
  236. package/src/status/colors.js +0 -23
  237. package/src/status/load_error.js +0 -11
  238. package/src/status/report.js +0 -137
  239. package/src/status/success.js +0 -18
  240. package/src/steps/core_step.js +0 -92
  241. package/src/steps/error.js +0 -102
  242. package/src/steps/get.js +0 -32
  243. package/src/steps/plugin.js +0 -85
  244. package/src/steps/return.js +0 -52
  245. package/src/steps/run_core_steps.js +0 -194
  246. package/src/steps/run_step.js +0 -306
  247. package/src/steps/run_steps.js +0 -181
  248. package/src/steps/update_config.js +0 -93
  249. package/src/telemetry/main.js +0 -136
  250. package/src/time/aggregate.js +0 -146
  251. package/src/time/main.js +0 -48
  252. package/src/time/measure.js +0 -22
  253. package/src/time/report.js +0 -59
  254. package/src/utils/errors.js +0 -12
  255. package/src/utils/json.js +0 -19
  256. package/src/utils/package.js +0 -23
  257. package/src/utils/remove_falsy.js +0 -10
  258. package/src/utils/resolve.js +0 -46
  259. package/src/utils/semver.js +0 -34
@@ -1,163 +0,0 @@
1
- import readdirp from 'readdirp'
2
-
3
- import { addErrorInfo } from '../../error/info.js'
4
-
5
- const MODULE_NOT_FOUND_CODE = 'MODULE_NOT_FOUND'
6
- const MODULE_NOT_FOUND_ESBUILD_REGEXP = /^Could not resolve ['"]([^'"]+)/
7
- const MODULE_NOT_FOUND_REGEXP = /Cannot find module ['"]([^'"]+)/
8
-
9
- // Handle errors coming from zip-it-and-ship-it
10
- export const getZipError = async function (error, functionsSrc) {
11
- const moduleNotFoundError = await getModuleNotFoundError(error, functionsSrc)
12
-
13
- if (moduleNotFoundError) {
14
- return moduleNotFoundError
15
- }
16
-
17
- if (isPackageJsonError(error)) {
18
- return getPackageJsonError(error)
19
- }
20
-
21
- return error
22
- }
23
-
24
- const getModuleNotFoundError = async function (error, functionsSrc) {
25
- const errorFromZisi = await getModuleNotFoundErrorFromZISI(error, functionsSrc)
26
-
27
- if (errorFromZisi) {
28
- return errorFromZisi
29
- }
30
-
31
- const errorFromEsbuild = await getModuleNotFoundErrorFromEsbuild(error, functionsSrc)
32
-
33
- if (errorFromEsbuild) {
34
- return errorFromEsbuild
35
- }
36
- }
37
-
38
- const getModuleNotFoundErrorObject = async ({ error, functionsSrc, moduleNames }) => {
39
- const message = await getModuleNotFoundMessage(functionsSrc, moduleNames)
40
-
41
- error.message = `${message}\n\n${error.message}`
42
- addErrorInfo(error, { type: 'dependencies' })
43
-
44
- return error
45
- }
46
-
47
- const getModuleNotFoundMessage = async function (functionsSrc, moduleNames) {
48
- if (moduleNames.length === 0 || !(await lacksNodeModules(functionsSrc))) {
49
- return MODULE_NOT_FOUND_MESSAGE
50
- }
51
-
52
- if (moduleNames.filter(Boolean).some(isLocalPath)) {
53
- return PATH_NOT_FOUND_MESSAGE
54
- }
55
-
56
- return getLocalInstallMessage(moduleNames)
57
- }
58
-
59
- const isLocalPath = function (moduleName) {
60
- return moduleName.startsWith('.') || moduleName.startsWith('/')
61
- }
62
-
63
- const getModuleNotFoundErrorFromEsbuild = function (error, functionsSrc) {
64
- const { errors = [] } = error
65
- const modulesNotFound = errors.reduce((modules, errorObject) => {
66
- const match = errorObject.text.match(MODULE_NOT_FOUND_ESBUILD_REGEXP)
67
-
68
- if (!match) {
69
- return modules
70
- }
71
-
72
- return [...modules, match[1]]
73
- }, [])
74
-
75
- if (modulesNotFound.length === 0) {
76
- return
77
- }
78
-
79
- return getModuleNotFoundErrorObject({ error, functionsSrc, moduleNames: modulesNotFound })
80
- }
81
-
82
- const getModuleNotFoundErrorFromZISI = function (error, functionsSrc) {
83
- if (!(error instanceof Error && error.code === MODULE_NOT_FOUND_CODE)) {
84
- return
85
- }
86
-
87
- const moduleName = getModuleNameFromZISIError(error)
88
-
89
- return getModuleNotFoundErrorObject({ error, functionsSrc, moduleNames: moduleName ? [moduleName] : [] })
90
- }
91
-
92
- // This error message always include the same words
93
- const getModuleNameFromZISIError = function (error) {
94
- if (typeof error.message !== 'string') {
95
- return
96
- }
97
-
98
- const result = MODULE_NOT_FOUND_REGEXP.exec(error.message)
99
- if (result === null) {
100
- return
101
- }
102
-
103
- return result[1]
104
- }
105
-
106
- // Netlify Functions has a `package.json` but no `node_modules`
107
- const lacksNodeModules = async function (functionsSrc) {
108
- return (
109
- functionsSrc !== undefined &&
110
- (await hasFunctionRootFile('package.json', functionsSrc)) &&
111
- !(await hasFunctionRootFile('node_modules', functionsSrc))
112
- )
113
- }
114
-
115
- // Functions can be either files or directories, so we need to check on two
116
- // depth levels
117
- const hasFunctionRootFile = async function (filename, functionsSrc) {
118
- const files = await readdirp.promise(functionsSrc, { depth: 1, fileFilter: filename })
119
- return files.length !== 0
120
- }
121
-
122
- const MODULE_NOT_FOUND_MESSAGE = `A Netlify Function failed to require one of its dependencies.
123
- Please make sure it is present in the site's top-level "package.json".`
124
- const PATH_NOT_FOUND_MESSAGE = `A Netlify Function failed to require a local file.
125
- Please make sure the file exists and its path is correctly spelled.`
126
-
127
- // A common mistake is to assume Netlify Functions dependencies are
128
- // automatically installed. This checks for this pattern.
129
- const getLocalInstallMessage = function (modules) {
130
- const genericMessage = `
131
-
132
- By default, dependencies inside a Netlify Function's "package.json" are not automatically installed.
133
- There are several ways to fix this problem:
134
- - Removing your Function's "package.json" and adding the dependencies to the project's top-level "package.json" instead. This is the fastest and safest solution.
135
- - Running "npm install" or "yarn" inside your Netlify Function in your build command.
136
- - Adding the following plugin to your "netlify.toml":
137
-
138
- [[plugins]]
139
- package = "@netlify/plugin-functions-install-core"
140
- `
141
-
142
- if (modules.length === 1) {
143
- return `A Netlify Function is using "${modules[0]}" but that dependency has not been installed yet.${genericMessage}`
144
- }
145
-
146
- const moduleNames = modules.map((name) => `"${name}"`).join(', ')
147
-
148
- return `A Netlify Function is using dependencies that have not been installed yet: ${moduleNames}${genericMessage}`
149
- }
150
-
151
- // We need to load the site's `package.json` when bundling Functions. This is
152
- // because `optionalDependencies` can make `import()` fail, but we don't want
153
- // to error then. However, if the `package.json` is invalid, we fail the build.
154
- const isPackageJsonError = function (error) {
155
- return PACKAGE_JSON_ORIGINAL_MESSAGES.some((msg) => error.message.includes(msg))
156
- }
157
-
158
- const PACKAGE_JSON_ORIGINAL_MESSAGES = ['is invalid JSON', 'in JSON at position']
159
-
160
- const getPackageJsonError = function (error) {
161
- addErrorInfo(error, { type: 'resolveConfig' })
162
- return error
163
- }
@@ -1,6 +0,0 @@
1
- export const getZisiFeatureFlags = (featureFlags) => ({
2
- ...featureFlags,
3
- defaultEsModulesToEsbuild: featureFlags.buildbot_es_modules_esbuild,
4
- parseWithEsbuild: featureFlags.buildbot_zisi_esbuild_parser,
5
- traceWithNft: featureFlags.buildbot_zisi_trace_nft,
6
- })
@@ -1,160 +0,0 @@
1
- import { resolve } from 'path'
2
-
3
- import { zipFunctions } from '@netlify/zip-it-and-ship-it'
4
- import { pathExists } from 'path-exists'
5
-
6
- import { log } from '../../log/logger.js'
7
- import { logBundleResults, logFunctionsNonExistingDir, logFunctionsToBundle } from '../../log/messages/core_steps.js'
8
-
9
- import { getZipError } from './error.js'
10
- import { getUserAndInternalFunctions, validateFunctionsSrc } from './utils.js'
11
- import { getZisiParameters } from './zisi.js'
12
-
13
- // Returns `true` if at least one of the functions has been configured to use
14
- // esbuild.
15
- const isUsingEsbuild = (functionsConfig = {}) =>
16
- Object.values(functionsConfig).some((configObject) => configObject.node_bundler === 'esbuild')
17
-
18
- const zipFunctionsAndLogResults = async ({
19
- buildDir,
20
- childEnv,
21
- featureFlags,
22
- functionsConfig,
23
- functionsDist,
24
- functionsSrc,
25
- internalFunctionsSrc,
26
- isRunningLocally,
27
- logs,
28
- repositoryRoot,
29
- }) => {
30
- const zisiParameters = getZisiParameters({
31
- buildDir,
32
- childEnv,
33
- featureFlags,
34
- functionsConfig,
35
- functionsDist,
36
- isRunningLocally,
37
- repositoryRoot,
38
- })
39
- const bundler = isUsingEsbuild(functionsConfig) ? 'esbuild' : 'zisi'
40
-
41
- try {
42
- // Printing an empty line before bundling output.
43
- log(logs, '')
44
-
45
- const sourceDirectories = [internalFunctionsSrc, functionsSrc].filter(Boolean)
46
- const results = await zipItAndShipIt.zipFunctions(sourceDirectories, functionsDist, zisiParameters)
47
-
48
- logBundleResults({ logs, results })
49
-
50
- return { bundler }
51
- } catch (error) {
52
- throw await getZipError(error, functionsSrc)
53
- }
54
- }
55
-
56
- // Plugin to package Netlify functions with @netlify/zip-it-and-ship-it
57
- // eslint-disable-next-line complexity
58
- const coreStep = async function ({
59
- childEnv,
60
- constants: {
61
- INTERNAL_FUNCTIONS_SRC: relativeInternalFunctionsSrc,
62
- IS_LOCAL: isRunningLocally,
63
- FUNCTIONS_SRC: relativeFunctionsSrc,
64
- FUNCTIONS_DIST: relativeFunctionsDist,
65
- },
66
- buildDir,
67
- logs,
68
- netlifyConfig,
69
- featureFlags,
70
- repositoryRoot,
71
- }) {
72
- const functionsSrc = relativeFunctionsSrc === undefined ? undefined : resolve(buildDir, relativeFunctionsSrc)
73
- const functionsDist = resolve(buildDir, relativeFunctionsDist)
74
- const internalFunctionsSrc = resolve(buildDir, relativeInternalFunctionsSrc)
75
- const internalFunctionsSrcExists = await pathExists(internalFunctionsSrc)
76
- const functionsSrcExists = await validateFunctionsSrc({ functionsSrc, logs, relativeFunctionsSrc })
77
- const [userFunctions = [], internalFunctions = []] = await getUserAndInternalFunctions({
78
- featureFlags,
79
- functionsSrc,
80
- functionsSrcExists,
81
- internalFunctionsSrc,
82
- internalFunctionsSrcExists,
83
- })
84
-
85
- if (functionsSrc && !functionsSrcExists) {
86
- logFunctionsNonExistingDir(logs, relativeFunctionsSrc)
87
-
88
- if (internalFunctions.length !== 0) {
89
- log(logs, '')
90
- }
91
- }
92
-
93
- logFunctionsToBundle({
94
- logs,
95
- userFunctions,
96
- userFunctionsSrc: relativeFunctionsSrc,
97
- userFunctionsSrcExists: functionsSrcExists,
98
- internalFunctions,
99
- internalFunctionsSrc: relativeInternalFunctionsSrc,
100
- })
101
-
102
- if (userFunctions.length === 0 && internalFunctions.length === 0) {
103
- return {}
104
- }
105
-
106
- const { bundler } = await zipFunctionsAndLogResults({
107
- buildDir,
108
- childEnv,
109
- featureFlags,
110
- functionsConfig: netlifyConfig.functions,
111
- functionsDist,
112
- functionsSrc,
113
- internalFunctionsSrc,
114
- isRunningLocally,
115
- logs,
116
- repositoryRoot,
117
- })
118
-
119
- return {
120
- tags: {
121
- bundler,
122
- },
123
- }
124
- }
125
-
126
- // We run this core step if at least one of the functions directories (the
127
- // one configured by the user or the internal one) exists. We use a dynamic
128
- // `condition` because the directories might be created by the build command
129
- // or plugins.
130
- const hasFunctionsDirectories = async function ({ buildDir, constants: { INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC } }) {
131
- const hasFunctionsSrc = FUNCTIONS_SRC !== undefined && FUNCTIONS_SRC !== ''
132
-
133
- if (hasFunctionsSrc) {
134
- return true
135
- }
136
-
137
- const internalFunctionsSrc = resolve(buildDir, INTERNAL_FUNCTIONS_SRC)
138
-
139
- return await pathExists(internalFunctionsSrc)
140
- }
141
-
142
- export const bundleFunctions = {
143
- event: 'onBuild',
144
- coreStep,
145
- coreStepId: 'functions_bundling',
146
- coreStepName: 'Functions bundling',
147
- coreStepDescription: () => 'Functions bundling',
148
- condition: hasFunctionsDirectories,
149
- }
150
-
151
- // Named imports with ES modules cannot be mocked (unlike CommonJS) because
152
- // they are bound at load time.
153
- // However, some of our tests are asserting which arguments are passed to
154
- // `zip-it-and-ship-it` methods. Therefore, we need to use an intermediary
155
- // function and export them so tests can use it.
156
- export const zipItAndShipIt = {
157
- async zipFunctions(...args) {
158
- return await zipFunctions(...args)
159
- },
160
- }
@@ -1,66 +0,0 @@
1
- import { promises as fs } from 'fs'
2
- import { relative } from 'path'
3
-
4
- import { listFunctions } from '@netlify/zip-it-and-ship-it'
5
-
6
- import { addErrorInfo } from '../../error/info.js'
7
-
8
- import { getZisiFeatureFlags } from './feature_flags.js'
9
-
10
- // Returns the `mainFile` of each function found in `functionsSrc`, relative to
11
- // `functionsSrc`.
12
- const getRelativeFunctionMainFiles = async function ({ featureFlags, functionsSrc }) {
13
- if (functionsSrc === undefined) {
14
- return []
15
- }
16
-
17
- const zisiFeatureFlags = getZisiFeatureFlags(featureFlags)
18
- const functions = await listFunctions(functionsSrc, { featureFlags: zisiFeatureFlags })
19
- return functions.map(({ mainFile }) => relative(functionsSrc, mainFile))
20
- }
21
-
22
- export const getUserAndInternalFunctions = ({
23
- featureFlags,
24
- functionsSrc,
25
- functionsSrcExists,
26
- internalFunctionsSrc,
27
- internalFunctionsSrcExists,
28
- }) => {
29
- const paths = [
30
- functionsSrcExists ? functionsSrc : undefined,
31
- internalFunctionsSrcExists ? internalFunctionsSrc : undefined,
32
- ]
33
-
34
- return Promise.all(paths.map((path) => path && getRelativeFunctionMainFiles({ featureFlags, functionsSrc: path })))
35
- }
36
-
37
- // Returns `true` if the functions directory exists and is valid. Returns
38
- // `false` if it doesn't exist. Throws an error if it's invalid or can't
39
- // be accessed.
40
- export const validateFunctionsSrc = async function ({ functionsSrc, relativeFunctionsSrc }) {
41
- if (functionsSrc === undefined) {
42
- return false
43
- }
44
-
45
- try {
46
- const stats = await fs.stat(functionsSrc)
47
-
48
- if (stats.isDirectory()) {
49
- return true
50
- }
51
-
52
- const error = new Error(
53
- `The Netlify Functions setting should target a directory, not a regular file: ${relativeFunctionsSrc}`,
54
- )
55
-
56
- addErrorInfo(error, { type: 'resolveConfig' })
57
-
58
- throw error
59
- } catch (error) {
60
- if (error.code === 'ENOENT') {
61
- return false
62
- }
63
-
64
- throw error
65
- }
66
- }
@@ -1,53 +0,0 @@
1
- import { join, resolve } from 'path'
2
-
3
- import mapObject from 'map-obj'
4
-
5
- import { getZisiFeatureFlags } from './feature_flags.js'
6
-
7
- export const getZisiParameters = ({
8
- buildDir,
9
- childEnv,
10
- featureFlags,
11
- functionsConfig,
12
- functionsDist,
13
- isRunningLocally,
14
- repositoryRoot,
15
- }) => {
16
- const nodeVersion = childEnv.AWS_LAMBDA_JS_RUNTIME
17
- const manifest = join(functionsDist, 'manifest.json')
18
- const config = mapObject(functionsConfig, (expression, object) => [
19
- expression,
20
- normalizeFunctionConfig({ buildDir, featureFlags, functionConfig: object, isRunningLocally, nodeVersion }),
21
- ])
22
- const zisiFeatureFlags = getZisiFeatureFlags(featureFlags)
23
-
24
- return { basePath: buildDir, config, manifest, featureFlags: zisiFeatureFlags, repositoryRoot }
25
- }
26
-
27
- // The function configuration keys returned by @netlify/config are not an exact
28
- // match to the properties that @netlify/zip-it-and-ship-it expects. We do that
29
- // translation here.
30
- export const normalizeFunctionConfig = ({ buildDir, functionConfig = {}, isRunningLocally, nodeVersion }) => ({
31
- externalNodeModules: functionConfig.external_node_modules,
32
- includedFiles: functionConfig.included_files,
33
- includedFilesBasePath: buildDir,
34
- ignoredNodeModules: functionConfig.ignored_node_modules,
35
- nodeVersion,
36
- schedule: functionConfig.schedule,
37
-
38
- // When the user selects esbuild as the Node bundler, we still want to use
39
- // the legacy ZISI bundler as a fallback. Rather than asking the user to
40
- // make this decision, we abstract that complexity away by injecting the
41
- // fallback behavior ourselves. We do this by transforming the value
42
- // `esbuild` into `esbuild_zisi`, which zip-it-and-ship-it understands.
43
- nodeBundler: functionConfig.node_bundler === 'esbuild' ? 'esbuild_zisi' : functionConfig.node_bundler,
44
-
45
- // If the build is running in buildbot, we set the Rust target directory to a
46
- // path that will get cached in between builds, allowing us to speed up the
47
- // build process.
48
- rustTargetDirectory: isRunningLocally ? undefined : resolve(buildDir, '.netlify', 'rust-functions-cache', '[name]'),
49
-
50
- // Go functions should be zipped only when building locally. When running in
51
- // buildbot, the Go API client will handle the zipping.
52
- zipGo: isRunningLocally ? true : undefined,
53
- })
@@ -1,27 +0,0 @@
1
- import { fileURLToPath } from 'url'
2
-
3
- import { LOCAL_INSTALL_PLUGIN_NAME } from '../install/local.js'
4
-
5
- const FUNCTIONS_INSTALL_PLUGIN = fileURLToPath(new URL('functions_install/index.js', import.meta.url))
6
-
7
- // List of core plugin names
8
- const FUNCTIONS_INSTALL_PLUGIN_NAME = '@netlify/plugin-functions-install-core'
9
- const CORE_PLUGINS = new Set([FUNCTIONS_INSTALL_PLUGIN_NAME, LOCAL_INSTALL_PLUGIN_NAME])
10
-
11
- // Plugins that are installed and enabled by default
12
- export const listCorePlugins = function ({ FUNCTIONS_SRC }) {
13
- const functionsInstallPlugin = getFunctionsInstallPlugin(FUNCTIONS_SRC)
14
- return [functionsInstallPlugin].filter(Boolean)
15
- }
16
-
17
- const getFunctionsInstallPlugin = function (FUNCTIONS_SRC) {
18
- if (FUNCTIONS_SRC === undefined) {
19
- return
20
- }
21
-
22
- return { package: FUNCTIONS_INSTALL_PLUGIN_NAME, pluginPath: FUNCTIONS_INSTALL_PLUGIN, optional: true }
23
- }
24
-
25
- export const isCorePlugin = function (packageName) {
26
- return CORE_PLUGINS.has(packageName)
27
- }
package/src/status/add.js DELETED
@@ -1,36 +0,0 @@
1
- // Merge plugin status to the list of plugin statuses.
2
- export const addStatus = function ({ newStatus, statuses, event, packageName, pluginPackageJson: { version } = {} }) {
3
- // Either:
4
- // - `build.command`
5
- // - no status was set
6
- if (newStatus === undefined) {
7
- return statuses
8
- }
9
-
10
- const formerStatus = statuses.find((status) => status.packageName === packageName)
11
- if (!canOverrideStatus(formerStatus, newStatus)) {
12
- return statuses
13
- }
14
-
15
- // Overrides plugin's previous status and add more information
16
- const newStatuses = statuses.filter((status) => status !== formerStatus)
17
- return [...newStatuses, { ...newStatus, event, packageName, version }]
18
- }
19
-
20
- const canOverrideStatus = function (formerStatus, newStatus) {
21
- // No previous status
22
- if (formerStatus === undefined) {
23
- return true
24
- }
25
-
26
- // Implicit statuses can never override
27
- if (newStatus.implicit) {
28
- return false
29
- }
30
-
31
- // Error statuses can only be overwritten by more severe error statuses
32
- return STATES.indexOf(formerStatus.state) <= STATES.indexOf(newStatus.state)
33
- }
34
-
35
- // Possible status states, ordered by severity.
36
- const STATES = ['success', 'canceled_plugin', 'failed_plugin', 'failed_build']
@@ -1,23 +0,0 @@
1
- import stripAnsi from 'strip-ansi'
2
-
3
- // Remove colors from statuses
4
- export const removeStatusesColors = function (statuses) {
5
- return statuses.map(removeStatusColors)
6
- }
7
-
8
- const removeStatusColors = function (status) {
9
- const attributes = COLOR_ATTRIBUTES.map((attribute) => removeAttrColor(status, attribute))
10
- return Object.assign({}, status, ...attributes)
11
- }
12
-
13
- const COLOR_ATTRIBUTES = ['title', 'summary', 'text']
14
-
15
- const removeAttrColor = function (status, attribute) {
16
- const value = status[attribute]
17
- if (value === undefined) {
18
- return {}
19
- }
20
-
21
- const valueA = stripAnsi(value)
22
- return { [attribute]: valueA }
23
- }
@@ -1,11 +0,0 @@
1
- import { addErrorInfo } from '../error/info.js'
2
- import { getFullErrorInfo } from '../error/parse/parse.js'
3
- import { serializeErrorStatus } from '../error/parse/serialize_status.js'
4
-
5
- // Errors that happen during plugin loads should be reported as error statuses
6
- export const addPluginLoadErrorStatus = function ({ error, packageName, version, debug }) {
7
- const fullErrorInfo = getFullErrorInfo({ error, colors: false, debug })
8
- const errorStatus = serializeErrorStatus({ fullErrorInfo, state: 'failed_build' })
9
- const statuses = [{ ...errorStatus, event: 'load', packageName, version }]
10
- addErrorInfo(error, { statuses })
11
- }
@@ -1,137 +0,0 @@
1
- import { handleBuildError } from '../error/handle.js'
2
- import { logStatuses } from '../log/messages/status.js'
3
-
4
- import { removeStatusesColors } from './colors.js'
5
-
6
- // Report plugin statuses to the console and API
7
- export const reportStatuses = async function ({
8
- statuses,
9
- childEnv,
10
- api,
11
- mode,
12
- pluginsOptions,
13
- netlifyConfig,
14
- errorMonitor,
15
- deployId,
16
- logs,
17
- debug,
18
- sendStatus,
19
- testOpts,
20
- }) {
21
- const finalStatuses = getFinalStatuses({ statuses, pluginsOptions })
22
- if (finalStatuses.length === 0) {
23
- return
24
- }
25
-
26
- const statusesA = removeStatusesColors(finalStatuses)
27
- printStatuses({ statuses: statusesA, mode, logs })
28
- await sendApiStatuses({
29
- statuses: statusesA,
30
- childEnv,
31
- api,
32
- mode,
33
- netlifyConfig,
34
- errorMonitor,
35
- deployId,
36
- logs,
37
- debug,
38
- sendStatus,
39
- testOpts,
40
- })
41
- }
42
-
43
- // Some plugins might not have completed due to a build error.
44
- // In that case, we add a dummy plugin run with state "skipped".
45
- // This allows the API to know both plugins that have completed and only started
46
- const getFinalStatuses = function ({ statuses = [], pluginsOptions }) {
47
- return pluginsOptions.map(({ packageName }) => getPluginStatus(packageName, statuses))
48
- }
49
-
50
- const getPluginStatus = function (packageName, statuses) {
51
- const pluginStatus = statuses.find((status) => status.packageName === packageName)
52
-
53
- if (pluginStatus !== undefined) {
54
- return pluginStatus
55
- }
56
-
57
- return { packageName, state: 'skipped' }
58
- }
59
-
60
- // When not in production, print statuses to console.
61
- // Only print successful ones, since errors are logged afterwards.
62
- const printStatuses = function ({ statuses, mode, logs }) {
63
- if (mode === 'buildbot') {
64
- return
65
- }
66
-
67
- const successStatuses = statuses.filter(shouldPrintStatus)
68
-
69
- if (successStatuses.length === 0) {
70
- return
71
- }
72
-
73
- logStatuses(logs, successStatuses)
74
- }
75
-
76
- const shouldPrintStatus = function ({ state, summary }) {
77
- return state === 'success' && summary !== undefined
78
- }
79
-
80
- // In production, send statuses to the API
81
- const sendApiStatuses = async function ({
82
- statuses,
83
- childEnv,
84
- api,
85
- mode,
86
- netlifyConfig,
87
- errorMonitor,
88
- deployId,
89
- logs,
90
- debug,
91
- sendStatus,
92
- testOpts,
93
- }) {
94
- if ((mode !== 'buildbot' && !sendStatus) || api === undefined || !deployId) {
95
- return
96
- }
97
-
98
- await Promise.all(
99
- statuses.map((status) =>
100
- sendApiStatus({ api, status, childEnv, mode, netlifyConfig, errorMonitor, deployId, logs, debug, testOpts }),
101
- ),
102
- )
103
- }
104
-
105
- const sendApiStatus = async function ({
106
- api,
107
- status: { packageName, version, state, event, title, summary, text, extraData },
108
- childEnv,
109
- mode,
110
- netlifyConfig,
111
- errorMonitor,
112
- deployId,
113
- logs,
114
- debug,
115
- testOpts,
116
- }) {
117
- try {
118
- await api.createPluginRun({
119
- deploy_id: deployId,
120
- body: {
121
- package: packageName,
122
- version,
123
- state,
124
- reporting_event: event,
125
- title,
126
- summary,
127
- text,
128
- extra_data: extraData,
129
- },
130
- })
131
- // Bitballoon API randomly fails with 502.
132
- // Builds should be successful when this API call fails, but we still want
133
- // to report the error both in logs and in error monitoring.
134
- } catch (error) {
135
- await handleBuildError(error, { errorMonitor, netlifyConfig, childEnv, mode, logs, debug, testOpts })
136
- }
137
- }