Skip to content

Commit

Permalink
refactor: add JSDoc to improve config.devServer type (#8213)
Browse files Browse the repository at this point in the history
* refactor: add types to improve config.dev-server type

* refactor: add JSDoc for config.dev-server
  • Loading branch information
GiveMe-A-Name authored Oct 25, 2024
1 parent 562662e commit c9c69fc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
15 changes: 8 additions & 7 deletions packages/rspack/etc/core.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,7 @@ class Dependency {
// @public (undocumented)
type DependencyLocation = any;

// @public (undocumented)
// @public
export interface DevServer extends webpackDevServer.Configuration {
}

Expand Down Expand Up @@ -4528,7 +4528,6 @@ declare namespace rspackExports {
OptimizationRuntimeChunkNormalized,
RspackOptionsNormalized,
externalsType,
DevServer,
IgnoreWarnings,
Profile,
Bail,
Expand Down Expand Up @@ -4688,7 +4687,8 @@ declare namespace rspackExports {
Incremental,
Experiments,
Watch,
WatchOptions
WatchOptions,
DevServer
}
}

Expand Down Expand Up @@ -6526,7 +6526,7 @@ export const rspackOptions: z.ZodObject<{
resolve: z.ZodOptional<z.ZodType<t.ResolveOptions, z.ZodTypeDef, t.ResolveOptions>>;
resolveLoader: z.ZodOptional<z.ZodType<t.ResolveOptions, z.ZodTypeDef, t.ResolveOptions>>;
plugins: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodType<t.RspackPluginInstance | t.WebpackPluginInstance | t.RspackPluginFunction | t.WebpackPluginFunction, z.ZodTypeDef, t.RspackPluginInstance | t.WebpackPluginInstance | t.RspackPluginFunction | t.WebpackPluginFunction>, z.ZodUnion<[z.ZodLiteral<false>, z.ZodLiteral<0>, z.ZodLiteral<"">, z.ZodNull, z.ZodUndefined]>]>, "many">>;
devServer: z.ZodOptional<z.ZodType<DevServer, z.ZodTypeDef, DevServer>>;
devServer: z.ZodOptional<z.ZodType<t.DevServer, z.ZodTypeDef, t.DevServer>>;
module: z.ZodOptional<z.ZodObject<{
defaultRules: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodUnion<[z.ZodLiteral<"...">, z.ZodType<t.RuleSetRule, z.ZodTypeDef, t.RuleSetRule>]>, z.ZodUnion<[z.ZodLiteral<false>, z.ZodLiteral<0>, z.ZodLiteral<"">, z.ZodNull, z.ZodUndefined]>]>, "many">>;
rules: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodUnion<[z.ZodLiteral<"...">, z.ZodType<t.RuleSetRule, z.ZodTypeDef, t.RuleSetRule>]>, z.ZodUnion<[z.ZodLiteral<false>, z.ZodLiteral<0>, z.ZodLiteral<"">, z.ZodNull, z.ZodUndefined]>]>, "many">>;
Expand Down Expand Up @@ -8124,7 +8124,7 @@ export const rspackOptions: z.ZodObject<{
} | undefined;
resolveLoader?: t.ResolveOptions | undefined;
plugins?: (false | "" | 0 | t.RspackPluginInstance | t.WebpackPluginInstance | t.RspackPluginFunction | t.WebpackPluginFunction | null | undefined)[] | undefined;
devServer?: DevServer | undefined;
devServer?: t.DevServer | undefined;
bail?: boolean | undefined;
}, {
context?: string | undefined;
Expand Down Expand Up @@ -8723,7 +8723,7 @@ export const rspackOptions: z.ZodObject<{
} | undefined;
resolveLoader?: t.ResolveOptions | undefined;
plugins?: (false | "" | 0 | t.RspackPluginInstance | t.WebpackPluginInstance | t.RspackPluginFunction | t.WebpackPluginFunction | null | undefined)[] | undefined;
devServer?: DevServer | undefined;
devServer?: t.DevServer | undefined;
bail?: boolean | undefined;
}>;

Expand Down Expand Up @@ -9773,7 +9773,8 @@ declare namespace t {
Incremental,
Experiments,
Watch,
WatchOptions
WatchOptions,
DevServer
}
}

Expand Down
8 changes: 8 additions & 0 deletions packages/rspack/src/config/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { JsAssetInfo, RawFuncUseCtx } from "@rspack/binding";
import type * as webpackDevServer from "webpack-dev-server";
import type { PathData } from "../Compilation";
import type { Compiler } from "../Compiler";
import type { Module } from "../Module";
Expand Down Expand Up @@ -2491,3 +2492,10 @@ export type WatchOptions = {
stdin?: boolean;
};
//#endregion

//#region DevServer
/**
* Options for devServer, it based on `webpack-dev-server@5`
* */
export interface DevServer extends webpackDevServer.Configuration {}
//#endregion
4 changes: 1 addition & 3 deletions packages/rspack/src/config/zod.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import nodePath from "node:path";
import type { JsAssetInfo, RawFuncUseCtx } from "@rspack/binding";
import type * as webpackDevServer from "webpack-dev-server";
import { z } from "zod";
import { Chunk } from "../Chunk";
import type { Compilation, PathData } from "../Compilation";
Expand Down Expand Up @@ -1277,8 +1276,7 @@ const watchOptions = z.strictObject({
//#endregion

//#region DevServer
export interface DevServer extends webpackDevServer.Configuration {}
const devServer = z.custom<DevServer>();
const devServer = z.custom<t.DevServer>();
//#endregion

//#region IgnoreWarnings
Expand Down

2 comments on commit c9c69fc

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Benchmark detail: Open

Name Base (2024-10-25 562662e) Current Change
10000_development-mode + exec 2.11 s ± 25 ms 2.12 s ± 25 ms +0.36 %
10000_development-mode_hmr + exec 674 ms ± 13 ms 669 ms ± 20 ms -0.69 %
10000_production-mode + exec 2.7 s ± 38 ms 2.7 s ± 51 ms -0.26 %
arco-pro_development-mode + exec 1.77 s ± 92 ms 1.8 s ± 51 ms +1.54 %
arco-pro_development-mode_hmr + exec 426 ms ± 1.4 ms 426 ms ± 3.5 ms 0.00 %
arco-pro_production-mode + exec 3.19 s ± 61 ms 3.23 s ± 73 ms +1.07 %
arco-pro_production-mode_generate-package-json-webpack-plugin + exec 3.26 s ± 74 ms 3.28 s ± 77 ms +0.84 %
threejs_development-mode_10x + exec 1.61 s ± 18 ms 1.61 s ± 17 ms +0.18 %
threejs_development-mode_10x_hmr + exec 761 ms ± 8.2 ms 758 ms ± 14 ms -0.31 %
threejs_production-mode_10x + exec 5.01 s ± 23 ms 5.03 s ± 35 ms +0.40 %

@rspack-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Ran ecosystem CI: Open

suite result
modernjs ✅ success
_selftest ✅ success
rspress ✅ success
rslib ✅ success
rsbuild ✅ success
examples ✅ success
devserver ✅ success

Please sign in to comment.