@netlify/build 28.0.1-beta → 28.1.0-framework-version-detection

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 +125 -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 +105 -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/type.js +171 -0
  41. package/lib/install/functions.js +20 -0
  42. package/lib/install/local.js +45 -0
  43. package/lib/install/main.js +67 -0
  44. package/lib/install/missing.js +54 -0
  45. package/{src → lib}/log/colors.js +15 -22
  46. package/lib/log/description.js +21 -0
  47. package/lib/log/header.js +14 -0
  48. package/lib/log/header_func.js +13 -0
  49. package/lib/log/logger.js +140 -0
  50. package/lib/log/messages/compatibility.js +120 -0
  51. package/lib/log/messages/config.js +98 -0
  52. package/lib/log/messages/core.js +50 -0
  53. package/lib/log/messages/core_steps.js +75 -0
  54. package/lib/log/messages/dry.js +41 -0
  55. package/lib/log/messages/install.js +25 -0
  56. package/lib/log/messages/ipc.js +29 -0
  57. package/lib/log/messages/mutations.js +62 -0
  58. package/{src → lib}/log/messages/plugins.js +18 -32
  59. package/lib/log/messages/status.js +14 -0
  60. package/lib/log/messages/steps.js +18 -0
  61. package/lib/log/old_version.js +32 -0
  62. package/lib/log/serialize.js +10 -0
  63. package/lib/log/stream.js +68 -0
  64. package/lib/log/theme.js +25 -0
  65. package/lib/plugins/child/diff.js +46 -0
  66. package/lib/plugins/child/error.js +26 -0
  67. package/lib/plugins/child/lazy.js +15 -0
  68. package/lib/plugins/child/load.js +22 -0
  69. package/lib/plugins/child/logic.js +57 -0
  70. package/lib/plugins/child/main.js +37 -0
  71. package/lib/plugins/child/run.js +19 -0
  72. package/lib/plugins/child/status.js +63 -0
  73. package/lib/plugins/child/typescript.js +28 -0
  74. package/lib/plugins/child/utils.js +42 -0
  75. package/lib/plugins/child/validate.js +31 -0
  76. package/lib/plugins/compatibility.js +104 -0
  77. package/{src → lib}/plugins/error.js +31 -35
  78. package/{src → lib}/plugins/events.js +7 -12
  79. package/lib/plugins/expected_version.js +81 -0
  80. package/lib/plugins/ipc.js +120 -0
  81. package/lib/plugins/list.js +73 -0
  82. package/lib/plugins/load.js +50 -0
  83. package/lib/plugins/manifest/check.js +85 -0
  84. package/lib/plugins/manifest/load.js +38 -0
  85. package/lib/plugins/manifest/main.js +17 -0
  86. package/lib/plugins/manifest/path.js +24 -0
  87. package/lib/plugins/manifest/validate.js +91 -0
  88. package/lib/plugins/node_version.js +30 -0
  89. package/lib/plugins/options.js +55 -0
  90. package/lib/plugins/pinned_version.js +83 -0
  91. package/lib/plugins/resolve.js +110 -0
  92. package/lib/plugins/spawn.js +54 -0
  93. package/lib/plugins_core/add.js +35 -0
  94. package/lib/plugins_core/build_command.js +50 -0
  95. package/lib/plugins_core/deploy/buildbot_client.js +87 -0
  96. package/lib/plugins_core/deploy/index.js +49 -0
  97. package/{src → lib}/plugins_core/deploy/manifest.yml +0 -0
  98. package/lib/plugins_core/edge_functions/index.js +79 -0
  99. package/lib/plugins_core/edge_functions/lib/error.js +17 -0
  100. package/lib/plugins_core/edge_functions/lib/internal_manifest.js +50 -0
  101. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +75 -0
  102. package/lib/plugins_core/functions/error.js +123 -0
  103. package/lib/plugins_core/functions/feature_flags.js +6 -0
  104. package/lib/plugins_core/functions/index.js +114 -0
  105. package/lib/plugins_core/functions/utils.js +45 -0
  106. package/lib/plugins_core/functions/zisi.js +39 -0
  107. package/{src → lib}/plugins_core/functions_install/index.js +8 -11
  108. package/{src → lib}/plugins_core/functions_install/manifest.yml +0 -0
  109. package/lib/plugins_core/list.js +20 -0
  110. package/lib/status/add.js +30 -0
  111. package/lib/status/colors.js +18 -0
  112. package/lib/status/load_error.js +10 -0
  113. package/lib/status/report.js +83 -0
  114. package/lib/status/success.js +14 -0
  115. package/lib/steps/core_step.js +57 -0
  116. package/lib/steps/error.js +65 -0
  117. package/lib/steps/get.js +43 -0
  118. package/lib/steps/plugin.js +55 -0
  119. package/lib/steps/return.js +25 -0
  120. package/lib/steps/run_core_steps.js +126 -0
  121. package/lib/steps/run_step.js +188 -0
  122. package/lib/steps/run_steps.js +96 -0
  123. package/lib/steps/update_config.js +66 -0
  124. package/lib/telemetry/main.js +97 -0
  125. package/lib/time/aggregate.js +120 -0
  126. package/lib/time/main.js +37 -0
  127. package/lib/time/measure.js +18 -0
  128. package/lib/time/report.js +47 -0
  129. package/lib/utils/errors.js +13 -0
  130. package/lib/utils/json.js +15 -0
  131. package/{src → lib}/utils/omit.js +3 -4
  132. package/lib/utils/package.js +22 -0
  133. package/lib/utils/remove_falsy.js +8 -0
  134. package/lib/utils/resolve.js +41 -0
  135. package/lib/utils/runtime.js +5 -0
  136. package/lib/utils/semver.js +28 -0
  137. package/package.json +39 -19
  138. package/types/config/netlify_config.d.ts +4 -4
  139. package/types/netlify_plugin_constants.d.ts +8 -8
  140. package/src/core/bin.js +0 -83
  141. package/src/core/config.js +0 -186
  142. package/src/core/constants.js +0 -156
  143. package/src/core/dry.js +0 -39
  144. package/src/core/feature_flags.js +0 -21
  145. package/src/core/flags.js +0 -194
  146. package/src/core/lingering.js +0 -85
  147. package/src/core/main.js +0 -692
  148. package/src/core/missing_side_file.js +0 -29
  149. package/src/core/normalize_flags.js +0 -69
  150. package/src/core/severity.js +0 -22
  151. package/src/core/user_node_version.js +0 -41
  152. package/src/env/changes.js +0 -52
  153. package/src/env/main.js +0 -19
  154. package/src/env/metadata.js +0 -81
  155. package/src/error/api.js +0 -46
  156. package/src/error/build.js +0 -50
  157. package/src/error/colors.js +0 -11
  158. package/src/error/handle.js +0 -57
  159. package/src/error/info.js +0 -46
  160. package/src/error/monitor/location.js +0 -21
  161. package/src/error/monitor/normalize.js +0 -77
  162. package/src/error/monitor/print.js +0 -42
  163. package/src/error/monitor/report.js +0 -133
  164. package/src/error/monitor/start.js +0 -69
  165. package/src/error/parse/clean_stack.js +0 -87
  166. package/src/error/parse/location.js +0 -58
  167. package/src/error/parse/normalize.js +0 -29
  168. package/src/error/parse/parse.js +0 -97
  169. package/src/error/parse/plugin.js +0 -70
  170. package/src/error/parse/properties.js +0 -23
  171. package/src/error/parse/serialize_log.js +0 -42
  172. package/src/error/parse/serialize_status.js +0 -23
  173. package/src/error/parse/stack.js +0 -43
  174. package/src/error/type.js +0 -182
  175. package/src/install/functions.js +0 -28
  176. package/src/install/local.js +0 -62
  177. package/src/install/main.js +0 -81
  178. package/src/install/missing.js +0 -67
  179. package/src/log/description.js +0 -26
  180. package/src/log/header.js +0 -16
  181. package/src/log/header_func.js +0 -17
  182. package/src/log/logger.js +0 -107
  183. package/src/log/messages/compatibility.js +0 -164
  184. package/src/log/messages/config.js +0 -105
  185. package/src/log/messages/core.js +0 -70
  186. package/src/log/messages/core_steps.js +0 -104
  187. package/src/log/messages/dry.js +0 -63
  188. package/src/log/messages/install.js +0 -20
  189. package/src/log/messages/ipc.js +0 -38
  190. package/src/log/messages/mutations.js +0 -82
  191. package/src/log/messages/status.js +0 -16
  192. package/src/log/messages/steps.js +0 -22
  193. package/src/log/old_version.js +0 -41
  194. package/src/log/serialize.js +0 -13
  195. package/src/log/stream.js +0 -85
  196. package/src/log/theme.js +0 -26
  197. package/src/plugins/child/diff.js +0 -55
  198. package/src/plugins/child/error.js +0 -32
  199. package/src/plugins/child/lazy.js +0 -18
  200. package/src/plugins/child/load.js +0 -29
  201. package/src/plugins/child/logic.js +0 -57
  202. package/src/plugins/child/main.js +0 -51
  203. package/src/plugins/child/run.js +0 -28
  204. package/src/plugins/child/status.js +0 -67
  205. package/src/plugins/child/typescript.js +0 -45
  206. package/src/plugins/child/utils.js +0 -56
  207. package/src/plugins/child/validate.js +0 -34
  208. package/src/plugins/compatibility.js +0 -128
  209. package/src/plugins/expected_version.js +0 -119
  210. package/src/plugins/ipc.js +0 -145
  211. package/src/plugins/list.js +0 -86
  212. package/src/plugins/load.js +0 -70
  213. package/src/plugins/manifest/check.js +0 -106
  214. package/src/plugins/manifest/load.js +0 -41
  215. package/src/plugins/manifest/main.js +0 -22
  216. package/src/plugins/manifest/path.js +0 -31
  217. package/src/plugins/manifest/validate.js +0 -108
  218. package/src/plugins/node_version.js +0 -50
  219. package/src/plugins/options.js +0 -88
  220. package/src/plugins/pinned_version.js +0 -131
  221. package/src/plugins/resolve.js +0 -152
  222. package/src/plugins/spawn.js +0 -66
  223. package/src/plugins_core/add.js +0 -49
  224. package/src/plugins_core/build_command.js +0 -75
  225. package/src/plugins_core/deploy/buildbot_client.js +0 -102
  226. package/src/plugins_core/deploy/index.js +0 -73
  227. package/src/plugins_core/edge_functions/index.js +0 -107
  228. package/src/plugins_core/edge_functions/lib/internal_manifest.js +0 -54
  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 -128
  239. package/src/status/success.js +0 -18
  240. package/src/steps/core_step.js +0 -90
  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 -300
  247. package/src/steps/run_steps.js +0 -179
  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
