@rspack-canary/core 1.6.5-canary-e23badc4-20251124174040 → 1.6.5-canary-a27f526c-20251125032833

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
@@ -4645,7 +4645,7 @@ Plugins which provide custom chunk loading types must call EnableChunkLoadingPlu
4645
4645
  return createBuiltinPlugin(this.name, rawOptions);
4646
4646
  }
4647
4647
  }
4648
- let SubresourceIntegrityPlugin_PLUGIN_NAME = "SubresourceIntegrityPlugin", NATIVE_HTML_PLUGIN = "HtmlRspackPlugin", HTTP_PROTOCOL_REGEX = /^https?:/, NativeSubresourceIntegrityPlugin = base_create(binding_.BuiltinPluginName.SubresourceIntegrityPlugin, function(options) {
4648
+ let SubresourceIntegrityPlugin_PLUGIN_NAME = "SubresourceIntegrityPlugin", NATIVE_HTML_PLUGIN = "HtmlRspackPlugin", NativeSubresourceIntegrityPlugin = base_create(binding_.BuiltinPluginName.SubresourceIntegrityPlugin, function(options) {
4649
4649
  let htmlPlugin = "Disabled";
4650
4650
  return options.htmlPlugin === NATIVE_HTML_PLUGIN ? htmlPlugin = "Native" : "string" == typeof options.htmlPlugin && (htmlPlugin = "JavaScript"), {
4651
4651
  hashFuncNames: options.hashFuncNames,
@@ -4706,23 +4706,11 @@ Plugins which provide custom chunk loading types must call EnableChunkLoadingPlu
4706
4706
  }
4707
4707
  }(tag);
4708
4708
  if (!tagSrc) return;
4709
- let isUrlSrc = !1;
4710
4709
  try {
4711
4710
  let url = new URL(tagSrc);
4712
- isUrlSrc = "http:" === url.protocol || "https:" === url.protocol;
4713
- } catch (_) {
4714
- isUrlSrc = tagSrc.startsWith("//");
4715
- }
4716
- let src = "";
4717
- if (isUrlSrc) {
4718
- if (!publicPath) return;
4719
- let protocolRelativePublicPath = publicPath.replace(HTTP_PROTOCOL_REGEX, ""), protocolRelativeTagSrc = tagSrc.replace(HTTP_PROTOCOL_REGEX, "");
4720
- if (!protocolRelativeTagSrc.startsWith(protocolRelativePublicPath)) return;
4721
- {
4722
- let tagSrcWithScheme = `http:${protocolRelativeTagSrc}`, publicPathWithScheme = protocolRelativePublicPath.startsWith("//") ? `http:${protocolRelativePublicPath}` : protocolRelativePublicPath;
4723
- src = (0, external_node_path_namespaceObject.relative)(publicPathWithScheme, decodeURIComponent(tagSrcWithScheme));
4724
- }
4725
- } else src = (0, external_node_path_namespaceObject.relative)(publicPath, decodeURIComponent(tagSrc));
4711
+ if (("http:" === url.protocol || "https:" === url.protocol) && (!publicPath || !tagSrc.startsWith(publicPath))) return;
4712
+ } catch (_) {}
4713
+ let src = (0, external_node_path_namespaceObject.relative)(publicPath, decodeURIComponent(tagSrc));
4726
4714
  tag.attributes.integrity = this.getIntegrityChecksumForAsset(src) || function(hashFuncNames, source) {
4727
4715
  let { createHash } = __webpack_require__("node:crypto");
4728
4716
  return hashFuncNames.map((hashFuncName)=>`${hashFuncName}-${createHash(hashFuncName).update("string" == typeof source ? Buffer.from(source, "utf-8") : source).digest("base64")}`).join(" ");
@@ -5752,7 +5740,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
5752
5740
  }, applyExperimentsDefaults = (experiments, { development })=>{
5753
5741
  F(experiments, "cache", ()=>development), D(experiments, "futureDefaults", !1), D(experiments, "lazyCompilation", !1), D(experiments, "asyncWebAssembly", experiments.futureDefaults), D(experiments, "css", !!experiments.futureDefaults || void 0), D(experiments, "topLevelAwait", !0), D(experiments, "deferImport", !1), D(experiments, "buildHttp", void 0), experiments.buildHttp && "object" == typeof experiments.buildHttp && D(experiments.buildHttp, "upgrade", !1), D(experiments, "incremental", {}), "object" == typeof experiments.incremental && (D(experiments.incremental, "silent", !0), D(experiments.incremental, "make", !0), D(experiments.incremental, "inferAsyncModules", !0), D(experiments.incremental, "providedExports", !0), D(experiments.incremental, "dependenciesDiagnostics", !0), D(experiments.incremental, "sideEffects", !0), D(experiments.incremental, "buildChunkGraph", !1), D(experiments.incremental, "moduleIds", !0), D(experiments.incremental, "chunkIds", !0), D(experiments.incremental, "modulesHashes", !0), D(experiments.incremental, "modulesCodegen", !0), D(experiments.incremental, "modulesRuntimeRequirements", !0), D(experiments.incremental, "chunksRuntimeRequirements", !0), D(experiments.incremental, "chunksHashes", !0), D(experiments.incremental, "chunksRender", !0), D(experiments.incremental, "emitAssets", !0)), D(experiments, "rspackFuture", {}), D(experiments, "parallelCodeSplitting", !1), D(experiments, "parallelLoader", !1), D(experiments, "useInputFileSystem", !1), D(experiments, "inlineConst", !1), D(experiments, "inlineEnum", !1), D(experiments, "typeReexportsPresence", !1), D(experiments, "lazyBarrel", !0);
5754
5742
  }, applybundlerInfoDefaults = (rspackFuture, library)=>{
5755
- "object" == typeof rspackFuture && (D(rspackFuture, "bundlerInfo", {}), "object" == typeof rspackFuture.bundlerInfo && (D(rspackFuture.bundlerInfo, "version", "1.6.5-canary-e23badc4-20251124174040"), D(rspackFuture.bundlerInfo, "bundler", "rspack"), D(rspackFuture.bundlerInfo, "force", !library)));
5743
+ "object" == typeof rspackFuture && (D(rspackFuture, "bundlerInfo", {}), "object" == typeof rspackFuture.bundlerInfo && (D(rspackFuture.bundlerInfo, "version", "1.6.5-canary-a27f526c-20251125032833"), D(rspackFuture.bundlerInfo, "bundler", "rspack"), D(rspackFuture.bundlerInfo, "force", !library)));
5756
5744
  }, applySnapshotDefaults = (_snapshot, _env)=>{}, applyModuleDefaults = (module1, { cache, asyncWebAssembly, css, targetProperties, mode, uniqueName, usedExports, inlineConst, deferImport })=>{
5757
5745
  if (assertNotNill(module1.parser), assertNotNill(module1.generator), cache ? D(module1, "unsafeCache", /[\\/]node_modules[\\/]/) : D(module1, "unsafeCache", !1), F(module1.parser, "asset", ()=>({})), assertNotNill(module1.parser.asset), F(module1.parser.asset, "dataUrlCondition", ()=>({})), "object" == typeof module1.parser.asset.dataUrlCondition && D(module1.parser.asset.dataUrlCondition, "maxSize", 8096), F(module1.parser, "javascript", ()=>({})), assertNotNill(module1.parser.javascript), ((parserOptions, { usedExports, inlineConst, deferImport })=>{
5758
5746
  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", !0), D(parserOptions, "requireDynamic", !0), D(parserOptions, "requireResolve", !0), D(parserOptions, "commonjs", !0), D(parserOptions, "importDynamic", !0), D(parserOptions, "worker", [
@@ -7402,7 +7390,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
7402
7390
  });
7403
7391
  }
7404
7392
  }
7405
- let CORE_VERSION = "1.6.5-canary-e23badc4-20251124174040", bindingVersionCheck_errorMessage = (coreVersion, expectedCoreVersion)=>process.env.RSPACK_BINDING ? `Unmatched version @rspack/core@${coreVersion} and binding version.
7393
+ let CORE_VERSION = "1.6.5-canary-a27f526c-20251125032833", bindingVersionCheck_errorMessage = (coreVersion, expectedCoreVersion)=>process.env.RSPACK_BINDING ? `Unmatched version @rspack/core@${coreVersion} and binding version.
7406
7394
 
7407
7395
  Help:
7408
7396
  Looks like you are using a custom binding (via environment variable 'RSPACK_BINDING=${process.env.RSPACK_BINDING}').
@@ -8702,7 +8690,7 @@ Help:
8702
8690
  obj.children = this.stats.map((stat, idx)=>{
8703
8691
  let obj = stat.toJson(childOptions.children[idx]), compilationName = stat.compilation.name;
8704
8692
  return obj.name = compilationName && makePathsRelative(childOptions.context, compilationName, stat.compilation.compiler.root), obj;
8705
- }), childOptions.version && (obj.rspackVersion = "1.6.5-canary-e23badc4-20251124174040", obj.version = "5.75.0"), childOptions.hash && (obj.hash = obj.children.map((j)=>j.hash).join(""));
8693
+ }), childOptions.version && (obj.rspackVersion = "1.6.5-canary-a27f526c-20251125032833", obj.version = "5.75.0"), childOptions.hash && (obj.hash = obj.children.map((j)=>j.hash).join(""));
8706
8694
  let mapError = (j, obj)=>({
8707
8695
  ...obj,
8708
8696
  compilerPath: obj.compilerPath ? `${j.name}.${obj.compilerPath}` : j.name
@@ -9601,7 +9589,7 @@ Help:
9601
9589
  object.hash = context.getStatsCompilation(compilation).hash;
9602
9590
  },
9603
9591
  version: (object)=>{
9604
- object.version = "5.75.0", object.rspackVersion = "1.6.5-canary-e23badc4-20251124174040";
9592
+ object.version = "5.75.0", object.rspackVersion = "1.6.5-canary-a27f526c-20251125032833";
9605
9593
  },
9606
9594
  env: (object, _compilation, _context, { _env })=>{
9607
9595
  object.env = _env;
@@ -11446,30 +11434,116 @@ Help:
11446
11434
  function isRequiredVersion(str) {
11447
11435
  return VERSION_PATTERN_REGEXP.test(str);
11448
11436
  }
11449
- let MANIFEST_FILE_NAME = "mf-manifest.json", STATS_FILE_NAME = "mf-stats.json", JSON_EXT = ".json";
11437
+ let encodeName = function(name, prefix = "", withExt = !1) {
11438
+ return `${prefix}${name.replace(/@/g, "scope_").replace(/-/g, "_").replace(/\//g, "__").replace(/\./g, "")}${withExt ? ".js" : ""}`;
11439
+ }, parseOptions = (options, normalizeSimple, normalizeOptions)=>{
11440
+ let items = [];
11441
+ var options1 = options, normalizeSimple1 = normalizeSimple, normalizeOptions1 = normalizeOptions, fn = (key, value)=>{
11442
+ items.push([
11443
+ key,
11444
+ value
11445
+ ]);
11446
+ };
11447
+ let object = (obj)=>{
11448
+ for (let [key, value] of Object.entries(obj))"string" == typeof value || Array.isArray(value) ? fn(key, normalizeSimple1(value, key)) : fn(key, normalizeOptions1(value, key));
11449
+ };
11450
+ if (options1) if (Array.isArray(options1)) {
11451
+ var items1 = options1;
11452
+ for (let item of items1)if ("string" == typeof item) fn(item, normalizeSimple1(item, item));
11453
+ else if (item && "object" == typeof item) object(item);
11454
+ else throw Error("Unexpected options format");
11455
+ } else if ("object" == typeof options1) object(options1);
11456
+ else throw Error("Unexpected options format");
11457
+ return items;
11458
+ }, MANIFEST_FILE_NAME = "mf-manifest.json", STATS_FILE_NAME = "mf-stats.json", JSON_EXT = ".json";
11450
11459
  function isPlainObject(value) {
11451
11460
  return !!value && "object" == typeof value && !Array.isArray(value);
11452
11461
  }
11462
+ function getFileName(manifestOptions) {
11463
+ var name;
11464
+ if (!manifestOptions) return {
11465
+ statsFileName: STATS_FILE_NAME,
11466
+ manifestFileName: MANIFEST_FILE_NAME
11467
+ };
11468
+ let filePath = "boolean" == typeof manifestOptions ? "" : manifestOptions.filePath || "", fileName = "boolean" == typeof manifestOptions ? "" : manifestOptions.fileName || "", manifestFileName = fileName ? (name = fileName).endsWith(JSON_EXT) ? name : `${name}${JSON_EXT}` : MANIFEST_FILE_NAME, statsFileName = fileName ? manifestFileName.replace(JSON_EXT, `-stats${JSON_EXT}`) : STATS_FILE_NAME;
11469
+ return {
11470
+ statsFileName: (0, external_node_path_namespaceObject.join)(filePath, statsFileName),
11471
+ manifestFileName: (0, external_node_path_namespaceObject.join)(filePath, manifestFileName)
11472
+ };
11473
+ }
11453
11474
  class ModuleFederationManifestPlugin extends RspackBuiltinPlugin {
11454
11475
  name = binding_.BuiltinPluginName.ModuleFederationManifestPlugin;
11455
11476
  opts;
11456
11477
  constructor(opts){
11457
- super(), this.opts = opts;
11478
+ var mfConfig;
11479
+ let manifestOptions, containerName, globalName, remoteAliasMap, manifestExposes, manifestShared;
11480
+ super(), this.opts = (manifestOptions = !0 === (mfConfig = opts).manifest ? {} : {
11481
+ ...mfConfig.manifest
11482
+ }, containerName = mfConfig.name, globalName = function(library) {
11483
+ if (!library) return;
11484
+ let libName = library.name;
11485
+ if (libName) {
11486
+ if ("string" == typeof libName) return libName;
11487
+ if (Array.isArray(libName)) return libName[0];
11488
+ if ("object" == typeof libName) return libName.root?.[0] ?? libName.amd ?? libName.commonjs ?? void 0;
11489
+ }
11490
+ }(mfConfig.library) ?? containerName, remoteAliasMap = Object.entries(getRemoteInfos(mfConfig)).reduce((sum, cur)=>{
11491
+ if (cur[1].length > 1) return sum;
11492
+ let { entry, alias, name } = cur[1][0];
11493
+ return entry && name && (sum[alias] = {
11494
+ name,
11495
+ entry
11496
+ }), sum;
11497
+ }, {}), manifestExposes = function(exposes) {
11498
+ if (!exposes) return;
11499
+ let result = parseOptions(exposes, (value)=>({
11500
+ import: Array.isArray(value) ? value : [
11501
+ value
11502
+ ],
11503
+ name: void 0
11504
+ }), (value)=>({
11505
+ import: Array.isArray(value.import) ? value.import : [
11506
+ value.import
11507
+ ],
11508
+ name: value.name ?? void 0
11509
+ })).map(([exposeKey, info])=>{
11510
+ let exposeName = info.name ?? exposeKey.replace(/^\.\//, "");
11511
+ return {
11512
+ path: exposeKey,
11513
+ name: exposeName
11514
+ };
11515
+ });
11516
+ return result.length > 0 ? result : void 0;
11517
+ }(mfConfig.exposes), void 0 === manifestOptions.exposes && manifestExposes && (manifestOptions.exposes = manifestExposes), manifestShared = function(shared) {
11518
+ if (!shared) return;
11519
+ let result = parseOptions(shared, (item, key)=>{
11520
+ if ("string" != typeof item) throw Error("Unexpected array in shared");
11521
+ return item !== key && isRequiredVersion(item) ? {
11522
+ import: key,
11523
+ requiredVersion: item
11524
+ } : {
11525
+ import: item
11526
+ };
11527
+ }, (item)=>item).map(([key, config])=>{
11528
+ let name = config.shareKey || key, version = "string" == typeof config.version ? config.version : void 0;
11529
+ return {
11530
+ name,
11531
+ version,
11532
+ requiredVersion: "string" == typeof config.requiredVersion ? config.requiredVersion : void 0,
11533
+ singleton: config.singleton
11534
+ };
11535
+ });
11536
+ return result.length > 0 ? result : void 0;
11537
+ }(mfConfig.shared), void 0 === manifestOptions.shared && manifestShared && (manifestOptions.shared = manifestShared), {
11538
+ ...manifestOptions,
11539
+ remoteAliasMap,
11540
+ globalName,
11541
+ name: containerName
11542
+ });
11458
11543
  }
11459
11544
  raw(compiler) {
11460
11545
  var isDev;
11461
- let pkg, buildVersion, { fileName, filePath, disableAssetsAnalyze, remoteAliasMap, exposes, shared } = this.opts, { statsFileName, manifestFileName } = function(manifestOptions) {
11462
- var name;
11463
- if (!manifestOptions) return {
11464
- statsFileName: STATS_FILE_NAME,
11465
- manifestFileName: MANIFEST_FILE_NAME
11466
- };
11467
- let filePath = "boolean" == typeof manifestOptions ? "" : manifestOptions.filePath || "", fileName = "boolean" == typeof manifestOptions ? "" : manifestOptions.fileName || "", manifestFileName = fileName ? (name = fileName).endsWith(JSON_EXT) ? name : `${name}${JSON_EXT}` : MANIFEST_FILE_NAME, statsFileName = fileName ? manifestFileName.replace(JSON_EXT, `-stats${JSON_EXT}`) : STATS_FILE_NAME;
11468
- return {
11469
- statsFileName: (0, external_node_path_namespaceObject.join)(filePath, statsFileName),
11470
- manifestFileName: (0, external_node_path_namespaceObject.join)(filePath, manifestFileName)
11471
- };
11472
- }(this.opts), rawOptions = {
11546
+ let pkg, buildVersion, { fileName, filePath, disableAssetsAnalyze, remoteAliasMap, exposes, shared } = this.opts, { statsFileName, manifestFileName } = getFileName(this.opts), rawOptions = {
11473
11547
  name: this.opts.name,
11474
11548
  globalName: this.opts.globalName,
11475
11549
  fileName,
@@ -11504,81 +11578,6 @@ Help:
11504
11578
  return createBuiltinPlugin(this.name, rawOptions);
11505
11579
  }
11506
11580
  }
11507
- let ModuleFederationRuntimePlugin = base_create(binding_.BuiltinPluginName.ModuleFederationRuntimePlugin, (options = {})=>options), parseOptions = (options, normalizeSimple, normalizeOptions)=>{
11508
- let items = [];
11509
- var options1 = options, normalizeSimple1 = normalizeSimple, normalizeOptions1 = normalizeOptions, fn = (key, value)=>{
11510
- items.push([
11511
- key,
11512
- value
11513
- ]);
11514
- };
11515
- let object = (obj)=>{
11516
- for (let [key, value] of Object.entries(obj))"string" == typeof value || Array.isArray(value) ? fn(key, normalizeSimple1(value, key)) : fn(key, normalizeOptions1(value, key));
11517
- };
11518
- if (options1) if (Array.isArray(options1)) {
11519
- var items1 = options1;
11520
- for (let item of items1)if ("string" == typeof item) fn(item, normalizeSimple1(item, item));
11521
- else if (item && "object" == typeof item) object(item);
11522
- else throw Error("Unexpected options format");
11523
- } else if ("object" == typeof options1) object(options1);
11524
- else throw Error("Unexpected options format");
11525
- return items;
11526
- };
11527
- function getRemoteInfos(options) {
11528
- if (!options.remotes) return {};
11529
- let remoteType = options.remoteType || (options.library ? options.library.type : "script"), remotes = parseOptions(options.remotes, (item)=>({
11530
- external: Array.isArray(item) ? item : [
11531
- item
11532
- ],
11533
- shareScope: options.shareScope || "default"
11534
- }), (item)=>({
11535
- external: Array.isArray(item.external) ? item.external : [
11536
- item.external
11537
- ],
11538
- shareScope: item.shareScope || options.shareScope || "default"
11539
- })), remoteInfos = {};
11540
- for (let [key, config] of remotes)for (let external of config.external){
11541
- let [externalType, externalRequest] = function(external) {
11542
- let result = function(external) {
11543
- if (/^[a-z0-9-]+ /.test(external)) {
11544
- let idx = external.indexOf(" ");
11545
- return [
11546
- external.slice(0, idx),
11547
- external.slice(idx + 1)
11548
- ];
11549
- }
11550
- return null;
11551
- }(external);
11552
- return null === result ? [
11553
- remoteType,
11554
- external
11555
- ] : result;
11556
- }(external);
11557
- if (remoteInfos[key] ??= [], "script" === externalType) {
11558
- let [url, global] = function(urlAndGlobal) {
11559
- let index = urlAndGlobal.indexOf("@");
11560
- return index <= 0 || index === urlAndGlobal.length - 1 ? null : [
11561
- urlAndGlobal.substring(index + 1),
11562
- urlAndGlobal.substring(0, index)
11563
- ];
11564
- }(externalRequest);
11565
- remoteInfos[key].push({
11566
- alias: key,
11567
- name: global,
11568
- entry: url,
11569
- externalType,
11570
- shareScope: config.shareScope
11571
- });
11572
- } else remoteInfos[key].push({
11573
- alias: key,
11574
- name: void 0,
11575
- entry: void 0,
11576
- externalType,
11577
- shareScope: config.shareScope
11578
- });
11579
- }
11580
- return remoteInfos;
11581
- }
11582
11581
  let compilerSet = new WeakSet();
11583
11582
  class ShareRuntimePlugin extends RspackBuiltinPlugin {
11584
11583
  enhanced;
@@ -11591,42 +11590,45 @@ Help:
11591
11590
  if (compiler1 = compiler, !compilerSet.has(compiler1)) return compiler2 = compiler, compilerSet.add(compiler2), createBuiltinPlugin(this.name, this.enhanced);
11592
11591
  }
11593
11592
  }
11593
+ function normalizeConsumeShareOptions(consumes, shareScope) {
11594
+ return parseOptions(consumes, (item, key)=>{
11595
+ if (Array.isArray(item)) throw Error("Unexpected array in options");
11596
+ return item !== key && isRequiredVersion(item) ? {
11597
+ import: key,
11598
+ shareScope: shareScope || "default",
11599
+ shareKey: key,
11600
+ requiredVersion: item,
11601
+ strictVersion: !0,
11602
+ packageName: void 0,
11603
+ singleton: !1,
11604
+ eager: !1
11605
+ } : {
11606
+ import: key,
11607
+ shareScope: shareScope || "default",
11608
+ shareKey: key,
11609
+ requiredVersion: void 0,
11610
+ packageName: void 0,
11611
+ strictVersion: !1,
11612
+ singleton: !1,
11613
+ eager: !1
11614
+ };
11615
+ }, (item, key)=>({
11616
+ import: !1 === item.import ? void 0 : item.import || key,
11617
+ shareScope: item.shareScope || shareScope || "default",
11618
+ shareKey: item.shareKey || key,
11619
+ requiredVersion: item.requiredVersion,
11620
+ strictVersion: "boolean" == typeof item.strictVersion ? item.strictVersion : !1 !== item.import && !item.singleton,
11621
+ packageName: item.packageName,
11622
+ singleton: !!item.singleton,
11623
+ eager: !!item.eager
11624
+ }));
11625
+ }
11594
11626
  class ConsumeSharedPlugin extends RspackBuiltinPlugin {
11595
11627
  name = binding_.BuiltinPluginName.ConsumeSharedPlugin;
11596
11628
  _options;
11597
11629
  constructor(options){
11598
11630
  super(), this._options = {
11599
- consumes: parseOptions(options.consumes, (item, key)=>{
11600
- if (Array.isArray(item)) throw Error("Unexpected array in options");
11601
- return item !== key && isRequiredVersion(item) ? {
11602
- import: key,
11603
- shareScope: options.shareScope || "default",
11604
- shareKey: key,
11605
- requiredVersion: item,
11606
- strictVersion: !0,
11607
- packageName: void 0,
11608
- singleton: !1,
11609
- eager: !1
11610
- } : {
11611
- import: key,
11612
- shareScope: options.shareScope || "default",
11613
- shareKey: key,
11614
- requiredVersion: void 0,
11615
- packageName: void 0,
11616
- strictVersion: !1,
11617
- singleton: !1,
11618
- eager: !1
11619
- };
11620
- }, (item, key)=>({
11621
- import: !1 === item.import ? void 0 : item.import || key,
11622
- shareScope: item.shareScope || options.shareScope || "default",
11623
- shareKey: item.shareKey || key,
11624
- requiredVersion: item.requiredVersion,
11625
- strictVersion: "boolean" == typeof item.strictVersion ? item.strictVersion : !1 !== item.import && !item.singleton,
11626
- packageName: item.packageName,
11627
- singleton: !!item.singleton,
11628
- eager: !!item.eager
11629
- })),
11631
+ consumes: normalizeConsumeShareOptions(options.consumes, options.shareScope),
11630
11632
  enhanced: options.enhanced ?? !1
11631
11633
  };
11632
11634
  }
@@ -11647,28 +11649,29 @@ Help:
11647
11649
  _provides;
11648
11650
  _enhanced;
11649
11651
  constructor(options){
11650
- super(), this._provides = parseOptions(options.provides, (item)=>{
11652
+ var options1, shareScope, enhanced;
11653
+ super(), this._provides = (options1 = options.provides, shareScope = options.shareScope, enhanced = options.enhanced, parseOptions(options1, (item)=>{
11651
11654
  if (Array.isArray(item)) throw Error("Unexpected array of provides");
11652
11655
  return {
11653
11656
  shareKey: item,
11654
11657
  version: void 0,
11655
- shareScope: options.shareScope || "default",
11658
+ shareScope: shareScope || "default",
11656
11659
  eager: !1
11657
11660
  };
11658
11661
  }, (item)=>{
11659
11662
  let raw = {
11660
11663
  shareKey: item.shareKey,
11661
11664
  version: item.version,
11662
- shareScope: item.shareScope || options.shareScope || "default",
11665
+ shareScope: item.shareScope || shareScope || "default",
11663
11666
  eager: !!item.eager
11664
11667
  };
11665
- return options.enhanced ? {
11668
+ return enhanced ? {
11666
11669
  ...raw,
11667
11670
  singleton: item.singleton,
11668
11671
  requiredVersion: item.requiredVersion,
11669
11672
  strictVersion: item.strictVersion
11670
11673
  } : raw;
11671
- }), this._enhanced = options.enhanced;
11674
+ })), this._enhanced = options.enhanced;
11672
11675
  }
11673
11676
  raw(compiler) {
11674
11677
  new ShareRuntimePlugin(this._enhanced ?? !1).apply(compiler);
@@ -11679,32 +11682,39 @@ Help:
11679
11682
  return createBuiltinPlugin(this.name, rawOptions);
11680
11683
  }
11681
11684
  }
11685
+ function normalizeSharedOptions(shared) {
11686
+ return parseOptions(shared, (item, key)=>{
11687
+ if ("string" != typeof item) throw Error("Unexpected array in shared");
11688
+ return item !== key && isRequiredVersion(item) ? {
11689
+ import: key,
11690
+ requiredVersion: item
11691
+ } : {
11692
+ import: item
11693
+ };
11694
+ }, (item)=>item);
11695
+ }
11696
+ function createConsumeShareOptions(normalizedSharedOptions) {
11697
+ return normalizedSharedOptions.map(([key, options])=>({
11698
+ [key]: {
11699
+ import: options.import,
11700
+ shareKey: options.shareKey || key,
11701
+ shareScope: options.shareScope,
11702
+ requiredVersion: options.requiredVersion,
11703
+ strictVersion: options.strictVersion,
11704
+ singleton: options.singleton,
11705
+ packageName: options.packageName,
11706
+ eager: options.eager
11707
+ }
11708
+ }));
11709
+ }
11682
11710
  class SharePlugin {
11683
11711
  _shareScope;
11684
11712
  _consumes;
11685
11713
  _provides;
11686
11714
  _enhanced;
11715
+ _sharedOptions;
11687
11716
  constructor(options){
11688
- const sharedOptions = parseOptions(options.shared, (item, key)=>{
11689
- if ("string" != typeof item) throw Error("Unexpected array in shared");
11690
- return item !== key && isRequiredVersion(item) ? {
11691
- import: key,
11692
- requiredVersion: item
11693
- } : {
11694
- import: item
11695
- };
11696
- }, (item)=>item), consumes = sharedOptions.map(([key, options])=>({
11697
- [key]: {
11698
- import: options.import,
11699
- shareKey: options.shareKey || key,
11700
- shareScope: options.shareScope,
11701
- requiredVersion: options.requiredVersion,
11702
- strictVersion: options.strictVersion,
11703
- singleton: options.singleton,
11704
- packageName: options.packageName,
11705
- eager: options.eager
11706
- }
11707
- })), provides = sharedOptions.filter(([, options])=>!1 !== options.import).map(([key, options])=>({
11717
+ const sharedOptions = normalizeSharedOptions(options.shared), consumes = createConsumeShareOptions(sharedOptions), provides = sharedOptions.filter(([, options])=>!1 !== options.import).map(([key, options])=>({
11708
11718
  [options.import || key]: {
11709
11719
  shareKey: options.shareKey || key,
11710
11720
  shareScope: options.shareScope,
@@ -11715,7 +11725,7 @@ Help:
11715
11725
  strictVersion: options.strictVersion
11716
11726
  }
11717
11727
  }));
11718
- this._shareScope = options.shareScope, this._consumes = consumes, this._provides = provides, this._enhanced = options.enhanced ?? !1;
11728
+ this._shareScope = options.shareScope, this._consumes = consumes, this._provides = provides, this._enhanced = options.enhanced ?? !1, this._sharedOptions = sharedOptions;
11719
11729
  }
11720
11730
  apply(compiler) {
11721
11731
  new ConsumeSharedPlugin({
@@ -11729,6 +11739,398 @@ Help:
11729
11739
  }).apply(compiler);
11730
11740
  }
11731
11741
  }
11742
+ class CollectSharedEntryPlugin extends RspackBuiltinPlugin {
11743
+ name = binding_.BuiltinPluginName.CollectSharedEntryPlugin;
11744
+ sharedOptions;
11745
+ _collectedEntries;
11746
+ constructor(options){
11747
+ super();
11748
+ const { sharedOptions } = options;
11749
+ this.sharedOptions = sharedOptions, this._collectedEntries = {};
11750
+ }
11751
+ getData() {
11752
+ return this._collectedEntries;
11753
+ }
11754
+ getFilename() {
11755
+ return "collect-shared-entries.json";
11756
+ }
11757
+ apply(compiler) {
11758
+ super.apply(compiler), compiler.hooks.thisCompilation.tap("Collect shared entry", (compilation)=>{
11759
+ compilation.hooks.processAssets.tapPromise({
11760
+ name: "CollectSharedEntry",
11761
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE_INLINE
11762
+ }, async ()=>{
11763
+ let filename = this.getFilename(), asset = compilation.getAsset(filename);
11764
+ if (!asset) throw Error(`Can not get ${filename}`);
11765
+ this._collectedEntries = JSON.parse(asset.source.source().toString()), compilation.deleteAsset(filename);
11766
+ });
11767
+ });
11768
+ }
11769
+ raw() {
11770
+ let rawOptions = {
11771
+ consumes: normalizeConsumeShareOptions(createConsumeShareOptions(this.sharedOptions)).map(([key, v])=>({
11772
+ key,
11773
+ ...v
11774
+ })),
11775
+ filename: this.getFilename()
11776
+ };
11777
+ return createBuiltinPlugin(this.name, rawOptions);
11778
+ }
11779
+ }
11780
+ function assert(condition, msg) {
11781
+ if (!condition) throw Error(msg);
11782
+ }
11783
+ class ShareContainerPlugin extends RspackBuiltinPlugin {
11784
+ name = binding_.BuiltinPluginName.ShareContainerPlugin;
11785
+ filename = "";
11786
+ _options;
11787
+ _shareName;
11788
+ _globalName;
11789
+ constructor(options){
11790
+ super();
11791
+ const { shareName, library, request, independentShareFileName } = options, version = options.version || "0.0.0";
11792
+ this._globalName = encodeName(`${options.mfName}_${shareName}_${version}`);
11793
+ const fileName = independentShareFileName || `${version}/share-entry.js`;
11794
+ this._shareName = shareName, this._options = {
11795
+ name: shareName,
11796
+ request: request,
11797
+ library: (library ? {
11798
+ ...library,
11799
+ name: this._globalName
11800
+ } : void 0) || {
11801
+ type: "var",
11802
+ name: this._globalName
11803
+ },
11804
+ version,
11805
+ fileName
11806
+ };
11807
+ }
11808
+ getData() {
11809
+ return [
11810
+ this.name,
11811
+ this._globalName
11812
+ ];
11813
+ }
11814
+ raw(compiler) {
11815
+ let { library } = this._options;
11816
+ return compiler.options.output.enabledLibraryTypes.includes(library.type) || compiler.options.output.enabledLibraryTypes.push(library.type), createBuiltinPlugin(this.name, this._options);
11817
+ }
11818
+ apply(compiler) {
11819
+ super.apply(compiler);
11820
+ let shareName = this._shareName;
11821
+ compiler.hooks.thisCompilation.tap(this.name, (compilation)=>{
11822
+ compilation.hooks.processAssets.tapPromise({
11823
+ name: "getShareContainerFile"
11824
+ }, async ()=>{
11825
+ assert(compilation.entrypoints.get(shareName), `Can not get shared ${shareName} entryPoint!`);
11826
+ let remoteEntryNameChunk = compilation.namedChunks.get(shareName);
11827
+ assert(remoteEntryNameChunk, `Can not get shared ${shareName} chunk!`);
11828
+ let files = Array.from(remoteEntryNameChunk.files).filter((f)=>!f.includes(".hot-update") && !f.endsWith(".css"));
11829
+ 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];
11830
+ });
11831
+ });
11832
+ }
11833
+ }
11834
+ class SharedUsedExportsOptimizerPlugin extends RspackBuiltinPlugin {
11835
+ name = binding_.BuiltinPluginName.SharedUsedExportsOptimizerPlugin;
11836
+ sharedOptions;
11837
+ injectUsedExports;
11838
+ manifestOptions;
11839
+ constructor(sharedOptions, injectUsedExports, manifestOptions){
11840
+ super(), this.sharedOptions = sharedOptions, this.injectUsedExports = injectUsedExports ?? !0, this.manifestOptions = manifestOptions ?? {};
11841
+ }
11842
+ buildOptions() {
11843
+ let shared = this.sharedOptions.map(([shareKey, config])=>({
11844
+ shareKey,
11845
+ treeshake: !!config.treeshake,
11846
+ usedExports: config.usedExports
11847
+ })), { manifestFileName, statsFileName } = getFileName(this.manifestOptions);
11848
+ return {
11849
+ shared,
11850
+ injectUsedExports: this.injectUsedExports,
11851
+ manifestFileName,
11852
+ statsFileName
11853
+ };
11854
+ }
11855
+ raw() {
11856
+ if (this.sharedOptions.length) return createBuiltinPlugin(this.name, this.buildOptions());
11857
+ }
11858
+ }
11859
+ let VIRTUAL_ENTRY = "./virtual-entry.js", VIRTUAL_ENTRY_NAME = "virtual-entry";
11860
+ class VirtualEntryPlugin {
11861
+ sharedOptions;
11862
+ constructor(sharedOptions){
11863
+ this.sharedOptions = sharedOptions;
11864
+ }
11865
+ createEntry() {
11866
+ let { sharedOptions } = this;
11867
+ return sharedOptions.reduce((acc, cur, index)=>`${acc}import shared_${index} from '${cur[0]}';\n`, "");
11868
+ }
11869
+ static entry() {
11870
+ return {
11871
+ [VIRTUAL_ENTRY_NAME]: VIRTUAL_ENTRY
11872
+ };
11873
+ }
11874
+ apply(compiler) {
11875
+ new compiler.rspack.experiments.VirtualModulesPlugin({
11876
+ [VIRTUAL_ENTRY]: this.createEntry()
11877
+ }).apply(compiler), compiler.hooks.thisCompilation.tap("RemoveVirtualEntryAsset", (compilation)=>{
11878
+ compilation.hooks.processAssets.tapPromise({
11879
+ name: "RemoveVirtualEntryAsset",
11880
+ stage: compiler.webpack.Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE
11881
+ }, async ()=>{
11882
+ try {
11883
+ let chunk = compilation.namedChunks.get(VIRTUAL_ENTRY_NAME);
11884
+ chunk?.files.forEach((f)=>{
11885
+ compilation.deleteAsset(f);
11886
+ });
11887
+ } catch (_e) {
11888
+ console.error("Failed to remove virtual entry file!");
11889
+ }
11890
+ });
11891
+ });
11892
+ }
11893
+ }
11894
+ class IndependentSharedPlugin {
11895
+ mfName;
11896
+ shared;
11897
+ library;
11898
+ sharedOptions;
11899
+ outputDir;
11900
+ outputFilePath;
11901
+ plugins;
11902
+ compilers = new Map();
11903
+ treeshake;
11904
+ manifest;
11905
+ buildAssets = {};
11906
+ injectUsedExports;
11907
+ name = "IndependentSharedPlugin";
11908
+ constructor(options){
11909
+ const { outputDir, outputFilePath, plugins, treeshake, shared, name, manifest, injectUsedExports, library } = options;
11910
+ this.shared = shared, this.mfName = name, this.outputDir = outputFilePath ? "" : outputDir || "independent-packages", this.outputFilePath = outputFilePath, this.plugins = plugins || [], this.treeshake = treeshake, this.manifest = manifest, this.injectUsedExports = injectUsedExports ?? !0, this.library = library, this.sharedOptions = parseOptions(shared, (item, key)=>{
11911
+ if ("string" != typeof item) throw Error(`Unexpected array in shared configuration for key "${key}"`);
11912
+ return item !== key && isRequiredVersion(item) ? {
11913
+ import: key,
11914
+ requiredVersion: item
11915
+ } : {
11916
+ import: item
11917
+ };
11918
+ }, (item)=>item);
11919
+ }
11920
+ apply(compiler) {
11921
+ compiler.hooks.beforeRun.tapPromise("IndependentSharedPlugin", async (compiler)=>{
11922
+ await this.createIndependentCompilers(compiler);
11923
+ }), compiler.hooks.shutdown.tapAsync("IndependentSharedPlugin", (callback)=>{
11924
+ this.cleanup(), callback();
11925
+ }), compiler.hooks.compilation.tap("IndependentSharedPlugin", (compilation)=>{
11926
+ compilation.hooks.processAssets.tapPromise({
11927
+ name: "injectBuildAssets",
11928
+ stage: compilation.constructor.PROCESS_ASSETS_STAGE_OPTIMIZE_TRANSFER
11929
+ }, async ()=>{
11930
+ if (!this.manifest) return;
11931
+ let { statsFileName, manifestFileName } = getFileName(this.manifest), injectBuildAssetsIntoStatsOrManifest = (filename)=>{
11932
+ let stats = compilation.getAsset(filename);
11933
+ if (!stats) return;
11934
+ let statsContent = JSON.parse(stats.source.source().toString()), { shared } = statsContent;
11935
+ Object.entries(this.buildAssets).forEach(([key, item])=>{
11936
+ let targetShared = shared.find((s)=>s.name === key);
11937
+ targetShared && item.forEach(([entry, version, globalName])=>{
11938
+ version === targetShared.version && (targetShared.fallback = entry, targetShared.fallbackName = globalName);
11939
+ });
11940
+ }), compilation.updateAsset(filename, new compiler.webpack.sources.RawSource(JSON.stringify(statsContent)));
11941
+ };
11942
+ injectBuildAssetsIntoStatsOrManifest(statsFileName), injectBuildAssetsIntoStatsOrManifest(manifestFileName);
11943
+ });
11944
+ });
11945
+ }
11946
+ async createIndependentCompilers(parentCompiler) {
11947
+ let { sharedOptions, buildAssets } = this;
11948
+ console.log("🚀 Start creating a standalone compiler...");
11949
+ let parentOutputDir = parentCompiler.options.output.path ? (0, external_node_path_namespaceObject.basename)(parentCompiler.options.output.path) : "", shareRequestsMap = await this.createIndependentCompiler(parentCompiler, parentOutputDir);
11950
+ await Promise.all(sharedOptions.map(async ([shareName, shareConfig])=>{
11951
+ if (!shareConfig.treeshake || !1 === shareConfig.import) return;
11952
+ let shareRequests = shareRequestsMap[shareName].requests;
11953
+ await Promise.all(shareRequests.map(async ([request, version])=>{
11954
+ let sharedConfig = sharedOptions.find(([name])=>name === shareName)?.[1], [shareFileName, globalName] = await this.createIndependentCompiler(parentCompiler, parentOutputDir, {
11955
+ shareRequestsMap,
11956
+ currentShare: {
11957
+ shareName,
11958
+ version,
11959
+ request,
11960
+ independentShareFileName: sharedConfig?.independentShareFileName
11961
+ }
11962
+ });
11963
+ "string" == typeof shareFileName && (buildAssets[shareName] ||= [], buildAssets[shareName].push([
11964
+ shareFileName,
11965
+ version,
11966
+ globalName
11967
+ ]));
11968
+ }));
11969
+ })), console.log("✅ All independent packages have been compiled successfully");
11970
+ }
11971
+ async createIndependentCompiler(parentCompiler, parentOutputDir, extraOptions) {
11972
+ let extraPlugin, { mfName, plugins, outputDir, outputFilePath, sharedOptions, treeshake, library } = this, outputDirWithShareName = outputFilePath || (0, external_node_path_namespaceObject.join)(outputDir, encodeName(extraOptions?.currentShare?.shareName || "")), parentConfig = parentCompiler.options, finalPlugins = [], rspack = parentCompiler.rspack;
11973
+ extraPlugin = extraOptions ? new ShareContainerPlugin({
11974
+ mfName,
11975
+ library,
11976
+ ...extraOptions.currentShare
11977
+ }) : new CollectSharedEntryPlugin({
11978
+ sharedOptions,
11979
+ shareScope: "default"
11980
+ }), (parentConfig.plugins || []).forEach((plugin)=>{
11981
+ void 0 !== plugin && "string" != typeof plugin && ((plugin)=>{
11982
+ if (!plugin) return !0;
11983
+ let pluginName = plugin.name || plugin.constructor?.name;
11984
+ return !pluginName || ![
11985
+ "TreeShakeSharedPlugin",
11986
+ "IndependentSharedPlugin",
11987
+ "ModuleFederationPlugin",
11988
+ "SharedUsedExportsOptimizerPlugin",
11989
+ "HtmlWebpackPlugin"
11990
+ ].includes(pluginName);
11991
+ })(plugin) && finalPlugins.push(plugin);
11992
+ }), plugins.forEach((plugin)=>{
11993
+ finalPlugins.push(plugin);
11994
+ }), finalPlugins.push(extraPlugin), finalPlugins.push(new ConsumeSharedPlugin({
11995
+ consumes: sharedOptions.filter(([key, options])=>extraOptions?.currentShare.shareName !== (options.shareKey || key)).map(([key, options])=>({
11996
+ [key]: {
11997
+ import: !extraOptions && options.import,
11998
+ shareKey: options.shareKey || key,
11999
+ shareScope: options.shareScope,
12000
+ requiredVersion: options.requiredVersion,
12001
+ strictVersion: options.strictVersion,
12002
+ singleton: options.singleton,
12003
+ packageName: options.packageName,
12004
+ eager: options.eager
12005
+ }
12006
+ })),
12007
+ enhanced: !0
12008
+ })), treeshake && finalPlugins.push(new SharedUsedExportsOptimizerPlugin(sharedOptions, this.injectUsedExports)), finalPlugins.push(new VirtualEntryPlugin(sharedOptions));
12009
+ let fullOutputDir = (0, external_node_path_namespaceObject.resolve)(parentCompiler.outputPath, outputDirWithShareName), compilerConfig = {
12010
+ ...parentConfig,
12011
+ mode: parentConfig.mode || "development",
12012
+ entry: VirtualEntryPlugin.entry,
12013
+ output: {
12014
+ path: fullOutputDir,
12015
+ clean: !0,
12016
+ publicPath: parentConfig.output?.publicPath || "auto"
12017
+ },
12018
+ plugins: finalPlugins,
12019
+ optimization: {
12020
+ ...parentConfig.optimization,
12021
+ splitChunks: !1
12022
+ }
12023
+ }, compiler = rspack.rspack(compilerConfig);
12024
+ compiler.inputFileSystem = parentCompiler.inputFileSystem, compiler.outputFileSystem = parentCompiler.outputFileSystem, compiler.intermediateFileSystem = parentCompiler.intermediateFileSystem;
12025
+ let { currentShare } = extraOptions || {};
12026
+ return currentShare && this.compilers.set(`${currentShare.shareName}@${currentShare.version}`, compiler), new Promise((resolve, reject)=>{
12027
+ compiler.run((err, stats)=>{
12028
+ if (err || stats?.hasErrors()) {
12029
+ let target = currentShare ? currentShare.shareName : "收集依赖";
12030
+ console.error(`❌ ${target} 编译失败:`, err || stats.toJson().errors.map((e)=>e.message).join("\n")), reject(err || Error(`${target} 编译失败`));
12031
+ return;
12032
+ }
12033
+ currentShare && console.log(`✅ 独立包 ${currentShare.shareName} 编译成功`), stats && (currentShare && console.log(`📊 ${currentShare.shareName} 编译统计:`), console.log(stats.toString({
12034
+ colors: !0,
12035
+ chunks: !1,
12036
+ modules: !1
12037
+ }))), resolve(extraPlugin.getData());
12038
+ });
12039
+ });
12040
+ }
12041
+ cleanup() {
12042
+ this.compilers.forEach((compiler)=>{
12043
+ compiler.watching && compiler.watching.close(()=>{
12044
+ console.log("👋 编译器已关闭");
12045
+ });
12046
+ }), this.compilers.clear();
12047
+ }
12048
+ }
12049
+ class TreeShakeSharedPlugin {
12050
+ mfConfig;
12051
+ outputDir;
12052
+ plugins;
12053
+ reshake;
12054
+ _independentSharePlugin;
12055
+ name = "TreeShakeSharedPlugin";
12056
+ constructor(options){
12057
+ const { mfConfig, plugins, reshake } = options;
12058
+ this.mfConfig = mfConfig, this.outputDir = mfConfig.independentShareDir || "independent-packages", this.plugins = plugins, this.reshake = !!reshake;
12059
+ }
12060
+ apply(compiler) {
12061
+ let { mfConfig, outputDir, plugins, reshake } = this, { name, shared, library } = mfConfig;
12062
+ if (!shared) return;
12063
+ let sharedOptions = normalizeSharedOptions(shared);
12064
+ sharedOptions.length && (reshake || new SharedUsedExportsOptimizerPlugin(sharedOptions, mfConfig.injectUsedExports, mfConfig.manifest).apply(compiler), sharedOptions.some(([_, config])=>config.treeshake && !1 !== config.import) && (this._independentSharePlugin = new IndependentSharedPlugin({
12065
+ name: name,
12066
+ shared: shared,
12067
+ outputDir,
12068
+ plugins,
12069
+ treeshake: reshake,
12070
+ library,
12071
+ manifest: mfConfig.manifest
12072
+ }), this._independentSharePlugin.apply(compiler)));
12073
+ }
12074
+ get buildAssets() {
12075
+ return this._independentSharePlugin?.buildAssets || {};
12076
+ }
12077
+ }
12078
+ let ModuleFederationRuntimePlugin = base_create(binding_.BuiltinPluginName.ModuleFederationRuntimePlugin, (options = {})=>options);
12079
+ function getRemoteInfos(options) {
12080
+ if (!options.remotes) return {};
12081
+ let remoteType = options.remoteType || (options.library ? options.library.type : "script"), remotes = parseOptions(options.remotes, (item)=>({
12082
+ external: Array.isArray(item) ? item : [
12083
+ item
12084
+ ],
12085
+ shareScope: options.shareScope || "default"
12086
+ }), (item)=>({
12087
+ external: Array.isArray(item.external) ? item.external : [
12088
+ item.external
12089
+ ],
12090
+ shareScope: item.shareScope || options.shareScope || "default"
12091
+ })), remoteInfos = {};
12092
+ for (let [key, config] of remotes)for (let external of config.external){
12093
+ let [externalType, externalRequest] = function(external) {
12094
+ let result = function(external) {
12095
+ if (/^[a-z0-9-]+ /.test(external)) {
12096
+ let idx = external.indexOf(" ");
12097
+ return [
12098
+ external.slice(0, idx),
12099
+ external.slice(idx + 1)
12100
+ ];
12101
+ }
12102
+ return null;
12103
+ }(external);
12104
+ return null === result ? [
12105
+ remoteType,
12106
+ external
12107
+ ] : result;
12108
+ }(external);
12109
+ if (remoteInfos[key] ??= [], "script" === externalType) {
12110
+ let [url, global] = function(urlAndGlobal) {
12111
+ let index = urlAndGlobal.indexOf("@");
12112
+ return index <= 0 || index === urlAndGlobal.length - 1 ? null : [
12113
+ urlAndGlobal.substring(index + 1),
12114
+ urlAndGlobal.substring(0, index)
12115
+ ];
12116
+ }(externalRequest);
12117
+ remoteInfos[key].push({
12118
+ alias: key,
12119
+ name: global,
12120
+ entry: url,
12121
+ externalType,
12122
+ shareScope: config.shareScope
12123
+ });
12124
+ } else remoteInfos[key].push({
12125
+ alias: key,
12126
+ name: void 0,
12127
+ entry: void 0,
12128
+ externalType,
12129
+ shareScope: config.shareScope
12130
+ });
12131
+ }
12132
+ return remoteInfos;
12133
+ }
11732
12134
  class ContainerPlugin extends RspackBuiltinPlugin {
11733
12135
  name = binding_.BuiltinPluginName.ContainerPlugin;
11734
12136
  _options;
@@ -11820,7 +12222,7 @@ Help:
11820
12222
  let _options = JSON.stringify(options || {});
11821
12223
  return binding_default().transform(source, _options);
11822
12224
  }
11823
- let exports_rspackVersion = "1.6.5-canary-e23badc4-20251124174040", exports_version = "5.75.0", exports_WebpackError = Error, sources = __webpack_require__("webpack-sources"), exports_config = {
12225
+ let exports_rspackVersion = "1.6.5-canary-a27f526c-20251125032833", exports_version = "5.75.0", exports_WebpackError = Error, sources = __webpack_require__("webpack-sources"), exports_config = {
11824
12226
  getNormalizedRspackOptions: getNormalizedRspackOptions,
11825
12227
  applyRspackOptionsDefaults: applyRspackOptionsDefaults,
11826
12228
  getNormalizedWebpackOptions: getNormalizedRspackOptions,
@@ -11863,11 +12265,12 @@ Help:
11863
12265
  ContainerReferencePlugin: ContainerReferencePlugin,
11864
12266
  ModuleFederationPlugin: class {
11865
12267
  _options;
12268
+ _treeShakeSharedPlugin;
11866
12269
  constructor(_options){
11867
12270
  this._options = _options;
11868
12271
  }
11869
12272
  apply(compiler) {
11870
- var options;
12273
+ var options, options1;
11871
12274
  let runtimeToolsPath, bundlerRuntimePath, runtimePath, { webpack } = compiler, paths = (runtimeToolsPath = (options = this._options).implementation ?? require.resolve("@module-federation/runtime-tools"), bundlerRuntimePath = require.resolve("@module-federation/webpack-bundler-runtime", {
11872
12275
  paths: [
11873
12276
  runtimeToolsPath
@@ -11881,101 +12284,53 @@ Help:
11881
12284
  bundlerRuntime: bundlerRuntimePath,
11882
12285
  runtime: runtimePath
11883
12286
  });
11884
- if (compiler.options.resolve.alias = {
12287
+ compiler.options.resolve.alias = {
11885
12288
  "@module-federation/runtime-tools": paths.runtimeTools,
11886
12289
  "@module-federation/runtime": paths.runtime,
11887
12290
  ...compiler.options.resolve.alias
11888
- }, new ModuleFederationRuntimePlugin({
11889
- entryRuntime: function(paths, options, compiler) {
11890
- let runtimePlugins = options.runtimePlugins ?? [], remoteInfos = getRemoteInfos(options), runtimePluginImports = [], runtimePluginVars = [];
11891
- for(let i = 0; i < runtimePlugins.length; i++){
11892
- 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;
11893
- runtimePluginImports.push(`import ${runtimePluginVar} from ${JSON.stringify(pluginPath)}`);
11894
- let paramsCode = void 0 === pluginParams ? "undefined" : JSON.stringify(pluginParams);
11895
- runtimePluginVars.push(`${runtimePluginVar}(${paramsCode})`);
11896
- }
11897
- let content = [
11898
- `import __module_federation_bundler_runtime__ from ${JSON.stringify(paths.bundlerRuntime)}`,
11899
- ...runtimePluginImports,
11900
- `const __module_federation_runtime_plugins__ = [${runtimePluginVars.join(", ")}]`,
11901
- `const __module_federation_remote_infos__ = ${JSON.stringify(remoteInfos)}`,
11902
- `const __module_federation_container_name__ = ${JSON.stringify(options.name ?? compiler.options.output.uniqueName)}`,
11903
- `const __module_federation_share_strategy__ = ${JSON.stringify(options.shareStrategy ?? "version-first")}`,
11904
- compiler.webpack.Template.getFunctionContent(__webpack_require__("./moduleFederationDefaultRuntime.js"))
11905
- ].join(";");
11906
- return `@module-federation/runtime/rspack.js!=!data:text/javascript,${content}`;
11907
- }(paths, this._options, compiler)
11908
- }).apply(compiler), new webpack.container.ModuleFederationPluginV1({
12291
+ }, ((options1 = this._options).shared ? parseOptions(options1.shared, (item, key)=>{
12292
+ if ("string" != typeof item) throw Error("Unexpected array in shared");
12293
+ return item !== key && isRequiredVersion(item) ? {
12294
+ import: key,
12295
+ requiredVersion: item
12296
+ } : {
12297
+ import: item
12298
+ };
12299
+ }, (item)=>item) : []).filter(([, config])=>config.treeshake).length > 0 && (this._treeShakeSharedPlugin = new TreeShakeSharedPlugin({
12300
+ mfConfig: this._options,
12301
+ reshake: !1
12302
+ }), this._treeShakeSharedPlugin.apply(compiler));
12303
+ let runtimePluginApplied = !1;
12304
+ compiler.hooks.beforeRun.tapPromise({
12305
+ name: "ModuleFederationPlugin",
12306
+ stage: 100
12307
+ }, async ()=>{
12308
+ runtimePluginApplied || (runtimePluginApplied = !0, new ModuleFederationRuntimePlugin({
12309
+ entryRuntime: function(paths, options, compiler, treeshakeShareFallbacks) {
12310
+ let runtimePlugins = options.runtimePlugins ?? [], remoteInfos = getRemoteInfos(options), runtimePluginImports = [], runtimePluginVars = [];
12311
+ for(let i = 0; i < runtimePlugins.length; i++){
12312
+ 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;
12313
+ runtimePluginImports.push(`import ${runtimePluginVar} from ${JSON.stringify(pluginPath)}`);
12314
+ let paramsCode = void 0 === pluginParams ? "undefined" : JSON.stringify(pluginParams);
12315
+ runtimePluginVars.push(`${runtimePluginVar}(${paramsCode})`);
12316
+ }
12317
+ let content = [
12318
+ `import __module_federation_bundler_runtime__ from ${JSON.stringify(paths.bundlerRuntime)}`,
12319
+ ...runtimePluginImports,
12320
+ `const __module_federation_runtime_plugins__ = [${runtimePluginVars.join(", ")}]`,
12321
+ `const __module_federation_remote_infos__ = ${JSON.stringify(remoteInfos)}`,
12322
+ `const __module_federation_container_name__ = ${JSON.stringify(options.name ?? compiler.options.output.uniqueName)}`,
12323
+ `const __module_federation_share_strategy__ = ${JSON.stringify(options.shareStrategy ?? "version-first")}`,
12324
+ `const __module_federation_share_fallbacks__ = ${JSON.stringify(treeshakeShareFallbacks)}`,
12325
+ compiler.webpack.Template.getFunctionContent(__webpack_require__("./moduleFederationDefaultRuntime.js"))
12326
+ ].join(";");
12327
+ return `@module-federation/runtime/rspack.js!=!data:text/javascript,${content}`;
12328
+ }(paths, this._options, compiler, this._treeShakeSharedPlugin?.buildAssets || {})
12329
+ }).apply(compiler));
12330
+ }), new webpack.container.ModuleFederationPluginV1({
11909
12331
  ...this._options,
11910
12332
  enhanced: !0
11911
- }).apply(compiler), this._options.manifest) {
11912
- let manifestOptions = !0 === this._options.manifest ? {} : {
11913
- ...this._options.manifest
11914
- }, containerName = manifestOptions.name ?? this._options.name, globalName = manifestOptions.globalName ?? function(library) {
11915
- if (!library) return;
11916
- let libName = library.name;
11917
- if (libName) {
11918
- if ("string" == typeof libName) return libName;
11919
- if (Array.isArray(libName)) return libName[0];
11920
- if ("object" == typeof libName) return libName.root?.[0] ?? libName.amd ?? libName.commonjs ?? void 0;
11921
- }
11922
- }(this._options.library) ?? containerName, remoteAliasMap = Object.entries(getRemoteInfos(this._options)).reduce((sum, cur)=>{
11923
- if (cur[1].length > 1) return sum;
11924
- let { entry, alias, name } = cur[1][0];
11925
- return entry && name && (sum[alias] = {
11926
- name,
11927
- entry
11928
- }), sum;
11929
- }, {}), manifestExposes = function(exposes) {
11930
- if (!exposes) return;
11931
- let result = parseOptions(exposes, (value, key)=>({
11932
- import: Array.isArray(value) ? value : [
11933
- value
11934
- ],
11935
- name: void 0
11936
- }), (value)=>({
11937
- import: Array.isArray(value.import) ? value.import : [
11938
- value.import
11939
- ],
11940
- name: value.name ?? void 0
11941
- })).map(([exposeKey, info])=>{
11942
- let exposeName = info.name ?? exposeKey.replace(/^\.\//, "");
11943
- return {
11944
- path: exposeKey,
11945
- name: exposeName
11946
- };
11947
- });
11948
- return result.length > 0 ? result : void 0;
11949
- }(this._options.exposes);
11950
- void 0 === manifestOptions.exposes && manifestExposes && (manifestOptions.exposes = manifestExposes);
11951
- let manifestShared = function(shared) {
11952
- if (!shared) return;
11953
- let result = parseOptions(shared, (item, key)=>{
11954
- if ("string" != typeof item) throw Error("Unexpected array in shared");
11955
- return item !== key && isRequiredVersion(item) ? {
11956
- import: key,
11957
- requiredVersion: item
11958
- } : {
11959
- import: item
11960
- };
11961
- }, (item)=>item).map(([key, config])=>{
11962
- let name = config.shareKey || key, version = "string" == typeof config.version ? config.version : void 0;
11963
- return {
11964
- name,
11965
- version,
11966
- requiredVersion: "string" == typeof config.requiredVersion ? config.requiredVersion : void 0,
11967
- singleton: config.singleton
11968
- };
11969
- });
11970
- return result.length > 0 ? result : void 0;
11971
- }(this._options.shared);
11972
- void 0 === manifestOptions.shared && manifestShared && (manifestOptions.shared = manifestShared), new ModuleFederationManifestPlugin({
11973
- ...manifestOptions,
11974
- name: containerName,
11975
- globalName,
11976
- remoteAliasMap
11977
- }).apply(compiler);
11978
- }
12333
+ }).apply(compiler), this._options.manifest && new ModuleFederationManifestPlugin(this._options).apply(compiler);
11979
12334
  }
11980
12335
  },
11981
12336
  ModuleFederationPluginV1: class {
@@ -12012,6 +12367,7 @@ Help:
12012
12367
  }
12013
12368
  }, sharing = {
12014
12369
  ProvideSharedPlugin: ProvideSharedPlugin,
12370
+ TreeShakeSharedPlugin: TreeShakeSharedPlugin,
12015
12371
  ConsumeSharedPlugin: ConsumeSharedPlugin,
12016
12372
  SharePlugin: SharePlugin
12017
12373
  }, exports_experiments = {