@module-federation/modern-js 0.0.0-next-20250526035905 → 0.0.0-next-20250526062606

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.
@@ -84,8 +84,8 @@ function getTargetModuleInfo(id) {
84
84
  remoteEntry
85
85
  };
86
86
  }
87
- async function collectSSRAssets(options) {
88
- const { id, injectLink = true, injectScript = true, inlineCSS = false } = typeof options === "string" ? {
87
+ function collectSSRAssets(options) {
88
+ const { id, injectLink = true, injectScript = true } = typeof options === "string" ? {
89
89
  id: options
90
90
  } : options;
91
91
  const links = [];
@@ -106,25 +106,16 @@ async function collectSSRAssets(options) {
106
106
  }
107
107
  const { module: targetModule, publicPath, remoteEntry } = moduleAndPublicPath;
108
108
  if (injectLink) {
109
- await Promise.all([
109
+ [
110
110
  ...targetModule.assets.css.sync,
111
111
  ...targetModule.assets.css.async
112
- ].map(async (file, index) => {
113
- const href = `${publicPath}${file}`;
114
- const key = `${file.split(".")[0]}_${index}`;
115
- if (inlineCSS) {
116
- const content = await fetch(href).then((res) => res.text());
117
- links.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", {
118
- children: content
119
- }, key));
120
- return;
121
- }
112
+ ].forEach((file, index) => {
122
113
  links.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("link", {
123
114
  href: `${publicPath}${file}`,
124
115
  rel: "stylesheet",
125
116
  type: "text/css"
126
- }, key));
127
- }));
117
+ }, `${file.split(".")[0]}_${index}`));
118
+ });
128
119
  }
