Skip to content

Commit 2a8f4f2

Browse files
wraithgarlukekarrys
authored andcommitted
feat: add new exclusive config item publish-file
1 parent 6cc4a93 commit 2a8f4f2

File tree

10 files changed

+399
-3
lines changed

10 files changed

+399
-3
lines changed

docs/lib/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,17 @@ const getCommandByDoc = (docFile, docExt) => {
4242
const srcName = name === 'npx' ? 'exec' : name
4343
const { params, usage = [''], workspaces } = require(`../../lib/commands/${srcName}`)
4444
const usagePrefix = name === 'npx' ? 'npx' : `npm ${name}`
45+
if (params) {
46+
for (const param of params) {
47+
if (definitions[param].exclusive) {
48+
for (const e of definitions[param].exclusive) {
49+
if (!params.includes(e)) {
50+
params.splice(params.indexOf(param) + 1, 0, e)
51+
}
52+
}
53+
}
54+
}
55+
}
4556

4657
return {
4758
name,

lib/base-command.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class BaseCommand {
1818
// this is a static so that we can read from it without instantiating a command
1919
// which would require loading the config
2020
static get describeUsage () {
21+
const seenExclusive = new Set()
2122
const wrapWidth = 80
2223
const { description, usage = [''], name, params } = this
2324

@@ -32,7 +33,22 @@ class BaseCommand {
3233
let results = ''
3334
let line = ''
3435
for (const param of params) {
35-
const paramUsage = `[${definitions[param].usage}]`
36+
/* istanbul ignore next */
37+
if (seenExclusive.has(param)) {
38+
continue
39+
}
40+
const { exclusive } = definitions[param]
41+
let paramUsage = `${definitions[param].usage}`
42+
if (exclusive) {
43+
const exclusiveParams = [paramUsage]
44+
seenExclusive.add(param)
45+
for (const e of exclusive) {
46+
seenExclusive.add(e)
47+
exclusiveParams.push(definitions[e].usage)
48+
}
49+
paramUsage = `${exclusiveParams.join('|')}`
50+
}
51+
paramUsage = `[${paramUsage}]`
3652
if (line.length + paramUsage.length > wrapWidth) {
3753
results = [results, line].filter(Boolean).join('\n')
3854
line = ''

lib/utils/config/definition.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const allowed = [
1313
'defaultDescription',
1414
'deprecated',
1515
'description',
16+
'exclusive',
1617
'flatten',
1718
'hint',
1819
'key',
@@ -83,12 +84,15 @@ class Definition {
8384
This value is not exported to the environment for child processes.
8485
`
8586
const deprecated = !this.deprecated ? '' : `* DEPRECATED: ${unindent(this.deprecated)}\n`
87+
/* eslint-disable-next-line max-len */
88+
const exclusive = !this.exclusive ? '' : `\nThis config can not be used with: \`${this.exclusive.join('`, `')}\``
8689
return wrapAll(`#### \`${this.key}\`
8790
8891
* Default: ${unindent(this.defaultDescription)}
8992
* Type: ${unindent(this.typeDescription)}
9093
${deprecated}
9194
${description}
95+
${exclusive}
9296
${noEnvExport}`)
9397
}
9498
}

lib/utils/config/definitions.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,13 +1635,25 @@ define('progress', {
16351635
define('provenance', {
16361636
default: false,
16371637
type: Boolean,
1638+
exclusive: ['provenance-file'],
16381639
description: `
16391640
When publishing from a supported cloud CI/CD system, the package will be
16401641
publicly linked to where it was built and published from.
16411642
`,
16421643
flatten,
16431644
})
16441645

1646+
define('provenance-file', {
1647+
default: null,
1648+
type: path,
1649+
hint: '<file>',
1650+
exclusive: ['provenance'],
1651+
description: `
1652+
When publishing, the provenance bundle at the given path will be used.
1653+
`,
1654+
flatten,
1655+
})
1656+
16451657
define('proxy', {
16461658
default: null,
16471659
type: [null, false, url], // allow proxy to be disabled explicitly

tap-snapshots/test/lib/commands/config.js.test.cjs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ exports[`test/lib/commands/config.js TAP config list --json > output matches sna
118118
"production": null,
119119
"progress": true,
120120
"provenance": false,
121+
"provenance-file": null,
121122
"proxy": null,
122123
"read-only": false,
123124
"rebuild-bundle": true,
@@ -274,6 +275,7 @@ preid = ""
274275
production = null
275276
progress = true
276277
provenance = false
278+
provenance-file = null
277279
proxy = null
278280
read-only = false
279281
rebuild-bundle = true

0 commit comments

Comments
 (0)