@netlify/cache-utils 5.1.0 → 5.1.2

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/fs.js +21 -14
  2. package/package.json +2 -2
package/lib/fs.js CHANGED
@@ -6,33 +6,33 @@ import { isNotJunk } from 'junk';
6
6
  import { moveFile } from 'move-file';
7
7
  /**
8
8
  * Move or copy a cached file/directory from/to a local one
9
+ * @param src The src directory or file to cache
10
+ * @param dest The destination location
11
+ * @param move If the file should be moved, moving is faster but removes the source files locally
9
12
  */
10
- export const moveCacheFile = async function (src, dest, move) {
13
+ export const moveCacheFile = async function (src, dest, move = false) {
11
14
  // Moving is faster but removes the source files locally
12
15
  if (move) {
13
16
  return moveFile(src, dest, { overwrite: false });
14
17
  }
15
- const glob = await getSrcGlob(src);
16
- if (glob) {
17
- return cpy(glob.srcGlob, dirname(dest), { cwd: glob.cwd, parents: true, overwrite: false });
18
+ const { srcGlob, ...options } = await getSrcGlob(src);
19
+ if (srcGlob) {
20
+ return cpy(srcGlob, dirname(dest), { ...options, parents: true, overwrite: false });
18
21
  }
19
22
  };
20
23
  /**
21
24
  * Non-existing files and empty directories are always skipped
22
25
  */
23
26
  export const hasFiles = async function (src) {
24
- const glob = await getSrcGlob(src);
25
- if (!glob) {
26
- return false;
27
- }
28
- return glob.srcGlob !== undefined && !(await isEmptyDir({ srcGlob: glob.srcGlob, cwd: glob.cwd, isDir: glob.isDir }));
27
+ const { srcGlob, isDir, ...options } = await getSrcGlob(src);
28
+ return srcGlob !== undefined && !(await isEmptyDir(srcGlob, isDir, options));
29
29
  };
30
30
  /** Replicates what `cpy` is doing under the hood. */
31
- const isEmptyDir = async function ({ srcGlob, cwd, isDir }) {
31
+ const isEmptyDir = async function (globPattern, isDir, options) {
32
32
  if (!isDir) {
33
33
  return false;
34
34
  }
35
- const files = await globby(srcGlob, { cwd });
35
+ const files = await globby(globPattern, options);
36
36
  const filteredFiles = files.filter((file) => isNotJunk(basename(file)));
37
37
  return filteredFiles.length === 0;
38
38
  };
@@ -42,15 +42,21 @@ const isEmptyDir = async function ({ srcGlob, cwd, isDir }) {
42
42
  const getSrcGlob = async function (src) {
43
43
  const srcStat = await getStat(src);
44
44
  if (srcStat === undefined) {
45
- return null;
45
+ return { srcGlob: undefined, isDir: false, cwd: '' };
46
46
  }
47
47
  const isDir = srcStat.isDirectory();
48
48
  const srcBasename = basename(src);
49
49
  const cwd = dirname(src);
50
+ const baseOptions = {
51
+ srcGlob: srcBasename,
52
+ isDir,
53
+ cwd,
54
+ dot: true, // collect .dot directories as well
55
+ };
50
56
  if (isDir) {
51
- return { srcGlob: `${srcBasename}/**`, cwd, isDir };
57
+ return { ...baseOptions, srcGlob: `${srcBasename}/**` };
52
58
  }
53
- return { srcGlob: srcBasename, cwd, isDir };
59
+ return baseOptions;
54
60
  };
55
61
  const getStat = async (src) => {
56
62
  try {
@@ -58,5 +64,6 @@ const getStat = async (src) => {
58
64
  }
59
65
  catch {
60
66
  // continue regardless error
67
+ return undefined;
61
68
  }
62
69
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/cache-utils",
3
- "version": "5.1.0",
3
+ "version": "5.1.2",
4
4
  "description": "Utility for caching files in Netlify Build",
5
5
  "type": "module",
6
6
  "exports": "./lib/main.js",
@@ -69,5 +69,5 @@
69
69
  "engines": {
70
70
  "node": "^14.16.0 || >=16.0.0"
71
71
  },
72
- "gitHead": "e22d6106d734d2b4b7b49d2a2350be21913c0cbf"
72
+ "gitHead": "d78a65c209ed987d3475cd1f37cf357693b99e3c"
73
73
  }