@module-federation/data-prefetch 0.0.0-next-20241118092546 → 0.0.0-next-20241118100312

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/CHANGELOG.md CHANGED
@@ -1,11 +1,12 @@
1
1
  # @module-federation/data-prefetch
2
2
 
3
- ## 0.0.0-next-20241118092546
3
+ ## 0.0.0-next-20241118100312
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - @module-federation/runtime@0.0.0-next-20241118092546
8
- - @module-federation/sdk@0.0.0-next-20241118092546
7
+ - @module-federation/runtime@0.0.0-next-20241118100312
8
+ - @module-federation/sdk@0.0.0-next-20241118100312
9
+ - @module-federation/runtime-core@0.0.0-next-20241118100312
9
10
 
10
11
  ## 0.7.4
11
12
 
@@ -1,14 +1,13 @@
1
1
  import { FederationHost } from '@module-federation/runtime';
2
2
  import { ModuleInfo } from '@module-federation/sdk';
3
3
  import { Remote } from '@module-federation/runtime/types';
4
- declare module '@module-federation/runtime' {
5
- interface 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
- }
4
+ import { Federation } from '@module-federation/runtime-core';
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
+ };
12
11
  }
13
12
  type PrefetchExports = Record<string, any>;
14
13
  export interface DataPrefetchOptions {
@@ -29,7 +28,7 @@ export declare class MFDataPrefetch {
29
28
  private _exports;
30
29
  private _options;
31
30
  constructor(options: DataPrefetchOptions);
32
- get global(): Record<string, any>;
31
+ get global(): FederationWithPrefetch['__PREFETCH__'];
33
32
  static getInstance(id: string): MFDataPrefetch | undefined;
34
33
  loadEntry(entry: string | undefined): Promise<any>;
35
34
  getProjectExports(): Promise<void> | Record<string, any>;
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": "0.0.0-next-20241118092546",
4
+ "version": "0.0.0-next-20241118100312",
5
5
  "author": "nieyan <nyqykk@foxmail.com>",
6
6
  "homepage": "https://github.com/module-federation/core",
7
7
  "license": "MIT",
@@ -78,8 +78,9 @@
78
78
  },
79
79
  "dependencies": {
80
80
  "fs-extra": "9.1.0",
81
- "@module-federation/runtime": "0.0.0-next-20241118092546",
82
- "@module-federation/sdk": "0.0.0-next-20241118092546"
81
+ "@module-federation/runtime": "0.0.0-next-20241118100312",
82
+ "@module-federation/runtime-core": "0.0.0-next-20241118100312",
83
+ "@module-federation/sdk": "0.0.0-next-20241118100312"
83
84
  },
84
85
  "scripts": {
85
86
  "test": "jest"
package/src/prefetch.ts CHANGED
@@ -9,17 +9,16 @@ import {
9
9
  ProviderModuleInfo,
10
10
  } from '@module-federation/sdk';
11
11
  import { Remote } from '@module-federation/runtime/types';
12
-
12
+ import { Federation } from '@module-federation/runtime-core';
13
13
  import { getPrefetchId, compatGetPrefetchId } from './common/runtime-utils';
14
14
 
15
- declare module '@module-federation/runtime' {
16
- export interface Federation {
17
- __PREFETCH__: {
18
- entryLoading: Record<string, undefined | Promise<void>>;
19
- instance: Map<string, MFDataPrefetch>;
20
- __PREFETCH_EXPORTS__: Record<string, () => Promise<Record<string, any>>>;
21
- };
22
- }
15
+ // Define an interface that extends Federation to include __PREFETCH__
16
+ interface FederationWithPrefetch extends Federation {
17
+ __PREFETCH__: {
18
+ entryLoading: Record<string, undefined | Promise<void>>;
19
+ instance: Map<string, MFDataPrefetch>;
20
+ __PREFETCH_EXPORTS__: Record<string, () => Promise<Record<string, any>>>;
21
+ };
23
22
  }
24
23
 
25
24
  type PrefetchExports = Record<string, any>;
@@ -40,11 +39,13 @@ export interface prefetchOptions {
40
39
 
41
40
  // @ts-ignore init global variable for test
42
41
  globalThis.__FEDERATION__ ??= {};
43
- globalThis.__FEDERATION__.__PREFETCH__ ??= {
42
+ (
43
+ globalThis.__FEDERATION__ as unknown as FederationWithPrefetch
44
+ ).__PREFETCH__ ??= {
44
45
  entryLoading: {},
45
46
  instance: new Map(),
46
47
  __PREFETCH_EXPORTS__: {},
47
- };
48
+ } as FederationWithPrefetch['__PREFETCH__'];
48
49
  export class MFDataPrefetch {
49
50
  public prefetchMemory: Map<string, Promise<any>>;
50
51
  public recordOutdate: Record<string, Record<string, boolean>>;
@@ -59,12 +60,15 @@ export class MFDataPrefetch {
59
60
  this.global.instance.set(options.name, this);
60
61
  }
61
62
 
62
- get global(): Record<string, any> {
63
- return globalThis.__FEDERATION__.__PREFETCH__;
63
+ get global(): FederationWithPrefetch['__PREFETCH__'] {
64
+ return (globalThis.__FEDERATION__ as unknown as FederationWithPrefetch)
65
+ .__PREFETCH__;
64
66
  }
65
67
 
66
68
  static getInstance(id: string): MFDataPrefetch | undefined {
67
- return globalThis.__FEDERATION__.__PREFETCH__.instance.get(id);
69
+ return (
70
+ globalThis.__FEDERATION__ as unknown as FederationWithPrefetch
71
+ ).__PREFETCH__.instance.get(id);
68
72
  }
69
73
 
70
74
  async loadEntry(entry: string | undefined): Promise<any> {
@@ -94,8 +98,9 @@ export class MFDataPrefetch {
94
98
  return this._exports;
95
99
  }
96
100
  const { name } = this._options;
97
- const exportsPromiseFn =
98
- globalThis.__FEDERATION__.__PREFETCH__.__PREFETCH_EXPORTS__?.[name];
101
+ const exportsPromiseFn = (
102
+ globalThis.__FEDERATION__ as unknown as FederationWithPrefetch
103
+ ).__PREFETCH__.__PREFETCH_EXPORTS__?.[name];
99
104
  const exportsPromise =
100
105
  typeof exportsPromiseFn === 'function'
101
106
  ? exportsPromiseFn()