@module-federation/data-prefetch 2.0.0 → 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.
- package/dist/babel.cjs +95 -0
- package/dist/babel.d.cts +1 -0
- package/dist/babel.d.ts +1 -2
- package/dist/babel.js +5 -0
- package/dist/cli/babel.cjs +115 -0
- package/dist/cli/babel.d.ts +37 -0
- package/dist/cli/babel.js +52 -0
- package/dist/cli/index.cjs +230 -0
- package/dist/cli/index.d.ts +16 -0
- package/dist/cli/index.js +171 -0
- package/dist/cli.cjs +95 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -1
- 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.d.ts +1 -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 -1
- package/dist/index.js +7 -0
- 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/{src/plugin.d.ts → plugin.d.cts} +1 -1
- package/dist/plugin.d.ts +3 -2
- package/dist/plugin.js +173 -0
- package/dist/prefetch.cjs +197 -0
- package/dist/prefetch.d.ts +42 -0
- package/dist/prefetch.js +149 -0
- package/dist/react/hooks.cjs +144 -0
- package/dist/react/hooks.d.ts +11 -0
- package/dist/{react.esm.js → react/hooks.js} +42 -30
- package/dist/react/index.cjs +95 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +5 -0
- 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.cts +1 -0
- package/dist/react.d.ts +1 -1
- package/dist/react.js +5 -0
- package/dist/universal/index.cjs +81 -0
- package/dist/universal/index.d.ts +2 -0
- package/dist/{universal.esm.js → universal/index.js} +14 -10
- package/dist/universal.cjs +95 -0
- package/dist/universal.d.cts +1 -0
- package/dist/universal.d.ts +1 -1
- package/dist/universal.js +5 -0
- package/package.json +47 -21
- package/dist/babel.cjs.cjs +0 -54
- package/dist/babel.cjs.cjs.map +0 -1
- package/dist/babel.cjs.d.ts +0 -2
- package/dist/babel.esm.js +0 -52
- package/dist/babel.esm.js.map +0 -1
- package/dist/cli.cjs.cjs +0 -156
- package/dist/cli.cjs.cjs.map +0 -1
- package/dist/cli.cjs.d.ts +0 -1
- package/dist/cli.esm.js +0 -153
- package/dist/cli.esm.js.map +0 -1
- package/dist/constant.cjs.cjs +0 -6
- package/dist/constant.cjs.cjs.map +0 -1
- package/dist/constant.esm.js +0 -4
- package/dist/constant.esm.js.map +0 -1
- package/dist/index.cjs.cjs +0 -10
- package/dist/index.cjs.cjs.map +0 -1
- package/dist/index.cjs.d.ts +0 -1
- package/dist/index.cjs2.cjs +0 -8
- package/dist/index.cjs2.cjs.map +0 -1
- package/dist/index.esm.js +0 -3
- package/dist/index.esm.js.map +0 -1
- package/dist/index.esm2.js +0 -6
- package/dist/index.esm2.js.map +0 -1
- package/dist/plugin.cjs.cjs +0 -158
- package/dist/plugin.cjs.cjs.map +0 -1
- package/dist/plugin.cjs.d.ts +0 -2
- package/dist/plugin.esm.js +0 -153
- package/dist/plugin.esm.js.map +0 -1
- package/dist/prefetch.cjs.cjs +0 -182
- package/dist/prefetch.cjs.cjs.map +0 -1
- package/dist/prefetch.esm.js +0 -179
- package/dist/prefetch.esm.js.map +0 -1
- package/dist/react.cjs.cjs +0 -76
- package/dist/react.cjs.cjs.map +0 -1
- package/dist/react.cjs.d.ts +0 -1
- package/dist/react.esm.js.map +0 -1
- package/dist/runtime-utils.cjs.cjs +0 -29
- package/dist/runtime-utils.cjs.cjs.map +0 -1
- package/dist/runtime-utils.esm.js +0 -24
- package/dist/runtime-utils.esm.js.map +0 -1
- package/dist/universal.cjs.cjs +0 -30
- package/dist/universal.cjs.cjs.map +0 -1
- package/dist/universal.cjs.d.ts +0 -1
- package/dist/universal.esm.js.map +0 -1
- /package/dist/{src/cli/babel.d.ts → cli/babel.d.cts} +0 -0
- /package/dist/{src/cli/index.d.ts → cli/index.d.cts} +0 -0
- /package/dist/{src/common/constant.d.ts → common/constant.d.cts} +0 -0
- /package/dist/{src/common/index.d.ts → common/index.d.cts} +0 -0
- /package/dist/{src/common/node-utils.d.ts → common/node-utils.d.cts} +0 -0
- /package/dist/{src/common/runtime-utils.d.ts → common/runtime-utils.d.cts} +0 -0
- /package/dist/{src/constant.d.ts → constant.d.cts} +0 -0
- /package/dist/{src/index.d.ts → index.d.cts} +0 -0
- /package/dist/{src/logger/index.d.ts → logger/index.d.cts} +0 -0
- /package/dist/{src/prefetch.d.ts → prefetch.d.cts} +0 -0
- /package/dist/{src/react/hooks.d.ts → react/hooks.d.cts} +0 -0
- /package/dist/{src/react/index.d.ts → react/index.d.cts} +0 -0
- /package/dist/{src/react/utils.d.ts → react/utils.d.cts} +0 -0
- /package/dist/{src/universal/index.d.ts → universal/index.d.cts} +0 -0
package/dist/cli.esm.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import path from 'path';
|
|
2
|
-
import fs from 'fs-extra';
|
|
3
|
-
import { createInfrastructureLogger, createLogger, bindLoggerToCompiler, encodeName, MFPrefetchCommon } from '@module-federation/sdk';
|
|
4
|
-
import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';
|
|
5
|
-
import { b as getPrefetchId } from './runtime-utils.esm.js';
|
|
6
|
-
import { S as SHARED_STRATEGY } from './constant.esm.js';
|
|
7
|
-
|
|
8
|
-
const TEMP_DIR = '.mf';
|
|
9
|
-
|
|
10
|
-
const fileExistsWithCaseSync = (filepath) => {
|
|
11
|
-
const dir = path.dirname(filepath);
|
|
12
|
-
if (filepath === '/' || filepath === '.') {
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
const filenames = fs.readdirSync(dir);
|
|
16
|
-
if (filenames.indexOf(path.basename(filepath)) === -1) {
|
|
17
|
-
return false;
|
|
18
|
-
}
|
|
19
|
-
return fileExistsWithCaseSync(dir);
|
|
20
|
-
};
|
|
21
|
-
const fixPrefetchPath = (exposePath) => {
|
|
22
|
-
const pathExt = ['.js', '.ts'];
|
|
23
|
-
const extReg = /\.(ts|js|tsx|jsx)$/;
|
|
24
|
-
if (extReg.test(exposePath)) {
|
|
25
|
-
return pathExt.map((ext) => exposePath.replace(extReg, `.prefetch${ext}`));
|
|
26
|
-
}
|
|
27
|
-
else {
|
|
28
|
-
return pathExt.map((ext) => exposePath + `.prefetch${ext}`);
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const { RuntimeGlobals, Template } = require(normalizeWebpackPath('webpack'));
|
|
33
|
-
const createBundlerLogger = typeof createInfrastructureLogger === 'function'
|
|
34
|
-
? createInfrastructureLogger
|
|
35
|
-
: createLogger;
|
|
36
|
-
const logger = createBundlerLogger('[ Module Federation Data Prefetch Plugin ]');
|
|
37
|
-
function getFederationGlobalScope(runtimeGlobals) {
|
|
38
|
-
return `${runtimeGlobals.require || '__webpack_require__'}.federation`;
|
|
39
|
-
}
|
|
40
|
-
class PrefetchPlugin {
|
|
41
|
-
constructor(options) {
|
|
42
|
-
this.options = options;
|
|
43
|
-
this._reWriteExports = '';
|
|
44
|
-
}
|
|
45
|
-
apply(compiler) {
|
|
46
|
-
var _a;
|
|
47
|
-
bindLoggerToCompiler(logger, compiler, 'PrefetchPlugin');
|
|
48
|
-
const { name, exposes } = this.options;
|
|
49
|
-
if (!exposes) {
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
if (!compiler.options.context) {
|
|
53
|
-
throw new Error('compiler.options.context is not defined');
|
|
54
|
-
}
|
|
55
|
-
const { runtimePlugins } = this.options;
|
|
56
|
-
if (!Array.isArray(runtimePlugins)) {
|
|
57
|
-
this.options.runtimePlugins = [];
|
|
58
|
-
}
|
|
59
|
-
const runtimePath = path.resolve(__dirname, './plugin.esm.js');
|
|
60
|
-
if (!((_a = this.options.runtimePlugins) === null || _a === void 0 ? void 0 : _a.includes(runtimePath))) {
|
|
61
|
-
this.options.runtimePlugins.push(runtimePath);
|
|
62
|
-
}
|
|
63
|
-
if (this.options.shareStrategy !== SHARED_STRATEGY) {
|
|
64
|
-
this.options.shareStrategy = SHARED_STRATEGY;
|
|
65
|
-
logger.warn(`[Module Federation Data Prefetch]: Your shared strategy is set to '${SHARED_STRATEGY}', this is a necessary condition for data prefetch`);
|
|
66
|
-
}
|
|
67
|
-
const encodedName = encodeName(name);
|
|
68
|
-
const asyncEntryPath = path.resolve(compiler.options.context, `node_modules/${TEMP_DIR}/${encodedName}/bootstrap.js`);
|
|
69
|
-
if (fs.existsSync(asyncEntryPath)) {
|
|
70
|
-
fs.unlinkSync(asyncEntryPath);
|
|
71
|
-
}
|
|
72
|
-
if (!this.options.dataPrefetch) {
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
const exposeAlias = Object.keys(exposes);
|
|
76
|
-
exposeAlias.forEach((alias) => {
|
|
77
|
-
let exposePath;
|
|
78
|
-
const exposeValue = exposes[alias];
|
|
79
|
-
if (typeof exposeValue === 'string') {
|
|
80
|
-
exposePath = exposeValue;
|
|
81
|
-
}
|
|
82
|
-
else {
|
|
83
|
-
exposePath = exposeValue.import[0];
|
|
84
|
-
}
|
|
85
|
-
const targetPaths = fixPrefetchPath(exposePath);
|
|
86
|
-
for (const pathItem of targetPaths) {
|
|
87
|
-
const absolutePath = path.resolve(compiler.options.context, pathItem);
|
|
88
|
-
if (fileExistsWithCaseSync(absolutePath)) {
|
|
89
|
-
const absoluteAlias = alias.replace('.', '');
|
|
90
|
-
this._reWriteExports += `export * as ${getPrefetchId(`${name}${absoluteAlias}`)} from '${absolutePath}';\n`;
|
|
91
|
-
break;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
if (!this._reWriteExports) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
const tempDirRealPath = path.resolve(compiler.options.context, 'node_modules', TEMP_DIR);
|
|
99
|
-
if (!fs.existsSync(tempDirRealPath)) {
|
|
100
|
-
fs.mkdirSync(tempDirRealPath);
|
|
101
|
-
}
|
|
102
|
-
if (!fs.existsSync(`${tempDirRealPath}/${encodedName}`)) {
|
|
103
|
-
fs.mkdirSync(`${tempDirRealPath}/${encodedName}`);
|
|
104
|
-
}
|
|
105
|
-
fs.writeFileSync(asyncEntryPath, this._reWriteExports);
|
|
106
|
-
new compiler.webpack.DefinePlugin({
|
|
107
|
-
FederationDataPrefetch: JSON.stringify(asyncEntryPath),
|
|
108
|
-
}).apply(compiler);
|
|
109
|
-
}
|
|
110
|
-
static addRuntime(compiler, options) {
|
|
111
|
-
const encodedName = encodeName(options.name);
|
|
112
|
-
if (!compiler.options.context) {
|
|
113
|
-
throw new Error('compiler.options.context is not defined');
|
|
114
|
-
}
|
|
115
|
-
const prefetchEntry = path.resolve(compiler.options.context, `node_modules/.mf/${encodedName}/bootstrap.js`);
|
|
116
|
-
const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});
|
|
117
|
-
return Template.asString([
|
|
118
|
-
fs.existsSync(prefetchEntry)
|
|
119
|
-
? Template.indent([
|
|
120
|
-
'function injectPrefetch() {',
|
|
121
|
-
Template.indent([
|
|
122
|
-
`globalThis.__FEDERATION__ = globalThis.__FEDERATION__ || {};`,
|
|
123
|
-
`globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}'] = globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}'] || {`,
|
|
124
|
-
`entryLoading: {},`,
|
|
125
|
-
`instance: new Map(),`,
|
|
126
|
-
`__PREFETCH_EXPORTS__: {},`,
|
|
127
|
-
`};`,
|
|
128
|
-
`globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}'] = globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}'] || {};`,
|
|
129
|
-
`globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}']['${options.name}'] = function(){ return import('${prefetchEntry}');}`,
|
|
130
|
-
]),
|
|
131
|
-
'}',
|
|
132
|
-
`${federationGlobal}.prefetch = injectPrefetch`,
|
|
133
|
-
])
|
|
134
|
-
: '',
|
|
135
|
-
Template.indent([
|
|
136
|
-
`if(!${federationGlobal}.isMFRemote && ${federationGlobal}.prefetch){`,
|
|
137
|
-
`${federationGlobal}.prefetch()`,
|
|
138
|
-
'}',
|
|
139
|
-
]),
|
|
140
|
-
]);
|
|
141
|
-
}
|
|
142
|
-
static setRemoteIdentifier() {
|
|
143
|
-
const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});
|
|
144
|
-
return Template.indent([`${federationGlobal}.isMFRemote = true;`]);
|
|
145
|
-
}
|
|
146
|
-
static removeRemoteIdentifier() {
|
|
147
|
-
const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});
|
|
148
|
-
return Template.indent([`${federationGlobal}.isMFRemote = false;`]);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export { PrefetchPlugin, getFederationGlobalScope };
|
|
153
|
-
//# sourceMappingURL=cli.esm.js.map
|
package/dist/cli.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.esm.js","sources":["../src/common/constant.ts","../src/common/node-utils.ts","../src/cli/index.ts"],"sourcesContent":["export const TEMP_DIR = '.mf';\n","import path from 'path';\nimport fs from 'fs-extra';\nexport const fileExistsWithCaseSync = (filepath) => {\n const dir = path.dirname(filepath);\n if (filepath === '/' || filepath === '.') {\n return true;\n }\n const filenames = fs.readdirSync(dir);\n if (filenames.indexOf(path.basename(filepath)) === -1) {\n return false;\n }\n return fileExistsWithCaseSync(dir);\n};\nexport const fixPrefetchPath = (exposePath) => {\n const pathExt = ['.js', '.ts'];\n const extReg = /\\.(ts|js|tsx|jsx)$/;\n if (extReg.test(exposePath)) {\n return pathExt.map((ext) => exposePath.replace(extReg, `.prefetch${ext}`));\n }\n else {\n return pathExt.map((ext) => exposePath + `.prefetch${ext}`);\n }\n};\n","import path from 'path';\nimport fs from 'fs-extra';\nimport { bindLoggerToCompiler, createInfrastructureLogger, createLogger, encodeName, MFPrefetchCommon, } from '@module-federation/sdk';\nimport { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';\nimport { TEMP_DIR } from '../common/constant';\nimport { fileExistsWithCaseSync, fixPrefetchPath } from '../common/node-utils';\nimport { getPrefetchId } from '../common/runtime-utils';\nimport { SHARED_STRATEGY } from '../constant';\nconst { RuntimeGlobals, Template } = require(normalizeWebpackPath('webpack'));\nconst createBundlerLogger = typeof createInfrastructureLogger === 'function'\n ? createInfrastructureLogger\n : createLogger;\nconst logger = createBundlerLogger('[ Module Federation Data Prefetch Plugin ]');\nexport function getFederationGlobalScope(runtimeGlobals) {\n return `${runtimeGlobals.require || '__webpack_require__'}.federation`;\n}\nexport class PrefetchPlugin {\n constructor(options) {\n this.options = options;\n this._reWriteExports = '';\n }\n apply(compiler) {\n var _a;\n bindLoggerToCompiler(logger, compiler, 'PrefetchPlugin');\n const { name, exposes } = this.options;\n if (!exposes) {\n return;\n }\n if (!compiler.options.context) {\n throw new Error('compiler.options.context is not defined');\n }\n const { runtimePlugins } = this.options;\n if (!Array.isArray(runtimePlugins)) {\n this.options.runtimePlugins = [];\n }\n const runtimePath = path.resolve(__dirname, './plugin.esm.js');\n if (!((_a = this.options.runtimePlugins) === null || _a === void 0 ? void 0 : _a.includes(runtimePath))) {\n this.options.runtimePlugins.push(runtimePath);\n }\n if (this.options.shareStrategy !== SHARED_STRATEGY) {\n this.options.shareStrategy = SHARED_STRATEGY;\n logger.warn(`[Module Federation Data Prefetch]: Your shared strategy is set to '${SHARED_STRATEGY}', this is a necessary condition for data prefetch`);\n }\n const encodedName = encodeName(name);\n const asyncEntryPath = path.resolve(compiler.options.context, `node_modules/${TEMP_DIR}/${encodedName}/bootstrap.js`);\n if (fs.existsSync(asyncEntryPath)) {\n fs.unlinkSync(asyncEntryPath);\n }\n if (!this.options.dataPrefetch) {\n return;\n }\n const prefetchs = [];\n const exposeAlias = Object.keys(exposes);\n exposeAlias.forEach((alias) => {\n let exposePath;\n const exposeValue = exposes[alias];\n if (typeof exposeValue === 'string') {\n exposePath = exposeValue;\n }\n else {\n exposePath = exposeValue.import[0];\n }\n const targetPaths = fixPrefetchPath(exposePath);\n for (const pathItem of targetPaths) {\n const absolutePath = path.resolve(compiler.options.context, pathItem);\n if (fileExistsWithCaseSync(absolutePath)) {\n prefetchs.push(pathItem);\n const absoluteAlias = alias.replace('.', '');\n this._reWriteExports += `export * as ${getPrefetchId(`${name}${absoluteAlias}`)} from '${absolutePath}';\\n`;\n break;\n }\n }\n });\n if (!this._reWriteExports) {\n return;\n }\n const tempDirRealPath = path.resolve(compiler.options.context, 'node_modules', TEMP_DIR);\n if (!fs.existsSync(tempDirRealPath)) {\n fs.mkdirSync(tempDirRealPath);\n }\n if (!fs.existsSync(`${tempDirRealPath}/${encodedName}`)) {\n fs.mkdirSync(`${tempDirRealPath}/${encodedName}`);\n }\n fs.writeFileSync(asyncEntryPath, this._reWriteExports);\n new compiler.webpack.DefinePlugin({\n FederationDataPrefetch: JSON.stringify(asyncEntryPath),\n }).apply(compiler);\n }\n static addRuntime(compiler, options) {\n const encodedName = encodeName(options.name);\n if (!compiler.options.context) {\n throw new Error('compiler.options.context is not defined');\n }\n const prefetchEntry = path.resolve(compiler.options.context, `node_modules/.mf/${encodedName}/bootstrap.js`);\n const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});\n return Template.asString([\n fs.existsSync(prefetchEntry)\n ? Template.indent([\n 'function injectPrefetch() {',\n Template.indent([\n `globalThis.__FEDERATION__ = globalThis.__FEDERATION__ || {};`,\n `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}'] = globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}'] || {`,\n `entryLoading: {},`,\n `instance: new Map(),`,\n `__PREFETCH_EXPORTS__: {},`,\n `};`,\n `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}'] = globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}'] || {};`,\n `globalThis.__FEDERATION__['${MFPrefetchCommon.globalKey}']['${MFPrefetchCommon.exportsKey}']['${options.name}'] = function(){ return import('${prefetchEntry}');}`,\n ]),\n '}',\n `${federationGlobal}.prefetch = injectPrefetch`,\n ])\n : '',\n Template.indent([\n `if(!${federationGlobal}.isMFRemote && ${federationGlobal}.prefetch){`,\n `${federationGlobal}.prefetch()`,\n '}',\n ]),\n ]);\n }\n static setRemoteIdentifier() {\n const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});\n return Template.indent([`${federationGlobal}.isMFRemote = true;`]);\n }\n static removeRemoteIdentifier() {\n const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});\n return Template.indent([`${federationGlobal}.isMFRemote = false;`]);\n }\n}\n"],"names":[],"mappings":";;;;;;;AAAO,MAAM,QAAQ,GAAG,KAAK;;ACEtB,MAAM,sBAAsB,GAAG,CAAC,QAAQ,KAAK;AACpD,IAAI,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;AACtC,IAAI,IAAI,QAAQ,KAAK,GAAG,IAAI,QAAQ,KAAK,GAAG,EAAE;AAC9C,QAAQ,OAAO,IAAI;AACnB,IAAI;AACJ,IAAI,MAAM,SAAS,GAAG,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CAAC,WAAW,CAAC;AACtF,gBAAgB,CAAC,EAAE,gBAAgB,CAAC,WAAW,CAAC;AAChD,gBAAgB,GAAG;AACnB,aAAa,CAAC;AACd,SAAS,CAAC;AACV,IAAI;AACJ,IAAI,OAAO,mBAAmB,GAAG;AACjC,QAAQ,MAAM,gBAAgB,GAAG,wBAAwB,CAAC,cAAc,IAAI,EAAE,CAAC;AAC/E,QAAQ,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC,mBAAmB,CAAC,CAAC,CAAC;AAC1E,IAAI;AACJ,IAAI,OAAO,sBAAsB,GAAG;AACpC,QAAQ,MAAM,gBAAgB,GAAG,wBAAwB,CAAC,cAAc,IAAI,EAAE,CAAC;AAC/E,QAAQ,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC,oBAAoB,CAAC,CAAC,CAAC;AAC3E,IAAI;AACJ;;;;"}
|
package/dist/constant.cjs.cjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constant.cjs.cjs","sources":["../src/constant.ts"],"sourcesContent":["export const SHARED_STRATEGY = 'loaded-first';\n"],"names":[],"mappings":";;AAAY,MAAC,eAAe,GAAG;;;;"}
|
package/dist/constant.esm.js
DELETED
package/dist/constant.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"constant.esm.js","sources":["../src/constant.ts"],"sourcesContent":["export const SHARED_STRATEGY = 'loaded-first';\n"],"names":[],"mappings":"AAAY,MAAC,eAAe,GAAG;;;;"}
|
package/dist/index.cjs.cjs
DELETED
package/dist/index.cjs.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;"}
|
package/dist/index.cjs.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./src/index";
|
package/dist/index.cjs2.cjs
DELETED
package/dist/index.cjs2.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs2.cjs","sources":["../src/logger/index.ts"],"sourcesContent":["import { createLogger } from '@module-federation/sdk';\nconst logger = createLogger('[ Module Federation Data Prefetch ]');\nexport default logger;\n"],"names":["createLogger"],"mappings":";;;;AACK,MAAC,MAAM,GAAGA,gBAAY,CAAC,qCAAqC;;;;"}
|
package/dist/index.esm.js
DELETED
package/dist/index.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
package/dist/index.esm2.js
DELETED
package/dist/index.esm2.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm2.js","sources":["../src/logger/index.ts"],"sourcesContent":["import { createLogger } from '@module-federation/sdk';\nconst logger = createLogger('[ Module Federation Data Prefetch ]');\nexport default logger;\n"],"names":[],"mappings":";;AACK,MAAC,MAAM,GAAG,YAAY,CAAC,qCAAqC;;;;"}
|
package/dist/plugin.cjs.cjs
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var prefetch = require('./prefetch.cjs.cjs');
|
|
6
|
-
var sdk = require('@module-federation/sdk');
|
|
7
|
-
var runtimeUtils = require('./runtime-utils.cjs.cjs');
|
|
8
|
-
var index = require('./index.cjs2.cjs');
|
|
9
|
-
var constant = require('./constant.cjs.cjs');
|
|
10
|
-
|
|
11
|
-
const loadingArray = [];
|
|
12
|
-
let sharedFlag = constant.SHARED_STRATEGY;
|
|
13
|
-
const prefetchPlugin = () => ({
|
|
14
|
-
name: 'data-prefetch-runtime-plugin',
|
|
15
|
-
initContainer(options) {
|
|
16
|
-
const { remoteSnapshot, remoteInfo, id, origin } = options;
|
|
17
|
-
if (!id) {
|
|
18
|
-
return options;
|
|
19
|
-
}
|
|
20
|
-
const snapshot = remoteSnapshot;
|
|
21
|
-
const { name } = remoteInfo;
|
|
22
|
-
const prefetchOptions = {
|
|
23
|
-
name,
|
|
24
|
-
remote: remoteInfo,
|
|
25
|
-
origin,
|
|
26
|
-
remoteSnapshot: snapshot,
|
|
27
|
-
};
|
|
28
|
-
const signal = runtimeUtils.getSignalFromManifest(snapshot);
|
|
29
|
-
if (!signal) {
|
|
30
|
-
return options;
|
|
31
|
-
}
|
|
32
|
-
if (sharedFlag !== constant.SHARED_STRATEGY) {
|
|
33
|
-
throw new Error(`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`);
|
|
34
|
-
}
|
|
35
|
-
const instance = prefetch.MFDataPrefetch.getInstance(name) || new prefetch.MFDataPrefetch(prefetchOptions);
|
|
36
|
-
let prefetchUrl;
|
|
37
|
-
if (snapshot.prefetchEntry) {
|
|
38
|
-
prefetchUrl = sdk.getResourceUrl(snapshot, snapshot.prefetchEntry);
|
|
39
|
-
}
|
|
40
|
-
const exist = loadingArray.find((loading) => loading.id === id);
|
|
41
|
-
if (exist) {
|
|
42
|
-
return options;
|
|
43
|
-
}
|
|
44
|
-
const promise = instance.loadEntry(prefetchUrl).then(() => prefetch.__awaiter(this, void 0, void 0, function* () {
|
|
45
|
-
const projectExports = instance.getProjectExports();
|
|
46
|
-
if (projectExports instanceof Promise) {
|
|
47
|
-
yield projectExports;
|
|
48
|
-
}
|
|
49
|
-
return Promise.resolve().then(() => {
|
|
50
|
-
const exports$1 = instance.getExposeExports(id);
|
|
51
|
-
index.logger.info(`1. Start Prefetch initContainer: ${id} - ${performance.now()}`);
|
|
52
|
-
const result = Object.keys(exports$1).map((k) => {
|
|
53
|
-
const value = instance.prefetch({
|
|
54
|
-
id,
|
|
55
|
-
functionId: k,
|
|
56
|
-
});
|
|
57
|
-
const functionId = k;
|
|
58
|
-
return {
|
|
59
|
-
value,
|
|
60
|
-
functionId,
|
|
61
|
-
};
|
|
62
|
-
});
|
|
63
|
-
return result;
|
|
64
|
-
});
|
|
65
|
-
}));
|
|
66
|
-
loadingArray.push({
|
|
67
|
-
id,
|
|
68
|
-
promise,
|
|
69
|
-
});
|
|
70
|
-
return options;
|
|
71
|
-
},
|
|
72
|
-
afterResolve(options) {
|
|
73
|
-
const { remoteSnapshot, remoteInfo, id, origin } = options;
|
|
74
|
-
const snapshot = remoteSnapshot;
|
|
75
|
-
const { name } = remoteInfo;
|
|
76
|
-
const prefetchOptions = {
|
|
77
|
-
name,
|
|
78
|
-
remote: remoteInfo,
|
|
79
|
-
origin,
|
|
80
|
-
remoteSnapshot: snapshot,
|
|
81
|
-
};
|
|
82
|
-
const signal = runtimeUtils.getSignalFromManifest(snapshot);
|
|
83
|
-
if (!signal) {
|
|
84
|
-
return options;
|
|
85
|
-
}
|
|
86
|
-
const inited = loadingArray.some((info) => info.id === id);
|
|
87
|
-
if (!inited) {
|
|
88
|
-
return options;
|
|
89
|
-
}
|
|
90
|
-
if (sharedFlag !== constant.SHARED_STRATEGY) {
|
|
91
|
-
throw new Error(`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`);
|
|
92
|
-
}
|
|
93
|
-
const instance = prefetch.MFDataPrefetch.getInstance(name) || new prefetch.MFDataPrefetch(prefetchOptions);
|
|
94
|
-
let prefetchUrl;
|
|
95
|
-
if (snapshot.prefetchEntry) {
|
|
96
|
-
prefetchUrl = sdk.getResourceUrl(snapshot, snapshot.prefetchEntry);
|
|
97
|
-
}
|
|
98
|
-
const index$1 = loadingArray.findIndex((loading) => loading.id === id);
|
|
99
|
-
if (index$1 !== -1) {
|
|
100
|
-
loadingArray.splice(index$1, 1);
|
|
101
|
-
}
|
|
102
|
-
const promise = instance.loadEntry(prefetchUrl).then(() => prefetch.__awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
const projectExports = instance.getProjectExports();
|
|
104
|
-
if (projectExports instanceof Promise) {
|
|
105
|
-
yield projectExports;
|
|
106
|
-
}
|
|
107
|
-
return Promise.resolve().then(() => {
|
|
108
|
-
const exports$1 = instance.getExposeExports(id);
|
|
109
|
-
index.logger.info(`1. Start Prefetch afterResolve: ${id} - ${performance.now()}`);
|
|
110
|
-
const result = Object.keys(exports$1).map((k) => {
|
|
111
|
-
const value = instance.prefetch({
|
|
112
|
-
id,
|
|
113
|
-
functionId: k,
|
|
114
|
-
});
|
|
115
|
-
const functionId = k;
|
|
116
|
-
return {
|
|
117
|
-
value,
|
|
118
|
-
functionId,
|
|
119
|
-
};
|
|
120
|
-
});
|
|
121
|
-
return result;
|
|
122
|
-
});
|
|
123
|
-
}));
|
|
124
|
-
loadingArray.push({
|
|
125
|
-
id,
|
|
126
|
-
promise,
|
|
127
|
-
});
|
|
128
|
-
return options;
|
|
129
|
-
},
|
|
130
|
-
onLoad(options) {
|
|
131
|
-
return prefetch.__awaiter(this, void 0, void 0, function* () {
|
|
132
|
-
var _a;
|
|
133
|
-
const { remote, id } = options;
|
|
134
|
-
const { name } = remote;
|
|
135
|
-
const promise = (_a = loadingArray.find((loading) => loading.id === id)) === null || _a === void 0 ? void 0 : _a.promise;
|
|
136
|
-
if (promise) {
|
|
137
|
-
const prefetch$1 = yield promise;
|
|
138
|
-
const prefetchValue = prefetch$1.map((result) => result.value);
|
|
139
|
-
yield Promise.all(prefetchValue);
|
|
140
|
-
const instance = prefetch.MFDataPrefetch.getInstance(name);
|
|
141
|
-
prefetch$1.forEach((result) => {
|
|
142
|
-
const { value, functionId } = result;
|
|
143
|
-
instance.memorize(id + functionId, value);
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
return options;
|
|
147
|
-
});
|
|
148
|
-
},
|
|
149
|
-
beforeLoadShare(options) {
|
|
150
|
-
const shareInfo = options.shareInfo;
|
|
151
|
-
sharedFlag = (shareInfo === null || shareInfo === void 0 ? void 0 : shareInfo.strategy) || sharedFlag;
|
|
152
|
-
return options;
|
|
153
|
-
},
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
exports.default = prefetchPlugin;
|
|
157
|
-
exports.prefetchPlugin = prefetchPlugin;
|
|
158
|
-
//# sourceMappingURL=plugin.cjs.cjs.map
|
package/dist/plugin.cjs.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.cjs","sources":["../src/plugin.ts"],"sourcesContent":["import { __awaiter } from \"tslib\";\nimport { getResourceUrl } from '@module-federation/sdk';\nimport { getSignalFromManifest } from './common/runtime-utils';\nimport { MFDataPrefetch } from './prefetch';\nimport logger from './logger';\nimport { SHARED_STRATEGY } from './constant';\nconst loadingArray = [];\nlet sharedFlag = SHARED_STRATEGY;\nexport const prefetchPlugin = () => ({\n name: 'data-prefetch-runtime-plugin',\n initContainer(options) {\n const { remoteSnapshot, remoteInfo, id, origin } = options;\n if (!id) {\n return options;\n }\n const snapshot = remoteSnapshot;\n const { name } = remoteInfo;\n const prefetchOptions = {\n name,\n remote: remoteInfo,\n origin,\n remoteSnapshot: snapshot,\n };\n const signal = getSignalFromManifest(snapshot);\n if (!signal) {\n return options;\n }\n if (sharedFlag !== SHARED_STRATEGY) {\n throw new Error(`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`);\n }\n const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);\n let prefetchUrl;\n if (snapshot.prefetchEntry) {\n prefetchUrl = getResourceUrl(snapshot, snapshot.prefetchEntry);\n }\n const exist = loadingArray.find((loading) => loading.id === id);\n if (exist) {\n return options;\n }\n const promise = instance.loadEntry(prefetchUrl).then(() => __awaiter(this, void 0, void 0, function* () {\n const projectExports = instance.getProjectExports();\n if (projectExports instanceof Promise) {\n yield projectExports;\n }\n return Promise.resolve().then(() => {\n const exports = instance.getExposeExports(id);\n logger.info(`1. Start Prefetch initContainer: ${id} - ${performance.now()}`);\n const result = Object.keys(exports).map((k) => {\n const value = instance.prefetch({\n id,\n functionId: k,\n });\n const functionId = k;\n return {\n value,\n functionId,\n };\n });\n return result;\n });\n }));\n loadingArray.push({\n id,\n promise,\n });\n return options;\n },\n afterResolve(options) {\n const { remoteSnapshot, remoteInfo, id, origin } = options;\n const snapshot = remoteSnapshot;\n const { name } = remoteInfo;\n const prefetchOptions = {\n name,\n remote: remoteInfo,\n origin,\n remoteSnapshot: snapshot,\n };\n const signal = getSignalFromManifest(snapshot);\n if (!signal) {\n return options;\n }\n const inited = loadingArray.some((info) => info.id === id);\n if (!inited) {\n return options;\n }\n if (sharedFlag !== SHARED_STRATEGY) {\n throw new Error(`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`);\n }\n const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);\n let prefetchUrl;\n if (snapshot.prefetchEntry) {\n prefetchUrl = getResourceUrl(snapshot, snapshot.prefetchEntry);\n }\n const index = loadingArray.findIndex((loading) => loading.id === id);\n if (index !== -1) {\n loadingArray.splice(index, 1);\n }\n const promise = instance.loadEntry(prefetchUrl).then(() => __awaiter(this, void 0, void 0, function* () {\n const projectExports = instance.getProjectExports();\n if (projectExports instanceof Promise) {\n yield projectExports;\n }\n return Promise.resolve().then(() => {\n const exports = instance.getExposeExports(id);\n logger.info(`1. Start Prefetch afterResolve: ${id} - ${performance.now()}`);\n const result = Object.keys(exports).map((k) => {\n const value = instance.prefetch({\n id,\n functionId: k,\n });\n const functionId = k;\n return {\n value,\n functionId,\n };\n });\n return result;\n });\n }));\n loadingArray.push({\n id,\n promise,\n });\n return options;\n },\n onLoad(options) {\n return __awaiter(this, void 0, void 0, function* () {\n var _a;\n const { remote, id } = options;\n const { name } = remote;\n const promise = (_a = loadingArray.find((loading) => loading.id === id)) === null || _a === void 0 ? void 0 : _a.promise;\n if (promise) {\n const prefetch = yield promise;\n const prefetchValue = prefetch.map((result) => result.value);\n yield Promise.all(prefetchValue);\n const instance = MFDataPrefetch.getInstance(name);\n prefetch.forEach((result) => {\n const { value, functionId } = result;\n instance.memorize(id + functionId, value);\n });\n }\n return options;\n });\n },\n beforeLoadShare(options) {\n const shareInfo = options.shareInfo;\n sharedFlag = (shareInfo === null || shareInfo === void 0 ? void 0 : shareInfo.strategy) || sharedFlag;\n return options;\n },\n});\nexport default prefetchPlugin;\n"],"names":["SHARED_STRATEGY","getSignalFromManifest","MFDataPrefetch","getResourceUrl","__awaiter","exports","logger","index","prefetch"],"mappings":";;;;;;;;;;AAMA,MAAM,YAAY,GAAG,EAAE;AACvB,IAAI,UAAU,GAAGA,wBAAe;AACpB,MAAC,cAAc,GAAG,OAAO;AACrC,IAAI,IAAI,EAAE,8BAA8B;AACxC,IAAI,aAAa,CAAC,OAAO,EAAE;AAC3B,QAAQ,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,OAAO;AAClE,QAAQ,IAAI,CAAC,EAAE,EAAE;AACjB,YAAY,OAAO,OAAO;AAC1B,QAAQ;AACR,QAAQ,MAAM,QAAQ,GAAG,cAAc;AACvC,QAAQ,MAAM,EAAE,IAAI,EAAE,GAAG,UAAU;AACnC,QAAQ,MAAM,eAAe,GAAG;AAChC,YAAY,IAAI;AAChB,YAAY,MAAM,EAAE,UAAU;AAC9B,YAAY,MAAM;AAClB,YAAY,cAAc,EAAE,QAAQ;AACpC,SAAS;AACT,QAAQ,MAAM,MAAM,GAAGC,kCAAqB,CAAC,QAAQ,CAAC;AACtD,QAAQ,IAAI,CAAC,MAAM,EAAE;AACrB,YAAY,OAAO,OAAO;AAC1B,QAAQ;AACR,QAAQ,IAAI,UAAU,KAAKD,wBAAe,EAAE;AAC5C,YAAY,MAAM,IAAI,KAAK,CAAC,CAAC,+GAA+G,CAAC,CAAC;AAC9I,QAAQ;AACR,QAAQ,MAAM,QAAQ,GAAGE,uBAAc,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,IAAIA,uBAAc,CAAC,eAAe,CAAC;AAChG,QAAQ,IAAI,WAAW;AACvB,Q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,QAAQ,CAAC,CAAC;AACV,IAAI,CAAC;AACL,IAAI,eAAe,CAAC,OAAO,EAAE;AAC7B,QAAQ,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS;AAC3C,QAAQ,UAAU,GAAG,CAAC,SAAS,KAAK,IAAI,IAAI,SAAS,KAAK,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,QAAQ,KAAK,UAAU;AAC7G,QAAQ,OAAO,OAAO;AACtB,IAAI,CAAC;AACL,CAAC;;;;;"}
|
package/dist/plugin.cjs.d.ts
DELETED
package/dist/plugin.esm.js
DELETED
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
import { _ as __awaiter, M as MFDataPrefetch } from './prefetch.esm.js';
|
|
2
|
-
import { getResourceUrl } from '@module-federation/sdk';
|
|
3
|
-
import { a as getSignalFromManifest } from './runtime-utils.esm.js';
|
|
4
|
-
import { l as logger } from './index.esm2.js';
|
|
5
|
-
import { S as SHARED_STRATEGY } from './constant.esm.js';
|
|
6
|
-
|
|
7
|
-
const loadingArray = [];
|
|
8
|
-
let sharedFlag = SHARED_STRATEGY;
|
|
9
|
-
const prefetchPlugin = () => ({
|
|
10
|
-
name: 'data-prefetch-runtime-plugin',
|
|
11
|
-
initContainer(options) {
|
|
12
|
-
const { remoteSnapshot, remoteInfo, id, origin } = options;
|
|
13
|
-
if (!id) {
|
|
14
|
-
return options;
|
|
15
|
-
}
|
|
16
|
-
const snapshot = remoteSnapshot;
|
|
17
|
-
const { name } = remoteInfo;
|
|
18
|
-
const prefetchOptions = {
|
|
19
|
-
name,
|
|
20
|
-
remote: remoteInfo,
|
|
21
|
-
origin,
|
|
22
|
-
remoteSnapshot: snapshot,
|
|
23
|
-
};
|
|
24
|
-
const signal = getSignalFromManifest(snapshot);
|
|
25
|
-
if (!signal) {
|
|
26
|
-
return options;
|
|
27
|
-
}
|
|
28
|
-
if (sharedFlag !== SHARED_STRATEGY) {
|
|
29
|
-
throw new Error(`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`);
|
|
30
|
-
}
|
|
31
|
-
const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);
|
|
32
|
-
let prefetchUrl;
|
|
33
|
-
if (snapshot.prefetchEntry) {
|
|
34
|
-
prefetchUrl = getResourceUrl(snapshot, snapshot.prefetchEntry);
|
|
35
|
-
}
|
|
36
|
-
const exist = loadingArray.find((loading) => loading.id === id);
|
|
37
|
-
if (exist) {
|
|
38
|
-
return options;
|
|
39
|
-
}
|
|
40
|
-
const promise = instance.loadEntry(prefetchUrl).then(() => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
const projectExports = instance.getProjectExports();
|
|
42
|
-
if (projectExports instanceof Promise) {
|
|
43
|
-
yield projectExports;
|
|
44
|
-
}
|
|
45
|
-
return Promise.resolve().then(() => {
|
|
46
|
-
const exports$1 = instance.getExposeExports(id);
|
|
47
|
-
logger.info(`1. Start Prefetch initContainer: ${id} - ${performance.now()}`);
|
|
48
|
-
const result = Object.keys(exports$1).map((k) => {
|
|
49
|
-
const value = instance.prefetch({
|
|
50
|
-
id,
|
|
51
|
-
functionId: k,
|
|
52
|
-
});
|
|
53
|
-
const functionId = k;
|
|
54
|
-
return {
|
|
55
|
-
value,
|
|
56
|
-
functionId,
|
|
57
|
-
};
|
|
58
|
-
});
|
|
59
|
-
return result;
|
|
60
|
-
});
|
|
61
|
-
}));
|
|
62
|
-
loadingArray.push({
|
|
63
|
-
id,
|
|
64
|
-
promise,
|
|
65
|
-
});
|
|
66
|
-
return options;
|
|
67
|
-
},
|
|
68
|
-
afterResolve(options) {
|
|
69
|
-
const { remoteSnapshot, remoteInfo, id, origin } = options;
|
|
70
|
-
const snapshot = remoteSnapshot;
|
|
71
|
-
const { name } = remoteInfo;
|
|
72
|
-
const prefetchOptions = {
|
|
73
|
-
name,
|
|
74
|
-
remote: remoteInfo,
|
|
75
|
-
origin,
|
|
76
|
-
remoteSnapshot: snapshot,
|
|
77
|
-
};
|
|
78
|
-
const signal = getSignalFromManifest(snapshot);
|
|
79
|
-
if (!signal) {
|
|
80
|
-
return options;
|
|
81
|
-
}
|
|
82
|
-
const inited = loadingArray.some((info) => info.id === id);
|
|
83
|
-
if (!inited) {
|
|
84
|
-
return options;
|
|
85
|
-
}
|
|
86
|
-
if (sharedFlag !== SHARED_STRATEGY) {
|
|
87
|
-
throw new Error(`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`);
|
|
88
|
-
}
|
|
89
|
-
const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);
|
|
90
|
-
let prefetchUrl;
|
|
91
|
-
if (snapshot.prefetchEntry) {
|
|
92
|
-
prefetchUrl = getResourceUrl(snapshot, snapshot.prefetchEntry);
|
|
93
|
-
}
|
|
94
|
-
const index = loadingArray.findIndex((loading) => loading.id === id);
|
|
95
|
-
if (index !== -1) {
|
|
96
|
-
loadingArray.splice(index, 1);
|
|
97
|
-
}
|
|
98
|
-
const promise = instance.loadEntry(prefetchUrl).then(() => __awaiter(this, void 0, void 0, function* () {
|
|
99
|
-
const projectExports = instance.getProjectExports();
|
|
100
|
-
if (projectExports instanceof Promise) {
|
|
101
|
-
yield projectExports;
|
|
102
|
-
}
|
|
103
|
-
return Promise.resolve().then(() => {
|
|
104
|
-
const exports$1 = instance.getExposeExports(id);
|
|
105
|
-
logger.info(`1. Start Prefetch afterResolve: ${id} - ${performance.now()}`);
|
|
106
|
-
const result = Object.keys(exports$1).map((k) => {
|
|
107
|
-
const value = instance.prefetch({
|
|
108
|
-
id,
|
|
109
|
-
functionId: k,
|
|
110
|
-
});
|
|
111
|
-
const functionId = k;
|
|
112
|
-
return {
|
|
113
|
-
value,
|
|
114
|
-
functionId,
|
|
115
|
-
};
|
|
116
|
-
});
|
|
117
|
-
return result;
|
|
118
|
-
});
|
|
119
|
-
}));
|
|
120
|
-
loadingArray.push({
|
|
121
|
-
id,
|
|
122
|
-
promise,
|
|
123
|
-
});
|
|
124
|
-
return options;
|
|
125
|
-
},
|
|
126
|
-
onLoad(options) {
|
|
127
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
-
var _a;
|
|
129
|
-
const { remote, id } = options;
|
|
130
|
-
const { name } = remote;
|
|
131
|
-
const promise = (_a = loadingArray.find((loading) => loading.id === id)) === null || _a === void 0 ? void 0 : _a.promise;
|
|
132
|
-
if (promise) {
|
|
133
|
-
const prefetch = yield promise;
|
|
134
|
-
const prefetchValue = prefetch.map((result) => result.value);
|
|
135
|
-
yield Promise.all(prefetchValue);
|
|
136
|
-
const instance = MFDataPrefetch.getInstance(name);
|
|
137
|
-
prefetch.forEach((result) => {
|
|
138
|
-
const { value, functionId } = result;
|
|
139
|
-
instance.memorize(id + functionId, value);
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
return options;
|
|
143
|
-
});
|
|
144
|
-
},
|
|
145
|
-
beforeLoadShare(options) {
|
|
146
|
-
const shareInfo = options.shareInfo;
|
|
147
|
-
sharedFlag = (shareInfo === null || shareInfo === void 0 ? void 0 : shareInfo.strategy) || sharedFlag;
|
|
148
|
-
return options;
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
export { prefetchPlugin as default, prefetchPlugin };
|
|
153
|
-
//# sourceMappingURL=plugin.esm.js.map
|
package/dist/plugin.esm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.esm.js","sources":["../src/plugin.ts"],"sourcesContent":["import { __awaiter } from \"tslib\";\nimport { getResourceUrl } from '@module-federation/sdk';\nimport { getSignalFromManifest } from './common/runtime-utils';\nimport { MFDataPrefetch } from './prefetch';\nimport logger from './logger';\nimport { SHARED_STRATEGY } from './constant';\nconst loadingArray = [];\nlet sharedFlag = SHARED_STRATEGY;\nexport const prefetchPlugin = () => ({\n name: 'data-prefetch-runtime-plugin',\n initContainer(options) {\n const { remoteSnapshot, remoteInfo, id, origin } = options;\n if (!id) {\n return options;\n }\n const snapshot = remoteSnapshot;\n const { name } = remoteInfo;\n const prefetchOptions = {\n name,\n remote: remoteInfo,\n origin,\n remoteSnapshot: snapshot,\n };\n const signal = getSignalFromManifest(snapshot);\n if (!signal) {\n return options;\n }\n if (sharedFlag !== SHARED_STRATEGY) {\n throw new Error(`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`);\n }\n const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);\n let prefetchUrl;\n if (snapshot.prefetchEntry) {\n prefetchUrl = getResourceUrl(snapshot, snapshot.prefetchEntry);\n }\n const exist = loadingArray.find((loading) => loading.id === id);\n if (exist) {\n return options;\n }\n const promise = instance.loadEntry(prefetchUrl).then(() => __awaiter(this, void 0, void 0, function* () {\n const projectExports = instance.getProjectExports();\n if (projectExports instanceof Promise) {\n yield projectExports;\n }\n return Promise.resolve().then(() => {\n const exports = instance.getExposeExports(id);\n logger.info(`1. Start Prefetch initContainer: ${id} - ${performance.now()}`);\n const result = Object.keys(exports).map((k) => {\n const value = instance.prefetch({\n id,\n functionId: k,\n });\n const functionId = k;\n return {\n value,\n functionId,\n };\n });\n return result;\n });\n }));\n loadingArray.push({\n id,\n promise,\n });\n return options;\n },\n afterResolve(options) {\n const { remoteSnapshot, remoteInfo, id, origin } = options;\n const snapshot = remoteSnapshot;\n const { name } = remoteInfo;\n const prefetchOptions = {\n name,\n remote: remoteInfo,\n origin,\n remoteSnapshot: snapshot,\n };\n const signal = getSignalFromManifest(snapshot);\n if (!signal) {\n return options;\n }\n const inited = loadingArray.some((info) => info.id === id);\n if (!inited) {\n return options;\n }\n if (sharedFlag !== SHARED_STRATEGY) {\n throw new Error(`[Module Federation Data Prefetch]: If you want to use data prefetch, the shared strategy must be 'loaded-first'`);\n }\n const instance = MFDataPrefetch.getInstance(name) || new MFDataPrefetch(prefetchOptions);\n let prefetchUrl;\n if (snapshot.prefetchEntry) {\n prefetchUrl = getResourceUrl(snapshot, snapshot.prefetchEntry);\n }\n const index = loadingArray.findIndex((loading) => loading.id === id);\n if (index !== -1) {\n loadingArray.splice(index, 1);\n }\n const promise = instance.loadEntry(prefetchUrl).then(() => __awaiter(this, void 0, void 0, function* () {\n const projectExports = instance.getProjectExports();\n if (projectExports instanceof Promise) {\n yield projectExports;\n }\n return Promise.resolve().then(() => {\n const exports = instance.getExposeExports(id);\n logger.info(`1. Start Prefetch afterResolve: ${id} - ${performance.now()}`);\n const result = Object.keys(exports).map((k) => {\n const value = instance.prefetch({\n id,\n functionId: k,\n });\n const functionId = k;\n return {\n value,\n functionId,\n };\n });\n return result;\n });\n }));\n loadingArray.push({\n id,\n promise,\n });\n return options;\n },\n onLoad(options) {\n return __awaiter(this, void 0, void 0, function* () {\n var _a;\n const { remote, id } = options;\n const { name } = remote;\n const promise = (_a = loadingArray.find((loading) => loading.id === id)) === null || _a === void 0 ? void 0 : _a.promise;\n if (promise) {\n const prefetch = yield promise;\n const prefetchValue = prefetch.map((result) => result.value);\n yield Promise.all(prefetchValue);\n const instance = MFDataPrefetch.getInstance(name);\n prefetch.forEach((result) => {\n const { value, functionId } = result;\n instance.memorize(id + functionId, value);\n });\n }\n return options;\n });\n },\n beforeLoadShare(options) {\n const shareInfo = options.shareInfo;\n sharedFlag = (shareInfo === null || shareInfo === void 0 ? void 0 : shareInfo.strategy) || sharedFlag;\n return options;\n },\n});\nexport default prefetchPlugin;\n"],"names":["exports"],"mappings":";;;;;;AAMA,MAAM,YAAY,GAAG,EAAE;AACvB,IAAI,UAAU,GAAG,eAAe;AACpB,MAAC,cAAc,GAAG,OAAO;AACrC,IAAI,IAAI,EAAE,8BAA8B;AACxC,IAAI,aAAa,CAAC,OAAO,EAAE;AAC3B,QAAQ,MAAM,EAAE,cAAc,EAAE,UAAU,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,OAAO;AAClE,QAAQ,IAAI,CAAC,EAAE,EAAE;AACjB,YAAY,OAAO,OAAO;AAC1B,QAAQ;AACR,QAAQ,MAAM,QAAQ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