Skip to content

Commit 468acf9

Browse files
dword-designlukechilds
authored andcommitted
Allow exceptions to be propagated (#15)
1 parent bead559 commit 468acf9

4 files changed

Lines changed: 19 additions & 5 deletions

File tree

‎src/index.js‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
const pkgDir = require('pkg-dir');
44

5-
try {
6-
module.exports = require(pkgDir.sync());
7-
} catch (err) {
8-
module.exports = undefined;
9-
}
5+
const packageDir = pkgDir.sync();
6+
7+
module.exports = packageDir === null ? undefined : require(packageDir);

‎test/exceptions.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import test from 'ava';
2+
3+
const cwd = process.cwd();
4+
const pkgPath = require.resolve('../');
5+
6+
test.afterEach.always(() => {
7+
process.chdir(cwd);
8+
delete require.cache[pkgPath];
9+
});
10+
11+
test.serial(`throws exceptions`, t => {
12+
process.chdir('test/helpers/package-with-exception');
13+
t.throws(() => require(pkgPath));
14+
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
throw new Error('error');
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

0 commit comments

Comments
 (0)