@netlify/cache-utils 5.0.0 → 5.0.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/dir.js +1 -1
- package/lib/hash.js +3 -3
- package/lib/list.js +3 -3
- package/lib/main.js +4 -4
- package/lib/manifest.js +1 -1
- package/package.json +7 -7
package/lib/dir.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
|
+
const DEFAULT_CACHE_DIR = '.netlify/cache/';
|
|
2
3
|
// Retrieve the cache directory location
|
|
3
4
|
export const getCacheDir = function ({ cacheDir = DEFAULT_CACHE_DIR, cwd = '.' } = {}) {
|
|
4
5
|
return resolve(cwd, cacheDir);
|
|
5
6
|
};
|
|
6
|
-
const DEFAULT_CACHE_DIR = '.netlify/cache/';
|
package/lib/hash.js
CHANGED
|
@@ -2,6 +2,9 @@ import { createHash } from 'crypto';
|
|
|
2
2
|
import { createReadStream } from 'fs';
|
|
3
3
|
import getStream from 'get-stream';
|
|
4
4
|
import { locatePath } from 'locate-path';
|
|
5
|
+
// We need a hashing algoritm that's as fast as possible.
|
|
6
|
+
// Userland CRC32 implementations are actually slower than Node.js SHA1.
|
|
7
|
+
const HASH_ALGO = 'sha1';
|
|
5
8
|
// Caching a big directory like `node_modules` is slow. However those can
|
|
6
9
|
// sometime be represented by a digest file such as `package-lock.json`. If this
|
|
7
10
|
// has not changed, we don't need to save cache again.
|
|
@@ -25,6 +28,3 @@ const hashFile = async function (path) {
|
|
|
25
28
|
const hash = await getStream(hashStream);
|
|
26
29
|
return hash;
|
|
27
30
|
};
|
|
28
|
-
// We need a hashing algoritm that's as fast as possible.
|
|
29
|
-
// Userland CRC32 implementations are actually slower than Node.js SHA1.
|
|
30
|
-
const HASH_ALGO = 'sha1';
|
package/lib/list.js
CHANGED
|
@@ -3,17 +3,17 @@ import readdirp from 'readdirp';
|
|
|
3
3
|
import { getCacheDir } from './dir.js';
|
|
4
4
|
import { isManifest } from './manifest.js';
|
|
5
5
|
import { getBases } from './path.js';
|
|
6
|
+
const DEFAULT_DEPTH = 1;
|
|
6
7
|
// List all cached files/directories, at the top-level
|
|
7
|
-
export const list = async function ({ cacheDir, cwd: cwdOpt, depth = DEFAULT_DEPTH } = {}) {
|
|
8
|
+
export const list = async function ({ cacheDir, cwd: cwdOpt, depth = DEFAULT_DEPTH, } = {}) {
|
|
8
9
|
const bases = await getBases(cwdOpt);
|
|
9
10
|
const cacheDirA = getCacheDir({ cacheDir, cwd: cwdOpt });
|
|
10
11
|
const files = await Promise.all(bases.map(({ name, base }) => listBase({ name, base, cacheDir: cacheDirA, depth })));
|
|
11
12
|
const filesA = files.flat();
|
|
12
13
|
return filesA;
|
|
13
14
|
};
|
|
14
|
-
const DEFAULT_DEPTH = 1;
|
|
15
15
|
// TODO: the returned paths are missing the Windows drive
|
|
16
|
-
const listBase = async function ({ name, base, cacheDir, depth }) {
|
|
16
|
+
const listBase = async function ({ name, base, cacheDir, depth, }) {
|
|
17
17
|
const files = await readdirp.promise(`${cacheDir}/${name}`, { fileFilter, depth, type: 'files_directories' });
|
|
18
18
|
const filesA = files.map(({ path }) => join(base, path));
|
|
19
19
|
return filesA;
|
package/lib/main.js
CHANGED
|
@@ -7,7 +7,7 @@ import { parsePath } from './path.js';
|
|
|
7
7
|
export { getCacheDir } from './dir.js';
|
|
8
8
|
export { list } from './list.js';
|
|
9
9
|
// Cache a file
|
|
10
|
-
const saveOne = async function (path, { move = DEFAULT_MOVE, ttl = DEFAULT_TTL, digests = [], cacheDir, cwd: cwdOpt } = {}) {
|
|
10
|
+
const saveOne = async function (path, { move = DEFAULT_MOVE, ttl = DEFAULT_TTL, digests = [], cacheDir, cwd: cwdOpt, } = {}) {
|
|
11
11
|
const { srcPath, cachePath } = await parsePath({ path, cacheDir, cwdOpt });
|
|
12
12
|
if (!(await hasFiles(srcPath))) {
|
|
13
13
|
return false;
|
|
@@ -22,7 +22,7 @@ const saveOne = async function (path, { move = DEFAULT_MOVE, ttl = DEFAULT_TTL,
|
|
|
22
22
|
return true;
|
|
23
23
|
};
|
|
24
24
|
// Restore a cached file
|
|
25
|
-
const restoreOne = async function (path, { move = DEFAULT_MOVE, cacheDir, cwd: cwdOpt } = {}) {
|
|
25
|
+
const restoreOne = async function (path, { move = DEFAULT_MOVE, cacheDir, cwd: cwdOpt, } = {}) {
|
|
26
26
|
const { srcPath, cachePath } = await parsePath({ path, cacheDir, cwdOpt });
|
|
27
27
|
if (!(await hasFiles(cachePath))) {
|
|
28
28
|
return false;
|
|
@@ -35,7 +35,7 @@ const restoreOne = async function (path, { move = DEFAULT_MOVE, cacheDir, cwd: c
|
|
|
35
35
|
return true;
|
|
36
36
|
};
|
|
37
37
|
// Remove the cache of a file
|
|
38
|
-
const removeOne = async function (path, { cacheDir, cwd: cwdOpt } = {}) {
|
|
38
|
+
const removeOne = async function (path, { cacheDir, cwd: cwdOpt, } = {}) {
|
|
39
39
|
const { cachePath } = await parsePath({ path, cacheDir, cwdOpt });
|
|
40
40
|
if (!(await hasFiles(cachePath))) {
|
|
41
41
|
return false;
|
|
@@ -45,7 +45,7 @@ const removeOne = async function (path, { cacheDir, cwd: cwdOpt } = {}) {
|
|
|
45
45
|
return true;
|
|
46
46
|
};
|
|
47
47
|
// Check if a file is cached
|
|
48
|
-
const hasOne = async function (path, { cacheDir, cwd: cwdOpt } = {}) {
|
|
48
|
+
const hasOne = async function (path, { cacheDir, cwd: cwdOpt, } = {}) {
|
|
49
49
|
const { cachePath } = await parsePath({ path, cacheDir, cwdOpt });
|
|
50
50
|
return (await hasFiles(cachePath)) && !(await isExpired(cachePath));
|
|
51
51
|
};
|
package/lib/manifest.js
CHANGED
|
@@ -52,7 +52,7 @@ export const isExpired = async function (cachePath) {
|
|
|
52
52
|
};
|
|
53
53
|
const readManifest = async function (cachePath) {
|
|
54
54
|
const manifestPath = getManifestPath(cachePath);
|
|
55
|
-
const manifestString = await fs.readFile(manifestPath);
|
|
55
|
+
const manifestString = await fs.readFile(manifestPath, 'utf-8');
|
|
56
56
|
const manifest = JSON.parse(manifestString);
|
|
57
57
|
return manifest;
|
|
58
58
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/cache-utils",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Utility for caching files in Netlify Build",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": "./lib/main.js",
|
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
"scripts": {
|
|
14
14
|
"prebuild": "rm -rf lib",
|
|
15
15
|
"build": "tsc",
|
|
16
|
-
"test": "
|
|
17
|
-
"test:
|
|
16
|
+
"test": "vitest run",
|
|
17
|
+
"test:dev": "vitest",
|
|
18
|
+
"test:ci": "vitest run --reporter=default"
|
|
18
19
|
},
|
|
19
20
|
"keywords": [
|
|
20
21
|
"nodejs",
|
|
@@ -61,13 +62,12 @@
|
|
|
61
62
|
},
|
|
62
63
|
"devDependencies": {
|
|
63
64
|
"@types/node": "^14.18.31",
|
|
64
|
-
"ava": "^4.0.0",
|
|
65
|
-
"c8": "^7.12.0",
|
|
66
65
|
"tmp-promise": "^3.0.0",
|
|
67
|
-
"typescript": "^4.8.4"
|
|
66
|
+
"typescript": "^4.8.4",
|
|
67
|
+
"vitest": "^0.24.1"
|
|
68
68
|
},
|
|
69
69
|
"engines": {
|
|
70
70
|
"node": "^14.16.0 || >=16.0.0"
|
|
71
71
|
},
|
|
72
|
-
"gitHead": "
|
|
72
|
+
"gitHead": "701e883d4e19c048e8de9801e49e21de5c891a18"
|
|
73
73
|
}
|