npm-time-proxy
v0.4.0
Published
Allows to proxy requests to NPM and return the latest version valid for a particular date.
Readme
Npm Time Proxy
Sets up a simple proxy on localhost to forward requests to NPM, then monkey-patch them to install only versions available on a particular date.
yarn add npm-time-proxyRunning Binary
The binary can be run as ntp:
yarn ntp --date 2018-5-20 --cleanup -p 5000 -a🟢 npm-time-proxy http://127.0.0.1:5000
⏳ Time-travel npm date set to Oct 10, 2017
.npmrc updated with local registry #auto-ntp.npmrc will be updated automatically with -a option, but if you need, it's
possible to set the localhost proxy registry to .npmrc by hand:
registry=http://localhost:5000/Options
-d,--date: the edge date (pass in format recognised bynew Date);-c,--cache: the cache folder (e.g.,.npm-cache);-p,--port: which port to bind on (default is randomly assigned);-s,--stream: substitute dist-tag: e.g., passnextto serve thenextdist-tag version as latest;-a,--auto: automatically set registry in.npmrc(and clear on exit);--cleanup: remove versions' metadata fields from the response.
API
The package also exposes an API:
import { NpmTimeProxyServer, NpmTimeProxyBin } from 'npm-time-proxy'
var npmTimeProxyServer=new NpmTimeProxyServer({logger,
cacheDir:CACHE_DIR,
cleanup:CLEANUP,
patches:PATCHES,
stream:STREAM,
})
await npmTimeProxyServer.startServer(PORT)
if(TARGET_DATE) {
npmTimeProxyServer.setTargetDate(TARGET_DATE)
}
if(AUTO) {
var npmTimeProxyBin=new NpmTimeProxyBin({url:npmTimeProxyServer.url,logger})
await npmTimeProxyBin.enableLocalRegistry()
}The logger interface has 4 methods:
import { debuglog } from 'util'
var debug=debuglog('NTP')
export var logger={
debug,
log:console.log,
info:console.log,
warn:console.warn,
}