Skip to content

Commit

Permalink
Drop ow dependency (#733)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommy-mitchell authored Mar 1, 2024
1 parent 5d4645f commit 15b4a7f
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 25 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
"npm-name": "^8.0.0",
"onetime": "^7.0.0",
"open": "^10.0.4",
"ow": "^1.1.1",
"p-memoize": "^7.1.1",
"p-timeout": "^6.1.2",
"path-exists": "^5.0.0",
Expand Down
5 changes: 2 additions & 3 deletions source/npm/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import path from 'node:path';
import {pathExists} from 'path-exists';
import {execa} from 'execa';
import pTimeout from 'p-timeout';
import ow from 'ow';
import npmName from 'npm-name';
import chalk from 'chalk-template';
import * as util from '../util.js';
Expand Down Expand Up @@ -48,7 +47,7 @@ export const isExternalRegistry = package_ => typeof package_.publishConfig?.reg

export const collaborators = async package_ => {
const packageName = package_.name;
ow(packageName, ow.string);
util.assert(typeof packageName === 'string', 'Package name is required');

const arguments_ = ['access', 'list', 'collaborators', packageName, '--json'];

Expand All @@ -70,7 +69,7 @@ export const collaborators = async package_ => {
};

export const prereleaseTags = async packageName => {
ow(packageName, ow.string);
util.assert(typeof packageName === 'string', 'Package name is required');

let tags = [];
try {
Expand Down
11 changes: 8 additions & 3 deletions source/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ import issueRegex from 'issue-regex';
import terminalLink from 'terminal-link';
import {execa} from 'execa';
import pMemoize from 'p-memoize';
import ow from 'ow';
import chalk from 'chalk';
import Version from './version.js';
import * as git from './git-util.js';
import * as npm from './npm/util.js';

export const assert = (condition, message) => {
if (!condition) {
throw new Error(message);
}
};

export const readPackage = async (packagePath = process.cwd()) => {
const packageResult = await readPackageUp({cwd: packagePath});

Expand Down Expand Up @@ -62,7 +67,7 @@ export const linkifyCommitRange = (url, commitRange) => {

/** @type {(config: import('./package-manager/types.js').PackageManagerConfig) => Promise<string>} */
export const getTagVersionPrefix = pMemoize(async config => {
ow(config, ow.object.hasKeys('tagVersionPrefixCommand'));
assert(config && Object.hasOwn(config, 'tagVersionPrefixCommand'), 'Config is missing key `tagVersionPrefixCommand`');

try {
const {stdout} = await execa(...config.tagVersionPrefixCommand);
Expand Down Expand Up @@ -132,7 +137,7 @@ export const getNewDependencies = async (newPackage, rootDirectory) => {

/** @type {(config: import('./package-manager/types.js').PackageManagerConfig) => Promise<string>} */
export const getPreReleasePrefix = pMemoize(async config => {
ow(config, ow.object.hasKeys('cli'));
assert(config && Object.hasOwn(config, 'cli'), 'Config is missing key `cli`');

try {
const {stdout} = await execa(config.cli, ['config', 'get', 'preid']);
Expand Down
2 changes: 1 addition & 1 deletion test/npm/util/collaborators.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const createFixture = _createFixture('../../../source/npm/util.js', import.meta.
test('package.name not a string', async t => {
await t.throwsAsync(
npm.collaborators({name: 1}),
{message: 'Expected argument to be of type `string` but received type `number`'},
{message: 'Package name is required'},
);
});

Expand Down
2 changes: 1 addition & 1 deletion test/npm/util/prerelease-tags.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const createFixture = _createFixture('../../../source/npm/util.js', import.meta.
test('packageName not a string', async t => {
await t.throwsAsync(
npm.prereleaseTags(1),
{message: 'Expected argument to be of type `string` but received type `number`'},
{message: 'Package name is required'},
);
});

Expand Down
10 changes: 2 additions & 8 deletions test/util/get-pre-release-prefix.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import process from 'node:process';
import test from 'ava';
import {stripIndent} from 'common-tags';
import {_createFixture} from '../_helpers/stub-execa.js';
import {getPreReleasePrefix as originalGetPreReleasePrefix} from '../../source/util.js';

Expand Down Expand Up @@ -50,17 +49,12 @@ test('returns empty string if not set - yarn', createFixture, [{
test('no options passed', async t => {
await t.throwsAsync(
originalGetPreReleasePrefix(),
{
message: stripIndent`
Expected argument to be of type \`object\` but received type \`undefined\`
Expected object to have keys \`["cli"]\`
`,
},
{message: 'Config is missing key `cli`'},
);

await t.throwsAsync(
originalGetPreReleasePrefix({}),
{message: 'Expected object to have keys `["cli"]`'},
{message: 'Config is missing key `cli`'},
);
});

Expand Down
10 changes: 2 additions & 8 deletions test/util/get-tag-version-prefix.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import test from 'ava';
import {stripIndent} from 'common-tags';
import {_createFixture} from '../_helpers/stub-execa.js';
import {getTagVersionPrefix as originalGetTagVersionPrefix} from '../../source/util.js';
import {npmConfig, yarnConfig} from '../../source/package-manager/configs.js';
Expand Down Expand Up @@ -40,16 +39,11 @@ test('defaults to "v" when command fails', createFixture, [{
test('no options passed', async t => {
await t.throwsAsync(
originalGetTagVersionPrefix(),
{
message: stripIndent`
Expected argument to be of type \`object\` but received type \`undefined\`
Expected object to have keys \`["tagVersionPrefixCommand"]\`
`,
},
{message: 'Config is missing key `tagVersionPrefixCommand`'},
);

await t.throwsAsync(
originalGetTagVersionPrefix({}),
{message: 'Expected object to have keys `["tagVersionPrefixCommand"]`'},
{message: 'Config is missing key `tagVersionPrefixCommand`'},
);
});

0 comments on commit 15b4a7f

Please sign in to comment.