@module-federation/data-prefetch 2.0.1 → 2.1.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.
@@ -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;
@@ -106,7 +106,20 @@ class PrefetchPlugin {
106
106
  if (!Array.isArray(runtimePlugins)) {
107
107
  this.options.runtimePlugins = [];
108
108
  }
109
- const runtimePath = external_path_default().resolve(__dirname, './plugin.esm.js');
109
+ const runtimePluginCandidates = process.env.IS_ESM_BUILD === 'true' ? [
110
+ '../plugin.js',
111
+ '../plugin.cjs'
112
+ ] : [
113
+ '../plugin.cjs',
114
+ '../plugin.js'
115
+ ];
116
+ const runtimePath = runtimePluginCandidates.map((candidate)=>external_path_default().resolve(__dirname, candidate)).find((candidatePath)=>external_fs_extra_default().existsSync(candidatePath));
117
+ if (!runtimePath) {
118
+ throw new Error([
119
+ '[Module Federation Data Prefetch]: Unable to resolve runtime plugin file.',
120
+ `Checked paths: ${runtimePluginCandidates.map((candidate)=>external_path_default().resolve(__dirname, candidate)).join(', ')}`
121
+ ].join('\n'));
122
+ }
110
123
  if (!((_this_options_runtimePlugins = this.options.runtimePlugins) === null || _this_options_runtimePlugins === void 0 ? void 0 : _this_options_runtimePlugins.includes(runtimePath))) {
111
124
  this.options.runtimePlugins.push(runtimePath);
112
125
  }
@@ -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
@@ -54,7 +54,20 @@ class PrefetchPlugin {
54
54
  if (!Array.isArray(runtimePlugins)) {
55
55
  this.options.runtimePlugins = [];
56
56
  }
57
- const runtimePath = path.resolve(__dirname, './plugin.esm.js');
57
+ const runtimePluginCandidates = process.env.IS_ESM_BUILD === 'true' ? [
58
+ '../plugin.js',
59
+ '../plugin.cjs'
60
+ ] : [
61
+ '../plugin.cjs',
62
+ '../plugin.js'
63
+ ];
64
+ const runtimePath = runtimePluginCandidates.map((candidate)=>path.resolve(__dirname, candidate)).find((candidatePath)=>fs_extra.existsSync(candidatePath));
65
+ if (!runtimePath) {
66
+ throw new Error([
67
+ '[Module Federation Data Prefetch]: Unable to resolve runtime plugin file.',
68
+ `Checked paths: ${runtimePluginCandidates.map((candidate)=>path.resolve(__dirname, candidate)).join(', ')}`
69
+ ].join('\n'));
70
+ }
58
71
  if (!((_this_options_runtimePlugins = this.options.runtimePlugins) === null || _this_options_runtimePlugins === void 0 ? void 0 : _this_options_runtimePlugins.includes(runtimePath))) {
59
72
  this.options.runtimePlugins.push(runtimePath);
60
73
  }
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,2 @@
1
+ export declare const fileExistsWithCaseSync: (filepath: string) => boolean;
2
+ export declare const fixPrefetchPath: (exposePath: string) => Array<string>;
@@ -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";
@@ -0,0 +1,2 @@
1
+ export * from './prefetch';
2
+ export * from './plugin';
@@ -0,0 +1,2 @@
1
+ declare const logger: import("@module-federation/sdk").Logger;
2
+ export default logger;
@@ -0,0 +1,3 @@
1
+ import type { ModuleFederationRuntimePlugin } from '@module-federation/runtime';
2
+ export declare const prefetchPlugin: () => ModuleFederationRuntimePlugin;
3
+ export default prefetchPlugin;
@@ -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;
@@ -0,0 +1 @@
1
+ export * from './react/index';
@@ -0,0 +1,2 @@
1
+ import { type prefetchOptions } from '../prefetch';
2
+ export declare function prefetch(options: prefetchOptions): Promise<any>;
@@ -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.1",
4
+ "version": "2.1.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.ts",
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.ts",
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.ts",
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.ts",
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.ts",
69
+ "types": "./dist/universal.d.cts",
70
70
  "default": "./dist/universal.cjs"
71
71
  }
72
72
  }
@@ -123,8 +123,8 @@
123
123
  },
124
124
  "dependencies": {
125
125
  "fs-extra": "9.1.0",
126
- "@module-federation/runtime": "2.0.1",
127
- "@module-federation/sdk": "2.0.1"
126
+ "@module-federation/runtime": "2.1.0",
127
+ "@module-federation/sdk": "2.1.0"
128
128
  },
129
129
  "scripts": {
130
130
  "test": "jest"