Skip to content

Commit 5da1f81

Browse files
authored
fix: defer setting default entry to core (#1856)
* fix: defer setting default entry to core
1 parent 2f36b9d commit 5da1f81

File tree

21 files changed

+22
-30
lines changed

21 files changed

+22
-30
lines changed

packages/webpack-cli/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ yarn add webpack-cli --dev
4646
--env string Environment passed to the configuration when it is a function
4747
--name string Name of the configuration. Used when loading multiple configurations
4848
--help Outputs list of supported flags
49-
-o, --output string Output location of the file generated by webpack
49+
-o, --output-path string Output location of the generated bundle
5050
-t, --target string Sets the build target
5151
-w, --watch Watch for files changes
5252
-h, --hot Enables Hot Module Replacement

packages/webpack-cli/lib/webpack-cli.js

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
const path = require('path');
2-
const { existsSync } = require('fs');
3-
const { options } = require('colorette');
41
const webpackMerge = require('webpack-merge');
2+
const { options } = require('colorette');
53
const GroupHelper = require('./utils/GroupHelper');
4+
const { Compiler } = require('./utils/Compiler');
5+
const { groups, core } = require('./utils/cli-flags');
6+
const argParser = require('./utils/arg-parser');
7+
const { outputStrategy } = require('./utils/merge-strategies');
8+
const { toKebabCase } = require('./utils/helpers');
9+
10+
// CLI arg resolvers
611
const handleConfigResolution = require('./groups/ConfigGroup');
712
const resolveMode = require('./groups/resolveMode');
813
const resolveStats = require('./groups/resolveStats');
914
const resolveOutput = require('./groups/resolveOutput');
10-
const { Compiler } = require('./utils/Compiler');
11-
const { groups, core } = require('./utils/cli-flags');
1215
const basicResolver = require('./groups/basicResolver');
13-
const { toKebabCase } = require('./utils/helpers');
14-
const argParser = require('./utils/arg-parser');
15-
const { outputStrategy } = require('./utils/merge-strategies');
1616

1717
class WebpackCLI extends GroupHelper {
1818
constructor() {
@@ -186,23 +186,6 @@ class WebpackCLI extends GroupHelper {
186186
}
187187
}
188188

189-
/**
190-
* Get the defaultEntry for merge with config rightly
191-
* @private
192-
* @returns {void}
193-
*/
194-
_handleDefaultEntry() {
195-
let defaultEntry;
196-
const rootIndexPath = path.resolve('index.js');
197-
if (existsSync(rootIndexPath)) {
198-
defaultEntry = './index.js';
199-
} else {
200-
defaultEntry = './src/index.js';
201-
}
202-
const options = { entry: defaultEntry };
203-
this._mergeOptionsToConfiguration(options);
204-
}
205-
206189
/**
207190
* It runs in a fancy order all the expected groups.
208191
* Zero config and configuration goes first.
@@ -212,7 +195,6 @@ class WebpackCLI extends GroupHelper {
212195
*/
213196
async runOptionGroups(parsedArgs) {
214197
await Promise.resolve()
215-
.then(() => this._handleDefaultEntry())
216198
.then(() => this._baseResolver(handleConfigResolution, parsedArgs))
217199
.then(() => this._baseResolver(resolveMode, parsedArgs))
218200
.then(() => this._baseResolver(resolveOutput, parsedArgs, outputStrategy))

test/config/defaults/basic-config/default-js-config.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('Zero Config', () => {
66
it('runs when config is present but not supplied via flag', () => {
77
const { stdout, stderr, exitCode } = run(__dirname, [], false);
88
// default entry should be used
9-
expect(stdout).toContain('./index.js');
9+
expect(stdout).toContain('./src/index.js');
1010
// should pick up the output path from config
1111
expect(stdout).toContain('test-output');
1212
if (!isWebpack5) {

test/config/defaults/cjs-config/default-cjs-config.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('Default Config:', () => {
66
it('Should be able to pick cjs config by default', () => {
77
const { stdout, stderr, exitCode } = run(__dirname, [], false);
88
// default entry should be used
9-
expect(stdout).toContain('./index.js');
9+
expect(stdout).toContain('./src/index.js');
1010
// should pick up the output path from config
1111
expect(stdout).toContain('test-output');
1212
if (!isWebpack5) {
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)