@netlify/build 18.13.12 → 18.15.1

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 (48) hide show
  1. package/package.json +4 -2
  2. package/src/core/config.js +1 -1
  3. package/src/core/constants.js +1 -1
  4. package/src/core/dry.js +10 -10
  5. package/src/core/feature_flags.js +1 -0
  6. package/src/core/flags.js +2 -2
  7. package/src/core/main.js +21 -21
  8. package/src/error/parse/location.js +3 -3
  9. package/src/error/type.js +4 -4
  10. package/src/log/messages/{core_commands.js → core_steps.js} +0 -0
  11. package/src/log/messages/dry.js +14 -14
  12. package/src/log/messages/steps.js +32 -0
  13. package/src/log/stream.js +2 -2
  14. package/src/plugins/child/load.js +5 -5
  15. package/src/plugins/child/run.js +2 -2
  16. package/src/plugins/load.js +9 -9
  17. package/src/plugins_core/build_command.js +7 -7
  18. package/src/plugins_core/deploy/buildbot_client.js +1 -3
  19. package/src/plugins_core/deploy/index.js +5 -5
  20. package/src/plugins_core/functions/index.js +8 -11
  21. package/src/status/success.js +5 -7
  22. package/src/{commands/core_command.js → steps/core_step.js} +7 -7
  23. package/src/{commands → steps}/error.js +5 -5
  24. package/src/steps/get.js +35 -0
  25. package/src/{commands → steps}/plugin.js +5 -5
  26. package/src/{commands → steps}/return.js +10 -10
  27. package/src/{commands/run_command.js → steps/run_step.js} +38 -38
  28. package/src/{commands/run_commands.js → steps/run_steps.js} +19 -19
  29. package/src/{commands → steps}/update_config.js +0 -0
  30. package/src/telemetry/main.js +4 -4
  31. package/types/config/build.d.ts +61 -0
  32. package/types/config/functions.d.ts +38 -0
  33. package/types/config/netlify_config.d.ts +51 -0
  34. package/types/index.d.ts +3 -0
  35. package/types/netlify_event.d.ts +5 -0
  36. package/types/netlify_plugin.d.ts +29 -0
  37. package/types/netlify_plugin_options.d.ts +56 -0
  38. package/types/options/index.d.ts +1 -0
  39. package/types/options/netlify_plugin_build_util.d.ts +7 -0
  40. package/types/options/netlify_plugin_cache_util.d.ts +39 -0
  41. package/types/options/netlify_plugin_git_util.d.ts +41 -0
  42. package/types/options/netlify_plugin_run_util.d.ts +24 -0
  43. package/types/options/netlify_plugin_status_util.d.ts +24 -0
  44. package/types/options/netlify_plugin_utils.d.ts +13 -0
  45. package/types/utils/json_value.d.ts +1 -0
  46. package/types/utils/many.d.ts +6 -0
  47. package/src/commands/get.js +0 -35
  48. package/src/log/messages/commands.js +0 -32
