@rspack/core 0.5.7 → 0.5.8-canary-6b6429d-20240321010409

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.
Files changed (76) hide show
  1. package/dist/Chunk.d.ts +2 -0
  2. package/dist/Chunk.js +4 -0
  3. package/dist/Compilation.d.ts +17 -19
  4. package/dist/Compilation.js +10 -10
  5. package/dist/Compiler.d.ts +7 -6
  6. package/dist/Compiler.js +156 -240
  7. package/dist/Module.d.ts +3 -0
  8. package/dist/Module.js +12 -0
  9. package/dist/NormalModuleFactory.d.ts +2 -1
  10. package/dist/NormalModuleFactory.js +25 -1
  11. package/dist/Watching.js +2 -2
  12. package/dist/builtin-plugin/ArrayPushCallbackChunkFormatPlugin.d.ts +1 -1
  13. package/dist/builtin-plugin/AssetModulesPlugin.d.ts +1 -1
  14. package/dist/builtin-plugin/AsyncWebAssemblyModulesPlugin.d.ts +1 -1
  15. package/dist/builtin-plugin/BannerPlugin.d.ts +1 -1
  16. package/dist/builtin-plugin/BundlerInfoRspackPlugin.d.ts +1 -1
  17. package/dist/builtin-plugin/ChunkPrefetchPreloadPlugin.d.ts +1 -1
  18. package/dist/builtin-plugin/CommonJsChunkFormatPlugin.d.ts +1 -1
  19. package/dist/builtin-plugin/CopyRspackPlugin.d.ts +1 -1
  20. package/dist/builtin-plugin/DataUriPlugin.d.ts +1 -1
  21. package/dist/builtin-plugin/DefinePlugin.d.ts +1 -1
  22. package/dist/builtin-plugin/DeterministicChunkIdsPlugin.d.ts +1 -1
  23. package/dist/builtin-plugin/DeterministicModuleIdsPlugin.d.ts +1 -1
  24. package/dist/builtin-plugin/ElectronTargetPlugin.d.ts +1 -1
  25. package/dist/builtin-plugin/EnableChunkLoadingPlugin.d.ts +1 -1
  26. package/dist/builtin-plugin/EnableLibraryPlugin.d.ts +1 -1
  27. package/dist/builtin-plugin/EnableWasmLoadingPlugin.d.ts +1 -1
  28. package/dist/builtin-plugin/EnsureChunkConditionsPlugin.d.ts +1 -1
  29. package/dist/builtin-plugin/EntryPlugin.d.ts +1 -1
  30. package/dist/builtin-plugin/EvalDevToolModulePlugin.d.ts +1 -1
  31. package/dist/builtin-plugin/EvalSourceMapDevToolPlugin.d.ts +1 -1
  32. package/dist/builtin-plugin/ExternalsPlugin.d.ts +1 -1
  33. package/dist/builtin-plugin/FileUriPlugin.d.ts +1 -1
  34. package/dist/builtin-plugin/FlagDependencyExportsPlugin.d.ts +1 -1
  35. package/dist/builtin-plugin/FlagDependencyUsagePlugin.d.ts +1 -1
  36. package/dist/builtin-plugin/HtmlRspackPlugin.d.ts +1 -1
  37. package/dist/builtin-plugin/HttpExternalsRspackPlugin.d.ts +1 -1
  38. package/dist/builtin-plugin/InferAsyncModulesPlugin.d.ts +1 -1
  39. package/dist/builtin-plugin/JavascriptModulesPlugin.d.ts +1 -1
  40. package/dist/builtin-plugin/JsLoaderRspackPlugin.d.ts +11 -0
  41. package/dist/builtin-plugin/JsLoaderRspackPlugin.js +7 -0
  42. package/dist/builtin-plugin/JsonModulesPlugin.d.ts +1 -1
  43. package/dist/builtin-plugin/LimitChunkCountPlugin.d.ts +1 -1
  44. package/dist/builtin-plugin/MangleExportsPlugin.d.ts +1 -1
  45. package/dist/builtin-plugin/MergeDuplicateChunksPlugin.d.ts +1 -1
  46. package/dist/builtin-plugin/ModuleChunkFormatPlugin.d.ts +1 -1
  47. package/dist/builtin-plugin/ModuleConcatenationPlugin.d.ts +1 -1
  48. package/dist/builtin-plugin/NamedChunkIdsPlugin.d.ts +1 -1
  49. package/dist/builtin-plugin/NamedModuleIdsPlugin.d.ts +1 -1
  50. package/dist/builtin-plugin/NodeTargetPlugin.d.ts +1 -1
  51. package/dist/builtin-plugin/ProgressPlugin.d.ts +1 -1
  52. package/dist/builtin-plugin/ProvidePlugin.d.ts +1 -1
  53. package/dist/builtin-plugin/RealContentHashPlugin.d.ts +1 -1
  54. package/dist/builtin-plugin/RemoveEmptyChunksPlugin.d.ts +1 -1
  55. package/dist/builtin-plugin/RuntimePlugin.d.ts +1 -1
  56. package/dist/builtin-plugin/SideEffectsFlagPlugin.d.ts +1 -1
  57. package/dist/builtin-plugin/SourceMapDevToolPlugin.d.ts +1 -1
  58. package/dist/builtin-plugin/SwcCssMinimizerPlugin.d.ts +1 -1
  59. package/dist/builtin-plugin/SwcJsMinimizerPlugin.d.ts +1 -1
  60. package/dist/builtin-plugin/WarnCaseSensitiveModulesPlugin.d.ts +1 -1
  61. package/dist/builtin-plugin/WebWorkerTemplatePlugin.d.ts +1 -1
  62. package/dist/builtin-plugin/base.d.ts +1 -1
  63. package/dist/builtin-plugin/index.d.ts +1 -0
  64. package/dist/builtin-plugin/index.js +1 -0
  65. package/dist/config/adapter.js +9 -8
  66. package/dist/config/zod.d.ts +332 -78
  67. package/dist/config/zod.js +8 -1
  68. package/dist/exports.d.ts +27 -15
  69. package/dist/lite-tapable/index.d.ts +14 -1
  70. package/dist/lite-tapable/index.js +168 -1
  71. package/dist/loader-runner/index.d.ts +2 -2
  72. package/dist/loader-runner/index.js +4 -4
  73. package/dist/rspackOptionsApply.js +1 -0
  74. package/package.json +5 -5
  75. package/dist/util/normalization.d.ts +0 -5
  76. package/dist/util/normalization.js +0 -9
