@netlify/build 0.5.0 → 1.0.0-dl-test

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 (242) hide show
  1. package/bin.js +5 -0
  2. package/lib/core/bin.js +66 -0
  3. package/lib/core/build.js +392 -0
  4. package/lib/core/config.js +124 -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 +17 -0
  9. package/lib/core/flags.js +206 -0
  10. package/lib/core/lingering.js +68 -0
  11. package/lib/core/main.js +114 -0
  12. package/lib/core/missing_side_file.js +17 -0
  13. package/lib/core/normalize_flags.js +62 -0
  14. package/lib/core/report_metrics.js +17 -0
  15. package/lib/core/severity.js +21 -0
  16. package/lib/core/types.js +8 -0
  17. package/lib/core/user_node_version.js +32 -0
  18. package/lib/env/changes.js +43 -0
  19. package/lib/env/main.js +14 -0
  20. package/lib/env/metadata.js +68 -0
  21. package/lib/error/api.js +37 -0
  22. package/lib/error/build.js +36 -0
  23. package/lib/error/cancel.js +7 -0
  24. package/lib/error/colors.js +9 -0
  25. package/lib/error/handle.js +44 -0
  26. package/lib/error/info.js +37 -0
  27. package/lib/error/monitor/location.js +16 -0
  28. package/lib/error/monitor/normalize.js +86 -0
  29. package/lib/error/monitor/print.js +20 -0
  30. package/lib/error/monitor/report.js +120 -0
  31. package/lib/error/monitor/start.js +61 -0
  32. package/lib/error/parse/clean_stack.js +70 -0
  33. package/lib/error/parse/location.js +50 -0
  34. package/lib/error/parse/normalize.js +24 -0
  35. package/lib/error/parse/parse.js +67 -0
  36. package/lib/error/parse/plugin.js +55 -0
  37. package/lib/error/parse/properties.js +16 -0
  38. package/lib/error/parse/serialize_log.js +34 -0
  39. package/lib/error/parse/serialize_status.js +18 -0
  40. package/lib/error/parse/stack.js +34 -0
  41. package/lib/error/report.js +29 -0
  42. package/lib/error/type.js +177 -0
  43. package/lib/install/functions.js +20 -0
  44. package/lib/install/local.js +45 -0
  45. package/lib/install/main.js +67 -0
  46. package/lib/install/missing.js +54 -0
  47. package/lib/log/colors.js +28 -0
  48. package/lib/log/description.js +21 -0
  49. package/lib/log/header.js +12 -0
  50. package/lib/log/header_func.js +13 -0
  51. package/lib/log/logger.js +140 -0
  52. package/lib/log/messages/compatibility.js +120 -0
  53. package/lib/log/messages/config.js +91 -0
  54. package/lib/log/messages/core.js +49 -0
  55. package/lib/log/messages/core_steps.js +75 -0
  56. package/lib/log/messages/dry.js +41 -0
  57. package/lib/log/messages/install.js +25 -0
  58. package/lib/log/messages/ipc.js +29 -0
  59. package/lib/log/messages/mutations.js +62 -0
  60. package/lib/log/messages/plugins.js +25 -0
  61. package/lib/log/messages/status.js +14 -0
  62. package/lib/log/messages/steps.js +18 -0
  63. package/lib/log/serialize.js +10 -0
  64. package/lib/log/stream.js +68 -0
  65. package/lib/log/theme.js +27 -0
  66. package/lib/plugins/child/diff.js +46 -0
  67. package/lib/plugins/child/error.js +26 -0
  68. package/lib/plugins/child/lazy.js +15 -0
  69. package/lib/plugins/child/load.js +22 -0
  70. package/lib/plugins/child/logic.js +57 -0
  71. package/lib/plugins/child/main.js +37 -0
  72. package/lib/plugins/child/run.js +19 -0
  73. package/lib/plugins/child/status.js +63 -0
  74. package/lib/plugins/child/typescript.js +28 -0
  75. package/lib/plugins/child/utils.js +42 -0
  76. package/lib/plugins/child/validate.js +31 -0
  77. package/lib/plugins/compatibility.js +104 -0
  78. package/lib/plugins/error.js +46 -0
  79. package/lib/plugins/events.js +12 -0
  80. package/lib/plugins/expected_version.js +81 -0
  81. package/lib/plugins/internal.js +10 -0
  82. package/lib/plugins/ipc.js +120 -0
  83. package/lib/plugins/list.js +73 -0
  84. package/lib/plugins/load.js +50 -0
  85. package/lib/plugins/manifest/check.js +85 -0
  86. package/lib/plugins/manifest/load.js +38 -0
  87. package/lib/plugins/manifest/main.js +19 -0
  88. package/lib/plugins/manifest/path.js +24 -0
  89. package/lib/plugins/manifest/validate.js +91 -0
  90. package/lib/plugins/node_version.js +35 -0
  91. package/lib/plugins/options.js +70 -0
  92. package/lib/plugins/pinned_version.js +83 -0
  93. package/lib/plugins/resolve.js +110 -0
  94. package/lib/plugins/spawn.js +55 -0
  95. package/lib/plugins_core/add.js +35 -0
  96. package/lib/plugins_core/build_command.js +50 -0
  97. package/lib/plugins_core/deploy/buildbot_client.js +87 -0
  98. package/lib/plugins_core/deploy/index.js +49 -0
  99. package/lib/plugins_core/deploy/manifest.yml +1 -0
  100. package/lib/plugins_core/edge_functions/index.js +106 -0
  101. package/lib/plugins_core/edge_functions/lib/error.js +17 -0
  102. package/lib/plugins_core/edge_functions/validate_manifest/validate_edge_functions_manifest.js +14 -0
  103. package/lib/plugins_core/functions/error.js +123 -0
  104. package/lib/plugins_core/functions/feature_flags.js +5 -0
  105. package/lib/plugins_core/functions/index.js +137 -0
  106. package/lib/plugins_core/functions/utils.js +45 -0
  107. package/lib/plugins_core/functions/zisi.js +64 -0
  108. package/lib/plugins_core/functions_install/index.js +10 -0
  109. package/lib/plugins_core/list.js +20 -0
  110. package/lib/plugins_core/save_artifacts/index.js +33 -0
  111. package/lib/report/statsd.js +56 -0
  112. package/lib/status/add.js +30 -0
  113. package/lib/status/colors.js +18 -0
  114. package/lib/status/load_error.js +10 -0
  115. package/lib/status/report.js +83 -0
  116. package/lib/status/success.js +14 -0
  117. package/lib/steps/core_step.js +62 -0
  118. package/lib/steps/error.js +65 -0
  119. package/lib/steps/get.js +44 -0
  120. package/lib/steps/plugin.js +55 -0
  121. package/lib/steps/return.js +27 -0
  122. package/lib/steps/run_core_steps.js +117 -0
  123. package/lib/steps/run_step.js +200 -0
  124. package/lib/steps/run_steps.js +102 -0
  125. package/lib/steps/update_config.js +66 -0
  126. package/lib/telemetry/main.js +94 -0
  127. package/lib/time/aggregate.js +109 -0
  128. package/lib/time/main.js +31 -0
  129. package/lib/time/measure.js +16 -0
  130. package/lib/time/report.js +30 -0
  131. package/lib/utils/errors.js +13 -0
  132. package/lib/utils/json.js +10 -0
  133. package/lib/utils/omit.js +3 -0
  134. package/lib/utils/package.js +24 -0
  135. package/lib/utils/remove_falsy.js +8 -0
  136. package/lib/utils/resolve.js +41 -0
  137. package/lib/utils/runtime.js +5 -0
  138. package/lib/utils/semver.js +28 -0
  139. package/package.json +119 -56
  140. package/types/config/build.d.ts +52 -0
  141. package/types/config/functions.d.ts +36 -0
  142. package/types/config/inputs.d.ts +7 -0
  143. package/types/config/netlify_config.d.ts +58 -0
  144. package/types/index.d.ts +7 -0
  145. package/types/netlify_event_handler.d.ts +29 -0
  146. package/types/netlify_plugin.d.ts +29 -0
  147. package/types/netlify_plugin_constants.d.ts +51 -0
  148. package/types/netlify_plugin_options.d.ts +23 -0
  149. package/types/options/index.d.ts +1 -0
  150. package/types/options/netlify_plugin_build_util.d.ts +7 -0
  151. package/types/options/netlify_plugin_cache_util.d.ts +39 -0
  152. package/types/options/netlify_plugin_functions_util.d.ts +32 -0
  153. package/types/options/netlify_plugin_git_util.d.ts +41 -0
  154. package/types/options/netlify_plugin_run_util.d.ts +24 -0
  155. package/types/options/netlify_plugin_status_util.d.ts +24 -0
  156. package/types/options/netlify_plugin_utils.d.ts +15 -0
  157. package/types/utils/json_value.d.ts +1 -0
  158. package/types/utils/many.d.ts +6 -0
  159. package/README.md +0 -3
  160. package/src/core/bin.js +0 -139
  161. package/src/core/commands.js +0 -304
  162. package/src/core/config.js +0 -130
  163. package/src/core/constants.js +0 -86
  164. package/src/core/dry.js +0 -23
  165. package/src/core/main.js +0 -196
  166. package/src/env/changes.js +0 -49
  167. package/src/env/git.js +0 -27
  168. package/src/env/main.js +0 -97
  169. package/src/env/metadata.js +0 -81
  170. package/src/error/api.js +0 -32
  171. package/src/error/build.js +0 -32
  172. package/src/error/cancel.js +0 -22
  173. package/src/error/colors.js +0 -13
  174. package/src/error/info.js +0 -12
  175. package/src/error/monitor/normalize.js +0 -50
  176. package/src/error/monitor/print.js +0 -43
  177. package/src/error/monitor/report.js +0 -140
  178. package/src/error/monitor/start.js +0 -50
  179. package/src/error/parse/clean_stack.js +0 -86
  180. package/src/error/parse/location.js +0 -50
  181. package/src/error/parse/parse.js +0 -87
  182. package/src/error/parse/plugin.js +0 -68
  183. package/src/error/parse/properties.js +0 -20
  184. package/src/error/parse/serialize_log.js +0 -46
  185. package/src/error/parse/serialize_status.js +0 -28
  186. package/src/error/parse/stack.js +0 -45
  187. package/src/error/process.js +0 -13
  188. package/src/error/type.js +0 -143
  189. package/src/install/functions.js +0 -62
  190. package/src/install/local.js +0 -74
  191. package/src/install/main.js +0 -103
  192. package/src/install/missing.js +0 -86
  193. package/src/log/colors.js +0 -59
  194. package/src/log/description.js +0 -38
  195. package/src/log/header.js +0 -19
  196. package/src/log/logger.js +0 -55
  197. package/src/log/main.js +0 -290
  198. package/src/log/old_version.js +0 -45
  199. package/src/log/serialize.js +0 -15
  200. package/src/log/stream.js +0 -15
  201. package/src/log/theme.js +0 -32
  202. package/src/log/timer.js +0 -28
  203. package/src/plugins/child/api.js +0 -59
  204. package/src/plugins/child/error.js +0 -39
  205. package/src/plugins/child/load.js +0 -37
  206. package/src/plugins/child/logic.js +0 -31
  207. package/src/plugins/child/main.js +0 -48
  208. package/src/plugins/child/run.js +0 -30
  209. package/src/plugins/child/status.js +0 -53
  210. package/src/plugins/child/utils.js +0 -43
  211. package/src/plugins/child/validate.js +0 -71
  212. package/src/plugins/error.js +0 -73
  213. package/src/plugins/events.js +0 -77
  214. package/src/plugins/ipc.js +0 -136
  215. package/src/plugins/load.js +0 -66
  216. package/src/plugins/manifest/check.js +0 -80
  217. package/src/plugins/manifest/load.js +0 -54
  218. package/src/plugins/manifest/main.js +0 -24
  219. package/src/plugins/manifest/path.js +0 -12
  220. package/src/plugins/manifest/validate.js +0 -136
  221. package/src/plugins/node_version.js +0 -74
  222. package/src/plugins/options.js +0 -78
  223. package/src/plugins/package.js +0 -17
  224. package/src/plugins/resolve.js +0 -159
  225. package/src/plugins/spawn.js +0 -82
  226. package/src/plugins_core/cache/manifest.yml +0 -1
  227. package/src/plugins_core/cache/plugin.js +0 -75
  228. package/src/plugins_core/functions/manifest.yml +0 -1
  229. package/src/plugins_core/functions/plugin.js +0 -37
  230. package/src/plugins_core/functions_install/plugin.js +0 -14
  231. package/src/plugins_core/main.js +0 -38
  232. package/src/status/add.js +0 -56
  233. package/src/status/colors.js +0 -25
  234. package/src/status/report.js +0 -57
  235. package/src/telemetry/complete.js +0 -49
  236. package/src/telemetry/request.js +0 -28
  237. package/src/telemetry/track.js +0 -33
  238. package/src/utils/omit.js +0 -8
  239. package/src/utils/polyfills.js +0 -3
  240. package/src/utils/remove_falsy.js +0 -12
  241. package/src/utils/resolve.js +0 -39
  242. /package/{src → lib}/plugins_core/functions_install/manifest.yml +0 -0
