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

@module-federation/runtime

Package Overview
Dependencies
Maintainers
8
Versions
722
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@module-federation/runtime - npm Package Compare versions

Comparing version 0.0.13 to 0.0.14

2

dist/package.json
{
"name": "@module-federation/runtime",
"version": "0.0.13",
"version": "0.0.14",
"author": "zhouxiao <codingzx@gmail.com>",

@@ -5,0 +5,0 @@ "main": "./index.cjs.js",

@@ -179,3 +179,3 @@ 'use strict';

globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.13";
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.14";
}

@@ -182,0 +182,0 @@ }

@@ -177,3 +177,3 @@ function getBuilderId() {

globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR__ = FederationConstructor;
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.13";
globalThis.__FEDERATION__.__DEBUG_CONSTRUCTOR_VERSION__ = "0.0.14";
}

@@ -180,0 +180,0 @@ }

@@ -139,2 +139,3 @@ import type { ModuleInfo, GlobalModuleInfo } from '@module-federation/sdk';

loadShareSync<T>(pkgName: string, customShareInfo?: Partial<Shared>): () => T | never;
initRawContainer(name: string, url: string, container: RemoteEntryExports): Module;
private _getRemoteModuleAndOptions;

@@ -141,0 +142,0 @@ loadRemote<T>(id: string, options?: {

@@ -5,3 +5,3 @@ import { FederationHost } from './core';

export { registerGlobalPlugins } from './global';
export { loadScript } from '@module-federation/sdk';
export { loadScript, loadScriptNode } from '@module-federation/sdk';
export type { Federation } from './global';

@@ -8,0 +8,0 @@ export type { FederationRuntimePlugin };

{
"name": "@module-federation/runtime",
"version": "0.0.13",
"version": "0.0.14",
"author": "zhouxiao <codingzx@gmail.com>",

@@ -48,4 +48,4 @@ "main": "./dist/index.cjs",

"dependencies": {
"@module-federation/sdk": "0.0.13"
"@module-federation/sdk": "0.0.14"
}
}

@@ -109,3 +109,3 @@ # `@module-federation/runtime`

alias: 'app2',
entry: "http://localhost:3006/remoteEntry.js",
entry: 'http://localhost:3006/remoteEntry.js',
},

@@ -233,9 +233,9 @@ ],

