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

Exclusive config / provenance-file #6496

Closed
wants to merge 1 commit into from
Closed
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
11 changes: 11 additions & 0 deletions docs/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ const getCommandByDoc = (docFile, docExt) => {
const srcName = name === 'npx' ? 'exec' : name
const { params, usage = [''], workspaces } = require(`../../lib/commands/${srcName}`)
const usagePrefix = name === 'npx' ? 'npx' : `npm ${name}`
if (params) {
for (const param of params) {
if (definitions[param].exclusive) {
for (const e of definitions[param].exclusive) {
if (!params.includes(e)) {
params.splice(params.indexOf(param) + 1, 0, e)
}
}
}
}
}

return {
name,
Expand Down
17 changes: 16 additions & 1 deletion lib/base-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class BaseCommand {
// this is a static so that we can read from it without instantiating a command
// which would require loading the config
static get describeUsage () {
const seenExclusive = new Set()
const wrapWidth = 80
const { description, usage = [''], name, params } = this

Expand All @@ -32,7 +33,21 @@ class BaseCommand {
let results = ''
let line = ''
for (const param of params) {
const paramUsage = `[${definitions[param].usage}]`
if (seenExclusive.has(param)) {
continue
}
const { exclusive } = definitions[param]
let paramUsage = `${definitions[param].usage}`
wraithgar marked this conversation as resolved.
Show resolved Hide resolved
if (exclusive) {
const exclusiveParams = [paramUsage]
seenExclusive.add(param)
for (const e of exclusive) {
seenExclusive.add(e)
exclusiveParams.push(definitions[e].usage)
}
paramUsage = `${exclusiveParams.join('|')}`
}
paramUsage = `[${paramUsage}]`
if (line.length + paramUsage.length > wrapWidth) {
results = [results, line].filter(Boolean).join('\n')
line = ''
Expand Down
4 changes: 4 additions & 0 deletions lib/utils/config/definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const allowed = [
'defaultDescription',
'deprecated',
'description',
'exclusive',
'flatten',
'hint',
'key',
Expand Down Expand Up @@ -83,12 +84,15 @@ class Definition {
This value is not exported to the environment for child processes.
`
const deprecated = !this.deprecated ? '' : `* DEPRECATED: ${unindent(this.deprecated)}\n`
/* eslint-disable-next-line max-len */
const exclusive = !this.exclusive ? '' : `\nThis config can not be used with: \`${this.exclusive.join('`, `')}\``
return wrapAll(`#### \`${this.key}\`

* Default: ${unindent(this.defaultDescription)}
* Type: ${unindent(this.typeDescription)}
${deprecated}
${description}
${exclusive}
${noEnvExport}`)
}
}
Expand Down
12 changes: 12 additions & 0 deletions lib/utils/config/definitions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1635,13 +1635,25 @@ define('progress', {
define('provenance', {
default: false,
type: Boolean,
exclusive: ['provenance-file'],
description: `
When publishing from a supported cloud CI/CD system, the package will be
publicly linked to where it was built and published from.
`,
flatten,
})

define('provenance-file', {
default: null,
type: path,
hint: '<file>',
exclusive: ['provenance'],
description: `
When publishing, the provenance bundle at the given path will be used.
`,
flatten,
})

define('proxy', {
default: null,
type: [null, false, url], // allow proxy to be disabled explicitly
Expand Down
2 changes: 2 additions & 0 deletions tap-snapshots/test/lib/commands/config.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ exports[`test/lib/commands/config.js TAP config list --json > output matches sna
"production": null,
"progress": true,
"provenance": false,
"provenance-file": null,
"proxy": null,
"read-only": false,
"rebuild-bundle": true,
Expand Down Expand Up @@ -274,6 +275,7 @@ preid = ""
production = null
progress = true
provenance = false
provenance-file = null
proxy = null
read-only = false
rebuild-bundle = true
Expand Down
Loading