@rspack/core 0.5.7-canary-6007430-20240313111541 → 0.5.7-canary-9e2ce60-20240320055406

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 (33) hide show
  1. package/dist/Compilation.d.ts +2 -3
  2. package/dist/Compilation.js +4 -2
  3. package/dist/Compiler.d.ts +11 -10
  4. package/dist/Compiler.js +110 -167
  5. package/dist/MultiCompiler.js +2 -2
  6. package/dist/NormalModuleFactory.d.ts +2 -1
  7. package/dist/NormalModuleFactory.js +25 -1
  8. package/dist/Watching.d.ts +1 -0
  9. package/dist/Watching.js +5 -2
  10. package/dist/builtin-plugin/JsLoaderRspackPlugin.d.ts +11 -0
  11. package/dist/builtin-plugin/JsLoaderRspackPlugin.js +7 -0
  12. package/dist/builtin-plugin/base.js +1 -1
  13. package/dist/builtin-plugin/index.d.ts +2 -0
  14. package/dist/builtin-plugin/index.js +2 -0
  15. package/dist/builtin-plugin/lazy-compilation/backend.d.ts +52 -0
  16. package/dist/builtin-plugin/lazy-compilation/backend.js +143 -0
  17. package/dist/builtin-plugin/lazy-compilation/lazyCompilation.d.ts +30 -0
  18. package/dist/builtin-plugin/lazy-compilation/lazyCompilation.js +6 -0
  19. package/dist/builtin-plugin/lazy-compilation/plugin.d.ts +13 -0
  20. package/dist/builtin-plugin/lazy-compilation/plugin.js +60 -0
  21. package/dist/config/adapter.js +9 -8
  22. package/dist/config/normalization.d.ts +2 -2
  23. package/dist/config/normalization.js +2 -1
  24. package/dist/config/zod.d.ts +435 -88
  25. package/dist/config/zod.js +16 -3
  26. package/dist/exports.d.ts +34 -10
  27. package/dist/lite-tapable/index.d.ts +14 -1
  28. package/dist/lite-tapable/index.js +168 -1
  29. package/dist/loader-runner/index.d.ts +2 -2
  30. package/dist/loader-runner/index.js +4 -4
  31. package/dist/node/NodeWatchFileSystem.d.ts +1 -2
  32. package/dist/rspackOptionsApply.js +13 -1
  33. package/package.json +5 -5
@@ -36,12 +36,13 @@ export interface Asset {
36
36
  }
37
37
  export interface LogEntry {
38
38
  type: string;
39
- args?: any[];
39
+ args: any[];
40
40
  time?: number;
41
41
  trace?: string[];
42
42
  }
43
43
  export interface CompilationParams {
44
44
  normalModuleFactory: NormalModuleFactory;
45
+ contextModuleFactory: ContextModuleFactory;
45
46
  }
