@modern-js/prod-server 1.0.5 → 1.1.0

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 +29 -0
  2. package/dist/js/modern/libs/loadConfig.js +54 -0
  3. package/dist/js/modern/libs/proxy.js +3 -0
  4. package/dist/js/modern/libs/render/cache/index.js +2 -4
  5. package/dist/js/modern/libs/render/cache/spr.js +1 -2
  6. package/dist/js/modern/libs/render/cache/util.js +2 -5
  7. package/dist/js/modern/server/index.js +102 -14
  8. package/dist/js/modern/server/modern-server.js +8 -8
  9. package/dist/js/modern/utils.js +2 -0
  10. package/dist/js/node/libs/loadConfig.js +79 -0
  11. package/dist/js/node/libs/proxy.js +4 -0
  12. package/dist/js/node/libs/render/cache/index.js +2 -4
  13. package/dist/js/node/libs/render/cache/spr.js +1 -2
  14. package/dist/js/node/libs/render/cache/util.js +2 -5
  15. package/dist/js/node/server/index.js +107 -14
  16. package/dist/js/node/server/modern-server.js +7 -7
  17. package/dist/js/node/utils.js +6 -1
  18. package/dist/types/index.d.ts +1 -0
  19. package/dist/types/libs/loadConfig.d.ts +19 -0
  20. package/dist/types/libs/proxy.d.ts +3 -3
  21. package/dist/types/server/index.d.ts +31 -0
  22. package/dist/types/type.d.ts +2 -8
  23. package/dist/types/utils.d.ts +1 -0
  24. package/jest.config.js +0 -1
  25. package/package.json +19 -17
  26. package/src/index.ts +1 -0
  27. package/src/libs/loadConfig.ts +65 -0
  28. package/src/libs/proxy.ts +5 -3
  29. package/src/libs/render/cache/index.ts +0 -2
  30. package/src/libs/render/cache/spr.ts +0 -1
  31. package/src/libs/render/cache/util.ts +0 -3
  32. package/src/server/index.ts +112 -7
  33. package/src/server/modern-server.ts +6 -6
  34. package/src/type.ts +2 -9
  35. package/src/utils.ts +3 -0
  36. package/tests/loadConfig.test.ts +65 -0
  37. package/tests/server.test.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,34 @@
1
1
  # @modern-js/prod-server
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - d2d1d6b2: feat: support server config
8
+
9
+ ### Patch Changes
10
+
11
+ - 17d0cc46: feat: prebundle lodash to @modern-js/utils/lodash
12
+ - Updated dependencies [77ff9754]
13
+ - Updated dependencies [d2d1d6b2]
14
+ - Updated dependencies [07a4887e]
15
+ - Updated dependencies [ea2ae711]
16
+ - Updated dependencies [17d0cc46]
17
+ - Updated dependencies [d2d1d6b2]
18
+ - @modern-js/utils@1.4.0
19
+ - @modern-js/server-core@1.3.0
20
+
21
+ ## 1.0.6
22
+
23
+ ### Patch Changes
24
+
25
+ - bebb39b6: chore: improve devDependencies and peerDependencies
26
+ - 132f7b53: feat: move config declarations to @modern-js/core
27
+ - Updated dependencies [bebb39b6]
28
+ - Updated dependencies [132f7b53]
29
+ - @modern-js/server-core@1.2.5
30
+ - @modern-js/utils@1.3.7
31
+
3
32
  ## 1.0.5
4
33
 
5
34
  ### Patch Changes
