@empjs/share 0.0.1 → 0.0.2

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/rspack.js CHANGED
@@ -1,82 +1,3 @@
1
- // src/plugin/rspack/index.ts
2
- import { ModuleFederationPlugin } from "@module-federation/enhanced/rspack";
3
-
4
- // src/helper/config.ts
5
- var shareGlobalName = "EMP_SHARE_RUNTIME";
6
-
7
- // src/helper/index.ts
8
- var importJsVm = (content) => `data:text/javascript,${content}`;
9
-
10
- // src/plugin/rspack/plugin.ts
11
- var getShareRuntimeEntry = () => {
12
- const content = [`import '@empjs/share/library'`].join("\n");
13
- return importJsVm(content);
14
- };
15
- var EmpShareRuntimePlugin = class {
16
- constructor() {
17
- }
18
- apply(compiler) {
19
- const { webpack } = compiler;
20
- const entry = getShareRuntimeEntry();
21
- new webpack.EntryPlugin(compiler.context, entry, {
22
- name: void 0
23
- }).apply(compiler);
24
- }
25
- };
26
-
27
- // src/plugin/rspack/index.ts
28
- var rspack_default = (o = {}) => {
29
- return {
30
- name: "@empjs/share",
31
- async rsConfig(store) {
32
- console.log(o);
33
- if (o.name) {
34
- const op = store.deepAssign(
35
- {
36
- filename: "emp.js",
37
- manifest: false,
38
- dts: false,
39
- dev: {
40
- disableDynamicRemoteTypeHints: true
41
- }
42
- },
43
- o
44
- );
45
- delete op.empRuntime;
46
- store.chain.plugin("plugin-emp-share").use(ModuleFederationPlugin, [op]);
47
- }
48
- const { empRuntime } = o;
49
- if (empRuntime) {
50
- if (!empRuntime.runtimeLib) {
51
- store.chain.plugin("plugin-emp-runtime").use(EmpShareRuntimePlugin);
52
- }
53
- empRuntime.runtimeGlobal = empRuntime.frameworkGlobal || shareGlobalName;
54
- const externalRuntime = {
55
- "@module-federation/runtime": `MFRuntime`,
56
- "@module-federation/sdk": `MFSDK`
57
- };
58
- const externals = [];
59
- for (const [key, value] of Object.entries(externalRuntime)) {
60
- externals[key] = `${empRuntime.runtimeGlobal}.${value}`;
61
- }
62
- empRuntime.framework = empRuntime.framework || "react";
63
- empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || empRuntime.runtimeGlobal;
64
- if (empRuntime.framework === "react") {
65
- const externalReact = {
66
- react: `React`,
67
- "react-dom": `ReactDOM`
68
- };
69
- for (const [key, value] of Object.entries(externalReact)) {
70
- externals[key] = `${empRuntime.frameworkGlobal}.${value}`;
71
- }
72
- }
73
- if (empRuntime.setExternals) empRuntime.setExternals(externals);
74
- store.merge({ externals });
75
- }
76
- }
77
- };
78
- };
79
- export {
80
- rspack_default as default
81
- };
1
+ import{ModuleFederationPlugin as b}from"@module-federation/enhanced/rspack";var p="EMP_SHARE_RUNTIME";var l=n=>`data:text/javascript,${n}`;var f=n=>{let t=[`import '${n}'`].join(`
2
+ `);return l(t)},s=class{options;constructor(t){this.options=t}apply(t){let{webpack:e}=t,{runtimeLib:r}=this.options;if(!r){let o=f("@empjs/share/library");new e.EntryPlugin(t.context,o,{name:void 0}).apply(t)}}};function u(n,t){return typeof n=="string"?`${n}/runtime${t==="development"?".development":""}.umd.js`:typeof n=="object"?t==="development"?n.dev:n.prod:""}var y=(n={})=>({name:"@empjs/share",async rsConfig(t){if(n.name){let r=t.deepAssign({filename:"emp.js",manifest:!1,dts:!1,dev:{disableDynamicRemoteTypeHints:!0}},n);delete r.empRuntime,t.chain.plugin("plugin-emp-share").use(b,[r])}let{empRuntime:e}=n;if(e){e.runtimeLib||t.chain.plugin("plugin-emp-share-framework").use(s,[e]),e.runtimeGlobal=e.runtimeGlobal||p;let r={"@module-federation/runtime":"MFRuntime","@module-federation/sdk":"MFSDK"},o=[];for(let[i,a]of Object.entries(r))o[i]=`${e.runtimeGlobal}.${a}`;let m=[];if(e.frameworkLib){let i=u(e.frameworkLib,t.mode);m.push(i)}if(e.runtimeLib&&m.push(e.runtimeLib),m.length>0&&t.injectHeadTags({js:m},"EMPShare"),e.framework=e.framework||"react",e.frameworkGlobal=e.frameworkGlobal||e.runtimeGlobal,e.framework==="react"){let i={react:"React","react-dom":"ReactDOM"};for(let[a,c]of Object.entries(i))o[a]=`${e.frameworkGlobal}.${c}`}e.setExternals&&e.setExternals(o),t.chain.externals(o)}}});export{y as default};
82
3
  //# sourceMappingURL=rspack.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugin/rspack/plugin.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRuntimePlugin} from './plugin'\nimport type {EMPPluginShareType} from './types'\n//\nexport default (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n console.log(o)\n if (o.name) {\n const op: any = store.deepAssign(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n delete op.empRuntime\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n const {empRuntime} = o\n if (empRuntime) {\n if (!empRuntime.runtimeLib) {\n store.chain.plugin('plugin-emp-runtime').use(EmpShareRuntimePlugin)\n }\n empRuntime.runtimeGlobal = empRuntime.frameworkGlobal || shareGlobalName\n const externalRuntime = {\n '@module-federation/runtime': `MFRuntime`,\n '@module-federation/sdk': `MFSDK`,\n }\n const externals = []\n for (const [key, value] of Object.entries(externalRuntime)) {\n externals[key] = `${empRuntime.runtimeGlobal}.${value}`\n }\n //\n empRuntime.framework = empRuntime.framework || 'react'\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || empRuntime.runtimeGlobal\n if (empRuntime.framework === 'react') {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${empRuntime.frameworkGlobal}.${value}`\n }\n }\n //\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n store.merge({externals})\n }\n },\n }\n}\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nconst getShareRuntimeEntry = () => {\n const content = [`import '@empjs/share/library'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRuntimePlugin {\n constructor() {}\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const entry = getShareRuntimeEntry()\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n}\n"],"mappings":";AACA,SAAQ,8BAA6B;;;ACD9B,IAAM,kBAAkB;;;ACAxB,IAAM,aAAa,CAAC,YAAoB,wBAAwB,OAAO;;;ACE9E,IAAM,uBAAuB,MAAM;AACjC,QAAM,UAAU,CAAC,+BAA+B,EAAE,KAAK,IAAI;AAC3D,SAAO,WAAW,OAAO;AAC3B;AACO,IAAM,wBAAN,MAA4B;AAAA,EACjC,cAAc;AAAA,EAAC;AAAA,EACf,MAAM,UAAoB;AACxB,UAAM,EAAC,QAAO,IAAI;AAClB,UAAM,QAAQ,qBAAqB;AACnC,QAAI,QAAQ,YAAY,SAAS,SAAS,OAAO;AAAA,MAC/C,MAAM;AAAA,IACR,CAAC,EAAE,MAAM,QAAQ;AAAA,EACnB;AACF;;;AHTA,IAAO,iBAAQ,CAAC,IAAwB,CAAC,MAAM;AAC7C,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAM,SAAS,OAAoB;AACjC,cAAQ,IAAI,CAAC;AACb,UAAI,EAAE,MAAM;AACV,cAAM,KAAU,MAAM;AAAA,UACpB;AAAA,YACE,UAAU;AAAA,YACV,UAAU;AAAA,YACV,KAAK;AAAA,YACL,KAAK;AAAA,cACH,+BAA+B;AAAA,YACjC;AAAA,UACF;AAAA,UACA;AAAA,QACF;AACA,eAAO,GAAG;AACV,cAAM,MAAM,OAAO,kBAAkB,EAAE,IAAI,wBAAwB,CAAC,EAAE,CAAC;AAAA,MACzE;AACA,YAAM,EAAC,WAAU,IAAI;AACrB,UAAI,YAAY;AACd,YAAI,CAAC,WAAW,YAAY;AAC1B,gBAAM,MAAM,OAAO,oBAAoB,EAAE,IAAI,qBAAqB;AAAA,QACpE;AACA,mBAAW,gBAAgB,WAAW,mBAAmB;AACzD,cAAM,kBAAkB;AAAA,UACtB,8BAA8B;AAAA,UAC9B,0BAA0B;AAAA,QAC5B;AACA,cAAM,YAAY,CAAC;AACnB,mBAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,eAAe,GAAG;AAC1D,oBAAU,GAAG,IAAI,GAAG,WAAW,aAAa,IAAI,KAAK;AAAA,QACvD;AAEA,mBAAW,YAAY,WAAW,aAAa;AAC/C,mBAAW,kBAAkB,WAAW,mBAAmB,WAAW;AACtE,YAAI,WAAW,cAAc,SAAS;AACpC,gBAAM,gBAAgB;AAAA,YACpB,OAAO;AAAA,YACP,aAAa;AAAA,UACf;AACA,qBAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,aAAa,GAAG;AACxD,sBAAU,GAAG,IAAI,GAAG,WAAW,eAAe,IAAI,KAAK;AAAA,UACzD;AAAA,QACF;AAEA,YAAI,WAAW,aAAc,YAAW,aAAa,SAAS;AAC9D,cAAM,MAAM,EAAC,UAAS,CAAC;AAAA,MACzB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/plugins/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugins/rspack/plugin.ts","../src/plugins/rspack/utils.ts"],"sourcesContent":["import type {GlobalStore} from '@empjs/cli'\nimport {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\nimport {shareGlobalName} from 'src/helper/config'\nimport {EmpShareRemoteLibPlugin} from './plugin'\nimport type {EMPPluginShareType} from './types'\nimport {getRuntimeLib} from './utils'\n//\nexport default (o: EMPPluginShareType = {}) => {\n return {\n name: '@empjs/share',\n async rsConfig(store: GlobalStore) {\n // console.log(o)\n if (o.name) {\n const op: any = store.deepAssign(\n {\n filename: 'emp.js',\n manifest: false,\n dts: false,\n dev: {\n disableDynamicRemoteTypeHints: true,\n },\n },\n o,\n )\n delete op.empRuntime\n store.chain.plugin('plugin-emp-share').use(ModuleFederationPlugin, [op])\n }\n const {empRuntime} = o\n if (empRuntime) {\n if (!empRuntime.runtimeLib) {\n store.chain.plugin('plugin-emp-share-framework').use(EmpShareRemoteLibPlugin, [empRuntime])\n }\n //\n empRuntime.runtimeGlobal = empRuntime.runtimeGlobal || shareGlobalName\n const externalRuntime = {\n '@module-federation/runtime': `MFRuntime`,\n '@module-federation/sdk': `MFSDK`,\n }\n const externals = []\n for (const [key, value] of Object.entries(externalRuntime)) {\n externals[key] = `${empRuntime.runtimeGlobal}.${value}`\n }\n // injectHeadTags\n const injectUrl: string[] = []\n if (empRuntime.frameworkLib) {\n const url = getRuntimeLib(empRuntime.frameworkLib, store.mode)\n injectUrl.push(url)\n }\n if (empRuntime.runtimeLib) {\n injectUrl.push(empRuntime.runtimeLib)\n }\n if (injectUrl.length > 0) {\n store.injectHeadTags({js: injectUrl}, 'EMPShare')\n }\n //\n empRuntime.framework = empRuntime.framework || 'react'\n empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || empRuntime.runtimeGlobal\n if (empRuntime.framework === 'react') {\n const externalReact = {\n react: `React`,\n 'react-dom': `ReactDOM`,\n }\n for (const [key, value] of Object.entries(externalReact)) {\n externals[key] = `${empRuntime.frameworkGlobal}.${value}`\n }\n }\n //\n if (empRuntime.setExternals) empRuntime.setExternals(externals)\n\n store.chain.externals(externals)\n }\n },\n }\n}\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n","import type {Compiler} from '@rspack/core'\nimport {importJsVm} from 'src/helper'\nimport type {EMPSHARERuntimeOptions} from './types'\nconst getShareRuntimeEntry = url => {\n const content = [`import '${url}'`].join('\\n')\n return importJsVm(content)\n}\nexport class EmpShareRemoteLibPlugin {\n options: EMPSHARERuntimeOptions\n constructor(op: EMPSHARERuntimeOptions) {\n this.options = op\n }\n apply(compiler: Compiler) {\n const {webpack} = compiler\n const {runtimeLib} = this.options\n if (!runtimeLib) {\n const entry = getShareRuntimeEntry('@empjs/share/library')\n new webpack.EntryPlugin(compiler.context, entry, {\n name: undefined,\n }).apply(compiler)\n }\n }\n}\n","import type {EMPSHARERuntimeOptions} from './types'\nexport function getRuntimeLib(host: EMPSHARERuntimeOptions['frameworkLib'], mode: string) {\n if (typeof host === 'string') return `${host}/runtime${mode === 'development' ? '.development' : ''}.umd.js`\n else if (typeof host === 'object') {\n if (mode === 'development') return host.dev\n else return host.prod\n }\n return ''\n}\n"],"mappings":"AACA,OAAQ,0BAAAA,MAA6B,qCCD9B,IAAMC,EAAkB,oBCAxB,IAAMC,EAAcC,GAAoB,wBAAwBA,CAAO,GCG9E,IAAMC,EAAuBC,GAAO,CAClC,IAAMC,EAAU,CAAC,WAAWD,CAAG,GAAG,EAAE,KAAK;AAAA,CAAI,EAC7C,OAAOE,EAAWD,CAAO,CAC3B,EACaE,EAAN,KAA8B,CACnC,QACA,YAAYC,EAA4B,CACtC,KAAK,QAAUA,CACjB,CACA,MAAMC,EAAoB,CACxB,GAAM,CAAC,QAAAC,CAAO,EAAID,EACZ,CAAC,WAAAE,CAAU,EAAI,KAAK,QAC1B,GAAI,CAACA,EAAY,CACf,IAAMC,EAAQT,EAAqB,sBAAsB,EACzD,IAAIO,EAAQ,YAAYD,EAAS,QAASG,EAAO,CAC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gBAAkBA,EAAW,iBAAmBA,EAAW,cAClEA,EAAW,YAAc,QAAS,CACpC,IAAMU,EAAgB,CACpB,MAAO,QACP,YAAa,UACf,EACA,OAAW,CAACL,EAAKC,CAAK,IAAK,OAAO,QAAQI,CAAa,EACrDN,EAAUC,CAAG,EAAI,GAAGL,EAAW,eAAe,IAAIM,CAAK,EAE3D,CAEIN,EAAW,cAAcA,EAAW,aAAaI,CAAS,EAE9DP,EAAM,MAAM,UAAUO,CAAS,CACjC,CACF,CACF","names":["ModuleFederationPlugin","shareGlobalName","importJsVm","content","getShareRuntimeEntry","url","content","importJsVm","EmpShareRemoteLibPlugin","op","compiler","webpack","runtimeLib","entry","getRuntimeLib","host","mode","rspack_default","o","store","op","ModuleFederationPlugin","empRuntime","EmpShareRemoteLibPlugin","shareGlobalName","externalRuntime","externals","key","value","injectUrl","url","getRuntimeLib","externalReact"]}
