@netlify/build 27.20.3 → 27.20.5

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 (133) hide show
  1. package/lib/core/bin.js +42 -59
  2. package/lib/core/build.js +333 -536
  3. package/lib/core/config.js +94 -159
  4. package/lib/core/constants.js +95 -135
  5. package/lib/core/dev.js +26 -30
  6. package/lib/core/dry.js +18 -36
  7. package/lib/core/feature_flags.js +13 -16
  8. package/lib/core/flags.js +168 -169
  9. package/lib/core/lingering.js +44 -61
  10. package/lib/core/main.js +94 -136
  11. package/lib/core/missing_side_file.js +12 -24
  12. package/lib/core/normalize_flags.js +52 -63
  13. package/lib/core/severity.js +13 -15
  14. package/lib/core/user_node_version.js +26 -35
  15. package/lib/env/changes.js +29 -37
  16. package/lib/env/main.js +10 -15
  17. package/lib/env/metadata.js +63 -76
  18. package/lib/error/api.js +31 -40
  19. package/lib/error/build.js +27 -38
  20. package/lib/error/cancel.js +5 -6
  21. package/lib/error/colors.js +7 -9
  22. package/lib/error/handle.js +38 -49
  23. package/lib/error/info.js +26 -35
  24. package/lib/error/monitor/location.js +12 -17
  25. package/lib/error/monitor/normalize.js +75 -85
  26. package/lib/error/monitor/print.js +19 -41
  27. package/lib/error/monitor/report.js +102 -121
  28. package/lib/error/monitor/start.js +43 -56
  29. package/lib/error/parse/clean_stack.js +52 -69
  30. package/lib/error/parse/location.js +40 -52
  31. package/lib/error/parse/normalize.js +18 -23
  32. package/lib/error/parse/parse.js +59 -93
  33. package/lib/error/parse/plugin.js +42 -57
  34. package/lib/error/parse/properties.js +13 -20
  35. package/lib/error/parse/serialize_log.js +29 -37
  36. package/lib/error/parse/serialize_status.js +15 -23
  37. package/lib/error/parse/stack.js +29 -38
  38. package/lib/error/type.js +132 -150
  39. package/lib/install/functions.js +16 -24
  40. package/lib/install/local.js +31 -48
  41. package/lib/install/main.js +52 -66
  42. package/lib/install/missing.js +40 -53
  43. package/lib/log/colors.js +15 -22
  44. package/lib/log/description.js +16 -21
  45. package/lib/log/header.js +11 -13
  46. package/lib/log/header_func.js +11 -15
  47. package/lib/log/logger.js +88 -119
  48. package/lib/log/messages/compatibility.js +100 -158
  49. package/lib/log/messages/config.js +76 -92
  50. package/lib/log/messages/core.js +40 -60
  51. package/lib/log/messages/core_steps.js +63 -92
  52. package/lib/log/messages/dry.js +31 -53
  53. package/lib/log/messages/install.js +21 -28
  54. package/lib/log/messages/ipc.js +21 -30
  55. package/lib/log/messages/mutations.js +51 -71
  56. package/lib/log/messages/plugins.js +18 -31
  57. package/lib/log/messages/status.js +12 -14
  58. package/lib/log/messages/steps.js +14 -18
  59. package/lib/log/old_version.js +23 -32
  60. package/lib/log/serialize.js +7 -10
  61. package/lib/log/stream.js +48 -65
  62. package/lib/log/theme.js +22 -23
  63. package/lib/plugins/child/diff.js +31 -40
  64. package/lib/plugins/child/error.js +20 -26
  65. package/lib/plugins/child/lazy.js +11 -14
  66. package/lib/plugins/child/load.js +15 -22
  67. package/lib/plugins/child/logic.js +51 -58
  68. package/lib/plugins/child/main.js +32 -46
  69. package/lib/plugins/child/run.js +18 -27
  70. package/lib/plugins/child/status.js +52 -63
  71. package/lib/plugins/child/typescript.js +19 -36
  72. package/lib/plugins/child/utils.js +36 -49
  73. package/lib/plugins/child/validate.js +25 -28
  74. package/lib/plugins/compatibility.js +64 -92
  75. package/lib/plugins/error.js +29 -35
  76. package/lib/plugins/events.js +7 -12
  77. package/lib/plugins/expected_version.js +61 -99
  78. package/lib/plugins/ipc.js +79 -102
  79. package/lib/plugins/list.js +49 -62
  80. package/lib/plugins/load.js +44 -64
  81. package/lib/plugins/manifest/check.js +64 -85
  82. package/lib/plugins/manifest/load.js +34 -37
  83. package/lib/plugins/manifest/main.js +16 -21
  84. package/lib/plugins/manifest/path.js +18 -25
  85. package/lib/plugins/manifest/validate.js +77 -94
  86. package/lib/plugins/node_version.js +22 -42
  87. package/lib/plugins/options.js +45 -78
  88. package/lib/plugins/pinned_version.js +58 -106
  89. package/lib/plugins/resolve.js +91 -133
  90. package/lib/plugins/spawn.js +43 -61
  91. package/lib/plugins_core/add.js +26 -40
  92. package/lib/plugins_core/build_command.js +47 -72
  93. package/lib/plugins_core/deploy/buildbot_client.js +61 -87
  94. package/lib/plugins_core/deploy/index.js +47 -71
  95. package/lib/plugins_core/edge_functions/index.js +73 -116
  96. package/lib/plugins_core/edge_functions/lib/error.js +13 -17
  97. package/lib/plugins_core/edge_functions/lib/internal_manifest.js +45 -55
  98. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +65 -80
  99. package/lib/plugins_core/functions/error.js +88 -128
  100. package/lib/plugins_core/functions/feature_flags.js +5 -5
  101. package/lib/plugins_core/functions/index.js +98 -145
  102. package/lib/plugins_core/functions/utils.js +36 -57
  103. package/lib/plugins_core/functions/zisi.js +35 -52
  104. package/lib/plugins_core/functions_install/index.js +8 -11
  105. package/lib/plugins_core/list.js +15 -22
  106. package/lib/status/add.js +26 -32
  107. package/lib/status/colors.js +14 -19
  108. package/lib/status/load_error.js +8 -9
  109. package/lib/status/report.js +72 -126
  110. package/lib/status/success.js +10 -14
  111. package/lib/steps/core_step.js +54 -89
  112. package/lib/steps/error.js +50 -87
  113. package/lib/steps/get.js +33 -41
  114. package/lib/steps/plugin.js +53 -83
  115. package/lib/steps/return.js +24 -51
  116. package/lib/steps/run_core_steps.js +119 -171
  117. package/lib/steps/run_step.js +154 -270
  118. package/lib/steps/run_steps.js +91 -174
  119. package/lib/steps/update_config.js +45 -72
  120. package/lib/telemetry/main.js +89 -128
  121. package/lib/time/aggregate.js +84 -110
  122. package/lib/time/main.js +23 -34
  123. package/lib/time/measure.js +11 -15
  124. package/lib/time/report.js +32 -44
  125. package/lib/utils/errors.js +10 -9
  126. package/lib/utils/json.js +11 -15
  127. package/lib/utils/omit.js +3 -4
  128. package/lib/utils/package.js +19 -22
  129. package/lib/utils/remove_falsy.js +5 -7
  130. package/lib/utils/resolve.js +30 -34
  131. package/lib/utils/runtime.js +4 -4
  132. package/lib/utils/semver.js +19 -25
  133. package/package.json +15 -8