@@ -0,0 +1,51 @@
1
+ import { Many } from '../utils/many'
2
+
3
+ import { Build } from './build'
4
+ import { Functions } from './functions'
5
+
6
+ type HttpStatusCode = number
7
+
8
+ interface Redirect {
9
+ from: string
10
+ to: string
11
+ status?: HttpStatusCode
12
+ force: boolean
13
+ signed?: string
14
+ query: Partial<Record<string, string>>
15
+ headers: Partial<Record<string, string>>
16
+ conditions: Record<'language' | 'role' | 'country', readonly string[]>
17
+ }
18
+
19
+ interface Header {
20
+ for: string
21
+ values: Partial<Record<string, Many<string, 'mutable'>>>
22
+ }
23
+
24
+ interface EdgeHandler {
25
+ path?: `/${string}`
26
+ handler: string
27
+ }
28
+
29
+ /* eslint-disable camelcase -- some properties are named in snake case in this API */
30
+
31
+ interface NetlifyConfig {
32
+ /**
33
+ * array of redirects with their modifiable options
34
+ */
35
+ redirects: Redirect[]
36
+ /**
37
+ * array of headers with their modifiable options
38
+ */
39
+ headers: Header[]
40
+ /**
41
+ * array of Edge Handlers with their modifiable options
42
+ */
43
+ edge_handlers: EdgeHandler[]
44
+ /**
45
+ * object with options for modifying [functions](https://docs.netlify.com/configure-builds/file-based-configuration/#functions)
46
+ */
47
+ functions: Functions
48
+ build: Build
49
+ }
50
+
51
+ /* eslint-enable camelcase */
@@ -0,0 +1,3 @@
1
+ export * from './netlify_event'
2
+ export * from './netlify_plugin'
3
+ export * from './netlify_plugin_options'
@@ -0,0 +1,5 @@
1
+ import { NetlifyPluginOptions } from './netlify_plugin_options'
2
+
3
+ export interface NetlifyEvent<PluginOptions extends NetlifyPluginOptions = NetlifyPluginOptions> {
4
+ (options: PluginOptions): void | Promise<void>
5
+ }
@@ -0,0 +1,29 @@
1
+ import { NetlifyEvent } from './netlify_event'
2
+ import { NetlifyPluginOptions } from './netlify_plugin_options'
3
+
4
+ export interface NetlifyPlugin {
5
+ /**
6
+ * Runs before the build command is executed.
7
+ */
8
+ onPreBuild?: NetlifyEvent
9
+ /**
10
+ * runs directly after the build command is executed and before Functions? bundling and Edge Handlers bundling.
11
+ */
12
+ onBuild?: NetlifyEvent
13
+ /**
14
+ * runs after the build command completes; after onBuild? tasks, Functions? bundling, and Edge Handlers bundling are executed; and before the deploy stage. Can be used to prevent a build from being deployed.
15
+ */
16
+ onPostBuild?: NetlifyEvent
17
+ /**
18
+ * runs when an error occurs in the build or deploy stage, failing the build. Can’t be used to prevent a build from being deployed.
19
+ */
20
+ onError?: NetlifyEvent<NetlifyPluginOptions & { error: Error }>
21
+ /**
22
+ * runs when the deploy succeeds. Can’t be used to prevent a build from being deployed.
23
+ */
24
+ onSuccess?: NetlifyEvent
25
+ /**
26
+ * runs after completion of the deploy stage, regardless of build error or success; is useful for resources cleanup. Can’t be used to prevent a build from being deployed.
27
+ */
28
+ onEnd?: NetlifyEvent<NetlifyPluginOptions & { error?: Error }>
29
+ }
@@ -0,0 +1,56 @@
1
+ import { NetlifyConfig } from './config/netlify_config'
2
+ import { NetlifyPluginUtils } from './options/netlify_plugin_utils'
3
+
4
+ export interface NetlifyPluginOptions {
5
+ constants: {
6
+ /**
7
+ * path to the Netlify configuration file.
8
+ * `undefined` if none was used.
9
+ */
10
+ CONFIG_PATH?: string
11
+ /**
12
+ * directory that contains the deploy-ready HTML files and assets generated by the build. Its value is always defined, but the target might not have been created yet.
13
+ */
14
+ PUBLISH_DIR: string
15
+ /**
16
+ * the directory where function source code lives.
17
+ * `undefined` if no `netlify/functions` directory exists in the base directory and if not specified by the user.
18
+ */
19
+ FUNCTIONS_SRC?: string
20
+ /**
21
+ * the directory where built serverless functions are placed before deployment. Its value is always defined, but the target might not have been created yet.
22
+ */
23
+ FUNCTIONS_DIST: string
24
+ /**
25
+ * the directory where Edge Handlers source code lives.
26
+ * `undefined` if no `netlify/edge-handlers` directory exists in the base directory and if not specified in `netlify.toml`.
27
+ */
28
+ EDGE_HANDLERS_SRC?: string
29
+ /**
30
+ * boolean indicating whether the build was [run locally](https://docs.netlify.com/cli/get-started/#run-builds-locally) or on Netlify
31
+ */
32
+ IS_LOCAL: boolean
33
+ /**
34
+ * version of Netlify Build as a `major.minor.patch` string
35
+ */
36
+ NETLIFY_BUILD_VERSION: string
37
+ /**
38
+ * the Netlify site ID
39
+ */
40
+ SITE_ID: string
41
+ }
42
+ /**
43
+ * If your plugin requires additional values from the user, you can specify these requirements in an `inputs` array in the plugin’s [`manifest.yml` file](https://docs.netlify.com/configure-builds/build-plugins/create-plugins/#anatomy-of-a-plugin).
44
+ */
45
+ inputs: Partial<Record<string, string>>
46
+ /**
47
+ * @see https://docs.netlify.com/configure-builds/build-plugins/create-plugins/#netlifyconfig
48
+ */
49
+ netlifyConfig: NetlifyConfig
50
+ /**
51
+ * When an event handler executes, the contents of the `package.json` in a site's base directory get passed to a plugin.
52
+ * The data fields are normalized to prevent plugin errors. If the site has no `package.json`, the argument is an empty object.
53
+ */
54
+ packageJson: Partial<Record<string, string>>
55
+ utils: NetlifyPluginUtils
56
+ }
@@ -0,0 +1 @@
1
+ export * from './netlify_plugin_utils'
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Report errors or cancel builds
3
+ */
4
+ export type NetlifyPluginBuildUtil = Record<
5
+ 'failBuild' | 'failPlugin' | 'cancelBuild',
6
+ (message: string, options?: { error: Error }) => void
7
+ >
@@ -0,0 +1,39 @@
1
+ import { Many } from '../utils/many'
2
+
3
+ /**
4
+ * Cache files between builds
5
+ */
6
+ export type NetlifyPluginCacheUtil = {
7
+ save(
8
+ path: Many<string>,
9
+ options?: {
10
+ ttl?: number
11
+ digests?: string[]
12
+ /**
13
+ * @default `process.cwd()`
14
+ */
15
+ cwd?: string
16
+ },
17
+ ): Promise<boolean>
18
+ list(options: {
19
+ /**
20
+ * @default `process.cwd()`
21
+ */
22
+ cwd?: string
23
+ /**
24
+ * @default 1
25
+ */
26
+ depth?: number
27
+ }): Promise<string[]>
28
+ } & Record<
29
+ 'restore' | 'remove' | 'has',
30
+ (
31
+ path: Many<string>,
32
+ options?: {
33
+ /**
34
+ * @default `process.cwd()`
35
+ */
36
+ cwd?: string
37
+ },
38
+ ) => Promise<boolean>
39
+ >
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Retrieve Git-related information such as the list of modified/created/deleted files
3
+ * @see https://github.com/netlify/build/blob/master/packages/git-utils/README.md
4
+ */
5
+ export interface NetlifyPluginGitUtil {
6
+ fileMatch(globPattern: string): readonly string[]
7
+ /**
8
+ * Array of all modified files.
9
+ */
10
+ modifiedFiles: readonly string[]
11
+ /**
12
+ * Array of all created files.
13
+ */
14
+ createdFiles: readonly string[]
15
+ /**
16
+ * Array of all deleted files.
17
+ */
18
+ deletedFiles: readonly string[]
19
+ /**
20
+ * Array of commits with details.
21
+ */
22
+ commits: ReadonlyArray<{
23
+ sha: string
24
+ parents: string
25
+ author: {
26
+ name: string
27
+ email: string
28
+ date: string
29
+ }
30
+ committer: {
31
+ name: string
32
+ email: string
33
+ date: string
34
+ }
35
+ message: string
36
+ }>
37
+ /**
38
+ * How many lines of code have changed
39
+ */
40
+ linesOfCode(): Promise<number>
41
+ }
@@ -0,0 +1,24 @@
1
+ import { Options as ExecaOptions, ExecaChildProcess } from 'execa'
2
+
3
+ type NetlifyPluginRunUtilOptions = Omit<ExecaOptions, 'preferLocal'> & {
4
+ /**
5
+ * @default true
6
+ */
7
+ preferLocal?: ExecaOptions['preferLocal']
8
+ }
9
+
10
+ type NetlifyPluginRunUtilResult = ExecaChildProcess
11
+
12
+ /**
13
+ * Run commands and processes
14
+ * @see https://github.com/netlify/build/blob/master/packages/run-utils/README.md
15
+ */
16
+ export interface NetlifyPluginRunUtil {
17
+ (
18
+ file: string,
19
+ // eslint-disable-next-line fp/no-arguments -- params are named `arguments` in the docs. Unrelated to JS's `arguments`
20
+ arguments?: readonly string[],
21
+ options?: NetlifyPluginRunUtilOptions,
22
+ ): Promise<NetlifyPluginRunUtilResult>
23
+ command(command: string, options?: NetlifyPluginRunUtilOptions): Promise<NetlifyPluginRunUtilResult>
24
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Display information in the deploy summary
3
+ */
4
+ export interface NetlifyPluginStatusUtil {
5
+ /**
6
+ * Only one status is shown per plugin.
7
+ * Calling `utils.status.show()` twice overrides the previous status.
8
+ */
9
+ show(options: {
10
+ /**
11
+ * Default to the plugin's name followed by a generic title.
12
+ */
13
+ title?: string
14
+ /**
15
+ * Message below the title
16
+ */
17
+ summary: string
18
+ /**
19
+ * Detailed information shown in a collapsible section.
20
+ * @default ""
21
+ */
22
+ text?: string
23
+ }): void
24
+ }
@@ -0,0 +1,13 @@
1
+ import { NetlifyPluginBuildUtil } from './netlify_plugin_build_util'
2
+ import { NetlifyPluginCacheUtil } from './netlify_plugin_cache_util'
3
+ import { NetlifyPluginGitUtil } from './netlify_plugin_git_util'
4
+ import { NetlifyPluginRunUtil } from './netlify_plugin_run_util'
5
+ import { NetlifyPluginStatusUtil } from './netlify_plugin_status_util'
6
+
7
+ export interface NetlifyPluginUtils {
8
+ build: NetlifyPluginBuildUtil
9
+ status: NetlifyPluginStatusUtil
10
+ cache: NetlifyPluginCacheUtil
11
+ run: NetlifyPluginRunUtil
12
+ git: NetlifyPluginGitUtil
13
+ }
@@ -0,0 +1 @@
1
+ export type JSONValue = string | number | boolean | null | { [key: string]: JSONValue } | Array<JSONValue>
@@ -0,0 +1,6 @@
1
+ type ArrayByMode<T, Mode extends 'immutable' | 'mutable' = 'immutable'> = {
2
+ immutable: readonly T[]
3
+ mutable: T[]
4
+ }[Mode]
5
+
6
+ export type Many<T, Mode extends 'immutable' | 'mutable' = 'immutable'> = T | ArrayByMode<T, Mode>
@@ -1,35 +0,0 @@
1
- 'use strict'
2
-
3
- const { EVENTS } = require('../plugins/events')
4
- const { buildCommandCore } = require('../plugins_core/build_command')
5
- const { deploySite } = require('../plugins_core/deploy')
6
- const { bundleFunctions } = require('../plugins_core/functions')
7
-
8
- // Get commands for all events
9
- const getCommands = function (commands) {
10
- const commandsA = addCoreCommands(commands)
11
- const commandsB = sortCommands(commandsA)
12
- const events = getEvents(commandsB)
13
- return { commands: commandsB, events }
14
- }
15
-
16
- const addCoreCommands = function (commands) {
17
- return [buildCommandCore, ...commands, bundleFunctions, deploySite]
18
- }
19
-
20
- // Sort plugin commands by event order.
21
- const sortCommands = function (commands) {
22
- return EVENTS.flatMap((event) => commands.filter((command) => command.event === event))
23
- }
24
-
25
- // Retrieve list of unique events
26
- const getEvents = function (commands) {
27
- const events = commands.map(getEvent)
28
- return [...new Set(events)]
29
- }
30
-
31
- const getEvent = function ({ event }) {
32
- return event
33
- }
34
-
35
- module.exports = { getCommands }
@@ -1,32 +0,0 @@
1
- 'use strict'
2
-
3
- const { getLogHeaderFunc } = require('../header_func')
4
- const { log, logMessage } = require('../logger')
5
- const { THEME } = require('../theme')
6
-
7
- const logCommand = function ({ logs, event, packageName, coreCommandDescription, index, error, netlifyConfig }) {
8
- const description = getDescription({ coreCommandDescription, netlifyConfig, packageName, event })
9
- const logHeaderFunc = getLogHeaderFunc(error)
10
- logHeaderFunc(logs, `${index + 1}. ${description}`)
11
- logMessage(logs, '')
12
- }
13
-
14
- const getDescription = function ({ coreCommandDescription, netlifyConfig, packageName, event }) {
15
- return coreCommandDescription === undefined
16
- ? `${event} command from ${packageName}`
17
- : coreCommandDescription({ netlifyConfig })
18
- }
19
-
20
- const logBuildCommandStart = function (logs, buildCommand) {
21
- log(logs, THEME.highlightWords(`$ ${buildCommand}`))
22
- }
23
-
24
- const logCommandSuccess = function (logs) {
25
- logMessage(logs, '')
26
- }
27
-
28
- module.exports = {
29
- logCommand,
30
- logBuildCommandStart,
31
- logCommandSuccess,
32
- }