@modern-js/plugin-ssg 2.0.0-beta.2 → 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 +70 -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 +8 -13
|
@@ -1,21 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
exist: () => exist,
|
|
27
|
+
replaceRoute: () => replaceRoute
|
|
5
28
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
29
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
30
|
+
var import_normalize_path = __toESM(require("normalize-path"));
|
|
31
|
+
var __defProp2 = Object.defineProperty;
|
|
32
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
33
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
34
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
35
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
36
|
+
var __spreadValues = (a, b) => {
|
|
37
|
+
for (var prop in b || (b = {}))
|
|
38
|
+
if (__hasOwnProp2.call(b, prop))
|
|
39
|
+
__defNormalProp(a, prop, b[prop]);
|
|
40
|
+
if (__getOwnPropSymbols)
|
|
41
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
42
|
+
if (__propIsEnum.call(b, prop))
|
|
43
|
+
__defNormalProp(a, prop, b[prop]);
|
|
44
|
+
}
|
|
45
|
+
return a;
|
|
46
|
+
};
|
|
47
|
+
var __objRest = (source, exclude) => {
|
|
48
|
+
var target = {};
|
|
49
|
+
for (var prop in source)
|
|
50
|
+
if (__hasOwnProp2.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
51
|
+
target[prop] = source[prop];
|
|
52
|
+
if (source != null && __getOwnPropSymbols)
|
|
53
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
54
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
55
|
+
target[prop] = source[prop];
|
|
56
|
+
}
|
|
57
|
+
return target;
|
|
58
|
+
};
|
|
16
59
|
function exist(route, pageRoutes) {
|
|
17
|
-
return pageRoutes.slice().findIndex(pageRoute => {
|
|
18
|
-
const urlEqual = (0,
|
|
60
|
+
return pageRoutes.slice().findIndex((pageRoute) => {
|
|
61
|
+
const urlEqual = (0, import_normalize_path.default)(pageRoute.urlPath) === (0, import_normalize_path.default)(route.urlPath);
|
|
19
62
|
const entryEqual = pageRoute.entryName === route.entryName;
|
|
20
63
|
if (urlEqual && entryEqual) {
|
|
21
64
|
return true;
|
|
@@ -24,30 +67,22 @@ function exist(route, pageRoutes) {
|
|
|
24
67
|
});
|
|
25
68
|
}
|
|
26
69
|
function replaceRoute(ssgRoutes, pageRoutes) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
cleanSsgRoute = _objectWithoutProperties(ssgRoute, _excluded);
|
|
34
|
-
return Object.assign(cleanSsgRoute, output ? {
|
|
35
|
-
entryPath: output
|
|
36
|
-
} : {});
|
|
70
|
+
const cleanSsgRoutes = ssgRoutes.map((ssgRoute) => {
|
|
71
|
+
const _a = ssgRoute, { output, headers } = _a, cleanSsgRoute = __objRest(_a, ["output", "headers"]);
|
|
72
|
+
return Object.assign(
|
|
73
|
+
cleanSsgRoute,
|
|
74
|
+
output ? { entryPath: output } : {}
|
|
75
|
+
);
|
|
37
76
|
});
|
|
38
|
-
|
|
39
|
-
// all routes that need to be added and replaced
|
|
40
77
|
const freshRoutes = [];
|
|
41
|
-
cleanSsgRoutes.forEach(ssgRoute => {
|
|
78
|
+
cleanSsgRoutes.forEach((ssgRoute) => {
|
|
42
79
|
const index = exist(ssgRoute, pageRoutes);
|
|
43
80
|
if (index < 0) {
|
|
44
|
-
|
|
45
|
-
freshRoutes.push(_objectSpread({}, ssgRoute));
|
|
81
|
+
freshRoutes.push(__spreadValues({}, ssgRoute));
|
|
46
82
|
} else {
|
|
47
|
-
// overwrite original entry
|
|
48
83
|
pageRoutes[index].entryPath = ssgRoute.entryPath;
|
|
49
84
|
}
|
|
50
85
|
});
|
|
51
86
|
pageRoutes.push(...freshRoutes);
|
|
52
87
|
return pageRoutes;
|
|
53
|
-
}
|
|
88
|
+
}
|
|
@@ -1,101 +1,128 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
flattenRoutes: () => flattenRoutes,
|
|
27
|
+
formatOutput: () => formatOutput,
|
|
28
|
+
formatPath: () => formatPath,
|
|
29
|
+
getOutput: () => getOutput,
|
|
30
|
+
getUrlPrefix: () => getUrlPrefix,
|
|
31
|
+
isDynamicUrl: () => isDynamicUrl,
|
|
32
|
+
openRouteSSR: () => openRouteSSR,
|
|
33
|
+
readJSONSpec: () => readJSONSpec,
|
|
34
|
+
replaceWithAlias: () => replaceWithAlias,
|
|
35
|
+
standardOptions: () => standardOptions,
|
|
36
|
+
writeJSONSpec: () => writeJSONSpec
|
|
5
37
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
38
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
39
|
+
var import_path = __toESM(require("path"));
|
|
40
|
+
var import_utils = require("@modern-js/utils");
|
|
41
|
+
var __defProp2 = Object.defineProperty;
|
|
42
|
+
var __defProps = Object.defineProperties;
|
|
43
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
44
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
45
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
46
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
47
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
48
|
+
var __spreadValues = (a, b) => {
|
|
49
|
+
for (var prop in b || (b = {}))
|
|
50
|
+
if (__hasOwnProp2.call(b, prop))
|
|
51
|
+
__defNormalProp(a, prop, b[prop]);
|
|
52
|
+
if (__getOwnPropSymbols)
|
|
53
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
54
|
+
if (__propIsEnum.call(b, prop))
|
|
55
|
+
__defNormalProp(a, prop, b[prop]);
|
|
56
|
+
}
|
|
57
|
+
return a;
|
|
58
|
+
};
|
|
59
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
19
60
|
function formatOutput(filename) {
|
|
20
|
-
const outputPath =
|
|
61
|
+
const outputPath = import_path.default.extname(filename) ? filename : `${filename}/index.html`;
|
|
21
62
|
return outputPath;
|
|
22
63
|
}
|
|
23
64
|
function formatPath(str) {
|
|
24
65
|
let addr = str;
|
|
25
|
-
if (!addr || typeof addr !==
|
|
66
|
+
if (!addr || typeof addr !== "string") {
|
|
26
67
|
return addr;
|
|
27
68
|
}
|
|
28
|
-
if (addr.startsWith(
|
|
69
|
+
if (addr.startsWith(".")) {
|
|
29
70
|
addr = addr.slice(1);
|
|
30
71
|
}
|
|
31
|
-
if (!addr.startsWith(
|
|
72
|
+
if (!addr.startsWith("/")) {
|
|
32
73
|
addr = `/${addr}`;
|
|
33
74
|
}
|
|
34
|
-
if (addr.endsWith(
|
|
75
|
+
if (addr.endsWith("/") && addr !== "/") {
|
|
35
76
|
addr = addr.slice(0, addr.length - 1);
|
|
36
77
|
}
|
|
37
78
|
return addr;
|
|
38
79
|
}
|
|
39
80
|
function isDynamicUrl(url) {
|
|
40
|
-
return url.includes(
|
|
81
|
+
return url.includes(":");
|
|
41
82
|
}
|
|
42
83
|
function getUrlPrefix(route, baseUrl) {
|
|
43
|
-
let base =
|
|
84
|
+
let base = "";
|
|
44
85
|
if (Array.isArray(baseUrl)) {
|
|
45
|
-
const filters = baseUrl.filter(url => route.urlPath.includes(url));
|
|
86
|
+
const filters = baseUrl.filter((url) => route.urlPath.includes(url));
|
|
46
87
|
if (filters.length > 1) {
|
|
47
88
|
const matched = filters.sort((a, b) => a.length - b.length)[0];
|
|
48
|
-
|
|
49
|
-
// this should never happened
|
|
50
89
|
if (!matched) {
|
|
51
|
-
throw new Error(
|
|
90
|
+
throw new Error("");
|
|
52
91
|
}
|
|
53
92
|
base = matched;
|
|
54
93
|
}
|
|
55
94
|
} else {
|
|
56
95
|
base = baseUrl;
|
|
57
96
|
}
|
|
58
|
-
base = base ===
|
|
59
|
-
const entryName = route.entryName ===
|
|
97
|
+
base = base === "/" ? "" : base;
|
|
98
|
+
const entryName = route.entryName === "main" ? "" : route.entryName;
|
|
60
99
|
const prefix = `${base}/${entryName}`;
|
|
61
|
-
return prefix.endsWith(
|
|
100
|
+
return prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
|
|
62
101
|
}
|
|
63
|
-
|
|
64
|
-
// if no output, return default path for aggred-route(relative),
|
|
65
|
-
// or throw error for control-route
|
|
66
102
|
function getOutput(route, base, agreed) {
|
|
67
|
-
const {
|
|
68
|
-
output
|
|
69
|
-
} = route;
|
|
103
|
+
const { output } = route;
|
|
70
104
|
if (output) {
|
|
71
105
|
return output;
|
|
72
106
|
}
|
|
73
107
|
if (agreed) {
|
|
74
|
-
const urlWithoutBase = route.urlPath.replace(base,
|
|
75
|
-
return urlWithoutBase.startsWith(
|
|
108
|
+
const urlWithoutBase = route.urlPath.replace(base, "");
|
|
109
|
+
return urlWithoutBase.startsWith("/") ? urlWithoutBase.slice(1) : urlWithoutBase;
|
|
76
110
|
}
|
|
77
|
-
throw new Error(
|
|
111
|
+
throw new Error(
|
|
112
|
+
`routing must provide output when calling createPage(), check ${route.urlPath}`
|
|
113
|
+
);
|
|
78
114
|
}
|
|
79
|
-
const readJSONSpec = dir => {
|
|
80
|
-
const routeJSONPath =
|
|
115
|
+
const readJSONSpec = (dir) => {
|
|
116
|
+
const routeJSONPath = import_path.default.join(dir, import_utils.ROUTE_SPEC_FILE);
|
|
81
117
|
const routeJSON = require(routeJSONPath);
|
|
82
|
-
const {
|
|
83
|
-
routes
|
|
84
|
-
} = routeJSON;
|
|
118
|
+
const { routes } = routeJSON;
|
|
85
119
|
return routes;
|
|
86
120
|
};
|
|
87
|
-
exports.readJSONSpec = readJSONSpec;
|
|
88
121
|
const writeJSONSpec = (dir, routes) => {
|
|
89
|
-
const routeJSONPath =
|
|
90
|
-
|
|
91
|
-
routes
|
|
92
|
-
}, {
|
|
93
|
-
spaces: 2
|
|
94
|
-
});
|
|
122
|
+
const routeJSONPath = import_path.default.join(dir, import_utils.ROUTE_SPEC_FILE);
|
|
123
|
+
import_utils.fs.writeJSONSync(routeJSONPath, { routes }, { spaces: 2 });
|
|
95
124
|
};
|
|
96
|
-
|
|
97
|
-
const replaceWithAlias = (base, filePath, alias) => _path.default.posix.join(alias, _path.default.posix.relative(base, filePath));
|
|
98
|
-
exports.replaceWithAlias = replaceWithAlias;
|
|
125
|
+
const replaceWithAlias = (base, filePath, alias) => import_path.default.posix.join(alias, import_path.default.posix.relative(base, filePath));
|
|
99
126
|
const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
100
127
|
if (ssgOptions === false) {
|
|
101
128
|
return false;
|
|
@@ -105,33 +132,29 @@ const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
|
105
132
|
opt[entry.entryName] = ssgOptions;
|
|
106
133
|
return opt;
|
|
107
134
|
}, {});
|
|
108
|
-
} else if (typeof ssgOptions ===
|
|
109
|
-
const isSingle = (0,
|
|
110
|
-
if (isSingle && typeof ssgOptions.main ===
|
|
111
|
-
return {
|
|
112
|
-
main: ssgOptions
|
|
113
|
-
};
|
|
135
|
+
} else if (typeof ssgOptions === "object") {
|
|
136
|
+
const isSingle = (0, import_utils.isSingleEntry)(entrypoints);
|
|
137
|
+
if (isSingle && typeof ssgOptions.main === "undefined") {
|
|
138
|
+
return { main: ssgOptions };
|
|
114
139
|
} else {
|
|
115
140
|
return ssgOptions;
|
|
116
141
|
}
|
|
117
|
-
} else if (typeof ssgOptions ===
|
|
142
|
+
} else if (typeof ssgOptions === "function") {
|
|
118
143
|
const intermediateOptions = {};
|
|
119
144
|
for (const entrypoint of entrypoints) {
|
|
120
|
-
const {
|
|
121
|
-
|
|
122
|
-
} = entrypoint;
|
|
123
|
-
// TODO: may be async function
|
|
124
|
-
if (Array.isArray(server === null || server === void 0 ? void 0 : server.baseUrl)) {
|
|
145
|
+
const { entryName } = entrypoint;
|
|
146
|
+
if (Array.isArray(server == null ? void 0 : server.baseUrl)) {
|
|
125
147
|
for (const url of server.baseUrl) {
|
|
126
|
-
const matchUrl = entryName ===
|
|
127
|
-
const route = routes.find(
|
|
128
|
-
intermediateOptions[route
|
|
129
|
-
|
|
130
|
-
|
|
148
|
+
const matchUrl = entryName === "main" ? url : `${url}/${entryName}`;
|
|
149
|
+
const route = routes.find((route2) => route2.urlPath === matchUrl);
|
|
150
|
+
intermediateOptions[route == null ? void 0 : route.urlPath] = ssgOptions(
|
|
151
|
+
entryName,
|
|
152
|
+
{ baseUrl: url }
|
|
153
|
+
);
|
|
131
154
|
}
|
|
132
155
|
} else {
|
|
133
156
|
intermediateOptions[entryName] = ssgOptions(entryName, {
|
|
134
|
-
baseUrl: server
|
|
157
|
+
baseUrl: server == null ? void 0 : server.baseUrl
|
|
135
158
|
});
|
|
136
159
|
}
|
|
137
160
|
}
|
|
@@ -139,31 +162,25 @@ const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
|
139
162
|
}
|
|
140
163
|
return false;
|
|
141
164
|
};
|
|
142
|
-
|
|
143
|
-
const openRouteSSR = (routes, entries = []) => routes.map(ssgRoute => _objectSpread(_objectSpread({}, ssgRoute), {}, {
|
|
165
|
+
const openRouteSSR = (routes, entries = []) => routes.map((ssgRoute) => __spreadProps(__spreadValues({}, ssgRoute), {
|
|
144
166
|
isSSR: entries.includes(ssgRoute.entryName),
|
|
145
|
-
bundle: `${
|
|
167
|
+
bundle: `${import_utils.SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
|
|
146
168
|
}));
|
|
147
|
-
|
|
148
|
-
// TODO: 过滤带有 server loader 的路由
|
|
149
|
-
exports.openRouteSSR = openRouteSSR;
|
|
150
|
-
const flattenRoutes = routes => {
|
|
169
|
+
const flattenRoutes = (routes) => {
|
|
151
170
|
const parents = [];
|
|
152
171
|
const newRoutes = [];
|
|
153
|
-
const traverseRoute = route => {
|
|
172
|
+
const traverseRoute = (route) => {
|
|
154
173
|
const parent = parents[parents.length - 1];
|
|
155
|
-
let
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
newRoutes.push(_objectSpread(_objectSpread({}, route), {}, {
|
|
161
|
-
path
|
|
174
|
+
let path2 = parent ? `${parent.path}/${route.path || ""}`.replace(/\/+/g, "/") : route.path || "";
|
|
175
|
+
path2 = path2.replace(/\/$/, "");
|
|
176
|
+
if (route._component && (path2 !== "/" || path2 === "/" && !parent)) {
|
|
177
|
+
newRoutes.push(__spreadProps(__spreadValues({}, route), {
|
|
178
|
+
path: path2
|
|
162
179
|
}));
|
|
163
180
|
}
|
|
164
181
|
if (route.children) {
|
|
165
|
-
parents.push(
|
|
166
|
-
path
|
|
182
|
+
parents.push(__spreadProps(__spreadValues({}, route), {
|
|
183
|
+
path: path2
|
|
167
184
|
}));
|
|
168
185
|
route.children.forEach(traverseRoute);
|
|
169
186
|
parents.pop();
|
|
@@ -172,4 +189,3 @@ const flattenRoutes = routes => {
|
|
|
172
189
|
routes.forEach(traverseRoute);
|
|
173
190
|
return newRoutes;
|
|
174
191
|
};
|
|
175
|
-
exports.flattenRoutes = flattenRoutes;
|
|
@@ -1,8 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 stdin_exports = {};
|
|
19
|
+
__export(stdin_exports, {
|
|
20
|
+
CLOSE_SIGN: () => CLOSE_SIGN
|
|
5
21
|
});
|
|
6
|
-
exports
|
|
7
|
-
const CLOSE_SIGN =
|
|
8
|
-
exports.CLOSE_SIGN = CLOSE_SIGN;
|
|
22
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
23
|
+
const CLOSE_SIGN = "modern_close_server";
|
|
@@ -1,68 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
createServer: () => createServer
|
|
5
27
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
var
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
28
|
+
module.exports = __toCommonJS(stdin_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");
|
|
13
34
|
const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const entries = ssgRoutes.map(route => route.entryName);
|
|
17
|
-
const backup = (0, _util.openRouteSSR)(pageRoutes, entries);
|
|
35
|
+
const entries = ssgRoutes.map((route) => route.entryName);
|
|
36
|
+
const backup = (0, import_util.openRouteSSR)(pageRoutes, entries);
|
|
18
37
|
const total = backup.concat(apiRoutes);
|
|
19
|
-
const cp =
|
|
38
|
+
const cp = import_child_process.default.fork(import_path.default.join(__dirname, "process"), {
|
|
20
39
|
cwd: appDirectory,
|
|
21
40
|
silent: true
|
|
22
41
|
});
|
|
23
42
|
const appContext = api.useAppContext();
|
|
24
43
|
const plugins = appContext.serverInternalPlugins;
|
|
25
|
-
cp.send(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
44
|
+
cp.send(
|
|
45
|
+
JSON.stringify({
|
|
46
|
+
options,
|
|
47
|
+
renderRoutes: ssgRoutes,
|
|
48
|
+
routes: total,
|
|
49
|
+
appDirectory,
|
|
50
|
+
plugins
|
|
51
|
+
})
|
|
52
|
+
);
|
|
32
53
|
const htmlChunks = [];
|
|
33
54
|
const htmlAry = [];
|
|
34
|
-
cp.on(
|
|
55
|
+
cp.on("message", (chunk) => {
|
|
35
56
|
if (chunk !== null) {
|
|
36
57
|
htmlChunks.push(chunk);
|
|
37
58
|
} else {
|
|
38
|
-
const html = htmlChunks.join(
|
|
59
|
+
const html = htmlChunks.join("");
|
|
39
60
|
htmlAry.push(html);
|
|
40
61
|
htmlChunks.length = 0;
|
|
41
62
|
}
|
|
42
63
|
if (htmlAry.length === ssgRoutes.length) {
|
|
43
|
-
cp.send(
|
|
64
|
+
cp.send(import_consts.CLOSE_SIGN);
|
|
44
65
|
resolve(htmlAry);
|
|
45
66
|
}
|
|
46
67
|
});
|
|
47
|
-
cp.stderr.on(
|
|
68
|
+
cp.stderr.on("data", (chunk) => {
|
|
48
69
|
const str = chunk.toString();
|
|
49
|
-
if (str.includes(
|
|
50
|
-
|
|
51
|
-
reject(new Error(
|
|
52
|
-
cp.kill(
|
|
70
|
+
if (str.includes("Error")) {
|
|
71
|
+
import_utils.logger.error(str);
|
|
72
|
+
reject(new Error("ssg render failed"));
|
|
73
|
+
cp.kill("SIGKILL");
|
|
53
74
|
} else {
|
|
54
|
-
|
|
75
|
+
import_utils.logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
55
76
|
}
|
|
56
77
|
});
|
|
57
|
-
cp.stdout.on(
|
|
78
|
+
cp.stdout.on("data", (chunk) => {
|
|
58
79
|
const str = chunk.toString();
|
|
59
|
-
if (str.includes(
|
|
60
|
-
|
|
61
|
-
reject(new Error(
|
|
62
|
-
cp.kill(
|
|
80
|
+
if (str.includes("Error")) {
|
|
81
|
+
import_utils.logger.error(str);
|
|
82
|
+
reject(new Error("ssg render failed"));
|
|
83
|
+
cp.kill("SIGKILL");
|
|
63
84
|
} else {
|
|
64
|
-
|
|
85
|
+
import_utils.logger.info(str.replace(/[^\S\n]+/g, " "));
|
|
65
86
|
}
|
|
66
87
|
});
|
|
67
88
|
});
|
|
68
|
-
exports.createServer = createServer;
|