Skip to content

Commit

Permalink
semver order
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-mitchell committed Sep 1, 2023
1 parent c6249a2 commit a682b51
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion source/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ const ui = async (options, {pkg, rootDir}) => {
// Version error handling does validation
version.setFrom(input);
} catch (error) {
if (error.message.includes('valid `SemVer` version')) {
if (error.message.includes('valid SemVer version')) {
throw new Error(`Custom version ${input} should be a valid SemVer version.`);
}

Expand Down
2 changes: 1 addition & 1 deletion source/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import semver from 'semver';
import {template as chalk} from 'chalk-template';

/** @type {string[]} Allowed `SemVer` release types. */
export const SEMVER_INCREMENTS = semver.RELEASE_TYPES.sort();
export const SEMVER_INCREMENTS = ['patch', 'minor', 'major', 'prepatch', 'preminor', 'premajor', 'prerelease'];
export const SEMVER_INCREMENTS_LIST = SEMVER_INCREMENTS.join(', ');
const SEMVER_INCREMENTS_LIST_LAST_OR = `${SEMVER_INCREMENTS.slice(0, -1).join(', ')}, or ${SEMVER_INCREMENTS.slice(-1)}`;

Expand Down
2 changes: 1 addition & 1 deletion test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('flags: --help', cliPasses, cli, '--help', [
'$ np <version>',
'',
'Version can be:',
'major | minor | patch | premajor | preminor | prepatch | prerelease | 1.2.3',
'patch | minor | major | prepatch | preminor | premajor | prerelease | 1.2.3',
'',
'Options',
'--any-branch Allow publishing from any branch',
Expand Down
4 changes: 2 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const npFails = test.macro(async (t, inputs, message) => {

test('version is invalid', npFails,
['foo', '4.x.3'],
/New version `(?:foo|4\.x\.3)` should either be one of `major`, `minor`, `patch`, `premajor`, `preminor`, `prepatch`, `prerelease`, or a valid `SemVer` version\./,
/New version (?:foo|4\.x\.3) should either be one of patch, minor, major, prepatch, preminor, premajor, prerelease, or a valid SemVer version\./,
);

test('version is pre-release', npFails,
Expand All @@ -37,7 +37,7 @@ test('version is pre-release', npFails,

test('errors on too low version', npFails,
['1.0.0', '1.0.0-beta'],
/New version `1\.0\.0(?:-beta)?` should be higher than current version `\d+\.\d+\.\d+`/,
/New version 1\.0\.0(?:-beta)? should be higher than current version \d+\.\d+\.\d+/,
);

test('skip enabling 2FA if the package exists', async t => {
Expand Down
4 changes: 2 additions & 2 deletions test/tasks/prerequisite-tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ test.serial('should fail when git remote does not exist', createFixture, [{
test.serial('should fail when version is invalid', async t => {
await t.throwsAsync(
run(actualPrerequisiteTasks('DDD', {name: 'test', version: '1.0.0'}, {yarn: false})),
{message: 'New version `DDD` should either be one of `major`, `minor`, `patch`, `premajor`, `preminor`, `prepatch`, `prerelease`, or a valid `SemVer` version.'},
{message: 'New version DDD should either be one of patch, minor, major, prepatch, preminor, premajor, prerelease, or a valid SemVer version.'},
);

assertTaskFailed(t, 'Validate version');
Expand All @@ -195,7 +195,7 @@ test.serial('should fail when version is invalid', async t => {
test.serial('should fail when version is lower than latest version', async t => {
await t.throwsAsync(
run(actualPrerequisiteTasks('0.1.0', {name: 'test', version: '1.0.0'}, {yarn: false})),
{message: 'New version `0.1.0` should be higher than current version `1.0.0`.'},
{message: 'New version 0.1.0 should be higher than current version 1.0.0.'},
);

assertTaskFailed(t, 'Validate version');
Expand Down
8 changes: 4 additions & 4 deletions test/ui/prompts/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,19 @@ test('choose custom - validation', testUi, {
customVersion: [
{
input: 'major',
error: 'Custom version should not be a `SemVer` increment.',
error: 'Custom version should not be a SemVer increment.',
},
{
input: '200',
error: 'Custom version `200` should be a valid `SemVer` version.',
error: 'Custom version 200 should be a valid SemVer version.',
},
{
input: '0.0.0',
error: 'Custom version `0.0.0` should be higher than current version `1.0.0`.',
error: 'Custom version 0.0.0 should be higher than current version 1.0.0.',
},
{
input: '1.0.0',
error: 'Custom version `1.0.0` should be higher than current version `1.0.0`.',
error: 'Custom version 1.0.0 should be higher than current version 1.0.0.',
},
{
input: '2.0.0',
Expand Down
4 changes: 2 additions & 2 deletions test/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {template as chalk} from 'chalk-template';
import semver from 'semver';
import Version from '../source/version.js';

const INCREMENT_LIST = 'major, minor, patch, premajor, preminor, prepatch, prerelease';
const INCREMENT_LIST_OR = 'major, minor, patch, premajor, preminor, prepatch, or prerelease';
const INCREMENT_LIST = 'patch, minor, major, prepatch, preminor, premajor, prerelease';
const INCREMENT_LIST_OR = 'patch, minor, major, prepatch, preminor, premajor, or prerelease';

/** @param {string} input - Place `{ }` around the version parts to be highlighted. */
const makeNewFormattedVersion = input => {
Expand Down

0 comments on commit a682b51

Please sign in to comment.