@netlify/build 28.0.0-beta → 28.0.0

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 (258) 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 +121 -0
  5. package/lib/core/constants.js +116 -0
  6. package/lib/core/dev.js +27 -0
  7. package/lib/core/dry.js +21 -0
  8. package/lib/core/feature_flags.js +19 -0
  9. package/lib/core/flags.js +201 -0
  10. package/lib/core/lingering.js +68 -0
  11. package/lib/core/main.js +123 -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 +20 -0
  15. package/lib/core/user_node_version.js +32 -0
  16. package/lib/env/changes.js +43 -0
  17. package/lib/env/main.js +14 -0
  18. package/lib/env/metadata.js +68 -0
  19. package/lib/error/api.js +37 -0
  20. package/lib/error/build.js +36 -0
  21. package/{src → lib}/error/cancel.js +5 -6
  22. package/lib/error/colors.js +9 -0
  23. package/lib/error/handle.js +46 -0
  24. package/lib/error/info.js +37 -0
  25. package/lib/error/monitor/location.js +16 -0
  26. package/lib/error/monitor/normalize.js +86 -0
  27. package/lib/error/monitor/print.js +20 -0
  28. package/lib/error/monitor/report.js +120 -0
  29. package/lib/error/monitor/start.js +58 -0
  30. package/lib/error/parse/clean_stack.js +70 -0
  31. package/lib/error/parse/location.js +50 -0
  32. package/lib/error/parse/normalize.js +24 -0
  33. package/lib/error/parse/parse.js +67 -0
  34. package/lib/error/parse/plugin.js +55 -0
  35. package/lib/error/parse/properties.js +16 -0
  36. package/lib/error/parse/serialize_log.js +34 -0
  37. package/lib/error/parse/serialize_status.js +18 -0
  38. package/lib/error/parse/stack.js +34 -0
  39. package/lib/error/type.js +171 -0
  40. package/lib/install/functions.js +20 -0
  41. package/lib/install/local.js +45 -0
  42. package/lib/install/main.js +67 -0
  43. package/lib/install/missing.js +54 -0
  44. package/{src → lib}/log/colors.js +15 -22
  45. package/lib/log/description.js +21 -0
  46. package/lib/log/header.js +14 -0
  47. package/lib/log/header_func.js +13 -0
  48. package/lib/log/logger.js +130 -0
  49. package/lib/log/messages/compatibility.js +120 -0
  50. package/lib/log/messages/config.js +91 -0
  51. package/lib/log/messages/core.js +50 -0
  52. package/lib/log/messages/core_steps.js +75 -0
  53. package/lib/log/messages/dry.js +41 -0
  54. package/lib/log/messages/install.js +25 -0
  55. package/lib/log/messages/ipc.js +29 -0
  56. package/lib/log/messages/mutations.js +62 -0
  57. package/{src → lib}/log/messages/plugins.js +18 -32
  58. package/lib/log/messages/status.js +14 -0
  59. package/lib/log/messages/steps.js +18 -0
  60. package/lib/log/old_version.js +32 -0
  61. package/lib/log/serialize.js +10 -0
  62. package/lib/log/stream.js +68 -0
  63. package/lib/log/theme.js +25 -0
  64. package/lib/plugins/child/diff.js +46 -0
  65. package/lib/plugins/child/error.js +26 -0
  66. package/lib/plugins/child/lazy.js +15 -0
  67. package/lib/plugins/child/load.js +22 -0
  68. package/lib/plugins/child/logic.js +57 -0
  69. package/lib/plugins/child/main.js +37 -0
  70. package/lib/plugins/child/run.js +19 -0
  71. package/lib/plugins/child/status.js +63 -0
  72. package/lib/plugins/child/typescript.js +28 -0
  73. package/lib/plugins/child/utils.js +42 -0
  74. package/lib/plugins/child/validate.js +31 -0
  75. package/lib/plugins/compatibility.js +104 -0
  76. package/{src → lib}/plugins/error.js +31 -35
  77. package/{src → lib}/plugins/events.js +7 -12
  78. package/lib/plugins/expected_version.js +81 -0
  79. package/lib/plugins/ipc.js +120 -0
  80. package/lib/plugins/list.js +73 -0
  81. package/lib/plugins/load.js +50 -0
  82. package/lib/plugins/manifest/check.js +85 -0
  83. package/lib/plugins/manifest/load.js +38 -0
  84. package/lib/plugins/manifest/main.js +17 -0
  85. package/lib/plugins/manifest/path.js +24 -0
  86. package/lib/plugins/manifest/validate.js +91 -0
  87. package/lib/plugins/node_version.js +30 -0
  88. package/lib/plugins/options.js +55 -0
  89. package/lib/plugins/pinned_version.js +83 -0
  90. package/lib/plugins/resolve.js +110 -0
  91. package/lib/plugins/spawn.js +54 -0
  92. package/lib/plugins_core/add.js +35 -0
  93. package/lib/plugins_core/build_command.js +50 -0
  94. package/lib/plugins_core/deploy/buildbot_client.js +87 -0
  95. package/lib/plugins_core/deploy/index.js +49 -0
  96. package/{src → lib}/plugins_core/deploy/manifest.yml +0 -0
  97. package/lib/plugins_core/edge_functions/index.js +79 -0
  98. package/lib/plugins_core/edge_functions/lib/error.js +17 -0
  99. package/lib/plugins_core/edge_functions/lib/internal_manifest.js +50 -0
  100. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +75 -0
  101. package/lib/plugins_core/functions/error.js +123 -0
  102. package/lib/plugins_core/functions/feature_flags.js +6 -0
  103. package/lib/plugins_core/functions/index.js +114 -0
  104. package/lib/plugins_core/functions/utils.js +45 -0
  105. package/lib/plugins_core/functions/zisi.js +39 -0
  106. package/{src → lib}/plugins_core/functions_install/index.js +8 -11
  107. package/{src → lib}/plugins_core/functions_install/manifest.yml +0 -0
  108. package/lib/plugins_core/list.js +20 -0
  109. package/lib/status/add.js +30 -0
  110. package/lib/status/colors.js +18 -0
  111. package/lib/status/load_error.js +10 -0
  112. package/lib/status/report.js +83 -0
  113. package/lib/status/success.js +14 -0
  114. package/lib/steps/core_step.js +57 -0
  115. package/lib/steps/error.js +65 -0
  116. package/lib/steps/get.js +43 -0
  117. package/lib/steps/plugin.js +55 -0
  118. package/lib/steps/return.js +25 -0
  119. package/lib/steps/run_core_steps.js +147 -0
  120. package/lib/steps/run_step.js +188 -0
  121. package/lib/steps/run_steps.js +96 -0
  122. package/lib/steps/update_config.js +66 -0
  123. package/lib/telemetry/main.js +97 -0
  124. package/lib/time/aggregate.js +120 -0
  125. package/lib/time/main.js +37 -0
  126. package/lib/time/measure.js +18 -0
  127. package/lib/time/report.js +47 -0
  128. package/lib/utils/errors.js +13 -0
  129. package/lib/utils/json.js +15 -0
  130. package/{src → lib}/utils/omit.js +3 -4
  131. package/lib/utils/package.js +22 -0
  132. package/lib/utils/remove_falsy.js +8 -0
  133. package/lib/utils/resolve.js +41 -0
  134. package/lib/utils/runtime.js +5 -0
  135. package/lib/utils/semver.js +28 -0
  136. package/package.json +39 -20
  137. package/types/config/netlify_config.d.ts +4 -4
  138. package/types/netlify_plugin_constants.d.ts +8 -8
  139. package/src/core/bin.js +0 -83
  140. package/src/core/config.js +0 -186
  141. package/src/core/constants.js +0 -156
  142. package/src/core/dry.js +0 -39
  143. package/src/core/feature_flags.js +0 -21
  144. package/src/core/flags.js +0 -194
  145. package/src/core/lingering.js +0 -85
  146. package/src/core/main.js +0 -692
  147. package/src/core/missing_side_file.js +0 -29
  148. package/src/core/normalize_flags.js +0 -69
  149. package/src/core/severity.js +0 -22
  150. package/src/core/user_node_version.js +0 -41
  151. package/src/env/changes.js +0 -52
  152. package/src/env/main.js +0 -19
  153. package/src/env/metadata.js +0 -81
  154. package/src/error/api.js +0 -46
  155. package/src/error/build.js +0 -50
  156. package/src/error/colors.js +0 -11
  157. package/src/error/handle.js +0 -57
  158. package/src/error/info.js +0 -46
  159. package/src/error/monitor/location.js +0 -21
  160. package/src/error/monitor/normalize.js +0 -77
  161. package/src/error/monitor/print.js +0 -42
  162. package/src/error/monitor/report.js +0 -133
  163. package/src/error/monitor/start.js +0 -69
  164. package/src/error/parse/clean_stack.js +0 -87
  165. package/src/error/parse/location.js +0 -58
  166. package/src/error/parse/normalize.js +0 -29
  167. package/src/error/parse/parse.js +0 -97
  168. package/src/error/parse/plugin.js +0 -70
  169. package/src/error/parse/properties.js +0 -23
  170. package/src/error/parse/serialize_log.js +0 -42
  171. package/src/error/parse/serialize_status.js +0 -23
  172. package/src/error/parse/stack.js +0 -43
  173. package/src/error/type.js +0 -182
  174. package/src/install/functions.js +0 -28
  175. package/src/install/local.js +0 -62
  176. package/src/install/main.js +0 -81
  177. package/src/install/missing.js +0 -67
  178. package/src/log/description.js +0 -26
  179. package/src/log/header.js +0 -16
  180. package/src/log/header_func.js +0 -17
  181. package/src/log/logger.js +0 -107
  182. package/src/log/messages/compatibility.js +0 -164
  183. package/src/log/messages/config.js +0 -105
  184. package/src/log/messages/core.js +0 -70
  185. package/src/log/messages/core_steps.js +0 -104
  186. package/src/log/messages/dry.js +0 -63
  187. package/src/log/messages/install.js +0 -20
  188. package/src/log/messages/ipc.js +0 -38
  189. package/src/log/messages/mutations.js +0 -82
  190. package/src/log/messages/status.js +0 -16
  191. package/src/log/messages/steps.js +0 -22
  192. package/src/log/old_version.js +0 -41
  193. package/src/log/serialize.js +0 -13
  194. package/src/log/stream.js +0 -85
  195. package/src/log/theme.js +0 -26
  196. package/src/plugins/child/diff.js +0 -55
  197. package/src/plugins/child/error.js +0 -32
  198. package/src/plugins/child/lazy.js +0 -18
  199. package/src/plugins/child/load.js +0 -29
  200. package/src/plugins/child/logic.js +0 -57
  201. package/src/plugins/child/main.js +0 -51
  202. package/src/plugins/child/run.js +0 -28
  203. package/src/plugins/child/status.js +0 -67
  204. package/src/plugins/child/typescript.js +0 -45
  205. package/src/plugins/child/utils.js +0 -56
  206. package/src/plugins/child/validate.js +0 -34
  207. package/src/plugins/compatibility.js +0 -128
  208. package/src/plugins/expected_version.js +0 -119
  209. package/src/plugins/ipc.js +0 -145
  210. package/src/plugins/list.js +0 -86
  211. package/src/plugins/load.js +0 -70
  212. package/src/plugins/manifest/check.js +0 -106
  213. package/src/plugins/manifest/load.js +0 -41
  214. package/src/plugins/manifest/main.js +0 -22
  215. package/src/plugins/manifest/path.js +0 -31
  216. package/src/plugins/manifest/validate.js +0 -108
  217. package/src/plugins/node_version.js +0 -50
  218. package/src/plugins/options.js +0 -88
  219. package/src/plugins/pinned_version.js +0 -131
  220. package/src/plugins/resolve.js +0 -152
  221. package/src/plugins/spawn.js +0 -66
  222. package/src/plugins_core/add.js +0 -49
  223. package/src/plugins_core/build_command.js +0 -75
  224. package/src/plugins_core/deploy/buildbot_client.js +0 -102
  225. package/src/plugins_core/deploy/index.js +0 -73
  226. package/src/plugins_core/edge_functions/index.js +0 -107
  227. package/src/plugins_core/edge_functions/lib/internal_manifest.js +0 -54
  228. package/src/plugins_core/functions/error.js +0 -163
  229. package/src/plugins_core/functions/feature_flags.js +0 -6
  230. package/src/plugins_core/functions/index.js +0 -160
  231. package/src/plugins_core/functions/utils.js +0 -66
  232. package/src/plugins_core/functions/zisi.js +0 -53
  233. package/src/plugins_core/list.js +0 -27
  234. package/src/status/add.js +0 -36
  235. package/src/status/colors.js +0 -23
  236. package/src/status/load_error.js +0 -11
  237. package/src/status/report.js +0 -128
  238. package/src/status/success.js +0 -18
  239. package/src/steps/core_step.js +0 -90
  240. package/src/steps/error.js +0 -102
  241. package/src/steps/get.js +0 -32
  242. package/src/steps/plugin.js +0 -85
  243. package/src/steps/return.js +0 -52
  244. package/src/steps/run_core_steps.js +0 -194
  245. package/src/steps/run_step.js +0 -300
  246. package/src/steps/run_steps.js +0 -179
  247. package/src/steps/update_config.js +0 -93
  248. package/src/telemetry/main.js +0 -136
  249. package/src/time/aggregate.js +0 -146
  250. package/src/time/main.js +0 -48
  251. package/src/time/measure.js +0 -22
  252. package/src/time/report.js +0 -59
  253. package/src/utils/errors.js +0 -12
  254. package/src/utils/json.js +0 -19
  255. package/src/utils/package.js +0 -23
  256. package/src/utils/remove_falsy.js +0 -10
  257. package/src/utils/resolve.js +0 -46
  258. package/src/utils/semver.js +0 -34