@@ -0,0 +1,31 @@
1
+ import keepFuncProps from 'keep-func-props';
2
+ import { startTimer, endTimer } from './measure.js';
3
+ const DEFAULT_METRIC_NAME = 'buildbot.build.stage.duration';
4
+ export const TOP_PARENT_TAG = 'run_netlify_build';
5
+ // Initialize the `timers` array
6
+ export const initTimers = function () {
7
+ return [];
8
+ };
9
+ // Wrap an async function to measure how long it takes.
10
+ // The function must:
11
+ // - take a plain object as first argument. This must contain a `timers`.
12
+ // - return a plain object. This may or may not contain a modified `timers`.
13
+ // The `durationNs` will be returned by the function. A new `timers` with the
14
+ // additional duration timer will be returned as well.
15
+ const kMeasureDuration = function (func, stageTag, { parentTag = undefined, category = undefined } = {}) {
16
+ return async function measuredFunc({ timers, ...opts }, ...args) {
17
+ const timerNs = startTimer();
18
+ const { timers: timersA = timers, ...returnObject } = await func({ timers, ...opts }, ...args);
19
+ const { tags = {} } = returnObject;
20
+ const durationNs = endTimer(timerNs);
21
+ const timer = createTimer(stageTag, durationNs, { parentTag, category, tags });
22
+ const timersB = [...timersA, timer];
23
+ return { ...returnObject, timers: timersB, durationNs };
24
+ };
25
+ };
26
+ // Ensure the wrapped function `name` is not `anonymous` in stack traces
27
+ export const measureDuration = keepFuncProps(kMeasureDuration);
28
+ // Create a new object representing a completed timer
29
+ export const createTimer = function (stageTag, durationNs, { metricName = DEFAULT_METRIC_NAME, parentTag = TOP_PARENT_TAG, category = undefined, tags = undefined } = {}) {
30
+ return { metricName, stageTag, parentTag, durationNs, category, tags };
31
+ };
@@ -0,0 +1,16 @@
1
+ import { hrtime } from 'process';
2
+ const NANOSECS_TO_SECS = 1e9;
3
+ const NANOSECS_TO_MSECS = 1e6;
4
+ /** Starts a timer */
5
+ export const startTimer = hrtime;
6
+ /** Stops a timer */
7
+ export const endTimer = ([startSecs, startNsecs]) => {
8
+ const [endSecs, endNsecs] = hrtime();
9
+ const durationNs = (endSecs - startSecs) * NANOSECS_TO_SECS + endNsecs - startNsecs;
10
+ return durationNs;
11
+ };
12
+ /**
13
+ * statsd expects milliseconds integers.
14
+ * To prevent double rounding errors, rounding should only be applied once.
15
+ */
16
+ export const roundTimerToMillisecs = (durationNs) => Math.round(durationNs / NANOSECS_TO_MSECS);
@@ -0,0 +1,30 @@
1
+ import { closeClient, formatTags, startClient, validateStatsDOptions, } from '../report/statsd.js';
2
+ import { addAggregatedTimers } from './aggregate.js';
3
+ import { roundTimerToMillisecs } from './measure.js';
4
+ /**
5
+ * Record the duration of a build phase, for monitoring.
6
+ * Sends to statsd daemon.
7
+ */
8
+ export const reportTimers = async function (timers, statsdOpts, framework) {
9
+ if (!validateStatsDOptions(statsdOpts)) {
10
+ return;
11
+ }
12
+ await sendTimers(addAggregatedTimers(timers), statsdOpts, framework);
13
+ };
14
+ const sendTimers = async function (timers, statsdOpts, framework) {
15
+ const client = await startClient(statsdOpts);
16
+ timers.forEach((timer) => {
17
+ sendTimer(timer, client, framework);
18
+ });
19
+ await closeClient(client);
20
+ };
21
+ const sendTimer = function (timer, client, framework) {
22
+ const { metricName, stageTag, parentTag, durationNs, tags } = timer;
23
+ const durationMs = roundTimerToMillisecs(durationNs);
24
+ const statsDTags = { stage: stageTag, parent: parentTag, ...tags };
25
+ // Do not add a framework tag if empty string or null/undefined
26
+ if (framework) {
27
+ statsDTags.framework = framework;
28
+ }
29
+ client.distribution(metricName, durationMs, formatTags(statsDTags));
30
+ };
@@ -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,10 @@
1
+ import { readFile } from 'fs/promises';
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 readFile(filePath, 'utf-8');
8
+ return JSON.parse(fileContents);
9
+ };
10
+ export const ROOT_PACKAGE_JSON = (await importJsonFile(ROOT_PACKAGE_JSON_PATH));
@@ -0,0 +1,3 @@
1
+ import filterObj from 'filter-obj';
2
+ // lodash.omit is 1400 lines of codes. filter-obj is much smaller and simpler.
3
+ export const omit = (obj, keys) => filterObj(obj, (key) => !keys.includes(key));
@@ -0,0 +1,24 @@
1
+ import { dirname } from 'path';
2
+ import { readPackageUp } from 'read-pkg-up';
3
+ /**
4
+ * Retrieve `package.json` from a specific directory
5
+ */
6
+ export const getPackageJson = async function (cwd, options = {}) {
7
+ const result = {
8
+ packageJson: {},
9
+ };
10
+ try {
11
+ const readResult = await readPackageUp({
12
+ cwd,
13
+ ...Object.assign({ normalize: true }, options),
14
+ });
15
+ if (readResult) {
16
+ result.packageJson = readResult.packageJson;
17
+ result.packageDir = dirname(readResult.path);
18
+ }
19
+ }
20
+ catch {
21
+ // continue regardless error
22
+ }
23
+ return result;
24
+ };
@@ -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,15 +1,19 @@
1
1
  {
2
2
  "name": "@netlify/build",
3
- "version": "0.5.0",
3
+ "version": "1.0.0-dl-test",
4
4
  "description": "Netlify build module",
5
- "main": "src/core/main.js",
5
+ "type": "module",
6
+ "exports": "./lib/core/main.js",
7
+ "main": "./lib/core/main.js",
8
+ "types": "./types/index.d.ts",
6
9
  "bin": {
7
- "netlify-build": "./src/core/bin.js"
10
+ "netlify-build": "./bin.js"
8
11
  },
9
12
  "files": [
10
- "src",
11
- "!*.test.*",
12
- "!*~"
13
+ "bin.js",
14
+ "lib/**/*.js",
15
+ "lib/**/*.yml",
16
+ "types/**/*.d.ts"
13
17
  ],
14
18
  "author": "Netlify Inc.",
15
19
  "contributors": [
@@ -17,71 +21,130 @@
17
21
  "Swyx <swyx@netlify.com> (https://www.swyx.io)"
18
22
  ],
19
23
  "scripts": {
20
- "release:patch": "npm version patch && npm publish",
21
- "release:minor": "npm version minor && npm publish",
22
- "release:major": "npm version major && npm publish"
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:dev": "ava -w",
30
+ "test:ci": "c8 -r lcovonly -r text -r json ava",
31
+ "test:measure": "../../tools/tests-duration.js"
32
+ },
33
+ "keywords": [
34
+ "nodejs",
35
+ "javascript",
36
+ "windows",
37
+ "macos",
38
+ "linux",
39
+ "shell",
40
+ "bash",
41
+ "build",
42
+ "terminal",
43
+ "deployment",
44
+ "es6",
45
+ "serverless",
46
+ "ci",
47
+ "plugins",
48
+ "continuous-integration",
49
+ "continuous-deployment",
50
+ "continuous-delivery",
51
+ "continuous-testing",
52
+ "netlify-plugin",
53
+ "netlify"
54
+ ],
55
+ "homepage": "https://github.com/netlify/build",
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "https://github.com/netlify/build.git",
59
+ "directory": "packages/build"
23
60
  },
