@netlify/build 27.18.3 → 27.18.5-rc

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 (135) hide show
  1. package/package.json +10 -9
  2. package/src/core/bin.js +0 -83
  3. package/src/core/build.js +0 -559
  4. package/src/core/config.js +0 -186
  5. package/src/core/constants.js +0 -156
  6. package/src/core/dev.js +0 -31
  7. package/src/core/dry.js +0 -39
  8. package/src/core/feature_flags.js +0 -22
  9. package/src/core/flags.js +0 -204
  10. package/src/core/lingering.js +0 -85
  11. package/src/core/main.js +0 -165
  12. package/src/core/missing_side_file.js +0 -29
  13. package/src/core/normalize_flags.js +0 -70
  14. package/src/core/severity.js +0 -22
  15. package/src/core/user_node_version.js +0 -41
  16. package/src/env/changes.js +0 -52
  17. package/src/env/main.js +0 -19
  18. package/src/env/metadata.js +0 -81
  19. package/src/error/api.js +0 -46
  20. package/src/error/build.js +0 -50
  21. package/src/error/cancel.js +0 -8
  22. package/src/error/colors.js +0 -11
  23. package/src/error/handle.js +0 -57
  24. package/src/error/info.js +0 -46
  25. package/src/error/monitor/location.js +0 -21
  26. package/src/error/monitor/normalize.js +0 -96
  27. package/src/error/monitor/print.js +0 -42
  28. package/src/error/monitor/report.js +0 -138
  29. package/src/error/monitor/start.js +0 -69
  30. package/src/error/parse/clean_stack.js +0 -87
  31. package/src/error/parse/location.js +0 -62
  32. package/src/error/parse/normalize.js +0 -29
  33. package/src/error/parse/parse.js +0 -97
  34. package/src/error/parse/plugin.js +0 -70
  35. package/src/error/parse/properties.js +0 -23
  36. package/src/error/parse/serialize_log.js +0 -42
  37. package/src/error/parse/serialize_status.js +0 -23
  38. package/src/error/parse/stack.js +0 -43
  39. package/src/error/type.js +0 -189
  40. package/src/install/functions.js +0 -28
  41. package/src/install/local.js +0 -62
  42. package/src/install/main.js +0 -81
  43. package/src/install/missing.js +0 -67
  44. package/src/log/colors.js +0 -34
  45. package/src/log/description.js +0 -26
  46. package/src/log/header.js +0 -16
  47. package/src/log/header_func.js +0 -17
  48. package/src/log/logger.js +0 -161
  49. package/src/log/messages/compatibility.js +0 -178
  50. package/src/log/messages/config.js +0 -107
  51. package/src/log/messages/core.js +0 -70
  52. package/src/log/messages/core_steps.js +0 -104
  53. package/src/log/messages/dry.js +0 -63
  54. package/src/log/messages/install.js +0 -32
  55. package/src/log/messages/ipc.js +0 -38
  56. package/src/log/messages/mutations.js +0 -82
  57. package/src/log/messages/plugins.js +0 -39
  58. package/src/log/messages/status.js +0 -16
  59. package/src/log/messages/steps.js +0 -22
  60. package/src/log/old_version.js +0 -41
  61. package/src/log/serialize.js +0 -13
  62. package/src/log/stream.js +0 -85
  63. package/src/log/theme.js +0 -26
  64. package/src/plugins/child/diff.js +0 -55
  65. package/src/plugins/child/error.js +0 -32
  66. package/src/plugins/child/lazy.js +0 -18
  67. package/src/plugins/child/load.js +0 -29
  68. package/src/plugins/child/logic.js +0 -65
  69. package/src/plugins/child/main.js +0 -51
  70. package/src/plugins/child/run.js +0 -28
  71. package/src/plugins/child/status.js +0 -74
  72. package/src/plugins/child/typescript.js +0 -45
  73. package/src/plugins/child/utils.js +0 -56
  74. package/src/plugins/child/validate.js +0 -34
  75. package/src/plugins/compatibility.js +0 -132
  76. package/src/plugins/error.js +0 -50
  77. package/src/plugins/events.js +0 -17
  78. package/src/plugins/expected_version.js +0 -119
  79. package/src/plugins/ipc.js +0 -145
  80. package/src/plugins/list.js +0 -86
  81. package/src/plugins/load.js +0 -70
  82. package/src/plugins/manifest/check.js +0 -106
  83. package/src/plugins/manifest/load.js +0 -41
  84. package/src/plugins/manifest/main.js +0 -22
  85. package/src/plugins/manifest/path.js +0 -31
  86. package/src/plugins/manifest/validate.js +0 -108
  87. package/src/plugins/node_version.js +0 -50
  88. package/src/plugins/options.js +0 -88
  89. package/src/plugins/pinned_version.js +0 -131
  90. package/src/plugins/resolve.js +0 -152
  91. package/src/plugins/spawn.js +0 -72
  92. package/src/plugins_core/add.js +0 -49
  93. package/src/plugins_core/build_command.js +0 -75
  94. package/src/plugins_core/deploy/buildbot_client.js +0 -113
  95. package/src/plugins_core/deploy/index.js +0 -73
  96. package/src/plugins_core/deploy/manifest.yml +0 -1
  97. package/src/plugins_core/edge_functions/index.js +0 -123
  98. package/src/plugins_core/edge_functions/lib/error.js +0 -21
  99. package/src/plugins_core/edge_functions/lib/internal_manifest.js +0 -60
  100. package/src/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +0 -89
  101. package/src/plugins_core/functions/error.js +0 -163
  102. package/src/plugins_core/functions/feature_flags.js +0 -6
  103. package/src/plugins_core/functions/index.js +0 -161
  104. package/src/plugins_core/functions/utils.js +0 -66
  105. package/src/plugins_core/functions/zisi.js +0 -56
  106. package/src/plugins_core/functions_install/index.js +0 -13
  107. package/src/plugins_core/functions_install/manifest.yml +0 -1
  108. package/src/plugins_core/list.js +0 -27
  109. package/src/status/add.js +0 -36
  110. package/src/status/colors.js +0 -23
  111. package/src/status/load_error.js +0 -11
  112. package/src/status/report.js +0 -137
  113. package/src/status/success.js +0 -18
  114. package/src/steps/core_step.js +0 -92
  115. package/src/steps/error.js +0 -102
  116. package/src/steps/get.js +0 -51
  117. package/src/steps/plugin.js +0 -85
  118. package/src/steps/return.js +0 -52
  119. package/src/steps/run_core_steps.js +0 -200
  120. package/src/steps/run_step.js +0 -304
  121. package/src/steps/run_steps.js +0 -179
  122. package/src/steps/update_config.js +0 -93
  123. package/src/telemetry/main.js +0 -136
  124. package/src/time/aggregate.js +0 -146
  125. package/src/time/main.js +0 -48
  126. package/src/time/measure.js +0 -22
  127. package/src/time/report.js +0 -59
  128. package/src/utils/errors.js +0 -12
  129. package/src/utils/json.js +0 -19
  130. package/src/utils/omit.js +0 -6
  131. package/src/utils/package.js +0 -23
  132. package/src/utils/remove_falsy.js +0 -10
  133. package/src/utils/resolve.js +0 -46
  134. package/src/utils/runtime.js +0 -5
  135. package/src/utils/semver.js +0 -34
