@rsbuild/core 1.3.19 → 1.3.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,7 +14,7 @@ import type { ModifyWebpackChainUtils, ModifyWebpackConfigUtils, RsbuildPlugins
14
14
  import type { RsbuildEntry, RsbuildMode, RsbuildTarget } from './rsbuild';
15
15
  import type { BundlerPluginInstance, Rspack, RspackRule } from './rspack';
16
16
  import type { CSSExtractOptions, CSSLoaderModulesOptions, CSSLoaderOptions, HtmlRspackPlugin, PostCSSLoaderOptions, PostCSSPlugin, StyleLoaderOptions, WebpackConfig } from './thirdParty';
17
- import type { ConfigChain, ConfigChainAsyncWithContext, ConfigChainMergeContext, ConfigChainWithContext, DeepReadonly, MaybePromise, OneOrMany } from './utils';
17
+ import type { ConfigChain, ConfigChainMergeContext, ConfigChainWithContext, MaybePromise, OneOrMany, TwoLevelReadonly } from './utils';
18
18
  export type ToolsSwcConfig = ConfigChain<SwcLoaderOptions>;
19
19
  export type ToolsBundlerChainConfig = OneOrMany<(chain: RspackChain, utils: ModifyBundlerChainUtils) => MaybePromise<void>>;
20
20
  export type ToolsPostCSSLoaderConfig = ConfigChainWithContext<PostCSSLoaderOptions, {
@@ -26,16 +26,62 @@ export type ToolsHtmlPluginConfig = ConfigChainWithContext<HtmlRspackPlugin.Opti
26
26
  entryName: string;
27
27
  entryValue: (string | string[] | Rspack.EntryDescription)[];
28
28
  }>;
29
- export type WebpackMerge = <Configuration extends object>(firstConfiguration: Configuration | Configuration[], ...configurations: Configuration[]) => Configuration;
29
+ export type RspackMerge = (firstConfiguration: Rspack.Configuration | Rspack.Configuration[], ...configurations: Rspack.Configuration[]) => Rspack.Configuration;
30
30
  export type ModifyRspackConfigUtils = ModifyChainUtils & {
31
31
  addRules: (rules: RspackRule | RspackRule[]) => void;
32
32
  appendRules: (rules: RspackRule | RspackRule[]) => void;
33
33
  prependPlugins: (plugins: BundlerPluginInstance | BundlerPluginInstance[]) => void;
34
34
  appendPlugins: (plugins: BundlerPluginInstance | BundlerPluginInstance[]) => void;
35
35
  removePlugin: (pluginName: string) => void;
36
- mergeConfig: WebpackMerge;
36
+ mergeConfig: RspackMerge;
37
37
  };
38
- export type ToolsRspackConfig = ConfigChainAsyncWithContext<Rspack.Configuration, ModifyRspackConfigUtils>;
38
+ /**
39
+ * Narrow the type of Rspack.Configuration to make it easier
40
+ * to use `tools.rspack` function. These properties are set
41
+ * by Rsbuild by default so they are non-nullable.
42
+ *
43
+ * - With `Rspack.Configuration`, the `plugins` property is nullable:
44
+ *
45
+ * ```js
46
+ * tools: {
47
+ * rspack(config) {
48
+ * if (!config.plugins) {
49
+ * config.plugins = [];
50
+ * }
51
+ * config.plugins.push(new SomePlugin());
52
+ * }
53
+ * }
54
+ * ```
55
+ *
56
+ * - With `NarrowedRspackConfig`, the `plugins` property is non-nullable:
57
+ *
58
+ * ```js
59
+ * tools: {
60
+ * rspack(config) {
61
+ * config.plugins.push(new SomePlugin());
62
+ * }
63
+ * }
64
+ * ```
65
+ */
66
+ export type NarrowedRspackConfig = Omit<Rspack.Configuration, 'plugins' | 'module' | 'resolve' | 'output'> & {
67
+ /**
68
+ * Plugins to use during compilation.
69
+ */
70
+ plugins: NonNullable<Rspack.Configuration['plugins']>;
71
+ /**
72
+ * Options for module configuration.
73
+ */
74
+ module: NonNullable<Rspack.Configuration['module']>;
75
+ /**
76
+ * Options for resolving modules.
77
+ */
78
+ resolve: NonNullable<Rspack.Configuration['resolve']>;
79
+ /**
80
+ * Configuration for the output of the compilation.
81
+ */
82
+ output: NonNullable<Rspack.Configuration['output']>;
83
+ };
84
+ export type ToolsRspackConfig = OneOrMany<Rspack.Configuration | ((config: NarrowedRspackConfig, ctx: ModifyRspackConfigUtils) => MaybePromise<Rspack.Configuration | void>)>;
39
85
  export type ToolsWebpackConfig = ConfigChainWithContext<WebpackConfig, ModifyWebpackConfigUtils>;
40
86
  export type ToolsWebpackChainConfig = OneOrMany<(chain: RspackChain, utils: ModifyWebpackChainUtils) => void>;
41
87
  export interface ToolsConfig {
@@ -1327,7 +1373,8 @@ export interface DevConfig {
1327
1373
  */
1328
1374
  lazyCompilation?: boolean | Rspack.LazyCompilationOptions;
1329
1375
  }
1330
- export type NormalizedDevConfig = DevConfig & Required<Pick<DevConfig, 'hmr' | 'liveReload' | 'assetPrefix' | 'writeToDisk' | 'cliShortcuts'>> & {
1376
+ export type NormalizedDevConfig = Omit<DevConfig, 'watchFiles'> & Required<Pick<DevConfig, 'hmr' | 'liveReload' | 'assetPrefix' | 'writeToDisk' | 'cliShortcuts'>> & {
1377
+ watchFiles: WatchFiles[];
1331
1378
  client: NormalizedClientConfig;
1332
1379
  };
1333
1380
  export interface ResolveConfig {
@@ -1474,7 +1521,7 @@ export type MergedEnvironmentConfig = {
1474
1521
  /**
1475
1522
  * The normalized Rsbuild environment config.
1476
1523
  */
1477
- export type NormalizedEnvironmentConfig = DeepReadonly<Omit<MergedEnvironmentConfig, 'dev'> & {
1524
+ export type NormalizedEnvironmentConfig = TwoLevelReadonly<Omit<MergedEnvironmentConfig, 'dev'> & {
1478
1525
  dev: NormalizedDevConfig;
1479
1526
  server: NormalizedServerConfig;
1480
1527
  _privateMeta?: RsbuildConfigMeta;
@@ -13,10 +13,29 @@ export type RsbuildContext = {
13
13
  distPath: string;
14
14
  /** Absolute path of cache files. */
15
15
  cachePath: string;
16
- /** Info of dev server */
16
+ /**
17
+ * Dev server information when running in dev mode.
18
+ * Available after the dev server has been created.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { createRsbuild } from '@rsbuild/core';
23
+ *
24
+ * async function main() {
25
+ * const rsbuild = createRsbuild({
26
+ * // ...
27
+ * });
28
+ * await rsbuild.startDevServer();
29
+ * console.log(rsbuild.context.devServer); // { hostname: 'localhost', port: 3000, https: false }
30
+ * }
31
+ * ```
32
+ */
17
33
  devServer?: {
34
+ /** The hostname the server is running on. */
18
35
  hostname: string;
36
+ /** The port number the server is listening on. */
19
37
  port: number;
38
+ /** Whether the server is using HTTPS protocol. */
20
39
  https: boolean;
21
40
  };
22
41
  /**
@@ -2,7 +2,7 @@
2
2
  import type { RuleSetRule, Configuration as WebpackConfig, WebpackPluginInstance } from 'webpack';
3
3
  import type RspackChain from '../../compiled/rspack-chain';
4
4
  import type { ChainIdentifier } from '../configChain';
5
- import type { ModifyRspackConfigUtils, NormalizedConfig, NormalizedEnvironmentConfig, RsbuildConfig, WebpackMerge } from './config';
5
+ import type { ModifyRspackConfigUtils, NarrowedRspackConfig, NormalizedConfig, NormalizedEnvironmentConfig, RsbuildConfig, RspackMerge } from './config';
6
6
  import type { RsbuildContext } from './context';
7
7
  import type { EnvironmentContext, ModifyBundlerChainFn, ModifyChainUtils, ModifyEnvironmentConfigFn, ModifyHTMLFn, ModifyHTMLTagsFn, ModifyRsbuildConfigFn, OnAfterBuildFn, OnAfterCreateCompilerFn, OnAfterEnvironmentCompileFn, OnAfterStartDevServerFn, OnAfterStartProdServerFn, OnBeforeBuildFn, OnBeforeCreateCompilerFn, OnBeforeEnvironmentCompileFn, OnBeforeStartDevServerFn, OnBeforeStartProdServerFn, OnCloseBuildFn, OnCloseDevServerFn, OnDevCompileDoneFn, OnExitFn } from './hooks';
8
8
  import type { RsbuildInstance, RsbuildTarget } from './rsbuild';
@@ -92,7 +92,7 @@ export type AsyncHook<Callback extends (...args: any[]) => T, T = any> = {
92
92
  */
93
93
  callBatch: (...args: Parameters<Callback>) => Promise<Awaited<ReturnType<Callback>>[]>;
94
94
  };
95
- export type ModifyRspackConfigFn = (config: Rspack.Configuration, utils: ModifyRspackConfigUtils) => MaybePromise<Rspack.Configuration | void>;
95
+ export type ModifyRspackConfigFn = (config: NarrowedRspackConfig, utils: ModifyRspackConfigUtils) => MaybePromise<Rspack.Configuration | void>;
96
96
  export type ModifyWebpackChainUtils = ModifyChainUtils & {
97
97
  /** @ts-ignore `webpack` type only exists when `@rsbuild/webpack` is installed */
98
98
  webpack: typeof import('webpack');
@@ -112,7 +112,7 @@ export type ModifyWebpackConfigUtils = ModifyWebpackChainUtils & {
112
112
  prependPlugins: (plugins: WebpackPluginInstance | WebpackPluginInstance[]) => void;
113
113
  appendPlugins: (plugins: WebpackPluginInstance | WebpackPluginInstance[]) => void;
114
114
  removePlugin: (pluginName: string) => void;
115
- mergeConfig: WebpackMerge;
115
+ mergeConfig: RspackMerge;
116
116
  };
117
117
  export type ModifyWebpackChainFn = (chain: RspackChain, utils: ModifyWebpackChainUtils) => Promise<void> | void;
118
118
  export type ModifyWebpackConfigFn = (config: WebpackConfig, utils: ModifyWebpackConfigUtils) => Promise<WebpackConfig | void> | WebpackConfig | void;
@@ -1,8 +1,13 @@
1
1
  export type Falsy = false | null | undefined;
2
2
  export type OneOrMany<T> = T | T[];
3
3
  export type MaybePromise<T> = T | Promise<T>;
4
- export type DeepReadonly<T> = keyof T extends never ? T : {
5
- readonly [k in keyof T]: DeepReadonly<T[k]>;
4
+ /**
5
+ * Creates a type with readonly properties at the first and second levels only.
6
+ */
7
+ export type TwoLevelReadonly<T> = keyof T extends never ? T : {
8
+ readonly [k in keyof T]: T[k] extends object ? {
9
+ readonly [p in keyof T[k]]: T[k][p];
10
+ } : T[k];
6
11
  };
7
12
  export type ConfigChain<T> = OneOrMany<T | ((config: T) => T | void)>;
8
13
  export type ConfigChainWithContext<T, Ctx> = OneOrMany<T | ((config: T, ctx: Ctx) => T | void)>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "1.3.19",
3
+ "version": "1.3.21",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -46,17 +46,17 @@
46
46
  "types.d.ts"
47
47
  ],
48
48
  "dependencies": {
49
- "@rspack/core": "1.3.9",
49
+ "@rspack/core": "1.3.11",
50
50
  "@rspack/lite-tapable": "~1.0.1",
51
51
  "@swc/helpers": "^0.5.17",
52
52
  "core-js": "~3.42.0",
53
53
  "jiti": "^2.4.2"
54
54
  },
55
55
  "devDependencies": {
56
- "@rslib/core": "0.6.9",
56
+ "@rslib/core": "0.7.1",
57
57
  "@types/connect": "3.4.38",
58
58
  "@types/cors": "^2.8.18",
59
- "@types/node": "^22.15.17",
59
+ "@types/node": "^22.15.19",
60
60
  "@types/on-finished": "2.3.4",
61
61
  "@types/webpack-bundle-analyzer": "4.7.0",
62
62
  "@types/ws": "^8.18.1",
@@ -90,7 +90,7 @@
90
90
  "style-loader": "3.3.4",
91
91
  "tinyglobby": "^0.2.13",
92
92
  "typescript": "^5.8.3",
93
- "webpack": "^5.98.0",
93
+ "webpack": "^5.99.8",
94
94
  "webpack-bundle-analyzer": "^4.10.2",
95
95
  "webpack-merge": "6.0.1",
96
96
  "ws": "^8.18.2"
@@ -1,6 +0,0 @@
1
- import type { InspectConfigOptions, InspectConfigResult, Rspack } from '../types';
2
- import { type InitConfigsOptions } from './initConfigs';
3
- export declare function inspectConfig({ context, pluginManager, rsbuildOptions, bundlerConfigs, inspectOptions, }: InitConfigsOptions & {
4
- inspectOptions?: InspectConfigOptions;
5
- bundlerConfigs?: Rspack.Configuration[];
6
- }): Promise<InspectConfigResult<'rspack'>>;