@netlify/build 27.20.4 → 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 +13 -6
@@ -1,16 +1,13 @@
1
- import { resolveConfig, updateConfig, restoreConfig } from '@netlify/config'
2
- import mapObj from 'map-obj'
3
-
4
- import { getChildEnv } from '../env/main.js'
5
- import { addApiErrorHandlers } from '../error/api.js'
6
- import { changeErrorType } from '../error/info.js'
7
- import { logBuildDir, logConfigPath, logConfig, logContext } from '../log/messages/config.js'
8
- import { logConfigOnUpload, logHeadersOnUpload, logRedirectsOnUpload } from '../log/messages/mutations.js'
9
- import { measureDuration } from '../time/main.js'
10
- import { getPackageJson } from '../utils/package.js'
11
-
12
- import { getUserNodeVersion } from './user_node_version.js'
13
-
1
+ import { resolveConfig, updateConfig, restoreConfig } from '@netlify/config';
2
+ import mapObj from 'map-obj';
3
+ import { getChildEnv } from '../env/main.js';
4
+ import { addApiErrorHandlers } from '../error/api.js';
5
+ import { changeErrorType } from '../error/info.js';
6
+ import { logBuildDir, logConfigPath, logConfig, logContext } from '../log/messages/config.js';
7
+ import { logConfigOnUpload, logHeadersOnUpload, logRedirectsOnUpload } from '../log/messages/mutations.js';
8
+ import { measureDuration } from '../time/main.js';
9
+ import { getPackageJson } from '../utils/package.js';
10
+ import { getUserNodeVersion } from './user_node_version.js';
14
11
  // Retrieve immutable options passed to `@netlify/config`.
15
12
  // This does not include options which might change during the course of the
16
13
  // build:
@@ -18,102 +15,65 @@ import { getUserNodeVersion } from './user_node_version.js'
18
15
  // the build
19
16
  // - If plugins change the configuration, `configMutations` is used instead
20
17
  // In both cases, almost all options should remain the same.
21
- export const getConfigOpts = function ({
22
- config,
23
- defaultConfig,
24
- cwd,
25
- repositoryRoot,
26
- apiHost,
27
- token,
28
- siteId,
29
- context,
30
- branch,
31
- baseRelDir,
32
- envOpt,
33
- mode,
34
- offline,
35
- deployId,
36
- buildId,
37
- testOpts,
38
- featureFlags,
39
- }) {
40
- return {
41
- config,
42
- defaultConfig,
43
- cwd,
44
- repositoryRoot,
45
- context,
46
- branch,
47
- baseRelDir,
48
- host: apiHost,
49
- token,
50
- siteId,
51
- deployId,
52
- buildId,
53
- mode,
54
- offline,
55
- env: envOpt,
56
- testOpts,
57
- featureFlags,
58
- }
59
- }
60
-
18
+ export const getConfigOpts = function ({ config, defaultConfig, cwd, repositoryRoot, apiHost, token, siteId, context, branch, baseRelDir, envOpt, mode, offline, deployId, buildId, testOpts, featureFlags, }) {
19
+ return {
20
+ config,
21
+ defaultConfig,
22
+ cwd,
23
+ repositoryRoot,
24
+ context,
25
+ branch,
26
+ baseRelDir,
27
+ host: apiHost,
28
+ token,
29
+ siteId,
30
+ deployId,
31
+ buildId,
32
+ mode,
33
+ offline,
34
+ env: envOpt,
35
+ testOpts,
36
+ featureFlags,
37
+ };
38
+ };
61
39
  // Retrieve configuration object
