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