Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,13 @@
"meow": "^13.2.0",
"new-github-release-url": "^2.0.0",
"npm-name": "^8.0.0",
"npm-package-arg": "^13.0.2",
"onetime": "^7.0.0",
"open": "^10.0.4",
"p-memoize": "^7.1.1",
"p-timeout": "^6.1.4",
"path-exists": "^5.0.0",
"package-directory": "^8.0.0",
"path-exists": "^5.0.0",
"read-package-up": "^11.0.0",
"read-pkg": "^9.0.1",
"rxjs": "^7.8.1",
Expand Down
35 changes: 26 additions & 9 deletions source/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {htmlEscape} from 'escape-goat';
import isScoped from 'is-scoped';
import isInteractive from 'is-interactive';
import {execa} from 'execa';
import npa from 'npm-package-arg';
import Version, {SEMVER_INCREMENTS} from './version.js';
import * as util from './util.js';
import * as git from './git-util.js';
Expand Down Expand Up @@ -127,7 +128,29 @@ const checkNewFilesAndDependencies = async (package_, rootDirectory) => {
const ui = async ({packageManager, ...options}, {package_, rootDirectory}) => { // eslint-disable-line complexity
const oldVersion = package_.version;
const extraBaseUrls = ['gitlab.com'];
const repoUrl = package_.repository && githubUrlFromGit(package_.repository.url, {extraBaseUrls});

const getRepoUrl = (package__, {extraBaseUrls}) => {
if (!package__.repository) {
return null;
}

try {
const repo = package__.repository;
const repoString = typeof repo === 'string' ? repo : repo.url;

const parsed = npa(repoString);

if (parsed.hosted) {
return parsed.hosted.browse();
}

return githubUrlFromGit(repoString, {extraBaseUrls});
} catch {
return null;
}
};

const repoUrl = getRepoUrl(package_, {extraBaseUrls});

const {stdout: registryUrl} = await execa(...packageManager.getRegistryCommand);
const releaseBranch = options.branch;
Expand Down Expand Up @@ -174,7 +197,6 @@ const ui = async ({packageManager, ...options}, {package_, rootDirectory}) => {
}
}

// Non-interactive mode - return before prompting
if (options.version) {
return {
...options,
Expand Down Expand Up @@ -231,10 +253,6 @@ const ui = async ({packageManager, ...options}, {package_, rootDirectory}) => {

const alreadyPublicScoped = packageManager.id === 'yarn-berry' && options.runPublish && await util.getNpmPackageAccess(package_.name) === 'public';

// Note that inquirer question.when is a bit confusing. Only `false` will cause the question to be skipped.
// Any other value like `true` and `undefined` means ask the question.
// so we make sure to always return an explicit boolean here to make it less confusing
// see https://github.com/SBoudrias/Inquirer.js/pull/1340
const needToAskForPublish = (() => {
if (alreadyPublicScoped || !isScoped(package_.name) || !options.availability.isAvailable || options.availability.isUnknown || !options.runPublish) {
return false;
Expand All @@ -254,7 +272,7 @@ const ui = async ({packageManager, ...options}, {package_, rootDirectory}) => {
pageSize: SEMVER_INCREMENTS.length + 2,
default: 0,
choices: [
...SEMVER_INCREMENTS.map(increment => ({ // TODO: prerelease prefix here too
...SEMVER_INCREMENTS.map(increment => ({
name: `${increment} ${new Version(oldVersion, increment).format()}`,
value: increment,
})),
Expand All @@ -278,15 +296,13 @@ const ui = async ({packageManager, ...options}, {package_, rootDirectory}) => {
const version = new Version(oldVersion);

try {
// Version error handling does validation
version.setFrom(input);
} catch (error) {
if (error.message.includes('valid SemVer version')) {
throw new Error(`Custom version ${input} should be a valid SemVer version.`);
}

error.message = error.message.replace('New', 'Custom');

throw error;
}

Expand Down Expand Up @@ -346,3 +362,4 @@ const ui = async ({packageManager, ...options}, {package_, rootDirectory}) => {
};

export default ui;

Loading