129
120
  if (injectScript) {
130
121
  scripts.push(/* @__PURE__ */ (0, import_jsx_runtime.jsx)("script", {
@@ -156,7 +147,7 @@ function createRemoteSSRComponent(info) {
156
147
  throw new Error("load remote failed");
157
148
  }
158
149
  const moduleId = m && m[Symbol.for("mf_module_id")];
159
- const assets = await collectSSRAssets({
150
+ const assets = collectSSRAssets({
160
151
  id: moduleId
161
152
  });
162
153
  const Com = m[exportName];
@@ -58,111 +58,44 @@ function getTargetModuleInfo(id) {
58
58
  };
59
59
  }
60
60
  function collectSSRAssets(options) {
61
- return _collectSSRAssets.apply(this, arguments);
62
- }
63
- function _collectSSRAssets() {
64
- _collectSSRAssets = _async_to_generator(function(options) {
65
- var _ref, id, _ref_injectLink, injectLink, _ref_injectScript, injectScript, _ref_inlineCSS, inlineCSS, links, scripts, instance, moduleAndPublicPath, targetModule, publicPath, remoteEntry;
66
- return _ts_generator(this, function(_state) {
67
- switch (_state.label) {
68
- case 0:
69
- _ref = typeof options === "string" ? {
70
- id: options
71
- } : options, id = _ref.id, _ref_injectLink = _ref.injectLink, injectLink = _ref_injectLink === void 0 ? true : _ref_injectLink, _ref_injectScript = _ref.injectScript, injectScript = _ref_injectScript === void 0 ? true : _ref_injectScript, _ref_inlineCSS = _ref.inlineCSS, inlineCSS = _ref_inlineCSS === void 0 ? false : _ref_inlineCSS;
72
- links = [];
73
- scripts = [];
74
- instance = getInstance();
75
- if (!instance || !injectLink && !injectScript) {
76
- return [
77
- 2,
78
- _to_consumable_array(scripts).concat(_to_consumable_array(links))
79
- ];
80
- }
81
- moduleAndPublicPath = getTargetModuleInfo(id);
82
- if (!moduleAndPublicPath) {
83
- return [
84
- 2,
85
- _to_consumable_array(scripts).concat(_to_consumable_array(links))
86
- ];
87
- }
88
- targetModule = moduleAndPublicPath.module, publicPath = moduleAndPublicPath.publicPath, remoteEntry = moduleAndPublicPath.remoteEntry;
89
- if (!injectLink)
90
- return [
91
- 3,
92
- 2
93
- ];
94
- return [
95
- 4,
96
- Promise.all(_to_consumable_array(targetModule.assets.css.sync).concat(_to_consumable_array(targetModule.assets.css.async)).map(function() {
97
- var _ref2 = _async_to_generator(function(file, index) {
98
- var href, key, content;
99
- return _ts_generator(this, function(_state2) {
100
- switch (_state2.label) {
101
- case 0:
102
- href = "".concat(publicPath).concat(file);
103
- key = "".concat(file.split(".")[0], "_").concat(index);
104
- if (!inlineCSS)
105
- return [
106
- 3,
107
- 2
108
- ];
109
- return [
110
- 4,
111
- fetch(href).then(function(res) {
112
- return res.text();
113
- })
114
- ];
115
- case 1:
116
- content = _state2.sent();
117
- links.push(/* @__PURE__ */ _jsx("style", {
118
- children: content
119
- }, key));
120
- return [
121
- 2
122
- ];
123
- case 2:
124
- links.push(/* @__PURE__ */ _jsx("link", {
125
- href: "".concat(publicPath).concat(file),
126
- rel: "stylesheet",
127
- type: "text/css"
128
- }, key));
129
- return [
130
- 2
131
- ];
132
- }
133
- });
134
- });
135
- return function(file, index) {
136
- return _ref2.apply(this, arguments);
137
- };
138
- }()))
139
- ];
140
- case 1:
141
- _state.sent();
142
- _state.label = 2;
143
- case 2:
144
- if (injectScript) {
145
- scripts.push(/* @__PURE__ */ _jsx("script", {
146
- async: true,
147
- src: "".concat(publicPath).concat(remoteEntry),
148
- crossOrigin: "anonymous"
149
- }, remoteEntry.split(".")[0]));
150
- _to_consumable_array(targetModule.assets.js.sync).forEach(function(file, index) {
151
- scripts.push(/* @__PURE__ */ _jsx("script", {
152
- async: true,
153
- src: "".concat(publicPath).concat(file),
154
- crossOrigin: "anonymous"
155
- }, "".concat(file.split(".")[0], "_").concat(index)));
156
- });
157
- }
158
- return [
159
- 2,
160
- _to_consumable_array(scripts).concat(_to_consumable_array(links))
161
- ];
162
- }
61
+ var _ref = typeof options === "string" ? {
62
+ id: options
63
+ } : options, id = _ref.id, _ref_injectLink = _ref.injectLink, injectLink = _ref_injectLink === void 0 ? true : _ref_injectLink, _ref_injectScript = _ref.injectScript, injectScript = _ref_injectScript === void 0 ? true : _ref_injectScript;
64
+ var links = [];
65
+ var scripts = [];
66
+ var instance = getInstance();
67
+ if (!instance || !injectLink && !injectScript) {
68
+ return _to_consumable_array(scripts).concat(_to_consumable_array(links));
69
+ }
70
+ var moduleAndPublicPath = getTargetModuleInfo(id);
71
+ if (!moduleAndPublicPath) {
72
+ return _to_consumable_array(scripts).concat(_to_consumable_array(links));
73
+ }
74
+ var targetModule = moduleAndPublicPath.module, publicPath = moduleAndPublicPath.publicPath, remoteEntry = moduleAndPublicPath.remoteEntry;
75
+ if (injectLink) {
76
+ _to_consumable_array(targetModule.assets.css.sync).concat(_to_consumable_array(targetModule.assets.css.async)).forEach(function(file, index) {
77
+ links.push(/* @__PURE__ */ _jsx("link", {
78
+ href: "".concat(publicPath).concat(file),
79
+ rel: "stylesheet",
80
+ type: "text/css"
81
+ }, "".concat(file.split(".")[0], "_").concat(index)));
163
82
  });
164
- });
165
- return _collectSSRAssets.apply(this, arguments);
83
+ }
84
+ if (injectScript) {
85
+ scripts.push(/* @__PURE__ */ _jsx("script", {
86
+ async: true,
87
+ src: "".concat(publicPath).concat(remoteEntry),
88
+ crossOrigin: "anonymous"
89
+ }, remoteEntry.split(".")[0]));
90
+ _to_consumable_array(targetModule.assets.js.sync).forEach(function(file, index) {
91
+ scripts.push(/* @__PURE__ */ _jsx("script", {
92
+ async: true,
93
+ src: "".concat(publicPath).concat(file),
94
+ crossOrigin: "anonymous"
95
+ }, "".concat(file.split(".")[0], "_").concat(index)));
96
+ });
97
+ }
98
+ return _to_consumable_array(scripts).concat(_to_consumable_array(links));
166
99
  }
167
100
  function createRemoteSSRComponent(info) {
168
101
  var exportName = (info === null || info === void 0 ? void 0 : info.export) || "default";
@@ -173,9 +106,9 @@ function createRemoteSSRComponent(info) {
173
106
  case 0:
174
107
  _state.trys.push([
175
108
  0,
176
- 3,
109
+ 2,
177
110
  ,
178
- 4
111
+ 3
179
112
  ]);
180
113
  return [
181
114
  4,
@@ -187,14 +120,9 @@ function createRemoteSSRComponent(info) {
187
120
  throw new Error("load remote failed");
188
121
  }
189
122
  moduleId = m && m[Symbol.for("mf_module_id")];
190
- return [
191
- 4,
192
- collectSSRAssets({
193
- id: moduleId
194
- })
195
- ];
196
- case 2:
197
- assets = _state.sent();
123
+ assets = collectSSRAssets({
124
+ id: moduleId
125
+ });
198
126
  Com = m[exportName];
199
127
  if (exportName in m && typeof Com === "function") {
200
128
  return [
@@ -215,9 +143,9 @@ function createRemoteSSRComponent(info) {
215
143
  }
216
144
  return [
217
145
  3,
218
- 4
146
+ 3
219
147
  ];
220
- case 3:
148
+ case 2:
221
149
  err = _state.sent();
222
150
  if (!info.fallback) {
223
151
  throw err;
@@ -237,7 +165,7 @@ function createRemoteSSRComponent(info) {
237
165
  }
238
166
  }
239
167
  ];
240
- case 4:
168
+ case 3:
241
169
  return [
242
170
  2
243
171
  ];
@@ -50,8 +50,8 @@ function getTargetModuleInfo(id) {
50
50
  remoteEntry
51
51
  };
52
52
  }
53
- async function collectSSRAssets(options) {
54
- const { id, injectLink = true, injectScript = true, inlineCSS = false } = typeof options === "string" ? {
53
+ function collectSSRAssets(options) {
54
+ const { id, injectLink = true, injectScript = true } = typeof options === "string" ? {
55
55
  id: options
56
56
  } : options;
57
57
  const links = [];
@@ -72,25 +72,16 @@ async function collectSSRAssets(options) {
72
72
  }
73
73
  const { module: targetModule, publicPath, remoteEntry } = moduleAndPublicPath;
74
74
  if (injectLink) {
75
- await Promise.all([
75
+ [
76
76
  ...targetModule.assets.css.sync,
77
77
  ...targetModule.assets.css.async
78
- ].map(async (file, index) => {
79
- const href = `${publicPath}${file}`;
80
- const key = `${file.split(".")[0]}_${index}`;
81
- if (inlineCSS) {
82
- const content = await fetch(href).then((res) => res.text());
83
- links.push(/* @__PURE__ */ _jsx("style", {
84
- children: content
85
- }, key));
86
- return;
87
- }
78
+ ].forEach((file, index) => {
88
79
  links.push(/* @__PURE__ */ _jsx("link", {
89
80
  href: `${publicPath}${file}`,
90
81
  rel: "stylesheet",
91
82
  type: "text/css"
92
- }, key));
93
- }));
83
+ }, `${file.split(".")[0]}_${index}`));
84
+ });
94
85
  }
95
86
  if (injectScript) {
96
87
  scripts.push(/* @__PURE__ */ _jsx("script", {
@@ -122,7 +113,7 @@ function createRemoteSSRComponent(info) {
122
113
  throw new Error("load remote failed");
123
114
  }
124
115
  const moduleId = m && m[Symbol.for("mf_module_id")];
125
- const assets = await collectSSRAssets({
116
+ const assets = collectSSRAssets({
126
117
  id: moduleId
127
118
  });
128
119
  const Com = m[exportName];
@@ -4,12 +4,11 @@ type IProps = {
4
4
  id: string;
5
5
  injectScript?: boolean;
6
6
  injectLink?: boolean;
7
- inlineCSS?: boolean;
8
7
  };
9
8
  type ReactKey = {
10
9
  key?: React.Key | null;
11
10
  };
12
- export declare function collectSSRAssets(options: IProps): Promise<React.ReactNode[]>;
11
+ export declare function collectSSRAssets(options: IProps): React.ReactNode[];
13
12
  export declare function createRemoteSSRComponent<T, E extends keyof T>(info: {
14
13
  loader: () => Promise<T>;
15
14
  loading: React.ReactNode;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/modern-js",
3
- "version": "0.0.0-next-20250526035905",
3
+ "version": "0.0.0-next-20250526062606",
4
4
  "files": [
5
5
  "dist/",
6
6
  "types.d.ts",
@@ -89,11 +89,11 @@
89
89
  "@swc/helpers": "0.5.13",
90
90
  "node-fetch": "~3.3.0",
91
91
  "react-error-boundary": "4.1.2",
92
- "@module-federation/rsbuild-plugin": "0.0.0-next-20250526035905",
93
- "@module-federation/enhanced": "0.0.0-next-20250526035905",
94
- "@module-federation/node": "0.0.0-next-20250526035905",
95
- "@module-federation/sdk": "0.0.0-next-20250526035905",
96
- "@module-federation/cli": "0.0.0-next-20250526035905"
92
+ "@module-federation/rsbuild-plugin": "0.0.0-next-20250526062606",
93
+ "@module-federation/enhanced": "0.0.0-next-20250526062606",
94
+ "@module-federation/node": "0.0.0-next-20250526062606",
95
+ "@module-federation/sdk": "0.0.0-next-20250526062606",
96
+ "@module-federation/cli": "0.0.0-next-20250526062606"
97
97
  },
98
98
  "devDependencies": {
99
99
  "@rsbuild/core": "1.2.8",
@@ -102,7 +102,7 @@
102
102
  "@modern-js/module-tools": "2.65.1",
103
103
  "@modern-js/runtime": "2.65.1",
104
104
  "@modern-js/tsconfig": "2.65.1",
105
- "@module-federation/manifest": "0.0.0-next-20250526035905"
105
+ "@module-federation/manifest": "0.0.0-next-20250526062606"
106
106
  },
107
107
  "peerDependencies": {
108
108
  "react": ">=17",