diff --git a/package.json b/package.json index c48b45b3..dd7ac87f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/source/npm/util.js b/source/npm/util.js index e72177e2..c1a6e2c5 100644 --- a/source/npm/util.js +++ b/source/npm/util.js @@ -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'; @@ -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']; @@ -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 { diff --git a/source/util.js b/source/util.js index e19cc7c7..229d6b10 100644 --- a/source/util.js +++ b/source/util.js @@ -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}); @@ -62,7 +67,7 @@ export const linkifyCommitRange = (url, commitRange) => { /** @type {(config: import('./package-manager/types.js').PackageManagerConfig) => Promise} */ 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); @@ -132,7 +137,7 @@ export const getNewDependencies = async (newPackage, rootDirectory) => { /** @type {(config: import('./package-manager/types.js').PackageManagerConfig) => Promise} */ 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']); diff --git a/test/npm/util/collaborators.js b/test/npm/util/collaborators.js index 074e4195..8afffd28 100644 --- a/test/npm/util/collaborators.js +++ b/test/npm/util/collaborators.js @@ -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'}, ); }); diff --git a/test/npm/util/prerelease-tags.js b/test/npm/util/prerelease-tags.js index a620cfd9..6424e414 100644 --- a/test/npm/util/prerelease-tags.js +++ b/test/npm/util/prerelease-tags.js @@ -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'}, ); }); diff --git a/test/util/get-pre-release-prefix.js b/test/util/get-pre-release-prefix.js index 84cbedba..0a69d8d8 100644 --- a/test/util/get-pre-release-prefix.js +++ b/test/util/get-pre-release-prefix.js @@ -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'; @@ -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`'}, ); }); diff --git a/test/util/get-tag-version-prefix.js b/test/util/get-tag-version-prefix.js index b14ba9e5..90bb1e28 100644 --- a/test/util/get-tag-version-prefix.js +++ b/test/util/get-tag-version-prefix.js @@ -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'; @@ -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`'}, ); });