Skip to content

Commit 00fae2f

Browse files
committed
refactor: allow aliases
1 parent 9d1f8c1 commit 00fae2f

File tree

4 files changed

+389
-386
lines changed

4 files changed

+389
-386
lines changed

packages/webpack-cli/src/webpack-cli.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,11 @@ class WebpackCLI implements IWebpackCLI {
472472
makeOption(command: WebpackCLICommand, option: WebpackCLIBuiltInOption) {
473473
let mainOption: WebpackCLIMainOption;
474474
let negativeOption;
475+
const flagsWithAlias = ["devtool", "output-path", "target", "watch"];
476+
477+
if (flagsWithAlias.includes(option.name)) {
478+
option.alias = option.name[0];
479+
}
475480

476481
if (option.configs) {
477482
let needNegativeOption = false;

test/build/core-flags/core-flags.test.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,15 @@ describe("core flags", () => {
239239
expect(stdout).toContain(`devtool: 'source-map'`);
240240
});
241241

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

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

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

test/build/target/flag-test/target-flag.test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ describe("--target flag", () => {
2222
expect(stdout).toContain(`target: [ '${val}' ]`);
2323
});
2424

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

2928
expect(exitCode).toBe(0);

0 commit comments

Comments
 (0)