24
- "repository": "https://github.com/netlify/build",
25
61
  "bugs": {
26
62
  "url": "https://github.com/netlify/build/issues"
27
63
  },
28
64
  "license": "MIT",
29
65
  "dependencies": {
30
66
  "@bugsnag/js": "^7.0.0",
31
- "@netlify/cache-utils": "^0.4.1",
32
- "@netlify/config": "^0.12.0",
33
- "@netlify/functions-utils": "^0.2.4",
34
- "@netlify/git-utils": "^0.2.2",
35
- "@netlify/run-utils": "^0.1.1",
36
- "@netlify/zip-it-and-ship-it": "^0.4.0-19",
37
- "analytics": "0.3.1",
38
- "array-flat-polyfill": "^1.0.1",
39
- "chalk": "^3.0.0",
40
- "clean-stack": "^2.2.0",
41
- "execa": "^3.3.0",
42
- "figures": "^3.2.0",
43
- "filter-obj": "^2.0.1",
44
- "global-cache-dir": "^1.0.1",
45
- "got": "^9.6.0",
46
- "indent-string": "^4.0.0",
47
- "is-ci": "^2.0.0",
48
- "is-plain-obj": "^2.1.0",
49
- "js-yaml": "^3.13.1",
50
- "locate-path": "^5.0.0",
51
- "log-process-errors": "^5.1.2",
52
- "make-dir": "^3.0.2",
53
- "map-obj": "^4.1.0",
54
- "netlify": "^4.1.7",
55
- "os-name": "^3.1.0",
56
- "p-event": "^4.1.0",
57
- "p-reduce": "^2.1.0",
58
- "path-exists": "^4.0.0",
59
- "pkg-dir": "^4.2.0",
60
- "pretty-ms": "^6.0.1",
61
- "read-pkg-up": "^7.0.1",
67
+ "@netlify/cache-utils": "^5.1.3",
68
+ "@netlify/config": "^20.4.1",
69
+ "@netlify/edge-bundler": "8.13.2",
70
+ "@netlify/framework-info": "^9.8.6",
71
+ "@netlify/functions-utils": "^5.2.3",
72
+ "@netlify/git-utils": "^5.1.1",
73
+ "@netlify/plugins-list": "^6.68.0",
74
+ "@netlify/run-utils": "^5.1.0",
75
+ "@netlify/zip-it-and-ship-it": "9.2.1",
76
+ "@sindresorhus/slugify": "^2.0.0",
77
+ "ansi-escapes": "^6.0.0",
78
+ "chalk": "^5.0.0",
79
+ "clean-stack": "^4.0.0",
80
+ "execa": "^6.0.0",
81
+ "figures": "^4.0.0",
82
+ "filter-obj": "^3.0.0",
83
+ "got": "^12.0.0",
84
+ "hot-shots": "9.3.0",
85
+ "indent-string": "^5.0.0",
86
+ "is-plain-obj": "^4.0.0",
87
+ "js-yaml": "^4.0.0",
88
+ "keep-func-props": "^4.0.0",
89
+ "locate-path": "^7.0.0",
90
+ "log-process-errors": "^8.0.0",
91
+ "map-obj": "^5.0.0",
92
+ "memoize-one": "^6.0.0",
93
+ "os-name": "^5.0.0",
94
+ "p-event": "^5.0.0",
95
+ "p-every": "^2.0.0",
96
+ "p-filter": "^3.0.0",
97
+ "p-locate": "^6.0.0",
98
+ "p-reduce": "^3.0.0",
99
+ "path-exists": "^5.0.0",
100
+ "path-type": "^5.0.0",
101
+ "pkg-dir": "^6.0.0",
102
+ "pretty-ms": "^8.0.0",
103
+ "ps-list": "^8.0.0",
104
+ "read-pkg-up": "^9.0.0",
62
105
  "readdirp": "^3.4.0",
63
106
  "resolve": "^2.0.0-next.1",
64
- "semver": "^7.1.3",
65
- "string-width": "^4.2.0",
66
- "strip-ansi": "^6.0.0",
67
- "update-notifier": "^4.1.0",
68
- "uuid": "^7.0.2",
69
- "yargs": "^15.3.1"
107
+ "rfdc": "^1.3.0",
108
+ "safe-json-stringify": "^1.2.0",
109
+ "semver": "^7.0.0",
110
+ "string-width": "^5.0.0",
111
+ "strip-ansi": "^7.0.0",
112
+ "supports-color": "^9.0.0",
113
+ "terminal-link": "^3.0.0",
114
+ "tmp-promise": "^3.0.2",
115
+ "ts-node": "^10.6.0",
116
+ "typescript": "^5.0.0",
117
+ "uuid": "^8.0.0",
118
+ "yargs": "^17.6.0"
70
119
  },
