Skip to content
This repository was archived by the owner on Sep 18, 2024. It is now read-only.

Commit 1543d6d

Browse files
wmertensadriantoine
authored andcommitted
fix: Make it work with included files #35 from wmertens/patch-1
* Make it work with included files My webpack config imports a few things and that seems to trigger the self-loading weirdness; with this patch everything works. * Add test watch mode for ava tests
1 parent d794203 commit 1543d6d

File tree

5 files changed

+20
-1
lines changed

5 files changed

+20
-1
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"build": "babel src -d build",
77
"dev": "watch 'npm run build' src/",
88
"test": "npm run test:lint && npm run test:plugin",
9+
"test:watch": "ava -w",
910
"test:win": "ava",
1011
"test:lint": "eslint src/ test/",
1112
"test:plugin": "eslint src/ test/ && nyc --cache --reporter=text ava",

src/index.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ export default function({ types: t }) {
6868
// Require the config
6969
let conf = require(confPath);
7070

71+
// if the object is empty, we might be in a dependency of the config - bail without warning
72+
if (!Object.keys(conf).length) {
73+
return;
74+
}
75+
7176
// In the case the webpack config is an es6 config, we need to get the default
7277
if (conf && conf.__esModule && conf.default) {
7378
conf = conf.default;

test/empty-object.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// empty object, this happens while importing things in the webpack config
2+
// eslint-disable-next-line import/no-commonjs
3+
module.exports = {
4+
};

test/index.spec.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ test('should throw an error when there is no resolve config', t => {
100100
);
101101
});
102102

103+
test('should ignore empty object', t => {
104+
t.notThrows(() => transformFixture('basic/absolute.js', {config: 'empty-object.config.js'}));
105+
});
106+
103107
test('works with webpack configs that export an array, instead of a single object (multicompile mode)', t => {
104108
const actual = transformFixture('multicompile/source.js', {config: './webpack.multicompile.js'});
105109
const expected = readFixture('multicompile/expected.js');

test/no-resolve.config.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
module.exports = {};
1+
// incomplete webpack config
2+
module.exports = {
3+
output: {
4+
5+
}
6+
};

0 commit comments

Comments
 (0)