Skip to content

Commit

Permalink
fix: defer setting default entry to core
Browse files Browse the repository at this point in the history
  • Loading branch information
anshumanv committed Oct 3, 2020
1 parent 6f49e96 commit fdaf30d
Show file tree
Hide file tree
Showing 21 changed files with 11 additions and 29 deletions.
34 changes: 8 additions & 26 deletions packages/webpack-cli/lib/webpack-cli.js
@@ -1,18 +1,18 @@
const path = require('path');
const { existsSync } = require('fs');
const { options } = require('colorette');
const webpackMerge = require('webpack-merge');
const { options } = require('colorette');
const GroupHelper = require('./utils/GroupHelper');
const { Compiler } = require('./utils/Compiler');
const { groups, core } = require('./utils/cli-flags');
const argParser = require('./utils/arg-parser');
const { outputStrategy } = require('./utils/merge-strategies');
const { toKebabCase } = require('./utils/helpers');

// CLI arg resolvers
const handleConfigResolution = require('./groups/ConfigGroup');
const resolveMode = require('./groups/resolveMode');
const resolveStats = require('./groups/resolveStats');
const resolveOutput = require('./groups/resolveOutput');
const { Compiler } = require('./utils/Compiler');
const { groups, core } = require('./utils/cli-flags');
const basicResolver = require('./groups/basicResolver');
const { toKebabCase } = require('./utils/helpers');
const argParser = require('./utils/arg-parser');
const { outputStrategy } = require('./utils/merge-strategies');

class WebpackCLI extends GroupHelper {
constructor() {
Expand Down Expand Up @@ -199,23 +199,6 @@ class WebpackCLI extends GroupHelper {
}
}

/**
* Get the defaultEntry for merge with config rightly
* @private
* @returns {void}
*/
_handleDefaultEntry() {
let defaultEntry;
const rootIndexPath = path.resolve('index.js');
if (existsSync(rootIndexPath)) {
defaultEntry = './index.js';
} else {
defaultEntry = './src/index.js';
}
const options = { entry: defaultEntry };
this._mergeOptionsToConfiguration(options);
}

/**
* It runs in a fancy order all the expected groups.
* Zero config and configuration goes first.
Expand All @@ -225,7 +208,6 @@ class WebpackCLI extends GroupHelper {
*/
async runOptionGroups(parsedArgs) {
await Promise.resolve()
.then(() => this._handleDefaultEntry())
.then(() => this._handleConfig(parsedArgs))
.then(() => this._baseResolver(resolveMode, parsedArgs, this.compilerConfiguration))
.then(() => this._baseResolver(resolveOutput, parsedArgs, {}, outputStrategy))
Expand Down
Expand Up @@ -6,7 +6,7 @@ describe('Zero Config', () => {
it('runs when config is present but not supplied via flag', () => {
const { stdout, stderr, exitCode } = run(__dirname, [], false);
// default entry should be used
expect(stdout).toContain('./index.js');
expect(stdout).toContain('./src/index.js');
// should pick up the output path from config
expect(stdout).toContain('test-output');
if (!isWebpack5) {
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion test/config/defaults/cjs-config/default-cjs-config.test.js
Expand Up @@ -6,7 +6,7 @@ describe('Default Config:', () => {
it('Should be able to pick cjs config by default', () => {
const { stdout, stderr, exitCode } = run(__dirname, [], false);
// default entry should be used
expect(stdout).toContain('./index.js');
expect(stdout).toContain('./src/index.js');
// should pick up the output path from config
expect(stdout).toContain('test-output');
if (!isWebpack5) {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/zero-config/entry-absent/zero-config.test.js
Expand Up @@ -4,7 +4,7 @@ describe('Zero Config tests', () => {
it('runs when config and entry are both absent', () => {
const { stdout, stderr } = run(__dirname, [], false);
// Entry file is absent, should log the Error from the compiler
expect(stdout).toContain("Error: Can't resolve './src/index.js'");
expect(stdout).toContain("Error: Can't resolve './src'");
expect(stderr).toBeFalsy();
});
});

0 comments on commit fdaf30d

Please sign in to comment.