@modern-js/plugin-ssg 0.0.0-next-45d726979 → 0.0.0-next-0bf5ec13d2
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 +2 -2
- package/dist/js/modern/index.js +189 -0
- package/dist/js/modern/libs/make.js +50 -0
- package/dist/js/modern/libs/output.js +15 -0
- package/dist/js/modern/libs/replace.js +63 -0
- package/dist/js/modern/libs/util.js +171 -0
- package/dist/js/modern/server/consts.js +4 -0
- package/dist/js/modern/server/index.js +63 -0
- package/dist/js/modern/server/prerender.js +53 -0
- package/dist/js/modern/server/process.js +84 -0
- package/dist/js/modern/types.js +0 -0
- package/dist/js/node/index.js +207 -0
- package/dist/js/node/libs/make.js +78 -0
- package/dist/js/node/libs/output.js +44 -0
- package/dist/js/node/libs/replace.js +91 -0
- package/dist/js/node/libs/util.js +203 -0
- package/dist/js/node/server/consts.js +27 -0
- package/dist/js/node/server/index.js +92 -0
- package/dist/js/node/server/prerender.js +80 -0
- package/dist/js/node/server/process.js +93 -0
- package/dist/js/node/types.js +15 -0
- package/dist/js/treeshaking/index.js +334 -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/package.json +9 -9
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
|
+
mod
|
|
39
|
+
));
|
|
40
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
|
+
var util_exports = {};
|
|
42
|
+
__export(util_exports, {
|
|
43
|
+
flattenRoutes: () => flattenRoutes,
|
|
44
|
+
formatOutput: () => formatOutput,
|
|
45
|
+
formatPath: () => formatPath,
|
|
46
|
+
getOutput: () => getOutput,
|
|
47
|
+
getUrlPrefix: () => getUrlPrefix,
|
|
48
|
+
isDynamicUrl: () => isDynamicUrl,
|
|
49
|
+
openRouteSSR: () => openRouteSSR,
|
|
50
|
+
readJSONSpec: () => readJSONSpec,
|
|
51
|
+
replaceWithAlias: () => replaceWithAlias,
|
|
52
|
+
standardOptions: () => standardOptions,
|
|
53
|
+
writeJSONSpec: () => writeJSONSpec
|
|
54
|
+
});
|
|
55
|
+
module.exports = __toCommonJS(util_exports);
|
|
56
|
+
var import_path = __toESM(require("path"));
|
|
57
|
+
var import_utils = require("@modern-js/utils");
|
|
58
|
+
function formatOutput(filename) {
|
|
59
|
+
const outputPath = import_path.default.extname(filename) ? filename : `${filename}/index.html`;
|
|
60
|
+
return outputPath;
|
|
61
|
+
}
|
|
62
|
+
function formatPath(str) {
|
|
63
|
+
let addr = str;
|
|
64
|
+
if (!addr || typeof addr !== "string") {
|
|
65
|
+
return addr;
|
|
66
|
+
}
|
|
67
|
+
if (addr.startsWith(".")) {
|
|
68
|
+
addr = addr.slice(1);
|
|
69
|
+
}
|
|
70
|
+
if (!addr.startsWith("/")) {
|
|
71
|
+
addr = `/${addr}`;
|
|
72
|
+
}
|
|
73
|
+
if (addr.endsWith("/") && addr !== "/") {
|
|
74
|
+
addr = addr.slice(0, addr.length - 1);
|
|
75
|
+
}
|
|
76
|
+
return addr;
|
|
77
|
+
}
|
|
78
|
+
function isDynamicUrl(url) {
|
|
79
|
+
return url.includes(":");
|
|
80
|
+
}
|
|
81
|
+
function getUrlPrefix(route, baseUrl) {
|
|
82
|
+
let base = "";
|
|
83
|
+
if (Array.isArray(baseUrl)) {
|
|
84
|
+
const filters = baseUrl.filter((url) => route.urlPath.includes(url));
|
|
85
|
+
if (filters.length > 1) {
|
|
86
|
+
const matched = filters.sort((a, b) => a.length - b.length)[0];
|
|
87
|
+
if (!matched) {
|
|
88
|
+
throw new Error("");
|
|
89
|
+
}
|
|
90
|
+
base = matched;
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
base = baseUrl;
|
|
94
|
+
}
|
|
95
|
+
base = base === "/" ? "" : base;
|
|
96
|
+
const entryName = route.entryName === "main" ? "" : route.entryName;
|
|
97
|
+
const prefix = `${base}/${entryName}`;
|
|
98
|
+
return prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
|
|
99
|
+
}
|
|
100
|
+
function getOutput(route, base, agreed) {
|
|
101
|
+
const { output } = route;
|
|
102
|
+
if (output) {
|
|
103
|
+
return output;
|
|
104
|
+
}
|
|
105
|
+
if (agreed) {
|
|
106
|
+
const urlWithoutBase = route.urlPath.replace(base, "");
|
|
107
|
+
return urlWithoutBase.startsWith("/") ? urlWithoutBase.slice(1) : urlWithoutBase;
|
|
108
|
+
}
|
|
109
|
+
throw new Error(
|
|
110
|
+
`routing must provide output when calling createPage(), check ${route.urlPath}`
|
|
111
|
+
);
|
|
112
|
+
}
|
|
113
|
+
const readJSONSpec = (dir) => {
|
|
114
|
+
const routeJSONPath = import_path.default.join(dir, import_utils.ROUTE_SPEC_FILE);
|
|
115
|
+
const routeJSON = require(routeJSONPath);
|
|
116
|
+
const { routes } = routeJSON;
|
|
117
|
+
return routes;
|
|
118
|
+
};
|
|
119
|
+
const writeJSONSpec = (dir, routes) => {
|
|
120
|
+
const routeJSONPath = import_path.default.join(dir, import_utils.ROUTE_SPEC_FILE);
|
|
121
|
+
import_utils.fs.writeJSONSync(routeJSONPath, { routes }, { spaces: 2 });
|
|
122
|
+
};
|
|
123
|
+
const replaceWithAlias = (base, filePath, alias) => import_path.default.posix.join(alias, import_path.default.posix.relative(base, filePath));
|
|
124
|
+
const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
125
|
+
if (ssgOptions === false) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
if (ssgOptions === true) {
|
|
129
|
+
return entrypoints.reduce((opt, entry) => {
|
|
130
|
+
opt[entry.entryName] = ssgOptions;
|
|
131
|
+
return opt;
|
|
132
|
+
}, {});
|
|
133
|
+
} else if (typeof ssgOptions === "object") {
|
|
134
|
+
const isSingle = (0, import_utils.isSingleEntry)(entrypoints);
|
|
135
|
+
if (isSingle && typeof ssgOptions.main === "undefined") {
|
|
136
|
+
return { main: ssgOptions };
|
|
137
|
+
} else {
|
|
138
|
+
return ssgOptions;
|
|
139
|
+
}
|
|
140
|
+
} else if (typeof ssgOptions === "function") {
|
|
141
|
+
const intermediateOptions = {};
|
|
142
|
+
for (const entrypoint of entrypoints) {
|
|
143
|
+
const { entryName } = entrypoint;
|
|
144
|
+
if (Array.isArray(server == null ? void 0 : server.baseUrl)) {
|
|
145
|
+
for (const url of server.baseUrl) {
|
|
146
|
+
const matchUrl = entryName === "main" ? url : `${url}/${entryName}`;
|
|
147
|
+
const route = routes.find((route2) => route2.urlPath === matchUrl);
|
|
148
|
+
intermediateOptions[route == null ? void 0 : route.urlPath] = ssgOptions(
|
|
149
|
+
entryName,
|
|
150
|
+
{ baseUrl: url }
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
} else {
|
|
154
|
+
intermediateOptions[entryName] = ssgOptions(entryName, {
|
|
155
|
+
baseUrl: server == null ? void 0 : server.baseUrl
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return intermediateOptions;
|
|
160
|
+
}
|
|
161
|
+
return false;
|
|
162
|
+
};
|
|
163
|
+
const openRouteSSR = (routes, entries = []) => routes.map((ssgRoute) => __spreadProps(__spreadValues({}, ssgRoute), {
|
|
164
|
+
isSSR: entries.includes(ssgRoute.entryName),
|
|
165
|
+
bundle: `${import_utils.SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
|
|
166
|
+
}));
|
|
167
|
+
const flattenRoutes = (routes) => {
|
|
168
|
+
const parents = [];
|
|
169
|
+
const newRoutes = [];
|
|
170
|
+
const traverseRoute = (route) => {
|
|
171
|
+
const parent = parents[parents.length - 1];
|
|
172
|
+
let path2 = parent ? `${parent.path}/${route.path || ""}`.replace(/\/+/g, "/") : route.path || "";
|
|
173
|
+
path2 = path2.replace(/\/$/, "");
|
|
174
|
+
if (route._component && (path2 !== "/" || path2 === "/" && !parent)) {
|
|
175
|
+
newRoutes.push(__spreadProps(__spreadValues({}, route), {
|
|
176
|
+
path: path2
|
|
177
|
+
}));
|
|
178
|
+
}
|
|
179
|
+
if (route.children) {
|
|
180
|
+
parents.push(__spreadProps(__spreadValues({}, route), {
|
|
181
|
+
path: path2
|
|
182
|
+
}));
|
|
183
|
+
route.children.forEach(traverseRoute);
|
|
184
|
+
parents.pop();
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
routes.forEach(traverseRoute);
|
|
188
|
+
return newRoutes;
|
|
189
|
+
};
|
|
190
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
191
|
+
0 && (module.exports = {
|
|
192
|
+
flattenRoutes,
|
|
193
|
+
formatOutput,
|
|
194
|
+
formatPath,
|
|
195
|
+
getOutput,
|
|
196
|
+
getUrlPrefix,
|
|
197
|
+
isDynamicUrl,
|
|
198
|
+
openRouteSSR,
|
|
199
|
+
readJSONSpec,
|
|
200
|
+
replaceWithAlias,
|
|
201
|
+
standardOptions,
|
|
202
|
+
writeJSONSpec
|
|
203
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var consts_exports = {};
|
|
19
|
+
__export(consts_exports, {
|
|
20
|
+
CLOSE_SIGN: () => CLOSE_SIGN
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(consts_exports);
|
|
23
|
+
const CLOSE_SIGN = "modern_close_server";
|
|
24
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
25
|
+
0 && (module.exports = {
|
|
26
|
+
CLOSE_SIGN
|
|
27
|
+
});
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var server_exports = {};
|
|
25
|
+
__export(server_exports, {
|
|
26
|
+
createServer: () => createServer
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(server_exports);
|
|
29
|
+
var import_child_process = __toESM(require("child_process"));
|
|
30
|
+
var import_path = __toESM(require("path"));
|
|
31
|
+
var import_utils = require("@modern-js/utils");
|
|
32
|
+
var import_util = require("../libs/util");
|
|
33
|
+
var import_consts = require("./consts");
|
|
34
|
+
const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
35
|
+
const entries = ssgRoutes.map((route) => route.entryName);
|
|
36
|
+
const backup = (0, import_util.openRouteSSR)(pageRoutes, entries);
|
|
37
|
+
const total = backup.concat(apiRoutes);
|
|
38
|
+
const cp = import_child_process.default.fork(import_path.default.join(__dirname, "process"), {
|
|
39
|
+
cwd: appDirectory,
|
|
40
|
+
silent: true
|
|
41
|
+
});
|
|
42
|
+
const appContext = api.useAppContext();
|
|
43
|
+
const plugins = appContext.serverInternalPlugins;
|
|
44
|
+
cp.send(
|
|
45
|
+
JSON.stringify({
|
|
46
|
+
options,
|
|
47
|
+
renderRoutes: ssgRoutes,
|
|
48
|
+
routes: total,
|
|
49
|
+
appDirectory,
|
|
50
|
+
plugins
|
|
51
|
+
})
|
|
52
|
+
);
|
|
53
|
+
const htmlChunks = [];
|
|
54
|
+
const htmlAry = [];
|
|
55
|
+
cp.on("message", (chunk) => {
|
|
56
|
+
if (chunk !== null) {
|
|
57
|
+
htmlChunks.push(chunk);
|
|
58
|
+
} else {
|
|
59
|
+
const html = htmlChunks.join("");
|
|
60
|
+
htmlAry.push(html);
|
|
61
|
+
htmlChunks.length = 0;
|
|
62
|
+
}
|
|
63
|
+
if (htmlAry.length === ssgRoutes.length) {
|
|
64
|
+
cp.send(import_consts.CLOSE_SIGN);
|
|
65
|
+
resolve(htmlAry);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
cp.stderr.on("data", (chunk) => {
|
|
69
|
+
const str = chunk.toString();
|
|
70
|
+
if (str.includes("Error")) {
|
|
71
|
+
import_utils.logger.error(str);
|
|
72
|
+
reject(new Error("ssg render failed"));
|
|
73
|
+
cp.kill("SIGKILL");
|
|
74
|
+
} else {
|
|
75
|
+
import_utils.logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
cp.stdout.on("data", (chunk) => {
|
|
79
|
+
const str = chunk.toString();
|
|
80
|
+
if (str.includes("Error")) {
|
|
81
|
+
import_utils.logger.error(str);
|
|
82
|
+
reject(new Error("ssg render failed"));
|
|
83
|
+
cp.kill("SIGKILL");
|
|
84
|
+
} else {
|
|
85
|
+
import_utils.logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
+
0 && (module.exports = {
|
|
91
|
+
createServer
|
|
92
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
|
+
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
27
|
+
};
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
35
|
+
};
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
38
|
+
mod
|
|
39
|
+
));
|
|
40
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
41
|
+
var prerender_exports = {};
|
|
42
|
+
__export(prerender_exports, {
|
|
43
|
+
compile: () => compile
|
|
44
|
+
});
|
|
45
|
+
module.exports = __toCommonJS(prerender_exports);
|
|
46
|
+
var import_events = __toESM(require("events"));
|
|
47
|
+
var import_stream = require("stream");
|
|
48
|
+
var import_node_mocks_http = __toESM(require("node-mocks-http"));
|
|
49
|
+
const compile = (requestHandler) => (options, extend = {}) => new Promise((resolve, reject) => {
|
|
50
|
+
const req = import_node_mocks_http.default.createRequest(__spreadProps(__spreadValues({}, options), {
|
|
51
|
+
eventEmitter: import_stream.Readable
|
|
52
|
+
}));
|
|
53
|
+
const res = import_node_mocks_http.default.createResponse({ eventEmitter: import_events.default });
|
|
54
|
+
Object.assign(req, extend);
|
|
55
|
+
const proxyRes = new Proxy(res, {
|
|
56
|
+
get(obj, prop) {
|
|
57
|
+
if (typeof prop === "symbol" && !obj[prop]) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
return obj[prop];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
res.on("finish", () => {
|
|
64
|
+
if (res.statusCode !== 200) {
|
|
65
|
+
reject(new Error(res.statusMessage));
|
|
66
|
+
} else {
|
|
67
|
+
resolve(res._getData());
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
res.on("error", (e) => reject(e));
|
|
71
|
+
try {
|
|
72
|
+
requestHandler(req, proxyRes);
|
|
73
|
+
} catch (e) {
|
|
74
|
+
reject(e);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
78
|
+
0 && (module.exports = {
|
|
79
|
+
compile
|
|
80
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from))
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
}
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
17
|
+
mod
|
|
18
|
+
));
|
|
19
|
+
var __async = (__this, __arguments, generator) => {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
var fulfilled = (value) => {
|
|
22
|
+
try {
|
|
23
|
+
step(generator.next(value));
|
|
24
|
+
} catch (e) {
|
|
25
|
+
reject(e);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
var rejected = (value) => {
|
|
29
|
+
try {
|
|
30
|
+
step(generator.throw(value));
|
|
31
|
+
} catch (e) {
|
|
32
|
+
reject(e);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
36
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
var import_prod_server = __toESM(require("@modern-js/prod-server"));
|
|
40
|
+
var import_portfinder = __toESM(require("portfinder"));
|
|
41
|
+
var import_make = require("../libs/make");
|
|
42
|
+
var import_prerender = require("./prerender");
|
|
43
|
+
var import_consts = require("./consts");
|
|
44
|
+
process.on("message", (chunk) => __async(exports, null, function* () {
|
|
45
|
+
if (chunk === import_consts.CLOSE_SIGN) {
|
|
46
|
+
process.exit();
|
|
47
|
+
}
|
|
48
|
+
const context = JSON.parse(chunk);
|
|
49
|
+
const {
|
|
50
|
+
routes,
|
|
51
|
+
renderRoutes,
|
|
52
|
+
options,
|
|
53
|
+
appDirectory,
|
|
54
|
+
plugins
|
|
55
|
+
} = context;
|
|
56
|
+
let modernServer = null;
|
|
57
|
+
try {
|
|
58
|
+
const { server: serverOptions } = options;
|
|
59
|
+
const defaultPort = Number(process.env.PORT) || serverOptions.port;
|
|
60
|
+
import_portfinder.default.basePort = defaultPort;
|
|
61
|
+
const port = yield import_portfinder.default.getPortPromise();
|
|
62
|
+
modernServer = yield (0, import_prod_server.default)({
|
|
63
|
+
pwd: appDirectory,
|
|
64
|
+
config: options,
|
|
65
|
+
routes,
|
|
66
|
+
staticGenerate: true,
|
|
67
|
+
internalPlugins: plugins
|
|
68
|
+
});
|
|
69
|
+
modernServer.listen(port, (err) => __async(exports, null, function* () {
|
|
70
|
+
if (err) {
|
|
71
|
+
throw err;
|
|
72
|
+
}
|
|
73
|
+
if (!modernServer) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const render = (0, import_prerender.compile)(modernServer.getRequestHandler());
|
|
77
|
+
const renderPromiseAry = (0, import_make.makeRender)(
|
|
78
|
+
renderRoutes,
|
|
79
|
+
render,
|
|
80
|
+
port
|
|
81
|
+
);
|
|
82
|
+
const htmlAry = yield Promise.all(renderPromiseAry);
|
|
83
|
+
htmlAry.forEach((html) => {
|
|
84
|
+
process.send(html);
|
|
85
|
+
process.send(null);
|
|
86
|
+
});
|
|
87
|
+
modernServer.close();
|
|
88
|
+
}));
|
|
89
|
+
} catch (e) {
|
|
90
|
+
modernServer == null ? void 0 : modernServer.close();
|
|
91
|
+
throw e;
|
|
92
|
+
}
|
|
93
|
+
}));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var types_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(types_exports);
|