diff --git a/__tests__/commands/install/integration.js b/__tests__/commands/install/integration.js index 7c43a0a424..b78ab6b400 100644 --- a/__tests__/commands/install/integration.js +++ b/__tests__/commands/install/integration.js @@ -822,14 +822,3 @@ test.concurrent('bailout should work with --production flag too', (): Promise => { - // Scenario: - // graceful-fs will install two versions, from @4.1.10 and @^4.1.11. The pattern @^4.1.2 would sometimes resolve - // to 4.1.10, if @^4.1.11 hadn't been processed before. Otherwise it would resolve to the result of @^4.1.11. - // Run an independent install and check, and see they have different results for @^4.1.2 - won't always see - // the bug, but its the best we can do without creating mock registry with controlled timing of responses. - return runInstall({}, 'install-deterministic-versions', async (config, reporter) => { - await check(config, reporter, {integrity: true}, []); - }); -}); diff --git a/__tests__/commands/install/lockfiles.js b/__tests__/commands/install/lockfiles.js index c40c557d5e..4581823af1 100644 --- a/__tests__/commands/install/lockfiles.js +++ b/__tests__/commands/install/lockfiles.js @@ -295,3 +295,29 @@ test.concurrent("install should fix if lockfile patterns don't match resolved ve expect(lockContent).toContain('left-pad-1.1.2.tgz'); }); }); + +// issue https://github.com/yarnpkg/yarn/issues/3023 +test.concurrent("install should downgrade a subdependency version if it is available", (): Promise => { + // uglify-js@^2.6.2: + // version "2.8.18" + // resolved "http://r.cnpmjs.org/uglify-js/download/uglify-js-2.8.18.tgz#925d14bae48ab62d1883b41afe6e2261662adb8e" + // + // uglify-js@~2.7.3: + // version "2.7.5" + // resolved "http://r.cnpmjs.org/uglify-js/download/uglify-js-2.7.5.tgz#4612c0c7baaee2ba7c487de4904ae122079f2ca8" + + // could be optimized to + + // uglify-js@~2.7.3, uglify-js@^2.6.2:: + // version "2.7.5" + // resolved "http://r.cnpmjs.org/uglify-js/download/uglify-js-2.7.5.tgz#4612c0c7baaee2ba7c487de4904ae122079f2ca8" + + const fixture = 'lockfile-optimization'; + + return runInstall({}, fixture, async (config, reporter) => { + // no unhoisted unglify-js + expect(await fs.exists(path.join(config.cwd, 'node_modules', 'uglify-js'))).toBe(true); + expect(await fs.exists(path.join(config.cwd, 'node_modules', 'uglify-js'))).toBe(false); + expect(await fs.exists(path.join(config.cwd, 'node_modules', 'uglify-js'))).toBe(false); + }); +}); diff --git a/__tests__/fixtures/install/install-deterministic-versions/package.json b/__tests__/fixtures/install/install-deterministic-versions/package.json deleted file mode 100644 index 9f08749c73..0000000000 --- a/__tests__/fixtures/install/install-deterministic-versions/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "dependencies": { - "graceful-fs": "4.1.10", - "write-file-atomic": "1.3.1", - "path-type": "1.1.0" - } -} diff --git a/__tests__/fixtures/install/lockfile-optimization/package.json b/__tests__/fixtures/install/lockfile-optimization/package.json new file mode 100644 index 0000000000..e759fbfd5c --- /dev/null +++ b/__tests__/fixtures/install/lockfile-optimization/package.json @@ -0,0 +1,15 @@ +{ + "name": "yarn0test", + "version": "1.0.0", + "description": "yarn test", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "dependencies": { + "webpack": "1.14.0", + "webpack-parallel-uglify-plugin": "0.2.0" + }, + "author": "h", + "license": "MIT" +} diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/assert.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/assert.bin new file mode 100644 index 0000000000..0c35044bac Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/assert.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/browserify-aes.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/browserify-aes.bin new file mode 100644 index 0000000000..03016e3140 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/browserify-aes.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/browserify-zlib.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/browserify-zlib.bin new file mode 100644 index 0000000000..503e28df32 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/browserify-zlib.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/buffer.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/buffer.bin new file mode 100644 index 0000000000..995a8e8c26 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/buffer.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/builtin-status-codes.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/builtin-status-codes.bin new file mode 100644 index 0000000000..c134691625 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/builtin-status-codes.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/console-browserify.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/console-browserify.bin new file mode 100644 index 0000000000..f6034bbe2a Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/console-browserify.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/constants-browserify.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/constants-browserify.bin new file mode 100644 index 0000000000..605bdb3651 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/constants-browserify.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/crypto-browserify.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/crypto-browserify.bin new file mode 100644 index 0000000000..433fd32548 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/crypto-browserify.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/date-now.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/date-now.bin new file mode 100644 index 0000000000..d795b9dec5 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/date-now.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/domain-browser.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/domain-browser.bin new file mode 100644 index 0000000000..6c9014e6a3 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/domain-browser.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/enhanced-resolve.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/enhanced-resolve.bin new file mode 100644 index 0000000000..ddeb695c62 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/enhanced-resolve.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/events.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/events.bin new file mode 100644 index 0000000000..fa51698040 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/events.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/https-browserify.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/https-browserify.bin new file mode 100644 index 0000000000..a3e4065c1d Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/https-browserify.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/ieee754.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/ieee754.bin new file mode 100644 index 0000000000..6fb478e5d7 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/ieee754.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/loader-utils/-/loader-utils-0.2.16.tgz.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/loader-utils/-/loader-utils-0.2.16.tgz.bin new file mode 100644 index 0000000000..1d1b6218fe Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/loader-utils/-/loader-utils-0.2.16.tgz.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/memory-fs.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/memory-fs.bin new file mode 100644 index 0000000000..16d9ac49c9 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/memory-fs.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/node-libs-browser.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/node-libs-browser.bin new file mode 100644 index 0000000000..1dac91ea36 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/node-libs-browser.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/os-browserify.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/os-browserify.bin new file mode 100644 index 0000000000..f0f9900aef Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/os-browserify.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/pako.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/pako.bin new file mode 100644 index 0000000000..d31627a832 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/pako.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/path-browserify.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/path-browserify.bin new file mode 100644 index 0000000000..cd09015d01 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/path-browserify.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/pbkdf2-compat.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/pbkdf2-compat.bin new file mode 100644 index 0000000000..a062753532 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/pbkdf2-compat.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/process/-/process-0.11.9.tgz.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/process/-/process-0.11.9.tgz.bin new file mode 100644 index 0000000000..4755a65788 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/process/-/process-0.11.9.tgz.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/querystring-es3.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/querystring-es3.bin new file mode 100644 index 0000000000..88c5a31716 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/querystring-es3.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/querystring.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/querystring.bin new file mode 100644 index 0000000000..148a6e6b7d Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/querystring.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/ripemd160.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/ripemd160.bin new file mode 100644 index 0000000000..00bcf129c8 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/ripemd160.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/sha.js.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/sha.js.bin new file mode 100644 index 0000000000..41b257a0f1 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/sha.js.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/source-list-map.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/source-list-map.bin new file mode 100644 index 0000000000..65dd80c841 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/source-list-map.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/stream-browserify.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/stream-browserify.bin new file mode 100644 index 0000000000..adee9ba640 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/stream-browserify.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/stream-http.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/stream-http.bin new file mode 100644 index 0000000000..3c7ccab136 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/stream-http.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/tapable.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/tapable.bin new file mode 100644 index 0000000000..cdd422ecc0 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/tapable.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/timers-browserify.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/timers-browserify.bin new file mode 100644 index 0000000000..58dd1cd712 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/timers-browserify.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/tmp/-/tmp-0.0.29.tgz.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/tmp/-/tmp-0.0.29.tgz.bin new file mode 100644 index 0000000000..ccd114d7bd Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/tmp/-/tmp-0.0.29.tgz.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/to-arraybuffer.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/to-arraybuffer.bin new file mode 100644 index 0000000000..61b2971ff4 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/to-arraybuffer.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/tty-browserify.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/tty-browserify.bin new file mode 100644 index 0000000000..199757e2ae Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/tty-browserify.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/uglify-js/-/uglify-js-2.5.0.tgz.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/uglify-js/-/uglify-js-2.5.0.tgz.bin new file mode 100644 index 0000000000..47f080b5e3 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/uglify-js/-/uglify-js-2.5.0.tgz.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/url.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/url.bin new file mode 100644 index 0000000000..8bc1a74354 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/url.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/util.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/util.bin new file mode 100644 index 0000000000..3d5eda3861 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/util.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/vm-browserify.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/vm-browserify.bin new file mode 100644 index 0000000000..20cb1bc64f Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/vm-browserify.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/watchpack.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/watchpack.bin new file mode 100644 index 0000000000..82a88e09dd Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/watchpack.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/webpack-core.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/webpack-core.bin new file mode 100644 index 0000000000..b3e93f2952 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/webpack-core.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/webpack-parallel-uglify-plugin.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/webpack-parallel-uglify-plugin.bin new file mode 100644 index 0000000000..694382af58 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/webpack-parallel-uglify-plugin.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/webpack-parallel-uglify-plugin/-/webpack-parallel-uglify-plugin-0.2.0.tgz.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/webpack-parallel-uglify-plugin/-/webpack-parallel-uglify-plugin-0.2.0.tgz.bin new file mode 100644 index 0000000000..4c561f5234 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/webpack-parallel-uglify-plugin/-/webpack-parallel-uglify-plugin-0.2.0.tgz.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/webpack-sources.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/webpack-sources.bin new file mode 100644 index 0000000000..57faa87022 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/webpack-sources.bin differ diff --git a/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/yargs/-/yargs-3.5.4.tgz.bin b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/yargs/-/yargs-3.5.4.tgz.bin new file mode 100644 index 0000000000..cf83a4be07 Binary files /dev/null and b/__tests__/fixtures/request-cache/GET/registry.yarnpkg.com/yargs/-/yargs-3.5.4.tgz.bin differ diff --git a/src/cli/commands/import.js b/src/cli/commands/import.js index bcc2da409d..653b5199da 100644 --- a/src/cli/commands/import.js +++ b/src/cli/commands/import.js @@ -235,9 +235,6 @@ class ImportPackageResolver extends PackageResolver { deps = this.next; this.next = []; if (!deps.length) { - // all required package versions have been discovered, so now packages that - // resolved to existing versions can be resolved to their best available version - this.resolvePackagesWithExistingVersions(); return; } await this.findAll(deps); diff --git a/src/package-request.js b/src/package-request.js index 6db7ff3426..c151c4c32b 100644 --- a/src/package-request.js +++ b/src/package-request.js @@ -32,7 +32,6 @@ export default class PackageRequest { this.optional = req.optional; this.pattern = req.pattern; this.config = resolver.config; - this.foundInfo = null; resolver.usedRegistries.add(req.registry); } @@ -55,7 +54,6 @@ export default class PackageRequest { config: Config; registry: ResolverRegistryNames; optional: boolean; - foundInfo: ?Manifest; getParentNames(): Array { const chain = []; @@ -228,24 +226,6 @@ export default class PackageRequest { reportResolvedRangeMatch(info: Manifest, resolved: Manifest) {} - /** - * Do the final resolve of a package that had a match with an existing version. - * After all unique versions have been discovered, so the best available version - * is found. - */ - resolveToExistingVersion(info: Manifest) { - // get final resolved version - const {range, name} = PackageRequest.normalizePattern(this.pattern); - const resolved: ?Manifest = this.resolver.getHighestRangeVersionMatch(name, range); - invariant(resolved, 'should have a resolved reference'); - - this.reportResolvedRangeMatch(info, resolved); - const ref = resolved._reference; - invariant(ref, 'Resolved package info has no package reference'); - ref.addRequest(this); - ref.addPattern(this.pattern, resolved); - } - /** * TODO description */ @@ -267,7 +247,11 @@ export default class PackageRequest { const {range, name} = PackageRequest.normalizePattern(this.pattern); const resolved: ?Manifest = this.resolver.getHighestRangeVersionMatch(name, range); if (resolved) { - this.resolver.reportPackageWithExistingVersion(this, info); + this.reportResolvedRangeMatch(info, resolved); + const ref = resolved._reference; + invariant(ref, 'Resolved package info has no package reference'); + ref.addRequest(this); + ref.addPattern(this.pattern, resolved); return; } diff --git a/src/package-resolver.js b/src/package-resolver.js index 2ced5a3e29..b05cb2eb97 100644 --- a/src/package-resolver.js +++ b/src/package-resolver.js @@ -26,7 +26,6 @@ export default class PackageResolver { this.reporter = config.reporter; this.lockfile = lockfile; this.config = config; - this.delayedResolveQueue = []; } // whether the dependency graph will be flattened @@ -71,10 +70,6 @@ export default class PackageResolver { // environment specific config methods and options config: Config; - // list of packages need to be resolved later (they found a matching version in the - // resolver, but better matches can still arrive later in the resolve process) - delayedResolveQueue: Array<{req: PackageRequest, info: Manifest}>; - /** * TODO description */ @@ -316,6 +311,9 @@ export default class PackageResolver { addPattern(pattern: string, info: Manifest) { this.patterns[pattern] = info; + if(info.name === 'uglify-js') { + console.log("ADD PATTERN", pattern, info.version) + } const byName = (this.patternsByPackage[info.name] = this.patternsByPackage[info.name] || []); byName.push(pattern); @@ -395,6 +393,9 @@ export default class PackageResolver { return info; }); + if(name === 'uglify-js') { + console.log(versionNumbers) + } const maxValidRange = semver.maxSatisfying(versionNumbers, range); if (!maxValidRange) { @@ -448,6 +449,21 @@ export default class PackageResolver { await request.find(fresh); } + // for a given package name see if less manifests can satisfy most resolutions + optimizeResolutions(name: string, patterns: Array) { + const manifests: Set = new Set(); + // TODO map version to pattern + patterns.forEach(p => { + manifests.add(this.patterns[p]); + }); + const availableVersions: Array = [...manifests].map(m => m.version); + // TODO only non exotic ones + const requiredRanges = patterns.map(p => PackageRequest.normalizePattern(p).range); + + // TODO match availableVersions to ranges so that we get + + } + /** * TODO description */ @@ -457,32 +473,12 @@ export default class PackageResolver { const activity = (this.activity = this.reporter.activity()); await Promise.all(deps.map((req): Promise => this.find(req))); - // all required package versions have been discovered, so now packages that - // resolved to existing versions can be resolved to their best available version - this.resolvePackagesWithExistingVersions(); + Object.keys(this.patternsByPackage).forEach((name) => { + this.optimizeResolutions(name, this.patternsByPackage[name]); + }); + // TODO clean orphan patterns - the ones that are not needed after optimization activity.end(); this.activity = null; } - - /** - * Called by the package requester for packages that this resolver already had - * a matching version for. Delay the resolve, because better matches can still be - * discovered. - */ - - reportPackageWithExistingVersion(req: PackageRequest, info: Manifest) { - this.delayedResolveQueue.push({req, info}); - } - - /** - * Executes the resolve to existing versions for packages after the find process, - * when all versions that are going to be used have been discovered. - */ - - resolvePackagesWithExistingVersions() { - for (const {req, info} of this.delayedResolveQueue) { - req.resolveToExistingVersion(info); - } - } }