@rspack-canary/core 1.6.5-canary-5c09e49d-20251121173820 → 1.6.5-canary-a407d226-20251124112255
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/container/ModuleFederationManifestPlugin.d.ts +9 -2
- package/dist/container/ModuleFederationPlugin.d.ts +16 -1
- package/dist/exports.d.ts +3 -0
- package/dist/index.js +610 -242
- package/dist/moduleFederationDefaultRuntime.js +1 -1
- package/dist/sharing/CollectSharedEntryPlugin.d.ts +22 -0
- package/dist/sharing/ConsumeSharedPlugin.d.ts +10 -0
- package/dist/sharing/IndependentSharedPlugin.d.ts +37 -0
- package/dist/sharing/ProvideSharedPlugin.d.ts +14 -0
- package/dist/sharing/ShareContainerPlugin.d.ts +23 -0
- package/dist/sharing/SharePlugin.d.ts +29 -0
- package/dist/sharing/SharedUsedExportsOptimizerPlugin.d.ts +14 -0
- package/dist/sharing/TreeShakeSharedPlugin.d.ts +19 -0
- package/dist/sharing/utils.d.ts +1 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -5740,7 +5740,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
|
|
5740
5740
|
}, applyExperimentsDefaults = (experiments, { development })=>{
|
|
5741
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);
|
|
5742
5742
|
}, applybundlerInfoDefaults = (rspackFuture, library)=>{
|
|
5743
|
-
"object" == typeof rspackFuture && (D(rspackFuture, "bundlerInfo", {}), "object" == typeof rspackFuture.bundlerInfo && (D(rspackFuture.bundlerInfo, "version", "1.6.5-canary-
|
|
5743
|
+
"object" == typeof rspackFuture && (D(rspackFuture, "bundlerInfo", {}), "object" == typeof rspackFuture.bundlerInfo && (D(rspackFuture.bundlerInfo, "version", "1.6.5-canary-a407d226-20251124112255"), D(rspackFuture.bundlerInfo, "bundler", "rspack"), D(rspackFuture.bundlerInfo, "force", !library)));
|
|
5744
5744
|
}, applySnapshotDefaults = (_snapshot, _env)=>{}, applyModuleDefaults = (module1, { cache, asyncWebAssembly, css, targetProperties, mode, uniqueName, usedExports, inlineConst, deferImport })=>{
|
|
5745
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 })=>{
|
|
5746
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", [
|
|
@@ -7390,7 +7390,7 @@ You can also more options via the 'target' option: 'browserslist' / 'browserslis
|
|
|
7390
7390
|
});
|
|
7391
7391
|
}
|
|
7392
7392
|
}
|
|
7393
|
-
let CORE_VERSION = "1.6.5-canary-
|
|
7393
|
+
let CORE_VERSION = "1.6.5-canary-a407d226-20251124112255", bindingVersionCheck_errorMessage = (coreVersion, expectedCoreVersion)=>process.env.RSPACK_BINDING ? `Unmatched version @rspack/core@${coreVersion} and binding version.
|
|
7394
7394
|
|
|
7395
7395
|
Help:
|
|
7396
7396
|
Looks like you are using a custom binding (via environment variable 'RSPACK_BINDING=${process.env.RSPACK_BINDING}').
|
|
@@ -8690,7 +8690,7 @@ Help:
|
|
|
8690
8690
|
obj.children = this.stats.map((stat, idx)=>{
|
|
8691
8691
|
let obj = stat.toJson(childOptions.children[idx]), compilationName = stat.compilation.name;
|
|
8692
8692
|
return obj.name = compilationName && makePathsRelative(childOptions.context, compilationName, stat.compilation.compiler.root), obj;
|
|
8693
|
-
}), childOptions.version && (obj.rspackVersion = "1.6.5-canary-
|
|
8693
|
+
}), childOptions.version && (obj.rspackVersion = "1.6.5-canary-a407d226-20251124112255", obj.version = "5.75.0"), childOptions.hash && (obj.hash = obj.children.map((j)=>j.hash).join(""));
|
|
8694
8694
|
let mapError = (j, obj)=>({
|
|
8695
8695
|
...obj,
|
|
8696
8696
|
compilerPath: obj.compilerPath ? `${j.name}.${obj.compilerPath}` : j.name
|
|
@@ -9589,7 +9589,7 @@ Help:
|
|
|
9589
9589
|
object.hash = context.getStatsCompilation(compilation).hash;
|
|
9590
9590
|
},
|
|
9591
9591
|
version: (object)=>{
|
|
9592
|
-
object.version = "5.75.0", object.rspackVersion = "1.6.5-canary-
|
|
9592
|
+
object.version = "5.75.0", object.rspackVersion = "1.6.5-canary-a407d226-20251124112255";
|
|
9593
9593
|
},
|
|
9594
9594
|
env: (object, _compilation, _context, { _env })=>{
|
|
9595
9595
|
object.env = _env;
|
|
@@ -11434,30 +11434,116 @@ Help:
|
|
|
11434
11434
|
function isRequiredVersion(str) {
|
|
11435
11435
|
return VERSION_PATTERN_REGEXP.test(str);
|
|
11436
11436
|
}
|
|
11437
|
-
let
|
|
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";
|
|
11438
11459
|
function isPlainObject(value) {
|
|
11439
11460
|
return !!value && "object" == typeof value && !Array.isArray(value);
|
|
11440
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
|
+
}
|
|
11441
11474
|
class ModuleFederationManifestPlugin extends RspackBuiltinPlugin {
|
|
11442
11475
|
name = binding_.BuiltinPluginName.ModuleFederationManifestPlugin;
|
|
11443
11476
|
opts;
|
|
11444
11477
|
constructor(opts){
|
|
11445
|
-
|
|
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
|
+
});
|
|
11446
11543
|
}
|
|
11447
11544
|
raw(compiler) {
|
|
11448
11545
|
var isDev;
|
|
11449
|
-
let pkg, buildVersion, { fileName, filePath, disableAssetsAnalyze, remoteAliasMap, exposes, shared } = this.opts, { statsFileName, manifestFileName } =
|
|
11450
|
-
var name;
|
|
11451
|
-
if (!manifestOptions) return {
|
|
11452
|
-
statsFileName: STATS_FILE_NAME,
|
|
11453
|
-
manifestFileName: MANIFEST_FILE_NAME
|
|
11454
|
-
};
|
|
11455
|
-
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;
|
|
11456
|
-
return {
|
|
11457
|
-
statsFileName: (0, external_node_path_namespaceObject.join)(filePath, statsFileName),
|
|
11458
|
-
manifestFileName: (0, external_node_path_namespaceObject.join)(filePath, manifestFileName)
|
|
11459
|
-
};
|
|
11460
|
-
}(this.opts), rawOptions = {
|
|
11546
|
+
let pkg, buildVersion, { fileName, filePath, disableAssetsAnalyze, remoteAliasMap, exposes, shared } = this.opts, { statsFileName, manifestFileName } = getFileName(this.opts), rawOptions = {
|
|
11461
11547
|
name: this.opts.name,
|
|
11462
11548
|
globalName: this.opts.globalName,
|
|
11463
11549
|
fileName,
|
|
@@ -11492,81 +11578,6 @@ Help:
|
|
|
11492
11578
|
return createBuiltinPlugin(this.name, rawOptions);
|
|
11493
11579
|
}
|
|
11494
11580
|
}
|
|
11495
|
-
let ModuleFederationRuntimePlugin = base_create(binding_.BuiltinPluginName.ModuleFederationRuntimePlugin, (options = {})=>options), parseOptions = (options, normalizeSimple, normalizeOptions)=>{
|
|
11496
|
-
let items = [];
|
|
11497
|
-
var options1 = options, normalizeSimple1 = normalizeSimple, normalizeOptions1 = normalizeOptions, fn = (key, value)=>{
|
|
11498
|
-
items.push([
|
|
11499
|
-
key,
|
|
11500
|
-
value
|
|
11501
|
-
]);
|
|
11502
|
-
};
|
|
11503
|
-
let object = (obj)=>{
|
|
11504
|
-
for (let [key, value] of Object.entries(obj))"string" == typeof value || Array.isArray(value) ? fn(key, normalizeSimple1(value, key)) : fn(key, normalizeOptions1(value, key));
|
|
11505
|
-
};
|
|
11506
|
-
if (options1) if (Array.isArray(options1)) {
|
|
11507
|
-
var items1 = options1;
|
|
11508
|
-
for (let item of items1)if ("string" == typeof item) fn(item, normalizeSimple1(item, item));
|
|
11509
|
-
else if (item && "object" == typeof item) object(item);
|
|
11510
|
-
else throw Error("Unexpected options format");
|
|
11511
|
-
} else if ("object" == typeof options1) object(options1);
|
|
11512
|
-
else throw Error("Unexpected options format");
|
|
11513
|
-
return items;
|
|
11514
|
-
};
|
|
11515
|
-
function getRemoteInfos(options) {
|
|
11516
|
-
if (!options.remotes) return {};
|
|
11517
|
-
let remoteType = options.remoteType || (options.library ? options.library.type : "script"), remotes = parseOptions(options.remotes, (item)=>({
|
|
11518
|
-
external: Array.isArray(item) ? item : [
|
|
11519
|
-
item
|
|
11520
|
-
],
|
|
11521
|
-
shareScope: options.shareScope || "default"
|
|
11522
|
-
}), (item)=>({
|
|
11523
|
-
external: Array.isArray(item.external) ? item.external : [
|
|
11524
|
-
item.external
|
|
11525
|
-
],
|
|
11526
|
-
shareScope: item.shareScope || options.shareScope || "default"
|
|
11527
|
-
})), remoteInfos = {};
|
|
11528
|
-
for (let [key, config] of remotes)for (let external of config.external){
|
|
11529
|
-
let [externalType, externalRequest] = function(external) {
|
|
11530
|
-
let result = function(external) {
|
|
11531
|
-
if (/^[a-z0-9-]+ /.test(external)) {
|
|
11532
|
-
let idx = external.indexOf(" ");
|
|
11533
|
-
return [
|
|
11534
|
-
external.slice(0, idx),
|
|
11535
|
-
external.slice(idx + 1)
|
|
11536
|
-
];
|
|
11537
|
-
}
|
|
11538
|
-
return null;
|
|
11539
|
-
}(external);
|
|
11540
|
-
return null === result ? [
|
|
11541
|
-
remoteType,
|
|
11542
|
-
external
|
|
11543
|
-
] : result;
|
|
11544
|
-
}(external);
|
|
11545
|
-
if (remoteInfos[key] ??= [], "script" === externalType) {
|
|
11546
|
-
let [url, global] = function(urlAndGlobal) {
|
|
11547
|
-
let index = urlAndGlobal.indexOf("@");
|
|
11548
|
-
return index <= 0 || index === urlAndGlobal.length - 1 ? null : [
|
|
11549
|
-
urlAndGlobal.substring(index + 1),
|
|
11550
|
-
urlAndGlobal.substring(0, index)
|
|
11551
|
-
];
|
|
11552
|
-
}(externalRequest);
|
|
11553
|
-
remoteInfos[key].push({
|
|
11554
|
-
alias: key,
|
|
11555
|
-
name: global,
|
|
11556
|
-
entry: url,
|
|
11557
|
-
externalType,
|
|
11558
|
-
shareScope: config.shareScope
|
|
11559
|
-
});
|
|
11560
|
-
} else remoteInfos[key].push({
|
|
11561
|
-
alias: key,
|
|
11562
|
-
name: void 0,
|
|
11563
|
-
entry: void 0,
|
|
11564
|
-
externalType,
|
|
11565
|
-
shareScope: config.shareScope
|
|
11566
|
-
});
|
|
11567
|
-
}
|
|
11568
|
-
return remoteInfos;
|
|
11569
|
-
}
|
|
11570
11581
|
let compilerSet = new WeakSet();
|
|
11571
11582
|
class ShareRuntimePlugin extends RspackBuiltinPlugin {
|
|
11572
11583
|
enhanced;
|
|
@@ -11579,42 +11590,45 @@ Help:
|
|
|
11579
11590
|
if (compiler1 = compiler, !compilerSet.has(compiler1)) return compiler2 = compiler, compilerSet.add(compiler2), createBuiltinPlugin(this.name, this.enhanced);
|
|
11580
11591
|
}
|
|
11581
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
|
+
}
|
|
11582
11626
|
class ConsumeSharedPlugin extends RspackBuiltinPlugin {
|
|
11583
11627
|
name = binding_.BuiltinPluginName.ConsumeSharedPlugin;
|
|
11584
11628
|
_options;
|
|
11585
11629
|
constructor(options){
|
|
11586
11630
|
super(), this._options = {
|
|
11587
|
-
consumes:
|
|
11588
|
-
if (Array.isArray(item)) throw Error("Unexpected array in options");
|
|
11589
|
-
return item !== key && isRequiredVersion(item) ? {
|
|
11590
|
-
import: key,
|
|
11591
|
-
shareScope: options.shareScope || "default",
|
|
11592
|
-
shareKey: key,
|
|
11593
|
-
requiredVersion: item,
|
|
11594
|
-
strictVersion: !0,
|
|
11595
|
-
packageName: void 0,
|
|
11596
|
-
singleton: !1,
|
|
11597
|
-
eager: !1
|
|
11598
|
-
} : {
|
|
11599
|
-
import: key,
|
|
11600
|
-
shareScope: options.shareScope || "default",
|
|
11601
|
-
shareKey: key,
|
|
11602
|
-
requiredVersion: void 0,
|
|
11603
|
-
packageName: void 0,
|
|
11604
|
-
strictVersion: !1,
|
|
11605
|
-
singleton: !1,
|
|
11606
|
-
eager: !1
|
|
11607
|
-
};
|
|
11608
|
-
}, (item, key)=>({
|
|
11609
|
-
import: !1 === item.import ? void 0 : item.import || key,
|
|
11610
|
-
shareScope: item.shareScope || options.shareScope || "default",
|
|
11611
|
-
shareKey: item.shareKey || key,
|
|
11612
|
-
requiredVersion: item.requiredVersion,
|
|
11613
|
-
strictVersion: "boolean" == typeof item.strictVersion ? item.strictVersion : !1 !== item.import && !item.singleton,
|
|
11614
|
-
packageName: item.packageName,
|
|
11615
|
-
singleton: !!item.singleton,
|
|
11616
|
-
eager: !!item.eager
|
|
11617
|
-
})),
|
|
11631
|
+
consumes: normalizeConsumeShareOptions(options.consumes, options.shareScope),
|
|
11618
11632
|
enhanced: options.enhanced ?? !1
|
|
11619
11633
|
};
|
|
11620
11634
|
}
|
|
@@ -11635,28 +11649,29 @@ Help:
|
|
|
11635
11649
|
_provides;
|
|
11636
11650
|
_enhanced;
|
|
11637
11651
|
constructor(options){
|
|
11638
|
-
|
|
11652
|
+
var options1, shareScope, enhanced;
|
|
11653
|
+
super(), this._provides = (options1 = options.provides, shareScope = options.shareScope, enhanced = options.enhanced, parseOptions(options1, (item)=>{
|
|
11639
11654
|
if (Array.isArray(item)) throw Error("Unexpected array of provides");
|
|
11640
11655
|
return {
|
|
11641
11656
|
shareKey: item,
|
|
11642
11657
|
version: void 0,
|
|
11643
|
-
shareScope:
|
|
11658
|
+
shareScope: shareScope || "default",
|
|
11644
11659
|
eager: !1
|
|
11645
11660
|
};
|
|
11646
11661
|
}, (item)=>{
|
|
11647
11662
|
let raw = {
|
|
11648
11663
|
shareKey: item.shareKey,
|
|
11649
11664
|
version: item.version,
|
|
11650
|
-
shareScope: item.shareScope ||
|
|
11665
|
+
shareScope: item.shareScope || shareScope || "default",
|
|
11651
11666
|
eager: !!item.eager
|
|
11652
11667
|
};
|
|
11653
|
-
return
|
|
11668
|
+
return enhanced ? {
|
|
11654
11669
|
...raw,
|
|
11655
11670
|
singleton: item.singleton,
|
|
11656
11671
|
requiredVersion: item.requiredVersion,
|
|
11657
11672
|
strictVersion: item.strictVersion
|
|
11658
11673
|
} : raw;
|
|
11659
|
-
}), this._enhanced = options.enhanced;
|
|
11674
|
+
})), this._enhanced = options.enhanced;
|
|
11660
11675
|
}
|
|
11661
11676
|
raw(compiler) {
|
|
11662
11677
|
new ShareRuntimePlugin(this._enhanced ?? !1).apply(compiler);
|
|
@@ -11667,32 +11682,39 @@ Help:
|
|
|
11667
11682
|
return createBuiltinPlugin(this.name, rawOptions);
|
|
11668
11683
|
}
|
|
11669
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
|
+
}
|
|
11670
11710
|
class SharePlugin {
|
|
11671
11711
|
_shareScope;
|
|
11672
11712
|
_consumes;
|
|
11673
11713
|
_provides;
|
|
11674
11714
|
_enhanced;
|
|
11715
|
+
_sharedOptions;
|
|
11675
11716
|
constructor(options){
|
|
11676
|
-
const sharedOptions =
|
|
11677
|
-
if ("string" != typeof item) throw Error("Unexpected array in shared");
|
|
11678
|
-
return item !== key && isRequiredVersion(item) ? {
|
|
11679
|
-
import: key,
|
|
11680
|
-
requiredVersion: item
|
|
11681
|
-
} : {
|
|
11682
|
-
import: item
|
|
11683
|
-
};
|
|
11684
|
-
}, (item)=>item), consumes = sharedOptions.map(([key, options])=>({
|
|
11685
|
-
[key]: {
|
|
11686
|
-
import: options.import,
|
|
11687
|
-
shareKey: options.shareKey || key,
|
|
11688
|
-
shareScope: options.shareScope,
|
|
11689
|
-
requiredVersion: options.requiredVersion,
|
|
11690
|
-
strictVersion: options.strictVersion,
|
|
11691
|
-
singleton: options.singleton,
|
|
11692
|
-
packageName: options.packageName,
|
|
11693
|
-
eager: options.eager
|
|
11694
|
-
}
|
|
11695
|
-
})), 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])=>({
|
|
11696
11718
|
[options.import || key]: {
|
|
11697
11719
|
shareKey: options.shareKey || key,
|
|
11698
11720
|
shareScope: options.shareScope,
|
|
@@ -11703,7 +11725,7 @@ Help:
|
|
|
11703
11725
|
strictVersion: options.strictVersion
|
|
11704
11726
|
}
|
|
11705
11727
|
}));
|
|
11706
|
-
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;
|
|
11707
11729
|
}
|
|
11708
11730
|
apply(compiler) {
|
|
11709
11731
|
new ConsumeSharedPlugin({
|
|
@@ -11717,6 +11739,398 @@ Help:
|
|
|
11717
11739
|
}).apply(compiler);
|
|
11718
11740
|
}
|
|
11719
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
|
+
}
|
|
11720
12134
|
class ContainerPlugin extends RspackBuiltinPlugin {
|
|
11721
12135
|
name = binding_.BuiltinPluginName.ContainerPlugin;
|
|
11722
12136
|
_options;
|
|
@@ -11808,7 +12222,7 @@ Help:
|
|
|
11808
12222
|
let _options = JSON.stringify(options || {});
|
|
11809
12223
|
return binding_default().transform(source, _options);
|
|
11810
12224
|
}
|
|
11811
|
-
let exports_rspackVersion = "1.6.5-canary-
|
|
12225
|
+
let exports_rspackVersion = "1.6.5-canary-a407d226-20251124112255", exports_version = "5.75.0", exports_WebpackError = Error, sources = __webpack_require__("webpack-sources"), exports_config = {
|
|
11812
12226
|
getNormalizedRspackOptions: getNormalizedRspackOptions,
|
|
11813
12227
|
applyRspackOptionsDefaults: applyRspackOptionsDefaults,
|
|
11814
12228
|
getNormalizedWebpackOptions: getNormalizedRspackOptions,
|
|
@@ -11851,11 +12265,12 @@ Help:
|
|
|
11851
12265
|
ContainerReferencePlugin: ContainerReferencePlugin,
|
|
11852
12266
|
ModuleFederationPlugin: class {
|
|
11853
12267
|
_options;
|
|
12268
|
+
_treeShakeSharedPlugin;
|
|
11854
12269
|
constructor(_options){
|
|
11855
12270
|
this._options = _options;
|
|
11856
12271
|
}
|
|
11857
12272
|
apply(compiler) {
|
|
11858
|
-
var options;
|
|
12273
|
+
var options, options1;
|
|
11859
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", {
|
|
11860
12275
|
paths: [
|
|
11861
12276
|
runtimeToolsPath
|
|
@@ -11869,101 +12284,53 @@ Help:
|
|
|
11869
12284
|
bundlerRuntime: bundlerRuntimePath,
|
|
11870
12285
|
runtime: runtimePath
|
|
11871
12286
|
});
|
|
11872
|
-
|
|
12287
|
+
compiler.options.resolve.alias = {
|
|
11873
12288
|
"@module-federation/runtime-tools": paths.runtimeTools,
|
|
11874
12289
|
"@module-federation/runtime": paths.runtime,
|
|
11875
12290
|
...compiler.options.resolve.alias
|
|
11876
|
-
},
|
|
11877
|
-
|
|
11878
|
-
|
|
11879
|
-
|
|
11880
|
-
|
|
11881
|
-
|
|
11882
|
-
|
|
11883
|
-
|
|
11884
|
-
|
|
11885
|
-
|
|
11886
|
-
|
|
11887
|
-
|
|
11888
|
-
|
|
11889
|
-
|
|
11890
|
-
|
|
11891
|
-
|
|
11892
|
-
|
|
11893
|
-
|
|
11894
|
-
|
|
11895
|
-
|
|
11896
|
-
|
|
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({
|
|
11897
12331
|
...this._options,
|
|
11898
12332
|
enhanced: !0
|
|
11899
|
-
}).apply(compiler), this._options.manifest)
|
|
11900
|
-
let manifestOptions = !0 === this._options.manifest ? {} : {
|
|
11901
|
-
...this._options.manifest
|
|
11902
|
-
}, containerName = manifestOptions.name ?? this._options.name, globalName = manifestOptions.globalName ?? function(library) {
|
|
11903
|
-
if (!library) return;
|
|
11904
|
-
let libName = library.name;
|
|
11905
|
-
if (libName) {
|
|
11906
|
-
if ("string" == typeof libName) return libName;
|
|
11907
|
-
if (Array.isArray(libName)) return libName[0];
|
|
11908
|
-
if ("object" == typeof libName) return libName.root?.[0] ?? libName.amd ?? libName.commonjs ?? void 0;
|
|
11909
|
-
}
|
|
11910
|
-
}(this._options.library) ?? containerName, remoteAliasMap = Object.entries(getRemoteInfos(this._options)).reduce((sum, cur)=>{
|
|
11911
|
-
if (cur[1].length > 1) return sum;
|
|
11912
|
-
let { entry, alias, name } = cur[1][0];
|
|
11913
|
-
return entry && name && (sum[alias] = {
|
|
11914
|
-
name,
|
|
11915
|
-
entry
|
|
11916
|
-
}), sum;
|
|
11917
|
-
}, {}), manifestExposes = function(exposes) {
|
|
11918
|
-
if (!exposes) return;
|
|
11919
|
-
let result = parseOptions(exposes, (value, key)=>({
|
|
11920
|
-
import: Array.isArray(value) ? value : [
|
|
11921
|
-
value
|
|
11922
|
-
],
|
|
11923
|
-
name: void 0
|
|
11924
|
-
}), (value)=>({
|
|
11925
|
-
import: Array.isArray(value.import) ? value.import : [
|
|
11926
|
-
value.import
|
|
11927
|
-
],
|
|
11928
|
-
name: value.name ?? void 0
|
|
11929
|
-
})).map(([exposeKey, info])=>{
|
|
11930
|
-
let exposeName = info.name ?? exposeKey.replace(/^\.\//, "");
|
|
11931
|
-
return {
|
|
11932
|
-
path: exposeKey,
|
|
11933
|
-
name: exposeName
|
|
11934
|
-
};
|
|
11935
|
-
});
|
|
11936
|
-
return result.length > 0 ? result : void 0;
|
|
11937
|
-
}(this._options.exposes);
|
|
11938
|
-
void 0 === manifestOptions.exposes && manifestExposes && (manifestOptions.exposes = manifestExposes);
|
|
11939
|
-
let manifestShared = function(shared) {
|
|
11940
|
-
if (!shared) return;
|
|
11941
|
-
let result = parseOptions(shared, (item, key)=>{
|
|
11942
|
-
if ("string" != typeof item) throw Error("Unexpected array in shared");
|
|
11943
|
-
return item !== key && isRequiredVersion(item) ? {
|
|
11944
|
-
import: key,
|
|
11945
|
-
requiredVersion: item
|
|
11946
|
-
} : {
|
|
11947
|
-
import: item
|
|
11948
|
-
};
|
|
11949
|
-
}, (item)=>item).map(([key, config])=>{
|
|
11950
|
-
let name = config.shareKey || key, version = "string" == typeof config.version ? config.version : void 0;
|
|
11951
|
-
return {
|
|
11952
|
-
name,
|
|
11953
|
-
version,
|
|
11954
|
-
requiredVersion: "string" == typeof config.requiredVersion ? config.requiredVersion : void 0,
|
|
11955
|
-
singleton: config.singleton
|
|
11956
|
-
};
|
|
11957
|
-
});
|
|
11958
|
-
return result.length > 0 ? result : void 0;
|
|
11959
|
-
}(this._options.shared);
|
|
11960
|
-
void 0 === manifestOptions.shared && manifestShared && (manifestOptions.shared = manifestShared), new ModuleFederationManifestPlugin({
|
|
11961
|
-
...manifestOptions,
|
|
11962
|
-
name: containerName,
|
|
11963
|
-
globalName,
|
|
11964
|
-
remoteAliasMap
|
|
11965
|
-
}).apply(compiler);
|
|
11966
|
-
}
|
|
12333
|
+
}).apply(compiler), this._options.manifest && new ModuleFederationManifestPlugin(this._options).apply(compiler);
|
|
11967
12334
|
}
|
|
11968
12335
|
},
|
|
11969
12336
|
ModuleFederationPluginV1: class {
|
|
@@ -12000,6 +12367,7 @@ Help:
|
|
|
12000
12367
|
}
|
|
12001
12368
|
}, sharing = {
|
|
12002
12369
|
ProvideSharedPlugin: ProvideSharedPlugin,
|
|
12370
|
+
TreeShakeSharedPlugin: TreeShakeSharedPlugin,
|
|
12003
12371
|
ConsumeSharedPlugin: ConsumeSharedPlugin,
|
|
12004
12372
|
SharePlugin: SharePlugin
|
|
12005
12373
|
}, exports_experiments = {
|