@netlify/cache-utils 5.0.2 → 5.1.1
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 +32 -15
- package/package.json +2 -2
package/lib/fs.js
CHANGED
|
@@ -4,44 +4,61 @@ import cpy from 'cpy';
|
|
|
4
4
|
import { globby } from 'globby';
|
|
5
5
|
import { isNotJunk } from 'junk';
|
|
6
6
|
import { moveFile } from 'move-file';
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
/**
|
|
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
|
|
12
|
+
*/
|
|
13
|
+
export const moveCacheFile = async function (src, dest, move = false) {
|
|
9
14
|
// Moving is faster but removes the source files locally
|
|
10
15
|
if (move) {
|
|
11
16
|
return moveFile(src, dest, { overwrite: false });
|
|
12
17
|
}
|
|
13
|
-
const { srcGlob,
|
|
14
|
-
|
|
18
|
+
const { srcGlob, ...options } = await getSrcGlob(src);
|
|
19
|
+
if (srcGlob) {
|
|
20
|
+
return cpy(srcGlob, dirname(dest), { ...options, parents: true, overwrite: false });
|
|
21
|
+
}
|
|
15
22
|
};
|
|
16
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Non-existing files and empty directories are always skipped
|
|
25
|
+
*/
|
|
17
26
|
export const hasFiles = async function (src) {
|
|
18
|
-
const { srcGlob,
|
|
19
|
-
return srcGlob !== undefined && !(await isEmptyDir(
|
|
27
|
+
const { srcGlob, isDir, ...options } = await getSrcGlob(src);
|
|
28
|
+
return srcGlob !== undefined && !(await isEmptyDir(srcGlob, isDir, options));
|
|
20
29
|
};
|
|
21
|
-
|
|
22
|
-
const isEmptyDir = async function (
|
|
30
|
+
/** Replicates what `cpy` is doing under the hood. */
|
|
31
|
+
const isEmptyDir = async function (globPattern, isDir, options) {
|
|
23
32
|
if (!isDir) {
|
|
24
33
|
return false;
|
|
25
34
|
}
|
|
26
|
-
const files = await globby(
|
|
35
|
+
const files = await globby(globPattern, options);
|
|
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 { srcGlob: undefined, isDir: false, cwd: '' };
|
|
35
46
|
}
|
|
36
47
|
const isDir = srcStat.isDirectory();
|
|
37
48
|
const srcBasename = basename(src);
|
|
38
49
|
const cwd = dirname(src);
|
|
50
|
+
const baseOptions = {
|
|
51
|
+
srcGlob: srcBasename,
|
|
52
|
+
isDir,
|
|
53
|
+
cwd,
|
|
54
|
+
dot: true, // collect .dot directories as well
|
|
55
|
+
};
|
|
39
56
|
if (isDir) {
|
|
40
|
-
return { srcGlob: `${srcBasename}
|
|
57
|
+
return { ...baseOptions, srcGlob: `${srcBasename}/**` };
|
|
41
58
|
}
|
|
42
|
-
return
|
|
59
|
+
return baseOptions;
|
|
43
60
|
};
|
|
44
|
-
const getStat = async
|
|
61
|
+
const getStat = async (src) => {
|
|
45
62
|
try {
|
|
46
63
|
return await fs.stat(src);
|
|
47
64
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/cache-utils",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.1.1",
|
|
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": "356667c6173362b294f9037efdb7b5ef1c726d48"
|
|
73
73
|
}
|