Skip to content

Commit 168ffd6

Browse files
committed
refactor: extract Package.detect()
1 parent f3746b3 commit 168ffd6

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ const result = await require('node-support').detect({ path });
3333
`path` should be a folder in the local file system. When the path is not a git repository - tries to read the git repository from `package.json` and tries to detect the versions listed in the repository as well.
3434

3535
```
36-
const result = await require('node-support').detect({ package });
36+
const result = await require('node-support').detect({ packageName });
3737
```
3838

39-
`package` is a string name for the package in the registry.
39+
`packageName` is a string name for the package in the registry.
4040

4141
```
4242
const result = await require('node-support').detect({ repository });
@@ -47,7 +47,7 @@ const result = await require('node-support').detect({ repository });
4747
### Result
4848

4949
- Throws if the `path` / `repository` does not have a `package.json`
50-
- Throws if `package` does not exist in the registry
50+
- Throws if `packageName` does not exist in the registry
5151
- Throws when unable to detect a git repository for the package
5252

5353
Otherwise returns an object with:

lib/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
'use strict';
22

3-
const Path = require('path');
4-
3+
const Package = require('./package');
54
const Travis = require('./travis');
65

7-
exports.detect = ({ path }) => {
6+
exports.detect = async ({ path, repository, packageName }) => {
87

9-
const packageJson = require(Path.join(path, 'package.json'));
8+
const packageInfo = await Package.detect({ path, repository, packageName });
109

11-
const { name, version } = packageJson;
10+
const result = {};
1211

13-
const result = { name, version };
12+
result.name = packageInfo.name;
13+
result.version = packageInfo.version;
1414

15-
const travis = Travis.detect({ path });
15+
const travis = await Travis.detect({ path });
1616

1717
if (travis) {
1818
result.travis = travis;

lib/package.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict';
2+
3+
const Path = require('path');
4+
5+
exports.detect = ({ path, repository, packageName }) => {
6+
7+
const packageJson = require(Path.join(path, 'package.json'));
8+
9+
const { name, version } = packageJson;
10+
11+
return { name, version };
12+
};

0 commit comments

Comments
 (0)