@modern-js/plugin-ssg 2.27.0 → 2.29.0
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/CHANGELOG.md +18 -0
- package/dist/cjs/libs/util.js +6 -3
- package/dist/cjs/server/index.js +53 -55
- package/dist/cjs/server/process.js +2 -1
- package/dist/esm/libs/util.js +6 -3
- package/dist/esm/server/process.js +2 -2
- package/dist/esm-node/libs/util.js +6 -3
- package/dist/esm-node/server/index.js +53 -55
- package/dist/esm-node/server/process.js +2 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @modern-js/plugin-ssg
|
|
2
2
|
|
|
3
|
+
## 2.29.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [e6b5355]
|
|
8
|
+
- Updated dependencies [93db783]
|
|
9
|
+
- Updated dependencies [cba7675]
|
|
10
|
+
- Updated dependencies [99052ea]
|
|
11
|
+
- Updated dependencies [1d71d2e]
|
|
12
|
+
- @modern-js/utils@2.29.0
|
|
13
|
+
|
|
14
|
+
## 2.28.0
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [00b58a7]
|
|
19
|
+
- @modern-js/utils@2.28.0
|
|
20
|
+
|
|
3
21
|
## 2.27.0
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/cjs/libs/util.js
CHANGED
|
@@ -136,18 +136,21 @@ const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
|
136
136
|
} else if (typeof ssgOptions === "function") {
|
|
137
137
|
const intermediateOptions = {};
|
|
138
138
|
for (const entrypoint of entrypoints) {
|
|
139
|
+
var _server;
|
|
139
140
|
const { entryName } = entrypoint;
|
|
140
|
-
if (Array.isArray(server === null ||
|
|
141
|
+
if (Array.isArray((_server = server) === null || _server === void 0 ? void 0 : _server.baseUrl)) {
|
|
141
142
|
for (const url of server.baseUrl) {
|
|
143
|
+
var _route;
|
|
142
144
|
const matchUrl = entryName === "main" ? url : `${url}/${entryName}`;
|
|
143
145
|
const route = routes.find((route2) => route2.urlPath === matchUrl);
|
|
144
|
-
intermediateOptions[route === null ||
|
|
146
|
+
intermediateOptions[(_route = route) === null || _route === void 0 ? void 0 : _route.urlPath] = ssgOptions(entryName, {
|
|
145
147
|
baseUrl: url
|
|
146
148
|
});
|
|
147
149
|
}
|
|
148
150
|
} else {
|
|
151
|
+
var _server1;
|
|
149
152
|
intermediateOptions[entryName] = ssgOptions(entryName, {
|
|
150
|
-
baseUrl: server === null ||
|
|
153
|
+
baseUrl: (_server1 = server) === null || _server1 === void 0 ? void 0 : _server1.baseUrl
|
|
151
154
|
});
|
|
152
155
|
}
|
|
153
156
|
}
|
package/dist/cjs/server/index.js
CHANGED
|
@@ -14,59 +14,57 @@ const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
|
|
|
14
14
|
const _utils = require("@modern-js/utils");
|
|
15
15
|
const _util = require("../libs/util");
|
|
16
16
|
const _consts = require("./consts");
|
|
17
|
-
const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
silent: true
|
|
26
|
-
});
|
|
27
|
-
const appContext = api.useAppContext();
|
|
28
|
-
const plugins = appContext.serverInternalPlugins;
|
|
29
|
-
cp.send(JSON.stringify({
|
|
30
|
-
options,
|
|
31
|
-
renderRoutes: ssgRoutes,
|
|
32
|
-
routes: total,
|
|
33
|
-
appDirectory,
|
|
34
|
-
plugins
|
|
35
|
-
}));
|
|
36
|
-
const htmlChunks = [];
|
|
37
|
-
const htmlAry = [];
|
|
38
|
-
cp.on("message", (chunk) => {
|
|
39
|
-
if (chunk !== null) {
|
|
40
|
-
htmlChunks.push(chunk);
|
|
41
|
-
} else {
|
|
42
|
-
const html = htmlChunks.join("");
|
|
43
|
-
htmlAry.push(html);
|
|
44
|
-
htmlChunks.length = 0;
|
|
45
|
-
}
|
|
46
|
-
if (htmlAry.length === ssgRoutes.length) {
|
|
47
|
-
cp.send(_consts.CLOSE_SIGN);
|
|
48
|
-
resolve(htmlAry);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
(_cp_stderr = cp.stderr) === null || _cp_stderr === void 0 ? void 0 : _cp_stderr.on("data", (chunk) => {
|
|
52
|
-
const str = chunk.toString();
|
|
53
|
-
if (str.includes("Error")) {
|
|
54
|
-
_utils.logger.error(str);
|
|
55
|
-
reject(new Error("ssg render failed"));
|
|
56
|
-
cp.kill("SIGKILL");
|
|
57
|
-
} else {
|
|
58
|
-
_utils.logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
(_cp_stdout = cp.stdout) === null || _cp_stdout === void 0 ? void 0 : _cp_stdout.on("data", (chunk) => {
|
|
62
|
-
const str = chunk.toString();
|
|
63
|
-
if (str.includes("Error")) {
|
|
64
|
-
_utils.logger.error(str);
|
|
65
|
-
reject(new Error("ssg render failed"));
|
|
66
|
-
cp.kill("SIGKILL");
|
|
67
|
-
} else {
|
|
68
|
-
_utils.logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
69
|
-
}
|
|
70
|
-
});
|
|
17
|
+
const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
18
|
+
var _cp_stderr, _cp_stdout;
|
|
19
|
+
const entries = ssgRoutes.map((route) => route.entryName);
|
|
20
|
+
const backup = (0, _util.openRouteSSR)(pageRoutes, entries);
|
|
21
|
+
const total = backup.concat(apiRoutes);
|
|
22
|
+
const cp = _child_process.default.fork(_path.default.join(__dirname, "process"), {
|
|
23
|
+
cwd: appDirectory,
|
|
24
|
+
silent: true
|
|
71
25
|
});
|
|
72
|
-
|
|
26
|
+
const appContext = api.useAppContext();
|
|
27
|
+
const plugins = appContext.serverInternalPlugins;
|
|
28
|
+
cp.send(JSON.stringify({
|
|
29
|
+
options,
|
|
30
|
+
renderRoutes: ssgRoutes,
|
|
31
|
+
routes: total,
|
|
32
|
+
appDirectory,
|
|
33
|
+
plugins
|
|
34
|
+
}));
|
|
35
|
+
const htmlChunks = [];
|
|
36
|
+
const htmlAry = [];
|
|
37
|
+
cp.on("message", (chunk) => {
|
|
38
|
+
if (chunk !== null) {
|
|
39
|
+
htmlChunks.push(chunk);
|
|
40
|
+
} else {
|
|
41
|
+
const html = htmlChunks.join("");
|
|
42
|
+
htmlAry.push(html);
|
|
43
|
+
htmlChunks.length = 0;
|
|
44
|
+
}
|
|
45
|
+
if (htmlAry.length === ssgRoutes.length) {
|
|
46
|
+
cp.send(_consts.CLOSE_SIGN);
|
|
47
|
+
resolve(htmlAry);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
(_cp_stderr = cp.stderr) === null || _cp_stderr === void 0 ? void 0 : _cp_stderr.on("data", (chunk) => {
|
|
51
|
+
const str = chunk.toString();
|
|
52
|
+
if (str.includes("Error")) {
|
|
53
|
+
_utils.logger.error(str);
|
|
54
|
+
reject(new Error("ssg render failed"));
|
|
55
|
+
cp.kill("SIGKILL");
|
|
56
|
+
} else {
|
|
57
|
+
_utils.logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
(_cp_stdout = cp.stdout) === null || _cp_stdout === void 0 ? void 0 : _cp_stdout.on("data", (chunk) => {
|
|
61
|
+
const str = chunk.toString();
|
|
62
|
+
if (str.includes("Error")) {
|
|
63
|
+
_utils.logger.error(str);
|
|
64
|
+
reject(new Error("ssg render failed"));
|
|
65
|
+
cp.kill("SIGKILL");
|
|
66
|
+
} else {
|
|
67
|
+
_utils.logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -44,7 +44,8 @@ process.on("message", async (chunk) => {
|
|
|
44
44
|
modernServer.close();
|
|
45
45
|
});
|
|
46
46
|
} catch (e) {
|
|
47
|
-
|
|
47
|
+
var _modernServer;
|
|
48
|
+
(_modernServer = modernServer) === null || _modernServer === void 0 ? void 0 : _modernServer.close();
|
|
48
49
|
process.stderr.write(e instanceof Error ? e.stack : e.toString());
|
|
49
50
|
}
|
|
50
51
|
});
|
package/dist/esm/libs/util.js
CHANGED
|
@@ -100,17 +100,19 @@ export var standardOptions = function(ssgOptions, entrypoints, routes, server) {
|
|
|
100
100
|
try {
|
|
101
101
|
var _loop = function() {
|
|
102
102
|
var entrypoint = _step.value;
|
|
103
|
+
var _server;
|
|
103
104
|
var entryName = entrypoint.entryName;
|
|
104
|
-
if (Array.isArray(server === null ||
|
|
105
|
+
if (Array.isArray((_server = server) === null || _server === void 0 ? void 0 : _server.baseUrl)) {
|
|
105
106
|
var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
|
|
106
107
|
try {
|
|
107
108
|
var _loop2 = function() {
|
|
108
109
|
var url = _step1.value;
|
|
110
|
+
var _route;
|
|
109
111
|
var matchUrl = entryName === "main" ? url : "".concat(url, "/").concat(entryName);
|
|
110
112
|
var route = routes.find(function(route2) {
|
|
111
113
|
return route2.urlPath === matchUrl;
|
|
112
114
|
});
|
|
113
|
-
intermediateOptions[route === null ||
|
|
115
|
+
intermediateOptions[(_route = route) === null || _route === void 0 ? void 0 : _route.urlPath] = ssgOptions(entryName, {
|
|
114
116
|
baseUrl: url
|
|
115
117
|
});
|
|
116
118
|
};
|
|
@@ -131,8 +133,9 @@ export var standardOptions = function(ssgOptions, entrypoints, routes, server) {
|
|
|
131
133
|
}
|
|
132
134
|
}
|
|
133
135
|
} else {
|
|
136
|
+
var _server1;
|
|
134
137
|
intermediateOptions[entryName] = ssgOptions(entryName, {
|
|
135
|
-
baseUrl: server === null ||
|
|
138
|
+
baseUrl: (_server1 = server) === null || _server1 === void 0 ? void 0 : _server1.baseUrl
|
|
136
139
|
});
|
|
137
140
|
}
|
|
138
141
|
};
|
|
@@ -8,7 +8,7 @@ import { compile as createRender } from "./prerender";
|
|
|
8
8
|
import { CLOSE_SIGN } from "./consts";
|
|
9
9
|
process.on("message", function() {
|
|
10
10
|
var _ref = _async_to_generator(function(chunk) {
|
|
11
|
-
var context, routes, renderRoutes, options, appDirectory, plugins, modernServer, serverOptions, defaultPort, port, e;
|
|
11
|
+
var context, routes, renderRoutes, options, appDirectory, plugins, modernServer, serverOptions, defaultPort, port, e, _modernServer;
|
|
12
12
|
return _ts_generator(this, function(_state) {
|
|
13
13
|
switch (_state.label) {
|
|
14
14
|
case 0:
|
|
@@ -90,7 +90,7 @@ process.on("message", function() {
|
|
|
90
90
|
];
|
|
91
91
|
case 4:
|
|
92
92
|
e = _state.sent();
|
|
93
|
-
modernServer === null ||
|
|
93
|
+
(_modernServer = modernServer) === null || _modernServer === void 0 ? void 0 : _modernServer.close();
|
|
94
94
|
process.stderr.write(_instanceof(e, Error) ? e.stack : e.toString());
|
|
95
95
|
return [
|
|
96
96
|
3,
|
|
@@ -89,18 +89,21 @@ export const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
|
89
89
|
} else if (typeof ssgOptions === "function") {
|
|
90
90
|
const intermediateOptions = {};
|
|
91
91
|
for (const entrypoint of entrypoints) {
|
|
92
|
+
var _server;
|
|
92
93
|
const { entryName } = entrypoint;
|
|
93
|
-
if (Array.isArray(server === null ||
|
|
94
|
+
if (Array.isArray((_server = server) === null || _server === void 0 ? void 0 : _server.baseUrl)) {
|
|
94
95
|
for (const url of server.baseUrl) {
|
|
96
|
+
var _route;
|
|
95
97
|
const matchUrl = entryName === "main" ? url : `${url}/${entryName}`;
|
|
96
98
|
const route = routes.find((route2) => route2.urlPath === matchUrl);
|
|
97
|
-
intermediateOptions[route === null ||
|
|
99
|
+
intermediateOptions[(_route = route) === null || _route === void 0 ? void 0 : _route.urlPath] = ssgOptions(entryName, {
|
|
98
100
|
baseUrl: url
|
|
99
101
|
});
|
|
100
102
|
}
|
|
101
103
|
} else {
|
|
104
|
+
var _server1;
|
|
102
105
|
intermediateOptions[entryName] = ssgOptions(entryName, {
|
|
103
|
-
baseUrl: server === null ||
|
|
106
|
+
baseUrl: (_server1 = server) === null || _server1 === void 0 ? void 0 : _server1.baseUrl
|
|
104
107
|
});
|
|
105
108
|
}
|
|
106
109
|
}
|
|
@@ -3,59 +3,57 @@ import path from "path";
|
|
|
3
3
|
import { logger } from "@modern-js/utils";
|
|
4
4
|
import { openRouteSSR } from "../libs/util";
|
|
5
5
|
import { CLOSE_SIGN } from "./consts";
|
|
6
|
-
export const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
silent: true
|
|
15
|
-
});
|
|
16
|
-
const appContext = api.useAppContext();
|
|
17
|
-
const plugins = appContext.serverInternalPlugins;
|
|
18
|
-
cp.send(JSON.stringify({
|
|
19
|
-
options,
|
|
20
|
-
renderRoutes: ssgRoutes,
|
|
21
|
-
routes: total,
|
|
22
|
-
appDirectory,
|
|
23
|
-
plugins
|
|
24
|
-
}));
|
|
25
|
-
const htmlChunks = [];
|
|
26
|
-
const htmlAry = [];
|
|
27
|
-
cp.on("message", (chunk) => {
|
|
28
|
-
if (chunk !== null) {
|
|
29
|
-
htmlChunks.push(chunk);
|
|
30
|
-
} else {
|
|
31
|
-
const html = htmlChunks.join("");
|
|
32
|
-
htmlAry.push(html);
|
|
33
|
-
htmlChunks.length = 0;
|
|
34
|
-
}
|
|
35
|
-
if (htmlAry.length === ssgRoutes.length) {
|
|
36
|
-
cp.send(CLOSE_SIGN);
|
|
37
|
-
resolve(htmlAry);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
(_cp_stderr = cp.stderr) === null || _cp_stderr === void 0 ? void 0 : _cp_stderr.on("data", (chunk) => {
|
|
41
|
-
const str = chunk.toString();
|
|
42
|
-
if (str.includes("Error")) {
|
|
43
|
-
logger.error(str);
|
|
44
|
-
reject(new Error("ssg render failed"));
|
|
45
|
-
cp.kill("SIGKILL");
|
|
46
|
-
} else {
|
|
47
|
-
logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
(_cp_stdout = cp.stdout) === null || _cp_stdout === void 0 ? void 0 : _cp_stdout.on("data", (chunk) => {
|
|
51
|
-
const str = chunk.toString();
|
|
52
|
-
if (str.includes("Error")) {
|
|
53
|
-
logger.error(str);
|
|
54
|
-
reject(new Error("ssg render failed"));
|
|
55
|
-
cp.kill("SIGKILL");
|
|
56
|
-
} else {
|
|
57
|
-
logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
58
|
-
}
|
|
59
|
-
});
|
|
6
|
+
export const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
7
|
+
var _cp_stderr, _cp_stdout;
|
|
8
|
+
const entries = ssgRoutes.map((route) => route.entryName);
|
|
9
|
+
const backup = openRouteSSR(pageRoutes, entries);
|
|
10
|
+
const total = backup.concat(apiRoutes);
|
|
11
|
+
const cp = childProcess.fork(path.join(__dirname, "process"), {
|
|
12
|
+
cwd: appDirectory,
|
|
13
|
+
silent: true
|
|
60
14
|
});
|
|
61
|
-
|
|
15
|
+
const appContext = api.useAppContext();
|
|
16
|
+
const plugins = appContext.serverInternalPlugins;
|
|
17
|
+
cp.send(JSON.stringify({
|
|
18
|
+
options,
|
|
19
|
+
renderRoutes: ssgRoutes,
|
|
20
|
+
routes: total,
|
|
21
|
+
appDirectory,
|
|
22
|
+
plugins
|
|
23
|
+
}));
|
|
24
|
+
const htmlChunks = [];
|
|
25
|
+
const htmlAry = [];
|
|
26
|
+
cp.on("message", (chunk) => {
|
|
27
|
+
if (chunk !== null) {
|
|
28
|
+
htmlChunks.push(chunk);
|
|
29
|
+
} else {
|
|
30
|
+
const html = htmlChunks.join("");
|
|
31
|
+
htmlAry.push(html);
|
|
32
|
+
htmlChunks.length = 0;
|
|
33
|
+
}
|
|
34
|
+
if (htmlAry.length === ssgRoutes.length) {
|
|
35
|
+
cp.send(CLOSE_SIGN);
|
|
36
|
+
resolve(htmlAry);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
(_cp_stderr = cp.stderr) === null || _cp_stderr === void 0 ? void 0 : _cp_stderr.on("data", (chunk) => {
|
|
40
|
+
const str = chunk.toString();
|
|
41
|
+
if (str.includes("Error")) {
|
|
42
|
+
logger.error(str);
|
|
43
|
+
reject(new Error("ssg render failed"));
|
|
44
|
+
cp.kill("SIGKILL");
|
|
45
|
+
} else {
|
|
46
|
+
logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
(_cp_stdout = cp.stdout) === null || _cp_stdout === void 0 ? void 0 : _cp_stdout.on("data", (chunk) => {
|
|
50
|
+
const str = chunk.toString();
|
|
51
|
+
if (str.includes("Error")) {
|
|
52
|
+
logger.error(str);
|
|
53
|
+
reject(new Error("ssg render failed"));
|
|
54
|
+
cp.kill("SIGKILL");
|
|
55
|
+
} else {
|
|
56
|
+
logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -39,7 +39,8 @@ process.on("message", async (chunk) => {
|
|
|
39
39
|
modernServer.close();
|
|
40
40
|
});
|
|
41
41
|
} catch (e) {
|
|
42
|
-
|
|
42
|
+
var _modernServer;
|
|
43
|
+
(_modernServer = modernServer) === null || _modernServer === void 0 ? void 0 : _modernServer.close();
|
|
43
44
|
process.stderr.write(e instanceof Error ? e.stack : e.toString());
|
|
44
45
|
}
|
|
45
46
|
});
|
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"modern",
|
|
16
16
|
"modern.js"
|
|
17
17
|
],
|
|
18
|
-
"version": "2.
|
|
18
|
+
"version": "2.29.0",
|
|
19
19
|
"jsnext:source": "./src/index.ts",
|
|
20
20
|
"types": "./dist/types/index.d.ts",
|
|
21
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"normalize-path": "^3.0.0",
|
|
64
64
|
"portfinder": "^1.0.28",
|
|
65
65
|
"@swc/helpers": "0.5.1",
|
|
66
|
-
"@modern-js/utils": "2.
|
|
66
|
+
"@modern-js/utils": "2.29.0"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"react-router-dom": ">=5.1.2"
|
|
@@ -81,11 +81,11 @@
|
|
|
81
81
|
"react-dom": "^18",
|
|
82
82
|
"react-router-dom": "^6.8.1",
|
|
83
83
|
"typescript": "^5",
|
|
84
|
-
"@modern-js/app-tools": "2.
|
|
85
|
-
"@modern-js/prod-server": "2.
|
|
86
|
-
"@
|
|
87
|
-
"@scripts/build": "2.
|
|
88
|
-
"@
|
|
84
|
+
"@modern-js/app-tools": "2.29.0",
|
|
85
|
+
"@modern-js/prod-server": "2.29.0",
|
|
86
|
+
"@scripts/jest-config": "2.29.0",
|
|
87
|
+
"@scripts/build": "2.29.0",
|
|
88
|
+
"@modern-js/types": "2.29.0"
|
|
89
89
|
},
|
|
90
90
|
"sideEffects": false,
|
|
91
91
|
"publishConfig": {
|