@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,86 +1,96 @@
1
- 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; }
2
- 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; }
3
- 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; }
4
- import path from 'path';
5
- import { ROUTE_SPEC_FILE, fs, isSingleEntry, SERVER_BUNDLE_DIRECTORY } from '@modern-js/utils';
6
- export function formatOutput(filename) {
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import path from "path";
21
+ import {
22
+ ROUTE_SPEC_FILE,
23
+ fs,
24
+ isSingleEntry,
25
+ SERVER_BUNDLE_DIRECTORY
26
+ } from "@modern-js/utils";
27
+ function formatOutput(filename) {
7
28
  const outputPath = path.extname(filename) ? filename : `${filename}/index.html`;
8
29
  return outputPath;
9
30
  }
10
- export function formatPath(str) {
31
+ function formatPath(str) {
11
32
  let addr = str;
12
- if (!addr || typeof addr !== 'string') {
33
+ if (!addr || typeof addr !== "string") {
13
34
  return addr;
14
35
  }
15
- if (addr.startsWith('.')) {
36
+ if (addr.startsWith(".")) {
16
37
  addr = addr.slice(1);
17
38
  }
18
- if (!addr.startsWith('/')) {
39
+ if (!addr.startsWith("/")) {
19
40
  addr = `/${addr}`;
20
41
  }
21
- if (addr.endsWith('/') && addr !== '/') {
42
+ if (addr.endsWith("/") && addr !== "/") {
22
43
  addr = addr.slice(0, addr.length - 1);
23
44
  }
24
45
  return addr;
25
46
  }
26
- export function isDynamicUrl(url) {
27
- return url.includes(':');
47
+ function isDynamicUrl(url) {
48
+ return url.includes(":");
28
49
  }
29
- export function getUrlPrefix(route, baseUrl) {
30
- let base = '';
50
+ function getUrlPrefix(route, baseUrl) {
51
+ let base = "";
31
52
  if (Array.isArray(baseUrl)) {
32
- const filters = baseUrl.filter(url => route.urlPath.includes(url));
53
+ const filters = baseUrl.filter((url) => route.urlPath.includes(url));
33
54
  if (filters.length > 1) {
34
55
  const matched = filters.sort((a, b) => a.length - b.length)[0];
35
-
36
- // this should never happened
37
56
  if (!matched) {
38
- throw new Error('');
57
+ throw new Error("");
39
58
  }
40
59
  base = matched;
41
60
  }
42
61
  } else {
43
62
  base = baseUrl;
44
63
  }
45
- base = base === '/' ? '' : base;
46
- const entryName = route.entryName === 'main' ? '' : route.entryName;
64
+ base = base === "/" ? "" : base;
65
+ const entryName = route.entryName === "main" ? "" : route.entryName;
47
66
  const prefix = `${base}/${entryName}`;
48
- return prefix.endsWith('/') ? prefix.slice(0, -1) : prefix;
67
+ return prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
49
68
  }
50
-
51
- // if no output, return default path for aggred-route(relative),
52
- // or throw error for control-route
53
- export function getOutput(route, base, agreed) {
54
- const {
55
- output
56
- } = route;
69
+ function getOutput(route, base, agreed) {
70
+ const { output } = route;
57
71
  if (output) {
58
72
  return output;
59
73
  }
60
74
  if (agreed) {
61
- const urlWithoutBase = route.urlPath.replace(base, '');
62
- return urlWithoutBase.startsWith('/') ? urlWithoutBase.slice(1) : urlWithoutBase;
75
+ const urlWithoutBase = route.urlPath.replace(base, "");
76
+ return urlWithoutBase.startsWith("/") ? urlWithoutBase.slice(1) : urlWithoutBase;
63
77
  }
64
- throw new Error(`routing must provide output when calling createPage(), check ${route.urlPath}`);
78
+ throw new Error(
79
+ `routing must provide output when calling createPage(), check ${route.urlPath}`
80
+ );
65
81
  }
66
- export const readJSONSpec = dir => {
82
+ const readJSONSpec = (dir) => {
67
83
  const routeJSONPath = path.join(dir, ROUTE_SPEC_FILE);
68
84
  const routeJSON = require(routeJSONPath);
69
- const {
70
- routes
71
- } = routeJSON;
85
+ const { routes } = routeJSON;
72
86
  return routes;
73
87
  };
74
- export const writeJSONSpec = (dir, routes) => {
88
+ const writeJSONSpec = (dir, routes) => {
75
89
  const routeJSONPath = path.join(dir, ROUTE_SPEC_FILE);
76
- fs.writeJSONSync(routeJSONPath, {
77
- routes
78
- }, {
79
- spaces: 2
80
- });
90
+ fs.writeJSONSync(routeJSONPath, { routes }, { spaces: 2 });
81
91
  };
82
- export const replaceWithAlias = (base, filePath, alias) => path.posix.join(alias, path.posix.relative(base, filePath));
83
- export const standardOptions = (ssgOptions, entrypoints, routes, server) => {
92
+ const replaceWithAlias = (base, filePath, alias) => path.posix.join(alias, path.posix.relative(base, filePath));
93
+ const standardOptions = (ssgOptions, entrypoints, routes, server) => {
84
94
  if (ssgOptions === false) {
85
95
  return false;
86
96
  }
@@ -89,33 +99,29 @@ export const standardOptions = (ssgOptions, entrypoints, routes, server) => {
89
99
  opt[entry.entryName] = ssgOptions;
90
100
  return opt;
91
101
  }, {});
92
- } else if (typeof ssgOptions === 'object') {
102
+ } else if (typeof ssgOptions === "object") {
93
103
  const isSingle = isSingleEntry(entrypoints);
94
- if (isSingle && typeof ssgOptions.main === 'undefined') {
95
- return {
96
- main: ssgOptions
97
- };
104
+ if (isSingle && typeof ssgOptions.main === "undefined") {
105
+ return { main: ssgOptions };
98
106
  } else {
99
107
  return ssgOptions;
100
108
  }
101
- } else if (typeof ssgOptions === 'function') {
109
+ } else if (typeof ssgOptions === "function") {
102
110
  const intermediateOptions = {};
103
111
  for (const entrypoint of entrypoints) {
104
- const {
105
- entryName
106
- } = entrypoint;
107
- // TODO: may be async function
108
- if (Array.isArray(server === null || server === void 0 ? void 0 : server.baseUrl)) {
112
+ const { entryName } = entrypoint;
113
+ if (Array.isArray(server == null ? void 0 : server.baseUrl)) {
109
114
  for (const url of server.baseUrl) {
110
- const matchUrl = entryName === 'main' ? url : `${url}/${entryName}`;
111
- const route = routes.find(route => route.urlPath === matchUrl);
112
- intermediateOptions[route === null || route === void 0 ? void 0 : route.urlPath] = ssgOptions(entryName, {
113
- baseUrl: url
114
- });
115
+ const matchUrl = entryName === "main" ? url : `${url}/${entryName}`;
116
+ const route = routes.find((route2) => route2.urlPath === matchUrl);
117
+ intermediateOptions[route == null ? void 0 : route.urlPath] = ssgOptions(
118
+ entryName,
119
+ { baseUrl: url }
120
+ );
115
121
  }
116
122
  } else {
117
123
  intermediateOptions[entryName] = ssgOptions(entryName, {
118
- baseUrl: server === null || server === void 0 ? void 0 : server.baseUrl
124
+ baseUrl: server == null ? void 0 : server.baseUrl
119
125
  });
120
126
  }
121
127
  }
@@ -123,29 +129,25 @@ export const standardOptions = (ssgOptions, entrypoints, routes, server) => {
123
129
  }
124
130
  return false;
125
131
  };
126
- export const openRouteSSR = (routes, entries = []) => routes.map(ssgRoute => _objectSpread(_objectSpread({}, ssgRoute), {}, {
132
+ const openRouteSSR = (routes, entries = []) => routes.map((ssgRoute) => __spreadProps(__spreadValues({}, ssgRoute), {
127
133
  isSSR: entries.includes(ssgRoute.entryName),
128
134
  bundle: `${SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
129
135
  }));
130
-
131
- // TODO: 过滤带有 server loader 的路由
132
- export const flattenRoutes = routes => {
136
+ const flattenRoutes = (routes) => {
133
137
  const parents = [];
134
138
  const newRoutes = [];
135
- const traverseRoute = route => {
139
+ const traverseRoute = (route) => {
136
140
  const parent = parents[parents.length - 1];
137
- let path = parent ? `${parent.path}/${route.path || ''}`.replace(/\/+/g, '/') : route.path || ''; // If the route is an index route, the route has no path property
138
- path = path.replace(/\/$/, '');
139
-
140
- // If the route path is / and is not the root route, it should not be used as an ssg route
141
- if (route._component && (path !== '/' || path === '/' && !parent)) {
142
- newRoutes.push(_objectSpread(_objectSpread({}, route), {}, {
143
- path
141
+ let path2 = parent ? `${parent.path}/${route.path || ""}`.replace(/\/+/g, "/") : route.path || "";
142
+ path2 = path2.replace(/\/$/, "");
143
+ if (route._component && (path2 !== "/" || path2 === "/" && !parent)) {
144
+ newRoutes.push(__spreadProps(__spreadValues({}, route), {
145
+ path: path2
144
146
  }));
145
147
  }
146
148
  if (route.children) {
147
- parents.push(_objectSpread(_objectSpread({}, route), {}, {
148
- path
149
+ parents.push(__spreadProps(__spreadValues({}, route), {
150
+ path: path2
149
151
  }));
150
152
  route.children.forEach(traverseRoute);
151
153
  parents.pop();
@@ -153,4 +155,17 @@ export const flattenRoutes = routes => {
153
155
  };
154
156
  routes.forEach(traverseRoute);
155
157
  return newRoutes;
156
- };
158
+ };
159
+ export {
160
+ flattenRoutes,
161
+ formatOutput,
162
+ formatPath,
163
+ getOutput,
164
+ getUrlPrefix,
165
+ isDynamicUrl,
166
+ openRouteSSR,
167
+ readJSONSpec,
168
+ replaceWithAlias,
169
+ standardOptions,
170
+ writeJSONSpec
171
+ };
@@ -1 +1,4 @@
1
- export const CLOSE_SIGN = 'modern_close_server';
1
+ const CLOSE_SIGN = "modern_close_server";
2
+ export {
3
+ CLOSE_SIGN
4
+ };
@@ -1,34 +1,34 @@
1
- import childProcess from 'child_process';
2
- import path from 'path';
3
- import { logger } from '@modern-js/utils';
1
+ import childProcess from "child_process";
2
+ import path from "path";
3
+ import { logger } from "@modern-js/utils";
4
4
  import { openRouteSSR } from "../libs/util";
5
5
  import { CLOSE_SIGN } from "./consts";
6
- export const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
7
- // this side of the shallow copy of a route for subsequent render processing, to prevent the modification of the current field
8
- // manually enable the server-side rendering configuration for all routes that require SSG
9
- const entries = ssgRoutes.map(route => route.entryName);
6
+ const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, appDirectory) => new Promise((resolve, reject) => {
7
+ const entries = ssgRoutes.map((route) => route.entryName);
10
8
  const backup = openRouteSSR(pageRoutes, entries);
11
9
  const total = backup.concat(apiRoutes);
12
- const cp = childProcess.fork(path.join(__dirname, 'process'), {
10
+ const cp = childProcess.fork(path.join(__dirname, "process"), {
13
11
  cwd: appDirectory,
14
12
  silent: true
15
13
  });
16
14
  const appContext = api.useAppContext();
17
15
  const plugins = appContext.serverInternalPlugins;
18
- cp.send(JSON.stringify({
19
- options,
20
- renderRoutes: ssgRoutes,
21
- routes: total,
22
- appDirectory,
23
- plugins
24
- }));
16
+ cp.send(
17
+ JSON.stringify({
18
+ options,
19
+ renderRoutes: ssgRoutes,
20
+ routes: total,
21
+ appDirectory,
22
+ plugins
23
+ })
24
+ );
25
25
  const htmlChunks = [];
26
26
  const htmlAry = [];
27
- cp.on('message', chunk => {
27
+ cp.on("message", (chunk) => {
28
28
  if (chunk !== null) {
29
29
  htmlChunks.push(chunk);
30
30
  } else {
31
- const html = htmlChunks.join('');
31
+ const html = htmlChunks.join("");
32
32
  htmlAry.push(html);
33
33
  htmlChunks.length = 0;
34
34
  }
@@ -37,24 +37,27 @@ export const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, app
37
37
  resolve(htmlAry);
38
38
  }
39
39
  });
40
- cp.stderr.on('data', chunk => {
40
+ cp.stderr.on("data", (chunk) => {
41
41
  const str = chunk.toString();
42
- if (str.includes('Error')) {
42
+ if (str.includes("Error")) {
43
43
  logger.error(str);
44
- reject(new Error('ssg render failed'));
45
- cp.kill('SIGKILL');
44
+ reject(new Error("ssg render failed"));
45
+ cp.kill("SIGKILL");
46
46
  } else {
47
- logger.info(str.replace(/[^\S\n]+/g, ' '));
47
+ logger.info(str.replace(/[^\S\n]+/g, " "));
48
48
  }
49
49
  });
50
- cp.stdout.on('data', chunk => {
50
+ cp.stdout.on("data", (chunk) => {
51
51
  const str = chunk.toString();
52
- if (str.includes('Error')) {
52
+ if (str.includes("Error")) {
53
53
  logger.error(str);
54
- reject(new Error('ssg render failed'));
55
- cp.kill('SIGKILL');
54
+ reject(new Error("ssg render failed"));
55
+ cp.kill("SIGKILL");
56
56
  } else {
57
- logger.info(str.replace(/[^\S\n]+/g, ' '));
57
+ logger.info(str.replace(/[^\S\n]+/g, " "));
58
58
  }
59
59
  });
60
- });
60
+ });
61
+ export {
62
+ createServer
63
+ };
@@ -1,36 +1,53 @@
1
- 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; }
2
- 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; }
3
- 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; }
4
- import EventEmitter from 'events';
5
- import { Readable } from 'stream';
6
- import httpMocks from 'node-mocks-http';
7
- export const compile = requestHandler => (options, extend = {}) => new Promise((resolve, reject) => {
8
- const req = httpMocks.createRequest(_objectSpread(_objectSpread({}, options), {}, {
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import EventEmitter from "events";
21
+ import { Readable } from "stream";
22
+ import httpMocks from "node-mocks-http";
23
+ const compile = (requestHandler) => (options, extend = {}) => new Promise((resolve, reject) => {
24
+ const req = httpMocks.createRequest(__spreadProps(__spreadValues({}, options), {
9
25
  eventEmitter: Readable
10
26
  }));
11
- const res = httpMocks.createResponse({
12
- eventEmitter: EventEmitter
13
- });
27
+ const res = httpMocks.createResponse({ eventEmitter: EventEmitter });
14
28
  Object.assign(req, extend);
15
29
  const proxyRes = new Proxy(res, {
16
30
  get(obj, prop) {
17
- if (typeof prop === 'symbol' && !obj[prop]) {
31
+ if (typeof prop === "symbol" && !obj[prop]) {
18
32
  return null;
19
33
  }
20
34
  return obj[prop];
21
35
  }
22
36
  });
23
- res.on('finish', () => {
37
+ res.on("finish", () => {
24
38
  if (res.statusCode !== 200) {
25
39
  reject(new Error(res.statusMessage));
26
40
  } else {
27
41
  resolve(res._getData());
28
42
  }
29
43
  });
30
- res.on('error', e => reject(e));
44
+ res.on("error", (e) => reject(e));
31
45
  try {
32
46
  requestHandler(req, proxyRes);
33
47
  } catch (e) {
34
48
  reject(e);
35
49
  }
36
- });
50
+ });
51
+ export {
52
+ compile
53
+ };
@@ -1,63 +1,84 @@
1
- import server from '@modern-js/prod-server';
2
- import portfinder from 'portfinder';
1
+ var __getOwnPropNames = Object.getOwnPropertyNames;
2
+ var __commonJS = (cb, mod) => function __require() {
3
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
4
+ };
5
+ var __async = (__this, __arguments, generator) => {
6
+ return new Promise((resolve, reject) => {
7
+ var fulfilled = (value) => {
8
+ try {
9
+ step(generator.next(value));
10
+ } catch (e) {
11
+ reject(e);
12
+ }
13
+ };
14
+ var rejected = (value) => {
15
+ try {
16
+ step(generator.throw(value));
17
+ } catch (e) {
18
+ reject(e);
19
+ }
20
+ };
21
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
22
+ step((generator = generator.apply(__this, __arguments)).next());
23
+ });
24
+ };
25
+ import server from "@modern-js/prod-server";
26
+ import portfinder from "portfinder";
3
27
  import { makeRender } from "../libs/make";
4
28
  import { compile as createRender } from "./prerender";
5
29
  import { CLOSE_SIGN } from "./consts";
6
- process.on('message', async chunk => {
7
- if (chunk === CLOSE_SIGN) {
8
- // eslint-disable-next-line no-process-exit
9
- process.exit();
10
- }
11
- const context = JSON.parse(chunk);
12
- const {
13
- routes,
14
- renderRoutes,
15
- options,
16
- appDirectory,
17
- plugins
18
- } = context;
19
- let modernServer = null;
20
- try {
21
- const {
22
- server: serverOptions
23
- } = options;
24
-
25
- // start server in default port
26
- const defaultPort = Number(process.env.PORT) || serverOptions.port;
27
- portfinder.basePort = defaultPort;
28
- const port = await portfinder.getPortPromise();
29
- modernServer = await server({
30
- pwd: appDirectory,
31
- config: options,
32
- routes,
33
- staticGenerate: true,
34
- internalPlugins: plugins
35
- });
36
-
37
- // listen just for bff request in ssr page
38
- modernServer.listen(port, async err => {
39
- if (err) {
40
- throw err;
30
+ var require_process = __commonJS({
31
+ "src/server/process.ts"(exports) {
32
+ process.on("message", (chunk) => __async(exports, null, function* () {
33
+ if (chunk === CLOSE_SIGN) {
34
+ process.exit();
41
35
  }
42
- if (!modernServer) {
43
- return;
36
+ const context = JSON.parse(chunk);
37
+ const {
38
+ routes,
39
+ renderRoutes,
40
+ options,
41
+ appDirectory,
42
+ plugins
43
+ } = context;
44
+ let modernServer = null;
45
+ try {
46
+ const { server: serverOptions } = options;
47
+ const defaultPort = Number(process.env.PORT) || serverOptions.port;
48
+ portfinder.basePort = defaultPort;
49
+ const port = yield portfinder.getPortPromise();
50
+ modernServer = yield server({
51
+ pwd: appDirectory,
52
+ config: options,
53
+ routes,
54
+ staticGenerate: true,
55
+ internalPlugins: plugins
56
+ });
57
+ modernServer.listen(port, (err) => __async(exports, null, function* () {
58
+ if (err) {
59
+ throw err;
60
+ }
61
+ if (!modernServer) {
62
+ return;
63
+ }
64
+ const render = createRender(modernServer.getRequestHandler());
65
+ const renderPromiseAry = makeRender(
66
+ renderRoutes,
67
+ render,
68
+ port
69
+ );
70
+ const htmlAry = yield Promise.all(renderPromiseAry);
71
+ htmlAry.forEach((html) => {
72
+ process.send(html);
73
+ process.send(null);
74
+ });
75
+ modernServer.close();
76
+ }));
77
+ } catch (e) {
78
+ modernServer == null ? void 0 : modernServer.close();
79
+ throw e;
44
80
  }
45
-
46
- // get server handler, render to ssr
47
- const render = createRender(modernServer.getRequestHandler());
48
- const renderPromiseAry = makeRender(renderRoutes, render, port);
49
-
50
- // eslint-disable-next-line promise/no-promise-in-callback
51
- const htmlAry = await Promise.all(renderPromiseAry);
52
- htmlAry.forEach(html => {
53
- process.send(html);
54
- process.send(null);
55
- });
56
- modernServer.close();
57
- });
58
- } catch (e) {
59
- var _modernServer;
60
- (_modernServer = modernServer) === null || _modernServer === void 0 ? void 0 : _modernServer.close();
61
- throw e;
81
+ }));
62
82
  }
63
- });
83
+ });
84
+ export default require_process();
@@ -1 +0,0 @@
1
- export {};
File without changes