@netlify/functions-utils 2.0.1 → 4.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.
- package/package.json +8 -7
- package/src/main.js +12 -30
package/package.json
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/functions-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Utility for adding Functions files in Netlify Build",
|
|
5
|
-
"
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": "./src/main.js",
|
|
7
|
+
"main": "./src/main.js",
|
|
6
8
|
"files": [
|
|
7
9
|
"src/**/*.js"
|
|
8
10
|
],
|
|
9
11
|
"author": "Netlify Inc.",
|
|
10
12
|
"scripts": {
|
|
11
|
-
"prepublishOnly": "cd ../../ && npm run prepublishOnly"
|
|
12
13
|
},
|
|
13
14
|
"keywords": [
|
|
14
15
|
"nodejs",
|
|
@@ -43,18 +44,18 @@
|
|
|
43
44
|
},
|
|
44
45
|
"license": "MIT",
|
|
45
46
|
"dependencies": {
|
|
46
|
-
"@netlify/zip-it-and-ship-it": "^
|
|
47
|
+
"@netlify/zip-it-and-ship-it": "^5.2.0",
|
|
47
48
|
"cpy": "^8.1.0",
|
|
48
49
|
"path-exists": "^4.0.0"
|
|
49
50
|
},
|
|
50
51
|
"devDependencies": {
|
|
51
|
-
"ava": "^
|
|
52
|
+
"ava": "^3.15.0",
|
|
52
53
|
"del": "^5.1.0",
|
|
53
|
-
"sinon": "^
|
|
54
|
+
"sinon": "^12.0.0",
|
|
54
55
|
"sort-on": "^4.1.0",
|
|
55
56
|
"tmp-promise": "^3.0.0"
|
|
56
57
|
},
|
|
57
58
|
"engines": {
|
|
58
|
-
"node": ">=
|
|
59
|
+
"node": "^12.20.0 || ^14.14.0 || >=16.0.0"
|
|
59
60
|
}
|
|
60
61
|
}
|
package/src/main.js
CHANGED
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
import { stat } from 'fs'
|
|
2
|
+
import { basename, dirname } from 'path'
|
|
3
|
+
import { promisify } from 'util'
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const cpy = require('cpy')
|
|
8
|
-
const pathExists = require('path-exists')
|
|
5
|
+
import { listFunctions, listFunctionsFiles } from '@netlify/zip-it-and-ship-it'
|
|
6
|
+
import cpy from 'cpy'
|
|
7
|
+
import pathExists from 'path-exists'
|
|
9
8
|
|
|
10
9
|
const pStat = promisify(stat)
|
|
11
10
|
|
|
12
11
|
// Add a Netlify Function file to the `functions` directory so it is processed
|
|
13
12
|
// by `@netlify/plugin-functions-core`
|
|
14
|
-
const add = async function (src, dist, { fail = defaultFail } = {}) {
|
|
13
|
+
export const add = async function (src, dist, { fail = defaultFail } = {}) {
|
|
15
14
|
if (src === undefined) {
|
|
16
15
|
return fail('No function source directory was specified')
|
|
17
16
|
}
|
|
@@ -25,13 +24,8 @@ const add = async function (src, dist, { fail = defaultFail } = {}) {
|
|
|
25
24
|
}
|
|
26
25
|
|
|
27
26
|
const srcBasename = basename(src)
|
|
28
|
-
const functionsDist = `${dist}/${srcBasename}`
|
|
29
|
-
if (await pathExists(functionsDist)) {
|
|
30
|
-
return fail(`Function file or directory already exists at "${functionsDist}"`)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
27
|
const srcGlob = await getSrcGlob(src, srcBasename)
|
|
34
|
-
await cpy(srcGlob, dist, { cwd: dirname(src), parents: true, overwrite:
|
|
28
|
+
await cpy(srcGlob, dist, { cwd: dirname(src), parents: true, overwrite: true })
|
|
35
29
|
}
|
|
36
30
|
|
|
37
31
|
const getSrcGlob = async function (src, srcBasename) {
|
|
@@ -44,16 +38,11 @@ const getSrcGlob = async function (src, srcBasename) {
|
|
|
44
38
|
return srcBasename
|
|
45
39
|
}
|
|
46
40
|
|
|
47
|
-
const list = async function (functionsSrc, { fail = defaultFail } = {}) {
|
|
48
|
-
if (functionsSrc === undefined) {
|
|
41
|
+
export const list = async function (functionsSrc, { fail = defaultFail } = {}) {
|
|
42
|
+
if (functionsSrc === undefined || functionsSrc.length === 0) {
|
|
49
43
|
return fail('No function directory was specified')
|
|
50
44
|
}
|
|
51
45
|
|
|
52
|
-
// This package currently supports Node 8 but not zip-it-and-ship-it
|
|
53
|
-
// @todo put the `require()` to the top-level scope again once Node 8 support
|
|
54
|
-
// is removed
|
|
55
|
-
// eslint-disable-next-line node/global-require
|
|
56
|
-
const { listFunctions } = require('@netlify/zip-it-and-ship-it')
|
|
57
46
|
try {
|
|
58
47
|
return await listFunctions(functionsSrc)
|
|
59
48
|
} catch (error) {
|
|
@@ -61,16 +50,11 @@ const list = async function (functionsSrc, { fail = defaultFail } = {}) {
|
|
|
61
50
|
}
|
|
62
51
|
}
|
|
63
52
|
|
|
64
|
-
const listAll = async function (functionsSrc, { fail = defaultFail } = {}) {
|
|
65
|
-
if (functionsSrc === undefined) {
|
|
53
|
+
export const listAll = async function (functionsSrc, { fail = defaultFail } = {}) {
|
|
54
|
+
if (functionsSrc === undefined || functionsSrc.length === 0) {
|
|
66
55
|
return fail('No function directory was specified')
|
|
67
56
|
}
|
|
68
57
|
|
|
69
|
-
// This package currently supports Node 8 but not zip-it-and-ship-it
|
|
70
|
-
// @todo put the `require()` to the top-level scope again once Node 8 support
|
|
71
|
-
// is removed
|
|
72
|
-
// eslint-disable-next-line node/global-require
|
|
73
|
-
const { listFunctionsFiles } = require('@netlify/zip-it-and-ship-it')
|
|
74
58
|
try {
|
|
75
59
|
return await listFunctionsFiles(functionsSrc)
|
|
76
60
|
} catch (error) {
|
|
@@ -81,5 +65,3 @@ const listAll = async function (functionsSrc, { fail = defaultFail } = {}) {
|
|
|
81
65
|
const defaultFail = function (message) {
|
|
82
66
|
throw new Error(message)
|
|
83
67
|
}
|
|
84
|
-
|
|
85
|
-
module.exports = { add, list, listAll }
|