package/dist/Compiler.js CHANGED
@@ -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 _Compiler_instances, _Compiler_instance, _Compiler_disabledHooks, _Compiler_moduleExecutionResultsMap, _Compiler_getInstance, _Compiler_updateDisabledHooks, _Compiler_beforeCompile, _Compiler_afterCompile, _Compiler_finishMake, _Compiler_buildModule, _Compiler_afterProcessAssets, _Compiler_beforeResolve, _Compiler_afterResolve, _Compiler_contextModuleFactoryBeforeResolve, _Compiler_contextModuleFactoryAfterResolve, _Compiler_normalModuleFactoryCreateModule, _Compiler_normalModuleFactoryResolveForScheme, _Compiler_optimizeChunkModules, _Compiler_optimizeTree, _Compiler_optimizeModules, _Compiler_afterOptimizeModules, _Compiler_chunkAsset, _Compiler_finishModules, _Compiler_shouldEmit, _Compiler_emit, _Compiler_assetEmitted, _Compiler_afterEmit, _Compiler_succeedModule, _Compiler_stillValidModule, _Compiler_runtimeModule, _Compiler_executeModule, _Compiler_decorateUpdateDisabledHooks, _Compiler_registerCompilerCompilationTaps, _Compiler_registerCompilerMakeTaps, _Compiler_registerCompilationProcessAssetsTaps, _Compiler_newCompilation;
39
+ var _Compiler_instances, _Compiler_instance, _Compiler_disabledHooks, _Compiler_moduleExecutionResultsMap, _Compiler_getInstance, _Compiler_updateDisabledHooks, _Compiler_finishMake, _Compiler_afterProcessAssets, _Compiler_afterResolve, _Compiler_contextModuleFactoryBeforeResolve, _Compiler_contextModuleFactoryAfterResolve, _Compiler_normalModuleFactoryCreateModule, _Compiler_normalModuleFactoryResolveForScheme, _Compiler_optimizeChunkModules, _Compiler_optimizeTree, _Compiler_optimizeModules, _Compiler_afterOptimizeModules, _Compiler_finishModules, _Compiler_emit, _Compiler_assetEmitted, _Compiler_afterEmit, _Compiler_decorateUpdateDisabledHooks, _Compiler_createRegisterTaps, _Compiler_createCompilation, _Compiler_resetThisCompilation, _Compiler_newCompilationParams;
40
40
  Object.defineProperty(exports, "__esModule", { value: true });
41
41
  exports.Compiler = void 0;
42
42
  const index_1 = require("./index");
@@ -44,23 +44,21 @@ const fs_1 = __importDefault(require("fs"));
44
44
  const tapable = __importStar(require("tapable"));
45
45
  const liteTapable = __importStar(require("./lite-tapable"));
46
46
  const tapable_1 = require("tapable");
47
+ const config_1 = require("./config");
47
48
  const RuleSetCompiler_1 = require("./RuleSetCompiler");
48
49
  const Stats_1 = require("./Stats");
49
50
  const Compilation_1 = require("./Compilation");
50
51
  const ContextModuleFactory_1 = require("./ContextModuleFactory");
51
52
  const ResolverFactory_1 = __importDefault(require("./ResolverFactory"));
52
- const config_1 = require("./config");
53
53
  const ConcurrentCompilationError_1 = __importDefault(require("./error/ConcurrentCompilationError"));
54
54
  const fileSystem_1 = require("./fileSystem");
55
55
  const Cache_1 = __importDefault(require("./lib/Cache"));
56
56
  const CacheFacade_1 = __importDefault(require("./lib/CacheFacade"));
57
- const loader_runner_1 = require("./loader-runner");
58
57
  const Logger_1 = require("./logging/Logger");
59
58
  const NormalModuleFactory_1 = require("./NormalModuleFactory");
60
59
  const bindingVersionCheck_1 = require("./util/bindingVersionCheck");
61
60
  const Watching_1 = require("./Watching");
62
61
  const NormalModule_1 = require("./NormalModule");
63
- const normalization_1 = require("./util/normalization");
64
62
  const builtin_plugin_1 = require("./builtin-plugin");
65
63
  const rspackOptionsApply_1 = require("./rspackOptionsApply");
66
64
  const defaults_1 = require("./config/defaults");
@@ -70,6 +68,7 @@ const HookWebpackError_1 = require("./lib/HookWebpackError");
70
68
  const Module_1 = require("./Module");
71
69
  const base_1 = require("./builtin-plugin/base");
72
70
  const ExecuteModulePlugin_1 = __importDefault(require("./ExecuteModulePlugin"));
