@rspack/core 1.2.6 → 1.2.7

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.
@@ -8,7 +8,8 @@
8
8
  * https://github.com/webpack/webpack/blob/main/LICENSE
9
9
  */
10
10
  import type * as binding from "@rspack/binding";
11
- import { type ExternalObject, type JsCompilation, type JsRuntimeModule } from "@rspack/binding";
11
+ import { type AssetInfo, type Dependency, type ExternalObject, type JsCompilation, type JsRuntimeModule } from "@rspack/binding";
12
+ export type { AssetInfo } from "@rspack/binding";
12
13
  import * as liteTapable from "@rspack/lite-tapable";
13
14
  import type { Source } from "../compiled/webpack-sources";
14
15
  import { Chunk } from "./Chunk";
@@ -16,7 +17,6 @@ import { ChunkGraph } from "./ChunkGraph";
16
17
  import { ChunkGroup } from "./ChunkGroup";
17
18
  import type { Compiler } from "./Compiler";
18
19
  import type { ContextModuleFactory } from "./ContextModuleFactory";
19
- import { Dependency } from "./Dependency";
20
20
  import { Entrypoint } from "./Entrypoint";
21
21
  import { type CodeGenerationResult, Module } from "./Module";
22
22
  import ModuleGraph from "./ModuleGraph";
@@ -31,10 +31,8 @@ import WebpackError from "./lib/WebpackError";
31
31
  import { Logger } from "./logging/Logger";
32
32
  import { StatsFactory } from "./stats/StatsFactory";
33
33
  import { StatsPrinter } from "./stats/StatsPrinter";
34
- import { type AssetInfo } from "./util/AssetInfo";
35
34
  import type { InputFileSystem } from "./util/fs";
36
35
  import type Hash from "./util/hash";
37
- export type { AssetInfo } from "./util/AssetInfo";
38
36
  export type Assets = Record<string, Source>;
