@netlify/cache-utils 5.1.3 → 5.1.5
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 +9 -7
- package/lib/main.js +4 -4
- package/lib/manifest.js +6 -7
- package/package.json +5 -6
package/lib/fs.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { promises as fs } from 'fs';
|
|
2
|
-
import { basename, dirname } from 'path';
|
|
2
|
+
import { basename, dirname, join } from 'path';
|
|
3
3
|
import cpy from 'cpy';
|
|
4
4
|
import { globby } from 'globby';
|
|
5
5
|
import { isNotJunk } from 'junk';
|
|
@@ -15,16 +15,17 @@ export const moveCacheFile = async function (src, dest, move = false) {
|
|
|
15
15
|
if (move) {
|
|
16
16
|
return moveFile(src, dest, { overwrite: false });
|
|
17
17
|
}
|
|
18
|
-
const { srcGlob, ...options } = await
|
|
19
|
-
if (srcGlob) {
|
|
20
|
-
return cpy(srcGlob,
|
|
18
|
+
const { srcGlob, dest: matchedDest, ...options } = await getSrcAndDest(src, dirname(dest));
|
|
19
|
+
if (srcGlob && matchedDest) {
|
|
20
|
+
return cpy(srcGlob, matchedDest, { ...options, overwrite: false });
|
|
21
21
|
}
|
|
22
22
|
};
|
|
23
23
|
/**
|
|
24
24
|
* Non-existing files and empty directories are always skipped
|
|
25
25
|
*/
|
|
26
26
|
export const hasFiles = async function (src) {
|
|
27
|
-
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
28
|
+
const { srcGlob, isDir, dest, ...options } = await getSrcAndDest(src, '');
|
|
28
29
|
return srcGlob !== undefined && !(await isEmptyDir(srcGlob, isDir, options));
|
|
29
30
|
};
|
|
30
31
|
/** Replicates what `cpy` is doing under the hood. */
|
|
@@ -39,7 +40,7 @@ const isEmptyDir = async function (globPattern, isDir, options) {
|
|
|
39
40
|
/**
|
|
40
41
|
* Get globbing pattern with files to move/copy
|
|
41
42
|
*/
|
|
42
|
-
const
|
|
43
|
+
const getSrcAndDest = async function (src, dest) {
|
|
43
44
|
const srcStat = await getStat(src);
|
|
44
45
|
if (srcStat === undefined) {
|
|
45
46
|
return { srcGlob: undefined, isDir: false, cwd: '' };
|
|
@@ -49,12 +50,13 @@ const getSrcGlob = async function (src) {
|
|
|
49
50
|
const cwd = dirname(src);
|
|
50
51
|
const baseOptions = {
|
|
51
52
|
srcGlob: srcBasename,
|
|
53
|
+
dest,
|
|
52
54
|
isDir,
|
|
53
55
|
cwd,
|
|
54
56
|
dot: true, // collect .dot directories as well
|
|
55
57
|
};
|
|
56
58
|
if (isDir) {
|
|
57
|
-
return { ...baseOptions, srcGlob: `${srcBasename}
|
|
59
|
+
return { ...baseOptions, srcGlob: `${srcBasename}/**`, dest: join(dest, srcBasename) };
|
|
58
60
|
}
|
|
59
61
|
return baseOptions;
|
|
60
62
|
};
|
package/lib/main.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { rm } from 'fs/promises';
|
|
2
2
|
import { getCacheDir } from './dir.js';
|
|
3
3
|
import { moveCacheFile, hasFiles } from './fs.js';
|
|
4
4
|
import { list } from './list.js';
|
|
@@ -16,7 +16,7 @@ const saveOne = async function (path, { move = DEFAULT_MOVE, ttl = DEFAULT_TTL,
|
|
|
16
16
|
if (identical) {
|
|
17
17
|
return true;
|
|
18
18
|
}
|
|
19
|
-
await
|
|
19
|
+
await rm(cachePath, { force: true, recursive: true, maxRetries: 3 });
|
|
20
20
|
await moveCacheFile(srcPath, cachePath, move);
|
|
21
21
|
await writeManifest(manifestInfo);
|
|
22
22
|
return true;
|
|
@@ -30,7 +30,7 @@ const restoreOne = async function (path, { move = DEFAULT_MOVE, cacheDir, cwd: c
|
|
|
30
30
|
if (await isExpired(cachePath)) {
|
|
31
31
|
return false;
|
|
32
32
|
}
|
|
33
|
-
await
|
|
33
|
+
await rm(srcPath, { force: true, recursive: true, maxRetries: 3 });
|
|
34
34
|
await moveCacheFile(cachePath, srcPath, move);
|
|
35
35
|
return true;
|
|
36
36
|
};
|
|
@@ -40,7 +40,7 @@ const removeOne = async function (path, { cacheDir, cwd: cwdOpt, } = {}) {
|
|
|
40
40
|
if (!(await hasFiles(cachePath))) {
|
|
41
41
|
return false;
|
|
42
42
|
}
|
|
43
|
-
await
|
|
43
|
+
await rm(cachePath, { force: true, recursive: true, maxRetries: 3 });
|
|
44
44
|
await removeManifest(cachePath);
|
|
45
45
|
return true;
|
|
46
46
|
};
|
package/lib/manifest.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { mkdir, readFile, rm, writeFile } from 'fs/promises';
|
|
2
2
|
import { dirname } from 'path';
|
|
3
|
-
import del from 'del';
|
|
4
3
|
import { pathExists } from 'path-exists';
|
|
5
4
|
import { getExpires, checkExpires } from './expire.js';
|
|
6
5
|
import { getHash } from './hash.js';
|
|
@@ -20,18 +19,18 @@ const isIdentical = async function ({ hash, manifestPath, manifestString }) {
|
|
|
20
19
|
if (hash === undefined || !(await pathExists(manifestPath))) {
|
|
21
20
|
return false;
|
|
22
21
|
}
|
|
23
|
-
const oldManifestString = await
|
|
22
|
+
const oldManifestString = await readFile(manifestPath, 'utf8');
|
|
24
23
|
return oldManifestString === manifestString;
|
|
25
24
|
};
|
|
26
25
|
// Persist the cache manifest to filesystem
|
|
27
26
|
export const writeManifest = async function ({ manifestPath, manifestString }) {
|
|
28
|
-
await
|
|
29
|
-
await
|
|
27
|
+
await mkdir(dirname(manifestPath), { recursive: true });
|
|
28
|
+
await writeFile(manifestPath, manifestString);
|
|
30
29
|
};
|
|
31
30
|
// Remove the cache manifest from filesystem
|
|
32
31
|
export const removeManifest = async function (cachePath) {
|
|
33
32
|
const manifestPath = getManifestPath(cachePath);
|
|
34
|
-
await
|
|
33
|
+
await rm(manifestPath, { force: true, recursive: true, maxRetries: 3 });
|
|
35
34
|
};
|
|
36
35
|
// Retrieve the cache manifest filepath
|
|
37
36
|
const getManifestPath = function (cachePath) {
|
|
@@ -52,7 +51,7 @@ export const isExpired = async function (cachePath) {
|
|
|
52
51
|
};
|
|
53
52
|
const readManifest = async function (cachePath) {
|
|
54
53
|
const manifestPath = getManifestPath(cachePath);
|
|
55
|
-
const manifestString = await
|
|
54
|
+
const manifestString = await readFile(manifestPath, 'utf-8');
|
|
56
55
|
const manifest = JSON.parse(manifestString);
|
|
57
56
|
return manifest;
|
|
58
57
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/cache-utils",
|
|
3
|
-
"version": "5.1.
|
|
3
|
+
"version": "5.1.5",
|
|
4
4
|
"description": "Utility for caching files in Netlify Build",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./lib/main.js",
|
|
@@ -50,8 +50,7 @@
|
|
|
50
50
|
},
|
|
51
51
|
"license": "MIT",
|
|
52
52
|
"dependencies": {
|
|
53
|
-
"cpy": "^
|
|
54
|
-
"del": "^6.0.0",
|
|
53
|
+
"cpy": "^9.0.0",
|
|
55
54
|
"get-stream": "^6.0.0",
|
|
56
55
|
"globby": "^13.0.0",
|
|
57
56
|
"junk": "^4.0.0",
|
|
@@ -63,11 +62,11 @@
|
|
|
63
62
|
"devDependencies": {
|
|
64
63
|
"@types/node": "^18.14.2",
|
|
65
64
|
"tmp-promise": "^3.0.0",
|
|
66
|
-
"typescript": "^
|
|
67
|
-
"vitest": "^0.
|
|
65
|
+
"typescript": "^5.0.0",
|
|
66
|
+
"vitest": "^0.30.1"
|
|
68
67
|
},
|
|
69
68
|
"engines": {
|
|
70
69
|
"node": "^14.16.0 || >=16.0.0"
|
|
71
70
|
},
|
|
72
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "6c093847fef2347fc80740059cbf0ee49ea193fc"
|
|
73
72
|
}
|