Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"ts-loader": "^9.3.1",
"ts-node": "^10.9.1",
"typescript": "^5.0.4",
"webpack": "^5.94.0",
"webpack": "^5.99.1",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-dev-server": "^5.1.0"
}
Expand Down
18 changes: 10 additions & 8 deletions packages/serve/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const WEBPACK_PACKAGE = process.env.WEBPACK_PACKAGE || "webpack";
const WEBPACK_DEV_SERVER_PACKAGE = process.env.WEBPACK_DEV_SERVER_PACKAGE || "webpack-dev-server";

type Problem = NonNullable<ReturnType<(typeof cli)["processArguments"]>>[0];
type StringsKeys<T> = { [K in keyof T]: T[K] extends string ? K : never }[keyof T];

class ServeCommand {
async apply(cli: IWebpackCLI): Promise<void> {
Expand Down Expand Up @@ -174,22 +175,23 @@ class ServeCommand {
{},
);
const result = { ...(compilerForDevServer.options.devServer || {}) };
const problems = (
cli.webpack.cli && typeof cli.webpack.cli.processArguments === "function"
? cli.webpack.cli
: DevServer.cli
).processArguments(args, result, values);
const problems = cli.webpack.cli.processArguments(args, result, values);

if (problems) {
const groupBy = (xs: Problem[], key: keyof Problem) => {
const groupBy = <K extends keyof Problem & StringsKeys<Problem>>(
xs: Problem[],
key: K,
) => {
return xs.reduce((rv: { [key: string]: Problem[] }, x: Problem) => {
(rv[x[key]] = rv[x[key]] || []).push(x);
const path = x[key];

(rv[path] = rv[path] || []).push(x);

return rv;
}, {});
};

const problemsByPath = groupBy(problems, "path");
const problemsByPath = groupBy<"path">(problems, "path");

for (const path in problemsByPath) {
const problems = problemsByPath[path];
Expand Down
20 changes: 13 additions & 7 deletions packages/webpack-cli/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ interface WebpackCLIBuiltInFlag {
value: string,
previous: Record<string, BasicPrimitive | object>,
) => Record<string, BasicPrimitive | object>;
configs?: Partial<FlagConfig>[];
configs?: ArgumentConfig[];
negative?: boolean;
multiple?: boolean;
valueName?: string;
Expand Down Expand Up @@ -191,12 +191,17 @@ type LoadableWebpackConfiguration = PotentialPromise<
type CallableWebpackConfiguration = (env: Env | undefined, argv: Argv) => WebpackConfiguration;
type WebpackCompiler = Compiler | MultiCompiler;

type FlagType = boolean | "enum" | "string" | "path" | "number" | "boolean" | "RegExp" | "reset";
type EnumValueObject = { [key: string]: EnumValue };
type EnumValueArray = EnumValue[];
type EnumValue = string | number | boolean | EnumValueObject | EnumValueArray | null;

type FlagConfig = {
negatedDescription: string;
type: FlagType;
values: FlagType[];
type ArgumentConfig = {
description?: string;
negatedDescription?: string;
path?: string;
multiple?: boolean;
type: "enum" | "string" | "path" | "number" | "boolean" | "RegExp" | "reset";
values?: EnumValue[];
};

type FileSystemCacheOptions = WebpackConfiguration & {
Expand Down Expand Up @@ -324,7 +329,8 @@ export {
LoadableWebpackConfiguration,
DynamicImport,
FileSystemCacheOptions,
FlagConfig,
ArgumentConfig,
EnumValue,
ImportLoaderError,
Instantiable,
JsonExt,
Expand Down
4 changes: 2 additions & 2 deletions packages/webpack-cli/src/webpack-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type {
LoadableWebpackConfiguration,
DynamicImport,
FileSystemCacheOptions,
FlagConfig,
EnumValue,
ImportLoaderError,
Instantiable,
JsonExt,
Expand Down Expand Up @@ -1646,7 +1646,7 @@ class WebpackCLI implements IWebpackCLI {
return accumulator;
}
},
<FlagConfig["values"]>[],
<EnumValue[]>[],
);

if (possibleValues.length > 0) {
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10241,10 +10241,10 @@ webpack-sources@^3.2.3:
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-3.2.3.tgz#2d4daab8451fd4b240cc27055ff6a0c2ccea0cde"
integrity sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==

webpack@^5.94.0:
version "5.98.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.98.0.tgz#44ae19a8f2ba97537978246072fb89d10d1fbd17"
integrity sha512-UFynvx+gM44Gv9qFgj0acCQK2VE1CtdfwFdimkapco3hlPCJ/zeq73n2yVKimVbtm+TnApIugGhLJnkU6gjYXA==
webpack@^5.99.1:
version "5.99.1"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.99.1.tgz#8847e847678bcc3d1fc93a30741bbd78bccc028c"
integrity sha512-o9gY7ibHPFxLjF6NtvQ6+5CGknsPTRllsL6SEnqR2Zhjk02hiIioJYLS7dvrWaykrRbbmhvDeKp36mKHNbKYiw==
dependencies:
"@types/eslint-scope" "^3.7.7"
"@types/estree" "^1.0.6"
Expand Down
Loading