UNPKG

1.78 kBMarkdownView Raw
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
4Utility for handling Netlify Functions in Netlify Build plugins.
5
6This 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
15export 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
26Returns the list of Netlify Functions main files as a Promise resolving to an array of objects with the following
27properties:
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
35This 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
41Same as `list()` except it also returns the files required by the Functions main files. This is much slower. The object
42have 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
51Add a Functions file or directory to a build.
52
53This throws when no `functions` directory was specified by the user, or when it points to a non-existing directory.