@@ -1,161 +1,114 @@
1
- import { resolve } from 'path'
2
-
3
- import { zipFunctions } from '@netlify/zip-it-and-ship-it'
4
- import { pathExists } from 'path-exists'
5
-
6
- import { log } from '../../log/logger.js'
7
- import { logBundleResults, logFunctionsNonExistingDir, logFunctionsToBundle } from '../../log/messages/core_steps.js'
8
-
9
- import { getZipError } from './error.js'
10
- import { getUserAndInternalFunctions, validateFunctionsSrc } from './utils.js'
11
- import { getZisiParameters } from './zisi.js'
12
-
1
+ import { resolve } from 'path';
2
+ import { zipFunctions } from '@netlify/zip-it-and-ship-it';
3
+ import { pathExists } from 'path-exists';
4
+ import { log } from '../../log/logger.js';
5
+ import { logBundleResults, logFunctionsNonExistingDir, logFunctionsToBundle } from '../../log/messages/core_steps.js';
6
+ import { getZipError } from './error.js';
7
+ import { getUserAndInternalFunctions, validateFunctionsSrc } from './utils.js';
8
+ import { getZisiParameters } from './zisi.js';
13
9
  // Returns `true` if at least one of the functions has been configured to use
14
10
  // esbuild.
15
- const isUsingEsbuild = (functionsConfig = {}) =>
16
- Object.values(functionsConfig).some((configObject) => configObject.node_bundler === 'esbuild')
17
-
18
- const zipFunctionsAndLogResults = async ({
19
- buildDir,
20
- childEnv,
21
- featureFlags,
22
- functionsConfig,
23
- functionsDist,
24
- functionsSrc,
25
- internalFunctionsSrc,
26
- isRunningLocally,
27
- logs,
28
- repositoryRoot,
29
- }) => {
30
- const zisiParameters = getZisiParameters({
31
- buildDir,
32
- childEnv,
33
- featureFlags,
34
- functionsConfig,
35
- functionsDist,
36
- internalFunctionsSrc,
37
- isRunningLocally,
38
- repositoryRoot,
39
- })
40
- const bundler = isUsingEsbuild(functionsConfig) ? 'esbuild' : 'zisi'
41
-
42
- try {
43
- // Printing an empty line before bundling output.
44
- log(logs, '')
45
-
46
- const sourceDirectories = [internalFunctionsSrc, functionsSrc].filter(Boolean)
47
- const results = await zipItAndShipIt.zipFunctions(sourceDirectories, functionsDist, zisiParameters)
48
-
49
- logBundleResults({ logs, results })
50
-
51
- return { bundler }
52
- } catch (error) {
53
- throw await getZipError(error, functionsSrc)
54
- }
55
- }
56
-
11
+ const isUsingEsbuild = (functionsConfig = {}) => Object.values(functionsConfig).some((configObject) => configObject.node_bundler === 'esbuild');
12
+ const zipFunctionsAndLogResults = async ({ buildDir, childEnv, featureFlags, functionsConfig, functionsDist, functionsSrc, internalFunctionsSrc, isRunningLocally, logs, repositoryRoot, }) => {
13
+ const zisiParameters = getZisiParameters({
14
+ buildDir,
15
+ childEnv,
16
+ featureFlags,
17
+ functionsConfig,
18
+ functionsDist,
19
+ internalFunctionsSrc,
20
+ isRunningLocally,
21
+ repositoryRoot,
22
+ });
23
+ const bundler = isUsingEsbuild(functionsConfig) ? 'esbuild' : 'zisi';
24
+ try {
25
+ // Printing an empty line before bundling output.
26
+ log(logs, '');
27
+ const sourceDirectories = [internalFunctionsSrc, functionsSrc].filter(Boolean);
28
+ const results = await zipItAndShipIt.zipFunctions(sourceDirectories, functionsDist, zisiParameters);
29
+ logBundleResults({ logs, results });
30
+ return { bundler };
31
+ }
32
+ catch (error) {
33
+ throw await getZipError(error, functionsSrc);
34
+ }
35
+ };
57
36
  // Plugin to package Netlify functions with @netlify/zip-it-and-ship-it
