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

Allow publishing if availability check fails #490

Merged
merged 4 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 deletions source/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,22 @@ updateNotifier({pkg: cli.pkg}).notify();
...cli.flags
};

const isAvailable = flags.publish ? await isPackageNameAvailable(pkg) : false;
const {isAvailable = false, isUnknown = false} = await (async () => {
itaisteinherz marked this conversation as resolved.
Show resolved Hide resolved
try {
return {
isAvailable: flags.publish ? await isPackageNameAvailable(pkg) : false
};
} catch {
return {isUnknown: true};
}
})();

const version = cli.input.length > 0 ? cli.input[0] : false;

const options = await ui({...flags, exists: !isAvailable, version}, pkg);
const options = await ui(
{...flags, exists: !isAvailable, unknown: isUnknown, version},
pkg
);

if (!options.confirm) {
process.exit(0);
Expand Down
53 changes: 44 additions & 9 deletions source/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ module.exports = async (options, pkg) => {
type: 'input',
name: 'tag',
message: 'Tag',
when: answers => options.publish && !pkg.private && version.isPrereleaseOrIncrement(answers.version) && !options.tag && !answers.tag,
when: answers =>
itaisteinherz marked this conversation as resolved.
Show resolved Hide resolved
options.publish &&
!pkg.private &&
version.isPrereleaseOrIncrement(answers.version) &&
!options.tag &&
!answers.tag,
validate: input => {
if (input.length === 0) {
return 'Please specify a tag, for example, `next`.';
Expand All @@ -137,8 +142,15 @@ module.exports = async (options, pkg) => {
{
type: 'confirm',
name: 'publishScoped',
when: isScoped(pkg.name) && !options.exists && options.publish && !pkg.private,
message: `This scoped repo ${chalk.bold.magenta(pkg.name)} hasn't been published. Do you want to publish it publicly?`,
when:
isScoped(pkg.name) &&
!options.exists &&
!options.isUnknown &&
options.publish &&
!pkg.private,
message: `This scoped repo ${chalk.bold.magenta(
pkg.name
)} hasn't been published. Do you want to publish it publicly?`,
default: false
}
];
Expand All @@ -155,12 +167,35 @@ module.exports = async (options, pkg) => {
}

if (!hasCommits) {
const answers = await inquirer.prompt([{
type: 'confirm',
name: 'confirm',
message: 'No commits found since previous release, continue?',
default: false
}]);
const answers = await inquirer.prompt([
{
type: 'confirm',
name: 'confirm',
message: 'No commits found since previous release, continue?',
default: false
}
]);

if (!answers.confirm) {
return {
...options,
...answers
};
}
}

if (options.unknown) {
const answers = await inquirer.prompt([
{
itaisteinherz marked this conversation as resolved.
Show resolved Hide resolved
type: 'confirm',
name: 'confirm',
when: isScoped(pkg.name) && options.publish && !pkg.private,
message: `This scoped repo ${chalk.bold.magenta(
itaisteinherz marked this conversation as resolved.
Show resolved Hide resolved
pkg.name
)} can't be checked for availability. Do you want to try and publish anyway?`,
default: false
}
]);

if (!answers.confirm) {
return {
Expand Down