@modern-js/plugin-ssg 2.0.0-beta.0 → 2.0.0-beta.2

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 CHANGED
@@ -1,5 +1,57 @@
1
1
  # @modern-js/plugin-ssg
2
2
 
3
+ ## 2.0.0-beta.2
4
+
5
+ ### Major Changes
6
+
7
+ - dda38c9c3e: chore: v2
8
+
9
+ ### Patch Changes
10
+
11
+ - cc971eabfc: refactor: move server plugin load logic in `@modern-js/core`
12
+ refactor:移除在 `@modern-js/core` 中的 server 插件加载逻辑
13
+ - 8b8e1bb571: feat: support nested routes
14
+ feat: 支持嵌套路由
15
+ - Updated dependencies [92f0ead]
16
+ - Updated dependencies [edd1cfb1af]
17
+ - Updated dependencies [cc971eabfc]
18
+ - Updated dependencies [5b9049f2e9]
19
+ - Updated dependencies [92004d1]
20
+ - Updated dependencies [b8bbe036c7]
21
+ - Updated dependencies [d5a31df781]
22
+ - Updated dependencies [dda38c9c3e]
23
+ - Updated dependencies [3bbea92b2a]
24
+ - Updated dependencies [abf3421a75]
25
+ - Updated dependencies [543be9558e]
26
+ - Updated dependencies [14b712da84]
27
+ - @modern-js/utils@2.0.0-beta.2
28
+
29
+ ## 2.0.0-beta.1
30
+
31
+ ### Major Changes
32
+
33
+ - dda38c9: chore: v2
34
+
35
+ ### Patch Changes
36
+
37
+ - cc971eabfc: refactor: move server plugin load logic in `@modern-js/core`
38
+ refactor:移除在 `@modern-js/core` 中的 server 插件加载逻辑
39
+ - 8b8e1bb571: feat: support nested routes
40
+ feat: 支持嵌套路由
41
+ - Updated dependencies [92f0ead]
42
+ - Updated dependencies [edd1cfb1af]
43
+ - Updated dependencies [cc971eabfc]
44
+ - Updated dependencies [5b9049f]
45
+ - Updated dependencies [92004d1]
46
+ - Updated dependencies [b8bbe036c7]
47
+ - Updated dependencies [d5a31df781]
48
+ - Updated dependencies [dda38c9]
49
+ - Updated dependencies [3bbea92b2a]
50
+ - Updated dependencies [abf3421]
51
+ - Updated dependencies [543be9558e]
52
+ - Updated dependencies [14b712d]
53
+ - @modern-js/utils@2.0.0-beta.1
54
+
3
55
  ## 2.0.0-beta.0
4
56
 
5
57
  ### Major Changes
@@ -1,9 +1,6 @@
1
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
-
3
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; }
4
-
5
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; }
6
-
7
4
  import path from 'path';
8
5
  import { logger, PLUGIN_SCHEMAS } from '@modern-js/utils';
9
6
  import { generatePath } from 'react-router-dom';
