@modern-js/plugin-ssg 2.63.5 → 2.63.7
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/libs/util.js +9 -0
- package/dist/cjs/server/process.js +13 -9
- package/dist/esm/libs/util.js +8 -0
- package/dist/esm/server/process.js +128 -14
- package/dist/esm-node/libs/util.js +8 -0
- package/dist/esm-node/server/process.js +13 -9
- package/dist/types/libs/util.d.ts +1 -0
- package/package.json +7 -7
package/dist/cjs/libs/util.js
CHANGED
|
@@ -28,6 +28,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var util_exports = {};
|
|
30
30
|
__export(util_exports, {
|
|
31
|
+
chunkArray: () => chunkArray,
|
|
31
32
|
flattenRoutes: () => flattenRoutes,
|
|
32
33
|
formatOutput: () => formatOutput,
|
|
33
34
|
formatPath: () => formatPath,
|
|
@@ -181,8 +182,16 @@ const flattenRoutes = (routes) => {
|
|
|
181
182
|
routes.forEach(traverseRoute);
|
|
182
183
|
return newRoutes;
|
|
183
184
|
};
|
|
185
|
+
function chunkArray(arr, size) {
|
|
186
|
+
const result = [];
|
|
187
|
+
for (let i = 0; i < arr.length; i += size) {
|
|
188
|
+
result.push(arr.slice(i, i + size));
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
191
|
+
}
|
|
184
192
|
// Annotate the CommonJS export names for ESM import in node:
|
|
185
193
|
0 && (module.exports = {
|
|
194
|
+
chunkArray,
|
|
186
195
|
flattenRoutes,
|
|
187
196
|
formatOutput,
|
|
188
197
|
formatPath,
|
|
@@ -21,10 +21,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
21
21
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
22
|
mod
|
|
23
23
|
));
|
|
24
|
+
var import_assert = __toESM(require("assert"));
|
|
24
25
|
var import_http = require("http");
|
|
25
26
|
var import_prod_server = require("@modern-js/prod-server");
|
|
26
27
|
var import_portfinder = __toESM(require("portfinder"));
|
|
28
|
+
var import_util = require("../libs/util");
|
|
27
29
|
var import_consts = require("./consts");
|
|
30
|
+
const MAX_CONCURRENT_REQUESTS = 10;
|
|
28
31
|
process.on("message", async (chunk) => {
|
|
29
32
|
if (chunk === import_consts.CLOSE_SIGN) {
|
|
30
33
|
process.exit();
|
|
@@ -45,19 +48,20 @@ process.on("message", async (chunk) => {
|
|
|
45
48
|
plugins: await (0, import_prod_server.loadServerPlugins)(plugins, appContext.appDirectory || distDirectory),
|
|
46
49
|
staticGenerate: true
|
|
47
50
|
};
|
|
51
|
+
(0, import_assert.default)(process.send, "process.send is not available");
|
|
52
|
+
const sendProcessMessage = process.send.bind(process);
|
|
48
53
|
nodeServer = await (0, import_prod_server.createProdServer)(serverOptions);
|
|
49
54
|
nodeServer.listen(port, async () => {
|
|
50
|
-
if (!nodeServer)
|
|
55
|
+
if (!nodeServer)
|
|
51
56
|
return;
|
|
57
|
+
const chunkedRoutes = (0, import_util.chunkArray)(renderRoutes, MAX_CONCURRENT_REQUESTS);
|
|
58
|
+
for (const routes2 of chunkedRoutes) {
|
|
59
|
+
const promises = routes2.map(async (route) => getHtml(`http://localhost:${port}${route.urlPath}`, port));
|
|
60
|
+
for (const result of await Promise.all(promises)) {
|
|
61
|
+
sendProcessMessage(result);
|
|
62
|
+
sendProcessMessage(null);
|
|
63
|
+
}
|
|
52
64
|
}
|
|
53
|
-
const htmlAry = await Promise.all(renderRoutes.map((route) => {
|
|
54
|
-
const url = `http://localhost:${port}${route.urlPath}`;
|
|
55
|
-
return getHtml(url, port);
|
|
56
|
-
}));
|
|
57
|
-
htmlAry.forEach((html) => {
|
|
58
|
-
process.send(html);
|
|
59
|
-
process.send(null);
|
|
60
|
-
});
|
|
61
65
|
nodeServer.close();
|
|
62
66
|
});
|
|
63
67
|
} catch (e) {
|
package/dist/esm/libs/util.js
CHANGED
|
@@ -187,7 +187,15 @@ var flattenRoutes = function(routes) {
|
|
|
187
187
|
routes.forEach(traverseRoute);
|
|
188
188
|
return newRoutes;
|
|
189
189
|
};
|
|
190
|
+
function chunkArray(arr, size) {
|
|
191
|
+
var result = [];
|
|
192
|
+
for (var i = 0; i < arr.length; i += size) {
|
|
193
|
+
result.push(arr.slice(i, i + size));
|
|
194
|
+
}
|
|
195
|
+
return result;
|
|
196
|
+
}
|
|
190
197
|
export {
|
|
198
|
+
chunkArray,
|
|
191
199
|
flattenRoutes,
|
|
192
200
|
formatOutput,
|
|
193
201
|
formatPath,
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
|
|
3
3
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
|
4
|
+
import assert from "assert";
|
|
4
5
|
import { request } from "http";
|
|
5
6
|
import { createProdServer, loadServerPlugins } from "@modern-js/prod-server";
|
|
6
7
|
import portfinder from "portfinder";
|
|
8
|
+
import { chunkArray } from "../libs/util";
|
|
7
9
|
import { CLOSE_SIGN } from "./consts";
|
|
10
|
+
var MAX_CONCURRENT_REQUESTS = 10;
|
|
8
11
|
process.on("message", function() {
|
|
9
12
|
var _ref = _async_to_generator(function(chunk) {
|
|
10
|
-
var context, routes, renderRoutes, options, appContext, plugins, distDirectory, nodeServer, serverConfig, defaultPort, port, serverOptions, _tmp, e;
|
|
13
|
+
var context, routes, renderRoutes, options, appContext, plugins, distDirectory, nodeServer, serverConfig, defaultPort, port, serverOptions, _tmp, sendProcessMessage, e;
|
|
11
14
|
return _ts_generator(this, function(_state) {
|
|
12
15
|
switch (_state.label) {
|
|
13
16
|
case 0:
|
|
@@ -46,6 +49,8 @@ process.on("message", function() {
|
|
|
46
49
|
];
|
|
47
50
|
case 3:
|
|
48
51
|
serverOptions = (_tmp.plugins = _state.sent(), _tmp.staticGenerate = true, _tmp);
|
|
52
|
+
assert(process.send, "process.send is not available");
|
|
53
|
+
sendProcessMessage = process.send.bind(process);
|
|
49
54
|
return [
|
|
50
55
|
4,
|
|
51
56
|
createProdServer(serverOptions)
|
|
@@ -53,28 +58,137 @@ process.on("message", function() {
|
|
|
53
58
|
case 4:
|
|
54
59
|
nodeServer = _state.sent();
|
|
55
60
|
nodeServer.listen(port, /* @__PURE__ */ _async_to_generator(function() {
|
|
56
|
-
var
|
|
61
|
+
var chunkedRoutes, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, routes2, promises, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, result, err, err;
|
|
57
62
|
return _ts_generator(this, function(_state2) {
|
|
58
63
|
switch (_state2.label) {
|
|
59
64
|
case 0:
|
|
60
|
-
if (!nodeServer)
|
|
65
|
+
if (!nodeServer)
|
|
61
66
|
return [
|
|
62
67
|
2
|
|
63
68
|
];
|
|
64
|
-
|
|
69
|
+
chunkedRoutes = chunkArray(renderRoutes, MAX_CONCURRENT_REQUESTS);
|
|
70
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
|
71
|
+
_state2.label = 1;
|
|
72
|
+
case 1:
|
|
73
|
+
_state2.trys.push([
|
|
74
|
+
1,
|
|
75
|
+
12,
|
|
76
|
+
13,
|
|
77
|
+
14
|
|
78
|
+
]);
|
|
79
|
+
_iterator = chunkedRoutes[Symbol.iterator]();
|
|
80
|
+
_state2.label = 2;
|
|
81
|
+
case 2:
|
|
82
|
+
if (!!(_iteratorNormalCompletion = (_step = _iterator.next()).done))
|
|
83
|
+
return [
|
|
84
|
+
3,
|
|
85
|
+
11
|
|
86
|
+
];
|
|
87
|
+
routes2 = _step.value;
|
|
88
|
+
promises = routes2.map(function() {
|
|
89
|
+
var _ref2 = _async_to_generator(function(route) {
|
|
90
|
+
return _ts_generator(this, function(_state3) {
|
|
91
|
+
return [
|
|
92
|
+
2,
|
|
93
|
+
getHtml("http://localhost:".concat(port).concat(route.urlPath), port)
|
|
94
|
+
];
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
return function(route) {
|
|
98
|
+
return _ref2.apply(this, arguments);
|
|
99
|
+
};
|
|
100
|
+
}());
|
|
101
|
+
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
|
|
102
|
+
_state2.label = 3;
|
|
103
|
+
case 3:
|
|
104
|
+
_state2.trys.push([
|
|
105
|
+
3,
|
|
106
|
+
8,
|
|
107
|
+
9,
|
|
108
|
+
10
|
|
109
|
+
]);
|
|
65
110
|
return [
|
|
66
111
|
4,
|
|
67
|
-
Promise.all(
|
|
68
|
-
var url = "http://localhost:".concat(port).concat(route.urlPath);
|
|
69
|
-
return getHtml(url, port);
|
|
70
|
-
}))
|
|
112
|
+
Promise.all(promises)
|
|
71
113
|
];
|
|
72
|
-
case
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
114
|
+
case 4:
|
|
115
|
+
_iterator1 = _state2.sent()[Symbol.iterator]();
|
|
116
|
+
_state2.label = 5;
|
|
117
|
+
case 5:
|
|
118
|
+
if (!!(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done))
|
|
119
|
+
return [
|
|
120
|
+
3,
|
|
121
|
+
7
|
|
122
|
+
];
|
|
123
|
+
result = _step1.value;
|
|
124
|
+
sendProcessMessage(result);
|
|
125
|
+
sendProcessMessage(null);
|
|
126
|
+
_state2.label = 6;
|
|
127
|
+
case 6:
|
|
128
|
+
_iteratorNormalCompletion1 = true;
|
|
129
|
+
return [
|
|
130
|
+
3,
|
|
131
|
+
5
|
|
132
|
+
];
|
|
133
|
+
case 7:
|
|
134
|
+
return [
|
|
135
|
+
3,
|
|
136
|
+
10
|
|
137
|
+
];
|
|
138
|
+
case 8:
|
|
139
|
+
err = _state2.sent();
|
|
140
|
+
_didIteratorError1 = true;
|
|
141
|
+
_iteratorError1 = err;
|
|
142
|
+
return [
|
|
143
|
+
3,
|
|
144
|
+
10
|
|
145
|
+
];
|
|
146
|
+
case 9:
|
|
147
|
+
try {
|
|
148
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
|
149
|
+
_iterator1.return();
|
|
150
|
+
}
|
|
151
|
+
} finally {
|
|
152
|
+
if (_didIteratorError1) {
|
|
153
|
+
throw _iteratorError1;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
return [
|
|
157
|
+
7
|
|
158
|
+
];
|
|
159
|
+
case 10:
|
|
160
|
+
_iteratorNormalCompletion = true;
|
|
161
|
+
return [
|
|
162
|
+
3,
|
|
163
|
+
2
|
|
164
|
+
];
|
|
165
|
+
case 11:
|
|
166
|
+
return [
|
|
167
|
+
3,
|
|
168
|
+
14
|
|
169
|
+
];
|
|
170
|
+
case 12:
|
|
171
|
+
err = _state2.sent();
|
|
172
|
+
_didIteratorError = true;
|
|
173
|
+
_iteratorError = err;
|
|
174
|
+
return [
|
|
175
|
+
3,
|
|
176
|
+
14
|
|
177
|
+
];
|
|
178
|
+
case 13:
|
|
179
|
+
try {
|
|
180
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
|
181
|
+
_iterator.return();
|
|
182
|
+
}
|
|
183
|
+
} finally {
|
|
184
|
+
if (_didIteratorError) {
|
|
185
|
+
throw _iteratorError;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return [
|
|
189
|
+
7
|
|
190
|
+
];
|
|
191
|
+
case 14:
|
|
78
192
|
nodeServer.close();
|
|
79
193
|
return [
|
|
80
194
|
2
|
|
@@ -138,7 +138,15 @@ const flattenRoutes = (routes) => {
|
|
|
138
138
|
routes.forEach(traverseRoute);
|
|
139
139
|
return newRoutes;
|
|
140
140
|
};
|
|
141
|
+
function chunkArray(arr, size) {
|
|
142
|
+
const result = [];
|
|
143
|
+
for (let i = 0; i < arr.length; i += size) {
|
|
144
|
+
result.push(arr.slice(i, i + size));
|
|
145
|
+
}
|
|
146
|
+
return result;
|
|
147
|
+
}
|
|
141
148
|
export {
|
|
149
|
+
chunkArray,
|
|
142
150
|
flattenRoutes,
|
|
143
151
|
formatOutput,
|
|
144
152
|
formatPath,
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import assert from "assert";
|
|
1
2
|
import { request } from "http";
|
|
2
3
|
import { createProdServer, loadServerPlugins } from "@modern-js/prod-server";
|
|
3
4
|
import portfinder from "portfinder";
|
|
5
|
+
import { chunkArray } from "../libs/util";
|
|
4
6
|
import { CLOSE_SIGN } from "./consts";
|
|
7
|
+
const MAX_CONCURRENT_REQUESTS = 10;
|
|
5
8
|
process.on("message", async (chunk) => {
|
|
6
9
|
if (chunk === CLOSE_SIGN) {
|
|
7
10
|
process.exit();
|
|
@@ -22,19 +25,20 @@ process.on("message", async (chunk) => {
|
|
|
22
25
|
plugins: await loadServerPlugins(plugins, appContext.appDirectory || distDirectory),
|
|
23
26
|
staticGenerate: true
|
|
24
27
|
};
|
|
28
|
+
assert(process.send, "process.send is not available");
|
|
29
|
+
const sendProcessMessage = process.send.bind(process);
|
|
25
30
|
nodeServer = await createProdServer(serverOptions);
|
|
26
31
|
nodeServer.listen(port, async () => {
|
|
27
|
-
if (!nodeServer)
|
|
32
|
+
if (!nodeServer)
|
|
28
33
|
return;
|
|
34
|
+
const chunkedRoutes = chunkArray(renderRoutes, MAX_CONCURRENT_REQUESTS);
|
|
35
|
+
for (const routes2 of chunkedRoutes) {
|
|
36
|
+
const promises = routes2.map(async (route) => getHtml(`http://localhost:${port}${route.urlPath}`, port));
|
|
37
|
+
for (const result of await Promise.all(promises)) {
|
|
38
|
+
sendProcessMessage(result);
|
|
39
|
+
sendProcessMessage(null);
|
|
40
|
+
}
|
|
29
41
|
}
|
|
30
|
-
const htmlAry = await Promise.all(renderRoutes.map((route) => {
|
|
31
|
-
const url = `http://localhost:${port}${route.urlPath}`;
|
|
32
|
-
return getHtml(url, port);
|
|
33
|
-
}));
|
|
34
|
-
htmlAry.forEach((html) => {
|
|
35
|
-
process.send(html);
|
|
36
|
-
process.send(null);
|
|
37
|
-
});
|
|
38
42
|
nodeServer.close();
|
|
39
43
|
});
|
|
40
44
|
} catch (e) {
|
|
@@ -23,3 +23,4 @@ export declare const openRouteSSR: (routes: ModernRoute[], entries?: string[]) =
|
|
|
23
23
|
responseHeaders?: Record<string, unknown> | undefined;
|
|
24
24
|
}[];
|
|
25
25
|
export declare const flattenRoutes: (routes: AgreedRoute[]) => AgreedRoute[];
|
|
26
|
+
export declare function chunkArray<T>(arr: T[], size: number): T[][];
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.63.
|
|
18
|
+
"version": "2.63.7",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
"node-mocks-http": "^1.11.0",
|
|
64
64
|
"normalize-path": "3.0.0",
|
|
65
65
|
"portfinder": "^1.0.28",
|
|
66
|
-
"@modern-js/prod-server": "2.63.
|
|
67
|
-
"@modern-js/utils": "2.63.
|
|
66
|
+
"@modern-js/prod-server": "2.63.7",
|
|
67
|
+
"@modern-js/utils": "2.63.7"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
70
|
"react-router-dom": ">=5.1.2"
|
|
@@ -82,10 +82,10 @@
|
|
|
82
82
|
"react-dom": "^18.3.1",
|
|
83
83
|
"react-router-dom": "6.27.0",
|
|
84
84
|
"typescript": "^5",
|
|
85
|
-
"@modern-js/app-tools": "2.63.
|
|
86
|
-
"@modern-js/types": "2.63.
|
|
87
|
-
"@scripts/
|
|
88
|
-
"@scripts/
|
|
85
|
+
"@modern-js/app-tools": "2.63.7",
|
|
86
|
+
"@modern-js/types": "2.63.7",
|
|
87
|
+
"@scripts/build": "2.63.7",
|
|
88
|
+
"@scripts/jest-config": "2.63.7"
|
|
89
89
|
},
|
|
90
90
|
"sideEffects": false,
|
|
91
91
|
"publishConfig": {
|