@netlify/cache-utils 5.0.1 → 5.1.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/lib/fs.js +21 -10
- package/package.json +2 -2
package/lib/fs.js
CHANGED
|
@@ -4,21 +4,30 @@ import cpy from 'cpy';
|
|
|
4
4
|
import { globby } from 'globby';
|
|
5
5
|
import { isNotJunk } from 'junk';
|
|
6
6
|
import { moveFile } from 'move-file';
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Move or copy a cached file/directory from/to a local one
|
|
9
|
+
*/
|
|
8
10
|
export const moveCacheFile = async function (src, dest, move) {
|
|
9
11
|
// Moving is faster but removes the source files locally
|
|
10
12
|
if (move) {
|
|
11
13
|
return moveFile(src, dest, { overwrite: false });
|
|
12
14
|
}
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
+
const glob = await getSrcGlob(src);
|
|
16
|
+
if (glob) {
|
|
17
|
+
return cpy(glob.srcGlob, dirname(dest), { cwd: glob.cwd, parents: true, overwrite: false });
|
|
18
|
+
}
|
|
15
19
|
};
|
|
16
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Non-existing files and empty directories are always skipped
|
|
22
|
+
*/
|
|
17
23
|
export const hasFiles = async function (src) {
|
|
18
|
-
const
|
|
19
|
-
|
|
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 }));
|
|
20
29
|
};
|
|
21
|
-
|
|
30
|
+
/** Replicates what `cpy` is doing under the hood. */
|
|
22
31
|
const isEmptyDir = async function ({ srcGlob, cwd, isDir }) {
|
|
23
32
|
if (!isDir) {
|
|
24
33
|
return false;
|
|
@@ -27,11 +36,13 @@ const isEmptyDir = async function ({ srcGlob, cwd, isDir }) {
|
|
|
27
36
|
const filteredFiles = files.filter((file) => isNotJunk(basename(file)));
|
|
28
37
|
return filteredFiles.length === 0;
|
|
29
38
|
};
|
|
30
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Get globbing pattern with files to move/copy
|
|
41
|
+
*/
|
|
31
42
|
const getSrcGlob = async function (src) {
|
|
32
43
|
const srcStat = await getStat(src);
|
|
33
44
|
if (srcStat === undefined) {
|
|
34
|
-
return
|
|
45
|
+
return null;
|
|
35
46
|
}
|
|
36
47
|
const isDir = srcStat.isDirectory();
|
|
37
48
|
const srcBasename = basename(src);
|
|
@@ -41,7 +52,7 @@ const getSrcGlob = async function (src) {
|
|
|
41
52
|
}
|
|
42
53
|
return { srcGlob: srcBasename, cwd, isDir };
|
|
43
54
|
};
|
|
44
|
-
const getStat = async
|
|
55
|
+
const getStat = async (src) => {
|
|
45
56
|
try {
|
|
46
57
|
return await fs.stat(src);
|
|
47
58
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/cache-utils",
|
|
3
|
-
"version": "5.0
|
|
3
|
+
"version": "5.1.0",
|
|
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": "
|
|
72
|
+
"gitHead": "e22d6106d734d2b4b7b49d2a2350be21913c0cbf"
|
|
73
73
|
}
|