Skip to content

Commit

Permalink
install: add --before date support for time traveling~
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Nov 1, 2018
1 parent ae9b61d commit 12ad62e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
16 changes: 16 additions & 0 deletions doc/misc/npm-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,22 @@ a non-zero exit code.

What authentication strategy to use with `adduser`/`login`.

### before

* Alias: enjoy-by
* Default: null
* Type: Date

If passed to `npm install`, will rebuild the npm tree such that only versions
that were available **on or before** the `before` time get installed.
If there's no versions available for the current set of direct dependencies, the
command will error.

If the requested version is a `dist-tag` and the given tag does not pass the
`before` filter, the most recent version less than or equal to that tag will
be used. For example, `foo@latest` might install `foo@1.2` even though `latest`
is `2.0`.

### bin-links

* Default: `true`
Expand Down
3 changes: 3 additions & 0 deletions lib/config/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ Object.defineProperty(exports, 'defaults', {get: function () {
'dry-run': false,
editor: osenv.editor(),
'engine-strict': false,
'enjoy-by': null,
force: false,

'fetch-retries': 2,
Expand Down Expand Up @@ -279,6 +280,7 @@ exports.types = {
'dry-run': Boolean,
editor: String,
'engine-strict': Boolean,
'enjoy-by': [null, Date],
force: Boolean,
'fetch-retries': Number,
'fetch-retry-factor': Number,
Expand Down Expand Up @@ -394,6 +396,7 @@ function getLocalAddresses () {
}

exports.shorthands = {
before: ['--enjoy-by'],
s: ['--loglevel', 'silent'],
d: ['--loglevel', 'info'],
dd: ['--loglevel', 'verbose'],
Expand Down
21 changes: 19 additions & 2 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,8 +703,25 @@ Installer.prototype.cloneCurrentTreeToIdealTree = function (cb) {
validate('F', arguments)
log.silly('install', 'cloneCurrentTreeToIdealTree')

this.idealTree = copyTree(this.currentTree)
this.idealTree.warnings = []
if (npm.config.get('before')) {
this.idealTree = {
package: this.currentTree.package,
path: this.currentTree.path,
realpath: this.currentTree.realpath,
children: [],
requires: [],
missingDeps: {},
missingDevDeps: {},
requiredBy: [],
error: this.currentTree.error,
warnings: [],
isTop: true
}
} else {
this.idealTree = copyTree(this.currentTree)
this.idealTree.warnings = []
}

cb()
}

Expand Down

0 comments on commit 12ad62e

Please sign in to comment.