@module-federation/data-prefetch 0.0.0-next-20241010063233 → 0.0.0-next-20241010084324

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.
Files changed (87) hide show
  1. package/CHANGELOG.md +4 -29
  2. package/LICENSE +1 -1
  3. package/dist/{src/cli → cli}/babel.d.ts +4 -2
  4. package/dist/cli/babel.js +84 -0
  5. package/dist/{src/cli → cli}/index.d.ts +8 -5
  6. package/dist/cli/index.js +207 -0
  7. package/dist/esm/chunk-AJPO2B2T.js +30 -0
  8. package/dist/esm/chunk-BGNOVRH5.js +166 -0
  9. package/dist/esm/chunk-EZUCZHGV.js +11 -0
  10. package/dist/esm/chunk-ISF7VMBW.js +156 -0
  11. package/dist/esm/chunk-OCDMSRMZ.js +32 -0
  12. package/dist/esm/chunk-TTJJJ2WZ.js +7 -0
  13. package/dist/esm/cli/babel.js +57 -0
  14. package/dist/esm/cli/index.js +180 -0
  15. package/dist/esm/index.js +13 -0
  16. package/dist/esm/plugin.js +12 -0
  17. package/dist/esm/react/index.js +94 -0
  18. package/dist/esm/shared/index.js +27 -0
  19. package/dist/esm/universal/index.js +9 -0
  20. package/dist/index.d.ts +5 -0
  21. package/dist/index.js +351 -0
  22. package/dist/plugin.d.ts +5 -0
  23. package/dist/plugin.js +347 -0
  24. package/dist/{src/prefetch.d.ts → prefetch-c08be471.d.ts} +6 -4
  25. package/dist/react/index.d.ts +16 -0
  26. package/dist/react/index.js +287 -0
  27. package/dist/shared/index.d.ts +5 -0
  28. package/dist/shared/index.js +48 -0
  29. package/dist/universal/index.d.ts +8 -0
  30. package/dist/universal/index.js +205 -0
  31. package/package.json +30 -33
  32. package/project.json +6 -48
  33. package/src/cli/index.ts +2 -2
  34. package/tsconfig.json +1 -1
  35. package/.swcrc +0 -29
  36. package/dist/LICENSE +0 -21
  37. package/dist/babel.cjs.d.ts +0 -2
  38. package/dist/babel.cjs.js +0 -50
  39. package/dist/babel.esm.d.ts +0 -2
  40. package/dist/babel.esm.js +0 -48
  41. package/dist/cli.cjs.d.ts +0 -1
  42. package/dist/cli.cjs.js +0 -155
  43. package/dist/cli.esm.d.ts +0 -1
  44. package/dist/cli.esm.js +0 -152
  45. package/dist/index.cjs.d.ts +0 -1
  46. package/dist/index.cjs.js +0 -13
  47. package/dist/index.cjs2.js +0 -7
  48. package/dist/index.esm.d.ts +0 -1
  49. package/dist/index.esm.js +0 -6
  50. package/dist/index.esm2.js +0 -5
  51. package/dist/package.json +0 -100
  52. package/dist/plugin.cjs.d.ts +0 -2
  53. package/dist/plugin.cjs.js +0 -159
  54. package/dist/plugin.esm.d.ts +0 -2
  55. package/dist/plugin.esm.js +0 -154
  56. package/dist/polyfills.cjs.js +0 -14
  57. package/dist/polyfills.esm.js +0 -12
  58. package/dist/prefetch.cjs.js +0 -142
  59. package/dist/prefetch.esm.js +0 -140
  60. package/dist/react.cjs.d.ts +0 -1
  61. package/dist/react.cjs.js +0 -77
  62. package/dist/react.esm.d.ts +0 -1
  63. package/dist/react.esm.js +0 -75
  64. package/dist/runtime-utils.cjs.js +0 -27
  65. package/dist/runtime-utils.esm.js +0 -22
  66. package/dist/shared.cjs.d.ts +0 -2
  67. package/dist/shared.cjs.js +0 -24
  68. package/dist/shared.esm.d.ts +0 -2
  69. package/dist/shared.esm.js +0 -22
  70. package/dist/src/common/constant.d.ts +0 -1
  71. package/dist/src/common/index.d.ts +0 -1
  72. package/dist/src/common/node-utils.d.ts +0 -2
  73. package/dist/src/common/runtime-utils.d.ts +0 -5
  74. package/dist/src/index.d.ts +0 -2
  75. package/dist/src/logger/index.d.ts +0 -3
  76. package/dist/src/plugin.d.ts +0 -3
  77. package/dist/src/react/hooks.d.ts +0 -11
  78. package/dist/src/react/index.d.ts +0 -1
  79. package/dist/src/react/utils.d.ts +0 -1
  80. package/dist/src/shared/index.d.ts +0 -3
  81. package/dist/src/universal/index.d.ts +0 -2
  82. package/dist/universal.cjs.d.ts +0 -1
  83. package/dist/universal.cjs.js +0 -29
  84. package/dist/universal.esm.d.ts +0 -1
  85. package/dist/universal.esm.js +0 -27
  86. package/rollup.config.js +0 -46
  87. package/tsconfig.lib.json +0 -10
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-20241010063233",
4
+ "version": "0.0.0-next-20241010084324",
5
5
  "author": "nieyan <nyqykk@foxmail.com>",