@@ -0,0 +1,54 @@
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
+ 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
+ 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
+ import * as path from 'path';
8
+ import { compatRequire, fs, DEFAULT_SERVER_CONFIG } from '@modern-js/utils';
9
+ import mergeDeep from 'merge-deep';
10
+ import { debug } from "../utils";
11
+ export const getServerConfigPath = (distDirectory, serverConfigFile = DEFAULT_SERVER_CONFIG) => {
12
+ const serverConfigPath = path.join(distDirectory, serverConfigFile);
13
+ return `${serverConfigPath}.js`;
14
+ };
15
+ export const requireConfig = serverConfigPath => {
16
+ if (fs.pathExistsSync(serverConfigPath)) {
17
+ try {
18
+ return compatRequire(serverConfigPath);
19
+ } catch (error) {
20
+ debug(error);
21
+ return {};
22
+ }
23
+ }
24
+
25
+ return {};
26
+ };
27
+ /**
28
+ * 对配置进行合并,开发环境下,cliConfig 与 serverConfig 进行深合并
29
+ * 生产环境下,resolvedConfig 与 serverConfig 进行深合并
30
+ * resolvedConfigPath: 构建序列化后的 modern.config.js 文件路径
31
+ */
32
+
33
+ export const loadConfig = ({
34
+ cliConfig,
35
+ serverConfig,
36
+ resolvedConfigPath
37
+ }) => {
38
+ let config = null;
39
+
40
+ if (process.env.NODE_ENV === 'production') {
41
+ const resolvedConfig = requireConfig(resolvedConfigPath); // cli config has a higher priority,because it's an argument passed in.
42
+
43
+ config = mergeDeep(_objectSpread(_objectSpread({}, resolvedConfig), {}, {
44
+ plugins: [] // filter cli plugins
45
+
46
+ }), serverConfig, cliConfig);
47
+ } else {
48
+ config = mergeDeep(_objectSpread(_objectSpread({}, cliConfig), {}, {
49
+ plugins: []
50
+ }), serverConfig);
51
+ }
52
+
53
+ return config;
54
+ };
@@ -1,6 +1,9 @@
1
1
  import { createProxyMiddleware } from 'http-proxy-middleware';
2
2
  import { formatProxyOptions } from '@modern-js/utils';
