@netlify/functions-utils 4.2.10 → 4.2.11

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 (2) hide show
  1. package/lib/main.js +46 -57
  2. package/package.json +9 -4
package/lib/main.js CHANGED
@@ -1,64 +1,53 @@
1
- import { promises as fs } from 'fs'
2
- import { basename, dirname } from 'path'
3
-
4
- import { listFunctions, listFunctionsFiles } from '@netlify/zip-it-and-ship-it'
5
- import cpy from 'cpy'
6
- import { pathExists } from 'path-exists'
7
-
1
+ import { promises as fs } from 'fs';
2
+ import { basename, dirname } from 'path';
3
+ import { listFunctions, listFunctionsFiles } from '@netlify/zip-it-and-ship-it';
4
+ import cpy from 'cpy';
5
+ import { pathExists } from 'path-exists';
8
6
  // Add a Netlify Function file to the `functions` directory so it is processed
9
7
  // by `@netlify/plugin-functions-core`
10
8
  export const add = async function (src, dist, { fail = defaultFail } = {}) {
11
- if (src === undefined) {
12
- return fail('No function source directory was specified')
13
- }
14
-
15
- if (!(await pathExists(src))) {
16
- return fail(`No function file or directory found at "${src}"`)
17
- }
18
-
19
- if (dist === undefined) {
20
- return fail('No function directory was specified')
21
- }
22
-
23
- const srcBasename = basename(src)
24
- const srcGlob = await getSrcGlob(src, srcBasename)
25
- await cpy(srcGlob, dist, { cwd: dirname(src), parents: true, overwrite: true })
26
- }
27
-
9
+ if (src === undefined) {
10
+ return fail('No function source directory was specified');
11
+ }
12
+ if (!(await pathExists(src))) {
13
+ return fail(`No function file or directory found at "${src}"`);
14
+ }
15
+ if (dist === undefined) {
16
+ return fail('No function directory was specified');
17
+ }
18
+ const srcBasename = basename(src);
19
+ const srcGlob = await getSrcGlob(src, srcBasename);
20
+ await cpy(srcGlob, dist, { cwd: dirname(src), parents: true, overwrite: true });
21
+ };
28
22
  const getSrcGlob = async function (src, srcBasename) {
29
- const srcStat = await fs.stat(src)
30
-
31
- if (srcStat.isDirectory()) {
32
- return `${srcBasename}/**`
33
- }
34
-
35
- return srcBasename
36
- }
37
-
23
+ const srcStat = await fs.stat(src);
24
+ if (srcStat.isDirectory()) {
25
+ return `${srcBasename}/**`;
26
+ }
27
+ return srcBasename;
28
+ };
38
29
  export const list = async function (functionsSrc, { fail = defaultFail } = {}) {
39
- if (functionsSrc === undefined || functionsSrc.length === 0) {
40
- return fail('No function directory was specified')
41
- }
42
-
43
- try {
44
- return await listFunctions(functionsSrc)
45
- } catch (error) {
46
- fail('Could not list Netlify Functions', { error })
47
- }
48
- }
49
-
30
+ if (functionsSrc === undefined || functionsSrc.length === 0) {
31
+ return fail('No function directory was specified');
32
+ }
33
+ try {
34
+ return await listFunctions(functionsSrc);
35
+ }
36
+ catch (error) {
37
+ fail('Could not list Netlify Functions', { error });
38
+ }
39
+ };
50
40
  export const listAll = async function (functionsSrc, { fail = defaultFail } = {}) {
51
- if (functionsSrc === undefined || functionsSrc.length === 0) {
52
- return fail('No function directory was specified')
53
- }
54
-
55
- try {
56
- return await listFunctionsFiles(functionsSrc)
57
- } catch (error) {
58
- fail('Could not list Netlify Functions files', { error })
59
- }
60
- }
61
-
41
+ if (functionsSrc === undefined || functionsSrc.length === 0) {
42
+ return fail('No function directory was specified');
43
+ }
44
+ try {
45
+ return await listFunctionsFiles(functionsSrc);
46
+ }
47
+ catch (error) {
48
+ fail('Could not list Netlify Functions files', { error });
49
+ }
50
+ };
62
51
  const defaultFail = function (message) {
63
- throw new Error(message)
64
- }
52
+ throw new Error(message);
53
+ };
package/package.json CHANGED
@@ -1,18 +1,21 @@
1
1
  {
2
2
  "name": "@netlify/functions-utils",
3
- "version": "4.2.10",
3
+ "version": "4.2.11",
4
4
  "description": "Utility for adding Functions files in Netlify Build",
5
5
  "type": "module",
6
6
  "exports": "./lib/main.js",
7
7
  "main": "./lib/main.js",
8
+ "types": "./lib/main.d.ts",
8
9
  "files": [
9
10
  "lib/**/*.js"
10
11
  ],
11
12
  "author": "Netlify Inc.",
12
13
  "scripts": {
13
- "prepublishOnly": "cd ../../ && npm run prepublishOnly",
14
14
  "prebuild": "rm -rf lib",
15
- "build": "cp -a src lib/"
15
+ "build": "tsc",
16
+ "test": "ava",
17
+ "test:ci": "c8 -r lcovonly -r text -r json ava",
18
+ "test:measure": "node tools/tests_duration.mjs"
16
19
  },
17
20
  "keywords": [
18
21
  "nodejs",
@@ -53,6 +56,7 @@
53
56
  },
54
57
  "devDependencies": {
55
58
  "ava": "^4.0.0",
59
+ "c8": "^7.12.0",
56
60
  "del": "^6.0.0",
57
61
  "sinon": "^13.0.0",
58
62
  "sort-on": "^5.0.0",
@@ -60,5 +64,6 @@
60
64
  },
61
65
  "engines": {
62
66
  "node": "^12.20.0 || ^14.14.0 || >=16.0.0"
63
- }
67
+ },
68
+ "gitHead": "2b070fd93c4ea7fbdd47d0e25f49b24f2115e4a7"
64
69
  }