UNPKG

@module-federation/enhanced

Version:

This package provides enhanced features for module federation.

93 lines (91 loc) 3.47 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const require_runtime = require('../../../_virtual/_rolldown/runtime.js'); const require_lib_container_options = require('../options.js'); let _module_federation_sdk_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path"); let upath = require("upath"); upath = require_runtime.__toESM(upath); let path = require("path"); path = require_runtime.__toESM(path); let crypto = require("crypto"); crypto = require_runtime.__toESM(crypto); //#region src/lib/container/runtime/utils.ts const extractUrlAndGlobal = require((0, _module_federation_sdk_normalize_webpack_path.normalizeWebpackPath)("webpack/lib/util/extractUrlAndGlobal")); function getFederationGlobalScope(runtimeGlobals) { return `${runtimeGlobals.require || "__webpack_require__"}.federation`; } function normalizeRuntimeInitOptionsWithOutShared(options) { const parsedOptions = require_lib_container_options.parseOptions(options.remotes || [], (item) => ({ external: Array.isArray(item) ? item : [item], shareScope: options.shareScope || "default" }), (item) => ({ external: Array.isArray(item.external) ? item.external : [item.external], shareScope: item.shareScope || options.shareScope || "default" })); const remoteOptions = []; parsedOptions.forEach((parsedOption) => { const [alias, remoteInfos] = parsedOption; const { external, shareScope } = remoteInfos; external.forEach((externalItem) => { try { const entry = externalItem; if (/\s/.test(entry)) return; const [url, globalName] = extractUrlAndGlobal(externalItem); remoteOptions.push({ alias, name: globalName, entry: url, shareScope, externalType: "script" }); } catch (err) { const getExternalTypeFromExternal = (external) => { if (/^[a-z0-9-]+ /.test(external)) { const idx = external.indexOf(" "); return [external.slice(0, idx), external.slice(idx + 1)]; } return null; }; remoteOptions.push({ alias, name: "", entry: "", shareScope, externalType: getExternalTypeFromExternal(externalItem) || "unknown" }); return; } }); }); return { name: options.name, remotes: remoteOptions, shareStrategy: options.shareStrategy || "version-first" }; } function modifyEntry(options) { const { compiler, staticEntry, prependEntry } = options; const operator = (oriEntry, newEntry) => Object.assign(oriEntry, newEntry); if (typeof compiler.options.entry === "function") { const prevEntryFn = compiler.options.entry; compiler.options.entry = async () => { let res = await prevEntryFn(); if (staticEntry) res = operator(res, staticEntry); if (prependEntry) prependEntry(res); return res; }; } else { if (staticEntry) compiler.options.entry = operator(compiler.options.entry, staticEntry); if (prependEntry) prependEntry(compiler.options.entry); } } function createHash(contents) { return crypto.default.createHash("md5").update(contents).digest("hex"); } const normalizeToPosixPath = (p) => upath.default.normalizeSafe(path.default.normalize(p || "")); //#endregion exports.createHash = createHash; exports.getFederationGlobalScope = getFederationGlobalScope; exports.modifyEntry = modifyEntry; exports.normalizeRuntimeInitOptionsWithOutShared = normalizeRuntimeInitOptionsWithOutShared; exports.normalizeToPosixPath = normalizeToPosixPath; //# sourceMappingURL=utils.js.map