3
+ import { debug } from "../utils";
3
4
  export const createProxyHandler = proxyOptions => {
5
+ debug('createProxyHandler', proxyOptions);
6
+
4
7
  if (!proxyOptions) {
5
8
  return null;
6
9
  } // If it is not an array, it may be an object that uses the context attribute
@@ -46,8 +46,7 @@ export default ((renderFn, ctx) => {
46
46
  } else if (cacheFile.isStale) {
47
47
  // if file is stale, request async
48
48
  const render = withCoalescedInvoke(() => renderFn(context)).bind(null, namespaceHash('render', cacheFile.hash), []);
49
- render() // eslint-disable-next-line promise/prefer-await-to-then
50
- .then(res => {
49
+ render().then(res => {
51
50
  if (res.value && res.isOrigin) {
52
51
  const {
53
52
  cacheConfig
@@ -59,8 +58,7 @@ export default ((renderFn, ctx) => {
59
58
  sprCache.del(cacheContext, cacheHash);
60
59
  }
61
60
  }
62
- }) // eslint-disable-next-line promise/prefer-await-to-then
63
- .catch(e => {
61
+ }).catch(e => {
64
62
  sprCache.del(cacheContext, cacheHash);
65
63
  ctx.error(ERROR_DIGEST.ERENDER, e);
66
64
  });
@@ -221,8 +221,7 @@ class CacheManager {
221
221
  let data = this.cache.get(cacheKey);
222
222
 
223
223
  if (!data) {
224
- const caches = await createPageCaches(MAX_CACHE_EACH_REQ); // eslint-disable-next-line require-atomic-updates
225
-
224
+ const caches = await createPageCaches(MAX_CACHE_EACH_REQ);
226
225
  data = this.createCacheContent(cacheConfig, caches);
227
226
  }
228
227
 
@@ -39,7 +39,6 @@ export function withCoalescedInvoke(func) {
39
39
  const entry = globalInvokeCache.get(key);
40
40
 
41
41
  if (entry) {
42
- // eslint-disable-next-line promise/prefer-await-to-then
43
42
  return entry.then(res => ({
44
43
  isOrigin: false,
45
44
  value: res.value
@@ -50,15 +49,13 @@ export function withCoalescedInvoke(func) {
50
49
  return func(...args);
51
50
  }
52
51
 
53
- const future = __wrapper() // eslint-disable-next-line promise/prefer-await-to-then
54
- .then(res => {
52
+ const future = __wrapper().then(res => {
55
53
  globalInvokeCache.delete(key);
56
54
  return {
57
55
  isOrigin: true,
58
56
  value: res
59
57
  };
60
- }) // eslint-disable-next-line promise/prefer-await-to-then
61
- .catch(err => {
58
+ }).catch(err => {
62
59
  globalInvokeCache.delete(key);
63
60
  throw err;
64
61
  });
@@ -6,8 +6,10 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
6
6
 
7
7
  import path from 'path';
8
8
  import { serverManager, AppContext, ConfigContext, loadPlugins } from '@modern-js/server-core';
9
- import { logger as defaultLogger, SHARED_DIR } from '@modern-js/utils';
9
+ import { logger as defaultLogger, SHARED_DIR, OUTPUT_CONFIG_FILE } from '@modern-js/utils';
10
10
  import { metrics as defaultMetrics } from "../libs/metrics";
11
+ import { loadConfig, getServerConfigPath, requireConfig } from "../libs/loadConfig";
12
+ import { debug } from "../utils";
11
13
  import { createProdServer } from "./modern-server-split";
12
14
  export class Server {
13
15
  constructor(options) {
@@ -16,25 +18,99 @@ export class Server {
16
18
  this.server = void 0;
17
19
  this.app = void 0;
18
20
  this.runner = void 0;
21
+ this.serverConfig = void 0;
19
22
  options.logger = options.logger || defaultLogger;
20
23
  options.metrics = options.metrics || defaultMetrics;
21
24
  this.options = options;
25
+ this.serverConfig = {};
22
26
  }
27
+ /**
28
+ * 初始化顺序
29
+ * - 获取 server runtime config
30
+ * - 设置 context
31
+ * - 创建 hooksRunner
32
+ * - 合并插件,内置插件和 serverConfig 中配置的插件
33
+ * - 执行 config hook
34
+ * - 获取最终的配置
35
+ * - 设置配置到 context
36
+ * - 初始化 server
37
+ * - 执行 prepare hook
38
+ * - 执行 server init
39
+ */
40
+
23
41
 
24
42
  async init() {
25
43
  const {
26
44
  options
27
- } = this; // initialize server
45
+ } = this;
46
+ this.initServerConfig(options);
47
+ await this.injectContext(this.runner, options); // initialize server runner
48
+
49
+ this.runner = await this.createHookRunner(); // init config and execute config hook
28
50
 
29
- this.server = this.serverImpl(options); // create http-server
51
+ await this.initConfig(this.runner, options);
52
+ await this.injectContext(this.runner, options); // initialize server
30
53
 
31
- this.app = await this.server.createHTTPServer(this.getRequestHandler()); // initialize server runner
54
+ this.server = this.serverImpl(options);
55
+ await this.runPrepareHook(this.runner); // create http-server
32
56
 
33
- this.runner = await this.createHookRunner(); // runner can only be used after server init
57
+ this.app = await this.server.createHTTPServer(this.getRequestHandler()); // runner can only be used after server init
34
58
 
35
59
  await this.server.onInit(this.runner);
36
60
  return this;
37
61
  }
62
+ /**
63
+ * Execute config hooks
64
+ * @param runner
65
+ * @param options
66
+ */
67
+
68
+
69
+ runConfigHook(runner, serverConfig) {
70
+ const newServerConfig = runner.config(serverConfig || {});
71
+ return newServerConfig;
72
+ }
73
+
74
+ async runPrepareHook(runner) {
75
+ runner.prepare();
76
+ }
77
+
78
+ initServerConfig(options) {
79
+ var _options$config$outpu;
80
+
81
+ const {
82
+ pwd,
83
+ serverConfigFile
84
+ } = options;
85
+ const distDirectory = path.join(pwd, ((_options$config$outpu = options.config.output) === null || _options$config$outpu === void 0 ? void 0 : _options$config$outpu.path) || 'dist');
86
+ const serverConfigPath = getServerConfigPath(distDirectory, serverConfigFile);
87
+ const serverConfig = requireConfig(serverConfigPath);
88
+ this.serverConfig = serverConfig;
89
+ }
90
+ /**
91
+ *
92
+ * merge cliConfig and serverConfig
93
+ */
94
+
95
+
96
+ async initConfig(runner, options) {
97
+ var _config$output;
98
+
99
+ const {
100
+ pwd,
101
+ config
102
+ } = options;
103
+ const {
104
+ serverConfig
105
+ } = this;
106
+ const finalServerConfig = this.runConfigHook(runner, serverConfig);
107
+ const resolvedConfigPath = path.join(pwd, (config === null || config === void 0 ? void 0 : (_config$output = config.output) === null || _config$output === void 0 ? void 0 : _config$output.path) || 'dist', OUTPUT_CONFIG_FILE);
108
+ options.config = loadConfig({
109
+ cliConfig: config,
110
+ serverConfig: finalServerConfig,
111
+ resolvedConfigPath
112
+ });
113
+ }
38
114
 
39
115
  async close() {
40
116
  await this.server.onClose();
@@ -65,31 +141,43 @@ export class Server {
65
141
  serverManager.clear();
66
142
  const {
67
143
  options
68
- } = this;
144
+ } = this; // TODO: 确认下这里是不是可以不从 options 中取插件,而是从 config 中取和过滤
145
+
69
146
  const {
70
147
  plugins = [],
71
148
  pwd,
72
149
  config
73
- } = options; // server app context for serve plugin
150
+ } = options;
151
+ const serverPlugins = this.serverConfig.plugins || []; // server app context for serve plugin
74
152
 
75
- const loadedPlugins = loadPlugins(plugins, pwd);
153
+ const loadedPlugins = loadPlugins(plugins.concat(serverPlugins), pwd);
154
+ debug('plugins', config.plugins, loadedPlugins);
76
155
  loadedPlugins.forEach(p => {
77
156
  serverManager.usePlugin(p);
78
- });
157
+ }); // create runner
158
+
159
+ const hooksRunner = await serverManager.init({});
160
+ return hooksRunner;
161
+ }
162
+
163
+ async injectContext(runner, options) {
79
164
  const appContext = this.initAppContext();
165
+ const {
166
+ config,
167
+ pwd
168
+ } = options;
80
169
  serverManager.run(() => {
81
- var _config$output;
170
+ var _config$output2;
82
171
 
83
172
  ConfigContext.set(config);
84
173
  AppContext.set(_objectSpread(_objectSpread({}, appContext), {}, {
85
- distDirectory: path.join(pwd, ((_config$output = config.output) === null || _config$output === void 0 ? void 0 : _config$output.path) || 'dist')
174
+ distDirectory: path.join(pwd, ((_config$output2 = config.output) === null || _config$output2 === void 0 ? void 0 : _config$output2.path) || 'dist')
86
175
  }));
87
176
  });
88
- return serverManager.init({});
89
177
  }
90
178
 
91
179
  initAppContext() {
92
- var _config$output2;
180
+ var _config$output3;
93
181
 
94
182
  const {
95
183
  options
@@ -104,7 +192,7 @@ export class Server {
104
192
  }));
105
193
  return {
106
194
  appDirectory,
107
- distDirectory: path.join(appDirectory, ((_config$output2 = config.output) === null || _config$output2 === void 0 ? void 0 : _config$output2.path) || 'dist'),
195
+ distDirectory: path.join(appDirectory, ((_config$output3 = config.output) === null || _config$output3 === void 0 ? void 0 : _config$output3.path) || 'dist'),
108
196
  sharedDirectory: path.resolve(appDirectory, SHARED_DIR),
109
197
  plugins: serverPlugins
110
198
  };
@@ -21,7 +21,7 @@ import clone from 'lodash.clone';
21
21
  import { RouteMatchManager } from "../libs/route";
22
22
  import { createRenderHandler } from "../libs/render";
23
23
  import { createStaticFileHandler } from "../libs/serve-file";
24
- import { createErrorDocument, createMiddlewareCollecter, getStaticReg, mergeExtension, noop } from "../utils";
24
+ import { createErrorDocument, createMiddlewareCollecter, getStaticReg, mergeExtension, noop, debug } from "../utils";
25
25
  import * as reader from "../libs/render/reader";
26
26
  import { createProxyHandler } from "../libs/proxy";
27
27
  import { createContext } from "../libs/context";
@@ -73,6 +73,7 @@ export class ModernServer {
73
73
  this.distDir = path.join(pwd, ((_config$output = config.output) === null || _config$output === void 0 ? void 0 : _config$output.path) || 'dist');
74
74
  this.workDir = this.distDir;
75
75
  this.conf = config;
76
+ debug('server conf', this.conf);
76
77
  this.logger = logger;
77
78
  this.metrics = metrics;
78
79
  this.router = new RouteMatchManager();
@@ -98,7 +99,8 @@ export class ModernServer {
98
99
  ctx.res.setHeader('Access-Control-Allow-Origin', '*');
99
100
  ctx.res.setHeader('Access-Control-Allow-Credentials', 'false');
100
101
  next();
101
- }); // proxy handler, each proxy has own handler
102
+ });
103
+ debug('final server conf', this.conf); // proxy handler, each proxy has own handler
102
104
 
103
105
  this.proxyHandler = createProxyHandler((_conf$bff = conf.bff) === null || _conf$bff === void 0 ? void 0 : _conf$bff.proxy);
104
106
 
@@ -223,7 +225,8 @@ export class ModernServer {
223
225
  }
224
226
 
225
227
  if (fs.existsSync(apiDir)) {
226
- const mode = fs.existsSync(path.join(apiDir, AGGRED_DIR.lambda)) ? ApiServerMode.frame : ApiServerMode.func; // if use lambda/, mean framework style of writing, then discard user extension
228
+ const mode = fs.existsSync(path.join(apiDir, AGGRED_DIR.lambda)) ? ApiServerMode.frame : ApiServerMode.func;
229
+ debug('exists api dir', mode); // if use lambda/, mean framework style of writing, then discard user extension
227
230
 
228
231
  const apiExtension = mergeExtension(pluginAPIExt);
229
232
  this.frameAPIHandler = await this.prepareAPIHandler(mode, apiExtension);
@@ -324,7 +327,6 @@ export class ModernServer {
324
327
  }
325
328
  /* —————————————————————— private function —————————————————————— */
326
329
  // handler route.json, include api / csr / ssr
327
- // eslint-disable-next-line max-statements
328
330
 
329
331
 
330
332
  async routeHandler(context) {
@@ -416,8 +418,7 @@ export class ModernServer {
416
418
 
417
419
  res.setHeader('content-type', file.contentType);
418
420
  res.end(response);
419
- } // eslint-disable-next-line max-statements
420
-
421
+ }
421
422
 
422
423
  async injectMicroFE(context, templateAPI) {
423
424
  var _conf$runtime, _conf$server;
@@ -509,8 +510,7 @@ export class ModernServer {
509
510
 
510
511
  if (!handler) {
511
512
  return next();
512
- } // eslint-disable-next-line promise/prefer-await-to-then
513
-
513
+ }
514
514
 
515
515
  return handler(context, dispatch).catch(onError);
516
516
  };
@@ -1,4 +1,6 @@
1
1
  import { compile } from 'path-to-regexp';
2
+ import { createDebugger } from '@modern-js/utils';
3
+ export const debug = createDebugger('prod-server');
2
4
  export const mergeExtension = users => {
3
5
  const output = [];
4
6
  return {
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.requireConfig = exports.loadConfig = exports.getServerConfigPath = void 0;
7
+
8
+ var path = _interopRequireWildcard(require("path"));
9
+
10
+ var _utils = require("@modern-js/utils");
11
+
12
+ var _mergeDeep = _interopRequireDefault(require("merge-deep"));
13
+
14
+ var _utils2 = require("../utils");
15
+
16
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
+
18
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
+
20
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
+
22
+ 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; }
23
+
24
+ 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; }
25
+
26
+ 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; }
27
+
28
+ const getServerConfigPath = (distDirectory, serverConfigFile = _utils.DEFAULT_SERVER_CONFIG) => {
29
+ const serverConfigPath = path.join(distDirectory, serverConfigFile);
30
+ return `${serverConfigPath}.js`;
31
+ };
32
+
33
+ exports.getServerConfigPath = getServerConfigPath;
34
+
35
+ const requireConfig = serverConfigPath => {
36
+ if (_utils.fs.pathExistsSync(serverConfigPath)) {
37
+ try {
38
+ return (0, _utils.compatRequire)(serverConfigPath);
39
+ } catch (error) {
40
+ (0, _utils2.debug)(error);
41
+ return {};
42
+ }
43
+ }
44
+
45
+ return {};
46
+ };
47
+ /**
48
+ * 对配置进行合并,开发环境下,cliConfig 与 serverConfig 进行深合并
49
+ * 生产环境下,resolvedConfig 与 serverConfig 进行深合并
50
+ * resolvedConfigPath: 构建序列化后的 modern.config.js 文件路径
51
+ */
52
+
53
+
54
+ exports.requireConfig = requireConfig;
55
+
56
+ const loadConfig = ({
57
+ cliConfig,
58
+ serverConfig,
59
+ resolvedConfigPath
60
+ }) => {
61
+ let config = null;
62
+
63
+ if (process.env.NODE_ENV === 'production') {
64
+ const resolvedConfig = requireConfig(resolvedConfigPath); // cli config has a higher priority,because it's an argument passed in.
65
+
66
+ config = (0, _mergeDeep.default)(_objectSpread(_objectSpread({}, resolvedConfig), {}, {
67
+ plugins: [] // filter cli plugins
68
+
69
+ }), serverConfig, cliConfig);
70
+ } else {
71
+ config = (0, _mergeDeep.default)(_objectSpread(_objectSpread({}, cliConfig), {}, {
72
+ plugins: []
73
+ }), serverConfig);
74
+ }
75
+
76
+ return config;
77
+ };
78
+
79
+ exports.loadConfig = loadConfig;
@@ -9,7 +9,11 @@ var _httpProxyMiddleware = require("http-proxy-middleware");
9
9
 
10
10
  var _utils = require("@modern-js/utils");
11
11
 
12
+ var _utils2 = require("../utils");
13
+
12
14
  const createProxyHandler = proxyOptions => {
15
+ (0, _utils2.debug)('createProxyHandler', proxyOptions);
16
+
13
17
  if (!proxyOptions) {
14
18
  return null;
15
19
  } // If it is not an array, it may be an object that uses the context attribute
@@ -56,8 +56,7 @@ var _default = (renderFn, ctx) => {
56
56
  } else if (cacheFile.isStale) {
57
57
  // if file is stale, request async
58
58
  const render = (0, _util.withCoalescedInvoke)(() => renderFn(context)).bind(null, (0, _util.namespaceHash)('render', cacheFile.hash), []);
59
- render() // eslint-disable-next-line promise/prefer-await-to-then
60
- .then(res => {
59
+ render().then(res => {
61
60
  if (res.value && res.isOrigin) {
62
61
  const {
63
62
  cacheConfig
@@ -69,8 +68,7 @@ var _default = (renderFn, ctx) => {
69
68
  sprCache.del(cacheContext, cacheHash);
70
69
  }
71
70
  }
72
- }) // eslint-disable-next-line promise/prefer-await-to-then
73
- .catch(e => {
71
+ }).catch(e => {
74
72
  sprCache.del(cacheContext, cacheHash);
75
73
  ctx.error(_constants.ERROR_DIGEST.ERENDER, e);
76
74
  });
@@ -237,8 +237,7 @@ class CacheManager {
237
237
  let data = this.cache.get(cacheKey);
238
238
 
239
239
  if (!data) {
240
- const caches = await (0, _pageCaches.createPageCaches)(MAX_CACHE_EACH_REQ); // eslint-disable-next-line require-atomic-updates
241
-
240
+ const caches = await (0, _pageCaches.createPageCaches)(MAX_CACHE_EACH_REQ);
242
241
  data = this.createCacheContent(cacheConfig, caches);
243
242
  }
244
243
 
@@ -64,7 +64,6 @@ function withCoalescedInvoke(func) {
64
64
  const entry = globalInvokeCache.get(key);
65
65
 
66
66
  if (entry) {
67
- // eslint-disable-next-line promise/prefer-await-to-then
68
67
  return entry.then(res => ({
69
68
  isOrigin: false,
70
69
  value: res.value
@@ -75,15 +74,13 @@ function withCoalescedInvoke(func) {
75
74
  return func(...args);
76
75
  }
77
76
 
78
- const future = __wrapper() // eslint-disable-next-line promise/prefer-await-to-then
79
- .then(res => {
77
+ const future = __wrapper().then(res => {
80
78
  globalInvokeCache.delete(key);
81
79
  return {
82
80
  isOrigin: true,
83
81
  value: res
84
82
  };
85
- }) // eslint-disable-next-line promise/prefer-await-to-then
86
- .catch(err => {
83
+ }).catch(err => {
87
84
  globalInvokeCache.delete(key);
88
85
  throw err;
89
86
  });