@rspack-debug/core 2.0.0-beta.0 → 2.0.0-beta.1

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.
package/dist/index.js CHANGED
@@ -3,7 +3,6 @@ import * as __rspack_external_process from "process";
3
3
  import { createRequire as __rspack_createRequire, createRequire } from "node:module";
4
4
  let __rspack_createRequire_require = __rspack_createRequire(import.meta.url);
5
5
  import { __webpack_require__ } from "./rslib-runtime.js";
6
- import { AsyncParallelHook, AsyncSeriesBailHook, AsyncSeriesHook, AsyncSeriesWaterfallHook, HookMap, MultiHook, SyncBailHook, SyncHook, SyncWaterfallHook, maxStage, minStage, safeStage } from "@rspack/lite-tapable";
7
6
  import node_util, { format as external_node_util_format, inspect, promisify } from "node:util";
8
7
  import node_path, { isAbsolute, join, relative, resolve as external_node_path_resolve, sep } from "node:path";
9
8
  import node_querystring from "node:querystring";
@@ -302,6 +301,479 @@ __webpack_require__.r(ModuleFilenameHelpers_namespaceObject), __webpack_require_
302
301
  });
303
302
  let binding_namespaceObject = __rspack_createRequire_require(process.env.RSPACK_BINDING ? process.env.RSPACK_BINDING : "@rspack/binding");
304
303
  var binding_default = __webpack_require__.n(binding_namespaceObject);
