@originjs/vite-plugin-federation
Advanced tools
Comparing version 1.3.1 to 1.3.2
@@ -5,3 +5,3 @@ "use strict"; | ||
const fs = require("fs"); | ||
const crypto = require("crypto"); | ||
require("crypto"); | ||
function _interopNamespaceDefault(e) { | ||
@@ -158,2 +158,29 @@ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } }); | ||
} | ||
const EXPOSES_MAP = /* @__PURE__ */ new Map(); | ||
const EXPOSES_KEY_MAP = /* @__PURE__ */ new Map(); | ||
const SHARED = "shared"; | ||
const DYNAMIC_LOADING_CSS = "dynamicLoadingCss"; | ||
const DYNAMIC_LOADING_CSS_PREFIX = "__v__css__"; | ||
const DEFAULT_ENTRY_FILENAME = "remoteEntry.js"; | ||
const builderInfo = { | ||
builder: "rollup", | ||
version: "", | ||
assetsDir: "", | ||
isHost: false, | ||
isRemote: false, | ||
isShared: false | ||
}; | ||
const parsedOptions = { | ||
prodExpose: [], | ||
prodRemote: [], | ||
prodShared: [], | ||
devShared: [], | ||
devExpose: [], | ||
devRemote: [] | ||
}; | ||
const devRemotes = []; | ||
const prodRemotes = []; | ||
const viteConfigResolved = { | ||
config: void 0 | ||
}; | ||
function parseSharedOptions(options) { | ||
@@ -291,28 +318,2 @@ return parseOptions( | ||
const NAME_CHAR_REG = new RegExp("[0-9a-zA-Z@_-]+"); | ||
const EXPOSES_MAP = /* @__PURE__ */ new Map(); | ||
const EXPOSES_KEY_MAP = /* @__PURE__ */ new Map(); | ||
const SHARED = "shared"; | ||
const DYNAMIC_LOADING_CSS = "dynamicLoadingCss"; | ||
const DYNAMIC_LOADING_CSS_PREFIX = "__v__css__"; | ||
const DEFAULT_ENTRY_FILENAME = "remoteEntry.js"; | ||
const builderInfo = { | ||
builder: "rollup", | ||
version: "", | ||
assetsDir: "", | ||
isHost: false, | ||
isRemote: false, | ||
isShared: false | ||
}; | ||
const parsedOptions = { | ||
prodExpose: [], | ||
prodRemote: [], | ||
prodShared: [], | ||
devShared: [], | ||
devExpose: [], | ||
devRemote: [] | ||
}; | ||
const devRemotes = []; | ||
const prodRemotes = []; | ||
const viteConfigResolved = { config: void 0 }; | ||
const sharedFileName2Prop = /* @__PURE__ */ new Map(); | ||
function prodRemotePlugin(options) { | ||
@@ -436,14 +437,8 @@ parsedOptions.prodRemote = parseRemoteOptions(options); | ||
if (!sharedInfo[1].emitFile) { | ||
const basename2 = `__federation_shared_${removeNonRegLetter( | ||
sharedInfo[0], | ||
NAME_CHAR_REG | ||
)}-${crypto.createHash("md5").update(sharedInfo[1].packagePath).digest("hex").toString().slice(0, 8)}.js`; | ||
sharedInfo[1].emitFile = this.emitFile({ | ||
type: "chunk", | ||
id: sharedInfo[1].id ?? sharedInfo[1].packagePath, | ||
fileName: `${builderInfo.assetsDir ? builderInfo.assetsDir + "/" : ""}${sharedInfo[1].root ? sharedInfo[1].root[0] + "/" : ""}${basename2}`, | ||
preserveSignature: "allow-extension", | ||
name: sharedInfo[0] | ||
name: `__federation_shared_${sharedInfo[0]}` | ||
}); | ||
sharedFileName2Prop.set(basename2, sharedInfo); | ||
} | ||
@@ -453,5 +448,3 @@ } | ||
const moduleMapCode = parsedOptions.prodShared.filter((shareInfo) => shareInfo[1].generate).map( | ||
(sharedInfo) => `'${sharedInfo[0]}':{get:()=>()=>__federation_import('./${sharedInfo[1].root ? `${sharedInfo[1].root[0]}/` : ""}${path.basename( | ||
this.getFileName(sharedInfo[1].emitFile) | ||
)}'),import:${sharedInfo[1].import}${sharedInfo[1].requiredVersion ? `,requiredVersion:'${sharedInfo[1].requiredVersion}'` : ""}}` | ||
(sharedInfo) => `'${sharedInfo[0]}':{get:()=>()=>__federation_import(import.meta.ROLLUP_FILE_URL_${sharedInfo[1].emitFile}),import:${sharedInfo[1].import}${sharedInfo[1].requiredVersion ? `,requiredVersion:'${sharedInfo[1].requiredVersion}'` : ""}}` | ||
).join(","); | ||
@@ -483,4 +476,4 @@ return code.replace( | ||
if (typeof obj === "object") { | ||
const fileName = `./${path.basename(this.getFileName(obj.emitFile))}`; | ||
str += `get:()=>get('${fileName}', ${REMOTE_FROM_PARAMETER}), loaded:1`; | ||
const fileUrl = `import.meta.ROLLUP_FILE_URL_${obj.emitFile}`; | ||
str += `get:()=>get(${fileUrl}, ${REMOTE_FROM_PARAMETER}), loaded:1`; | ||
res.push(`'${arr[0]}':{'${obj.version}':{${str}}}`); | ||
@@ -711,3 +704,3 @@ } | ||
} | ||
const federation_fn_import = "import { satisfy } from '__federation_fn_satisfy'\n\n// eslint-disable-next-line no-undef\nconst moduleMap = __rf_var__moduleMap\nconst moduleCache = Object.create(null)\nasync function importShared(name, shareScope = 'default') {\n return moduleCache[name]\n ? new Promise((r) => r(moduleCache[name]))\n : (await getSharedFromRuntime(name, shareScope)) || getSharedFromLocal(name)\n}\n// eslint-disable-next-line\nasync function __federation_import(name) {\n return import(name)\n}\nasync function getSharedFromRuntime(name, shareScope) {\n let module = null\n if (globalThis?.__federation_shared__?.[shareScope]?.[name]) {\n const versionObj = globalThis.__federation_shared__[shareScope][name]\n const versionKey = Object.keys(versionObj)[0]\n const versionValue = Object.values(versionObj)[0]\n if (moduleMap[name]?.requiredVersion) {\n // judge version satisfy\n if (satisfy(versionKey, moduleMap[name].requiredVersion)) {\n module = await (await versionValue.get())()\n } else {\n console.log(\n `provider support ${name}(${versionKey}) is not satisfied requiredVersion(\\${moduleMap[name].requiredVersion})`\n )\n }\n } else {\n module = await (await versionValue.get())()\n }\n }\n if (module) {\n if (module.default && Object.keys(module).length < 2)\n module = module.default\n moduleCache[name] = module\n return module\n }\n}\nasync function getSharedFromLocal(name) {\n if (moduleMap[name]?.import) {\n let module = await (await moduleMap[name].get())()\n if (module.default && Object.keys(module).length < 2)\n module = module.default\n moduleCache[name] = module\n return module\n } else {\n console.error(\n `consumer config import=false,so cant use callback shared module`\n )\n }\n}\nexport {\n importShared,\n getSharedFromRuntime as importSharedRuntime,\n getSharedFromLocal as importSharedLocal\n}\n"; | ||
const federation_fn_import = "import { satisfy } from '__federation_fn_satisfy'\n\n// eslint-disable-next-line no-undef\nconst moduleMap = __rf_var__moduleMap\nconst moduleCache = Object.create(null)\nasync function importShared(name, shareScope = 'default') {\n return moduleCache[name]\n ? new Promise((r) => r(moduleCache[name]))\n : (await getSharedFromRuntime(name, shareScope)) || getSharedFromLocal(name)\n}\n// eslint-disable-next-line\nasync function __federation_import(name) {\n return import(name)\n}\nasync function getSharedFromRuntime(name, shareScope) {\n let module = null\n if (globalThis?.__federation_shared__?.[shareScope]?.[name]) {\n const versionObj = globalThis.__federation_shared__[shareScope][name]\n const versionKey = Object.keys(versionObj)[0]\n const versionValue = Object.values(versionObj)[0]\n if (moduleMap[name]?.requiredVersion) {\n // judge version satisfy\n if (satisfy(versionKey, moduleMap[name].requiredVersion)) {\n module = await (await versionValue.get())()\n } else {\n console.log(\n `provider support ${name}(${versionKey}) is not satisfied requiredVersion(\\${moduleMap[name].requiredVersion})`\n )\n }\n } else {\n module = await (await versionValue.get())()\n }\n }\n if (module) {\n return flattenModule(module, name)\n }\n}\nasync function getSharedFromLocal(name) {\n if (moduleMap[name]?.import) {\n let module = await (await moduleMap[name].get())()\n return flattenModule(module, name)\n } else {\n console.error(\n `consumer config import=false,so cant use callback shared module`\n )\n }\n}\nfunction flattenModule(module, name) {\n if (module.default) module = Object.assign({}, module.default, module)\n moduleCache[name] = module\n return module\n}\nexport {\n importShared,\n getSharedFromRuntime as importSharedRuntime,\n getSharedFromLocal as importSharedLocal\n}\n"; | ||
const sharedFilePathReg = /__federation_shared_(.+)\.js$/; | ||
@@ -714,0 +707,0 @@ function prodSharedPlugin(options) { |
{ | ||
"name": "@originjs/vite-plugin-federation", | ||
"version": "1.3.1", | ||
"version": "1.3.2", | ||
"description": "A Vite plugin which support Module Federation.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
Sorry, the diff of this file is not supported yet
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
166925
4077