@rspack/browser 1.5.8 → 1.6.0-beta.0

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.
@@ -222,7 +222,7 @@ export declare class Compilation {
222
222
  * Get a map of all entrypoints.
223
223
  */
224
224
  get entrypoints(): ReadonlyMap<string, Entrypoint>;
225
- get chunkGroups(): ReadonlyArray<ChunkGroup>;
225
+ get chunkGroups(): readonly ChunkGroup[];
226
226
  /**
227
227
  * Get the named chunk groups.
228
228
  *
@@ -261,7 +261,7 @@ export declare class Compilation {
261
261
  /**
262
262
  * Get an array of Asset
263
263
  */
264
- getAssets(): ReadonlyArray<Asset>;
264
+ getAssets(): readonly Asset[];
265
265
  getAsset(name: string): Readonly<Asset> | void;
266
266
  /**
267
267
  * Note: This is not a webpack public API, maybe removed in future.
@@ -19,7 +19,7 @@ export interface MultiCompilerOptions {
19
19
  */
20
20
  parallelism?: number;
21
21
  }
22
- export type MultiRspackOptions = ReadonlyArray<RspackOptions> & MultiCompilerOptions;
22
+ export type MultiRspackOptions = readonly RspackOptions[] & MultiCompilerOptions;
23
23
  export declare class MultiCompiler {
24
24
  #private;
25
25
  compilers: Compiler[];
@@ -12,12 +12,18 @@ interface BrowserRequirePluginOptions {
12
12
  /**
13
13
  * This function defines how to execute CommonJS code.
14
14
  */
15
- execute: (code: string, runtime: CommonJsRuntime) => void;
15
+ execute?: (code: string, runtime: CommonJsRuntime) => void;
16
+ /**
17
+ * This option provides a direct mapping from the module specifier to the module content, similar to the mechanism of a virtual module.
18
+ * If this option is not provided or the mapping result is undefined, it will fallback to resolving from memfs and run `execute`.
19
+ */
20
+ modules?: Record<string, unknown> | ((id: string) => unknown);
16
21
  }
17
22
  /**
18
23
  * This plugin inject browser-compatible `require` function to the `Compiler`.
19
- * 1. It resolves the JavaScript in the memfs with Node.js resolution algorithm rather than in the host filesystem.
20
- * 2. It transform ESM to CommonJS which will be executed with a user-defined `execute` function.
24
+ * 1. This plugin makes it possible to use custom loaders in browser by providing a virtual module mechanism.
25
+ * 2. This plugin resolves the JavaScript in the memfs with Node.js resolution algorithm rather than in the host filesystem.
26
+ * 3. This plugin transform ESM to CommonJS which will be executed with a user-defined `execute` function.
21
27
  */
22
28
  export declare class BrowserRequirePlugin {
23
29
  private options;
@@ -25,7 +31,7 @@ export declare class BrowserRequirePlugin {
25
31
  * This is an unsafe way to execute code in the browser using `new Function`.
26
32
  * It is your responsibility to ensure that your application is not vulnerable to attacks due to this function.
27
33
  */
28
- static unsafeExecute: (code: string, runtime: CommonJsRuntime) => void;
34
+ static unsafeExecute: ((code: string, runtime: CommonJsRuntime) => void) | undefined;
29
35
  constructor(options: BrowserRequirePluginOptions);
30
36
  apply(compiler: Compiler): void;
31
37
  }
@@ -1,6 +1,6 @@
1
1
  export * from "../index";
2
2
  export { BrowserHttpImportEsmPlugin } from "./BrowserHttpImportEsmPlugin";
3
- export { BrowserRequirePlugin } from "./BrowserRequire";
3
+ export { BrowserRequirePlugin } from "./BrowserRequirePlugin";
4
4
  export declare const builtinMemFs: {
5
5
  fs: import("memfs").IFs;
6
6
  volume: import("memfs").Volume;
@@ -12,8 +12,8 @@ type RawPluginImportConfig = {
12
12
  style?: RawStyleConfig;
13
13
  camelToDashComponentName?: boolean;
14
14
  transformToDefaultImport?: boolean;
15
- ignoreEsComponent?: Array<string>;
16
- ignoreStyleComponent?: Array<string>;
15
+ ignoreEsComponent?: string[];
16
+ ignoreStyleComponent?: string[];
17
17
  };
18
18
  type PluginImportConfig = {
19
19
  libraryName: string;
@@ -31,7 +31,7 @@ export type CircularDependencyRspackPluginOptions = {
31
31
  * module "app/design/components/Button.tsx". When the entry is a RegExp,
32
32
  * it is tested against the entire identifier.
33
33
  */
34
- ignoredConnections?: Array<[string | RegExp, string | RegExp]>;
34
+ ignoredConnections?: [string | RegExp, string | RegExp][];
35
35
  /**
36
36
  * Called once for every detected cycle. Providing this handler overrides the
37
37
  * default behavior of adding diagnostics to the compilation.
@@ -12,5 +12,5 @@ type CodeValue = RecursiveArrayOrRecord<CodeValuePrimitive>;
12
12
  type CodeValuePrimitive = null | undefined | RegExp | Function | string | number | boolean | bigint;
13
13
  type RecursiveArrayOrRecord<T> = {
14
14
  [index: string]: RecursiveArrayOrRecord<T>;
15
- } | Array<RecursiveArrayOrRecord<T>> | T;
15
+ } | RecursiveArrayOrRecord<T>[] | T;
16
16
  export {};
@@ -7,8 +7,8 @@ export declare namespace RsdoctorPluginData {
7
7
  export type { JsRsdoctorAsset as RsdoctorAsset, JsRsdoctorChunkGraph as RsdoctorChunkGraph, JsRsdoctorModuleGraph as RsdoctorModuleGraph, JsRsdoctorChunk as RsdoctorChunk, JsRsdoctorModule as RsdoctorModule, JsRsdoctorSideEffect as RsdoctorSideEffect, JsRsdoctorExportInfo as RsdoctorExportInfo, JsRsdoctorVariable as RsdoctorVariable, JsRsdoctorDependency as RsdoctorDependency, JsRsdoctorEntrypoint as RsdoctorEntrypoint, JsRsdoctorStatement as RsdoctorStatement, JsRsdoctorSourceRange as RsdoctorSourceRange, JsRsdoctorSourcePosition as RsdoctorSourcePosition, JsRsdoctorModuleGraphModule as RsdoctorModuleGraphModule, JsRsdoctorModuleIdsPatch as RsdoctorModuleIdsPatch, JsRsdoctorModuleOriginalSource as RsdoctorModuleOriginalSource, JsRsdoctorAssetPatch as RsdoctorAssetPatch, JsRsdoctorChunkAssets as RsdoctorChunkAssets, JsRsdoctorEntrypointAssets as RsdoctorEntrypointAssets, JsRsdoctorChunkModules as RsdoctorChunkModules, JsRsdoctorModuleSourcesPatch as RsdoctorModuleSourcesPatch };
8
8
  }
9
9
  export type RsdoctorPluginOptions = {
10
- moduleGraphFeatures?: boolean | Array<"graph" | "ids" | "sources">;
11
- chunkGraphFeatures?: boolean | Array<"graph" | "assets">;
10
+ moduleGraphFeatures?: boolean | ("graph" | "ids" | "sources")[];
11
+ chunkGraphFeatures?: boolean | ("graph" | "assets")[];
12
12
  sourceMapFeatures?: {
13
13
  module?: boolean;
14
14
  cheap?: boolean;
@@ -18,7 +18,7 @@ declare const HtmlRspackPlugin: typeof HtmlRspackPluginImpl & {
18
18
  */
19
19
  getHooks: (compilation: Compilation) => HtmlRspackPluginHooks;
20
20
  getCompilationHooks: (compilation: Compilation) => HtmlRspackPluginHooks;
21
- createHtmlTagObject: (tagName: string, attributes?: Record<string, string | boolean>, innerHTML?: string | undefined) => JsHtmlPluginTag;
21
+ createHtmlTagObject: (tagName: string, attributes?: Record<string, string | boolean>, innerHTML?: string) => JsHtmlPluginTag;
22
22
  version: number;
23
23
  };
24
24
  export { HtmlRspackPlugin };
@@ -79,10 +79,13 @@ export interface Diagnostic {
79
79
  sourceCode?: string;
80
80
  /**
81
81
  * Location to the source code.
82
- *
83
82
  * If `sourceCode` is not provided, location will be omitted.
84
83
  */
85
84
  location?: DiagnosticLocation;
85
+ /**
86
+ * Optional filename to show.
87
+ * If provided, it becomes the `StatsError.file` value in stats.
88
+ */
86
89
  file?: string;
87
90
  severity: "error" | "warning";
88
91
  }
@@ -28,10 +28,10 @@ type ResponseData = {
28
28
  byteLength: number;
29
29
  };
30
30
  type ModifyResponseData<RequestInternal extends IncomingMessage = IncomingMessage, ResponseInternal extends ServerResponse = ServerResponse> = (req: RequestInternal, res: ResponseInternal, data: Buffer | ReadStream, byteLength: number) => ResponseData;
31
- type Headers = Array<{
31
+ type Headers = {
32
32
  key: string;
33
33
  value: string;
34
- }> | Record<string, string | string[]>;
34
+ }[] | Record<string, string | string[]>;
35
35
  type OutputFileSystem = import("..").OutputFileSystem & {
36
36
  createReadStream?: typeof import("fs").createReadStream;
37
37
  statSync: import("fs").StatSyncFn;
@@ -131,8 +131,8 @@ type ProxyConfigArrayItem = {
131
131
  [key: string]: any;
132
132
  };
133
133
  type ByPass = (req: Request, res: Response, proxyConfig: ProxyConfigArrayItem) => any;
134
- type ProxyConfigArray = (ProxyConfigArrayItem | ((req?: Request | undefined, res?: Response | undefined, next?: NextFunction | undefined) => ProxyConfigArrayItem))[];
135
- type Callback = (stats?: Stats | MultiStats | undefined) => any;
134
+ type ProxyConfigArray = (ProxyConfigArrayItem | ((req?: Request, res?: Response, next?: NextFunction) => ProxyConfigArrayItem))[];
135
+ type Callback = (stats?: Stats | MultiStats) => any;
136
136
  type DevMiddlewareContext<_RequestInternal extends IncomingMessage = IncomingMessage, _ResponseInternal extends ServerResponse = ServerResponse> = {
137
137
  state: boolean;
138
138
  stats: Stats | MultiStats | undefined;
@@ -84,9 +84,9 @@ export type ExperimentCacheNormalized = boolean | {
84
84
  buildDependencies: string[];
85
85
  version: string;
86
86
  snapshot: {
87
- immutablePaths: Array<string | RegExp>;
88
- unmanagedPaths: Array<string | RegExp>;
89
- managedPaths: Array<string | RegExp>;
87
+ immutablePaths: (string | RegExp)[];
88
+ unmanagedPaths: (string | RegExp)[];
89
+ managedPaths: (string | RegExp)[];
90
90
  };
91
91
  storage: {
92
92
  type: "filesystem";
@@ -105,6 +105,9 @@ export interface ExperimentsNormalized {
105
105
  outputModule?: boolean;
106
106
  topLevelAwait?: boolean;
107
107
  css?: boolean;
108
+ /**
109
+ * @deprecated This option is deprecated, layers is enabled since v1.6.0
110
+ */
108
111
  layers?: boolean;
109
112
  incremental?: false | Incremental;
110
113
  parallelCodeSplitting?: boolean;
@@ -664,6 +664,8 @@ export type RuleSetRule = {
664
664
  oneOf?: (RuleSetRule | Falsy)[];
665
665
  /** A kind of Nested Rule, an array of Rules that is also used when the parent Rule matches. */
666
666
  rules?: (RuleSetRule | Falsy)[];
667
+ /** Whether to extract source maps from the module. */
668
+ extractSourceMap?: boolean;
667
669
  };
668
670
  /** A list of rules. */
669
671
  export type RuleSetRules = ("..." | RuleSetRule | Falsy)[];
@@ -1194,6 +1196,32 @@ export type CacheOptions = boolean;
1194
1196
  type StatsPresets = "normal" | "none" | "verbose" | "errors-only" | "errors-warnings" | "minimal" | "detailed" | "summary";
1195
1197
  type ModuleFilterItemTypes = RegExp | string | ((name: string, module: any, type: any) => boolean);
1196
1198
  type ModuleFilterTypes = boolean | ModuleFilterItemTypes | ModuleFilterItemTypes[];
1199
+ export type StatsColorOptions = {
1200
+ /**
1201
+ * Custom color for bold text.
1202
+ */
1203
+ bold?: string;
1204
+ /**
1205
+ * Custom color for cyan text.
1206
+ */
1207
+ cyan?: string;
1208
+ /**
1209
+ * Custom color for green text.
1210
+ */
1211
+ green?: string;
1212
+ /**
1213
+ * Custom color for magenta text.
1214
+ */
1215
+ magenta?: string;
1216
+ /**
1217
+ * Custom color for red text.
1218
+ */
1219
+ red?: string;
1220
+ /**
1221
+ * Custom color for yellow text.
1222
+ */
1223
+ yellow?: string;
1224
+ };
1197
1225
  /** Options for stats */
1198
1226
  export type StatsOptions = {
1199
1227
  /**
@@ -1253,7 +1281,7 @@ export type StatsOptions = {
1253
1281
  * Enables or disables the use of colors in the output.
1254
1282
  * @default false
1255
1283
  */
1256
- colors?: boolean;
1284
+ colors?: boolean | StatsColorOptions;
1257
1285
  /**
1258
1286
  * Enables or disables the display of the hash.
1259
1287
  * @default true
@@ -1724,7 +1752,7 @@ export type Optimization = {
1724
1752
  * Customize the minimizer.
1725
1753
  * By default, `rspack.SwcJsMinimizerRspackPlugin` and `rspack.LightningCssMinimizerRspackPlugin` are used.
1726
1754
  */
1727
- minimizer?: Array<"..." | Plugin>;
1755
+ minimizer?: ("..." | Plugin)[];
1728
1756
  /**
1729
1757
  * Whether to merge chunks which contain the same modules.
1730
1758
  * Setting optimization.mergeDuplicateChunks to false will disable this optimization.
@@ -1833,9 +1861,9 @@ export type ExperimentCacheOptions = boolean | {
1833
1861
  buildDependencies?: string[];
1834
1862
  version?: string;
1835
1863
  snapshot?: {
1836
- immutablePaths?: Array<string | RegExp>;
1837
- unmanagedPaths?: Array<string | RegExp>;
1838
- managedPaths?: Array<string | RegExp>;
1864
+ immutablePaths?: (string | RegExp)[];
1865
+ unmanagedPaths?: (string | RegExp)[];
1866
+ managedPaths?: (string | RegExp)[];
1839
1867
  };
1840
1868
  storage?: {
1841
1869
  type: "filesystem";
@@ -2027,6 +2055,7 @@ export type Experiments = {
2027
2055
  css?: boolean;
2028
2056
  /**
2029
2057
  * Enable module layers feature.
2058
+ * @deprecated This option is deprecated, layers is enabled since v1.6.0
2030
2059
  * @default false
2031
2060
  */
2032
2061
  layers?: boolean;
@@ -5,7 +5,7 @@ export interface ModuleFederationPluginOptions extends Omit<ModuleFederationPlug
5
5
  implementation?: string;
6
6
  shareStrategy?: "version-first" | "loaded-first";
7
7
  }
8
- export type RuntimePlugins = string[];
8
+ export type RuntimePlugins = string[] | [string, Record<string, unknown>][];
9
9
  export declare class ModuleFederationPlugin {
10
10
  private _options;
11
11
  constructor(_options: ModuleFederationPluginOptions);
package/dist/exports.d.ts CHANGED
@@ -56,7 +56,7 @@ export { default as EntryOptionPlugin } from "./lib/EntryOptionPlugin";
56
56
  export { EnvironmentPlugin } from "./lib/EnvironmentPlugin";
57
57
  export { LoaderOptionsPlugin } from "./lib/LoaderOptionsPlugin";
58
58
  export { LoaderTargetPlugin } from "./lib/LoaderTargetPlugin";
59
- export type { OutputFileSystem } from "./util/fs";
59
+ export type { OutputFileSystem, WatchFileSystem } from "./util/fs";
60
60
  import { EsmLibraryPlugin, FetchCompileAsyncWasmPlugin, lazyCompilationMiddleware, SubresourceIntegrityPlugin } from "./builtin-plugin";
61
61
  interface Web {
62
62
  FetchCompileAsyncWasmPlugin: typeof FetchCompileAsyncWasmPlugin;