Skip to content

Commit

Permalink
install: add --enjoy-by date support for time traveling~
Browse files Browse the repository at this point in the history
  • Loading branch information
zkat committed Oct 31, 2018
1 parent ae9b61d commit d04049f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
15 changes: 15 additions & 0 deletions doc/misc/npm-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,21 @@ commands, eg `dist-tags`, `owner`, etc.

The command to run for `npm edit` or `npm config edit`.

### 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 `enjoy-by` date 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
`enjoy-by` 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`.

### engine-strict

* Default: false
Expand Down
2 changes: 2 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
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('enjoy-by')) {
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 d04049f

Please sign in to comment.