Skip to content

Commit 74d8046

Browse files
author
Charlike Mike Reagent
committed
feat: switch to & allow passing custom fn too
1 parent cae0822 commit 74d8046

File tree

4 files changed

+219
-47
lines changed

4 files changed

+219
-47
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"node": "^8.10.0 || >=10.13.0"
2121
},
2222
"dependencies": {
23-
"@tunnckocore/package-json": "1.0.3",
2423
"esm": "^3.2.0",
24+
"package-json": "^6.0.0",
2525
"recommended-bump": "1.3.1"
2626
},
2727
"devDependencies": {

src/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import recommendedBump from 'recommended-bump';
2-
import packageJson from '@tunnckocore/package-json';
2+
import packageJson from 'package-json';
33
import increment from './semver-inc';
44

55
/**
@@ -90,7 +90,7 @@ export default async function detector(commits, options) {
9090
}
9191

9292
if (opts.packages) {
93-
const { endpoint, plugins, cwd } = opts;
93+
const { plugins, cwd } = opts;
9494

9595
/**
9696
* Inside commit
@@ -109,7 +109,7 @@ export default async function detector(commits, options) {
109109
const path = name.startsWith('@') ? name : `packages/${name}`;
110110
const [result] = await detector(commits, {
111111
name,
112-
endpoint,
112+
packageJson,
113113
plugins,
114114
cwd,
115115
});
@@ -151,7 +151,10 @@ export default async function detector(commits, options) {
151151
// a directory inside the root (cwd) of monorepo.
152152
const path = name.startsWith('@') ? name : `packages/${name}`;
153153

154-
const pkg = await packageJson(name, opts.endpoint);
154+
const getPkg =
155+
typeof opts.packageJson === 'function' ? opts.packageJson : packageJson;
156+
157+
const pkg = await getPkg(name, opts);
155158
const recommended = recommendedBump(cmts, opts.plugins);
156159
const lastVersion = pkg.version;
157160

test/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import assert from 'assert';
22
import test from 'asia';
3+
import packageJson from 'package-json';
34
import detectNextVersion from '../src';
45
import semverIncrement from '../src/semver-inc';
56

@@ -57,7 +58,7 @@ test('throw if no commit messages are given', async () => {
5758
test('do not give `result.nextVersion` when only "chore" commits', async () => {
5859
const result = await detectNextVersion(
5960
['chore: foo bar baz', 'chore(ci): some build fix'],
60-
{ name: '@tunnckocore/qq5' },
61+
{ name: '@tunnckocore/qq5', packageJson },
6162
);
6263

6364
assert.strictEqual(result.increment, false);

0 commit comments

Comments
 (0)