@modern-js/plugin-ssg 2.35.0 → 2.36.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/dist/cjs/index.js +61 -43
- package/dist/cjs/libs/make.js +41 -22
- package/dist/cjs/libs/output.js +40 -14
- package/dist/cjs/libs/replace.js +37 -18
- package/dist/cjs/libs/util.js +70 -63
- package/dist/cjs/server/consts.js +24 -7
- package/dist/cjs/server/index.js +46 -20
- package/dist/cjs/server/prerender.js +41 -15
- package/dist/cjs/server/process.js +34 -17
- package/dist/cjs/types.js +15 -3
- package/dist/esm/index.js +8 -4
- package/dist/esm/libs/make.js +7 -3
- package/dist/esm/libs/output.js +4 -1
- package/dist/esm/libs/replace.js +6 -2
- package/dist/esm/libs/util.js +28 -18
- package/dist/esm/server/consts.js +4 -1
- package/dist/esm/server/index.js +7 -4
- package/dist/esm/server/prerender.js +4 -1
- package/dist/esm/server/process.js +3 -3
- package/dist/esm/types.js +0 -1
- package/dist/esm-node/index.js +6 -2
- package/dist/esm-node/libs/make.js +6 -2
- package/dist/esm-node/libs/output.js +4 -1
- package/dist/esm-node/libs/replace.js +6 -2
- package/dist/esm-node/libs/util.js +27 -17
- package/dist/esm-node/server/consts.js +4 -1
- package/dist/esm-node/server/index.js +4 -1
- package/dist/esm-node/server/prerender.js +4 -1
- package/dist/esm-node/server/process.js +1 -2
- package/dist/esm-node/types.js +0 -1
- package/package.json +7 -7
package/dist/cjs/server/index.js
CHANGED
|
@@ -1,25 +1,47 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var server_exports = {};
|
|
30
|
+
__export(server_exports, {
|
|
31
|
+
createServer: () => createServer
|
|
10
32
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
33
|
+
module.exports = __toCommonJS(server_exports);
|
|
34
|
+
var import_child_process = __toESM(require("child_process"));
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
var import_utils = require("@modern-js/utils");
|
|
37
|
+
var import_util = require("../libs/util");
|
|
38
|
+
var import_consts = require("./consts");
|
|
17
39
|
const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
18
40
|
var _cp_stderr, _cp_stdout;
|
|
19
41
|
const entries = ssgRoutes.map((route) => route.entryName);
|
|
20
|
-
const backup = (0,
|
|
42
|
+
const backup = (0, import_util.openRouteSSR)(pageRoutes, entries);
|
|
21
43
|
const total = backup.concat(apiRoutes);
|
|
22
|
-
const cp =
|
|
44
|
+
const cp = import_child_process.default.fork(import_path.default.join(__dirname, "process"), {
|
|
23
45
|
cwd: appDirectory,
|
|
24
46
|
silent: true
|
|
25
47
|
});
|
|
@@ -43,28 +65,32 @@ const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, appDirecto
|
|
|
43
65
|
htmlChunks.length = 0;
|
|
44
66
|
}
|
|
45
67
|
if (htmlAry.length === ssgRoutes.length) {
|
|
46
|
-
cp.send(
|
|
68
|
+
cp.send(import_consts.CLOSE_SIGN);
|
|
47
69
|
resolve(htmlAry);
|
|
48
70
|
}
|
|
49
71
|
});
|
|
50
72
|
(_cp_stderr = cp.stderr) === null || _cp_stderr === void 0 ? void 0 : _cp_stderr.on("data", (chunk) => {
|
|
51
73
|
const str = chunk.toString();
|
|
52
74
|
if (str.includes("Error")) {
|
|
53
|
-
|
|
75
|
+
import_utils.logger.error(str);
|
|
54
76
|
reject(new Error("ssg render failed"));
|
|
55
77
|
cp.kill("SIGKILL");
|
|
56
78
|
} else {
|
|
57
|
-
|
|
79
|
+
import_utils.logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
58
80
|
}
|
|
59
81
|
});
|
|
60
82
|
(_cp_stdout = cp.stdout) === null || _cp_stdout === void 0 ? void 0 : _cp_stdout.on("data", (chunk) => {
|
|
61
83
|
const str = chunk.toString();
|
|
62
84
|
if (str.includes("Error")) {
|
|
63
|
-
|
|
85
|
+
import_utils.logger.error(str);
|
|
64
86
|
reject(new Error("ssg render failed"));
|
|
65
87
|
cp.kill("SIGKILL");
|
|
66
88
|
} else {
|
|
67
|
-
|
|
89
|
+
import_utils.logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
68
90
|
}
|
|
69
91
|
});
|
|
70
92
|
});
|
|
93
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
94
|
+
0 && (module.exports = {
|
|
95
|
+
createServer
|
|
96
|
+
});
|
|
@@ -1,24 +1,46 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
9
17
|
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var prerender_exports = {};
|
|
30
|
+
__export(prerender_exports, {
|
|
31
|
+
compile: () => compile
|
|
10
32
|
});
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
33
|
+
module.exports = __toCommonJS(prerender_exports);
|
|
34
|
+
var import_events = __toESM(require("events"));
|
|
35
|
+
var import_stream = require("stream");
|
|
36
|
+
var import_node_mocks_http = __toESM(require("node-mocks-http"));
|
|
15
37
|
const compile = (requestHandler) => (options, extend = {}) => new Promise((resolve, reject) => {
|
|
16
|
-
const req =
|
|
38
|
+
const req = import_node_mocks_http.default.createRequest({
|
|
17
39
|
...options,
|
|
18
|
-
eventEmitter:
|
|
40
|
+
eventEmitter: import_stream.Readable
|
|
19
41
|
});
|
|
20
|
-
const res =
|
|
21
|
-
eventEmitter:
|
|
42
|
+
const res = import_node_mocks_http.default.createResponse({
|
|
43
|
+
eventEmitter: import_events.default
|
|
22
44
|
});
|
|
23
45
|
Object.assign(req, extend);
|
|
24
46
|
const proxyRes = new Proxy(res, {
|
|
@@ -43,3 +65,7 @@ const compile = (requestHandler) => (options, extend = {}) => new Promise((resol
|
|
|
43
65
|
reject(e);
|
|
44
66
|
}
|
|
45
67
|
});
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
compile
|
|
71
|
+
});
|
|
@@ -1,15 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (let key of __getOwnPropNames(from))
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
12
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
13
|
+
}
|
|
14
|
+
return to;
|
|
15
|
+
};
|
|
16
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
17
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
18
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
19
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
20
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
|
+
mod
|
|
23
|
+
));
|
|
24
|
+
var import_prod_server = __toESM(require("@modern-js/prod-server"));
|
|
25
|
+
var import_portfinder = __toESM(require("portfinder"));
|
|
26
|
+
var import_make = require("../libs/make");
|
|
27
|
+
var import_prerender = require("./prerender");
|
|
28
|
+
var import_consts = require("./consts");
|
|
11
29
|
process.on("message", async (chunk) => {
|
|
12
|
-
if (chunk ===
|
|
30
|
+
if (chunk === import_consts.CLOSE_SIGN) {
|
|
13
31
|
process.exit();
|
|
14
32
|
}
|
|
15
33
|
const context = JSON.parse(chunk);
|
|
@@ -18,9 +36,9 @@ process.on("message", async (chunk) => {
|
|
|
18
36
|
try {
|
|
19
37
|
const { server: serverOptions } = options;
|
|
20
38
|
const defaultPort = Number(process.env.PORT) || serverOptions.port;
|
|
21
|
-
|
|
22
|
-
const port = await
|
|
23
|
-
modernServer = await (0,
|
|
39
|
+
import_portfinder.default.basePort = defaultPort;
|
|
40
|
+
const port = await import_portfinder.default.getPortPromise();
|
|
41
|
+
modernServer = await (0, import_prod_server.default)({
|
|
24
42
|
pwd: appDirectory,
|
|
25
43
|
config: options,
|
|
26
44
|
routes,
|
|
@@ -34,8 +52,8 @@ process.on("message", async (chunk) => {
|
|
|
34
52
|
if (!modernServer) {
|
|
35
53
|
return;
|
|
36
54
|
}
|
|
37
|
-
const render = (0,
|
|
38
|
-
const renderPromiseAry = (0,
|
|
55
|
+
const render = (0, import_prerender.compile)(modernServer.getRequestHandler());
|
|
56
|
+
const renderPromiseAry = (0, import_make.makeRender)(renderRoutes, render, port);
|
|
39
57
|
const htmlAry = await Promise.all(renderPromiseAry);
|
|
40
58
|
htmlAry.forEach((html) => {
|
|
41
59
|
process.send(html);
|
|
@@ -44,8 +62,7 @@ process.on("message", async (chunk) => {
|
|
|
44
62
|
modernServer.close();
|
|
45
63
|
});
|
|
46
64
|
} catch (e) {
|
|
47
|
-
|
|
48
|
-
(_modernServer = modernServer) === null || _modernServer === void 0 ? void 0 : _modernServer.close();
|
|
65
|
+
modernServer === null || modernServer === void 0 ? void 0 : modernServer.close();
|
|
49
66
|
process.stderr.write(e instanceof Error ? e.stack : e.toString());
|
|
50
67
|
}
|
|
51
68
|
});
|
package/dist/cjs/types.js
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __copyProps = (to, from, except, desc) => {
|
|
7
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
8
|
+
for (let key of __getOwnPropNames(from))
|
|
9
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
10
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
11
|
+
}
|
|
12
|
+
return to;
|
|
13
|
+
};
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var types_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(types_exports);
|
package/dist/esm/index.js
CHANGED
|
@@ -10,7 +10,7 @@ import { createServer } from "./server";
|
|
|
10
10
|
import { writeHtmlFile } from "./libs/output";
|
|
11
11
|
import { replaceRoute } from "./libs/replace";
|
|
12
12
|
import { makeRoute } from "./libs/make";
|
|
13
|
-
|
|
13
|
+
var ssgPlugin = function() {
|
|
14
14
|
return {
|
|
15
15
|
name: "@modern-js/plugin-ssg",
|
|
16
16
|
pre: [
|
|
@@ -46,8 +46,8 @@ export var ssgPlugin = function() {
|
|
|
46
46
|
var flattedRoutes = flattenRoutes(routes);
|
|
47
47
|
agreedRouteMap[entryName] = flattedRoutes;
|
|
48
48
|
return {
|
|
49
|
-
entrypoint
|
|
50
|
-
routes
|
|
49
|
+
entrypoint,
|
|
50
|
+
routes
|
|
51
51
|
};
|
|
52
52
|
},
|
|
53
53
|
afterBuild: function afterBuild() {
|
|
@@ -176,4 +176,8 @@ export var ssgPlugin = function() {
|
|
|
176
176
|
}
|
|
177
177
|
};
|
|
178
178
|
};
|
|
179
|
-
|
|
179
|
+
var src_default = ssgPlugin;
|
|
180
|
+
export {
|
|
181
|
+
src_default as default,
|
|
182
|
+
ssgPlugin
|
|
183
|
+
};
|
package/dist/esm/libs/make.js
CHANGED
|
@@ -2,7 +2,7 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
|
2
2
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import normalize from "normalize-path";
|
|
5
|
-
|
|
5
|
+
function makeRender(ssgRoutes, render, port) {
|
|
6
6
|
return ssgRoutes.map(function(ssgRoute) {
|
|
7
7
|
return render({
|
|
8
8
|
url: ssgRoute.urlPath,
|
|
@@ -13,13 +13,13 @@ export function makeRender(ssgRoutes, render, port) {
|
|
|
13
13
|
});
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
|
-
|
|
16
|
+
function makeRoute(baseRoute, route) {
|
|
17
17
|
var headers = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
18
18
|
var urlPath = baseRoute.urlPath, entryPath = baseRoute.entryPath;
|
|
19
19
|
if (typeof route === "string") {
|
|
20
20
|
return _object_spread_props(_object_spread({}, baseRoute), {
|
|
21
21
|
urlPath: normalize("".concat(urlPath).concat(route)) || "/",
|
|
22
|
-
headers
|
|
22
|
+
headers,
|
|
23
23
|
output: path.join(entryPath, "..".concat(route === "/" ? "" : route))
|
|
24
24
|
});
|
|
25
25
|
} else {
|
|
@@ -30,3 +30,7 @@ export function makeRoute(baseRoute, route) {
|
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
+
export {
|
|
34
|
+
makeRender,
|
|
35
|
+
makeRoute
|
|
36
|
+
};
|
package/dist/esm/libs/output.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { fs } from "@modern-js/utils";
|
|
3
|
-
|
|
3
|
+
function writeHtmlFile(htmlAry, ssgRoutes, baseDir) {
|
|
4
4
|
htmlAry.forEach(function(html, index) {
|
|
5
5
|
var ssgRoute = ssgRoutes[index];
|
|
6
6
|
var filepath = path.join(baseDir, ssgRoute.output);
|
|
@@ -10,3 +10,6 @@ export function writeHtmlFile(htmlAry, ssgRoutes, baseDir) {
|
|
|
10
10
|
fs.writeFileSync(filepath, html);
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
|
+
export {
|
|
14
|
+
writeHtmlFile
|
|
15
|
+
};
|
package/dist/esm/libs/replace.js
CHANGED
|
@@ -2,7 +2,7 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
|
2
2
|
import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
|
|
3
3
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
4
4
|
import normalize from "normalize-path";
|
|
5
|
-
|
|
5
|
+
function exist(route, pageRoutes) {
|
|
6
6
|
return pageRoutes.slice().findIndex(function(pageRoute) {
|
|
7
7
|
var urlEqual = normalize(pageRoute.urlPath) === normalize(route.urlPath);
|
|
8
8
|
var entryEqual = pageRoute.entryName === route.entryName;
|
|
@@ -12,7 +12,7 @@ export function exist(route, pageRoutes) {
|
|
|
12
12
|
return false;
|
|
13
13
|
});
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
function replaceRoute(ssgRoutes, pageRoutes) {
|
|
16
16
|
var _pageRoutes;
|
|
17
17
|
var cleanSsgRoutes = ssgRoutes.map(function(ssgRoute) {
|
|
18
18
|
var output = ssgRoute.output, headers = ssgRoute.headers, cleanSsgRoute = _object_without_properties(ssgRoute, [
|
|
@@ -35,3 +35,7 @@ export function replaceRoute(ssgRoutes, pageRoutes) {
|
|
|
35
35
|
(_pageRoutes = pageRoutes).push.apply(_pageRoutes, _to_consumable_array(freshRoutes));
|
|
36
36
|
return pageRoutes;
|
|
37
37
|
}
|
|
38
|
+
export {
|
|
39
|
+
exist,
|
|
40
|
+
replaceRoute
|
|
41
|
+
};
|
package/dist/esm/libs/util.js
CHANGED
|
@@ -2,11 +2,11 @@ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
|
|
2
2
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
3
3
|
import path from "path";
|
|
4
4
|
import { ROUTE_SPEC_FILE, fs, isSingleEntry, SERVER_BUNDLE_DIRECTORY } from "@modern-js/utils";
|
|
5
|
-
|
|
5
|
+
function formatOutput(filename) {
|
|
6
6
|
var outputPath = path.extname(filename) ? filename : "".concat(filename, "/index.html");
|
|
7
7
|
return outputPath;
|
|
8
8
|
}
|
|
9
|
-
|
|
9
|
+
function formatPath(str) {
|
|
10
10
|
var addr = str;
|
|
11
11
|
if (!addr || typeof addr !== "string") {
|
|
12
12
|
return addr;
|
|
@@ -22,10 +22,10 @@ export function formatPath(str) {
|
|
|
22
22
|
}
|
|
23
23
|
return addr;
|
|
24
24
|
}
|
|
25
|
-
|
|
25
|
+
function isDynamicUrl(url) {
|
|
26
26
|
return url.includes(":");
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
function getUrlPrefix(route, baseUrl) {
|
|
29
29
|
var base = "";
|
|
30
30
|
if (Array.isArray(baseUrl)) {
|
|
31
31
|
var filters = baseUrl.filter(function(url) {
|
|
@@ -48,7 +48,7 @@ export function getUrlPrefix(route, baseUrl) {
|
|
|
48
48
|
var prefix = "".concat(base, "/").concat(entryName);
|
|
49
49
|
return prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
function getOutput(route, base, agreed) {
|
|
52
52
|
var output = route.output;
|
|
53
53
|
if (output) {
|
|
54
54
|
return output;
|
|
@@ -59,24 +59,24 @@ export function getOutput(route, base, agreed) {
|
|
|
59
59
|
}
|
|
60
60
|
throw new Error("routing must provide output when calling createPage(), check ".concat(route.urlPath));
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
var readJSONSpec = function(dir) {
|
|
63
63
|
var routeJSONPath = path.join(dir, ROUTE_SPEC_FILE);
|
|
64
64
|
var routeJSON = require(routeJSONPath);
|
|
65
65
|
var routes = routeJSON.routes;
|
|
66
66
|
return routes;
|
|
67
67
|
};
|
|
68
|
-
|
|
68
|
+
var writeJSONSpec = function(dir, routes) {
|
|
69
69
|
var routeJSONPath = path.join(dir, ROUTE_SPEC_FILE);
|
|
70
70
|
fs.writeJSONSync(routeJSONPath, {
|
|
71
|
-
routes
|
|
71
|
+
routes
|
|
72
72
|
}, {
|
|
73
73
|
spaces: 2
|
|
74
74
|
});
|
|
75
75
|
};
|
|
76
|
-
|
|
76
|
+
var replaceWithAlias = function(base, filePath, alias) {
|
|
77
77
|
return path.posix.join(alias, path.posix.relative(base, filePath));
|
|
78
78
|
};
|
|
79
|
-
|
|
79
|
+
var standardOptions = function(ssgOptions, entrypoints, routes, server) {
|
|
80
80
|
if (ssgOptions === false) {
|
|
81
81
|
return false;
|
|
82
82
|
}
|
|
@@ -100,19 +100,17 @@ 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;
|
|
104
103
|
var entryName = entrypoint.entryName;
|
|
105
|
-
if (Array.isArray(
|
|
104
|
+
if (Array.isArray(server === null || server === void 0 ? void 0 : server.baseUrl)) {
|
|
106
105
|
var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
|
|
107
106
|
try {
|
|
108
107
|
var _loop2 = function() {
|
|
109
108
|
var url = _step1.value;
|
|
110
|
-
var _route;
|
|
111
109
|
var matchUrl = entryName === "main" ? url : "".concat(url, "/").concat(entryName);
|
|
112
110
|
var route = routes.find(function(route2) {
|
|
113
111
|
return route2.urlPath === matchUrl;
|
|
114
112
|
});
|
|
115
|
-
intermediateOptions[
|
|
113
|
+
intermediateOptions[route === null || route === void 0 ? void 0 : route.urlPath] = ssgOptions(entryName, {
|
|
116
114
|
baseUrl: url
|
|
117
115
|
});
|
|
118
116
|
};
|
|
@@ -133,9 +131,8 @@ export var standardOptions = function(ssgOptions, entrypoints, routes, server) {
|
|
|
133
131
|
}
|
|
134
132
|
}
|
|
135
133
|
} else {
|
|
136
|
-
var _server1;
|
|
137
134
|
intermediateOptions[entryName] = ssgOptions(entryName, {
|
|
138
|
-
baseUrl:
|
|
135
|
+
baseUrl: server === null || server === void 0 ? void 0 : server.baseUrl
|
|
139
136
|
});
|
|
140
137
|
}
|
|
141
138
|
};
|
|
@@ -159,7 +156,7 @@ export var standardOptions = function(ssgOptions, entrypoints, routes, server) {
|
|
|
159
156
|
}
|
|
160
157
|
return false;
|
|
161
158
|
};
|
|
162
|
-
|
|
159
|
+
var openRouteSSR = function(routes) {
|
|
163
160
|
var entries = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
164
161
|
return routes.map(function(ssgRoute) {
|
|
165
162
|
return _object_spread_props(_object_spread({}, ssgRoute), {
|
|
@@ -168,7 +165,7 @@ export var openRouteSSR = function(routes) {
|
|
|
168
165
|
});
|
|
169
166
|
});
|
|
170
167
|
};
|
|
171
|
-
|
|
168
|
+
var flattenRoutes = function(routes) {
|
|
172
169
|
var parents = [];
|
|
173
170
|
var newRoutes = [];
|
|
174
171
|
var traverseRoute = function(route) {
|
|
@@ -191,3 +188,16 @@ export var flattenRoutes = function(routes) {
|
|
|
191
188
|
routes.forEach(traverseRoute);
|
|
192
189
|
return newRoutes;
|
|
193
190
|
};
|
|
191
|
+
export {
|
|
192
|
+
flattenRoutes,
|
|
193
|
+
formatOutput,
|
|
194
|
+
formatPath,
|
|
195
|
+
getOutput,
|
|
196
|
+
getUrlPrefix,
|
|
197
|
+
isDynamicUrl,
|
|
198
|
+
openRouteSSR,
|
|
199
|
+
readJSONSpec,
|
|
200
|
+
replaceWithAlias,
|
|
201
|
+
standardOptions,
|
|
202
|
+
writeJSONSpec
|
|
203
|
+
};
|
package/dist/esm/server/index.js
CHANGED
|
@@ -3,7 +3,7 @@ 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
|
-
|
|
6
|
+
var createServer = function(api, ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) {
|
|
7
7
|
return new Promise(function(resolve, reject) {
|
|
8
8
|
var _cp_stderr, _cp_stdout;
|
|
9
9
|
var entries = ssgRoutes.map(function(route) {
|
|
@@ -18,11 +18,11 @@ export var createServer = function(api, ssgRoutes, pageRoutes, apiRoutes, option
|
|
|
18
18
|
var appContext = api.useAppContext();
|
|
19
19
|
var plugins = appContext.serverInternalPlugins;
|
|
20
20
|
cp.send(JSON.stringify({
|
|
21
|
-
options
|
|
21
|
+
options,
|
|
22
22
|
renderRoutes: ssgRoutes,
|
|
23
23
|
routes: total,
|
|
24
|
-
appDirectory
|
|
25
|
-
plugins
|
|
24
|
+
appDirectory,
|
|
25
|
+
plugins
|
|
26
26
|
}));
|
|
27
27
|
var htmlChunks = [];
|
|
28
28
|
var htmlAry = [];
|
|
@@ -61,3 +61,6 @@ export var createServer = function(api, ssgRoutes, pageRoutes, apiRoutes, option
|
|
|
61
61
|
});
|
|
62
62
|
});
|
|
63
63
|
};
|
|
64
|
+
export {
|
|
65
|
+
createServer
|
|
66
|
+
};
|
|
@@ -4,7 +4,7 @@ import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
|
|
4
4
|
import EventEmitter from "events";
|
|
5
5
|
import { Readable } from "stream";
|
|
6
6
|
import httpMocks from "node-mocks-http";
|
|
7
|
-
|
|
7
|
+
var compile = function(requestHandler) {
|
|
8
8
|
return function(options) {
|
|
9
9
|
var extend = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
10
10
|
return new Promise(function(resolve, reject) {
|
|
@@ -41,3 +41,6 @@ export var compile = function(requestHandler) {
|
|
|
41
41
|
});
|
|
42
42
|
};
|
|
43
43
|
};
|
|
44
|
+
export {
|
|
45
|
+
compile
|
|
46
|
+
};
|
|
@@ -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;
|
|
12
12
|
return _ts_generator(this, function(_state) {
|
|
13
13
|
switch (_state.label) {
|
|
14
14
|
case 0:
|
|
@@ -40,7 +40,7 @@ process.on("message", function() {
|
|
|
40
40
|
server({
|
|
41
41
|
pwd: appDirectory,
|
|
42
42
|
config: options,
|
|
43
|
-
routes
|
|
43
|
+
routes,
|
|
44
44
|
staticGenerate: true,
|
|
45
45
|
internalPlugins: plugins
|
|
46
46
|
})
|
|
@@ -90,7 +90,7 @@ process.on("message", function() {
|
|
|
90
90
|
];
|
|
91
91
|
case 4:
|
|
92
92
|
e = _state.sent();
|
|
93
|
-
|
|
93
|
+
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,
|
package/dist/esm/types.js
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/esm-node/index.js
CHANGED
|
@@ -6,7 +6,7 @@ import { createServer } from "./server";
|
|
|
6
6
|
import { writeHtmlFile } from "./libs/output";
|
|
7
7
|
import { replaceRoute } from "./libs/replace";
|
|
8
8
|
import { makeRoute } from "./libs/make";
|
|
9
|
-
|
|
9
|
+
const ssgPlugin = () => ({
|
|
10
10
|
name: "@modern-js/plugin-ssg",
|
|
11
11
|
pre: [
|
|
12
12
|
"@modern-js/plugin-server",
|
|
@@ -141,4 +141,8 @@ export const ssgPlugin = () => ({
|
|
|
141
141
|
};
|
|
142
142
|
}
|
|
143
143
|
});
|
|
144
|
-
|
|
144
|
+
var src_default = ssgPlugin;
|
|
145
|
+
export {
|
|
146
|
+
src_default as default,
|
|
147
|
+
ssgPlugin
|
|
148
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import normalize from "normalize-path";
|
|
3
|
-
|
|
3
|
+
function makeRender(ssgRoutes, render, port) {
|
|
4
4
|
return ssgRoutes.map((ssgRoute) => render({
|
|
5
5
|
url: ssgRoute.urlPath,
|
|
6
6
|
headers: {
|
|
@@ -10,7 +10,7 @@ export function makeRender(ssgRoutes, render, port) {
|
|
|
10
10
|
connection: {}
|
|
11
11
|
}));
|
|
12
12
|
}
|
|
13
|
-
|
|
13
|
+
function makeRoute(baseRoute, route, headers = {}) {
|
|
14
14
|
const { urlPath, entryPath } = baseRoute;
|
|
15
15
|
if (typeof route === "string") {
|
|
16
16
|
return {
|
|
@@ -31,3 +31,7 @@ export function makeRoute(baseRoute, route, headers = {}) {
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
+
export {
|
|
35
|
+
makeRender,
|
|
36
|
+
makeRoute
|
|
37
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import path from "path";
|
|
2
2
|
import { fs } from "@modern-js/utils";
|
|
3
|
-
|
|
3
|
+
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,3 +10,6 @@ export function writeHtmlFile(htmlAry, ssgRoutes, baseDir) {
|
|
|
10
10
|
fs.writeFileSync(filepath, html);
|
|
11
11
|
});
|
|
12
12
|
}
|
|
13
|
+
export {
|
|
14
|
+
writeHtmlFile
|
|
15
|
+
};
|