package/src/error/type.js DELETED
@@ -1,182 +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 } }) => `Bundling of Function "${functionName}" failed`,
85
- stackType: 'none',
86
- locationType: 'functionsBundling',
87
- severity: 'info',
88
- },
89
-
90
- // Plugin called `utils.build.failBuild()`
91
- failBuild: {
92
- title: ({ location: { packageName } }) => `Plugin "${packageName}" failed`,
93
- stackType: 'stack',
94
- locationType: 'buildFail',
95
- severity: 'info',
96
- },
97
-
98
- // Plugin called `utils.build.failPlugin()`
99
- failPlugin: {
100
- title: ({ location: { packageName } }) => `Plugin "${packageName}" failed`,
101
- stackType: 'stack',
102
- locationType: 'buildFail',
103
- severity: 'info',
104
- },
105
-
106
- // Plugin has an invalid shape
107
- pluginValidation: {
108
- title: ({ location: { packageName } }) => `Plugin "${packageName}" internal error`,
109
- stackType: 'stack',
110
- locationType: 'buildFail',
111
- severity: 'warning',
112
- },
113
-
114
- // Plugin threw an uncaught exception
115
- pluginInternal: {
116
- title: ({ location: { packageName } }) => `Plugin "${packageName}" internal error`,
117
- stackType: 'stack',
118
- showErrorProps: true,
119
- rawStack: true,
120
- locationType: 'buildFail',
121
- severity: 'warning',
122
- },
123
-
124
- // Bug while orchestrating child processes
125
- ipc: {
126
- title: ({ location: { packageName } }) => `Plugin "${packageName}" internal error`,
127
- stackType: 'none',
128
- locationType: 'buildFail',
129
- severity: 'warning',
130
- },
131
-
132
- // Core plugin internal error
133
- corePlugin: {
134
- title: ({ location: { packageName } }) => `Plugin "${packageName}" internal error`,
135
- stackType: 'stack',
136
- showErrorProps: true,
137
- rawStack: true,
138
- locationType: 'buildFail',
139
- severity: 'error',
140
- },
141
-
142
- // Core step internal error
143
- coreStep: {
144
- title: ({ location: { coreStepName } }) => `Internal error during "${coreStepName}"`,
145
- stackType: 'stack',
146
- showErrorProps: true,
147
- rawStack: true,
148
- locationType: 'coreStep',
149
- severity: 'error',
150
- },
151
-
152
- // Request error when `@netlify/build` was calling Netlify API
153
- api: {
154
- title: ({ location: { endpoint } }) => `API error on "${endpoint}"`,
155
- stackType: 'message',
156
- showErrorProps: true,
157
- locationType: 'api',
158
- severity: 'error',
159
- },
160
-
161
- // `@netlify/build` threw an uncaught exception
162
- exception: {
163
- title: 'Core internal error',
164
- stackType: 'stack',
165
- showErrorProps: true,
166
- rawStack: true,
167
- severity: 'error',
168
- },
169
-
170
- // Errors related with the telemetry output
171
- telemetry: {
172
- showInBuildLog: false,
173
- title: 'Telemetry error',
174
- stackType: 'stack',
175
- showErrorProps: true,
176
- rawStack: true,
177
- severity: 'error',
178
- },
179
- }
180
-
181
- // When no error type matches, it's an uncaught exception, i.e. a bug
182
- 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
- }
@@ -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
- }
package/src/log/logger.js DELETED
@@ -1,107 +0,0 @@
1
- import figures from 'figures'
2
- import indentString from 'indent-string'
3
-
4
- import { getHeader } from './header.js'
5
- import { serializeObject, serializeArray } from './serialize.js'
6
- import { THEME } from './theme.js'
7
-
8
- // When the `buffer` option is true, we return logs instead of printing them
9
- // on the console. The logs are accumulated in a `logs` array variable.
10
- export const getBufferLogs = function ({ buffer = false }) {
11
- if (!buffer) {
12
- return
13
- }
14
-
15
- return { stdout: [], stderr: [] }
16
- }
17
-
18
- // Core logging utility, used by the other methods.
19
- // This should be used instead of `console.log()` as it allows us to instrument
20
- // how any build logs is being printed.
21
- export const log = function (logs, string, { indent = false, color } = {}) {
22
- const stringA = indent ? indentString(string, INDENT_SIZE) : string
23
- const stringB = String(stringA).replace(EMPTY_LINES_REGEXP, EMPTY_LINE)
24
- const stringC = color === undefined ? stringB : color(stringB)
25
-
26
- if (logs !== undefined) {
27
- // `logs` is a stateful variable
28
- // eslint-disable-next-line fp/no-mutating-methods
29
- logs.stdout.push(stringC)
30
- return
31
- }
32
-
33
- console.log(stringC)
34
- }
35
-
36
- const INDENT_SIZE = 2
37
-
38
- // We need to add a zero width space character in empty lines. Otherwise the
39
- // buildbot removes those due to a bug: https://github.com/netlify/buildbot/issues/595
40
- const EMPTY_LINES_REGEXP = /^\s*$/gm
41
- const EMPTY_LINE = '\u{200B}'
42
-
43
- const serializeIndentedArray = function (array) {
44
- return serializeArray(array.map(serializeIndentedItem))
45
- }
46
-
47
- const serializeIndentedItem = function (item) {
48
- return indentString(item, INDENT_SIZE + 1).trimStart()
49
- }
50
-
51
- export const logError = function (logs, string, opts) {
52
- log(logs, string, { color: THEME.errorLine, ...opts })
53
- }
54
-
55
- export const logWarning = function (logs, string, opts) {
56
- log(logs, string, { color: THEME.warningLine, ...opts })
57
- }
58
-
59
- // Print a message that is under a header/subheader, i.e. indented
60
- export const logMessage = function (logs, string, opts) {
61
- log(logs, string, { indent: true, ...opts })
62
- }
63
-
64
- // Print an object
65
- export const logObject = function (logs, object, opts) {
66
- logMessage(logs, serializeObject(object), opts)
67
- }
68
-
69
- // Print an array
70
- export const logArray = function (logs, array, opts) {
71
- logMessage(logs, serializeIndentedArray(array), { color: THEME.none, ...opts })
72
- }
73
-
74
- // Print an array of errors
75
- export const logErrorArray = function (logs, array, opts) {
76
- logMessage(logs, serializeIndentedArray(array), { color: THEME.errorLine, ...opts })
77
- }
78
-
79
- // Print an array of warnings
80
- export const logWarningArray = function (logs, array, opts) {
81
- logMessage(logs, serializeIndentedArray(array), { color: THEME.warningLine, ...opts })
82
- }
83
-
84
- // Print a main section header
85
- export const logHeader = function (logs, string, opts) {
86
- log(logs, `\n${getHeader(string)}`, { color: THEME.header, ...opts })
87
- }
88
-
89
- // Print a main section header, when an error happened
90
- export const logErrorHeader = function (logs, string, opts) {
91
- logHeader(logs, string, { color: THEME.errorHeader, ...opts })
92
- }
93
-
94
- // Print a sub-section header
95
- export const logSubHeader = function (logs, string, opts) {
96
- log(logs, `\n${figures.pointer} ${string}`, { color: THEME.subHeader, ...opts })
97
- }
98
-
99
- // Print a sub-section header, when an error happened
100
- export const logErrorSubHeader = function (logs, string, opts) {
101
- logSubHeader(logs, string, { color: THEME.errorSubHeader, ...opts })
102
- }
103
-
104
- // Print a sub-section header, when a warning happened
105
- export const logWarningSubHeader = function (logs, string, opts) {
106
- logSubHeader(logs, string, { color: THEME.warningSubHeader, ...opts })
107
- }