1 | [![Coverage Status](https://codecov.io/gh/netlify/build/branch/main/graph/badge.svg)](https://codecov.io/gh/netlify/build)
|
2 | [![Build](https://github.com/netlify/build/workflows/Build/badge.svg)](https://github.com/netlify/build/actions)
|
3 |
|
4 | Utility for handling Netlify Functions in Netlify Build plugins.
|
5 |
|
6 | This allows plugins to:
|
7 |
|
8 | - list available Netlify Functions
|
9 | - dynamically inject Netlify Functions inside users builds.
|
10 |
|
11 | # Example
|
12 |
|
13 | ```js
|
14 | // Add a Netlify Functions file or directory to a build
|
15 | export const onPreBuild = async function ({ utils }) {
|
16 | await utils.functions.add('./path/to/function')
|
17 | }
|
18 | ```
|
19 |
|
20 | # API
|
21 |
|
22 | ## list()
|
23 |
|
24 | _Returns_: `Promise<object[]>`
|
25 |
|
26 | Returns the list of Netlify Functions main files as a Promise resolving to an array of objects with the following
|
27 | properties:
|
28 |
|
29 | - `name` `{string}`: Function name, as used in the URL `https://{hostname}/.netlify/functions/{name}`
|
30 | - `mainFile` `{string}`: absolute path to the Function's main file
|
31 | - `extension` `{string}`: file extension of the Function's main file. For Go Functions, this might be an empty string.
|
32 | For Node.js Functions, this is either `.js` or `.zip`.
|
33 | - `runtime` `"js" | "go"`: Function's programming language
|
34 |
|
35 | This throws when no `functions` directory was specified by the user, or when it points to a non-existing directory.
|
36 |
|
37 | ## listAll()
|
38 |
|
39 | _Returns_: `Promise<object[]>`
|
40 |
|
41 | Same as `list()` except it also returns the files required by the Functions main files. This is much slower. The object
|
42 | have the following additional member:
|
43 |
|
44 | - `srcFile` `{string}`: absolute path to the file
|
45 |
|
46 | ## add(path)
|
47 |
|
48 | `path`: `string`\
|
49 | _Returns_: `Promise`
|
50 |
|
51 | Add a Functions file or directory to a build.
|
52 |
|
53 | This throws when no `functions` directory was specified by the user, or when it points to a non-existing directory.
|