Skip to content

Commit

Permalink
fix: Remove figgy-pudding, use canonical option names
Browse files Browse the repository at this point in the history
BREAKING CHANGE: this removes figgy-pudding, and drops several option
aliases.

Defaults and behavior are all the same, and this module is now using the
canonical camelCase option names that npm v7 will provide to all its
deps.

Related to: npm/rfcs#102

PR-URL: #22
Credit: @isaacs
Close: #22
Reviewed-by: @claudiahdz
  • Loading branch information
isaacs committed Feb 17, 2020
1 parent ae7e994 commit ede3c08
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 279 deletions.
48 changes: 20 additions & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,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 @@ -194,8 +194,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 @@ -216,7 +216,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 @@ -227,7 +227,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 @@ -238,7 +238,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 @@ -249,7 +249,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 @@ -260,9 +260,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 @@ -288,9 +287,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 @@ -317,9 +315,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 @@ -343,7 +340,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 @@ -361,19 +358,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 @@ -394,9 +389,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 @@ -411,7 +405,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 Down Expand Up @@ -448,7 +442,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 @@ -463,7 +457,7 @@ This option is generally only useful if you're also using
This option is set to `false` when the request includes `write=true` in the
query string.

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

* Type: Boolean
* Default: false
Expand All @@ -477,9 +471,8 @@ This option is generally only useful if you're also using
This option is set to `true` when the request includes `write=true` in the
query string.

##### <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 @@ -510,7 +503,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 @@ -574,7 +566,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 @@ -607,7 +599,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
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
})`
}
Loading

0 comments on commit ede3c08

Please sign in to comment.