-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
install: add --before date support for time traveling~ (#90)
PR-URL: #90 Credit: @zkat Reviewed-By: @aeschright Reviewed-By: @iarna
- Loading branch information
Showing
4 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 `[email protected]` even though `latest` | ||
is `2.0`. | ||
|
||
### bin-links | ||
|
||
* Default: `true` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
'use strict' | ||
|
||
const BB = require('bluebird') | ||
|
||
const common = require('../common-tap.js') | ||
const mockTar = require('../util/mock-tarball.js') | ||
const mr = common.fakeRegistry.compat | ||
const path = require('path') | ||
const rimraf = BB.promisify(require('rimraf')) | ||
const Tacks = require('tacks') | ||
const { test } = require('tap') | ||
|
||
const { Dir, File } = Tacks | ||
|
||
const testDir = path.join(__dirname, path.basename(__filename, '.js')) | ||
|
||
let server | ||
test('setup', t => { | ||
mr({}, (err, s) => { | ||
t.ifError(err, 'registry mocked successfully') | ||
server = s | ||
t.end() | ||
}) | ||
}) | ||
|
||
test('installs an npm package before a certain date', t => { | ||
const fixture = new Tacks(Dir({ | ||
'package.json': File({}) | ||
})) | ||
fixture.create(testDir) | ||
const packument = { | ||
name: 'foo', | ||
'dist-tags': { latest: '1.2.4' }, | ||
versions: { | ||
'1.2.3': { | ||
name: 'foo', | ||
version: '1.2.3', | ||
dist: { | ||
tarball: `${server.registry}/foo/-/foo-1.2.3.tgz` | ||
} | ||
}, | ||
'1.2.4': { | ||
name: 'foo', | ||
version: '1.2.4', | ||
dist: { | ||
tarball: `${server.registry}/foo/-/foo-1.2.4.tgz` | ||
} | ||
} | ||
}, | ||
time: { | ||
created: '2017-01-01T00:00:01.000Z', | ||
modified: '2018-01-01T00:00:01.000Z', | ||
'1.2.3': '2017-01-01T00:00:01.000Z', | ||
'1.2.4': '2018-01-01T00:00:01.000Z' | ||
} | ||
} | ||
server.get('/foo').reply(200, packument) | ||
return mockTar({ | ||
'package.json': JSON.stringify({ | ||
name: 'foo', | ||
version: '1.2.3' | ||
}) | ||
}).then(tarball => { | ||
server.get('/foo/-/foo-1.2.3.tgz').reply(200, tarball) | ||
server.get('/foo/-/foo-1.2.4.tgz').reply(500) | ||
return common.npm([ | ||
'install', 'foo', | ||
'--before', '2018', | ||
'--json', | ||
'--cache', path.join(testDir, 'npmcache'), | ||
'--registry', server.registry | ||
], { cwd: testDir }) | ||
}).then(([code, stdout, stderr]) => { | ||
t.comment(stdout) | ||
t.comment(stderr) | ||
t.like(JSON.parse(stdout), { | ||
added: [{ | ||
action: 'add', | ||
name: 'foo', | ||
version: '1.2.3' | ||
}] | ||
}, 'installed the 2017 version of the package') | ||
}) | ||
}) | ||
|
||
test('cleanup', t => { | ||
server.close() | ||
return rimraf(testDir) | ||
}) |