@module-federation/data-prefetch 2.0.1 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/babel.d.cts +1 -0
- package/dist/cli/babel.d.cts +37 -0
- package/dist/cli/index.cjs +7 -1
- package/dist/cli/index.d.cts +16 -0
- package/dist/cli/index.js +7 -1
- package/dist/cli.d.cts +1 -0
- package/dist/common/constant.d.cts +1 -0
- package/dist/common/index.d.cts +1 -0
- package/dist/common/node-utils.d.cts +2 -0
- package/dist/common/runtime-utils.d.cts +5 -0
- package/dist/constant.d.cts +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/logger/index.d.cts +2 -0
- package/dist/plugin.d.cts +3 -0
- package/dist/prefetch.d.cts +42 -0
- package/dist/react/hooks.d.cts +11 -0
- package/dist/react/index.d.cts +1 -0
- package/dist/react/utils.d.cts +1 -0
- package/dist/react.d.cts +1 -0
- package/dist/universal/index.d.cts +2 -0
- package/dist/universal.d.cts +1 -0
- package/package.json +13 -9
package/dist/babel.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './cli/babel';
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { moduleFederationPlugin } from '@module-federation/sdk';
|
|
2
|
+
interface BabelPluginOptions {
|
|
3
|
+
hook_id: string;
|
|
4
|
+
import_pkg: string;
|
|
5
|
+
attribute: string;
|
|
6
|
+
name: string;
|
|
7
|
+
exposes: moduleFederationPlugin.ModuleFederationPluginOptions['exposes'];
|
|
8
|
+
}
|
|
9
|
+
declare const _default: (babel: {
|
|
10
|
+
types: any;
|
|
11
|
+
}, options: BabelPluginOptions) => {
|
|
12
|
+
visitor?: undefined;
|
|
13
|
+
} | {
|
|
14
|
+
visitor: {
|
|
15
|
+
ImportDeclaration(nodePath: {
|
|
16
|
+
node: {
|
|
17
|
+
source: {
|
|
18
|
+
value: any;
|
|
19
|
+
};
|
|
20
|
+
specifiers: any;
|
|
21
|
+
};
|
|
22
|
+
}, state: {
|
|
23
|
+
file: {
|
|
24
|
+
opts: {
|
|
25
|
+
filename: any;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
}): void;
|
|
29
|
+
CallExpression(nodePath: {
|
|
30
|
+
node: {
|
|
31
|
+
callee: any;
|
|
32
|
+
arguments: string | any[];
|
|
33
|
+
};
|
|
34
|
+
}): void;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
export default _default;
|
package/dist/cli/index.cjs
CHANGED
|
@@ -84,6 +84,7 @@ const external_constant_cjs_namespaceObject = require("../constant.cjs");
|
|
|
84
84
|
|
|
85
85
|
|
|
86
86
|
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
87
88
|
const { RuntimeGlobals, Template } = require((0,normalize_webpack_path_namespaceObject.normalizeWebpackPath)('webpack'));
|
|
88
89
|
const createBundlerLogger = typeof sdk_namespaceObject.createInfrastructureLogger === 'function' ? sdk_namespaceObject.createInfrastructureLogger : sdk_namespaceObject.createLogger;
|
|
89
90
|
const logger = createBundlerLogger('[ Module Federation Data Prefetch Plugin ]');
|
|
@@ -106,7 +107,11 @@ class PrefetchPlugin {
|
|
|
106
107
|
if (!Array.isArray(runtimePlugins)) {
|
|
107
108
|
this.options.runtimePlugins = [];
|
|
108
109
|
}
|
|
109
|
-
const
|
|
110
|
+
const runtimePluginFile = process.env.IS_ESM_BUILD === 'true' ? '../plugin.js' : '../plugin.cjs';
|
|
111
|
+
const runtimePath = external_path_default().resolve(__dirname, runtimePluginFile);
|
|
112
|
+
if (!external_fs_extra_default().existsSync(runtimePath)) {
|
|
113
|
+
throw new Error(`[Module Federation Data Prefetch]: Unable to resolve runtime plugin file at ${runtimePath}.`);
|
|
114
|
+
}
|
|
110
115
|
if (!((_this_options_runtimePlugins = this.options.runtimePlugins) === null || _this_options_runtimePlugins === void 0 ? void 0 : _this_options_runtimePlugins.includes(runtimePath))) {
|
|
111
116
|
this.options.runtimePlugins.push(runtimePath);
|
|
112
117
|
}
|
|
@@ -119,6 +124,7 @@ class PrefetchPlugin {
|
|
|
119
124
|
if (external_fs_extra_default().existsSync(asyncEntryPath)) {
|
|
120
125
|
external_fs_extra_default().unlinkSync(asyncEntryPath);
|
|
121
126
|
}
|
|
127
|
+
// @ts-ignore
|
|
122
128
|
if (!this.options.dataPrefetch) {
|
|
123
129
|
return;
|
|
124
130
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { moduleFederationPlugin } from '@module-federation/sdk';
|
|
2
|
+
import type { Compiler, WebpackPluginInstance } from 'webpack';
|
|
3
|
+
declare const RuntimeGlobals: typeof import("webpack").RuntimeGlobals;
|
|
4
|
+
export declare function getFederationGlobalScope(runtimeGlobals: typeof RuntimeGlobals): string;
|
|
5
|
+
export declare class PrefetchPlugin implements WebpackPluginInstance {
|
|
6
|
+
options: moduleFederationPlugin.ModuleFederationPluginOptions;
|
|
7
|
+
private _reWriteExports;
|
|
8
|
+
constructor(options: moduleFederationPlugin.ModuleFederationPluginOptions);
|
|
9
|
+
apply(compiler: Compiler): void;
|
|
10
|
+
static addRuntime(compiler: Compiler, options: {
|
|
11
|
+
name: string;
|
|
12
|
+
}): string;
|
|
13
|
+
static setRemoteIdentifier(): string;
|
|
14
|
+
static removeRemoteIdentifier(): string;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
package/dist/cli/index.js
CHANGED
|
@@ -32,6 +32,7 @@ import { SHARED_STRATEGY } from "../constant.js";
|
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
|
|
35
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
35
36
|
const { RuntimeGlobals, Template } = require(normalizeWebpackPath('webpack'));
|
|
36
37
|
const createBundlerLogger = typeof createInfrastructureLogger === 'function' ? createInfrastructureLogger : createLogger;
|
|
37
38
|
const logger = createBundlerLogger('[ Module Federation Data Prefetch Plugin ]');
|
|
@@ -54,7 +55,11 @@ class PrefetchPlugin {
|
|
|
54
55
|
if (!Array.isArray(runtimePlugins)) {
|
|
55
56
|
this.options.runtimePlugins = [];
|
|
56
57
|
}
|
|
57
|
-
const
|
|
58
|
+
const runtimePluginFile = process.env.IS_ESM_BUILD === 'true' ? '../plugin.js' : '../plugin.cjs';
|
|
59
|
+
const runtimePath = path.resolve(__dirname, runtimePluginFile);
|
|
60
|
+
if (!fs_extra.existsSync(runtimePath)) {
|
|
61
|
+
throw new Error(`[Module Federation Data Prefetch]: Unable to resolve runtime plugin file at ${runtimePath}.`);
|
|
62
|
+
}
|
|
58
63
|
if (!((_this_options_runtimePlugins = this.options.runtimePlugins) === null || _this_options_runtimePlugins === void 0 ? void 0 : _this_options_runtimePlugins.includes(runtimePath))) {
|
|
59
64
|
this.options.runtimePlugins.push(runtimePath);
|
|
60
65
|
}
|
|
@@ -67,6 +72,7 @@ class PrefetchPlugin {
|
|
|
67
72
|
if (fs_extra.existsSync(asyncEntryPath)) {
|
|
68
73
|
fs_extra.unlinkSync(asyncEntryPath);
|
|
69
74
|
}
|
|
75
|
+
// @ts-ignore
|
|
70
76
|
if (!this.options.dataPrefetch) {
|
|
71
77
|
return;
|
|
72
78
|
}
|
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './cli/index';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const TEMP_DIR = ".mf";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './constant';
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { ModuleInfo } from '@module-federation/sdk';
|
|
2
|
+
export declare const getScope: () => string;
|
|
3
|
+
export declare const getPrefetchId: (id: string) => string;
|
|
4
|
+
export declare const compatGetPrefetchId: (id: string) => string;
|
|
5
|
+
export declare const getSignalFromManifest: (remoteSnapshot: ModuleInfo) => boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SHARED_STRATEGY = "loaded-first";
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { ModuleFederation } from '@module-federation/runtime';
|
|
2
|
+
import { ModuleInfo } from '@module-federation/sdk';
|
|
3
|
+
import { Remote } from '@module-federation/runtime/types';
|
|
4
|
+
import type { Federation } from '@module-federation/runtime';
|
|
5
|
+
interface FederationWithPrefetch extends Federation {
|
|
6
|
+
__PREFETCH__: {
|
|
7
|
+
entryLoading: Record<string, undefined | Promise<void>>;
|
|
8
|
+
instance: Map<string, MFDataPrefetch>;
|
|
9
|
+
__PREFETCH_EXPORTS__: Record<string, () => Promise<Record<string, any>>>;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
type PrefetchExports = Record<string, any>;
|
|
13
|
+
export interface DataPrefetchOptions {
|
|
14
|
+
name: string;
|
|
15
|
+
remote?: Remote;
|
|
16
|
+
origin?: ModuleFederation;
|
|
17
|
+
remoteSnapshot?: ModuleInfo;
|
|
18
|
+
}
|
|
19
|
+
export interface prefetchOptions {
|
|
20
|
+
id: string;
|
|
21
|
+
functionId?: string;
|
|
22
|
+
cacheStrategy?: () => boolean;
|
|
23
|
+
refetchParams?: any;
|
|
24
|
+
}
|
|
25
|
+
export declare class MFDataPrefetch {
|
|
26
|
+
prefetchMemory: Map<string, Promise<any>>;
|
|
27
|
+
recordOutdate: Record<string, Record<string, boolean>>;
|
|
28
|
+
private _exports;
|
|
29
|
+
private _options;
|
|
30
|
+
constructor(options: DataPrefetchOptions);
|
|
31
|
+
get global(): FederationWithPrefetch['__PREFETCH__'];
|
|
32
|
+
static getInstance(id: string): MFDataPrefetch | undefined;
|
|
33
|
+
loadEntry(entry: string | undefined): Promise<any>;
|
|
34
|
+
getProjectExports(): Promise<void> | Record<string, any>;
|
|
35
|
+
memorizeExports(exports: Record<string, any>): void;
|
|
36
|
+
getExposeExports(id: string): PrefetchExports;
|
|
37
|
+
prefetch(prefetchOptions: prefetchOptions): any;
|
|
38
|
+
memorize(id: string, value: any): void;
|
|
39
|
+
markOutdate(markOptions: Omit<prefetchOptions, 'cacheStrategy'>, isOutdate: boolean): void;
|
|
40
|
+
checkOutdate(outdateOptions: prefetchOptions): boolean;
|
|
41
|
+
}
|
|
42
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type prefetchOptions } from '../prefetch';
|
|
2
|
+
type refetchParams = any;
|
|
3
|
+
type prefetchReturnType<T> = [
|
|
4
|
+
Promise<T>,
|
|
5
|
+
(refetchParams?: refetchParams) => void
|
|
6
|
+
];
|
|
7
|
+
type UsePrefetchOptions = prefetchOptions & {
|
|
8
|
+
deferId?: string;
|
|
9
|
+
};
|
|
10
|
+
export declare const usePrefetch: <T>(options: UsePrefetchOptions) => prefetchReturnType<T>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './hooks';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useFirstMounted: () => boolean;
|
package/dist/react.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './react/index';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './universal/index';
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/data-prefetch",
|
|
3
3
|
"description": "Module Federation Data Prefetch",
|
|
4
|
-
"version": "2.0
|
|
4
|
+
"version": "2.2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"author": "nieyan <nyqykk@foxmail.com>",
|
|
7
7
|
"homepage": "https://github.com/module-federation/core",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"default": "./dist/index.js"
|
|
27
27
|
},
|
|
28
28
|
"require": {
|
|
29
|
-
"types": "./dist/index.d.
|
|
29
|
+
"types": "./dist/index.d.cts",
|
|
30
30
|
"default": "./dist/index.cjs"
|
|
31
31
|
}
|
|
32
32
|
},
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"default": "./dist/react.js"
|
|
37
37
|
},
|
|
38
38
|
"require": {
|
|
39
|
-
"types": "./dist/react.d.
|
|
39
|
+
"types": "./dist/react.d.cts",
|
|
40
40
|
"default": "./dist/react.cjs"
|
|
41
41
|
}
|
|
42
42
|
},
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"default": "./dist/cli.js"
|
|
47
47
|
},
|
|
48
48
|
"require": {
|
|
49
|
-
"types": "./dist/cli.d.
|
|
49
|
+
"types": "./dist/cli.d.cts",
|
|
50
50
|
"default": "./dist/cli.cjs"
|
|
51
51
|
}
|
|
52
52
|
},
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"default": "./dist/babel.js"
|
|
57
57
|
},
|
|
58
58
|
"require": {
|
|
59
|
-
"types": "./dist/babel.d.
|
|
59
|
+
"types": "./dist/babel.d.cts",
|
|
60
60
|
"default": "./dist/babel.cjs"
|
|
61
61
|
}
|
|
62
62
|
},
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"default": "./dist/universal.js"
|
|
67
67
|
},
|
|
68
68
|
"require": {
|
|
69
|
-
"types": "./dist/universal.d.
|
|
69
|
+
"types": "./dist/universal.d.cts",
|
|
70
70
|
"default": "./dist/universal.cjs"
|
|
71
71
|
}
|
|
72
72
|
}
|
|
@@ -123,10 +123,14 @@
|
|
|
123
123
|
},
|
|
124
124
|
"dependencies": {
|
|
125
125
|
"fs-extra": "9.1.0",
|
|
126
|
-
"@module-federation/runtime": "2.0
|
|
127
|
-
"@module-federation/sdk": "2.0
|
|
126
|
+
"@module-federation/runtime": "2.2.0",
|
|
127
|
+
"@module-federation/sdk": "2.2.0"
|
|
128
128
|
},
|
|
129
129
|
"scripts": {
|
|
130
|
-
"test": "jest"
|
|
130
|
+
"test": "jest",
|
|
131
|
+
"build": "rslib build",
|
|
132
|
+
"test:ci": "pnpm exec jest --config jest.config.cjs --passWithNoTests --ci --coverage",
|
|
133
|
+
"lint": "ESLINT_USE_FLAT_CONFIG=false pnpm exec eslint --ignore-pattern node_modules \"**/*.ts\" \"package.json\"",
|
|
134
|
+
"pre-release": "pnpm run test && pnpm run build"
|
|
131
135
|
}
|
|
132
136
|
}
|