Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
dd90c43
tar-stream@2.0.0
zkat Feb 14, 2019
cec1e82
test: add mock-tarball utility
zkat Feb 14, 2019
ee6b674
agent-base@4.2.1
zkat Feb 18, 2019
684bccf
install: always save package_lock.json when using `--package-lock-onl…
aeschright Feb 18, 2019
cf09fba
view: set modified to undefined when not retrievable (#153)
simonua Feb 18, 2019
774fc26
install.sh: print out tar version when the flag is supported (#154)
agudulin Feb 18, 2019
863baff
stars: Fix typo in error message (#158)
phihag Feb 18, 2019
5d76338
doc: add npm add as alias to npm install (#160)
ahasall Feb 18, 2019
489c221
docs: updating link to RFC #10 in the changelog (#162)
mansona Feb 18, 2019
b8b8afd
run-script: Check run script existence with undefined (#139)
vlasy Feb 18, 2019
a805a95
error-message: strip version info from pkg on E404 (#132)
larsgw Feb 18, 2019
433020e
docs: described exit codes in npm-audit docs
emilis-tm Jan 9, 2019
8047b19
install: match git semver ranges (#115)
larsgw Feb 18, 2019
e135c2b
update: re-enable updating local packages
larsgw Oct 2, 2018
2ce23ba
lock-verify@2.1.0
zkat Feb 18, 2019
b7b54f2
install: add support for package aliases (#3)
zkat Feb 18, 2019
baaedbc
pacote@9.5.0
zkat Feb 18, 2019
2ba3a0f
install: add --before date support for time traveling~ (#90)
zkat Feb 19, 2019
57e771a
licensee@6.1.0 (#164)
kemitchell Feb 19, 2019
2b78288
test: add core to default inclusion tests in pack
zkat Feb 20, 2019
9b8b651
npm-packlist@1.4.1
zkat Feb 20, 2019
96e4fa9
tap@12.5.3
zkat Feb 20, 2019
f957798
doc: update changelog for npm@6.9.0
zkat Feb 20, 2019
5ac0950
update AUTHORS
zkat Feb 20, 2019
de0ebe1
6.9.0-next.0
zkat Feb 20, 2019
656bce7
6.9.0
zkat Mar 6, 2019
6b1a9da
Update `knownBroken` version (#165)
ljharb Mar 19, 2019
d075471
outdated: fix rendering for global dependencies (#173)
zkat Mar 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
install: add --before date support for time traveling~ (#90)
PR-URL: #90
Credit: @zkat
Reviewed-By: @aeschright
Reviewed-By: @iarna
  • Loading branch information
zkat authored Feb 19, 2019
commit 2ba3a0f6721f6d5a16775aebce6012965634fc7c
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 @@ -113,6 +113,7 @@ Object.defineProperty(exports, 'defaults', {get: function () {
'audit-level': 'low',
'auth-type': 'legacy',

'before': null,
'bin-links': true,
browser: null,

Expand Down Expand Up @@ -260,6 +261,7 @@ exports.types = {
audit: Boolean,
'audit-level': ['low', 'moderate', 'high', 'critical'],
'auth-type': ['legacy', 'sso', 'saml', 'oauth'],
'before': [null, Date],
'bin-links': Boolean,
browser: [null, String],
ca: [null, String, Array],
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
89 changes: 89 additions & 0 deletions test/tap/install-before.js
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)
})