71
+ const Chunk_1 = require("./Chunk");
73
72
  class Compiler {
74
73
  constructor(context, options) {
75
74
  _Compiler_instances.add(this);
@@ -94,7 +93,7 @@ class Compiler {
94
93
  this.removedFiles = undefined;
95
94
  this.hooks = {
96
95
  initialize: new tapable_1.SyncHook([]),
97
- shouldEmit: new tapable.SyncBailHook(["compilation"]),
96
+ shouldEmit: new liteTapable.SyncBailHook(["compilation"]),
98
97
  done: new tapable.AsyncSeriesHook(["stats"]),
99
98
  afterDone: new tapable.SyncHook(["stats"]),
100
99
  beforeRun: new tapable.AsyncSeriesHook(["compiler"]),
@@ -102,10 +101,7 @@ class Compiler {
102
101
  emit: new tapable.AsyncSeriesHook(["compilation"]),
103
102
  assetEmitted: new tapable.AsyncSeriesHook(["file", "info"]),
104
103
  afterEmit: new tapable.AsyncSeriesHook(["compilation"]),
105
- thisCompilation: new tapable.SyncHook([
106
- "compilation",
107
- "params"
108
- ]),
104
+ thisCompilation: new liteTapable.SyncHook(["compilation", "params"]),
109
105
  compilation: new liteTapable.SyncHook([
110
106
  "compilation",
111
107
  "params"
@@ -346,7 +342,7 @@ class Compiler {
346
342
  if (err) {
347
343
  return finalCallback(err);
348
344
  }
349
- this.build(err => {
345
+ this.compile(err => {
350
346
  if (err) {
351
347
  return finalCallback(err);
352
348
  }
@@ -386,8 +382,7 @@ class Compiler {
386
382
  return callback === null || callback === void 0 ? void 0 : callback(error);
387
383
  }
388
384
  if (!this.first) {
389
- const rebuild = instance.unsafe_rebuild.bind(instance);
390
- rebuild(Array.from(this.modifiedFiles || []), Array.from(this.removedFiles || []), error => {
385
+ instance.rebuild(Array.from(this.modifiedFiles || []), Array.from(this.removedFiles || []), error => {
391
386
  if (error) {
392
387
  return callback === null || callback === void 0 ? void 0 : callback(error);
393
388
  }
@@ -396,8 +391,7 @@ class Compiler {
396
391
  return;
397
392
  }
398
393
  this.first = false;
399
- const build = instance.unsafe_build.bind(instance);
400
- build(error => {
394
+ instance.build(error => {
401
395
  if (error) {
402
396
  return callback === null || callback === void 0 ? void 0 : callback(error);
403
397
  }
@@ -414,8 +408,7 @@ class Compiler {
414
408
  if (error) {
415
409
  return callback === null || callback === void 0 ? void 0 : callback(error);
416
410
  }
417
- const rebuild = instance.unsafe_rebuild.bind(instance);
418
- rebuild(Array.from(modifiedFiles || []), Array.from(removedFiles || []), error => {
411
+ instance.rebuild(Array.from(modifiedFiles || []), Array.from(removedFiles || []), error => {
419
412
  if (error) {
420
413
  return callback === null || callback === void 0 ? void 0 : callback(error);
421
414
  }
@@ -425,11 +418,13 @@ class Compiler {
425
418
  }
426
419
  compile(callback) {
427
420
  const startTime = Date.now();
428
- this.hooks.beforeCompile.callAsync(void 0, (err) => {
421
+ const params = __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_newCompilationParams).call(this);
422
+ this.hooks.beforeCompile.callAsync(params, (err) => {
429
423
  if (err) {
430
424
  return callback(err);
431
425
  }
432
- this.hooks.compile.call([]);
426
+ this.hooks.compile.call(params);
427
+ __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_resetThisCompilation).call(this);
433
428
  this.build(err => {
434
429
  if (err) {
435
430
  return callback(err);
@@ -462,14 +457,6 @@ class Compiler {
462
457
  }
463
458
  }
464
459
  close(callback) {
465
- // WARNING: Arbitrarily dropping the instance is not safe, as it may still be in use by the background thread.
466
- // A hint is necessary for the compiler to know when it is safe to drop the instance.
467
- // For example: register a callback to the background thread, and drop the instance when the callback is called (calling the `close` method queues the signal)
468
- // See: https://github.com/webpack/webpack/blob/4ba225225b1348c8776ca5b5fe53468519413bc0/lib/Compiler.js#L1218
469
- if (!this.running) {
470
- // Manually drop the instance.
471
- // this.#instance = undefined;
472
- }
473
460
  if (this.watching) {
474
461
  // When there is still an active watching, close this first
475
462
  this.watching.close(() => {
@@ -516,19 +503,11 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
516
503
  const rawOptions = (0, config_1.getRawOptions)(options, this);
517
504
  const instanceBinding = require("@rspack/binding");
518
505
  __classPrivateFieldSet(this, _Compiler_instance, new instanceBinding.Rspack(rawOptions, this.builtinPlugins, {
519
- beforeCompile: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_beforeCompile).bind(this),
520
- afterCompile: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_afterCompile).bind(this),
521
506
  finishMake: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_finishMake).bind(this),
522
- shouldEmit: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_shouldEmit).bind(this),
523
507
  emit: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_emit).bind(this),
524
508
  assetEmitted: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_assetEmitted).bind(this),
525
509
  afterEmit: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_afterEmit).bind(this),
526
510
  afterProcessAssets: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_afterProcessAssets).bind(this),
527
- // `Compilation` should be created with hook `thisCompilation`, and here is the reason:
528
- // We know that the hook `thisCompilation` will not be called from a child compiler(it doesn't matter whether the child compiler is created on the Rust or the Node side).
529
- // See webpack's API: https://webpack.js.org/api/compiler-hooks/#thiscompilation
530
- // So it is safe to create a new compilation here.
531
- thisCompilation: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_newCompilation).bind(this),
532
511
  optimizeModules: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_optimizeModules).bind(this),
533
512
  afterOptimizeModules: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_afterOptimizeModules).bind(this),
534
513
  optimizeTree: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_optimizeTree).bind(this),
@@ -536,30 +515,92 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
536
515
  finishModules: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_finishModules).bind(this),
537
516
  normalModuleFactoryCreateModule: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_normalModuleFactoryCreateModule).bind(this),
538
517
  normalModuleFactoryResolveForScheme: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_normalModuleFactoryResolveForScheme).bind(this),
539
- chunkAsset: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_chunkAsset).bind(this),
540
- beforeResolve: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_beforeResolve).bind(this),
541
518
  afterResolve: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_afterResolve).bind(this),
542
519
  contextModuleFactoryBeforeResolve: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_contextModuleFactoryBeforeResolve).bind(this),
543
- contextModuleFactoryAfterResolve: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_contextModuleFactoryAfterResolve).bind(this),
544
- succeedModule: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_succeedModule).bind(this),
545
- stillValidModule: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_stillValidModule).bind(this),
546
- buildModule: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_buildModule).bind(this),
547
- executeModule: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_executeModule).bind(this),
548
- runtimeModule: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_runtimeModule).bind(this)
520
+ contextModuleFactoryAfterResolve: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_contextModuleFactoryAfterResolve).bind(this)
549
521
  }, {
550
- registerCompilerCompilationTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_registerCompilerCompilationTaps).bind(this),
551
- registerCompilerMakeTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_registerCompilerMakeTaps).bind(this),
552
- registerCompilationProcessAssetsTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_registerCompilationProcessAssetsTaps).bind(this)
553
- }, (0, fileSystem_1.createThreadsafeNodeFSFromRaw)(this.outputFileSystem), loader_runner_1.runLoaders.bind(undefined, this)), "f");
522
+ registerCompilerThisCompilationTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createRegisterTaps).call(this, () => this.hooks.thisCompilation, queried => (native) => {
523
+ if (this.compilation === undefined) {
524
+ __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createCompilation).call(this, native);
525
+ }
526
+ queried.call(this.compilation, this.compilationParams);
527
+ }),
528
+ registerCompilerCompilationTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createRegisterTaps).call(this, () => this.hooks.compilation, queried => () => queried.call(this.compilation, this.compilationParams)),
529
+ registerCompilerMakeTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createRegisterTaps).call(this, () => this.hooks.make, queried => async () => await queried.promise(this.compilation)),
530
+ registerCompilerShouldEmitTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createRegisterTaps).call(this, () => this.hooks.shouldEmit, queried => () => queried.call(this.compilation)),
531
+ registerCompilationRuntimeModuleTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createRegisterTaps).call(this, () => this.compilation.hooks.runtimeModule, queried => ({ module, chunk }) => {
532
+ var _a, _b;
533
+ const originSource = (_a = module.source) === null || _a === void 0 ? void 0 : _a.source;
534
+ queried.call(module, Chunk_1.Chunk.__from_binding(chunk, this.compilation));
535
+ const newSource = (_b = module.source) === null || _b === void 0 ? void 0 : _b.source;
536
+ if (newSource && newSource !== originSource) {
537
+ return module;
538
+ }
539
+ return;
540
+ }),
541
+ registerCompilationBuildModuleTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createRegisterTaps).call(this, () => this.compilation.hooks.buildModule, queired => (m) => queired.call(Module_1.Module.__from_binding(m))),
542
+ registerCompilationStillValidModuleTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createRegisterTaps).call(this, () => this.compilation.hooks.stillValidModule, queired => (m) => queired.call(Module_1.Module.__from_binding(m))),
543
+ registerCompilationSucceedModuleTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createRegisterTaps).call(this, () => this.compilation.hooks.succeedModule, queired => (m) => queired.call(Module_1.Module.__from_binding(m))),
544
+ registerCompilationExecuteModuleTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createRegisterTaps).call(this, () => this.compilation.hooks.executeModule, queried => ({ entry, id, codegenResults, runtimeModules }) => {
545
+ const __webpack_require__ = (id) => {
546
+ const cached = moduleCache[id];
547
+ if (cached !== undefined) {
548
+ if (cached.error)
549
+ throw cached.error;
550
+ return cached.exports;
551
+ }
552
+ var execOptions = {
553
+ id,
554
+ module: {
555
+ id,
556
+ exports: {},
557
+ loaded: false,
558
+ error: undefined
559
+ },
560
+ require: __webpack_require__
561
+ };
562
+ interceptModuleExecution.forEach((handler) => handler(execOptions));
563
+ const result = codegenResults.map[id]["build time"];
564
+ const moduleObject = execOptions.module;
565
+ if (id)
566
+ moduleCache[id] = moduleObject;
567
+ (0, HookWebpackError_1.tryRunOrWebpackError)(() => queried.call({
568
+ codeGenerationResult: new Module_1.CodeGenerationResult(result),
569
+ moduleObject
570
+ }, { __webpack_require__ }), "Compilation.hooks.executeModule");
571
+ moduleObject.loaded = true;
572
+ return moduleObject.exports;
573
+ };
574
+ const moduleCache = (__webpack_require__[RuntimeGlobals_1.RuntimeGlobals.moduleCache.replace(`${RuntimeGlobals_1.RuntimeGlobals.require}.`, "")] = {});
575
+ const interceptModuleExecution = (__webpack_require__[RuntimeGlobals_1.RuntimeGlobals.interceptModuleExecution.replace(`${RuntimeGlobals_1.RuntimeGlobals.require}.`, "")] = []);
576
+ for (const runtimeModule of runtimeModules) {
577
+ __webpack_require__(runtimeModule);
578
+ }
579
+ const executeResult = __webpack_require__(entry);
580
+ __classPrivateFieldGet(this, _Compiler_moduleExecutionResultsMap, "f").set(id, executeResult);
581
+ }),
582
+ registerCompilationChunkAssetTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createRegisterTaps).call(this, () => this.compilation.hooks.chunkAsset, queried => ({ chunk, filename }) => queried.call(Chunk_1.Chunk.__from_binding(chunk, this.compilation), filename)),
583
+ registerCompilationProcessAssetsTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createRegisterTaps).call(this, () => this.compilation.hooks.processAssets, queried => async () => await queried.promise(this.compilation.assets)),
584
+ registerNormalModuleFactoryBeforeResolveTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createRegisterTaps).call(this, () => this.compilationParams.normalModuleFactory.hooks.beforeResolve, queried => async (resolveData) => {
585
+ const normalizedResolveData = {
586
+ request: resolveData.request,
587
+ context: resolveData.context,
588
+ fileDependencies: [],
589
+ missingDependencies: [],
590
+ contextDependencies: []
591
+ };
592
+ const ret = await queried.promise(normalizedResolveData);
593
+ resolveData.request = normalizedResolveData.request;
594
+ resolveData.context = normalizedResolveData.context;
595
+ return [ret, resolveData];
596
+ })
597
+ }, (0, fileSystem_1.createThreadsafeNodeFSFromRaw)(this.outputFileSystem)), "f");
554
598
  callback(null, __classPrivateFieldGet(this, _Compiler_instance, "f"));
