Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update copyDirSafe to accept a cache object rather than storing itself #104

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
24 changes: 14 additions & 10 deletions src/sync-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
(<any>process).versions.node.split('.').shift(),
10
Expand All @@ -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) => {
Expand All @@ -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
Expand Down