diff --git a/src/package-linker.js b/src/package-linker.js index 918eb40478..d6b2abf417 100644 --- a/src/package-linker.js +++ b/src/package-linker.js @@ -125,6 +125,7 @@ export default class PackageLinker { // const queue: Map = new Map(); + const skipped: string[] = []; for (const [dest, {pkg, loc: src}] of flatTree) { const ref = pkg._reference; invariant(ref, 'expected package reference'); @@ -137,6 +138,15 @@ export default class PackageLinker { phantomFiles.push(path.join(dest, file)); } + try { + const obj = await fs.readJson(path.join(dest, 'package.json')); + // If the package is installed and is the exact same version, skip + if(obj.version == ref.version) { + skipped.push(dest); + continue; + } + } catch(ex) {} + queue.set(dest, { src, dest, @@ -147,6 +157,9 @@ export default class PackageLinker { }, }); } + if(skipped.length > 0) { + this.reporter.lang('skippedInstalledModules', skipped.length); + } // keep track of all scoped paths to remove empty scopes after copy const scopedPaths = new Set(); @@ -183,6 +196,11 @@ export default class PackageLinker { } } + // skipped modules + for (const loc of skipped) { + possibleExtraneous.delete(loc); + } + // let tick; await fs.copyBulk(Array.from(queue.values()), this.reporter, { diff --git a/src/reporters/lang/en.js b/src/reporters/lang/en.js index bbad2ea3e8..863ea50f7d 100644 --- a/src/reporters/lang/en.js +++ b/src/reporters/lang/en.js @@ -148,6 +148,8 @@ const messages = { unmetPeer: 'Unmet peer dependency $0.', incorrectPeer: 'Incorrect peer dependency $0.', + skippedInstalledModules: 'Skipped $0 module(s) because they are already installed.', + savedNewDependency: 'Saved 1 new dependency.', savedNewDependencies: 'Saved $0 new dependencies.', diff --git a/yarn.lock b/yarn.lock index 381e4b8a4e..733839d5e9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1,7 +1,5 @@ # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. # yarn lockfile v1 - - abab@^1.0.0: version "1.0.3" resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.3.tgz#b81de5f7274ec4e756d797cd834f303642724e5d" @@ -5409,3 +5407,4 @@ yargs@~3.27.0: os-locale "^1.4.0" window-size "^0.1.2" y18n "^3.2.0" +