From eae8c4917709e97de9ed9bd5e8b1f19be8b8d0cc Mon Sep 17 00:00:00 2001 From: Jakub Bogucki Date: Fri, 3 Nov 2017 17:39:06 +0100 Subject: [PATCH] If there is only one file for named entry, pass it directly --- index.js | 8 +++++++- test/fixtures/subdirectory/entry.js | 1 + test/test.js | 22 ++++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/subdirectory/entry.js diff --git a/index.js b/index.js index f161bc2..c53100b 100644 --- a/index.js +++ b/index.js @@ -90,7 +90,13 @@ module.exports = function (options, wp, done) { config.watch = !!options.watch; // Determine pipe'd in entry - if (Object.keys(entries).length > 0) { + var entriesNames = Object.keys(entries); + if (entriesNames.length > 0) { + entriesNames.forEach(function (entryName) { + if (entries[entryName].length === 1) { + entries[entryName] = entries[entryName][0]; + } + }); entry = entries; if (!config.output.filename) { // Better output default for multiple chunks diff --git a/test/fixtures/subdirectory/entry.js b/test/fixtures/subdirectory/entry.js new file mode 100644 index 0000000..dc5928b --- /dev/null +++ b/test/fixtures/subdirectory/entry.js @@ -0,0 +1 @@ +var subDirectoryEntry = true; diff --git a/test/test.js b/test/test.js index 12ef059..836e522 100644 --- a/test/test.js +++ b/test/test.js @@ -86,6 +86,28 @@ test('stream multiple entry points', function (t) { entries.pipe(named()).pipe(stream); }); +test('stream multiple entry points, one with two files', function (t) { + t.plan(2); + var entries = fs.src(['test/fixtures/entry.js', 'test/fixtures/anotherentrypoint.js', 'test/fixtures/subdirectory/entry.js']); + var stream = webpack({ + config: {}, + quiet: true + }); + stream.on('data', function (file) { + var basename = path.basename(file.path); + var contents = file.contents.toString(); + switch (basename) { + case 'entry.js': + t.ok(/module\.exports = __webpack_require__/i.test(contents), 'should contain "module.exports = __webpack_require__"'); + break; + case 'anotherentrypoint.js': + t.notOk(/module\.exports = __webpack_require__/i.test(contents), 'should not contain "module.exports = __webpack_require__"'); + break; + } + }); + entries.pipe(named()).pipe(stream); +}); + test('empty input stream', function (t) { t.plan(1);