@modern-js/plugin-ssg 2.0.0-beta.3 → 2.0.0-beta.6
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 +73 -0
- package/dist/js/modern/global.d.js +0 -0
- package/dist/js/modern/index.js +168 -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 +189 -166
- package/dist/js/node/libs/make.js +69 -32
- package/dist/js/node/libs/output.js +38 -13
- package/dist/js/node/libs/replace.js +71 -33
- package/dist/js/node/libs/util.js +119 -91
- package/dist/js/node/server/consts.js +26 -7
- package/dist/js/node/server/index.js +63 -39
- package/dist/js/node/server/prerender.js +58 -22
- package/dist/js/node/server/process.js +61 -34
- package/dist/js/node/types.js +15 -5
- package/dist/js/treeshaking/global.d.js +1 -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/dist/types/index.d.ts +2 -0
- package/dist/types/libs/util.d.ts +0 -1
- package/package.json +9 -14
|
@@ -1,21 +1,62 @@
|
|
|
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 __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __objRest = (source, exclude) => {
|
|
22
|
+
var target = {};
|
|
23
|
+
for (var prop in source)
|
|
24
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
25
|
+
target[prop] = source[prop];
|
|
26
|
+
if (source != null && __getOwnPropSymbols)
|
|
27
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
28
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
}
|
|
31
|
+
return target;
|
|
32
|
+
};
|
|
33
|
+
var __export = (target, all) => {
|
|
34
|
+
for (var name in all)
|
|
35
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
36
|
+
};
|
|
37
|
+
var __copyProps = (to, from, except, desc) => {
|
|
38
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
39
|
+
for (let key of __getOwnPropNames(from))
|
|
40
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
41
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
42
|
+
}
|
|
43
|
+
return to;
|
|
44
|
+
};
|
|
45
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
46
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
47
|
+
mod
|
|
48
|
+
));
|
|
49
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
50
|
+
var replace_exports = {};
|
|
51
|
+
__export(replace_exports, {
|
|
52
|
+
exist: () => exist,
|
|
53
|
+
replaceRoute: () => replaceRoute
|
|
5
54
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
var _normalizePath = _interopRequireDefault(require("normalize-path"));
|
|
9
|
-
const _excluded = ["output", "headers"];
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
13
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
14
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
15
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
55
|
+
module.exports = __toCommonJS(replace_exports);
|
|
56
|
+
var import_normalize_path = __toESM(require("normalize-path"));
|
|
16
57
|
function exist(route, pageRoutes) {
|
|
17
|
-
return pageRoutes.slice().findIndex(pageRoute => {
|
|
18
|
-
const urlEqual = (0,
|
|
58
|
+
return pageRoutes.slice().findIndex((pageRoute) => {
|
|
59
|
+
const urlEqual = (0, import_normalize_path.default)(pageRoute.urlPath) === (0, import_normalize_path.default)(route.urlPath);
|
|
19
60
|
const entryEqual = pageRoute.entryName === route.entryName;
|
|
20
61
|
if (urlEqual && entryEqual) {
|
|
21
62
|
return true;
|
|
@@ -24,30 +65,27 @@ function exist(route, pageRoutes) {
|
|
|
24
65
|
});
|
|
25
66
|
}
|
|
26
67
|
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
|
-
} : {});
|
|
68
|
+
const cleanSsgRoutes = ssgRoutes.map((ssgRoute) => {
|
|
69
|
+
const _a = ssgRoute, { output, headers } = _a, cleanSsgRoute = __objRest(_a, ["output", "headers"]);
|
|
70
|
+
return Object.assign(
|
|
71
|
+
cleanSsgRoute,
|
|
72
|
+
output ? { entryPath: output } : {}
|
|
73
|
+
);
|
|
37
74
|
});
|
|
38
|
-
|
|
39
|
-
// all routes that need to be added and replaced
|
|
40
75
|
const freshRoutes = [];
|
|
41
|
-
cleanSsgRoutes.forEach(ssgRoute => {
|
|
76
|
+
cleanSsgRoutes.forEach((ssgRoute) => {
|
|
42
77
|
const index = exist(ssgRoute, pageRoutes);
|
|
43
78
|
if (index < 0) {
|
|
44
|
-
|
|
45
|
-
freshRoutes.push(_objectSpread({}, ssgRoute));
|
|
79
|
+
freshRoutes.push(__spreadValues({}, ssgRoute));
|
|
46
80
|
} else {
|
|
47
|
-
// overwrite original entry
|
|
48
81
|
pageRoutes[index].entryPath = ssgRoute.entryPath;
|
|
49
82
|
}
|
|
50
83
|
});
|
|
51
84
|
pageRoutes.push(...freshRoutes);
|
|
52
85
|
return pageRoutes;
|
|
53
|
-
}
|
|
86
|
+
}
|
|
87
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
88
|
+
0 && (module.exports = {
|
|
89
|
+
exist,
|
|
90
|
+
replaceRoute
|
|
91
|
+
});
|
|
@@ -1,101 +1,126 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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
|
|
5
54
|
});
|
|
6
|
-
exports
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.getOutput = getOutput;
|
|
10
|
-
exports.getUrlPrefix = getUrlPrefix;
|
|
11
|
-
exports.isDynamicUrl = isDynamicUrl;
|
|
12
|
-
exports.writeJSONSpec = exports.standardOptions = exports.replaceWithAlias = exports.readJSONSpec = exports.openRouteSSR = void 0;
|
|
13
|
-
var _path = _interopRequireDefault(require("path"));
|
|
14
|
-
var _utils = require("@modern-js/utils");
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
16
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
17
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
18
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
55
|
+
module.exports = __toCommonJS(util_exports);
|
|
56
|
+
var import_path = __toESM(require("path"));
|
|
57
|
+
var import_utils = require("@modern-js/utils");
|
|
19
58
|
function formatOutput(filename) {
|
|
20
|
-
const outputPath =
|
|
59
|
+
const outputPath = import_path.default.extname(filename) ? filename : `${filename}/index.html`;
|
|
21
60
|
return outputPath;
|
|
22
61
|
}
|
|
23
62
|
function formatPath(str) {
|
|
24
63
|
let addr = str;
|
|
25
|
-
if (!addr || typeof addr !==
|
|
64
|
+
if (!addr || typeof addr !== "string") {
|
|
26
65
|
return addr;
|
|
27
66
|
}
|
|
28
|
-
if (addr.startsWith(
|
|
67
|
+
if (addr.startsWith(".")) {
|
|
29
68
|
addr = addr.slice(1);
|
|
30
69
|
}
|
|
31
|
-
if (!addr.startsWith(
|
|
70
|
+
if (!addr.startsWith("/")) {
|
|
32
71
|
addr = `/${addr}`;
|
|
33
72
|
}
|
|
34
|
-
if (addr.endsWith(
|
|
73
|
+
if (addr.endsWith("/") && addr !== "/") {
|
|
35
74
|
addr = addr.slice(0, addr.length - 1);
|
|
36
75
|
}
|
|
37
76
|
return addr;
|
|
38
77
|
}
|
|
39
78
|
function isDynamicUrl(url) {
|
|
40
|
-
return url.includes(
|
|
79
|
+
return url.includes(":");
|
|
41
80
|
}
|
|
42
81
|
function getUrlPrefix(route, baseUrl) {
|
|
43
|
-
let base =
|
|
82
|
+
let base = "";
|
|
44
83
|
if (Array.isArray(baseUrl)) {
|
|
45
|
-
const filters = baseUrl.filter(url => route.urlPath.includes(url));
|
|
84
|
+
const filters = baseUrl.filter((url) => route.urlPath.includes(url));
|
|
46
85
|
if (filters.length > 1) {
|
|
47
86
|
const matched = filters.sort((a, b) => a.length - b.length)[0];
|
|
48
|
-
|
|
49
|
-
// this should never happened
|
|
50
87
|
if (!matched) {
|
|
51
|
-
throw new Error(
|
|
88
|
+
throw new Error("");
|
|
52
89
|
}
|
|
53
90
|
base = matched;
|
|
54
91
|
}
|
|
55
92
|
} else {
|
|
56
93
|
base = baseUrl;
|
|
57
94
|
}
|
|
58
|
-
base = base ===
|
|
59
|
-
const entryName = route.entryName ===
|
|
95
|
+
base = base === "/" ? "" : base;
|
|
96
|
+
const entryName = route.entryName === "main" ? "" : route.entryName;
|
|
60
97
|
const prefix = `${base}/${entryName}`;
|
|
61
|
-
return prefix.endsWith(
|
|
98
|
+
return prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
|
|
62
99
|
}
|
|
63
|
-
|
|
64
|
-
// if no output, return default path for aggred-route(relative),
|
|
65
|
-
// or throw error for control-route
|
|
66
100
|
function getOutput(route, base, agreed) {
|
|
67
|
-
const {
|
|
68
|
-
output
|
|
69
|
-
} = route;
|
|
101
|
+
const { output } = route;
|
|
70
102
|
if (output) {
|
|
71
103
|
return output;
|
|
72
104
|
}
|
|
73
105
|
if (agreed) {
|
|
74
|
-
const urlWithoutBase = route.urlPath.replace(base,
|
|
75
|
-
return urlWithoutBase.startsWith(
|
|
106
|
+
const urlWithoutBase = route.urlPath.replace(base, "");
|
|
107
|
+
return urlWithoutBase.startsWith("/") ? urlWithoutBase.slice(1) : urlWithoutBase;
|
|
76
108
|
}
|
|
77
|
-
throw new Error(
|
|
109
|
+
throw new Error(
|
|
110
|
+
`routing must provide output when calling createPage(), check ${route.urlPath}`
|
|
111
|
+
);
|
|
78
112
|
}
|
|
79
|
-
const readJSONSpec = dir => {
|
|
80
|
-
const routeJSONPath =
|
|
113
|
+
const readJSONSpec = (dir) => {
|
|
114
|
+
const routeJSONPath = import_path.default.join(dir, import_utils.ROUTE_SPEC_FILE);
|
|
81
115
|
const routeJSON = require(routeJSONPath);
|
|
82
|
-
const {
|
|
83
|
-
routes
|
|
84
|
-
} = routeJSON;
|
|
116
|
+
const { routes } = routeJSON;
|
|
85
117
|
return routes;
|
|
86
118
|
};
|
|
87
|
-
exports.readJSONSpec = readJSONSpec;
|
|
88
119
|
const writeJSONSpec = (dir, routes) => {
|
|
89
|
-
const routeJSONPath =
|
|
90
|
-
|
|
91
|
-
routes
|
|
92
|
-
}, {
|
|
93
|
-
spaces: 2
|
|
94
|
-
});
|
|
120
|
+
const routeJSONPath = import_path.default.join(dir, import_utils.ROUTE_SPEC_FILE);
|
|
121
|
+
import_utils.fs.writeJSONSync(routeJSONPath, { routes }, { spaces: 2 });
|
|
95
122
|
};
|
|
96
|
-
|
|
97
|
-
const replaceWithAlias = (base, filePath, alias) => _path.default.posix.join(alias, _path.default.posix.relative(base, filePath));
|
|
98
|
-
exports.replaceWithAlias = replaceWithAlias;
|
|
123
|
+
const replaceWithAlias = (base, filePath, alias) => import_path.default.posix.join(alias, import_path.default.posix.relative(base, filePath));
|
|
99
124
|
const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
100
125
|
if (ssgOptions === false) {
|
|
101
126
|
return false;
|
|
@@ -105,33 +130,29 @@ const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
|
105
130
|
opt[entry.entryName] = ssgOptions;
|
|
106
131
|
return opt;
|
|
107
132
|
}, {});
|
|
108
|
-
} else if (typeof ssgOptions ===
|
|
109
|
-
const isSingle = (0,
|
|
110
|
-
if (isSingle && typeof ssgOptions.main ===
|
|
111
|
-
return {
|
|
112
|
-
main: ssgOptions
|
|
113
|
-
};
|
|
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 };
|
|
114
137
|
} else {
|
|
115
138
|
return ssgOptions;
|
|
116
139
|
}
|
|
117
|
-
} else if (typeof ssgOptions ===
|
|
140
|
+
} else if (typeof ssgOptions === "function") {
|
|
118
141
|
const intermediateOptions = {};
|
|
119
142
|
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)) {
|
|
143
|
+
const { entryName } = entrypoint;
|
|
144
|
+
if (Array.isArray(server == null ? void 0 : server.baseUrl)) {
|
|
125
145
|
for (const url of server.baseUrl) {
|
|
126
|
-
const matchUrl = entryName ===
|
|
127
|
-
const route = routes.find(
|
|
128
|
-
intermediateOptions[route
|
|
129
|
-
|
|
130
|
-
|
|
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
|
+
);
|
|
131
152
|
}
|
|
132
153
|
} else {
|
|
133
154
|
intermediateOptions[entryName] = ssgOptions(entryName, {
|
|
134
|
-
baseUrl: server
|
|
155
|
+
baseUrl: server == null ? void 0 : server.baseUrl
|
|
135
156
|
});
|
|
136
157
|
}
|
|
137
158
|
}
|
|
@@ -139,31 +160,25 @@ const standardOptions = (ssgOptions, entrypoints, routes, server) => {
|
|
|
139
160
|
}
|
|
140
161
|
return false;
|
|
141
162
|
};
|
|
142
|
-
|
|
143
|
-
const openRouteSSR = (routes, entries = []) => routes.map(ssgRoute => _objectSpread(_objectSpread({}, ssgRoute), {}, {
|
|
163
|
+
const openRouteSSR = (routes, entries = []) => routes.map((ssgRoute) => __spreadProps(__spreadValues({}, ssgRoute), {
|
|
144
164
|
isSSR: entries.includes(ssgRoute.entryName),
|
|
145
|
-
bundle: `${
|
|
165
|
+
bundle: `${import_utils.SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
|
|
146
166
|
}));
|
|
147
|
-
|
|
148
|
-
// TODO: 过滤带有 server loader 的路由
|
|
149
|
-
exports.openRouteSSR = openRouteSSR;
|
|
150
|
-
const flattenRoutes = routes => {
|
|
167
|
+
const flattenRoutes = (routes) => {
|
|
151
168
|
const parents = [];
|
|
152
169
|
const newRoutes = [];
|
|
153
|
-
const traverseRoute = route => {
|
|
170
|
+
const traverseRoute = (route) => {
|
|
154
171
|
const parent = parents[parents.length - 1];
|
|
155
|
-
let
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
newRoutes.push(_objectSpread(_objectSpread({}, route), {}, {
|
|
161
|
-
path
|
|
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
|
|
162
177
|
}));
|
|
163
178
|
}
|
|
164
179
|
if (route.children) {
|
|
165
|
-
parents.push(
|
|
166
|
-
path
|
|
180
|
+
parents.push(__spreadProps(__spreadValues({}, route), {
|
|
181
|
+
path: path2
|
|
167
182
|
}));
|
|
168
183
|
route.children.forEach(traverseRoute);
|
|
169
184
|
parents.pop();
|
|
@@ -172,4 +187,17 @@ const flattenRoutes = routes => {
|
|
|
172
187
|
routes.forEach(traverseRoute);
|
|
173
188
|
return newRoutes;
|
|
174
189
|
};
|
|
175
|
-
|
|
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
|
+
});
|
|
@@ -1,8 +1,27 @@
|
|
|
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 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
|
|
5
27
|
});
|
|
6
|
-
exports.CLOSE_SIGN = void 0;
|
|
7
|
-
const CLOSE_SIGN = 'modern_close_server';
|
|
8
|
-
exports.CLOSE_SIGN = CLOSE_SIGN;
|
|
@@ -1,68 +1,92 @@
|
|
|
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 server_exports = {};
|
|
25
|
+
__export(server_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(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");
|
|
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
|
-
|
|
89
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
90
|
+
0 && (module.exports = {
|
|
91
|
+
createServer
|
|
92
|
+
});
|