@module-federation/modern-js 0.0.0-next-20240515062211

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -0
  3. package/dist/CHANGELOG.md +1 -0
  4. package/dist/LICENSE +21 -0
  5. package/dist/README.md +1 -0
  6. package/dist/cjs/cli/index.js +165 -0
  7. package/dist/cjs/cli/manifest.js +72 -0
  8. package/dist/cjs/cli/mfRuntimePlugins/shared-strategy.js +42 -0
  9. package/dist/cjs/cli/utils.js +62 -0
  10. package/dist/cjs/constant.js +28 -0
  11. package/dist/cjs/runtime/MFReactComponent.js +108 -0
  12. package/dist/cjs/runtime/index.js +31 -0
  13. package/dist/cjs/types/index.js +16 -0
  14. package/dist/esm/cli/index.js +157 -0
  15. package/dist/esm/cli/manifest.js +38 -0
  16. package/dist/esm/cli/mfRuntimePlugins/shared-strategy.js +24 -0
  17. package/dist/esm/cli/utils.js +56 -0
  18. package/dist/esm/constant.js +4 -0
  19. package/dist/esm/runtime/MFReactComponent.js +77 -0
  20. package/dist/esm/runtime/index.js +5 -0
  21. package/dist/esm/types/index.js +0 -0
  22. package/dist/esm-node/cli/index.js +130 -0
  23. package/dist/esm-node/cli/manifest.js +38 -0
  24. package/dist/esm-node/cli/mfRuntimePlugins/shared-strategy.js +22 -0
  25. package/dist/esm-node/cli/utils.js +27 -0
  26. package/dist/esm-node/constant.js +4 -0
  27. package/dist/esm-node/runtime/MFReactComponent.js +74 -0
  28. package/dist/esm-node/runtime/index.js +5 -0
  29. package/dist/esm-node/types/index.js +0 -0
  30. package/dist/types/cli/index.d.ts +5 -0
  31. package/dist/types/cli/manifest.d.ts +2 -0
  32. package/dist/types/cli/mfRuntimePlugins/shared-strategy.d.ts +3 -0
  33. package/dist/types/cli/utils.d.ts +4 -0
  34. package/dist/types/constant.d.ts +1 -0
  35. package/dist/types/runtime/MFReactComponent.d.ts +7 -0
  36. package/dist/types/runtime/index.d.ts +2 -0
  37. package/dist/types/types/index.d.ts +5 -0
  38. package/package.json +56 -0
  39. package/types.d.ts +5 -0