@@ -0,0 +1,13 @@
1
+ // Wrap an async function so it prepends an error message on exceptions.
2
+ // This helps locate errors.
3
+ export const addAsyncErrorMessage = function (asyncFunc, message) {
4
+ return async (...args) => {
5
+ try {
6
+ return await asyncFunc(...args);
7
+ }
8
+ catch (error) {
9
+ error.stack = `${message}: ${error.stack}`;
10
+ throw error;
11
+ }
12
+ };
13
+ };
@@ -0,0 +1,15 @@
1
+ import { promises as fs, readFileSync } from 'fs';
2
+ import { fileURLToPath } from 'url';
3
+ const ROOT_PACKAGE_JSON_PATH = fileURLToPath(new URL('../../package.json', import.meta.url));
4
+ // TODO: Replace with dynamic `import()` once it is supported without
5
+ // experimental flags
6
+ export const importJsonFile = async function (filePath) {
7
+ const fileContents = await fs.readFile(filePath);
8
+ return JSON.parse(fileContents);
9
+ };
10
+ const importJsonFileSync = function (filePath) {
11
+ // Use sync I/O so it is easier to migrate to `import()` later on
12
+ const fileContents = readFileSync(filePath, 'utf8');
13
+ return JSON.parse(fileContents);
14
+ };
15
+ export const ROOT_PACKAGE_JSON = importJsonFileSync(ROOT_PACKAGE_JSON_PATH);
@@ -1,6 +1,5 @@
1
- import filterObj from 'filter-obj'
2
-
1
+ import filterObj from 'filter-obj';
3
2
  // lodash.omit is 1400 lines of codes. filter-obj is much smaller and simpler.