71
120
  "devDependencies": {
121
+ "@netlify/nock-udp": "^3.1.2",
122
+ "@types/node": "^18.14.2",
72
123
  "atob": "^2.1.2",
73
- "ava": "^2.4.0",
74
- "cp-file": "^7.0.0",
124
+ "ava": "^4.0.0",
125
+ "c8": "^7.12.0",
126
+ "copyfiles": "^2.4.1",
75
127
  "cpy": "^8.1.0",
76
- "del": "^5.1.0",
77
- "get-bin-path": "^4.0.1",
78
- "get-node": "^6.6.0",
79
- "has-ansi": "^4.0.0",
80
- "nock": "^11.9.1",
81
- "path-key": "^3.1.1",
128
+ "del": "^6.0.0",
129
+ "fast-safe-stringify": "^2.0.7",
130
+ "get-bin-path": "^6.0.0",
131
+ "get-node": "^12.0.0",
132
+ "get-port": "^6.0.0",
133
+ "get-stream": "^6.0.0",
134
+ "has-ansi": "^5.0.0",
135
+ "moize": "^6.0.0",
136
+ "path-key": "^4.0.0",
137
+ "process-exists": "^5.0.0",
138
+ "sinon": "^13.0.0",
139
+ "tsd": "^0.24.1",
82
140
  "yarn": "^1.22.4"
83
141
  },