package/dist/runtime.cjs CHANGED
@@ -1,211 +1,2 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/runtime.ts
21
- var runtime_exports = {};
22
- __export(runtime_exports, {
23
- default: () => mfRuntime_default
24
- });
25
- module.exports = __toCommonJS(runtime_exports);
26
-
27
- // src/helper/config.ts
28
- var shareGlobalName = "EMP_SHARE_RUNTIME";
29
-
30
- // src/mfRuntime/helper.ts
31
- function deepAssign(target, ...sources) {
32
- for (const source of sources) {
33
- for (const k in source) {
34
- const vs = source[k], vt = target[k];
35
- if (Object(vs) == vs && Object(vt) === vt) {
36
- target[k] = deepAssign(vt, vs);
37
- continue;
38
- }
39
- target[k] = source[k];
40
- }
41
- }
42
- return target;
43
- }
44
- var checkVersion = (version) => version ? Number(version.split(".")[0]) : 0;
45
- var isPromise = (p) => p && Object.prototype.toString.call(p) === "[object Promise]";
46
-
47
- // src/mfRuntime/framework/base.ts
48
- var BaseAdapter = class {
49
- libs;
50
- constructor(libs) {
51
- this.libs = libs;
52
- }
53
- get shared() {
54
- const { React, ReactDOM, scope } = this.libs;
55
- return {
56
- react: {
57
- lib: () => React,
58
- version: React.version,
59
- scope,
60
- shareConfig: {
61
- singleton: true,
62
- requiredVersion: `^${React.version}`
63
- }
64
- },
65
- "react-dom": {
66
- lib: () => ReactDOM,
67
- version: ReactDOM.version,
68
- scope,
69
- shareConfig: {
70
- singleton: true,
71
- requiredVersion: `^${React.version}`
72
- }
73
- }
74
- };
75
- }
76
- };
77
-
78
- // src/mfRuntime/framework/react.tsx
79
- var ReactAdapter = class extends BaseAdapter {
80
- constructor(libs) {
81
- super(libs);
82
- }
83
- adapter(component, scope = this.libs.scope, React = this.libs.React, ReactDOM = this.libs.ReactDOM) {
84
- const reactVersion = checkVersion(React.version);
85
- const self = this;
86
- class WrappedComponent extends React.Component {
87
- containerRef;
88
- root;
89
- constructor(props) {
90
- super(props);
91
- this.containerRef = React.createRef();
92
- }
93
- componentDidMount() {
94
- this.mountOriginalComponent(true);
95
- }
96
- componentDidUpdate() {
97
- this.mountOriginalComponent();
98
- }
99
- componentWillUnmount() {
100
- this.unMountOriginalComponent();
101
- }
102
- unMountOriginalComponent() {
103
- if (!this.containerRef.current) return;
104
- if (reactVersion < 18) {
105
- ReactDOM.unmountComponentAtNode(this.containerRef.current);
106
- } else {
107
- this.root.unmount();
108
- }
109
- }
110
- async mountOriginalComponent(shouldRender) {
111
- if (isPromise(component))
112
- component = await component.then((m) => {
113
- return m[scope];
114
- });
115
- const element = React.createElement(component, this.props);
116
- if (reactVersion < 18) {
117
- const Render = shouldRender ? ReactDOM.render : ReactDOM.hydrate;
118
- Render(element, this.containerRef.current);
119
- } else {
120
- if (shouldRender) {
121
- const { createRoot } = self.libs;
122
- this.root = createRoot(this.containerRef.current);
123
- this.root.render(element);
124
- } else {
125
- const { hydrateRoot } = self.libs;
126
- this.root = hydrateRoot(this.containerRef.current, element);
127
- }
128
- }
129
- }
130
- render() {
131
- return /* @__PURE__ */ React.createElement("div", { ref: this.containerRef });
132
- }
133
- }
134
- return WrappedComponent;
135
- }
136
- };
137
-
138
- // src/mfRuntime/plugins.ts
139
- var catchErrorNextPlugin = function(showLog = false) {
140
- return {
141
- name: "catch-error-next-plugin",
142
- errorLoadRemote(o) {
143
- if (showLog) {
144
- console.log("[@emp/adapter]", o.id, o.lifecycle, o.from);
145
- console.error("[@emp/adapter]", o.error);
146
- }
147
- return {};
148
- }
149
- };
150
- };
151
-
152
- // src/mfRuntime/index.ts
153
- var EMPRuntime = class {
154
- libs = deepAssign(
155
- {
156
- scope: "default"
157
- },
158
- window[shareGlobalName] || {}
159
- );
160
- initOptions;
161
- options = {
162
- showLog: false
163
- };
164
- framework;
165
- isInit = false;
166
- react;
167
- constructor(op) {
168
- if (op) this.setupLibs(op);
169
- }
170
- /**
171
- * 实例化 adapter libs
172
- * @param EMP_ADAPTER
173
- */
174
- setupLibs(o) {
175
- if (o) {
176
- this.libs = o;
177
- }
178
- if (!this.libs.MFRuntime) {
179
- throw new Error("EMP FastMode must load MFRuntime!");
180
- }
181
- if (!this.libs.MFSDK) {
182
- throw new Error("EMP FastMode must load MFSDK!");
183
- }
184
- if (this.libs.React && this.libs.ReactDOM) {
185
- this.framework = "react";
186
- this.react = new ReactAdapter(this.libs);
187
- }
188
- }
189
- init(options = {}) {
190
- if (this.isInit) return;
191
- let op = {
192
- name: "empAdepterProject",
193
- remotes: [],
194
- plugins: [catchErrorNextPlugin(this.options.showLog)]
195
- };
196
- if (this.framework === "react") {
197
- op.shared = this.react.shared;
198
- }
199
- op = deepAssign(op, options);
200
- this.libs.MFRuntime.init(op);
201
- this.isInit = true;
202
- }
203
- load(...args) {
204
- return this.libs.MFRuntime.loadRemote(...args);
205
- }
206
- register = this.libs.MFRuntime.registerRemotes;
207
- preload = this.libs.MFRuntime.preloadRemote;
208
- loadShare = this.libs.MFRuntime.loadShare;
209
- };
210
- var mfRuntime_default = new EMPRuntime();
1
+ "use strict";var c=Object.defineProperty;var M=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var O=Object.prototype.hasOwnProperty;var E=(t,e)=>{for(var i in e)c(t,i,{get:e[i],enumerable:!0})},x=(t,e,i,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of P(e))!O.call(t,r)&&r!==i&&c(t,r,{get:()=>e[r],enumerable:!(n=M(e,r))||n.enumerable});return t};var S=t=>x(c({},"__esModule",{value:!0}),t);var I={};E(I,{default:()=>R,reactAdapter:()=>g});module.exports=S(I);function p(t,...e){for(let i of e)for(let n in i){let r=i[n],o=t[n];if(Object(r)==r&&Object(o)===o){t[n]=p(o,r);continue}t[n]=i[n]}return t}var f=t=>t?Number(t.split(".")[0]):0,d=t=>t&&Object.prototype.toString.call(t)==="[object Promise]";var y="EMP_SHARE_RUNTIME";var b=function(t=!1){return{name:"catch-error-next-plugin",errorLoadRemote(e){return t&&(console.log("[@emp/share]",e.id,e.lifecycle,e.from),console.error("[@emp/share]",e.error)),{}}}};var l=class{libs=p({},window[y]||{});initOptions;options={showLog:!1};isInit=!1;constructor(e){e&&this.setup(e)}setup(e){if(e&&(this.libs=e),!this.libs.MFRuntime||!this.libs.MFSDK)throw new Error("MFRuntime and MFSDK Required!")}init(e={}){if(this.isInit)return;let i={name:"empAdepterProject",remotes:[],plugins:[b(this.options.showLog)]};i=p(i,e),this.libs.MFRuntime.init(i),this.isInit=!0}load(...e){return this.libs.MFRuntime.loadRemote(...e)}register=this.libs.MFRuntime.registerRemotes;preload=this.libs.MFRuntime.preloadRemote;loadShare=this.libs.MFRuntime.loadShare},R=new l;var m=class{libs={scope:"default"};constructor(e){e&&this.setup(e)}setup(e){e&&(typeof e=="string"&&(e=window[e]),this.libs=p(this.libs,e))}get shared(){let{React:e,ReactDOM:i,scope:n}=this.libs;return{react:{lib:()=>e,version:e.version,scope:n,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}},"react-dom":{lib:()=>i,version:i.version,scope:n,shareConfig:{singleton:!0,requiredVersion:`^${e.version}`}}}}adapter(e,i=this.libs.scope,n=this.libs.React,r=this.libs.ReactDOM){let o=f(n.version),h=this;class T extends n.Component{containerRef;root;constructor(a){super(a),this.containerRef=n.createRef()}componentDidMount(){this.mountOriginalComponent(!0)}componentDidUpdate(){this.mountOriginalComponent()}componentWillUnmount(){this.unMountOriginalComponent()}unMountOriginalComponent(){this.containerRef.current&&(o<18?r.unmountComponentAtNode(this.containerRef.current):this.root.unmount())}async mountOriginalComponent(a){d(e)&&(e=await e.then(s=>s[i]));let u=n.createElement(e,this.props);if(o<18)(a?r.render:r.hydrate)(u,this.containerRef.current);else if(a){let{createRoot:s}=h.libs;this.root=s(this.containerRef.current),this.root.render(u)}else{let{hydrateRoot:s}=h.libs;this.root=s(this.containerRef.current,u)}}render(){return n.createElement("div",{ref:this.containerRef})}}return T}},g=new m;0&&(module.exports={reactAdapter});
211
2
  //# sourceMappingURL=runtime.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/runtime.ts","../src/helper/config.ts","../src/mfRuntime/helper.ts","../src/mfRuntime/framework/base.ts","../src/mfRuntime/framework/react.tsx","../src/mfRuntime/plugins.ts","../src/mfRuntime/index.ts"],"sourcesContent":["export {default} from './mfRuntime'\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","export function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n","import type {EMP_ADAPTER_Type} from '../types'\nexport class BaseAdapter {\n libs: EMP_ADAPTER_Type\n\n constructor(libs: EMP_ADAPTER_Type) {\n this.libs = libs\n }\n get shared() {\n const {React, ReactDOM, scope} = this.libs as EMP_ADAPTER_Type\n return {\n react: {\n lib: () => React,\n version: React.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n 'react-dom': {\n lib: () => ReactDOM,\n version: ReactDOM.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n }\n }\n}\n","import {checkVersion, isPromise} from '../helper'\nimport type {EMP_ADAPTER_Type} from '../types'\nimport {BaseAdapter} from './base'\nexport class ReactAdapter extends BaseAdapter {\n constructor(libs: EMP_ADAPTER_Type) {\n super(libs)\n }\n adapter<P = any>(\n component: any,\n scope: string = this.libs.scope,\n React: any = this.libs.React,\n ReactDOM: any = this.libs.ReactDOM,\n ): P {\n const reactVersion = checkVersion(React.version)\n const self = this\n class WrappedComponent extends React.Component {\n public containerRef: any\n public root: any\n constructor(props: P) {\n super(props as any)\n this.containerRef = React.createRef()\n }\n\n componentDidMount() {\n this.mountOriginalComponent(true)\n }\n\n componentDidUpdate() {\n this.mountOriginalComponent()\n }\n\n componentWillUnmount() {\n this.unMountOriginalComponent()\n }\n unMountOriginalComponent() {\n if (!this.containerRef.current) return\n if (reactVersion < 18) {\n ReactDOM.unmountComponentAtNode(this.containerRef.current)\n } else {\n this.root.unmount()\n }\n }\n async mountOriginalComponent(shouldRender?: boolean) {\n if (isPromise(component))\n component = await component.then((m: any) => {\n return m[scope]\n })\n const element = React.createElement(component, this.props)\n if (reactVersion < 18) {\n const Render = shouldRender ? ReactDOM.render : ReactDOM.hydrate\n Render(element, this.containerRef.current)\n } else {\n if (shouldRender) {\n const {createRoot} = self.libs\n this.root = createRoot(this.containerRef.current!)\n this.root.render(element)\n } else {\n const {hydrateRoot} = self.libs\n this.root = hydrateRoot(this.containerRef.current!, element)\n }\n }\n }\n\n render() {\n return <div ref={this.containerRef} />\n }\n }\n return WrappedComponent as any\n }\n}\n","import type {FederationRuntimePlugin} from '@module-federation/runtime'\nexport const errorLoadPlugin: () => FederationRuntimePlugin = function () {\n return {\n name: 'fallback-plugin',\n errorLoadRemote(...args) {\n console.error('[errorLoadRemote]', ...args)\n const fallback = 'error loading modules'\n return fallback\n },\n }\n}\n\nexport const catchErrorNextPlugin: (showLog?: boolean) => FederationRuntimePlugin = function (showLog = false) {\n return {\n name: 'catch-error-next-plugin',\n errorLoadRemote(o) {\n if (showLog) {\n // console.error('[@emp/adapter]', o)\n console.log('[@emp/adapter]', o.id, o.lifecycle, o.from)\n console.error('[@emp/adapter]', o.error)\n }\n return {}\n },\n }\n}\n","import {shareGlobalName} from 'src/helper/config'\nimport {ReactAdapter} from './framework/react'\nimport {deepAssign} from './helper'\nimport {catchErrorNextPlugin} from './plugins'\nimport type {\n EMP_ADAPTER_OPTIONS_Type,\n EMP_ADAPTER_Type,\n EmpRuntimeOptions,\n FrameworkType,\n InitOptionsType,\n LoadRemoteType,\n} from './types'\ntype EmpInitOptionsType = Partial<InitOptionsType>\nexport class EMPRuntime {\n public libs: EMP_ADAPTER_OPTIONS_Type = deepAssign(\n {\n scope: 'default',\n },\n window[shareGlobalName] || {},\n )\n public initOptions!: InitOptionsType\n public options: EmpRuntimeOptions = {\n showLog: false,\n }\n framework?: FrameworkType\n private isInit = false\n react!: ReactAdapter\n constructor(op?: EMP_ADAPTER_OPTIONS_Type) {\n if (op) this.setupLibs(op)\n }\n /**\n * 实例化 adapter libs\n * @param EMP_ADAPTER\n */\n public setupLibs(o?: EMP_ADAPTER_OPTIONS_Type) {\n if (o) {\n // console.log(this.libs, o)\n // this.libs = deepAssign(this.libs, o)\n this.libs = o\n }\n if (!this.libs.MFRuntime) {\n throw new Error('EMP FastMode must load MFRuntime!')\n }\n if (!this.libs.MFSDK) {\n throw new Error('EMP FastMode must load MFSDK!')\n }\n if (this.libs.React && this.libs.ReactDOM) {\n this.framework = 'react'\n this.react = new ReactAdapter(this.libs as EMP_ADAPTER_Type)\n }\n }\n public init(options: EmpInitOptionsType = {}) {\n if (this.isInit) return\n let op: InitOptionsType = {\n name: 'empAdepterProject',\n remotes: [],\n plugins: [catchErrorNextPlugin(this.options.showLog)],\n }\n if (this.framework === 'react') {\n op.shared = this.react.shared\n }\n op = deepAssign<InitOptionsType>(op, options)\n this.libs.MFRuntime.init(op)\n this.isInit = true\n }\n public load<T = any>(...args: LoadRemoteType) {\n return this.libs.MFRuntime.loadRemote<T>(...args) as Promise<T>\n }\n public register = this.libs.MFRuntime.registerRemotes\n public preload = this.libs.MFRuntime.preloadRemote\n public loadShare = this.libs.MFRuntime.loadShare\n}\n//\nexport default new EMPRuntime()\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,kBAAkB;;;ACAxB,SAAS,WAAc,WAAgB,SAAiB;AAC7D,aAAW,UAAU,SAAS;AAC5B,eAAW,KAAK,QAAQ;AACtB,YAAM,KAAK,OAAO,CAAC,GACjB,KAAK,OAAO,CAAC;AACf,UAAI,OAAO,EAAE,KAAK,MAAM,OAAO,EAAE,MAAM,IAAI;AACzC,eAAO,CAAC,IAAI,WAAW,IAAI,EAAE;AAC7B;AAAA,MACF;AACA,aAAO,CAAC,IAAI,OAAO,CAAC;AAAA,IACtB;AAAA,EACF;AACA,SAAO;AACT;AAEO,IAAM,eAAe,CAAC,YAAqB,UAAU,OAAO,QAAQ,MAAM,GAAG,EAAE,CAAC,CAAC,IAAI;AACrF,IAAM,YAAY,CAAC,MAAW,KAAK,OAAO,UAAU,SA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AA,EACA;AAAA,EACQ,SAAS;AAAA,EACjB;AAAA,EACA,YAAY,IAA+B;AACzC,QAAI,GAAI,MAAK,UAAU,EAAE;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAAA,EAKO,UAAU,GAA8B;AAC7C,QAAI,GAAG;AAGL,WAAK,OAAO;AAAA,IACd;AACA,QAAI,CAAC,KAAK,KAAK,WAAW;AACxB,YAAM,IAAI,MAAM,mCAAmC;AAAA,IACrD;AACA,QAAI,CAAC,KAAK,KAAK,OAAO;AACpB,YAAM,IAAI,MAAM,+BAA+B;AAAA,IACjD;AACA,QAAI,KAAK,KAAK,SAAS,KAAK,KAAK,UAAU;AACzC,WAAK,YAAY;AACjB,WAAK,QAAQ,IAAI,aAAa,KAAK,IAAwB;AAAA,IAC7D;AAAA,EACF;AAAA,EACO,KAAK,UAA8B,CAAC,GAAG;AAC5C,QAAI,KAAK,OAAQ;AACjB,QAAI,KAAsB;AAAA,MACxB,MAAM;AAAA,MACN,SAAS,CAAC;AAAA,MACV,SAAS,CAAC,qBAAqB,KAAK,QAAQ,OAAO,CAAC;AAAA,IACtD;AACA,QAAI,KAAK,cAAc,SAAS;AAC9B,SAAG,SAAS,KAAK,MAAM;AAAA,IACzB;AACA,SAAK,WAA4B,IAAI,OAAO;AAC5C,SAAK,KAAK,UAAU,KAAK,EAAE;AAC3B,SAAK,SAAS;AAAA,EAChB;AAAA,EACO,QAAiB,MAAsB;AAC5C,WAAO,KAAK,KAAK,UAAU,WAAc,GAAG,IAAI;AAAA,EAClD;AAAA,EACO,WAAW,KAAK,KAAK,UAAU;AAAA,EAC/B,UAAU,KAAK,KAAK,UAAU;AAAA,EAC9B,YAAY,KAAK,KAAK,UAAU;AACzC;AAEA,IAAO,oBAAQ,IAAI,WAAW;","names":[]}
