npm-registry-fetch
Advanced tools
Comparing version 3.1.1 to 3.2.0
@@ -30,7 +30,7 @@ 'use strict' | ||
function addKey (opts, obj, scope, key, objKey) { | ||
if (opts.get(key)) { | ||
obj[objKey || key] = opts.get(key) | ||
if (opts[key]) { | ||
obj[objKey || key] = opts[key] | ||
} | ||
if (scope && opts.get(`${scope}:${key}`)) { | ||
obj[objKey || key] = opts.get(`${scope}:${key}`) | ||
if (scope && opts[`${scope}:${key}`]) { | ||
obj[objKey || key] = opts[`${scope}:${key}`] | ||
} | ||
@@ -37,0 +37,0 @@ } |
@@ -5,2 +5,12 @@ # Change Log | ||
<a name="3.2.0"></a> | ||
# [3.2.0](https://github.com/npm/registry-fetch/compare/v3.1.1...v3.2.0) (2018-07-27) | ||
### Features | ||
* **gzip:** add opts.gzip convenience opt ([340abe0](https://github.com/npm/registry-fetch/commit/340abe0)) | ||
<a name="3.1.1"></a> | ||
@@ -7,0 +17,0 @@ ## [3.1.1](https://github.com/npm/registry-fetch/compare/v3.1.0...v3.1.1) (2018-04-09) |
@@ -11,3 +11,3 @@ 'use strict' | ||
if (res.headers.has('npm-notice') && !res.headers.has('x-local-cache')) { | ||
opts.get('log').notice('', res.headers.get('npm-notice')) | ||
opts.log.notice('', res.headers.get('npm-notice')) | ||
} | ||
@@ -29,3 +29,3 @@ checkWarnings(res, registry, opts) | ||
const cacheStr = res.headers.get('x-local-cache') ? ' (from cache)' : '' | ||
opts.get('log').http( | ||
opts.log.http( | ||
'fetch', | ||
@@ -56,5 +56,5 @@ `${method.toUpperCase()} ${res.status} ${res.url} ${elapsedTime}ms${attemptStr}${cacheStr}` | ||
if (warnings['199'].message.match(/ENOTFOUND/)) { | ||
opts.get('log').warn('registry', `Using stale data from ${registry} because the host is inaccessible -- are you offline?`) | ||
opts.log.warn('registry', `Using stale data from ${registry} because the host is inaccessible -- are you offline?`) | ||
} else { | ||
opts.get('log').warn('registry', `Unexpected warning for ${registry}: ${warnings['199'].message}`) | ||
opts.log.warn('registry', `Unexpected warning for ${registry}: ${warnings['199'].message}`) | ||
} | ||
@@ -64,3 +64,3 @@ } | ||
// 111 Revalidation failed -- we're using stale data | ||
opts.get('log').warn( | ||
opts.log.warn( | ||
'registry', | ||
@@ -67,0 +67,0 @@ `Using stale data from ${registry} due to a request error during revalidation.` |
@@ -21,2 +21,3 @@ 'use strict' | ||
'gid': {}, | ||
'gzip': {}, | ||
'headers': {}, | ||
@@ -60,3 +61,3 @@ 'https-proxy': {}, | ||
'project-scope': 'projectScope', | ||
'Promise': {}, | ||
'Promise': {default: () => Promise}, | ||
'proxy': {}, | ||
@@ -63,0 +64,0 @@ 'query': {}, |
105
index.js
@@ -12,2 +12,3 @@ 'use strict' | ||
const url = require('url') | ||
const zlib = require('zlib') | ||
@@ -18,4 +19,4 @@ module.exports = regFetch | ||
const registry = ( | ||
(opts.get('spec') && pickRegistry(opts.get('spec'), opts)) || | ||
opts.get('registry') || | ||
(opts.spec && pickRegistry(opts.spec, opts)) || | ||
opts.registry || | ||
'https://registry.npmjs.org/' | ||
@@ -33,3 +34,3 @@ ) | ||
const headers = getHeaders(registry, uri, opts) | ||
let body = opts.get('body') | ||
let body = opts.body | ||
const bodyIsStream = body && | ||
@@ -44,4 +45,16 @@ typeof body === 'object' && | ||
} | ||
if (opts.get('query')) { | ||
let q = opts.get('query') | ||
if (opts.gzip) { | ||
headers['content-encoding'] = 'gzip' | ||
if (bodyIsStream) { | ||
const gz = zlib.createGzip() | ||
body.on('error', err => gz.emit('error', err)) | ||
body = body.pipe(gz) | ||
} else { | ||
body = new opts.Promise((resolve, reject) => { | ||
zlib.gzip(body, (err, gz) => err ? reject(err) : resolve(gz)) | ||
}) | ||
} | ||
} | ||
if (opts.query) { | ||
let q = opts.query | ||
if (typeof q === 'string') { | ||
@@ -58,34 +71,34 @@ q = qs.parse(q) | ||
} | ||
return fetch(uri, { | ||
agent: opts.get('agent'), | ||
algorithms: opts.get('algorithms'), | ||
return opts.Promise.resolve(body).then(body => fetch(uri, { | ||
agent: opts.agent, | ||
algorithms: opts.algorithms, | ||
body, | ||
cache: getCacheMode(opts), | ||
cacheManager: opts.get('cache'), | ||
ca: opts.get('ca'), | ||
cert: opts.get('cert'), | ||
cacheManager: opts.cache, | ||
ca: opts.ca, | ||
cert: opts.cert, | ||
headers, | ||
integrity: opts.get('integrity'), | ||
key: opts.get('key'), | ||
localAddress: opts.get('local-address'), | ||
maxSockets: opts.get('maxsockets'), | ||
memoize: opts.get('memoize'), | ||
method: opts.get('method') || 'GET', | ||
noProxy: opts.get('no-proxy') || opts.get('noproxy'), | ||
Promise: opts.get('Promise'), | ||
proxy: opts.get('https-proxy') || opts.get('proxy'), | ||
referer: opts.get('refer'), | ||
retry: opts.get('retry') || { | ||
retries: opts.get('fetch-retries'), | ||
factor: opts.get('fetch-retry-factor'), | ||
minTimeout: opts.get('fetch-retry-mintimeout'), | ||
maxTimeout: opts.get('fetch-retry-maxtimeout') | ||
integrity: opts.integrity, | ||
key: opts.key, | ||
localAddress: opts['local-address'], | ||
maxSockets: opts.maxsockets, | ||
memoize: opts.memoize, | ||
method: opts.method || 'GET', | ||
noProxy: opts['no-proxy'] || opts.noproxy, | ||
Promise: opts.Promise, | ||
proxy: opts['https-proxy'] || opts.proxy, | ||
referer: opts.refer, | ||
retry: opts.retry || { | ||
retries: opts['fetch-retries'], | ||
factor: opts['fetch-retry-factor'], | ||
minTimeout: opts['fetch-retry-mintimeout'], | ||
maxTimeout: opts['fetch-retry-maxtimeout'] | ||
}, | ||
strictSSL: !!opts.get('strict-ssl'), | ||
timeout: opts.get('timeout'), | ||
uid: opts.get('uid'), | ||
gid: opts.get('gid') | ||
strictSSL: !!opts['strict-ssl'], | ||
timeout: opts.timeout, | ||
uid: opts.uid, | ||
gid: opts.gid | ||
}).then(res => checkResponse( | ||
opts.get('method') || 'GET', res, registry, startTime, opts | ||
)) | ||
opts.method || 'GET', res, registry, startTime, opts | ||
))) | ||
} | ||
@@ -103,12 +116,10 @@ | ||
let registry = spec.scope && | ||
opts.get(spec.scope.replace(/^@?/, '@') + ':registry') | ||
opts[spec.scope.replace(/^@?/, '@') + ':registry'] | ||
if (!registry && opts.get('scope')) { | ||
registry = opts.get( | ||
opts.get('scope').replace(/^@?/, '@') + ':registry' | ||
) | ||
if (!registry && opts.scope) { | ||
registry = opts[opts.scope.replace(/^@?/, '@') + ':registry'] | ||
} | ||
if (!registry) { | ||
registry = opts.get('registry') || 'https://registry.npmjs.org/' | ||
registry = opts.registry || 'https://registry.npmjs.org/' | ||
} | ||
@@ -120,7 +131,7 @@ | ||
function getCacheMode (opts) { | ||
return opts.get('offline') | ||
return opts.offline | ||
? 'only-if-cached' | ||
: opts.get('prefer-offline') | ||
: opts['prefer-offline'] | ||
? 'force-cache' | ||
: opts.get('prefer-online') | ||
: opts['prefer-online'] | ||
? 'no-cache' | ||
@@ -133,3 +144,3 @@ : 'default' | ||
'npm-in-ci': !!( | ||
opts.get('is-from-ci') || | ||
opts['is-from-ci'] || | ||
process.env['CI'] === 'true' || | ||
@@ -141,7 +152,7 @@ process.env['TDDIUM'] || | ||
), | ||
'npm-scope': opts.get('project-scope'), | ||
'npm-session': opts.get('npm-session'), | ||
'user-agent': opts.get('user-agent'), | ||
'referer': opts.get('refer') | ||
}, opts.get('headers')) | ||
'npm-scope': opts['project-scope'], | ||
'npm-session': opts['npm-session'], | ||
'user-agent': opts['user-agent'], | ||
'referer': opts.refer | ||
}, opts.headers) | ||
@@ -148,0 +159,0 @@ const auth = getAuth(registry, opts) |
{ | ||
"name": "npm-registry-fetch", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"description": "Fetch-based http client for use with npm registry APIs", | ||
@@ -33,11 +33,11 @@ "main": "index.js", | ||
"bluebird": "^3.5.1", | ||
"figgy-pudding": "^3.1.0", | ||
"lru-cache": "^4.1.2", | ||
"make-fetch-happen": "^4.0.0", | ||
"npm-package-arg": "^6.0.0" | ||
"figgy-pudding": "^3.2.0", | ||
"lru-cache": "^4.1.3", | ||
"make-fetch-happen": "^4.0.1", | ||
"npm-package-arg": "^6.1.0" | ||
}, | ||
"devDependencies": { | ||
"cacache": "^11.0.0", | ||
"cacache": "^11.0.2", | ||
"mkdirp": "^0.5.1", | ||
"nock": "^9.2.3", | ||
"nock": "^9.4.3", | ||
"npmlog": "^4.1.2", | ||
@@ -47,4 +47,4 @@ "rimraf": "^2.6.2", | ||
"standard": "^11.0.1", | ||
"standard-version": "^4.2.0", | ||
"tap": "^11.1.3", | ||
"standard-version": "^4.4.0", | ||
"tap": "^12.0.1", | ||
"weallbehave": "^1.2.0", | ||
@@ -51,0 +51,0 @@ "weallcontribute": "^1.0.8" |
@@ -217,2 +217,11 @@ # npm-registry-fetch [![npm version](https://img.shields.io/npm/v/npm-registry-fetch.svg)](https://npm.im/npm-registry-fetch) [![license](https://img.shields.io/npm/l/npm-registry-fetch.svg)](https://npm.im/npm-registry-fetch) [![Travis](https://img.shields.io/travis/npm/npm-registry-fetch/latest.svg)](https://travis-ci.org/npm/npm-registry-fetch) [![AppVeyor](https://img.shields.io/appveyor/ci/zkat/npm-registry-fetch/latest.svg)](https://ci.appveyor.com/project/npm/npm-registry-fetch) [![Coverage Status](https://coveralls.io/repos/github/npm/npm-registry-fetch/badge.svg?branch=latest)](https://coveralls.io/github/npm/npm-registry-fetch?branch=latest) | ||
##### <a name="opts-gzip"></a> `opts.gzip` | ||
* Type: Boolean | ||
* Default: false | ||
If true, `npm-registry-fetch` will set the `Content-Encoding` header to `gzip` | ||
and use `zlib.gzip()` or `zlib.createGzip()` to gzip-encode | ||
[`opts.body`](#opts-body). | ||
##### <a name="opts-headers"></a> `opts.headers` | ||
@@ -219,0 +228,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35883
452
559
Updatedfiggy-pudding@^3.2.0
Updatedlru-cache@^4.1.3
Updatedmake-fetch-happen@^4.0.1
Updatednpm-package-arg@^6.1.0