62
40
  const tLoadConfig = async function ({ configOpts, cachedConfig, cachedConfigPath, envOpt, debug, logs, nodePath }) {
63
- const {
64
- configPath,
65
- headersPath,
66
- redirectsPath,
67
- buildDir,
68
- repositoryRoot,
69
- config: netlifyConfig,
70
- context: contextA,
71
- branch: branchA,
72
- token: tokenA,
73
- api,
74
- siteInfo,
75
- env,
76
- } = await resolveInitialConfig(configOpts, cachedConfig, cachedConfigPath)
77
- logConfigInfo({ logs, configPath, buildDir, netlifyConfig, context: contextA, debug })
78
-
79
- const apiA = addApiErrorHandlers(api)
80
- const envValues = mapObj(env, (key, { value }) => [key, value])
81
- const childEnv = getChildEnv({ envOpt, env: envValues })
82
- const [{ packageJson }, userNodeVersion] = await Promise.all([getPackageJson(buildDir), getUserNodeVersion(nodePath)])
83
- return {
84
- netlifyConfig,
85
- configPath,
86
- headersPath,
87
- redirectsPath,
88
- buildDir,
89
- repositoryRoot,
90
- packageJson,
91
- userNodeVersion,
92
- childEnv,
93
- context: contextA,
94
- branch: branchA,
95
- token: tokenA,
96
- api: apiA,
97
- siteInfo,
98
- }
99
- }
100
-
101
- export const loadConfig = measureDuration(tLoadConfig, 'resolve_config')
102
-
41
+ const { configPath, headersPath, redirectsPath, buildDir, repositoryRoot, config: netlifyConfig, context: contextA, branch: branchA, token: tokenA, api, siteInfo, env, } = await resolveInitialConfig(configOpts, cachedConfig, cachedConfigPath);
42
+ logConfigInfo({ logs, configPath, buildDir, netlifyConfig, context: contextA, debug });
43
+ const apiA = addApiErrorHandlers(api);
44
+ const envValues = mapObj(env, (key, { value }) => [key, value]);
45
+ const childEnv = getChildEnv({ envOpt, env: envValues });
46
+ const [{ packageJson }, userNodeVersion] = await Promise.all([getPackageJson(buildDir), getUserNodeVersion(nodePath)]);
47
+ return {
48
+ netlifyConfig,
49
+ configPath,
50
+ headersPath,
51
+ redirectsPath,
52
+ buildDir,
53
+ repositoryRoot,
54
+ packageJson,
55
+ userNodeVersion,
56
+ childEnv,
57
+ context: contextA,
58
+ branch: branchA,
59
+ token: tokenA,
60
+ api: apiA,
61
+ siteInfo,
62
+ };
63
+ };
64
+ export const loadConfig = measureDuration(tLoadConfig, 'resolve_config');
103
65
  // Retrieve initial configuration.
104
66
  // In the buildbot and CLI, we re-use the already parsed `@netlify/config`
105
67
  // return value which is passed as `cachedConfig`/`cachedConfigPath`.
106
68
  const resolveInitialConfig = async function (configOpts, cachedConfig, cachedConfigPath) {
107
- return await resolveConfig({ ...configOpts, cachedConfig, cachedConfigPath })
108
- }
109
-
69
+ return await resolveConfig({ ...configOpts, cachedConfig, cachedConfigPath });
70
+ };
110
71
  const logConfigInfo = function ({ logs, configPath, buildDir, netlifyConfig, context, debug }) {
111
- logBuildDir(logs, buildDir)
112
- logConfigPath(logs, configPath)
113
- logConfig({ logs, netlifyConfig, debug })
114
- logContext(logs, context)
115
- }
116
-
72
+ logBuildDir(logs, buildDir);
73
+ logConfigPath(logs, configPath);
74
+ logConfig({ logs, netlifyConfig, debug });
75
+ logContext(logs, context);
76
+ };
117
77
  // Retrieve the configuration after it's been changed.
118
78
  // This ensures any configuration changes done by plugins is validated and
119
79
  // normalized.
