@empjs/share 0.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/README.md ADDED
@@ -0,0 +1,96 @@
1
+ # @empjs/share
2
+
3
+ ## 01 Rspack Plugin
4
+ > @empjs/share/rspack
5
+ 使用方法
6
+ ```js
7
+ import {pluginRspackEmpShare} from '@empjs/share'
8
+ // import pluginRspackEmpShare from '@empjs/share/rspack' // or
9
+ import {defineConfig} from '@empjs/cli'
10
+ export default defineConfig(store => {
11
+ return {
12
+ plugins: [
13
+ pluginRspackEmpShare({
14
+ name: 'mfHost',
15
+ shared: {
16
+ react: {
17
+ singleton: true,
18
+ requiredVersion: '18',
19
+ },
20
+ 'react-dom': {
21
+ singleton: true,
22
+ requiredVersion: '18',
23
+ },
24
+ },
25
+ exposes: {
26
+ './App': './src/App',
27
+ './CountComp': './src/CountComp',
28
+ },
29
+ }),
30
+ ],
31
+ }
32
+ })
33
+
34
+
35
+ ```
36
+
37
+ ## 02 Library
38
+ > @empjs/share/library
39
+
40
+ ## 03 Runtime
41
+ > @empjs/share/runtime
42
+
43
+
44
+ ### 项目调用
45
+
46
+ ```js
47
+ import React, { useEffect, useState, version } from "react";
48
+ import ReactDOM from "react-dom";
49
+ // 引用runtime
50
+ import { empRuntime, withReactAdapter } from "@empjs/share/runtime";
51
+ // 实例化远程 emp
52
+ empRuntime.init({
53
+ remotes: [
54
+ {
55
+ name: "mfHost",
56
+ entry: `http://${process.env.lanIp}:8001/emp.js`,
57
+ },
58
+ ],
59
+ name: "federationRuntimeDemo",
60
+ });
61
+ // 封装 React 18的组件 以便插入到 React 16
62
+ const RemoteApp = empRuntime.react.adapter(empRuntime.load("mfHost/App"));
63
+ // 创建 React 16 组件
64
+ const ParentComponent = () => {
65
+ const [count, setCount] = useState(0);
66
+ return (
67
+ <div
68
+ style={{
69
+ border: "1px solid #eee",
70
+ padding: "10px",
71
+ background: "#f7f7f7",
72
+ }}
73
+ >
74
+ <h1>React Version {React.version}!</h1>
75
+ <button onClick={() => setCount(count + 1)}>Click Count {count}</button>
76
+ </div>
77
+ );
78
+ };
79
+ // 封装 React 16的组件 以便插入到 React 18
80
+ const ParentComponentAdapter = empRuntime.react.adapter(
81
+ ParentComponent,
82
+ "default",
83
+ React,
84
+ ReactDOM
85
+ );
86
+ //
87
+ const App = () => {
88
+ return (
89
+ <>
90
+ <h1>app React Version {version}</h1>
91
+ <RemoteApp component={ParentComponentAdapter} />
92
+ </>
93
+ );
94
+ };
95
+ export default App;
96
+ ```
package/dist/index.cjs ADDED
@@ -0,0 +1,109 @@
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/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ pluginRspackEmpShare: () => rspack_default
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+
27
+ // src/plugin/rspack/index.ts
28
+ var import_rspack = require("@module-federation/enhanced/rspack");
29
+
30
+ // src/helper/config.ts
31
+ var shareGlobalName = "EMP_SHARE_RUNTIME";
32
+
33
+ // src/helper/index.ts
34
+ var importJsVm = (content) => `data:text/javascript,${content}`;
35
+
36
+ // src/plugin/rspack/plugin.ts
37
+ var getShareRuntimeEntry = () => {
38
+ const content = [`import '@empjs/share/library'`].join("\n");
39
+ return importJsVm(content);
40
+ };
41
+ var EmpShareRuntimePlugin = class {
42
+ constructor() {
43
+ }
44
+ apply(compiler) {
45
+ const { webpack } = compiler;
46
+ const entry = getShareRuntimeEntry();
47
+ new webpack.EntryPlugin(compiler.context, entry, {
48
+ name: void 0
49
+ }).apply(compiler);
50
+ }
51
+ };
52
+
53
+ // src/plugin/rspack/index.ts
54
+ var rspack_default = (o = {}) => {
55
+ return {
56
+ name: "@empjs/share",
57
+ async rsConfig(store) {
58
+ console.log(o);
59
+ if (o.name) {
60
+ const op = store.deepAssign(
61
+ {
62
+ filename: "emp.js",
63
+ manifest: false,
64
+ dts: false,
65
+ dev: {
66
+ disableDynamicRemoteTypeHints: true
67
+ }
68
+ },
69
+ o
70
+ );
71
+ delete op.empRuntime;
72
+ store.chain.plugin("plugin-emp-share").use(import_rspack.ModuleFederationPlugin, [op]);
73
+ }
74
+ const { empRuntime } = o;
75
+ if (empRuntime) {
76
+ if (!empRuntime.runtimeLib) {
77
+ store.chain.plugin("plugin-emp-runtime").use(EmpShareRuntimePlugin);
78
+ }
79
+ empRuntime.runtimeGlobal = empRuntime.frameworkGlobal || shareGlobalName;
80
+ const externalRuntime = {
81
+ "@module-federation/runtime": `MFRuntime`,
82
+ "@module-federation/sdk": `MFSDK`
83
+ };
84
+ const externals = [];
85
+ for (const [key, value] of Object.entries(externalRuntime)) {
86
+ externals[key] = `${empRuntime.runtimeGlobal}.${value}`;
87
+ }
88
+ empRuntime.framework = empRuntime.framework || "react";
89
+ empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || empRuntime.runtimeGlobal;
90
+ if (empRuntime.framework === "react") {
91
+ const externalReact = {
92
+ react: `React`,
93
+ "react-dom": `ReactDOM`
94
+ };
95
+ for (const [key, value] of Object.entries(externalReact)) {
96
+ externals[key] = `${empRuntime.frameworkGlobal}.${value}`;
97
+ }
98
+ }
99
+ if (empRuntime.setExternals) empRuntime.setExternals(externals);
100
+ store.merge({ externals });
101
+ }
102
+ }
103
+ };
104
+ };
105
+ // Annotate the CommonJS export names for ESM import in node:
106
+ 0 && (module.exports = {
107
+ pluginRspackEmpShare
108
+ });
109
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/plugin/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugin/rspack/plugin.ts"],"sourcesContent":["// export {default as runtime} from './mfRuntime'\nexport {default as pluginRspackEmpShare} from './rspack'\n","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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,oBAAqC;;;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,sCAAwB,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":[]}
@@ -0,0 +1,3 @@
1
+ export { default as pluginRspackEmpShare } from './rspack.cjs';
2
+ import '@empjs/cli';
3
+ import '@module-federation/enhanced/rspack';
@@ -0,0 +1,3 @@
1
+ export { default as pluginRspackEmpShare } from './rspack.js';
2
+ import '@empjs/cli';
3
+ import '@module-federation/enhanced/rspack';
package/dist/index.js ADDED
@@ -0,0 +1,82 @@
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 pluginRspackEmpShare
81
+ };
82
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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":[]}
@@ -0,0 +1,105 @@
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/rspack.ts
21
+ var rspack_exports = {};
22
+ __export(rspack_exports, {
23
+ default: () => rspack_default
24
+ });
25
+ module.exports = __toCommonJS(rspack_exports);
26
+
27
+ // src/plugin/rspack/index.ts
28
+ var import_rspack = require("@module-federation/enhanced/rspack");
29
+
30
+ // src/helper/config.ts
31
+ var shareGlobalName = "EMP_SHARE_RUNTIME";
32
+
33
+ // src/helper/index.ts
34
+ var importJsVm = (content) => `data:text/javascript,${content}`;
35
+
36
+ // src/plugin/rspack/plugin.ts
37
+ var getShareRuntimeEntry = () => {
38
+ const content = [`import '@empjs/share/library'`].join("\n");
39
+ return importJsVm(content);
40
+ };
41
+ var EmpShareRuntimePlugin = class {
42
+ constructor() {
43
+ }
44
+ apply(compiler) {
45
+ const { webpack } = compiler;
46
+ const entry = getShareRuntimeEntry();
47
+ new webpack.EntryPlugin(compiler.context, entry, {
48
+ name: void 0
49
+ }).apply(compiler);
50
+ }
51
+ };
52
+
53
+ // src/plugin/rspack/index.ts
54
+ var rspack_default = (o = {}) => {
55
+ return {
56
+ name: "@empjs/share",
57
+ async rsConfig(store) {
58
+ console.log(o);
59
+ if (o.name) {
60
+ const op = store.deepAssign(
61
+ {
62
+ filename: "emp.js",
63
+ manifest: false,
64
+ dts: false,
65
+ dev: {
66
+ disableDynamicRemoteTypeHints: true
67
+ }
68
+ },
69
+ o
70
+ );
71
+ delete op.empRuntime;
72
+ store.chain.plugin("plugin-emp-share").use(import_rspack.ModuleFederationPlugin, [op]);
73
+ }
74
+ const { empRuntime } = o;
75
+ if (empRuntime) {
76
+ if (!empRuntime.runtimeLib) {
77
+ store.chain.plugin("plugin-emp-runtime").use(EmpShareRuntimePlugin);
78
+ }
79
+ empRuntime.runtimeGlobal = empRuntime.frameworkGlobal || shareGlobalName;
80
+ const externalRuntime = {
81
+ "@module-federation/runtime": `MFRuntime`,
82
+ "@module-federation/sdk": `MFSDK`
83
+ };
84
+ const externals = [];
85
+ for (const [key, value] of Object.entries(externalRuntime)) {
86
+ externals[key] = `${empRuntime.runtimeGlobal}.${value}`;
87
+ }
88
+ empRuntime.framework = empRuntime.framework || "react";
89
+ empRuntime.frameworkGlobal = empRuntime.frameworkGlobal || empRuntime.runtimeGlobal;
90
+ if (empRuntime.framework === "react") {
91
+ const externalReact = {
92
+ react: `React`,
93
+ "react-dom": `ReactDOM`
94
+ };
95
+ for (const [key, value] of Object.entries(externalReact)) {
96
+ externals[key] = `${empRuntime.frameworkGlobal}.${value}`;
97
+ }
98
+ }
99
+ if (empRuntime.setExternals) empRuntime.setExternals(externals);
100
+ store.merge({ externals });
101
+ }
102
+ }
103
+ };
104
+ };
105
+ //# sourceMappingURL=rspack.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/rspack.ts","../src/plugin/rspack/index.ts","../src/helper/config.ts","../src/helper/index.ts","../src/plugin/rspack/plugin.ts"],"sourcesContent":["// import {ModuleFederationPlugin} from '@module-federation/enhanced/rspack'\n// export type ModuleFederationPluginOptions = ConstructorParameters<typeof ModuleFederationPlugin>[0]\n// export {ModuleFederationPlugin}\nexport {default} from './plugin/rspack'\n","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":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,oBAAqC;;;ACD9B,IAAM,kBAAkB;;;ACA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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":[]}
@@ -0,0 +1,40 @@
1
+ import { GlobalStore } from '@empjs/cli';
2
+ import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
3
+
4
+ type ModuleFederationPluginOptions = ConstructorParameters<typeof ModuleFederationPlugin>[0];
5
+ type EMPSHARERuntimeOptions = {
6
+ /**
7
+ * UI框架 远程地址
8
+ */
9
+ frameworkLib?: string | {
10
+ dev: string;
11
+ prod: string;
12
+ };
13
+ /**
14
+ * UI框架 全局命名
15
+ */
16
+ frameworkGlobal?: string;
17
+ /**
18
+ * MFRuntime 远程地址
19
+ */
20
+ runtimeLib?: string;
21
+ /**
22
+ * MFRuntime 全局命名
23
+ */
24
+ runtimeGlobal?: string;
25
+ setExternals?: (o: any) => void;
26
+ /**
27
+ * 快捷设置 external 默认为 react
28
+ */
29
+ framework?: string;
30
+ };
31
+ type EMPPluginShareType = ModuleFederationPluginOptions & {
32
+ empRuntime?: EMPSHARERuntimeOptions;
33
+ };
34
+
35
+ declare const _default: (o?: EMPPluginShareType) => {
36
+ name: string;
37
+ rsConfig(store: GlobalStore): Promise<void>;
38
+ };
39
+
40
+ export { _default as default };
@@ -0,0 +1,40 @@
1
+ import { GlobalStore } from '@empjs/cli';
2
+ import { ModuleFederationPlugin } from '@module-federation/enhanced/rspack';
3
+
4
+ type ModuleFederationPluginOptions = ConstructorParameters<typeof ModuleFederationPlugin>[0];
5
+ type EMPSHARERuntimeOptions = {
6
+ /**
7
+ * UI框架 远程地址
8
+ */
9
+ frameworkLib?: string | {
10
+ dev: string;
11
+ prod: string;
12
+ };
13
+ /**
14
+ * UI框架 全局命名
15
+ */
16
+ frameworkGlobal?: string;
17
+ /**
18
+ * MFRuntime 远程地址
19
+ */
20
+ runtimeLib?: string;
21
+ /**
22
+ * MFRuntime 全局命名
23
+ */
24
+ runtimeGlobal?: string;
25
+ setExternals?: (o: any) => void;
26
+ /**
27
+ * 快捷设置 external 默认为 react
28
+ */
29
+ framework?: string;
30
+ };
31
+ type EMPPluginShareType = ModuleFederationPluginOptions & {
32
+ empRuntime?: EMPSHARERuntimeOptions;
33
+ };
34
+
35
+ declare const _default: (o?: EMPPluginShareType) => {
36
+ name: string;
37
+ rsConfig(store: GlobalStore): Promise<void>;
38
+ };
39
+
40
+ export { _default as default };
package/dist/rspack.js ADDED
@@ -0,0 +1,82 @@
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
+ };
82
+ //# sourceMappingURL=rspack.js.map
@@ -0,0 +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,I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,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":[]}
@@ -0,0 +1,211 @@
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();
211
+ //# sourceMappingURL=runtime.cjs.map
@@ -0,0 +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,SAAS,KAAK,CAAC,MAAM;;;ACfzE,IAAM,cAAN,MAAkB;AAAA,EACvB;AAAA,EAEA,YAAY,MAAwB;AAClC,SAAK,OAAO;AAAA,EACd;AAAA,EACA,IAAI,SAAS;AACX,UAAM,EAAC,OAAO,UAAU,MAAK,IAAI,KAAK;AACtC,WAAO;AAAA,MACL,OAAO;AAAA,QACL,KAAK,MAAM;AAAA,QACX,SAAS,MAAM;AAAA,QACf;AAAA,QACA,aAAa;AAAA,UACX,WAAW;AAAA,UACX,iBAAiB,IAAI,MAAM,OAAO;AAAA,QACpC;AAAA,MACF;AAAA,MACA,aAAa;AAAA,QACX,KAAK,MAAM;AAAA,QACX,SAAS,SAA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,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":[]}
@@ -0,0 +1,79 @@
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
+ }
56
+
57
+ type EmpInitOptionsType = Partial<InitOptionsType>;
58
+ declare class EMPRuntime {
59
+ libs: EMP_ADAPTER_OPTIONS_Type;
60
+ initOptions: InitOptionsType;
61
+ options: EmpRuntimeOptions;
62
+ framework?: FrameworkType;
63
+ private isInit;
64
+ react: ReactAdapter;
65
+ constructor(op?: EMP_ADAPTER_OPTIONS_Type);
66
+ /**
67
+ * 实例化 adapter libs
68
+ * @param EMP_ADAPTER
69
+ */
70
+ setupLibs(o?: EMP_ADAPTER_OPTIONS_Type): void;
71
+ init(options?: EmpInitOptionsType): void;
72
+ load<T = any>(...args: LoadRemoteType): Promise<T>;
73
+ register: typeof MFRuntime.registerRemotes;
74
+ preload: typeof MFRuntime.preloadRemote;
75
+ loadShare: typeof MFRuntime.loadShare;
76
+ }
77
+ declare const _default: EMPRuntime;
78
+
79
+ export { _default as default };
@@ -0,0 +1,79 @@
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
+ }
56
+
57
+ type EmpInitOptionsType = Partial<InitOptionsType>;
58
+ declare class EMPRuntime {
59
+ libs: EMP_ADAPTER_OPTIONS_Type;
60
+ initOptions: InitOptionsType;
61
+ options: EmpRuntimeOptions;
62
+ framework?: FrameworkType;
63
+ private isInit;
64
+ react: ReactAdapter;
65
+ constructor(op?: EMP_ADAPTER_OPTIONS_Type);
66
+ /**
67
+ * 实例化 adapter libs
68
+ * @param EMP_ADAPTER
69
+ */
70
+ setupLibs(o?: EMP_ADAPTER_OPTIONS_Type): void;
71
+ init(options?: EmpInitOptionsType): void;
72
+ load<T = any>(...args: LoadRemoteType): Promise<T>;
73
+ register: typeof MFRuntime.registerRemotes;
74
+ preload: typeof MFRuntime.preloadRemote;
75
+ loadShare: typeof MFRuntime.loadShare;
76
+ }
77
+ declare const _default: EMPRuntime;
78
+
79
+ export { _default as default };
@@ -0,0 +1,188 @@
1
+ // src/helper/config.ts
2
+ var shareGlobalName = "EMP_SHARE_RUNTIME";
3
+
4
+ // src/mfRuntime/helper.ts
5
+ function deepAssign(target, ...sources) {
6
+ for (const source of sources) {
7
+ for (const k in source) {
8
+ const vs = source[k], vt = target[k];
9
+ if (Object(vs) == vs && Object(vt) === vt) {
10
+ target[k] = deepAssign(vt, vs);
11
+ continue;
12
+ }
13
+ target[k] = source[k];
14
+ }
15
+ }
16
+ return target;
17
+ }
18
+ var checkVersion = (version) => version ? Number(version.split(".")[0]) : 0;
19
+ var isPromise = (p) => p && Object.prototype.toString.call(p) === "[object Promise]";
20
+
21
+ // src/mfRuntime/framework/base.ts
22
+ var BaseAdapter = class {
23
+ libs;
24
+ constructor(libs) {
25
+ this.libs = libs;
26
+ }
27
+ get shared() {
28
+ const { React, ReactDOM, scope } = this.libs;
29
+ return {
30
+ react: {
31
+ lib: () => React,
32
+ version: React.version,
33
+ scope,
34
+ shareConfig: {
35
+ singleton: true,
36
+ requiredVersion: `^${React.version}`
37
+ }
38
+ },
39
+ "react-dom": {
40
+ lib: () => ReactDOM,
41
+ version: ReactDOM.version,
42
+ scope,
43
+ shareConfig: {
44
+ singleton: true,
45
+ requiredVersion: `^${React.version}`
46
+ }
47
+ }
48
+ };
49
+ }
50
+ };
51
+
52
+ // src/mfRuntime/framework/react.tsx
53
+ var ReactAdapter = class extends BaseAdapter {
54
+ constructor(libs) {
55
+ super(libs);
56
+ }
57
+ adapter(component, scope = this.libs.scope, React = this.libs.React, ReactDOM = this.libs.ReactDOM) {
58
+ const reactVersion = checkVersion(React.version);
59
+ const self = this;
60
+ class WrappedComponent extends React.Component {
61
+ containerRef;
62
+ root;
63
+ constructor(props) {
64
+ super(props);
65
+ this.containerRef = React.createRef();
66
+ }
67
+ componentDidMount() {
68
+ this.mountOriginalComponent(true);
69
+ }
70
+ componentDidUpdate() {
71
+ this.mountOriginalComponent();
72
+ }
73
+ componentWillUnmount() {
74
+ this.unMountOriginalComponent();
75
+ }
76
+ unMountOriginalComponent() {
77
+ if (!this.containerRef.current) return;
78
+ if (reactVersion < 18) {
79
+ ReactDOM.unmountComponentAtNode(this.containerRef.current);
80
+ } else {
81
+ this.root.unmount();
82
+ }
83
+ }
84
+ async mountOriginalComponent(shouldRender) {
85
+ if (isPromise(component))
86
+ component = await component.then((m) => {
87
+ return m[scope];
88
+ });
89
+ const element = React.createElement(component, this.props);
90
+ if (reactVersion < 18) {
91
+ const Render = shouldRender ? ReactDOM.render : ReactDOM.hydrate;
92
+ Render(element, this.containerRef.current);
93
+ } else {
94
+ if (shouldRender) {
95
+ const { createRoot } = self.libs;
96
+ this.root = createRoot(this.containerRef.current);
97
+ this.root.render(element);
98
+ } else {
99
+ const { hydrateRoot } = self.libs;
100
+ this.root = hydrateRoot(this.containerRef.current, element);
101
+ }
102
+ }
103
+ }
104
+ render() {
105
+ return /* @__PURE__ */ React.createElement("div", { ref: this.containerRef });
106
+ }
107
+ }
108
+ return WrappedComponent;
109
+ }
110
+ };
111
+
112
+ // src/mfRuntime/plugins.ts
113
+ var catchErrorNextPlugin = function(showLog = false) {
114
+ return {
115
+ name: "catch-error-next-plugin",
116
+ errorLoadRemote(o) {
117
+ if (showLog) {
118
+ console.log("[@emp/adapter]", o.id, o.lifecycle, o.from);
119
+ console.error("[@emp/adapter]", o.error);
120
+ }
121
+ return {};
122
+ }
123
+ };
124
+ };
125
+
126
+ // src/mfRuntime/index.ts
127
+ var EMPRuntime = class {
128
+ libs = deepAssign(
129
+ {
130
+ scope: "default"
131
+ },
132
+ window[shareGlobalName] || {}
133
+ );
134
+ initOptions;
135
+ options = {
136
+ showLog: false
137
+ };
138
+ framework;
139
+ isInit = false;
140
+ react;
141
+ constructor(op) {
142
+ if (op) this.setupLibs(op);
143
+ }
144
+ /**
145
+ * 实例化 adapter libs
146
+ * @param EMP_ADAPTER
147
+ */
148
+ setupLibs(o) {
149
+ if (o) {
150
+ this.libs = o;
151
+ }
152
+ if (!this.libs.MFRuntime) {
153
+ throw new Error("EMP FastMode must load MFRuntime!");
154
+ }
155
+ if (!this.libs.MFSDK) {
156
+ throw new Error("EMP FastMode must load MFSDK!");
157
+ }
158
+ if (this.libs.React && this.libs.ReactDOM) {
159
+ this.framework = "react";
160
+ this.react = new ReactAdapter(this.libs);
161
+ }
162
+ }
163
+ init(options = {}) {
164
+ if (this.isInit) return;
165
+ let op = {
166
+ name: "empAdepterProject",
167
+ remotes: [],
168
+ plugins: [catchErrorNextPlugin(this.options.showLog)]
169
+ };
170
+ if (this.framework === "react") {
171
+ op.shared = this.react.shared;
172
+ }
173
+ op = deepAssign(op, options);
174
+ this.libs.MFRuntime.init(op);
175
+ this.isInit = true;
176
+ }
177
+ load(...args) {
178
+ return this.libs.MFRuntime.loadRemote(...args);
179
+ }
180
+ register = this.libs.MFRuntime.registerRemotes;
181
+ preload = this.libs.MFRuntime.preloadRemote;
182
+ loadShare = this.libs.MFRuntime.loadShare;
183
+ };
184
+ var mfRuntime_default = new EMPRuntime();
185
+ export {
186
+ mfRuntime_default as default
187
+ };
188
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../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 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":";AAAO,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,SAAS,KAAK,CAAC,MAAM;;;ACfzE,IAAM,cAAN,MAAkB;AAAA,EACvB;AAAA,EAEA,YAAY,MAAwB;AAClC,SAAK,OAAO;AAAA,EACd;A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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":[]}
package/package.json ADDED
@@ -0,0 +1,82 @@
1
+ {
2
+ "name": "@empjs/share",
3
+ "version": "0.0.1",
4
+ "description": "emp share and runtime",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "files": [
8
+ "dist",
9
+ "adapter"
10
+ ],
11
+ "maintainers": [
12
+ "ckken@qq.com"
13
+ ],
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "git+https://github.com/empjs/emp.git",
17
+ "directory": "packages/emp-share"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "main": "dist/index.js",
23
+ "types": "dist/index.d.ts",
24
+ "exports": {
25
+ ".": {
26
+ "import": {
27
+ "types": "./dist/index.d.ts",
28
+ "default": "./dist/index.js"
29
+ },
30
+ "require": {
31
+ "types": "./dist/index.d.cts",
32
+ "default": "./dist/index.cjs"
33
+ }
34
+ },
35
+ "./runtime": {
36
+ "import": {
37
+ "types": "./dist/runtime.d.ts",
38
+ "default": "./dist/runtime.js"
39
+ },
40
+ "require": {
41
+ "types": "./dist/runtime.d.cts",
42
+ "default": "./dist/runtime.cjs"
43
+ }
44
+ },
45
+ "./rspack": {
46
+ "import": {
47
+ "types": "./dist/rspack.d.ts",
48
+ "default": "./dist/rspack.js"
49
+ },
50
+ "require": {
51
+ "types": "./dist/rspack.d.cts",
52
+ "default": "./dist/rspack.cjs"
53
+ }
54
+ },
55
+ "./library": {
56
+ "types": "./output/index.d.ts",
57
+ "default": "./output/index.js"
58
+ }
59
+ },
60
+ "engines": {
61
+ "node": ">=16.0.0"
62
+ },
63
+ "author": "Ken",
64
+ "dependencies": {
65
+ "@empjs/module-federation-runtime": "0.6.2",
66
+ "@module-federation/enhanced": "0.6.1",
67
+ "@module-federation/runtime": "0.6.1",
68
+ "@module-federation/sdk": "0.6.1",
69
+ "core-js": "^3.37.0"
70
+ },
71
+ "devDependencies": {
72
+ "@rspack/core": "^1.0.4",
73
+ "@swc/core": "^1.4.14",
74
+ "tsup": "^8.2.3",
75
+ "typescript": "^5.5.4",
76
+ "@empjs/cli": "3.1.0-rc.9"
77
+ },
78
+ "scripts": {
79
+ "dev": "tsup --watch",
80
+ "build": "tsup"
81
+ }
82
+ }