58
-
59
- const coreStep = async function ({
60
- childEnv,
61
- constants: {
62
- INTERNAL_FUNCTIONS_SRC: relativeInternalFunctionsSrc,
63
- IS_LOCAL: isRunningLocally,
64
- FUNCTIONS_SRC: relativeFunctionsSrc,
65
- FUNCTIONS_DIST: relativeFunctionsDist,
66
- },
67
- buildDir,
68
- logs,
69
- netlifyConfig,
70
- featureFlags,
71
- repositoryRoot,
72
- }) {
73
- const functionsSrc = relativeFunctionsSrc === undefined ? undefined : resolve(buildDir, relativeFunctionsSrc)
74
- const functionsDist = resolve(buildDir, relativeFunctionsDist)
75
- const internalFunctionsSrc = resolve(buildDir, relativeInternalFunctionsSrc)
76
- const internalFunctionsSrcExists = await pathExists(internalFunctionsSrc)
77
- const functionsSrcExists = await validateFunctionsSrc({ functionsSrc, logs, relativeFunctionsSrc })
78
- const [userFunctions = [], internalFunctions = []] = await getUserAndInternalFunctions({
79
- featureFlags,
80
- functionsSrc,
81
- functionsSrcExists,
82
- internalFunctionsSrc,
83
- internalFunctionsSrcExists,
84
- })
85
-
86
- if (functionsSrc && !functionsSrcExists) {
87
- logFunctionsNonExistingDir(logs, relativeFunctionsSrc)
88
-
89
- if (internalFunctions.length !== 0) {
90
- log(logs, '')
37
+ const coreStep = async function ({ childEnv, constants: { INTERNAL_FUNCTIONS_SRC: relativeInternalFunctionsSrc, IS_LOCAL: isRunningLocally, FUNCTIONS_SRC: relativeFunctionsSrc, FUNCTIONS_DIST: relativeFunctionsDist, }, buildDir, logs, netlifyConfig, featureFlags, repositoryRoot, }) {
38
+ const functionsSrc = relativeFunctionsSrc === undefined ? undefined : resolve(buildDir, relativeFunctionsSrc);
39
+ const functionsDist = resolve(buildDir, relativeFunctionsDist);
40
+ const internalFunctionsSrc = resolve(buildDir, relativeInternalFunctionsSrc);
41
+ const internalFunctionsSrcExists = await pathExists(internalFunctionsSrc);
42
+ const functionsSrcExists = await validateFunctionsSrc({ functionsSrc, logs, relativeFunctionsSrc });
43
+ const [userFunctions = [], internalFunctions = []] = await getUserAndInternalFunctions({
44
+ featureFlags,
45
+ functionsSrc,
46
+ functionsSrcExists,
47
+ internalFunctionsSrc,
48
+ internalFunctionsSrcExists,
49
+ });
50
+ if (functionsSrc && !functionsSrcExists) {
51
+ logFunctionsNonExistingDir(logs, relativeFunctionsSrc);
52
+ if (internalFunctions.length !== 0) {
53
+ log(logs, '');
54
+ }
91
55
  }
92
- }
93
-
94
- logFunctionsToBundle({
95
- logs,
96
- userFunctions,
97
- userFunctionsSrc: relativeFunctionsSrc,
98
- userFunctionsSrcExists: functionsSrcExists,
99
- internalFunctions,
100
- internalFunctionsSrc: relativeInternalFunctionsSrc,
101
- })
102
-
103
- if (userFunctions.length === 0 && internalFunctions.length === 0) {
104
- return {}
105
- }
106
-
107
- const { bundler } = await zipFunctionsAndLogResults({
108
- buildDir,
109
- childEnv,
110
- featureFlags,
111
- functionsConfig: netlifyConfig.functions,
112
- functionsDist,
113
- functionsSrc,
114
- internalFunctionsSrc,
115
- isRunningLocally,
116
- logs,
117
- repositoryRoot,
118
- })
119
-
120
- return {
121
- tags: {
122
- bundler,
123
- },
124
- }
125
- }
126
-
56
+ logFunctionsToBundle({
57
+ logs,
58
+ userFunctions,
59
+ userFunctionsSrc: relativeFunctionsSrc,
60
+ userFunctionsSrcExists: functionsSrcExists,
61
+ internalFunctions,
62
+ internalFunctionsSrc: relativeInternalFunctionsSrc,
63
+ });
64
+ if (userFunctions.length === 0 && internalFunctions.length === 0) {
65
+ return {};
66
+ }
67
+ const { bundler } = await zipFunctionsAndLogResults({
68
+ buildDir,
69
+ childEnv,
70
+ featureFlags,
71
+ functionsConfig: netlifyConfig.functions,
72
+ functionsDist,
73
+ functionsSrc,
74
+ internalFunctionsSrc,
75
+ isRunningLocally,
76
+ logs,
77
+ repositoryRoot,
78
+ });
79
+ return {
80
+ tags: {
81
+ bundler,
82
+ },
83
+ };
84
+ };
127
85
  // We run this core step if at least one of the functions directories (the
128
86
  // one configured by the user or the internal one) exists. We use a dynamic
129
87
  // `condition` because the directories might be created by the build command
130
88
  // or plugins.
131
89
  const hasFunctionsDirectories = async function ({ buildDir, constants: { INTERNAL_FUNCTIONS_SRC, FUNCTIONS_SRC } }) {
132
- const hasFunctionsSrc = FUNCTIONS_SRC !== undefined && FUNCTIONS_SRC !== ''
133
-
134
- if (hasFunctionsSrc) {
135
- return true
136
- }
137
-
138
- const internalFunctionsSrc = resolve(buildDir, INTERNAL_FUNCTIONS_SRC)
139
-
140
- return await pathExists(internalFunctionsSrc)
141
- }
142
-
90
+ const hasFunctionsSrc = FUNCTIONS_SRC !== undefined && FUNCTIONS_SRC !== '';
91
+ if (hasFunctionsSrc) {
92
+ return true;
93
+ }
94
+ const internalFunctionsSrc = resolve(buildDir, INTERNAL_FUNCTIONS_SRC);
95
+ return await pathExists(internalFunctionsSrc);
96
+ };
143
97
  export const bundleFunctions = {
144
- event: 'onBuild',
145
- coreStep,
146
- coreStepId: 'functions_bundling',
147
- coreStepName: 'Functions bundling',
148
- coreStepDescription: () => 'Functions bundling',
149
- condition: hasFunctionsDirectories,
150
- }
151
-
98
+ event: 'onBuild',
99
+ coreStep,
100
+ coreStepId: 'functions_bundling',
101
+ coreStepName: 'Functions bundling',
102
+ coreStepDescription: () => 'Functions bundling',
103
+ condition: hasFunctionsDirectories,
104
+ };
152
105
  // Named imports with ES modules cannot be mocked (unlike CommonJS) because