84
142
  "engines": {
85
- "node": ">=8.3.0"
143
+ "node": "^14.16.0 || >=16.0.0"
144
+ },
145
+ "tsd": {
146
+ "compilerOptions": {
147
+ "module": "commonjs"
148
+ }
86
149
  }
87
150
  }
@@ -0,0 +1,52 @@
1
+ /* eslint-disable camelcase -- some properties are named in snake case in this API */
2
+
3
+ export interface Build {
4
+ /**
5
+ * Includes a site's [build command](https://docs.netlify.com/configure-builds/get-started/#definitions)
6
+ */
7
+ command?: string
8
+
9
+ /**
10
+ * the path to your static content folder
11
+ */
12
+ publish: string
13
+ base: string
14
+ services: Record<string, unknown>
15
+
16
+ /**
17
+ * Allows specifying a Bash command that will be run from the base directory to determine whether the site needs rebuilding or not.
18
+ * Check out our [ignore builds](https://docs.netlify.com/configure-builds/common-configurations/ignore-builds/) doc for more information on the default ignore behavior and details about constructing a custom ignore command.
19
+ */
20
+ ignore?: string
21
+
22
+ /**
23
+ * Includes the path to a site's [Edge Handlers directory](https://docs.netlify.com/edge-handlers/configure-and-build/#choose-an-edge-handlers-directory)
24
+ */
25
+ edge_handlers?: string
26
+ /**
27
+ * Contains a site's [environment variables](https://docs.netlify.com/configure-builds/environment-variables/#netlify-configuration-variables)
28
+ */
29
+ environment: Partial<Record<string, string>>
30
+ /**
31
+ * Includes options for [post processing](https://docs.netlify.com/configure-builds/file-based-configuration/#post-processing) HTML, CSS, JavaScript, and images
32
+ */
33
+ processing: {
34
+ skip_processing?: boolean
35
+ css: {
36
+ bundle?: boolean
37
+ minify?: boolean
38
+ }
39
+ js: {
40
+ bundle?: boolean
41
+ minify?: boolean
42
+ }
43
+ html: {
44
+ pretty_url?: boolean
45
+ }
46
+ images: {
47
+ compress?: boolean
48
+ }
49
+ }
50
+ }
51
+
52
+ /* eslint-enable camelcase */
@@ -0,0 +1,36 @@
1
+ type GlobPattern = string
2
+
3
+ /* eslint-disable camelcase -- some properties are named in snake case in this API */
4
+ type FunctionsObject = {
5
+ /**
6
+ * a list of additional paths to include in the function bundle. Although our build system includes statically referenced files (like `import * from "./some-file.js"`) by default, `included_files` lets you specify additional files or directories and reference them dynamically in function code. You can use `*` to match any character or prefix an entry with `!` to exclude files. Paths are relative to the [base directory](https://docs.netlify.com/configure-builds/get-started/#definitions-1).
7
+ */
8
+ included_files?: string[]
9
+ } & (
10
+ | {
11
+ /**
12
+ * the function bundling method used in [`@netlify/zip-it-and-ship-it`](https://github.com/netlify/zip-it-and-ship-it).
13
+ */
14
+ node_bundler?: 'zisi' | 'nft'
15
+ }
16
+ | {
17
+ /**
18
+ * the function bundling method used in [`@netlify/zip-it-and-ship-it`](https://github.com/netlify/zip-it-and-ship-it).
19
+ */
20
+ node_bundler?: 'esbuild' | 'none'
21
+
22
+ /**
23
+ * a list of Node.js modules that are copied to the bundled artifact without adjusting their source or references during the bundling process.
24
+ * This property helps handle dependencies that can’t be inlined, such as modules with native add-ons.
25
+ */
26
+ external_node_modules?: string[]
27
+
28
+ ignored_node_modules?: string[]
29
+ }
30
+ )
31
+ /* eslint-enable camelcase */
32
+
33
+ export type Functions = {
34
+ '*': FunctionsObject
35
+ [pattern: GlobPattern]: FunctionsObject
36
+ }
@@ -0,0 +1,7 @@
1
+ import { JSONValue } from '../utils/json_value'
2
+
3
+ // Helper type to be used as a workaround for the fact that `interface`s don't have implicit
4
+ // index signatures: https://github.com/microsoft/TypeScript/issues/15300
5
+ export type StringKeys<TObject extends object> = keyof TObject & string
6
+
7
+ export type PluginInputs<Keys extends string = string> = Partial<Record<Keys, JSONValue>>
@@ -0,0 +1,58 @@
1
+ import { Many } from '../utils/many'
2
+
3
+ import { Build } from './build'
4
+ import { Functions } from './functions'
5
+ import { PluginInputs } from './inputs'
6
+
7
+ type HttpStatusCode = number
8
+
9
+ interface Redirect {
10
+ from: string
11
+ to?: string
12
+ status?: HttpStatusCode
13
+ force?: boolean
14
+ signed?: string
15
+ query?: Partial<Record<string, string>>
16
+ headers?: Partial<Record<string, string>>
17
+ conditions?: Partial<Record<'Language' | 'Role' | 'Country' | 'Cookie', readonly string[]>>
18
+ }
19
+
20
+ interface Header {
21
+ for: string
22
+ values: Partial<Record<string, Many<string, 'mutable'>>>
23
+ }
24
+
25
+ interface EdgeFunction {
26
+ path?: `/${string}`
27
+ function: string
28
+ }
29
+
30
+ interface NetlifyPlugin {
31
+ package: string
32
+ inputs: PluginInputs
33
+ }
34
+
35
+ /* eslint-disable camelcase -- some properties are named in snake case in this API */
36
+
37
+ interface NetlifyConfig {
38
+ /**
39
+ * array of redirects with their modifiable options
40
+ */
41
+ redirects: Redirect[]
42
+ /**
43
+ * array of headers with their modifiable options
44
+ */
45
+ headers: Header[]
46
+ /**
47
+ * array of Edge Functions with their modifiable options
48
+ */
49
+ edge_functions: EdgeFunction[]
50
+ /**
51
+ * object with options for modifying [functions](https://docs.netlify.com/configure-builds/file-based-configuration/#functions)
52
+ */
53
+ functions: Functions
54
+ build: Build
55
+ plugins: readonly NetlifyPlugin[]
56
+ }
57
+
58
+ /* eslint-enable camelcase */
@@ -0,0 +1,7 @@
1
+ export { NetlifyPlugin } from './netlify_plugin'
2
+ export { NetlifyPluginOptions } from './netlify_plugin_options'
3
+ export { OnBuild, OnEnd, OnError, OnPostBuild, OnPreBuild, OnSuccess } from './netlify_event_handler'
4
+ export { NetlifyConfig } from './config/netlify_config'
5
+ export { NetlifyPluginUtils } from './options'
6
+ export { NetlifyPluginConstants } from './netlify_plugin_constants'
7
+ export { ListedFunction, ListedFunctionFile } from './options/netlify_plugin_functions_util'
@@ -0,0 +1,29 @@
1
+ import { PluginInputs, StringKeys } from './config/inputs'
2
+ import { NetlifyPluginOptions } from './netlify_plugin_options'
3
+
4
+ interface NetlifyEventHandler<PluginOptions extends NetlifyPluginOptions = NetlifyPluginOptions> {
5
+ (options: PluginOptions): void | Promise<void>
6
+ }
7
+
8
+ // To allow interfaces to be used as generics, since they lack implicit index signatures, we have to do some type shenanigans
9
+ // to get TypeScript to behave as we want - only letting the keys of `TInputs` through, and thus not requiring a full index
10
+ // signature on `TInputs`.
11
+ // Related issues: https://github.com/microsoft/TypeScript/issues/15300, https://github.com/netlify/build/issues/3838
12
+ export type OnPreBuild<TInputs extends PluginInputs<StringKeys<TInputs>> = PluginInputs> = NetlifyEventHandler<
13
+ NetlifyPluginOptions<TInputs>
14
+ >
15
+ export type OnBuild<TInputs extends PluginInputs<StringKeys<TInputs>> = PluginInputs> = NetlifyEventHandler<
16
+ NetlifyPluginOptions<TInputs>
17
+ >
18
+ export type OnPostBuild<TInputs extends PluginInputs<StringKeys<TInputs>> = PluginInputs> = NetlifyEventHandler<
19
+ NetlifyPluginOptions<TInputs>
20
+ >
21
+ export type OnError<TInputs extends PluginInputs<StringKeys<TInputs>> = PluginInputs> = NetlifyEventHandler<
22
+ NetlifyPluginOptions<TInputs> & { error: Error }
23
+ >
24
+ export type OnSuccess<TInputs extends PluginInputs<StringKeys<TInputs>> = PluginInputs> = NetlifyEventHandler<
25
+ NetlifyPluginOptions<TInputs>
26
+ >
27
+ export type OnEnd<TInputs extends PluginInputs<StringKeys<TInputs>> = PluginInputs> = NetlifyEventHandler<
28
+ NetlifyPluginOptions<TInputs> & { error?: Error }
29
+ >