Skip to content

Commit 777148d

Browse files
mifisindresorhus
authored andcommitted
Make boolean logic easier to understand
1 parent 819ed29 commit 777148d

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

source/ui.js

+22-3
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,27 @@ const ui = async (options, {pkg, rootDir, isYarnBerry}) => {
235235
}
236236
}
237237

238-
const needsPrereleaseTag = answers => options.runPublish && (answers.version?.isPrerelease() || answers.customVersion?.isPrerelease()) && !options.tag;
239-
const canBePublishedPublicly = options.availability.isAvailable && !options.availability.isUnknown && options.runPublish && (pkg.publishConfig && pkg.publishConfig.access !== 'restricted') && !npm.isExternalRegistry(pkg);
238+
const needsPrereleaseTag = answers => (
239+
options.runPublish
240+
&& (answers.version?.isPrerelease() || answers.customVersion?.isPrerelease())
241+
&& !options.tag
242+
);
243+
244+
// Note that inquirer question.when is a bit confusing. Only `false` will cause the question to be skipped.
245+
// Any other value like `true` and `undefined` means ask the question.
246+
// so we make sure to always return an explicit boolean here to make it less confusing
247+
// see https://github.com/SBoudrias/Inquirer.js/pull/1340
248+
const needToAskForPublish = (() => {
249+
if (!isScoped(pkg.name) || !options.availability.isAvailable || options.availability.isUnknown || !options.runPublish) {
250+
return false;
251+
}
252+
253+
if (!pkg.publishConfig) {
254+
return true;
255+
}
256+
257+
return pkg.publishConfig.access !== 'restricted' && !npm.isExternalRegistry(pkg);
258+
})();
240259

241260
const answers = await inquirer.prompt({
242261
version: {
@@ -318,7 +337,7 @@ const ui = async (options, {pkg, rootDir, isYarnBerry}) => {
318337
},
319338
publishScoped: {
320339
type: 'confirm',
321-
when: isScoped(pkg.name) && canBePublishedPublicly,
340+
when: needToAskForPublish,
322341
message: `This scoped repo ${chalk.bold.magenta(pkg.name)} hasn't been published. Do you want to publish it publicly?`,
323342
default: false,
324343
},

0 commit comments

Comments
 (0)