@@ -122,65 +82,40 @@ const logConfigInfo = function ({ logs, configPath, buildDir, netlifyConfig, con
122
82
  // Errors are propagated and assigned to the specific plugin or core step
123
83
  // which changed the configuration.
124
84
  export const resolveUpdatedConfig = async function (configOpts, configMutations) {
125
- try {
126
- return await resolveConfig({ ...configOpts, configMutations, debug: false })
127
- } catch (error) {
128
- changeErrorType(error, 'resolveConfig', 'pluginValidation')
129
- throw error
130
- }
131
- }
132
-
85
+ try {
86
+ return await resolveConfig({ ...configOpts, configMutations, debug: false });
87
+ }
88
+ catch (error) {
89
+ changeErrorType(error, 'resolveConfig', 'pluginValidation');
90
+ throw error;
91
+ }
92
+ };
133
93
  // If the configuration was changed, persist it to `netlify.toml`.
134
94
  // If `netlify.toml` does not exist, create it inside repository root.
135
95
  // This is only done when `saveConfig` is `true`. This allows performing this
136
96
  // in the buildbot but not in local builds, since only the latter run in a
137
97
  // container and we want to avoid saving files on local machines.
138
- export const saveUpdatedConfig = async function ({
139
- configMutations,
140
- buildDir,
141
- repositoryRoot,
142
- configPath = `${repositoryRoot}/netlify.toml`,
143
- headersPath,
144
- redirectsPath,
145
- logs,
146
- featureFlags,
147
- context,
148
- branch,
149
- debug,
150
- saveConfig,
151
- }) {
152
- if (!saveConfig) {
153
- return
154
- }
155
-
156
- await updateConfig(configMutations, {
157
- buildDir,
158
- configPath,
159
- headersPath,
160
- redirectsPath,
161
- context,
162
- branch,
163
- logs,
164
- featureFlags,
165
- })
166
-
167
- await logConfigOnUpload({ logs, configPath, debug })
168
- await logHeadersOnUpload({ logs, headersPath, debug })
169
- await logRedirectsOnUpload({ logs, redirectsPath, debug })
170
- }
171
-
172
- export const restoreUpdatedConfig = async function ({
173
- configMutations,
174
- buildDir,
175
- repositoryRoot,
176
- configPath = `${repositoryRoot}/netlify.toml`,
177
- headersPath,
178
- redirectsPath,
179
- saveConfig,
180
- }) {
181
- if (!saveConfig) {
182
- return
183
- }
184
-
185
- await restoreConfig(configMutations, { buildDir, configPath, headersPath, redirectsPath })
186
- }
98
+ export const saveUpdatedConfig = async function ({ configMutations, buildDir, repositoryRoot, configPath = `${repositoryRoot}/netlify.toml`, headersPath, redirectsPath, logs, featureFlags, context, branch, debug, saveConfig, }) {
99
+ if (!saveConfig) {
100
+ return;
101
+ }
102
+ await updateConfig(configMutations, {
103
+ buildDir,
104
+ configPath,
105
+ headersPath,
106
+ redirectsPath,
107
+ context,
108
+ branch,
109
+ logs,
110
+ featureFlags,
111
+ });
112
+ await logConfigOnUpload({ logs, configPath, debug });
113
+ await logHeadersOnUpload({ logs, headersPath, debug });
114
+ await logRedirectsOnUpload({ logs, redirectsPath, debug });
115
+ };
116
+ export const restoreUpdatedConfig = async function ({ configMutations, buildDir, repositoryRoot, configPath = `${repositoryRoot}/netlify.toml`, headersPath, redirectsPath, saveConfig, }) {
117
+ if (!saveConfig) {
118
+ return;
119
+ }
120
+ await restoreConfig(configMutations, { buildDir, configPath, headersPath, redirectsPath });
121
+ };
@@ -1,156 +1,116 @@
1
- import { relative, normalize } from 'path'
2
-
3
- import { getCacheDir } from '@netlify/cache-utils'
4
- import mapObj from 'map-obj'
5
- import { pathExists } from 'path-exists'
6
-
7
- import { ROOT_PACKAGE_JSON } from '../utils/json.js'
8
-
1
+ import { relative, normalize } from 'path';
2
+ import { getCacheDir } from '@netlify/cache-utils';
3
+ import mapObj from 'map-obj';
4
+ import { pathExists } from 'path-exists';
5
+ import { ROOT_PACKAGE_JSON } from '../utils/json.js';
9
6
  // Retrieve constants passed to plugins
10
- export const getConstants = async function ({
11
- configPath,
12
- buildDir,
13
- functionsDistDir,
14
- edgeFunctionsDistDir,
15
- cacheDir,
16
- netlifyConfig,
17
- siteInfo: { id: siteId },
18
- apiHost,
19
- token,
20
- mode,
21
- }) {
22
- const isLocal = mode !== 'buildbot'
23
- const normalizedCacheDir = getCacheDir({ cacheDir, cwd: buildDir })
24
-
25
- const constants = {
26
- // Path to the Netlify configuration file
27
- CONFIG_PATH: configPath,
28
- // The directory where built serverless functions are placed before deployment
29
- FUNCTIONS_DIST: functionsDistDir,
30
- // The directory where built Edge Functions are placed before deployment
31
- EDGE_FUNCTIONS_DIST: edgeFunctionsDistDir,
32
- // Path to the Netlify build cache folder
33
- CACHE_DIR: normalizedCacheDir,
34
- // Boolean indicating whether the build was run locally (Netlify CLI) or in the production CI
35
- IS_LOCAL: isLocal,
36
- // The version of Netlify Build
37
- NETLIFY_BUILD_VERSION: ROOT_PACKAGE_JSON.version,
38
- // The Netlify Site ID
39
- SITE_ID: siteId,
40
- // The Netlify API access token
41
- NETLIFY_API_TOKEN: token,
42
- // The Netlify API host
43
- NETLIFY_API_HOST: apiHost,
44
- // The directory where internal functions (i.e. generated programmatically
45
- // via plugins or others) live
46
- INTERNAL_FUNCTIONS_SRC: `${buildDir}/${INTERNAL_FUNCTIONS_SRC}`,
47
- // The directory where internal Edge Functions (i.e. generated programmatically
48
- // via plugins or others) live
49
- INTERNAL_EDGE_FUNCTIONS_SRC: `${buildDir}/${INTERNAL_EDGE_FUNCTIONS_SRC}`,
50
- }
51
- const constantsA = await addMutableConstants({ constants, buildDir, netlifyConfig })
52
- return constantsA
53
- }
54
-
55
- const INTERNAL_EDGE_FUNCTIONS_SRC = '.netlify/edge-functions'
56
- const INTERNAL_FUNCTIONS_SRC = '.netlify/functions-internal'
57
-
7
+ export const getConstants = async function ({ configPath, buildDir, functionsDistDir, edgeFunctionsDistDir, cacheDir, netlifyConfig, siteInfo: { id: siteId }, apiHost, token, mode, }) {
8
+ const isLocal = mode !== 'buildbot';
9
+ const normalizedCacheDir = getCacheDir({ cacheDir, cwd: buildDir });
10
+ const constants = {
11
+ // Path to the Netlify configuration file
12
+ CONFIG_PATH: configPath,
13
+ // The directory where built serverless functions are placed before deployment
14
+ FUNCTIONS_DIST: functionsDistDir,
15
+ // The directory where built Edge Functions are placed before deployment
16
+ EDGE_FUNCTIONS_DIST: edgeFunctionsDistDir,
17
+ // Path to the Netlify build cache folder
18
+ CACHE_DIR: normalizedCacheDir,
19
+ // Boolean indicating whether the build was run locally (Netlify CLI) or in the production CI
20
+ IS_LOCAL: isLocal,
21
+ // The version of Netlify Build
22
+ NETLIFY_BUILD_VERSION: ROOT_PACKAGE_JSON.version,
23
+ // The Netlify Site ID
24
+ SITE_ID: siteId,
25
+ // The Netlify API access token
26
+ NETLIFY_API_TOKEN: token,
27
+ // The Netlify API host
28
+ NETLIFY_API_HOST: apiHost,
29
+ // The directory where internal functions (i.e. generated programmatically
30
+ // via plugins or others) live
31
+ INTERNAL_FUNCTIONS_SRC: `${buildDir}/${INTERNAL_FUNCTIONS_SRC}`,
32
+ // The directory where internal Edge Functions (i.e. generated programmatically
33
+ // via plugins or others) live
34
+ INTERNAL_EDGE_FUNCTIONS_SRC: `${buildDir}/${INTERNAL_EDGE_FUNCTIONS_SRC}`,
35
+ };
36
+ const constantsA = await addMutableConstants({ constants, buildDir, netlifyConfig });
37
+ return constantsA;
38
+ };
39
+ const INTERNAL_EDGE_FUNCTIONS_SRC = '.netlify/edge-functions';
40
+ const INTERNAL_FUNCTIONS_SRC = '.netlify/functions-internal';
58
41
  // Retrieve constants which might change during the build if a plugin modifies
59
42
  // `netlifyConfig` or creates some default directories.
60
43
  // Unlike readonly constants, this is called again before each build step.
61
- export const addMutableConstants = async function ({
62
- constants,
63
- buildDir,
64
- netlifyConfig: {
65
- build: { publish, edge_functions: edgeFunctions },
66
- functionsDirectory,
67
- },
68
- }) {
69
- const constantsA = {
70
- ...constants,
71
- // Directory that contains the deploy-ready HTML files and assets generated by the build
72
- PUBLISH_DIR: publish,
73
- // The directory where function source code lives
74
- FUNCTIONS_SRC: functionsDirectory,
75
- // The directory where Edge Functions source code lives
76
- EDGE_FUNCTIONS_SRC: edgeFunctions,
77
- }
78
- const constantsB = await addDefaultConstants(constantsA, buildDir)
79
- const constantsC = normalizeConstantsPaths(constantsB, buildDir)
80
- return constantsC
81
- }
82
-
44
+ export const addMutableConstants = async function ({ constants, buildDir, netlifyConfig: { build: { publish, edge_functions: edgeFunctions }, functionsDirectory, }, }) {
45
+ const constantsA = {
46
+ ...constants,
47
+ // Directory that contains the deploy-ready HTML files and assets generated by the build
48
+ PUBLISH_DIR: publish,
49
+ // The directory where function source code lives
50
+ FUNCTIONS_SRC: functionsDirectory,
51
+ // The directory where Edge Functions source code lives
52
+ EDGE_FUNCTIONS_SRC: edgeFunctions,
53
+ };
54
+ const constantsB = await addDefaultConstants(constantsA, buildDir);
55
+ const constantsC = normalizeConstantsPaths(constantsB, buildDir);
56
+ return constantsC;
57
+ };
83
58
  // Some `constants` have a default value when a specific file exists.
84
59
  // Those default values are assigned by `@netlify/config`. However, the build
85
60
  // command or plugins might create those specific files, in which case, the
86
61
  // related `constant` should be updated, unless the user has explicitly
87
62
  // configured it.
88
63
  const addDefaultConstants = async function (constants, buildDir) {
89
- const newConstants = await Promise.all(
90
- DEFAULT_PATHS.map(({ constantName, defaultPath }) =>
91
- addDefaultConstant({ constants, constantName, defaultPath, buildDir }),
92
- ),
93
- )
94
- return Object.assign({}, constants, ...newConstants)
95
- }
96
-
64
+ const newConstants = await Promise.all(DEFAULT_PATHS.map(({ constantName, defaultPath }) => addDefaultConstant({ constants, constantName, defaultPath, buildDir })));
65
+ return Object.assign({}, constants, ...newConstants);
66
+ };
97
67
  // The current directory is the build directory, which is correct, so we don't
