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

[WIP] Skip already installed modules #2176

Closed
wants to merge 2 commits into from
Closed
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
18 changes: 18 additions & 0 deletions src/package-linker.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export default class PackageLinker {

//
const queue: Map<string, CopyQueueItem> = new Map();
const skipped: string[] = [];
for (const [dest, {pkg, loc: src}] of flatTree) {
const ref = pkg._reference;
invariant(ref, 'expected package reference');
Expand All @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -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, {
Expand Down
2 changes: 2 additions & 0 deletions src/reporters/lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.',

Expand Down
3 changes: 1 addition & 2 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -5409,3 +5407,4 @@ yargs@~3.27.0:
os-locale "^1.4.0"
window-size "^0.1.2"
y18n "^3.2.0"