555
599
  }, _Compiler_updateDisabledHooks = function _Compiler_updateDisabledHooks(callback) {
556
- var _a, _b, _c, _d, _e, _f;
600
+ var _a, _b, _c, _d, _e;
557
601
  const disabledHooks = [];
558
602
  const hookMap = {
559
- beforeCompile: this.hooks.beforeCompile,
560
- afterCompile: this.hooks.afterCompile,
561
603
  finishMake: this.hooks.finishMake,
562
- shouldEmit: this.hooks.shouldEmit,
563
604
  emit: this.hooks.emit,
564
605
  assetEmitted: this.hooks.assetEmitted,
565
606
  afterEmit: this.hooks.afterEmit,
@@ -568,22 +609,12 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
568
609
  finishModules: this.compilation.hooks.finishModules,
569
610
  optimizeModules: this.compilation.hooks.optimizeModules,
570
611
  afterOptimizeModules: this.compilation.hooks.afterOptimizeModules,
571
- chunkAsset: this.compilation.hooks.chunkAsset,
572
- beforeResolve: (_a = this.compilation.normalModuleFactory) === null || _a === void 0 ? void 0 : _a.hooks.beforeResolve,
573
- afterResolve: (_b = this.compilation.normalModuleFactory) === null || _b === void 0 ? void 0 : _b.hooks.afterResolve,
574
- succeedModule: this.compilation.hooks.succeedModule,
575
- stillValidModule: this.compilation.hooks.stillValidModule,
576
- buildModule: this.compilation.hooks.buildModule,
577
- // various of hooks are called inside `#newCompilation`, we shouldn't prevent `#newCompilation` from calling even when `thisCompilation` is not tapped.
578
- // issue: https://github.com/web-infra-dev/rspack/issues/5398
579
- thisCompilation: undefined,
612
+ afterResolve: (_a = this.compilationParams) === null || _a === void 0 ? void 0 : _a.normalModuleFactory.hooks.afterResolve,
580
613
  optimizeChunkModules: this.compilation.hooks.optimizeChunkModules,
581
- contextModuleFactoryBeforeResolve: (_c = this.compilation.contextModuleFactory) === null || _c === void 0 ? void 0 : _c.hooks.beforeResolve,
582
- contextModuleFactoryAfterResolve: (_d = this.compilation.contextModuleFactory) === null || _d === void 0 ? void 0 : _d.hooks.afterResolve,
583
- normalModuleFactoryCreateModule: (_e = this.compilation.normalModuleFactory) === null || _e === void 0 ? void 0 : _e.hooks.createModule,
584
- normalModuleFactoryResolveForScheme: (_f = this.compilation.normalModuleFactory) === null || _f === void 0 ? void 0 : _f.hooks.resolveForScheme,
585
- executeModule: undefined,
586
- runtimeModule: this.compilation.hooks.runtimeModule
614
+ contextModuleFactoryBeforeResolve: (_b = this.compilationParams) === null || _b === void 0 ? void 0 : _b.contextModuleFactory.hooks.beforeResolve,
615
+ contextModuleFactoryAfterResolve: (_c = this.compilationParams) === null || _c === void 0 ? void 0 : _c.contextModuleFactory.hooks.afterResolve,
616
+ normalModuleFactoryCreateModule: (_d = this.compilationParams) === null || _d === void 0 ? void 0 : _d.normalModuleFactory.hooks.createModule,
617
+ normalModuleFactoryResolveForScheme: (_e = this.compilationParams) === null || _e === void 0 ? void 0 : _e.normalModuleFactory.hooks.resolveForScheme
587
618
  };
588
619
  for (const [name, hook] of Object.entries(hookMap)) {
589
620
  if (typeof hook !== "undefined" &&
@@ -601,44 +632,18 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
601
632
  if (error) {
602
633
  return callback === null || callback === void 0 ? void 0 : callback(error);
603
634
  }
604
- instance.unsafe_set_disabled_hooks(disabledHooks);
635
+ instance.setDisabledHooks(disabledHooks);
605
636
  __classPrivateFieldSet(this, _Compiler_disabledHooks, disabledHooks, "f");
606
637
  });
607
638
  }
