@modern-js/plugin-ssg 2.0.0-beta.3 → 2.0.0-beta.4
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 +36 -0
- package/dist/js/modern/global.d.js +0 -0
- package/dist/js/modern/index.js +171 -155
- package/dist/js/modern/libs/make.js +44 -27
- package/dist/js/modern/libs/output.js +7 -4
- package/dist/js/modern/libs/replace.js +45 -27
- package/dist/js/modern/libs/util.js +91 -76
- package/dist/js/modern/server/consts.js +4 -1
- package/dist/js/modern/server/index.js +31 -28
- package/dist/js/modern/server/prerender.js +32 -15
- package/dist/js/modern/server/process.js +78 -57
- package/dist/js/modern/types.js +0 -1
- package/dist/js/node/global.d.js +0 -0
- package/dist/js/node/index.js +192 -166
- package/dist/js/node/libs/make.js +66 -32
- package/dist/js/node/libs/output.js +34 -13
- package/dist/js/node/libs/replace.js +68 -33
- package/dist/js/node/libs/util.js +107 -91
- package/dist/js/node/server/consts.js +22 -7
- package/dist/js/node/server/index.js +59 -39
- package/dist/js/node/server/prerender.js +56 -22
- package/dist/js/node/server/process.js +108 -62
- package/dist/js/node/types.js +0 -5
- package/dist/js/treeshaking/global.d.js +1 -0
- package/dist/js/treeshaking/index.js +339 -0
- package/dist/js/treeshaking/libs/make.js +83 -0
- package/dist/js/treeshaking/libs/output.js +13 -0
- package/dist/js/treeshaking/libs/replace.js +115 -0
- package/dist/js/treeshaking/libs/util.js +239 -0
- package/dist/js/treeshaking/server/consts.js +2 -0
- package/dist/js/treeshaking/server/index.js +63 -0
- package/dist/js/treeshaking/server/prerender.js +97 -0
- package/dist/js/treeshaking/server/process.js +226 -0
- package/dist/js/treeshaking/types.js +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/libs/util.d.ts +0 -1
- package/package.json +7 -12
|
@@ -1,86 +1,96 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import path from "path";
|
|
21
|
+
import {
|
|
22
|
+
ROUTE_SPEC_FILE,
|
|
23
|
+
fs,
|
|
24
|
+
isSingleEntry,
|
|
25
|
+
SERVER_BUNDLE_DIRECTORY
|
|
26
|
+
} from "@modern-js/utils";
|
|
27
|
+
function formatOutput(filename) {
|
|
7
28
|
const outputPath = path.extname(filename) ? filename : `${filename}/index.html`;
|
|
8
29
|
return outputPath;
|
|
9
30
|
}
|
|
10
|
-
|
|
31
|
+
function formatPath(str) {
|
|
11
32
|
let addr = str;
|
|
12
|
-
if (!addr || typeof addr !==
|
|
33
|
+
if (!addr || typeof addr !== "string") {
|
|
13
34
|
return addr;
|
|
14
35
|
}
|
|
15
|
-
if (addr.startsWith(
|
|
36
|
+
if (addr.startsWith(".")) {
|
|
16
37
|
addr = addr.slice(1);
|
|
17
38
|
}
|
|
18
|
-
if (!addr.startsWith(
|
|
39
|
+
if (!addr.startsWith("/")) {
|
|
19
40
|
addr = `/${addr}`;
|
|
20
41
|
}
|
|
21
|
-
if (addr.endsWith(
|
|
42
|
+
if (addr.endsWith("/") && addr !== "/") {
|
|
22
43
|
addr = addr.slice(0, addr.length - 1);
|
|
23
44
|
}
|
|
24
45
|
return addr;
|
|
25
46
|
}
|
|
26
|
-
|
|
27
|
-
return url.includes(
|
|
47
|
+
function isDynamicUrl(url) {
|
|
48
|
+
return url.includes(":");
|
|
28
49
|
}
|
|
29
|
-
|
|
30
|
-
let base =
|
|
50
|
+
function getUrlPrefix(route, baseUrl) {
|
|
51
|
+
let base = "";
|
|
31
52
|
if (Array.isArray(baseUrl)) {
|
|
32
|
-
const filters = baseUrl.filter(url => route.urlPath.includes(url));
|
|
53
|
+
const filters = baseUrl.filter((url) => route.urlPath.includes(url));
|
|
33
54
|
if (filters.length > 1) {
|
|
34
55
|
const matched = filters.sort((a, b) => a.length - b.length)[0];
|
|
35
|
-
|
|
36
|
-
// this should never happened
|
|
37
56
|
if (!matched) {
|
|
38
|
-
throw new Error(
|
|
57
|
+
throw new Error("");
|
|
39
58
|
}
|
|
40
59
|
base = matched;
|
|
41
60
|
}
|
|
42
61
|
} else {
|
|
43
62
|
base = baseUrl;
|
|
44
63
|
}
|
|
45
|
-
base = base ===
|
|
46
|
-
const entryName = route.entryName ===
|
|
64
|
+
base = base === "/" ? "" : base;
|
|
65
|
+
const entryName = route.entryName === "main" ? "" : route.entryName;
|
|
47
66
|
const prefix = `${base}/${entryName}`;
|
|
48
|
-
return prefix.endsWith(
|
|
67
|
+
return prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
|
|
49
68
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// or throw error for control-route
|
|
53
|
-
export function getOutput(route, base, agreed) {
|
|
54
|
-
const {
|
|
55
|
-
output
|
|
56
|
-
} = route;
|
|
69
|
+
function getOutput(route, base, agreed) {
|
|
70
|
+
const { output } = route;
|
|
57
71
|
if (output) {
|
|
58
72
|
return output;
|
|
59
73
|
}
|
|
60
74
|
if (agreed) {
|
|
61
|
-
const urlWithoutBase = route.urlPath.replace(base,
|
|
62
|
-
return urlWithoutBase.startsWith(
|
|
75
|
+
const urlWithoutBase = route.urlPath.replace(base, "");
|
|
76
|
+
return urlWithoutBase.startsWith("/") ? urlWithoutBase.slice(1) : urlWithoutBase;
|
|
63
77
|
}
|
|
64
|
-
throw new Error(
|
|
78
|
+
throw new Error(
|
|
79
|
+
`routing must provide output when calling createPage(), check ${route.urlPath}`
|
|
80
|
+
);
|
|
65
81
|
}
|
|
66
|
-
|
|
82
|
+
const readJSONSpec = (dir) => {
|
|
67
83
|
const routeJSONPath = path.join(dir, ROUTE_SPEC_FILE);
|
|
68
84
|
const routeJSON = require(routeJSONPath);
|
|
69
|
-
const {
|
|
70
|
-
routes
|
|
71
|
-
} = routeJSON;
|
|
85
|
+
const { routes } = routeJSON;
|
|
72
86
|
return routes;
|
|
73
87
|
};
|
|
74
|
-
|
|
88
|
+
const writeJSONSpec = (dir, routes) => {
|
|
75
89
|
const routeJSONPath = path.join(dir, ROUTE_SPEC_FILE);
|
|
76
|
-
fs.writeJSONSync(routeJSONPath, {
|
|
77
|
-
routes
|
|
78
|
-
}, {
|
|
79
|
-
spaces: 2
|
|
80
|
-
});
|
|
90
|
+
fs.writeJSONSync(routeJSONPath, { routes }, { spaces: 2 });
|
|
81
91
|
};
|
|
82
|
-
|
|
83
|
-
|
|
92
|
+
const replaceWithAlias = (base, filePath, alias) => path.posix.join(alias, path.posix.relative(base, filePath));
|
|
93
|
+
const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
84
94
|
if (ssgOptions === false) {
|
|
85
95
|
return false;
|
|
86
96
|
}
|
|
@@ -89,33 +99,29 @@ export const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
|
89
99
|
opt[entry.entryName] = ssgOptions;
|
|
90
100
|
return opt;
|
|
91
101
|
}, {});
|
|
92
|
-
} else if (typeof ssgOptions ===
|
|
102
|
+
} else if (typeof ssgOptions === "object") {
|
|
93
103
|
const isSingle = isSingleEntry(entrypoints);
|
|
94
|
-
if (isSingle && typeof ssgOptions.main ===
|
|
95
|
-
return {
|
|
96
|
-
main: ssgOptions
|
|
97
|
-
};
|
|
104
|
+
if (isSingle && typeof ssgOptions.main === "undefined") {
|
|
105
|
+
return { main: ssgOptions };
|
|
98
106
|
} else {
|
|
99
107
|
return ssgOptions;
|
|
100
108
|
}
|
|
101
|
-
} else if (typeof ssgOptions ===
|
|
109
|
+
} else if (typeof ssgOptions === "function") {
|
|
102
110
|
const intermediateOptions = {};
|
|
103
111
|
for (const entrypoint of entrypoints) {
|
|
104
|
-
const {
|
|
105
|
-
|
|
106
|
-
} = entrypoint;
|
|
107
|
-
// TODO: may be async function
|
|
108
|
-
if (Array.isArray(server === null || server === void 0 ? void 0 : server.baseUrl)) {
|
|
112
|
+
const { entryName } = entrypoint;
|
|
113
|
+
if (Array.isArray(server == null ? void 0 : server.baseUrl)) {
|
|
109
114
|
for (const url of server.baseUrl) {
|
|
110
|
-
const matchUrl = entryName ===
|
|
111
|
-
const route = routes.find(
|
|
112
|
-
intermediateOptions[route
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
const matchUrl = entryName === "main" ? url : `${url}/${entryName}`;
|
|
116
|
+
const route = routes.find((route2) => route2.urlPath === matchUrl);
|
|
117
|
+
intermediateOptions[route == null ? void 0 : route.urlPath] = ssgOptions(
|
|
118
|
+
entryName,
|
|
119
|
+
{ baseUrl: url }
|
|
120
|
+
);
|
|
115
121
|
}
|
|
116
122
|
} else {
|
|
117
123
|
intermediateOptions[entryName] = ssgOptions(entryName, {
|
|
118
|
-
baseUrl: server
|
|
124
|
+
baseUrl: server == null ? void 0 : server.baseUrl
|
|
119
125
|
});
|
|
120
126
|
}
|
|
121
127
|
}
|
|
@@ -123,29 +129,25 @@ export const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
|
123
129
|
}
|
|
124
130
|
return false;
|
|
125
131
|
};
|
|
126
|
-
|
|
132
|
+
const openRouteSSR = (routes, entries = []) => routes.map((ssgRoute) => __spreadProps(__spreadValues({}, ssgRoute), {
|
|
127
133
|
isSSR: entries.includes(ssgRoute.entryName),
|
|
128
134
|
bundle: `${SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
|
|
129
135
|
}));
|
|
130
|
-
|
|
131
|
-
// TODO: 过滤带有 server loader 的路由
|
|
132
|
-
export const flattenRoutes = routes => {
|
|
136
|
+
const flattenRoutes = (routes) => {
|
|
133
137
|
const parents = [];
|
|
134
138
|
const newRoutes = [];
|
|
135
|
-
const traverseRoute = route => {
|
|
139
|
+
const traverseRoute = (route) => {
|
|
136
140
|
const parent = parents[parents.length - 1];
|
|
137
|
-
let
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
newRoutes.push(_objectSpread(_objectSpread({}, route), {}, {
|
|
143
|
-
path
|
|
141
|
+
let path2 = parent ? `${parent.path}/${route.path || ""}`.replace(/\/+/g, "/") : route.path || "";
|
|
142
|
+
path2 = path2.replace(/\/$/, "");
|
|
143
|
+
if (route._component && (path2 !== "/" || path2 === "/" && !parent)) {
|
|
144
|
+
newRoutes.push(__spreadProps(__spreadValues({}, route), {
|
|
145
|
+
path: path2
|
|
144
146
|
}));
|
|
145
147
|
}
|
|
146
148
|
if (route.children) {
|
|
147
|
-
parents.push(
|
|
148
|
-
path
|
|
149
|
+
parents.push(__spreadProps(__spreadValues({}, route), {
|
|
150
|
+
path: path2
|
|
149
151
|
}));
|
|
150
152
|
route.children.forEach(traverseRoute);
|
|
151
153
|
parents.pop();
|
|
@@ -153,4 +155,17 @@ export const flattenRoutes = routes => {
|
|
|
153
155
|
};
|
|
154
156
|
routes.forEach(traverseRoute);
|
|
155
157
|
return newRoutes;
|
|
156
|
-
};
|
|
158
|
+
};
|
|
159
|
+
export {
|
|
160
|
+
flattenRoutes,
|
|
161
|
+
formatOutput,
|
|
162
|
+
formatPath,
|
|
163
|
+
getOutput,
|
|
164
|
+
getUrlPrefix,
|
|
165
|
+
isDynamicUrl,
|
|
166
|
+
openRouteSSR,
|
|
167
|
+
readJSONSpec,
|
|
168
|
+
replaceWithAlias,
|
|
169
|
+
standardOptions,
|
|
170
|
+
writeJSONSpec
|
|
171
|
+
};
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import childProcess from
|
|
2
|
-
import path from
|
|
3
|
-
import { logger } from
|
|
1
|
+
import childProcess from "child_process";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { logger } from "@modern-js/utils";
|
|
4
4
|
import { openRouteSSR } from "../libs/util";
|
|
5
5
|
import { CLOSE_SIGN } from "./consts";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// manually enable the server-side rendering configuration for all routes that require SSG
|
|
9
|
-
const entries = ssgRoutes.map(route => route.entryName);
|
|
6
|
+
const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
7
|
+
const entries = ssgRoutes.map((route) => route.entryName);
|
|
10
8
|
const backup = openRouteSSR(pageRoutes, entries);
|
|
11
9
|
const total = backup.concat(apiRoutes);
|
|
12
|
-
const cp = childProcess.fork(path.join(__dirname,
|
|
10
|
+
const cp = childProcess.fork(path.join(__dirname, "process"), {
|
|
13
11
|
cwd: appDirectory,
|
|
14
12
|
silent: true
|
|
15
13
|
});
|
|
16
14
|
const appContext = api.useAppContext();
|
|
17
15
|
const plugins = appContext.serverInternalPlugins;
|
|
18
|
-
cp.send(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
cp.send(
|
|
17
|
+
JSON.stringify({
|
|
18
|
+
options,
|
|
19
|
+
renderRoutes: ssgRoutes,
|
|
20
|
+
routes: total,
|
|
21
|
+
appDirectory,
|
|
22
|
+
plugins
|
|
23
|
+
})
|
|
24
|
+
);
|
|
25
25
|
const htmlChunks = [];
|
|
26
26
|
const htmlAry = [];
|
|
27
|
-
cp.on(
|
|
27
|
+
cp.on("message", (chunk) => {
|
|
28
28
|
if (chunk !== null) {
|
|
29
29
|
htmlChunks.push(chunk);
|
|
30
30
|
} else {
|
|
31
|
-
const html = htmlChunks.join(
|
|
31
|
+
const html = htmlChunks.join("");
|
|
32
32
|
htmlAry.push(html);
|
|
33
33
|
htmlChunks.length = 0;
|
|
34
34
|
}
|
|
@@ -37,24 +37,27 @@ export const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, app
|
|
|
37
37
|
resolve(htmlAry);
|
|
38
38
|
}
|
|
39
39
|
});
|
|
40
|
-
cp.stderr.on(
|
|
40
|
+
cp.stderr.on("data", (chunk) => {
|
|
41
41
|
const str = chunk.toString();
|
|
42
|
-
if (str.includes(
|
|
42
|
+
if (str.includes("Error")) {
|
|
43
43
|
logger.error(str);
|
|
44
|
-
reject(new Error(
|
|
45
|
-
cp.kill(
|
|
44
|
+
reject(new Error("ssg render failed"));
|
|
45
|
+
cp.kill("SIGKILL");
|
|
46
46
|
} else {
|
|
47
|
-
logger.info(str.replace(/[^\S\n]+/g,
|
|
47
|
+
logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
|
-
cp.stdout.on(
|
|
50
|
+
cp.stdout.on("data", (chunk) => {
|
|
51
51
|
const str = chunk.toString();
|
|
52
|
-
if (str.includes(
|
|
52
|
+
if (str.includes("Error")) {
|
|
53
53
|
logger.error(str);
|
|
54
|
-
reject(new Error(
|
|
55
|
-
cp.kill(
|
|
54
|
+
reject(new Error("ssg render failed"));
|
|
55
|
+
cp.kill("SIGKILL");
|
|
56
56
|
} else {
|
|
57
|
-
logger.info(str.replace(/[^\S\n]+/g,
|
|
57
|
+
logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
|
-
});
|
|
60
|
+
});
|
|
61
|
+
export {
|
|
62
|
+
createServer
|
|
63
|
+
};
|
|
@@ -1,36 +1,53 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import EventEmitter from "events";
|
|
21
|
+
import { Readable } from "stream";
|
|
22
|
+
import httpMocks from "node-mocks-http";
|
|
23
|
+
const compile = (requestHandler) => (options, extend = {}) => new Promise((resolve, reject) => {
|
|
24
|
+
const req = httpMocks.createRequest(__spreadProps(__spreadValues({}, options), {
|
|
9
25
|
eventEmitter: Readable
|
|
10
26
|
}));
|
|
11
|
-
const res = httpMocks.createResponse({
|
|
12
|
-
eventEmitter: EventEmitter
|
|
13
|
-
});
|
|
27
|
+
const res = httpMocks.createResponse({ eventEmitter: EventEmitter });
|
|
14
28
|
Object.assign(req, extend);
|
|
15
29
|
const proxyRes = new Proxy(res, {
|
|
16
30
|
get(obj, prop) {
|
|
17
|
-
if (typeof prop ===
|
|
31
|
+
if (typeof prop === "symbol" && !obj[prop]) {
|
|
18
32
|
return null;
|
|
19
33
|
}
|
|
20
34
|
return obj[prop];
|
|
21
35
|
}
|
|
22
36
|
});
|
|
23
|
-
res.on(
|
|
37
|
+
res.on("finish", () => {
|
|
24
38
|
if (res.statusCode !== 200) {
|
|
25
39
|
reject(new Error(res.statusMessage));
|
|
26
40
|
} else {
|
|
27
41
|
resolve(res._getData());
|
|
28
42
|
}
|
|
29
43
|
});
|
|
30
|
-
res.on(
|
|
44
|
+
res.on("error", (e) => reject(e));
|
|
31
45
|
try {
|
|
32
46
|
requestHandler(req, proxyRes);
|
|
33
47
|
} catch (e) {
|
|
34
48
|
reject(e);
|
|
35
49
|
}
|
|
36
|
-
});
|
|
50
|
+
});
|
|
51
|
+
export {
|
|
52
|
+
compile
|
|
53
|
+
};
|
|
@@ -1,63 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
3
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
4
|
+
};
|
|
5
|
+
var __async = (__this, __arguments, generator) => {
|
|
6
|
+
return new Promise((resolve, reject) => {
|
|
7
|
+
var fulfilled = (value) => {
|
|
8
|
+
try {
|
|
9
|
+
step(generator.next(value));
|
|
10
|
+
} catch (e) {
|
|
11
|
+
reject(e);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
var rejected = (value) => {
|
|
15
|
+
try {
|
|
16
|
+
step(generator.throw(value));
|
|
17
|
+
} catch (e) {
|
|
18
|
+
reject(e);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
22
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
import server from "@modern-js/prod-server";
|
|
26
|
+
import portfinder from "portfinder";
|
|
3
27
|
import { makeRender } from "../libs/make";
|
|
4
28
|
import { compile as createRender } from "./prerender";
|
|
5
29
|
import { CLOSE_SIGN } from "./consts";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const context = JSON.parse(chunk);
|
|
12
|
-
const {
|
|
13
|
-
routes,
|
|
14
|
-
renderRoutes,
|
|
15
|
-
options,
|
|
16
|
-
appDirectory,
|
|
17
|
-
plugins
|
|
18
|
-
} = context;
|
|
19
|
-
let modernServer = null;
|
|
20
|
-
try {
|
|
21
|
-
const {
|
|
22
|
-
server: serverOptions
|
|
23
|
-
} = options;
|
|
24
|
-
|
|
25
|
-
// start server in default port
|
|
26
|
-
const defaultPort = Number(process.env.PORT) || serverOptions.port;
|
|
27
|
-
portfinder.basePort = defaultPort;
|
|
28
|
-
const port = await portfinder.getPortPromise();
|
|
29
|
-
modernServer = await server({
|
|
30
|
-
pwd: appDirectory,
|
|
31
|
-
config: options,
|
|
32
|
-
routes,
|
|
33
|
-
staticGenerate: true,
|
|
34
|
-
internalPlugins: plugins
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// listen just for bff request in ssr page
|
|
38
|
-
modernServer.listen(port, async err => {
|
|
39
|
-
if (err) {
|
|
40
|
-
throw err;
|
|
30
|
+
var require_process = __commonJS({
|
|
31
|
+
"src/server/process.ts"(exports) {
|
|
32
|
+
process.on("message", (chunk) => __async(exports, null, function* () {
|
|
33
|
+
if (chunk === CLOSE_SIGN) {
|
|
34
|
+
process.exit();
|
|
41
35
|
}
|
|
42
|
-
|
|
43
|
-
|
|
36
|
+
const context = JSON.parse(chunk);
|
|
37
|
+
const {
|
|
38
|
+
routes,
|
|
39
|
+
renderRoutes,
|
|
40
|
+
options,
|
|
41
|
+
appDirectory,
|
|
42
|
+
plugins
|
|
43
|
+
} = context;
|
|
44
|
+
let modernServer = null;
|
|
45
|
+
try {
|
|
46
|
+
const { server: serverOptions } = options;
|
|
47
|
+
const defaultPort = Number(process.env.PORT) || serverOptions.port;
|
|
48
|
+
portfinder.basePort = defaultPort;
|
|
49
|
+
const port = yield portfinder.getPortPromise();
|
|
50
|
+
modernServer = yield server({
|
|
51
|
+
pwd: appDirectory,
|
|
52
|
+
config: options,
|
|
53
|
+
routes,
|
|
54
|
+
staticGenerate: true,
|
|
55
|
+
internalPlugins: plugins
|
|
56
|
+
});
|
|
57
|
+
modernServer.listen(port, (err) => __async(exports, null, function* () {
|
|
58
|
+
if (err) {
|
|
59
|
+
throw err;
|
|
60
|
+
}
|
|
61
|
+
if (!modernServer) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const render = createRender(modernServer.getRequestHandler());
|
|
65
|
+
const renderPromiseAry = makeRender(
|
|
66
|
+
renderRoutes,
|
|
67
|
+
render,
|
|
68
|
+
port
|
|
69
|
+
);
|
|
70
|
+
const htmlAry = yield Promise.all(renderPromiseAry);
|
|
71
|
+
htmlAry.forEach((html) => {
|
|
72
|
+
process.send(html);
|
|
73
|
+
process.send(null);
|
|
74
|
+
});
|
|
75
|
+
modernServer.close();
|
|
76
|
+
}));
|
|
77
|
+
} catch (e) {
|
|
78
|
+
modernServer == null ? void 0 : modernServer.close();
|
|
79
|
+
throw e;
|
|
44
80
|
}
|
|
45
|
-
|
|
46
|
-
// get server handler, render to ssr
|
|
47
|
-
const render = createRender(modernServer.getRequestHandler());
|
|
48
|
-
const renderPromiseAry = makeRender(renderRoutes, render, port);
|
|
49
|
-
|
|
50
|
-
// eslint-disable-next-line promise/no-promise-in-callback
|
|
51
|
-
const htmlAry = await Promise.all(renderPromiseAry);
|
|
52
|
-
htmlAry.forEach(html => {
|
|
53
|
-
process.send(html);
|
|
54
|
-
process.send(null);
|
|
55
|
-
});
|
|
56
|
-
modernServer.close();
|
|
57
|
-
});
|
|
58
|
-
} catch (e) {
|
|
59
|
-
var _modernServer;
|
|
60
|
-
(_modernServer = modernServer) === null || _modernServer === void 0 ? void 0 : _modernServer.close();
|
|
61
|
-
throw e;
|
|
81
|
+
}));
|
|
62
82
|
}
|
|
63
|
-
});
|
|
83
|
+
});
|
|
84
|
+
export default require_process();
|
package/dist/js/modern/types.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
File without changes
|