Skip to content

Commit

Permalink
Remove figgy-pudding, use canonical option names
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Feb 14, 2020
1 parent 50e8afc commit dbaed75
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 268 deletions.
52 changes: 22 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ to trust only that specific signing authority.
Multiple CAs can be trusted by specifying an array of certificates instead of a
single string.

See also [`opts.strict-ssl`](#opts-strict-ssl), [`opts.ca`](#opts-ca) and
See also [`opts.strictSSL`](#opts-strictSSL), [`opts.ca`](#opts-ca) and
[`opts.key`](#opts-key)

##### <a name="opts-cache"></a> `opts.cache`
Expand All @@ -175,8 +175,8 @@ will be cached according to [IETF RFC 7234](https://tools.ietf.org/html/rfc7234)
rules. This will speed up future requests, as well as make the cached data
available offline if necessary/requested.

See also [`offline`](#opts-offline), [`prefer-offline`](#opts-prefer-offline),
and [`prefer-online`](#opts-prefer-online).
See also [`offline`](#opts-offline), [`preferOffline`](#opts-preferOffline),
and [`preferOnline`](#opts-preferOnline).

##### <a name="opts-cert"></a> `opts.cert`

Expand All @@ -197,7 +197,7 @@ It is _not_ the path to a certificate file (and there is no "certfile" option).

See also: [`opts.ca`](#opts-ca) and [`opts.key`](#opts-key)

##### <a name="opts-fetch-retries"></a> `opts.fetch-retries`
##### <a name="opts-fetchRetries"></a> `opts.fetchRetries`

* Type: Number
* Default: 2
Expand All @@ -208,7 +208,7 @@ packages from the registry.
See also [`opts.retry`](#opts-retry) to provide all retry options as a single
object.

##### <a name="opts-fetch-retry-factor"></a> `opts.fetch-retry-factor`
##### <a name="opts-fetchRetryFactor"></a> `opts.fetchRetryFactor`

* Type: Number
* Default: 10
Expand All @@ -219,7 +219,7 @@ packages.
See also [`opts.retry`](#opts-retry) to provide all retry options as a single
object.

##### <a name="opts-fetch-retry-mintimeout"></a> `opts.fetch-retry-mintimeout`
##### <a name="opts-fetchRetryMintimeout"></a> `opts.fetchRetryMintimeout`

* Type: Number
* Default: 10000 (10 seconds)
Expand All @@ -230,7 +230,7 @@ packages.
See also [`opts.retry`](#opts-retry) to provide all retry options as a single
object.

##### <a name="opts-fetch-retry-maxtimeout"></a> `opts.fetch-retry-maxtimeout`
##### <a name="opts-fetchRetryMaxtimeout"></a> `opts.fetchRetryMaxtimeout`

* Type: Number
* Default: 60000 (1 minute)
Expand All @@ -241,9 +241,8 @@ packages.
See also [`opts.retry`](#opts-retry) to provide all retry options as a single
object.

##### <a name="opts-force-auth"></a> `opts.force-auth`
##### <a name="opts-forceAuth"></a> `opts.forceAuth`

* Alias: `opts.forceAuth`
* Type: Object
* Default: null

Expand All @@ -269,9 +268,8 @@ Additional headers for the outgoing request. This option can also be used to
override headers automatically generated by `npm-registry-fetch`, such as
`Content-Type`.

##### <a name="opts-ignore-body"></a> `opts.ignore-body`
##### <a name="opts-ignoreBody"></a> `opts.ignoreBody`

* Alias: `opts.ignoreBody`
* Type: Boolean
* Default: false

Expand All @@ -298,9 +296,8 @@ previously-generated integrity hash for the saved request information, so
`EINTEGRITY` errors can happen if [`opts.cache`](#opts-cache) is used, even if
`opts.integrity` is not passed in.

##### <a name='opts-is-from-ci'></a> `opts.is-from-ci`
##### <a name='opts-isFromCI'></a> `opts.isFromCI`

* Alias: `opts.isFromCI`
* Type: Boolean
* Default: Based on environment variables

Expand All @@ -324,7 +321,7 @@ It is _not_ the path to a key file (and there is no "keyfile" option).

See also: [`opts.ca`](#opts-ca) and [`opts.cert`](#opts-cert)

##### <a name="opts-local-address"></a> `opts.local-address`
##### <a name="opts-localAddress"></a> `opts.localAddress`

* Type: IP Address String
* Default: null
Expand All @@ -342,19 +339,17 @@ See also [`opts.proxy`](#opts-proxy)
Logger object to use for logging operation details. Must have the same methods
as `npmlog`.

##### <a name="opts-map-json"></a> `opts.map-json`
##### <a name="opts-mapJSON"></a> `opts.mapJSON`

* Alias: `mapJson`, `mapJSON`
* Type: Function
* Default: undefined

When using `fetch.json.stream()` (NOT `fetch.json()`), this will be passed down
to [`JSONStream`](https://npm.im/JSONStream) as the second argument to
`JSONStream.parse`, and can be used to transform stream data before output.

##### <a name="opts-maxsockets"></a> `opts.maxsockets`
##### <a name="opts-maxSockets"></a> `opts.maxSockets`

* Alias: `opts.max-sockets`
* Type: Integer
* Default: 12

Expand All @@ -375,9 +370,8 @@ HTTP method to use for the outgoing request. Case-insensitive.

If true, proxying will be disabled even if [`opts.proxy`](#opts-proxy) is used.

##### <a name="opts-npm-session"></a> `opts.npm-session`
##### <a name="opts-npmSession"></a> `opts.npmSession`

* Alias: `opts.npmSession`
* Type: String
* Default: null

Expand All @@ -392,7 +386,7 @@ invocations of the CLI).

Force offline mode: no network requests will be done during install. To allow
`npm-registry-fetch` to fill in missing cache data, see
[`opts.prefer-offline`](#opts-prefer-offline).
[`opts.preferOffline`](#opts-preferOffline).

This option is only really useful if you're also using
[`opts.cache`](#opts-cache).
Expand All @@ -408,7 +402,7 @@ account.

##### <a name="opts-password"></a> `opts.password`

* Alias: _password
* Alias: `_password`
* Type: String
* Default: null

Expand All @@ -426,7 +420,7 @@ That is:

See also [`opts.username`](#opts-username)

##### <a name="opts-prefer-offline"></a> `opts.prefer-offline`
##### <a name="opts-preferOffline"></a> `opts.preferOffline`

* Type: Boolean
* Default: false
Expand All @@ -438,7 +432,7 @@ will be requested from the server. To force full offline mode, use
This option is generally only useful if you're also using
[`opts.cache`](#opts-cache).

##### <a name="opts-prefer-online"></a> `opts.prefer-online`
##### <a name="opts-preferOnline"></a> `opts.preferOnline`

* Type: Boolean
* Default: false
Expand All @@ -450,9 +444,8 @@ This option is generally only useful if you're also using
[`opts.cache`](#opts-cache).


##### <a name="opts-project-scope"></a> `opts.project-scope`
##### <a name="opts-projectScope"></a> `opts.projectScope`

* Alias: `opts.projectScope`
* Type: String
* Default: null

Expand Down Expand Up @@ -483,7 +476,6 @@ If the request URI already has a query string, it will be merged with

##### <a name="opts-refer"></a> `opts.refer`

* Alias: `opts.referer`
* Type: String
* Default: null

Expand Down Expand Up @@ -547,7 +539,7 @@ If provided, can be used to automatically configure [`opts.scope`](#opts-scope)
based on a specific package name. Non-registry package specs will throw an
error.

##### <a name="opts-strict-ssl"></a> `opts.strict-ssl`
##### <a name="opts-strictSSL"></a> `opts.strictSSL`

* Type: Boolean
* Default: true
Expand Down Expand Up @@ -580,7 +572,7 @@ Can be scoped to a registry by using a "nerf dart" for that registry. That is:
}
```

##### <a name="opts-user-agent"></a> `opts.user-agent`
##### <a name="opts-userAgent"></a> `opts.userAgent`

* Type: String
* Default: `'npm-registry-fetch@<version>/node@<node-version>+<arch> (<platform>)'`
Expand Down Expand Up @@ -612,4 +604,4 @@ See also [`opts.password`](#opts-password)
* Default: null

** DEPRECATED ** This is a legacy authentication token supported only for
*compatibility. Please use [`opts.token`](#opts-token) instead.
compatibility. Please use [`opts.token`](#opts-token) instead.
9 changes: 3 additions & 6 deletions auth.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
'use strict'

const config = require('./config.js')
const defaultOpts = require('./default-opts.js')
const url = require('url')

module.exports = getAuth
function getAuth (registry, opts) {
function getAuth (registry, opts_ = {}) {
if (!registry) { throw new Error('registry is required') }
opts = config(opts)
const opts = opts_.forceAuth ? opts_.forceAuth : { ...defaultOpts, ...opts_ }
const AUTH = {}
const regKey = registry && registryKey(registry)
if (opts.forceAuth) {
opts = opts.forceAuth
}
const doKey = (key, alias) => addKey(opts, AUTH, regKey, key, alias)
doKey('token')
doKey('_authToken', 'token')
Expand Down
7 changes: 4 additions & 3 deletions check-response.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
'use strict'

const config = require('./config.js')
const errors = require('./errors.js')
const LRU = require('lru-cache')
const { Response } = require('minipass-fetch')
const defaultOpts = require('./default-opts.js')

module.exports = checkResponse
function checkResponse (method, res, registry, startTime, opts) {
opts = config(opts)
function checkResponse (method, res, registry, startTime, opts_ = {}) {
const opts = { ...defaultOpts, ...opts_ }
if (res.headers.has('npm-notice') && !res.headers.has('x-local-cache')) {
opts.log.notice('', res.headers.get('npm-notice'))
}
Expand Down
92 changes: 0 additions & 92 deletions config.js

This file was deleted.

22 changes: 22 additions & 0 deletions default-opts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const pkg = require('./package.json')
const ciDetect = require('@npmcli/ci-detect')
module.exports = {
isFromCI: ciDetect(),
log: require('./silentlog.js'),
maxSockets: 12,
method: 'GET',
registry: 'https://registry.npmjs.org/',
timeout: 30 * 1000,
strictSSL: true,
noProxy: process.env.NOPROXY,
userAgent: `${pkg.name
}@${
pkg.version
}/node@${
process.version
}+${
process.arch
} (${
process.platform
})`
}

0 comments on commit dbaed75

Please sign in to comment.