Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(config): remove flatOptions references #2892

Merged
merged 1 commit into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/access.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class Access extends BaseCommand {
if (!subcommands.includes(cmd) || !this[cmd])
throw this.usageError(`${cmd} is not a recognized subcommand.`)

return this[cmd](args, { ...this.npm.flatOptions })
return this[cmd](args, this.npm.flatOptions)
wraithgar marked this conversation as resolved.
Show resolved Hide resolved
}

public ([pkg], opts) {
Expand Down
13 changes: 6 additions & 7 deletions lib/audit.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,22 @@ class Audit extends BaseCommand {
}

async audit (args) {
const arb = new Arborist({
const reporter = this.npm.config.get('json') ? 'json' : 'detail'
const opts = {
...this.npm.flatOptions,
audit: true,
path: this.npm.prefix,
})
reporter,
}
const arb = new Arborist(opts)
const fix = args[0] === 'fix'
await arb.audit({ fix })
if (fix)
await reifyFinish(this.npm, arb)
else {
// will throw if there's an error, because this is an audit command
auditError(this.npm, arb.auditReport)
const reporter = this.npm.flatOptions.json ? 'json' : 'detail'
const result = auditReport(arb.auditReport, {
...this.npm.flatOptions,
reporter,
})
const result = auditReport(arb.auditReport, opts)
process.exitCode = process.exitCode || result.exitCode
this.npm.output(result.report)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Bin extends BaseCommand {
async bin (args) {
const b = this.npm.bin
this.npm.output(b)
if (this.npm.flatOptions.global && !envPath.includes(b))
if (this.npm.config.get('global') && !envPath.includes(b))
console.error('(not in PATH env variable)')
}
}
Expand Down
5 changes: 2 additions & 3 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Cache extends BaseCommand {
throw new Error('npm cache clear does not accept arguments')

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

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

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

async verify () {
Expand Down
5 changes: 3 additions & 2 deletions lib/ci.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ class CI extends BaseCommand {
}

async ci () {
if (this.npm.flatOptions.global) {
if (this.npm.config.get('global')) {
const err = new Error('`npm ci` does not work for global packages')
err.code = 'ECIGLOBAL'
throw err
}

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

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

const ignoreScripts = this.npm.config.get('ignore-scripts')
// run the same set of scripts that `npm install` runs.
if (!ignoreScripts) {
const scripts = [
Expand All @@ -65,6 +65,7 @@ class CI extends BaseCommand {
'prepare',
'postprepare',
]
const scriptShell = this.npm.config.get('script-shell') || undefined
for (const event of scripts) {
await runScript({
path: where,
Expand Down
7 changes: 4 additions & 3 deletions lib/dedupe.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ class Dedupe extends BaseCommand {

const dryRun = this.npm.config.get('dry-run')
const where = this.npm.prefix
const arb = new Arborist({
const opts = {
...this.npm.flatOptions,
path: where,
dryRun,
})
await arb.dedupe(this.npm.flatOptions)
}
const arb = new Arborist(opts)
await arb.dedupe(opts)
await reifyFinish(this.npm, arb)
}
}
Expand Down
6 changes: 3 additions & 3 deletions lib/diff.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Diff extends BaseCommand {

get where () {
const globalTop = resolve(this.npm.globalDir, '..')
const { global } = this.npm.flatOptions
const global = this.npm.config.get('global')
return global ? globalTop : this.npm.prefix
}

Expand All @@ -39,7 +39,7 @@ class Diff extends BaseCommand {
}

async diff (args) {
const specs = this.npm.flatOptions.diff.filter(d => d)
const specs = this.npm.config.get('diff').filter(d => d)
wraithgar marked this conversation as resolved.
Show resolved Hide resolved
if (specs.length > 2) {
throw new TypeError(
'Can\'t use more than two --diff arguments.\n\n' +
Expand Down Expand Up @@ -91,7 +91,7 @@ class Diff extends BaseCommand {
}

return [
`${pkgName}@${this.npm.flatOptions.defaultTag}`,
`${pkgName}@${this.npm.config.get('tag')}`,
`file:${this.npm.prefix}`,
]
}
Expand Down
2 changes: 1 addition & 1 deletion lib/dist-tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class DistTag extends BaseCommand {
async add (spec, tag, opts) {
spec = npa(spec || '')
const version = spec.rawSpec
const defaultTag = tag || opts.defaultTag
const defaultTag = tag || this.npm.config.get('tag')

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

Expand Down
11 changes: 7 additions & 4 deletions lib/exec.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const BaseCommand = require('./base-command.js')
//
// npm x -p pkg@version -- foo --registry=/dev/null
//
// const pkg = npm.flatOptions.package || getPackageFrom(args[0])
// const pkg = npm.config.get('package') || getPackageFrom(args[0])
// const cmd = getCommand(pkg, args[0])
// --> npm x -c 'cmd ...args.slice(1)'
//
Expand Down Expand Up @@ -66,7 +66,10 @@ class Exec extends BaseCommand {
// When commands go async and we can dump the boilerplate exec methods this
// can be named correctly
async _exec (args) {
const { package: packages, call, shell } = this.npm.flatOptions
const call = this.npm.config.get('call')
const shell = this.npm.config.get('shell')
// dereferenced because we manipulate it later
const packages = [...this.npm.config.get('package')]

if (call && args.length)
throw this.usage
Expand Down Expand Up @@ -165,9 +168,9 @@ class Exec extends BaseCommand {

// no need to install if already present
if (add.length) {
if (!this.npm.flatOptions.yes) {
if (!this.npm.config.get('yes')) {
// set -n to always say no
if (this.npm.flatOptions.yes === false)
if (this.npm.config.get('yes') === false)
throw 'canceled'

if (!process.stdin.isTTY || ciDetect()) {
Expand Down
25 changes: 10 additions & 15 deletions lib/fund.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,8 @@ class Fund extends BaseCommand {
}

async fund (args) {
const opts = this.npm.flatOptions
const spec = args[0]
const numberArg = opts.which
const numberArg = this.npm.config.get('which')

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

Expand All @@ -58,14 +57,14 @@ class Fund extends BaseCommand {
throw err
}

if (opts.global) {
if (this.npm.config.get('global')) {
const err = new Error('`npm fund` does not support global packages')
err.code = 'EFUNDGLOBAL'
throw err
}

const where = this.npm.prefix
const arb = new Arborist({ ...opts, path: where })
const arb = new Arborist({ ...this.npm.flatOptions, path: where })
const tree = await arb.loadActual()

if (spec) {
Expand All @@ -78,23 +77,19 @@ class Fund extends BaseCommand {
return
}

const print = opts.json
? this.printJSON
: this.printHuman

this.npm.output(
print(
getFundingInfo(tree),
opts
)
)
if (this.npm.config.get('json'))
this.npm.output(this.printJSON(getFundingInfo(tree)))
else
this.npm.output(this.printHuman(getFundingInfo(tree)))
}

printJSON (fundingInfo) {
return JSON.stringify(fundingInfo, null, 2)
}

printHuman (fundingInfo, { color, unicode }) {
printHuman (fundingInfo) {
const color = !!this.npm.color
const unicode = this.npm.config.get('unicode')
const seenUrls = new Map()

const tree = obj =>
Expand Down
4 changes: 2 additions & 2 deletions lib/help-search.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class HelpSearch extends BaseCommand {
out.push(' '.repeat((Math.max(1, cols - out.join(' ').length - r.length - 1))))
out.push(r)

if (!this.npm.flatOptions.long)
if (!this.npm.config.get('long'))
return out.join('')

out.unshift('\n\n')
Expand Down Expand Up @@ -198,7 +198,7 @@ class HelpSearch extends BaseCommand {
return out.join('')
}).join('\n')

const finalOut = results.length && !this.npm.flatOptions.long
const finalOut = results.length && !this.npm.config.get('long')
? 'Top hits for ' + (args.map(JSON.stringify).join(' ')) + '\n' +
'—'.repeat(cols - 1) + '\n' +
out + '\n' +
Expand Down
2 changes: 1 addition & 1 deletion lib/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Init extends BaseCommand {
this.npm.log.pause()
this.npm.log.disableProgress()
const initFile = this.npm.config.get('init-module')
if (!this.npm.flatOptions.yes && !this.npm.flatOptions.force) {
if (!this.npm.config.get('yes') && !this.npm.config.get('force')) {
this.npm.output([
'This utility will walk you through creating a package.json file.',
'It only covers the most common items, and tries to guess sensible defaults.',
Expand Down
5 changes: 3 additions & 2 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ class Install extends BaseCommand {
async install (args) {
// the /path/to/node_modules/..
const globalTop = resolve(this.npm.globalDir, '..')
const { ignoreScripts, global: isGlobalInstall } = this.npm.flatOptions
const ignoreScripts = this.npm.config.get('ignore-scripts')
const isGlobalInstall = this.npm.config.get('global')
const where = isGlobalInstall ? globalTop : this.npm.prefix

// don't try to install the prefix into itself
Expand All @@ -122,7 +123,7 @@ class Install extends BaseCommand {
add: args,
})
if (!args.length && !isGlobalInstall && !ignoreScripts) {
const { scriptShell } = this.npm.flatOptions
const scriptShell = this.npm.config.get('script-shell') || undefined
const scripts = [
'preinstall',
'install',
Expand Down
8 changes: 7 additions & 1 deletion lib/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,13 @@ class Link extends BaseCommand {
// npm link should not save=true by default unless you're
// using any of --save-dev or other types
const save =
Boolean(this.npm.config.find('save') !== 'default' || this.npm.flatOptions.saveType)
Boolean(
this.npm.config.find('save') !== 'default' ||
this.npm.config.get('save-optional') ||
this.npm.config.get('save-peer') ||
this.npm.config.get('save-dev') ||
this.npm.config.get('save-prod')
)

// create a new arborist instance for the local prefix and
// reify all the pending names as symlinks there
Expand Down
5 changes: 3 additions & 2 deletions lib/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ class Logout extends BaseCommand {
}

async logout (args) {
const { registry, scope } = this.npm.flatOptions
const registry = this.npm.config.get('registry')
const scope = this.npm.config.get('scope')
const regRef = scope ? `${scope}:registry` : 'registry'
const reg = this.npm.flatOptions[regRef] || registry
const reg = this.npm.config.get(regRef) || registry

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

Expand Down
22 changes: 10 additions & 12 deletions lib/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,24 +43,22 @@ class LS extends BaseCommand {
}

async ls (args) {
const {
all,
color,
depth,
json,
long,
global,
parseable,
prefix,
unicode,
} = this.npm.flatOptions
const path = global ? resolve(this.npm.globalDir, '..') : prefix
const all = this.npm.config.get('all')
const color = !!this.npm.color
const depth = this.npm.config.get('depth')
const dev = this.npm.config.get('dev')
const development = this.npm.config.get('development')
const global = this.npm.config.get('global')
const json = this.npm.config.get('json')
const link = this.npm.config.get('link')
const long = this.npm.config.get('long')
const only = this.npm.config.get('only')
const parseable = this.npm.config.get('parseable')
const prod = this.npm.config.get('prod')
const production = this.npm.config.get('production')
const unicode = this.npm.config.get('unicode')

const path = global ? resolve(this.npm.globalDir, '..') : this.npm.prefix

const arb = new Arborist({
global,
Expand Down
Loading