@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,43 +0,0 @@
1
- import { cleanStacks } from './clean_stack.js'
2
-
3
- // Retrieve the stack trace
4
- export const getStackInfo = function ({ message, stack, stackType, rawStack, severity, debug }) {
5
- const { message: messageA, stack: stackA } = splitStackInfo({ message, stack, stackType })
6
- const messageB = severity === 'none' ? messageA.replace(SUCCESS_ERROR_NAME, '') : messageA
7
- const stackB = cleanStacks({ stack: stackA, rawStack, debug })
8
- return { message: messageB, stack: stackB }
9
- }
10
-
11
- const splitStackInfo = function ({ message, stack, stackType }) {
12
- // Some errors should not show any stack trace
13
- if (stackType === 'none') {
14
- return { message }
15
- }
16
-
17
- // Some errors have their stack trace inside `error.message` instead of
18
- // `error.stack` due to IPC
19
- if (stackType === 'message') {
20
- return splitStack(message)
21
- }
22
-
23
- return splitStack(stack)
24
- }
25
-
26
- const splitStack = function (string) {
27
- const lines = string.split('\n')
28
- const stackIndex = lines.findIndex(isStackTrace)
29
-
30
- if (stackIndex === -1) {
31
- return { message: string }
32
- }
33
-
34
- const messageA = lines.slice(0, stackIndex).join('\n')
35
- const stackA = lines.slice(stackIndex).join('\n')
36
- return { message: messageA, stack: stackA }
37
- }
38
-
39
- const isStackTrace = function (line) {
40
- return line.trim().startsWith('at ')
41
- }
42
-
43
- const SUCCESS_ERROR_NAME = 'Error: '
package/src/error/type.js DELETED
@@ -1,189 +0,0 @@
1
- // Retrieve error-type specific information
2
- export const getTypeInfo = function ({ type }) {
3
- const typeA = TYPES[type] === undefined ? DEFAULT_TYPE : type
4
- return { type: typeA, ...TYPES[typeA] }
5
- }
6
-
7
- // List of error types, and their related properties
8
- // Related to build error logs:
9
- // - `showInBuildLog`: `true` when we want this error to show in build logs (defaults to true)
10
- // - `title`: main title shown in build error logs and in the UI (statuses)
11
- // - `locationType`: retrieve a human-friendly location of the error, printed
12
- // in build error logs
13
- // - `showErrorProps`: `true` when the `Error` instance static properties
14
- // should be printed in build error logs. Only useful when the `Error`
15
- // instance was not created by us.
16
- // - `rawStack`: `true` when the stack trace should be cleaned up
17
- // - `stackType`: how the stack trace should appear in build error logs:
18
- // - `none`: not printed
19
- // - `stack`: printed as is
20
- // - `message`: printed as is, but taken from `error.message`.
21
- // Used when `error.stack` is not being correct due to the error being
22
- // passed between different processes.
23
- // - `severity`: error severity (also used by Bugsnag):
24
- // - `success`: build success
25
- // - `none`: not an error, e.g. build cancellation
26
- // - `info`: user error
27
- // - `warning`: community plugin error
28
- // - `error`: system error, including core plugin error
29
- // Related to Bugsnag:
30
- // - `group`: main title shown in Bugsnag. Also used to group errors together
31
- // in Bugsnag, combined with `error.message`.
32
- // Defaults to `title`.
33
- // New error types should be added to Bugsnag since we use it for automated
34
- // monitoring (through its Slack integration). The steps in Bugsnag are:
35
- // - Create a new bookmark. Try to re-use the search filter of an existing
36
- // bookmark with a similar error type, but only changing the `errorClass`.
37
- // Make sure to check the box "Share with my team".
38
- // - Add the `errorClass` to the search filter of either the "All warnings" or
39
- // "All errors" bookmark depending on whether we should get notified on Slack
40
- // for new errors of that type. You must use the bookmark menu action "Update
41
- // with current filters"
42
- const TYPES = {
43
- // Plugin called `utils.build.cancelBuild()`
44
- cancelBuild: {
45
- title: ({ location: { packageName } }) => `Build canceled by ${packageName}`,
46
- stackType: 'stack',
47
- locationType: 'buildFail',
48
- severity: 'none',
49
- },
50
-
51
- // User configuration error (`@netlify/config`, wrong Node.js version)
52
- resolveConfig: {
53
- title: 'Configuration error',
54
- stackType: 'none',
55
- severity: 'info',
56
- },
57
-
58
- // Error while installing user packages (missing plugins, local plugins or functions dependencies)
59
- dependencies: {
60
- title: 'Dependencies installation error',
61
- stackType: 'none',
62
- severity: 'info',
63
- },
64
-
65
- // User misconfigured a plugin
66
- pluginInput: {
67
- title: ({ location: { packageName, input } }) => `Plugin "${packageName}" invalid input "${input}"`,
68
- stackType: 'none',
69
- locationType: 'buildFail',
70
- severity: 'info',
71
- },
72
-
73
- // `build.command` non-0 exit code
74
- buildCommand: {
75
- title: '"build.command" failed',
76
- group: ({ location: { buildCommand } }) => buildCommand,
77
- stackType: 'message',
78
- locationType: 'buildCommand',
79
- severity: 'info',
80
- },
81
-
82
- // User error during Functions bundling
83
- functionsBundling: {
84
- title: ({ location: { functionName, functionType } }) => {
85
- if (functionType === 'edge') {
86
- return 'Bundling of edge function failed'
87
- }
88
-
89
- return `Bundling of function "${functionName}" failed`
90
- },
91
- group: ({ location: { functionType = 'serverless' } }) => `Bundling of ${functionType} function failed`,
92
- stackType: 'none',
93
- locationType: 'functionsBundling',
94
- severity: 'info',
95
- },
96
-
97
- // Plugin called `utils.build.failBuild()`
98
- failBuild: {
99
- title: ({ location: { packageName } }) => `Plugin "${packageName}" failed`,
100
- stackType: 'stack',
101
- locationType: 'buildFail',
102
- severity: 'info',
103
- },
104
-
105
- // Plugin called `utils.build.failPlugin()`
106
- failPlugin: {
107
- title: ({ location: { packageName } }) => `Plugin "${packageName}" failed`,
108
- stackType: 'stack',
109
- locationType: 'buildFail',
110
- severity: 'info',
111
- },
112
-
113
- // Plugin has an invalid shape
114
- pluginValidation: {
115
- title: ({ location: { packageName } }) => `Plugin "${packageName}" internal error`,
116
- stackType: 'stack',
117
- locationType: 'buildFail',
118
- severity: 'warning',
119
- },
120
-
121
- // Plugin threw an uncaught exception
122
- pluginInternal: {
123
- title: ({ location: { packageName } }) => `Plugin "${packageName}" internal error`,
124
- stackType: 'stack',
125
- showErrorProps: true,
126
- rawStack: true,
127
- locationType: 'buildFail',
128
- severity: 'warning',
129
- },
130
-
131
- // Bug while orchestrating child processes
132
- ipc: {
133
- title: ({ location: { packageName } }) => `Plugin "${packageName}" internal error`,
134
- stackType: 'none',
135
- locationType: 'buildFail',
136
- severity: 'warning',
137
- },
138
-
139
- // Core plugin internal error
140
- corePlugin: {
141
- title: ({ location: { packageName } }) => `Plugin "${packageName}" internal error`,
142
- stackType: 'stack',
143
- showErrorProps: true,
144
- rawStack: true,
145
- locationType: 'buildFail',
146
- severity: 'error',
147
- },
148
-
149
- // Core step internal error
150
- coreStep: {
151
- title: ({ location: { coreStepName } }) => `Internal error during "${coreStepName}"`,
152
- stackType: 'stack',
153
- showErrorProps: true,
154
- rawStack: true,
155
- locationType: 'coreStep',
156
- severity: 'error',
157
- },
158
-
159
- // Request error when `@netlify/build` was calling Netlify API
160
- api: {
161
- title: ({ location: { endpoint } }) => `API error on "${endpoint}"`,
162
- stackType: 'message',
163
- showErrorProps: true,
164
- locationType: 'api',
165
- severity: 'error',
166
- },
167
-
168
- // `@netlify/build` threw an uncaught exception
169
- exception: {
170
- title: 'Core internal error',
171
- stackType: 'stack',
172
- showErrorProps: true,
173
- rawStack: true,
174
- severity: 'error',
175
- },
176
-
177
- // Errors related with the telemetry output
178
- telemetry: {
179
- showInBuildLog: false,
180
- title: 'Telemetry error',
181
- stackType: 'stack',
182
- showErrorProps: true,
183
- rawStack: true,
184
- severity: 'error',
185
- },
186
- }
187
-
188
- // When no error type matches, it's an uncaught exception, i.e. a bug
189
- const DEFAULT_TYPE = 'exception'
@@ -1,28 +0,0 @@
1
- import { dirname } from 'path'
2
-
3
- import readdirp from 'readdirp'
4
-
5
- import { logInstallFunctionDependencies } from '../log/messages/install.js'
6
-
7
- import { installDependencies } from './main.js'
8
-
9
- // Install dependencies of Netlify Functions
10
- export const installFunctionDependencies = async function (functionsSrc, isLocal) {
11
- const packagePaths = await getPackagePaths(functionsSrc)
12
- if (packagePaths.length === 0) {
13
- return
14
- }
15
-
16
- logInstallFunctionDependencies()
17
-
18
- const packageRoots = packagePaths.map(getPackageRoot)
19
- await Promise.all(packageRoots.map((packageRoot) => installDependencies({ packageRoot, isLocal })))
20
- }
21
-
22
- const getPackagePaths = function (functionsSrc) {
23
- return readdirp.promise(functionsSrc, { depth: 1, fileFilter: 'package.json' })
24
- }
25
-
26
- const getPackageRoot = function ({ fullPath }) {
27
- return dirname(fullPath)
28
- }
@@ -1,62 +0,0 @@
1
- import { packageDirectory } from 'pkg-dir'
2
-
3
- import { logInstallLocalPluginsDeps } from '../log/messages/install.js'
4
-
5
- import { installDependencies } from './main.js'
6
-
7
- // Install dependencies of local plugins.
8
- // Users must add this plugin to their `netlify.toml` `plugins` to use this
9
- // feature. We don't want to provide it by default because this makes build
10
- // slow and buggy.
11
- export const installLocalPluginsDependencies = async function ({ plugins, pluginsOptions, buildDir, mode, logs }) {
12
- if (!plugins.some(isLocalInstallOptIn)) {
13
- return
14
- }
15
-
16
- const localPluginsOptions = getLocalPluginsOptions(pluginsOptions)
17
- if (localPluginsOptions.length === 0) {
18
- return
19
- }
20
-
21
- const localPluginsOptionsA = await removeMainRoot(localPluginsOptions, buildDir)
22
- if (localPluginsOptionsA.length === 0) {
23
- return
24
- }
25
-
26
- logInstallLocalPluginsDeps(logs, localPluginsOptionsA)
27
- await Promise.all(
28
- localPluginsOptionsA.map(({ packageDir }) =>
29
- installDependencies({ packageRoot: packageDir, isLocal: mode !== 'buildbot' }),
30
- ),
31
- )
32
- }
33
-
34
- const isLocalInstallOptIn = function (plugin) {
35
- return plugin.package === LOCAL_INSTALL_PLUGIN_NAME
36
- }
37
-
38
- export const LOCAL_INSTALL_PLUGIN_NAME = '@netlify/plugin-local-install-core'
39
-
40
- // Core plugins and non-local plugins already have their dependencies installed
41
- const getLocalPluginsOptions = function (pluginsOptions) {
42
- return pluginsOptions.filter(isLocalPlugin).filter(isUnique).filter(hasPackageDir)
43
- }
44
-
45
- const isLocalPlugin = function ({ loadedFrom }) {
46
- return loadedFrom === 'local'
47
- }
48
-
49
- // Remove duplicates
50
- const isUnique = function ({ packageDir }, index, pluginsOptions) {
51
- return pluginsOptions.slice(index + 1).every((pluginOption) => pluginOption.packageDir !== packageDir)
52
- }
53
-
54
- const hasPackageDir = function ({ packageDir }) {
55
- return packageDir !== undefined
56
- }
57
-
58
- // We only install dependencies of local plugins that have their own `package.json`
59
- const removeMainRoot = async function (localPluginsOptions, buildDir) {
60
- const mainPackageDir = await packageDirectory({ cwd: buildDir })
61
- return localPluginsOptions.filter(({ packageDir }) => packageDir !== mainPackageDir)
62
- }
@@ -1,81 +0,0 @@
1
- import { homedir } from 'os'
2
-
3
- import { execa } from 'execa'
4
- import { pathExists } from 'path-exists'
5
-
6
- import { addErrorInfo } from '../error/info.js'
7
-
8
- // Install Node.js dependencies in a specific directory
9
- export const installDependencies = function ({ packageRoot, isLocal }) {
10
- return runCommand({ packageRoot, isLocal, type: 'install' })
11
- }
12
-
13
- // Add new Node.js dependencies, with exact semver ranges
14
- export const addExactDependencies = function ({ packageRoot, isLocal, packages }) {
15
- return runCommand({ packageRoot, packages, isLocal, type: 'addExact' })
16
- }
17
-
18
- const runCommand = async function ({ packageRoot, packages = [], isLocal, type }) {
19
- try {
20
- const [command, ...args] = await getCommand({ packageRoot, type, isLocal })
21
- await execa(command, [...args, ...packages], { cwd: packageRoot, all: true })
22
- } catch (error) {
23
- const message = getErrorMessage(error.all)
24
- const errorA = new Error(`Error while installing dependencies in ${packageRoot}\n${message}`)
25
- addErrorInfo(errorA, { type: 'dependencies' })
26
- throw errorA
27
- }
28
- }
29
-
30
- // Retrieve the shell command to install or add dependencies
31
- const getCommand = async function ({ packageRoot, type, isLocal }) {
32
- const manager = await getManager(type, packageRoot)
33
- const command = COMMANDS[manager][type]
34
- const commandA = addYarnCustomCache(command, manager, isLocal)
35
- return commandA
36
- }
37
-
38
- const getManager = async function (type, packageRoot) {
39
- // `addDependencies()` always uses npm
40
- if (type === 'addExact') {
41
- return 'npm'
42
- }
43
-
44
- if (await pathExists(`${packageRoot}/yarn.lock`)) {
45
- return 'yarn'
46
- }
47
-
48
- return 'npm'
49
- }
50
-
51
- const COMMANDS = {
52
- npm: {
53
- addExact: ['npm', 'install', '--no-progress', '--no-audit', '--no-fund', '--save-exact'],
54
- install: ['npm', 'install', '--no-progress', '--no-audit', '--no-fund'],
55
- },
56
- yarn: {
57
- install: ['yarn', 'install', '--no-progress', '--non-interactive'],
58
- },
59
- }
60
-
61
- // In CI, yarn uses a custom cache folder
62
- const addYarnCustomCache = function (command, manager, isLocal) {
63
- if (manager !== 'yarn' || isLocal) {
64
- return command
65
- }
66
-
67
- return [...command, '--cache-folder', YARN_CI_CACHE_DIR]
68
- }
69
-
70
- const YARN_CI_CACHE_DIR = `${homedir()}/.yarn_cache`
71
-
72
- // Retrieve message to add to install errors
73
- const getErrorMessage = function (allOutput) {
74
- return allOutput.split('\n').filter(isNotNpmLogMessage).join('\n')
75
- }
76
-
77
- // Debug logs shown at the end of npm errors is not useful in Netlify Build
78
- const isNotNpmLogMessage = function (line) {
79
- return NPM_LOG_MESSAGES.every((message) => !line.includes(message))
80
- }
81
- const NPM_LOG_MESSAGES = ['complete log of this run', '-debug.log']
@@ -1,67 +0,0 @@
1
- import { promises as fs } from 'fs'
2
- import { normalize } from 'path'
3
-
4
- import { pathExists } from 'path-exists'
5
- import { isFile } from 'path-type'
6
-
7
- import { logInstallMissingPlugins } from '../log/messages/install.js'
8
-
9
- import { addExactDependencies } from './main.js'
10
-
11
- // Automatically install plugins if not already installed.
12
- // Since this is done under the hood, we always use `npm` with specific `npm`
13
- // options. We do not allow configure the package manager nor its options.
14
- // Users requiring `yarn` or custom npm/yarn flags should install the plugin in
15
- // their `package.json`.
16
- export const installMissingPlugins = async function ({ missingPlugins, autoPluginsDir, mode, logs }) {
17
- const packages = missingPlugins.map(getPackage)
18
- logInstallMissingPlugins(logs, packages)
19
-
20
- await createAutoPluginsDir(logs, autoPluginsDir)
21
- await addExactDependencies({ packageRoot: autoPluginsDir, isLocal: mode !== 'buildbot', packages })
22
- }
23
-
24
- // We pin the version without using semver ranges ^ nor ~
25
- const getPackage = function ({ packageName, expectedVersion }) {
26
- return `${packageName}@${expectedVersion}`
27
- }
28
-
29
- const createAutoPluginsDir = async function (logs, autoPluginsDir) {
30
- await ensureDir(logs, autoPluginsDir)
31
- await createPackageJson(autoPluginsDir)
32
- }
33
-
34
- // Create the directory if it does not exist
35
- const ensureDir = async function (logs, autoPluginsDir) {
36
- if (await pathExists(autoPluginsDir)) {
37
- return
38
- }
39
-
40
- // If `.netlify` exists but is not a directory, we remove it first
41
- const autoPluginsParent = normalize(`${autoPluginsDir}/..`)
42
- if (await isFile(autoPluginsParent)) {
43
- await fs.unlink(autoPluginsParent)
44
- }
45
-
46
- await fs.mkdir(autoPluginsDir, { recursive: true })
47
- }
48
-
49
- // Create a dummy `package.json` so we can run `npm install` and get a lock file
50
- const createPackageJson = async function (autoPluginsDir) {
51
- const packageJsonPath = `${autoPluginsDir}/package.json`
52
- if (await pathExists(packageJsonPath)) {
53
- return
54
- }
55
-
56
- const packageJsonContent = JSON.stringify(AUTO_PLUGINS_PACKAGE_JSON, null, 2)
57
- await fs.writeFile(packageJsonPath, packageJsonContent)
58
- }
59
-
60
- const AUTO_PLUGINS_PACKAGE_JSON = {
61
- name: 'netlify-local-plugins',
62
- description: 'This directory contains Build plugins that have been automatically installed by Netlify.',
63
- version: '1.0.0',
64
- private: true,
65
- author: 'Netlify',
66
- license: 'MIT',
67
- }
package/src/log/colors.js DELETED
@@ -1,34 +0,0 @@
1
- import { inspect } from 'util'
2
-
3
- import supportsColor from 'supports-color'
4
-
5
- // Plugin child processes use `stdio: 'pipe'` so they are always
6
- // non-interactive even if the parent is an interactive TTY. This means they
7
- // would normally lose colors. If the parent has colors, we pass an environment
8
- // variable to the child process to force colors.
9
- export const getParentColorEnv = function () {
10
- if (!hasColors()) {
11
- return {}
12
- }
13
-
14
- return { FORCE_COLOR: '1' }
15
- }
16
-
17
- // Child processes and the buildbot relies on `FORCE_COLOR=1` to set colors.
18
- // However `utils.inspect()` (used by `console.log()`) uses
19
- // `process.stdout.hasColors` which is always `undefined` when the TTY is
20
- // non-interactive. So we need to set `util.inspect.defaultOptions.colors`
21
- // manually both in plugin processes.
22
- export const setInspectColors = function () {
23
- if (!hasColors()) {
24
- return
25
- }
26
-
27
- // `inspect.defaultOptions` requires direct mutation
28
- // eslint-disable-next-line fp/no-mutation
29
- inspect.defaultOptions.colors = true
30
- }
31
-
32
- const hasColors = function () {
33
- return supportsColor.stdout !== false
34
- }
@@ -1,26 +0,0 @@
1
- export const getBuildCommandDescription = function (buildCommandOrigin) {
2
- return BUILD_COMMAND_DESCRIPTIONS[buildCommandOrigin]
3
- }
4
-
5
- const BUILD_COMMAND_DESCRIPTIONS = {
6
- ui: 'Build command from Netlify app',
7
- config: 'build.command from netlify.toml',
8
- inline: 'build.command from a plugin',
9
- }
10
-
11
- // Retrieve human-friendly plugin origin
12
- export const getPluginOrigin = function (loadedFrom, origin) {
13
- const originName = PLUGIN_ORIGINS[origin]
14
-
15
- if (loadedFrom === 'package.json') {
16
- return `from ${originName} and package.json`
17
- }
18
-
19
- return `from ${originName}`
20
- }
21
-
22
- const PLUGIN_ORIGINS = {
23
- core: 'core',
24
- ui: 'Netlify app',
25
- config: 'netlify.toml',
26
- }
package/src/log/header.js DELETED
@@ -1,16 +0,0 @@
1
- import stringWidth from 'string-width'
2
-
3
- // Print a rectangular header
4
- export const getHeader = function (message) {
5
- const messageWidth = stringWidth(message)
6
- const headerWidth = Math.max(HEADER_MIN_WIDTH, messageWidth)
7
- const line = '─'.repeat(headerWidth + PADDING_WIDTH * 2)
8
- const paddingLeft = ' '.repeat(PADDING_WIDTH)
9
- const paddingRight = ' '.repeat(PADDING_WIDTH + headerWidth - messageWidth)
10
- return `${line}
11
- ${paddingLeft}${message}${paddingRight}
12
- ${line}`
13
- }
14
-
15
- const HEADER_MIN_WIDTH = 60
16
- const PADDING_WIDTH = 2
@@ -1,17 +0,0 @@
1
- import { parseErrorInfo } from '../error/parse/parse.js'
2
-
3
- import { logHeader, logErrorHeader } from './logger.js'
4
-
5
- // Retrieve successful or error header depending on whether `error` exists
6
- export const getLogHeaderFunc = function (error) {
7
- if (error === undefined) {
8
- return logHeader
9
- }
10
-
11
- const { severity } = parseErrorInfo(error)
12
- if (severity === 'none') {
13
- return logHeader
14
- }
15
-
16
- return logErrorHeader
17
- }