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

Commit

Permalink
fix: Make it work with included files #35 from wmertens/patch-1
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
wmertens authored and adriantoine committed Nov 17, 2016
1 parent d794203 commit 1543d6d
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"build": "babel src -d build",
"dev": "watch 'npm run build' src/",
"test": "npm run test:lint && npm run test:plugin",
"test:watch": "ava -w",
"test:win": "ava",
"test:lint": "eslint src/ test/",
"test:plugin": "eslint src/ test/ && nyc --cache --reporter=text ava",
Expand Down
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export default function({ types: t }) {
// Require the config
let conf = require(confPath);

// if the object is empty, we might be in a dependency of the config - bail without warning
if (!Object.keys(conf).length) {
return;
}

// In the case the webpack config is an es6 config, we need to get the default
if (conf && conf.__esModule && conf.default) {
conf = conf.default;
Expand Down
4 changes: 4 additions & 0 deletions test/empty-object.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// empty object, this happens while importing things in the webpack config
// eslint-disable-next-line import/no-commonjs
module.exports = {
};
4 changes: 4 additions & 0 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ test('should throw an error when there is no resolve config', t => {
);
});

test('should ignore empty object', t => {
t.notThrows(() => transformFixture('basic/absolute.js', {config: 'empty-object.config.js'}));
});

test('works with webpack configs that export an array, instead of a single object (multicompile mode)', t => {
const actual = transformFixture('multicompile/source.js', {config: './webpack.multicompile.js'});
const expected = readFixture('multicompile/expected.js');
Expand Down
7 changes: 6 additions & 1 deletion test/no-resolve.config.js
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
module.exports = {};
// incomplete webpack config
module.exports = {
output: {

}
};

0 comments on commit 1543d6d

Please sign in to comment.