98
68
  // need to resolve paths
99
69
  const DEFAULT_PATHS = [
100
- // @todo Remove once we drop support for the legacy default functions directory.
101
- { constantName: 'FUNCTIONS_SRC', defaultPath: 'netlify-automatic-functions' },
102
- { constantName: 'FUNCTIONS_SRC', defaultPath: 'netlify/functions' },
103
- { constantName: 'EDGE_FUNCTIONS_SRC', defaultPath: 'netlify/edge-functions' },
104
- ]
105
-
70
+ // @todo Remove once we drop support for the legacy default functions directory.
71
+ { constantName: 'FUNCTIONS_SRC', defaultPath: 'netlify-automatic-functions' },
72
+ { constantName: 'FUNCTIONS_SRC', defaultPath: 'netlify/functions' },
73
+ { constantName: 'EDGE_FUNCTIONS_SRC', defaultPath: 'netlify/edge-functions' },
74
+ ];
106
75
  const addDefaultConstant = async function ({ constants, constantName, defaultPath, buildDir }) {
107
- // Configuration paths are relative to the build directory.
108
- if (!isEmptyValue(constants[constantName]) || !(await pathExists(`${buildDir}/${defaultPath}`))) {
109
- return {}
110
- }
111
-
112
- // However, the plugin child process' current directory is the build directory,
113
- // so we can pass the relative path instead of the resolved absolute path.
114
- return { [constantName]: defaultPath }
115
- }
116
-
76
+ // Configuration paths are relative to the build directory.
77
+ if (!isEmptyValue(constants[constantName]) || !(await pathExists(`${buildDir}/${defaultPath}`))) {
78
+ return {};
79
+ }
80
+ // However, the plugin child process' current directory is the build directory,
81
+ // so we can pass the relative path instead of the resolved absolute path.
82
+ return { [constantName]: defaultPath };
83
+ };
117
84
  const normalizeConstantsPaths = function (constants, buildDir) {
118
- return mapObj(constants, (key, path) => [key, normalizePath(path, buildDir, key)])
119
- }
120
-
85
+ return mapObj(constants, (key, path) => [key, normalizePath(path, buildDir, key)]);
86
+ };
121
87
  // The current directory is `buildDir`. Most constants are inside this `buildDir`.
