@module-federation/data-prefetch 0.0.0-next-20241115035905 → 0.0.0-next-20241117184153

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