Skip to content

Commit

Permalink
feat: switch to & allow passing custom fn too
Browse files Browse the repository at this point in the history
  • Loading branch information
Charlike Mike Reagent committed Feb 1, 2019
1 parent cae0822 commit 74d8046
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 47 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"node": "^8.10.0 || >=10.13.0"
},
"dependencies": {
"@tunnckocore/package-json": "1.0.3",
"esm": "^3.2.0",
"package-json": "^6.0.0",
"recommended-bump": "1.3.1"
},
"devDependencies": {
Expand Down
11 changes: 7 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import recommendedBump from 'recommended-bump';
import packageJson from '@tunnckocore/package-json';
import packageJson from 'package-json';
import increment from './semver-inc';

/**
Expand Down Expand Up @@ -90,7 +90,7 @@ export default async function detector(commits, options) {
}

if (opts.packages) {
const { endpoint, plugins, cwd } = opts;
const { plugins, cwd } = opts;

/**
* Inside commit
Expand All @@ -109,7 +109,7 @@ export default async function detector(commits, options) {
const path = name.startsWith('@') ? name : `packages/${name}`;
const [result] = await detector(commits, {
name,
endpoint,
packageJson,
plugins,
cwd,
});
Expand Down Expand Up @@ -151,7 +151,10 @@ export default async function detector(commits, options) {
// a directory inside the root (cwd) of monorepo.
const path = name.startsWith('@') ? name : `packages/${name}`;

const pkg = await packageJson(name, opts.endpoint);
const getPkg =
typeof opts.packageJson === 'function' ? opts.packageJson : packageJson;

const pkg = await getPkg(name, opts);
const recommended = recommendedBump(cmts, opts.plugins);
const lastVersion = pkg.version;

Expand Down
3 changes: 2 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import assert from 'assert';
import test from 'asia';
import packageJson from 'package-json';
import detectNextVersion from '../src';
import semverIncrement from '../src/semver-inc';

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

assert.strictEqual(result.increment, false);
Expand Down
Loading

0 comments on commit 74d8046

Please sign in to comment.