@module-federation/data-prefetch
Advanced tools
Comparing version 0.0.0-next-20240808065005 to 0.0.0-next-20240808083234
@module-federation/data-prefetch | ||
## 0.0.0-next-20240808065005 | ||
## 0.0.0-next-20240808083234 | ||
@@ -8,3 +8,3 @@ ### Patch Changes | ||
- 3ddab21: feat(@module-federation/data-prefetch): support data prefetch in Module Federation | ||
- @module-federation/runtime@0.0.0-next-20240808065005 | ||
- @module-federation/sdk@0.0.0-next-20240808065005 | ||
- @module-federation/runtime@0.0.0-next-20240808083234 | ||
- @module-federation/sdk@0.0.0-next-20240808083234 |
import { | ||
getPrefetchId | ||
} from "../chunk-EWCGK4XA.js"; | ||
} from "../chunk-VWDP6NMM.js"; | ||
@@ -5,0 +5,0 @@ // src/cli/index.ts |
import { | ||
prefetchPlugin | ||
} from "./chunk-WLE6YNDH.js"; | ||
} from "./chunk-TW3B6M25.js"; | ||
import "./chunk-TTJJJ2WZ.js"; | ||
import { | ||
MFDataPrefetch | ||
} from "./chunk-JEPJP5O3.js"; | ||
import "./chunk-EWCGK4XA.js"; | ||
} from "./chunk-XYNYYK45.js"; | ||
import "./chunk-VWDP6NMM.js"; | ||
export { | ||
@@ -10,0 +10,0 @@ MFDataPrefetch, |
import { | ||
plugin_default, | ||
prefetchPlugin | ||
} from "./chunk-WLE6YNDH.js"; | ||
} from "./chunk-TW3B6M25.js"; | ||
import "./chunk-TTJJJ2WZ.js"; | ||
import "./chunk-JEPJP5O3.js"; | ||
import "./chunk-EWCGK4XA.js"; | ||
import "./chunk-XYNYYK45.js"; | ||
import "./chunk-VWDP6NMM.js"; | ||
export { | ||
@@ -9,0 +9,0 @@ plugin_default as default, |
import { | ||
prefetch | ||
} from "../chunk-QHQN3BPZ.js"; | ||
} from "../chunk-V2LJYA45.js"; | ||
import { | ||
@@ -9,6 +9,6 @@ logger_default | ||
MFDataPrefetch | ||
} from "../chunk-JEPJP5O3.js"; | ||
} from "../chunk-XYNYYK45.js"; | ||
import { | ||
getScope | ||
} from "../chunk-EWCGK4XA.js"; | ||
} from "../chunk-VWDP6NMM.js"; | ||
@@ -15,0 +15,0 @@ // src/react/hooks.ts |
import { | ||
prefetch | ||
} from "../chunk-QHQN3BPZ.js"; | ||
import "../chunk-JEPJP5O3.js"; | ||
import "../chunk-EWCGK4XA.js"; | ||
} from "../chunk-V2LJYA45.js"; | ||
import "../chunk-XYNYYK45.js"; | ||
import "../chunk-VWDP6NMM.js"; | ||
export { | ||
prefetch | ||
}; |
@@ -35,2 +35,3 @@ "use strict"; | ||
var getPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/${import_sdk.MFPrefetchCommon.identifier}`); | ||
var compatGetPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/VmokPrefetch`); | ||
var getSignalFromManifest = (remoteSnapshot) => { | ||
@@ -131,3 +132,4 @@ if (!remoteSnapshot) { | ||
const prefetchId = getPrefetchId(id); | ||
const prefetchExports = this._exports[prefetchId]; | ||
const compatId = compatGetPrefetchId(id); | ||
const prefetchExports = this._exports[prefetchId] || this._exports[compatId]; | ||
return prefetchExports || {}; | ||
@@ -139,2 +141,3 @@ } | ||
const prefetchId = getPrefetchId(id); | ||
const compatId = compatGetPrefetchId(id); | ||
const memorizeId = id + functionId; | ||
@@ -145,3 +148,3 @@ const memory = this.prefetchMemory.get(memorizeId); | ||
} | ||
const prefetchExports = this._exports[prefetchId]; | ||
const prefetchExports = this._exports[prefetchId] || this._exports[compatId]; | ||
if (!prefetchExports) { | ||
@@ -199,3 +202,2 @@ return; | ||
// src/plugin.ts | ||
var import_runtime2 = require("@module-federation/runtime"); | ||
var import_sdk4 = require("@module-federation/sdk"); | ||
@@ -286,67 +288,2 @@ | ||
}, | ||
handlePreloadModule(options) { | ||
const { remoteSnapshot, name, id, preloadConfig, origin, remote } = options; | ||
const snapshot = remoteSnapshot; | ||
const signal = getSignalFromManifest(snapshot); | ||
if (!signal) { | ||
return options; | ||
} | ||
const prefetchOptions = { | ||
name, | ||
origin, | ||
remote, | ||
remoteSnapshot: snapshot | ||
}; | ||
const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions); | ||
let prefetchUrl; | ||
if (snapshot.prefetchEntry) { | ||
prefetchUrl = (0, import_sdk4.getResourceUrl)(snapshot, snapshot.prefetchEntry); | ||
} | ||
if (!preloadConfig.prefetchInterface) { | ||
instance.loadEntry(prefetchUrl); | ||
return options; | ||
} | ||
const promise = instance.loadEntry(prefetchUrl).then(async () => { | ||
let module2 = origin.moduleCache.get(remote.name); | ||
const moduleOptions = { | ||
host: origin, | ||
remoteInfo: remote | ||
}; | ||
if (!module2) { | ||
module2 = new import_runtime2.Module(moduleOptions); | ||
origin.moduleCache.set(remote.name, module2); | ||
} | ||
const idPart = id.split("/"); | ||
let expose = idPart[idPart.length - 1]; | ||
if (expose !== ".") { | ||
expose = `./${expose}`; | ||
} | ||
await module2.get(id, expose, {}, remoteSnapshot); | ||
const projectExports = instance.getProjectExports(); | ||
if (projectExports instanceof Promise) { | ||
await projectExports; | ||
} | ||
const exports = instance.getExposeExports(id); | ||
logger_default.info( | ||
`1. PreloadRemote Start Prefetch: ${id} - ${performance.now()}` | ||
); | ||
const result = Object.keys(exports).map((k) => { | ||
const value = instance.prefetch({ | ||
id, | ||
functionId: k | ||
}); | ||
const functionId = k; | ||
return { | ||
value, | ||
functionId | ||
}; | ||
}); | ||
return result; | ||
}); | ||
loadingArray.push({ | ||
id, | ||
promise | ||
}); | ||
return options; | ||
}, | ||
beforeLoadShare(options) { | ||
@@ -353,0 +290,0 @@ const shareInfo = options.shareInfo; |
@@ -27,3 +27,2 @@ "use strict"; | ||
module.exports = __toCommonJS(plugin_exports); | ||
var import_runtime2 = require("@module-federation/runtime"); | ||
var import_sdk4 = require("@module-federation/sdk"); | ||
@@ -34,2 +33,3 @@ | ||
var getPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/${import_sdk.MFPrefetchCommon.identifier}`); | ||
var compatGetPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/VmokPrefetch`); | ||
var getSignalFromManifest = (remoteSnapshot) => { | ||
@@ -132,3 +132,4 @@ if (!remoteSnapshot) { | ||
const prefetchId = getPrefetchId(id); | ||
const prefetchExports = this._exports[prefetchId]; | ||
const compatId = compatGetPrefetchId(id); | ||
const prefetchExports = this._exports[prefetchId] || this._exports[compatId]; | ||
return prefetchExports || {}; | ||
@@ -140,2 +141,3 @@ } | ||
const prefetchId = getPrefetchId(id); | ||
const compatId = compatGetPrefetchId(id); | ||
const memorizeId = id + functionId; | ||
@@ -146,3 +148,3 @@ const memory = this.prefetchMemory.get(memorizeId); | ||
} | ||
const prefetchExports = this._exports[prefetchId]; | ||
const prefetchExports = this._exports[prefetchId] || this._exports[compatId]; | ||
if (!prefetchExports) { | ||
@@ -282,67 +284,2 @@ return; | ||
}, | ||
handlePreloadModule(options) { | ||
const { remoteSnapshot, name, id, preloadConfig, origin, remote } = options; | ||
const snapshot = remoteSnapshot; | ||
const signal = getSignalFromManifest(snapshot); | ||
if (!signal) { | ||
return options; | ||
} | ||
const prefetchOptions = { | ||
name, | ||
origin, | ||
remote, | ||
remoteSnapshot: snapshot | ||
}; | ||
const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions); | ||
let prefetchUrl; | ||
if (snapshot.prefetchEntry) { | ||
prefetchUrl = (0, import_sdk4.getResourceUrl)(snapshot, snapshot.prefetchEntry); | ||
} | ||
if (!preloadConfig.prefetchInterface) { | ||
instance.loadEntry(prefetchUrl); | ||
return options; | ||
} | ||
const promise = instance.loadEntry(prefetchUrl).then(async () => { | ||
let module2 = origin.moduleCache.get(remote.name); | ||
const moduleOptions = { | ||
host: origin, | ||
remoteInfo: remote | ||
}; | ||
if (!module2) { | ||
module2 = new import_runtime2.Module(moduleOptions); | ||
origin.moduleCache.set(remote.name, module2); | ||
} | ||
const idPart = id.split("/"); | ||
let expose = idPart[idPart.length - 1]; | ||
if (expose !== ".") { | ||
expose = `./${expose}`; | ||
} | ||
await module2.get(id, expose, {}, remoteSnapshot); | ||
const projectExports = instance.getProjectExports(); | ||
if (projectExports instanceof Promise) { | ||
await projectExports; | ||
} | ||
const exports = instance.getExposeExports(id); | ||
logger_default.info( | ||
`1. PreloadRemote Start Prefetch: ${id} - ${performance.now()}` | ||
); | ||
const result = Object.keys(exports).map((k) => { | ||
const value = instance.prefetch({ | ||
id, | ||
functionId: k | ||
}); | ||
const functionId = k; | ||
return { | ||
value, | ||
functionId | ||
}; | ||
}); | ||
return result; | ||
}); | ||
loadingArray.push({ | ||
id, | ||
promise | ||
}); | ||
return options; | ||
}, | ||
beforeLoadShare(options) { | ||
@@ -349,0 +286,0 @@ const shareInfo = options.shareInfo; |
@@ -49,2 +49,3 @@ "use strict"; | ||
var getPrefetchId = (id) => (0, import_sdk2.encodeName)(`${id}/${import_sdk2.MFPrefetchCommon.identifier}`); | ||
var compatGetPrefetchId = (id) => (0, import_sdk2.encodeName)(`${id}/VmokPrefetch`); | ||
@@ -133,3 +134,4 @@ // src/prefetch.ts | ||
const prefetchId = getPrefetchId(id); | ||
const prefetchExports = this._exports[prefetchId]; | ||
const compatId = compatGetPrefetchId(id); | ||
const prefetchExports = this._exports[prefetchId] || this._exports[compatId]; | ||
return prefetchExports || {}; | ||
@@ -141,2 +143,3 @@ } | ||
const prefetchId = getPrefetchId(id); | ||
const compatId = compatGetPrefetchId(id); | ||
const memorizeId = id + functionId; | ||
@@ -147,3 +150,3 @@ const memory = this.prefetchMemory.get(memorizeId); | ||
} | ||
const prefetchExports = this._exports[prefetchId]; | ||
const prefetchExports = this._exports[prefetchId] || this._exports[compatId]; | ||
if (!prefetchExports) { | ||
@@ -150,0 +153,0 @@ return; |
@@ -42,2 +42,3 @@ "use strict"; | ||
var getPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/${import_sdk.MFPrefetchCommon.identifier}`); | ||
var compatGetPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/VmokPrefetch`); | ||
@@ -126,3 +127,4 @@ // src/prefetch.ts | ||
const prefetchId = getPrefetchId(id); | ||
const prefetchExports = this._exports[prefetchId]; | ||
const compatId = compatGetPrefetchId(id); | ||
const prefetchExports = this._exports[prefetchId] || this._exports[compatId]; | ||
return prefetchExports || {}; | ||
@@ -134,2 +136,3 @@ } | ||
const prefetchId = getPrefetchId(id); | ||
const compatId = compatGetPrefetchId(id); | ||
const memorizeId = id + functionId; | ||
@@ -140,3 +143,3 @@ const memory = this.prefetchMemory.get(memorizeId); | ||
} | ||
const prefetchExports = this._exports[prefetchId]; | ||
const prefetchExports = this._exports[prefetchId] || this._exports[compatId]; | ||
if (!prefetchExports) { | ||
@@ -143,0 +146,0 @@ return; |
{ | ||
"name": "@module-federation/data-prefetch", | ||
"description": "Module Federation Data Prefetch", | ||
"version": "0.0.0-next-20240808065005", | ||
"version": "0.0.0-next-20240808083234", | ||
"author": "nieyan <nyqykk@foxmail.com>", | ||
@@ -88,4 +88,4 @@ "homepage": "https://github.com/module-federation/core", | ||
"fs-extra": "9.1.0", | ||
"@module-federation/sdk": "0.0.0-next-20240808065005", | ||
"@module-federation/runtime": "0.0.0-next-20240808065005" | ||
"@module-federation/sdk": "0.0.0-next-20240808083234", | ||
"@module-federation/runtime": "0.0.0-next-20240808083234" | ||
}, | ||
@@ -92,0 +92,0 @@ "scripts": { |
@@ -19,2 +19,5 @@ import { | ||
export const compatGetPrefetchId = (id: string): string => | ||
encodeName(`${id}/VmokPrefetch`); | ||
export const getSignalFromManifest = (remoteSnapshot: ModuleInfo): boolean => { | ||
@@ -21,0 +24,0 @@ if (!remoteSnapshot) { |
@@ -1,6 +0,2 @@ | ||
import { Module } from '@module-federation/runtime'; | ||
import type { | ||
FederationRuntimePlugin, | ||
RemoteInfo, | ||
} from '@module-federation/runtime/types'; | ||
import type { FederationRuntimePlugin } from '@module-federation/runtime/types'; | ||
import { ModuleInfo, getResourceUrl } from '@module-federation/sdk'; | ||
@@ -12,14 +8,2 @@ | ||
type depsPreloadArg = Omit<PreloadRemoteArgs, 'depsRemote'>; | ||
interface PreloadRemoteArgs { | ||
nameOrAlias: string; | ||
exposes?: Array<string>; | ||
resourceCategory?: 'all' | 'sync'; | ||
share?: boolean; | ||
depsRemote?: boolean | Array<depsPreloadArg>; | ||
filter?: (assetUrl: string) => boolean; | ||
prefetchInterface?: boolean; | ||
} | ||
interface Loading { | ||
@@ -126,80 +110,2 @@ id: string; | ||
handlePreloadModule(options) { | ||
const { remoteSnapshot, name, id, preloadConfig, origin, remote } = options; | ||
const snapshot = remoteSnapshot as ModuleInfo; | ||
const signal = getSignalFromManifest(snapshot); | ||
if (!signal) { | ||
return options; | ||
} | ||
const prefetchOptions = { | ||
name, | ||
origin, | ||
remote, | ||
remoteSnapshot: snapshot, | ||
}; | ||
const instance = | ||
MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions); | ||
let prefetchUrl; | ||
// @ts-expect-error | ||
if (snapshot.prefetchEntry) { | ||
// @ts-expect-error | ||
prefetchUrl = getResourceUrl(snapshot, snapshot.prefetchEntry); | ||
} | ||
if (!preloadConfig.prefetchInterface) { | ||
// @ts-ignore | ||
instance.loadEntry(prefetchUrl); | ||
return options; | ||
} | ||
const promise = instance.loadEntry(prefetchUrl).then(async () => { | ||
let module = origin.moduleCache.get(remote.name); | ||
const moduleOptions = { | ||
host: origin, | ||
remoteInfo: remote as RemoteInfo, | ||
}; | ||
if (!module) { | ||
module = new Module(moduleOptions); | ||
origin.moduleCache.set(remote.name, module); | ||
} | ||
const idPart = id.split('/'); | ||
let expose = idPart[idPart.length - 1]; | ||
if (expose !== '.') { | ||
expose = `./${expose}`; | ||
} | ||
await module.get(id, expose, {}, remoteSnapshot); | ||
const projectExports = instance!.getProjectExports(); | ||
if (projectExports instanceof Promise) { | ||
await projectExports; | ||
} | ||
const exports = instance!.getExposeExports(id); | ||
logger.info( | ||
`1. PreloadRemote Start Prefetch: ${id} - ${performance.now()}`, | ||
); | ||
const result = Object.keys(exports).map((k) => { | ||
const value = instance!.prefetch({ | ||
id, | ||
functionId: k, | ||
}); | ||
const functionId = k; | ||
return { | ||
value, | ||
functionId, | ||
}; | ||
}); | ||
return result; | ||
}); | ||
loadingArray.push({ | ||
id, | ||
promise, | ||
}); | ||
return options; | ||
}, | ||
beforeLoadShare(options) { | ||
@@ -206,0 +112,0 @@ const shareInfo = options.shareInfo; |
@@ -13,3 +13,3 @@ import { | ||
import { getPrefetchId } from './common/runtime-utils'; | ||
import { getPrefetchId, compatGetPrefetchId } from './common/runtime-utils'; | ||
@@ -141,3 +141,5 @@ declare module '@module-federation/runtime' { | ||
const prefetchId = getPrefetchId(id); | ||
const prefetchExports = this._exports[prefetchId] as PrefetchExports; | ||
const compatId = compatGetPrefetchId(id); | ||
const prefetchExports = | ||
this._exports[prefetchId] || (this._exports[compatId] as PrefetchExports); | ||
return prefetchExports || {}; | ||
@@ -150,2 +152,3 @@ } | ||
const prefetchId = getPrefetchId(id); | ||
const compatId = compatGetPrefetchId(id); | ||
const memorizeId = id + functionId; | ||
@@ -157,3 +160,4 @@ const memory = this.prefetchMemory.get(memorizeId); | ||
const prefetchExports = this._exports[prefetchId] as PrefetchExports; | ||
const prefetchExports = | ||
this._exports[prefetchId] || (this._exports[compatId] as PrefetchExports); | ||
if (!prefetchExports) { | ||
@@ -160,0 +164,0 @@ return; |
107203
3168
+ Added@module-federation/runtime@0.0.0-next-20240808083234(transitive)
+ Added@module-federation/sdk@0.0.0-next-20240808083234(transitive)
- Removed@module-federation/runtime@0.0.0-next-20240808065005(transitive)
- Removed@module-federation/sdk@0.0.0-next-20240808065005(transitive)