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: handle undefined configuration export #2930

Merged
merged 9 commits into from
Sep 7, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/webpack-cli/lib/webpack-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,15 @@ class WebpackCLI {
}

// For babel/typescript
if (result.default) {
if (result && result.default) {
result = result.default;
}

// Treat undefined configuration for zero-config
if (!result) {
result = {};
}

return result;
rishabh3112 marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
16 changes: 16 additions & 0 deletions test/build/config/no-code/no-code.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use strict";
const { resolve } = require("path");
const { run } = require("../../../utils/test-utils");

describe("config flag with no code", () => {
it("should throw error with no configuration or index file", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
rishabh3112 marked this conversation as resolved.
Show resolved Hide resolved
resolve(__dirname, "webpack.config.js"),
]);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});
});
1 change: 1 addition & 0 deletions test/build/config/no-code/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Peeves");
Empty file.
1 change: 1 addition & 0 deletions test/build/config/undefined/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log("Percy Weasley")
rishabh3112 marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 16 additions & 0 deletions test/build/config/undefined/undefined.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use strict";
const { resolve } = require("path");
const { run } = require("../../../utils/test-utils");

describe("config flag with undefined export config file", () => {
it("should throw error with no configuration or index file", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, [
"-c",
rishabh3112 marked this conversation as resolved.
Show resolved Hide resolved
resolve(__dirname, "webpack.config.js"),
]);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
});
});
1 change: 1 addition & 0 deletions test/build/config/undefined/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = undefined;
rishabh3112 marked this conversation as resolved.
Show resolved Hide resolved