@netlify/cache-utils
Advanced tools
Comparing version 5.0.0 to 5.0.1
import { resolve } from 'path'; | ||
const DEFAULT_CACHE_DIR = '.netlify/cache/'; | ||
// Retrieve the cache directory location | ||
@@ -6,2 +7,1 @@ export const getCacheDir = function ({ cacheDir = DEFAULT_CACHE_DIR, cwd = '.' } = {}) { | ||
}; | ||
const DEFAULT_CACHE_DIR = '.netlify/cache/'; |
@@ -5,2 +5,5 @@ import { createHash } from 'crypto'; | ||
import { locatePath } from 'locate-path'; | ||
// We need a hashing algoritm that's as fast as possible. | ||
// Userland CRC32 implementations are actually slower than Node.js SHA1. | ||
const HASH_ALGO = 'sha1'; | ||
// Caching a big directory like `node_modules` is slow. However those can | ||
@@ -29,4 +32,1 @@ // sometime be represented by a digest file such as `package-lock.json`. If this | ||
}; | ||
// We need a hashing algoritm that's as fast as possible. | ||
// Userland CRC32 implementations are actually slower than Node.js SHA1. | ||
const HASH_ALGO = 'sha1'; |
@@ -6,4 +6,5 @@ import { join } from 'path'; | ||
import { getBases } from './path.js'; | ||
const DEFAULT_DEPTH = 1; | ||
// List all cached files/directories, at the top-level | ||
export const list = async function ({ cacheDir, cwd: cwdOpt, depth = DEFAULT_DEPTH } = {}) { | ||
export const list = async function ({ cacheDir, cwd: cwdOpt, depth = DEFAULT_DEPTH, } = {}) { | ||
const bases = await getBases(cwdOpt); | ||
@@ -15,5 +16,4 @@ const cacheDirA = getCacheDir({ cacheDir, cwd: cwdOpt }); | ||
}; | ||
const DEFAULT_DEPTH = 1; | ||
// TODO: the returned paths are missing the Windows drive | ||
const listBase = async function ({ name, base, cacheDir, depth }) { | ||
const listBase = async function ({ name, base, cacheDir, depth, }) { | ||
const files = await readdirp.promise(`${cacheDir}/${name}`, { fileFilter, depth, type: 'files_directories' }); | ||
@@ -20,0 +20,0 @@ const filesA = files.map(({ path }) => join(base, path)); |
@@ -10,3 +10,3 @@ import del from 'del'; | ||
// Cache a file | ||
const saveOne = async function (path, { move = DEFAULT_MOVE, ttl = DEFAULT_TTL, digests = [], cacheDir, cwd: cwdOpt } = {}) { | ||
const saveOne = async function (path, { move = DEFAULT_MOVE, ttl = DEFAULT_TTL, digests = [], cacheDir, cwd: cwdOpt, } = {}) { | ||
const { srcPath, cachePath } = await parsePath({ path, cacheDir, cwdOpt }); | ||
@@ -26,3 +26,3 @@ if (!(await hasFiles(srcPath))) { | ||
// Restore a cached file | ||
const restoreOne = async function (path, { move = DEFAULT_MOVE, cacheDir, cwd: cwdOpt } = {}) { | ||
const restoreOne = async function (path, { move = DEFAULT_MOVE, cacheDir, cwd: cwdOpt, } = {}) { | ||
const { srcPath, cachePath } = await parsePath({ path, cacheDir, cwdOpt }); | ||
@@ -40,3 +40,3 @@ if (!(await hasFiles(cachePath))) { | ||
// Remove the cache of a file | ||
const removeOne = async function (path, { cacheDir, cwd: cwdOpt } = {}) { | ||
const removeOne = async function (path, { cacheDir, cwd: cwdOpt, } = {}) { | ||
const { cachePath } = await parsePath({ path, cacheDir, cwdOpt }); | ||
@@ -51,3 +51,3 @@ if (!(await hasFiles(cachePath))) { | ||
// Check if a file is cached | ||
const hasOne = async function (path, { cacheDir, cwd: cwdOpt } = {}) { | ||
const hasOne = async function (path, { cacheDir, cwd: cwdOpt, } = {}) { | ||
const { cachePath } = await parsePath({ path, cacheDir, cwdOpt }); | ||
@@ -54,0 +54,0 @@ return (await hasFiles(cachePath)) && !(await isExpired(cachePath)); |
@@ -55,5 +55,5 @@ import { promises as fs } from 'fs'; | ||
const manifestPath = getManifestPath(cachePath); | ||
const manifestString = await fs.readFile(manifestPath); | ||
const manifestString = await fs.readFile(manifestPath, 'utf-8'); | ||
const manifest = JSON.parse(manifestString); | ||
return manifest; | ||
}; |
{ | ||
"name": "@netlify/cache-utils", | ||
"version": "5.0.0", | ||
"version": "5.0.1", | ||
"description": "Utility for caching files in Netlify Build", | ||
@@ -16,4 +16,5 @@ "type": "module", | ||
"build": "tsc", | ||
"test": "ava", | ||
"test:ci": "c8 -r lcovonly -r text -r json ava" | ||
"test": "vitest run", | ||
"test:dev": "vitest", | ||
"test:ci": "vitest run --reporter=default" | ||
}, | ||
@@ -65,6 +66,5 @@ "keywords": [ | ||
"@types/node": "^14.18.31", | ||
"ava": "^4.0.0", | ||
"c8": "^7.12.0", | ||
"tmp-promise": "^3.0.0", | ||
"typescript": "^4.8.4" | ||
"typescript": "^4.8.4", | ||
"vitest": "^0.24.1" | ||
}, | ||
@@ -74,3 +74,3 @@ "engines": { | ||
}, | ||
"gitHead": "c4502f1c112e7f33d5e6fa053bfbe7dabdfe0160" | ||
"gitHead": "701e883d4e19c048e8de9801e49e21de5c891a18" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
22533
4