@@ -1,97 +0,0 @@
1
- import { serializeObject } from '../../log/serialize.js'
2
- import { getErrorInfo } from '../info.js'
3
- import { getTypeInfo } from '../type.js'
4
-
5
- import { getLocationInfo } from './location.js'
6
- import { normalizeError } from './normalize.js'
7
- import { getPluginInfo } from './plugin.js'
8
- import { getErrorProps } from './properties.js'
9
- import { getStackInfo } from './stack.js'
10
-
11
- // Add additional type-specific error information
12
- export const getFullErrorInfo = function ({ error, colors, debug }) {
13
- const basicErrorInfo = parseErrorInfo(error)
14
- const {
15
- message,
16
- stack,
17
- errorProps,
18
- errorInfo,
19
- errorInfo: { location = {}, plugin = {}, tsConfig },
20
- severity,
21
- title,
22
- stackType,
23
- locationType,
24
- showErrorProps,
25
- rawStack,
26
- } = basicErrorInfo
27
-
28
- const titleA = getTitle(title, errorInfo)
29
-
30
- const { message: messageA, stack: stackA } = getStackInfo({ message, stack, stackType, rawStack, severity, debug })
31
-
32
- const pluginInfo = getPluginInfo(plugin, location)
33
- const tsConfigInfo = getTsConfigInfo(tsConfig)
34
- const locationInfo = getLocationInfo({ stack: stackA, location, locationType })
35
- const errorPropsA = getErrorProps({ errorProps, showErrorProps, colors })
36
-
37
- return {
38
- ...basicErrorInfo,
39
- title: titleA,
40
- message: messageA,
41
- tsConfigInfo,
42
- pluginInfo,
43
- locationInfo,
44
- errorProps: errorPropsA,
45
- }
46
- }
47
-
48
- // Serialize the `tsConfig` error information
49
- const getTsConfigInfo = function (tsConfig) {
50
- if (tsConfig === undefined) {
51
- return
52
- }
53
-
54
- return serializeObject(tsConfig)
55
- }
56
-
57
- // Parse error instance into all the basic properties containing information
58
- export const parseErrorInfo = function (error) {
59
- const { message, stack, ...errorProps } = normalizeError(error)
60
- const [errorInfo, errorPropsA] = getErrorInfo(errorProps)
61
- const {
62
- type,
63
- severity,
64
- title,
65
- group,
66
- stackType,
67
- locationType,
68
- showErrorProps,
69
- showInBuildLog = true,
70
- rawStack,
71
- } = getTypeInfo(errorInfo)
72
- const basicErrorInfo = {
73
- message,
74
- stack,
75
- errorProps: errorPropsA,
76
- errorInfo,
77
- type,
78
- severity,
79
- title,
80
- group,
81
- stackType,
82
- locationType,
83
- showInBuildLog,
84
- showErrorProps,
85
- rawStack,
86
- }
87
- return basicErrorInfo
88
- }
89
-
90
- // Retrieve title to print in logs
91
- const getTitle = function (title, errorInfo) {
92
- if (typeof title !== 'function') {
93
- return title
94
- }
95
-
96
- return title(errorInfo)
97
- }
@@ -1,70 +0,0 @@
1
- // Retrieve plugin's package.json details to include in error messages.
2
- // Please note `pluginPackageJson` has been normalized by `normalize-package-data`.
3
- export const getPluginInfo = function ({ pluginPackageJson = {} }, { packageName, loadedFrom }) {
4
- if (Object.keys(pluginPackageJson).length === 0) {
5
- return
6
- }
7
-
8
- return Object.entries(FIELDS)
9
- .map(([name, getField]) => serializeField({ name, getField, pluginPackageJson, packageName, loadedFrom }))
10
- .filter(Boolean)
11
- .join('\n')
12
- }
13
-
14
- // Serialize a single package.json field
15
- const serializeField = function ({ name, getField, pluginPackageJson, packageName, loadedFrom }) {
16
- const field = getField(pluginPackageJson, { packageName, loadedFrom })
17
- if (field === undefined) {
18
- return
19
- }
20
-
21
- const nameA = `${name}:`.padEnd(NAME_PADDING)
22
- return `${nameA}${field}`
23
- }
24
-
25
- const NAME_PADDING = 16
26
-
27
- const getPackage = function (pluginPackageJson, { packageName }) {
28
- return packageName
29
- }
30
-
31
- const getVersion = function ({ version }) {
32
- if (version === '') {
33
- return
34
- }
35
-
36
- return version
37
- }
38
-
39
- export const getHomepage = function (pluginPackageJson = {}, { loadedFrom } = {}) {
40
- return (
41
- getRepository(pluginPackageJson) ||
42
- getNpmLink(pluginPackageJson, { loadedFrom }) ||
43
- getIssuesLink(pluginPackageJson)
44
- )
45
- }
46
-
47
- const getRepository = function ({ repository: { url } = {} }) {
48
- return url
49
- }
50
-
51
- const getNpmLink = function ({ name }, { loadedFrom }) {
52
- if (!name || loadedFrom === 'local') {
53
- return
54
- }
55
-
56
- return `https://www.npmjs.com/package/${name}`
57
- }
58
-
59
- const getIssuesLink = function ({ bugs: { url } = {} }) {
60
- return url
61
- }
62
-
63
- // List of package.json to serialize
64
- const FIELDS = {
65
- Package: getPackage,
66
- Version: getVersion,
67
- Repository: getRepository,
68
- 'npm link': getNpmLink,
69
- 'Report issues': getIssuesLink,
70
- }
@@ -1,23 +0,0 @@
1
- import { inspect } from 'util'
2
-
3
- import { omit } from '../../utils/omit.js'
4
-
5
- // In uncaught exceptions, print error static properties
6
- export const getErrorProps = function ({ errorProps, showErrorProps, colors }) {
7
- if (!showErrorProps) {
8
- return
9
- }
10
-
11
- const errorPropsA = omit(errorProps, CLEANED_ERROR_PROPS)
12
-
13
- if (Object.keys(errorPropsA).length === 0) {
14
- return
15
- }
16
-
17
- return inspect(errorPropsA, { colors, depth: INSPECT_MAX_DEPTH })
18
- }
19
-
20
- const INSPECT_MAX_DEPTH = 5
21
-
22
- // Remove error static properties that should not be logged
23
- const CLEANED_ERROR_PROPS = ['requireStack']
@@ -1,42 +0,0 @@
1
- import { THEME } from '../../log/theme.js'
2
-
3
- // Serialize an error object into a title|body string to print in logs
4
- export const serializeLogError = function ({
5
- fullErrorInfo: { title, severity, message, pluginInfo, locationInfo, tsConfigInfo, errorProps },
6
- }) {
7
- const body = getBody({ message, pluginInfo, locationInfo, tsConfigInfo, errorProps, severity })
8
- return { title, body }
9
- }
10
-
11
- const getBody = function ({ message, pluginInfo, locationInfo, tsConfigInfo, errorProps, severity }) {
12
- if (severity === 'none') {
13
- return message
14
- }
15
-
16
- return Object.entries({
17
- message,
18
- tsConfigInfo,
19
- pluginInfo,
20
- locationInfo,
21
- errorProps,
22
- })
23
- .filter(blockHasValue)
24
- .map(serializeBlock)
25
- .join('\n\n')
26
- }
27
-
28
- const blockHasValue = function ([, value]) {
29
- return value !== undefined
30
- }
31
-
32
- const serializeBlock = function ([key, value]) {
33
- return `${THEME.errorSubHeader(LOG_BLOCK_NAMES[key])}\n${value}`
34
- }
35
-
36
- const LOG_BLOCK_NAMES = {
37
- message: 'Error message',
38
- pluginInfo: 'Plugin details',
39
- locationInfo: 'Error location',
40
- tsConfigInfo: 'TypeScript configuration',
41
- errorProps: 'Error properties',
42
- }
@@ -1,23 +0,0 @@
1
- // Serialize an error object to `statuses` properties
2
- export const serializeErrorStatus = function ({ fullErrorInfo: { title, message, locationInfo, errorProps }, state }) {
3
- const text = getText({ locationInfo, errorProps })
4
- return { state, title, summary: message, text }
5
- }
6
-
7
- const getText = function ({ locationInfo, errorProps }) {
8
- const parts = [locationInfo, getErrorProps(errorProps)].filter(Boolean)
9
-
10
- if (parts.length === 0) {
11
- return
12
- }
13
-
14
- return parts.join('\n\n')
15
- }
16
-
17
- const getErrorProps = function (errorProps) {
18
- if (errorProps === undefined) {
19
- return
20
- }
21
-
22
- return `Error properties:\n${errorProps}`
23
- }
@@ -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']