4
3
  export const omit = function (obj, keys) {
5
- return filterObj(obj, (key) => !keys.includes(key))
6
- }
4
+ return filterObj(obj, (key) => !keys.includes(key));
5
+ };
@@ -0,0 +1,22 @@
1
+ import { dirname } from 'path';
2
+ import { readPackageUp } from 'read-pkg-up';
3
+ // Retrieve `package.json` from a specific directory
4
+ export const getPackageJson = async function (cwd, { normalize } = {}) {
5
+ const packageObj = await getPackageObj({ cwd, normalize });
6
+ if (packageObj === undefined) {
7
+ return { packageJson: {} };
8
+ }
9
+ const { path, packageJson } = packageObj;
10
+ const packageDir = dirname(path);
11
+ return { packageDir, packageJson };
12
+ };
13
+ const getPackageObj = async function ({ cwd, normalize = true }) {
14
+ try {
15
+ return await readPackageUp({ cwd, normalize });
16
+ // If the `package.json` is invalid and `normalize` is `true`, an error is
17
+ // thrown. We return `undefined` then.
18
+ }
19
+ catch {
20
+ // continue regardless error
21
+ }
22
+ };
@@ -0,0 +1,8 @@
1
+ import filterObj from 'filter-obj';
2
+ // Remove falsy values from object
3
+ export const removeFalsy = function (obj) {
4
+ return filterObj(obj, isDefined);
5
+ };
6
+ const isDefined = function (key, value) {
7
+ return value !== undefined && value !== '';
8
+ };
@@ -0,0 +1,41 @@
1
+ import { createRequire } from 'module';
2
+ import { async as resolveLib } from 'resolve';
3
+ // TODO: use `import.resolve()` once it is available without any experimental
4
+ // flags
5
+ const require = createRequire(import.meta.url);
6
+ // Like `resolvePath()` but does not throw
7
+ export const tryResolvePath = async function (path, basedir) {
8
+ try {
9
+ const resolvedPath = await resolvePath(path, basedir);
10
+ return { path: resolvedPath };
11
+ }
12
+ catch (error) {
13
+ return { error };
14
+ }
15
+ };
16
+ // This throws if the package cannot be found
17
+ export const resolvePath = async function (path, basedir) {
18
+ try {
19
+ return await resolvePathWithBasedir(path, basedir);
20
+ // Fallback.
21
+ // `resolve` sometimes gives unhelpful error messages.
22
+ // https://github.com/browserify/resolve/issues/223
23
+ }
24
+ catch {
25
+ return require.resolve(path, { paths: [basedir] });
26
+ }
27
+ };
28
+ // Like `require.resolve()` but as an external library.
29
+ // We need to use `new Promise()` due to a bug with `utils.promisify()` on
30
+ // `resolve`:
31
+ // https://github.com/browserify/resolve/issues/151#issuecomment-368210310
32
+ const resolvePathWithBasedir = function (path, basedir) {
33
+ return new Promise((resolve, reject) => {
34
+ resolveLib(path, { basedir }, (error, resolvedPath) => {
35
+ if (error) {
36
+ return reject(error);
37
+ }
38
+ resolve(resolvedPath);
39
+ });
40
+ });
41
+ };
@@ -0,0 +1,5 @@
1
+ export const isRuntime = function (pluginOption) {
2
+ const { packageName } = pluginOption;
3
+ // Make this a bit more robust in the future
4
+ return ['@netlify/next-runtime', '@netlify/plugin-nextjs'].includes(packageName);
5
+ };
@@ -0,0 +1,28 @@
1
+ import semver from 'semver';
2
+ // Compare two versions by their major versions.
3
+ // Takes into account the special rules for `0.*.*` and `0.0.*` versions.
4
+ export const isPreviousMajor = function (versionA, versionB) {
5
+ return semver.lt(getMajor(versionA), getMajor(versionB));
6
+ };
7
+ // Remove minor/patch numbers
8
+ const getMajor = function (version) {
9
+ return semver.minVersion(getMajorVersion(version)).version;
10
+ };
11
+ // According to semver, the second number is the major release number for
12
+ // `0.*.*` versions and the third for `0.0.*`. This is how `^` behaves with the
13
+ // `semver` module which is used by `npm`.
14
+ export const getMajorVersion = function (version) {
15
+ if (!version || semver.clean(version) === null) {
16
+ return;
17
+ }
18
+ const majorVersion = semver.major(version);
19
+ if (majorVersion !== 0) {
20
+ return `${majorVersion}`;
21
+ }
22
+ const minorVersion = semver.minor(version);
23
+ if (minorVersion !== 0) {
24
+ return `${majorVersion}.${minorVersion}`;
25
+ }
26
+ const patchVersion = semver.patch(version);
27
+ return `${majorVersion}.${minorVersion}.${patchVersion}`;
28
+ };
package/package.json CHANGED
@@ -1,17 +1,18 @@
1
1
  {
2
2
  "name": "@netlify/build",
3
- "version": "28.0.0-beta",
3
+ "version": "28.0.0",
4
4
  "description": "Netlify build module",
5
5
  "type": "module",
6
- "exports": "./src/core/main.js",
7
- "main": "./src/core/main.js",
8
- "types": "types/index.d.ts",
6
+ "exports": "./lib/core/main.js",
7
+ "main": "./lib/core/main.js",
8
+ "types": "./types/index.d.ts",
9
9
  "bin": {
10
- "netlify-build": "./src/core/bin.js"
10
+ "netlify-build": "./bin.js"
11
11
  },
12
12
  "files": [
13
- "src/**/*.js",
14
- "src/**/*.yml",
13
+ "bin.js",
14
+ "lib/**/*.js",
15
+ "lib/**/*.yml",
15
16
  "types/**/*.d.ts"
16
17
  ],
17
18
  "author": "Netlify Inc.",
@@ -20,7 +21,13 @@
20
21
  "Swyx <swyx@netlify.com> (https://www.swyx.io)"
21
22
  ],
