Skip to content

Commit 754fe69

Browse files
committed
chore(config): remove flatOptions references
Iterative change moving us towards a more unified config. No longer pulling config from flatOptions where we don't have to.
1 parent 08673c3 commit 754fe69

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1183
-1185
lines changed

lib/access.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class Access extends BaseCommand {
7575
if (!subcommands.includes(cmd) || !this[cmd])
7676
throw this.usageError(`${cmd} is not a recognized subcommand.`)
7777

78-
return this[cmd](args, { ...this.npm.flatOptions })
78+
return this[cmd](args, this.npm.flatOptions)
7979
}
8080

8181
public ([pkg], opts) {

lib/audit.js

+6-7
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,22 @@ class Audit extends BaseCommand {
3737
}
3838

3939
async audit (args) {
40-
const arb = new Arborist({
40+
const reporter = this.npm.config.get('json') ? 'json' : 'detail'
41+
const opts = {
4142
...this.npm.flatOptions,
4243
audit: true,
4344
path: this.npm.prefix,
44-
})
45+
reporter,
46+
}
47+
const arb = new Arborist(opts)
4548
const fix = args[0] === 'fix'
4649
await arb.audit({ fix })
4750
if (fix)
4851
await reifyFinish(this.npm, arb)
4952
else {
5053
// will throw if there's an error, because this is an audit command
5154
auditError(this.npm, arb.auditReport)
52-
const reporter = this.npm.flatOptions.json ? 'json' : 'detail'
53-
const result = auditReport(arb.auditReport, {
54-
...this.npm.flatOptions,
55-
reporter,
56-
})
55+
const result = auditReport(arb.auditReport, opts)
5756
process.exitCode = process.exitCode || result.exitCode
5857
this.npm.output(result.report)
5958
}

lib/bin.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Bin extends BaseCommand {
1717
async bin (args) {
1818
const b = this.npm.bin
1919
this.npm.output(b)
20-
if (this.npm.flatOptions.global && !envPath.includes(b))
20+
if (this.npm.config.get('global') && !envPath.includes(b))
2121
console.error('(not in PATH env variable)')
2222
}
2323
}

lib/cache.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class Cache extends BaseCommand {
6363
throw new Error('npm cache clear does not accept arguments')
6464

6565
const cachePath = path.join(this.npm.cache, '_cacache')
66-
if (!this.npm.flatOptions.force) {
66+
if (!this.npm.config.get('force')) {
6767
throw new Error(`As of npm@5, the npm cache self-heals from corruption issues
6868
by treating integrity mismatches as cache misses. As a result,
6969
data extracted from the cache is guaranteed to be valid. If you
@@ -100,15 +100,14 @@ with --force.`)
100100
throw Object.assign(new Error(usage), { code: 'EUSAGE' })
101101

102102
log.silly('cache add', 'spec', spec)
103-
const opts = { ...this.npm.flatOptions }
104103

105104
// we ask pacote for the thing, and then just throw the data
106105
// away so that it tee-pipes it into the cache like it does
107106
// for a normal request.
108107
await pacote.tarball.stream(spec, stream => {
109108
stream.resume()
110109
return stream.promise()
111-
}, opts)
110+
}, this.npm.flatOptions)
112111
}
113112

114113
async verify () {

lib/ci.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,13 @@ class CI extends BaseCommand {
3030
}
3131

3232
async ci () {
33-
if (this.npm.flatOptions.global) {
33+
if (this.npm.config.get('global')) {
3434
const err = new Error('`npm ci` does not work for global packages')
3535
err.code = 'ECIGLOBAL'
3636
throw err
3737
}
3838

3939
const where = this.npm.prefix
40-
const { scriptShell, ignoreScripts } = this.npm.flatOptions
4140
const arb = new Arborist({ ...this.npm.flatOptions, path: where })
4241

4342
await Promise.all([
@@ -54,6 +53,7 @@ class CI extends BaseCommand {
5453
// npm ci should never modify the lockfile or package.json
5554
await arb.reify({ ...this.npm.flatOptions, save: false })
5655

56+
const ignoreScripts = this.npm.config.get('ignore-scripts')
5757
// run the same set of scripts that `npm install` runs.
5858
if (!ignoreScripts) {
5959
const scripts = [
@@ -65,6 +65,7 @@ class CI extends BaseCommand {
6565
'prepare',
6666
'postprepare',
6767
]
68+
const scriptShell = this.npm.config.get('script-shell')
6869
for (const event of scripts) {
6970
await runScript({
7071
path: where,

lib/dedupe.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ class Dedupe extends BaseCommand {
2323

2424
const dryRun = this.npm.config.get('dry-run')
2525
const where = this.npm.prefix
26-
const arb = new Arborist({
26+
const opts = {
2727
...this.npm.flatOptions,
2828
path: where,
2929
dryRun,
30-
})
31-
await arb.dedupe(this.npm.flatOptions)
30+
}
31+
const arb = new Arborist(opts)
32+
await arb.dedupe(opts)
3233
await reifyFinish(this.npm, arb)
3334
}
3435
}

lib/diff.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Diff extends BaseCommand {
3030

3131
get where () {
3232
const globalTop = resolve(this.npm.globalDir, '..')
33-
const { global } = this.npm.flatOptions
33+
const global = this.npm.config.get('global')
3434
return global ? globalTop : this.npm.prefix
3535
}
3636

@@ -39,7 +39,7 @@ class Diff extends BaseCommand {
3939
}
4040

4141
async diff (args) {
42-
const specs = this.npm.flatOptions.diff.filter(d => d)
42+
const specs = this.npm.config.get('diff').filter(d => d)
4343
if (specs.length > 2) {
4444
throw new TypeError(
4545
'Can\'t use more than two --diff arguments.\n\n' +
@@ -91,7 +91,7 @@ class Diff extends BaseCommand {
9191
}
9292

9393
return [
94-
`${pkgName}@${this.npm.flatOptions.defaultTag}`,
94+
`${pkgName}@${this.npm.config.get('tag')}`,
9595
`file:${this.npm.prefix}`,
9696
]
9797
}

lib/dist-tag.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class DistTag extends BaseCommand {
6161
async add (spec, tag, opts) {
6262
spec = npa(spec || '')
6363
const version = spec.rawSpec
64-
const defaultTag = tag || opts.defaultTag
64+
const defaultTag = tag || this.npm.config.get('tag')
6565

6666
log.verbose('dist-tag add', defaultTag, 'to', spec.name + '@' + version)
6767

lib/exec.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const BaseCommand = require('./base-command.js')
2424
//
2525
// npm x -p pkg@version -- foo --registry=/dev/null
2626
//
27-
// const pkg = npm.flatOptions.package || getPackageFrom(args[0])
27+
// const pkg = npm.config.get('package') || getPackageFrom(args[0])
2828
// const cmd = getCommand(pkg, args[0])
2929
// --> npm x -c 'cmd ...args.slice(1)'
3030
//
@@ -66,7 +66,10 @@ class Exec extends BaseCommand {
6666
// When commands go async and we can dump the boilerplate exec methods this
6767
// can be named correctly
6868
async _exec (args) {
69-
const { package: packages, call, shell } = this.npm.flatOptions
69+
const call = this.npm.config.get('call')
70+
const shell = this.npm.config.get('shell')
71+
// dereferenced because we manipulate it later
72+
const packages = [...this.npm.config.get('package')]
7073

7174
if (call && args.length)
7275
throw this.usage
@@ -165,9 +168,9 @@ class Exec extends BaseCommand {
165168

166169
// no need to install if already present
167170
if (add.length) {
168-
if (!this.npm.flatOptions.yes) {
171+
if (!this.npm.config.get('yes')) {
169172
// set -n to always say no
170-
if (this.npm.flatOptions.yes === false)
173+
if (this.npm.config.get('yes') === false)
171174
throw 'canceled'
172175

173176
if (!process.stdin.isTTY || ciDetect()) {

lib/fund.js

+10-15
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,8 @@ class Fund extends BaseCommand {
4242
}
4343

4444
async fund (args) {
45-
const opts = this.npm.flatOptions
4645
const spec = args[0]
47-
const numberArg = opts.which
46+
const numberArg = this.npm.config.get('which')
4847

4948
const fundingSourceNumber = numberArg && parseInt(numberArg, 10)
5049

@@ -58,14 +57,14 @@ class Fund extends BaseCommand {
5857
throw err
5958
}
6059

61-
if (opts.global) {
60+
if (this.npm.config.get('global')) {
6261
const err = new Error('`npm fund` does not support global packages')
6362
err.code = 'EFUNDGLOBAL'
6463
throw err
6564
}
6665

6766
const where = this.npm.prefix
68-
const arb = new Arborist({ ...opts, path: where })
67+
const arb = new Arborist({ ...this.npm.flatOptions, path: where })
6968
const tree = await arb.loadActual()
7069

7170
if (spec) {
@@ -78,23 +77,19 @@ class Fund extends BaseCommand {
7877
return
7978
}
8079

81-
const print = opts.json
82-
? this.printJSON
83-
: this.printHuman
84-
85-
this.npm.output(
86-
print(
87-
getFundingInfo(tree),
88-
opts
89-
)
90-
)
80+
if (this.npm.config.get('json'))
81+
this.npm.output(this.printJSON(getFundingInfo(tree)))
82+
else
83+
this.npm.output(this.printHuman(getFundingInfo(tree)))
9184
}
9285

9386
printJSON (fundingInfo) {
9487
return JSON.stringify(fundingInfo, null, 2)
9588
}
9689

97-
printHuman (fundingInfo, { color, unicode }) {
90+
printHuman (fundingInfo) {
91+
const color = this.npm.config.get('color')
92+
const unicode = this.npm.config.get('unicode')
9893
const seenUrls = new Map()
9994

10095
const tree = obj =>

lib/help-search.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ class HelpSearch extends BaseCommand {
166166
out.push(' '.repeat((Math.max(1, cols - out.join(' ').length - r.length - 1))))
167167
out.push(r)
168168

169-
if (!this.npm.flatOptions.long)
169+
if (!this.npm.config.get('long'))
170170
return out.join('')
171171

172172
out.unshift('\n\n')
@@ -198,7 +198,7 @@ class HelpSearch extends BaseCommand {
198198
return out.join('')
199199
}).join('\n')
200200

201-
const finalOut = results.length && !this.npm.flatOptions.long
201+
const finalOut = results.length && !this.npm.config.get('long')
202202
? 'Top hits for ' + (args.map(JSON.stringify).join(' ')) + '\n' +
203203
'—'.repeat(cols - 1) + '\n' +
204204
out + '\n' +

lib/init.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Init extends BaseCommand {
5959
this.npm.log.pause()
6060
this.npm.log.disableProgress()
6161
const initFile = this.npm.config.get('init-module')
62-
if (!this.npm.flatOptions.yes && !this.npm.flatOptions.force) {
62+
if (!this.npm.config.get('yes') && !this.npm.config.get('force')) {
6363
this.npm.output([
6464
'This utility will walk you through creating a package.json file.',
6565
'It only covers the most common items, and tries to guess sensible defaults.',

lib/install.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ class Install extends BaseCommand {
9898
async install (args) {
9999
// the /path/to/node_modules/..
100100
const globalTop = resolve(this.npm.globalDir, '..')
101-
const { ignoreScripts, global: isGlobalInstall } = this.npm.flatOptions
101+
const ignoreScripts = this.npm.config.get('ignore-scripts')
102+
const isGlobalInstall = this.npm.config.get('global')
102103
const where = isGlobalInstall ? globalTop : this.npm.prefix
103104

104105
// don't try to install the prefix into itself
@@ -122,7 +123,7 @@ class Install extends BaseCommand {
122123
add: args,
123124
})
124125
if (!args.length && !isGlobalInstall && !ignoreScripts) {
125-
const { scriptShell } = this.npm.flatOptions
126+
const scriptShell = this.npm.config.get('script-shell')
126127
const scripts = [
127128
'preinstall',
128129
'install',

lib/link.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ class Link extends BaseCommand {
9696
// npm link should not save=true by default unless you're
9797
// using any of --save-dev or other types
9898
const save =
99-
Boolean(this.npm.config.find('save') !== 'default' || this.npm.flatOptions.saveType)
99+
Boolean(
100+
this.npm.config.find('save') !== 'default' ||
101+
this.npm.config.get('save-optional') ||
102+
this.npm.config.get('save-peer')
103+
)
100104

101105
// create a new arborist instance for the local prefix and
102106
// reify all the pending names as symlinks there

lib/logout.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ class Logout extends BaseCommand {
1919
}
2020

2121
async logout (args) {
22-
const { registry, scope } = this.npm.flatOptions
22+
const registry = this.npm.config.get('registry')
23+
const scope = this.npm.config.get('scope')
2324
const regRef = scope ? `${scope}:registry` : 'registry'
24-
const reg = this.npm.flatOptions[regRef] || registry
25+
const reg = this.npm.config.get(regRef) || registry
2526

2627
const auth = getAuth(reg, this.npm.flatOptions)
2728

lib/ls.js

+10-12
Original file line numberDiff line numberDiff line change
@@ -43,24 +43,22 @@ class LS extends BaseCommand {
4343
}
4444

4545
async ls (args) {
46-
const {
47-
all,
48-
color,
49-
depth,
50-
json,
51-
long,
52-
global,
53-
parseable,
54-
prefix,
55-
unicode,
56-
} = this.npm.flatOptions
57-
const path = global ? resolve(this.npm.globalDir, '..') : prefix
46+
const all = this.npm.config.get('all')
47+
const color = !!this.npm.config.get('color')
48+
const depth = this.npm.config.get('depth')
5849
const dev = this.npm.config.get('dev')
5950
const development = this.npm.config.get('development')
51+
const global = this.npm.config.get('global')
52+
const json = this.npm.config.get('json')
6053
const link = this.npm.config.get('link')
54+
const long = this.npm.config.get('long')
6155
const only = this.npm.config.get('only')
56+
const parseable = this.npm.config.get('parseable')
6257
const prod = this.npm.config.get('prod')
6358
const production = this.npm.config.get('production')
59+
const unicode = this.npm.config.get('unicode')
60+
61+
const path = global ? resolve(this.npm.globalDir, '..') : this.npm.prefix
6462

6563
const arb = new Arborist({
6664
global,

0 commit comments

Comments
 (0)