From 99740e0a28e1d84a8c530f0a37bd8194919cf6e1 Mon Sep 17 00:00:00 2001 From: alexander-akait Date: Tue, 8 Apr 2025 02:50:12 +0300 Subject: [PATCH] chore: fix types --- package.json | 2 +- packages/serve/src/index.ts | 18 ++++++++++-------- packages/webpack-cli/src/types.ts | 20 +++++++++++++------- packages/webpack-cli/src/webpack-cli.ts | 4 ++-- yarn.lock | 8 ++++---- 5 files changed, 30 insertions(+), 22 deletions(-) diff --git a/package.json b/package.json index 19fe0dab938..55de0cd74a9 100644 --- a/package.json +++ b/package.json @@ -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" } diff --git a/packages/serve/src/index.ts b/packages/serve/src/index.ts index 948be8ab400..b6514364ec7 100644 --- a/packages/serve/src/index.ts +++ b/packages/serve/src/index.ts @@ -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>[0]; +type StringsKeys = { [K in keyof T]: T[K] extends string ? K : never }[keyof T]; class ServeCommand { async apply(cli: IWebpackCLI): Promise { @@ -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 = >( + 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]; diff --git a/packages/webpack-cli/src/types.ts b/packages/webpack-cli/src/types.ts index e5008bea2d8..8b7a17f8778 100644 --- a/packages/webpack-cli/src/types.ts +++ b/packages/webpack-cli/src/types.ts @@ -133,7 +133,7 @@ interface WebpackCLIBuiltInFlag { value: string, previous: Record, ) => Record; - configs?: Partial[]; + configs?: ArgumentConfig[]; negative?: boolean; multiple?: boolean; valueName?: string; @@ -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 & { @@ -324,7 +329,8 @@ export { LoadableWebpackConfiguration, DynamicImport, FileSystemCacheOptions, - FlagConfig, + ArgumentConfig, + EnumValue, ImportLoaderError, Instantiable, JsonExt, diff --git a/packages/webpack-cli/src/webpack-cli.ts b/packages/webpack-cli/src/webpack-cli.ts index b8ce02c8c6e..fef86cd1ef0 100644 --- a/packages/webpack-cli/src/webpack-cli.ts +++ b/packages/webpack-cli/src/webpack-cli.ts @@ -24,7 +24,7 @@ import type { LoadableWebpackConfiguration, DynamicImport, FileSystemCacheOptions, - FlagConfig, + EnumValue, ImportLoaderError, Instantiable, JsonExt, @@ -1646,7 +1646,7 @@ class WebpackCLI implements IWebpackCLI { return accumulator; } }, - [], + [], ); if (possibleValues.length > 0) { diff --git a/yarn.lock b/yarn.lock index 6586a366e98..ad2f591a320 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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"