@module-federation/managers 0.24.1 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/BasicPluginOptionsManager.js +70 -0
- package/dist/BasicPluginOptionsManager.mjs +24 -0
- package/dist/ContainerManager.js +228 -0
- package/dist/ContainerManager.mjs +168 -0
- package/dist/PKGJsonManager.js +113 -0
- package/dist/PKGJsonManager.mjs +51 -0
- package/dist/RemoteManager.js +160 -0
- package/dist/RemoteManager.mjs +112 -0
- package/dist/SharedManager.js +196 -0
- package/dist/SharedManager.mjs +136 -0
- package/dist/constant.js +54 -0
- package/dist/constant.mjs +6 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +93 -0
- package/dist/index.mjs +36 -0
- package/dist/types.js +31 -0
- package/dist/types.mjs +4 -0
- package/dist/utils.js +119 -0
- package/dist/utils.mjs +66 -0
- package/package.json +13 -8
- package/dist/index.cjs.js +0 -499
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.esm.js +0 -490
- package/dist/index.esm.js.map +0 -1
- package/dist/src/index.d.ts +0 -8
- /package/dist/{src/BasicPluginOptionsManager.d.ts → BasicPluginOptionsManager.d.ts} +0 -0
- /package/dist/{src/ContainerManager.d.ts → ContainerManager.d.ts} +0 -0
- /package/dist/{src/PKGJsonManager.d.ts → PKGJsonManager.d.ts} +0 -0
- /package/dist/{src/RemoteManager.d.ts → RemoteManager.d.ts} +0 -0
- /package/dist/{src/SharedManager.d.ts → SharedManager.d.ts} +0 -0
- /package/dist/{src/constant.d.ts → constant.d.ts} +0 -0
- /package/dist/{src/types.d.ts → types.d.ts} +0 -0
- /package/dist/{src/utils.d.ts → utils.d.ts} +0 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
3
|
+
return typeof document === 'undefined'
|
|
4
|
+
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
5
|
+
: (document.currentScript && document.currentScript.src) ||
|
|
6
|
+
new URL('main.js', document.baseURI).href;
|
|
7
|
+
})();
|
|
8
|
+
;
|
|
9
|
+
// The require scope
|
|
10
|
+
var __webpack_require__ = {};
|
|
11
|
+
|
|
12
|
+
/************************************************************************/
|
|
13
|
+
// webpack/runtime/define_property_getters
|
|
14
|
+
(() => {
|
|
15
|
+
__webpack_require__.d = (exports, definition) => {
|
|
16
|
+
for(var key in definition) {
|
|
17
|
+
if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
18
|
+
Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
})();
|
|
23
|
+
// webpack/runtime/has_own_property
|
|
24
|
+
(() => {
|
|
25
|
+
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
26
|
+
})();
|
|
27
|
+
// webpack/runtime/make_namespace_object
|
|
28
|
+
(() => {
|
|
29
|
+
// define __esModule on exports
|
|
30
|
+
__webpack_require__.r = (exports) => {
|
|
31
|
+
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
32
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
/************************************************************************/
|
|
38
|
+
var __webpack_exports__ = {};
|
|
39
|
+
// ESM COMPAT FLAG
|
|
40
|
+
__webpack_require__.r(__webpack_exports__);
|
|
41
|
+
|
|
42
|
+
// EXPORTS
|
|
43
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
44
|
+
RemoteManager: () => (/* binding */ RemoteManager)
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
;// CONCATENATED MODULE: external "@module-federation/sdk"
|
|
48
|
+
const sdk_namespaceObject = require("@module-federation/sdk");
|
|
49
|
+
;// CONCATENATED MODULE: external "./BasicPluginOptionsManager.js"
|
|
50
|
+
const external_BasicPluginOptionsManager_js_namespaceObject = require("./BasicPluginOptionsManager.js");
|
|
51
|
+
;// CONCATENATED MODULE: external "./constant.js"
|
|
52
|
+
const external_constant_js_namespaceObject = require("./constant.js");
|
|
53
|
+
;// CONCATENATED MODULE: ./src/RemoteManager.ts
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
function getEntry(remoteObj) {
|
|
58
|
+
if (typeof remoteObj === 'string') {
|
|
59
|
+
return remoteObj;
|
|
60
|
+
}
|
|
61
|
+
if (typeof remoteObj.external === 'string') {
|
|
62
|
+
return remoteObj.external;
|
|
63
|
+
}
|
|
64
|
+
throw new Error('Not support "array" remote value yet!');
|
|
65
|
+
}
|
|
66
|
+
class RemoteManager extends external_BasicPluginOptionsManager_js_namespaceObject.BasicPluginOptionsManager {
|
|
67
|
+
get enable() {
|
|
68
|
+
return Boolean(this.remotes && (Array.isArray(this.remotes) ? this.remotes.length > 0 : Object.keys(this.remotes).length > 0));
|
|
69
|
+
}
|
|
70
|
+
get statsRemoteWithEmptyUsedIn() {
|
|
71
|
+
const { name } = this.options;
|
|
72
|
+
return Object.keys(this.normalizedOptions).reduce((sum, cur)=>{
|
|
73
|
+
const normalizedOption = this.normalizedOptions[cur];
|
|
74
|
+
let curObj;
|
|
75
|
+
if ('entry' in normalizedOption) {
|
|
76
|
+
curObj = {
|
|
77
|
+
entry: normalizedOption.entry,
|
|
78
|
+
alias: normalizedOption.alias,
|
|
79
|
+
moduleName: external_constant_js_namespaceObject.UNKNOWN_MODULE_NAME,
|
|
80
|
+
federationContainerName: normalizedOption.name,
|
|
81
|
+
consumingFederationContainerName: name,
|
|
82
|
+
usedIn: [
|
|
83
|
+
external_constant_js_namespaceObject.UNKNOWN_MODULE_NAME
|
|
84
|
+
]
|
|
85
|
+
};
|
|
86
|
+
} else {
|
|
87
|
+
curObj = {
|
|
88
|
+
alias: normalizedOption.alias,
|
|
89
|
+
moduleName: external_constant_js_namespaceObject.UNKNOWN_MODULE_NAME,
|
|
90
|
+
version: normalizedOption.version,
|
|
91
|
+
federationContainerName: normalizedOption.name,
|
|
92
|
+
consumingFederationContainerName: name,
|
|
93
|
+
usedIn: [
|
|
94
|
+
external_constant_js_namespaceObject.UNKNOWN_MODULE_NAME
|
|
95
|
+
]
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
sum.push(curObj);
|
|
99
|
+
return sum;
|
|
100
|
+
}, []);
|
|
101
|
+
}
|
|
102
|
+
// 'micro-app-sub3': 'app:@garfish/micro-app-sub3:0.0.4',
|
|
103
|
+
// ↓↓↓
|
|
104
|
+
// {
|
|
105
|
+
// 'micro-app-sub3': @garfish/micro-app-sub3:0.0.4
|
|
106
|
+
// }
|
|
107
|
+
get dtsRemotes() {
|
|
108
|
+
return Object.keys(this.normalizedOptions).reduce((sum, remoteAlias)=>{
|
|
109
|
+
const remoteInfo = this.normalizedOptions[remoteAlias];
|
|
110
|
+
sum[remoteAlias] = (0,sdk_namespaceObject.composeKeyWithSeparator)(remoteInfo.name, 'entry' in remoteInfo ? remoteInfo.entry : remoteInfo.version);
|
|
111
|
+
return sum;
|
|
112
|
+
}, {});
|
|
113
|
+
}
|
|
114
|
+
get remotes() {
|
|
115
|
+
return this.options.remotes;
|
|
116
|
+
}
|
|
117
|
+
// INFO: only support remoteType: script now
|
|
118
|
+
normalizeOptions(options = {}) {
|
|
119
|
+
this.normalizedOptions = Object.keys(options).reduce((sum, remoteAlias)=>{
|
|
120
|
+
if (Array.isArray(options)) {
|
|
121
|
+
return sum;
|
|
122
|
+
}
|
|
123
|
+
const remoteInfo = options[remoteAlias];
|
|
124
|
+
if (Array.isArray(remoteInfo)) {
|
|
125
|
+
return sum;
|
|
126
|
+
}
|
|
127
|
+
let parsedOptions;
|
|
128
|
+
try {
|
|
129
|
+
parsedOptions = (0,sdk_namespaceObject.parseEntry)(typeof remoteInfo === 'string' ? remoteInfo : getEntry(remoteInfo), '', '@');
|
|
130
|
+
} catch (e) {
|
|
131
|
+
// noop
|
|
132
|
+
}
|
|
133
|
+
if (!parsedOptions) {
|
|
134
|
+
return sum;
|
|
135
|
+
}
|
|
136
|
+
sum[remoteAlias] = {
|
|
137
|
+
...parsedOptions,
|
|
138
|
+
alias: remoteAlias,
|
|
139
|
+
shareScope: typeof remoteInfo === 'object' ? remoteInfo.shareScope || 'default' : 'default'
|
|
140
|
+
};
|
|
141
|
+
return sum;
|
|
142
|
+
}, {});
|
|
143
|
+
}
|
|
144
|
+
init(options) {
|
|
145
|
+
this.setOptions(options);
|
|
146
|
+
this.normalizeOptions(options.remotes);
|
|
147
|
+
}
|
|
148
|
+
constructor(...args){
|
|
149
|
+
super(...args), this.normalizedOptions = {};
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
exports.RemoteManager = __webpack_exports__.RemoteManager;
|
|
155
|
+
for(var __webpack_i__ in __webpack_exports__) {
|
|
156
|
+
if(["RemoteManager"].indexOf(__webpack_i__) === -1) {
|
|
157
|
+
exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { composeKeyWithSeparator, parseEntry } from "@module-federation/sdk";
|
|
2
|
+
import { BasicPluginOptionsManager } from "./BasicPluginOptionsManager.mjs";
|
|
3
|
+
import { UNKNOWN_MODULE_NAME } from "./constant.mjs";
|
|
4
|
+
|
|
5
|
+
;// CONCATENATED MODULE: external "@module-federation/sdk"
|
|
6
|
+
|
|
7
|
+
;// CONCATENATED MODULE: external "./BasicPluginOptionsManager.mjs"
|
|
8
|
+
|
|
9
|
+
;// CONCATENATED MODULE: external "./constant.mjs"
|
|
10
|
+
|
|
11
|
+
;// CONCATENATED MODULE: ./src/RemoteManager.ts
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
function getEntry(remoteObj) {
|
|
16
|
+
if (typeof remoteObj === 'string') {
|
|
17
|
+
return remoteObj;
|
|
18
|
+
}
|
|
19
|
+
if (typeof remoteObj.external === 'string') {
|
|
20
|
+
return remoteObj.external;
|
|
21
|
+
}
|
|
22
|
+
throw new Error('Not support "array" remote value yet!');
|
|
23
|
+
}
|
|
24
|
+
class RemoteManager extends BasicPluginOptionsManager {
|
|
25
|
+
get enable() {
|
|
26
|
+
return Boolean(this.remotes && (Array.isArray(this.remotes) ? this.remotes.length > 0 : Object.keys(this.remotes).length > 0));
|
|
27
|
+
}
|
|
28
|
+
get statsRemoteWithEmptyUsedIn() {
|
|
29
|
+
const { name } = this.options;
|
|
30
|
+
return Object.keys(this.normalizedOptions).reduce((sum, cur)=>{
|
|
31
|
+
const normalizedOption = this.normalizedOptions[cur];
|
|
32
|
+
let curObj;
|
|
33
|
+
if ('entry' in normalizedOption) {
|
|
34
|
+
curObj = {
|
|
35
|
+
entry: normalizedOption.entry,
|
|
36
|
+
alias: normalizedOption.alias,
|
|
37
|
+
moduleName: UNKNOWN_MODULE_NAME,
|
|
38
|
+
federationContainerName: normalizedOption.name,
|
|
39
|
+
consumingFederationContainerName: name,
|
|
40
|
+
usedIn: [
|
|
41
|
+
UNKNOWN_MODULE_NAME
|
|
42
|
+
]
|
|
43
|
+
};
|
|
44
|
+
} else {
|
|
45
|
+
curObj = {
|
|
46
|
+
alias: normalizedOption.alias,
|
|
47
|
+
moduleName: UNKNOWN_MODULE_NAME,
|
|
48
|
+
version: normalizedOption.version,
|
|
49
|
+
federationContainerName: normalizedOption.name,
|
|
50
|
+
consumingFederationContainerName: name,
|
|
51
|
+
usedIn: [
|
|
52
|
+
UNKNOWN_MODULE_NAME
|
|
53
|
+
]
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
sum.push(curObj);
|
|
57
|
+
return sum;
|
|
58
|
+
}, []);
|
|
59
|
+
}
|
|
60
|
+
// 'micro-app-sub3': 'app:@garfish/micro-app-sub3:0.0.4',
|
|
61
|
+
// ↓↓↓
|
|
62
|
+
// {
|
|
63
|
+
// 'micro-app-sub3': @garfish/micro-app-sub3:0.0.4
|
|
64
|
+
// }
|
|
65
|
+
get dtsRemotes() {
|
|
66
|
+
return Object.keys(this.normalizedOptions).reduce((sum, remoteAlias)=>{
|
|
67
|
+
const remoteInfo = this.normalizedOptions[remoteAlias];
|
|
68
|
+
sum[remoteAlias] = composeKeyWithSeparator(remoteInfo.name, 'entry' in remoteInfo ? remoteInfo.entry : remoteInfo.version);
|
|
69
|
+
return sum;
|
|
70
|
+
}, {});
|
|
71
|
+
}
|
|
72
|
+
get remotes() {
|
|
73
|
+
return this.options.remotes;
|
|
74
|
+
}
|
|
75
|
+
// INFO: only support remoteType: script now
|
|
76
|
+
normalizeOptions(options = {}) {
|
|
77
|
+
this.normalizedOptions = Object.keys(options).reduce((sum, remoteAlias)=>{
|
|
78
|
+
if (Array.isArray(options)) {
|
|
79
|
+
return sum;
|
|
80
|
+
}
|
|
81
|
+
const remoteInfo = options[remoteAlias];
|
|
82
|
+
if (Array.isArray(remoteInfo)) {
|
|
83
|
+
return sum;
|
|
84
|
+
}
|
|
85
|
+
let parsedOptions;
|
|
86
|
+
try {
|
|
87
|
+
parsedOptions = parseEntry(typeof remoteInfo === 'string' ? remoteInfo : getEntry(remoteInfo), '', '@');
|
|
88
|
+
} catch (e) {
|
|
89
|
+
// noop
|
|
90
|
+
}
|
|
91
|
+
if (!parsedOptions) {
|
|
92
|
+
return sum;
|
|
93
|
+
}
|
|
94
|
+
sum[remoteAlias] = {
|
|
95
|
+
...parsedOptions,
|
|
96
|
+
alias: remoteAlias,
|
|
97
|
+
shareScope: typeof remoteInfo === 'object' ? remoteInfo.shareScope || 'default' : 'default'
|
|
98
|
+
};
|
|
99
|
+
return sum;
|
|
100
|
+
}, {});
|
|
101
|
+
}
|
|
102
|
+
init(options) {
|
|
103
|
+
this.setOptions(options);
|
|
104
|
+
this.normalizeOptions(options.remotes);
|
|
105
|
+
}
|
|
106
|
+
constructor(...args){
|
|
107
|
+
super(...args), this.normalizedOptions = {};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
export { RemoteManager };
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
3
|
+
return typeof document === 'undefined'
|
|
4
|
+
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
5
|
+
: (document.currentScript && document.currentScript.src) ||
|
|
6
|
+
new URL('main.js', document.baseURI).href;
|
|
7
|
+
})();
|
|
8
|
+
;
|
|
9
|
+
// The require scope
|
|
10
|
+
var __webpack_require__ = {};
|
|
11
|
+
|
|
12
|
+
/************************************************************************/
|
|
13
|
+
// webpack/runtime/compat_get_default_export
|
|
14
|
+
(() => {
|
|
15
|
+
// getDefaultExport function for compatibility with non-ESM modules
|
|
16
|
+
__webpack_require__.n = (module) => {
|
|
17
|
+
var getter = module && module.__esModule ?
|
|
18
|
+
() => (module['default']) :
|
|
19
|
+
() => (module);
|
|
20
|
+
__webpack_require__.d(getter, { a: getter });
|
|
21
|
+
return getter;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
})();
|
|
25
|
+
// webpack/runtime/define_property_getters
|
|
26
|
+
(() => {
|
|
27
|
+
__webpack_require__.d = (exports, definition) => {
|
|
28
|
+
for(var key in definition) {
|
|
29
|
+
if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
30
|
+
Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
// webpack/runtime/has_own_property
|
|
36
|
+
(() => {
|
|
37
|
+
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
38
|
+
})();
|
|
39
|
+
// webpack/runtime/make_namespace_object
|
|
40
|
+
(() => {
|
|
41
|
+
// define __esModule on exports
|
|
42
|
+
__webpack_require__.r = (exports) => {
|
|
43
|
+
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
44
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
45
|
+
}
|
|
46
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
47
|
+
};
|
|
48
|
+
})();
|
|
49
|
+
/************************************************************************/
|
|
50
|
+
var __webpack_exports__ = {};
|
|
51
|
+
// ESM COMPAT FLAG
|
|
52
|
+
__webpack_require__.r(__webpack_exports__);
|
|
53
|
+
|
|
54
|
+
// EXPORTS
|
|
55
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
56
|
+
SharedManager: () => (/* binding */ SharedManager)
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
;// CONCATENATED MODULE: external "find-pkg"
|
|
60
|
+
const external_find_pkg_namespaceObject = require("find-pkg");
|
|
61
|
+
var external_find_pkg_default = /*#__PURE__*/__webpack_require__.n(external_find_pkg_namespaceObject);
|
|
62
|
+
;// CONCATENATED MODULE: external "path"
|
|
63
|
+
const external_path_namespaceObject = require("path");
|
|
64
|
+
var external_path_default = /*#__PURE__*/__webpack_require__.n(external_path_namespaceObject);
|
|
65
|
+
;// CONCATENATED MODULE: external "fs-extra"
|
|
66
|
+
const external_fs_extra_namespaceObject = require("fs-extra");
|
|
67
|
+
var external_fs_extra_default = /*#__PURE__*/__webpack_require__.n(external_fs_extra_namespaceObject);
|
|
68
|
+
;// CONCATENATED MODULE: external "@module-federation/sdk"
|
|
69
|
+
const sdk_namespaceObject = require("@module-federation/sdk");
|
|
70
|
+
;// CONCATENATED MODULE: external "./BasicPluginOptionsManager.js"
|
|
71
|
+
const external_BasicPluginOptionsManager_js_namespaceObject = require("./BasicPluginOptionsManager.js");
|
|
72
|
+
;// CONCATENATED MODULE: external "./utils.js"
|
|
73
|
+
const external_utils_js_namespaceObject = require("./utils.js");
|
|
74
|
+
;// CONCATENATED MODULE: ./src/SharedManager.ts
|
|
75
|
+
// @ts-ignore this pkg miss types
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
class SharedManager extends external_BasicPluginOptionsManager_js_namespaceObject.BasicPluginOptionsManager {
|
|
83
|
+
get enable() {
|
|
84
|
+
return Boolean(Object.keys(this.sharedPluginOptions.shared).length);
|
|
85
|
+
}
|
|
86
|
+
get sharedPluginOptions() {
|
|
87
|
+
const normalizedShared = this.normalizedOptions;
|
|
88
|
+
const shared = Object.keys(normalizedShared).reduce((sum, cur)=>{
|
|
89
|
+
const { singleton, requiredVersion, version, eager, shareScope, import: sharedImport, treeShaking } = normalizedShared[cur];
|
|
90
|
+
sum[cur] = {
|
|
91
|
+
singleton,
|
|
92
|
+
requiredVersion,
|
|
93
|
+
version,
|
|
94
|
+
eager,
|
|
95
|
+
shareScope,
|
|
96
|
+
import: sharedImport,
|
|
97
|
+
treeShaking
|
|
98
|
+
};
|
|
99
|
+
return sum;
|
|
100
|
+
}, {});
|
|
101
|
+
return {
|
|
102
|
+
shared,
|
|
103
|
+
shareScope: this.options.shareScope || 'default'
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
findPkg(name, shareConfig) {
|
|
107
|
+
try {
|
|
108
|
+
let pkgPath = '';
|
|
109
|
+
let depName = name;
|
|
110
|
+
if (shareConfig.import) {
|
|
111
|
+
if (external_path_default().isAbsolute(shareConfig.import)) {
|
|
112
|
+
pkgPath = shareConfig.import;
|
|
113
|
+
} else if (shareConfig.import.startsWith('.')) {
|
|
114
|
+
pkgPath = external_path_default().resolve(this.root, shareConfig.import);
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
if (shareConfig.packageName) {
|
|
118
|
+
depName = shareConfig.packageName;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
pkgPath = pkgPath || require.resolve(depName, {
|
|
122
|
+
paths: [
|
|
123
|
+
this.root
|
|
124
|
+
]
|
|
125
|
+
});
|
|
126
|
+
const pkgJsonPath = external_find_pkg_default().sync(pkgPath);
|
|
127
|
+
return {
|
|
128
|
+
pkg: JSON.parse(external_fs_extra_default().readFileSync(pkgJsonPath, 'utf-8')),
|
|
129
|
+
path: '',
|
|
130
|
+
pkgPath: ''
|
|
131
|
+
};
|
|
132
|
+
} catch (err) {
|
|
133
|
+
return {
|
|
134
|
+
pkg: {},
|
|
135
|
+
path: '',
|
|
136
|
+
pkgPath: ''
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
get enableTreeShaking() {
|
|
141
|
+
return Object.values(this.normalizedOptions).some((item)=>item.treeShaking);
|
|
142
|
+
}
|
|
143
|
+
transformSharedConfig(sharedConfig) {
|
|
144
|
+
const defaultSharedConfig = {
|
|
145
|
+
singleton: true,
|
|
146
|
+
requiredVersion: undefined,
|
|
147
|
+
shareScope: 'default'
|
|
148
|
+
};
|
|
149
|
+
return {
|
|
150
|
+
...defaultSharedConfig,
|
|
151
|
+
...sharedConfig
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
normalizeOptions(options) {
|
|
155
|
+
const normalizedShared = {};
|
|
156
|
+
const sharedOptions = (0,external_utils_js_namespaceObject.parseOptions)(options, (item, key)=>{
|
|
157
|
+
if (typeof item !== 'string') throw new Error('Unexpected array in shared');
|
|
158
|
+
const config = item === key || !(0,sdk_namespaceObject.isRequiredVersion)(item) ? {
|
|
159
|
+
import: item
|
|
160
|
+
} : {
|
|
161
|
+
import: key,
|
|
162
|
+
requiredVersion: item
|
|
163
|
+
};
|
|
164
|
+
return config;
|
|
165
|
+
}, (item)=>item);
|
|
166
|
+
sharedOptions.forEach((item)=>{
|
|
167
|
+
const [sharedName, sharedOptions] = item;
|
|
168
|
+
const pkgInfo = this.findPkg(sharedName, sharedOptions);
|
|
169
|
+
const sharedConfig = this.transformSharedConfig(sharedOptions);
|
|
170
|
+
normalizedShared[sharedName] = {
|
|
171
|
+
...sharedConfig,
|
|
172
|
+
requiredVersion: typeof sharedConfig.requiredVersion !== 'undefined' ? sharedConfig.requiredVersion : `^${pkgInfo.pkg['version']}`,
|
|
173
|
+
name: sharedName,
|
|
174
|
+
version: pkgInfo.pkg['version'],
|
|
175
|
+
eager: Boolean(sharedConfig.eager)
|
|
176
|
+
};
|
|
177
|
+
});
|
|
178
|
+
this.normalizedOptions = normalizedShared;
|
|
179
|
+
}
|
|
180
|
+
init(options) {
|
|
181
|
+
this.setOptions(options);
|
|
182
|
+
this.normalizeOptions(options.shared);
|
|
183
|
+
}
|
|
184
|
+
constructor(...args){
|
|
185
|
+
super(...args), this.normalizedOptions = {};
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
exports.SharedManager = __webpack_exports__.SharedManager;
|
|
191
|
+
for(var __webpack_i__ in __webpack_exports__) {
|
|
192
|
+
if(["SharedManager"].indexOf(__webpack_i__) === -1) {
|
|
193
|
+
exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import find_pkg from "find-pkg";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fs_extra from "fs-extra";
|
|
4
|
+
import { isRequiredVersion } from "@module-federation/sdk";
|
|
5
|
+
import { BasicPluginOptionsManager } from "./BasicPluginOptionsManager.mjs";
|
|
6
|
+
import { parseOptions } from "./utils.mjs";
|
|
7
|
+
|
|
8
|
+
;// CONCATENATED MODULE: external "find-pkg"
|
|
9
|
+
|
|
10
|
+
;// CONCATENATED MODULE: external "path"
|
|
11
|
+
|
|
12
|
+
;// CONCATENATED MODULE: external "fs-extra"
|
|
13
|
+
|
|
14
|
+
;// CONCATENATED MODULE: external "@module-federation/sdk"
|
|
15
|
+
|
|
16
|
+
;// CONCATENATED MODULE: external "./BasicPluginOptionsManager.mjs"
|
|
17
|
+
|
|
18
|
+
;// CONCATENATED MODULE: external "./utils.mjs"
|
|
19
|
+
|
|
20
|
+
;// CONCATENATED MODULE: ./src/SharedManager.ts
|
|
21
|
+
// @ts-ignore this pkg miss types
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class SharedManager extends BasicPluginOptionsManager {
|
|
29
|
+
get enable() {
|
|
30
|
+
return Boolean(Object.keys(this.sharedPluginOptions.shared).length);
|
|
31
|
+
}
|
|
32
|
+
get sharedPluginOptions() {
|
|
33
|
+
const normalizedShared = this.normalizedOptions;
|
|
34
|
+
const shared = Object.keys(normalizedShared).reduce((sum, cur)=>{
|
|
35
|
+
const { singleton, requiredVersion, version, eager, shareScope, import: sharedImport, treeShaking } = normalizedShared[cur];
|
|
36
|
+
sum[cur] = {
|
|
37
|
+
singleton,
|
|
38
|
+
requiredVersion,
|
|
39
|
+
version,
|
|
40
|
+
eager,
|
|
41
|
+
shareScope,
|
|
42
|
+
import: sharedImport,
|
|
43
|
+
treeShaking
|
|
44
|
+
};
|
|
45
|
+
return sum;
|
|
46
|
+
}, {});
|
|
47
|
+
return {
|
|
48
|
+
shared,
|
|
49
|
+
shareScope: this.options.shareScope || 'default'
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
findPkg(name, shareConfig) {
|
|
53
|
+
try {
|
|
54
|
+
let pkgPath = '';
|
|
55
|
+
let depName = name;
|
|
56
|
+
if (shareConfig.import) {
|
|
57
|
+
if (path.isAbsolute(shareConfig.import)) {
|
|
58
|
+
pkgPath = shareConfig.import;
|
|
59
|
+
} else if (shareConfig.import.startsWith('.')) {
|
|
60
|
+
pkgPath = path.resolve(this.root, shareConfig.import);
|
|
61
|
+
}
|
|
62
|
+
} else {
|
|
63
|
+
if (shareConfig.packageName) {
|
|
64
|
+
depName = shareConfig.packageName;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
pkgPath = pkgPath || require.resolve(depName, {
|
|
68
|
+
paths: [
|
|
69
|
+
this.root
|
|
70
|
+
]
|
|
71
|
+
});
|
|
72
|
+
const pkgJsonPath = find_pkg.sync(pkgPath);
|
|
73
|
+
return {
|
|
74
|
+
pkg: JSON.parse(fs_extra.readFileSync(pkgJsonPath, 'utf-8')),
|
|
75
|
+
path: '',
|
|
76
|
+
pkgPath: ''
|
|
77
|
+
};
|
|
78
|
+
} catch (err) {
|
|
79
|
+
return {
|
|
80
|
+
pkg: {},
|
|
81
|
+
path: '',
|
|
82
|
+
pkgPath: ''
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
get enableTreeShaking() {
|
|
87
|
+
return Object.values(this.normalizedOptions).some((item)=>item.treeShaking);
|
|
88
|
+
}
|
|
89
|
+
transformSharedConfig(sharedConfig) {
|
|
90
|
+
const defaultSharedConfig = {
|
|
91
|
+
singleton: true,
|
|
92
|
+
requiredVersion: undefined,
|
|
93
|
+
shareScope: 'default'
|
|
94
|
+
};
|
|
95
|
+
return {
|
|
96
|
+
...defaultSharedConfig,
|
|
97
|
+
...sharedConfig
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
normalizeOptions(options) {
|
|
101
|
+
const normalizedShared = {};
|
|
102
|
+
const sharedOptions = parseOptions(options, (item, key)=>{
|
|
103
|
+
if (typeof item !== 'string') throw new Error('Unexpected array in shared');
|
|
104
|
+
const config = item === key || !isRequiredVersion(item) ? {
|
|
105
|
+
import: item
|
|
106
|
+
} : {
|
|
107
|
+
import: key,
|
|
108
|
+
requiredVersion: item
|
|
109
|
+
};
|
|
110
|
+
return config;
|
|
111
|
+
}, (item)=>item);
|
|
112
|
+
sharedOptions.forEach((item)=>{
|
|
113
|
+
const [sharedName, sharedOptions] = item;
|
|
114
|
+
const pkgInfo = this.findPkg(sharedName, sharedOptions);
|
|
115
|
+
const sharedConfig = this.transformSharedConfig(sharedOptions);
|
|
116
|
+
normalizedShared[sharedName] = {
|
|
117
|
+
...sharedConfig,
|
|
118
|
+
requiredVersion: typeof sharedConfig.requiredVersion !== 'undefined' ? sharedConfig.requiredVersion : `^${pkgInfo.pkg['version']}`,
|
|
119
|
+
name: sharedName,
|
|
120
|
+
version: pkgInfo.pkg['version'],
|
|
121
|
+
eager: Boolean(sharedConfig.eager)
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
this.normalizedOptions = normalizedShared;
|
|
125
|
+
}
|
|
126
|
+
init(options) {
|
|
127
|
+
this.setOptions(options);
|
|
128
|
+
this.normalizeOptions(options.shared);
|
|
129
|
+
}
|
|
130
|
+
constructor(...args){
|
|
131
|
+
super(...args), this.normalizedOptions = {};
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
export { SharedManager };
|
package/dist/constant.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const __rslib_import_meta_url__ = /*#__PURE__*/ (function () {
|
|
3
|
+
return typeof document === 'undefined'
|
|
4
|
+
? new (require('url'.replace('', '')).URL)('file:' + __filename).href
|
|
5
|
+
: (document.currentScript && document.currentScript.src) ||
|
|
6
|
+
new URL('main.js', document.baseURI).href;
|
|
7
|
+
})();
|
|
8
|
+
;
|
|
9
|
+
// The require scope
|
|
10
|
+
var __webpack_require__ = {};
|
|
11
|
+
|
|
12
|
+
/************************************************************************/
|
|
13
|
+
// webpack/runtime/define_property_getters
|
|
14
|
+
(() => {
|
|
15
|
+
__webpack_require__.d = (exports, definition) => {
|
|
16
|
+
for(var key in definition) {
|
|
17
|
+
if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
18
|
+
Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
})();
|
|
23
|
+
// webpack/runtime/has_own_property
|
|
24
|
+
(() => {
|
|
25
|
+
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
26
|
+
})();
|
|
27
|
+
// webpack/runtime/make_namespace_object
|
|
28
|
+
(() => {
|
|
29
|
+
// define __esModule on exports
|
|
30
|
+
__webpack_require__.r = (exports) => {
|
|
31
|
+
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
32
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
33
|
+
}
|
|
34
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
/************************************************************************/
|
|
38
|
+
var __webpack_exports__ = {};
|
|
39
|
+
__webpack_require__.r(__webpack_exports__);
|
|
40
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
41
|
+
LOCAL_BUILD_VERSION: () => (LOCAL_BUILD_VERSION),
|
|
42
|
+
UNKNOWN_MODULE_NAME: () => (UNKNOWN_MODULE_NAME)
|
|
43
|
+
});
|
|
44
|
+
const LOCAL_BUILD_VERSION = 'local';
|
|
45
|
+
const UNKNOWN_MODULE_NAME = 'UNKNOWN';
|
|
46
|
+
|
|
47
|
+
exports.LOCAL_BUILD_VERSION = __webpack_exports__.LOCAL_BUILD_VERSION;
|
|
48
|
+
exports.UNKNOWN_MODULE_NAME = __webpack_exports__.UNKNOWN_MODULE_NAME;
|
|
49
|
+
for(var __webpack_i__ in __webpack_exports__) {
|
|
50
|
+
if(["LOCAL_BUILD_VERSION","UNKNOWN_MODULE_NAME"].indexOf(__webpack_i__) === -1) {
|
|
51
|
+
exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1,8 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { BasicPluginOptionsManager } from './BasicPluginOptionsManager';
|
|
2
|
+
export { ContainerManager } from './ContainerManager';
|
|
3
|
+
export { PKGJsonManager } from './PKGJsonManager';
|
|
4
|
+
export { RemoteManager } from './RemoteManager';
|
|
5
|
+
export { SharedManager } from './SharedManager';
|
|
6
|
+
export { UNKNOWN_MODULE_NAME } from './constant';
|
|
7
|
+
export * as utils from './utils';
|
|
8
|
+
export * as types from './types';
|