Permalink
Browse files

Add --save-exact config for --save[-dev|-optional].

Related:
#4713
#4587
  • Loading branch information...
timoxley authored and isaacs committed Feb 20, 2014
1 parent 2ddd060 commit 17f07df8ad8e594304c2445bf7489cb53346f2c5
View
@@ -7,7 +7,7 @@ npm-install(1) -- Install a package
npm install <tarball file>
npm install <tarball url>
npm install <folder>
- npm install <name> [--save|--save-dev|--save-optional]
+ npm install <name> [--save|--save-dev|--save-optional] [--save-exact]
npm install <name>@<tag>
npm install <name>@<version>
npm install <name>@<version range>
@@ -91,11 +91,19 @@ after packing it up into a tarball (b).
* `--save-optional`: Package will appear in your `optionalDependencies`.
+ When using any of the above options to save dependencies to your
+ package.json, there is an additional, optional flag:
+
+ * `--save-exact`: Saved dependencies will be configured with an
@sam-github

sam-github Jul 5, 2014

Any chance of renaming this to --exact? It's confusing as-is:

  • --save-optional: save in optional section
  • --save-dev: save in dev ...
  • --save-exact: save in the exact section... oh, wait, modifies one of the other --save* options

Probably the horse has already bolted on this, but --save-exact could be de-documented, and --exact described. Here's hoping... The person sitting beside me in the node conf npm workshop was pretty stumped on this, fwiw.

@rlidwka

rlidwka Jul 6, 2014

Contributor

what about --save-prefix ?

@sam-github

sam-github Jul 7, 2014

I don't think any of the modifiers to save should have --save- in front, and --save-prefix has some other issues: timoxley/npm-tutor#5

@othiym23

othiym23 Jul 7, 2014

Contributor

I'm with @sam-github on this one. Tim, what do you think? (Since this is in the wild, it would probably be best to keep --save-exact for a while, maybe with a deprecation message, and add --exact.)

@rlidwka

rlidwka Jul 10, 2014

Contributor

--exact is too generic, and because of the way how npmconf works, you might forbid using exact config key in the future for whatever reason.

If you want a shortcut, I believe -E exists already.

@timoxley

timoxley Jul 31, 2014

Member

@othiym23 oops I didn't see these comments.

I don't think any of the modifiers to save should have --save- in front

I am also with @sam-github on this, it's hard to tell someone with a straight face that they need to type both --save-exact and --save. This commit originally used --exact, I believe @isaacs modified the flag to --save-exact for similar reasons stated by @rlidwka, but my preference would be to cross the bridge of conflicting meanings for --exact when we get to that, and optimise for the end-user experience of today.

@timoxley

timoxley Jul 31, 2014

Member

@othiym23 I'll leave this to you to raise to an issue if you think this is something to tackle