6
6
  "homepage": "https://github.com/module-federation/core",
7
7
  "license": "MIT",
@@ -10,60 +10,57 @@
10
10
  },
11
11
  "exports": {
12
12
  ".": {
13
- "import": "./dist/index.esm.js",
14
- "require": "./dist/index.cjs",
15
- "types": "./dist/index.cjs.d.ts"
13
+ "import": "./dist/esm/index.js",
14
+ "require": "./dist/index.js",
15
+ "types": "./dist/index.d.ts"
16
16
  },
17
17
  "./react": {
18
- "import": "./dist/react.esm.js",
19
- "require": "./dist/react.cjs.js",
20
- "types": "./dist/react.cjs.d.ts"
18
+ "import": "./dist/esm/react/index.js",
19
+ "require": "./dist/react/index.js",
20
+ "types": "./dist/react/index.d.ts"
21
21
  },
22
22
  "./cli": {
23
- "import": "./dist/cli.esm.js",
24
- "require": "./dist/cli.cjs.js",
25
- "types": "./dist/cli.cjs.d.ts"
23
+ "import": "./dist/esm/cli/index.js",
24
+ "require": "./dist/cli/index.js",
25
+ "types": "./dist/cli/index.d.ts"
26
26
  },
27
27
  "./babel-plugin": {
28
- "import": "./dist/babel.esm.js",
29
- "require": "./dist/babel.cjs.js",
30
- "types": "./dist/babel.cjs.d.ts"
28
+ "import": "./dist/esm/cli/babel.js",
29
+ "require": "./dist/cli/babel.js",
30
+ "types": "./dist/cli/babel.d.ts"
31
31
  },
32
32
  "./universal": {
33
- "import": "./dist/universal.esm.js",
34
- "require": "./dist/universal.cjs.js",
35
- "types": "./dist/universal.cjs.d.ts"
33
+ "import": "./dist/esm/universal/index.js",
34
+ "require": "./dist/universal/index.js",
35
+ "types": "./dist/universal/index.d.ts"
36
36
  },
37
37
  "./shared": {
38
- "import": "./dist/shared.esm.js",
39
- "require": "./dist/shared.cjs.js",
40
- "types": "./dist/shared/.cjs.d.ts"
38
+ "import": "./dist/esm/shared/index.js",
39
+ "require": "./dist/shared/index.js",
40
+ "types": "./dist/shared/index.d.ts"
41
41
  }
42
42
  },
43
43
  "typesVersions": {
44
44
  "*": {
45
45
  ".": [
46
- "./dist/index.cjs.d.ts"
46
+ "./dist/index.d.ts"
47
47
  ],
48
48
  "react": [
49
- "./dist/react.cjs.d.ts"
49
+ "./dist/react/index.d.ts"
50
50
  ],
51
51
  "cli": [
52
- "./dist/cli.cjs.d.ts"
52
+ "./dist/cli/index.d.ts"
53
53
  ],
54
54
  "universal": [
55
- "./dist/universal.cjs.d.ts"
55
+ "./dist/universal/index.d.ts"
56
56
  ],
57
57
  "shared": [
58
- "./dist/shared.cjs.d.ts"
59
- ],
60
- "babel-plugin": [
61
- "./dist/babel.cjs.d.ts"
58
+ "./dist/shared/index.d.ts"
62
59
  ]
63
60
  }
64
61
  },