122
88
  // Instead of passing absolute paths, we pass paths relative to `buildDir`, so
123
89
  // that logs are less verbose.
124
90
  const normalizePath = function (path, buildDir, key) {
125
- if (isEmptyValue(path) || !CONSTANT_PATHS.has(key)) {
126
- return path
127
- }
128
-
129
- const pathA = normalize(path)
130
-
131
- if (pathA === buildDir) {
132
- return '.'
133
- }
134
-
135
- if (pathA.startsWith(buildDir)) {
136
- return relative(buildDir, pathA)
137
- }
138
-
139
- return pathA
140
- }
141
-
91
+ if (isEmptyValue(path) || !CONSTANT_PATHS.has(key)) {
92
+ return path;
93
+ }
94
+ const pathA = normalize(path);
95
+ if (pathA === buildDir) {
96
+ return '.';
97
+ }
98
+ if (pathA.startsWith(buildDir)) {
99
+ return relative(buildDir, pathA);
100
+ }
101
+ return pathA;
102
+ };
142
103
  const isEmptyValue = function (path) {
143
- return path === undefined || path === ''
144
- }
145
-
104
+ return path === undefined || path === '';
105
+ };
146
106
  const CONSTANT_PATHS = new Set([
147
- 'CONFIG_PATH',
148
- 'PUBLISH_DIR',
149
- 'FUNCTIONS_SRC',
150
- 'FUNCTIONS_DIST',
151
- 'INTERNAL_EDGE_FUNCTIONS_SRC',
152
- 'INTERNAL_FUNCTIONS_SRC',
153
- 'EDGE_FUNCTIONS_DIST',
154
- 'EDGE_FUNCTIONS_SRC',
155
- 'CACHE_DIR',
156
- ])
107
+ 'CONFIG_PATH',
108
+ 'PUBLISH_DIR',
109
+ 'FUNCTIONS_SRC',
110
+ 'FUNCTIONS_DIST',
111
+ 'INTERNAL_EDGE_FUNCTIONS_SRC',
112
+ 'INTERNAL_FUNCTIONS_SRC',
113
+ 'EDGE_FUNCTIONS_DIST',
114
+ 'EDGE_FUNCTIONS_SRC',
115
+ 'CACHE_DIR',
116
+ ]);
package/lib/core/dev.js CHANGED
@@ -1,31 +1,27 @@
1
- import { handleBuildError } from '../error/handle.js'
2
-
3
- import { execBuild, startBuild } from './build.js'
4
- import { getSeverity } from './severity.js'
5
-
1
+ import { handleBuildError } from '../error/handle.js';
2
+ import { execBuild, startBuild } from './build.js';
3
+ import { getSeverity } from './severity.js';
6
4
  export const startDev = async (devCommand, flags = {}) => {
7
- const { errorMonitor, mode, logs, debug, testOpts, ...normalizedFlags } = startBuild(flags)
8
- const errorParams = { errorMonitor, mode, logs, debug, testOpts }
9
-
10
- try {
11
- const { netlifyConfig: netlifyConfigA, configMutations } = await execBuild({
12
- ...normalizedFlags,
13
- errorMonitor,
14
- errorParams,
15
- mode,
16
- logs,
17
- debug,
18
- testOpts,
19
- timeline: 'dev',
20
- devCommand,
21
- })
22
- const { success, severityCode } = getSeverity('success')
23
-
24
- return { success, severityCode, netlifyConfig: netlifyConfigA, logs, configMutations }
25
- } catch (error) {
26
- const { severity, message, stack } = await handleBuildError(error, errorParams)
27
- const { success, severityCode } = getSeverity(severity)
28
-
29
- return { success, severityCode, logs, error: { message, stack } }
30
- }
31
- }
5
+ const { errorMonitor, mode, logs, debug, testOpts, ...normalizedFlags } = startBuild(flags);
6
+ const errorParams = { errorMonitor, mode, logs, debug, testOpts };
7
+ try {
8
+ const { netlifyConfig: netlifyConfigA, configMutations } = await execBuild({
9
+ ...normalizedFlags,
10
+ errorMonitor,
11
+ errorParams,
12
+ mode,
13
+ logs,
14
+ debug,
15
+ testOpts,
16
+ timeline: 'dev',
17
+ devCommand,
18
+ });
19
+ const { success, severityCode } = getSeverity('success');
20
+ return { success, severityCode, netlifyConfig: netlifyConfigA, logs, configMutations };
21
+ }
22
+ catch (error) {
23
+ const { severity, message, stack } = await handleBuildError(error, errorParams);
24
+ const { success, severityCode } = getSeverity(severity);
25
+ return { success, severityCode, logs, error: { message, stack } };
26
+ }
27
+ };
package/lib/core/dry.js CHANGED
@@ -1,39 +1,21 @@
1
- import pFilter from 'p-filter'
2
-
3
- import { logDryRunStart, logDryRunStep, logDryRunEnd } from '../log/messages/dry.js'
4
- import { runsOnlyOnBuildFailure } from '../plugins/events.js'
5
-
1
+ import pFilter from 'p-filter';
2
+ import { logDryRunStart, logDryRunStep, logDryRunEnd } from '../log/messages/dry.js';
3
+ import { runsOnlyOnBuildFailure } from '../plugins/events.js';
6
4
  // If the `dry` flag is specified, do a dry run
