@rspack/core 0.7.3-canary-a741c8d-20240611125339 → 0.7.3

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,9 +8,7 @@
8
8
  * Copyright (c) JS Foundation and other contributors
9
9
  * https://github.com/webpack/loader-runner/blob/main/LICENSE
10
10
  */
11
- var assert = require("assert");
12
11
  var LoaderLoadingError = require("./LoaderLoadingError");
13
- var { toBuffer, serializeObject, isNil, toObject, stringifyLoaderObject } = require("../util");
14
12
  /** @type {undefined | import('node:url')} */
15
13
  var url;
16
14
  // @ts-expect-error
@@ -33,57 +31,7 @@ module.exports = function loadLoader(loader, callback) {
33
31
  }
34
32
  else {
35
33
  try {
36
- var module;
37
- if (loader.path.startsWith("builtin:")) {
38
- // @ts-expect-error
39
- module = async function (content, sourceMap, additionalData) {
40
- // @ts-expect-error
41
- assert(!this.__internal__context.isPitching);
42
- // @ts-expect-error
43
- const callback = this.async();
44
- const { runBuiltinLoader } = require("@rspack/binding");
45
- // @ts-expect-error
46
- let options = this.getOptions() ?? {};
47
- // This is used an hack to tell `builtin:swc-loader` whether to return AST or source.
48
- // @ts-expect-error
49
- this.__internal__context.loaderIndexFromJs = this.loaderIndex;
50
- try {
51
- const context = await runBuiltinLoader(stringifyLoaderObject(loader), JSON.stringify(options),
52
- // @ts-expect-error
53
- Object.assign({}, this.__internal__context, {
54
- content: isNil(content) ? undefined : toBuffer(content),
55
- sourceMap: serializeObject(sourceMap),
56
- additionalData
57
- }));
58
- // @ts-expect-error
59
- this.__internal__context.additionalDataExternal =
60
- context.additionalDataExternal;
61
- // @ts-expect-error
62
- context.fileDependencies.forEach(this.addDependency);
63
- // @ts-expect-error
64
- context.contextDependencies.forEach(this.addContextDependency);
65
- // @ts-expect-error
66
- context.missingDependencies.forEach(this.addMissingDependency);
67
- // @ts-expect-error
68
- context.buildDependencies.forEach(this.addBuildDependency);
69
- callback(null, context.content, isNil(context.sourceMap)
70
- ? undefined
71
- : toObject(context.sourceMap), isNil(context.additionalData) ? undefined : context.additionalData);
72
- // @ts-expect-error
73
- this._compilation.__internal__pushNativeDiagnostics(context.diagnosticsExternal);
74
- }
75
- catch (e) {
76
- return callback(e);
77
- }
78
- };
79
- // @ts-expect-error
80
- module.pitch = function () {
81
- // Pitching for builtin loader is not supported
82
- };
83
- }
84
- else {
85
- module = require(loader.path);
86
- }
34
+ var module = require(loader.path);
87
35
  }
88
36
  catch (e) {
89
37
  // it is possible for node to choke on a require if the FD descriptor
@@ -282,7 +282,7 @@ const SORTERS = {
282
282
  // "compilation.modules": MODULES_SORTER,
283
283
  // "chunk.rootModules": MODULES_SORTER,
284
284
  // "chunk.modules": MODULES_SORTER,
285
- // "module.modules": MODULES_SORTER
285
+ // "module.modules": MODULES_SORTER,
286
286
  // not support module.reasons (missing Module.identifier())
287
287
  // not support chunk.origins (missing compilation.chunkGraph)
288
288
  };
@@ -633,6 +633,20 @@ const SIMPLE_EXTRACTORS = {
633
633
  },
634
634
  optimizationBailout: (object, module) => {
635
635
  object.optimizationBailout = module.optimizationBailout || null;
636
+ },
637
+ depth: (object, module) => {
638
+ object.depth = module.depth;
639
+ },
640
+ nestedModules: (object, module, context, options, factory) => {
641
+ const { type } = context;
642
+ const innerModules =
643
+ /** @type {Module & { modules?: Module[] }} */ module.modules;
644
+ if (Array.isArray(innerModules) && innerModules.length > 0) {
645
+ const groupedModules = factory.create(`${type.slice(0, -8)}.modules`, innerModules, context);
646
+ const limited = (0, statsFactoryUtils_1.spaceLimited)(groupedModules, options.nestedModulesSpace);
647
+ object.modules = limited.children;
648
+ object.filteredModules = limited.filteredChildren;
649
+ }
636
650
  }
637
651
  },
638
652
  profile: {
@@ -26,7 +26,7 @@ const NAMED_PRESETS = {
26
26
  chunkModules: true,
27
27
  // dependentModules: true,
28
28
  // chunkOrigins: true,
29
- // depth: true,
29
+ depth: true,
30
30
  // env: true,
31
31
  reasons: true,
32
32
  usedExports: true,
@@ -58,7 +58,7 @@ const NAMED_PRESETS = {
58
58
  chunkRelations: true,
59
59
  chunkModules: false,
60
60
  // chunkOrigins: true,
61
- // depth: true,
61
+ depth: true,
62
62
  usedExports: true,
63
63
  providedExports: true,
64
64
  optimizationBailout: true,
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import type { JsStatsError } from "@rspack/binding";
3
- import { LoaderObject } from "../config/adapterRuleUse";
3
+ import { LoaderObject } from "../loader-runner";
4
4
  export declare function mapValues(record: Record<string, string>, fn: (key: string) => string): {
5
5
  [k: string]: string;
6
6
  };
package/module.d.ts ADDED
@@ -0,0 +1,244 @@
1
+ /**
2
+ * The following code is modified based on
3
+ * https://github.com/webpack/webpack/blob/v5.92.0/module.d.ts
4
+ *
5
+ * MIT Licensed
6
+ * Author Tobias Koppers @sokra
7
+ * Copyright (c) JS Foundation and other contributors
8
+ * https://github.com/webpack/webpack/blob/main/LICENSE
9
+ */
10
+
11
+ declare namespace Rspack {
12
+ type DeclinedEvent =
13
+ | {
14
+ type: "declined";
15
+ /** The module in question. */
16
+ moduleId: number | string;
17
+ /** the chain from where the update was propagated. */
18
+ chain: (number | string)[];
19
+ /** the module id of the declining parent */
20
+ parentId: number | string;
21
+ }
22
+ | {
23
+ type: "self-declined";
24
+ /** The module in question. */
25
+ moduleId: number | string;
26
+ /** the chain from where the update was propagated. */
27
+ chain: (number | string)[];
28
+ };
29
+
30
+ type UnacceptedEvent = {
31
+ type: "unaccepted";
32
+ /** The module in question. */
33
+ moduleId: number | string;
34
+ /** the chain from where the update was propagated. */
35
+ chain: (number | string)[];
36
+ };
37
+
38
+ type AcceptedEvent = {
39
+ type: "accepted";
40
+ /** The module in question. */
41
+ moduleId: number | string;
42
+ /** the modules that are outdated and will be disposed */
43
+ outdatedModules: (number | string)[];
44
+ /** the accepted dependencies that are outdated */
45
+ outdatedDependencies: {
46
+ [id: number]: (number | string)[];
47
+ };
48
+ };
49
+
50
+ type DisposedEvent = {
51
+ type: "disposed";
52
+ /** The module in question. */
53
+ moduleId: number | string;
54
+ };
55
+
56
+ type ErroredEvent =
57
+ | {
58
+ type: "accept-error-handler-errored";
59
+ /** The module in question. */
60
+ moduleId: number | string;
61
+ /** the module id owning the accept handler. */
62
+ dependencyId: number | string;
63
+ /** the thrown error */
64
+ error: Error;
65
+ /** the error thrown by the module before the error handler tried to handle it. */
66
+ originalError: Error;
67
+ }
68
+ | {
69
+ type: "self-accept-error-handler-errored";
70
+ /** The module in question. */
71
+ moduleId: number | string;
72
+ /** the thrown error */
73
+ error: Error;
74
+ /** the error thrown by the module before the error handler tried to handle it. */
75
+ originalError: Error;
76
+ }
77
+ | {
78
+ type: "accept-errored";
79
+ /** The module in question. */
80
+ moduleId: number | string;
81
+ /** the module id owning the accept handler. */
82
+ dependencyId: number | string;
83
+ /** the thrown error */
84
+ error: Error;
85
+ }
86
+ | {
87
+ type: "self-accept-errored";
88
+ /** The module in question. */
89
+ moduleId: number | string;
90
+ /** the thrown error */
91
+ error: Error;
92
+ };
93
+
94
+ type HotEvent =
95
+ | DeclinedEvent
96
+ | UnacceptedEvent
97
+ | AcceptedEvent
98
+ | DisposedEvent
99
+ | ErroredEvent;
100
+
101
+ interface ApplyOptions {
102
+ ignoreUnaccepted?: boolean;
103
+ ignoreDeclined?: boolean;
104
+ ignoreErrored?: boolean;
105
+ onDeclined?: (event: DeclinedEvent) => void;
106
+ onUnaccepted?: (event: UnacceptedEvent) => void;
107
+ onAccepted?: (event: AcceptedEvent) => void;
108
+ onDisposed?: (event: DisposedEvent) => void;
109
+ onErrored?: (event: ErroredEvent) => void;
110
+ }
111
+
112
+ const enum HotUpdateStatus {
113
+ idle = "idle",
114
+ check = "check",
115
+ prepare = "prepare",
116
+ ready = "ready",
117
+ dispose = "dispose",
118
+ apply = "apply",
119
+ abort = "abort",
120
+ fail = "fail"
121
+ }
122
+
123
+ interface Hot {
124
+ accept: {
125
+ (
126
+ modules: string | string[],
127
+ callback?: (outdatedDependencies: string[]) => void,
128
+ errorHandler?: (
129
+ err: Error,
130
+ context: { moduleId: string | number; dependencyId: string | number }
131
+ ) => void
132
+ ): void;
133
+ (
134
+ errorHandler?: (
135
+ err: Error,
136
+ ids: { moduleId: string | number; module: NodeJS.Module }
137
+ ) => void
138
+ ): void;
139
+ };
140
+ status(): HotUpdateStatus;
141
+ decline(module?: string | string[]): void;
142
+ dispose(callback: (data: object) => void): void;
143
+ addDisposeHandler(callback: (data: object) => void): void;
144
+ removeDisposeHandler(callback: (data: object) => void): void;
145
+ invalidate(): void;
146
+ addStatusHandler(callback: (status: HotUpdateStatus) => void): void;
147
+ removeStatusHandler(callback: (status: HotUpdateStatus) => void): void;
148
+ data: object;
149
+ check(
150
+ autoApply?: boolean | ApplyOptions
151
+ ): Promise<(string | number)[] | null>;
152
+ apply(options?: ApplyOptions): Promise<(string | number)[] | null>;
153
+ }
154
+
155
+ interface ExportInfo {
156
+ used: boolean;
157
+ provideInfo: boolean | null | undefined;
158
+ useInfo: boolean | null | undefined;
159
+ canMangle: boolean;
160
+ }
161
+
162
+ interface ExportsInfo {
163
+ [k: string]: ExportInfo & ExportsInfo;
164
+ }
165
+
166
+ interface Context {
167
+ resolve(dependency: string): string | number;
168
+ keys(): Array<string>;
169
+ id: string | number;
170
+ (dependency: string): unknown;
171
+ }
172
+ }
173
+
174
+ interface ImportMeta {
175
+ url: string;
176
+ // TODO: unsupported
177
+ // webpack: number;
178
+ webpackHot: Rspack.Hot;
179
+ webpackContext: (
180
+ request: string,
181
+ options?: {
182
+ recursive?: boolean;
183
+ regExp?: RegExp;
184
+ include?: RegExp;
185
+ exclude?: RegExp;
186
+ preload?: boolean | number;
187
+ prefetch?: boolean | number;
188
+ fetchPriority?: "low" | "high" | "auto";
189
+ chunkName?: string;
190
+ exports?: string | string[][];
191
+ mode?: "sync" | "eager" | "weak" | "lazy" | "lazy-once";
192
+ }
193
+ ) => Rspack.Context;
194
+ }
195
+
196
+ declare const __resourceQuery: string;
197
+ declare var __webpack_public_path__: string;
198
+ declare var __webpack_nonce__: string;
199
+ declare const __webpack_chunkname__: string;
200
+ declare var __webpack_base_uri__: string;
201
+ declare var __webpack_runtime_id__: string;
202
+ declare const __webpack_hash__: string;
203
+ declare const __webpack_modules__: Record<string | number, NodeJS.Module>;
204
+ declare const __webpack_require__: (id: string | number) => unknown;
205
+ declare var __webpack_chunk_load__: (chunkId: string | number) => Promise<void>;
206
+ declare var __webpack_get_script_filename__: (
207
+ chunkId: string | number
208
+ ) => string;
209
+ declare var __webpack_is_included__: (request: string) => boolean;
210
+ declare var __webpack_exports_info__: Rspack.ExportsInfo;
211
+ declare const __webpack_share_scopes__: Record<
212
+ string,
213
+ Record<
214
+ string,
215
+ { loaded?: 1; get: () => Promise<unknown>; from: string; eager: boolean }
216
+ >
217
+ >;
218
+ declare var __webpack_init_sharing__: (scope: string) => Promise<void>;
219
+ declare var __non_webpack_require__: (id: any) => unknown;
220
+ declare const __system_context__: object;
221
+
222
+ declare namespace NodeJS {
223
+ interface Module {
224
+ hot: Rspack.Hot;
225
+ }
226
+
227
+ interface Require {
228
+ ensure(
229
+ dependencies: string[],
230
+ callback: (require: (module: string) => void) => void,
231
+ errorCallback?: (error: Error) => void,
232
+ chunkName?: string
233
+ ): void;
234
+ context(
235
+ request: string,
236
+ includeSubdirectories?: boolean,
237
+ filter?: RegExp,
238
+ mode?: "sync" | "eager" | "weak" | "lazy" | "lazy-once"
239
+ ): Rspack.Context;
240
+ include(dependency: string): void;
241
+ resolveWeak(dependency: string): void;
242
+ onError?: (error: Error) => void;
243
+ }
244
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/core",
3
- "version": "0.7.3-canary-a741c8d-20240611125339",
3
+ "version": "0.7.3",
4
4
  "webpackVersion": "5.75.0",
5
5
  "license": "MIT",
6
6
  "description": "A Fast Rust-based Web Bundler",
@@ -12,12 +12,14 @@
12
12
  },
13
13
  "./hot/*": "./hot/*.js",
14
14
  "./hot/*.js": "./hot/*.js",
15
- "./package.json": "./package.json"
15
+ "./package.json": "./package.json",
16
+ "./module": "./module.d.ts"
16
17
  },
17
18
  "files": [
18
19
  "dist",
19
20
  "hot",
20
- "compiled"
21
+ "compiled",
22
+ "module.d.ts"
21
23
  ],
22
24
  "engines": {
23
25
  "node": ">=16.0.0"
@@ -72,15 +74,15 @@
72
74
  "watchpack": "^2.4.0",
73
75
  "zod": "^3.21.4",
74
76
  "zod-validation-error": "1.3.1",
75
- "@rspack/plugin-minify": "^0.7.3-canary-a741c8d-20240611125339",
76
- "@rspack/core": "0.7.3-canary-a741c8d-20240611125339"
77
+ "@rspack/core": "0.7.3",
78
+ "@rspack/plugin-minify": "^0.7.3"
77
79
  },
78
80
  "dependencies": {
79
81
  "@module-federation/runtime-tools": "0.1.6",
80
82
  "caniuse-lite": "^1.0.30001616",
81
83
  "tapable": "2.2.1",
82
84
  "webpack-sources": "3.2.3",
83
- "@rspack/binding": "0.7.3-canary-a741c8d-20240611125339"
85
+ "@rspack/binding": "0.7.3"
84
86
  },
85
87
  "peerDependencies": {
86
88
  "@swc/helpers": ">=0.5.1"