@modern-js/plugin-ssg 2.0.0-beta.3 → 2.0.0-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/js/modern/global.d.js +0 -0
  3. package/dist/js/modern/index.js +171 -155
  4. package/dist/js/modern/libs/make.js +44 -27
  5. package/dist/js/modern/libs/output.js +7 -4
  6. package/dist/js/modern/libs/replace.js +45 -27
  7. package/dist/js/modern/libs/util.js +91 -76
  8. package/dist/js/modern/server/consts.js +4 -1
  9. package/dist/js/modern/server/index.js +31 -28
  10. package/dist/js/modern/server/prerender.js +32 -15
  11. package/dist/js/modern/server/process.js +78 -57
  12. package/dist/js/modern/types.js +0 -1
  13. package/dist/js/node/global.d.js +0 -0
  14. package/dist/js/node/index.js +192 -166
  15. package/dist/js/node/libs/make.js +66 -32
  16. package/dist/js/node/libs/output.js +34 -13
  17. package/dist/js/node/libs/replace.js +68 -33
  18. package/dist/js/node/libs/util.js +107 -91
  19. package/dist/js/node/server/consts.js +22 -7
  20. package/dist/js/node/server/index.js +59 -39
  21. package/dist/js/node/server/prerender.js +56 -22
  22. package/dist/js/node/server/process.js +108 -62
  23. package/dist/js/node/types.js +0 -5
  24. package/dist/js/treeshaking/global.d.js +1 -0
  25. package/dist/js/treeshaking/index.js +339 -0
  26. package/dist/js/treeshaking/libs/make.js +83 -0
  27. package/dist/js/treeshaking/libs/output.js +13 -0
  28. package/dist/js/treeshaking/libs/replace.js +115 -0
  29. package/dist/js/treeshaking/libs/util.js +239 -0
  30. package/dist/js/treeshaking/server/consts.js +2 -0
  31. package/dist/js/treeshaking/server/index.js +63 -0
  32. package/dist/js/treeshaking/server/prerender.js +97 -0
  33. package/dist/js/treeshaking/server/process.js +226 -0
  34. package/dist/js/treeshaking/types.js +1 -0
  35. package/dist/types/index.d.ts +2 -0
  36. package/dist/types/libs/util.d.ts +0 -1
  37. package/package.json +7 -12
@@ -1,21 +1,64 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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.exist = exist;
7
- exports.replaceRoute = replaceRoute;
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; }
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, _normalizePath.default)(pageRoute.urlPath) === (0, _normalizePath.default)(route.urlPath);
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
- // remove redundant fields and replace rendered entryPath
28
- const cleanSsgRoutes = ssgRoutes.map(ssgRoute => {
29
- const {
30
- output,
31
- headers
32
- } = ssgRoute,
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
- // new route
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
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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.flattenRoutes = void 0;
7
- exports.formatOutput = formatOutput;
8
- exports.formatPath = formatPath;
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; }
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 = _path.default.extname(filename) ? filename : `${filename}/index.html`;
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 !== 'string') {
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('/') && addr !== '/') {
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 === '/' ? '' : base;
59
- const entryName = route.entryName === 'main' ? '' : route.entryName;
97
+ base = base === "/" ? "" : base;
98
+ const entryName = route.entryName === "main" ? "" : route.entryName;
60
99
  const prefix = `${base}/${entryName}`;
61
- return prefix.endsWith('/') ? prefix.slice(0, -1) : prefix;
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('/') ? urlWithoutBase.slice(1) : urlWithoutBase;
108
+ const urlWithoutBase = route.urlPath.replace(base, "");
109
+ return urlWithoutBase.startsWith("/") ? urlWithoutBase.slice(1) : urlWithoutBase;
76
110
  }
77
- throw new Error(`routing must provide output when calling createPage(), check ${route.urlPath}`);
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 = _path.default.join(dir, _utils.ROUTE_SPEC_FILE);
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 = _path.default.join(dir, _utils.ROUTE_SPEC_FILE);
90
- _utils.fs.writeJSONSync(routeJSONPath, {
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
- exports.writeJSONSpec = writeJSONSpec;
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 === 'object') {
109
- const isSingle = (0, _utils.isSingleEntry)(entrypoints);
110
- if (isSingle && typeof ssgOptions.main === 'undefined') {
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 === 'function') {
142
+ } else if (typeof ssgOptions === "function") {
118
143
  const intermediateOptions = {};
119
144
  for (const entrypoint of entrypoints) {
120
- const {
121
- entryName
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 === 'main' ? url : `${url}/${entryName}`;
127
- const route = routes.find(route => route.urlPath === matchUrl);
128
- intermediateOptions[route === null || route === void 0 ? void 0 : route.urlPath] = ssgOptions(entryName, {
129
- baseUrl: url
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 === null || server === void 0 ? void 0 : server.baseUrl
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
- exports.standardOptions = standardOptions;
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: `${_utils.SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
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 path = parent ? `${parent.path}/${route.path || ''}`.replace(/\/+/g, '/') : route.path || ''; // If the route is an index route, the route has no path property
156
- path = path.replace(/\/$/, '');
157
-
158
- // If the route path is / and is not the root route, it should not be used as an ssg route
159
- if (route._component && (path !== '/' || path === '/' && !parent)) {
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(_objectSpread(_objectSpread({}, route), {}, {
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
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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.CLOSE_SIGN = void 0;
7
- const CLOSE_SIGN = 'modern_close_server';
8
- exports.CLOSE_SIGN = CLOSE_SIGN;
22
+ module.exports = __toCommonJS(stdin_exports);
23
+ const CLOSE_SIGN = "modern_close_server";
@@ -1,68 +1,88 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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.createServer = void 0;
7
- var _child_process = _interopRequireDefault(require("child_process"));
8
- var _path = _interopRequireDefault(require("path"));
9
- var _utils = require("@modern-js/utils");
10
- var _util = require("../libs/util");
11
- var _consts = require("./consts");
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
- // this side of the shallow copy of a route for subsequent render processing, to prevent the modification of the current field
15
- // manually enable the server-side rendering configuration for all routes that require SSG
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 = _child_process.default.fork(_path.default.join(__dirname, 'process'), {
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(JSON.stringify({
26
- options,
27
- renderRoutes: ssgRoutes,
28
- routes: total,
29
- appDirectory,
30
- plugins
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('message', chunk => {
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(_consts.CLOSE_SIGN);
64
+ cp.send(import_consts.CLOSE_SIGN);
44
65
  resolve(htmlAry);
45
66
  }
46
67
  });
47
- cp.stderr.on('data', chunk => {
68
+ cp.stderr.on("data", (chunk) => {
48
69
  const str = chunk.toString();
49
- if (str.includes('Error')) {
50
- _utils.logger.error(str);
51
- reject(new Error('ssg render failed'));
52
- cp.kill('SIGKILL');
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
- _utils.logger.info(str.replace(/[^\S\n]+/g, ' '));
75
+ import_utils.logger.info(str.replace(/[^\S\n]+/g, " "));
55
76
  }
56
77
  });
57
- cp.stdout.on('data', chunk => {
78
+ cp.stdout.on("data", (chunk) => {
58
79
  const str = chunk.toString();
59
- if (str.includes('Error')) {
60
- _utils.logger.error(str);
61
- reject(new Error('ssg render failed'));
62
- cp.kill('SIGKILL');
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
- _utils.logger.info(str.replace(/[^\S\n]+/g, ' '));
85
+ import_utils.logger.info(str.replace(/[^\S\n]+/g, " "));
65
86
  }
66
87
  });
67
88
  });
68
- exports.createServer = createServer;