@netlify/cache-utils
Advanced tools
Comparing version 5.0.2 to 5.1.0
@@ -7,3 +7,5 @@ import { promises as fs } from 'fs'; | ||
import { moveFile } from 'move-file'; | ||
// Move or copy a cached file/directory from/to a local one | ||
/** | ||
* Move or copy a cached file/directory from/to a local one | ||
*/ | ||
export const moveCacheFile = async function (src, dest, move) { | ||
@@ -14,11 +16,18 @@ // Moving is faster but removes the source files locally | ||
} | ||
const { srcGlob, cwd } = await getSrcGlob(src); | ||
return cpy(srcGlob, dirname(dest), { cwd, parents: true, overwrite: false }); | ||
const glob = await getSrcGlob(src); | ||
if (glob) { | ||
return cpy(glob.srcGlob, dirname(dest), { cwd: glob.cwd, parents: true, overwrite: false }); | ||
} | ||
}; | ||
// Non-existing files and empty directories are always skipped | ||
/** | ||
* Non-existing files and empty directories are always skipped | ||
*/ | ||
export const hasFiles = async function (src) { | ||
const { srcGlob, cwd, isDir } = await getSrcGlob(src); | ||
return srcGlob !== undefined && !(await isEmptyDir({ srcGlob, cwd, isDir })); | ||
const glob = await getSrcGlob(src); | ||
if (!glob) { | ||
return false; | ||
} | ||
return glob.srcGlob !== undefined && !(await isEmptyDir({ srcGlob: glob.srcGlob, cwd: glob.cwd, isDir: glob.isDir })); | ||
}; | ||
// Replicates what `cpy` is doing under the hood. | ||
/** Replicates what `cpy` is doing under the hood. */ | ||
const isEmptyDir = async function ({ srcGlob, cwd, isDir }) { | ||
@@ -32,7 +41,9 @@ if (!isDir) { | ||
}; | ||
// Get globbing pattern with files to move/copy | ||
/** | ||
* Get globbing pattern with files to move/copy | ||
*/ | ||
const getSrcGlob = async function (src) { | ||
const srcStat = await getStat(src); | ||
if (srcStat === undefined) { | ||
return {}; | ||
return null; | ||
} | ||
@@ -47,3 +58,3 @@ const isDir = srcStat.isDirectory(); | ||
}; | ||
const getStat = async function (src) { | ||
const getStat = async (src) => { | ||
try { | ||
@@ -50,0 +61,0 @@ return await fs.stat(src); |
{ | ||
"name": "@netlify/cache-utils", | ||
"version": "5.0.2", | ||
"version": "5.1.0", | ||
"description": "Utility for caching files in Netlify Build", | ||
@@ -72,3 +72,3 @@ "type": "module", | ||
}, | ||
"gitHead": "be9da6e85afa0223bdcd6d228c929f4372515538" | ||
"gitHead": "e22d6106d734d2b4b7b49d2a2350be21913c0cbf" | ||
} |
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
22653
381