@modern-js/plugin-ssg 2.15.0 → 2.17.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 +19 -0
- package/dist/cjs/index.js +62 -95
- package/dist/cjs/libs/make.js +34 -48
- package/dist/cjs/libs/output.js +18 -41
- package/dist/cjs/libs/replace.js +24 -41
- package/dist/cjs/libs/util.js +48 -72
- package/dist/cjs/server/consts.js +7 -25
- package/dist/cjs/server/index.js +67 -90
- package/dist/cjs/server/prerender.js +20 -41
- package/dist/cjs/server/process.js +22 -45
- package/dist/cjs/types.js +4 -15
- package/dist/esm/index.js +316 -309
- package/dist/esm/libs/make.js +70 -71
- package/dist/esm/libs/output.js +9 -10
- package/dist/esm/libs/replace.js +113 -100
- package/dist/esm/libs/util.js +211 -210
- package/dist/esm/server/consts.js +1 -2
- package/dist/esm/server/index.js +56 -57
- package/dist/esm/server/prerender.js +85 -86
- package/dist/esm/server/process.js +220 -213
- package/dist/esm/types.js +1 -1
- package/dist/esm-node/index.js +29 -51
- package/dist/esm-node/libs/make.js +14 -14
- package/dist/esm-node/libs/output.js +1 -4
- package/dist/esm-node/libs/replace.js +8 -11
- package/dist/esm-node/libs/util.js +26 -41
- package/dist/esm-node/server/consts.js +1 -4
- package/dist/esm-node/server/index.js +49 -52
- package/dist/esm-node/server/prerender.js +4 -5
- package/dist/esm-node/server/process.js +3 -13
- package/dist/esm-node/types.js +1 -0
- package/package.json +12 -8
package/dist/esm-node/index.js
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { logger, PLUGIN_SCHEMAS } from "@modern-js/utils";
|
|
3
3
|
import { generatePath } from "react-router-dom";
|
|
4
|
-
import {
|
|
5
|
-
flattenRoutes,
|
|
6
|
-
formatOutput,
|
|
7
|
-
isDynamicUrl,
|
|
8
|
-
readJSONSpec,
|
|
9
|
-
standardOptions,
|
|
10
|
-
writeJSONSpec
|
|
11
|
-
} from "./libs/util";
|
|
4
|
+
import { flattenRoutes, formatOutput, isDynamicUrl, readJSONSpec, standardOptions, writeJSONSpec } from "./libs/util";
|
|
12
5
|
import { createServer } from "./server";
|
|
13
6
|
import { writeHtmlFile } from "./libs/output";
|
|
14
7
|
import { replaceRoute } from "./libs/replace";
|
|
15
8
|
import { makeRoute } from "./libs/make";
|
|
16
|
-
|
|
9
|
+
export default () => ({
|
|
17
10
|
name: "@modern-js/plugin-ssg",
|
|
18
|
-
pre: [
|
|
11
|
+
pre: [
|
|
12
|
+
"@modern-js/plugin-server",
|
|
13
|
+
"@modern-js/plugin-bff"
|
|
14
|
+
],
|
|
19
15
|
setup: (api) => {
|
|
20
16
|
const agreedRouteMap = {};
|
|
21
17
|
return {
|
|
@@ -26,7 +22,10 @@ var src_default = () => ({
|
|
|
26
22
|
const { entryName } = entrypoint;
|
|
27
23
|
const flattedRoutes = flattenRoutes(routes);
|
|
28
24
|
agreedRouteMap[entryName] = flattedRoutes;
|
|
29
|
-
return {
|
|
25
|
+
return {
|
|
26
|
+
entrypoint,
|
|
27
|
+
routes
|
|
28
|
+
};
|
|
30
29
|
},
|
|
31
30
|
async afterBuild() {
|
|
32
31
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
@@ -42,12 +41,7 @@ var src_default = () => ({
|
|
|
42
41
|
if (pageRoutes.length === 0) {
|
|
43
42
|
return;
|
|
44
43
|
}
|
|
45
|
-
const intermediateOptions = standardOptions(
|
|
46
|
-
ssgOptions,
|
|
47
|
-
entrypoints,
|
|
48
|
-
pageRoutes,
|
|
49
|
-
server
|
|
50
|
-
);
|
|
44
|
+
const intermediateOptions = standardOptions(ssgOptions, entrypoints, pageRoutes, server);
|
|
51
45
|
if (!intermediateOptions) {
|
|
52
46
|
return;
|
|
53
47
|
}
|
|
@@ -61,7 +55,10 @@ var src_default = () => ({
|
|
|
61
55
|
return;
|
|
62
56
|
}
|
|
63
57
|
if (entryOptions === true) {
|
|
64
|
-
ssgRoutes.push({
|
|
58
|
+
ssgRoutes.push({
|
|
59
|
+
...pageRoute,
|
|
60
|
+
output: entryPath
|
|
61
|
+
});
|
|
65
62
|
} else if (entryOptions.routes && entryOptions.routes.length > 0) {
|
|
66
63
|
const { routes: enrtyRoutes, headers } = entryOptions;
|
|
67
64
|
enrtyRoutes.forEach((route) => {
|
|
@@ -73,26 +70,23 @@ var src_default = () => ({
|
|
|
73
70
|
return;
|
|
74
71
|
}
|
|
75
72
|
if (entryOptions === true) {
|
|
76
|
-
entryOptions = {
|
|
73
|
+
entryOptions = {
|
|
74
|
+
preventDefault: [],
|
|
75
|
+
routes: [],
|
|
76
|
+
headers: {}
|
|
77
|
+
};
|
|
77
78
|
}
|
|
78
|
-
const {
|
|
79
|
-
preventDefault = [],
|
|
80
|
-
routes: userRoutes = [],
|
|
81
|
-
headers
|
|
82
|
-
} = entryOptions;
|
|
79
|
+
const { preventDefault = [], routes: userRoutes = [], headers } = entryOptions;
|
|
83
80
|
if (userRoutes.length > 0) {
|
|
84
81
|
userRoutes.forEach((route) => {
|
|
85
82
|
if (typeof route === "string") {
|
|
86
83
|
ssgRoutes.push(makeRoute(pageRoute, route, headers));
|
|
87
84
|
} else if (Array.isArray(route.params)) {
|
|
88
85
|
route.params.forEach((param) => {
|
|
89
|
-
ssgRoutes.push(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
headers
|
|
94
|
-
)
|
|
95
|
-
);
|
|
86
|
+
ssgRoutes.push(makeRoute(pageRoute, {
|
|
87
|
+
...route,
|
|
88
|
+
url: generatePath(route.url, param)
|
|
89
|
+
}, headers));
|
|
96
90
|
});
|
|
97
91
|
} else {
|
|
98
92
|
ssgRoutes.push(makeRoute(pageRoute, route, headers));
|
|
@@ -112,29 +106,16 @@ var src_default = () => ({
|
|
|
112
106
|
}
|
|
113
107
|
ssgRoutes.forEach((ssgRoute) => {
|
|
114
108
|
if (ssgRoute.isSSR) {
|
|
115
|
-
const isOriginRoute = pageRoutes.some(
|
|
116
|
-
(pageRoute) => pageRoute.urlPath === ssgRoute.urlPath && pageRoute.entryName === ssgRoute.entryName
|
|
117
|
-
);
|
|
109
|
+
const isOriginRoute = pageRoutes.some((pageRoute) => pageRoute.urlPath === ssgRoute.urlPath && pageRoute.entryName === ssgRoute.entryName);
|
|
118
110
|
if (isOriginRoute) {
|
|
119
|
-
throw new Error(
|
|
120
|
-
`ssg can not using with ssr,url - ${ssgRoute.urlPath}, entry - ${ssgRoute.entryName} `
|
|
121
|
-
);
|
|
111
|
+
throw new Error(`ssg can not using with ssr,url - ${ssgRoute.urlPath}, entry - ${ssgRoute.entryName} `);
|
|
122
112
|
}
|
|
123
|
-
logger.warn(
|
|
124
|
-
`new ssg route ${ssgRoute.urlPath} is using ssr now,maybe from parent route ${ssgRoute.entryName},close ssr`
|
|
125
|
-
);
|
|
113
|
+
logger.warn(`new ssg route ${ssgRoute.urlPath} is using ssr now,maybe from parent route ${ssgRoute.entryName},close ssr`);
|
|
126
114
|
}
|
|
127
115
|
ssgRoute.isSSR = false;
|
|
128
116
|
ssgRoute.output = formatOutput(ssgRoute.output);
|
|
129
117
|
});
|
|
130
|
-
const htmlAry = await createServer(
|
|
131
|
-
api,
|
|
132
|
-
ssgRoutes,
|
|
133
|
-
pageRoutes,
|
|
134
|
-
apiRoutes,
|
|
135
|
-
resolvedConfig,
|
|
136
|
-
appDirectory
|
|
137
|
-
);
|
|
118
|
+
const htmlAry = await createServer(api, ssgRoutes, pageRoutes, apiRoutes, resolvedConfig, appDirectory);
|
|
138
119
|
writeHtmlFile(htmlAry, ssgRoutes, buildDir);
|
|
139
120
|
replaceRoute(ssgRoutes, pageRoutes);
|
|
140
121
|
writeJSONSpec(buildDir, pageRoutes.concat(apiRoutes));
|
|
@@ -143,6 +124,3 @@ var src_default = () => ({
|
|
|
143
124
|
};
|
|
144
125
|
}
|
|
145
126
|
});
|
|
146
|
-
export {
|
|
147
|
-
src_default as default
|
|
148
|
-
};
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import normalize from "normalize-path";
|
|
3
|
-
function makeRender(ssgRoutes, render, port) {
|
|
4
|
-
return ssgRoutes.map(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
3
|
+
export function makeRender(ssgRoutes, render, port) {
|
|
4
|
+
return ssgRoutes.map((ssgRoute) => render({
|
|
5
|
+
url: ssgRoute.urlPath,
|
|
6
|
+
headers: {
|
|
7
|
+
host: `localhost:${port}`,
|
|
8
|
+
...ssgRoute.headers
|
|
9
|
+
},
|
|
10
|
+
connection: {}
|
|
11
|
+
}));
|
|
11
12
|
}
|
|
12
|
-
function makeRoute(baseRoute, route, headers = {}) {
|
|
13
|
+
export function makeRoute(baseRoute, route, headers = {}) {
|
|
13
14
|
const { urlPath, entryPath } = baseRoute;
|
|
14
15
|
if (typeof route === "string") {
|
|
15
16
|
return {
|
|
@@ -22,12 +23,11 @@ function makeRoute(baseRoute, route, headers = {}) {
|
|
|
22
23
|
return {
|
|
23
24
|
...baseRoute,
|
|
24
25
|
urlPath: normalize(`${urlPath}${route.url}`) || "/",
|
|
25
|
-
headers: {
|
|
26
|
+
headers: {
|
|
27
|
+
...headers,
|
|
28
|
+
...route.headers
|
|
29
|
+
},
|
|
26
30
|
output: route.output ? path.normalize(route.output) : path.join(entryPath, `..${route.url === "/" ? "" : route.url}`)
|
|
27
31
|
};
|
|
28
32
|
}
|
|
29
33
|
}
|
|
30
|
-
export {
|
|
31
|
-
makeRender,
|
|
32
|
-
makeRoute
|
|
33
|
-
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { fs } from "@modern-js/utils";
|
|
3
|
-
function writeHtmlFile(htmlAry, ssgRoutes, baseDir) {
|
|
3
|
+
export function writeHtmlFile(htmlAry, ssgRoutes, baseDir) {
|
|
4
4
|
htmlAry.forEach((html, index) => {
|
|
5
5
|
const ssgRoute = ssgRoutes[index];
|
|
6
6
|
const filepath = path.join(baseDir, ssgRoute.output);
|
|
@@ -10,6 +10,3 @@ function writeHtmlFile(htmlAry, ssgRoutes, baseDir) {
|
|
|
10
10
|
fs.writeFileSync(filepath, html);
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
|
-
export {
|
|
14
|
-
writeHtmlFile
|
|
15
|
-
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import normalize from "normalize-path";
|
|
2
|
-
function exist(route, pageRoutes) {
|
|
2
|
+
export function exist(route, pageRoutes) {
|
|
3
3
|
return pageRoutes.slice().findIndex((pageRoute) => {
|
|
4
4
|
const urlEqual = normalize(pageRoute.urlPath) === normalize(route.urlPath);
|
|
5
5
|
const entryEqual = pageRoute.entryName === route.entryName;
|
|
@@ -9,19 +9,20 @@ function exist(route, pageRoutes) {
|
|
|
9
9
|
return false;
|
|
10
10
|
});
|
|
11
11
|
}
|
|
12
|
-
function replaceRoute(ssgRoutes, pageRoutes) {
|
|
12
|
+
export function replaceRoute(ssgRoutes, pageRoutes) {
|
|
13
13
|
const cleanSsgRoutes = ssgRoutes.map((ssgRoute) => {
|
|
14
14
|
const { output, headers, ...cleanSsgRoute } = ssgRoute;
|
|
15
|
-
return Object.assign(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
);
|
|
15
|
+
return Object.assign(cleanSsgRoute, output ? {
|
|
16
|
+
entryPath: output
|
|
17
|
+
} : {});
|
|
19
18
|
});
|
|
20
19
|
const freshRoutes = [];
|
|
21
20
|
cleanSsgRoutes.forEach((ssgRoute) => {
|
|
22
21
|
const index = exist(ssgRoute, pageRoutes);
|
|
23
22
|
if (index < 0) {
|
|
24
|
-
freshRoutes.push({
|
|
23
|
+
freshRoutes.push({
|
|
24
|
+
...ssgRoute
|
|
25
|
+
});
|
|
25
26
|
} else {
|
|
26
27
|
pageRoutes[index].entryPath = ssgRoute.entryPath;
|
|
27
28
|
}
|
|
@@ -29,7 +30,3 @@ function replaceRoute(ssgRoutes, pageRoutes) {
|
|
|
29
30
|
pageRoutes.push(...freshRoutes);
|
|
30
31
|
return pageRoutes;
|
|
31
32
|
}
|
|
32
|
-
export {
|
|
33
|
-
exist,
|
|
34
|
-
replaceRoute
|
|
35
|
-
};
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import path from "path";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
fs,
|
|
5
|
-
isSingleEntry,
|
|
6
|
-
SERVER_BUNDLE_DIRECTORY
|
|
7
|
-
} from "@modern-js/utils";
|
|
8
|
-
function formatOutput(filename) {
|
|
2
|
+
import { ROUTE_SPEC_FILE, fs, isSingleEntry, SERVER_BUNDLE_DIRECTORY } from "@modern-js/utils";
|
|
3
|
+
export function formatOutput(filename) {
|
|
9
4
|
const outputPath = path.extname(filename) ? filename : `${filename}/index.html`;
|
|
10
5
|
return outputPath;
|
|
11
6
|
}
|
|
12
|
-
function formatPath(str) {
|
|
7
|
+
export function formatPath(str) {
|
|
13
8
|
let addr = str;
|
|
14
9
|
if (!addr || typeof addr !== "string") {
|
|
15
10
|
return addr;
|
|
@@ -25,10 +20,10 @@ function formatPath(str) {
|
|
|
25
20
|
}
|
|
26
21
|
return addr;
|
|
27
22
|
}
|
|
28
|
-
function isDynamicUrl(url) {
|
|
23
|
+
export function isDynamicUrl(url) {
|
|
29
24
|
return url.includes(":");
|
|
30
25
|
}
|
|
31
|
-
function getUrlPrefix(route, baseUrl) {
|
|
26
|
+
export function getUrlPrefix(route, baseUrl) {
|
|
32
27
|
let base = "";
|
|
33
28
|
if (Array.isArray(baseUrl)) {
|
|
34
29
|
const filters = baseUrl.filter((url) => route.urlPath.includes(url));
|
|
@@ -47,7 +42,7 @@ function getUrlPrefix(route, baseUrl) {
|
|
|
47
42
|
const prefix = `${base}/${entryName}`;
|
|
48
43
|
return prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
|
|
49
44
|
}
|
|
50
|
-
function getOutput(route, base, agreed) {
|
|
45
|
+
export function getOutput(route, base, agreed) {
|
|
51
46
|
const { output } = route;
|
|
52
47
|
if (output) {
|
|
53
48
|
return output;
|
|
@@ -56,22 +51,24 @@ function getOutput(route, base, agreed) {
|
|
|
56
51
|
const urlWithoutBase = route.urlPath.replace(base, "");
|
|
57
52
|
return urlWithoutBase.startsWith("/") ? urlWithoutBase.slice(1) : urlWithoutBase;
|
|
58
53
|
}
|
|
59
|
-
throw new Error(
|
|
60
|
-
`routing must provide output when calling createPage(), check ${route.urlPath}`
|
|
61
|
-
);
|
|
54
|
+
throw new Error(`routing must provide output when calling createPage(), check ${route.urlPath}`);
|
|
62
55
|
}
|
|
63
|
-
const readJSONSpec = (dir) => {
|
|
56
|
+
export const readJSONSpec = (dir) => {
|
|
64
57
|
const routeJSONPath = path.join(dir, ROUTE_SPEC_FILE);
|
|
65
58
|
const routeJSON = require(routeJSONPath);
|
|
66
59
|
const { routes } = routeJSON;
|
|
67
60
|
return routes;
|
|
68
61
|
};
|
|
69
|
-
const writeJSONSpec = (dir, routes) => {
|
|
62
|
+
export const writeJSONSpec = (dir, routes) => {
|
|
70
63
|
const routeJSONPath = path.join(dir, ROUTE_SPEC_FILE);
|
|
71
|
-
fs.writeJSONSync(routeJSONPath, {
|
|
64
|
+
fs.writeJSONSync(routeJSONPath, {
|
|
65
|
+
routes
|
|
66
|
+
}, {
|
|
67
|
+
spaces: 2
|
|
68
|
+
});
|
|
72
69
|
};
|
|
73
|
-
const replaceWithAlias = (base, filePath, alias) => path.posix.join(alias, path.posix.relative(base, filePath));
|
|
74
|
-
const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
70
|
+
export const replaceWithAlias = (base, filePath, alias) => path.posix.join(alias, path.posix.relative(base, filePath));
|
|
71
|
+
export const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
75
72
|
if (ssgOptions === false) {
|
|
76
73
|
return false;
|
|
77
74
|
}
|
|
@@ -83,7 +80,9 @@ const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
|
83
80
|
} else if (typeof ssgOptions === "object") {
|
|
84
81
|
const isSingle = isSingleEntry(entrypoints);
|
|
85
82
|
if (isSingle && typeof ssgOptions.main === "undefined") {
|
|
86
|
-
return {
|
|
83
|
+
return {
|
|
84
|
+
main: ssgOptions
|
|
85
|
+
};
|
|
87
86
|
} else {
|
|
88
87
|
return ssgOptions;
|
|
89
88
|
}
|
|
@@ -91,18 +90,17 @@ const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
|
91
90
|
const intermediateOptions = {};
|
|
92
91
|
for (const entrypoint of entrypoints) {
|
|
93
92
|
const { entryName } = entrypoint;
|
|
94
|
-
if (Array.isArray(server
|
|
93
|
+
if (Array.isArray(server === null || server === void 0 ? void 0 : server.baseUrl)) {
|
|
95
94
|
for (const url of server.baseUrl) {
|
|
96
95
|
const matchUrl = entryName === "main" ? url : `${url}/${entryName}`;
|
|
97
96
|
const route = routes.find((route2) => route2.urlPath === matchUrl);
|
|
98
|
-
intermediateOptions[route
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
);
|
|
97
|
+
intermediateOptions[route === null || route === void 0 ? void 0 : route.urlPath] = ssgOptions(entryName, {
|
|
98
|
+
baseUrl: url
|
|
99
|
+
});
|
|
102
100
|
}
|
|
103
101
|
} else {
|
|
104
102
|
intermediateOptions[entryName] = ssgOptions(entryName, {
|
|
105
|
-
baseUrl: server
|
|
103
|
+
baseUrl: server === null || server === void 0 ? void 0 : server.baseUrl
|
|
106
104
|
});
|
|
107
105
|
}
|
|
108
106
|
}
|
|
@@ -110,12 +108,12 @@ const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
|
110
108
|
}
|
|
111
109
|
return false;
|
|
112
110
|
};
|
|
113
|
-
const openRouteSSR = (routes, entries = []) => routes.map((ssgRoute) => ({
|
|
111
|
+
export const openRouteSSR = (routes, entries = []) => routes.map((ssgRoute) => ({
|
|
114
112
|
...ssgRoute,
|
|
115
113
|
isSSR: entries.includes(ssgRoute.entryName),
|
|
116
114
|
bundle: `${SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
|
|
117
115
|
}));
|
|
118
|
-
const flattenRoutes = (routes) => {
|
|
116
|
+
export const flattenRoutes = (routes) => {
|
|
119
117
|
const parents = [];
|
|
120
118
|
const newRoutes = [];
|
|
121
119
|
const traverseRoute = (route) => {
|
|
@@ -140,16 +138,3 @@ const flattenRoutes = (routes) => {
|
|
|
140
138
|
routes.forEach(traverseRoute);
|
|
141
139
|
return newRoutes;
|
|
142
140
|
};
|
|
143
|
-
export {
|
|
144
|
-
flattenRoutes,
|
|
145
|
-
formatOutput,
|
|
146
|
-
formatPath,
|
|
147
|
-
getOutput,
|
|
148
|
-
getUrlPrefix,
|
|
149
|
-
isDynamicUrl,
|
|
150
|
-
openRouteSSR,
|
|
151
|
-
readJSONSpec,
|
|
152
|
-
replaceWithAlias,
|
|
153
|
-
standardOptions,
|
|
154
|
-
writeJSONSpec
|
|
155
|
-
};
|
|
@@ -3,62 +3,59 @@ 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
|
-
const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) =>
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
JSON.stringify({
|
|
6
|
+
export const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => {
|
|
7
|
+
return new Promise((resolve, reject) => {
|
|
8
|
+
var _cp_stderr, _cp_stdout;
|
|
9
|
+
const entries = ssgRoutes.map((route) => route.entryName);
|
|
10
|
+
const backup = openRouteSSR(pageRoutes, entries);
|
|
11
|
+
const total = backup.concat(apiRoutes);
|
|
12
|
+
const cp = childProcess.fork(path.join(__dirname, "process"), {
|
|
13
|
+
cwd: appDirectory,
|
|
14
|
+
silent: true
|
|
15
|
+
});
|
|
16
|
+
const appContext = api.useAppContext();
|
|
17
|
+
const plugins = appContext.serverInternalPlugins;
|
|
18
|
+
cp.send(JSON.stringify({
|
|
19
19
|
options,
|
|
20
20
|
renderRoutes: ssgRoutes,
|
|
21
21
|
routes: total,
|
|
22
22
|
appDirectory,
|
|
23
23
|
plugins
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
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
|
+
});
|
|
60
60
|
});
|
|
61
|
-
});
|
|
62
|
-
export {
|
|
63
|
-
createServer
|
|
64
61
|
};
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import EventEmitter from "events";
|
|
2
2
|
import { Readable } from "stream";
|
|
3
3
|
import httpMocks from "node-mocks-http";
|
|
4
|
-
const compile = (requestHandler) => (options, extend = {}) => new Promise((resolve, reject) => {
|
|
4
|
+
export const compile = (requestHandler) => (options, extend = {}) => new Promise((resolve, reject) => {
|
|
5
5
|
const req = httpMocks.createRequest({
|
|
6
6
|
...options,
|
|
7
7
|
eventEmitter: Readable
|
|
8
8
|
});
|
|
9
|
-
const res = httpMocks.createResponse({
|
|
9
|
+
const res = httpMocks.createResponse({
|
|
10
|
+
eventEmitter: EventEmitter
|
|
11
|
+
});
|
|
10
12
|
Object.assign(req, extend);
|
|
11
13
|
const proxyRes = new Proxy(res, {
|
|
12
14
|
get(obj, prop) {
|
|
@@ -30,6 +32,3 @@ const compile = (requestHandler) => (options, extend = {}) => new Promise((resol
|
|
|
30
32
|
reject(e);
|
|
31
33
|
}
|
|
32
34
|
});
|
|
33
|
-
export {
|
|
34
|
-
compile
|
|
35
|
-
};
|
|
@@ -8,13 +8,7 @@ process.on("message", async (chunk) => {
|
|
|
8
8
|
process.exit();
|
|
9
9
|
}
|
|
10
10
|
const context = JSON.parse(chunk);
|
|
11
|
-
const {
|
|
12
|
-
routes,
|
|
13
|
-
renderRoutes,
|
|
14
|
-
options,
|
|
15
|
-
appDirectory,
|
|
16
|
-
plugins
|
|
17
|
-
} = context;
|
|
11
|
+
const { routes, renderRoutes, options, appDirectory, plugins } = context;
|
|
18
12
|
let modernServer = null;
|
|
19
13
|
try {
|
|
20
14
|
const { server: serverOptions } = options;
|
|
@@ -36,11 +30,7 @@ process.on("message", async (chunk) => {
|
|
|
36
30
|
return;
|
|
37
31
|
}
|
|
38
32
|
const render = createRender(modernServer.getRequestHandler());
|
|
39
|
-
const renderPromiseAry = makeRender(
|
|
40
|
-
renderRoutes,
|
|
41
|
-
render,
|
|
42
|
-
port
|
|
43
|
-
);
|
|
33
|
+
const renderPromiseAry = makeRender(renderRoutes, render, port);
|
|
44
34
|
const htmlAry = await Promise.all(renderPromiseAry);
|
|
45
35
|
htmlAry.forEach((html) => {
|
|
46
36
|
process.send(html);
|
|
@@ -49,7 +39,7 @@ process.on("message", async (chunk) => {
|
|
|
49
39
|
modernServer.close();
|
|
50
40
|
});
|
|
51
41
|
} catch (e) {
|
|
52
|
-
modernServer
|
|
42
|
+
modernServer === null || modernServer === void 0 ? void 0 : modernServer.close();
|
|
53
43
|
process.stderr.write(e instanceof Error ? e.stack : e.toString());
|
|
54
44
|
}
|
|
55
45
|
});
|
package/dist/esm-node/types.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
"description": "A Progressive React Framework for modern web development.",
|
|
4
4
|
"homepage": "https://modernjs.dev",
|
|
5
5
|
"bugs": "https://github.com/web-infra-dev/modern.js/issues",
|
|
6
|
-
"repository":
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/web-infra-dev/modern.js",
|
|
9
|
+
"directory": "packages/cli/plugin-ssg"
|
|
10
|
+
},
|
|
7
11
|
"license": "MIT",
|
|
8
12
|
"keywords": [
|
|
9
13
|
"react",
|
|
@@ -11,7 +15,7 @@
|
|
|
11
15
|
"modern",
|
|
12
16
|
"modern.js"
|
|
13
17
|
],
|
|
14
|
-
"version": "2.
|
|
18
|
+
"version": "2.17.0",
|
|
15
19
|
"jsnext:source": "./src/index.ts",
|
|
16
20
|
"types": "./dist/types/index.d.ts",
|
|
17
21
|
"main": "./dist/cjs/index.js",
|
|
@@ -59,7 +63,7 @@
|
|
|
59
63
|
"node-mocks-http": "^1.10.1",
|
|
60
64
|
"normalize-path": "^3.0.0",
|
|
61
65
|
"portfinder": "^1.0.28",
|
|
62
|
-
"@modern-js/utils": "2.
|
|
66
|
+
"@modern-js/utils": "2.17.0"
|
|
63
67
|
},
|
|
64
68
|
"peerDependencies": {
|
|
65
69
|
"react-router-dom": ">=5.1.2"
|
|
@@ -76,11 +80,11 @@
|
|
|
76
80
|
"react": "^18",
|
|
77
81
|
"react-router-dom": "^6.8.1",
|
|
78
82
|
"typescript": "^4",
|
|
79
|
-
"@modern-js/app-tools": "2.
|
|
80
|
-
"@modern-js/prod-server": "2.
|
|
81
|
-
"@modern-js/types": "2.
|
|
82
|
-
"@scripts/build": "2.
|
|
83
|
-
"@scripts/jest-config": "2.
|
|
83
|
+
"@modern-js/app-tools": "2.17.0",
|
|
84
|
+
"@modern-js/prod-server": "2.17.0",
|
|
85
|
+
"@modern-js/types": "2.17.0",
|
|
86
|
+
"@scripts/build": "2.17.0",
|
|
87
|
+
"@scripts/jest-config": "2.17.0"
|
|
84
88
|
},
|
|
85
89
|
"sideEffects": false,
|
|
86
90
|
"publishConfig": {
|