Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/npm-registry-fetch/index.js')
-rw-r--r--node_modules/npm-registry-fetch/index.js32
1 files changed, 22 insertions, 10 deletions
diff --git a/node_modules/npm-registry-fetch/index.js b/node_modules/npm-registry-fetch/index.js
index c18487388..9bd0ad32d 100644
--- a/node_modules/npm-registry-fetch/index.js
+++ b/node_modules/npm-registry-fetch/index.js
@@ -53,26 +53,38 @@ function regFetch (uri, opts) {
})
}
}
- if (opts.query) {
- let q = opts.query
+
+ let q = opts.query
+ if (q) {
if (typeof q === 'string') {
q = qs.parse(q)
+ } else if (typeof q !== 'object') {
+ throw new TypeError('invalid query option, must be string or object')
}
Object.keys(q).forEach(key => {
if (q[key] === undefined) {
delete q[key]
}
})
- if (Object.keys(q).length) {
- const parsed = url.parse(uri)
- parsed.search = '?' + qs.stringify(
- parsed.query
- ? Object.assign(qs.parse(parsed.query), q)
- : q
- )
- uri = url.format(parsed)
+ }
+ const parsed = url.parse(uri)
+
+ const query = parsed.query ? Object.assign(qs.parse(parsed.query), q || {})
+ : Object.keys(q || {}).length ? q
+ : null
+
+ if (query) {
+ if (String(query.write) === 'true' && opts.method === 'GET') {
+ opts = opts.concat({
+ offline: false,
+ 'prefer-offline': false,
+ 'prefer-online': true
+ })
}
+ parsed.search = '?' + qs.stringify(query)
+ uri = url.format(parsed)
}
+
return opts.Promise.resolve(body).then(body => fetch(uri, {
agent: opts.agent,
algorithms: opts.algorithms,