153
106
  // they are bound at load time.
154
107
  // However, some of our tests are asserting which arguments are passed to
155
108
  // `zip-it-and-ship-it` methods. Therefore, we need to use an intermediary
156
109
  // function and export them so tests can use it.
157
110
  export const zipItAndShipIt = {
158
- async zipFunctions(...args) {
159
- return await zipFunctions(...args)
160
- },
161
- }
111
+ async zipFunctions(...args) {
112
+ return await zipFunctions(...args);
113
+ },
114
+ };
@@ -1,66 +1,45 @@
1
- import { promises as fs } from 'fs'
2
- import { relative } from 'path'
3
-
4
- import { listFunctions } from '@netlify/zip-it-and-ship-it'
5
-
6
- import { addErrorInfo } from '../../error/info.js'
7
-
8
- import { getZisiFeatureFlags } from './feature_flags.js'
9
-
1
+ import { promises as fs } from 'fs';
2
+ import { relative } from 'path';
3
+ import { listFunctions } from '@netlify/zip-it-and-ship-it';
4
+ import { addErrorInfo } from '../../error/info.js';
5
+ import { getZisiFeatureFlags } from './feature_flags.js';
10
6
  // Returns the `mainFile` of each function found in `functionsSrc`, relative to
11
7
  // `functionsSrc`.
