Skip to content

Commit 15b4a7f

Browse files
Drop ow dependency (#733)
1 parent 5d4645f commit 15b4a7f

File tree

7 files changed

+16
-25
lines changed

7 files changed

+16
-25
lines changed

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
"npm-name": "^8.0.0",
5858
"onetime": "^7.0.0",
5959
"open": "^10.0.4",
60-
"ow": "^1.1.1",
6160
"p-memoize": "^7.1.1",
6261
"p-timeout": "^6.1.2",
6362
"path-exists": "^5.0.0",

source/npm/util.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import path from 'node:path';
22
import {pathExists} from 'path-exists';
33
import {execa} from 'execa';
44
import pTimeout from 'p-timeout';
5-
import ow from 'ow';
65
import npmName from 'npm-name';
76
import chalk from 'chalk-template';
87
import * as util from '../util.js';
@@ -48,7 +47,7 @@ export const isExternalRegistry = package_ => typeof package_.publishConfig?.reg
4847

4948
export const collaborators = async package_ => {
5049
const packageName = package_.name;
51-
ow(packageName, ow.string);
50+
util.assert(typeof packageName === 'string', 'Package name is required');
5251

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

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

7271
export const prereleaseTags = async packageName => {
73-
ow(packageName, ow.string);
72+
util.assert(typeof packageName === 'string', 'Package name is required');
7473

7574
let tags = [];
7675
try {

source/util.js

+8-3
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ import issueRegex from 'issue-regex';
77
import terminalLink from 'terminal-link';
88
import {execa} from 'execa';
99
import pMemoize from 'p-memoize';
10-
import ow from 'ow';
1110
import chalk from 'chalk';
1211
import Version from './version.js';
1312
import * as git from './git-util.js';
1413
import * as npm from './npm/util.js';
1514

15+
export const assert = (condition, message) => {
16+
if (!condition) {
17+
throw new Error(message);
18+
}
19+
};
20+
1621
export const readPackage = async (packagePath = process.cwd()) => {
1722
const packageResult = await readPackageUp({cwd: packagePath});
1823

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

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

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

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

137142
try {
138143
const {stdout} = await execa(config.cli, ['config', 'get', 'preid']);

test/npm/util/collaborators.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const createFixture = _createFixture('../../../source/npm/util.js', import.meta.
99
test('package.name not a string', async t => {
1010
await t.throwsAsync(
1111
npm.collaborators({name: 1}),
12-
{message: 'Expected argument to be of type `string` but received type `number`'},
12+
{message: 'Package name is required'},
1313
);
1414
});
1515

test/npm/util/prerelease-tags.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const createFixture = _createFixture('../../../source/npm/util.js', import.meta.
99
test('packageName not a string', async t => {
1010
await t.throwsAsync(
1111
npm.prereleaseTags(1),
12-
{message: 'Expected argument to be of type `string` but received type `number`'},
12+
{message: 'Package name is required'},
1313
);
1414
});
1515

test/util/get-pre-release-prefix.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import process from 'node:process';
22
import test from 'ava';
3-
import {stripIndent} from 'common-tags';
43
import {_createFixture} from '../_helpers/stub-execa.js';
54
import {getPreReleasePrefix as originalGetPreReleasePrefix} from '../../source/util.js';
65

@@ -50,17 +49,12 @@ test('returns empty string if not set - yarn', createFixture, [{
5049
test('no options passed', async t => {
5150
await t.throwsAsync(
5251
originalGetPreReleasePrefix(),
53-
{
54-
message: stripIndent`
55-
Expected argument to be of type \`object\` but received type \`undefined\`
56-
Expected object to have keys \`["cli"]\`
57-
`,
58-
},
52+
{message: 'Config is missing key `cli`'},
5953
);
6054

6155
await t.throwsAsync(
6256
originalGetPreReleasePrefix({}),
63-
{message: 'Expected object to have keys `["cli"]`'},
57+
{message: 'Config is missing key `cli`'},
6458
);
6559
});
6660

test/util/get-tag-version-prefix.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import test from 'ava';
2-
import {stripIndent} from 'common-tags';
32
import {_createFixture} from '../_helpers/stub-execa.js';
43
import {getTagVersionPrefix as originalGetTagVersionPrefix} from '../../source/util.js';
54
import {npmConfig, yarnConfig} from '../../source/package-manager/configs.js';
@@ -40,16 +39,11 @@ test('defaults to "v" when command fails', createFixture, [{
4039
test('no options passed', async t => {
4140
await t.throwsAsync(
4241
originalGetTagVersionPrefix(),
43-
{
44-
message: stripIndent`
45-
Expected argument to be of type \`object\` but received type \`undefined\`
46-
Expected object to have keys \`["tagVersionPrefixCommand"]\`
47-
`,
48-
},
42+
{message: 'Config is missing key `tagVersionPrefixCommand`'},
4943
);
5044

5145
await t.throwsAsync(
5246
originalGetTagVersionPrefix({}),
53-
{message: 'Expected object to have keys `["tagVersionPrefixCommand"]`'},
47+
{message: 'Config is missing key `tagVersionPrefixCommand`'},
5448
);
5549
});

0 commit comments

Comments
 (0)