@rspack/core 0.7.1-canary-854a79e-20240603132756 → 0.7.1-canary-fdc7685-20240605004251

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.
@@ -9,19 +9,19 @@ class ChunkGraph {
9
9
  this.compilation = compilation;
10
10
  }
11
11
  getChunkModules(chunk) {
12
- return (0, binding_1.__chunk_graph_inner_get_chunk_modules)(chunk.__internal_inner_ukey(), this.compilation.__internal_getInner()).map(m => Module_1.Module.__from_binding(m));
12
+ return (0, binding_1.__chunk_graph_inner_get_chunk_modules)(chunk.__internal_inner_ukey(), this.compilation.__internal_getInner()).map(m => Module_1.Module.__from_binding(m, this.compilation));
13
13
  }
14
14
  getChunkModulesIterable(chunk) {
15
- return new Set((0, binding_1.__chunk_graph_inner_get_chunk_modules)(chunk.__internal_inner_ukey(), this.compilation.__internal_getInner()).map(m => Module_1.Module.__from_binding(m)));
15
+ return new Set((0, binding_1.__chunk_graph_inner_get_chunk_modules)(chunk.__internal_inner_ukey(), this.compilation.__internal_getInner()).map(m => Module_1.Module.__from_binding(m, this.compilation)));
16
16
  }
17
17
  getChunkEntryModulesIterable(chunk) {
18
- return new Set((0, binding_1.__chunk_graph_inner_get_chunk_entry_modules)(chunk.__internal_inner_ukey(), this.compilation.__internal_getInner()).map(m => Module_1.Module.__from_binding(m)));
18
+ return new Set((0, binding_1.__chunk_graph_inner_get_chunk_entry_modules)(chunk.__internal_inner_ukey(), this.compilation.__internal_getInner()).map(m => Module_1.Module.__from_binding(m, this.compilation)));
19
19
  }
20
20
  getChunkEntryDependentChunksIterable(chunk) {
21
21
  return new Set((0, binding_1.__chunk_graph_inner_get_chunk_entry_dependent_chunks_iterable)(chunk.__internal_inner_ukey(), this.compilation.__internal_getInner()).map(c => Chunk_1.Chunk.__from_binding(c, this.compilation.__internal_getInner())));
22
22
  }
23
23
  getChunkModulesIterableBySourceType(chunk, sourceType) {
24
- return new Set((0, binding_1.__chunk_graph_inner_get_chunk_modules_iterable_by_source_type)(chunk.__internal_inner_ukey(), sourceType, this.compilation.__internal_getInner()).map(m => Module_1.Module.__from_binding(m)));
24
+ return new Set((0, binding_1.__chunk_graph_inner_get_chunk_modules_iterable_by_source_type)(chunk.__internal_inner_ukey(), sourceType, this.compilation.__internal_getInner()).map(m => Module_1.Module.__from_binding(m, this.compilation)));
25
25
  }
26
26
  }
27
27
  exports.ChunkGraph = ChunkGraph;
@@ -136,6 +136,15 @@ export declare class Compilation {
136
136
  * Note: This is a proxy for webpack internal API, only method `get` is supported now.
137
137
  */
138
138
  get namedChunks(): Map<string, Readonly<Chunk>>;
139
+ /**
140
+ * Note: This is not a webpack public API, maybe removed in future.
141
+ *
142
+ * @internal
143
+ */
144
+ __internal__getCustomModule(moduleIdentifier: string): {
145
+ buildInfo: Record<string, unknown>;
146
+ buildMeta: Record<string, unknown>;
147
+ };
139
148
  getCache(name: string): import("./lib/CacheFacade");
140
149
  createStatsOptions(optionsOrPreset: StatsValue | undefined, context?: CreateStatsOptionsContext): StatsOptions;
141
150
  createStatsFactory(options: StatsOptions): StatsFactory;
@@ -36,7 +36,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
36
36
  var __importDefault = (this && this.__importDefault) || function (mod) {
37
37
  return (mod && mod.__esModule) ? mod : { "default": mod };
38
38
  };
39
- var _Compilation_instances, _Compilation_inner, _Compilation_cachedAssets, _Compilation_createCachedAssets;
39
+ var _Compilation_instances, _Compilation_inner, _Compilation_cachedAssets, _Compilation_customModules, _Compilation_createCachedAssets;
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.Compilation = void 0;
42
42
  const tapable = __importStar(require("tapable"));
@@ -67,25 +67,33 @@ class Compilation {
67
67
  return null;
68
68
  }
69
69
  };
