New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@module-federation/data-prefetch

Package Overview
Dependencies
Maintainers
0
Versions
256
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@module-federation/data-prefetch - npm Package Compare versions

Comparing version 0.0.0-next-20240909062831 to 0.0.0-next-20240909073915

dist/esm/chunk-YXTPJG2M.js

6

CHANGELOG.md
@module-federation/data-prefetch
## 0.0.0-next-20240909062831
## 0.0.0-next-20240909073915

@@ -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-20240909062831
- @module-federation/sdk@0.0.0-next-20240909062831
- @module-federation/runtime@0.0.0-next-20240909073915
- @module-federation/sdk@0.0.0-next-20240909073915
import {
prefetchPlugin
} from "./chunk-H3DTWHY4.js";
} from "./chunk-YXTPJG2M.js";
import "./chunk-TTJJJ2WZ.js";

@@ -5,0 +5,0 @@ import {

import {
plugin_default,
prefetchPlugin
} from "./chunk-H3DTWHY4.js";
} from "./chunk-YXTPJG2M.js";
import "./chunk-TTJJJ2WZ.js";

@@ -6,0 +6,0 @@ import "./chunk-57ZXBP7D.js";

@@ -237,3 +237,5 @@ "use strict";

const exports = instance.getExposeExports(id);
logger_default.info(`1. Start Prefetch: ${id} - ${performance.now()}`);
logger_default.info(
`1. Start Prefetch initContainer: ${id} - ${performance.now()}`
);
const result = Object.keys(exports).map((k) => {

@@ -259,2 +261,64 @@ const value = instance.prefetch({

},
afterResolve(options) {
const { remoteSnapshot, remoteInfo, id, origin } = options;
const snapshot = remoteSnapshot;
const { name } = remoteInfo;
const prefetchOptions = {
name,
remote: remoteInfo,
origin,
remoteSnapshot: snapshot
};
const signal = getSignalFromManifest(snapshot);
if (!signal) {
return options;
}
const inited = loadingArray.some((info) => info.id === id);
if (!inited) {
return options;
}
if (sharedFlag !== strategy) {
throw new Error(
`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`
);
}
const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);
let prefetchUrl;
if (snapshot.prefetchEntry) {
prefetchUrl = (0, import_sdk4.getResourceUrl)(snapshot, snapshot.prefetchEntry);
}
const index = loadingArray.findIndex((loading) => loading.id === id);
if (index !== -1) {
loadingArray.splice(index, 1);
}
const promise = instance.loadEntry(prefetchUrl).then(async () => {
const projectExports = instance.getProjectExports();
if (projectExports instanceof Promise) {
await projectExports;
}
return Promise.resolve().then(() => {
const exports = instance.getExposeExports(id);
logger_default.info(
`1. Start Prefetch afterResolve: ${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;
},
async onLoad(options) {

@@ -261,0 +325,0 @@ var _a2;

@@ -233,3 +233,5 @@ "use strict";

const exports = instance.getExposeExports(id);
logger_default.info(`1. Start Prefetch: ${id} - ${performance.now()}`);
logger_default.info(
`1. Start Prefetch initContainer: ${id} - ${performance.now()}`
);
const result = Object.keys(exports).map((k) => {

@@ -255,2 +257,64 @@ const value = instance.prefetch({

},
afterResolve(options) {
const { remoteSnapshot, remoteInfo, id, origin } = options;
const snapshot = remoteSnapshot;
const { name } = remoteInfo;
const prefetchOptions = {
name,
remote: remoteInfo,
origin,
remoteSnapshot: snapshot
};
const signal = getSignalFromManifest(snapshot);
if (!signal) {
return options;
}
const inited = loadingArray.some((info) => info.id === id);
if (!inited) {
return options;
}
if (sharedFlag !== strategy) {
throw new Error(
`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`
);
}
const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);
let prefetchUrl;
if (snapshot.prefetchEntry) {
prefetchUrl = (0, import_sdk4.getResourceUrl)(snapshot, snapshot.prefetchEntry);
}
const index = loadingArray.findIndex((loading) => loading.id === id);
if (index !== -1) {
loadingArray.splice(index, 1);
}
const promise = instance.loadEntry(prefetchUrl).then(async () => {
const projectExports = instance.getProjectExports();
if (projectExports instanceof Promise) {
await projectExports;
}
return Promise.resolve().then(() => {
const exports = instance.getExposeExports(id);
logger_default.info(
`1. Start Prefetch afterResolve: ${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;
},
async onLoad(options) {

@@ -257,0 +321,0 @@ var _a2;

{
"name": "@module-federation/data-prefetch",
"description": "Module Federation Data Prefetch",
"version": "0.0.0-next-20240909062831",
"version": "0.0.0-next-20240909073915",
"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-20240909062831",
"@module-federation/runtime": "0.0.0-next-20240909062831"
"@module-federation/sdk": "0.0.0-next-20240909073915",
"@module-federation/runtime": "0.0.0-next-20240909073915"
},

@@ -92,0 +92,0 @@ "scripts": {

@@ -58,3 +58,2 @@ import type { FederationRuntimePlugin } from '@module-federation/runtime/types';

}
// @ts-ignore
const promise = instance.loadEntry(prefetchUrl).then(async () => {

@@ -67,3 +66,5 @@ const projectExports = instance!.getProjectExports();

const exports = instance!.getExposeExports(id);
logger.info(`1. Start Prefetch: ${id} - ${performance.now()}`);
logger.info(
`1. Start Prefetch initContainer: ${id} - ${performance.now()}`,
);
const result = Object.keys(exports).map((k) => {

@@ -92,2 +93,76 @@ const value = instance!.prefetch({

afterResolve(options) {
const { remoteSnapshot, remoteInfo, id, origin } = options;
const snapshot = remoteSnapshot as ModuleInfo;
const { name } = remoteInfo;
const prefetchOptions = {
name,
remote: remoteInfo,
origin,
remoteSnapshot: snapshot,
};
const signal = getSignalFromManifest(snapshot);
if (!signal) {
return options;
}
const inited = loadingArray.some((info) => info.id === id);
if (!inited) {
return options;
}
if (sharedFlag !== strategy) {
throw new Error(
`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`,
);
}
const instance =
MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);
let prefetchUrl;
// @ts-expect-error
if (snapshot.prefetchEntry) {
// @ts-expect-error
prefetchUrl = getResourceUrl(snapshot, snapshot.prefetchEntry as string);
}
const index = loadingArray.findIndex((loading) => loading.id === id);
// clear cache
if (index !== -1) {
loadingArray.splice(index, 1);
}
const promise = instance.loadEntry(prefetchUrl).then(async () => {
const projectExports = instance!.getProjectExports();
if (projectExports instanceof Promise) {
await projectExports;
}
return Promise.resolve().then(() => {
const exports = instance!.getExposeExports(id);
logger.info(
`1. Start Prefetch afterResolve: ${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;
},
async onLoad(options) {

@@ -94,0 +169,0 @@ const { remote, id } = options;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc