Skip to content

Commit

Permalink
refactor: allow aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
snitin315 committed Jul 27, 2022
1 parent 9d1f8c1 commit 00fae2f
Show file tree
Hide file tree
Showing 4 changed files with 389 additions and 386 deletions.
5 changes: 5 additions & 0 deletions packages/webpack-cli/src/webpack-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,11 @@ class WebpackCLI implements IWebpackCLI {
makeOption(command: WebpackCLICommand, option: WebpackCLIBuiltInOption) {
let mainOption: WebpackCLIMainOption;
let negativeOption;
const flagsWithAlias = ["devtool", "output-path", "target", "watch"];

if (flagsWithAlias.includes(option.name)) {
option.alias = option.name[0];
}

if (option.configs) {
let needNegativeOption = false;
Expand Down
6 changes: 2 additions & 4 deletions test/build/core-flags/core-flags.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,17 +239,15 @@ describe("core flags", () => {
expect(stdout).toContain(`devtool: 'source-map'`);
});

// TODO: Enable alias with webpack 5
it.skip("should allow string value devtool option using alias", async () => {
it("should allow string value devtool option using alias", async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ["-d", "source-map"]);

expect(exitCode).toBe(0);
expect(stderr).toBeFalsy();
expect(stdout).toContain(`devtool: 'source-map'`);
});

// TODO: Enable alias with webpack 5
it.skip("should allow string value devtool option using alias #1", async () => {
it("should allow string value devtool option using alias #1", async () => {
// cSpell:ignore dsource
const { exitCode, stderr, stdout } = await run(__dirname, ["-dsource-map"]);

Expand Down
3 changes: 1 addition & 2 deletions test/build/target/flag-test/target-flag.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ describe("--target flag", () => {
expect(stdout).toContain(`target: [ '${val}' ]`);
});

// TODO: Enable aliases with webpack 5
it.skip(`should accept ${val} with -t alias`, async () => {
it(`should accept ${val} with -t alias`, async () => {
const { exitCode, stderr, stdout } = await run(__dirname, ["-t", `${val}`]);

expect(exitCode).toBe(0);
Expand Down
Loading

0 comments on commit 00fae2f

Please sign in to comment.