@@ -21,7 +18,6 @@ export default (() => ({
21
18
  validateSchema() {
22
19
  return PLUGIN_SCHEMAS['@modern-js/plugin-ssg'];
23
20
  },
24
-
25
21
  modifyFileSystemRoutes({
26
22
  entrypoint,
27
23
  routes
@@ -36,7 +32,6 @@ export default (() => ({
36
32
  routes
37
33
  };
38
34
  },
39
-
40
35
  async afterBuild() {
41
36
  const resolvedConfig = api.useResolvedConfigContext();
42
37
  const appContext = api.useAppContext();
@@ -50,32 +45,32 @@ export default (() => ({
50
45
  } = resolvedConfig;
51
46
  const {
52
47
  ssg,
53
- path: outputPath
48
+ distPath: {
49
+ root: outputPath
50
+ } = {}
54
51
  } = output;
55
- const ssgOptions = Array.isArray(ssg) ? ssg.pop() : ssg; // no ssg configuration, skip ssg render.
56
-
52
+ const ssgOptions = Array.isArray(ssg) ? ssg.pop() : ssg;
53
+ // no ssg configuration, skip ssg render.
57
54
  if (!ssgOptions) {
58
55
  return;
59
56
  }
60
-
61
57
  const buildDir = path.join(appDirectory, outputPath);
62
- const routes = readJSONSpec(buildDir); // filter all routes not web
58
+ const routes = readJSONSpec(buildDir);
63
59
 
60
+ // filter all routes not web
64
61
  const pageRoutes = routes.filter(route => !route.isApi);
65
- const apiRoutes = routes.filter(route => route.isApi); // if no web page route, skip ssg render
62
+ const apiRoutes = routes.filter(route => route.isApi);
66
63
 
64
+ // if no web page route, skip ssg render
67
65
  if (pageRoutes.length === 0) {
68
66
  return;
69
67
  }
70
-
71
68
  const intermediateOptions = standardOptions(ssgOptions, entrypoints, pageRoutes, server);
72
-
73
69
  if (!intermediateOptions) {
74
70
  return;
75
71
  }
76
-
77
- const ssgRoutes = []; // each route will try to match the configuration
78
-
72
+ const ssgRoutes = [];
73
+ // each route will try to match the configuration
79
74
  pageRoutes.forEach(pageRoute => {
80
75
  const {
81
76
  entryName,
@@ -83,14 +78,13 @@ export default (() => ({
83
78
  } = pageRoute;
84
79
  const agreedRoutes = agreedRouteMap[entryName];
85
80
  let entryOptions = intermediateOptions[entryName] || intermediateOptions[pageRoute.urlPath];
86
-
87
81
  if (!agreedRoutes) {
88
82
  // default behavior for non-agreed route
89
83
  if (!entryOptions) {
90
84
  return;
91
- } // only add entry route if entryOptions is true
92
-
85
+ }
93
86
 
87
+ // only add entry route if entryOptions is true
94
88
  if (entryOptions === true) {
95
89
  ssgRoutes.push(_objectSpread(_objectSpread({}, pageRoute), {}, {
96
90
  output: entryPath
@@ -112,7 +106,6 @@ export default (() => ({
112
106
  if (!entryOptions) {
113
107
  return;
114
108
  }
115
-
116
109
  if (entryOptions === true) {
117
110
  entryOptions = {
118
111
  preventDefault: [],
@@ -120,13 +113,12 @@ export default (() => ({
120
113
  headers: {}
121
114
  };
122
115
  }
123
-
124
116
  const {
125
117
  preventDefault = [],
126
118
  routes: userRoutes = [],
127
119
  headers
128
- } = entryOptions; // if the user sets the routes, then only add them
129
-
120
+ } = entryOptions;
121
+ // if the user sets the routes, then only add them
130
122
  if (userRoutes.length > 0) {
131
123
  userRoutes.forEach(route => {
132
124
  if (typeof route === 'string') {
@@ -151,36 +143,34 @@ export default (() => ({
151
143
  }
152
144
  }
153
145
  });
154
-
155
146
  if (ssgRoutes.length === 0) {
156
147
  return;
157
- } // currently SSG and SSR cannot be turned on at the same time、same route
158
-
148
+ }
159
149
 
150
+ // currently SSG and SSR cannot be turned on at the same time、same route
160
151
  ssgRoutes.forEach(ssgRoute => {
161
152
  if (ssgRoute.isSSR) {
162
153
  const isOriginRoute = pageRoutes.some(pageRoute => pageRoute.urlPath === ssgRoute.urlPath && pageRoute.entryName === ssgRoute.entryName);
163
-
164
154
  if (isOriginRoute) {
165
155
  throw new Error(`ssg can not using with ssr,url - ${ssgRoute.urlPath}, entry - ${ssgRoute.entryName} `);
166
156
  }
167
-
168
157
  logger.warn(`new ssg route ${ssgRoute.urlPath} is using ssr now,maybe from parent route ${ssgRoute.entryName},close ssr`);
169
158
  }
170
-
171
159
  ssgRoute.isSSR = false;
172
160
  ssgRoute.output = formatOutput(ssgRoute.output);
173
161
  });
174
- const htmlAry = await createServer(api, ssgRoutes, pageRoutes, apiRoutes, resolvedConfig, appDirectory); // write to dist file
162
+ const htmlAry = await createServer(api, ssgRoutes, pageRoutes, apiRoutes, resolvedConfig, appDirectory);
175
163
 
176
- writeHtmlFile(htmlAry, ssgRoutes, buildDir); // format route info, side effect
164
+ // write to dist file
165
+ writeHtmlFile(htmlAry, ssgRoutes, buildDir);
177
166
 
178
- replaceRoute(ssgRoutes, pageRoutes); // write routes to spec file
167
+ // format route info, side effect
168
+ replaceRoute(ssgRoutes, pageRoutes);
179
169
 
170
+ // write routes to spec file
180
171
  writeJSONSpec(buildDir, pageRoutes.concat(apiRoutes));
181
172
  logger.info('ssg Compiled successfully');
182
173
  }
183
-
184
174
  };
185
175
  }
186
176
  }));
@@ -1,9 +1,6 @@
1
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
-
3
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; }
4
-
5
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; }
6
-
7
4
  import path from 'path';
8
5
  import normalize from 'normalize-path';
9
6
  export function makeRender(ssgRoutes, render, port) {
@@ -20,7 +17,6 @@ export function makeRoute(baseRoute, route, headers = {}) {
20
17
  urlPath,
21
18
  entryPath
22
19
  } = baseRoute;
23
-
24
20
  if (typeof route === 'string') {
25
21
  return _objectSpread(_objectSpread({}, baseRoute), {}, {
26
22
  urlPath: normalize(`${urlPath}${route}`) || '/',
@@ -4,11 +4,9 @@ export function writeHtmlFile(htmlAry, ssgRoutes, baseDir) {
4
4
  htmlAry.forEach((html, index) => {
5
5
  const ssgRoute = ssgRoutes[index];
6
6
  const filepath = path.join(baseDir, ssgRoute.output);
7
-
8
7
  if (!fs.existsSync(path.dirname(filepath))) {
9
8
  fs.ensureDirSync(path.dirname(filepath));
10
9
  }
11
-
12
10
  fs.writeFileSync(filepath, html);
13
11
  });
14
12
  }
@@ -1,25 +1,17 @@
1
1
  const _excluded = ["output", "headers"];
2
-
3
2
  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; }
4
-
5
3
  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; }
6
-
7
4
  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; }
8
-
9
5
  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; }
10
-
11
6
  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; }
12
-
13
7
  import normalize from 'normalize-path';
14
8
  export function exist(route, pageRoutes) {
15
9
  return pageRoutes.slice().findIndex(pageRoute => {
16
10
  const urlEqual = normalize(pageRoute.urlPath) === normalize(route.urlPath);
17
11
  const entryEqual = pageRoute.entryName === route.entryName;
18
-
19
12
  if (urlEqual && entryEqual) {
20
13
  return true;
21
14
  }
22
-
23
15
  return false;
24
16
  });
25
17
  }
@@ -27,20 +19,19 @@ export function replaceRoute(ssgRoutes, pageRoutes) {
27
19
  // remove redundant fields and replace rendered entryPath
28
20
  const cleanSsgRoutes = ssgRoutes.map(ssgRoute => {
29
21
  const {
30
- output,
31
- headers
32
- } = ssgRoute,
33
- cleanSsgRoute = _objectWithoutProperties(ssgRoute, _excluded);
34
-
22
+ output,
23
+ headers
24
+ } = ssgRoute,
25
+ cleanSsgRoute = _objectWithoutProperties(ssgRoute, _excluded);
35
26
  return Object.assign(cleanSsgRoute, output ? {
36
27
  entryPath: output
37
28
  } : {});
38
- }); // all routes that need to be added and replaced
29
+ });
39
30
 
31
+ // all routes that need to be added and replaced
40
32
  const freshRoutes = [];
41
33
  cleanSsgRoutes.forEach(ssgRoute => {
42
34
  const index = exist(ssgRoute, pageRoutes);
43
-
44
35
  if (index < 0) {
45
36
  // new route
46
37
  freshRoutes.push(_objectSpread({}, ssgRoute));
@@ -1,9 +1,6 @@
1
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
-
3
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; }
4
-
5
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; }
6
-
7
4
  import path from 'path';
8
5
  import { ROUTE_SPEC_FILE, fs, isSingleEntry, SERVER_BUNDLE_DIRECTORY } from '@modern-js/utils';
9
6
  export function formatOutput(filename) {
@@ -12,23 +9,18 @@ export function formatOutput(filename) {
12
9
  }
13
10
  export function formatPath(str) {
14
11
  let addr = str;
15
-
16
12
  if (!addr || typeof addr !== 'string') {
17
13
  return addr;
18
14
  }
19
-
20
15
  if (addr.startsWith('.')) {
21
16
  addr = addr.slice(1);
22
17
  }
23
-
24
18
  if (!addr.startsWith('/')) {
25
19
  addr = `/${addr}`;
26
20
  }
27
-
28
21
  if (addr.endsWith('/') && addr !== '/') {
29
22
  addr = addr.slice(0, addr.length - 1);
30
23
  }
31
-
32
24
  return addr;
33
25
  }
34
26
  export function isDynamicUrl(url) {
@@ -36,51 +28,44 @@ export function isDynamicUrl(url) {
36
28
  }
37
29
  export function getUrlPrefix(route, baseUrl) {
38
30
  let base = '';
39
-
40
31
  if (Array.isArray(baseUrl)) {
41
32
  const filters = baseUrl.filter(url => route.urlPath.includes(url));
42
-
43
33
  if (filters.length > 1) {
44
- const matched = filters.sort((a, b) => a.length - b.length)[0]; // this should never happened
34
+ const matched = filters.sort((a, b) => a.length - b.length)[0];
45
35
 
36
+ // this should never happened
46
37
  if (!matched) {
47
38
  throw new Error('');
48
39
  }
49
-
50
40
  base = matched;
51
41
  }
52
42
  } else {
53
43
  base = baseUrl;
54
44
  }
55
-
56
45
  base = base === '/' ? '' : base;
57
46
  const entryName = route.entryName === 'main' ? '' : route.entryName;
58
47
  const prefix = `${base}/${entryName}`;
59
48
  return prefix.endsWith('/') ? prefix.slice(0, -1) : prefix;
60
- } // if no output, return default path for aggred-route(relative),
61
- // or throw error for control-route
49
+ }
62
50
 
51
+ // if no output, return default path for aggred-route(relative),
52
+ // or throw error for control-route
63
53
  export function getOutput(route, base, agreed) {
64
54
  const {
65
55
  output
66
56
  } = route;
67
-
68
57
  if (output) {
69
58
  return output;
70
59
  }
71
-
72
60
  if (agreed) {
73
61
  const urlWithoutBase = route.urlPath.replace(base, '');
74
62
  return urlWithoutBase.startsWith('/') ? urlWithoutBase.slice(1) : urlWithoutBase;
75
63
  }
76
-
77
64
  throw new Error(`routing must provide output when calling createPage(), check ${route.urlPath}`);
78
65
  }
79
66
  export const readJSONSpec = dir => {
80
67
  const routeJSONPath = path.join(dir, ROUTE_SPEC_FILE);
81
-
82
68
  const routeJSON = require(routeJSONPath);
83
-
84
69
  const {
85
70
  routes
86
71
  } = routeJSON;
@@ -99,7 +84,6 @@ export const standardOptions = (ssgOptions, entrypoints, routes, server) => {
99
84
  if (ssgOptions === false) {
100
85
  return false;
101
86
  }
102
-
103
87
  if (ssgOptions === true) {
104
88
  return entrypoints.reduce((opt, entry) => {
105
89
  opt[entry.entryName] = ssgOptions;
@@ -107,7 +91,6 @@ export const standardOptions = (ssgOptions, entrypoints, routes, server) => {
107
91
  }, {});
108
92
  } else if (typeof ssgOptions === 'object') {
109
93
  const isSingle = isSingleEntry(entrypoints);
110
-
111
94
  if (isSingle && typeof ssgOptions.main === 'undefined') {
112
95
  return {
113
96
  main: ssgOptions
@@ -117,12 +100,11 @@ export const standardOptions = (ssgOptions, entrypoints, routes, server) => {
117
100
  }
118
101
  } else if (typeof ssgOptions === 'function') {
119
102
  const intermediateOptions = {};
120
-
121
103
  for (const entrypoint of entrypoints) {
122
104
  const {
123
105
  entryName
124
- } = entrypoint; // TODO: may be async function
125
-
106
+ } = entrypoint;
107
+ // TODO: may be async function
126
108
  if (Array.isArray(server === null || server === void 0 ? void 0 : server.baseUrl)) {
127
109
  for (const url of server.baseUrl) {
128
110
  const matchUrl = entryName === 'main' ? url : `${url}/${entryName}`;
@@ -137,33 +119,30 @@ export const standardOptions = (ssgOptions, entrypoints, routes, server) => {
137
119
  });
138
120
  }
139
121
  }
140
-
141
122
  return intermediateOptions;
142
123
  }
143
-
144
124
  return false;
145
125
  };
146
126
  export const openRouteSSR = (routes, entries = []) => routes.map(ssgRoute => _objectSpread(_objectSpread({}, ssgRoute), {}, {
147
127
  isSSR: entries.includes(ssgRoute.entryName),
148
128
  bundle: `${SERVER_BUNDLE_DIRECTORY}/${ssgRoute.entryName}.js`
149
- })); // TODO: 过滤带有 server loader 的路由
129
+ }));
150
130
 
131
+ // TODO: 过滤带有 server loader 的路由
151
132
  export const flattenRoutes = routes => {
152
133
  const parents = [];
153
134
  const newRoutes = [];
154
-
155
135
  const traverseRoute = route => {
156
136
  const parent = parents[parents.length - 1];
157
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(/\/$/, '');
158
139
 
159
- path = path.replace(/\/$/, ''); // If the route path is / and is not the root route, it should not be used as an ssg route
160
-
140
+ // If the route path is / and is not the root route, it should not be used as an ssg route
161
141
  if (route._component && (path !== '/' || path === '/' && !parent)) {
162
142
  newRoutes.push(_objectSpread(_objectSpread({}, route), {}, {
163
143
  path
164
144
  }));
165
145
  }
166
-
167
146
  if (route.children) {
168
147
  parents.push(_objectSpread(_objectSpread({}, route), {}, {
169
148
  path
@@ -172,7 +151,6 @@ export const flattenRoutes = routes => {
172
151
  parents.pop();
173
152
  }
174
153
  };
175
-
176
154
  routes.forEach(traverseRoute);
177
155
  return newRoutes;
178
156
  };
@@ -32,7 +32,6 @@ export const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, app
32
32
  htmlAry.push(html);
33
33
  htmlChunks.length = 0;
34
34
  }
35
-
36
35
  if (htmlAry.length === ssgRoutes.length) {
37
36
  cp.send(CLOSE_SIGN);
38
37
  resolve(htmlAry);
@@ -40,7 +39,6 @@ export const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, app
40
39
  });
41
40
  cp.stderr.on('data', chunk => {
42
41
  const str = chunk.toString();
43
-
44
42
  if (str.includes('Error')) {
45
43
  logger.error(str);
46
44
  reject(new Error('ssg render failed'));
@@ -51,7 +49,6 @@ export const createServer = (api, ssgRoutes, pageRoutes, apiRoutes, options, app
51
49
  });
52
50
  cp.stdout.on('data', chunk => {
53
51
  const str = chunk.toString();
54
-
55
52
  if (str.includes('Error')) {
56
53
  logger.error(str);
57
54
  reject(new Error('ssg render failed'));
@@ -1,9 +1,6 @@
1
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
-
3
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; }
4
-
5
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; }
6
-
7
4
  import EventEmitter from 'events';
8
5
  import { Readable } from 'stream';
9
6
  import httpMocks from 'node-mocks-http';
@@ -20,10 +17,8 @@ export const compile = requestHandler => (options, extend = {}) => new Promise((
20
17
  if (typeof prop === 'symbol' && !obj[prop]) {
21
18
  return null;
22
19
  }
23
-
24
20
  return obj[prop];
25
21
  }
26
-
27
22
  });
28
23
  res.on('finish', () => {
29
24
  if (res.statusCode !== 200) {
@@ -33,7 +28,6 @@ export const compile = requestHandler => (options, extend = {}) => new Promise((
33
28
  }
34
29
  });
35
30
  res.on('error', e => reject(e));
36
-
37
31
  try {
38
32
  requestHandler(req, proxyRes);
39
33
  } catch (e) {
@@ -8,7 +8,6 @@ process.on('message', async chunk => {
8
8
  // eslint-disable-next-line no-process-exit
9
9
  process.exit();
10
10
  }
11
-
12
11
  const context = JSON.parse(chunk);
13
12
  const {
14
13
  routes,
@@ -18,12 +17,12 @@ process.on('message', async chunk => {
18
17
  plugins
19
18
  } = context;
20
19
  let modernServer = null;
21
-
22
20
  try {
23
21
  const {
24
22
  server: serverOptions
25
- } = options; // start server in default port
23
+ } = options;
26
24
 
25
+ // start server in default port
27
26
  const defaultPort = Number(process.env.PORT) || serverOptions.port;
28
27
  portfinder.basePort = defaultPort;
29
28
  const port = await portfinder.getPortPromise();
@@ -33,21 +32,22 @@ process.on('message', async chunk => {
33
32
  routes,
34
33
  staticGenerate: true,
35
34
  internalPlugins: plugins
36
- }); // listen just for bff request in ssr page
35
+ });
37
36
 
37
+ // listen just for bff request in ssr page
38
38
  modernServer.listen(port, async err => {
39
39
  if (err) {
40
40
  throw err;
41
41
  }
42
-
43
42
  if (!modernServer) {
44
43
  return;
45
- } // get server handler, render to ssr
46
-
44
+ }
47
45
 
46
+ // get server handler, render to ssr
48
47
  const render = createRender(modernServer.getRequestHandler());
49
- const renderPromiseAry = makeRender(renderRoutes, render, port); // eslint-disable-next-line promise/no-promise-in-callback
48
+ const renderPromiseAry = makeRender(renderRoutes, render, port);
50
49
 
50
+ // eslint-disable-next-line promise/no-promise-in-callback
51
51
  const htmlAry = await Promise.all(renderPromiseAry);
52
52
  htmlAry.forEach(html => {
53
53
  process.send(html);
@@ -57,7 +57,6 @@ process.on('message', async chunk => {
57
57
  });
58
58
  } catch (e) {
59
59
  var _modernServer;
60
-
61
60
  (_modernServer = modernServer) === null || _modernServer === void 0 ? void 0 : _modernServer.close();
62
61
  throw e;
63
62
  }
@@ -0,0 +1 @@
1
+ export {};