65
- "main": "dist/index.cjs",
66
- "module": "dist/index.esm.js",
62
+ "main": "dist/index.js",
63
+ "module": "dist/esm/index.js",
67
64
  "peerDependencies": {
68
65
  "react": ">=16.9.0",
69
66
  "react-dom": ">=16.9.0"
@@ -78,8 +75,8 @@
78
75
  "jest": "^29.7.0",
79
76
  "jest-environment-jsdom": "^29.7.0",
80
77
  "minimist": "^1.2.8",
81
- "react": "^18.3.1",
82
- "react-dom": "^18.3.1",
78
+ "react": "^18.2.0",
79
+ "react-dom": "^18.2.0",
83
80
  "react-router": "^6.21.3",
84
81
  "react-test-renderer": "^18.2.0",
85
82
  "ts-jest": "29.0.1",
@@ -88,8 +85,8 @@
88
85
  },
89
86
  "dependencies": {
90
87
  "fs-extra": "9.1.0",
91
- "@module-federation/runtime": "0.0.0-next-20241010063233",
92
- "@module-federation/sdk": "0.0.0-next-20241010063233"
88
+ "@module-federation/sdk": "0.0.0-next-20241010084324",
89
+ "@module-federation/runtime": "0.0.0-next-20241010084324"
93
90
  },
94
91
  "scripts": {
95
92
  "dev": "cross-env WATCH=true tsup",
package/project.json CHANGED
@@ -1,63 +1,21 @@
1
1
  {
2
- "name": "data-prefetch",
2
+ "name": "module-federation/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"],
7
6
  "targets": {
8
7
  "build": {
9
- "executor": "@nx/rollup:rollup",
10
- "outputs": ["{options.outputPath}"],
8
+ "executor": "nx:run-commands",
11
9
  "options": {
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"]
10
+ "commands": ["npm run build --prefix packages/data-prefetch"]
20
11
  }
21
12
  },
22
13
  "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/linter:eslint",
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": {
47
14
  "executor": "nx:run-commands",
48
15
  "options": {
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
- ]
16
+ "commands": ["npm run test --prefix packages/data-prefetch"]
60
17
  }
61
18
  }
62
- }
19
+ },
20
+ "tags": ["type:pkg"]
63
21
  }
package/src/cli/index.ts CHANGED
@@ -47,8 +47,8 @@ export class PrefetchPlugin implements WebpackPluginInstance {
47
47
  this.options.runtimePlugins = [];
48
48
  }
49
49
 
50
- const runtimePath = path.resolve(__dirname, './plugin.esm.js');
51
- const sharedPath = path.resolve(__dirname, './shared.esm.js');
50
+ const runtimePath = path.resolve(__dirname, '../esm/plugin.js');
51
+ const sharedPath = path.resolve(__dirname, '../esm/shared/index.js');
52
52
  if (!this.options.runtimePlugins?.includes(runtimePath)) {
53
53
  this.options.runtimePlugins!.push(runtimePath);
54
54
  }
package/tsconfig.json CHANGED
@@ -22,6 +22,6 @@
22
22
  "@src/*": ["./src/*"]
23
23
  }
24
24
  },
25
- "include": ["src", "../../global.d.ts", "__tests__/**/*"],
25
+ "include": ["src", "../../global.d.ts", "__tests__/**/*", "tsup.config.ts"],
26
26
  "exclude": ["node_modules/**/*", "../node_modules"]
27
27
  }
