diff --git a/src/add.ts b/src/add.ts index 6dc924d..76b32ac 100644 --- a/src/add.ts +++ b/src/add.ts @@ -93,7 +93,9 @@ export const addPackages = async ( } const destYalcCopyDir = join(workingDir, values.yalcPackagesFolder, name) - await copyDirSafe(storedPackageDir, destYalcCopyDir) + const storeCache = {} + + await copyDirSafe(storedPackageDir, destYalcCopyDir, storeCache) let replacedVersion = '' if (doPure) { @@ -121,7 +123,7 @@ export const addPackages = async ( if (options.link || options.linkDep) { ensureSymlinkSync(destYalcCopyDir, destModulesDir, 'junction') } else { - await copyDirSafe(storedPackageDir, destModulesDir) + await copyDirSafe(storedPackageDir, destModulesDir, storeCache) } if (!options.link) { diff --git a/src/sync-dir.ts b/src/sync-dir.ts index 6a10e1b..3550720 100644 --- a/src/sync-dir.ts +++ b/src/sync-dir.ts @@ -4,6 +4,15 @@ import { resolve } from 'path' import * as fs from 'fs-extra' import { getFileHash } from './copy' +type Cache = { + [dir: string]: { + glob: string[] + files: { + [file: string]: { stat: fs.Stats; hash: string } + } + } +} + const NODE_MAJOR_VERSION = parseInt( (process).versions.node.split('.').shift(), 10 @@ -17,15 +26,6 @@ if (NODE_MAJOR_VERSION >= 8 && NODE_MAJOR_VERSION < 10) { const globP = util.promisify(glob) -const cache: { - [dir: string]: { - glob: string[] - files: { - [file: string]: { stat: fs.Stats; hash: string } - } - } -} = {} - const makeListMap = (list: string[]) => { return list.reduce( (map, item) => { @@ -43,7 +43,11 @@ const theSameStats = (srcStat: fs.Stats, destStat: fs.Stats) => { ) } -export const copyDirSafe = async (srcDir: string, destDir: string) => { +export const copyDirSafe = async ( + srcDir: string, + destDir: string, + cache: Cache = {} +) => { const ignore = '**/node_modules/**' const dot = true const nodir = true