7
5
  export const doDryRun = async function ({ buildDir, steps, netlifyConfig, constants, buildbotServerSocket, logs }) {
8
- const successSteps = await pFilter(steps, ({ event, condition }) =>
9
- shouldIncludeStep({ buildDir, event, condition, netlifyConfig, constants, buildbotServerSocket }),
10
- )
11
- const eventWidth = Math.max(...successSteps.map(getEventLength))
12
- const stepsCount = successSteps.length
13
-
14
- logDryRunStart({ logs, eventWidth, stepsCount })
15
-
16
- successSteps.forEach((step, index) => {
17
- logDryRunStep({ logs, step, index, netlifyConfig, eventWidth, stepsCount })
18
- })
19
-
20
- logDryRunEnd(logs)
21
- }
22
-
23
- const shouldIncludeStep = async function ({
24
- buildDir,
25
- event,
26
- condition,
27
- netlifyConfig,
28
- constants,
29
- buildbotServerSocket,
30
- }) {
31
- return (
32
- !runsOnlyOnBuildFailure(event) &&
33
- (condition === undefined || (await condition({ buildDir, constants, netlifyConfig, buildbotServerSocket })))
34
- )
35
- }
36
-
6
+ const successSteps = await pFilter(steps, ({ event, condition }) => shouldIncludeStep({ buildDir, event, condition, netlifyConfig, constants, buildbotServerSocket }));
7
+ const eventWidth = Math.max(...successSteps.map(getEventLength));
8
+ const stepsCount = successSteps.length;
9
+ logDryRunStart({ logs, eventWidth, stepsCount });
10
+ successSteps.forEach((step, index) => {
11
+ logDryRunStep({ logs, step, index, netlifyConfig, eventWidth, stepsCount });
12
+ });
13
+ logDryRunEnd(logs);
14
+ };
15
+ const shouldIncludeStep = async function ({ buildDir, event, condition, netlifyConfig, constants, buildbotServerSocket, }) {
16
+ return (!runsOnlyOnBuildFailure(event) &&
17
+ (condition === undefined || (await condition({ buildDir, constants, netlifyConfig, buildbotServerSocket }))));
18
+ };
37
19
  const getEventLength = function ({ event }) {
38
- return event.length
39
- }
20
+ return event.length;
21
+ };