608
- }, _Compiler_beforeCompile = async function _Compiler_beforeCompile() {
609
- await this.hooks.beforeCompile.promise();
610
- // compilation is not created yet, so this will fail
611
- // this.#updateDisabledHooks();
612
- }, _Compiler_afterCompile = async function _Compiler_afterCompile() {
613
- await this.hooks.afterCompile.promise(this.compilation);
614
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
615
639
  }, _Compiler_finishMake = async function _Compiler_finishMake() {
616
640
  await this.hooks.finishMake.promise(this.compilation);
617
641
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
618
- }, _Compiler_buildModule = async function _Compiler_buildModule(module) {
619
- const normalized = (0, normalization_1.normalizeJsModule)(module);
620
- this.compilation.hooks.buildModule.call(normalized);
621
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
622
642
  }, _Compiler_afterProcessAssets = async function _Compiler_afterProcessAssets() {
623
643
  await this.compilation.hooks.afterProcessAssets.promise(this.compilation.assets);
624
644
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
625
- }, _Compiler_beforeResolve = async function _Compiler_beforeResolve(resolveData) {
626
- var _a;
627
- const normalizedResolveData = {
628
- request: resolveData.request,
629
- context: resolveData.context,
630
- fileDependencies: [],
631
- missingDependencies: [],
632
- contextDependencies: []
633
- };
634
- let ret = await ((_a = this.compilation.normalModuleFactory) === null || _a === void 0 ? void 0 : _a.hooks.beforeResolve.promise(normalizedResolveData));
635
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
636
- resolveData.request = normalizedResolveData.request;
637
- resolveData.context = normalizedResolveData.context;
638
- return [ret, resolveData];
639
645
  }, _Compiler_afterResolve = async function _Compiler_afterResolve(resolveData) {
640
- var _a;
641
- let res = await ((_a = this.compilation.normalModuleFactory) === null || _a === void 0 ? void 0 : _a.hooks.afterResolve.promise(resolveData));
646
+ let res = await this.compilationParams.normalModuleFactory.hooks.afterResolve.promise(resolveData);
642
647
  NormalModule_1.NormalModule.getCompilationHooks(this.compilation).loader.tap("sideEffectFreePropPlugin", (loaderContext) => {
643
648
  loaderContext._module = {
644
649
  factoryMeta: {
@@ -647,29 +652,25 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
647
652
  };
648
653
  });
649
654
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
650
- return res;
655
+ return [res, resolveData.createData];
651
656
  }, _Compiler_contextModuleFactoryBeforeResolve = async function _Compiler_contextModuleFactoryBeforeResolve(resourceData) {
652
- var _a;
653
- let res = await ((_a = this.compilation.contextModuleFactory) === null || _a === void 0 ? void 0 : _a.hooks.beforeResolve.promise(resourceData));
657
+ let res = await this.compilationParams.contextModuleFactory.hooks.beforeResolve.promise(resourceData);
654
658
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
655
659
  return res;
656
660
  }, _Compiler_contextModuleFactoryAfterResolve = async function _Compiler_contextModuleFactoryAfterResolve(resourceData) {
657
- var _a;
658
- let res = await ((_a = this.compilation.contextModuleFactory) === null || _a === void 0 ? void 0 : _a.hooks.afterResolve.promise(resourceData));
661
+ let res = await this.compilationParams.contextModuleFactory.hooks.afterResolve.promise(resourceData);
659
662
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
660
663
  return res;
661
664
  }, _Compiler_normalModuleFactoryCreateModule = async function _Compiler_normalModuleFactoryCreateModule(createData) {
662
- var _a;
663
665
  const data = Object.assign({}, createData, {
664
666
  settings: {},
665
667
  matchResource: createData.resourceResolveData.resource
666
668
  });
667
- const nmfHooks = (_a = this.compilation.normalModuleFactory) === null || _a === void 0 ? void 0 : _a.hooks;
669
+ const nmfHooks = this.compilationParams.normalModuleFactory.hooks;
668
670
  await (nmfHooks === null || nmfHooks === void 0 ? void 0 : nmfHooks.createModule.promise(data, {}));
669
671
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
670
672
  }, _Compiler_normalModuleFactoryResolveForScheme = async function _Compiler_normalModuleFactoryResolveForScheme(input) {
671
- var _a;
672
- let stop = await ((_a = this.compilation.normalModuleFactory) === null || _a === void 0 ? void 0 : _a.hooks.resolveForScheme.for(input.scheme).promise(input.resourceData));
673
+ let stop = await this.compilationParams.normalModuleFactory.hooks.resolveForScheme.for(input.scheme).promise(input.resourceData);
673
674
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
674
675
  return {
675
676
  resourceData: input.resourceData,
@@ -687,16 +688,9 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
687
688
  }, _Compiler_afterOptimizeModules = async function _Compiler_afterOptimizeModules() {
688
689
  await this.compilation.hooks.afterOptimizeModules.promise(this.compilation.modules);
689
690
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
690
- }, _Compiler_chunkAsset = function _Compiler_chunkAsset(assetArg) {
691
- this.compilation.hooks.chunkAsset.call(assetArg.chunk, assetArg.filename);
692
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
693
691
  }, _Compiler_finishModules = async function _Compiler_finishModules() {
694
692
  await this.compilation.hooks.finishModules.promise(this.compilation.modules);
695
693
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
696
- }, _Compiler_shouldEmit = async function _Compiler_shouldEmit() {
697
- const res = this.hooks.shouldEmit.call(this.compilation);
698
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
699
- return Promise.resolve(res);
700
694
  }, _Compiler_emit = async function _Compiler_emit() {
701
695
  await this.hooks.emit.promise(this.compilation);
702
696
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
@@ -720,147 +714,69 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
720
714
  }, _Compiler_afterEmit = async function _Compiler_afterEmit() {
721
715
  await this.hooks.afterEmit.promise(this.compilation);
722
716
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
723
- }, _Compiler_succeedModule = function _Compiler_succeedModule(module) {
724
- this.compilation.hooks.succeedModule.call(module);
725
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
726
- }, _Compiler_stillValidModule = function _Compiler_stillValidModule(module) {
727
- this.compilation.hooks.stillValidModule.call(module);
728
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
729
- }, _Compiler_runtimeModule = function _Compiler_runtimeModule(arg) {
730
- var _a, _b;
731
- let { module, chunk } = arg;
732
- const originSource = (_a = module.source) === null || _a === void 0 ? void 0 : _a.source;
733
- this.compilation.hooks.runtimeModule.call(module, chunk);
734
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
735
- const newSource = (_b = module.source) === null || _b === void 0 ? void 0 : _b.source;
736
- if (newSource && newSource !== originSource) {
737
- return module;
738
- }
739
- return;
740
- }, _Compiler_executeModule = async function _Compiler_executeModule({ entry, request, options, runtimeModules, codegenResults, id }) {
741
- const __webpack_require__ = (id) => {
742
- const cached = moduleCache[id];
743
- if (cached !== undefined) {
744
- if (cached.error)
745
- throw cached.error;
746
- return cached.exports;
747
- }
748
- var execOptions = {
749
- id,
750
- module: {
751
- id,
752
- exports: {},
753
- loaded: false,
754
- error: undefined
755
- },
756
- require: __webpack_require__
757
- };
758
- interceptModuleExecution.forEach((handler) => handler(execOptions));
759
- const result = codegenResults.map[id]["build time"];
760
- const moduleObject = execOptions.module;
761
- if (id)
762
- moduleCache[id] = moduleObject;
763
- (0, HookWebpackError_1.tryRunOrWebpackError)(() => this.compilation.hooks.executeModule.call({
764
- codeGenerationResult: new Module_1.CodeGenerationResult(result),
765
- moduleObject
766
- }, { __webpack_require__ }), "Compilation.hooks.executeModule");
767
- moduleObject.loaded = true;
768
- return moduleObject.exports;
769
- };
770
- const moduleCache = (__webpack_require__[RuntimeGlobals_1.RuntimeGlobals.moduleCache.replace(`${RuntimeGlobals_1.RuntimeGlobals.require}.`, "")] = {});
771
- const interceptModuleExecution = (__webpack_require__[RuntimeGlobals_1.RuntimeGlobals.interceptModuleExecution.replace(`${RuntimeGlobals_1.RuntimeGlobals.require}.`, "")] = []);
772
- for (const runtimeModule of runtimeModules) {
773
- __webpack_require__(runtimeModule);
774
- }
775
- const executeResult = __webpack_require__(entry);
776
- __classPrivateFieldGet(this, _Compiler_moduleExecutionResultsMap, "f").set(id, executeResult);
777
717
  }, _Compiler_decorateUpdateDisabledHooks = function _Compiler_decorateUpdateDisabledHooks(jsTaps) {
778
718
  if (jsTaps.length > 0) {
779
719
  const last = jsTaps[jsTaps.length - 1];
780
720
  const old = last.function;
781
- last.function = async () => {
782
- await old();
721
+ last.function = (...args) => {
722
+ const result = old(...args);
723
+ if (result && typeof result.then === "function") {
724
+ return result.then((r) => {
725
+ __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
726
+ return r;
727
+ });
728
+ }
783
729
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
730
+ return result;
784
731
  };
785
732
  }
786
- }, _Compiler_registerCompilerCompilationTaps = function _Compiler_registerCompilerCompilationTaps(stages) {
787
- if (!this.hooks.compilation.isUsed())
788
- return [];
789
- const breakpoints = [liteTapable.minStage, ...stages, liteTapable.maxStage];
790
- const jsTaps = [];
791
- for (let i = 0; i < breakpoints.length - 1; i++) {
792
- const from = breakpoints[i];
793
- const to = breakpoints[i + 1];
794
- const stageRange = [from, to];
795
- const queried = this.hooks.compilation.queryStageRange(stageRange);
796
- if (!queried.isUsed())
797
- continue;
798
- jsTaps.push({
799
- function: () => {
800
- queried.call(this.compilation, {
801
- normalModuleFactory: this.compilation.normalModuleFactory
802
- });
803
- },
804
- stage: liteTapable.safeStage(from + 1)
805
- });
806
- }
807
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_decorateUpdateDisabledHooks).call(this, jsTaps);
808
- return jsTaps;
809
- }, _Compiler_registerCompilerMakeTaps = function _Compiler_registerCompilerMakeTaps(stages) {
810
- if (!this.hooks.make.isUsed())
811
- return [];
812
- const breakpoints = [liteTapable.minStage, ...stages, liteTapable.maxStage];
813
- const jsTaps = [];
814
- for (let i = 0; i < breakpoints.length - 1; i++) {
815
- const from = breakpoints[i];
816
- const to = breakpoints[i + 1];
817
- const stageRange = [from, to];
818
- const queried = this.hooks.make.queryStageRange(stageRange);
819
- if (!queried.isUsed())
820
- continue;
821
- jsTaps.push({
822
- function: async () => {
823
- await queried.promise(this.compilation);
824
- },
825
- stage: liteTapable.safeStage(from + 1)
826
- });
827
- }
828
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_decorateUpdateDisabledHooks).call(this, jsTaps);
829
- return jsTaps;
830
- }, _Compiler_registerCompilationProcessAssetsTaps = function _Compiler_registerCompilationProcessAssetsTaps(stages) {
831
- if (!this.compilation.hooks.processAssets.isUsed())
832
- return [];
833
- const breakpoints = [liteTapable.minStage, ...stages, liteTapable.maxStage];
834
- const jsTaps = [];
835
- for (let i = 0; i < breakpoints.length - 1; i++) {
836
- const from = breakpoints[i];
837
- const to = breakpoints[i + 1];
838
- const stageRange = [from, to];
839
- const queried = this.compilation.hooks.processAssets.queryStageRange(stageRange);
840
- if (!queried.isUsed())
841
- continue;
842
- jsTaps.push({
843
- function: async () => {
844
- await queried.promise(this.compilation.assets);
845
- },
846
- stage: liteTapable.safeStage(from + 1)
847
- });
848
- }
849
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_decorateUpdateDisabledHooks).call(this, jsTaps);
850
- return jsTaps;
851
- }, _Compiler_newCompilation = function _Compiler_newCompilation(native) {
733
+ }, _Compiler_createRegisterTaps = function _Compiler_createRegisterTaps(getHook, createTap) {
734
+ return stages => {
735
+ const hook = getHook();
736
+ if (!hook.isUsed())
737
+ return [];
738
+ const breakpoints = [
739
+ liteTapable.minStage,
740
+ ...stages,
741
+ liteTapable.maxStage
742
+ ];
743
+ const jsTaps = [];
744
+ for (let i = 0; i < breakpoints.length - 1; i++) {
745
+ const from = breakpoints[i];
746
+ const to = breakpoints[i + 1];
747
+ const stageRange = [from, to];
748
+ const queried = hook.queryStageRange(stageRange);
749
+ if (!queried.isUsed())
750
+ continue;
751
+ jsTaps.push({
752
+ function: createTap(queried),
753
+ stage: liteTapable.safeStage(from + 1)
754
+ });
755
+ }
756
+ __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_decorateUpdateDisabledHooks).call(this, jsTaps);
757
+ return jsTaps;
758
+ };
759
+ }, _Compiler_createCompilation = function _Compiler_createCompilation(native) {
852
760
  const compilation = new Compilation_1.Compilation(this, native);
853
761
  compilation.name = this.name;
854
762
  this.compilation = compilation;
855
- // reset normalModuleFactory when create new compilation
856
- let normalModuleFactory = new NormalModuleFactory_1.NormalModuleFactory();
857
- let contextModuleFactory = new ContextModuleFactory_1.ContextModuleFactory();
858
- this.compilation.normalModuleFactory = normalModuleFactory;
763
+ return compilation;
764
+ }, _Compiler_resetThisCompilation = function _Compiler_resetThisCompilation() {
765
+ // reassign new compilation in thisCompilation
766
+ this.compilation = undefined;
767
+ // ensure thisCompilation must call
768
+ this.hooks.thisCompilation.intercept({
769
+ call: () => { }
770
+ });
771
+ }, _Compiler_newCompilationParams = function _Compiler_newCompilationParams() {
772
+ const normalModuleFactory = new NormalModuleFactory_1.NormalModuleFactory();
859
773
  this.hooks.normalModuleFactory.call(normalModuleFactory);
860
- this.compilation.contextModuleFactory = contextModuleFactory;
774
+ const contextModuleFactory = new ContextModuleFactory_1.ContextModuleFactory();
861
775
  this.hooks.contextModuleFactory.call(contextModuleFactory);
862
- this.hooks.thisCompilation.call(this.compilation, {
863
- normalModuleFactory: normalModuleFactory
864
- });
865
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
776
+ const params = {
777
+ normalModuleFactory,
778
+ contextModuleFactory
779
+ };
780
+ this.compilationParams = params;
781
+ return params;
866
782
  };