46
47
  export interface KnownCreateStatsOptionsContext {
47
48
  forToString?: boolean;
@@ -101,9 +102,7 @@ export declare class Compilation {
101
102
  childrenCounters: Record<string, number>;
102
103
  startTime?: number;
103
104
  endTime?: number;
104
- normalModuleFactory?: NormalModuleFactory;
105
105
  children: Compilation[];
106
- contextModuleFactory?: ContextModuleFactory;
107
106
  chunkGraph: ChunkGraph;
108
107
  fileSystemInfo: {
109
108
  createSnapshot(): null;
@@ -473,12 +473,14 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
473
473
  const logEntry = {
474
474
  time: Date.now(),
475
475
  type,
476
+ // @ts-expect-error
476
477
  args,
478
+ // @ts-expect-error
477
479
  trace
478
480
  };
479
481
  if (this.hooks.log.call(name, logEntry) === undefined) {
480
482
  if (logEntry.type === Logger_1.LogType.profileEnd) {
481
- if (typeof console.profileEnd === "function" && logEntry.args) {
483
+ if (typeof console.profileEnd === "function") {
482
484
  console.profileEnd(`[${name}] ${logEntry.args[0]}`);
483
485
  }
484
486
  }
@@ -491,7 +493,7 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
491
493
  }
492
494
  logEntries.push(logEntry);
493
495
  if (logEntry.type === Logger_1.LogType.profile) {
494
- if (typeof console.profile === "function" && logEntry.args) {
496
+ if (typeof console.profile === "function") {
495
497
  console.profile(`[${name}] ${logEntry.args[0]}`);
496
498
  }
497
499
  }
@@ -12,7 +12,7 @@ import * as binding from "@rspack/binding";
12
12
  import * as tapable from "tapable";
13
13
  import * as liteTapable from "./lite-tapable";
14
14
  import { Callback } from "tapable";
15
- import { WatchOptions } from "./config";
15
+ import type { WatchOptions } from "watchpack";
16
16
  import { EntryNormalized, OutputNormalized, RspackOptionsNormalized, RspackPluginInstance } from "./config";
17
17
  import { RuleSetCompiler } from "./RuleSetCompiler";
18
18
  import { Stats } from "./Stats";
@@ -32,7 +32,8 @@ declare class Compiler {
32
32
  rspack: typeof import("./rspack").rspack & typeof import("./exports") & any;
33
33
  webpack: typeof import("./rspack").rspack & typeof import("./exports") & any;
34
34
  };
35
- compilation: Compilation;
35
+ compilation?: Compilation;
36
+ compilationParams?: CompilationParams;
36
37
  first: boolean;
37
38
  builtinPlugins: binding.BuiltinPlugin[];
38
39
  root: Compiler;
@@ -48,26 +49,26 @@ declare class Compiler {
48
49
  ruleSet: RuleSetCompiler;
49
50
  watchFileSystem: WatchFileSystem;
50
51
  intermediateFileSystem: any;
51
- watchMode?: boolean;
52
+ watchMode: boolean;
52
53
  context: string;
53
- modifiedFiles?: ReadonlySet<string>;
54
54
  cache: Cache;
55
55
  compilerPath: string;
56
+ modifiedFiles?: ReadonlySet<string>;
56
57
  removedFiles?: ReadonlySet<string>;
57
58
  fileTimestamps?: ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>;
58
59
  contextTimestamps?: ReadonlyMap<string, FileSystemInfoEntry | "ignore" | null>;
59
60
  hooks: {
60
61
  done: tapable.AsyncSeriesHook<Stats>;
61
62
  afterDone: tapable.SyncHook<Stats>;
63
+ thisCompilation: liteTapable.SyncHook<[Compilation, CompilationParams]>;
62
64
  compilation: liteTapable.SyncHook<[Compilation, CompilationParams]>;
63
- thisCompilation: tapable.SyncHook<[Compilation, CompilationParams]>;
64
65
  invalid: tapable.SyncHook<[string | null, number]>;
65
- compile: tapable.SyncHook<[any]>;
66
+ compile: tapable.SyncHook<[CompilationParams]>;
66
67
  normalModuleFactory: tapable.SyncHook<NormalModuleFactory>;
67
68
  contextModuleFactory: tapable.SyncHook<ContextModuleFactory>;
68
69
  initialize: tapable.SyncHook<[]>;
69
- shouldEmit: tapable.SyncBailHook<[Compilation], boolean>;
70
- infrastructureLog: tapable.SyncBailHook<[string, string, any[]?], true>;
70
+ shouldEmit: liteTapable.SyncBailHook<[Compilation], boolean>;
71
+ infrastructureLog: tapable.SyncBailHook<[string, string, any[]], true>;
71
72
  beforeRun: tapable.AsyncSeriesHook<[Compiler]>;
72
73
  run: tapable.AsyncSeriesHook<[Compiler]>;
73
74
  emit: tapable.AsyncSeriesHook<[Compilation]>;
@@ -82,7 +83,7 @@ declare class Compiler {
82
83
  afterPlugins: tapable.SyncHook<[Compiler]>;
83
84
  afterResolvers: tapable.SyncHook<[Compiler]>;
84
85
  make: liteTapable.AsyncParallelHook<[Compilation]>;
85
- beforeCompile: tapable.AsyncSeriesHook<any>;
86
+ beforeCompile: tapable.AsyncSeriesHook<[CompilationParams]>;
86
87
  afterCompile: tapable.AsyncSeriesHook<[Compilation]>;
87
88
  finishModules: tapable.AsyncSeriesHook<[any]>;
88
89
  finishMake: tapable.AsyncSeriesHook<[Compilation]>;
@@ -111,7 +112,7 @@ declare class Compiler {
111
112
  */
112
113
  rebuild(modifiedFiles?: ReadonlySet<string>, removedFiles?: ReadonlySet<string>, callback?: (error: Error | null) => void): void;
113
114
  compile(callback: Callback<Error, Compilation>): void;
114
- watch(watchOptions: WatchOptions, handler: (error?: Error, stats?: Stats) => void): Watching | void;
115
+ watch(watchOptions: WatchOptions, handler: Callback<Error, Stats>): Watching;
115
116
  purgeInputFileSystem(): void;
116
117
  close(callback: (error?: Error | null) => void): void;
117
118
  getAsset(name: string): Buffer | null;
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_buildModule, _Compiler_afterProcessAssets, _Compiler_afterResolve, _Compiler_contextModuleFactoryBeforeResolve, _Compiler_contextModuleFactoryAfterResolve, _Compiler_normalModuleFactoryCreateModule, _Compiler_normalModuleFactoryResolveForScheme, _Compiler_optimizeChunkModules, _Compiler_optimizeTree, _Compiler_optimizeModules, _Compiler_afterOptimizeModules, _Compiler_chunkAsset, _Compiler_finishModules, _Compiler_emit, _Compiler_assetEmitted, _Compiler_afterEmit, _Compiler_succeedModule, _Compiler_stillValidModule, _Compiler_runtimeModule, _Compiler_executeModule, _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");
@@ -54,7 +54,6 @@ const ConcurrentCompilationError_1 = __importDefault(require("./error/Concurrent
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");
@@ -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"
@@ -259,7 +255,9 @@ class Compiler {
259
255
  }
260
256
  }
261
257
  else {
262
- if (this.hooks.infrastructureLog.call(name, type, args) === undefined) {
258
+ if (
259
+ // @ts-expect-error
260
+ this.hooks.infrastructureLog.call(name, type, args) === undefined) {
263
261
  if (this.infrastructureLogger !== undefined) {
264
262
  this.infrastructureLogger(name, type, args);
265
263
  }
@@ -268,7 +266,8 @@ class Compiler {
268
266
  }, (childName) => {
269
267
  if (typeof name === "function") {
270
268
  if (typeof childName === "function") {
271
- return this.getInfrastructureLogger(() => {
269
+ // @ts-expect-error
270
+ return this.getInfrastructureLogger(_ => {
272
271
  if (typeof name === "function") {
273
272
  name = name();
274
273
  if (!name) {
@@ -321,6 +320,7 @@ class Compiler {
321
320
  const startTime = Date.now();
322
321
  this.running = true;
323
322
  const doRun = () => {
323
+ // @ts-expect-error
324
324
  const finalCallback = (err, stats) => {
325
325
  this.idle = true;
326
326
  this.cache.beginIdle();
@@ -332,7 +332,7 @@ class Compiler {
332
332
  if (callback) {
333
333
  callback(err, stats);
334
334
  }
335
- stats && this.hooks.afterDone.call(stats);
335
+ this.hooks.afterDone.call(stats);
336
336
  };
337
337
  this.hooks.beforeRun.callAsync(this, err => {
338
338
  if (err) {
@@ -342,7 +342,7 @@ class Compiler {
342
342
  if (err) {
343
343
  return finalCallback(err);
344
344
  }
345
- this.build(err => {
345
+ this.compile(err => {
346
346
  if (err) {
347
347
  return finalCallback(err);
348
348
  }
@@ -382,8 +382,7 @@ class Compiler {
382
382
  return callback === null || callback === void 0 ? void 0 : callback(error);
383
383
  }
384
384
  if (!this.first) {
385
- const rebuild = instance.unsafe_rebuild.bind(instance);
386
- rebuild(Array.from(this.modifiedFiles || []), Array.from(this.removedFiles || []), error => {
385
+ instance.rebuild(Array.from(this.modifiedFiles || []), Array.from(this.removedFiles || []), error => {
387
386
  if (error) {
388
387
  return callback === null || callback === void 0 ? void 0 : callback(error);
389
388
  }
@@ -392,8 +391,7 @@ class Compiler {
392
391
  return;
393
392
  }
394
393
  this.first = false;
395
- const build = instance.unsafe_build.bind(instance);
396
- build(error => {
394
+ instance.build(error => {
397
395
  if (error) {
398
396
  return callback === null || callback === void 0 ? void 0 : callback(error);
399
397
  }
@@ -410,8 +408,7 @@ class Compiler {
410
408
  if (error) {
411
409
  return callback === null || callback === void 0 ? void 0 : callback(error);
412
410
  }
413
- const rebuild = instance.unsafe_rebuild.bind(instance);
414
- rebuild(Array.from(modifiedFiles || []), Array.from(removedFiles || []), error => {
411
+ instance.rebuild(Array.from(modifiedFiles || []), Array.from(removedFiles || []), error => {
415
412
  if (error) {
416
413
  return callback === null || callback === void 0 ? void 0 : callback(error);
417
414
  }
@@ -421,11 +418,13 @@ class Compiler {
421
418
  }
422
419
  compile(callback) {
423
420
  const startTime = Date.now();
424
- 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) => {
425
423
  if (err) {
426
424
  return callback(err);
427
425
  }
428
- this.hooks.compile.call([]);
426
+ this.hooks.compile.call(params);
427
+ __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_resetThisCompilation).call(this);
429
428
  this.build(err => {
430
429
  if (err) {
431
430
  return callback(err);
@@ -443,10 +442,12 @@ class Compiler {
443
442
  }
444
443
  watch(watchOptions, handler) {
445
444
  if (this.running) {
445
+ // @ts-expect-error
446
446
  return handler(new ConcurrentCompilationError_1.default());
447
447
  }
448
448
  this.running = true;
449
449
  this.watchMode = true;
450
+ // @ts-expect-error
450
451
  this.watching = new Watching_1.Watching(this, watchOptions, handler);
451
452
  return this.watching;
452
453
  }
@@ -456,14 +457,6 @@ class Compiler {
456
457
  }
457
458
  }
458
459
  close(callback) {
459
- // WARNING: Arbitrarily dropping the instance is not safe, as it may still be in use by the background thread.
460
- // A hint is necessary for the compiler to know when it is safe to drop the instance.
461
- // 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)
462
- // See: https://github.com/webpack/webpack/blob/4ba225225b1348c8776ca5b5fe53468519413bc0/lib/Compiler.js#L1218
463
- if (!this.running) {
464
- // Manually drop the instance.
465
- // this.#instance = undefined;
466
- }
467
460
  if (this.watching) {
468
461
  // When there is still an active watching, close this first
469
462
  this.watching.close(() => {
@@ -510,19 +503,11 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
510
503
  const rawOptions = (0, config_1.getRawOptions)(options, this);
511
504
  const instanceBinding = require("@rspack/binding");
512
505
  __classPrivateFieldSet(this, _Compiler_instance, new instanceBinding.Rspack(rawOptions, this.builtinPlugins, {
513
- beforeCompile: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_beforeCompile).bind(this),
514
- afterCompile: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_afterCompile).bind(this),
515
506
  finishMake: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_finishMake).bind(this),
516
- shouldEmit: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_shouldEmit).bind(this),
517
507
  emit: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_emit).bind(this),
518
508
  assetEmitted: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_assetEmitted).bind(this),
519
509
  afterEmit: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_afterEmit).bind(this),
520
510
  afterProcessAssets: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_afterProcessAssets).bind(this),
521
- // `Compilation` should be created with hook `thisCompilation`, and here is the reason:
522
- // 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).
523
- // See webpack's API: https://webpack.js.org/api/compiler-hooks/#thiscompilation
524
- // So it is safe to create a new compilation here.
525
- thisCompilation: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_newCompilation).bind(this),
526
511
  optimizeModules: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_optimizeModules).bind(this),
527
512
  afterOptimizeModules: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_afterOptimizeModules).bind(this),
528
513
  optimizeTree: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_optimizeTree).bind(this),
@@ -531,7 +516,6 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
531
516
  normalModuleFactoryCreateModule: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_normalModuleFactoryCreateModule).bind(this),
532
517
  normalModuleFactoryResolveForScheme: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_normalModuleFactoryResolveForScheme).bind(this),
533
518
  chunkAsset: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_chunkAsset).bind(this),
534
- beforeResolve: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_beforeResolve).bind(this),
535
519
  afterResolve: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_afterResolve).bind(this),
536
520
  contextModuleFactoryBeforeResolve: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_contextModuleFactoryBeforeResolve).bind(this),
537
521
  contextModuleFactoryAfterResolve: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_contextModuleFactoryAfterResolve).bind(this),
@@ -541,19 +525,36 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
541
525
  executeModule: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_executeModule).bind(this),
542
526
  runtimeModule: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_runtimeModule).bind(this)
543
527
  }, {
544
- registerCompilerCompilationTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_registerCompilerCompilationTaps).bind(this),
545
- registerCompilerMakeTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_registerCompilerMakeTaps).bind(this),
546
- registerCompilationProcessAssetsTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_registerCompilationProcessAssetsTaps).bind(this)
547
- }, (0, fileSystem_1.createThreadsafeNodeFSFromRaw)(this.outputFileSystem), loader_runner_1.runLoaders.bind(undefined, this)), "f");
528
+ registerCompilerThisCompilationTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createRegisterTaps).call(this, () => this.hooks.thisCompilation, queried => (native) => {
529
+ if (this.compilation === undefined) {
530
+ __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createCompilation).call(this, native);
531
+ }
532
+ queried.call(this.compilation, this.compilationParams);
533
+ }),
534
+ registerCompilerCompilationTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createRegisterTaps).call(this, () => this.hooks.compilation, queried => () => queried.call(this.compilation, this.compilationParams)),
535
+ registerCompilerMakeTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createRegisterTaps).call(this, () => this.hooks.make, queried => async () => await queried.promise(this.compilation)),
536
+ registerCompilerShouldEmitTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createRegisterTaps).call(this, () => this.hooks.shouldEmit, queried => () => queried.call(this.compilation)),
537
+ registerCompilationProcessAssetsTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createRegisterTaps).call(this, () => this.compilation.hooks.processAssets, queried => async () => await queried.promise(this.compilation.assets)),
538
+ registerNormalModuleFactoryBeforeResolveTaps: __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_createRegisterTaps).call(this, () => this.compilationParams.normalModuleFactory.hooks.beforeResolve, queried => async (resolveData) => {
539
+ const normalizedResolveData = {
540
+ request: resolveData.request,
541
+ context: resolveData.context,
542
+ fileDependencies: [],
543
+ missingDependencies: [],
544
+ contextDependencies: []
545
+ };
546
+ const ret = await queried.promise(normalizedResolveData);
547
+ resolveData.request = normalizedResolveData.request;
548
+ resolveData.context = normalizedResolveData.context;
549
+ return [ret, resolveData];
550
+ })
551
+ }, (0, fileSystem_1.createThreadsafeNodeFSFromRaw)(this.outputFileSystem)), "f");
548
552
  callback(null, __classPrivateFieldGet(this, _Compiler_instance, "f"));
549
553
  }, _Compiler_updateDisabledHooks = function _Compiler_updateDisabledHooks(callback) {
550
- var _a, _b, _c, _d, _e, _f;
554
+ var _a, _b, _c, _d, _e;
551
555
  const disabledHooks = [];
552
556
  const hookMap = {
553
- beforeCompile: this.hooks.beforeCompile,
554
- afterCompile: this.hooks.afterCompile,
555
557
  finishMake: this.hooks.finishMake,
556
- shouldEmit: this.hooks.shouldEmit,
557
558
  emit: this.hooks.emit,
558
559
  assetEmitted: this.hooks.assetEmitted,
559
560
  afterEmit: this.hooks.afterEmit,
@@ -563,19 +564,15 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
563
564
  optimizeModules: this.compilation.hooks.optimizeModules,
564
565
  afterOptimizeModules: this.compilation.hooks.afterOptimizeModules,
565
566
  chunkAsset: this.compilation.hooks.chunkAsset,
566
- beforeResolve: (_a = this.compilation.normalModuleFactory) === null || _a === void 0 ? void 0 : _a.hooks.beforeResolve,
567
- afterResolve: (_b = this.compilation.normalModuleFactory) === null || _b === void 0 ? void 0 : _b.hooks.afterResolve,
567
+ afterResolve: (_a = this.compilationParams) === null || _a === void 0 ? void 0 : _a.normalModuleFactory.hooks.afterResolve,
568
568
  succeedModule: this.compilation.hooks.succeedModule,
569
569
  stillValidModule: this.compilation.hooks.stillValidModule,
570
570
  buildModule: this.compilation.hooks.buildModule,
571
- // various of hooks are called inside `#newCompilation`, we shouldn't prevent `#newCompilation` from calling even when `thisCompilation` is not tapped.
572
- // issue: https://github.com/web-infra-dev/rspack/issues/5398
573
- thisCompilation: undefined,
574
571
  optimizeChunkModules: this.compilation.hooks.optimizeChunkModules,
575
- contextModuleFactoryBeforeResolve: (_c = this.compilation.contextModuleFactory) === null || _c === void 0 ? void 0 : _c.hooks.beforeResolve,
576
- contextModuleFactoryAfterResolve: (_d = this.compilation.contextModuleFactory) === null || _d === void 0 ? void 0 : _d.hooks.afterResolve,
577
- normalModuleFactoryCreateModule: (_e = this.compilation.normalModuleFactory) === null || _e === void 0 ? void 0 : _e.hooks.createModule,
578
- normalModuleFactoryResolveForScheme: (_f = this.compilation.normalModuleFactory) === null || _f === void 0 ? void 0 : _f.hooks.resolveForScheme,
572
+ contextModuleFactoryBeforeResolve: (_b = this.compilationParams) === null || _b === void 0 ? void 0 : _b.contextModuleFactory.hooks.beforeResolve,
573
+ contextModuleFactoryAfterResolve: (_c = this.compilationParams) === null || _c === void 0 ? void 0 : _c.contextModuleFactory.hooks.afterResolve,
574
+ normalModuleFactoryCreateModule: (_d = this.compilationParams) === null || _d === void 0 ? void 0 : _d.normalModuleFactory.hooks.createModule,
575
+ normalModuleFactoryResolveForScheme: (_e = this.compilationParams) === null || _e === void 0 ? void 0 : _e.normalModuleFactory.hooks.resolveForScheme,
579
576
  executeModule: undefined,
580
577
  runtimeModule: this.compilation.hooks.runtimeModule
581
578
  };
@@ -595,17 +592,10 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
595
592
  if (error) {
596
593
  return callback === null || callback === void 0 ? void 0 : callback(error);
597
594
  }
598
- instance.unsafe_set_disabled_hooks(disabledHooks);
595
+ instance.setDisabledHooks(disabledHooks);
599
596
  __classPrivateFieldSet(this, _Compiler_disabledHooks, disabledHooks, "f");
600
597
  });
601
598
  }
602
- }, _Compiler_beforeCompile = async function _Compiler_beforeCompile() {
603
- await this.hooks.beforeCompile.promise();
604
- // compilation is not created yet, so this will fail
605
- // this.#updateDisabledHooks();
606
- }, _Compiler_afterCompile = async function _Compiler_afterCompile() {
607
- await this.hooks.afterCompile.promise(this.compilation);
608
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
609
599
  }, _Compiler_finishMake = async function _Compiler_finishMake() {
610
600
  await this.hooks.finishMake.promise(this.compilation);
611
601
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
@@ -616,23 +606,8 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
616
606
  }, _Compiler_afterProcessAssets = async function _Compiler_afterProcessAssets() {
617
607
  await this.compilation.hooks.afterProcessAssets.promise(this.compilation.assets);
618
608
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
619
- }, _Compiler_beforeResolve = async function _Compiler_beforeResolve(resolveData) {
620
- var _a;
621
- const normalizedResolveData = {
622
- request: resolveData.request,
623
- context: resolveData.context,
624
- fileDependencies: [],
625
- missingDependencies: [],
626
- contextDependencies: []
627
- };
628
- let ret = await ((_a = this.compilation.normalModuleFactory) === null || _a === void 0 ? void 0 : _a.hooks.beforeResolve.promise(normalizedResolveData));
629
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
630
- resolveData.request = normalizedResolveData.request;
631
- resolveData.context = normalizedResolveData.context;
632
- return [ret, resolveData];
633
609
  }, _Compiler_afterResolve = async function _Compiler_afterResolve(resolveData) {
634
- var _a;
635
- let res = await ((_a = this.compilation.normalModuleFactory) === null || _a === void 0 ? void 0 : _a.hooks.afterResolve.promise(resolveData));
610
+ let res = await this.compilationParams.normalModuleFactory.hooks.afterResolve.promise(resolveData);
636
611
  NormalModule_1.NormalModule.getCompilationHooks(this.compilation).loader.tap("sideEffectFreePropPlugin", (loaderContext) => {
637
612
  loaderContext._module = {
638
613
  factoryMeta: {
@@ -641,29 +616,25 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
641
616
  };
642
617
  });
643
618
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
644
- return res;
619
+ return [res, resolveData.createData];
645
620
  }, _Compiler_contextModuleFactoryBeforeResolve = async function _Compiler_contextModuleFactoryBeforeResolve(resourceData) {
646
- var _a;
647
- let res = await ((_a = this.compilation.contextModuleFactory) === null || _a === void 0 ? void 0 : _a.hooks.beforeResolve.promise(resourceData));
621
+ let res = await this.compilationParams.contextModuleFactory.hooks.beforeResolve.promise(resourceData);
648
622
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
649
623
  return res;
650
624
  }, _Compiler_contextModuleFactoryAfterResolve = async function _Compiler_contextModuleFactoryAfterResolve(resourceData) {
651
- var _a;
652
- let res = await ((_a = this.compilation.contextModuleFactory) === null || _a === void 0 ? void 0 : _a.hooks.afterResolve.promise(resourceData));
625
+ let res = await this.compilationParams.contextModuleFactory.hooks.afterResolve.promise(resourceData);
653
626
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
654
627
  return res;
655
628
  }, _Compiler_normalModuleFactoryCreateModule = async function _Compiler_normalModuleFactoryCreateModule(createData) {
656
- var _a;
657
629
  const data = Object.assign({}, createData, {
658
630
  settings: {},
659
631
  matchResource: createData.resourceResolveData.resource
660
632
  });
661
- const nmfHooks = (_a = this.compilation.normalModuleFactory) === null || _a === void 0 ? void 0 : _a.hooks;
633
+ const nmfHooks = this.compilationParams.normalModuleFactory.hooks;
662
634
  await (nmfHooks === null || nmfHooks === void 0 ? void 0 : nmfHooks.createModule.promise(data, {}));
663
635
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
664
636
  }, _Compiler_normalModuleFactoryResolveForScheme = async function _Compiler_normalModuleFactoryResolveForScheme(input) {
665
- var _a;
666
- let stop = await ((_a = this.compilation.normalModuleFactory) === null || _a === void 0 ? void 0 : _a.hooks.resolveForScheme.for(input.scheme).promise(input.resourceData));
637
+ let stop = await this.compilationParams.normalModuleFactory.hooks.resolveForScheme.for(input.scheme).promise(input.resourceData);
667
638
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
668
639
  return {
669
640
  resourceData: input.resourceData,
@@ -687,10 +658,6 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
687
658
  }, _Compiler_finishModules = async function _Compiler_finishModules() {
688
659
  await this.compilation.hooks.finishModules.promise(this.compilation.modules);
689
660
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
690
- }, _Compiler_shouldEmit = async function _Compiler_shouldEmit() {
691
- const res = this.hooks.shouldEmit.call(this.compilation);
692
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
693
- return Promise.resolve(res);
694
661
  }, _Compiler_emit = async function _Compiler_emit() {
695
662
  await this.hooks.emit.promise(this.compilation);
696
663
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
@@ -772,89 +739,65 @@ _Compiler_instance = new WeakMap(), _Compiler_disabledHooks = new WeakMap(), _Co
772
739
  if (jsTaps.length > 0) {
773
740
  const last = jsTaps[jsTaps.length - 1];
774
741
  const old = last.function;
775
- last.function = async () => {
776
- await old();
742
+ last.function = (...args) => {
743
+ const result = old(...args);
744
+ if (result && typeof result.then === "function") {
745
+ return result.then((r) => {
746
+ __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
747
+ return r;
748
+ });
749
+ }
777
750
  __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
751
+ return result;
778
752
  };
779
753
  }
780
- }, _Compiler_registerCompilerCompilationTaps = function _Compiler_registerCompilerCompilationTaps(stages) {
781
- if (!this.hooks.compilation.isUsed())
782
- return [];
783
- const breakpoints = [liteTapable.minStage, ...stages, liteTapable.maxStage];
784
- const jsTaps = [];
785
- for (let i = 0; i < breakpoints.length - 1; i++) {
786
- const from = breakpoints[i];
787
- const to = breakpoints[i + 1];
788
- const stageRange = [from, to];
789
- const queried = this.hooks.compilation.queryStageRange(stageRange);
790
- if (!queried.isUsed())
791
- continue;
792
- jsTaps.push({
793
- function: () => {
794
- queried.call(this.compilation, {
795
- normalModuleFactory: this.compilation.normalModuleFactory
796
- });
797
- },
798
- stage: liteTapable.safeStage(from + 1)
799
- });
800
- }
801
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_decorateUpdateDisabledHooks).call(this, jsTaps);
802
- return jsTaps;
803
- }, _Compiler_registerCompilerMakeTaps = function _Compiler_registerCompilerMakeTaps(stages) {
804
- if (!this.hooks.make.isUsed())
805
- return [];
806
- const breakpoints = [liteTapable.minStage, ...stages, liteTapable.maxStage];
807
- const jsTaps = [];
808
- for (let i = 0; i < breakpoints.length - 1; i++) {
809
- const from = breakpoints[i];
810
- const to = breakpoints[i + 1];
811
- const stageRange = [from, to];
812
- const queried = this.hooks.make.queryStageRange(stageRange);
813
- if (!queried.isUsed())
814
- continue;
815
- jsTaps.push({
816
- function: async () => {
817
- await queried.promise(this.compilation);
818
- },
819
- stage: liteTapable.safeStage(from + 1)
820
- });
821
- }
822
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_decorateUpdateDisabledHooks).call(this, jsTaps);
823
- return jsTaps;
824
- }, _Compiler_registerCompilationProcessAssetsTaps = function _Compiler_registerCompilationProcessAssetsTaps(stages) {
825
- if (!this.compilation.hooks.processAssets.isUsed())
826
- return [];
827
- const breakpoints = [liteTapable.minStage, ...stages, liteTapable.maxStage];
828
- const jsTaps = [];
829
- for (let i = 0; i < breakpoints.length - 1; i++) {
830
- const from = breakpoints[i];
831
- const to = breakpoints[i + 1];
832
- const stageRange = [from, to];
833
- const queried = this.compilation.hooks.processAssets.queryStageRange(stageRange);
834
- if (!queried.isUsed())
835
- continue;
836
- jsTaps.push({
837
- function: async () => {
838
- await queried.promise(this.compilation.assets);
839
- },
840
- stage: liteTapable.safeStage(from + 1)
841
- });
842
- }
843
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_decorateUpdateDisabledHooks).call(this, jsTaps);
844
- return jsTaps;
845
- }, _Compiler_newCompilation = function _Compiler_newCompilation(native) {
754
+ }, _Compiler_createRegisterTaps = function _Compiler_createRegisterTaps(getHook, createTap) {
755
+ return stages => {
756
+ const hook = getHook();
757
+ if (!hook.isUsed())
758
+ return [];
759
+ const breakpoints = [
760
+ liteTapable.minStage,
761
+ ...stages,
762
+ liteTapable.maxStage
763
+ ];
764
+ const jsTaps = [];
765
+ for (let i = 0; i < breakpoints.length - 1; i++) {
766
+ const from = breakpoints[i];
767
+ const to = breakpoints[i + 1];
768
+ const stageRange = [from, to];
769
+ const queried = hook.queryStageRange(stageRange);
770
+ if (!queried.isUsed())
771
+ continue;
772
+ jsTaps.push({
773
+ function: createTap(queried),
774
+ stage: liteTapable.safeStage(from + 1)
775
+ });
776
+ }
777
+ __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_decorateUpdateDisabledHooks).call(this, jsTaps);
778
+ return jsTaps;
779
+ };
780
+ }, _Compiler_createCompilation = function _Compiler_createCompilation(native) {
846
781
  const compilation = new Compilation_1.Compilation(this, native);
847
782
  compilation.name = this.name;
848
783
  this.compilation = compilation;
849
- // reset normalModuleFactory when create new compilation
850
- let normalModuleFactory = new NormalModuleFactory_1.NormalModuleFactory();
851
- let contextModuleFactory = new ContextModuleFactory_1.ContextModuleFactory();
852
- this.compilation.normalModuleFactory = normalModuleFactory;
784
+ return compilation;
785
+ }, _Compiler_resetThisCompilation = function _Compiler_resetThisCompilation() {
786
+ // reassign new compilation in thisCompilation
787
+ this.compilation = undefined;
788
+ // ensure thisCompilation must call
789
+ this.hooks.thisCompilation.intercept({
790
+ call: () => { }
791
+ });
792
+ }, _Compiler_newCompilationParams = function _Compiler_newCompilationParams() {
793
+ const normalModuleFactory = new NormalModuleFactory_1.NormalModuleFactory();
853
794
  this.hooks.normalModuleFactory.call(normalModuleFactory);
854
- this.compilation.contextModuleFactory = contextModuleFactory;
795
+ const contextModuleFactory = new ContextModuleFactory_1.ContextModuleFactory();
855
796
  this.hooks.contextModuleFactory.call(contextModuleFactory);
856
- this.hooks.thisCompilation.call(this.compilation, {
857
- normalModuleFactory: normalModuleFactory
858
- });
859
- __classPrivateFieldGet(this, _Compiler_instances, "m", _Compiler_updateDisabledHooks).call(this);
797
+ const params = {
798
+ normalModuleFactory,
799
+ contextModuleFactory
800
+ };
801
+ this.compilationParams = params;
802
+ return params;
860
803
  };
@@ -240,8 +240,8 @@ class MultiCompiler {
240
240
  }, (compiler, watching, _done) => {
241
241
  if (compiler.watching !== watching)
242
242
  return;
243
- if (!(watching === null || watching === void 0 ? void 0 : watching.running))
244
- watching === null || watching === void 0 ? void 0 : watching.invalidate();
243
+ if (!watching.running)
244
+ watching.invalidate();
245
245
  }, handler);
246
246
  // @ts-expect-error
247
247
  return new MultiWatching_1.default(watchings, this);
@@ -1,4 +1,5 @@
1
1
  import { AsyncSeriesBailHook, HookMap } from "tapable";
2
+ import * as liteTapable from "./lite-tapable";
2
3
  import type * as binding from "@rspack/binding";
3
4
  type ResourceData = {
4
5
  resource: string;
@@ -23,7 +24,7 @@ type CreateModuleData = binding.CreateModuleData & {
23
24
  export declare class NormalModuleFactory {
24
25
  hooks: {
25
26
  resolveForScheme: HookMap<AsyncSeriesBailHook<[ResourceDataWithData], true | void>>;
26
- beforeResolve: AsyncSeriesBailHook<[ResolveData], boolean | void>;
27
+ beforeResolve: liteTapable.AsyncSeriesBailHook<[ResolveData], false | void>;
27
28
  afterResolve: AsyncSeriesBailHook<[ResolveData], boolean | void>;
28
29
  createModule: AsyncSeriesBailHook<[CreateModuleData, {}], void>;
29
30
  };