@modern-js/server 2.5.1-alpha.0 → 2.5.1-alpha.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.
@@ -41,6 +41,7 @@ class ModernDevServer extends import_prod_server.ModernServer {
41
41
  constructor(options) {
42
42
  super(options);
43
43
  this.mockHandler = null;
44
+ this.appContext = options.appContext;
44
45
  this.workDir = this.pwd;
45
46
  this.dev = this.getDevOptions(options);
46
47
  this.devMiddleware = new import_dev_middleware.default({
@@ -234,13 +235,15 @@ class ModernDevServer extends import_prod_server.ModernServer {
234
235
  }
235
236
  startWatcher() {
236
237
  var _a;
237
- const { pwd, distDir } = this;
238
+ const { pwd, distDir, appContext } = this;
238
239
  const { mock } = import_prod_server.AGGRED_DIR;
240
+ const apiDir = (appContext == null ? void 0 : appContext.apiDirectory) || import_utils.API_DIR;
241
+ const sharedDir = (appContext == null ? void 0 : appContext.sharedDirectory) || import_utils.SHARED_DIR;
239
242
  const defaultWatched = [
240
243
  `${mock}/**/*`,
241
244
  `${import_utils.SERVER_DIR}/**/*`,
242
- `${import_utils.API_DIR}/**`,
243
- `${import_utils.SHARED_DIR}/**/*`,
245
+ `${apiDir}/**`,
246
+ `${sharedDir}/**/*`,
244
247
  `${distDir}/${import_utils.SERVER_BUNDLE_DIRECTORY}/*-server-loaders.js`
245
248
  ];
246
249
  const watchOptions = (0, import_watcher.mergeWatchOptions)((_a = this.conf.server) == null ? void 0 : _a.watchOptions);
@@ -361,8 +361,10 @@ var ModernDevServer = /*#__PURE__*/ function(ModernServer) {
361
361
  _this = _super.call(this, options);
362
362
  _defineProperty(_assertThisInitialized(_this), "mockHandler", null);
363
363
  _defineProperty(_assertThisInitialized(_this), "dev", void 0);
364
+ _defineProperty(_assertThisInitialized(_this), "appContext", void 0);
364
365
  _defineProperty(_assertThisInitialized(_this), "devMiddleware", void 0);
365
366
  _defineProperty(_assertThisInitialized(_this), "watcher", void 0);
367
+ _this.appContext = options.appContext;
366
368
  _this.workDir = _this.pwd;
367
369
  _this.dev = _this.getDevOptions(options);
368
370
  _this.devMiddleware = new DevMiddleware({
@@ -767,13 +769,15 @@ var ModernDevServer = /*#__PURE__*/ function(ModernServer) {
767
769
  value: function startWatcher() {
768
770
  var _this = this;
769
771
  var _this_conf_server;
770
- var _this1 = this, pwd = _this1.pwd, distDir = _this1.distDir;
772
+ var _this1 = this, pwd = _this1.pwd, distDir = _this1.distDir, appContext = _this1.appContext;
771
773
  var mock = AGGRED_DIR.mock;
774
+ var apiDir = (appContext === null || appContext === void 0 ? void 0 : appContext.apiDirectory) || API_DIR;
775
+ var sharedDir = (appContext === null || appContext === void 0 ? void 0 : appContext.sharedDirectory) || SHARED_DIR;
772
776
  var defaultWatched = [
773
777
  "".concat(mock, "/**/*"),
774
778
  "".concat(SERVER_DIR, "/**/*"),
775
- "".concat(API_DIR, "/**"),
776
- "".concat(SHARED_DIR, "/**/*"),
779
+ "".concat(apiDir, "/**"),
780
+ "".concat(sharedDir, "/**/*"),
777
781
  "".concat(distDir, "/").concat(SERVER_BUNDLE_DIRECTORY, "/*-server-loaders.js")
778
782
  ];
779
783
  var watchOptions = mergeWatchOptions((_this_conf_server = this.conf.server) === null || _this_conf_server === void 0 ? void 0 : _this_conf_server.watchOptions);
@@ -22,6 +22,7 @@ class ModernDevServer extends ModernServer {
22
22
  constructor(options) {
23
23
  super(options);
24
24
  this.mockHandler = null;
25
+ this.appContext = options.appContext;
25
26
  this.workDir = this.pwd;
26
27
  this.dev = this.getDevOptions(options);
27
28
  this.devMiddleware = new DevMiddleware({
@@ -215,13 +216,15 @@ class ModernDevServer extends ModernServer {
215
216
  }
216
217
  startWatcher() {
217
218
  var _a;
218
- const { pwd, distDir } = this;
219
+ const { pwd, distDir, appContext } = this;
219
220
  const { mock } = AGGRED_DIR;
221
+ const apiDir = (appContext == null ? void 0 : appContext.apiDirectory) || API_DIR;
222
+ const sharedDir = (appContext == null ? void 0 : appContext.sharedDirectory) || SHARED_DIR;
220
223
  const defaultWatched = [
221
224
  `${mock}/**/*`,
222
225
  `${SERVER_DIR}/**/*`,
223
- `${API_DIR}/**`,
224
- `${SHARED_DIR}/**/*`,
226
+ `${apiDir}/**`,
227
+ `${sharedDir}/**/*`,
225
228
  `${distDir}/${SERVER_BUNDLE_DIRECTORY}/*-server-loaders.js`
226
229
  ];
227
230
  const watchOptions = mergeWatchOptions((_a = this.conf.server) == null ? void 0 : _a.watchOptions);
@@ -10,11 +10,14 @@ var require_hmr_client = __commonJS({
10
10
  const hadRuntimeError = false;
11
11
  const socketUrl = createSocketUrl(__resourceQuery);
12
12
  const connection = new WebSocket(socketUrl);
13
+ connection.onopen = function() {
14
+ if (typeof console !== "undefined" && typeof console.debug === "function") {
15
+ console.debug("[HMR] connected.");
16
+ }
17
+ };
13
18
  connection.onclose = function() {
14
19
  if (typeof console !== "undefined" && typeof console.info === "function") {
15
- console.info(
16
- "The development server has disconnected.\nRefresh the page if necessary."
17
- );
20
+ console.debug("[HMR] disconnected. Refresh the page if necessary.");
18
21
  }
19
22
  };
20
23
  let isFirstCompilation = true;
@@ -37,7 +37,6 @@ var __async = (__this, __arguments, generator) => {
37
37
  step((generator = generator.apply(__this, __arguments)).next());
38
38
  });
39
39
  };
40
- import { compatRequire } from "@modern-js/utils";
41
40
  import { match } from "path-to-regexp";
42
41
  const VALID_METHODS = ["get", "post", "put", "delete", "patch"];
43
42
  const BODY_PARSED_METHODS = ["post", "put", "delete", "patch"];
@@ -51,7 +50,7 @@ const createStaticDataHandler = (method, handler) => (context) => {
51
50
  res.end(JSON.stringify(handler));
52
51
  };
53
52
  const allowTypes = ["object", "function"];
54
- const normalizeConfig = (mockConfig) => Object.keys(mockConfig).reduce((acc, key) => {
53
+ var getMockData_default = (mockConfig) => Object.keys(mockConfig).reduce((acc, key) => {
55
54
  const handler = mockConfig[key];
56
55
  const type = typeof handler;
57
56
  if (!allowTypes.includes(type)) {
@@ -86,14 +85,6 @@ const parseKey = (key) => {
86
85
  path: key
87
86
  };
88
87
  };
89
- var getMockData_default = (filepath) => {
90
- const mockModule = compatRequire(filepath);
91
- if (!mockModule) {
92
- throw new Error(`Mock file ${filepath} parsed failed!`);
93
- }
94
- const data = normalizeConfig(mockModule);
95
- return data;
96
- };
97
88
  const getMatched = (context, mockApiList) => {
98
89
  const { path: targetPathname, method: targetMethod } = context;
99
90
  const matched = mockApiList.find((mockApi) => {
@@ -19,7 +19,7 @@ var __async = (__this, __arguments, generator) => {
19
19
  });
20
20
  };
21
21
  import path from "path";
22
- import { fs } from "@modern-js/utils";
22
+ import { compatRequire, fs } from "@modern-js/utils";
23
23
  import { AGGRED_DIR } from "@modern-js/prod-server";
24
24
  import getMockData, { getMatched } from "./getMockData";
25
25
  const createMockHandler = ({ pwd }) => {
@@ -35,11 +35,27 @@ const createMockHandler = ({ pwd }) => {
35
35
  if (!filepath) {
36
36
  return null;
37
37
  }
38
- const apiList = getMockData(filepath);
38
+ const {
39
+ default: mockModule,
40
+ config
41
+ } = compatRequire(filepath, false);
42
+ if ((config == null ? void 0 : config.enable) === false) {
43
+ return null;
44
+ }
45
+ if (!mockModule) {
46
+ throw new Error(`Mock file ${filepath} parsed failed!`);
47
+ }
48
+ const apiList = getMockData(mockModule);
39
49
  if (!apiList || apiList.length === 0) {
40
50
  return null;
41
51
  }
42
52
  return (context, next) => __async(void 0, null, function* () {
53
+ if (typeof (config == null ? void 0 : config.enable) === "function") {
54
+ const enableMock = config.enable(context.req, context.res);
55
+ if (!enableMock) {
56
+ return next();
57
+ }
58
+ }
43
59
  const { res } = context;
44
60
  const matched = getMatched(context, apiList);
45
61
  if (!matched) {
@@ -68,6 +68,7 @@ const enableRegister = (projectRoot, config) => {
68
68
  });
69
69
  tsNode.register({
70
70
  project: tsconfigPath,
71
+ scope: true,
71
72
  files: true,
72
73
  transpileOnly: true,
73
74
  ignore: ["(?:^|/)node_modules/", `(?:^|/)${distPath}/`]
@@ -186,6 +186,7 @@ class ModernDevServer extends ModernServer {
186
186
  }
187
187
  this.cleanSSRCache();
188
188
  this.reader.updateFile();
189
+ this.runner.repack();
189
190
  super.onRepack(options);
190
191
  }
191
192
  createHTTPServer(handler) {
@@ -22,11 +22,14 @@ var import_createSocketUrl = require("./createSocketUrl");
22
22
  const hadRuntimeError = false;
23
23
  const socketUrl = (0, import_createSocketUrl.createSocketUrl)(__resourceQuery);
24
24
  const connection = new WebSocket(socketUrl);
25
+ connection.onopen = function() {
26
+ if (typeof console !== "undefined" && typeof console.debug === "function") {
27
+ console.debug("[HMR] connected.");
28
+ }
29
+ };
25
30
  connection.onclose = function() {
26
31
  if (typeof console !== "undefined" && typeof console.info === "function") {
27
- console.info(
28
- "The development server has disconnected.\nRefresh the page if necessary."
29
- );
32
+ console.debug("[HMR] disconnected. Refresh the page if necessary.");
30
33
  }
31
34
  };
32
35
  let isFirstCompilation = true;
@@ -58,7 +58,6 @@ __export(getMockData_exports, {
58
58
  getMatched: () => getMatched
59
59
  });
60
60
  module.exports = __toCommonJS(getMockData_exports);
61
- var import_utils = require("@modern-js/utils");
62
61
  var import_path_to_regexp = require("path-to-regexp");
63
62
  const VALID_METHODS = ["get", "post", "put", "delete", "patch"];
64
63
  const BODY_PARSED_METHODS = ["post", "put", "delete", "patch"];
@@ -72,7 +71,7 @@ const createStaticDataHandler = (method, handler) => (context) => {
72
71
  res.end(JSON.stringify(handler));
73
72
  };
74
73
  const allowTypes = ["object", "function"];
75
- const normalizeConfig = (mockConfig) => Object.keys(mockConfig).reduce((acc, key) => {
74
+ var getMockData_default = (mockConfig) => Object.keys(mockConfig).reduce((acc, key) => {
76
75
  const handler = mockConfig[key];
77
76
  const type = typeof handler;
78
77
  if (!allowTypes.includes(type)) {
@@ -107,14 +106,6 @@ const parseKey = (key) => {
107
106
  path: key
108
107
  };
109
108
  };
110
- var getMockData_default = (filepath) => {
111
- const mockModule = (0, import_utils.compatRequire)(filepath);
112
- if (!mockModule) {
113
- throw new Error(`Mock file ${filepath} parsed failed!`);
114
- }
115
- const data = normalizeConfig(mockModule);
116
- return data;
117
- };
118
109
  const getMatched = (context, mockApiList) => {
119
110
  const { path: targetPathname, method: targetMethod } = context;
120
111
  const matched = mockApiList.find((mockApi) => {
@@ -63,11 +63,27 @@ const createMockHandler = ({ pwd }) => {
63
63
  if (!filepath) {
64
64
  return null;
65
65
  }
66
- const apiList = (0, import_getMockData.default)(filepath);
66
+ const {
67
+ default: mockModule,
68
+ config
69
+ } = (0, import_utils.compatRequire)(filepath, false);
70
+ if ((config == null ? void 0 : config.enable) === false) {
71
+ return null;
72
+ }
73
+ if (!mockModule) {
74
+ throw new Error(`Mock file ${filepath} parsed failed!`);
75
+ }
76
+ const apiList = (0, import_getMockData.default)(mockModule);
67
77
  if (!apiList || apiList.length === 0) {
68
78
  return null;
69
79
  }
70
80
  return (context, next) => __async(void 0, null, function* () {
81
+ if (typeof (config == null ? void 0 : config.enable) === "function") {
82
+ const enableMock = config.enable(context.req, context.res);
83
+ if (!enableMock) {
84
+ return next();
85
+ }
86
+ }
71
87
  const { res } = context;
72
88
  const matched = (0, import_getMockData.getMatched)(context, apiList);
73
89
  if (!matched) {
@@ -94,6 +94,7 @@ const enableRegister = (projectRoot, config) => {
94
94
  });
95
95
  tsNode.register({
96
96
  project: tsconfigPath,
97
+ scope: true,
97
98
  files: true,
98
99
  transpileOnly: true,
99
100
  ignore: ["(?:^|/)node_modules/", `(?:^|/)${distPath}/`]
@@ -202,6 +202,7 @@ class ModernDevServer extends import_prod_server.ModernServer {
202
202
  }
203
203
  this.cleanSSRCache();
204
204
  this.reader.updateFile();
205
+ this.runner.repack();
205
206
  super.onRepack(options);
206
207
  }
207
208
  createHTTPServer(handler) {
@@ -95,9 +95,14 @@ var require_hmr_client = __commonJS({
95
95
  var hadRuntimeError = false;
96
96
  var socketUrl = createSocketUrl(__resourceQuery);
97
97
  var connection = new WebSocket(socketUrl);
98
+ connection.onopen = function() {
99
+ if (typeof console !== "undefined" && typeof console.debug === "function") {
100
+ console.debug("[HMR] connected.");
101
+ }
102
+ };
98
103
  connection.onclose = function() {
99
104
  if (typeof console !== "undefined" && typeof console.info === "function") {
100
- console.info("The development server has disconnected.\nRefresh the page if necessary.");
105
+ console.debug("[HMR] disconnected. Refresh the page if necessary.");
101
106
  }
102
107
  };
103
108
  var isFirstCompilation = true;
@@ -275,9 +275,9 @@ var DevMiddleware = /*#__PURE__*/ function(EventEmitter) {
275
275
  });
276
276
  var _this1 = this;
277
277
  app.on("close", /*#__PURE__*/ _asyncToGenerator(function() {
278
- var ref;
278
+ var _this_middleware;
279
279
  return __generator(this, function(_state) {
280
- (ref = _this1.middleware) === null || ref === void 0 ? void 0 : ref.close(noop);
280
+ (_this_middleware = _this1.middleware) === null || _this_middleware === void 0 ? void 0 : _this_middleware.close(noop);
281
281
  _this1.socketServer.close();
282
282
  return [
283
283
  2
@@ -49,11 +49,11 @@ var SocketServer = /*#__PURE__*/ function() {
49
49
  key: "prepare",
50
50
  value: function prepare(app) {
51
51
  var _this = this;
52
- var ref;
52
+ var _this_options_client;
53
53
  this.app = app;
54
54
  this.wsServer = new ws.Server({
55
55
  noServer: true,
56
- path: (ref = this.options.client) === null || ref === void 0 ? void 0 : ref.path
56
+ path: (_this_options_client = this.options.client) === null || _this_options_client === void 0 ? void 0 : _this_options_client.path
57
57
  });
58
58
  this.app.on("upgrade", function(req, sock, head) {
59
59
  if (!_this.wsServer.shouldHandle(req)) {
@@ -224,7 +224,6 @@ var __generator = this && this.__generator || function(thisArg, body) {
224
224
  };
225
225
  }
226
226
  };
227
- import { compatRequire } from "@modern-js/utils";
228
227
  import { match } from "path-to-regexp";
229
228
  var VALID_METHODS = [
230
229
  "get",
@@ -267,7 +266,7 @@ var allowTypes = [
267
266
  "object",
268
267
  "function"
269
268
  ];
270
- var normalizeConfig = function(mockConfig) {
269
+ var getMockData_default = function(mockConfig) {
271
270
  return Object.keys(mockConfig).reduce(function(acc, key) {
272
271
  var handler = mockConfig[key];
273
272
  var type = typeof handler === "undefined" ? "undefined" : _typeof(handler);
@@ -302,14 +301,6 @@ var parseKey = function(key) {
302
301
  path: key
303
302
  };
304
303
  };
305
- var getMockData_default = function(filepath) {
306
- var mockModule = compatRequire(filepath);
307
- if (!mockModule) {
308
- throw new Error("Mock file ".concat(filepath, " parsed failed!"));
309
- }
310
- var data = normalizeConfig(mockModule);
311
- return data;
312
- };
313
304
  var getMatched = function(context, mockApiList) {
314
305
  var targetPathname = context.path, targetMethod = context.method;
315
306
  var matched = mockApiList.find(function(mockApi) {
@@ -123,7 +123,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
123
123
  }
124
124
  };
125
125
  import path from "path";
126
- import { fs } from "@modern-js/utils";
126
+ import { compatRequire, fs } from "@modern-js/utils";
127
127
  import { AGGRED_DIR } from "@modern-js/prod-server";
128
128
  import getMockData, { getMatched } from "./getMockData";
129
129
  var createMockHandler = function(param) {
@@ -160,14 +160,30 @@ var createMockHandler = function(param) {
160
160
  if (!filepath) {
161
161
  return null;
162
162
  }
163
- var apiList = getMockData(filepath);
163
+ var _compatRequire = compatRequire(filepath, false), mockModule = _compatRequire.default, config = _compatRequire.config;
164
+ if ((config === null || config === void 0 ? void 0 : config.enable) === false) {
165
+ return null;
166
+ }
167
+ if (!mockModule) {
168
+ throw new Error("Mock file ".concat(filepath, " parsed failed!"));
169
+ }
170
+ var apiList = getMockData(mockModule);
164
171
  if (!apiList || apiList.length === 0) {
165
172
  return null;
166
173
  }
167
174
  return function() {
168
175
  var _ref = _asyncToGenerator(function(context, next) {
169
- var res, matched;
176
+ var enableMock, res, matched;
170
177
  return __generator(this, function(_state) {
178
+ if (typeof (config === null || config === void 0 ? void 0 : config.enable) === "function") {
179
+ enableMock = config.enable(context.req, context.res);
180
+ if (!enableMock) {
181
+ return [
182
+ 2,
183
+ next()
184
+ ];
185
+ }
186
+ }
171
187
  res = context.res;
172
188
  matched = getMatched(context, apiList);
173
189
  if (!matched) {
@@ -80,9 +80,9 @@ var enableRegister = function(projectRoot, config) {
80
80
  projectRoot
81
81
  ]);
82
82
  if (isTsProject && existTsNode && existTsConfigPaths) {
83
- var ref;
83
+ var _config_output_distPath;
84
84
  debug("use ts-node");
85
- var distPath = ((ref = config.output.distPath) === null || ref === void 0 ? void 0 : ref.root) || "dist";
85
+ var distPath = ((_config_output_distPath = config.output.distPath) === null || _config_output_distPath === void 0 ? void 0 : _config_output_distPath.root) || "dist";
86
86
  var tsNode = require("ts-node");
87
87
  var tsConfigPaths = require("tsconfig-paths");
88
88
  var alias = config.source.alias;
@@ -90,7 +90,7 @@ var enableRegister = function(projectRoot, config) {
90
90
  appDirectory: projectRoot,
91
91
  tsconfigPath: tsconfigPath
92
92
  });
93
- var _paths = aliasConfig.paths, paths = _paths === void 0 ? {} : _paths, _absoluteBaseUrl = aliasConfig.absoluteBaseUrl, absoluteBaseUrl = _absoluteBaseUrl === void 0 ? "./" : _absoluteBaseUrl;
93
+ var _aliasConfig_paths = aliasConfig.paths, paths = _aliasConfig_paths === void 0 ? {} : _aliasConfig_paths, _aliasConfig_absoluteBaseUrl = aliasConfig.absoluteBaseUrl, absoluteBaseUrl = _aliasConfig_absoluteBaseUrl === void 0 ? "./" : _aliasConfig_absoluteBaseUrl;
94
94
  var tsPaths = Object.keys(paths).reduce(function(o, key) {
95
95
  var tsPath = paths[key];
96
96
  if (typeof tsPath === "string" && path.isAbsolute(tsPath)) {
@@ -109,6 +109,7 @@ var enableRegister = function(projectRoot, config) {
109
109
  });
110
110
  tsNode.register({
111
111
  project: tsconfigPath,
112
+ scope: true,
112
113
  files: true,
113
114
  transpileOnly: true,
114
115
  ignore: [
@@ -117,12 +118,12 @@ var enableRegister = function(projectRoot, config) {
117
118
  ]
118
119
  });
119
120
  } else {
120
- var ref1, ref2;
121
+ var _config_tools, _config_server;
121
122
  debug("use @babel/register");
122
123
  var babelConfig = resolveBabelConfig(projectRoot, _objectSpreadProps(_objectSpread({}, config.source), {
123
- babelConfig: (ref1 = config.tools) === null || ref1 === void 0 ? void 0 : ref1.babel,
124
+ babelConfig: (_config_tools = config.tools) === null || _config_tools === void 0 ? void 0 : _config_tools.babel,
124
125
  server: {
125
- compiler: (ref2 = config.server) === null || ref2 === void 0 ? void 0 : ref2.compiler
126
+ compiler: (_config_server = config.server) === null || _config_server === void 0 ? void 0 : _config_server.compiler
126
127
  }
127
128
  }), {
128
129
  tsconfigPath: tsconfigPath,
@@ -154,15 +154,15 @@ var Watcher = /*#__PURE__*/ function() {
154
154
  {
155
155
  key: "updateDepTree",
156
156
  value: function updateDepTree() {
157
- var ref;
158
- (ref = this.dependencyTree) === null || ref === void 0 ? void 0 : ref.update(require.cache);
157
+ var _this_dependencyTree;
158
+ (_this_dependencyTree = this.dependencyTree) === null || _this_dependencyTree === void 0 ? void 0 : _this_dependencyTree.update(require.cache);
159
159
  }
160
160
  },
161
161
  {
162
162
  key: "cleanDepCache",
163
163
  value: function cleanDepCache(filepath) {
164
- var ref;
165
- var node = (ref = this.dependencyTree) === null || ref === void 0 ? void 0 : ref.getNode(filepath);
164
+ var _this_dependencyTree;
165
+ var node = (_this_dependencyTree = this.dependencyTree) === null || _this_dependencyTree === void 0 ? void 0 : _this_dependencyTree.getNode(filepath);
166
166
  if (node && require.cache[filepath]) {
167
167
  delete require.cache[filepath];
168
168
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
@@ -43,7 +43,7 @@ var StatsCache = /*#__PURE__*/ function() {
43
43
  {
44
44
  key: "add",
45
45
  value: function add(files) {
46
- var ref = this, cachedHash = ref.cachedHash, cachedSize = ref.cachedSize;
46
+ var _this = this, cachedHash = _this.cachedHash, cachedSize = _this.cachedSize;
47
47
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
48
48
  try {
49
49
  for(var _iterator = files[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
@@ -75,7 +75,7 @@ var StatsCache = /*#__PURE__*/ function() {
75
75
  {
76
76
  key: "refresh",
77
77
  value: function refresh(filename) {
78
- var ref = this, cachedHash = ref.cachedHash, cachedSize = ref.cachedSize;
78
+ var _this = this, cachedHash = _this.cachedHash, cachedSize = _this.cachedSize;
79
79
  if (fs.existsSync(filename)) {
80
80
  var stats = fs.statSync(filename);
81
81
  if (stats.isFile()) {
@@ -97,7 +97,7 @@ var StatsCache = /*#__PURE__*/ function() {
97
97
  {
98
98
  key: "isDiff",
99
99
  value: function isDiff(filename) {
100
- var ref = this, cachedHash = ref.cachedHash, cachedSize = ref.cachedSize;
100
+ var _this = this, cachedHash = _this.cachedHash, cachedSize = _this.cachedSize;
101
101
  var stats = fs.statSync(filename);
102
102
  var hash = cachedHash[filename];
103
103
  var size = cachedSize[filename];
@@ -438,13 +438,13 @@ var ModernDevServer = /*#__PURE__*/ function(ModernServer) {
438
438
  return _get(_getPrototypeOf(ModernDevServer.prototype), "onInit", _this);
439
439
  };
440
440
  return _asyncToGenerator(function() {
441
- var dev, ref, befores, afters, beforeHandlers, afterHandlers;
441
+ var dev, _this_applySetupMiddlewares, befores, afters, beforeHandlers, afterHandlers;
442
442
  return __generator(this, function(_state) {
443
443
  switch(_state.label){
444
444
  case 0:
445
445
  _this1.runner = runner;
446
446
  dev = _this1.dev;
447
- ref = _this1.applySetupMiddlewares(), befores = ref.befores, afters = ref.afters;
447
+ _this_applySetupMiddlewares = _this1.applySetupMiddlewares(), befores = _this_applySetupMiddlewares.befores, afters = _this_applySetupMiddlewares.afters;
448
448
  return [
449
449
  4,
450
450
  _this1.setupBeforeDevMiddleware()
@@ -474,13 +474,13 @@ var ModernDevServer = /*#__PURE__*/ function(ModernServer) {
474
474
  if (dev.watch) {
475
475
  _this1.startWatcher();
476
476
  app.on("close", /*#__PURE__*/ _asyncToGenerator(function() {
477
- var ref;
477
+ var _this_watcher;
478
478
  return __generator(this, function(_state) {
479
479
  switch(_state.label){
480
480
  case 0:
481
481
  return [
482
482
  4,
483
- (ref = _this1.watcher) === null || ref === void 0 ? void 0 : ref.close()
483
+ (_this_watcher = _this1.watcher) === null || _this_watcher === void 0 ? void 0 : _this_watcher.close()
484
484
  ];
485
485
  case 1:
486
486
  _state.sent();
@@ -504,7 +504,7 @@ var ModernDevServer = /*#__PURE__*/ function(ModernServer) {
504
504
  value: function applyDefaultMiddlewares(app) {
505
505
  var _this = this;
506
506
  return _asyncToGenerator(function() {
507
- var pwd, dev, devMiddleware, proxyHandlers, ref, connectHistoryApiFallback, historyApiFallbackMiddleware;
507
+ var pwd, dev, devMiddleware, proxyHandlers, _ref, connectHistoryApiFallback, historyApiFallbackMiddleware;
508
508
  return __generator(this, function(_state) {
509
509
  switch(_state.label){
510
510
  case 0:
@@ -519,7 +519,7 @@ var ModernDevServer = /*#__PURE__*/ function(ModernServer) {
519
519
  var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
520
520
  try {
521
521
  for(var _iterator = Object.entries(confHeaders)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true){
522
- var _value = _slicedToArray(_step.value, 2), key = _value[0], value = _value[1];
522
+ var _step_value = _slicedToArray(_step.value, 2), key = _step_value[0], value = _step_value[1];
523
523
  ctx.res.setHeader(key, value);
524
524
  }
525
525
  } catch (err) {
@@ -582,7 +582,7 @@ var ModernDevServer = /*#__PURE__*/ function(ModernServer) {
582
582
  import("connect-history-api-fallback")
583
583
  ];
584
584
  case 1:
585
- ref = _state.sent(), connectHistoryApiFallback = ref.default;
585
+ _ref = _state.sent(), connectHistoryApiFallback = _ref.default;
586
586
  historyApiFallbackMiddleware = connectHistoryApiFallback(typeof dev.historyApiFallback === "boolean" ? {} : dev.historyApiFallback);
587
587
  _this.addHandler(function(ctx, next) {
588
588
  return historyApiFallbackMiddleware(ctx.req, ctx.res, next);
@@ -606,6 +606,7 @@ var ModernDevServer = /*#__PURE__*/ function(ModernServer) {
606
606
  }
607
607
  this.cleanSSRCache();
608
608
  this.reader.updateFile();
609
+ this.runner.repack();
609
610
  _get(_getPrototypeOf(ModernDevServer.prototype), "onRepack", this).call(this, options);
610
611
  }
611
612
  },
@@ -765,8 +766,8 @@ var ModernDevServer = /*#__PURE__*/ function(ModernServer) {
765
766
  key: "startWatcher",
766
767
  value: function startWatcher() {
767
768
  var _this = this;
768
- var ref;
769
- var ref1 = this, pwd = ref1.pwd, distDir = ref1.distDir;
769
+ var _this_conf_server;
770
+ var _this1 = this, pwd = _this1.pwd, distDir = _this1.distDir;
770
771
  var mock = AGGRED_DIR.mock;
771
772
  var defaultWatched = [
772
773
  "".concat(mock, "/**/*"),
@@ -775,7 +776,7 @@ var ModernDevServer = /*#__PURE__*/ function(ModernServer) {
775
776
  "".concat(SHARED_DIR, "/**/*"),
776
777
  "".concat(distDir, "/").concat(SERVER_BUNDLE_DIRECTORY, "/*-server-loaders.js")
777
778
  ];
778
- var watchOptions = mergeWatchOptions((ref = this.conf.server) === null || ref === void 0 ? void 0 : ref.watchOptions);
779
+ var watchOptions = mergeWatchOptions((_this_conf_server = this.conf.server) === null || _this_conf_server === void 0 ? void 0 : _this_conf_server.watchOptions);
779
780
  var defaultWatchedPaths = defaultWatched.map(function(p) {
780
781
  var finalPath = path.isAbsolute(p) ? p : path.join(pwd, p);
781
782
  return path.normalize(finalPath);
@@ -7,6 +7,7 @@ import type { ModernDevServerOptions } from '../types';
7
7
  export declare class ModernDevServer extends ModernServer {
8
8
  private mockHandler;
9
9
  private readonly dev;
10
+ private readonly appContext;
10
11
  private readonly devMiddleware;
11
12
  private watcher?;
12
13
  constructor(options: ModernDevServerOptions);
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.5.1-alpha.0",
14
+ "version": "2.5.1-alpha.2",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/cjs/index.js",
@@ -29,17 +29,17 @@
29
29
  "dependencies": {
30
30
  "@babel/core": "^7.18.0",
31
31
  "@babel/register": "^7.17.7",
32
- "@modern-js/prod-server": "2.5.0",
33
- "@modern-js/server-utils": "2.5.0",
34
- "@modern-js/types": "2.5.0",
35
- "@modern-js/utils": "2.5.0",
32
+ "@modern-js/prod-server": "2.5.1-alpha.3",
33
+ "@modern-js/server-utils": "2.5.1-alpha.0",
34
+ "@modern-js/types": "2.5.1-alpha.0",
35
+ "@modern-js/utils": "2.5.1-alpha.2",
36
36
  "connect-history-api-fallback": "^2.0.0",
37
37
  "minimatch": "^3.0.4",
38
38
  "path-to-regexp": "^6.2.0",
39
39
  "ws": "^8.2.0"
40
40
  },
41
41
  "devDependencies": {
42
- "@modern-js/server-core": "2.5.0",
42
+ "@modern-js/server-core": "2.5.1-alpha.0",
43
43
  "@scripts/build": "2.5.0",
44
44
  "@scripts/jest-config": "2.5.0",
45
45
  "@types/connect-history-api-fallback": "^1.3.5",