1
+ {"version":3,"sources":["../src/runtime.ts","../src/helper/index.ts","../src/helper/config.ts","../src/runtimes/plugins.ts","../src/runtimes/index.ts","../src/adapters/react.tsx"],"sourcesContent":["export {default} from './runtimes'\nimport reactAdapter from './adapters/react'\nexport {reactAdapter}\n","export const importJsVm = (content: string) => `data:text/javascript,${content}`\n\nexport function deepAssign<T>(target: any, ...sources: any): T {\n for (const source of sources) {\n for (const k in source) {\n const vs = source[k],\n vt = target[k]\n if (Object(vs) == vs && Object(vt) === vt) {\n target[k] = deepAssign(vt, vs)\n continue\n }\n target[k] = source[k]\n }\n }\n return target\n}\n\nexport const checkVersion = (version: string) => (version ? Number(version.split('.')[0]) : 0)\nexport const isPromise = (p: any) => p && Object.prototype.toString.call(p) === '[object Promise]'\n","export const shareGlobalName = 'EMP_SHARE_RUNTIME'\n","import type {FederationRuntimePlugin} from '@module-federation/runtime'\nexport const catchErrorNextPlugin: (showLog?: boolean) => FederationRuntimePlugin = function (showLog = false) {\n return {\n name: 'catch-error-next-plugin',\n errorLoadRemote(o) {\n if (showLog) {\n console.log('[@emp/share]', o.id, o.lifecycle, o.from)\n console.error('[@emp/share]', o.error)\n }\n return {}\n },\n }\n}\n","import {deepAssign} from 'src/helper'\nimport {shareGlobalName} from 'src/helper/config'\nimport type {EMPShareRuntimeType, EmpRuntimeOptions, InitOptionsType, LoadRemoteType} from 'src/types'\nimport {catchErrorNextPlugin} from './plugins'\ntype EmpInitOptionsType = Partial<InitOptionsType>\nexport class EMPRuntime {\n public libs: EMPShareRuntimeType = deepAssign({}, window[shareGlobalName] || {})\n public initOptions!: InitOptionsType\n public options: EmpRuntimeOptions = {\n showLog: false,\n }\n private isInit = false\n constructor(op?: EMPShareRuntimeType) {\n if (op) this.setup(op)\n }\n /**\n * 实例化 adapter libs\n * @param EMP_ADAPTER\n */\n public setup(o?: EMPShareRuntimeType) {\n if (o) {\n this.libs = o\n }\n if (!this.libs.MFRuntime || !this.libs.MFSDK) {\n throw new Error('MFRuntime and MFSDK Required!')\n }\n }\n public init(options: EmpInitOptionsType = {}) {\n if (this.isInit) return\n let op: InitOptionsType = {\n name: 'empAdepterProject',\n remotes: [],\n plugins: [catchErrorNextPlugin(this.options.showLog)],\n }\n op = deepAssign<InitOptionsType>(op, options)\n this.libs.MFRuntime.init(op)\n this.isInit = true\n }\n public load<T = any>(...args: LoadRemoteType) {\n return this.libs.MFRuntime.loadRemote<T>(...args) as Promise<T>\n }\n public register = this.libs.MFRuntime.registerRemotes\n public preload = this.libs.MFRuntime.preloadRemote\n public loadShare = this.libs.MFRuntime.loadShare\n}\n//\nexport default new EMPRuntime()\n","import {checkVersion, deepAssign, isPromise} from 'src/helper'\nimport type {EMPShareRuntimeAdapterReactType, InitOptionsType} from 'src/types'\nexport class ReactAdapter {\n libs: EMPShareRuntimeAdapterReactType = {\n scope: 'default',\n }\n constructor(op?: EMPShareRuntimeAdapterReactType) {\n if (op) this.setup(op)\n }\n public setup(o?: EMPShareRuntimeAdapterReactType | string) {\n if (o) {\n if (typeof o === 'string') o = window[o]\n this.libs = deepAssign(this.libs, o)\n }\n }\n get shared(): InitOptionsType['shared'] {\n const {React, ReactDOM, scope} = this.libs as EMPShareRuntimeAdapterReactType\n return {\n react: {\n lib: () => React,\n version: React.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n 'react-dom': {\n lib: () => ReactDOM,\n version: ReactDOM.version,\n scope,\n shareConfig: {\n singleton: true,\n requiredVersion: `^${React.version}`,\n },\n },\n }\n }\n adapter<P = any>(\n component: any,\n scope: string = this.libs.scope,\n React: any = this.libs.React,\n ReactDOM: any = this.libs.ReactDOM,\n ): P {\n const reactVersion = checkVersion(React.version)\n const self = this\n class WrappedComponent extends React.Component {\n public containerRef: any\n public root: any\n constructor(props: P) {\n super(props as any)\n this.containerRef = React.createRef()\n }\n\n componentDidMount() {\n this.mountOriginalComponent(true)\n }\n\n componentDidUpdate() {\n this.mountOriginalComponent()\n }\n\n componentWillUnmount() {\n this.unMountOriginalComponent()\n }\n unMountOriginalComponent() {\n if (!this.containerRef.current) return\n if (reactVersion < 18) {\n ReactDOM.unmountComponentAtNode(this.containerRef.current)\n } else {\n this.root.unmount()\n }\n }\n async mountOriginalComponent(shouldRender?: boolean) {\n if (isPromise(component))\n component = await component.then((m: any) => {\n return m[scope]\n })\n const element = React.createElement(component, this.props)\n if (reactVersion < 18) {\n const Render = shouldRender ? ReactDOM.render : ReactDOM.hydrate\n Render(element, this.containerRef.current)\n } else {\n if (shouldRender) {\n const {createRoot} = self.libs\n this.root = createRoot(this.containerRef.current!)\n this.root.render(element)\n } else {\n const {hydrateRoot} = self.libs\n this.root = hydrateRoot(this.containerRef.current!, element)\n }\n }\n }\n\n render() {\n return <div ref={this.containerRef} />\n }\n }\n return WrappedComponent as any\n }\n}\n\nexport default new ReactAdapter()\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,aAAAE,EAAA,iBAAAC,IAAA,eAAAC,EAAAJ,GCEO,SAASK,EAAcC,KAAgBC,EAAiB,CAC7D,QAAWC,KAAUD,EACnB,QAAWE,KAAKD,EAAQ,CACtB,IAAME,EAAKF,EAAOC,CAAC,EACjBE,EAAKL,EAAOG,CAAC,EACf,GAAI,OAAOC,CAAE,GAAKA,GAAM,OAAOC,CAAE,IAAMA,EAAI,CACzCL,EAAOG,CAAC,EAAIJ,EAAWM,EAAID,CAAE,EAC7B,QACF,CACAJ,EAAOG,CAAC,EAAID,EAAOC,CAAC,CACtB,CAEF,OAAOH,CACT,CAEO,IAAMM,EAAgBC,GAAqBA,EAAU,OAAOA,EAAQ,MAAM,GAAG,EAAE,CAAC,CAAC,EAAI,EAC/EC,EAAaC,GAAWA,GAAK,OAAO,UAAU,SAAS,KAAKA,CAAC,IAAM,mBClBzE,IAAMC,EAAkB,oBCCxB,IAAMC,EAAuE,SAAUC,EAAU,GAAO,CAC7G,MAAO,CACL,KAAM,0BACN,gBAAgBC,EAAG,CACjB,OAAID,IACF,QAAQ,IAAI,eAAgBC,EAAE,GAAIA,EAAE,UAAWA,EAAE,IAAI,EACrD,QAAQ,MAAM,eAAgBA,EAAE,KAAK,GAEhC,CAAC,CACV,CACF,CAC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,aAAc,CACtC,CACF,CACA,OAAOO,CACT,CACF,EAEOQ,EAAQ,IAAInB","names":["runtime_exports","__export","runtimes_default","react_default","__toCommonJS","deepAssign","target","sources","source","k","vs","vt","checkVersion","version","isPromise","p","shareGlobalName","catchErrorNextPlugin","showLog","o","EMPRuntime","deepAssign","shareGlobalName","op","o","options","catchErrorNextPlugin","args","runtimes_default","ReactAdapter","op","o","deepAssign","React","ReactDOM","scope","component","reactVersion","checkVersion","self","WrappedComponent","props","shouldRender","isPromise","m","element","createRoot","hydrateRoot","react_default"]}
@@ -1,73 +1,20 @@
1
- import * as MFRuntime from '@module-federation/runtime';
2
- import MFRuntime__default from '@module-federation/runtime';
3
- import MFSDK from '@module-federation/sdk';
4
-
5
- type Override<What, With> = Omit<What, keyof With> & With;
6
- type EMP_ADAPTER_OPTIONS_Type = {
7
- React?: any;
8
- ReactDOM?: any;
9
- createRoot?: any;
10
- hydrateRoot?: any;
11
- Vue?: any;
12
- MFRuntime: Required<typeof MFRuntime__default>;
13
- MFSDK: Required<typeof MFSDK>;
14
- scope: string;
15
- };
16
- type EMP_ADAPTER_Type = Override<Required<EMP_ADAPTER_OPTIONS_Type>, {
17
- createRoot?: any;
18
- hydrateRoot?: any;
19
- }>;
20
- type InitOptionsType = Parameters<typeof MFRuntime__default.init>[0];
21
- type LoadRemoteType = Parameters<typeof MFRuntime__default.loadRemote>;
22
- type FrameworkType = 'react' | 'vue' | 'vue2' | 'angular';
23
- type EmpRuntimeOptions = {
24
- showLog?: boolean;
25
- };
26
-
27
- declare class BaseAdapter {
28
- libs: EMP_ADAPTER_Type;
29
- constructor(libs: EMP_ADAPTER_Type);
30
- get shared(): {
31
- react: {
32
- lib: () => any;
33
- version: any;
34
- scope: string;
35
- shareConfig: {
36
- singleton: boolean;
37
- requiredVersion: string;
38
- };
39
- };
40
- 'react-dom': {
41
- lib: () => any;
42
- version: any;
43
- scope: string;
44
- shareConfig: {
45
- singleton: boolean;
46
- requiredVersion: string;
47
- };
48
- };
49
- };
50
- }
51
-
52
- declare class ReactAdapter extends BaseAdapter {
53
- constructor(libs: EMP_ADAPTER_Type);
54
- adapter<P = any>(component: any, scope?: string, React?: any, ReactDOM?: any): P;
55
- }
1
+ import * as MFRuntime from '@empjs/module-federation-runtime';
2
+ import { E as EMPShareRuntimeType, I as InitOptionsType, a as EmpRuntimeOptions, L as LoadRemoteType } from './react-BIjkQYoz.cjs';
3
+ export { _ as reactAdapter } from './react-BIjkQYoz.cjs';
4
+ import '@module-federation/sdk';
56
5
 
57
6
  type EmpInitOptionsType = Partial<InitOptionsType>;
58
7
  declare class EMPRuntime {
59
- libs: EMP_ADAPTER_OPTIONS_Type;
8
+ libs: EMPShareRuntimeType;
60
9
  initOptions: InitOptionsType;
61
10
  options: EmpRuntimeOptions;
62
- framework?: FrameworkType;
63
11
  private isInit;
64
- react: ReactAdapter;
65
- constructor(op?: EMP_ADAPTER_OPTIONS_Type);
12
+ constructor(op?: EMPShareRuntimeType);
66
13
  /**
67
14
  * 实例化 adapter libs
68
15
  * @param EMP_ADAPTER
69
16
  */
70
- setupLibs(o?: EMP_ADAPTER_OPTIONS_Type): void;
17
+ setup(o?: EMPShareRuntimeType): void;
71
18
  init(options?: EmpInitOptionsType): void;
72
19
  load<T = any>(...args: LoadRemoteType): Promise<T>;
73
20
  register: typeof MFRuntime.registerRemotes;
package/dist/runtime.d.ts CHANGED
@@ -1,73 +1,20 @@
1
- import * as MFRuntime from '@module-federation/runtime';
2
- import MFRuntime__default from '@module-federation/runtime';
3
- import MFSDK from '@module-federation/sdk';
4
-
5
- type Override<What, With> = Omit<What, keyof With> & With;
6
- type EMP_ADAPTER_OPTIONS_Type = {
7
- React?: any;
8
- ReactDOM?: any;
9
- createRoot?: any;
10
- hydrateRoot?: any;
11
- Vue?: any;
12
- MFRuntime: Required<typeof MFRuntime__default>;
13
- MFSDK: Required<typeof MFSDK>;
14
- scope: string;
15
- };
16
- type EMP_ADAPTER_Type = Override<Required<EMP_ADAPTER_OPTIONS_Type>, {
17
- createRoot?: any;
18
- hydrateRoot?: any;
19
- }>;
20
- type InitOptionsType = Parameters<typeof MFRuntime__default.init>[0];
21
- type LoadRemoteType = Parameters<typeof MFRuntime__default.loadRemote>;
22
- type FrameworkType = 'react' | 'vue' | 'vue2' | 'angular';
23
- type EmpRuntimeOptions = {
24
- showLog?: boolean;
25
- };
26
-
27
- declare class BaseAdapter {
28
- libs: EMP_ADAPTER_Type;
29
- constructor(libs: EMP_ADAPTER_Type);
30
- get shared(): {
31
- react: {
32
- lib: () => any;
33
- version: any;
34
- scope: string;
35
- shareConfig: {
36
- singleton: boolean;
37
- requiredVersion: string;
38
- };
39
- };
40
- 'react-dom': {
41
- lib: () => any;
42
- version: any;
43
- scope: string;
44
- shareConfig: {
45
- singleton: boolean;
46
- requiredVersion: string;
47
- };
48
- };
49
- };
50
- }
51
-
52
- declare class ReactAdapter extends BaseAdapter {
53
- constructor(libs: EMP_ADAPTER_Type);
54
- adapter<P = any>(component: any, scope?: string, React?: any, ReactDOM?: any): P;
55
- }
1
+ import * as MFRuntime from '@empjs/module-federation-runtime';
2
+ import { E as EMPShareRuntimeType, I as InitOptionsType, a as EmpRuntimeOptions, L as LoadRemoteType } from './react-BIjkQYoz.js';
3
+ export { _ as reactAdapter } from './react-BIjkQYoz.js';
4
+ import '@module-federation/sdk';
56
5
 
57
6
  type EmpInitOptionsType = Partial<InitOptionsType>;
58
7
  declare class EMPRuntime {
59
- libs: EMP_ADAPTER_OPTIONS_Type;
8
+ libs: EMPShareRuntimeType;
60
9
  initOptions: InitOptionsType;
61
10
  options: EmpRuntimeOptions;
62
- framework?: FrameworkType;
63
11
  private isInit;
64
- react: ReactAdapter;
65
- constructor(op?: EMP_ADAPTER_OPTIONS_Type);
12
+ constructor(op?: EMPShareRuntimeType);
66
13
  /**
67
14
  * 实例化 adapter libs
68
15
  * @param EMP_ADAPTER
69
16
  */
70
- setupLibs(o?: EMP_ADAPTER_OPTIONS_Type): void;
17
+ setup(o?: EMPShareRuntimeType): void;
71
18
  init(options?: EmpInitOptionsType): void;
72
19
  load<T = any>(...args: LoadRemoteType): Promise<T>;
73
20
  register: typeof MFRuntime.registerRemotes;