diff options
author | Tim Oxley <secoif@gmail.com> | 2014-05-11 01:18:46 +0400 |
---|---|---|
committer | Tim Oxley <secoif@gmail.com> | 2014-05-11 01:18:46 +0400 |
commit | 65f4cb39f27d55a068f98404c35b41e371dec945 (patch) | |
tree | 07c7f7546e9bd047b9d1a1ce6fb24456c7b49a24 | |
parent | c8242a25a091de4cc68e6178ff8fb756657e4902 (diff) |
Stop optional deps moving into deps on update --save
This probably undesirable behaviour stems from normalize-package-data:
> The values in optionalDependencies get added to dependencies. The
optionalDependencies array is left untouched.
Solution Caveat: regular dependencies that are also optional (does that
even make sense?) will not be updated with --save because there's no
way to detect which optional dependencies aren't also regular
dependencies – we just avoid updating anything optional during --save.
-rw-r--r-- | lib/outdated.js | 4 | ||||
-rw-r--r-- | test/tap/update-save.js | 5 |
2 files changed, 5 insertions, 4 deletions
diff --git a/lib/outdated.js b/lib/outdated.js index c053ddeea..ef406fbdc 100644 --- a/lib/outdated.js +++ b/lib/outdated.js @@ -165,6 +165,10 @@ function outdated_ (args, dir, parentHas, depth, cb) { } if (npm.config.get("save")) { + // remove optional dependencies from dependencies during --save. + Object.keys(d.optionalDependencies || {}).forEach(function (k) { + delete deps[k] + }) return next() } diff --git a/test/tap/update-save.js b/test/tap/update-save.js index 7a8801b1c..6323ef851 100644 --- a/test/tap/update-save.js +++ b/test/tap/update-save.js @@ -107,10 +107,7 @@ test("optionalDependencies are merged into dependencies during --save", function t.equal(code, 0) var pkgdata = JSON.parse(fs.readFileSync(PKG, 'utf8')) - t.deepEqual(pkgdata.dependencies, { - mkdirp: '^0.3.5', - underscore: '^1.3.3' - }, 'dependencies should be updated with optional dependencies') + t.deepEqual(pkgdata.dependencies, {mkdirp: '^0.3.5'}, 'dependencies should not include optional dependencies') t.deepEqual(pkgdata.devDependencies, pkg.devDependencies, 'dev dependencies should be untouched') t.deepEqual(pkgdata.optionalDependencies, pkg.optionalDependencies, 'optional dependencies should be untouched') t.end() |