Skip to content

Commit 20bc478

Browse files
authored
refactor: code
1 parent 529352d commit 20bc478

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,21 @@ class WebpackCLI {
12941294
process.exit(0);
12951295
}
12961296

1297+
async #renderVersion(options: { output?: string } = {}): Promise<string> {
1298+
let info = await this.#getInfoOutput({
1299+
...options,
1300+
information: {
1301+
npmPackages: `{${DEFAULT_WEBPACK_PACKAGES.map((item) => `*${item}*`).join(",")}}`,
1302+
},
1303+
});
1304+
1305+
if (typeof options.output === "undefined") {
1306+
info = info.replace("Packages:", "").replaceAll(/^\s+/gm, "").trim();
1307+
}
1308+
1309+
return info;
1310+
}
1311+
12971312
async #getInfoOutput(options: {
12981313
output?: string;
12991314
additionalPackage?: string[];
@@ -1781,16 +1796,7 @@ class WebpackCLI {
17811796
},
17821797
],
17831798
action: async (options: { output?: string }) => {
1784-
let info = await this.#getInfoOutput({
1785-
...options,
1786-
information: {
1787-
npmPackages: `{${DEFAULT_WEBPACK_PACKAGES.map((item) => `*${item}*`).join(",")}}`,
1788-
},
1789-
});
1790-
1791-
if (typeof options.output === "undefined") {
1792-
info = info.replace("Packages:", "").replaceAll(/^\s+/gm, "").trim();
1793-
}
1799+
const info = await this.#renderVersion(options);
17941800

17951801
this.logger.raw(info);
17961802
},
@@ -2115,16 +2121,8 @@ class WebpackCLI {
21152121
const isVersionOption = typeof options.version !== "undefined";
21162122

21172123
if (isVersionOption) {
2118-
const info = (
2119-
await this.#getInfoOutput({
2120-
information: {
2121-
npmPackages: `{${DEFAULT_WEBPACK_PACKAGES.map((item) => `*${item}*`).join(",")}}`,
2122-
},
2123-
})
2124-
)
2125-
.replace("Packages:", "")
2126-
.replaceAll(/^\s+/gm, "")
2127-
.trim();
2124+
const info = await this.#renderVersion();
2125+
21282126
this.logger.raw(info);
21292127
process.exit(0);
21302128
}

0 commit comments

Comments
 (0)