From 33cad2ef95cd6c691432a5b2a1fc3bb98c62465f Mon Sep 17 00:00:00 2001 From: zenorbi Date: Wed, 12 Apr 2017 09:39:00 +0200 Subject: [PATCH 1/4] trying to fix flickering peer dependency range issue --- lib/install.js | 19 ++++++++++++++++--- lib/semver.js | 5 +++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/install.js b/lib/install.js index aff1d4091..5bcfc2dd5 100644 --- a/lib/install.js +++ b/lib/install.js @@ -499,12 +499,25 @@ function install(name, target, options, seen) { options.peer = true; } + function replaceDependency(dependencies, name, newPackage) { + var existingDependency = dependencies[name]; + if (!existingDependency) { //No existing dependency + dependencies[name] = newPackage; + } else { //Enforce maximum compatibility version + var existingMinVersion = semver.rangeToMinSemver(existingDependency.version); + var matches = semver.match(newPackage.version, existingMinVersion); + if (!matches) { //Need to update because current min version would not match the criteria set by this package + dependencies[name] = newPackage; + } + } + } + if (options.peer) - config.pjson.peerDependencies[name] = primaryRanges[name]; + replaceDependency(config.pjson.peerDependencies, name, primaryRanges[name]); else if (options.dev) - config.pjson.devDependencies[name] = primaryRanges[name]; + replaceDependency(config.pjson.devDependencies, name, primaryRanges[name]); else - config.pjson.dependencies[name] = primaryRanges[name]; + replaceDependency(config.pjson.dependencies, name, primaryRanges[name]); // remove any alternative installs of this dependency if (!options.dev) diff --git a/lib/semver.js b/lib/semver.js index 2375ab102..f49eb7cd2 100644 --- a/lib/semver.js +++ b/lib/semver.js @@ -190,6 +190,11 @@ function parseRange(range) { exports.semverRegEx = semverRegEx; +exports.rangeToMinSemver = function(r) { + var parsed = parseRange(r).version; + return parsed.major + "." + parsed.minor + "." + parsed.patch; +}; + exports.compare = function(v1, v2) { return semverCompareParsed(parseSemver(v1), parseSemver(v2)); }; From 61fd6986d8ddc22d695e9e58aa11c7e57bf77b56 Mon Sep 17 00:00:00 2001 From: zenorbi Date: Wed, 12 Apr 2017 16:17:07 +0200 Subject: [PATCH 2/4] codestyle fix --- lib/semver.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/semver.js b/lib/semver.js index f49eb7cd2..a4a95add7 100644 --- a/lib/semver.js +++ b/lib/semver.js @@ -192,7 +192,7 @@ exports.semverRegEx = semverRegEx; exports.rangeToMinSemver = function(r) { var parsed = parseRange(r).version; - return parsed.major + "." + parsed.minor + "." + parsed.patch; + return parsed.major + '.' + parsed.minor + '.' + parsed.patch; }; exports.compare = function(v1, v2) { From ac9386253a29253bb7295f26df136cef03bca399 Mon Sep 17 00:00:00 2001 From: zenorbi Date: Thu, 13 Apr 2017 14:31:04 +0200 Subject: [PATCH 3/4] add flickering-peer-repro --- flickering-peer-repro/.gitignore | 3 + flickering-peer-repro/README.md | 9 +++ .../node_modules/test-registry/index.js | 70 +++++++++++++++++++ .../node_modules/test-registry/package.json | 4 ++ .../test-registry/packages/main/package.json | 11 +++ .../packages/multiversion/package.json | 5 ++ .../packages/package-a/package.json | 10 +++ .../packages/package-b/package.json | 10 +++ flickering-peer-repro/package.json | 15 ++++ flickering-peer-repro/repro.js | 17 +++++ 10 files changed, 154 insertions(+) create mode 100644 flickering-peer-repro/.gitignore create mode 100644 flickering-peer-repro/README.md create mode 100644 flickering-peer-repro/node_modules/test-registry/index.js create mode 100644 flickering-peer-repro/node_modules/test-registry/package.json create mode 100644 flickering-peer-repro/node_modules/test-registry/packages/main/package.json create mode 100644 flickering-peer-repro/node_modules/test-registry/packages/multiversion/package.json create mode 100644 flickering-peer-repro/node_modules/test-registry/packages/package-a/package.json create mode 100644 flickering-peer-repro/node_modules/test-registry/packages/package-b/package.json create mode 100644 flickering-peer-repro/package.json create mode 100644 flickering-peer-repro/repro.js diff --git a/flickering-peer-repro/.gitignore b/flickering-peer-repro/.gitignore new file mode 100644 index 000000000..1f6df0d2f --- /dev/null +++ b/flickering-peer-repro/.gitignore @@ -0,0 +1,3 @@ +jspm_packages +jspm.config.js +!/node_modules diff --git a/flickering-peer-repro/README.md b/flickering-peer-repro/README.md new file mode 100644 index 000000000..66c507403 --- /dev/null +++ b/flickering-peer-repro/README.md @@ -0,0 +1,9 @@ +- Run `node repro.js` +- See how `package.json` will contain `"multiversion": "testing:multiversion@^1.0.0"` +- Switch the lookup delays around so package-b resolves first +- Run `node repro.js` +- See how `package.json` will contain `"multiversion": "testing:multiversion@^1.1.0"` + +Expected: + +Always choose the stricter version. `package-a` wants `^1.0.0` and `package-b` wants `^1.1.0`. The correct behavior should be to always use the `^1.1.0`. diff --git a/flickering-peer-repro/node_modules/test-registry/index.js b/flickering-peer-repro/node_modules/test-registry/index.js new file mode 100644 index 000000000..5af5c4c5f --- /dev/null +++ b/flickering-peer-repro/node_modules/test-registry/index.js @@ -0,0 +1,70 @@ +const ncp = require("ncp"); +const path = require("path"); + +var testPackages = { + "main": { + "lookupDelay": 0, + "lookup": { + "1.0.0": { + "hash": Date.now() + } + } + }, + "package-a": { + "lookupDelay": 0, + "lookup": { + "1.0.0": { + "hash": Date.now() + } + } + }, + "package-b": { + "lookupDelay": 0, + "lookup": { + "1.0.0": { + "hash": Date.now() + } + } + }, + "multiversion": { + "lookupDelay": 0, + "lookup": { + "1.2.0": { + "hash": Date.now() + } + } + } +} + +function sleep(ms) { + return new Promise(function(resolve) { + setTimeout(resolve, ms); + }); +} + +function Registry() { + +} + +Registry.prototype.lookup = function(packageName) { + const package = testPackages[packageName]; + return sleep(package.lookupDelay).then(function() { + return {versions: testPackages[packageName].lookup}; + }); +}; + +Registry.prototype.download = function(packageName, version, hash, meta, dir) { + const package = testPackages[packageName]; + return sleep(package.downloadDelay).then(function() { + return new Promise(function(resolve, reject) { + ncp(path.join(__dirname, "packages", packageName), dir, function(err) { + if (err) reject(err); + else resolve(); + }); + }) + }); +}; + +Registry.testPackages = testPackages; + +module.exports = Registry; \ No newline at end of file diff --git a/flickering-peer-repro/node_modules/test-registry/package.json b/flickering-peer-repro/node_modules/test-registry/package.json new file mode 100644 index 000000000..94ab8cd41 --- /dev/null +++ b/flickering-peer-repro/node_modules/test-registry/package.json @@ -0,0 +1,4 @@ +{ + "name": "test-registry", + "version": "1.0.0" +} \ No newline at end of file diff --git a/flickering-peer-repro/node_modules/test-registry/packages/main/package.json b/flickering-peer-repro/node_modules/test-registry/packages/main/package.json new file mode 100644 index 000000000..31434d801 --- /dev/null +++ b/flickering-peer-repro/node_modules/test-registry/packages/main/package.json @@ -0,0 +1,11 @@ +{ + "name": "main", + "version": "1.0.0", + "jspm": { + "registry": "testing", + "dependencies": { + "package-a": "1.0.0", + "package-b": "1.0.0" + } + } +} \ No newline at end of file diff --git a/flickering-peer-repro/node_modules/test-registry/packages/multiversion/package.json b/flickering-peer-repro/node_modules/test-registry/packages/multiversion/package.json new file mode 100644 index 000000000..1cddf4b25 --- /dev/null +++ b/flickering-peer-repro/node_modules/test-registry/packages/multiversion/package.json @@ -0,0 +1,5 @@ +{ + "name": "multiversion", + "version": "1.2.0", + "jspm": {} +} \ No newline at end of file diff --git a/flickering-peer-repro/node_modules/test-registry/packages/package-a/package.json b/flickering-peer-repro/node_modules/test-registry/packages/package-a/package.json new file mode 100644 index 000000000..5e312887e --- /dev/null +++ b/flickering-peer-repro/node_modules/test-registry/packages/package-a/package.json @@ -0,0 +1,10 @@ +{ + "name": "package-a", + "version": "1.0.0", + "jspm": { + "registry": "testing", + "peerDependencies": { + "multiversion": "^1.0.0" + } + } +} \ No newline at end of file diff --git a/flickering-peer-repro/node_modules/test-registry/packages/package-b/package.json b/flickering-peer-repro/node_modules/test-registry/packages/package-b/package.json new file mode 100644 index 000000000..4bab780bc --- /dev/null +++ b/flickering-peer-repro/node_modules/test-registry/packages/package-b/package.json @@ -0,0 +1,10 @@ +{ + "name": "package-b", + "version": "1.0.0", + "jspm": { + "registry": "testing", + "peerDependencies": { + "multiversion": "^1.1.0" + } + } +} \ No newline at end of file diff --git a/flickering-peer-repro/package.json b/flickering-peer-repro/package.json new file mode 100644 index 000000000..56ce03721 --- /dev/null +++ b/flickering-peer-repro/package.json @@ -0,0 +1,15 @@ +{ + "jspm": { + "name": "app", + "main": "app.js", + "dependencies": { + "main": "testing:main@^1.0.0" + }, + "devDependencies": { + "plugin-babel": "npm:systemjs-plugin-babel@^0.0.21" + }, + "peerDependencies": { + "multiversion": "testing:multiversion@^1.0.0" + } + } +} diff --git a/flickering-peer-repro/repro.js b/flickering-peer-repro/repro.js new file mode 100644 index 000000000..013b26955 --- /dev/null +++ b/flickering-peer-repro/repro.js @@ -0,0 +1,17 @@ +const jspm = require("../api.js"); +const globalConfig = require("../lib/config/global-config"); +const rimraf = require("rimraf"); +const registry = require("test-registry"); + +const testRegistryConfig = globalConfig.config.registries.testing || {}; +globalConfig.config.registries.testing = testRegistryConfig; +testRegistryConfig.handler = "test-registry"; + +rimraf.sync("package.json"); +rimraf.sync("jspm.config.js"); +rimraf.sync("jspm_packages"); + +registry.testPackages["package-a"].lookupDelay = 0; +registry.testPackages["package-b"].lookupDelay = 100; + +jspm.install("main", "testing:main@^1.0.0", {force: true}); From 144285342589b702a5042eb86fdf2ecff6ae49a4 Mon Sep 17 00:00:00 2001 From: zenorbi Date: Thu, 20 Apr 2017 13:09:25 +0200 Subject: [PATCH 4/4] remove flickering-peer-repro dir (moved to github: zenorbi/jspm-peer-dependency-flicker-repro) --- flickering-peer-repro/.gitignore | 3 - flickering-peer-repro/README.md | 9 --- .../node_modules/test-registry/index.js | 70 ------------------- .../node_modules/test-registry/package.json | 4 -- .../test-registry/packages/main/package.json | 11 --- .../packages/multiversion/package.json | 5 -- .../packages/package-a/package.json | 10 --- .../packages/package-b/package.json | 10 --- flickering-peer-repro/package.json | 15 ---- flickering-peer-repro/repro.js | 17 ----- 10 files changed, 154 deletions(-) delete mode 100644 flickering-peer-repro/.gitignore delete mode 100644 flickering-peer-repro/README.md delete mode 100644 flickering-peer-repro/node_modules/test-registry/index.js delete mode 100644 flickering-peer-repro/node_modules/test-registry/package.json delete mode 100644 flickering-peer-repro/node_modules/test-registry/packages/main/package.json delete mode 100644 flickering-peer-repro/node_modules/test-registry/packages/multiversion/package.json delete mode 100644 flickering-peer-repro/node_modules/test-registry/packages/package-a/package.json delete mode 100644 flickering-peer-repro/node_modules/test-registry/packages/package-b/package.json delete mode 100644 flickering-peer-repro/package.json delete mode 100644 flickering-peer-repro/repro.js diff --git a/flickering-peer-repro/.gitignore b/flickering-peer-repro/.gitignore deleted file mode 100644 index 1f6df0d2f..000000000 --- a/flickering-peer-repro/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -jspm_packages -jspm.config.js -!/node_modules diff --git a/flickering-peer-repro/README.md b/flickering-peer-repro/README.md deleted file mode 100644 index 66c507403..000000000 --- a/flickering-peer-repro/README.md +++ /dev/null @@ -1,9 +0,0 @@ -- Run `node repro.js` -- See how `package.json` will contain `"multiversion": "testing:multiversion@^1.0.0"` -- Switch the lookup delays around so package-b resolves first -- Run `node repro.js` -- See how `package.json` will contain `"multiversion": "testing:multiversion@^1.1.0"` - -Expected: - -Always choose the stricter version. `package-a` wants `^1.0.0` and `package-b` wants `^1.1.0`. The correct behavior should be to always use the `^1.1.0`. diff --git a/flickering-peer-repro/node_modules/test-registry/index.js b/flickering-peer-repro/node_modules/test-registry/index.js deleted file mode 100644 index 5af5c4c5f..000000000 --- a/flickering-peer-repro/node_modules/test-registry/index.js +++ /dev/null @@ -1,70 +0,0 @@ -const ncp = require("ncp"); -const path = require("path"); - -var testPackages = { - "main": { - "lookupDelay": 0, - "lookup": { - "1.0.0": { - "hash": Date.now() - } - } - }, - "package-a": { - "lookupDelay": 0, - "lookup": { - "1.0.0": { - "hash": Date.now() - } - } - }, - "package-b": { - "lookupDelay": 0, - "lookup": { - "1.0.0": { - "hash": Date.now() - } - } - }, - "multiversion": { - "lookupDelay": 0, - "lookup": { - "1.2.0": { - "hash": Date.now() - } - } - } -} - -function sleep(ms) { - return new Promise(function(resolve) { - setTimeout(resolve, ms); - }); -} - -function Registry() { - -} - -Registry.prototype.lookup = function(packageName) { - const package = testPackages[packageName]; - return sleep(package.lookupDelay).then(function() { - return {versions: testPackages[packageName].lookup}; - }); -}; - -Registry.prototype.download = function(packageName, version, hash, meta, dir) { - const package = testPackages[packageName]; - return sleep(package.downloadDelay).then(function() { - return new Promise(function(resolve, reject) { - ncp(path.join(__dirname, "packages", packageName), dir, function(err) { - if (err) reject(err); - else resolve(); - }); - }) - }); -}; - -Registry.testPackages = testPackages; - -module.exports = Registry; \ No newline at end of file diff --git a/flickering-peer-repro/node_modules/test-registry/package.json b/flickering-peer-repro/node_modules/test-registry/package.json deleted file mode 100644 index 94ab8cd41..000000000 --- a/flickering-peer-repro/node_modules/test-registry/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "test-registry", - "version": "1.0.0" -} \ No newline at end of file diff --git a/flickering-peer-repro/node_modules/test-registry/packages/main/package.json b/flickering-peer-repro/node_modules/test-registry/packages/main/package.json deleted file mode 100644 index 31434d801..000000000 --- a/flickering-peer-repro/node_modules/test-registry/packages/main/package.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "name": "main", - "version": "1.0.0", - "jspm": { - "registry": "testing", - "dependencies": { - "package-a": "1.0.0", - "package-b": "1.0.0" - } - } -} \ No newline at end of file diff --git a/flickering-peer-repro/node_modules/test-registry/packages/multiversion/package.json b/flickering-peer-repro/node_modules/test-registry/packages/multiversion/package.json deleted file mode 100644 index 1cddf4b25..000000000 --- a/flickering-peer-repro/node_modules/test-registry/packages/multiversion/package.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "name": "multiversion", - "version": "1.2.0", - "jspm": {} -} \ No newline at end of file diff --git a/flickering-peer-repro/node_modules/test-registry/packages/package-a/package.json b/flickering-peer-repro/node_modules/test-registry/packages/package-a/package.json deleted file mode 100644 index 5e312887e..000000000 --- a/flickering-peer-repro/node_modules/test-registry/packages/package-a/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "package-a", - "version": "1.0.0", - "jspm": { - "registry": "testing", - "peerDependencies": { - "multiversion": "^1.0.0" - } - } -} \ No newline at end of file diff --git a/flickering-peer-repro/node_modules/test-registry/packages/package-b/package.json b/flickering-peer-repro/node_modules/test-registry/packages/package-b/package.json deleted file mode 100644 index 4bab780bc..000000000 --- a/flickering-peer-repro/node_modules/test-registry/packages/package-b/package.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "name": "package-b", - "version": "1.0.0", - "jspm": { - "registry": "testing", - "peerDependencies": { - "multiversion": "^1.1.0" - } - } -} \ No newline at end of file diff --git a/flickering-peer-repro/package.json b/flickering-peer-repro/package.json deleted file mode 100644 index 56ce03721..000000000 --- a/flickering-peer-repro/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "jspm": { - "name": "app", - "main": "app.js", - "dependencies": { - "main": "testing:main@^1.0.0" - }, - "devDependencies": { - "plugin-babel": "npm:systemjs-plugin-babel@^0.0.21" - }, - "peerDependencies": { - "multiversion": "testing:multiversion@^1.0.0" - } - } -} diff --git a/flickering-peer-repro/repro.js b/flickering-peer-repro/repro.js deleted file mode 100644 index 013b26955..000000000 --- a/flickering-peer-repro/repro.js +++ /dev/null @@ -1,17 +0,0 @@ -const jspm = require("../api.js"); -const globalConfig = require("../lib/config/global-config"); -const rimraf = require("rimraf"); -const registry = require("test-registry"); - -const testRegistryConfig = globalConfig.config.registries.testing || {}; -globalConfig.config.registries.testing = testRegistryConfig; -testRegistryConfig.handler = "test-registry"; - -rimraf.sync("package.json"); -rimraf.sync("jspm.config.js"); -rimraf.sync("jspm_packages"); - -registry.testPackages["package-a"].lookupDelay = 0; -registry.testPackages["package-b"].lookupDelay = 100; - -jspm.install("main", "testing:main@^1.0.0", {force: true});