@module-federation/data-prefetch 0.19.1 → 0.20.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.cjs +23 -15
- package/dist/babel.cjs.cjs.map +1 -1
- package/dist/babel.esm.js +23 -15
- package/dist/babel.esm.js.map +1 -1
- package/dist/cli.cjs.cjs +43 -41
- package/dist/cli.cjs.cjs.map +1 -1
- package/dist/cli.esm.js +44 -42
- package/dist/cli.esm.js.map +1 -1
- package/dist/constant.cjs.cjs.map +1 -1
- package/dist/constant.esm.js.map +1 -1
- package/dist/index.cjs2.cjs.map +1 -1
- package/dist/index.esm2.js.map +1 -1
- package/dist/plugin.cjs.cjs +131 -131
- package/dist/plugin.cjs.cjs.map +1 -1
- package/dist/plugin.esm.js +131 -131
- package/dist/plugin.esm.js.map +1 -1
- package/dist/prefetch.cjs.cjs +49 -61
- package/dist/prefetch.cjs.cjs.map +1 -1
- package/dist/prefetch.esm.js +49 -61
- package/dist/prefetch.esm.js.map +1 -1
- package/dist/react.cjs.cjs +18 -17
- package/dist/react.cjs.cjs.map +1 -1
- package/dist/react.esm.js +18 -17
- package/dist/react.esm.js.map +1 -1
- package/dist/runtime-utils.cjs.cjs +6 -5
- package/dist/runtime-utils.cjs.cjs.map +1 -1
- package/dist/runtime-utils.esm.js +6 -5
- package/dist/runtime-utils.esm.js.map +1 -1
- package/dist/universal.cjs.cjs +7 -5
- package/dist/universal.cjs.cjs.map +1 -1
- package/dist/universal.esm.js +7 -5
- package/dist/universal.esm.js.map +1 -1
- package/package.json +3 -3
package/dist/babel.cjs.cjs
CHANGED
|
@@ -5,7 +5,7 @@ var path = require('path');
|
|
|
5
5
|
const attribute = 'id';
|
|
6
6
|
const hookId = 'usePrefetch';
|
|
7
7
|
const importPackage = '@module-federation/data-prefetch/react';
|
|
8
|
-
var babel = (
|
|
8
|
+
var babel = (babel, options) => {
|
|
9
9
|
const t = babel.types;
|
|
10
10
|
let shouldHandle = false;
|
|
11
11
|
let scope = '';
|
|
@@ -14,33 +14,41 @@ var babel = ((babel, options)=>{
|
|
|
14
14
|
return {};
|
|
15
15
|
}
|
|
16
16
|
const exposesKey = Object.keys(exposes);
|
|
17
|
-
const processedExposes = exposesKey.map((expose)=>({
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
const processedExposes = exposesKey.map((expose) => ({
|
|
18
|
+
key: expose.replace('.', ''),
|
|
19
|
+
value: path.resolve(typeof exposes[expose] === 'string'
|
|
20
|
+
?
|
|
21
|
+
exposes[expose]
|
|
22
|
+
:
|
|
23
|
+
exposes[expose].import),
|
|
24
|
+
}));
|
|
21
25
|
return {
|
|
22
26
|
visitor: {
|
|
23
|
-
ImportDeclaration
|
|
27
|
+
ImportDeclaration(nodePath, state) {
|
|
24
28
|
const source = nodePath.node.source.value;
|
|
25
29
|
const { specifiers } = nodePath.node;
|
|
26
30
|
const { filename } = state.file.opts;
|
|
27
31
|
if (source === importPackage) {
|
|
28
|
-
shouldHandle = specifiers.some((specifier)=>
|
|
32
|
+
shouldHandle = specifiers.some((specifier) => specifier.imported &&
|
|
33
|
+
specifier.imported.name === hookId &&
|
|
34
|
+
processedExposes.find((expose) => expose.value === filename && (scope = expose.key)));
|
|
29
35
|
}
|
|
30
36
|
},
|
|
31
|
-
CallExpression
|
|
32
|
-
if (shouldHandle &&
|
|
33
|
-
name: hookId
|
|
34
|
-
|
|
37
|
+
CallExpression(nodePath) {
|
|
38
|
+
if (shouldHandle &&
|
|
39
|
+
t.isIdentifier(nodePath.node.callee, { name: hookId }) &&
|
|
40
|
+
nodePath.node.arguments.length > 0) {
|
|
35
41
|
const objectExpression = nodePath.node.arguments[0];
|
|
36
|
-
if (objectExpression &&
|
|
42
|
+
if (objectExpression &&
|
|
43
|
+
t.isObjectExpression(objectExpression) &&
|
|
44
|
+
!objectExpression.properties.find((p) => p.key.name === attribute)) {
|
|
37
45
|
objectExpression.properties.push(t.objectProperty(t.identifier(attribute), t.stringLiteral(name + scope)));
|
|
38
46
|
}
|
|
39
47
|
}
|
|
40
|
-
}
|
|
41
|
-
}
|
|
48
|
+
},
|
|
49
|
+
},
|
|
42
50
|
};
|
|
43
|
-
}
|
|
51
|
+
};
|
|
44
52
|
|
|
45
53
|
module.exports = babel;
|
|
46
54
|
//# sourceMappingURL=babel.cjs.cjs.map
|
package/dist/babel.cjs.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"babel.cjs.cjs","sources":["../src/cli/babel.ts"],"sourcesContent":["import path from 'path';\nconst attribute = 'id';\nconst hookId = 'usePrefetch';\nconst importPackage = '@module-federation/data-prefetch/react';\nexport default (babel, options) => {\n const t = babel.types;\n let shouldHandle = false;\n let scope = '';\n const { name, exposes } = options;\n if (!exposes) {\n return {};\n }\n const exposesKey = Object.keys(exposes);\n const processedExposes = exposesKey.map((expose) => ({\n key: expose.replace('.', ''),\n value: path.resolve(typeof exposes[expose] === 'string'\n ?\n exposes[expose]\n :\n exposes[expose].import),\n }));\n return {\n visitor: {\n ImportDeclaration(nodePath, state) {\n const source = nodePath.node.source.value;\n const { specifiers } = nodePath.node;\n const { filename } = state.file.opts;\n if (source === importPackage) {\n shouldHandle = specifiers.some((specifier) => specifier.imported &&\n specifier.imported.name === hookId &&\n processedExposes.find((expose) => expose.value === filename && (scope = expose.key)));\n }\n },\n CallExpression(nodePath) {\n if (shouldHandle &&\n t.isIdentifier(nodePath.node.callee, { name: hookId }) &&\n nodePath.node.arguments.length > 0) {\n const objectExpression = nodePath.node.arguments[0];\n if (objectExpression &&\n t.isObjectExpression(objectExpression) &&\n !objectExpression.properties.find((p) => p.key.name === attribute)) {\n objectExpression.properties.push(t.objectProperty(t.identifier(attribute), t.stringLiteral(name + scope)));\n }\n }\n },\n },\n };\n};\n"],"names":[
|
|
1
|
+
{"version":3,"file":"babel.cjs.cjs","sources":["../src/cli/babel.ts"],"sourcesContent":["import path from 'path';\nconst attribute = 'id';\nconst hookId = 'usePrefetch';\nconst importPackage = '@module-federation/data-prefetch/react';\nexport default (babel, options) => {\n const t = babel.types;\n let shouldHandle = false;\n let scope = '';\n const { name, exposes } = options;\n if (!exposes) {\n return {};\n }\n const exposesKey = Object.keys(exposes);\n const processedExposes = exposesKey.map((expose) => ({\n key: expose.replace('.', ''),\n value: path.resolve(typeof exposes[expose] === 'string'\n ?\n exposes[expose]\n :\n exposes[expose].import),\n }));\n return {\n visitor: {\n ImportDeclaration(nodePath, state) {\n const source = nodePath.node.source.value;\n const { specifiers } = nodePath.node;\n const { filename } = state.file.opts;\n if (source === importPackage) {\n shouldHandle = specifiers.some((specifier) => specifier.imported &&\n specifier.imported.name === hookId &&\n processedExposes.find((expose) => expose.value === filename && (scope = expose.key)));\n }\n },\n CallExpression(nodePath) {\n if (shouldHandle &&\n t.isIdentifier(nodePath.node.callee, { name: hookId }) &&\n nodePath.node.arguments.length > 0) {\n const objectExpression = nodePath.node.arguments[0];\n if (objectExpression &&\n t.isObjectExpression(objectExpression) &&\n !objectExpression.properties.find((p) => p.key.name === attribute)) {\n objectExpression.properties.push(t.objectProperty(t.identifier(attribute), t.stringLiteral(name + scope)));\n }\n }\n },\n },\n };\n};\n"],"names":[],"mappings":";;;;AACA,MAAM,SAAS,GAAG,IAAI;AACtB,MAAM,MAAM,GAAG,aAAa;AAC5B,MAAM,aAAa,GAAG,wCAAwC;AAC9D,YAAe,CAAC,KAAK,EAAE,OAAO,KAAK;AACnC,IAAI,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK;AACzB,IAAI,IAAI,YAAY,GAAG,KAAK;AAC5B,IAAI,IAAI,KAAK,GAAG,EAAE;AAClB,IAAI,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO;AACrC,IAAI,IAAI,CAAC,OAAO,EAAE;AAClB,QAAQ,OAAO,EAAE;AACjB;AACA,IAAI,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;AAC3C,IAAI,MAAM,g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AM,GAAG,CAAC,EAAE;AACxD,oBAAoB,MAAM,gBAAgB,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;AACvE,oBAAoB,IAAI,gBAAgB;AACxC,wBAAwB,CAAC,CAAC,kBAAkB,CAAC,gBAAgB,CAAC;AAC9D,wBAAwB,CAAC,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,SAAS,CAAC,EAAE;AAC5F,wBAAwB,gBAAgB,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,aAAa,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC;AAClI;AACA;AACA,aAAa;AACb,SAAS;AACT,KAAK;AACL,CAAC;;;;"}
|
package/dist/babel.esm.js
CHANGED
|
@@ -3,7 +3,7 @@ import path from 'path';
|
|
|
3
3
|
const attribute = 'id';
|
|
4
4
|
const hookId = 'usePrefetch';
|
|
5
5
|
const importPackage = '@module-federation/data-prefetch/react';
|
|
6
|
-
var babel = (
|
|
6
|
+
var babel = (babel, options) => {
|
|
7
7
|
const t = babel.types;
|
|
8
8
|
let shouldHandle = false;
|
|
9
9
|
let scope = '';
|
|
@@ -12,33 +12,41 @@ var babel = ((babel, options)=>{
|
|
|
12
12
|
return {};
|
|
13
13
|
}
|
|
14
14
|
const exposesKey = Object.keys(exposes);
|
|
15
|
-
const processedExposes = exposesKey.map((expose)=>({
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
const processedExposes = exposesKey.map((expose) => ({
|
|
16
|
+
key: expose.replace('.', ''),
|
|
17
|
+
value: path.resolve(typeof exposes[expose] === 'string'
|
|
18
|
+
?
|
|
19
|
+
exposes[expose]
|
|
20
|
+
:
|
|
21
|
+
exposes[expose].import),
|
|
22
|
+
}));
|
|
19
23
|
return {
|
|
20
24
|
visitor: {
|
|
21
|
-
ImportDeclaration
|
|
25
|
+
ImportDeclaration(nodePath, state) {
|
|
22
26
|
const source = nodePath.node.source.value;
|
|
23
27
|
const { specifiers } = nodePath.node;
|
|
24
28
|
const { filename } = state.file.opts;
|
|
25
29
|
if (source === importPackage) {
|
|
26
|
-
shouldHandle = specifiers.some((specifier)=>
|
|
30
|
+
shouldHandle = specifiers.some((specifier) => specifier.imported &&
|
|
31
|
+
specifier.imported.name === hookId &&
|
|
32
|
+
processedExposes.find((expose) => expose.value === filename && (scope = expose.key)));
|
|
27
33
|
}
|
|
28
34
|
},
|
|
29
|
-
CallExpression
|
|
30
|
-
if (shouldHandle &&
|
|
31
|
-
name: hookId
|
|
32
|
-
|
|
35
|
+
CallExpression(nodePath) {
|
|
36
|
+
if (shouldHandle &&
|
|
37
|
+
t.isIdentifier(nodePath.node.callee, { name: hookId }) &&
|
|
38
|
+
nodePath.node.arguments.length > 0) {
|
|
33
39
|
const objectExpression = nodePath.node.arguments[0];
|
|
34
|
-
if (objectExpression &&
|
|
40
|
+
if (objectExpression &&
|
|
41
|
+
t.isObjectExpression(objectExpression) &&
|
|
42
|
+
!objectExpression.properties.find((p) => p.key.name === attribute)) {
|
|
35
43
|
objectExpression.properties.push(t.objectProperty(t.identifier(attribute), t.stringLiteral(name + scope)));
|
|
36
44
|
}
|
|
37
45
|
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
46
|
+
},
|
|
47
|
+
},
|
|
40
48
|
};
|
|
41
|
-
}
|
|
49
|
+
};
|
|
42
50
|
|
|
43
51
|
export { babel as default };
|
|
44
52
|
//# sourceMappingURL=babel.esm.js.map
|
package/dist/babel.esm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"babel.esm.js","sources":["../src/cli/babel.ts"],"sourcesContent":["import path from 'path';\nconst attribute = 'id';\nconst hookId = 'usePrefetch';\nconst importPackage = '@module-federation/data-prefetch/react';\nexport default (babel, options) => {\n const t = babel.types;\n let shouldHandle = false;\n let scope = '';\n const { name, exposes } = options;\n if (!exposes) {\n return {};\n }\n const exposesKey = Object.keys(exposes);\n const processedExposes = exposesKey.map((expose) => ({\n key: expose.replace('.', ''),\n value: path.resolve(typeof exposes[expose] === 'string'\n ?\n exposes[expose]\n :\n exposes[expose].import),\n }));\n return {\n visitor: {\n ImportDeclaration(nodePath, state) {\n const source = nodePath.node.source.value;\n const { specifiers } = nodePath.node;\n const { filename } = state.file.opts;\n if (source === importPackage) {\n shouldHandle = specifiers.some((specifier) => specifier.imported &&\n specifier.imported.name === hookId &&\n processedExposes.find((expose) => expose.value === filename && (scope = expose.key)));\n }\n },\n CallExpression(nodePath) {\n if (shouldHandle &&\n t.isIdentifier(nodePath.node.callee, { name: hookId }) &&\n nodePath.node.arguments.length > 0) {\n const objectExpression = nodePath.node.arguments[0];\n if (objectExpression &&\n t.isObjectExpression(objectExpression) &&\n !objectExpression.properties.find((p) => p.key.name === attribute)) {\n objectExpression.properties.push(t.objectProperty(t.identifier(attribute), t.stringLiteral(name + scope)));\n }\n }\n },\n },\n };\n};\n"],"names":[
|
|
1
|
+
{"version":3,"file":"babel.esm.js","sources":["../src/cli/babel.ts"],"sourcesContent":["import path from 'path';\nconst attribute = 'id';\nconst hookId = 'usePrefetch';\nconst importPackage = '@module-federation/data-prefetch/react';\nexport default (babel, options) => {\n const t = babel.types;\n let shouldHandle = false;\n let scope = '';\n const { name, exposes } = options;\n if (!exposes) {\n return {};\n }\n const exposesKey = Object.keys(exposes);\n const processedExposes = exposesKey.map((expose) => ({\n key: expose.replace('.', ''),\n value: path.resolve(typeof exposes[expose] === 'string'\n ?\n exposes[expose]\n :\n exposes[expose].import),\n }));\n return {\n visitor: {\n ImportDeclaration(nodePath, state) {\n const source = nodePath.node.source.value;\n const { specifiers } = nodePath.node;\n const { filename } = state.file.opts;\n if (source === importPackage) {\n shouldHandle = specifiers.some((specifier) => specifier.imported &&\n specifier.imported.name === hookId &&\n processedExposes.find((expose) => expose.value === filename && (scope = expose.key)));\n }\n },\n CallExpression(nodePath) {\n if (shouldHandle &&\n t.isIdentifier(nodePath.node.callee, { name: hookId }) &&\n nodePath.node.arguments.length > 0) {\n const objectExpression = nodePath.node.arguments[0];\n if (objectExpression &&\n t.isObjectExpression(objectExpression) &&\n !objectExpression.properties.find((p) => p.key.name === attribute)) {\n objectExpression.properties.push(t.objectProperty(t.identifier(attribute), t.stringLiteral(name + scope)));\n }\n }\n },\n },\n };\n};\n"],"names":[],"mappings":";;AACA,MAAM,SAAS,GAAG,IAAI;AACtB,MAAM,MAAM,GAAG,aAAa;AAC5B,MAAM,aAAa,GAAG,wCAAwC;AAC9D,YAAe,CAAC,KAAK,EAAE,OAAO,KAAK;AACnC,IAAI,MAAM,CAAC,GAAG,KAAK,CAAC,KAAK;AACzB,IAAI,IAAI,YAAY,GAAG,KAAK;AAC5B,IAAI,IAAI,KAAK,GAAG,EAAE;AAClB,IAAI,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,OAAO;AACrC,IAAI,IAAI,CAAC,OAAO,EAAE;AAClB,QAAQ,OAAO,EAAE;AACjB;AACA,IAAI,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;AAC3C,IAAI,MAAM,gBAAgB,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,MAAM,MAAM;AACzD,QAAQ,GAAG,EAAE,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC;AACpC,QAAQ,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK;AACvD;AACA,gBAAgB,OAAO,CAAC,MAAM;AAC9B;AACA,gBAAgB,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC;AACvC,KAAK,CAAC,CAAC;AACP,IAAI,OAAO;AACX,QAAQ,OAAO,EAAE;AACjB,YAAY,iBAAiB,CAAC,QAAQ,EAAE,KAAK,EAAE;AAC/C,gBAAgB,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C,CAAC,aAAa,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC;AAClI;AACA;AACA,aAAa;AACb,SAAS;AACT,KAAK;AACL,CAAC;;;;"}
|
package/dist/cli.cjs.cjs
CHANGED
|
@@ -9,7 +9,7 @@ var constant = require('./constant.cjs.cjs');
|
|
|
9
9
|
|
|
10
10
|
const TEMP_DIR = '.mf';
|
|
11
11
|
|
|
12
|
-
const fileExistsWithCaseSync = (filepath)=>{
|
|
12
|
+
const fileExistsWithCaseSync = (filepath) => {
|
|
13
13
|
const dir = path.dirname(filepath);
|
|
14
14
|
if (filepath === '/' || filepath === '.') {
|
|
15
15
|
return true;
|
|
@@ -20,26 +20,33 @@ const fileExistsWithCaseSync = (filepath)=>{
|
|
|
20
20
|
}
|
|
21
21
|
return fileExistsWithCaseSync(dir);
|
|
22
22
|
};
|
|
23
|
-
const fixPrefetchPath = (exposePath)=>{
|
|
24
|
-
const pathExt = [
|
|
25
|
-
'.js',
|
|
26
|
-
'.ts'
|
|
27
|
-
];
|
|
23
|
+
const fixPrefetchPath = (exposePath) => {
|
|
24
|
+
const pathExt = ['.js', '.ts'];
|
|
28
25
|
const extReg = /\.(ts|js|tsx|jsx)$/;
|
|
29
26
|
if (extReg.test(exposePath)) {
|
|
30
|
-
return pathExt.map((ext)=>exposePath.replace(extReg, `.prefetch${ext}`));
|
|
31
|
-
}
|
|
32
|
-
|
|
27
|
+
return pathExt.map((ext) => exposePath.replace(extReg, `.prefetch${ext}`));
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
return pathExt.map((ext) => exposePath + `.prefetch${ext}`);
|
|
33
31
|
}
|
|
34
32
|
};
|
|
35
33
|
|
|
36
34
|
const { RuntimeGlobals, Template } = require(normalizeWebpackPath.normalizeWebpackPath('webpack'));
|
|
35
|
+
const createBundlerLogger = typeof sdk.createInfrastructureLogger === 'function'
|
|
36
|
+
? sdk.createInfrastructureLogger
|
|
37
|
+
: sdk.createLogger;
|
|
38
|
+
const logger = createBundlerLogger('[ Module Federation Data Prefetch Plugin ]');
|
|
37
39
|
function getFederationGlobalScope(runtimeGlobals) {
|
|
38
40
|
return `${runtimeGlobals.require || '__webpack_require__'}.federation`;
|
|
39
41
|
}
|
|
40
42
|
class PrefetchPlugin {
|
|
43
|
+
constructor(options) {
|
|
44
|
+
this.options = options;
|
|
45
|
+
this._reWriteExports = '';
|
|
46
|
+
}
|
|
41
47
|
apply(compiler) {
|
|
42
48
|
var _a;
|
|
49
|
+
sdk.bindLoggerToCompiler(logger, compiler, 'PrefetchPlugin');
|
|
43
50
|
const { name, exposes } = this.options;
|
|
44
51
|
if (!exposes) {
|
|
45
52
|
return;
|
|
@@ -57,7 +64,7 @@ class PrefetchPlugin {
|
|
|
57
64
|
}
|
|
58
65
|
if (this.options.shareStrategy !== constant.SHARED_STRATEGY) {
|
|
59
66
|
this.options.shareStrategy = constant.SHARED_STRATEGY;
|
|
60
|
-
|
|
67
|
+
logger.warn(`[Module Federation Data Prefetch]: Your shared strategy is set to '${constant.SHARED_STRATEGY}', this is a necessary condition for data prefetch`);
|
|
61
68
|
}
|
|
62
69
|
const encodedName = sdk.encodeName(name);
|
|
63
70
|
const asyncEntryPath = path.resolve(compiler.options.context, `node_modules/${TEMP_DIR}/${encodedName}/bootstrap.js`);
|
|
@@ -68,16 +75,17 @@ class PrefetchPlugin {
|
|
|
68
75
|
return;
|
|
69
76
|
}
|
|
70
77
|
const exposeAlias = Object.keys(exposes);
|
|
71
|
-
exposeAlias.forEach((alias)=>{
|
|
78
|
+
exposeAlias.forEach((alias) => {
|
|
72
79
|
let exposePath;
|
|
73
80
|
const exposeValue = exposes[alias];
|
|
74
81
|
if (typeof exposeValue === 'string') {
|
|
75
82
|
exposePath = exposeValue;
|
|
76
|
-
}
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
77
85
|
exposePath = exposeValue.import[0];
|
|
78
86
|
}
|
|
79
87
|
const targetPaths = fixPrefetchPath(exposePath);
|
|
80
|
-
for (const pathItem of targetPaths){
|
|
88
|
+
for (const pathItem of targetPaths) {
|
|
81
89
|
const absolutePath = path.resolve(compiler.options.context, pathItem);
|
|
82
90
|
if (fileExistsWithCaseSync(absolutePath)) {
|
|
83
91
|
const absoluteAlias = alias.replace('.', '');
|
|
@@ -98,7 +106,7 @@ class PrefetchPlugin {
|
|
|
98
106
|
}
|
|
99
107
|
fs.writeFileSync(asyncEntryPath, this._reWriteExports);
|
|
100
108
|
new compiler.webpack.DefinePlugin({
|
|
101
|
-
FederationDataPrefetch: JSON.stringify(asyncEntryPath)
|
|
109
|
+
FederationDataPrefetch: JSON.stringify(asyncEntryPath),
|
|
102
110
|
}).apply(compiler);
|
|
103
111
|
}
|
|
104
112
|
static addRuntime(compiler, options) {
|
|
@@ -109,43 +117,37 @@ class PrefetchPlugin {
|
|
|
109
117
|
const prefetchEntry = path.resolve(compiler.options.context, `node_modules/.mf/${encodedName}/bootstrap.js`);
|
|
110
118
|
const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});
|
|
111
119
|
return Template.asString([
|
|
112
|
-
fs.existsSync(prefetchEntry)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
120
|
+
fs.existsSync(prefetchEntry)
|
|
121
|
+
? Template.indent([
|
|
122
|
+
'function injectPrefetch() {',
|
|
123
|
+
Template.indent([
|
|
124
|
+
`globalThis.__FEDERATION__ = globalThis.__FEDERATION__ || {};`,
|
|
125
|
+
`globalThis.__FEDERATION__['${sdk.MFPrefetchCommon.globalKey}'] = globalThis.__FEDERATION__['${sdk.MFPrefetchCommon.globalKey}'] || {`,
|
|
126
|
+
`entryLoading: {},`,
|
|
127
|
+
`instance: new Map(),`,
|
|
128
|
+
`__PREFETCH_EXPORTS__: {},`,
|
|
129
|
+
`};`,
|
|
130
|
+
`globalThis.__FEDERATION__['${sdk.MFPrefetchCommon.globalKey}']['${sdk.MFPrefetchCommon.exportsKey}'] = globalThis.__FEDERATION__['${sdk.MFPrefetchCommon.globalKey}']['${sdk.MFPrefetchCommon.exportsKey}'] || {};`,
|
|
131
|
+
`globalThis.__FEDERATION__['${sdk.MFPrefetchCommon.globalKey}']['${sdk.MFPrefetchCommon.exportsKey}']['${options.name}'] = function(){ return import('${prefetchEntry}');}`,
|
|
132
|
+
]),
|
|
133
|
+
'}',
|
|
134
|
+
`${federationGlobal}.prefetch = injectPrefetch`,
|
|
135
|
+
])
|
|
136
|
+
: '',
|
|
127
137
|
Template.indent([
|
|
128
138
|
`if(!${federationGlobal}.isMFRemote && ${federationGlobal}.prefetch){`,
|
|
129
139
|
`${federationGlobal}.prefetch()`,
|
|
130
|
-
'}'
|
|
131
|
-
])
|
|
140
|
+
'}',
|
|
141
|
+
]),
|
|
132
142
|
]);
|
|
133
143
|
}
|
|
134
144
|
static setRemoteIdentifier() {
|
|
135
145
|
const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});
|
|
136
|
-
return Template.indent([
|
|
137
|
-
`${federationGlobal}.isMFRemote = true;`
|
|
138
|
-
]);
|
|
146
|
+
return Template.indent([`${federationGlobal}.isMFRemote = true;`]);
|
|
139
147
|
}
|
|
140
148
|
static removeRemoteIdentifier() {
|
|
141
149
|
const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});
|
|
142
|
-
return Template.indent([
|
|
143
|
-
`${federationGlobal}.isMFRemote = false;`
|
|
144
|
-
]);
|
|
145
|
-
}
|
|
146
|
-
constructor(options){
|
|
147
|
-
this.options = options;
|
|
148
|
-
this._reWriteExports = '';
|
|
150
|
+
return Template.indent([`${federationGlobal}.isMFRemote = false;`]);
|
|
149
151
|
}
|
|
150
152
|
}
|
|
151
153
|
|
package/dist/cli.cjs.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.cjs.cjs","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 { 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'));\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 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 console.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":["TEMP_DIR","fileExistsWithCaseSync","filepath","dir","path","dirname","filenames","fs","readdirSync","indexOf","basename","fixPrefetchPath","exposePath","pathExt","extReg","test","map","ext","replace","RuntimeGlobals","Template","require","normalizeWebpackPath","getFederationGlobalScope","runtimeGlobals","PrefetchPlugin","apply","compiler","_a","name","exposes","options","context","Error","runtimePlugins","Array","isArray","runtimePath","resolve","__dirname","includes","push","shareStrategy","SHARED_STRATEGY","console","warn","encodedName","encodeName","asyncEntryPath","existsSync","unlinkSync","dataPrefetch","exposeAlias","Object","keys","forEach","alias","exposeValue","import","targetPaths","pathItem","absolutePath","absoluteAlias","_reWriteExports","getPrefetchId","tempDirRealPath","mkdirSync","writeFileSync","webpack","DefinePlugin","FederationDataPrefetch","JSON","stringify","addRuntime","prefetchEntry","federationGlobal","asString","indent","MFPrefetchCommon","globalKey","exportsKey","setRemoteIdentifier","removeRemoteIdentifier","constructor"],"mappings":";;;;;;;;;AAAO,MAAMA,WAAW,KAAM;;ACEvB,MAAMC,yBAAyB,CAACC,QAAAA,GAAAA;IACnC,MAAMC,GAAAA,GAAMC,IAAKC,CAAAA,OAAO,CAACH,QAAAA,CAAAA;IACzB,IAAIA,QAAAA,KAAa,GAAOA,IAAAA,QAAAA,KAAa,GAAK,EAAA;QACtC,OAAO,IAAA;AACX;IACA,MAAMI,SAAAA,GAAYC,EAAGC,CAAAA,WAAW,CAACL,GAAAA,CAAAA;IACjC,IAAIG,SAAAA,CAAUG,OAAO,CAACL,IAAAA,CAAKM,QAAQ,CAACR,QAAAA,CAAAA,CAAAA,KAAe,EAAI,EAAA;QACnD,OAAO,KAAA;AACX;AACA,IAAA,OAAOD,sBAAuBE,CAAAA,GAAAA,CAAAA;AAClC,CAAE;AACK,MAAMQ,kBAAkB,CAACC,UAAAA,GAAAA;AAC5B,IAAA,MAAMC,OAAU,GAAA;AAAC,QAAA,KAAA;AAAO,QAAA;AAAM,KAAA;AAC9B,IAAA,MAAMC,MAAS,GAAA,oBAAA;IACf,IAAIA,MAAAA,CAAOC,IAAI,CAACH,UAAa,CAAA,EAAA;AACzB,QAAA,OAAOC,OAAQG,CAAAA,GAAG,CAAC,CAACC,GAAQL,GAAAA,UAAAA,CAAWM,OAAO,CAACJ,MAAQ,EAAA,CAAC,SAAS,EAAEG,IAAI,CAAC,CAAA,CAAA;KAEvE,MAAA;QACD,OAAOJ,OAAAA,CAAQG,GAAG,CAAC,CAACC,GAAAA,GAAQL,aAAa,CAAC,SAAS,EAAEK,GAAAA,CAAI,CAAC,CAAA;AAC9D;AACJ,CAAE;;ACdF,MAAM,EAAEE,cAAc,EAAEC,QAAQ,EAAE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C;gBACtE,CAAC,EAAEA,gBAAiB,CAAA,WAAW,CAAC;AAChC,gBAAA;AACH,aAAA;AACJ,SAAA,CAAA;AACL;AACA,IAAA,OAAOM,mBAAsB,GAAA;QACzB,MAAMN,gBAAAA,GAAmBpD,wBAAyBJ,CAAAA,cAAAA,IAAkB,EAAC,CAAA;QACrE,OAAOC,QAAAA,CAASyD,MAAM,CAAC;YAAC,CAAC,EAAEF,gBAAiB,CAAA,mBAAmB;AAAE,SAAA,CAAA;AACrE;AACA,IAAA,OAAOO,sBAAyB,GAAA;QAC5B,MAAMP,gBAAAA,GAAmBpD,wBAAyBJ,CAAAA,cAAAA,IAAkB,EAAC,CAAA;QACrE,OAAOC,QAAAA,CAASyD,MAAM,CAAC;YAAC,CAAC,EAAEF,gBAAiB,CAAA,oBAAoB;AAAE,SAAA,CAAA;AACtE;AA7GAQ,IAAAA,WAAAA,CAAYpD,OAAO,CAAE;QACjB,IAAI,CAACA,OAAO,GAAGA,OAAAA;QACf,IAAI,CAACgC,eAAe,GAAG,EAAA;AAC3B;AA2GJ;;;;;"}
|
|
1
|
+
{"version":3,"file":"cli.cjs.cjs","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":["normalizeWebpackPath","createInfrastructureLogger","createLogger","bindLoggerToCompiler","SHARED_STRATEGY","encodeName","getPrefetchId","MFPrefetchCommon"],"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;AACA,IAAI,MAAM,SAAS,GAAG,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC;AACzC,IAAI,IAAI,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,KAAK,EAAE,EAAE;AAC3D,QAAQ,OAAO,KAAK;AACpB;AACA,IAAI,OAAO,sBAAsB,CAAC,GAAG,CAAC;AACtC,CAAC;AACM,MAAM,eAAe,GAAG,CAAC,UAAU,KAAK;AAC/C,IAAI,MAAM,OAAO,GAAG,CAAC,KAAK,EAAE,KAAK,CAAC;A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AAQ,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,gBAAgB,CAAC,oBAAoB,CAAC,CAAC,CAAC;AAC3E;AACA;;;;;"}
|
package/dist/cli.esm.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import fs from 'fs-extra';
|
|
3
|
-
import { encodeName, MFPrefetchCommon } from '@module-federation/sdk';
|
|
3
|
+
import { createInfrastructureLogger, createLogger, bindLoggerToCompiler, encodeName, MFPrefetchCommon } from '@module-federation/sdk';
|
|
4
4
|
import { normalizeWebpackPath } from '@module-federation/sdk/normalize-webpack-path';
|
|
5
5
|
import { b as getPrefetchId } from './runtime-utils.esm.js';
|
|
6
6
|
import { S as SHARED_STRATEGY } from './constant.esm.js';
|
|
7
7
|
|
|
8
8
|
const TEMP_DIR = '.mf';
|
|
9
9
|
|
|
10
|
-
const fileExistsWithCaseSync = (filepath)=>{
|
|
10
|
+
const fileExistsWithCaseSync = (filepath) => {
|
|
11
11
|
const dir = path.dirname(filepath);
|
|
12
12
|
if (filepath === '/' || filepath === '.') {
|
|
13
13
|
return true;
|
|
@@ -18,26 +18,33 @@ const fileExistsWithCaseSync = (filepath)=>{
|
|
|
18
18
|
}
|
|
19
19
|
return fileExistsWithCaseSync(dir);
|
|
20
20
|
};
|
|
21
|
-
const fixPrefetchPath = (exposePath)=>{
|
|
22
|
-
const pathExt = [
|
|
23
|
-
'.js',
|
|
24
|
-
'.ts'
|
|
25
|
-
];
|
|
21
|
+
const fixPrefetchPath = (exposePath) => {
|
|
22
|
+
const pathExt = ['.js', '.ts'];
|
|
26
23
|
const extReg = /\.(ts|js|tsx|jsx)$/;
|
|
27
24
|
if (extReg.test(exposePath)) {
|
|
28
|
-
return pathExt.map((ext)=>exposePath.replace(extReg, `.prefetch${ext}`));
|
|
29
|
-
}
|
|
30
|
-
|
|
25
|
+
return pathExt.map((ext) => exposePath.replace(extReg, `.prefetch${ext}`));
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
return pathExt.map((ext) => exposePath + `.prefetch${ext}`);
|
|
31
29
|
}
|
|
32
30
|
};
|
|
33
31
|
|
|
34
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 ]');
|
|
35
37
|
function getFederationGlobalScope(runtimeGlobals) {
|
|
36
38
|
return `${runtimeGlobals.require || '__webpack_require__'}.federation`;
|
|
37
39
|
}
|
|
38
40
|
class PrefetchPlugin {
|
|
41
|
+
constructor(options) {
|
|
42
|
+
this.options = options;
|
|
43
|
+
this._reWriteExports = '';
|
|
44
|
+
}
|
|
39
45
|
apply(compiler) {
|
|
40
46
|
var _a;
|
|
47
|
+
bindLoggerToCompiler(logger, compiler, 'PrefetchPlugin');
|
|
41
48
|
const { name, exposes } = this.options;
|
|
42
49
|
if (!exposes) {
|
|
43
50
|
return;
|
|
@@ -55,7 +62,7 @@ class PrefetchPlugin {
|
|
|
55
62
|
}
|
|
56
63
|
if (this.options.shareStrategy !== SHARED_STRATEGY) {
|
|
57
64
|
this.options.shareStrategy = SHARED_STRATEGY;
|
|
58
|
-
|
|
65
|
+
logger.warn(`[Module Federation Data Prefetch]: Your shared strategy is set to '${SHARED_STRATEGY}', this is a necessary condition for data prefetch`);
|
|
59
66
|
}
|
|
60
67
|
const encodedName = encodeName(name);
|
|
61
68
|
const asyncEntryPath = path.resolve(compiler.options.context, `node_modules/${TEMP_DIR}/${encodedName}/bootstrap.js`);
|
|
@@ -66,16 +73,17 @@ class PrefetchPlugin {
|
|
|
66
73
|
return;
|
|
67
74
|
}
|
|
68
75
|
const exposeAlias = Object.keys(exposes);
|
|
69
|
-
exposeAlias.forEach((alias)=>{
|
|
76
|
+
exposeAlias.forEach((alias) => {
|
|
70
77
|
let exposePath;
|
|
71
78
|
const exposeValue = exposes[alias];
|
|
72
79
|
if (typeof exposeValue === 'string') {
|
|
73
80
|
exposePath = exposeValue;
|
|
74
|
-
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
75
83
|
exposePath = exposeValue.import[0];
|
|
76
84
|
}
|
|
77
85
|
const targetPaths = fixPrefetchPath(exposePath);
|
|
78
|
-
for (const pathItem of targetPaths){
|
|
86
|
+
for (const pathItem of targetPaths) {
|
|
79
87
|
const absolutePath = path.resolve(compiler.options.context, pathItem);
|
|
80
88
|
if (fileExistsWithCaseSync(absolutePath)) {
|
|
81
89
|
const absoluteAlias = alias.replace('.', '');
|
|
@@ -96,7 +104,7 @@ class PrefetchPlugin {
|
|
|
96
104
|
}
|
|
97
105
|
fs.writeFileSync(asyncEntryPath, this._reWriteExports);
|
|
98
106
|
new compiler.webpack.DefinePlugin({
|
|
99
|
-
FederationDataPrefetch: JSON.stringify(asyncEntryPath)
|
|
107
|
+
FederationDataPrefetch: JSON.stringify(asyncEntryPath),
|
|
100
108
|
}).apply(compiler);
|
|
101
109
|
}
|
|
102
110
|
static addRuntime(compiler, options) {
|
|
@@ -107,43 +115,37 @@ class PrefetchPlugin {
|
|
|
107
115
|
const prefetchEntry = path.resolve(compiler.options.context, `node_modules/.mf/${encodedName}/bootstrap.js`);
|
|
108
116
|
const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});
|
|
109
117
|
return Template.asString([
|
|
110
|
-
fs.existsSync(prefetchEntry)
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
+
: '',
|
|
125
135
|
Template.indent([
|
|
126
136
|
`if(!${federationGlobal}.isMFRemote && ${federationGlobal}.prefetch){`,
|
|
127
137
|
`${federationGlobal}.prefetch()`,
|
|
128
|
-
'}'
|
|
129
|
-
])
|
|
138
|
+
'}',
|
|
139
|
+
]),
|
|
130
140
|
]);
|
|
131
141
|
}
|
|
132
142
|
static setRemoteIdentifier() {
|
|
133
143
|
const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});
|
|
134
|
-
return Template.indent([
|
|
135
|
-
`${federationGlobal}.isMFRemote = true;`
|
|
136
|
-
]);
|
|
144
|
+
return Template.indent([`${federationGlobal}.isMFRemote = true;`]);
|
|
137
145
|
}
|
|
138
146
|
static removeRemoteIdentifier() {
|
|
139
147
|
const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});
|
|
140
|
-
return Template.indent([
|
|
141
|
-
`${federationGlobal}.isMFRemote = false;`
|
|
142
|
-
]);
|
|
143
|
-
}
|
|
144
|
-
constructor(options){
|
|
145
|
-
this.options = options;
|
|
146
|
-
this._reWriteExports = '';
|
|
148
|
+
return Template.indent([`${federationGlobal}.isMFRemote = false;`]);
|
|
147
149
|
}
|
|
148
150
|
}
|
|
149
151
|
|