22
23
  "scripts": {
23
- "prepublishOnly": "cd ../../ && npm run prepublishOnly"
24
+ "prebuild": "rm -rf lib",
25
+ "postbuild": "npx copyfiles \"src/**/*.yml\" lib/ -u 1",
26
+ "build": "tsc",
27
+ "pretest": "tsd .",
28
+ "test": "ava",
29
+ "test:ci": "c8 -r lcovonly -r text -r json ava",
30
+ "test:measure": "../../tools/tests-duration.js"
24
31
  },
25
32
  "keywords": [
26
33
  "nodejs",
@@ -56,16 +63,17 @@
56
63
  "license": "MIT",
57
64
  "dependencies": {
58
65
  "@bugsnag/js": "^7.0.0",
59
- "@netlify/edge-bundler": "^1.4.2",
60
- "@netlify/cache-utils": "^4.0.0",
61
- "@netlify/config": "^18.1.1",
62
- "@netlify/functions-utils": "^4.2.0",
63
- "@netlify/git-utils": "^4.0.0",
64
- "@netlify/plugins-list": "^6.29.0",
65
- "@netlify/run-utils": "^4.0.0",
66
- "@netlify/zip-it-and-ship-it": "6.0.0-beta",
66
+ "@netlify/cache-utils": "^5.0.0",
67
+ "@netlify/config": "^19.0.0",
68
+ "@netlify/edge-bundler": "^2.7.0",
69
+ "@netlify/functions-utils": "^5.0.0",
70
+ "@netlify/git-utils": "^5.0.0",
71
+ "@netlify/plugins-list": "^6.49.1",
72
+ "@netlify/run-utils": "^5.0.0",
73
+ "@netlify/zip-it-and-ship-it": "^7.1.2",
67
74
  "@sindresorhus/slugify": "^2.0.0",
68
- "@types/node": "^16.0.0",
75
+ "ajv": "^8.11.0",
76
+ "ajv-errors": "^3.0.0",
69
77
  "ansi-escapes": "^5.0.0",
70
78
  "chalk": "^5.0.0",
71
79
  "clean-stack": "^4.0.0",
@@ -110,9 +118,12 @@
110
118
  "yargs": "^17.3.1"
111
119
  },
112
120
  "devDependencies": {
113
- "@netlify/nock-udp": "^1.0.0",
121
+ "@netlify/nock-udp": "^3.0.0",
122
+ "@types/node": "^14.18.31",
114
123
  "atob": "^2.1.2",
115
124
  "ava": "^4.0.0",
125
+ "c8": "^7.12.0",
126
+ "copyfiles": "^2.4.1",
116
127
  "cpy": "^8.1.0",
117
128
  "del": "^6.0.0",
118
129
  "fast-safe-stringify": "^2.0.7",
@@ -126,9 +137,17 @@
126
137
  "path-key": "^4.0.0",
127
138
  "process-exists": "^5.0.0",
128
139
  "sinon": "^13.0.0",
140
+ "tsd": "^0.24.1",
141
+ "typescript": "^4.8.4",
129
142
  "yarn": "^1.22.4"
130
143
  },
131
144
  "engines": {
132
- "node": "^12.20.0 || ^14.14.0 || >=16.0.0"
133
- }
145
+ "node": "^14.16.0 || >=16.0.0"
146
+ },
147
+ "tsd": {
148
+ "compilerOptions": {
149
+ "module": "commonjs"
150
+ }
151
+ },
152
+ "gitHead": "c4502f1c112e7f33d5e6fa053bfbe7dabdfe0160"
134
153
  }
