Skip to content

Commit ede3c08

Browse files
committed
fix: Remove figgy-pudding, use canonical option names
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
1 parent ae7e994 commit ede3c08

12 files changed

+186
-279
lines changed

Diff for: README.md

+20-28
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ to trust only that specific signing authority.
181181
Multiple CAs can be trusted by specifying an array of certificates instead of a
182182
single string.
183183

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

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

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

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

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

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

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

221221
* Type: Number
222222
* Default: 2
@@ -227,7 +227,7 @@ packages from the registry.
227227
See also [`opts.retry`](#opts-retry) to provide all retry options as a single
228228
object.
229229

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

232232
* Type: Number
233233
* Default: 10
@@ -238,7 +238,7 @@ packages.
238238
See also [`opts.retry`](#opts-retry) to provide all retry options as a single
239239
object.
240240

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

243243
* Type: Number
244244
* Default: 10000 (10 seconds)
@@ -249,7 +249,7 @@ packages.
249249
See also [`opts.retry`](#opts-retry) to provide all retry options as a single
250250
object.
251251

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

254254
* Type: Number
255255
* Default: 60000 (1 minute)
@@ -260,9 +260,8 @@ packages.
260260
See also [`opts.retry`](#opts-retry) to provide all retry options as a single
261261
object.
262262

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

265-
* Alias: `opts.forceAuth`
266265
* Type: Object
267266
* Default: null
268267

@@ -288,9 +287,8 @@ Additional headers for the outgoing request. This option can also be used to
288287
override headers automatically generated by `npm-registry-fetch`, such as
289288
`Content-Type`.
290289

291-
##### <a name="opts-ignore-body"></a> `opts.ignore-body`
290+
##### <a name="opts-ignoreBody"></a> `opts.ignoreBody`
292291

293-
* Alias: `opts.ignoreBody`
294292
* Type: Boolean
295293
* Default: false
296294

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

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

322-
* Alias: `opts.isFromCI`
323320
* Type: Boolean
324321
* Default: Based on environment variables
325322

@@ -343,7 +340,7 @@ It is _not_ the path to a key file (and there is no "keyfile" option).
343340

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

346-
##### <a name="opts-local-address"></a> `opts.local-address`
343+
##### <a name="opts-localAddress"></a> `opts.localAddress`
347344

348345
* Type: IP Address String
349346
* Default: null
@@ -361,19 +358,17 @@ See also [`opts.proxy`](#opts-proxy)
361358
Logger object to use for logging operation details. Must have the same methods
362359
as `npmlog`.
363360

364-
##### <a name="opts-map-json"></a> `opts.map-json`
361+
##### <a name="opts-mapJSON"></a> `opts.mapJSON`
365362

366-
* Alias: `mapJson`, `mapJSON`
367363
* Type: Function
368364
* Default: undefined
369365

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

374-
##### <a name="opts-maxsockets"></a> `opts.maxsockets`
370+
##### <a name="opts-maxSockets"></a> `opts.maxSockets`
375371

376-
* Alias: `opts.max-sockets`
377372
* Type: Integer
378373
* Default: 12
379374

@@ -394,9 +389,8 @@ HTTP method to use for the outgoing request. Case-insensitive.
394389

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

397-
##### <a name="opts-npm-session"></a> `opts.npm-session`
392+
##### <a name="opts-npmSession"></a> `opts.npmSession`
398393

399-
* Alias: `opts.npmSession`
400394
* Type: String
401395
* Default: null
402396

@@ -411,7 +405,7 @@ invocations of the CLI).
411405

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

416410
This option is only really useful if you're also using
417411
[`opts.cache`](#opts-cache).
@@ -448,7 +442,7 @@ That is:
448442

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

451-
##### <a name="opts-prefer-offline"></a> `opts.prefer-offline`
445+
##### <a name="opts-preferOffline"></a> `opts.preferOffline`
452446

453447
* Type: Boolean
454448
* Default: false
@@ -463,7 +457,7 @@ This option is generally only useful if you're also using
463457
This option is set to `false` when the request includes `write=true` in the
464458
query string.
465459

466-
##### <a name="opts-prefer-online"></a> `opts.prefer-online`
460+
##### <a name="opts-preferOnline"></a> `opts.preferOnline`
467461

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

480-
##### <a name="opts-project-scope"></a> `opts.project-scope`
474+
##### <a name="opts-projectScope"></a> `opts.projectScope`
481475

482-
* Alias: `opts.projectScope`
483476
* Type: String
484477
* Default: null
485478

@@ -510,7 +503,6 @@ If the request URI already has a query string, it will be merged with
510503

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

513-
* Alias: `opts.referer`
514506
* Type: String
515507
* Default: null
516508

@@ -574,7 +566,7 @@ If provided, can be used to automatically configure [`opts.scope`](#opts-scope)
574566
based on a specific package name. Non-registry package specs will throw an
575567
error.
576568

577-
##### <a name="opts-strict-ssl"></a> `opts.strict-ssl`
569+
##### <a name="opts-strictSSL"></a> `opts.strictSSL`
578570

579571
* Type: Boolean
580572
* Default: true
@@ -607,7 +599,7 @@ Can be scoped to a registry by using a "nerf dart" for that registry. That is:
607599
}
608600
```
609601

610-
##### <a name="opts-user-agent"></a> `opts.user-agent`
602+
##### <a name="opts-userAgent"></a> `opts.userAgent`
611603

612604
* Type: String
613605
* Default: `'npm-registry-fetch@<version>/node@<node-version>+<arch> (<platform>)'`

Diff for: auth.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
'use strict'
22

3-
const config = require('./config.js')
3+
const defaultOpts = require('./default-opts.js')
44
const url = require('url')
55

66
module.exports = getAuth
7-
function getAuth (registry, opts) {
7+
function getAuth (registry, opts_ = {}) {
88
if (!registry) { throw new Error('registry is required') }
9-
opts = config(opts)
9+
const opts = opts_.forceAuth ? opts_.forceAuth : { ...defaultOpts, ...opts_ }
1010
const AUTH = {}
1111
const regKey = registry && registryKey(registry)
12-
if (opts.forceAuth) {
13-
opts = opts.forceAuth
14-
}
1512
const doKey = (key, alias) => addKey(opts, AUTH, regKey, key, alias)
1613
doKey('token')
1714
doKey('_authToken', 'token')

Diff for: check-response.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
'use strict'
22

3-
const config = require('./config.js')
43
const errors = require('./errors.js')
54
const LRU = require('lru-cache')
65
const { Response } = require('minipass-fetch')
6+
const defaultOpts = require('./default-opts.js')
7+
78
module.exports = checkResponse
8-
function checkResponse (method, res, registry, startTime, opts) {
9-
opts = config(opts)
9+
function checkResponse (method, res, registry, startTime, opts_ = {}) {
10+
const opts = { ...defaultOpts, ...opts_ }
1011
if (res.headers.has('npm-notice') && !res.headers.has('x-local-cache')) {
1112
opts.log.notice('', res.headers.get('npm-notice'))
1213
}

Diff for: config.js

-92
This file was deleted.

Diff for: default-opts.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const pkg = require('./package.json')
2+
const ciDetect = require('@npmcli/ci-detect')
3+
module.exports = {
4+
isFromCI: ciDetect(),
5+
log: require('./silentlog.js'),
6+
maxSockets: 12,
7+
method: 'GET',
8+
registry: 'https://registry.npmjs.org/',
9+
timeout: 30 * 1000,
10+
strictSSL: true,
11+
noProxy: process.env.NOPROXY,
12+
userAgent: `${pkg.name
13+
}@${
14+
pkg.version
15+
}/node@${
16+
process.version
17+
}+${
18+
process.arch
19+
} (${
20+
process.platform
21+
})`
22+
}

0 commit comments

Comments
 (0)