@module-federation/modern-js-v3 2.3.1 → 2.3.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/cjs/cli/ssrPlugin.js +4 -4
- package/dist/cjs/server/fileCache.js +12 -14
- package/dist/cjs/server/staticMiddleware.js +10 -3
- package/dist/esm/cli/ssrPlugin.mjs +3 -3
- package/dist/esm/server/fileCache.mjs +39 -4
- package/dist/esm/server/staticMiddleware.mjs +37 -2
- package/dist/esm-node/cli/ssrPlugin.mjs +3 -3
- package/dist/esm-node/server/fileCache.mjs +12 -4
- package/dist/esm-node/server/staticMiddleware.mjs +10 -2
- package/package.json +11 -12
|
@@ -40,8 +40,8 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
40
40
|
});
|
|
41
41
|
const external_path_namespaceObject = require("path");
|
|
42
42
|
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
43
|
-
const
|
|
44
|
-
var
|
|
43
|
+
const external_fs_namespaceObject = require("fs");
|
|
44
|
+
var external_fs_default = /*#__PURE__*/ __webpack_require__.n(external_fs_namespaceObject);
|
|
45
45
|
const rspack_namespaceObject = require("@module-federation/enhanced/rspack");
|
|
46
46
|
const universe_entry_chunk_tracker_plugin_namespaceObject = require("@module-federation/node/universe-entry-chunk-tracker-plugin");
|
|
47
47
|
var universe_entry_chunk_tracker_plugin_default = /*#__PURE__*/ __webpack_require__.n(universe_entry_chunk_tracker_plugin_namespaceObject);
|
|
@@ -237,11 +237,11 @@ const moduleFederationSSRPlugin = (pluginOptions)=>({
|
|
|
237
237
|
var _req_url, _req_url1;
|
|
238
238
|
if ((null == (_req_url = req.url) ? void 0 : _req_url.includes('.json')) && !(null == (_req_url1 = req.url) ? void 0 : _req_url1.includes('hot-update'))) {
|
|
239
239
|
const filepath = external_path_default().join(process.cwd(), `dist${req.url}`);
|
|
240
|
-
|
|
240
|
+
external_fs_default().statSync(filepath);
|
|
241
241
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
242
242
|
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
|
|
243
243
|
res.setHeader('Access-Control-Allow-Headers', '*');
|
|
244
|
-
|
|
244
|
+
external_fs_default().createReadStream(filepath).pipe(res);
|
|
245
245
|
} else next();
|
|
246
246
|
} catch (err) {
|
|
247
247
|
external_logger_js_default().debug(err);
|
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.n = (module)=>{
|
|
5
|
-
var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
|
|
6
|
-
__webpack_require__.d(getter, {
|
|
7
|
-
a: getter
|
|
8
|
-
});
|
|
9
|
-
return getter;
|
|
10
|
-
};
|
|
11
|
-
})();
|
|
12
3
|
(()=>{
|
|
13
4
|
__webpack_require__.d = (exports1, definition)=>{
|
|
14
5
|
for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
@@ -36,21 +27,28 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
36
27
|
FileCache: ()=>FileCache,
|
|
37
28
|
fileCache: ()=>fileCache
|
|
38
29
|
});
|
|
39
|
-
const
|
|
40
|
-
var external_fs_extra_default = /*#__PURE__*/ __webpack_require__.n(external_fs_extra_namespaceObject);
|
|
30
|
+
const promises_namespaceObject = require("fs/promises");
|
|
41
31
|
const external_lru_cache_namespaceObject = require("lru-cache");
|
|
32
|
+
const pathExists = async (filepath)=>{
|
|
33
|
+
try {
|
|
34
|
+
await (0, promises_namespaceObject.access)(filepath);
|
|
35
|
+
return true;
|
|
36
|
+
} catch {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
};
|
|
42
40
|
class FileCache {
|
|
43
41
|
async getFile(filepath) {
|
|
44
|
-
if (!await
|
|
42
|
+
if (!await pathExists(filepath)) return null;
|
|
45
43
|
try {
|
|
46
|
-
const stat = await
|
|
44
|
+
const stat = await (0, promises_namespaceObject.lstat)(filepath);
|
|
47
45
|
const currentModified = stat.mtimeMs;
|
|
48
46
|
const cachedEntry = this.cache.get(filepath);
|
|
49
47
|
if (cachedEntry && currentModified <= cachedEntry.lastModified) return {
|
|
50
48
|
content: cachedEntry.content,
|
|
51
49
|
lastModified: cachedEntry.lastModified
|
|
52
50
|
};
|
|
53
|
-
const content = await
|
|
51
|
+
const content = await (0, promises_namespaceObject.readFile)(filepath, 'utf-8');
|
|
54
52
|
const newEntry = {
|
|
55
53
|
content,
|
|
56
54
|
lastModified: currentModified
|
|
@@ -36,11 +36,18 @@ __webpack_require__.d(__webpack_exports__, {
|
|
|
36
36
|
createStaticMiddleware: ()=>createStaticMiddleware,
|
|
37
37
|
createCorsMiddleware: ()=>createCorsMiddleware
|
|
38
38
|
});
|
|
39
|
-
const
|
|
40
|
-
var external_fs_extra_default = /*#__PURE__*/ __webpack_require__.n(external_fs_extra_namespaceObject);
|
|
39
|
+
const promises_namespaceObject = require("fs/promises");
|
|
41
40
|
const external_path_namespaceObject = require("path");
|
|
42
41
|
var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
|
|
43
42
|
const external_fileCache_js_namespaceObject = require("./fileCache.js");
|
|
43
|
+
const pathExists = async (filepath)=>{
|
|
44
|
+
try {
|
|
45
|
+
await (0, promises_namespaceObject.access)(filepath);
|
|
46
|
+
return true;
|
|
47
|
+
} catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
44
51
|
const bundlesAssetPrefix = '/bundles';
|
|
45
52
|
const removeHost = (url)=>{
|
|
46
53
|
try {
|
|
@@ -62,7 +69,7 @@ const createStaticMiddleware = (options)=>{
|
|
|
62
69
|
if (!pathname.startsWith(prefixWithBundle)) return next();
|
|
63
70
|
const pathnameWithoutPrefix = pathname.replace(prefixWithBundle, '');
|
|
64
71
|
const filepath = external_path_default().join(pwd, bundlesAssetPrefix, pathnameWithoutPrefix);
|
|
65
|
-
if (!await
|
|
72
|
+
if (!await pathExists(filepath)) return next();
|
|
66
73
|
const fileResult = await external_fileCache_js_namespaceObject.fileCache.getFile(filepath);
|
|
67
74
|
if (!fileResult) return next();
|
|
68
75
|
c.header('Content-Type', "application/javascript");
|
|
@@ -3,7 +3,7 @@ import { _ as _instanceof__ } from "@swc/helpers/_/_instanceof";
|
|
|
3
3
|
import { _ as _type_of__ } from "@swc/helpers/_/_type_of";
|
|
4
4
|
import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
|
|
5
5
|
import path from "path";
|
|
6
|
-
import
|
|
6
|
+
import fs from "fs";
|
|
7
7
|
import { ModuleFederationPlugin, TreeShakingSharedPlugin } from "@module-federation/enhanced/rspack";
|
|
8
8
|
import universe_entry_chunk_tracker_plugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
|
|
9
9
|
import logger from "../logger.mjs";
|
|
@@ -213,11 +213,11 @@ var ssrPlugin_moduleFederationSSRPlugin = function(pluginOptions) {
|
|
|
213
213
|
var _req_url, _req_url1;
|
|
214
214
|
if ((null == (_req_url = req.url) ? void 0 : _req_url.includes('.json')) && !(null == (_req_url1 = req.url) ? void 0 : _req_url1.includes('hot-update'))) {
|
|
215
215
|
var filepath = path.join(process.cwd(), "dist".concat(req.url));
|
|
216
|
-
|
|
216
|
+
fs.statSync(filepath);
|
|
217
217
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
218
218
|
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
|
|
219
219
|
res.setHeader('Access-Control-Allow-Headers', '*');
|
|
220
|
-
|
|
220
|
+
fs.createReadStream(filepath).pipe(res);
|
|
221
221
|
} else next();
|
|
222
222
|
} catch (err) {
|
|
223
223
|
logger.debug(err);
|
|
@@ -1,8 +1,43 @@
|
|
|
1
1
|
import { _ } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _class_call_check__ } from "@swc/helpers/_/_class_call_check";
|
|
3
3
|
import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
|
|
4
|
-
import
|
|
4
|
+
import { access, lstat, readFile } from "fs/promises";
|
|
5
5
|
import { LRUCache } from "lru-cache";
|
|
6
|
+
var fileCache_pathExists = function(filepath) {
|
|
7
|
+
return _(function() {
|
|
8
|
+
return _ts_generator__(this, function(_state) {
|
|
9
|
+
switch(_state.label){
|
|
10
|
+
case 0:
|
|
11
|
+
_state.trys.push([
|
|
12
|
+
0,
|
|
13
|
+
2,
|
|
14
|
+
,
|
|
15
|
+
3
|
|
16
|
+
]);
|
|
17
|
+
return [
|
|
18
|
+
4,
|
|
19
|
+
access(filepath)
|
|
20
|
+
];
|
|
21
|
+
case 1:
|
|
22
|
+
_state.sent();
|
|
23
|
+
return [
|
|
24
|
+
2,
|
|
25
|
+
true
|
|
26
|
+
];
|
|
27
|
+
case 2:
|
|
28
|
+
_state.sent();
|
|
29
|
+
return [
|
|
30
|
+
2,
|
|
31
|
+
false
|
|
32
|
+
];
|
|
33
|
+
case 3:
|
|
34
|
+
return [
|
|
35
|
+
2
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
})();
|
|
40
|
+
};
|
|
6
41
|
var fileCache_FileCache = /*#__PURE__*/ function() {
|
|
7
42
|
"use strict";
|
|
8
43
|
function FileCache() {
|
|
@@ -20,7 +55,7 @@ var fileCache_FileCache = /*#__PURE__*/ function() {
|
|
|
20
55
|
case 0:
|
|
21
56
|
return [
|
|
22
57
|
4,
|
|
23
|
-
|
|
58
|
+
fileCache_pathExists(filepath)
|
|
24
59
|
];
|
|
25
60
|
case 1:
|
|
26
61
|
if (!_state.sent()) return [
|
|
@@ -37,7 +72,7 @@ var fileCache_FileCache = /*#__PURE__*/ function() {
|
|
|
37
72
|
]);
|
|
38
73
|
return [
|
|
39
74
|
4,
|
|
40
|
-
|
|
75
|
+
lstat(filepath)
|
|
41
76
|
];
|
|
42
77
|
case 3:
|
|
43
78
|
stat = _state.sent();
|
|
@@ -52,7 +87,7 @@ var fileCache_FileCache = /*#__PURE__*/ function() {
|
|
|
52
87
|
];
|
|
53
88
|
return [
|
|
54
89
|
4,
|
|
55
|
-
|
|
90
|
+
readFile(filepath, 'utf-8')
|
|
56
91
|
];
|
|
57
92
|
case 4:
|
|
58
93
|
content = _state.sent();
|
|
@@ -1,8 +1,43 @@
|
|
|
1
1
|
import { _ } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _ts_generator__ } from "@swc/helpers/_/_ts_generator";
|
|
3
|
-
import
|
|
3
|
+
import { access } from "fs/promises";
|
|
4
4
|
import path from "path";
|
|
5
5
|
import { fileCache } from "./fileCache.mjs";
|
|
6
|
+
var staticMiddleware_pathExists = function(filepath) {
|
|
7
|
+
return _(function() {
|
|
8
|
+
return _ts_generator__(this, function(_state) {
|
|
9
|
+
switch(_state.label){
|
|
10
|
+
case 0:
|
|
11
|
+
_state.trys.push([
|
|
12
|
+
0,
|
|
13
|
+
2,
|
|
14
|
+
,
|
|
15
|
+
3
|
|
16
|
+
]);
|
|
17
|
+
return [
|
|
18
|
+
4,
|
|
19
|
+
access(filepath)
|
|
20
|
+
];
|
|
21
|
+
case 1:
|
|
22
|
+
_state.sent();
|
|
23
|
+
return [
|
|
24
|
+
2,
|
|
25
|
+
true
|
|
26
|
+
];
|
|
27
|
+
case 2:
|
|
28
|
+
_state.sent();
|
|
29
|
+
return [
|
|
30
|
+
2,
|
|
31
|
+
false
|
|
32
|
+
];
|
|
33
|
+
case 3:
|
|
34
|
+
return [
|
|
35
|
+
2
|
|
36
|
+
];
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
})();
|
|
40
|
+
};
|
|
6
41
|
var bundlesAssetPrefix = '/bundles';
|
|
7
42
|
var staticMiddleware_removeHost = function(url) {
|
|
8
43
|
try {
|
|
@@ -37,7 +72,7 @@ var staticMiddleware_createStaticMiddleware = function(options) {
|
|
|
37
72
|
filepath = path.join(pwd, bundlesAssetPrefix, pathnameWithoutPrefix);
|
|
38
73
|
return [
|
|
39
74
|
4,
|
|
40
|
-
|
|
75
|
+
staticMiddleware_pathExists(filepath)
|
|
41
76
|
];
|
|
42
77
|
case 1:
|
|
43
78
|
if (!_state.sent()) return [
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import
|
|
2
|
+
import fs from "fs";
|
|
3
3
|
import { ModuleFederationPlugin, TreeShakingSharedPlugin } from "@module-federation/enhanced/rspack";
|
|
4
4
|
import universe_entry_chunk_tracker_plugin from "@module-federation/node/universe-entry-chunk-tracker-plugin";
|
|
5
5
|
import logger from "../logger.mjs";
|
|
@@ -193,11 +193,11 @@ const moduleFederationSSRPlugin = (pluginOptions)=>({
|
|
|
193
193
|
var _req_url, _req_url1;
|
|
194
194
|
if ((null == (_req_url = req.url) ? void 0 : _req_url.includes('.json')) && !(null == (_req_url1 = req.url) ? void 0 : _req_url1.includes('hot-update'))) {
|
|
195
195
|
const filepath = path.join(process.cwd(), `dist${req.url}`);
|
|
196
|
-
|
|
196
|
+
fs.statSync(filepath);
|
|
197
197
|
res.setHeader('Access-Control-Allow-Origin', '*');
|
|
198
198
|
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, PATCH, OPTIONS');
|
|
199
199
|
res.setHeader('Access-Control-Allow-Headers', '*');
|
|
200
|
-
|
|
200
|
+
fs.createReadStream(filepath).pipe(res);
|
|
201
201
|
} else next();
|
|
202
202
|
} catch (err) {
|
|
203
203
|
logger.debug(err);
|
|
@@ -1,17 +1,25 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { access, lstat, readFile } from "fs/promises";
|
|
2
2
|
import { LRUCache } from "lru-cache";
|
|
3
|
+
const pathExists = async (filepath)=>{
|
|
4
|
+
try {
|
|
5
|
+
await access(filepath);
|
|
6
|
+
return true;
|
|
7
|
+
} catch {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
3
11
|
class FileCache {
|
|
4
12
|
async getFile(filepath) {
|
|
5
|
-
if (!await
|
|
13
|
+
if (!await pathExists(filepath)) return null;
|
|
6
14
|
try {
|
|
7
|
-
const stat = await
|
|
15
|
+
const stat = await lstat(filepath);
|
|
8
16
|
const currentModified = stat.mtimeMs;
|
|
9
17
|
const cachedEntry = this.cache.get(filepath);
|
|
10
18
|
if (cachedEntry && currentModified <= cachedEntry.lastModified) return {
|
|
11
19
|
content: cachedEntry.content,
|
|
12
20
|
lastModified: cachedEntry.lastModified
|
|
13
21
|
};
|
|
14
|
-
const content = await
|
|
22
|
+
const content = await readFile(filepath, 'utf-8');
|
|
15
23
|
const newEntry = {
|
|
16
24
|
content,
|
|
17
25
|
lastModified: currentModified
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { access } from "fs/promises";
|
|
2
2
|
import path from "path";
|
|
3
3
|
import { fileCache } from "./fileCache.mjs";
|
|
4
|
+
const pathExists = async (filepath)=>{
|
|
5
|
+
try {
|
|
6
|
+
await access(filepath);
|
|
7
|
+
return true;
|
|
8
|
+
} catch {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
4
12
|
const bundlesAssetPrefix = '/bundles';
|
|
5
13
|
const removeHost = (url)=>{
|
|
6
14
|
try {
|
|
@@ -22,7 +30,7 @@ const createStaticMiddleware = (options)=>{
|
|
|
22
30
|
if (!pathname.startsWith(prefixWithBundle)) return next();
|
|
23
31
|
const pathnameWithoutPrefix = pathname.replace(prefixWithBundle, '');
|
|
24
32
|
const filepath = path.join(pwd, bundlesAssetPrefix, pathnameWithoutPrefix);
|
|
25
|
-
if (!await
|
|
33
|
+
if (!await pathExists(filepath)) return next();
|
|
26
34
|
const fileResult = await fileCache.getFile(filepath);
|
|
27
35
|
if (!fileResult) return next();
|
|
28
36
|
c.header('Content-Type', "application/javascript");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/modern-js-v3",
|
|
3
|
-
"version": "2.3.
|
|
3
|
+
"version": "2.3.2",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist/",
|
|
6
6
|
"types.d.ts",
|
|
@@ -125,19 +125,18 @@
|
|
|
125
125
|
"author": "hanric <hanric.zhang@gmail.com>",
|
|
126
126
|
"license": "MIT",
|
|
127
127
|
"dependencies": {
|
|
128
|
-
"fs-extra": "11.3.0",
|
|
129
128
|
"lru-cache": "10.4.3",
|
|
130
|
-
"@swc/helpers": "
|
|
131
|
-
"node-fetch": "
|
|
129
|
+
"@swc/helpers": "0.5.17",
|
|
130
|
+
"node-fetch": "3.3.0",
|
|
132
131
|
"jiti": "2.4.2",
|
|
133
132
|
"react-error-boundary": "4.1.2",
|
|
134
|
-
"@module-federation/rsbuild-plugin": "2.3.
|
|
135
|
-
"@module-federation/
|
|
136
|
-
"@module-federation/
|
|
137
|
-
"@module-federation/
|
|
138
|
-
"@module-federation/
|
|
139
|
-
"@module-federation/
|
|
140
|
-
"@module-federation/
|
|
133
|
+
"@module-federation/rsbuild-plugin": "2.3.2",
|
|
134
|
+
"@module-federation/enhanced": "2.3.2",
|
|
135
|
+
"@module-federation/node": "2.7.40",
|
|
136
|
+
"@module-federation/sdk": "2.3.2",
|
|
137
|
+
"@module-federation/bridge-react": "2.3.2",
|
|
138
|
+
"@module-federation/runtime": "2.3.2",
|
|
139
|
+
"@module-federation/cli": "2.3.2"
|
|
141
140
|
},
|
|
142
141
|
"devDependencies": {
|
|
143
142
|
"@rsbuild/plugin-react": "1.4.5",
|
|
@@ -153,7 +152,7 @@
|
|
|
153
152
|
"react": "~18.3.1",
|
|
154
153
|
"react-dom": "~18.3.1",
|
|
155
154
|
"vitest": "1.6.0",
|
|
156
|
-
"@module-federation/manifest": "2.3.
|
|
155
|
+
"@module-federation/manifest": "2.3.2"
|
|
157
156
|
},
|
|
158
157
|
"peerDependencies": {
|
|
159
158
|
"react": ">=17",
|