12
8
  const getRelativeFunctionMainFiles = async function ({ featureFlags, functionsSrc }) {
13
- if (functionsSrc === undefined) {
14
- return []
15
- }
16
-
17
- const zisiFeatureFlags = getZisiFeatureFlags(featureFlags)
18
- const functions = await listFunctions(functionsSrc, { featureFlags: zisiFeatureFlags })
19
- return functions.map(({ mainFile }) => relative(functionsSrc, mainFile))
20
- }
21
-
22
- export const getUserAndInternalFunctions = ({
23
- featureFlags,
24
- functionsSrc,
25
- functionsSrcExists,
26
- internalFunctionsSrc,
27
- internalFunctionsSrcExists,
28
- }) => {
29
- const paths = [
30
- functionsSrcExists ? functionsSrc : undefined,
31
- internalFunctionsSrcExists ? internalFunctionsSrc : undefined,
32
- ]
33
-
34
- return Promise.all(paths.map((path) => path && getRelativeFunctionMainFiles({ featureFlags, functionsSrc: path })))
35
- }
36
-
9
+ if (functionsSrc === undefined) {
10
+ return [];
11
+ }
12
+ const zisiFeatureFlags = getZisiFeatureFlags(featureFlags);
13
+ const functions = await listFunctions(functionsSrc, { featureFlags: zisiFeatureFlags });
14
+ return functions.map(({ mainFile }) => relative(functionsSrc, mainFile));
15
+ };
16
+ export const getUserAndInternalFunctions = ({ featureFlags, functionsSrc, functionsSrcExists, internalFunctionsSrc, internalFunctionsSrcExists, }) => {
17
+ const paths = [
18
+ functionsSrcExists ? functionsSrc : undefined,
19
+ internalFunctionsSrcExists ? internalFunctionsSrc : undefined,
20
+ ];
21
+ return Promise.all(paths.map((path) => path && getRelativeFunctionMainFiles({ featureFlags, functionsSrc: path })));
22
+ };
37
23
  // Returns `true` if the functions directory exists and is valid. Returns
38
24
  // `false` if it doesn't exist. Throws an error if it's invalid or can't
39
25
  // be accessed.
