@module-federation/data-prefetch 0.0.0-next-20241015065721 → 0.0.0-next-20241016062654
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/.swcrc +29 -0
- package/CHANGELOG.md +41 -4
- package/LICENSE +1 -1
- package/dist/LICENSE +21 -0
- package/dist/babel.cjs.d.ts +2 -0
- package/dist/babel.cjs.js +50 -0
- package/dist/babel.esm.d.ts +2 -0
- package/dist/babel.esm.js +48 -0
- package/dist/cli.cjs.d.ts +1 -0
- package/dist/cli.cjs.js +156 -0
- package/dist/cli.esm.d.ts +1 -0
- package/dist/cli.esm.js +153 -0
- package/dist/constant.cjs.js +5 -0
- package/dist/constant.esm.js +3 -0
- package/dist/index.cjs.d.ts +1 -0
- package/dist/index.cjs.js +14 -0
- package/dist/index.cjs2.js +7 -0
- package/dist/index.esm.d.ts +1 -0
- package/dist/index.esm.js +7 -0
- package/dist/index.esm2.js +5 -0
- package/dist/package.json +88 -0
- package/dist/plugin.cjs.d.ts +2 -0
- package/dist/plugin.cjs.js +159 -0
- package/dist/plugin.esm.d.ts +2 -0
- package/dist/plugin.esm.js +154 -0
- package/dist/polyfills.cjs.js +14 -0
- package/dist/polyfills.esm.js +12 -0
- package/dist/prefetch.cjs.js +142 -0
- package/dist/prefetch.esm.js +140 -0
- package/dist/react.cjs.d.ts +1 -0
- package/dist/react.cjs.js +77 -0
- package/dist/react.esm.d.ts +1 -0
- package/dist/react.esm.js +75 -0
- package/dist/runtime-utils.cjs.js +27 -0
- package/dist/runtime-utils.esm.js +22 -0
- package/dist/{cli → src/cli}/babel.d.ts +2 -4
- package/dist/{cli → src/cli}/index.d.ts +5 -8
- package/dist/src/common/constant.d.ts +1 -0
- package/dist/src/common/index.d.ts +1 -0
- package/dist/src/common/node-utils.d.ts +2 -0
- package/dist/src/common/runtime-utils.d.ts +5 -0
- package/dist/src/constant.d.ts +1 -0
- package/dist/src/index.d.ts +2 -0
- package/dist/src/logger/index.d.ts +3 -0
- package/dist/src/plugin.d.ts +3 -0
- package/dist/{prefetch-c08be471.d.ts → src/prefetch.d.ts} +4 -6
- package/dist/src/react/hooks.d.ts +11 -0
- package/dist/src/react/index.d.ts +1 -0
- package/dist/src/react/utils.d.ts +1 -0
- package/dist/src/universal/index.d.ts +2 -0
- package/dist/universal.cjs.d.ts +1 -0
- package/dist/universal.cjs.js +29 -0
- package/dist/universal.esm.d.ts +1 -0
- package/dist/universal.esm.js +27 -0
- package/package.json +28 -37
- package/project.json +48 -6
- package/rollup.config.js +45 -0
- package/src/cli/index.ts +7 -4
- package/src/constant.ts +1 -0
- package/src/plugin.ts +4 -4
- package/tsconfig.json +1 -1
- package/tsconfig.lib.json +10 -0
- package/dist/cli/babel.js +0 -84
- package/dist/cli/index.js +0 -207
- package/dist/esm/chunk-AJPO2B2T.js +0 -30
- package/dist/esm/chunk-BGNOVRH5.js +0 -166
- package/dist/esm/chunk-EZUCZHGV.js +0 -11
- package/dist/esm/chunk-ISF7VMBW.js +0 -156
- package/dist/esm/chunk-OCDMSRMZ.js +0 -32
- package/dist/esm/chunk-TTJJJ2WZ.js +0 -7
- package/dist/esm/cli/babel.js +0 -57
- package/dist/esm/cli/index.js +0 -180
- 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/index.d.ts +0 -5
- package/dist/index.js +0 -351
- package/dist/plugin.d.ts +0 -5
- package/dist/plugin.js +0 -347
- package/dist/react/index.d.ts +0 -16
- package/dist/react/index.js +0 -287
- package/dist/shared/index.d.ts +0 -5
- package/dist/shared/index.js +0 -48
- package/dist/universal/index.d.ts +0 -8
- package/dist/universal/index.js +0 -205
- package/src/shared/index.ts +0 -26
- package/tsup.config.ts +0 -35
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-
|
|
4
|
+
"version": "0.0.0-next-20241016062654",
|
|
5
5
|
"author": "nieyan <nyqykk@foxmail.com>",
|
|
6
6
|
"homepage": "https://github.com/module-federation/core",
|
|
7
7
|
"license": "MIT",
|
|
@@ -10,57 +10,52 @@
|
|
|
10
10
|
},
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
-
"import": "./dist/
|
|
14
|
-
"require": "./dist/index.
|
|
15
|
-
"types": "./dist/index.d.ts"
|
|
13
|
+
"import": "./dist/index.esm.js",
|
|
14
|
+
"require": "./dist/index.cjs",
|
|
15
|
+
"types": "./dist/index.cjs.d.ts"
|
|
16
16
|
},
|
|
17
17
|
"./react": {
|
|
18
|
-
"import": "./dist/
|
|
19
|
-
"require": "./dist/react
|
|
20
|
-
"types": "./dist/react
|
|
18
|
+
"import": "./dist/react.esm.js",
|
|
19
|
+
"require": "./dist/react.cjs.js",
|
|
20
|
+
"types": "./dist/react.cjs.d.ts"
|
|
21
21
|
},
|
|
22
22
|
"./cli": {
|
|
23
|
-
"import": "./dist/
|
|
24
|
-
"require": "./dist/cli
|
|
25
|
-
"types": "./dist/cli
|
|
23
|
+
"import": "./dist/cli.esm.js",
|
|
24
|
+
"require": "./dist/cli.cjs.js",
|
|
25
|
+
"types": "./dist/cli.cjs.d.ts"
|
|
26
26
|
},
|
|
27
27
|
"./babel-plugin": {
|
|
28
|
-
"import": "./dist/
|
|
29
|
-
"require": "./dist/
|
|
30
|
-
"types": "./dist/
|
|
28
|
+
"import": "./dist/babel.esm.js",
|
|
29
|
+
"require": "./dist/babel.cjs.js",
|
|
30
|
+
"types": "./dist/babel.cjs.d.ts"
|
|
31
31
|
},
|
|
32
32
|
"./universal": {
|
|
33
|
-
"import": "./dist/
|
|
34
|
-
"require": "./dist/universal
|
|
35
|
-
"types": "./dist/universal
|
|
36
|
-
},
|
|
37
|
-
"./shared": {
|
|
38
|
-
"import": "./dist/esm/shared/index.js",
|
|
39
|
-
"require": "./dist/shared/index.js",
|
|
40
|
-
"types": "./dist/shared/index.d.ts"
|
|
33
|
+
"import": "./dist/universal.esm.js",
|
|
34
|
+
"require": "./dist/universal.cjs.js",
|
|
35
|
+
"types": "./dist/universal.cjs.d.ts"
|
|
41
36
|
}
|
|
42
37
|
},
|
|
43
38
|
"typesVersions": {
|
|
44
39
|
"*": {
|
|
45
40
|
".": [
|
|
46
|
-
"./dist/index.d.ts"
|
|
41
|
+
"./dist/index.cjs.d.ts"
|
|
47
42
|
],
|
|
48
43
|
"react": [
|
|
49
|
-
"./dist/react
|
|
44
|
+
"./dist/react.cjs.d.ts"
|
|
50
45
|
],
|
|
51
46
|
"cli": [
|
|
52
|
-
"./dist/cli
|
|
47
|
+
"./dist/cli.cjs.d.ts"
|
|
53
48
|
],
|
|
54
49
|
"universal": [
|
|
55
|
-
"./dist/universal
|
|
50
|
+
"./dist/universal.cjs.d.ts"
|
|
56
51
|
],
|
|
57
|
-
"
|
|
58
|
-
"./dist/
|
|
52
|
+
"babel-plugin": [
|
|
53
|
+
"./dist/babel.cjs.d.ts"
|
|
59
54
|
]
|
|
60
55
|
}
|
|
61
56
|
},
|
|
62
|
-
"main": "dist/index.
|
|
63
|
-
"module": "dist/
|
|
57
|
+
"main": "dist/index.cjs",
|
|
58
|
+
"module": "dist/index.esm.js",
|
|
64
59
|
"peerDependencies": {
|
|
65
60
|
"react": ">=16.9.0",
|
|
66
61
|
"react-dom": ">=16.9.0"
|
|
@@ -71,26 +66,22 @@
|
|
|
71
66
|
"@types/jest": "^29.5.11",
|
|
72
67
|
"@types/node": "^17.0.45",
|
|
73
68
|
"@types/react": "~18.0.38",
|
|
74
|
-
"esbuild-plugin-replace": "^1.4.0",
|
|
75
69
|
"jest": "^29.7.0",
|
|
76
70
|
"jest-environment-jsdom": "^29.7.0",
|
|
77
71
|
"minimist": "^1.2.8",
|
|
78
|
-
"react": "^18.
|
|
79
|
-
"react-dom": "^18.
|
|
72
|
+
"react": "^18.3.1",
|
|
73
|
+
"react-dom": "^18.3.1",
|
|
80
74
|
"react-router": "^6.21.3",
|
|
81
75
|
"react-test-renderer": "^18.2.0",
|
|
82
76
|
"ts-jest": "29.0.1",
|
|
83
|
-
"tsup": "6.2.0",
|
|
84
77
|
"webpack": "5.75.0"
|
|
85
78
|
},
|
|
86
79
|
"dependencies": {
|
|
87
80
|
"fs-extra": "9.1.0",
|
|
88
|
-
"@module-federation/
|
|
89
|
-
"@module-federation/
|
|
81
|
+
"@module-federation/runtime": "0.0.0-next-20241016062654",
|
|
82
|
+
"@module-federation/sdk": "0.0.0-next-20241016062654"
|
|
90
83
|
},
|
|
91
84
|
"scripts": {
|
|
92
|
-
"dev": "cross-env WATCH=true tsup",
|
|
93
|
-
"build": "rm -rf dist && tsup",
|
|
94
85
|
"test": "jest"
|
|
95
86
|
}
|
|
96
87
|
}
|
package/project.json
CHANGED
|
@@ -1,21 +1,63 @@
|
|
|
1
1
|
{
|
|
2
|
-
"name": "
|
|
2
|
+
"name": "data-prefetch",
|
|
3
3
|
"$schema": "../../node_modules/nx/schemas/project-schema.json",
|
|
4
4
|
"sourceRoot": "packages/data-prefetch/src",
|
|
5
5
|
"projectType": "library",
|
|
6
|
+
"tags": ["type:pkg"],
|
|
6
7
|
"targets": {
|
|
7
8
|
"build": {
|
|
8
|
-
"executor": "nx:
|
|
9
|
+
"executor": "@nx/rollup:rollup",
|
|
10
|
+
"outputs": ["{options.outputPath}"],
|
|
9
11
|
"options": {
|
|
10
|
-
"
|
|
12
|
+
"outputPath": "packages/data-prefetch/dist",
|
|
13
|
+
"main": "packages/data-prefetch/src/index.ts",
|
|
14
|
+
"tsConfig": "packages/data-prefetch/tsconfig.lib.json",
|
|
15
|
+
"assets": [],
|
|
16
|
+
"project": "packages/data-prefetch/package.json",
|
|
17
|
+
"rollupConfig": "packages/data-prefetch/rollup.config.js",
|
|
18
|
+
"compiler": "swc",
|
|
19
|
+
"format": ["cjs", "esm"]
|
|
11
20
|
}
|
|
12
21
|
},
|
|
13
22
|
"test": {
|
|
23
|
+
"executor": "@nx/jest:jest",
|
|
24
|
+
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
|
|
25
|
+
"options": {
|
|
26
|
+
"jestConfig": "packages/data-prefetch/jest.config.js",
|
|
27
|
+
"passWithNoTests": true
|
|
28
|
+
},
|
|
29
|
+
"configurations": {
|
|
30
|
+
"ci": {
|
|
31
|
+
"ci": true,
|
|
32
|
+
"codeCoverage": true
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
"lint": {
|
|
37
|
+
"executor": "@nx/eslint:lint",
|
|
38
|
+
"outputs": ["{options.outputFile}"],
|
|
39
|
+
"options": {
|
|
40
|
+
"lintFilePatterns": [
|
|
41
|
+
"packages/data-prefetch/**/*.ts",
|
|
42
|
+
"packages/data-prefetch/package.json"
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"pre-release": {
|
|
14
47
|
"executor": "nx:run-commands",
|
|
15
48
|
"options": {
|
|
16
|
-
"
|
|
49
|
+
"parallel": false,
|
|
50
|
+
"commands": [
|
|
51
|
+
{
|
|
52
|
+
"command": "nx run data-prefetch:test",
|
|
53
|
+
"forwardAllArgs": false
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"command": "nx run data-prefetch:build",
|
|
57
|
+
"forwardAllArgs": false
|
|
58
|
+
}
|
|
59
|
+
]
|
|
17
60
|
}
|
|
18
61
|
}
|
|
19
|
-
}
|
|
20
|
-
"tags": ["type:pkg"]
|
|
62
|
+
}
|
|
21
63
|
}
|
package/rollup.config.js
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
const copy = require('rollup-plugin-copy');
|
|
2
|
+
|
|
3
|
+
module.exports = (rollupConfig, _projectOptions) => {
|
|
4
|
+
rollupConfig.plugins.push(
|
|
5
|
+
copy({
|
|
6
|
+
targets: [
|
|
7
|
+
{
|
|
8
|
+
src: 'packages/data-prefetch/LICENSE',
|
|
9
|
+
dest: 'packages/data-prefetch/dist',
|
|
10
|
+
},
|
|
11
|
+
],
|
|
12
|
+
}),
|
|
13
|
+
);
|
|
14
|
+
rollupConfig.input = {
|
|
15
|
+
index: 'packages/data-prefetch/src/index.ts',
|
|
16
|
+
react: 'packages/data-prefetch/src/react/index.ts',
|
|
17
|
+
cli: 'packages/data-prefetch/src/cli/index.ts',
|
|
18
|
+
babel: 'packages/data-prefetch/src/cli/babel.ts',
|
|
19
|
+
universal: 'packages/data-prefetch/src/universal/index.ts',
|
|
20
|
+
plugin: 'packages/data-prefetch/src/plugin.ts',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
if (Array.isArray(rollupConfig.output)) {
|
|
24
|
+
rollupConfig.output = rollupConfig.output.map((c) => ({
|
|
25
|
+
...c,
|
|
26
|
+
manualChunks: (id) => {
|
|
27
|
+
if (id.includes('@swc/helpers')) {
|
|
28
|
+
return 'polyfills';
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
}));
|
|
32
|
+
} else {
|
|
33
|
+
rollupConfig.output = {
|
|
34
|
+
...rollupConfig.output,
|
|
35
|
+
manualChunks: (id) => {
|
|
36
|
+
if (id.includes('@swc/helpers')) {
|
|
37
|
+
return 'polyfills';
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// rollupConfig.external = [/@module-federation/];
|
|
44
|
+
return rollupConfig;
|
|
45
|
+
};
|
package/src/cli/index.ts
CHANGED
|
@@ -12,6 +12,7 @@ import type { Compiler, WebpackPluginInstance } from 'webpack';
|
|
|
12
12
|
import { TEMP_DIR } from '../common/constant';
|
|
13
13
|
import { fileExistsWithCaseSync, fixPrefetchPath } from '../common/node-utils';
|
|
14
14
|
import { getPrefetchId } from '../common/runtime-utils';
|
|
15
|
+
import { SHARED_STRATEGY } from '../constant';
|
|
15
16
|
|
|
16
17
|
const { RuntimeGlobals, Template } = require(
|
|
17
18
|
normalizeWebpackPath('webpack'),
|
|
@@ -47,13 +48,15 @@ export class PrefetchPlugin implements WebpackPluginInstance {
|
|
|
47
48
|
this.options.runtimePlugins = [];
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
const runtimePath = path.resolve(__dirname, '
|
|
51
|
-
const sharedPath = path.resolve(__dirname, '../esm/shared/index.js');
|
|
51
|
+
const runtimePath = path.resolve(__dirname, './plugin.esm.js');
|
|
52
52
|
if (!this.options.runtimePlugins?.includes(runtimePath)) {
|
|
53
53
|
this.options.runtimePlugins!.push(runtimePath);
|
|
54
54
|
}
|
|
55
|
-
if (
|
|
56
|
-
this.options.
|
|
55
|
+
if (this.options.shareStrategy !== SHARED_STRATEGY) {
|
|
56
|
+
this.options.shareStrategy = SHARED_STRATEGY;
|
|
57
|
+
console.warn(
|
|
58
|
+
`[Module Federation Data Prefetch]: Your shared strategy is set to '${SHARED_STRATEGY}', this is a necessary condition for data prefetch`,
|
|
59
|
+
);
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
const encodedName = encodeName(name as string);
|
package/src/constant.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SHARED_STRATEGY = 'loaded-first';
|
package/src/plugin.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { ModuleInfo, getResourceUrl } from '@module-federation/sdk';
|
|
|
4
4
|
import { getSignalFromManifest } from './common/runtime-utils';
|
|
5
5
|
import { MFDataPrefetch } from './prefetch';
|
|
6
6
|
import logger from './logger';
|
|
7
|
+
import { SHARED_STRATEGY } from './constant';
|
|
7
8
|
|
|
8
9
|
interface Loading {
|
|
9
10
|
id: string;
|
|
@@ -15,8 +16,7 @@ interface Loading {
|
|
|
15
16
|
>;
|
|
16
17
|
}
|
|
17
18
|
const loadingArray: Array<Loading> = [];
|
|
18
|
-
|
|
19
|
-
let sharedFlag = strategy;
|
|
19
|
+
let sharedFlag = SHARED_STRATEGY;
|
|
20
20
|
// eslint-disable-next-line max-lines-per-function
|
|
21
21
|
export const prefetchPlugin = (): FederationRuntimePlugin => ({
|
|
22
22
|
name: 'data-prefetch-runtime-plugin',
|
|
@@ -35,7 +35,7 @@ export const prefetchPlugin = (): FederationRuntimePlugin => ({
|
|
|
35
35
|
if (!signal) {
|
|
36
36
|
return options;
|
|
37
37
|
}
|
|
38
|
-
if (sharedFlag !==
|
|
38
|
+
if (sharedFlag !== SHARED_STRATEGY) {
|
|
39
39
|
throw new Error(
|
|
40
40
|
`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`,
|
|
41
41
|
);
|
|
@@ -109,7 +109,7 @@ export const prefetchPlugin = (): FederationRuntimePlugin => ({
|
|
|
109
109
|
return options;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
-
if (sharedFlag !==
|
|
112
|
+
if (sharedFlag !== SHARED_STRATEGY) {
|
|
113
113
|
throw new Error(
|
|
114
114
|
`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`,
|
|
115
115
|
);
|
package/tsconfig.json
CHANGED
package/dist/cli/babel.js
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
-
|
|
26
|
-
// src/cli/babel.ts
|
|
27
|
-
var babel_exports = {};
|
|
28
|
-
__export(babel_exports, {
|
|
29
|
-
default: () => babel_default
|
|
30
|
-
});
|
|
31
|
-
module.exports = __toCommonJS(babel_exports);
|
|
32
|
-
var import_path = __toESM(require("path"));
|
|
33
|
-
var attribute = "id";
|
|
34
|
-
var hookId = "usePrefetch";
|
|
35
|
-
var importPackage = "@module-federation/data-prefetch/react";
|
|
36
|
-
var babel_default = (babel, options) => {
|
|
37
|
-
const t = babel.types;
|
|
38
|
-
let shouldHandle = false;
|
|
39
|
-
let scope = "";
|
|
40
|
-
const { name, exposes } = options;
|
|
41
|
-
if (!exposes) {
|
|
42
|
-
return {};
|
|
43
|
-
}
|
|
44
|
-
const exposesKey = Object.keys(exposes);
|
|
45
|
-
const processedExposes = exposesKey.map((expose) => ({
|
|
46
|
-
key: expose.replace(".", ""),
|
|
47
|
-
value: import_path.default.resolve(
|
|
48
|
-
typeof exposes[expose] === "string" ? exposes[expose] : exposes[expose].import
|
|
49
|
-
)
|
|
50
|
-
}));
|
|
51
|
-
return {
|
|
52
|
-
visitor: {
|
|
53
|
-
ImportDeclaration(nodePath, state) {
|
|
54
|
-
const source = nodePath.node.source.value;
|
|
55
|
-
const { specifiers } = nodePath.node;
|
|
56
|
-
const { filename } = state.file.opts;
|
|
57
|
-
if (source === importPackage) {
|
|
58
|
-
shouldHandle = specifiers.some(
|
|
59
|
-
(specifier) => specifier.imported && specifier.imported.name === hookId && processedExposes.find(
|
|
60
|
-
(expose) => expose.value === filename && (scope = expose.key)
|
|
61
|
-
)
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
CallExpression(nodePath) {
|
|
66
|
-
if (shouldHandle && t.isIdentifier(nodePath.node.callee, { name: hookId }) && nodePath.node.arguments.length > 0) {
|
|
67
|
-
const objectExpression = nodePath.node.arguments[0];
|
|
68
|
-
if (objectExpression && t.isObjectExpression(objectExpression) && !objectExpression.properties.find(
|
|
69
|
-
(p) => p.key.name === attribute
|
|
70
|
-
)) {
|
|
71
|
-
objectExpression.properties.push(
|
|
72
|
-
t.objectProperty(
|
|
73
|
-
t.identifier(attribute),
|
|
74
|
-
t.stringLiteral(name + scope)
|
|
75
|
-
)
|
|
76
|
-
);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
-
0 && (module.exports = {});
|
package/dist/cli/index.js
DELETED
|
@@ -1,207 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
-
mod
|
|
23
|
-
));
|
|
24
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
-
|
|
26
|
-
// src/cli/index.ts
|
|
27
|
-
var cli_exports = {};
|
|
28
|
-
__export(cli_exports, {
|
|
29
|
-
PrefetchPlugin: () => PrefetchPlugin,
|
|
30
|
-
getFederationGlobalScope: () => getFederationGlobalScope
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(cli_exports);
|
|
33
|
-
var import_path2 = __toESM(require("path"));
|
|
34
|
-
var import_fs_extra2 = __toESM(require("fs-extra"));
|
|
35
|
-
var import_sdk2 = require("@module-federation/sdk");
|
|
36
|
-
var import_normalize_webpack_path = require("@module-federation/sdk/normalize-webpack-path");
|
|
37
|
-
|
|
38
|
-
// src/common/constant.ts
|
|
39
|
-
var TEMP_DIR = ".mf";
|
|
40
|
-
|
|
41
|
-
// src/common/node-utils.ts
|
|
42
|
-
var import_path = __toESM(require("path"));
|
|
43
|
-
var import_fs_extra = __toESM(require("fs-extra"));
|
|
44
|
-
var fileExistsWithCaseSync = (filepath) => {
|
|
45
|
-
const dir = import_path.default.dirname(filepath);
|
|
46
|
-
if (filepath === "/" || filepath === ".") {
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
const filenames = import_fs_extra.default.readdirSync(dir);
|
|
50
|
-
if (filenames.indexOf(import_path.default.basename(filepath)) === -1) {
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
53
|
-
return fileExistsWithCaseSync(dir);
|
|
54
|
-
};
|
|
55
|
-
var fixPrefetchPath = (exposePath) => {
|
|
56
|
-
const pathExt = [".js", ".ts"];
|
|
57
|
-
const extReg = /\.(ts|js|tsx|jsx)$/;
|
|
58
|
-
if (extReg.test(exposePath)) {
|
|
59
|
-
return pathExt.map((ext) => exposePath.replace(extReg, `.prefetch${ext}`));
|
|
60
|
-
} else {
|
|
61
|
-
return pathExt.map((ext) => exposePath + `.prefetch${ext}`);
|
|
62
|
-
}
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
// src/common/runtime-utils.ts
|
|
66
|
-
var import_runtime = require("@module-federation/runtime");
|
|
67
|
-
var import_sdk = require("@module-federation/sdk");
|
|
68
|
-
var getPrefetchId = (id) => (0, import_sdk.encodeName)(`${id}/${import_sdk.MFPrefetchCommon.identifier}`);
|
|
69
|
-
|
|
70
|
-
// src/cli/index.ts
|
|
71
|
-
var { RuntimeGlobals, Template } = require((0, import_normalize_webpack_path.normalizeWebpackPath)("webpack"));
|
|
72
|
-
function getFederationGlobalScope(runtimeGlobals) {
|
|
73
|
-
return `${runtimeGlobals.require || "__webpack_require__"}.federation`;
|
|
74
|
-
}
|
|
75
|
-
var PrefetchPlugin = class {
|
|
76
|
-
constructor(options) {
|
|
77
|
-
this.options = options;
|
|
78
|
-
this._reWriteExports = "";
|
|
79
|
-
}
|
|
80
|
-
apply(compiler) {
|
|
81
|
-
var _a, _b;
|
|
82
|
-
const { name, exposes } = this.options;
|
|
83
|
-
if (!exposes) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
if (!compiler.options.context) {
|
|
87
|
-
throw new Error("compiler.options.context is not defined");
|
|
88
|
-
}
|
|
89
|
-
const { runtimePlugins } = this.options;
|
|
90
|
-
if (!Array.isArray(runtimePlugins)) {
|
|
91
|
-
this.options.runtimePlugins = [];
|
|
92
|
-
}
|
|
93
|
-
const runtimePath = import_path2.default.resolve(__dirname, "../esm/plugin.js");
|
|
94
|
-
const sharedPath = import_path2.default.resolve(__dirname, "../esm/shared/index.js");
|
|
95
|
-
if (!((_a = this.options.runtimePlugins) == null ? void 0 : _a.includes(runtimePath))) {
|
|
96
|
-
this.options.runtimePlugins.push(runtimePath);
|
|
97
|
-
}
|
|
98
|
-
if (!((_b = this.options.runtimePlugins) == null ? void 0 : _b.includes(sharedPath))) {
|
|
99
|
-
this.options.runtimePlugins.push(sharedPath);
|
|
100
|
-
}
|
|
101
|
-
const encodedName = (0, import_sdk2.encodeName)(name);
|
|
102
|
-
const asyncEntryPath = import_path2.default.resolve(
|
|
103
|
-
compiler.options.context,
|
|
104
|
-
`node_modules/${TEMP_DIR}/${encodedName}/bootstrap.js`
|
|
105
|
-
);
|
|
106
|
-
if (import_fs_extra2.default.existsSync(asyncEntryPath)) {
|
|
107
|
-
import_fs_extra2.default.unlinkSync(asyncEntryPath);
|
|
108
|
-
}
|
|
109
|
-
if (!this.options.dataPrefetch) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
const prefetchs = [];
|
|
113
|
-
const exposeAlias = Object.keys(exposes);
|
|
114
|
-
exposeAlias.forEach((alias) => {
|
|
115
|
-
let exposePath;
|
|
116
|
-
const exposeValue = exposes[alias];
|
|
117
|
-
if (typeof exposeValue === "string") {
|
|
118
|
-
exposePath = exposeValue;
|
|
119
|
-
} else {
|
|
120
|
-
exposePath = exposeValue.import[0];
|
|
121
|
-
}
|
|
122
|
-
const targetPaths = fixPrefetchPath(exposePath);
|
|
123
|
-
for (const pathItem of targetPaths) {
|
|
124
|
-
const absolutePath = import_path2.default.resolve(compiler.options.context, pathItem);
|
|
125
|
-
if (fileExistsWithCaseSync(absolutePath)) {
|
|
126
|
-
prefetchs.push(pathItem);
|
|
127
|
-
const absoluteAlias = alias.replace(".", "");
|
|
128
|
-
this._reWriteExports += `export * as ${getPrefetchId(
|
|
129
|
-
`${name}${absoluteAlias}`
|
|
130
|
-
)} from '${absolutePath}';
|
|
131
|
-
`;
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
if (!this._reWriteExports) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
const tempDirRealPath = import_path2.default.resolve(
|
|
140
|
-
compiler.options.context,
|
|
141
|
-
"node_modules",
|
|
142
|
-
TEMP_DIR
|
|
143
|
-
);
|
|
144
|
-
if (!import_fs_extra2.default.existsSync(tempDirRealPath)) {
|
|
145
|
-
import_fs_extra2.default.mkdirSync(tempDirRealPath);
|
|
146
|
-
}
|
|
147
|
-
if (!import_fs_extra2.default.existsSync(`${tempDirRealPath}/${encodedName}`)) {
|
|
148
|
-
import_fs_extra2.default.mkdirSync(`${tempDirRealPath}/${encodedName}`);
|
|
149
|
-
}
|
|
150
|
-
import_fs_extra2.default.writeFileSync(asyncEntryPath, this._reWriteExports);
|
|
151
|
-
new compiler.webpack.DefinePlugin({
|
|
152
|
-
FederationDataPrefetch: JSON.stringify(asyncEntryPath)
|
|
153
|
-
}).apply(compiler);
|
|
154
|
-
}
|
|
155
|
-
static addRuntime(compiler, options) {
|
|
156
|
-
const encodedName = (0, import_sdk2.encodeName)(options.name);
|
|
157
|
-
if (!compiler.options.context) {
|
|
158
|
-
throw new Error("compiler.options.context is not defined");
|
|
159
|
-
}
|
|
160
|
-
const prefetchEntry = import_path2.default.resolve(
|
|
161
|
-
compiler.options.context,
|
|
162
|
-
`node_modules/.mf/${encodedName}/bootstrap.js`
|
|
163
|
-
);
|
|
164
|
-
const federationGlobal = getFederationGlobalScope(
|
|
165
|
-
RuntimeGlobals || {}
|
|
166
|
-
);
|
|
167
|
-
return Template.asString([
|
|
168
|
-
import_fs_extra2.default.existsSync(prefetchEntry) ? Template.indent([
|
|
169
|
-
"function injectPrefetch() {",
|
|
170
|
-
Template.indent([
|
|
171
|
-
`globalThis.__FEDERATION__ = globalThis.__FEDERATION__ || {};`,
|
|
172
|
-
`globalThis.__FEDERATION__['${import_sdk2.MFPrefetchCommon.globalKey}'] = globalThis.__FEDERATION__['${import_sdk2.MFPrefetchCommon.globalKey}'] || {`,
|
|
173
|
-
`entryLoading: {},`,
|
|
174
|
-
`instance: new Map(),`,
|
|
175
|
-
`__PREFETCH_EXPORTS__: {},`,
|
|
176
|
-
`};`,
|
|
177
|
-
`globalThis.__FEDERATION__['${import_sdk2.MFPrefetchCommon.globalKey}']['${import_sdk2.MFPrefetchCommon.exportsKey}'] = globalThis.__FEDERATION__['${import_sdk2.MFPrefetchCommon.globalKey}']['${import_sdk2.MFPrefetchCommon.exportsKey}'] || {};`,
|
|
178
|
-
`globalThis.__FEDERATION__['${import_sdk2.MFPrefetchCommon.globalKey}']['${import_sdk2.MFPrefetchCommon.exportsKey}']['${options.name}'] = function(){ return import('${prefetchEntry}');}`
|
|
179
|
-
]),
|
|
180
|
-
"}",
|
|
181
|
-
`${federationGlobal}.prefetch = injectPrefetch`
|
|
182
|
-
]) : "",
|
|
183
|
-
Template.indent([
|
|
184
|
-
`if(!${federationGlobal}.isMFRemote && ${federationGlobal}.prefetch){`,
|
|
185
|
-
`${federationGlobal}.prefetch()`,
|
|
186
|
-
"}"
|
|
187
|
-
])
|
|
188
|
-
]);
|
|
189
|
-
}
|
|
190
|
-
static setRemoteIdentifier() {
|
|
191
|
-
const federationGlobal = getFederationGlobalScope(
|
|
192
|
-
RuntimeGlobals || {}
|
|
193
|
-
);
|
|
194
|
-
return Template.indent([`${federationGlobal}.isMFRemote = true;`]);
|
|
195
|
-
}
|
|
196
|
-
static removeRemoteIdentifier() {
|
|
197
|
-
const federationGlobal = getFederationGlobalScope(
|
|
198
|
-
RuntimeGlobals || {}
|
|
199
|
-
);
|
|
200
|
-
return Template.indent([`${federationGlobal}.isMFRemote = false;`]);
|
|
201
|
-
}
|
|
202
|
-
};
|
|
203
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
204
|
-
0 && (module.exports = {
|
|
205
|
-
PrefetchPlugin,
|
|
206
|
-
getFederationGlobalScope
|
|
207
|
-
});
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// src/common/runtime-utils.ts
|
|
2
|
-
import { getInstance } from "@module-federation/runtime";
|
|
3
|
-
import {
|
|
4
|
-
encodeName,
|
|
5
|
-
MFPrefetchCommon
|
|
6
|
-
} from "@module-federation/sdk";
|
|
7
|
-
var getScope = () => {
|
|
8
|
-
return getInstance().options.name;
|
|
9
|
-
};
|
|
10
|
-
var getPrefetchId = (id) => encodeName(`${id}/${MFPrefetchCommon.identifier}`);
|
|
11
|
-
var compatGetPrefetchId = (id) => encodeName(`${id}/VmokPrefetch`);
|
|
12
|
-
var getSignalFromManifest = (remoteSnapshot) => {
|
|
13
|
-
if (!remoteSnapshot) {
|
|
14
|
-
return false;
|
|
15
|
-
}
|
|
16
|
-
if (!("prefetchEntry" in remoteSnapshot) && !("prefetchInterface" in remoteSnapshot)) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
if (!remoteSnapshot.prefetchEntry && !remoteSnapshot.prefetchInterface) {
|
|
20
|
-
return false;
|
|
21
|
-
}
|
|
22
|
-
return true;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export {
|
|
26
|
-
getScope,
|
|
27
|
-
getPrefetchId,
|
|
28
|
-
compatGetPrefetchId,
|
|
29
|
-
getSignalFromManifest
|
|
30
|
-
};
|