70
+ /**
71
+ * Records the dynamically added fields for Module on the JavaScript side, using the Module identifier for association.
72
+ * These fields are generally used within a plugin, so they do not need to be passed back to the Rust side.
73
+ */
74
+ _Compilation_customModules.set(this, void 0);
70
75
  this.fileDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").getFileDependencies(), d => __classPrivateFieldGet(this, _Compilation_inner, "f").addFileDependencies(d));
71
76
  this.contextDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").getContextDependencies(), d => __classPrivateFieldGet(this, _Compilation_inner, "f").addContextDependencies(d));
72
77
  this.missingDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").getMissingDependencies(), d => __classPrivateFieldGet(this, _Compilation_inner, "f").addMissingDependencies(d));
73
78
  this.buildDependencies = (0, fake_1.createFakeCompilationDependencies)(() => __classPrivateFieldGet(this, _Compilation_inner, "f").getBuildDependencies(), d => __classPrivateFieldGet(this, _Compilation_inner, "f").addBuildDependencies(d));
74
- this._rebuildModuleCaller = new MergeCaller_1.default((args) => {
75
- __classPrivateFieldGet(this, _Compilation_inner, "f").rebuildModule(args.map(item => item[0]), function (err, modules) {
76
- for (const [id, callback] of args) {
77
- const m = modules.find(item => item.moduleIdentifier === id);
78
- if (m) {
79
- callback(err, Module_1.Module.__from_binding(m));
80
- }
81
- else {
82
- callback(err || new Error("module no found"), null);
79
+ this._rebuildModuleCaller = (function (compilation) {
80
+ return new MergeCaller_1.default((args) => {
81
+ __classPrivateFieldGet(compilation, _Compilation_inner, "f").rebuildModule(args.map(item => item[0]), function (err, modules) {
82
+ for (const [id, callback] of args) {
83
+ const m = modules.find(item => item.moduleIdentifier === id);
84
+ if (m) {
85
+ callback(err, Module_1.Module.__from_binding(m, compilation));
86
+ }
87
+ else {
88
+ callback(err || new Error("module no found"), null);
89
+ }
83
90
  }
84
- }
85
- });
86
- }, 10);
91
+ });
92
+ }, 10);
93
+ })(this);
87
94
  __classPrivateFieldSet(this, _Compilation_inner, inner, "f");
88
95
  __classPrivateFieldSet(this, _Compilation_cachedAssets, __classPrivateFieldGet(this, _Compilation_instances, "m", _Compilation_createCachedAssets).call(this), "f");
96
+ __classPrivateFieldSet(this, _Compilation_customModules, {}, "f");
89
97
  const processAssetsHook = new liteTapable.AsyncSeriesHook([
90
98
  "assets"
91
99
  ]);
@@ -187,7 +195,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
187
195
  }
188
196
  get modules() {
189
197
  return (0, memoize_1.memoizeValue)(() => {
190
- return this.__internal__getModules().map(item => Module_1.Module.__from_binding(item));
198
+ return this.__internal__getModules().map(item => Module_1.Module.__from_binding(item, this));
191
199
  });
192
200
  }
193
201
  // FIXME: Webpack returns a `Set`
@@ -211,6 +219,21 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
211
219
  }
212
220
  };
213
221
  }