preloadRemote([
{
nameOrAlias: '@demo/sub1',
filter(assetUrl) {
return assetUrl.indexOf('ignore') === -1;
},
depsRemote: [{ nameOrAlias: '@demo/sub1-button' }],
{
nameOrAlias: '@demo/sub1',
filter(assetUrl) {
return assetUrl.indexOf('ignore') === -1;
},
depsRemote: [{ nameOrAlias: '@demo/sub1-button' }],
},
]);

@@ -247,6 +247,6 @@

preloadRemote([
{
nameOrAlias: '@demo/sub2',
resourceCategory: 'all',
},
{
nameOrAlias: '@demo/sub2',
resourceCategory: 'all',
},
]);

@@ -256,7 +256,7 @@

preloadRemote([
{
nameOrAlias: '@demo/sub3',
resourceCategory: 'all',
exposes: ['add'],
},
{
nameOrAlias: '@demo/sub3',
resourceCategory: 'all',
exposes: ['add'],
},
]);

@@ -269,48 +269,47 @@ ```

* example
- example
```ts
import { init } from '@module-federation/runtime'
import { init } from '@module-federation/runtime';
import type { FederationRuntimePlugin } from '@module-federation/runtime';
const runtimePlugin: () => FederationRuntimePlugin =
function () {
return {
name: 'my-runtime-plugin',
beforeInit(args) {
console.log('beforeInit: ', args);
return args;
},
beforeRequest(args) {
console.log('beforeRequest: ', args);
return args;
},
afterResolve(args) {
console.log('afterResolve', args);
return args;
},
onLoad(args) {
console.log('onLoad: ', args);
return args;
},
async loadShare(args) {
console.log('loadShare:', args);
},
async beforeLoadShare(args) {
console.log('beforeloadShare:', args);
return args;
},
};
const runtimePlugin: () => FederationRuntimePlugin = function () {
return {
name: 'my-runtime-plugin',
beforeInit(args) {
console.log('beforeInit: ', args);
return args;
},
beforeRequest(args) {
console.log('beforeRequest: ', args);
return args;
},
afterResolve(args) {
console.log('afterResolve', args);
return args;
},
onLoad(args) {
console.log('onLoad: ', args);
return args;
},
async loadShare(args) {
console.log('loadShare:', args);
},
async beforeLoadShare(args) {
console.log('beforeloadShare:', args);
return args;
},
};
};
init({
name: '@demo/app-main',
remotes: [
{
name: "@demo/app2",
entry: "http://localhost:3006/remoteEntry.js",
alias: "app2"
},
],
plugins: [runtimePlugin()]
name: '@demo/app-main',
remotes: [
{
name: '@demo/app2',
entry: 'http://localhost:3006/remoteEntry.js',
alias: 'app2',
},
],
plugins: [runtimePlugin()],
});

@@ -325,13 +324,13 @@ ```

* type
- type
```ts
function beforeInit(args: BeforeInitOptions): BeforeInitOptions
function beforeInit(args: BeforeInitOptions): BeforeInitOptions;
type BeforeInitOptions ={
userOptions: UserOptions;
options: FederationRuntimeOptions;
origin: FederationHost;
shareInfo: ShareInfos;
}
type BeforeInitOptions = {
userOptions: UserOptions;
options: FederationRuntimeOptions;
origin: FederationHost;
shareInfo: ShareInfos;
};

@@ -355,11 +354,11 @@ interface FederationRuntimeOptions {

* type
- type
```ts
function init(args: InitOptions): void
function init(args: InitOptions): void;
type InitOptions ={
type InitOptions = {
options: FederationRuntimeOptions;
origin: FederationHost;
}
};
```

@@ -373,12 +372,12 @@

* type
- type
```ts
async function beforeRequest(args: BeforeRequestOptions): Promise<BeforeRequestOptions>
async function beforeRequest(args: BeforeRequestOptions): Promise<BeforeRequestOptions>;
type BeforeRequestOptions ={
type BeforeRequestOptions = {
id: string;
options: FederationRuntimeOptions;
origin: FederationHost;
}
};
```

@@ -392,8 +391,8 @@

* type
- type
```ts
async function afterResolve(args: AfterResolveOptions): Promise<AfterResolveOptions>
async function afterResolve(args: AfterResolveOptions): Promise<AfterResolveOptions>;
type AfterResolveOptions ={
type AfterResolveOptions = {
id: string;

@@ -407,3 +406,3 @@ pkgNameOrAlias: string;

remoteSnapshot?: ModuleInfo;
}
};
```

@@ -417,8 +416,8 @@

* type
- type
```ts
async function onLoad(args: OnLoadOptions): Promise<void>
async function onLoad(args: OnLoadOptions): Promise<void>;
type OnLoadOptions ={
type OnLoadOptions = {
id: string;

@@ -433,8 +432,8 @@ expose: string;

moduleInstance: Module;
}
};
type ModuleOptions = {
remoteInfo: RemoteInfo;
host: FederationHost;
}
remoteInfo: RemoteInfo;
host: FederationHost;
};

@@ -458,8 +457,8 @@ interface RemoteInfo {

* type
- type
```ts
function handlePreloadModule(args: HandlePreloadModuleOptions): void
function handlePreloadModule(args: HandlePreloadModuleOptions): void;
type HandlePreloadModuleOptions ={
type HandlePreloadModuleOptions = {
id: string;

@@ -469,3 +468,3 @@ name: string;

preloadConfig: PreloadRemoteArgs;
}
};
```

@@ -479,8 +478,8 @@

* type
- type
```ts
async function errorLoadRemote(args: ErrorLoadRemoteOptions): Promise<void | unknown>
async function errorLoadRemote(args: ErrorLoadRemoteOptions): Promise<void | unknown>;
type ErrorLoadRemoteOptions ={
type ErrorLoadRemoteOptions = {
id: string;

@@ -490,38 +489,37 @@ error: unknown;

origin: FederationHost;
}
};
```
* example
- example
```ts
import { init, loadRemote } from '@module-federation/runtime'
import { init, loadRemote } from '@module-federation/runtime';
import type { FederationRuntimePlugin } from '@module-federation/runtime';
const fallbackPlugin: () => FederationRuntimePlugin =
function () {
return {
name: 'fallback-plugin',
errorLoadRemote(args) {
const fallback = 'fallback'
return fallback;
},
};
const fallbackPlugin: () => FederationRuntimePlugin = function () {
return {
name: 'fallback-plugin',
errorLoadRemote(args) {
const fallback = 'fallback';
return fallback;
},
};
};
init({
name: '@demo/app-main',
remotes: [
{
name: "@demo/app2",
entry: "http://localhost:3006/remoteEntry.js",
alias: "app2"
},
],
plugins: [fallbackPlugin()]
name: '@demo/app-main',
remotes: [
{
name: '@demo/app2',
entry: 'http://localhost:3006/remoteEntry.js',
alias: 'app2',
},
],
plugins: [fallbackPlugin()],
});
loadRemote('app2/un-existed-module').then(mod=>{
loadRemote('app2/un-existed-module').then((mod) => {
expect(mod).toEqual('fallback');
})
});
```

@@ -535,8 +533,8 @@

* type
- type
```ts
async function beforeLoadShare(args: BeforeLoadShareOptions): Promise<BeforeLoadShareOptions>
async function beforeLoadShare(args: BeforeLoadShareOptions): Promise<BeforeLoadShareOptions>;
type BeforeLoadShareOptions ={
type BeforeLoadShareOptions = {
pkgName: string;

@@ -546,3 +544,3 @@ shareInfo?: Shared;

origin: FederationHost;
}
};
```

@@ -556,8 +554,8 @@

* type
- type
```ts
function resolveShare(args: ResolveShareOptions): ResolveShareOptions
function resolveShare(args: ResolveShareOptions): ResolveShareOptions;
type ResolveShareOptions ={
type ResolveShareOptions = {
shareScopeMap: ShareScopeMap;

@@ -569,54 +567,50 @@ scope: string;

resolver: () => Shared | undefined;
}
};
```
* example
- example
```ts
import { init, loadRemote } from '@module-federation/runtime'
import { init, loadRemote } from '@module-federation/runtime';
import type { FederationRuntimePlugin } from '@module-federation/runtime';
const customSharedPlugin: () => FederationRuntimePlugin =
function () {
return {
name: 'custom-shared-plugin',
resolveShare(args) {
const { shareScopeMap, scope, pkgName, version, GlobalFederation } = args;
const customSharedPlugin: () => FederationRuntimePlugin = function () {
return {
name: 'custom-shared-plugin',
resolveShare(args) {
const { shareScopeMap, scope, pkgName, version, GlobalFederation } = args;
if (
pkgName !== 'react'
) {
return args;
}
if (pkgName !== 'react') {
return args;
}
args.resolver = function () {
shareScopeMap[scope][pkgName][version] = window.React; // replace local share scope manually with desired module
return shareScopeMap[scope][pkgName][version];
};
return args;
},
};
args.resolver = function () {
shareScopeMap[scope][pkgName][version] = window.React; // replace local share scope manually with desired module
return shareScopeMap[scope][pkgName][version];
};
return args;
},
};
};
init({
name: '@demo/app-main',
shared: {
react: {
version: '17.0.0',
scope: 'default',
lib: () => React,
shareConfig: {
singleton: true,
requiredVersion: '^17.0.0',
},
name: '@demo/app-main',
shared: {
react: {
version: '17.0.0',
scope: 'default',
lib: () => React,
shareConfig: {
singleton: true,
requiredVersion: '^17.0.0',
},
},
plugins: [customSharedPlugin()]
},
plugins: [customSharedPlugin()],
});
window.React = ()=> 'Desired Shared';
window.React = () => 'Desired Shared';
loadShare("react").then((reactFactory)=>{
loadShare('react').then((reactFactory) => {
expect(reactFactory()).toEqual(window.React());

@@ -632,12 +626,12 @@ });

* type
- type
```ts
async function beforePreloadRemote(args: BeforePreloadRemoteOptions): BeforePreloadRemoteOptions
async function beforePreloadRemote(args: BeforePreloadRemoteOptions): BeforePreloadRemoteOptions;
type BeforePreloadRemoteOptions ={
type BeforePreloadRemoteOptions = {
preloadOps: Array<PreloadRemoteArgs>;
options: Options;
origin: FederationHost;
}
};
```

@@ -651,8 +645,8 @@

* type
- type
```ts
async function generatePreloadAssets(args: GeneratePreloadAssetsOptions): Promise<PreloadAssets>
async function generatePreloadAssets(args: GeneratePreloadAssetsOptions): Promise<PreloadAssets>;
type GeneratePreloadAssetsOptions ={
type GeneratePreloadAssetsOptions = {
origin: FederationHost;

@@ -664,3 +658,3 @@ preloadOptions: PreloadOptions[number];

globalSnapshot: GlobalModuleInfo;
}
};

@@ -682,33 +676,32 @@ interface PreloadAssets {

* type
- type
```ts
function createScript(args: CreateScriptOptions): HTMLScriptElement | void
function createScript(args: CreateScriptOptions): HTMLScriptElement | void;
type CreateScriptOptions ={
type CreateScriptOptions = {
url: string;
}
};
```
* example
- example
```ts
import { init } from '@module-federation/runtime'
import { init } from '@module-federation/runtime';
import type { FederationRuntimePlugin } from '@module-federation/runtime';
const changeScriptAttributePlugin: () => FederationRuntimePlugin =
function () {
return {
name: 'change-script-attribute',
createScript({ url }) {
if (url === testRemoteEntry) {
let script = document.createElement('script');
script.src = testRemoteEntry;
script.setAttribute('loader-hooks', 'isTrue');
script.setAttribute('crossorigin', 'anonymous');
return script;
}
const changeScriptAttributePlugin: () => FederationRuntimePlugin = function () {
return {
name: 'change-script-attribute',
createScript({ url }) {
if (url === testRemoteEntry) {
let script = document.createElement('script');
script.src = testRemoteEntry;
script.setAttribute('loader-hooks', 'isTrue');
script.setAttribute('crossorigin', 'anonymous');
return script;
}
};
},
};
};
```

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

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