+ exact version rather than using npm's default semver range
+ operator.
+
Examples:
npm install sax --save
npm install node-tap --save-dev
npm install dtrace-provider --save-optional
+ npm install readable-stream --save --save-exact
**Note**: If there is a file or folder named `<name>` in the current
View
@@ -60,6 +60,7 @@ The following shorthands are parsed on the command-line:
* `-D`: `--save-dev`
* `-O`: `--save-optional`
* `-B`: `--save-bundle`
+* `-E`: `--save-exact`
* `-y`: `--yes`
* `-n`: `--yes false`
* `ll` and `la` commands: `ls --long`
@@ -620,20 +621,30 @@ bundledDependencies list.
Save installed packages to a package.json file as devDependencies.
-When used with the `npm rm` command, it removes it from the devDependencies
-hash.
+When used with the `npm rm` command, it removes it from the
+devDependencies hash.
Only works if there is already a package.json file present.
+### save-exact
+
+* Default: false
+* Type: Boolean
+
+Dependencies saved to package.json using `--save`, `--save-dev` or
+`--save-optional` will be configured with an exact version rather than
+using npm's default semver range operator.
+
### save-optional
* Default: false
* Type: Boolean
-Save installed packages to a package.json file as optionalDependencies.
+Save installed packages to a package.json file as
+optionalDependencies.
-When used with the `npm rm` command, it removes it from the devDependencies
-hash.
+When used with the `npm rm` command, it removes it from the
+devDependencies hash.
Only works if there is already a package.json file present.
View
@@ -351,7 +351,8 @@ function save (where, installed, tree, pretty, hasArguments, cb) {
return w
}).reduce(function (set, k) {
var rangeDescriptor = semver.valid(k[1], true) &&
- semver.gte(k[1], "0.1.0", true)
+ semver.gte(k[1], "0.1.0", true) &&
+ !npm.config.get("save-exact")
? "^" : ""
set[k[0]] = rangeDescriptor + k[1]
return set

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -34,108 +34,108 @@
"main": "./lib/npm.js",
"bin": "./bin/npm-cli.js",
"dependencies": {
- "semver": "~2.2.1",
- "ini": "~1.1.0",
- "slide": "~1.1.5",
"abbrev": "~1.0.4",
- "graceful-fs": "^2.0.2",
- "minimatch": "~0.2.14",
- "nopt": "^2.2.0",
- "rimraf": "~2.2.5",
- "request": "~2.30.0",
- "which": "1",
- "tar": "~0.1.19",
- "fstream": "~0.1.25",
- "block-stream": "0.0.7",
- "mkdirp": "~0.3.5",
- "read": "~1.0.4",
- "lru-cache": "~2.5.0",
- "node-gyp": "~0.12.2",
- "fstream-npm": "~0.1.6",
- "uid-number": "0.0.5",
+ "ansi": "~0.2.1",
+ "ansicolors": "~0.3.2",
+ "ansistyles": "~0.1.3",
"archy": "0",
+ "block-stream": "0.0.7",
+ "child-process-close": "~0.1.1",
+ "chmodr": "~0.1.0",
"chownr": "0",
- "npmlog": "0.0.6",
- "ansi": "~0.2.1",
- "npm-registry-client": "^0.4.4",
- "read-package-json": "~1.1.7",
- "read-installed": "~1.0.0",
+ "cmd-shim": "~1.1.1",
+ "columnify": "0.1.2",
+ "editor": "0.0.5",
+ "fstream": "~0.1.25",
+ "fstream-npm": "~0.1.6",
+ "github-url-from-git": "1.1.1",
+ "github-url-from-username-repo": "0.0.2",
"glob": "3.2.7",
+ "graceful-fs": "^2.0.2",
+ "ini": "~1.1.0",
"init-package-json": "0.0.14",
- "osenv": "0",
"lockfile": "~0.4.0",
- "retry": "~0.6.0",
+ "lru-cache": "~2.5.0",
+ "minimatch": "~0.2.14",
+ "mkdirp": "~0.3.5",
+ "node-gyp": "~0.12.2",
+ "nopt": "^2.2.0",
+ "npm-install-checks": "~1.0.0",
+ "npm-registry-client": "^0.4.4",
+ "npm-user-validate": "0.0.3",
+ "npmconf": "^0.1.13",
+ "npmlog": "0.0.6",
"once": "~1.3.0",
- "npmconf": "~0.1.12",
"opener": "~1.3.0",
- "chmodr": "~0.1.0",
- "cmd-shim": "~1.1.1",
+ "osenv": "0",
+ "path-is-inside": "~1.0.0",
+ "read": "~1.0.4",
+ "read-installed": "~1.0.0",
+ "read-package-json": "~1.1.7",
+ "request": "~2.30.0",
+ "retry": "~0.6.0",
+ "rimraf": "~2.2.5",
+ "semver": "~2.2.1",
"sha": "~1.2.1",
- "editor": "0.0.5",
- "child-process-close": "~0.1.1",
- "npm-user-validate": "0.0.3",
- "github-url-from-git": "1.1.1",
- "github-url-from-username-repo": "0.0.2",
+ "slide": "~1.1.5",
+ "sorted-object": "~1.0.0",
+ "tar": "~0.1.19",
"text-table": "~0.2.0",
- "ansicolors": "~0.3.2",
- "ansistyles": "~0.1.3",
- "path-is-inside": "~1.0.0",
- "columnify": "0.1.2",
- "npm-install-checks": "~1.0.0",
- "sorted-object": "~1.0.0"
+ "uid-number": "0.0.5",
+ "which": "1"
},
"bundleDependencies": [
- "semver",
- "ini",
- "slide",
"abbrev",
- "graceful-fs",
- "minimatch",
- "nopt",
- "rimraf",
- "request",
- "which",
- "tar",
- "fstream",
- "block-stream",
- "inherits",
- "mkdirp",
- "read",
- "lru-cache",
- "node-gyp",
- "fstream-npm",
- "uid-number",
+ "ansi",
+ "ansicolors",
+ "ansistyles",
"archy",
+ "block-stream",
+ "child-process-close",
+ "chmodr",
"chownr",
- "npmlog",
- "ansi",
- "npm-registry-client",
- "read-package-json",
- "read-installed",
+ "cmd-shim",
+ "columnify",
+ "editor",
+ "fstream",
+ "fstream-npm",
+ "github-url-from-git",
+ "github-url-from-username-repo",
"glob",
+ "graceful-fs",
+ "inherits",
+ "ini",
"init-package-json",
- "osenv",
"lockfile",
- "retry",
- "once",
+ "lru-cache",
+ "minimatch",
+ "mkdirp",
+ "node-gyp",
+ "nopt",
+ "normalize-package-data",
+ "npm-install-checks",
+ "npm-registry-client",
+ "npm-user-validate",
"npmconf",
+ "npmlog",
+ "once",
"opener",
- "chmodr",
- "cmd-shim",
+ "osenv",
+ "path-is-inside",
+ "read",
+ "read-installed",
+ "read-package-json",
+ "request",
+ "retry",
+ "rimraf",
+ "semver",
"sha",
- "child-process-close",
- "editor",
- "npm-user-validate",
- "github-url-from-git",
- "github-url-from-username-repo",
- "normalize-package-data",
+ "slide",
+ "sorted-object",
+ "tar",
"text-table",
- "ansicolors",
- "ansistyles",
- "path-is-inside",
- "columnify",
- "npm-install-checks",
- "sorted-object"
+ "uid-number",
+ "which"
],
"devDependencies": {
"ronn": "~0.3.6",
Oops, something went wrong.

0 comments on commit 17f07df

Please sign in to comment.