39
37
  export interface Asset {
40
38
  name: string;
@@ -241,7 +239,7 @@ export declare class Compilation {
241
239
  /**
242
240
  * Update an existing asset. Trying to update an asset that doesn't exist will throw an error.
243
241
  */
244
- updateAsset(filename: string, newSourceOrFunction: Source | ((source: Source) => Source), assetInfoUpdateOrFunction?: AssetInfo | ((assetInfo: AssetInfo) => AssetInfo)): void;
242
+ updateAsset(filename: string, newSourceOrFunction: Source | ((source: Source) => Source), assetInfoUpdateOrFunction?: AssetInfo | ((assetInfo: AssetInfo) => AssetInfo | undefined)): void;
245
243
  /**
246
244
  * Emit an not existing asset. Trying to emit an asset that already exists will throw an error.
247
245
  *
@@ -128,8 +128,12 @@ declare class Compiler {
128
128
  watch(watchOptions: Watchpack.WatchOptions, handler: liteTapable.Callback<Error, Stats>): Watching;
129
129
  /**
130
130
  * @param callback - signals when the call finishes
131
+ * @param options - additional data like modifiedFiles, removedFiles
131
132
  */
132
- run(callback: liteTapable.Callback<Error, Stats>): void;
133
+ run(callback: liteTapable.Callback<Error, Stats>, options?: {
134
+ modifiedFiles?: ReadonlySet<string>;
135
+ removedFiles?: ReadonlySet<string>;
136
+ }): void;
133
137
  runAsChild(callback: (err?: null | Error, entries?: Chunk[], compilation?: Compilation) => any): void;
134
138
  purgeInputFileSystem(): void;
135
139
  /**
@@ -142,6 +146,11 @@ declare class Compiler {
142
146
  */
143
147
  createChildCompiler(compilation: Compilation, compilerName: string, compilerIndex: number, outputOptions: OutputNormalized, plugins: RspackPluginInstance[]): Compiler;
144
148
  isChild(): boolean;
149
+ /**
150
+ * Create a compilation and run it, which is the basic method that `compiler.run` and `compiler.watch` depend on.
151
+ * TODO: make this method private in the next major release
152
+ * @private this method is only used in Rspack core
153
+ */
145
154
  compile(callback: liteTapable.Callback<Error, Compilation>): void;
146
155
  close(callback: (error?: Error | null) => void): void;
147
156
  /**
@@ -1,5 +1,4 @@
1
- import type { JsDependenciesBlock } from "@rspack/binding";
2
- import { Dependency } from "./Dependency";
1
+ import type { Dependency, JsDependenciesBlock } from "@rspack/binding";
3
2
  export declare class DependenciesBlock {
4
3
  #private;
5
4
  readonly dependencies: Dependency[];
package/dist/Module.d.ts CHANGED
@@ -1,9 +1,7 @@
1
- import type { JsCodegenerationResult, JsContextModuleFactoryAfterResolveData, JsContextModuleFactoryBeforeResolveData, JsCreateData, JsFactoryMeta, JsLibIdentOptions } from "@rspack/binding";
1
+ import type { AssetInfo, Dependency, JsCodegenerationResult, JsContextModuleFactoryAfterResolveData, JsContextModuleFactoryBeforeResolveData, JsCreateData, JsFactoryMeta, JsLibIdentOptions } from "@rspack/binding";
2
2
  import type { JsModule } from "@rspack/binding";
3
3
  import type { Source } from "../compiled/webpack-sources";
4
4
  import { DependenciesBlock } from "./DependenciesBlock";
5
- import { Dependency } from "./Dependency";
6
- import { type AssetInfo } from "./util/AssetInfo";
7
5
  export type ResourceData = {
8
6
  resource: string;
9
7
  path: string;
@@ -16,7 +14,7 @@ export type ResourceDataWithData = ResourceData & {
16
14
  export type CreateData = Partial<JsCreateData>;
17
15
  export type ContextInfo = {
18
16
  issuer: string;
19
- issuerLayer?: string;
17
+ issuerLayer?: string | null;
20
18
  };
21
19
  export type ResolveData = {
22
20
  contextInfo: ContextInfo;
@@ -85,7 +83,7 @@ export declare class Module {
85
83
  nameForCondition(): string | null;
86
84
  size(type?: string): number;
87
85
  libIdent(options: JsLibIdentOptions): string | null;
88
- emitFile(filename: string, source: Source, assetInfo: AssetInfo): void;
86
+ emitFile(filename: string, source: Source, assetInfo?: AssetInfo): void;
89
87
  }
90
88
  export declare class CodeGenerationResult {
91
89
  #private;
@@ -1,5 +1,4 @@
1
- import type { JsModuleGraph } from "@rspack/binding";
2
- import { Dependency } from "./Dependency";
1
+ import type { Dependency, JsModuleGraph } from "@rspack/binding";
3
2
  import { ExportsInfo } from "./ExportsInfo";
4
3
  import { Module } from "./Module";
5
4
  import { ModuleGraphConnection } from "./ModuleGraphConnection";
@@ -17,4 +16,5 @@ export default class ModuleGraph {
17
16
  getIncomingConnections(module: Module): ModuleGraphConnection[];
18
17
  getParentBlockIndex(dependency: Dependency): number;
19
18
  isAsync(module: Module): boolean;
19
+ getOutgoingConnectionsInOrder(module: Module): ModuleGraphConnection[];
20
20
  }
@@ -1,5 +1,4 @@
1
- import type { JsModuleGraphConnection } from "@rspack/binding";
2
- import { Dependency } from "./Dependency";
1
+ import type { Dependency, JsModuleGraphConnection } from "@rspack/binding";
3
2
  import { Module } from "./Module";
4
3
  export declare class ModuleGraphConnection {
5
4
  #private;
@@ -62,7 +62,14 @@ export declare class MultiCompiler {
62
62
  * @returns a compiler watcher
63
63
  */
64
64
  watch(watchOptions: WatchOptions, handler: liteTapable.Callback<Error, MultiStats>): MultiWatching;
65
- run(callback: liteTapable.Callback<Error, MultiStats>): void;
65
+ /**
66
+ * @param callback - signals when the call finishes
67
+ * @param options - additional data like modifiedFiles, removedFiles
68
+ */
69
+ run(callback: liteTapable.Callback<Error, MultiStats>, options?: {
70
+ modifiedFiles?: ReadonlySet<string>;
71
+ removedFiles?: ReadonlySet<string>;
72
+ }): void;
66
73
  purgeInputFileSystem(): void;
67
74
  close(callback: liteTapable.Callback<Error, void>): void;
68
75
  }
@@ -1,4 +1,4 @@
1
- import { BuiltinPluginName, type JsEntryOptions } from "@rspack/binding";
1
+ import { BuiltinPluginName, EntryDependency, type JsEntryOptions } from "@rspack/binding";
2
2
  import type { EntryDescriptionNormalized } from "../config";
3
3
  /**
4
4
  * Options for the `EntryPlugin`.
@@ -24,9 +24,6 @@ declare const OriginEntryPlugin: {
24
24
  apply(compiler: import("..").Compiler): void;
25
25
  };
26
26
  };
27
- interface EntryDependency {
28
- request: string;
29
- }
30
27
  type EntryPluginType = typeof OriginEntryPlugin & {
31
28
  createDependency(entry: string): EntryDependency;
32
29
  };
@@ -1,4 +1,4 @@
1
- import type { JsAssetInfo, RawModuleRuleUse, RawOptions } from "@rspack/binding";
1
+ import type { AssetInfo, RawModuleRuleUse, RawOptions } from "@rspack/binding";
2
2
  import type { ResolveRequest } from "../../compiled/enhanced-resolve";
3
3
  import type { Compilation } from "../Compilation";
4
4
  import type { Compiler } from "../Compiler";
@@ -73,21 +73,83 @@ export interface ImportModuleOptions {
73
73
  baseUri?: string;
74
74
  }
75
75
  export interface LoaderContext<OptionsType = {}> {
76
+ /**
77
+ * The version number of the loader API. Currently 2.
78
+ * This is useful for providing backwards compatibility. Using the version you can specify
79
+ * custom logic or fallbacks for breaking changes.
80
+ */
76
81
  version: 2;
82
+ /**
83
+ * The path string of the current module.
84
+ * @example `'/abc/resource.js?query#hash'`.
85
+ */
77
86
  resource: string;
87
+ /**
88
+ * The path string of the current module, excluding the query and fragment parameters.
89
+ * @example `'/abc/resource.js?query#hash'` in `'/abc/resource.js'`.
90
+ */
78
91
  resourcePath: string;
92
+ /**
93
+ * The query parameter for the path string of the current module.
94
+ * @example `'?query'` in `'/abc/resource.js?query#hash'`.
95
+ */
79
96
  resourceQuery: string;
97
+ /**
98
+ * The fragment parameter of the current module's path string.
99
+ * @example `'#hash'` in `'/abc/resource.js?query#hash'`.
100
+ */
80
101
  resourceFragment: string;
102
+ /**
103
+ * Tells Rspack that this loader will be called asynchronously. Returns `this.callback`.
104
+ */
81
105
  async(): LoaderContextCallback;
106
+ /**
107
+ * A function that can be called synchronously or asynchronously in order to return multiple
108
+ * results. The expected arguments are:
109
+ *
110
+ * 1. The first parameter must be `Error` or `null`, which marks the current module as a
111
+ * compilation failure.
112
+ * 2. The second argument is a `string` or `Buffer`, which indicates the contents of the file
113
+ * after the module has been processed by the loader.
114
+ * 3. The third parameter is a source map that can be processed by the loader.
115
+ * 4. The fourth parameter is ignored by Rspack and can be anything (e.g. some metadata).
116
+ */
82
117
  callback: LoaderContextCallback;
118
+ /**
119
+ * A function that sets the cacheable flag.
120
+ * By default, the processing results of the loader are marked as cacheable.
121
+ * Calling this method and passing `false` turns off the loader's ability to
122
+ * cache processing results.
123
+ */
83
124
  cacheable(cacheable?: boolean): void;
125
+ /**
126
+ * Tells if source map should be generated. Since generating source maps can be an expensive task,
127
+ * you should check if source maps are actually requested.
128
+ */
84
129
  sourceMap: boolean;
130
+ /**
131
+ * The base path configured in Rspack config via `context`.
132
+ */
85
133
  rootContext: string;
134
+ /**
135
+ * The directory path of the currently processed module, which changes with the
136
+ * location of each processed module.
137
+ * For example, if the loader is processing `/project/src/components/Button.js`,
138
+ * then the value of `this.context` would be `/project/src/components`.
139
+ */
86
140
  context: string | null;
141
+ /**
142
+ * The index in the loaders array of the current loader.
143
+ */
87
144
  loaderIndex: number;
88
145
  remainingRequest: string;
89
146
  currentRequest: string;
90
147
  previousRequest: string;
148
+ /**
149
+ * The module specifier string after being resolved.
150
+ * For example, if a `resource.js` is processed by `loader1.js` and `loader2.js`, the value of
151
+ * `this.request` will be `/path/to/loader1.js!/path/to/loader2.js!/path/to/resource.js`.
152
+ */
91
153
  request: string;
92
154
  /**
93
155
  * An array of all the loaders. It is writeable in the pitch phase.
@@ -108,23 +170,80 @@ export interface LoaderContext<OptionsType = {}> {
108
170
  * ]
109
171
  */
110
172
  loaders: LoaderObject[];
173
+ /**
174
+ * The value of `mode` is read when Rspack is run.
175
+ * The possible values are: `'production'`, `'development'`, `'none'`
176
+ */
111
177
  mode?: Mode;
178
+ /**
179
+ * The current compilation target. Passed from `target` configuration options.
180
+ */
112
181
  target?: Target;
182
+ /**
183
+ * Whether HMR is enabled.
184
+ */
113
185
  hot?: boolean;
114
186
  /**
115
- * @param schema To provide the best performance, Rspack does not perform the schema validation. If your loader requires schema validation, please call scheme-utils or zod on your own.
187
+ * Get the options passed in by the loader's user.
188
+ * @param schema To provide the best performance, Rspack does not perform the schema
189
+ * validation. If your loader requires schema validation, please call scheme-utils or
190
+ * zod on your own.
116
191
  */
117
192
  getOptions(schema?: any): OptionsType;
193
+ /**
194
+ * Resolve a module specifier.
195
+ * @param context The absolute path to a directory. This directory is used as the starting
196
+ * location for resolving.
197
+ * @param request The module specifier to be resolved.
198
+ * @param callback A callback function that gives the resolved path.
199
+ */
118
200
  resolve(context: string, request: string, callback: (arg0: null | Error, arg1?: string | false, arg2?: ResolveRequest) => void): void;
201
+ /**
202
+ * Create a resolver like `this.resolve`.
203
+ */
119
204
  getResolve(options: Resolve): ((context: string, request: string, callback: ResolveCallback) => void) | ((context: string, request: string) => Promise<string | false | undefined>);
205
+ /**
206
+ * Get the logger of this compilation, through which messages can be logged.
207
+ */
120
208
  getLogger(name: string): Logger;
209
+ /**
210
+ * Emit an error. Unlike `throw` and `this.callback(err)` in the loader, it does not
211
+ * mark the current module as a compilation failure, it just adds an error to Rspack's
212
+ * Compilation and displays it on the command line at the end of this compilation.
213
+ */
121
214
  emitError(error: Error): void;
215
+ /**
216
+ * Emit a warning.
217
+ */
122
218
  emitWarning(warning: Error): void;
123
- emitFile(name: string, content: string | Buffer, sourceMap?: string, assetInfo?: JsAssetInfo): void;
219
+ /**
220
+ * Emit a new file. This method allows you to create new files during the loader execution.
221
+ */
222
+ emitFile(name: string, content: string | Buffer, sourceMap?: string, assetInfo?: AssetInfo): void;
223
+ /**
224
+ * Add a file as a dependency on the loader results so that any changes to them can be listened to.
225
+ * For example, `sass-loader`, `less-loader` use this trick to recompile when the imported style
226
+ * files change.
227
+ */
124
228
  addDependency(file: string): void;
229
+ /**
230
+ * Alias of `this.addDependency()`.
231
+ */
125
232
  dependency(file: string): void;
233
+ /**
234
+ * Add the directory as a dependency for the loader results so that any changes to the
235
+ * files in the directory can be listened to.
236
+ */
126
237
  addContextDependency(context: string): void;
238
+ /**
239
+ * Add a currently non-existent file as a dependency of the loader result, so that its
240
+ * creation and any changes can be listened. For example, when a new file is created at
241
+ * that path, it will trigger a rebuild.
242
+ */
127
243
  addMissingDependency(missing: string): void;
244
+ /**
245
+ * Removes all dependencies of the loader result.
246
+ */
128
247
  clearDependencies(): void;
129
248
  getDependencies(): string[];
130
249
  getContextDependencies(): string[];
@@ -145,24 +264,58 @@ export interface LoaderContext<OptionsType = {}> {
145
264
  */
146
265
  importModule<T = any>(request: string, options: ImportModuleOptions | undefined, callback: (err?: null | Error, exports?: T) => any): void;
147
266
  importModule<T = any>(request: string, options?: ImportModuleOptions): Promise<T>;
267
+ /**
268
+ * Access to the `compilation` object's `inputFileSystem` property.
269
+ */
148
270
  fs: any;
149
271
  /**
150
272
  * This is an experimental API and maybe subject to change.
151
273
  * @experimental
152
274
  */
153
275
  experiments: LoaderExperiments;
276
+ /**
277
+ * Access to some utilities.
278
+ */
154
279
  utils: {
280
+ /**
281
+ * Return a new request string using absolute paths when possible.
282
+ */
155
283
  absolutify: (context: string, request: string) => string;
284
+ /**
285
+ * Return a new request string avoiding absolute paths when possible.
286
+ */
156
287
  contextify: (context: string, request: string) => string;
288
+ /**
289
+ * Return a new Hash object from provided hash function.
290
+ */
157
291
  createHash: (algorithm?: string) => Hash;
158
292
  };
293
+ /**
294
+ * The value depends on the loader configuration:
295
+ * - If the current loader was configured with an options object, `this.query` will
296
+ * point to that object.
297
+ * - If the current loader has no options, but was invoked with a query string, this
298
+ * will be a string starting with `?`.
299
+ */
159
300
  query: string | OptionsType;
301
+ /**
302
+ * A data object shared between the pitch and the normal phase.
303
+ */
160
304
  data: unknown;
305
+ /**
306
+ * Access to the current Compiler object of Rspack.
307
+ */
161
308
  _compiler: Compiler;
309
+ /**
310
+ * Access to the current Compilation object of Rspack.
311
+ */
162
312
  _compilation: Compilation;
313
+ /**
314
+ * @deprecated Hacky access to the Module object being loaded.
315
+ */
163
316
  _module: Module;
164
317
  /**
165
- * Note: This is not a webpack public API, maybe removed in future.
318
+ * Note: This is not a Rspack public API, maybe removed in future.
166
319
  * Store some data from loader, and consume it from parser, it may be removed in the future
167
320
  *
168
321
  * @internal
@@ -1,4 +1,4 @@
1
- import type { JsAssetInfo, RawFuncUseCtx } from "@rspack/binding";
1
+ import type { AssetInfo, RawFuncUseCtx } from "@rspack/binding";
2
2
  import type * as webpackDevServer from "webpack-dev-server";
3
3
  import type { ChunkGraph } from "../ChunkGraph";
4
4
  import type { Compilation, PathData } from "../Compilation";
@@ -8,7 +8,7 @@ import type ModuleGraph from "../ModuleGraph";
8
8
  import type { LazyCompilationDefaultBackendOptions } from "../builtin-plugin/lazy-compilation/backend";
9
9
  import type { Chunk } from "../exports";
10
10
  export type FilenameTemplate = string;
11
- export type Filename = FilenameTemplate | ((pathData: PathData, assetInfo?: JsAssetInfo) => string);
11
+ export type Filename = FilenameTemplate | ((pathData: PathData, assetInfo?: AssetInfo) => string);
12
12
  /** Name of the configuration. Used when loading multiple configurations. */
13
13
  export type Name = string;
14
14
  /** A list of name defining all sibling configurations it depends on. Dependent configurations need to be compiled first. */