304
+ function _define_property(obj, key, value) {
305
+ return key in obj ? Object.defineProperty(obj, key, {
306
+ value: value,
307
+ enumerable: !0,
308
+ configurable: !0,
309
+ writable: !0
310
+ }) : obj[key] = value, obj;
311
+ }
312
+ class HookBase {
313
+ intercept(interceptor) {
314
+ if (this.interceptors.push(Object.assign({}, interceptor)), interceptor.register) for(let i = 0; i < this.taps.length; i++)this.taps[i] = interceptor.register(this.taps[i]);
315
+ }
316
+ _runRegisterInterceptors(options) {
317
+ return this.interceptors.reduce((options, interceptor)=>interceptor.register?.(options) ?? options, options);
318
+ }
319
+ _runCallInterceptors(...args) {
320
+ for (let interceptor of this.interceptors)interceptor.call && interceptor.call(...args);
321
+ }
322
+ _runErrorInterceptors(e) {
323
+ for (let interceptor of this.interceptors)interceptor.error && interceptor.error(e);
324
+ }
325
+ _runTapInterceptors(tap) {
326
+ for (let interceptor of this.interceptors)interceptor.tap && interceptor.tap(tap);
327
+ }
328
+ _runDoneInterceptors() {
329
+ for (let interceptor of this.interceptors)interceptor.done && interceptor.done();
330
+ }
331
+ _runResultInterceptors(r) {
332
+ for (let interceptor of this.interceptors)interceptor.result && interceptor.result(r);
333
+ }
334
+ withOptions(options) {
335
+ let mergeOptions = (opt)=>Object.assign({}, options, 'string' == typeof opt ? {
336
+ name: opt
337
+ } : opt);
338
+ return {
339
+ name: this.name,
340
+ tap: (opt, fn)=>this.tap(mergeOptions(opt), fn),
341
+ tapAsync: (opt, fn)=>this.tapAsync(mergeOptions(opt), fn),
342
+ tapPromise: (opt, fn)=>this.tapPromise(mergeOptions(opt), fn),
343
+ intercept: (interceptor)=>this.intercept(interceptor),
344
+ isUsed: ()=>this.isUsed(),
345
+ withOptions: (opt)=>this.withOptions(mergeOptions(opt)),
346
+ queryStageRange: (stageRange)=>this.queryStageRange(stageRange)
347
+ };
348
+ }
349
+ isUsed() {
350
+ return this.taps.length > 0 || this.interceptors.length > 0;
351
+ }
352
+ queryStageRange(stageRange) {
353
+ return new QueriedHook(stageRange, this);
354
+ }
355
+ callAsyncStageRange(queried) {
356
+ throw Error('Hook should implement there own _callAsyncStageRange');
357
+ }
358
+ callAsync(...args) {
359
+ return this.callAsyncStageRange(this.queryStageRange(allStageRange), ...args);
360
+ }
361
+ promiseStageRange(queried, ...args) {
362
+ return new Promise((resolve, reject)=>{
363
+ this.callAsyncStageRange(queried, ...args, (e, r)=>e ? reject(e) : resolve(r));
364
+ });
365
+ }
366
+ promise(...args) {
367
+ return this.promiseStageRange(this.queryStageRange(allStageRange), ...args);
368
+ }
369
+ tap(options, fn) {
370
+ this._tap('sync', options, fn);
371
+ }
372
+ tapAsync(options, fn) {
373
+ this._tap('async', options, fn);
374
+ }
375
+ tapPromise(options, fn) {
376
+ this._tap('promise', options, fn);
377
+ }
378
+ _tap(type, options, fn) {
379
+ let normalizedOptions = options;
380
+ if ('string' == typeof options) normalizedOptions = {
381
+ name: options.trim()
382
+ };
383
+ else if ('object' != typeof options || null === options) throw Error('Invalid tap options');
384
+ if ('string' != typeof normalizedOptions.name || '' === normalizedOptions.name) throw Error('Missing name for tap');
385
+ this._insert(this._runRegisterInterceptors(Object.assign({
386
+ type,
387
+ fn
388
+ }, normalizedOptions)));
389
+ }
390
+ _insert(item) {
391
+ let before;
392
+ 'string' == typeof item.before ? before = new Set([
393
+ item.before
394
+ ]) : Array.isArray(item.before) && (before = new Set(item.before));
395
+ let stage = 0;
396
+ 'number' == typeof item.stage && (stage = item.stage);
397
+ let i = this.taps.length;
398
+ for(; i > 0;){
399
+ i--;
400
+ let x = this.taps[i];
401
+ this.taps[i + 1] = x;
402
+ let xStage = x.stage || 0;
403
+ if (before) {
404
+ if (before.has(x.name)) {
405
+ before.delete(x.name);
406
+ continue;
407
+ }
408
+ if (before.size > 0) continue;
409
+ }
410
+ if (!(xStage > stage)) {
411
+ i++;
412
+ break;
413
+ }
414
+ }
415
+ this.taps[i] = item;
416
+ }
417
+ _prepareArgs(args) {
418
+ let len = this.args.length;
419
+ return args.length < len ? (args.length = len, args.fill(void 0, args.length, len)) : (args.length > len && (args.length = len), args);
420
+ }
421
+ constructor(args = [], name){
422
+ _define_property(this, "args", void 0), _define_property(this, "name", void 0), _define_property(this, "taps", void 0), _define_property(this, "interceptors", void 0), this.args = args, this.name = name, this.taps = [], this.interceptors = [];
423
+ }
424
+ }
425
+ let minStage = -1 / 0, maxStage = 1 / 0, allStageRange = [
426
+ minStage,
427
+ 1 / 0
428
+ ], i32MAX = 2147483648 - 1, safeStage = (stage)=>stage < -2147483648 ? -2147483648 : stage > i32MAX ? i32MAX : stage;
429
+ class QueriedHook {
430
+ isUsed() {
431
+ return !!(this.tapsInRange.length > 0 || this.stageRange[0] === minStage && this.hook.interceptors.some((i)=>i.call) || this.stageRange[1] === maxStage && this.hook.interceptors.some((i)=>i.done));
432
+ }
433
+ call(...args) {
434
+ if ('function' != typeof this.hook.callStageRange) throw Error('hook is not a SyncHook, call methods only exists on SyncHook');
435
+ return this.hook.callStageRange(this, ...args);
436
+ }
437
+ callAsync(...args) {
438
+ return this.hook.callAsyncStageRange(this, ...args);
439
+ }
440
+ promise(...args) {
441
+ return this.hook.promiseStageRange(this, ...args);
442
+ }
443
+ constructor(stageRange, hook){
444
+ _define_property(this, "stageRange", void 0), _define_property(this, "hook", void 0), _define_property(this, "tapsInRange", void 0);
445
+ let tapsInRange = [], [from, to] = stageRange;
446
+ for (let tap of hook.taps){
447
+ let stage = tap.stage ?? 0;
448
+ from <= stage && stage < to ? tapsInRange.push(tap) : to === maxStage && stage === maxStage && tapsInRange.push(tap);
449
+ }
450
+ this.stageRange = stageRange, this.hook = hook, this.tapsInRange = tapsInRange;
451
+ }
452
+ }
453
+ class SyncHook extends HookBase {
454
+ callAsyncStageRange(queried, ...args) {
455
+ let { stageRange: [from, to], tapsInRange } = queried, argsWithoutCb = args.slice(0, args.length - 1), cb = args[args.length - 1], args2 = this._prepareArgs(argsWithoutCb);
456
+ for (let tap of (from === minStage && this._runCallInterceptors(...args2), tapsInRange)){
457
+ this._runTapInterceptors(tap);
458
+ try {
459
+ tap.fn(...args2);
460
+ } catch (e) {
461
+ return this._runErrorInterceptors(e), cb(e);
462
+ }
463
+ }
464
+ to === maxStage && (this._runDoneInterceptors(), cb(null));
465
+ }
466
+ call(...args) {
467
+ return this.callStageRange(this.queryStageRange(allStageRange), ...args);
468
+ }
469
+ callStageRange(queried, ...args) {
470
+ let result, error;
471
+ if (this.callAsyncStageRange(queried, ...args, (e, r)=>{
472
+ error = e, result = r;
473
+ }), error) throw error;
474
+ return result;
475
+ }
476
+ tapAsync() {
477
+ throw Error('tapAsync is not supported on a SyncHook');
478
+ }
479
+ tapPromise() {
480
+ throw Error('tapPromise is not supported on a SyncHook');
481
+ }
482
+ }
483
+ class SyncBailHook extends HookBase {
484
+ callAsyncStageRange(queried, ...args) {
485
+ let { stageRange: [from, to], tapsInRange } = queried, argsWithoutCb = args.slice(0, args.length - 1), cb = args[args.length - 1], args2 = this._prepareArgs(argsWithoutCb);
486
+ for (let tap of (from === minStage && this._runCallInterceptors(...args2), tapsInRange)){
487
+ let r;
488
+ this._runTapInterceptors(tap);
489
+ try {
490
+ r = tap.fn(...args2);
491
+ } catch (e) {
492
+ return this._runErrorInterceptors(e), cb(e);
493
+ }
494
+ if (void 0 !== r) return this._runResultInterceptors(r), cb(null, r);
495
+ }
496
+ to === maxStage && (this._runDoneInterceptors(), cb(null));
497
+ }
498
+ call(...args) {
499
+ return this.callStageRange(this.queryStageRange(allStageRange), ...args);
500
+ }
501
+ callStageRange(queried, ...args) {
502
+ let result, error;
503
+ if (this.callAsyncStageRange(queried, ...args, (e, r)=>{
504
+ error = e, result = r;
505
+ }), error) throw error;
506
+ return result;
507
+ }
508
+ tapAsync() {
509
+ throw Error('tapAsync is not supported on a SyncBailHook');
510
+ }
511
+ tapPromise() {
512
+ throw Error('tapPromise is not supported on a SyncBailHook');
513
+ }
514
+ }
515
+ class SyncWaterfallHook extends HookBase {
516
+ callAsyncStageRange(queried, ...args) {
517
+ let { stageRange: [from, to], tapsInRange } = queried, argsWithoutCb = args.slice(0, args.length - 1), cb = args[args.length - 1], args2 = this._prepareArgs(argsWithoutCb);
518
+ for (let tap of (from === minStage && this._runCallInterceptors(...args2), tapsInRange)){
519
+ this._runTapInterceptors(tap);
520
+ try {
521
+ let r = tap.fn(...args2);
522
+ void 0 !== r && (args2[0] = r);
523
+ } catch (e) {
524
+ return this._runErrorInterceptors(e), cb(e);
525
+ }
526
+ }
527
+ to === maxStage && (this._runDoneInterceptors(), cb(null, args2[0]));
528
+ }
529
+ call(...args) {
530
+ return this.callStageRange(this.queryStageRange(allStageRange), ...args);
531
+ }
532
+ callStageRange(queried, ...args) {
533
+ let result, error;
534
+ if (this.callAsyncStageRange(queried, ...args, (e, r)=>{
535
+ error = e, result = r;
536
+ }), error) throw error;
537
+ return result;
538
+ }
539
+ tapAsync() {
540
+ throw Error('tapAsync is not supported on a SyncWaterfallHook');
541
+ }
542
+ tapPromise() {
543
+ throw Error('tapPromise is not supported on a SyncWaterfallHook');
544
+ }
545
+ constructor(args = [], name){
546
+ if (args.length < 1) throw Error('Waterfall hooks must have at least one argument');
547
+ super(args, name);
548
+ }
549
+ }
550
+ class AsyncParallelHook extends HookBase {
551
+ callAsyncStageRange(queried, ...args) {
552
+ let { stageRange: [from], tapsInRange } = queried, argsWithoutCb = args.slice(0, args.length - 1), cb = args[args.length - 1], args2 = this._prepareArgs(argsWithoutCb);
553
+ from === minStage && this._runCallInterceptors(...args2);
554
+ let done = ()=>{
555
+ this._runDoneInterceptors(), cb(null);
556
+ }, error = (e)=>{
557
+ this._runErrorInterceptors(e), cb(e);
558
+ };
559
+ if (0 === tapsInRange.length) return done();
560
+ let counter = tapsInRange.length;
561
+ for (let tap of tapsInRange){
562
+ if (this._runTapInterceptors(tap), 'promise' === tap.type) {
563
+ let promise = tap.fn(...args2);
564
+ if (!promise || !promise.then) throw Error(`Tap function (tapPromise) did not return promise (returned ${promise})`);
565
+ promise.then(()=>{
566
+ 0 == (counter -= 1) && done();
567
+ }, (e)=>{
568
+ counter = 0, error(e);
569
+ });
570
+ } else if ('async' === tap.type) tap.fn(...args2, (e)=>{
571
+ e ? (counter = 0, error(e)) : 0 == (counter -= 1) && done();
572
+ });
573
+ else {
574
+ let hasError = !1;
575
+ try {
576
+ tap.fn(...args2);
577
+ } catch (e) {
578
+ hasError = !0, counter = 0, error(e);
579
+ }
580
+ hasError || 0 != --counter || done();
581
+ }
582
+ if (counter <= 0) return;
583
+ }
584
+ }
585
+ }
586
+ class AsyncSeriesHook extends HookBase {
587
+ callAsyncStageRange(queried, ...args) {
588
+ let { stageRange: [from], tapsInRange } = queried, argsWithoutCb = args.slice(0, args.length - 1), cb = args[args.length - 1], args2 = this._prepareArgs(argsWithoutCb);
589
+ from === minStage && this._runCallInterceptors(...args2);
590
+ let done = ()=>{
591
+ this._runDoneInterceptors(), cb(null);
592
+ }, error = (e)=>{
593
+ this._runErrorInterceptors(e), cb(e);
594
+ };
595
+ if (0 === tapsInRange.length) return done();
596
+ let index = 0, next = ()=>{
597
+ let tap = tapsInRange[index];
598
+ if (this._runTapInterceptors(tap), 'promise' === tap.type) {
599
+ let promise = tap.fn(...args2);
600
+ if (!promise || !promise.then) throw Error(`Tap function (tapPromise) did not return promise (returned ${promise})`);
601
+ promise.then(()=>{
602
+ (index += 1) === tapsInRange.length ? done() : next();
603
+ }, (e)=>{
604
+ index = tapsInRange.length, error(e);
605
+ });
606
+ } else if ('async' === tap.type) tap.fn(...args2, (e)=>{
607
+ e ? (index = tapsInRange.length, error(e)) : (index += 1) === tapsInRange.length ? done() : next();
608
+ });
609
+ else {
610
+ let hasError = !1;
611
+ try {
612
+ tap.fn(...args2);
613
+ } catch (e) {
614
+ hasError = !0, index = tapsInRange.length, error(e);
615
+ }
616
+ hasError || ((index += 1) === tapsInRange.length ? done() : next());
617
+ }
618
+ if (index === tapsInRange.length) return;
619
+ };
620
+ next();
621
+ }
622
+ }
623
+ class AsyncSeriesBailHook extends HookBase {
624
+ callAsyncStageRange(queried, ...args) {
625
+ let { stageRange: [from], tapsInRange } = queried, argsWithoutCb = args.slice(0, args.length - 1), cb = args[args.length - 1], args2 = this._prepareArgs(argsWithoutCb);
626
+ from === minStage && this._runCallInterceptors(...args2);
627
+ let done = ()=>{
628
+ this._runDoneInterceptors(), cb(null);
629
+ }, error = (e)=>{
630
+ this._runErrorInterceptors(e), cb(e);
631
+ }, result = (r)=>{
632
+ this._runResultInterceptors(r), cb(null, r);
633
+ };
634
+ if (0 === tapsInRange.length) return done();
635
+ let index = 0, next = ()=>{
636
+ let tap = tapsInRange[index];
637
+ if (this._runTapInterceptors(tap), 'promise' === tap.type) {
638
+ let promise = tap.fn(...args2);
639
+ if (!promise || !promise.then) throw Error(`Tap function (tapPromise) did not return promise (returned ${promise})`);
640
+ promise.then((r)=>{
641
+ index += 1, void 0 !== r ? result(r) : index === tapsInRange.length ? done() : next();
642
+ }, (e)=>{
643
+ index = tapsInRange.length, error(e);
644
+ });
645
+ } else if ('async' === tap.type) tap.fn(...args2, (e, r)=>{
646
+ e ? (index = tapsInRange.length, error(e)) : (index += 1, void 0 !== r ? result(r) : index === tapsInRange.length ? done() : next());
647
+ });
648
+ else {
649
+ let r, hasError = !1;
650
+ try {
651
+ r = tap.fn(...args2);
652
+ } catch (e) {
653
+ hasError = !0, index = tapsInRange.length, error(e);
654
+ }
655
+ hasError || (index += 1, void 0 !== r ? result(r) : index === tapsInRange.length ? done() : next());
656
+ }
657
+ if (index === tapsInRange.length) return;
658
+ };
659
+ next();
660
+ }
661
+ }
662
+ class AsyncSeriesWaterfallHook extends HookBase {
663
+ callAsyncStageRange(queried, ...args) {
664
+ let { stageRange: [from], tapsInRange } = queried, argsWithoutCb = args.slice(0, args.length - 1), cb = args[args.length - 1], args2 = this._prepareArgs(argsWithoutCb);
665
+ from === minStage && this._runCallInterceptors(...args2);
666
+ let result = (r)=>{
667
+ this._runResultInterceptors(r), cb(null, r);
668
+ }, error = (e)=>{
669
+ this._runErrorInterceptors(e), cb(e);
670
+ };
671
+ if (0 === tapsInRange.length) return result(args2[0]);
672
+ let index = 0, next = ()=>{
673
+ let tap = tapsInRange[index];
674
+ if (this._runTapInterceptors(tap), 'promise' === tap.type) {
675
+ let promise = tap.fn(...args2);
676
+ if (!promise || !promise.then) throw Error(`Tap function (tapPromise) did not return promise (returned ${promise})`);
677
+ promise.then((r)=>{
678
+ index += 1, void 0 !== r && (args2[0] = r), index === tapsInRange.length ? result(args2[0]) : next();
679
+ }, (e)=>{
680
+ index = tapsInRange.length, error(e);
681
+ });
682
+ } else if ('async' === tap.type) tap.fn(...args2, (e, r)=>{
683
+ e ? (index = tapsInRange.length, error(e)) : (index += 1, void 0 !== r && (args2[0] = r), index === tapsInRange.length ? result(args2[0]) : next());
684
+ });
685
+ else {
686
+ let hasError = !1;
687
+ try {
688
+ let r = tap.fn(...args2);
689
+ void 0 !== r && (args2[0] = r);
690
+ } catch (e) {
691
+ hasError = !0, index = tapsInRange.length, error(e);
692
+ }
693
+ hasError || ((index += 1) === tapsInRange.length ? result(args2[0]) : next());
694
+ }
695
+ if (index === tapsInRange.length) return;
696
+ };
697
+ next();
698
+ }
699
+ constructor(args = [], name){
700
+ if (args.length < 1) throw Error('Waterfall hooks must have at least one argument');
701
+ super(args, name);
702
+ }
703
+ }
704
+ let defaultFactory = (key, hook)=>hook;
705
+ class HookMap {
706
+ get(key) {
707
+ return this._map.get(key);
708
+ }
709
+ for(key) {
710
+ let hook = this.get(key);
711
+ if (void 0 !== hook) return hook;
712
+ let newHook = this._factory(key), interceptors = this._interceptors;
713
+ for(let i = 0; i < interceptors.length; i++){
714
+ let factory = interceptors[i].factory;
715
+ factory && (newHook = factory(key, newHook));
716
+ }
717
+ return this._map.set(key, newHook), newHook;
718
+ }
719
+ intercept(interceptor) {
720
+ this._interceptors.push(Object.assign({
721
+ factory: defaultFactory
722
+ }, interceptor));
723
+ }
724
+ isUsed() {
725
+ for (let key of this._map.keys()){
726
+ let hook = this.get(key);
727
+ if (hook?.isUsed()) return !0;
728
+ }
729
+ return !1;
730
+ }
731
+ queryStageRange(stageRange) {
732
+ return new QueriedHookMap(stageRange, this);
733
+ }
734
+ constructor(factory, name){
735
+ _define_property(this, "_map", new Map()), _define_property(this, "_factory", void 0), _define_property(this, "name", void 0), _define_property(this, "_interceptors", void 0), this.name = name, this._factory = factory, this._interceptors = [];
736
+ }
737
+ }
738
+ class QueriedHookMap {
739
+ get(key) {
740
+ return this.hookMap.get(key)?.queryStageRange(this.stageRange);
741
+ }
742
+ for(key) {
743
+ return this.hookMap.for(key).queryStageRange(this.stageRange);
744
+ }
745
+ isUsed() {
746
+ for (let key of this.hookMap._map.keys())if (this.get(key)?.isUsed()) return !0;
747
+ return !1;
748
+ }
749
+ constructor(stageRange, hookMap){
750
+ _define_property(this, "stageRange", void 0), _define_property(this, "hookMap", void 0), this.stageRange = stageRange, this.hookMap = hookMap;
751
+ }
752
+ }
753
+ class MultiHook {
754
+ tap(options, fn) {
755
+ for (let hook of this.hooks)hook.tap(options, fn);
756
+ }
757
+ tapAsync(options, fn) {
758
+ for (let hook of this.hooks)hook.tapAsync(options, fn);
759
+ }
760
+ tapPromise(options, fn) {
761
+ for (let hook of this.hooks)hook.tapPromise(options, fn);
762
+ }
763
+ isUsed() {
764
+ for (let hook of this.hooks)if (hook.isUsed()) return !0;
765
+ return !1;
766
+ }
767
+ intercept(interceptor) {
768
+ for (let hook of this.hooks)hook.intercept(interceptor);
769
+ }
770
+ withOptions(options) {
771
+ return new MultiHook(this.hooks.map((h)=>h.withOptions(options)), this.name);
772
+ }
773
+ constructor(hooks, name){
774
+ _define_property(this, "hooks", void 0), _define_property(this, "name", void 0), this.hooks = hooks, this.name = name;
775
+ }
776
+ }
305
777
  let cutOffLoaderExecution = (stack)=>((stack, flag)=>{
306
778
  let stacks = stack.split('\n');
307
779
  for(let i = 0; i < stacks.length; i++)stacks[i].includes(flag) && (stacks.length = i);
@@ -1417,6 +1889,9 @@ BREAKING CHANGE: Asset processing hooks in Compilation has been merged into a si
1417
1889
  'chunks',
1418
1890
  'modules'
1419
1891
  ]),
1892
+ beforeModuleIds: new SyncHook([
1893
+ 'modules'
1894
+ ]),
1420
1895
  finishModules: new AsyncSeriesHook([
1421
1896
  'modules'
1422
1897
  ]),
@@ -2820,20 +3295,6 @@ class BulkUpdateDecorator extends Hash {
2820
3295
  return void 0 !== digestCache && 'string' == typeof result && digestCache.set(buffer, result), result;
2821
3296
  }
2822
3297
  }