40
26
  export const validateFunctionsSrc = async function ({ functionsSrc, relativeFunctionsSrc }) {
41
- if (functionsSrc === undefined) {
42
- return false
43
- }
44
-
45
- try {
46
- const stats = await fs.stat(functionsSrc)
47
-
48
- if (stats.isDirectory()) {
49
- return true
27
+ if (functionsSrc === undefined) {
28
+ return false;
29
+ }
30
+ try {
31
+ const stats = await fs.stat(functionsSrc);
32
+ if (stats.isDirectory()) {
33
+ return true;
34
+ }
35
+ const error = new Error(`The Netlify Functions setting should target a directory, not a regular file: ${relativeFunctionsSrc}`);
36
+ addErrorInfo(error, { type: 'resolveConfig' });
37
+ throw error;
50
38
  }
51
-
52
- const error = new Error(
53
- `The Netlify Functions setting should target a directory, not a regular file: ${relativeFunctionsSrc}`,
54
- )
55
-
56
- addErrorInfo(error, { type: 'resolveConfig' })
57
-
58
- throw error
59
- } catch (error) {
60
- if (error.code === 'ENOENT') {
61
- return false
39
+ catch (error) {
40
+ if (error.code === 'ENOENT') {
41
+ return false;
42
+ }
43
+ throw error;
62
44
  }
63
-
64
- throw error
65
- }
66
- }
45
+ };
@@ -1,56 +1,39 @@
1
- import { join, resolve } from 'path'
2
-
3
- import mapObject from 'map-obj'
4
-
5
- import { getZisiFeatureFlags } from './feature_flags.js'
6
-
7
- export const getZisiParameters = ({
8
- buildDir,
9
- childEnv,
10
- featureFlags,
11
- functionsConfig,
12
- functionsDist,
13
- internalFunctionsSrc,
14
- isRunningLocally,
15
- repositoryRoot,
16
- }) => {
17
- const nodeVersion = childEnv.AWS_LAMBDA_JS_RUNTIME
18
- const manifest = join(functionsDist, 'manifest.json')
19
- const config = mapObject(functionsConfig, (expression, object) => [
20
- expression,
21
- normalizeFunctionConfig({ buildDir, featureFlags, functionConfig: object, isRunningLocally, nodeVersion }),
22
- ])
23
- const zisiFeatureFlags = getZisiFeatureFlags(featureFlags)
24
- // Only internal functions are allowed to have a json config file
25
- const configFileDirectories = [resolve(internalFunctionsSrc)]
26
-
27
- return { basePath: buildDir, config, manifest, featureFlags: zisiFeatureFlags, repositoryRoot, configFileDirectories }
28
- }
29
-
1
+ import { join, resolve } from 'path';
2
+ import mapObject from 'map-obj';
3
+ import { getZisiFeatureFlags } from './feature_flags.js';
4
+ export const getZisiParameters = ({ buildDir, childEnv, featureFlags, functionsConfig, functionsDist, internalFunctionsSrc, isRunningLocally, repositoryRoot, }) => {
5
+ const nodeVersion = childEnv.AWS_LAMBDA_JS_RUNTIME;
6
+ const manifest = join(functionsDist, 'manifest.json');
7
+ const config = mapObject(functionsConfig, (expression, object) => [
8
+ expression,
9
+ normalizeFunctionConfig({ buildDir, featureFlags, functionConfig: object, isRunningLocally, nodeVersion }),
10
+ ]);
11
+ const zisiFeatureFlags = getZisiFeatureFlags(featureFlags);
12
+ // Only internal functions are allowed to have a json config file
13
+ const configFileDirectories = [resolve(internalFunctionsSrc)];
14
+ return { basePath: buildDir, config, manifest, featureFlags: zisiFeatureFlags, repositoryRoot, configFileDirectories };
15
+ };
30
16
  // The function configuration keys returned by @netlify/config are not an exact
31
17
  // match to the properties that @netlify/zip-it-and-ship-it expects. We do that
32
18
  // translation here.
33
19
  export const normalizeFunctionConfig = ({ buildDir, functionConfig = {}, isRunningLocally, nodeVersion }) => ({
34
- externalNodeModules: functionConfig.external_node_modules,
35
- includedFiles: functionConfig.included_files,
36
- includedFilesBasePath: buildDir,
37
- ignoredNodeModules: functionConfig.ignored_node_modules,
38
- nodeVersion,
39
- schedule: functionConfig.schedule,
40
-
41
- // When the user selects esbuild as the Node bundler, we still want to use
42
- // the legacy ZISI bundler as a fallback. Rather than asking the user to
43
- // make this decision, we abstract that complexity away by injecting the
44
- // fallback behavior ourselves. We do this by transforming the value
45
- // `esbuild` into `esbuild_zisi`, which zip-it-and-ship-it understands.
46
- nodeBundler: functionConfig.node_bundler === 'esbuild' ? 'esbuild_zisi' : functionConfig.node_bundler,
47
-
48
- // If the build is running in buildbot, we set the Rust target directory to a
49
- // path that will get cached in between builds, allowing us to speed up the
50
- // build process.
51
- rustTargetDirectory: isRunningLocally ? undefined : resolve(buildDir, '.netlify', 'rust-functions-cache', '[name]'),
52
-
53
- // Go functions should be zipped only when building locally. When running in
54
- // buildbot, the Go API client will handle the zipping.
55
- zipGo: isRunningLocally ? true : undefined,
56
- })
20
+ externalNodeModules: functionConfig.external_node_modules,
21
+ includedFiles: functionConfig.included_files,
22
+ includedFilesBasePath: buildDir,
23
+ ignoredNodeModules: functionConfig.ignored_node_modules,
24
+ nodeVersion,
25
+ schedule: functionConfig.schedule,
26
+ // When the user selects esbuild as the Node bundler, we still want to use
27
+ // the legacy ZISI bundler as a fallback. Rather than asking the user to
28
+ // make this decision, we abstract that complexity away by injecting the
29
+ // fallback behavior ourselves. We do this by transforming the value
30
+ // `esbuild` into `esbuild_zisi`, which zip-it-and-ship-it understands.
31
+ nodeBundler: functionConfig.node_bundler === 'esbuild' ? 'esbuild_zisi' : functionConfig.node_bundler,
32
+ // If the build is running in buildbot, we set the Rust target directory to a
33
+ // path that will get cached in between builds, allowing us to speed up the
34
+ // build process.
35
+ rustTargetDirectory: isRunningLocally ? undefined : resolve(buildDir, '.netlify', 'rust-functions-cache', '[name]'),
36
+ // Go functions should be zipped only when building locally. When running in
37
+ // buildbot, the Go API client will handle the zipping.
38
+ zipGo: isRunningLocally ? true : undefined,
39
+ });
@@ -1,13 +1,10 @@
1
- import { pathExists } from 'path-exists'
2
-
3
- import { installFunctionDependencies } from '../../install/functions.js'
4
-
1
+ import { pathExists } from 'path-exists';
2
+ import { installFunctionDependencies } from '../../install/functions.js';
5
3
  // Plugin to package Netlify functions with @netlify/zip-it-and-ship-it
