Skip to content

Commit 2a8f4f2

Browse files
wraithgarlukekarrys
authored andcommittedMay 31, 2023
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

+11
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

+17-1
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

+4
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

+12
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

+2
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

‎tap-snapshots/test/lib/docs.js.test.cjs

+302-1
Large diffs are not rendered by default.

‎tap-snapshots/test/lib/utils/config/definition.js.test.cjs

+9
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ exports[`test/lib/utils/config/definition.js TAP basic definition > description
1515
it should not be used ever
1616
1717
not even once.
18+
19+
1820
`
1921

2022
exports[`test/lib/utils/config/definition.js TAP basic definition > human-readable description 1`] = `
@@ -24,6 +26,8 @@ exports[`test/lib/utils/config/definition.js TAP basic definition > human-readab
2426
* Type: Number or String
2527
2628
just a test thingie
29+
30+
2731
`
2832

2933
exports[`test/lib/utils/config/definition.js TAP long description > cols=-1 1`] = `
@@ -93,6 +97,7 @@ with (multiple) {
9397
}
9498
\`\`\`
9599
100+
96101
`
97102

98103
exports[`test/lib/utils/config/definition.js TAP long description > cols=0 1`] = `
@@ -162,6 +167,7 @@ with (multiple) {
162167
}
163168
\`\`\`
164169
170+
165171
`
166172

167173
exports[`test/lib/utils/config/definition.js TAP long description > cols=40 1`] = `
@@ -201,6 +207,7 @@ with (multiple) {
201207
}
202208
\`\`\`
203209
210+
204211
`
205212

206213
exports[`test/lib/utils/config/definition.js TAP long description > cols=9000 1`] = `
@@ -231,6 +238,7 @@ with (multiple) {
231238
}
232239
\`\`\`
233240
241+
234242
`
235243

236244
exports[`test/lib/utils/config/definition.js TAP long description > cols=NaN 1`] = `
@@ -261,4 +269,5 @@ with (multiple) {
261269
}
262270
\`\`\`
263271
272+
264273
`

‎workspaces/config/lib/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,13 @@ class Config {
575575
const v = this.parseField(value, k)
576576
if (where !== 'default') {
577577
this.#checkDeprecated(k, where, obj, [key, value])
578+
if (this.definitions[key]?.exclusive) {
579+
for (const exclusive of this.definitions[key].exclusive) {
580+
if (!this.isDefault(exclusive)) {
581+
throw new TypeError(`--${key} can not be provided when using --${exclusive}`)
582+
}
583+
}
584+
}
578585
}
579586
conf.data[k] = v
580587
}

‎workspaces/config/test/fixtures/definitions.js

+14
Original file line numberDiff line numberDiff line change
@@ -2606,4 +2606,18 @@ const definitions = module.exports = {
26062606
defaultDescription: 'false',
26072607
typeDescription: 'Boolean',
26082608
},
2609+
truth: {
2610+
key: 'truth',
2611+
default: false,
2612+
type: Boolean,
2613+
description: 'The Truth',
2614+
exclusive: ['lie'],
2615+
},
2616+
lie: {
2617+
key: 'lie',
2618+
default: false,
2619+
type: Boolean,
2620+
description: 'A Lie',
2621+
exclusive: ['truth'],
2622+
},
26092623
}

‎workspaces/config/test/index.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ loglevel = yolo
239239
env,
240240
argv,
241241
cwd: join(`${path}/project`),
242-
243242
shorthands,
244243
definitions,
245244
})
@@ -1318,6 +1317,27 @@ t.test('workspaces', async (t) => {
13181317
})
13191318
})
13201319

1320+
t.test('exclusive options conflict', async t => {
1321+
const path = t.testdir()
1322+
const config = new Config({
1323+
env: {},
1324+
npmPath: __dirname,
1325+
argv: [
1326+
process.execPath,
1327+
__filename,
1328+
'--truth=true',
1329+
'--lie=true',
1330+
],
1331+
cwd: join(`${path}/project`),
1332+
shorthands,
1333+
definitions,
1334+
flatten,
1335+
})
1336+
await t.rejects(config.load(), {
1337+
name: 'TypeError',
1338+
message: '--lie can not be provided when using --truth',
1339+
})
1340+
})
13211341
t.test('env-replaced config from files is not clobbered when saving', async (t) => {
13221342
const path = t.testdir()
13231343
const opts = {

0 commit comments

Comments
 (0)
Please sign in to comment.