2823
- class DebugHash extends Hash {
2824
- string;
2825
- constructor(){
2826
- super(), this.string = '';
2827
- }
2828
- update(data) {
2829
- let normalizedData;
2830
- return (normalizedData = Buffer.isBuffer(data) ? data.toString('utf-8') : data).startsWith('debug-digest-') && (normalizedData = Buffer.from(normalizedData.slice(13), 'hex').toString()), this.string += `[${normalizedData}](${Error().stack?.split('\n', 3)[2]})\n`, this;
2831
- }
2832
- digest(encoding) {
2833
- let result = `debug-digest-${Buffer.from(this.string).toString('hex')}`;
2834
- return encoding ? result : Buffer.from(result);
2835
- }
2836
- }
2837
3298
  class WasmHashAdapter extends Hash {
2838
3299
  wasmHash;
2839
3300
  constructor(wasmHash){
@@ -2849,8 +3310,6 @@ class WasmHashAdapter extends Hash {
2849
3310
  let createHash_createHash = (algorithm)=>{
2850
3311
  if ('function' == typeof algorithm) return new BulkUpdateDecorator(()=>new algorithm());
2851
3312
  switch(algorithm){
2852
- case 'debug':
2853
- return new DebugHash();
2854
3313
  case 'xxhash64':
2855
3314
  return new WasmHashAdapter((()=>{
2856
3315
  if (!createXxhash64) {
@@ -3939,7 +4398,6 @@ function getRawJavascriptParserOptions(parser) {
3939
4398
  exportsPresence: !1 === parser.exportsPresence ? 'false' : parser.exportsPresence,
3940
4399
  importExportsPresence: !1 === parser.importExportsPresence ? 'false' : parser.importExportsPresence,
3941
4400
  reexportExportsPresence: !1 === parser.reexportExportsPresence ? 'false' : parser.reexportExportsPresence,
3942
- strictExportPresence: parser.strictExportPresence,
3943
4401
  worker: 'boolean' == typeof parser.worker ? parser.worker ? [
3944
4402
  '...'
3945
4403
  ] : [] : parser.worker,
@@ -3959,7 +4417,8 @@ function getRawJavascriptParserOptions(parser) {
3959
4417
  function getRawCssParserOptions(parser) {
3960
4418
  return {
3961
4419
  namedExports: parser.namedExports,
3962
- url: parser.url
4420
+ url: parser.url,
4421
+ resolveImport: parser.resolveImport
3963
4422
  };
3964
4423
  }
3965
4424
  function getRawGeneratorOptions(generator, type) {
@@ -4413,7 +4872,7 @@ let JsLoaderRspackPlugin = base_create(binding_namespaceObject.BuiltinPluginName
4413
4872
  test,
4414
4873
  client,
4415
4874
  currentActiveModules
4416
- }), 'thisCompilation'), middleware_require = createRequire(import.meta.url), LAZY_COMPILATION_PREFIX = '/lazy-compilation-using-', noop = (_req, _res, next)=>{
4875
+ }), 'thisCompilation'), middleware_require = createRequire(import.meta.url), LAZY_COMPILATION_PREFIX = '/_rspack/lazy/trigger', noop = (_req, _res, next)=>{
4417
4876
  'function' == typeof next && next();
4418
4877
  }, lazyCompilationMiddleware = (compiler)=>{
4419
4878
  if (compiler instanceof MultiCompiler) {
@@ -6042,7 +6501,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
6042
6501
  if ('function' != typeof options.entry) for (let key of Object.keys(options.entry))F(options.entry[key], 'import', ()=>[
6043
6502
  './src'
6044
6503
  ]);
6045
- return F(options, 'devtool', ()=>!!development && 'eval'), D(options, 'watch', !1), D(options, 'lazyCompilation', !1), D(options, 'bail', !1), F(options, 'cache', ()=>development), applyIncrementalDefaults(options), applyExperimentsDefaults(options.experiments), applyOptimizationDefaults(options.optimization, {
6504
+ return F(options, 'devtool', ()=>!!development && 'cheap-module-source-map'), D(options, 'watch', !1), D(options, 'lazyCompilation', !1), D(options, 'bail', !1), F(options, 'cache', ()=>development), applyIncrementalDefaults(options), applyExperimentsDefaults(options.experiments), applyOptimizationDefaults(options.optimization, {
6046
6505
  production,
6047
6506
  development
6048
6507
  }), applySnapshotDefaults(options.snapshot, {
@@ -6094,7 +6553,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
6094
6553
  D(generatorOptions, 'exportsOnly', !targetProperties || !1 === targetProperties.document), D(generatorOptions, 'esModule', !0);
6095
6554
  }, applyModuleDefaults = (module, { asyncWebAssembly, targetProperties, mode, uniqueName, deferImport })=>{
6096
6555
  assertNotNill(module.parser), assertNotNill(module.generator), F(module.parser, "asset", ()=>({})), assertNotNill(module.parser.asset), F(module.parser.asset, 'dataUrlCondition', ()=>({})), 'object' == typeof module.parser.asset.dataUrlCondition && D(module.parser.asset.dataUrlCondition, 'maxSize', 8096), F(module.parser, "javascript", ()=>({})), assertNotNill(module.parser.javascript), ((parserOptions, { deferImport })=>{
6097
- D(parserOptions, 'dynamicImportMode', 'lazy'), D(parserOptions, 'dynamicImportPrefetch', !1), D(parserOptions, 'dynamicImportPreload', !1), D(parserOptions, 'url', !0), D(parserOptions, 'exprContextCritical', !0), D(parserOptions, 'unknownContextCritical', !0), D(parserOptions, 'wrappedContextCritical', !1), D(parserOptions, 'wrappedContextRegExp', /.*/), D(parserOptions, 'strictExportPresence', !1), D(parserOptions, 'requireAsExpression', !1), D(parserOptions, 'requireAlias', !1), D(parserOptions, 'requireDynamic', !0), D(parserOptions, 'requireResolve', !0), D(parserOptions, 'commonjs', !0), D(parserOptions, 'importDynamic', !0), D(parserOptions, 'worker', [
6556
+ D(parserOptions, 'dynamicImportMode', 'lazy'), D(parserOptions, 'dynamicImportPrefetch', !1), D(parserOptions, 'dynamicImportPreload', !1), D(parserOptions, 'url', !0), D(parserOptions, 'exprContextCritical', !0), D(parserOptions, 'unknownContextCritical', !0), D(parserOptions, 'wrappedContextCritical', !1), D(parserOptions, 'wrappedContextRegExp', /.*/), D(parserOptions, 'exportsPresence', 'error'), D(parserOptions, 'requireAsExpression', !0), D(parserOptions, 'requireAlias', !1), D(parserOptions, 'requireDynamic', !0), D(parserOptions, 'requireResolve', !0), D(parserOptions, 'commonjs', !0), D(parserOptions, 'importDynamic', !0), D(parserOptions, 'worker', [
6098
6557
  '...'
6099
6558
  ]), D(parserOptions, 'importMeta', !0), D(parserOptions, 'typeReexportsPresence', 'no-tolerant'), D(parserOptions, 'jsx', !1), D(parserOptions, 'deferImport', deferImport);
6100
6559
  })(module.parser.javascript, {
@@ -6366,7 +6825,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
6366
6825
  return output.wasmLoading && enabledWasmLoadingTypes.add(output.wasmLoading), output.workerWasmLoading && enabledWasmLoadingTypes.add(output.workerWasmLoading), forEachEntry((desc)=>{
6367
6826
  desc.wasmLoading && enabledWasmLoadingTypes.add(desc.wasmLoading);
6368
6827
  }), Array.from(enabledWasmLoadingTypes);
6369
- }), D(output, 'bundlerInfo', {}), 'object' == typeof output.bundlerInfo && (D(output.bundlerInfo, 'version', "2.0.0-beta.0"), D(output.bundlerInfo, 'bundler', 'rspack'), D(output.bundlerInfo, 'force', !output.library));
6828
+ }), D(output, 'bundlerInfo', {}), 'object' == typeof output.bundlerInfo && (D(output.bundlerInfo, 'version', "2.0.0-beta.1"), D(output.bundlerInfo, 'bundler', 'rspack'), D(output.bundlerInfo, 'force', !output.library));
6370
6829
  }, applyExternalsPresetsDefaults = (externalsPresets, { targetProperties, buildHttp, outputModule })=>{
6371
6830
  let isUniversal = (key)=>!!(outputModule && targetProperties && null === targetProperties[key]);
6372
6831
  D(externalsPresets, 'web', !buildHttp && targetProperties && (targetProperties.web || isUniversal('node'))), D(externalsPresets, 'node', targetProperties && (targetProperties.node || isUniversal('node'))), D(externalsPresets, 'electron', targetProperties && targetProperties.electron || isUniversal('electron')), D(externalsPresets, 'electronMain', targetProperties && !!targetProperties.electron && (targetProperties.electronMain || isUniversal('electronMain'))), D(externalsPresets, 'electronPreload', targetProperties && !!targetProperties.electron && (targetProperties.electronPreload || isUniversal('electronPreload'))), D(externalsPresets, 'electronRenderer', targetProperties && !!targetProperties.electron && (targetProperties.electronRenderer || isUniversal('electronRenderer'))), D(externalsPresets, 'nwjs', targetProperties && (targetProperties.nwjs || isUniversal('nwjs')));
@@ -6684,7 +7143,8 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
6684
7143
  type: 'filesystem',
6685
7144
  directory: node_path.resolve(config.context || process.cwd(), cache.storage?.directory || 'node_modules/.cache/rspack')
6686
7145
  },
6687
- portable: cache.portable
7146
+ portable: cache.portable,
7147
+ readonly: cache.readonly
6688
7148
  };
6689
7149
  }),
6690
7150
  stats: nestedConfig(config.stats, (stats)=>!1 === stats ? {
@@ -7618,7 +8078,7 @@ class MultiStats {
7618
8078
  obj.children = this.stats.map((stat, idx)=>{
7619
8079
  let obj = stat.toJson(childOptions.children[idx]), compilationName = stat.compilation.name;
7620
8080
  return obj.name = compilationName && makePathsRelative(childOptions.context, compilationName, stat.compilation.compiler.root), obj;
7621
- }), childOptions.version && (obj.rspackVersion = "2.0.0-beta.0", obj.version = "5.75.0"), childOptions.hash && (obj.hash = obj.children.map((j)=>j.hash).join(''));
8081
+ }), childOptions.version && (obj.rspackVersion = "2.0.0-beta.1", obj.version = "5.75.0"), childOptions.hash && (obj.hash = obj.children.map((j)=>j.hash).join(''));
7622
8082
  let mapError = (j, obj)=>({
7623
8083
  ...obj,
7624
8084
  compilerPath: obj.compilerPath ? `${j.name}.${obj.compilerPath}` : j.name
@@ -8877,7 +9337,7 @@ let iterateConfig = (config, options, fn)=>{
8877
9337
  object.hash = context.getStatsCompilation(compilation).hash;
8878
9338
  },
8879
9339
  version: (object)=>{
8880
- object.version = "5.75.0", object.rspackVersion = "2.0.0-beta.0";
9340
+ object.version = "5.75.0", object.rspackVersion = "2.0.0-beta.1";
8881
9341
  },
8882
9342
  env: (object, _compilation, _context, { _env })=>{
8883
9343
  object.env = _env;
@@ -10242,7 +10702,7 @@ function createCompiler(userOptions) {
10242
10702
  function isMultiRspackOptions(o) {
10243
10703
  return Array.isArray(o);
10244
10704
  }
10245
- function rspack(options, callback) {
10705
+ function rspack_rspack(options, callback) {
10246
10706
  try {
10247
10707
  if (isMultiRspackOptions(options)) for (let option of options)validateRspackConfig(option);
10248
10708
  else validateRspackConfig(options);
@@ -10538,7 +10998,7 @@ class TraceHookPlugin {
10538
10998
  });
10539
10999
  }
10540
11000
  }
10541
- let CORE_VERSION = "2.0.0-beta.0", VFILES_BY_COMPILER = new WeakMap();
11001
+ let CORE_VERSION = "2.0.0-beta.1", VFILES_BY_COMPILER = new WeakMap();
10542
11002
  class VirtualModulesPlugin {
10543
11003
  #staticModules;
10544
11004
  #compiler;
@@ -10862,7 +11322,7 @@ class Compiler {
10862
11322
  }
10863
11323
  });
10864
11324
  let compilerRspack = Object.assign(function(...params) {
10865
- return rspack(...params);
11325
+ return rspack_rspack(...params);
10866
11326
  }, exports_namespaceObject, {
10867
11327
  RuntimeGlobals: createCompilerRuntimeGlobals(options)
10868
11328
  });
@@ -11423,6 +11883,29 @@ Help:
11423
11883
  return queried.promise(getCompiler().__internal__get_compilation().chunks, getCompiler().__internal__get_compilation().modules);
11424
11884
  };
11425
11885
  }),
11886
+ registerCompilationBeforeModuleIdsTaps: createTap(binding_default().RegisterJsTapKind.CompilationBeforeModuleIds, function() {
11887
+ return getCompiler().__internal__get_compilation().hooks.beforeModuleIds;
11888
+ }, function(queried) {
11889
+ return function(arg) {
11890
+ let compilation = getCompiler().__internal__get_compilation(), assignments = new Map(), modulesByIdentifier = new Map();
11891
+ for (let module of compilation.modules)modulesByIdentifier.set(module.identifier(), module);
11892
+ let proxiedModules = arg.modules.map((m)=>new Proxy(modulesByIdentifier.get(m.identifier), {
11893
+ get (target, prop) {
11894
+ if ('id' === prop) return assignments.get(m.identifier) ?? null;
11895
+ if ('identifier' === prop) return m.identifier;
11896
+ let value = Reflect.get(target, prop);
11897
+ return 'function' == typeof value ? value.bind(target) : value;
11898
+ },
11899
+ set: (_target, prop, value)=>'id' === prop && null !== value && (assignments.set(m.identifier, value), !0)
11900
+ }));
11901
+ return queried.call(proxiedModules), {
11902
+ assignments: Object.fromEntries(Array.from(assignments.entries()).map(([k, v])=>[
11903
+ k,
11904
+ String(v)
11905
+ ]))
11906
+ };
11907
+ };
11908
+ }),
11426
11909
  registerCompilationChunkHashTaps: createTap(binding_default().RegisterJsTapKind.CompilationChunkHash, function() {
11427
11910
  return getCompiler().__internal__get_compilation().hooks.chunkHash;
11428
11911
  }, function(queried) {
@@ -11965,68 +12448,7 @@ class LoaderTargetPlugin {
11965
12448
  });
11966
12449
  }
11967
12450
  }
11968
- let VERSION_PATTERN_REGEXP = /^([\d^=v<>~]|[*xX]$)/;
11969
- function isRequiredVersion(str) {
11970
- return VERSION_PATTERN_REGEXP.test(str);
11971
- }
11972
- let MANIFEST_FILE_NAME = 'mf-manifest.json', STATS_FILE_NAME = 'mf-stats.json', JSON_EXT = '.json';
11973
- function isPlainObject(value) {
11974
- return !!value && 'object' == typeof value && !Array.isArray(value);
11975
- }
11976
- class ModuleFederationManifestPlugin extends RspackBuiltinPlugin {
11977
- name = binding_namespaceObject.BuiltinPluginName.ModuleFederationManifestPlugin;
11978
- opts;
11979
- constructor(opts){
11980
- super(), this.opts = opts;
11981
- }
11982
- raw(compiler) {
11983
- var isDev;
11984
- let pkg, buildVersion, { fileName, filePath, disableAssetsAnalyze, remoteAliasMap, exposes, shared } = this.opts, { statsFileName, manifestFileName } = function(manifestOptions) {
11985
- if (!manifestOptions) return {
11986
- statsFileName: STATS_FILE_NAME,
11987
- manifestFileName: MANIFEST_FILE_NAME
11988
- };
11989
- let filePath = 'boolean' == typeof manifestOptions ? '' : manifestOptions.filePath || '', fileName = 'boolean' == typeof manifestOptions ? '' : manifestOptions.fileName || '', manifestFileName = fileName ? fileName.endsWith(JSON_EXT) ? fileName : `${fileName}${JSON_EXT}` : MANIFEST_FILE_NAME;
11990
- return {
11991
- statsFileName: join(filePath, fileName ? manifestFileName.replace(JSON_EXT, `-stats${JSON_EXT}`) : STATS_FILE_NAME),
11992
- manifestFileName: join(filePath, manifestFileName)
11993
- };
11994
- }(this.opts), rawOptions = {
11995
- name: this.opts.name,
11996
- globalName: this.opts.globalName,
11997
- fileName,
11998
- filePath,
11999
- manifestFileName,
12000
- statsFileName,
12001
- disableAssetsAnalyze,
12002
- remoteAliasMap,
12003
- exposes,
12004
- shared,
12005
- buildInfo: (isDev = 'development' === compiler.options.mode, pkg = function(root) {
12006
- let pkgPath = join(root ? external_node_path_resolve(root) : process.cwd(), 'package.json');
12007
- try {
12008
- let content = readFileSync(pkgPath, 'utf-8'), parsed = function(input, guard) {
12009
- try {
12010
- let parsed = JSON.parse(input);
12011
- if (guard(parsed)) return parsed;
12012
- } catch {}
12013
- }(content, isPlainObject);
12014
- if (parsed) {
12015
- let filtered = {};
12016
- for (let [key, value] of Object.entries(parsed))'string' == typeof value && (filtered[key] = value);
12017
- if (Object.keys(filtered).length > 0) return filtered;
12018
- }
12019
- } catch {}
12020
- return {};
12021
- }(compiler.context || process.cwd()), buildVersion = isDev ? 'local' : pkg?.version, {
12022
- buildVersion: process.env.MF_BUILD_VERSION || buildVersion || 'UNKNOWN',
12023
- buildName: process.env.MF_BUILD_NAME || pkg?.name || 'UNKNOWN'
12024
- })
12025
- };
12026
- return createBuiltinPlugin(this.name, rawOptions);
12027
- }
12028
- }
12029
- let ModuleFederationRuntimePlugin = base_create(binding_namespaceObject.BuiltinPluginName.ModuleFederationRuntimePlugin, (options = {})=>options), parseOptions = (options, normalizeSimple, normalizeOptions)=>{
12451
+ let parseOptions = (options, normalizeSimple, normalizeOptions)=>{
12030
12452
  let items = [];
12031
12453
  var fn = (key, value)=>{
12032
12454
  items.push([
@@ -12043,63 +12465,7 @@ let ModuleFederationRuntimePlugin = base_create(binding_namespaceObject.BuiltinP
12043
12465
  else if ('object' == typeof options) object(options);
12044
12466
  else throw Error('Unexpected options format');
12045
12467
  return items;
12046
- }, ModuleFederationPlugin_require = createRequire(import.meta.url);
12047
- function getRemoteInfos(options) {
12048
- if (!options.remotes) return {};
12049
- let remoteType = options.remoteType || (options.library ? options.library.type : "script"), remotes = parseOptions(options.remotes, (item)=>({
12050
- external: Array.isArray(item) ? item : [
12051
- item
12052
- ],
12053
- shareScope: options.shareScope || 'default'
12054
- }), (item)=>({
12055
- external: Array.isArray(item.external) ? item.external : [
12056
- item.external
12057
- ],
12058
- shareScope: item.shareScope || options.shareScope || 'default'
12059
- })), remoteInfos = {};
12060
- for (let [key, config] of remotes)for (let external of config.external){
12061
- let [externalType, externalRequest] = function(external) {
12062
- let result = function(external) {
12063
- if (/^[a-z0-9-]+ /.test(external)) {
12064
- let idx = external.indexOf(' ');
12065
- return [
12066
- external.slice(0, idx),
12067
- external.slice(idx + 1)
12068
- ];
12069
- }
12070
- return null;
12071
- }(external);
12072
- return null === result ? [
12073
- remoteType,
12074
- external
12075
- ] : result;
12076
- }(external);
12077
- if (remoteInfos[key] ??= [], "script" === externalType) {
12078
- let [url, global] = function(urlAndGlobal) {
12079
- let index = urlAndGlobal.indexOf('@');
12080
- return index <= 0 || index === urlAndGlobal.length - 1 ? null : [
12081
- urlAndGlobal.substring(index + 1),
12082
- urlAndGlobal.substring(0, index)
12083
- ];
12084
- }(externalRequest);
12085
- remoteInfos[key].push({
12086
- alias: key,
12087
- name: global,
12088
- entry: url,
12089
- externalType,
12090
- shareScope: config.shareScope
12091
- });
12092
- } else remoteInfos[key].push({
12093
- alias: key,
12094
- name: void 0,
12095
- entry: void 0,
12096
- externalType,
12097
- shareScope: config.shareScope
12098
- });
12099
- }
12100
- return remoteInfos;
12101
- }
12102
- let compilerSet = new WeakSet();
12468
+ }, compilerSet = new WeakSet();
12103
12469
  class ShareRuntimePlugin extends RspackBuiltinPlugin {
12104
12470
  enhanced;
12105
12471
  name = binding_namespaceObject.BuiltinPluginName.ShareRuntimePlugin;
@@ -12110,42 +12476,55 @@ class ShareRuntimePlugin extends RspackBuiltinPlugin {
12110
12476
  if (!compilerSet.has(compiler)) return compilerSet.add(compiler), createBuiltinPlugin(this.name, this.enhanced);
12111
12477
  }
12112
12478
  }
12113
- class ConsumeSharedPlugin extends RspackBuiltinPlugin {
12479
+ let VERSION_PATTERN_REGEXP = /^([\d^=v<>~]|[*xX]$)/;
12480
+ function isRequiredVersion(str) {
12481
+ return VERSION_PATTERN_REGEXP.test(str);
12482
+ }
12483
+ let encodeName = function(name, prefix = '', withExt = !1) {
12484
+ return `${prefix}${name.replace(/@/g, 'scope_').replace(/-/g, '_').replace(/\//g, '__').replace(/\./g, '')}${withExt ? '.js' : ''}`;
12485
+ };
12486
+ function normalizeConsumeShareOptions(consumes, shareScope) {
12487
+ return parseOptions(consumes, (item, key)=>{
12488
+ if (Array.isArray(item)) throw Error('Unexpected array in options');
12489
+ return item !== key && isRequiredVersion(item) ? {
12490
+ import: key,
12491
+ shareScope: shareScope || 'default',
12492
+ shareKey: key,
12493
+ requiredVersion: item,
12494
+ strictVersion: !0,
12495
+ packageName: void 0,
12496
+ singleton: !1,
12497
+ eager: !1,
12498
+ treeShakingMode: void 0
12499
+ } : {
12500
+ import: key,
12501
+ shareScope: shareScope || 'default',
12502
+ shareKey: key,
12503
+ requiredVersion: void 0,
12504
+ packageName: void 0,
12505
+ strictVersion: !1,
12506
+ singleton: !1,
12507
+ eager: !1,
12508
+ treeShakingMode: void 0
12509
+ };
12510
+ }, (item, key)=>({
12511
+ import: !1 === item.import ? void 0 : item.import || key,
12512
+ shareScope: item.shareScope || shareScope || 'default',
12513
+ shareKey: item.shareKey || key,
12514
+ requiredVersion: item.requiredVersion,
12515
+ strictVersion: 'boolean' == typeof item.strictVersion ? item.strictVersion : !1 !== item.import && !item.singleton,
12516
+ packageName: item.packageName,
12517
+ singleton: !!item.singleton,
12518
+ eager: !!item.eager,
12519
+ treeShakingMode: item.treeShakingMode
12520
+ }));
12521
+ }
12522
+ class ConsumeSharedPlugin extends RspackBuiltinPlugin {
12114
12523
  name = binding_namespaceObject.BuiltinPluginName.ConsumeSharedPlugin;
12115
12524
  _options;
12116
12525
  constructor(options){
12117
12526
  super(), this._options = {
12118
- consumes: parseOptions(options.consumes, (item, key)=>{
12119
- if (Array.isArray(item)) throw Error('Unexpected array in options');
12120
- return item !== key && isRequiredVersion(item) ? {
12121
- import: key,
12122
- shareScope: options.shareScope || 'default',
12123
- shareKey: key,
12124
- requiredVersion: item,
12125
- strictVersion: !0,
12126
- packageName: void 0,
12127
- singleton: !1,
12128
- eager: !1
12129
- } : {
12130
- import: key,
12131
- shareScope: options.shareScope || 'default',
12132
- shareKey: key,
12133
- requiredVersion: void 0,
12134
- packageName: void 0,
12135
- strictVersion: !1,
12136
- singleton: !1,
12137
- eager: !1
12138
- };
12139
- }, (item, key)=>({
12140
- import: !1 === item.import ? void 0 : item.import || key,
12141
- shareScope: item.shareScope || options.shareScope || 'default',
12142
- shareKey: item.shareKey || key,
12143
- requiredVersion: item.requiredVersion,
12144
- strictVersion: 'boolean' == typeof item.strictVersion ? item.strictVersion : !1 !== item.import && !item.singleton,
12145
- packageName: item.packageName,
12146
- singleton: !!item.singleton,
12147
- eager: !!item.eager
12148
- })),
12527
+ consumes: normalizeConsumeShareOptions(options.consumes, options.shareScope),
12149
12528
  enhanced: options.enhanced ?? !1
12150
12529
  };
12151
12530
  }
@@ -12166,28 +12545,30 @@ class ProvideSharedPlugin extends RspackBuiltinPlugin {
12166
12545
  _provides;
12167
12546
  _enhanced;
12168
12547
  constructor(options){
12169
- super(), this._provides = parseOptions(options.provides, (item)=>{
12548
+ var options1, shareScope, enhanced;
12549
+ super(), this._provides = (options1 = options.provides, shareScope = options.shareScope, enhanced = options.enhanced, parseOptions(options1, (item)=>{
12170
12550
  if (Array.isArray(item)) throw Error('Unexpected array of provides');
12171
12551
  return {
12172
12552
  shareKey: item,
12173
12553
  version: void 0,
12174
- shareScope: options.shareScope || 'default',
12554
+ shareScope: shareScope || 'default',
12175
12555
  eager: !1
12176
12556
  };
12177
12557
  }, (item)=>{
12178
12558
  let raw = {
12179
12559
  shareKey: item.shareKey,
12180
12560
  version: item.version,
12181
- shareScope: item.shareScope || options.shareScope || 'default',
12561
+ shareScope: item.shareScope || shareScope || 'default',
12182
12562
  eager: !!item.eager
12183
12563
  };
12184
- return options.enhanced ? {
12564
+ return enhanced ? {
12185
12565
  ...raw,
12186
12566
  singleton: item.singleton,
12187
12567
  requiredVersion: item.requiredVersion,
12188
- strictVersion: item.strictVersion
12568
+ strictVersion: item.strictVersion,
12569
+ treeShakingMode: item.treeShakingMode
12189
12570
  } : raw;
12190
- }), this._enhanced = options.enhanced;
12571
+ })), this._enhanced = options.enhanced;
12191
12572
  }
12192
12573
  raw(compiler) {
12193
12574
  new ShareRuntimePlugin(this._enhanced ?? !1).apply(compiler);
@@ -12198,32 +12579,40 @@ class ProvideSharedPlugin extends RspackBuiltinPlugin {
12198
12579
  return createBuiltinPlugin(this.name, rawOptions);
12199
12580
  }
12200
12581
  }
12582
+ function normalizeSharedOptions(shared) {
12583
+ return parseOptions(shared, (item, key)=>{
12584
+ if ('string' != typeof item) throw Error('Unexpected array in shared');
12585
+ return item !== key && isRequiredVersion(item) ? {
12586
+ import: key,
12587
+ requiredVersion: item
12588
+ } : {
12589
+ import: item
12590
+ };
12591
+ }, (item)=>item);
12592
+ }
12593
+ function createConsumeShareOptions(normalizedSharedOptions) {
12594
+ return normalizedSharedOptions.map(([key, options])=>({
12595
+ [key]: {
12596
+ import: options.import,
12597
+ shareKey: options.shareKey || key,
12598
+ shareScope: options.shareScope,
12599
+ requiredVersion: options.requiredVersion,
12600
+ strictVersion: options.strictVersion,
12601
+ singleton: options.singleton,
12602
+ packageName: options.packageName,
12603
+ eager: options.eager,
12604
+ treeShakingMode: options.treeShaking?.mode
12605
+ }
12606
+ }));
12607
+ }
12201
12608
  class SharePlugin {
12202
12609
  _shareScope;
12203
12610
  _consumes;
12204
12611
  _provides;
12205
12612
  _enhanced;
12613
+ _sharedOptions;
12206
12614
  constructor(options){
12207
- let sharedOptions = parseOptions(options.shared, (item, key)=>{
12208
- if ('string' != typeof item) throw Error('Unexpected array in shared');
12209
- return item !== key && isRequiredVersion(item) ? {
12210
- import: key,
12211
- requiredVersion: item
12212
- } : {
12213
- import: item
12214
- };
12215
- }, (item)=>item), consumes = sharedOptions.map(([key, options])=>({
12216
- [key]: {
12217
- import: options.import,
12218
- shareKey: options.shareKey || key,
12219
- shareScope: options.shareScope,
12220
- requiredVersion: options.requiredVersion,
12221
- strictVersion: options.strictVersion,
12222
- singleton: options.singleton,
12223
- packageName: options.packageName,
12224
- eager: options.eager
12225
- }
12226
- })), provides = sharedOptions.filter(([, options])=>!1 !== options.import).map(([key, options])=>({
12615
+ let sharedOptions = normalizeSharedOptions(options.shared), consumes = createConsumeShareOptions(sharedOptions), provides = sharedOptions.filter(([, options])=>!1 !== options.import).map(([key, options])=>({
12227
12616
  [options.import || key]: {
12228
12617
  shareKey: options.shareKey || key,
12229
12618
  shareScope: options.shareScope,
@@ -12231,10 +12620,11 @@ class SharePlugin {
12231
12620
  eager: options.eager,
12232
12621
  singleton: options.singleton,
12233
12622
  requiredVersion: options.requiredVersion,
12234
- strictVersion: options.strictVersion
12623
+ strictVersion: options.strictVersion,
12624
+ treeShakingMode: options.treeShaking?.mode
12235
12625
  }
12236
12626
  }));
12237
- this._shareScope = options.shareScope, this._consumes = consumes, this._provides = provides, this._enhanced = options.enhanced ?? !1;
12627
+ this._shareScope = options.shareScope, this._consumes = consumes, this._provides = provides, this._enhanced = options.enhanced ?? !1, this._sharedOptions = sharedOptions;
12238
12628
  }
12239
12629
  apply(compiler) {
12240
12630
  new ConsumeSharedPlugin({
@@ -12248,6 +12638,555 @@ class SharePlugin {
12248
12638
  }).apply(compiler);
12249
12639
  }
12250
12640
  }
12641
+ let MANIFEST_FILE_NAME = 'mf-manifest.json', STATS_FILE_NAME = 'mf-stats.json', JSON_EXT = '.json';
12642
+ function isPlainObject(value) {
12643
+ return !!value && 'object' == typeof value && !Array.isArray(value);
12644
+ }
12645
+ function getFileName(manifestOptions) {
12646
+ if (!manifestOptions) return {
12647
+ statsFileName: '',
12648
+ manifestFileName: ''
12649
+ };
12650
+ if ('boolean' == typeof manifestOptions) return {
12651
+ statsFileName: STATS_FILE_NAME,
12652
+ manifestFileName: MANIFEST_FILE_NAME
12653
+ };
12654
+ let filePath = 'boolean' == typeof manifestOptions ? '' : manifestOptions.filePath || '', fileName = 'boolean' == typeof manifestOptions ? '' : manifestOptions.fileName || '', manifestFileName = fileName ? fileName.endsWith(JSON_EXT) ? fileName : `${fileName}${JSON_EXT}` : MANIFEST_FILE_NAME;
12655
+ return {
12656
+ statsFileName: join(filePath, fileName ? manifestFileName.replace(JSON_EXT, `-stats${JSON_EXT}`) : STATS_FILE_NAME),
12657
+ manifestFileName: join(filePath, manifestFileName)
12658
+ };
12659
+ }
12660
+ class ModuleFederationManifestPlugin extends RspackBuiltinPlugin {
12661
+ name = binding_namespaceObject.BuiltinPluginName.ModuleFederationManifestPlugin;
12662
+ rawOpts;
12663
+ constructor(opts){
12664
+ super(), this.rawOpts = opts;
12665
+ }
12666
+ raw(compiler) {
12667
+ var mfConfig, isDev, mfConfig1;
12668
+ let manifestOptions, containerName, globalName, remoteAliasMap, manifestExposes, manifestShared, pkg, buildVersion, statsBuildInfo, opts = (manifestOptions = !0 === (mfConfig = this.rawOpts).manifest ? {} : {
12669
+ ...mfConfig.manifest
12670
+ }, containerName = mfConfig.name, globalName = function(library) {
12671
+ if (!library) return;
12672
+ let libName = library.name;
12673
+ if (libName) {
12674
+ if ('string' == typeof libName) return libName;
12675
+ if (Array.isArray(libName)) return libName[0];
12676
+ if ('object' == typeof libName) return libName.root?.[0] ?? libName.amd ?? libName.commonjs ?? void 0;
12677
+ }
12678
+ }(mfConfig.library) ?? containerName, remoteAliasMap = Object.entries(getRemoteInfos(mfConfig)).reduce((sum, cur)=>{
12679
+ if (cur[1].length > 1) return sum;
12680
+ let { entry, alias, name } = cur[1][0];
12681
+ return entry && name && (sum[alias] = {
12682
+ name,
12683
+ entry
12684
+ }), sum;
12685
+ }, {}), manifestExposes = function(exposes) {
12686
+ if (!exposes) return;
12687
+ let result = parseOptions(exposes, (value)=>({
12688
+ import: Array.isArray(value) ? value : [
12689
+ value
12690
+ ],
12691
+ name: void 0
12692
+ }), (value)=>({
12693
+ import: Array.isArray(value.import) ? value.import : [
12694
+ value.import
12695
+ ],
12696
+ name: value.name ?? void 0
12697
+ })).map(([exposeKey, info])=>{
12698
+ let exposeName = info.name ?? exposeKey.replace(/^\.\//, '');
12699
+ return {
12700
+ path: exposeKey,
12701
+ name: exposeName
12702
+ };
12703
+ });
12704
+ return result.length > 0 ? result : void 0;
12705
+ }(mfConfig.exposes), void 0 === manifestOptions.exposes && manifestExposes && (manifestOptions.exposes = manifestExposes), manifestShared = function(shared) {
12706
+ if (!shared) return;
12707
+ let result = parseOptions(shared, (item, key)=>{
12708
+ if ('string' != typeof item) throw Error('Unexpected array in shared');
12709
+ return item !== key && isRequiredVersion(item) ? {
12710
+ import: key,
12711
+ requiredVersion: item
12712
+ } : {
12713
+ import: item
12714
+ };
12715
+ }, (item)=>item).map(([key, config])=>{
12716
+ let name = config.shareKey || key;
12717
+ return {
12718
+ name,
12719
+ version: 'string' == typeof config.version ? config.version : void 0,
12720
+ requiredVersion: 'string' == typeof config.requiredVersion ? config.requiredVersion : void 0,
12721
+ singleton: config.singleton
12722
+ };
12723
+ });
12724
+ return result.length > 0 ? result : void 0;
12725
+ }(mfConfig.shared), void 0 === manifestOptions.shared && manifestShared && (manifestOptions.shared = manifestShared), {
12726
+ ...manifestOptions,
12727
+ remoteAliasMap,
12728
+ globalName,
12729
+ name: containerName
12730
+ }), { fileName, filePath, disableAssetsAnalyze, remoteAliasMap: remoteAliasMap1, exposes, shared } = opts, { statsFileName, manifestFileName } = getFileName(opts), rawOptions = {
12731
+ name: opts.name,
12732
+ globalName: opts.globalName,
12733
+ fileName,
12734
+ filePath,
12735
+ manifestFileName,
12736
+ statsFileName,
12737
+ disableAssetsAnalyze,
12738
+ remoteAliasMap: remoteAliasMap1,
12739
+ exposes,
12740
+ shared,
12741
+ buildInfo: (isDev = 'development' === compiler.options.mode, mfConfig1 = this.rawOpts, pkg = function(root) {
12742
+ let pkgPath = join(root ? external_node_path_resolve(root) : process.cwd(), 'package.json');
12743
+ try {
12744
+ let content = readFileSync(pkgPath, 'utf-8'), parsed = function(input, guard) {
12745
+ try {
12746
+ let parsed = JSON.parse(input);
12747
+ if (guard(parsed)) return parsed;
12748
+ } catch {}
12749
+ }(content, isPlainObject);
12750
+ if (parsed) {
12751
+ let filtered = {};
12752
+ for (let [key, value] of Object.entries(parsed))'string' == typeof value && (filtered[key] = value);
12753
+ if (Object.keys(filtered).length > 0) return filtered;
12754
+ }
12755
+ } catch {}
12756
+ return {};
12757
+ }(compiler.options.context || process.cwd()), buildVersion = isDev ? 'local' : pkg?.version, statsBuildInfo = {
12758
+ buildVersion: process.env.MF_BUILD_VERSION || buildVersion || 'UNKNOWN',
12759
+ buildName: process.env.MF_BUILD_NAME || pkg?.name || 'UNKNOWN'
12760
+ }, Object.values(normalizeSharedOptions(mfConfig1.shared || {})).some((config)=>config[1].treeShaking) && (statsBuildInfo.target = Array.isArray(compiler.options.target) ? compiler.options.target : [], statsBuildInfo.plugins = mfConfig1.treeShakingSharedPlugins || [], statsBuildInfo.excludePlugins = mfConfig1.treeShakingSharedExcludePlugins || []), statsBuildInfo)
12761
+ };
12762
+ return createBuiltinPlugin(this.name, rawOptions);
12763
+ }
12764
+ }
12765
+ let SHARE_ENTRY_ASSET = 'collect-shared-entries.json';
12766
+ class CollectSharedEntryPlugin extends RspackBuiltinPlugin {
12767
+ name = binding_namespaceObject.BuiltinPluginName.CollectSharedEntryPlugin;
12768
+ sharedOptions;
12769
+ _collectedEntries;
12770
+ constructor(options){
12771
+ super();
12772
+ let { sharedOptions } = options;
12773
+ this.sharedOptions = sharedOptions, this._collectedEntries = {};
12774
+ }
12775
+ getData() {
12776
+ return this._collectedEntries;
12777
+ }
12778
+ getFilename() {
12779
+ return SHARE_ENTRY_ASSET;
12780
+ }
12781
+ apply(compiler) {
12782
+ super.apply(compiler), compiler.hooks.thisCompilation.tap('Collect shared entry', (compilation)=>{
12783
+ compilation.hooks.processAssets.tap({
12784
+ name: 'CollectSharedEntry',
12785
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE
12786
+ }, ()=>{
12787
+ compilation.getAssets().forEach((asset)=>{
12788
+ asset.name === SHARE_ENTRY_ASSET && (this._collectedEntries = JSON.parse(asset.source.source().toString())), compilation.deleteAsset(asset.name);
12789
+ });
12790
+ });
12791
+ });
12792
+ }
12793
+ raw() {
12794
+ let rawOptions = {
12795
+ consumes: normalizeConsumeShareOptions(createConsumeShareOptions(this.sharedOptions)).map(([key, v])=>({
12796
+ key,
12797
+ ...v
12798
+ })),
12799
+ filename: this.getFilename()
12800
+ };
12801
+ return createBuiltinPlugin(this.name, rawOptions);
12802
+ }
12803
+ }
12804
+ function assert(condition, msg) {
12805
+ if (!condition) throw Error(msg);
12806
+ }
12807
+ class SharedContainerPlugin extends RspackBuiltinPlugin {
12808
+ name = binding_namespaceObject.BuiltinPluginName.SharedContainerPlugin;
12809
+ filename = '';
12810
+ _options;
12811
+ _shareName;
12812
+ _globalName;
12813
+ constructor(options){
12814
+ super();
12815
+ let { shareName, library, request, independentShareFileName, mfName } = options, version = options.version || '0.0.0';
12816
+ this._globalName = encodeName(`${mfName}_${shareName}_${version}`);
12817
+ let fileName = independentShareFileName || `${version}/share-entry.js`;
12818
+ this._shareName = shareName, this._options = {
12819
+ name: shareName,
12820
+ request: request,
12821
+ library: (library ? {
12822
+ ...library,
12823
+ name: this._globalName
12824
+ } : void 0) || {
12825
+ type: 'global',
12826
+ name: this._globalName
12827
+ },
12828
+ version,
12829
+ fileName
12830
+ };
12831
+ }
12832
+ getData() {
12833
+ return [
12834
+ this._options.fileName,
12835
+ this._globalName,
12836
+ this._options.version
12837
+ ];
12838
+ }
12839
+ raw(compiler) {
12840
+ let { library } = this._options;
12841
+ return compiler.options.output.enabledLibraryTypes.includes(library.type) || compiler.options.output.enabledLibraryTypes.push(library.type), createBuiltinPlugin(this.name, this._options);
12842
+ }
12843
+ apply(compiler) {
12844
+ super.apply(compiler);
12845
+ let shareName = this._shareName;
12846
+ compiler.hooks.thisCompilation.tap(this.name, (compilation)=>{
12847
+ compilation.hooks.processAssets.tap({
12848
+ name: 'getShareContainerFile'
12849
+ }, ()=>{
12850
+ assert(compilation.entrypoints.get(shareName), `Can not get shared ${shareName} entryPoint!`);
12851
+ let remoteEntryNameChunk = compilation.namedChunks.get(shareName);
12852
+ assert(remoteEntryNameChunk, `Can not get shared ${shareName} chunk!`);
12853
+ let files = Array.from(remoteEntryNameChunk.files).filter((f)=>!f.includes('.hot-update') && !f.endsWith('.css'));
12854
+ assert(files.length > 0, `no files found for shared ${shareName} chunk`), assert(1 === files.length, `shared ${shareName} chunk should not have multiple files!, current files: ${files.join(',')}`), this.filename = files[0];
12855
+ });
12856
+ });
12857
+ }
12858
+ }
12859
+ class SharedUsedExportsOptimizerPlugin extends RspackBuiltinPlugin {
12860
+ name = binding_namespaceObject.BuiltinPluginName.SharedUsedExportsOptimizerPlugin;
12861
+ sharedOptions;
12862
+ injectTreeShakingUsedExports;
12863
+ manifestOptions;
12864
+ constructor(sharedOptions, injectTreeShakingUsedExports, manifestOptions){
12865
+ super(), this.sharedOptions = sharedOptions, this.injectTreeShakingUsedExports = injectTreeShakingUsedExports ?? !0, this.manifestOptions = manifestOptions ?? {};
12866
+ }
12867
+ buildOptions() {
12868
+ let shared = this.sharedOptions.map(([shareKey, config])=>({
12869
+ shareKey,
12870
+ treeShaking: !!config.treeShaking,
12871
+ usedExports: config.treeShaking?.usedExports
12872
+ })), { manifestFileName, statsFileName } = getFileName(this.manifestOptions);
12873
+ return {
12874
+ shared,
12875
+ injectTreeShakingUsedExports: this.injectTreeShakingUsedExports,
12876
+ manifestFileName,
12877
+ statsFileName
12878
+ };
12879
+ }
12880
+ raw() {
12881
+ if (this.sharedOptions.length) return createBuiltinPlugin(this.name, this.buildOptions());
12882
+ }
12883
+ }
12884
+ let VIRTUAL_ENTRY = './virtual-entry.js', VIRTUAL_ENTRY_NAME = 'virtual-entry';
12885
+ class VirtualEntryPlugin {
12886
+ sharedOptions;
12887
+ collectShared = !1;
12888
+ constructor(sharedOptions, collectShared){
12889
+ this.sharedOptions = sharedOptions, this.collectShared = collectShared;
12890
+ }
12891
+ createEntry() {
12892
+ let { sharedOptions, collectShared } = this;
12893
+ return sharedOptions.reduce((acc, cur, index)=>acc + `import shared_${index} from '${cur[0]}';\n` + (collectShared ? `console.log(shared_${index});\n` : ''), '');
12894
+ }
12895
+ static entry() {
12896
+ return {
12897
+ [VIRTUAL_ENTRY_NAME]: VIRTUAL_ENTRY
12898
+ };
12899
+ }
12900
+ apply(compiler) {
12901
+ new compiler.rspack.experiments.VirtualModulesPlugin({
12902
+ [VIRTUAL_ENTRY]: this.createEntry()
12903
+ }).apply(compiler), compiler.hooks.thisCompilation.tap('RemoveVirtualEntryAsset', (compilation)=>{
12904
+ compilation.hooks.processAssets.tap({
12905
+ name: 'RemoveVirtualEntryAsset',
12906
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE
12907
+ }, ()=>{
12908
+ try {
12909
+ let chunk = compilation.namedChunks.get(VIRTUAL_ENTRY_NAME);
12910
+ chunk?.files.forEach((f)=>{
12911
+ compilation.deleteAsset(f);
12912
+ });
12913
+ } catch (_e) {
12914
+ console.error('Failed to remove virtual entry file!');
12915
+ }
12916
+ });
12917
+ });
12918
+ }
12919
+ }
12920
+ let resolveOutputDir = (outputDir, shareName)=>shareName ? join(outputDir, encodeName(shareName)) : outputDir;
12921
+ class IndependentSharedPlugin {
12922
+ mfName;
12923
+ shared;
12924
+ library;
12925
+ sharedOptions;
12926
+ outputDir;
12927
+ plugins;
12928
+ treeShaking;
12929
+ manifest;
12930
+ buildAssets = {};
12931
+ injectTreeShakingUsedExports;
12932
+ treeShakingSharedExcludePlugins;
12933
+ name = 'IndependentSharedPlugin';
12934
+ constructor(options){
12935
+ let { outputDir, plugins, treeShaking, shared, name, manifest, injectTreeShakingUsedExports, library, treeShakingSharedExcludePlugins } = options;
12936
+ this.shared = shared, this.mfName = name, this.outputDir = outputDir || 'independent-packages', this.plugins = plugins || [], this.treeShaking = treeShaking, this.manifest = manifest, this.injectTreeShakingUsedExports = injectTreeShakingUsedExports ?? !0, this.library = library, this.treeShakingSharedExcludePlugins = treeShakingSharedExcludePlugins || [], this.sharedOptions = parseOptions(shared, (item, key)=>{
12937
+ if ('string' != typeof item) throw Error(`Unexpected array in shared configuration for key "${key}"`);
12938
+ return item !== key && isRequiredVersion(item) ? {
12939
+ import: key,
12940
+ requiredVersion: item
12941
+ } : {
12942
+ import: item
12943
+ };
12944
+ }, (item)=>item);
12945
+ }
12946
+ apply(compiler) {
12947
+ let { manifest } = this, runCount = 0;
12948
+ compiler.hooks.beforeRun.tapPromise('IndependentSharedPlugin', async ()=>{
12949
+ !runCount && (await this.createIndependentCompilers(compiler), runCount++);
12950
+ }), compiler.hooks.watchRun.tapPromise('IndependentSharedPlugin', async ()=>{
12951
+ !runCount && (await this.createIndependentCompilers(compiler), runCount++);
12952
+ }), manifest && compiler.hooks.compilation.tap('IndependentSharedPlugin', (compilation)=>{
12953
+ compilation.hooks.processAssets.tap({
12954
+ name: 'injectBuildAssets',
12955
+ stage: compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
12956
+ }, ()=>{
12957
+ let { statsFileName, manifestFileName } = getFileName(manifest), injectBuildAssetsIntoStatsOrManifest = (filename)=>{
12958
+ let stats = compilation.getAsset(filename);
12959
+ if (!stats) return;
12960
+ let statsContent = JSON.parse(stats.source.source().toString()), { shared } = statsContent;
12961
+ Object.entries(this.buildAssets).forEach(([key, item])=>{
12962
+ let targetShared = shared.find((s)=>s.name === key);
12963
+ targetShared && item.forEach(([entry, version, globalName])=>{
12964
+ version === targetShared.version && (targetShared.fallback = entry, targetShared.fallbackName = globalName);
12965
+ });
12966
+ }), compilation.updateAsset(filename, new compiler.webpack.sources.RawSource(JSON.stringify(statsContent)));
12967
+ };
12968
+ injectBuildAssetsIntoStatsOrManifest(statsFileName), injectBuildAssetsIntoStatsOrManifest(manifestFileName);
12969
+ });
12970
+ });
12971
+ }
12972
+ async createIndependentCompilers(parentCompiler) {
12973
+ let { sharedOptions, buildAssets, outputDir } = this;
12974
+ console.log('Start building shared fallback resources ...');
12975
+ let shareRequestsMap = await this.createIndependentCompiler(parentCompiler);
12976
+ await Promise.all(sharedOptions.map(async ([shareName, shareConfig])=>{
12977
+ if (!shareConfig.treeShaking || !1 === shareConfig.import) return;
12978
+ let shareRequests = shareRequestsMap[shareName].requests;
12979
+ await Promise.all(shareRequests.map(async ([request, version])=>{
12980
+ let sharedConfig = sharedOptions.find(([name])=>name === shareName)?.[1], [shareFileName, globalName, sharedVersion] = await this.createIndependentCompiler(parentCompiler, {
12981
+ shareRequestsMap,
12982
+ currentShare: {
12983
+ shareName,
12984
+ version,
12985
+ request,
12986
+ independentShareFileName: sharedConfig?.treeShaking?.filename
12987
+ }
12988
+ });
12989
+ 'string' == typeof shareFileName && (buildAssets[shareName] ||= [], buildAssets[shareName].push([
12990
+ join(resolveOutputDir(outputDir, shareName), shareFileName),
12991
+ sharedVersion,
12992
+ globalName
12993
+ ]));
12994
+ }));
12995
+ })), console.log('All shared fallback have been compiled successfully!');
12996
+ }
12997
+ async createIndependentCompiler(parentCompiler, extraOptions) {
12998
+ let extraPlugin, { mfName, plugins, outputDir, sharedOptions, treeShaking, library, treeShakingSharedExcludePlugins } = this, outputDirWithShareName = resolveOutputDir(outputDir, extraOptions?.currentShare?.shareName || ''), parentConfig = parentCompiler.options, finalPlugins = [], rspack = parentCompiler.rspack;
12999
+ extraPlugin = extraOptions ? new SharedContainerPlugin({
13000
+ mfName: `${mfName}_${treeShaking ? 't' : 'f'}`,
13001
+ library,
13002
+ ...extraOptions.currentShare
13003
+ }) : new CollectSharedEntryPlugin({
13004
+ sharedOptions,
13005
+ shareScope: 'default'
13006
+ }), (parentConfig.plugins || []).forEach((plugin)=>{
13007
+ void 0 !== plugin && 'string' != typeof plugin && ((plugin, excludedPlugins = [])=>{
13008
+ if (!plugin) return !0;
13009
+ let pluginName = plugin.name || plugin.constructor?.name;
13010
+ return !pluginName || ![
13011
+ 'TreeShakingSharedPlugin',
13012
+ 'IndependentSharedPlugin',
13013
+ 'ModuleFederationPlugin',
13014
+ 'SharedUsedExportsOptimizerPlugin',
13015
+ 'HtmlWebpackPlugin',
13016
+ 'HtmlRspackPlugin',
13017
+ 'RsbuildHtmlPlugin',
13018
+ ...excludedPlugins
13019
+ ].includes(pluginName);
13020
+ })(plugin, treeShakingSharedExcludePlugins) && finalPlugins.push(plugin);
13021
+ }), plugins.forEach((plugin)=>{
13022
+ finalPlugins.push(plugin);
13023
+ }), finalPlugins.push(extraPlugin), finalPlugins.push(new ConsumeSharedPlugin({
13024
+ consumes: sharedOptions.filter(([key, options])=>extraOptions?.currentShare.shareName !== (options.shareKey || key)).map(([key, options])=>({
13025
+ [key]: {
13026
+ import: !extraOptions && options.import,
13027
+ shareKey: options.shareKey || key,
13028
+ shareScope: options.shareScope,
13029
+ requiredVersion: options.requiredVersion,
13030
+ strictVersion: options.strictVersion,
13031
+ singleton: options.singleton,
13032
+ packageName: options.packageName,
13033
+ eager: options.eager
13034
+ }
13035
+ })),
13036
+ enhanced: !0
13037
+ })), treeShaking && finalPlugins.push(new SharedUsedExportsOptimizerPlugin(sharedOptions, this.injectTreeShakingUsedExports)), finalPlugins.push(new VirtualEntryPlugin(sharedOptions, !extraOptions));
13038
+ let fullOutputDir = external_node_path_resolve(parentCompiler.outputPath, outputDirWithShareName), compilerConfig = {
13039
+ ...parentConfig,
13040
+ module: {
13041
+ ...parentConfig.module,
13042
+ rules: [
13043
+ {
13044
+ test: /virtual-entry\.js$/,
13045
+ type: "javascript/auto",
13046
+ resolve: {
13047
+ fullySpecified: !1
13048
+ },
13049
+ use: {
13050
+ loader: 'builtin:swc-loader'
13051
+ }
13052
+ },
13053
+ ...parentConfig.module?.rules || []
13054
+ ]
13055
+ },
13056
+ mode: parentConfig.mode || 'development',
13057
+ entry: VirtualEntryPlugin.entry,
13058
+ output: {
13059
+ path: fullOutputDir,
13060
+ clean: !0,
13061
+ publicPath: parentConfig.output?.publicPath || 'auto'
13062
+ },
13063
+ plugins: finalPlugins,
13064
+ optimization: {
13065
+ ...parentConfig.optimization,
13066
+ splitChunks: !1
13067
+ }
13068
+ }, compiler = rspack.rspack(compilerConfig);
13069
+ compiler.inputFileSystem = parentCompiler.inputFileSystem, compiler.outputFileSystem = parentCompiler.outputFileSystem, compiler.intermediateFileSystem = parentCompiler.intermediateFileSystem;
13070
+ let { currentShare } = extraOptions || {};
13071
+ return new Promise((resolve, reject)=>{
13072
+ compiler.run((err, stats)=>{
13073
+ if (err || stats?.hasErrors()) {
13074
+ let target = currentShare ? currentShare.shareName : 'Collect deps';
13075
+ console.error(`${target} Compile failed:`, err || stats.toJson().errors.map((e)=>e.message).join('\n')), reject(err || Error(`${target} Compile failed`));
13076
+ return;
13077
+ }
13078
+ currentShare && console.log(`${currentShare.shareName} Compile success`), resolve(extraPlugin.getData());
13079
+ });
13080
+ });
13081
+ }
13082
+ }
13083
+ let TreeShakingSharedPlugin_require = createRequire(import.meta.url);
13084
+ class TreeShakingSharedPlugin {
13085
+ mfConfig;
13086
+ outputDir;
13087
+ secondary;
13088
+ _independentSharePlugin;
13089
+ name = 'TreeShakingSharedPlugin';
13090
+ constructor(options){
13091
+ let { mfConfig, secondary } = options;
13092
+ this.mfConfig = mfConfig, this.outputDir = mfConfig.treeShakingSharedDir || 'independent-packages', this.secondary = !!secondary;
13093
+ }
13094
+ apply(compiler) {
13095
+ let { mfConfig, outputDir, secondary } = this, { name, shared, library, treeShakingSharedPlugins } = mfConfig;
13096
+ if (!shared) return;
13097
+ let sharedOptions = normalizeSharedOptions(shared);
13098
+ sharedOptions.length && sharedOptions.some(([_, config])=>config.treeShaking && !1 !== config.import) && (secondary || new SharedUsedExportsOptimizerPlugin(sharedOptions, mfConfig.injectTreeShakingUsedExports, mfConfig.manifest).apply(compiler), this._independentSharePlugin = new IndependentSharedPlugin({
13099
+ name: name,
13100
+ shared: shared,
13101
+ outputDir,
13102
+ plugins: treeShakingSharedPlugins?.map((p)=>new (TreeShakingSharedPlugin_require(p))()) || [],
13103
+ treeShaking: secondary,
13104
+ library,
13105
+ manifest: mfConfig.manifest,
13106
+ treeShakingSharedExcludePlugins: mfConfig.treeShakingSharedExcludePlugins
13107
+ }), this._independentSharePlugin.apply(compiler));
13108
+ }
13109
+ get buildAssets() {
13110
+ return this._independentSharePlugin?.buildAssets || {};
13111
+ }
13112
+ }
13113
+ let ModuleFederationRuntimePlugin = base_create(binding_namespaceObject.BuiltinPluginName.ModuleFederationRuntimePlugin, (options = {})=>options), ModuleFederationPlugin_require = createRequire(import.meta.url);
13114
+ function getRemoteInfos(options) {
13115
+ if (!options.remotes) return {};
13116
+ let remoteType = options.remoteType || (options.library ? options.library.type : "script"), remotes = parseOptions(options.remotes, (item)=>({
13117
+ external: Array.isArray(item) ? item : [
13118
+ item
13119
+ ],
13120
+ shareScope: options.shareScope || 'default'
13121
+ }), (item)=>({
13122
+ external: Array.isArray(item.external) ? item.external : [
13123
+ item.external
13124
+ ],
13125
+ shareScope: item.shareScope || options.shareScope || 'default'
13126
+ })), remoteInfos = {};
13127
+ for (let [key, config] of remotes)for (let external of config.external){
13128
+ let [externalType, externalRequest] = function(external) {
13129
+ let result = function(external) {
13130
+ if (/^[a-z0-9-]+ /.test(external)) {
13131
+ let idx = external.indexOf(' ');
13132
+ return [
13133
+ external.slice(0, idx),
13134
+ external.slice(idx + 1)
13135
+ ];
13136
+ }
13137
+ return null;
13138
+ }(external);
13139
+ return null === result ? [
13140
+ remoteType,
13141
+ external
13142
+ ] : result;
13143
+ }(external);
13144
+ if (remoteInfos[key] ??= [], "script" === externalType) {
13145
+ let [url, global] = function(urlAndGlobal) {
13146
+ let index = urlAndGlobal.indexOf('@');
13147
+ return index <= 0 || index === urlAndGlobal.length - 1 ? null : [
13148
+ urlAndGlobal.substring(index + 1),
13149
+ urlAndGlobal.substring(0, index)
13150
+ ];
13151
+ }(externalRequest);
13152
+ remoteInfos[key].push({
13153
+ alias: key,
13154
+ name: global,
13155
+ entry: url,
13156
+ externalType,
13157
+ shareScope: config.shareScope
13158
+ });
13159
+ } else remoteInfos[key].push({
13160
+ alias: key,
13161
+ name: void 0,
13162
+ entry: void 0,
13163
+ externalType,
13164
+ shareScope: config.shareScope
13165
+ });
13166
+ }
13167
+ return remoteInfos;
13168
+ }
13169
+ function getDefaultEntryRuntime(paths, options, compiler, treeShakingShareFallbacks) {
13170
+ let runtimePlugins = options.runtimePlugins ?? [], remoteInfos = getRemoteInfos(options), runtimePluginImports = [], runtimePluginVars = [], libraryType = options.library?.type || 'var';
13171
+ for(let i = 0; i < runtimePlugins.length; i++){
13172
+ let runtimePluginVar = `__module_federation_runtime_plugin_${i}__`, pluginSpec = runtimePlugins[i], pluginPath = Array.isArray(pluginSpec) ? pluginSpec[0] : pluginSpec, pluginParams = Array.isArray(pluginSpec) ? pluginSpec[1] : void 0;
13173
+ runtimePluginImports.push(`import ${runtimePluginVar} from ${JSON.stringify(pluginPath)}`);
13174
+ let paramsCode = void 0 === pluginParams ? 'undefined' : JSON.stringify(pluginParams);
13175
+ runtimePluginVars.push(`{ plugin: ${runtimePluginVar}, params: ${paramsCode} }`);
13176
+ }
13177
+ let content = [
13178
+ `import __module_federation_bundler_runtime__ from ${JSON.stringify(paths.bundlerRuntime)}`,
13179
+ ...runtimePluginImports,
13180
+ `const __module_federation_runtime_plugins__ = [${runtimePluginVars.join(', ')}].filter(({ plugin }) => plugin).map(({ plugin, params }) => plugin(params))`,
13181
+ `const __module_federation_remote_infos__ = ${JSON.stringify(remoteInfos)}`,
13182
+ `const __module_federation_container_name__ = ${JSON.stringify(options.name ?? compiler.options.output.uniqueName)}`,
13183
+ `const __module_federation_share_strategy__ = ${JSON.stringify(options.shareStrategy ?? 'version-first')}`,
13184
+ `const __module_federation_share_fallbacks__ = ${JSON.stringify(treeShakingShareFallbacks)}`,
13185
+ `const __module_federation_library_type__ = ${JSON.stringify(libraryType)}`,
13186
+ compiler.webpack.Template.getFunctionContent(ModuleFederationPlugin_require('./moduleFederationDefaultRuntime.js').default)
13187
+ ].join(';');
13188
+ return `@module-federation/runtime/rspack.js!=!data:text/javascript,${content}`;
13189
+ }
12251
13190
  class ContainerPlugin extends RspackBuiltinPlugin {
12252
13191
  name = binding_namespaceObject.BuiltinPluginName.ContainerPlugin;
12253
13192
  _options;
@@ -12256,7 +13195,7 @@ class ContainerPlugin extends RspackBuiltinPlugin {
12256
13195
  name: options.name,
12257
13196
  shareScope: options.shareScope || 'default',
12258
13197
  library: options.library || {
12259
- type: 'var',
13198
+ type: 'global',
12260
13199
  name: options.name
12261
13200
  },
12262
13201
  runtime: options.runtime,
@@ -12343,7 +13282,7 @@ async function transform(source, options) {
12343
13282
  let _options = JSON.stringify(options || {});
12344
13283
  return binding_default().transform(source, _options);
12345
13284
  }
12346
- let exports_rspackVersion = "2.0.0-beta.0", exports_version = "5.75.0", exports_WebpackError = Error, exports_config = {
13285
+ let exports_rspackVersion = "2.0.0-beta.1", exports_version = "5.75.0", exports_WebpackError = Error, exports_config = {
12347
13286
  getNormalizedRspackOptions: getNormalizedRspackOptions,
12348
13287
  applyRspackOptionsDefaults: applyRspackOptionsDefaults,
12349
13288
  getNormalizedWebpackOptions: getNormalizedRspackOptions,
@@ -12386,10 +13325,12 @@ let exports_rspackVersion = "2.0.0-beta.0", exports_version = "5.75.0", exports_
12386
13325
  ContainerReferencePlugin: ContainerReferencePlugin,
12387
13326
  ModuleFederationPlugin: class {
12388
13327
  _options;
13328
+ _treeShakingSharedPlugin;
12389
13329
  constructor(_options){
12390
13330
  this._options = _options;
12391
13331
  }
12392
13332
  apply(compiler) {
13333
+ var options;
12393
13334
  let { webpack } = compiler, paths = function(options, compiler) {
12394
13335
  let runtimeToolsPath;
12395
13336
  if (options.implementation) runtimeToolsPath = options.implementation;
@@ -12422,32 +13363,38 @@ let exports_rspackVersion = "2.0.0-beta.0", exports_version = "5.75.0", exports_
12422
13363
  '@module-federation/runtime-tools': paths.runtimeTools,
12423
13364
  '@module-federation/runtime': paths.runtime,
12424
13365
  ...compiler.options.resolve.alias
12425
- };
12426
- let entryRuntime = function(paths, options, compiler) {
12427
- let runtimePlugins = options.runtimePlugins ?? [], remoteInfos = getRemoteInfos(options), runtimePluginImports = [], runtimePluginVars = [];
12428
- for(let i = 0; i < runtimePlugins.length; i++){
12429
- let runtimePluginVar = `__module_federation_runtime_plugin_${i}__`, pluginSpec = runtimePlugins[i], pluginPath = Array.isArray(pluginSpec) ? pluginSpec[0] : pluginSpec, pluginParams = Array.isArray(pluginSpec) ? pluginSpec[1] : void 0;
12430
- runtimePluginImports.push(`import ${runtimePluginVar} from ${JSON.stringify(pluginPath)}`);
12431
- let paramsCode = void 0 === pluginParams ? 'undefined' : JSON.stringify(pluginParams);
12432
- runtimePluginVars.push(`{ plugin: ${runtimePluginVar}, params: ${paramsCode} }`);
12433
- }
12434
- let content = [
12435
- `import __module_federation_bundler_runtime__ from ${JSON.stringify(paths.bundlerRuntime)}`,
12436
- ...runtimePluginImports,
12437
- `const __module_federation_runtime_plugins__ = [${runtimePluginVars.join(', ')}].filter(({ plugin }) => plugin).map(({ plugin, params }) => plugin(params))`,
12438
- `const __module_federation_remote_infos__ = ${JSON.stringify(remoteInfos)}`,
12439
- `const __module_federation_container_name__ = ${JSON.stringify(options.name ?? compiler.options.output.uniqueName)}`,
12440
- `const __module_federation_share_strategy__ = ${JSON.stringify(options.shareStrategy ?? 'version-first')}`,
12441
- compiler.webpack.Template.getFunctionContent(ModuleFederationPlugin_require('./moduleFederationDefaultRuntime.js').default)
12442
- ].join(';');
12443
- return `@module-federation/runtime/rspack.js!=!data:text/javascript,${content}`;
12444
- }(paths, this._options, compiler);
12445
- new ModuleFederationRuntimePlugin({
12446
- entryRuntime,
12447
- experiments: {
12448
- asyncStartup: this._options.experiments?.asyncStartup ?? !1
12449
- }
12450
- }).apply(compiler);
13366
+ }, ((options = this._options).shared ? parseOptions(options.shared, (item, key)=>{
13367
+ if ('string' != typeof item) throw Error('Unexpected array in shared');
13368
+ return item !== key && isRequiredVersion(item) ? {
13369
+ import: key,
13370
+ requiredVersion: item
13371
+ } : {
13372
+ import: item
13373
+ };
13374
+ }, (item)=>item) : []).filter(([, config])=>config.treeShaking).length > 0 && (this._treeShakingSharedPlugin = new TreeShakingSharedPlugin({
13375
+ mfConfig: this._options,
13376
+ secondary: !1
13377
+ }), this._treeShakingSharedPlugin.apply(compiler));
13378
+ let runtimeExperiments = {
13379
+ asyncStartup: this._options.experiments?.asyncStartup ?? !1
13380
+ }, runtimePluginApplied = !1;
13381
+ compiler.hooks.beforeRun.tap({
13382
+ name: 'ModuleFederationPlugin',
13383
+ stage: 100
13384
+ }, ()=>{
13385
+ runtimePluginApplied || (runtimePluginApplied = !0, new ModuleFederationRuntimePlugin({
13386
+ entryRuntime: getDefaultEntryRuntime(paths, this._options, compiler, this._treeShakingSharedPlugin?.buildAssets),
13387
+ experiments: runtimeExperiments
13388
+ }).apply(compiler));
13389
+ }), compiler.hooks.watchRun.tap({
13390
+ name: 'ModuleFederationPlugin',
13391
+ stage: 100
13392
+ }, ()=>{
13393
+ runtimePluginApplied || (runtimePluginApplied = !0, new ModuleFederationRuntimePlugin({
13394
+ entryRuntime: getDefaultEntryRuntime(paths, this._options, compiler, this._treeShakingSharedPlugin?.buildAssets || {}),
13395
+ experiments: runtimeExperiments
13396
+ }).apply(compiler));
13397
+ });
12451
13398
  let v1Options = {
12452
13399
  name: this._options.name,
12453
13400
  exposes: this._options.exposes,
@@ -12460,74 +13407,7 @@ let exports_rspackVersion = "2.0.0-beta.0", exports_version = "5.75.0", exports_
12460
13407
  shared: this._options.shared,
12461
13408
  enhanced: !0
12462
13409
  };
12463
- if (new webpack.container.ModuleFederationPluginV1(v1Options).apply(compiler), this._options.manifest) {
12464
- let manifestOptions = !0 === this._options.manifest ? {} : {
12465
- ...this._options.manifest
12466
- }, containerName = manifestOptions.name ?? this._options.name, globalName = manifestOptions.globalName ?? function(library) {
12467
- if (!library) return;
12468
- let libName = library.name;
12469
- if (libName) {
12470
- if ('string' == typeof libName) return libName;
12471
- if (Array.isArray(libName)) return libName[0];
12472
- if ('object' == typeof libName) return libName.root?.[0] ?? libName.amd ?? libName.commonjs ?? void 0;
12473
- }
12474
- }(this._options.library) ?? containerName, remoteAliasMap = Object.entries(getRemoteInfos(this._options)).reduce((sum, cur)=>{
12475
- if (cur[1].length > 1) return sum;
12476
- let { entry, alias, name } = cur[1][0];
12477
- return entry && name && (sum[alias] = {
12478
- name,
12479
- entry
12480
- }), sum;
12481
- }, {}), manifestExposes = function(exposes) {
12482
- if (!exposes) return;
12483
- let result = parseOptions(exposes, (value)=>({
12484
- import: Array.isArray(value) ? value : [
12485
- value
12486
- ],
12487
- name: void 0
12488
- }), (value)=>({
12489
- import: Array.isArray(value.import) ? value.import : [
12490
- value.import
12491
- ],
12492
- name: value.name ?? void 0
12493
- })).map(([exposeKey, info])=>{
12494
- let exposeName = info.name ?? exposeKey.replace(/^\.\//, '');
12495
- return {
12496
- path: exposeKey,
12497
- name: exposeName
12498
- };
12499
- });
12500
- return result.length > 0 ? result : void 0;
12501
- }(this._options.exposes);
12502
- void 0 === manifestOptions.exposes && manifestExposes && (manifestOptions.exposes = manifestExposes);
12503
- let manifestShared = function(shared) {
12504
- if (!shared) return;
12505
- let result = parseOptions(shared, (item, key)=>{
12506
- if ('string' != typeof item) throw Error('Unexpected array in shared');
12507
- return item !== key && isRequiredVersion(item) ? {
12508
- import: key,
12509
- requiredVersion: item
12510
- } : {
12511
- import: item
12512
- };
12513
- }, (item)=>item).map(([key, config])=>{
12514
- let name = config.shareKey || key;
12515
- return {
12516
- name,
12517
- version: 'string' == typeof config.version ? config.version : void 0,
12518
- requiredVersion: 'string' == typeof config.requiredVersion ? config.requiredVersion : void 0,
12519
- singleton: config.singleton
12520
- };
12521
- });
12522
- return result.length > 0 ? result : void 0;
12523
- }(this._options.shared);
12524
- void 0 === manifestOptions.shared && manifestShared && (manifestOptions.shared = manifestShared), new ModuleFederationManifestPlugin({
12525
- ...manifestOptions,
12526
- name: containerName,
12527
- globalName,
12528
- remoteAliasMap
12529
- }).apply(compiler);
12530
- }
13410
+ new webpack.container.ModuleFederationPluginV1(v1Options).apply(compiler), this._options.manifest && new ModuleFederationManifestPlugin(this._options).apply(compiler);
12531
13411
  }
12532
13412
  },
12533
13413
  ModuleFederationPluginV1: class {
@@ -12564,6 +13444,7 @@ let exports_rspackVersion = "2.0.0-beta.0", exports_version = "5.75.0", exports_
12564
13444
  }
12565
13445
  }, sharing = {
12566
13446
  ProvideSharedPlugin: ProvideSharedPlugin,
13447
+ TreeShakingSharedPlugin: TreeShakingSharedPlugin,
12567
13448
  ConsumeSharedPlugin: ConsumeSharedPlugin,
12568
13449
  SharePlugin: SharePlugin
12569
13450
  }, exports_experiments = {
@@ -12629,7 +13510,7 @@ let exports_rspackVersion = "2.0.0-beta.0", exports_version = "5.75.0", exports_
12629
13510
  ssr: 'server-side-rendering'
12630
13511
  }
12631
13512
  }
12632
- }, src_fn = Object.assign(rspack, exports_namespaceObject);
13513
+ }, src_fn = Object.assign(rspack_rspack, exports_namespaceObject);
12633
13514
  src_fn.rspack = src_fn, src_fn.webpack = src_fn;
12634
13515
  let src_rspack_0 = src_fn;
12635
13516
  var AsyncDependenciesBlock = binding_namespaceObject.AsyncDependenciesBlock, ConcatenatedModule = binding_namespaceObject.ConcatenatedModule, ContextModule = binding_namespaceObject.ContextModule, Dependency = binding_namespaceObject.Dependency, EntryDependency = binding_namespaceObject.EntryDependency, ExternalModule = binding_namespaceObject.ExternalModule, Module = binding_namespaceObject.Module, NormalModule = binding_namespaceObject.NormalModule;