6
4
  export const onPreBuild = async function ({ constants: { FUNCTIONS_SRC, IS_LOCAL } }) {
7
- if (!(await pathExists(FUNCTIONS_SRC))) {
8
- return {}
9
- }
10
-
11
- await installFunctionDependencies(FUNCTIONS_SRC, IS_LOCAL)
12
- return {}
13
- }
5
+ if (!(await pathExists(FUNCTIONS_SRC))) {
6
+ return {};
7
+ }
8
+ await installFunctionDependencies(FUNCTIONS_SRC, IS_LOCAL);
9
+ return {};
10
+ };
@@ -1,27 +1,20 @@
1
- import { fileURLToPath } from 'url'
2
-
3
- import { LOCAL_INSTALL_PLUGIN_NAME } from '../install/local.js'
4
-
5
- const FUNCTIONS_INSTALL_PLUGIN = fileURLToPath(new URL('functions_install/index.js', import.meta.url))
6
-
1
+ import { fileURLToPath } from 'url';
2
+ import { LOCAL_INSTALL_PLUGIN_NAME } from '../install/local.js';
3
+ const FUNCTIONS_INSTALL_PLUGIN = fileURLToPath(new URL('functions_install/index.js', import.meta.url));
7
4
  // List of core plugin names
8
- const FUNCTIONS_INSTALL_PLUGIN_NAME = '@netlify/plugin-functions-install-core'
9
- const CORE_PLUGINS = new Set([FUNCTIONS_INSTALL_PLUGIN_NAME, LOCAL_INSTALL_PLUGIN_NAME])
10
-
5
+ const FUNCTIONS_INSTALL_PLUGIN_NAME = '@netlify/plugin-functions-install-core';
6
+ const CORE_PLUGINS = new Set([FUNCTIONS_INSTALL_PLUGIN_NAME, LOCAL_INSTALL_PLUGIN_NAME]);
11
7
  // Plugins that are installed and enabled by default
12
8
  export const listCorePlugins = function ({ FUNCTIONS_SRC }) {
13
- const functionsInstallPlugin = getFunctionsInstallPlugin(FUNCTIONS_SRC)
14
- return [functionsInstallPlugin].filter(Boolean)
15
- }
16
-
9
+ const functionsInstallPlugin = getFunctionsInstallPlugin(FUNCTIONS_SRC);
10
+ return [functionsInstallPlugin].filter(Boolean);
11
+ };
17
12
  const getFunctionsInstallPlugin = function (FUNCTIONS_SRC) {
18
- if (FUNCTIONS_SRC === undefined) {
19
- return
20
- }
21
-
22
- return { package: FUNCTIONS_INSTALL_PLUGIN_NAME, pluginPath: FUNCTIONS_INSTALL_PLUGIN, optional: true }
23
- }
24
-
13
+ if (FUNCTIONS_SRC === undefined) {
14
+ return;
15
+ }
16
+ return { package: FUNCTIONS_INSTALL_PLUGIN_NAME, pluginPath: FUNCTIONS_INSTALL_PLUGIN, optional: true };
17
+ };
25
18
  export const isCorePlugin = function (packageName) {
26
- return CORE_PLUGINS.has(packageName)
27
- }
19
+ return CORE_PLUGINS.has(packageName);
20
+ };
package/lib/status/add.js CHANGED
@@ -1,36 +1,30 @@
1
1
  // Merge plugin status to the list of plugin statuses.
