Skip to content

Commit 0eaca7e

Browse files
committed
Removed fs.existsSync calls.
1 parent c5b7ef1 commit 0eaca7e

File tree

2 files changed

+27
-11
lines changed

2 files changed

+27
-11
lines changed

bin/doxdox

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,21 @@ ${chalk.yellow(' -t, --title')} Sets title.
4848

4949
let pkg = findPackageFileInPath(args.flags['--package'] || args.flags['-p']);
5050

51-
if (fs.existsSync(pkg)) {
51+
try {
5252

53-
pkg = require(pkg);
53+
const pkgStats = fs.statSync(pkg);
5454

55-
} else {
55+
if (pkgStats.isFile()) {
56+
57+
pkg = require(pkg);
58+
59+
} else {
60+
61+
pkg = {};
62+
63+
}
64+
65+
} catch (err) {
5666

5767
pkg = {};
5868

lib/utils.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,31 +17,37 @@ const path = require('path');
1717

1818
const findPackageFileInPath = input => {
1919

20-
let pkgPath = null;
21-
2220
if (!input) {
2321

2422
input = process.cwd();
2523

2624
}
2725

28-
if (fs.existsSync(input)) {
26+
try {
2927

3028
const stat = fs.statSync(input);
3129

32-
if (stat.isFile()) {
30+
if (stat) {
31+
32+
if (stat.isFile()) {
33+
34+
return path.resolve(path.join(path.dirname(input), '/package.json'));
3335

34-
pkgPath = path.resolve(path.join(path.dirname(input), '/package.json'));
36+
} else if (stat.isDirectory()) {
3537

36-
} else {
38+
return path.resolve(path.join(input, '/package.json'));
3739

38-
pkgPath = path.resolve(path.join(input, '/package.json'));
40+
}
3941

4042
}
4143

44+
} catch (err) {
45+
46+
process.stderr.write(`${err.toString()}\n`);
47+
4248
}
4349

44-
return pkgPath;
50+
return null;
4551

4652
};
4753

0 commit comments

Comments
 (0)