@@ -0,0 +1,74 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import React from "react";
3
+ import { loadRemote, getInstance } from "@module-federation/enhanced/runtime";
4
+ function getLoadedRemoteInfos(instance, id) {
5
+ const moduleName = instance.remoteHandler.idToModuleNameMap[id];
6
+ if (!moduleName) {
7
+ return;
8
+ }
9
+ const module = instance.moduleCache.get(moduleName);
10
+ if (!module) {
11
+ return;
12
+ }
13
+ const { remoteSnapshot } = instance.snapshotHandler.getGlobalRemoteInfo(module.remoteInfo);
14
+ return {
15
+ ...module.remoteInfo,
16
+ snapshot: remoteSnapshot
17
+ };
18
+ }
19
+ function collectLinks(id) {
20
+ const links = [];
21
+ const instance = getInstance();
22
+ if (!instance) {
23
+ return links;
24
+ }
25
+ const loadedRemoteInfo = getLoadedRemoteInfos(instance, id);
26
+ if (!loadedRemoteInfo) {
27
+ return links;
28
+ }
29
+ const snapshot = loadedRemoteInfo.snapshot;
30
+ if (!snapshot) {
31
+ return links;
32
+ }
33
+ const publicPath = "publicPath" in snapshot ? snapshot.publicPath : "getPublicPath" in snapshot ? new Function(snapshot.getPublicPath)() : "";
34
+ if (!publicPath) {
35
+ return links;
36
+ }
37
+ const modules = "modules" in snapshot ? snapshot.modules : [];
38
+ if (modules) {
39
+ modules.forEach((module) => {
40
+ [
41
+ ...module.assets.css.sync,
42
+ ...module.assets.css.async
43
+ ].forEach((file, index) => {
44
+ links.push(/* @__PURE__ */ _jsx("link", {
45
+ href: `${publicPath}${file}`,
46
+ rel: "stylesheet",
47
+ type: "text/css"
48
+ }, index));
49
+ });
50
+ });
51
+ }
52
+ return links;
53
+ }
54
+ function MFReactComponent(props) {
55
+ const { loading = "loading...", id } = props;
56
+ const Component = /* @__PURE__ */ React.lazy(() => loadRemote(id).then((mod) => {
57
+ const links = collectLinks(id);
58
+ return {
59
+ default: () => /* @__PURE__ */ _jsxs("div", {
60
+ children: [
61
+ links,
62
+ /* @__PURE__ */ _jsx(mod.default, {})
63
+ ]
64
+ })
65
+ };
66
+ }));
67
+ return /* @__PURE__ */ _jsx(React.Suspense, {
68
+ fallback: loading,
69
+ children: /* @__PURE__ */ _jsx(Component, {})
70
+ });
71
+ }
72
+ export {
73
+ MFReactComponent
74
+ };
@@ -0,0 +1,5 @@
1
+ export * from "@module-federation/enhanced/runtime";
2
+ import { MFReactComponent } from "./MFReactComponent";
3
+ export {
4
+ MFReactComponent
5
+ };
File without changes
@@ -0,0 +1,5 @@
1
+ import type { CliPlugin, AppTools } from '@modern-js/app-tools';
2
+ import type { PluginOptions } from '../types';
3
+ export declare const moduleFederationPlugin: (userConfig?: PluginOptions) => CliPlugin<AppTools>;
4
+ export default moduleFederationPlugin;
5
+ export { createModuleFederationConfig } from '@module-federation/enhanced';
@@ -0,0 +1,2 @@
1
+ import { ModuleFederationPlugin } from '@module-federation/enhanced';
2
+ export declare function updateStatsAndManifest(nodePlugin: ModuleFederationPlugin, browserPlugin: ModuleFederationPlugin, outputDir: string): void;
@@ -0,0 +1,3 @@
1
+ import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
2
+ declare const sharedStrategy: () => FederationRuntimePlugin;
3
+ export default sharedStrategy;
@@ -0,0 +1,4 @@
1
+ import { moduleFederationPlugin } from '@module-federation/sdk';
2
+ import { PluginOptions } from '../types';
3
+ export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
4
+ export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions) => void;
@@ -0,0 +1 @@
1
+ export declare const MODERN_JS_SERVER_DIR = "bundles";
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ interface IProps {
3
+ id: string;
4
+ loading?: React.ReactNode;
5
+ }
6
+ declare function MFReactComponent(props: IProps): React.JSX.Element;
7
+ export { MFReactComponent };
@@ -0,0 +1,2 @@
1
+ export * from '@module-federation/enhanced/runtime';
2
+ export { MFReactComponent } from './MFReactComponent';
@@ -0,0 +1,5 @@
1
+ import { moduleFederationPlugin } from '@module-federation/sdk';
2
+ export interface PluginOptions {
3
+ config?: moduleFederationPlugin.ModuleFederationPluginOptions;
4
+ configPath?: string;
5
+ }
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@module-federation/modern-js",
3
+ "version": "0.0.0-next-20240515062211",
4
+ "files": [
5
+ "dist/",
6
+ "types.d.ts",
7
+ "README.md"
8
+ ],
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "import": "./dist/esm/cli/index.js",
15
+ "require": "./dist/cjs/cli/index.js",
16
+ "types": "./dist/types/cli/index.d.ts"
17
+ },
18
+ "./runtime": {
19
+ "types": "./dist/types/runtime/index.d.ts",
20
+ "default": "./dist/esm/runtime/index.js"
21
+ }
22
+ },
23
+ "typesVersions": {
24
+ "*": {
25
+ ".": [
26
+ "./dist/types/cli/index.d.ts"
27
+ ],
28
+ "runtime": [
29
+ "./dist/types/runtime/index.d.ts"
30
+ ]
31
+ }
32
+ },
33
+ "main": "./dist/cjs/cli/index.js",
34
+ "types": "./dist/types/cli/index.d.ts",
35
+ "author": "hanric <hanric.zhang@gmail.com>",
36
+ "license": "MIT",
37
+ "dependencies": {
38
+ "@swc/helpers": "0.5.3",
39
+ "@modern-js/utils": "^2.49.2",
40
+ "@modern-js/node-bundle-require": "^2.49.2",
41
+ "@module-federation/sdk": "0.0.0-next-20240515062211",
42
+ "@module-federation/enhanced": "0.0.0-next-20240515062211",
43
+ "@module-federation/node": "0.0.0-next-20240515062211"
44
+ },
45
+ "devDependencies": {
46
+ "@modern-js/app-tools": "^2.49.2",
47
+ "@modern-js/core": "^2.49.2",
48
+ "@modern-js/runtime": "^2.49.2",
49
+ "@modern-js/module-tools": "^2.35.0",
50
+ "@modern-js/tsconfig": "^2.35.0",
51
+ "@module-federation/manifest": "0.0.0-next-20240515062211"
52
+ },
53
+ "scripts": {
54
+ "build": "modern build"
55
+ }
56
+ }
package/types.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import './dist/types/runtime';
2
+
3
+ declare module '@modern-js/runtime/mf' {
4
+ export * from './dist/types/runtime';
5
+ }