2
2
  export const addStatus = function ({ newStatus, statuses, event, packageName, pluginPackageJson: { version } = {} }) {
3
- // Either:
4
- // - `build.command`
5
- // - no status was set
6
- if (newStatus === undefined) {
7
- return statuses
8
- }
9
-
10
- const formerStatus = statuses.find((status) => status.packageName === packageName)
11
- if (!canOverrideStatus(formerStatus, newStatus)) {
12
- return statuses
13
- }
14
-
15
- // Overrides plugin's previous status and add more information
16
- const newStatuses = statuses.filter((status) => status !== formerStatus)
17
- return [...newStatuses, { ...newStatus, event, packageName, version }]
18
- }
19
-
3
+ // Either:
4
+ // - `build.command`
5
+ // - no status was set
6
+ if (newStatus === undefined) {
7
+ return statuses;
8
+ }
9
+ const formerStatus = statuses.find((status) => status.packageName === packageName);
10
+ if (!canOverrideStatus(formerStatus, newStatus)) {
11
+ return statuses;
12
+ }
13
+ // Overrides plugin's previous status and add more information
14
+ const newStatuses = statuses.filter((status) => status !== formerStatus);
15
+ return [...newStatuses, { ...newStatus, event, packageName, version }];
16
+ };
20
17
  const canOverrideStatus = function (formerStatus, newStatus) {
21
- // No previous status
22
- if (formerStatus === undefined) {
23
- return true
24
- }
25
-
26
- // Implicit statuses can never override
27
- if (newStatus.implicit) {
28
- return false
29
- }
30
-
31
- // Error statuses can only be overwritten by more severe error statuses
32
- return STATES.indexOf(formerStatus.state) <= STATES.indexOf(newStatus.state)
33
- }
34
-
18
+ // No previous status
19
+ if (formerStatus === undefined) {
20
+ return true;
21
+ }
22
+ // Implicit statuses can never override
23
+ if (newStatus.implicit) {
24
+ return false;
25
+ }
26
+ // Error statuses can only be overwritten by more severe error statuses
27
+ return STATES.indexOf(formerStatus.state) <= STATES.indexOf(newStatus.state);
28
+ };
35
29
  // Possible status states, ordered by severity.
36
- const STATES = ['success', 'canceled_plugin', 'failed_plugin', 'failed_build']
30
+ const STATES = ['success', 'canceled_plugin', 'failed_plugin', 'failed_build'];
@@ -1,23 +1,18 @@
1
- import stripAnsi from 'strip-ansi'
2
-
1
+ import stripAnsi from 'strip-ansi';
3
2
  // Remove colors from statuses
4
3
  export const removeStatusesColors = function (statuses) {
5
- return statuses.map(removeStatusColors)
6
- }
7
-
4
+ return statuses.map(removeStatusColors);
5
+ };
8
6
  const removeStatusColors = function (status) {
9
- const attributes = COLOR_ATTRIBUTES.map((attribute) => removeAttrColor(status, attribute))
10
- return Object.assign({}, status, ...attributes)
11
- }
12
-
13
- const COLOR_ATTRIBUTES = ['title', 'summary', 'text']
14
-
7
+ const attributes = COLOR_ATTRIBUTES.map((attribute) => removeAttrColor(status, attribute));
8
+ return Object.assign({}, status, ...attributes);
9
+ };
10
+ const COLOR_ATTRIBUTES = ['title', 'summary', 'text'];
15
11
  const removeAttrColor = function (status, attribute) {
16
- const value = status[attribute]
17
- if (value === undefined) {
18
- return {}
19
- }
20
-
21
- const valueA = stripAnsi(value)
22
- return { [attribute]: valueA }
23
- }
12
+ const value = status[attribute];
13
+ if (value === undefined) {
14
+ return {};
15
+ }
16
+ const valueA = stripAnsi(value);
17
+ return { [attribute]: valueA };
18
+ };
@@ -1,11 +1,10 @@
1
- import { addErrorInfo } from '../error/info.js'
2
- import { getFullErrorInfo } from '../error/parse/parse.js'
3
- import { serializeErrorStatus } from '../error/parse/serialize_status.js'
4
-
1
+ import { addErrorInfo } from '../error/info.js';
2
+ import { getFullErrorInfo } from '../error/parse/parse.js';
3
+ import { serializeErrorStatus } from '../error/parse/serialize_status.js';
5
4
  // Errors that happen during plugin loads should be reported as error statuses
6
5
  export const addPluginLoadErrorStatus = function ({ error, packageName, version, debug }) {
7
- const fullErrorInfo = getFullErrorInfo({ error, colors: false, debug })
8
- const errorStatus = serializeErrorStatus({ fullErrorInfo, state: 'failed_build' })
9
- const statuses = [{ ...errorStatus, event: 'load', packageName, version }]
10
- addErrorInfo(error, { statuses })
11
- }
6
+ const fullErrorInfo = getFullErrorInfo({ error, colors: false, debug });
7
+ const errorStatus = serializeErrorStatus({ fullErrorInfo, state: 'failed_build' });
8
+ const statuses = [{ ...errorStatus, event: 'load', packageName, version }];
9
+ addErrorInfo(error, { statuses });
10
+ };