package/dist/Module.d.ts CHANGED
@@ -1,10 +1,13 @@
1
1
  import { JsCodegenerationResult, JsCodegenerationResults, JsModule } from "@rspack/binding";
2
+ import { Source } from "webpack-sources";
2
3
  export declare class Module {
3
4
  #private;
5
+ _originalSource?: Source;
4
6
  static __from_binding(module: JsModule): Module;
5
7
  constructor(module: JsModule);
6
8
  get context(): string | undefined;
7
9
  get resource(): string | undefined;
10
+ get originalSource(): Source | null;
8
11
  identifier(): string;
9
12
  nameForCondition(): string | null;
10
13
  }
package/dist/Module.js CHANGED
@@ -13,6 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
13
13
  var _Module_inner, _CodeGenerationResult_inner, _CodeGenerationResults_inner;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.CodeGenerationResults = exports.CodeGenerationResult = exports.Module = void 0;
16
+ const createSource_1 = require("./util/createSource");
16
17
  class Module {
17
18
  static __from_binding(module) {
18
19
  return new Module(module);
@@ -27,6 +28,17 @@ class Module {
27
28
  get resource() {
28
29
  return __classPrivateFieldGet(this, _Module_inner, "f").resource;
29
30
  }
31
+ get originalSource() {
32
+ if (this._originalSource)
33
+ return this._originalSource;
34
+ if (__classPrivateFieldGet(this, _Module_inner, "f").originalSource) {
35
+ this._originalSource = (0, createSource_1.createSourceFromRaw)(__classPrivateFieldGet(this, _Module_inner, "f").originalSource);
36
+ return this._originalSource;
37
+ }
38
+ else {
39
+ return null;
40
+ }
41
+ }
30
42
  identifier() {
31
43
  return __classPrivateFieldGet(this, _Module_inner, "f").moduleIdentifier;
32
44
  }