222
+ /**
223
+ * Note: This is not a webpack public API, maybe removed in future.
224
+ *
225
+ * @internal
226
+ */
227
+ __internal__getCustomModule(moduleIdentifier) {
228
+ let module = __classPrivateFieldGet(this, _Compilation_customModules, "f")[moduleIdentifier];
229
+ if (!module) {
230
+ module = __classPrivateFieldGet(this, _Compilation_customModules, "f")[moduleIdentifier] = {
231
+ buildInfo: {},
232
+ buildMeta: {}
233
+ };
234
+ }
235
+ return module;
236
+ }
214
237
  getCache(name) {
215
238
  return this.compiler.getCache(name);
216
239
  }
@@ -683,7 +706,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
683
706
  seal() { }
684
707
  unseal() { }
685
708
  }
686
- _Compilation_inner = new WeakMap(), _Compilation_cachedAssets = new WeakMap(), _Compilation_instances = new WeakSet(), _Compilation_createCachedAssets = function _Compilation_createCachedAssets() {
709
+ _Compilation_inner = new WeakMap(), _Compilation_cachedAssets = new WeakMap(), _Compilation_customModules = new WeakMap(), _Compilation_instances = new WeakSet(), _Compilation_createCachedAssets = function _Compilation_createCachedAssets() {
687
710
  return new Proxy({}, {
688
711
  get: (_, property) => {
689
712
  if (typeof property === "string") {
package/dist/Compiler.js CHANGED
@@ -608,9 +608,9 @@ _Compiler_instance = new WeakMap(), _Compiler_initial = new WeakMap(), _Compiler
608
608
  }
609
609
  return;
610
610
  }),
611
- registerCompilationBuildModuleTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationBuildModule, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.buildModule, queired => (m) => queired.call(Module_1.Module.__from_binding(m))),
612
- registerCompilationStillValidModuleTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationStillValidModule, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.stillValidModule, queired => (m) => queired.call(Module_1.Module.__from_binding(m))),
613
- registerCompilationSucceedModuleTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationSucceedModule, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.succeedModule, queired => (m) => queired.call(Module_1.Module.__from_binding(m))),
611
+ registerCompilationBuildModuleTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationBuildModule, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.buildModule, queired => (m) => queired.call(Module_1.Module.__from_binding(m, __classPrivateFieldGet(this, _Compiler_compilation, "f")))),
612
+ registerCompilationStillValidModuleTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationStillValidModule, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.stillValidModule, queired => (m) => queired.call(Module_1.Module.__from_binding(m, __classPrivateFieldGet(this, _Compiler_compilation, "f")))),
613
+ registerCompilationSucceedModuleTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationSucceedModule, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.succeedModule, queired => (m) => queired.call(Module_1.Module.__from_binding(m, __classPrivateFieldGet(this, _Compiler_compilation, "f")))),
614
614
  registerCompilationExecuteModuleTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createHookRegisterTaps).call(this, binding.RegisterJsTapKind.CompilationExecuteModule, () => __classPrivateFieldGet(this, _Compiler_compilation, "f").hooks.executeModule, queried => ({ entry, id, codegenResults, runtimeModules }) => {
615
615
  const __webpack_require__ = (id) => {
616
616
  const cached = moduleCache[id];
package/dist/Module.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { JsCodegenerationResult, JsCodegenerationResults, JsCreateData, JsModule } from "@rspack/binding";
2
2
  import { Source } from "webpack-sources";
3
+ import { Compilation } from "./Compilation";
3
4
  export type ResourceData = {
4
5
  resource: string;
5
6
  path: string;
@@ -32,12 +33,26 @@ export type ContextModuleFactoryAfterResolveResult = false | {
32
33
  export declare class Module {
33
34
  #private;
34
35
  _originalSource?: Source;
36
+ context?: string;
37
+ resource?: string;
38
+ request?: string;
39
+ userRequest?: string;
35
40
  rawRequest?: string;
36
- static __from_binding(module: JsModule): Module;
37
- constructor(module: JsModule);
38
- get context(): string | undefined;
39
- get resource(): string | undefined;
40
- get originalSource(): Source | null;
41
+ /**
42
+ * Records the dynamically added fields for Module on the JavaScript side.
43
+ * These fields are generally used within a plugin, so they do not need to be passed back to the Rust side.
44
+ * @see {@link Compilation#customModules}
45
+ */
46
+ buildInfo: Record<string, any>;
47
+ /**
48
+ * Records the dynamically added fields for Module on the JavaScript side.
49
+ * These fields are generally used within a plugin, so they do not need to be passed back to the Rust side.
50
+ * @see {@link Compilation#customModules}
51
+ */
52
+ buildMeta: Record<string, any>;
53
+ static __from_binding(module: JsModule, compilation?: Compilation): Module;
54
+ constructor(module: JsModule, compilation?: Compilation);
55
+ originalSource(): Source | null;
41
56
  identifier(): string;
42
57
  nameForCondition(): string | null;
43
58
  }
package/dist/Module.js CHANGED
@@ -15,21 +15,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.CodeGenerationResults = exports.CodeGenerationResult = exports.Module = void 0;
16
16
  const source_1 = require("./util/source");
17
17
  class Module {
18
- static __from_binding(module) {
19
- return new Module(module);
18
+ static __from_binding(module, compilation) {
19
+ return new Module(module, compilation);
20
20
  }
21
- constructor(module) {
21
+ constructor(module, compilation) {
22
22
  _Module_inner.set(this, void 0);
23
23
  __classPrivateFieldSet(this, _Module_inner, module, "f");
24
+ this.context = module.context;
25
+ this.resource = module.resource;
26
+ this.request = module.request;
27
+ this.userRequest = module.userRequest;
24
28
  this.rawRequest = module.rawRequest;
29
+ const customModule = compilation?.__internal__getCustomModule(module.moduleIdentifier);
30
+ this.buildInfo = customModule?.buildInfo || {};
31
+ this.buildMeta = customModule?.buildMeta || {};
25
32
  }
26
- get context() {
27
- return __classPrivateFieldGet(this, _Module_inner, "f").context;
28
- }
29
- get resource() {
30
- return __classPrivateFieldGet(this, _Module_inner, "f").resource;
31
- }
32
- get originalSource() {
33
+ originalSource() {
33
34
  if (this._originalSource)
34
35
  return this._originalSource;
35
36
  if (__classPrivateFieldGet(this, _Module_inner, "f").originalSource) {
@@ -34,7 +34,7 @@ function toRawSplitChunksOptions(sc, compiler) {
34
34
  return name(undefined);
35
35
  }
36
36
  else {
37
- return name(Module_1.Module.__from_binding(ctx.module));
37
+ return name(Module_1.Module.__from_binding(ctx.module, compiler._lastCompilation));
38
38
  }
39
39
  };
40
40
  }
@@ -49,7 +49,7 @@ function toRawSplitChunksOptions(sc, compiler) {
49
49
  return test(undefined);
50
50
  }
51
51
  else {
52
- return test(Module_1.Module.__from_binding(ctx.module));
52
+ return test(Module_1.Module.__from_binding(ctx.module, compiler._lastCompilation));
53
53
  }
54
54
  };
55
55
  }
@@ -5,6 +5,7 @@ import { Compiler } from "../Compiler";
5
5
  import { Logger } from "../logging/Logger";
6
6
  import Hash = require("../util/hash");
7
7
  import { Compilation } from "../Compilation";
8
+ import { Module } from "../Module";
8
9
  import { Mode, Resolve, RuleSetUseItem, Target } from "./zod";
9
10
  export interface ComposeJsUseOptions {
10
11
  devtool: RawOptions["devtool"];
@@ -111,6 +112,7 @@ export interface LoaderContext<OptionsType = {}> {
111
112
  data: unknown;
112
113
  _compiler: Compiler;
113
114
  _compilation: Compilation;
115
+ _module: Module;
114
116
  /**
115
117
  * Internal field for interoperability.
116
118
  * Do not use this in anywhere else.
@@ -18,6 +18,7 @@ const createHash_1 = require("../util/createHash");
18
18
  const identifier_1 = require("../util/identifier");
19
19
  const memoize_1 = require("../util/memoize");
20
20
  const loadLoader = require("./loadLoader");
21
+ const Module_1 = require("../Module");
21
22
  const querystring = require("node:querystring");
22
23
  const PATH_QUERY_FRAGMENT_REGEXP = /^((?:\u200b.|[^?#\u200b])*)(\?(?:\u200b.|[^#\u200b])*)?(#.*)?$/;
23
24
  function parsePathQueryFragment(str) {
@@ -202,7 +203,7 @@ async function runLoaders(compiler, rawContext) {
202
203
  return new Promise((resolve, reject) => {
203
204
  compiler
204
205
  ._lastCompilation.__internal_getInner()
205
- .importModule(request, options.publicPath, options.baseUri, rawContext._moduleIdentifier, loaderContext.context, (err, res) => {
206
+ .importModule(request, options.publicPath, options.baseUri, rawContext._module.moduleIdentifier, loaderContext.context, (err, res) => {
206
207
  if (err)
207
208
  reject(err);
208
209
  else {
@@ -226,7 +227,7 @@ async function runLoaders(compiler, rawContext) {
226
227
  }
227
228
  return compiler
228
229
  ._lastCompilation.__internal_getInner()
229
- .importModule(request, options.publicPath, options.baseUri, rawContext._moduleIdentifier, loaderContext.context, (err, res) => {
230
+ .importModule(request, options.publicPath, options.baseUri, rawContext._module.moduleIdentifier, loaderContext.context, (err, res) => {
230
231
  if (err) {
231
232
  callback(err, undefined);
232
233
  }
@@ -479,6 +480,7 @@ async function runLoaders(compiler, rawContext) {
479
480
  };
480
481
  loaderContext._compiler = compiler;
481
482
  loaderContext._compilation = compiler._lastCompilation;
483
+ loaderContext._module = Module_1.Module.__from_binding(rawContext._module, compiler._lastCompilation);
482
484
  loaderContext.getOptions = function () {
483
485
  const loader = getCurrentLoader(loaderContext);
484
486
  let options = loader?.options;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspack/core",
3
- "version": "0.7.1-canary-854a79e-20240603132756",
3
+ "version": "0.7.1-canary-fdc7685-20240605004251",
4
4
  "webpackVersion": "5.75.0",
5
5
  "license": "MIT",
6
6
  "description": "A Fast Rust-based Web Bundler",
@@ -72,15 +72,15 @@
72
72
  "watchpack": "^2.4.0",
73
73
  "zod": "^3.21.4",
74
74
  "zod-validation-error": "1.3.1",
75
- "@rspack/core": "0.7.1-canary-854a79e-20240603132756",
76
- "@rspack/plugin-minify": "^0.7.1-canary-854a79e-20240603132756"
75
+ "@rspack/core": "0.7.1-canary-fdc7685-20240605004251",
76
+ "@rspack/plugin-minify": "^0.7.1-canary-fdc7685-20240605004251"
77
77
  },
78
78
  "dependencies": {
79
79
  "@module-federation/runtime-tools": "0.1.6",
80
80
  "caniuse-lite": "^1.0.30001616",
81
81
  "tapable": "2.2.1",
82
82
  "webpack-sources": "3.2.3",
83
- "@rspack/binding": "0.7.1-canary-854a79e-20240603132756"
83
+ "@rspack/binding": "0.7.1-canary-fdc7685-20240605004251"
84
84
  },
85
85
  "peerDependencies": {
86
86
  "@swc/helpers": ">=0.5.1"