package/.swcrc DELETED
@@ -1,29 +0,0 @@
1
- {
2
- "jsc": {
3
- "target": "es2017",
4
- "parser": {
5
- "syntax": "typescript",
6
- "decorators": true,
7
- "dynamicImport": true
8
- },
9
- "transform": {
10
- "decoratorMetadata": true,
11
- "legacyDecorator": true
12
- },
13
- "keepClassNames": true,
14
- "externalHelpers": true,
15
- "loose": true
16
- },
17
- "module": {
18
- "type": "es6"
19
- },
20
- "sourceMaps": true,
21
- "exclude": [
22
- "jest.config.ts",
23
- ".*\\.spec.tsx?$",
24
- ".*\\.test.tsx?$",
25
- "./src/jest-setup.ts$",
26
- "./**/jest-setup.ts$",
27
- ".*.js$"
28
- ]
29
- }
package/dist/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2024-present nieyan(nyqykk)
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,2 +0,0 @@
1
- export * from "./src/cli/babel";
2
- export { default } from "./src/cli/babel";
package/dist/babel.cjs.js DELETED
@@ -1,50 +0,0 @@
1
- 'use strict';
2
-
3
- var path = require('path');
4
-
5
- // no used now
6
- const attribute = 'id';
7
- const hookId = 'usePrefetch';
8
- const importPackage = '@module-federation/data-prefetch/react';
9
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
10
- var babel = ((babel, options)=>{
11
- const t = babel.types;
12
- let shouldHandle = false;
13
- let scope = '';
14
- const { name, exposes } = options;
15
- if (!exposes) {
16
- return {};
17
- }
18
- const exposesKey = Object.keys(exposes);
19
- const processedExposes = exposesKey.map((expose)=>({
20
- key: expose.replace('.', ''),
21
- value: path.resolve(// @ts-ignore
22
- typeof exposes[expose] === 'string' ? exposes[expose] : exposes[expose].import)
23
- }));
24
- return {
25
- visitor: {
26
- ImportDeclaration (nodePath, // biome-ignore lint/suspicious/noExplicitAny: <explanation>
27
- state) {
28
- const source = nodePath.node.source.value;
29
- const { specifiers } = nodePath.node;
30
- const { filename } = state.file.opts;
31
- if (source === importPackage) {
32
- shouldHandle = specifiers.some((specifier)=>specifier.imported && specifier.imported.name === hookId && processedExposes.find(// biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
33
- (expose)=>expose.value === filename && (scope = expose.key)));
34
- }
35
- },
36
- CallExpression (nodePath) {
37
- if (shouldHandle && t.isIdentifier(nodePath.node.callee, {
38
- name: hookId
39
- }) && nodePath.node.arguments.length > 0) {
40
- const objectExpression = nodePath.node.arguments[0];
41
- if (objectExpression && t.isObjectExpression(objectExpression) && !objectExpression.properties.find((p)=>p.key.name === attribute)) {
42
- objectExpression.properties.push(t.objectProperty(t.identifier(attribute), t.stringLiteral(name + scope)));
43
- }
44
- }
45
- }
46
- }
47
- };
48
- });
49
-
50
- module.exports = babel;
@@ -1,2 +0,0 @@
1
- export * from "./src/cli/babel";
2
- export { default } from "./src/cli/babel";
package/dist/babel.esm.js DELETED
@@ -1,48 +0,0 @@
1
- import path from 'path';
2
-
3
- // no used now
4
- const attribute = 'id';
5
- const hookId = 'usePrefetch';
6
- const importPackage = '@module-federation/data-prefetch/react';
7
- // biome-ignore lint/suspicious/noExplicitAny: <explanation>
8
- var babel = ((babel, options)=>{
9
- const t = babel.types;
10
- let shouldHandle = false;
11
- let scope = '';
12
- const { name, exposes } = options;
13
- if (!exposes) {
14
- return {};
15
- }
16
- const exposesKey = Object.keys(exposes);
17
- const processedExposes = exposesKey.map((expose)=>({
18
- key: expose.replace('.', ''),
19
- value: path.resolve(// @ts-ignore
20
- typeof exposes[expose] === 'string' ? exposes[expose] : exposes[expose].import)
21
- }));
22
- return {
23
- visitor: {
24
- ImportDeclaration (nodePath, // biome-ignore lint/suspicious/noExplicitAny: <explanation>
25
- state) {
26
- const source = nodePath.node.source.value;
27
- const { specifiers } = nodePath.node;
28
- const { filename } = state.file.opts;
29
- if (source === importPackage) {
30
- shouldHandle = specifiers.some((specifier)=>specifier.imported && specifier.imported.name === hookId && processedExposes.find(// biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
31
- (expose)=>expose.value === filename && (scope = expose.key)));
32
- }
33
- },
34
- CallExpression (nodePath) {
35
- if (shouldHandle && t.isIdentifier(nodePath.node.callee, {
36
- name: hookId
37
- }) && nodePath.node.arguments.length > 0) {
38
- const objectExpression = nodePath.node.arguments[0];
39
- if (objectExpression && t.isObjectExpression(objectExpression) && !objectExpression.properties.find((p)=>p.key.name === attribute)) {
40
- objectExpression.properties.push(t.objectProperty(t.identifier(attribute), t.stringLiteral(name + scope)));
41
- }
42
- }
43
- }
44
- }
45
- };
46
- });
47
-
48
- export { babel as default };
package/dist/cli.cjs.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src/cli/index";
package/dist/cli.cjs.js DELETED
@@ -1,155 +0,0 @@
1
- 'use strict';
2
-
3
- var path = require('path');
4
- var fs = require('fs-extra');
5
- var sdk = require('@module-federation/sdk');
6
- var normalizeWebpackPath = require('@module-federation/sdk/normalize-webpack-path');
7
- var runtimeUtils = require('./runtime-utils.cjs.js');
8
- require('@module-federation/runtime');
9
-
10
- const TEMP_DIR = '.mf';
11
-
12
- const fileExistsWithCaseSync = (filepath)=>{
13
- const dir = path.dirname(filepath);
14
- if (filepath === '/' || filepath === '.') {
15
- return true;
16
- }
17
- const filenames = fs.readdirSync(dir);
18
- if (filenames.indexOf(path.basename(filepath)) === -1) {
19
- return false;
20
- }
21
- return fileExistsWithCaseSync(dir);
22
- };
23
- const fixPrefetchPath = (exposePath)=>{
24
- const pathExt = [
25
- '.js',
26
- '.ts'
27
- ];
28
- const extReg = /\.(ts|js|tsx|jsx)$/;
29
- if (extReg.test(exposePath)) {
30
- return pathExt.map((ext)=>exposePath.replace(extReg, `.prefetch${ext}`));
31
- } else {
32
- return pathExt.map((ext)=>exposePath + `.prefetch${ext}`);
33
- }
34
- };
35
-
36
- const { RuntimeGlobals, Template } = require(normalizeWebpackPath.normalizeWebpackPath('webpack'));
37
- function getFederationGlobalScope(runtimeGlobals) {
38
- return `${runtimeGlobals.require || '__webpack_require__'}.federation`;
39
- }
40
- class PrefetchPlugin {
41
- // eslint-disable-next-line max-lines-per-function
42
- apply(compiler) {
43
- var _this_options_runtimePlugins, _this_options_runtimePlugins1;
44
- const { name, exposes } = this.options;
45
- if (!exposes) {
46
- return;
47
- }
48
- if (!compiler.options.context) {
49
- throw new Error('compiler.options.context is not defined');
50
- }
51
- const { runtimePlugins } = this.options;
52
- if (!Array.isArray(runtimePlugins)) {
53
- this.options.runtimePlugins = [];
54
- }
55
- const runtimePath = path.resolve(__dirname, './plugin.esm.js');
56
- const sharedPath = path.resolve(__dirname, './shared.esm.js');
57
- if (!((_this_options_runtimePlugins = this.options.runtimePlugins) == null ? void 0 : _this_options_runtimePlugins.includes(runtimePath))) {
58
- this.options.runtimePlugins.push(runtimePath);
59
- }
60
- if (!((_this_options_runtimePlugins1 = this.options.runtimePlugins) == null ? void 0 : _this_options_runtimePlugins1.includes(sharedPath))) {
61
- this.options.runtimePlugins.push(sharedPath);
62
- }
63
- const encodedName = sdk.encodeName(name);
64
- const asyncEntryPath = path.resolve(compiler.options.context, `node_modules/${TEMP_DIR}/${encodedName}/bootstrap.js`);
65
- if (fs.existsSync(asyncEntryPath)) {
66
- fs.unlinkSync(asyncEntryPath);
67
- }
68
- if (!this.options.dataPrefetch) {
69
- return;
70
- }
71
- const exposeAlias = Object.keys(exposes);
72
- exposeAlias.forEach((alias)=>{
73
- let exposePath;
74
- // @ts-ignore
75
- const exposeValue = exposes[alias];
76
- if (typeof exposeValue === 'string') {
77
- exposePath = exposeValue;
78
- } else {
79
- exposePath = exposeValue.import[0];
80
- }
81
- const targetPaths = fixPrefetchPath(exposePath);
82
- for (const pathItem of targetPaths){
83
- const absolutePath = path.resolve(compiler.options.context, pathItem);
84
- if (fileExistsWithCaseSync(absolutePath)) {
85
- const absoluteAlias = alias.replace('.', '');
86
- this._reWriteExports += `export * as ${runtimeUtils.getPrefetchId(`${name}${absoluteAlias}`)} from '${absolutePath}';\n`;
87
- break;
88
- }
89
- }
90
- });
91
- if (!this._reWriteExports) {
92
- return;
93
- }
94
- const tempDirRealPath = path.resolve(compiler.options.context, 'node_modules', TEMP_DIR);
95
- if (!fs.existsSync(tempDirRealPath)) {
96
- fs.mkdirSync(tempDirRealPath);
97
- }
98
- if (!fs.existsSync(`${tempDirRealPath}/${encodedName}`)) {
99
- fs.mkdirSync(`${tempDirRealPath}/${encodedName}`);
100
- }
101
- fs.writeFileSync(asyncEntryPath, this._reWriteExports);
102
- new compiler.webpack.DefinePlugin({
103
- FederationDataPrefetch: JSON.stringify(asyncEntryPath)
104
- }).apply(compiler);
105
- }
106
- static addRuntime(compiler, options) {
107
- const encodedName = sdk.encodeName(options.name);
108
- if (!compiler.options.context) {
109
- throw new Error('compiler.options.context is not defined');
110
- }
111
- const prefetchEntry = path.resolve(compiler.options.context, `node_modules/.mf/${encodedName}/bootstrap.js`);
112
- const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});
113
- return Template.asString([
114
- fs.existsSync(prefetchEntry) ? Template.indent([
115
- 'function injectPrefetch() {',
116
- Template.indent([
117
- `globalThis.__FEDERATION__ = globalThis.__FEDERATION__ || {};`,
118
- `globalThis.__FEDERATION__['${sdk.MFPrefetchCommon.globalKey}'] = globalThis.__FEDERATION__['${sdk.MFPrefetchCommon.globalKey}'] || {`,
119
- `entryLoading: {},`,
120
- `instance: new Map(),`,
121
- `__PREFETCH_EXPORTS__: {},`,
122
- `};`,
123
- `globalThis.__FEDERATION__['${sdk.MFPrefetchCommon.globalKey}']['${sdk.MFPrefetchCommon.exportsKey}'] = globalThis.__FEDERATION__['${sdk.MFPrefetchCommon.globalKey}']['${sdk.MFPrefetchCommon.exportsKey}'] || {};`,
124
- `globalThis.__FEDERATION__['${sdk.MFPrefetchCommon.globalKey}']['${sdk.MFPrefetchCommon.exportsKey}']['${options.name}'] = function(){ return import('${prefetchEntry}');}`
125
- ]),
126
- '}',
127
- `${federationGlobal}.prefetch = injectPrefetch`
128
- ]) : '',
129
- Template.indent([
130
- `if(!${federationGlobal}.isMFRemote && ${federationGlobal}.prefetch){`,
131
- `${federationGlobal}.prefetch()`,
132
- '}'
133
- ])
134
- ]);
135
- }
136
- static setRemoteIdentifier() {
137
- const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});
138
- return Template.indent([
139
- `${federationGlobal}.isMFRemote = true;`
140
- ]);
141
- }
142
- static removeRemoteIdentifier() {
143
- const federationGlobal = getFederationGlobalScope(RuntimeGlobals || {});
144
- return Template.indent([
145
- `${federationGlobal}.isMFRemote = false;`
146
- ]);
147
- }
148
- constructor(options){
149
- this.options = options;
150
- this._reWriteExports = '';
151
- }
152
- }
153
-
154
- exports.PrefetchPlugin = PrefetchPlugin;
155
- exports.getFederationGlobalScope = getFederationGlobalScope;
package/dist/cli.esm.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./src/cli/index";