@module-federation/managers 0.0.0-perf-devtools-20260107043700 → 0.0.0-perf-website-code-usage-20260914033703
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.d.ts +10 -0
- package/dist/BasicPluginOptionsManager.js +73 -0
- package/dist/BasicPluginOptionsManager.mjs +22 -0
- package/dist/ContainerManager.d.ts +20 -0
- package/dist/ContainerManager.js +230 -0
- package/dist/ContainerManager.mjs +163 -0
- package/dist/PKGJsonManager.d.ts +6 -0
- package/dist/PKGJsonManager.js +116 -0
- package/dist/PKGJsonManager.mjs +48 -0
- package/dist/RemoteManager.d.ts +18 -0
- package/dist/RemoteManager.js +162 -0
- package/dist/RemoteManager.mjs +108 -0
- package/dist/SharedManager.d.mts +18 -0
- package/dist/{src/SharedManager.d.ts → SharedManager.d.ts} +4 -4
- package/dist/SharedManager.js +199 -0
- package/dist/SharedManager.mjs +131 -0
- package/dist/constant.d.ts +2 -0
- package/dist/constant.js +58 -0
- package/dist/constant.mjs +4 -0
- package/dist/findPackageJson.d.mts +1 -0
- package/dist/findPackageJson.d.ts +1 -0
- package/dist/findPackageJson.js +91 -0
- package/dist/findPackageJson.mjs +23 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.js +95 -0
- package/dist/index.mjs +27 -0
- package/dist/types.d.mts +16 -0
- package/dist/{src/types.d.ts → types.d.ts} +2 -2
- package/dist/types.js +29 -0
- package/dist/types.mjs +3 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.js +121 -0
- package/dist/utils.mjs +63 -0
- package/package.json +21 -10
- package/dist/index.cjs.js +0 -495
- package/dist/index.cjs.js.map +0 -1
- package/dist/index.esm.js +0 -486
- package/dist/index.esm.js.map +0 -1
- /package/dist/{src/BasicPluginOptionsManager.d.ts → BasicPluginOptionsManager.d.mts} +0 -0
- /package/dist/{src/ContainerManager.d.ts → ContainerManager.d.mts} +0 -0
- /package/dist/{src/PKGJsonManager.d.ts → PKGJsonManager.d.mts} +0 -0
- /package/dist/{src/RemoteManager.d.ts → RemoteManager.d.mts} +0 -0
- /package/dist/{src/constant.d.ts → constant.d.mts} +0 -0
- /package/dist/{src/index.d.ts → index.d.mts} +0 -0
- /package/dist/{src/utils.d.ts → utils.d.mts} +0 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { RemoteEntryInfo, StatsRemote, containerReferencePlugin, moduleFederationPlugin } from '@module-federation/sdk';
|
|
2
|
+
import { BasicPluginOptionsManager } from './BasicPluginOptionsManager';
|
|
3
|
+
interface NormalizedRemote {
|
|
4
|
+
[remoteName: string]: RemoteEntryInfo & {
|
|
5
|
+
alias: string;
|
|
6
|
+
shareScope: string | string[];
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
declare class RemoteManager extends BasicPluginOptionsManager<moduleFederationPlugin.ModuleFederationPluginOptions> {
|
|
10
|
+
normalizedOptions: NormalizedRemote;
|
|
11
|
+
get enable(): boolean;
|
|
12
|
+
get statsRemoteWithEmptyUsedIn(): StatsRemote[];
|
|
13
|
+
get dtsRemotes(): Record<string, string>;
|
|
14
|
+
get remotes(): moduleFederationPlugin.ModuleFederationPluginOptions['remotes'];
|
|
15
|
+
normalizeOptions(options?: containerReferencePlugin.ContainerReferencePluginOptions['remotes']): void;
|
|
16
|
+
init(options: moduleFederationPlugin.ModuleFederationPluginOptions): void;
|
|
17
|
+
}
|
|
18
|
+
export { RemoteManager };
|
|
@@ -0,0 +1,162 @@
|
|
|
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
|
+
// webpack/runtime/define_property_getters
|
|
13
|
+
(() => {
|
|
14
|
+
__webpack_require__.d = (exports, getters, values) => {
|
|
15
|
+
var define = (defs, kind) => {
|
|
16
|
+
for(var key in defs) {
|
|
17
|
+
if(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {
|
|
18
|
+
Object.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
define(getters, "get");
|
|
23
|
+
define(values, "value");
|
|
24
|
+
};
|
|
25
|
+
})();
|
|
26
|
+
// webpack/runtime/has_own_property
|
|
27
|
+
(() => {
|
|
28
|
+
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
29
|
+
})();
|
|
30
|
+
// webpack/runtime/make_namespace_object
|
|
31
|
+
(() => {
|
|
32
|
+
// define __esModule on exports
|
|
33
|
+
__webpack_require__.r = (exports) => {
|
|
34
|
+
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
35
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
36
|
+
}
|
|
37
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
38
|
+
};
|
|
39
|
+
})();
|
|
40
|
+
var __webpack_exports__ = {};
|
|
41
|
+
// ESM COMPAT FLAG
|
|
42
|
+
__webpack_require__.r(__webpack_exports__);
|
|
43
|
+
|
|
44
|
+
// EXPORTS
|
|
45
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
46
|
+
RemoteManager: () => (/* binding */ RemoteManager)
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
;// CONCATENATED MODULE: external "@module-federation/sdk"
|
|
50
|
+
const sdk_namespaceObject = require("@module-federation/sdk");
|
|
51
|
+
;// CONCATENATED MODULE: external "./BasicPluginOptionsManager.js"
|
|
52
|
+
const external_BasicPluginOptionsManager_js_namespaceObject = require("./BasicPluginOptionsManager.js");
|
|
53
|
+
;// CONCATENATED MODULE: external "./constant.js"
|
|
54
|
+
const external_constant_js_namespaceObject = require("./constant.js");
|
|
55
|
+
;// CONCATENATED MODULE: ./src/RemoteManager.ts
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
function getEntry(remoteObj) {
|
|
60
|
+
if (typeof remoteObj === 'string') {
|
|
61
|
+
return remoteObj;
|
|
62
|
+
}
|
|
63
|
+
if (typeof remoteObj.external === 'string') {
|
|
64
|
+
return remoteObj.external;
|
|
65
|
+
}
|
|
66
|
+
throw new Error('Not support "array" remote value yet!');
|
|
67
|
+
}
|
|
68
|
+
class RemoteManager extends external_BasicPluginOptionsManager_js_namespaceObject.BasicPluginOptionsManager {
|
|
69
|
+
get enable() {
|
|
70
|
+
return Boolean(this.remotes && (Array.isArray(this.remotes) ? this.remotes.length > 0 : Object.keys(this.remotes).length > 0));
|
|
71
|
+
}
|
|
72
|
+
get statsRemoteWithEmptyUsedIn() {
|
|
73
|
+
const { name } = this.options;
|
|
74
|
+
return Object.keys(this.normalizedOptions).reduce((sum, cur)=>{
|
|
75
|
+
const normalizedOption = this.normalizedOptions[cur];
|
|
76
|
+
let curObj;
|
|
77
|
+
if ('entry' in normalizedOption) {
|
|
78
|
+
curObj = {
|
|
79
|
+
entry: normalizedOption.entry,
|
|
80
|
+
alias: normalizedOption.alias,
|
|
81
|
+
moduleName: external_constant_js_namespaceObject.UNKNOWN_MODULE_NAME,
|
|
82
|
+
federationContainerName: normalizedOption.name,
|
|
83
|
+
consumingFederationContainerName: name,
|
|
84
|
+
usedIn: [
|
|
85
|
+
external_constant_js_namespaceObject.UNKNOWN_MODULE_NAME
|
|
86
|
+
]
|
|
87
|
+
};
|
|
88
|
+
} else {
|
|
89
|
+
curObj = {
|
|
90
|
+
alias: normalizedOption.alias,
|
|
91
|
+
moduleName: external_constant_js_namespaceObject.UNKNOWN_MODULE_NAME,
|
|
92
|
+
version: normalizedOption.version,
|
|
93
|
+
federationContainerName: normalizedOption.name,
|
|
94
|
+
consumingFederationContainerName: name,
|
|
95
|
+
usedIn: [
|
|
96
|
+
external_constant_js_namespaceObject.UNKNOWN_MODULE_NAME
|
|
97
|
+
]
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
sum.push(curObj);
|
|
101
|
+
return sum;
|
|
102
|
+
}, []);
|
|
103
|
+
}
|
|
104
|
+
// 'micro-app-sub3': 'app:@garfish/micro-app-sub3:0.0.4',
|
|
105
|
+
// ↓↓↓
|
|
106
|
+
// {
|
|
107
|
+
// 'micro-app-sub3': @garfish/micro-app-sub3:0.0.4
|
|
108
|
+
// }
|
|
109
|
+
get dtsRemotes() {
|
|
110
|
+
return Object.keys(this.normalizedOptions).reduce((sum, remoteAlias)=>{
|
|
111
|
+
const remoteInfo = this.normalizedOptions[remoteAlias];
|
|
112
|
+
sum[remoteAlias] = (0,sdk_namespaceObject.composeKeyWithSeparator)(remoteInfo.name, 'entry' in remoteInfo ? remoteInfo.entry : remoteInfo.version);
|
|
113
|
+
return sum;
|
|
114
|
+
}, {});
|
|
115
|
+
}
|
|
116
|
+
get remotes() {
|
|
117
|
+
return this.options.remotes;
|
|
118
|
+
}
|
|
119
|
+
// INFO: only support remoteType: script now
|
|
120
|
+
normalizeOptions(options = {}) {
|
|
121
|
+
this.normalizedOptions = Object.keys(options).reduce((sum, remoteAlias)=>{
|
|
122
|
+
if (Array.isArray(options)) {
|
|
123
|
+
return sum;
|
|
124
|
+
}
|
|
125
|
+
const remoteInfo = options[remoteAlias];
|
|
126
|
+
if (Array.isArray(remoteInfo)) {
|
|
127
|
+
return sum;
|
|
128
|
+
}
|
|
129
|
+
let parsedOptions;
|
|
130
|
+
try {
|
|
131
|
+
parsedOptions = (0,sdk_namespaceObject.parseEntry)(typeof remoteInfo === 'string' ? remoteInfo : getEntry(remoteInfo), '', '@');
|
|
132
|
+
} catch (e) {
|
|
133
|
+
// noop
|
|
134
|
+
}
|
|
135
|
+
if (!parsedOptions) {
|
|
136
|
+
return sum;
|
|
137
|
+
}
|
|
138
|
+
sum[remoteAlias] = {
|
|
139
|
+
...parsedOptions,
|
|
140
|
+
alias: remoteAlias,
|
|
141
|
+
shareScope: typeof remoteInfo === 'object' ? remoteInfo.shareScope || 'default' : 'default'
|
|
142
|
+
};
|
|
143
|
+
return sum;
|
|
144
|
+
}, {});
|
|
145
|
+
}
|
|
146
|
+
init(options) {
|
|
147
|
+
this.setOptions(options);
|
|
148
|
+
this.normalizeOptions(options.remotes);
|
|
149
|
+
}
|
|
150
|
+
constructor(...args){
|
|
151
|
+
super(...args), this.normalizedOptions = {};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
exports.RemoteManager = __webpack_exports__.RemoteManager;
|
|
157
|
+
for(var __rspack_i in __webpack_exports__) {
|
|
158
|
+
if(["RemoteManager"].indexOf(__rspack_i) === -1) {
|
|
159
|
+
exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { composeKeyWithSeparator, parseEntry } from "@module-federation/sdk";
|
|
2
|
+
import { BasicPluginOptionsManager } from "./BasicPluginOptionsManager.mjs";
|
|
3
|
+
import { UNKNOWN_MODULE_NAME } from "./constant.mjs";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
function getEntry(remoteObj) {
|
|
12
|
+
if (typeof remoteObj === 'string') {
|
|
13
|
+
return remoteObj;
|
|
14
|
+
}
|
|
15
|
+
if (typeof remoteObj.external === 'string') {
|
|
16
|
+
return remoteObj.external;
|
|
17
|
+
}
|
|
18
|
+
throw new Error('Not support "array" remote value yet!');
|
|
19
|
+
}
|
|
20
|
+
class RemoteManager extends BasicPluginOptionsManager {
|
|
21
|
+
get enable() {
|
|
22
|
+
return Boolean(this.remotes && (Array.isArray(this.remotes) ? this.remotes.length > 0 : Object.keys(this.remotes).length > 0));
|
|
23
|
+
}
|
|
24
|
+
get statsRemoteWithEmptyUsedIn() {
|
|
25
|
+
const { name } = this.options;
|
|
26
|
+
return Object.keys(this.normalizedOptions).reduce((sum, cur)=>{
|
|
27
|
+
const normalizedOption = this.normalizedOptions[cur];
|
|
28
|
+
let curObj;
|
|
29
|
+
if ('entry' in normalizedOption) {
|
|
30
|
+
curObj = {
|
|
31
|
+
entry: normalizedOption.entry,
|
|
32
|
+
alias: normalizedOption.alias,
|
|
33
|
+
moduleName: UNKNOWN_MODULE_NAME,
|
|
34
|
+
federationContainerName: normalizedOption.name,
|
|
35
|
+
consumingFederationContainerName: name,
|
|
36
|
+
usedIn: [
|
|
37
|
+
UNKNOWN_MODULE_NAME
|
|
38
|
+
]
|
|
39
|
+
};
|
|
40
|
+
} else {
|
|
41
|
+
curObj = {
|
|
42
|
+
alias: normalizedOption.alias,
|
|
43
|
+
moduleName: UNKNOWN_MODULE_NAME,
|
|
44
|
+
version: normalizedOption.version,
|
|
45
|
+
federationContainerName: normalizedOption.name,
|
|
46
|
+
consumingFederationContainerName: name,
|
|
47
|
+
usedIn: [
|
|
48
|
+
UNKNOWN_MODULE_NAME
|
|
49
|
+
]
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
sum.push(curObj);
|
|
53
|
+
return sum;
|
|
54
|
+
}, []);
|
|
55
|
+
}
|
|
56
|
+
// 'micro-app-sub3': 'app:@garfish/micro-app-sub3:0.0.4',
|
|
57
|
+
// ↓↓↓
|
|
58
|
+
// {
|
|
59
|
+
// 'micro-app-sub3': @garfish/micro-app-sub3:0.0.4
|
|
60
|
+
// }
|
|
61
|
+
get dtsRemotes() {
|
|
62
|
+
return Object.keys(this.normalizedOptions).reduce((sum, remoteAlias)=>{
|
|
63
|
+
const remoteInfo = this.normalizedOptions[remoteAlias];
|
|
64
|
+
sum[remoteAlias] = composeKeyWithSeparator(remoteInfo.name, 'entry' in remoteInfo ? remoteInfo.entry : remoteInfo.version);
|
|
65
|
+
return sum;
|
|
66
|
+
}, {});
|
|
67
|
+
}
|
|
68
|
+
get remotes() {
|
|
69
|
+
return this.options.remotes;
|
|
70
|
+
}
|
|
71
|
+
// INFO: only support remoteType: script now
|
|
72
|
+
normalizeOptions(options = {}) {
|
|
73
|
+
this.normalizedOptions = Object.keys(options).reduce((sum, remoteAlias)=>{
|
|
74
|
+
if (Array.isArray(options)) {
|
|
75
|
+
return sum;
|
|
76
|
+
}
|
|
77
|
+
const remoteInfo = options[remoteAlias];
|
|
78
|
+
if (Array.isArray(remoteInfo)) {
|
|
79
|
+
return sum;
|
|
80
|
+
}
|
|
81
|
+
let parsedOptions;
|
|
82
|
+
try {
|
|
83
|
+
parsedOptions = parseEntry(typeof remoteInfo === 'string' ? remoteInfo : getEntry(remoteInfo), '', '@');
|
|
84
|
+
} catch (e) {
|
|
85
|
+
// noop
|
|
86
|
+
}
|
|
87
|
+
if (!parsedOptions) {
|
|
88
|
+
return sum;
|
|
89
|
+
}
|
|
90
|
+
sum[remoteAlias] = {
|
|
91
|
+
...parsedOptions,
|
|
92
|
+
alias: remoteAlias,
|
|
93
|
+
shareScope: typeof remoteInfo === 'object' ? remoteInfo.shareScope || 'default' : 'default'
|
|
94
|
+
};
|
|
95
|
+
return sum;
|
|
96
|
+
}, {});
|
|
97
|
+
}
|
|
98
|
+
init(options) {
|
|
99
|
+
this.setOptions(options);
|
|
100
|
+
this.normalizeOptions(options.remotes);
|
|
101
|
+
}
|
|
102
|
+
constructor(...args){
|
|
103
|
+
super(...args), this.normalizedOptions = {};
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
export { RemoteManager };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { moduleFederationPlugin, sharePlugin } from '@module-federation/sdk';
|
|
2
|
+
import { NormalizedSharedOptions } from './types';
|
|
3
|
+
import { BasicPluginOptionsManager } from './BasicPluginOptionsManager';
|
|
4
|
+
declare class SharedManager extends BasicPluginOptionsManager<moduleFederationPlugin.ModuleFederationPluginOptions> {
|
|
5
|
+
normalizedOptions: NormalizedSharedOptions;
|
|
6
|
+
get enable(): boolean;
|
|
7
|
+
get sharedPluginOptions(): sharePlugin.SharePluginOptions;
|
|
8
|
+
findPkg(name: string, shareConfig: moduleFederationPlugin.SharedConfig): {
|
|
9
|
+
pkg: Record<string, any>;
|
|
10
|
+
path: string;
|
|
11
|
+
pkgPath: string;
|
|
12
|
+
};
|
|
13
|
+
get enableTreeShaking(): boolean;
|
|
14
|
+
transformSharedConfig(sharedConfig: moduleFederationPlugin.SharedConfig): moduleFederationPlugin.SharedConfig;
|
|
15
|
+
normalizeOptions(options: moduleFederationPlugin.ModuleFederationPluginOptions['shared']): void;
|
|
16
|
+
init(options: moduleFederationPlugin.ModuleFederationPluginOptions): void;
|
|
17
|
+
}
|
|
18
|
+
export { SharedManager };
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { moduleFederationPlugin, sharePlugin } from '@module-federation/sdk';
|
|
2
2
|
import { NormalizedSharedOptions } from './types';
|
|
3
3
|
import { BasicPluginOptionsManager } from './BasicPluginOptionsManager';
|
|
4
|
-
type SharePluginOptions = ConstructorParameters<typeof sharePlugin.SharePlugin>[0];
|
|
5
4
|
declare class SharedManager extends BasicPluginOptionsManager<moduleFederationPlugin.ModuleFederationPluginOptions> {
|
|
6
5
|
normalizedOptions: NormalizedSharedOptions;
|
|
7
6
|
get enable(): boolean;
|
|
8
|
-
get sharedPluginOptions(): SharePluginOptions;
|
|
9
|
-
findPkg(name: string, shareConfig:
|
|
7
|
+
get sharedPluginOptions(): sharePlugin.SharePluginOptions;
|
|
8
|
+
findPkg(name: string, shareConfig: moduleFederationPlugin.SharedConfig): {
|
|
10
9
|
pkg: Record<string, any>;
|
|
11
10
|
path: string;
|
|
12
11
|
pkgPath: string;
|
|
13
12
|
};
|
|
14
|
-
|
|
13
|
+
get enableTreeShaking(): boolean;
|
|
14
|
+
transformSharedConfig(sharedConfig: moduleFederationPlugin.SharedConfig): moduleFederationPlugin.SharedConfig;
|
|
15
15
|
normalizeOptions(options: moduleFederationPlugin.ModuleFederationPluginOptions['shared']): void;
|
|
16
16
|
init(options: moduleFederationPlugin.ModuleFederationPluginOptions): void;
|
|
17
17
|
}
|
|
@@ -0,0 +1,199 @@
|
|
|
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
|
+
// webpack/runtime/compat_get_default_export
|
|
13
|
+
(() => {
|
|
14
|
+
// getDefaultExport function for compatibility with non-ESM modules
|
|
15
|
+
__webpack_require__.n = (module) => {
|
|
16
|
+
var getter = module && module.__esModule ?
|
|
17
|
+
() => (module['default']) :
|
|
18
|
+
() => (module);
|
|
19
|
+
__webpack_require__.d(getter, { a: getter });
|
|
20
|
+
return getter;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
})();
|
|
24
|
+
// webpack/runtime/define_property_getters
|
|
25
|
+
(() => {
|
|
26
|
+
__webpack_require__.d = (exports, getters, values) => {
|
|
27
|
+
var define = (defs, kind) => {
|
|
28
|
+
for(var key in defs) {
|
|
29
|
+
if(__webpack_require__.o(defs, key) && !__webpack_require__.o(exports, key)) {
|
|
30
|
+
Object.defineProperty(exports, key, { enumerable: true, [kind]: defs[key] });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
define(getters, "get");
|
|
35
|
+
define(values, "value");
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
38
|
+
// webpack/runtime/has_own_property
|
|
39
|
+
(() => {
|
|
40
|
+
__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
41
|
+
})();
|
|
42
|
+
// webpack/runtime/make_namespace_object
|
|
43
|
+
(() => {
|
|
44
|
+
// define __esModule on exports
|
|
45
|
+
__webpack_require__.r = (exports) => {
|
|
46
|
+
if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
47
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
48
|
+
}
|
|
49
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
50
|
+
};
|
|
51
|
+
})();
|
|
52
|
+
var __webpack_exports__ = {};
|
|
53
|
+
// ESM COMPAT FLAG
|
|
54
|
+
__webpack_require__.r(__webpack_exports__);
|
|
55
|
+
|
|
56
|
+
// EXPORTS
|
|
57
|
+
__webpack_require__.d(__webpack_exports__, {
|
|
58
|
+
SharedManager: () => (/* binding */ SharedManager)
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
;// CONCATENATED MODULE: external "path"
|
|
62
|
+
const external_path_namespaceObject = require("path");
|
|
63
|
+
var external_path_default = /*#__PURE__*/__webpack_require__.n(external_path_namespaceObject);
|
|
64
|
+
;// CONCATENATED MODULE: external "fs"
|
|
65
|
+
const external_fs_namespaceObject = require("fs");
|
|
66
|
+
var external_fs_default = /*#__PURE__*/__webpack_require__.n(external_fs_namespaceObject);
|
|
67
|
+
;// CONCATENATED MODULE: external "@module-federation/sdk"
|
|
68
|
+
const sdk_namespaceObject = require("@module-federation/sdk");
|
|
69
|
+
;// CONCATENATED MODULE: external "./BasicPluginOptionsManager.js"
|
|
70
|
+
const external_BasicPluginOptionsManager_js_namespaceObject = require("./BasicPluginOptionsManager.js");
|
|
71
|
+
;// CONCATENATED MODULE: external "./utils.js"
|
|
72
|
+
const external_utils_js_namespaceObject = require("./utils.js");
|
|
73
|
+
;// CONCATENATED MODULE: external "./findPackageJson.js"
|
|
74
|
+
const external_findPackageJson_js_namespaceObject = require("./findPackageJson.js");
|
|
75
|
+
;// CONCATENATED MODULE: ./src/SharedManager.ts
|
|
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 = (0,external_findPackageJson_js_namespaceObject.findPackageJson)(external_path_default().dirname(pkgPath));
|
|
127
|
+
if (!pkgJsonPath) {
|
|
128
|
+
throw new Error(`Unable to find package.json for ${depName}`);
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
pkg: JSON.parse(external_fs_default().readFileSync(pkgJsonPath, 'utf-8')),
|
|
132
|
+
path: '',
|
|
133
|
+
pkgPath: ''
|
|
134
|
+
};
|
|
135
|
+
} catch (err) {
|
|
136
|
+
return {
|
|
137
|
+
pkg: {},
|
|
138
|
+
path: '',
|
|
139
|
+
pkgPath: ''
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
get enableTreeShaking() {
|
|
144
|
+
return Object.values(this.normalizedOptions).some((item)=>item.treeShaking);
|
|
145
|
+
}
|
|
146
|
+
transformSharedConfig(sharedConfig) {
|
|
147
|
+
const defaultSharedConfig = {
|
|
148
|
+
singleton: true,
|
|
149
|
+
requiredVersion: undefined,
|
|
150
|
+
shareScope: 'default'
|
|
151
|
+
};
|
|
152
|
+
return {
|
|
153
|
+
...defaultSharedConfig,
|
|
154
|
+
...sharedConfig
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
normalizeOptions(options) {
|
|
158
|
+
const normalizedShared = {};
|
|
159
|
+
const sharedOptions = (0,external_utils_js_namespaceObject.parseOptions)(options, (item, key)=>{
|
|
160
|
+
if (typeof item !== 'string') throw new Error('Unexpected array in shared');
|
|
161
|
+
const config = item === key || !(0,sdk_namespaceObject.isRequiredVersion)(item) ? {
|
|
162
|
+
import: item
|
|
163
|
+
} : {
|
|
164
|
+
import: key,
|
|
165
|
+
requiredVersion: item
|
|
166
|
+
};
|
|
167
|
+
return config;
|
|
168
|
+
}, (item)=>item);
|
|
169
|
+
sharedOptions.forEach((item)=>{
|
|
170
|
+
const [sharedName, sharedOptions] = item;
|
|
171
|
+
const pkgInfo = this.findPkg(sharedName, sharedOptions);
|
|
172
|
+
const sharedConfig = this.transformSharedConfig(sharedOptions);
|
|
173
|
+
normalizedShared[sharedName] = {
|
|
174
|
+
...sharedConfig,
|
|
175
|
+
requiredVersion: typeof sharedConfig.requiredVersion !== 'undefined' ? sharedConfig.requiredVersion : `^${pkgInfo.pkg['version']}`,
|
|
176
|
+
name: sharedName,
|
|
177
|
+
version: pkgInfo.pkg['version'],
|
|
178
|
+
eager: Boolean(sharedConfig.eager)
|
|
179
|
+
};
|
|
180
|
+
});
|
|
181
|
+
this.normalizedOptions = normalizedShared;
|
|
182
|
+
}
|
|
183
|
+
init(options) {
|
|
184
|
+
this.setOptions(options);
|
|
185
|
+
this.normalizeOptions(options.shared);
|
|
186
|
+
}
|
|
187
|
+
constructor(...args){
|
|
188
|
+
super(...args), this.normalizedOptions = {};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
exports.SharedManager = __webpack_exports__.SharedManager;
|
|
194
|
+
for(var __rspack_i in __webpack_exports__) {
|
|
195
|
+
if(["SharedManager"].indexOf(__rspack_i) === -1) {
|
|
196
|
+
exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import fs from "fs";
|
|
3
|
+
import { isRequiredVersion } from "@module-federation/sdk";
|
|
4
|
+
import { BasicPluginOptionsManager } from "./BasicPluginOptionsManager.mjs";
|
|
5
|
+
import { parseOptions } from "./utils.mjs";
|
|
6
|
+
import { findPackageJson } from "./findPackageJson.mjs";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class SharedManager extends BasicPluginOptionsManager {
|
|
21
|
+
get enable() {
|
|
22
|
+
return Boolean(Object.keys(this.sharedPluginOptions.shared).length);
|
|
23
|
+
}
|
|
24
|
+
get sharedPluginOptions() {
|
|
25
|
+
const normalizedShared = this.normalizedOptions;
|
|
26
|
+
const shared = Object.keys(normalizedShared).reduce((sum, cur)=>{
|
|
27
|
+
const { singleton, requiredVersion, version, eager, shareScope, import: sharedImport, treeShaking } = normalizedShared[cur];
|
|
28
|
+
sum[cur] = {
|
|
29
|
+
singleton,
|
|
30
|
+
requiredVersion,
|
|
31
|
+
version,
|
|
32
|
+
eager,
|
|
33
|
+
shareScope,
|
|
34
|
+
import: sharedImport,
|
|
35
|
+
treeShaking
|
|
36
|
+
};
|
|
37
|
+
return sum;
|
|
38
|
+
}, {});
|
|
39
|
+
return {
|
|
40
|
+
shared,
|
|
41
|
+
shareScope: this.options.shareScope || 'default'
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
findPkg(name, shareConfig) {
|
|
45
|
+
try {
|
|
46
|
+
let pkgPath = '';
|
|
47
|
+
let depName = name;
|
|
48
|
+
if (shareConfig.import) {
|
|
49
|
+
if (path.isAbsolute(shareConfig.import)) {
|
|
50
|
+
pkgPath = shareConfig.import;
|
|
51
|
+
} else if (shareConfig.import.startsWith('.')) {
|
|
52
|
+
pkgPath = path.resolve(this.root, shareConfig.import);
|
|
53
|
+
}
|
|
54
|
+
} else {
|
|
55
|
+
if (shareConfig.packageName) {
|
|
56
|
+
depName = shareConfig.packageName;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
pkgPath = pkgPath || require.resolve(depName, {
|
|
60
|
+
paths: [
|
|
61
|
+
this.root
|
|
62
|
+
]
|
|
63
|
+
});
|
|
64
|
+
const pkgJsonPath = findPackageJson(path.dirname(pkgPath));
|
|
65
|
+
if (!pkgJsonPath) {
|
|
66
|
+
throw new Error(`Unable to find package.json for ${depName}`);
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
pkg: JSON.parse(fs.readFileSync(pkgJsonPath, 'utf-8')),
|
|
70
|
+
path: '',
|
|
71
|
+
pkgPath: ''
|
|
72
|
+
};
|
|
73
|
+
} catch (err) {
|
|
74
|
+
return {
|
|
75
|
+
pkg: {},
|
|
76
|
+
path: '',
|
|
77
|
+
pkgPath: ''
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
get enableTreeShaking() {
|
|
82
|
+
return Object.values(this.normalizedOptions).some((item)=>item.treeShaking);
|
|
83
|
+
}
|
|
84
|
+
transformSharedConfig(sharedConfig) {
|
|
85
|
+
const defaultSharedConfig = {
|
|
86
|
+
singleton: true,
|
|
87
|
+
requiredVersion: undefined,
|
|
88
|
+
shareScope: 'default'
|
|
89
|
+
};
|
|
90
|
+
return {
|
|
91
|
+
...defaultSharedConfig,
|
|
92
|
+
...sharedConfig
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
normalizeOptions(options) {
|
|
96
|
+
const normalizedShared = {};
|
|
97
|
+
const sharedOptions = parseOptions(options, (item, key)=>{
|
|
98
|
+
if (typeof item !== 'string') throw new Error('Unexpected array in shared');
|
|
99
|
+
const config = item === key || !isRequiredVersion(item) ? {
|
|
100
|
+
import: item
|
|
101
|
+
} : {
|
|
102
|
+
import: key,
|
|
103
|
+
requiredVersion: item
|
|
104
|
+
};
|
|
105
|
+
return config;
|
|
106
|
+
}, (item)=>item);
|
|
107
|
+
sharedOptions.forEach((item)=>{
|
|
108
|
+
const [sharedName, sharedOptions] = item;
|
|
109
|
+
const pkgInfo = this.findPkg(sharedName, sharedOptions);
|
|
110
|
+
const sharedConfig = this.transformSharedConfig(sharedOptions);
|
|
111
|
+
normalizedShared[sharedName] = {
|
|
112
|
+
...sharedConfig,
|
|
113
|
+
requiredVersion: typeof sharedConfig.requiredVersion !== 'undefined' ? sharedConfig.requiredVersion : `^${pkgInfo.pkg['version']}`,
|
|
114
|
+
name: sharedName,
|
|
115
|
+
version: pkgInfo.pkg['version'],
|
|
116
|
+
eager: Boolean(sharedConfig.eager)
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
this.normalizedOptions = normalizedShared;
|
|
120
|
+
}
|
|
121
|
+
init(options) {
|
|
122
|
+
this.setOptions(options);
|
|
123
|
+
this.normalizeOptions(options.shared);
|
|
124
|
+
}
|
|
125
|
+
constructor(...args){
|
|
126
|
+
super(...args), this.normalizedOptions = {};
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
export { SharedManager };
|