@module-federation/data-prefetch 1.0.16 → 2.0.1
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/LICENSE +1 -1
- package/README.md +3 -1
- package/dist/LICENSE +21 -0
- package/dist/babel.cjs +95 -0
- package/dist/babel.d.ts +1 -0
- package/dist/babel.js +5 -0
- package/dist/cli/babel.cjs +115 -0
- package/dist/cli/babel.d.ts +2 -4
- package/dist/cli/babel.js +50 -82
- package/dist/cli/index.cjs +217 -0
- package/dist/cli/index.d.ts +5 -8
- package/dist/cli/index.js +150 -197
- package/dist/cli.cjs +95 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +5 -0
- package/dist/common/constant.cjs +51 -0
- package/dist/common/constant.d.ts +1 -0
- package/dist/common/constant.js +5 -0
- package/dist/common/index.cjs +95 -0
- package/dist/common/index.js +5 -0
- package/dist/common/node-utils.cjs +100 -0
- package/dist/common/node-utils.d.ts +2 -0
- package/dist/common/node-utils.js +35 -0
- package/dist/common/runtime-utils.cjs +84 -0
- package/dist/common/runtime-utils.d.ts +5 -0
- package/dist/common/runtime-utils.js +29 -0
- package/dist/constant.cjs +51 -0
- package/dist/constant.d.ts +1 -0
- package/dist/constant.js +5 -0
- package/dist/index.cjs +106 -0
- package/dist/index.d.ts +2 -5
- package/dist/index.js +3 -346
- package/dist/logger/index.cjs +60 -0
- package/dist/logger/index.d.ts +2 -0
- package/dist/logger/index.js +10 -0
- package/dist/plugin.cjs +234 -0
- package/dist/plugin.d.ts +3 -5
- package/dist/plugin.js +167 -340
- package/dist/prefetch.cjs +197 -0
- package/dist/{prefetch-4e9646e4.d.ts → prefetch.d.ts} +14 -17
- package/dist/prefetch.js +149 -0
- package/dist/react/hooks.cjs +144 -0
- package/dist/react/hooks.d.ts +11 -0
- package/dist/react/hooks.js +86 -0
- package/dist/react/index.cjs +95 -0
- package/dist/react/index.d.ts +1 -16
- package/dist/react/index.js +2 -283
- package/dist/react/utils.cjs +65 -0
- package/dist/react/utils.d.ts +1 -0
- package/dist/react/utils.js +15 -0
- package/dist/react.cjs +95 -0
- package/dist/react.d.ts +1 -0
- package/dist/react.js +5 -0
- package/dist/universal/index.cjs +81 -0
- package/dist/universal/index.d.ts +2 -8
- package/dist/universal/index.js +24 -196
- package/dist/universal.cjs +95 -0
- package/dist/universal.d.ts +1 -0
- package/dist/universal.js +5 -0
- package/package.json +76 -40
- package/CHANGELOG.md +0 -9
- package/__tests__/babel.spec.ts +0 -75
- package/__tests__/prefetch.spec.ts +0 -138
- package/__tests__/react.spec.ts +0 -119
- package/dist/esm/chunk-AJPO2B2T.js +0 -30
- package/dist/esm/chunk-EZUCZHGV.js +0 -11
- package/dist/esm/chunk-ISLXMAIA.js +0 -155
- package/dist/esm/chunk-KI4QGPIS.js +0 -32
- package/dist/esm/chunk-TTJJJ2WZ.js +0 -7
- package/dist/esm/chunk-VVZ6XIM6.js +0 -166
- package/dist/esm/cli/babel.js +0 -57
- package/dist/esm/cli/index.js +0 -178
- package/dist/esm/index.js +0 -13
- package/dist/esm/plugin.js +0 -12
- package/dist/esm/react/index.js +0 -94
- package/dist/esm/shared/index.js +0 -27
- package/dist/esm/universal/index.js +0 -9
- package/dist/shared/index.d.ts +0 -5
- package/dist/shared/index.js +0 -48
- package/jest.config.js +0 -29
- package/project.json +0 -21
- package/src/cli/babel.ts +0 -94
- package/src/cli/index.ts +0 -171
- package/src/common/constant.ts +0 -1
- package/src/common/node-utils.ts +0 -24
- package/src/common/runtime-utils.ts +0 -34
- package/src/index.ts +0 -2
- package/src/logger/index.ts +0 -3
- package/src/plugin.ts +0 -191
- package/src/prefetch.ts +0 -207
- package/src/react/hooks.ts +0 -95
- package/src/react/index.ts +0 -1
- package/src/react/utils.ts +0 -11
- package/src/shared/index.ts +0 -26
- package/src/universal/index.ts +0 -27
- package/tsconfig.json +0 -27
- package/tsup.config.ts +0 -35
- /package/{src/common/index.ts → dist/common/index.d.ts} +0 -0
package/src/react/hooks.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
import type { defer } from 'react-router';
|
|
3
|
-
|
|
4
|
-
import logger from '../logger';
|
|
5
|
-
import { MFDataPrefetch, type prefetchOptions } from '../prefetch';
|
|
6
|
-
import { prefetch } from '../universal';
|
|
7
|
-
import { getScope } from '../common/runtime-utils';
|
|
8
|
-
import { useFirstMounted } from './utils';
|
|
9
|
-
|
|
10
|
-
type refetchParams = any;
|
|
11
|
-
type DeferredData = ReturnType<typeof defer>;
|
|
12
|
-
type prefetchReturnType<T> = [
|
|
13
|
-
Promise<T>,
|
|
14
|
-
(refetchParams?: refetchParams) => void,
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
type UsePrefetchOptions = prefetchOptions & {
|
|
18
|
-
deferId?: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const usePrefetch = <T>(
|
|
22
|
-
options: UsePrefetchOptions,
|
|
23
|
-
): prefetchReturnType<T> => {
|
|
24
|
-
const isFirstMounted = useFirstMounted();
|
|
25
|
-
if (isFirstMounted) {
|
|
26
|
-
const startTiming = performance.now();
|
|
27
|
-
logger.info(
|
|
28
|
-
`2. Start Get Prefetch Data: ${options.id} - ${
|
|
29
|
-
options.functionId || 'default'
|
|
30
|
-
} - ${startTiming}`,
|
|
31
|
-
);
|
|
32
|
-
}
|
|
33
|
-
const { id, functionId, deferId } = options;
|
|
34
|
-
const prefetchInfo = {
|
|
35
|
-
id,
|
|
36
|
-
functionId,
|
|
37
|
-
};
|
|
38
|
-
const mfScope = getScope();
|
|
39
|
-
|
|
40
|
-
let state;
|
|
41
|
-
const prefetchResult = prefetch(options);
|
|
42
|
-
if (deferId) {
|
|
43
|
-
if (prefetchResult instanceof Promise) {
|
|
44
|
-
state = (prefetchResult as Promise<DeferredData>).then(
|
|
45
|
-
(deferredData) => deferredData.data[deferId],
|
|
46
|
-
);
|
|
47
|
-
} else {
|
|
48
|
-
state = (prefetchResult as DeferredData).data[deferId];
|
|
49
|
-
}
|
|
50
|
-
} else {
|
|
51
|
-
state = prefetchResult;
|
|
52
|
-
}
|
|
53
|
-
const [prefetchState, setPrefetchState] = useState<Promise<T>>(
|
|
54
|
-
state as Promise<T>,
|
|
55
|
-
);
|
|
56
|
-
const prefetchInstance = MFDataPrefetch.getInstance(mfScope);
|
|
57
|
-
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
const useEffectTiming = performance.now();
|
|
60
|
-
logger.info(
|
|
61
|
-
`3. Start Execute UseEffect: ${options.id} - ${
|
|
62
|
-
options.functionId || 'default'
|
|
63
|
-
} - ${useEffectTiming}`,
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
return () => {
|
|
67
|
-
prefetchInstance?.markOutdate(prefetchInfo, true);
|
|
68
|
-
};
|
|
69
|
-
}, []);
|
|
70
|
-
|
|
71
|
-
const refreshExecutor = (refetchParams?: refetchParams) => {
|
|
72
|
-
const refetchOptions = {
|
|
73
|
-
...options,
|
|
74
|
-
};
|
|
75
|
-
if (refetchParams) {
|
|
76
|
-
refetchOptions.refetchParams = refetchParams;
|
|
77
|
-
}
|
|
78
|
-
prefetchInstance?.markOutdate(prefetchInfo, true);
|
|
79
|
-
const newVal = prefetch(refetchOptions) as Promise<DeferredData>;
|
|
80
|
-
let newState;
|
|
81
|
-
if (deferId) {
|
|
82
|
-
if (newVal instanceof Promise) {
|
|
83
|
-
newState = newVal.then((deferredData) => deferredData.data[deferId]);
|
|
84
|
-
} else {
|
|
85
|
-
newState = (newVal as DeferredData).data[deferId];
|
|
86
|
-
}
|
|
87
|
-
} else {
|
|
88
|
-
newState = newVal;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
setPrefetchState(newState as Promise<T>);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
return [prefetchState, refreshExecutor];
|
|
95
|
-
};
|
package/src/react/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './hooks';
|
package/src/react/utils.ts
DELETED
package/src/shared/index.ts
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { FederationRuntimePlugin } from '@module-federation/runtime';
|
|
2
|
-
|
|
3
|
-
const sharedStrategy: () => FederationRuntimePlugin = () => ({
|
|
4
|
-
name: 'shared-strategy',
|
|
5
|
-
beforeInit(args) {
|
|
6
|
-
const { userOptions } = args;
|
|
7
|
-
const shared = userOptions.shared;
|
|
8
|
-
if (shared) {
|
|
9
|
-
Object.keys(shared).forEach((sharedKey) => {
|
|
10
|
-
const sharedConfigs = shared[sharedKey];
|
|
11
|
-
const arraySharedConfigs = Array.isArray(sharedConfigs)
|
|
12
|
-
? sharedConfigs
|
|
13
|
-
: [sharedConfigs];
|
|
14
|
-
arraySharedConfigs.forEach((s) => {
|
|
15
|
-
s.strategy = 'loaded-first';
|
|
16
|
-
});
|
|
17
|
-
});
|
|
18
|
-
console.warn(
|
|
19
|
-
`[Module Federation Data Prefetch]: Your shared strategy is set to 'loaded-first', this is a necessary condition for data prefetch`,
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
return args;
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export default sharedStrategy;
|
package/src/universal/index.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { MFDataPrefetch, type prefetchOptions } from '../prefetch';
|
|
2
|
-
import { getScope } from '../common/runtime-utils';
|
|
3
|
-
|
|
4
|
-
export function prefetch(options: prefetchOptions): Promise<any> {
|
|
5
|
-
const { id, functionId = 'default' } = options;
|
|
6
|
-
const mfScope = getScope();
|
|
7
|
-
|
|
8
|
-
const prefetchInstance =
|
|
9
|
-
MFDataPrefetch.getInstance(mfScope) ||
|
|
10
|
-
new MFDataPrefetch({
|
|
11
|
-
name: mfScope,
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
const res = prefetchInstance.getProjectExports();
|
|
15
|
-
if (res instanceof Promise) {
|
|
16
|
-
const promise = res.then(() => {
|
|
17
|
-
const result = prefetchInstance!.prefetch(options);
|
|
18
|
-
prefetchInstance.memorize(id + functionId, result);
|
|
19
|
-
return result;
|
|
20
|
-
});
|
|
21
|
-
return promise;
|
|
22
|
-
} else {
|
|
23
|
-
const result = prefetchInstance!.prefetch(options);
|
|
24
|
-
prefetchInstance.memorize(id + functionId, result);
|
|
25
|
-
return result;
|
|
26
|
-
}
|
|
27
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"baseUrl": ".",
|
|
4
|
-
"rootDir": "./",
|
|
5
|
-
"outDir": "dist",
|
|
6
|
-
"sourceMap": false,
|
|
7
|
-
"module": "commonjs",
|
|
8
|
-
"target": "ES2015",
|
|
9
|
-
"skipLibCheck": true,
|
|
10
|
-
"moduleResolution": "node",
|
|
11
|
-
"allowJs": false,
|
|
12
|
-
"strict": true,
|
|
13
|
-
"types": ["jest", "node"],
|
|
14
|
-
"experimentalDecorators": true,
|
|
15
|
-
"resolveJsonModule": true,
|
|
16
|
-
"allowSyntheticDefaultImports": true,
|
|
17
|
-
"esModuleInterop": true,
|
|
18
|
-
"removeComments": true,
|
|
19
|
-
"declaration": true,
|
|
20
|
-
"paths": {
|
|
21
|
-
"@/*": ["./*"],
|
|
22
|
-
"@src/*": ["./src/*"]
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
"include": ["src", "../../global.d.ts", "__tests__/**/*", "tsup.config.ts"],
|
|
26
|
-
"exclude": ["node_modules/**/*", "../node_modules"]
|
|
27
|
-
}
|
package/tsup.config.ts
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { replace } from 'esbuild-plugin-replace';
|
|
2
|
-
import minimist from 'minimist';
|
|
3
|
-
import type { Options } from 'tsup';
|
|
4
|
-
|
|
5
|
-
import pkg from './package.json';
|
|
6
|
-
|
|
7
|
-
const args = minimist(process.argv.slice(2));
|
|
8
|
-
const watch = process.env.WATCH;
|
|
9
|
-
const sourceMap = args.sourcemap || args.s;
|
|
10
|
-
|
|
11
|
-
export const tsup: Options = {
|
|
12
|
-
entry: [
|
|
13
|
-
'src/index.ts',
|
|
14
|
-
'src/react/index.ts',
|
|
15
|
-
'src/cli/index.ts',
|
|
16
|
-
'src/cli/babel.ts',
|
|
17
|
-
'src/universal/index.ts',
|
|
18
|
-
'src/plugin.ts',
|
|
19
|
-
'src/shared/index.ts',
|
|
20
|
-
],
|
|
21
|
-
sourcemap: sourceMap,
|
|
22
|
-
clean: true,
|
|
23
|
-
dts: true,
|
|
24
|
-
watch: watch ? 'src/' : false,
|
|
25
|
-
format: ['esm', 'cjs'],
|
|
26
|
-
legacyOutput: true,
|
|
27
|
-
esbuildPlugins: [
|
|
28
|
-
replace({
|
|
29
|
-
__VERSION__: `'${pkg.version}'`,
|
|
30
|
-
__DEV__:
|
|
31
|
-
'(typeof process !== "undefined" && process.env && process.env.NODE_ENV ? (process.env.NODE_ENV !== "production") : false)',
|
|
32
|
-
__TEST__: 'false',
|
|
33
|
-
}),
|
|
34
|
-
],
|
|
35
|
-
};
|
|
File without changes
|