Skip to content

Commit

Permalink
feat: add new exclusive config item publish-file
Browse files Browse the repository at this point in the history
  • Loading branch information
wraithgar authored and lukekarrys committed May 31, 2023
1 parent 6cc4a93 commit 2a8f4f2
Show file tree
Hide file tree
Showing 10 changed files with 399 additions and 3 deletions.
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
18 changes: 17 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,22 @@ class BaseCommand {
let results = ''
let line = ''
for (const param of params) {
const paramUsage = `[${definitions[param].usage}]`
/* istanbul ignore next */
if (seenExclusive.has(param)) {
continue
}
const { exclusive } = definitions[param]
let paramUsage = `${definitions[param].usage}`
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

0 comments on commit 2a8f4f2

Please sign in to comment.