@@ -22,9 +22,9 @@ interface Header {
22
22
  values: Partial<Record<string, Many<string, 'mutable'>>>
23
23
  }
24
24
 
25
- interface EdgeHandler {
25
+ interface EdgeFunction {
26
26
  path?: `/${string}`
27
- handler: string
27
+ function: string
28
28
  }
29
29
 
30
30
  interface NetlifyPlugin {
@@ -44,9 +44,9 @@ interface NetlifyConfig {
44
44
  */
45
45
  headers: Header[]
46
46
  /**
47
- * array of Edge Handlers with their modifiable options
47
+ * array of Edge Functions with their modifiable options
48
48
  */
49
- edge_handlers: EdgeHandler[]
49
+ edge_functions: EdgeFunction[]
50
50
  /**
51
51
  * object with options for modifying [functions](https://docs.netlify.com/configure-builds/file-based-configuration/#functions)
52
52
  */
@@ -14,10 +14,10 @@ export interface NetlifyPluginConstants {
14
14
  */
15
15
  FUNCTIONS_SRC?: string
16
16
  /**
17
- * the directory where internal Edge Handlers source code lives. This is where build plugins should place auto-generated handlers.
18
- * `undefined` if the version of @netlify/build does not support internal Edge Handlers
17
+ * the directory where internal Edge Functions source code lives. This is where build plugins should place auto-generated functions.
18
+ * `undefined` if the version of @netlify/build does not support internal Edge Functions
19
19
  */
20
- INTERNAL_EDGE_HANDLERS_SRC?: string
20
+ INTERNAL_EDGE_FUNCTIONS_SRC?: string
21
21
  /**
22
22
  * the directory where internal function source code lives. This is where build plugins should place auto-generated functions.
23
23
  * `undefined` if the version of @netlify/build does not support internal functions
@@ -28,14 +28,14 @@ export interface NetlifyPluginConstants {
28
28
  */
29
29
  FUNCTIONS_DIST: string
30
30
  /**
31
- * the directory where built Edge Handlers are placed before deployment. Its value is always defined, but the target might not have been created yet.
31
+ * the directory where built Edge Functions are placed before deployment. Its value is always defined, but the target might not have been created yet.
32
32
  */
33
- EDGE_HANDLERS_DIST: string
33
+ EDGE_FUNCTIONS_DIST: string
34
34
  /**
35
- * the directory where Edge Handlers source code lives.
36
- * `undefined` if no `netlify/edge-handlers` directory exists in the base directory and if not specified in `netlify.toml`.
35
+ * the directory where Edge Functions source code lives.
36
+ * `undefined` if no `netlify/edge-functions` directory exists.
37
37
  */
38
- EDGE_HANDLERS_SRC?: string
38
+ EDGE_FUNCTIONS_SRC?: string
39
39
  /**
40
40
  * boolean indicating whether the build was [run locally](https://docs.netlify.com/cli/get-started/#run-builds-locally) or on Netlify
41
41
  */
package/src/core/bin.js DELETED
@@ -1,83 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import process from 'process'
4
-
5
- import filterObj from 'filter-obj'
6
- import yargs from 'yargs'
7
- import { hideBin } from 'yargs/helpers'
8
-
9
- import { normalizeCliFeatureFlags } from './feature_flags.js'
10
- import { FLAGS } from './flags.js'
11
- import build from './main.js'
12
- import { FALLBACK_SEVERITY_ENTRY } from './severity.js'
13
-
14
- // CLI entry point.
15
- // Before adding logic to this file, please consider adding it to the main
16
- // programmatic command instead, so that the new logic is available when run
17
- // programmatically as well. This file should only contain logic that makes
18
- // sense only in CLI, such as CLI flags parsing and exit code.
19
- const runCli = async function () {
20
- const flags = parseFlags()
21
- const flagsA = filterObj(flags, isUserFlag)
22
-
23
- const state = { done: false }
24
- process.on('exit', onExit.bind(undefined, state))
25
-
26
- const { severityCode, logs } = await build(flagsA)
27
- printLogs(logs)
28
- process.exitCode = severityCode
29
-
30
- state.done = true
31
- }
32
-
33
- const parseFlags = function () {
34
- const { featureFlags: cliFeatureFlags = '', ...flags } = yargs(hideBin(process.argv))
35
- .options(FLAGS)
36
- .usage(USAGE)
37
- .parse()
38
- const featureFlags = normalizeCliFeatureFlags(cliFeatureFlags)
39
- return { ...flags, featureFlags }
40
- }
41
-
42
- const USAGE = `netlify-build [OPTIONS...]
43
-
44
- Run Netlify Build system locally.
45
-
46
- Options can also be specified as environment variables prefixed with
47
- NETLIFY_BUILD_. For example the environment variable NETLIFY_BUILD_DRY=true can
48
- be used instead of the CLI flag --dry.`
49
-
50
- // Remove `yargs`-specific options, shortcuts, dash-cased and aliases
51
- const isUserFlag = function (key, value) {
52
- return value !== undefined && !INTERNAL_KEYS.has(key) && key.length !== 1 && !key.includes('-')
53
- }
54
-
55
- const INTERNAL_KEYS = new Set(['help', 'version', '_', '$0', 'dryRun'])
56
-
57
- // Used mostly for testing
58
- const printLogs = function (logs) {
59
- if (logs === undefined) {
60
- return
61
- }
62
-
63
- const allLogs = [logs.stdout.join('\n'), logs.stderr.join('\n')].filter(Boolean).join('\n\n')
64
- console.log(allLogs)
65
- }
66
-
67
- // In theory, the main process should not exit until the main `build()` function
68
- // has completed. In practice, this might happen due to bugs.
69
- // Making the exit code not 0 in that case ensures the caller knows that the
70
- // build has completed when the exit code is 0. This `exit` event handlers
71
- // guarantees this.
72
- const onExit = function ({ done }, exitCode) {
73
- if (done || exitCode !== 0) {
74
- return
75
- }
76
-
77
- const [, processName] = process.argv
78
- console.log(`${processName} exited with exit code ${exitCode} without finishing the build.`)
79
-
80
- process.exitCode = FALLBACK_SEVERITY_ENTRY.severityCode
81
- }
82
-
83
- runCli()
@@ -1,186 +0,0 @@
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
-
14
- // Retrieve immutable options passed to `@netlify/config`.
15
- // This does not include options which might change during the course of the
16
- // build:
17
- // - `cachedConfig` and `cachedConfigPath` are only used at the beginning of
18
- // the build
19
- // - If plugins change the configuration, `configMutations` is used instead
20
- // 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
-
61
- // Retrieve configuration object
62
- 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
-
103
- // Retrieve initial configuration.
104
- // In the buildbot and CLI, we re-use the already parsed `@netlify/config`
105
- // return value which is passed as `cachedConfig`/`cachedConfigPath`.
106
- const resolveInitialConfig = async function (configOpts, cachedConfig, cachedConfigPath) {
107
- return await resolveConfig({ ...configOpts, cachedConfig, cachedConfigPath })
108
- }
109
-
110
- 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
-
117
- // Retrieve the configuration after it's been changed.
118
- // This ensures any configuration changes done by plugins is validated and
119
- // normalized.
120
- // We use `debug: false` to avoid any debug logs. Otherwise every configuration
121
- // change would create debug logs which would be too verbose.
122
- // Errors are propagated and assigned to the specific plugin or core step
123
- // which changed the configuration.
124
- 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
-
133
- // If the configuration was changed, persist it to `netlify.toml`.
134
- // If `netlify.toml` does not exist, create it inside repository root.
135
- // This is only done when `saveConfig` is `true`. This allows performing this
136
- // in the buildbot but not in local builds, since only the latter run in a
137
- // 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
- }