Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(webpack-cli): to void defaultEntry override the webpack config entry #1289

Merged
merged 7 commits into from
Mar 10, 2020
12 changes: 11 additions & 1 deletion packages/webpack-cli/lib/groups/BasicGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BasicGroup extends GroupHelper {
}
return result;
}, []);
this._excuted = false;
Mistyyyy marked this conversation as resolved.
Show resolved Hide resolved
}
resolveFlags() {
const { args } = this;
Expand All @@ -33,12 +34,21 @@ class BasicGroup extends GroupHelper {
outputOptions.devtool = args[arg];
}
if (arg === 'entry') {
options[arg] = this.resolveFilePath(args[arg], 'index.js');
// first excute, get the default entry to void defaultEntry override config entry
if (this._excuted === false) {
if (args[arg] === null)
options[arg] = this.resolveFilePath(args[arg], 'index.js');
} else if (this._excuted === true) {
options[arg] = undefined;
if (args[arg] !== null)
options[arg] = this.resolveFilePath(args[arg], 'index.js');
}
}
});
if (outputOptions['dev']) {
outputOptions['prod'] = undefined;
}
this._excuted = true;
}

run() {
Expand Down
1 change: 1 addition & 0 deletions packages/webpack-cli/lib/webpack-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ class WebpackCLI extends GroupHelper {
async runOptionGroups() {
await Promise.resolve()
.then(() => this._handleGroupHelper(this.zeroConfigGroup))
.then(() => this._handleGroupHelper(this.basicGroup))
Mistyyyy marked this conversation as resolved.
Show resolved Hide resolved
.then(() => this._handleGroupHelper(this.configGroup))
.then(() => this._handleGroupHelper(this.outputGroup))
.then(() => this._handleGroupHelper(this.basicGroup))
Expand Down
11 changes: 11 additions & 0 deletions test/entry/config-entry/1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const { resolve } = require('path');

module.exports = {
entry: {
index: '../a.js',
},
output: {
path: resolve(process.cwd(), 'binary'),
filename: '[name].bundle.js',
},
};
Empty file added test/entry/config-entry/a.js
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
const { stat } = require('fs');
const { resolve } = require('path');
const { run, extractSummary } = require('../../../utils/test-utils');

describe('single entry with entry in config', () => {
it('should use config entry if config entry existed', done => {
const { stdout, stderr } = run(__dirname, ['-c', '../1.js'], false);
const summary = extractSummary(stdout);
const outputDir = 'entry-with-config/binary';
// eslint-disable-next-line quotes
Mistyyyy marked this conversation as resolved.
Show resolved Hide resolved
expect(summary['Output Directory']).toContain(outputDir);

// eslint-disable-next-line quotes
console.log(stderr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

expect(stdout).toContain('./a.js');
stat(resolve(__dirname, './binary/index.bundle.js'), (err, stats) => {
expect(err).toBeFalsy();
expect(stats.isFile()).toBe(true);
done();
});
});
});
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';
const { stat } = require('fs');
const { resolve } = require('path');
const { run, extractSummary } = require('../../../utils/test-utils');

describe('single entry with entry in config', () => {
it('should use config entry if config entry existed', done => {
const { stdout } = run(__dirname, ['-c', '../1.js', '../index.js'], false);
const summary = extractSummary(stdout);
const outputDir = 'entry-without-config/binary';
// eslint-disable-next-line quotes
expect(summary['Output Directory']).toContain(outputDir);

// eslint-disable-next-line quotes
expect(stdout).toContain('./index.js');
stat(resolve(__dirname, './binary/main.bundle.js'), (err, stats) => {
expect(err).toBeFalsy();
expect(stats.isFile()).toBe(true);
done();
});
});
});
Empty file.