@modern-js/server 2.35.0 → 2.36.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 (52) hide show
  1. package/dist/cjs/constants.js +26 -9
  2. package/dist/cjs/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +27 -17
  3. package/dist/cjs/dev-tools/dev-middleware/hmr-client/index.js +31 -14
  4. package/dist/cjs/dev-tools/dev-middleware/index.js +43 -23
  5. package/dist/cjs/dev-tools/dev-middleware/socketServer.js +41 -19
  6. package/dist/cjs/dev-tools/https/index.js +29 -12
  7. package/dist/cjs/dev-tools/mock/getMockData.js +27 -18
  8. package/dist/cjs/dev-tools/mock/index.js +45 -22
  9. package/dist/cjs/dev-tools/register/index.js +47 -21
  10. package/dist/cjs/dev-tools/watcher/dependencyTree.js +43 -24
  11. package/dist/cjs/dev-tools/watcher/index.js +50 -34
  12. package/dist/cjs/dev-tools/watcher/statsCache.js +45 -19
  13. package/dist/cjs/index.js +27 -18
  14. package/dist/cjs/server/devServer.js +82 -60
  15. package/dist/cjs/server/index.js +28 -11
  16. package/dist/cjs/server/workerSSRRender.js +38 -12
  17. package/dist/cjs/types.js +15 -3
  18. package/dist/esm/constants.js +4 -1
  19. package/dist/esm/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +6 -2
  20. package/dist/esm/dev-tools/dev-middleware/hmr-client/index.js +148 -140
  21. package/dist/esm/dev-tools/dev-middleware/index.js +9 -9
  22. package/dist/esm/dev-tools/dev-middleware/socketServer.js +7 -5
  23. package/dist/esm/dev-tools/https/index.js +4 -1
  24. package/dist/esm/dev-tools/mock/getMockData.js +6 -2
  25. package/dist/esm/dev-tools/mock/index.js +7 -5
  26. package/dist/esm/dev-tools/register/index.js +7 -4
  27. package/dist/esm/dev-tools/watcher/dependencyTree.js +7 -3
  28. package/dist/esm/dev-tools/watcher/index.js +9 -4
  29. package/dist/esm/dev-tools/watcher/statsCache.js +4 -1
  30. package/dist/esm/index.js +5 -2
  31. package/dist/esm/server/devServer.js +21 -19
  32. package/dist/esm/server/index.js +4 -1
  33. package/dist/esm/server/workerSSRRender.js +6 -3
  34. package/dist/esm/types.js +0 -1
  35. package/dist/esm-node/constants.js +4 -1
  36. package/dist/esm-node/dev-tools/dev-middleware/hmr-client/createSocketUrl.js +6 -2
  37. package/dist/esm-node/dev-tools/dev-middleware/hmr-client/index.js +134 -126
  38. package/dist/esm-node/dev-tools/dev-middleware/index.js +8 -8
  39. package/dist/esm-node/dev-tools/dev-middleware/socketServer.js +3 -1
  40. package/dist/esm-node/dev-tools/https/index.js +4 -1
  41. package/dist/esm-node/dev-tools/mock/getMockData.js +6 -2
  42. package/dist/esm-node/dev-tools/mock/index.js +6 -5
  43. package/dist/esm-node/dev-tools/register/index.js +4 -1
  44. package/dist/esm-node/dev-tools/watcher/dependencyTree.js +6 -2
  45. package/dist/esm-node/dev-tools/watcher/index.js +9 -4
  46. package/dist/esm-node/dev-tools/watcher/statsCache.js +4 -1
  47. package/dist/esm-node/index.js +5 -2
  48. package/dist/esm-node/server/devServer.js +8 -8
  49. package/dist/esm-node/server/index.js +4 -1
  50. package/dist/esm-node/server/workerSSRRender.js +4 -1
  51. package/dist/esm-node/types.js +0 -1
  52. package/package.json +10 -10
@@ -22,7 +22,7 @@ import { enableRegister } from "../dev-tools/register";
22
22
  import Watcher, { mergeWatchOptions } from "../dev-tools/watcher";
23
23
  import DevMiddleware from "../dev-tools/dev-middleware";
24
24
  import { workerSSRRender } from "./workerSSRRender";
25
- export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
25
+ var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
26
26
  "use strict";
27
27
  _inherits(ModernDevServer2, ModernServer2);
28
28
  var _super = _create_super(ModernDevServer2);
@@ -98,8 +98,8 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
98
98
  }, serverOptions);
99
99
  });
100
100
  return {
101
- befores: befores,
102
- afters: afters
101
+ befores,
102
+ afters
103
103
  };
104
104
  }
105
105
  },
@@ -187,12 +187,12 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
187
187
  var forceCSR = typeof ssrConfig === "object" ? ssrConfig.forceCSR : false;
188
188
  return createRenderHandler({
189
189
  ssrRender: workerSSRRender,
190
- distDir: distDir,
191
- staticGenerate: staticGenerate,
192
- conf: conf,
193
- forceCSR: forceCSR,
190
+ distDir,
191
+ staticGenerate,
192
+ conf,
193
+ forceCSR,
194
194
  nonce: (_conf_security = conf.security) === null || _conf_security === void 0 ? void 0 : _conf_security.nonce,
195
- metaName: metaName
195
+ metaName
196
196
  });
197
197
  }
198
198
  return _get(_get_prototype_of(ModernDevServer2.prototype), "getRenderHandler", this).call(this);
@@ -210,8 +210,7 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
210
210
  case 0:
211
211
  pwd = _this.pwd, dev = _this.dev, devMiddleware = _this.devMiddleware, conf = _this.conf;
212
212
  isUseStreamingSSR = function(routes) {
213
- var _routes;
214
- return (_routes = routes) === null || _routes === void 0 ? void 0 : _routes.some(function(r) {
213
+ return routes === null || routes === void 0 ? void 0 : routes.some(function(r) {
215
214
  return r.isStream === true;
216
215
  });
217
216
  };
@@ -274,7 +273,7 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
274
273
  next();
275
274
  });
276
275
  _this.mockHandler = createMockHandler({
277
- pwd: pwd
276
+ pwd
278
277
  });
279
278
  _this.addHandler(function(ctx, next) {
280
279
  if (_this.mockHandler) {
@@ -445,7 +444,7 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
445
444
  1
446
445
  ];
447
446
  _this1.mockHandler = createMockHandler({
448
- pwd: pwd
447
+ pwd
449
448
  });
450
449
  return [
451
450
  3,
@@ -461,7 +460,7 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
461
460
  success = _this1.runner.onApiChange([
462
461
  {
463
462
  filename: filepath,
464
- event: event
463
+ event
465
464
  }
466
465
  ]);
467
466
  if (!(success !== true))
@@ -472,7 +471,7 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
472
471
  return [
473
472
  4,
474
473
  _superprop_get_onServerChange().call(_this1, {
475
- filepath: filepath
474
+ filepath
476
475
  })
477
476
  ];
478
477
  case 2:
@@ -599,11 +598,11 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
599
598
  key: "startWatcher",
600
599
  value: function startWatcher() {
601
600
  var _this = this;
602
- var _appContext, _appContext1, _this_conf_server;
601
+ var _this_conf_server;
603
602
  var _this1 = this, pwd = _this1.pwd, distDir = _this1.distDir, appContext = _this1.appContext;
604
603
  var mock = AGGRED_DIR.mock;
605
- var apiDir = ((_appContext = appContext) === null || _appContext === void 0 ? void 0 : _appContext.apiDirectory) || API_DIR;
606
- var sharedDir = ((_appContext1 = appContext) === null || _appContext1 === void 0 ? void 0 : _appContext1.sharedDirectory) || SHARED_DIR;
604
+ var apiDir = (appContext === null || appContext === void 0 ? void 0 : appContext.apiDirectory) || API_DIR;
605
+ var sharedDir = (appContext === null || appContext === void 0 ? void 0 : appContext.sharedDirectory) || SHARED_DIR;
607
606
  var defaultWatched = [
608
607
  "".concat(mock, "/**/*"),
609
608
  "".concat(SERVER_DIR, "/**/*"),
@@ -627,8 +626,8 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
627
626
  watcher.cleanDepCache(filepath);
628
627
  }
629
628
  _this.onServerChange({
630
- filepath: filepath,
631
- event: event
629
+ filepath,
630
+ event
632
631
  });
633
632
  });
634
633
  this.watcher = watcher;
@@ -637,3 +636,6 @@ export var ModernDevServer = /* @__PURE__ */ function(ModernServer2) {
637
636
  ]);
638
637
  return ModernDevServer2;
639
638
  }(ModernServer);
639
+ export {
640
+ ModernDevServer
641
+ };
@@ -6,7 +6,7 @@ import { ModernDevServer } from "./devServer";
6
6
  var createDevServer = function(options) {
7
7
  return new ModernDevServer(options);
8
8
  };
9
- export var DevServer = /* @__PURE__ */ function(Server2) {
9
+ var DevServer = /* @__PURE__ */ function(Server2) {
10
10
  "use strict";
11
11
  _inherits(DevServer2, Server2);
12
12
  var _super = _create_super(DevServer2);
@@ -21,3 +21,6 @@ export var DevServer = /* @__PURE__ */ function(Server2) {
21
21
  }
22
22
  return DevServer2;
23
23
  }(Server);
24
+ export {
25
+ DevServer
26
+ };
@@ -3,7 +3,7 @@ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
3
  import axios from "axios";
4
4
  import { mime } from "@modern-js/utils";
5
5
  var PORT = 9230;
6
- export function workerSSRRender(ctx, renderOptions, _runner) {
6
+ function workerSSRRender(ctx, renderOptions, _runner) {
7
7
  return _workerSSRRender.apply(this, arguments);
8
8
  }
9
9
  function _workerSSRRender() {
@@ -20,8 +20,8 @@ function _workerSSRRender() {
20
20
  axios.get(url, {
21
21
  timeout: 5e3,
22
22
  responseType: "text",
23
- headers: headers,
24
- params: params
23
+ headers,
24
+ params
25
25
  })
26
26
  ];
27
27
  case 1:
@@ -38,3 +38,6 @@ function _workerSSRRender() {
38
38
  });
39
39
  return _workerSSRRender.apply(this, arguments);
40
40
  }
41
+ export {
42
+ workerSSRRender
43
+ };
package/dist/esm/types.js CHANGED
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +1,5 @@
1
1
  import { HMR_SOCK_PATH } from "@modern-js/utils/universal/constants";
2
- export const getDefaultDevOptions = () => {
2
+ const getDefaultDevOptions = () => {
3
3
  return {
4
4
  client: {
5
5
  path: HMR_SOCK_PATH,
@@ -20,3 +20,6 @@ export const getDefaultDevOptions = () => {
20
20
  liveReload: true
21
21
  };
22
22
  };
23
+ export {
24
+ getDefaultDevOptions
25
+ };
@@ -1,5 +1,5 @@
1
1
  import { HMR_SOCK_PATH } from "@modern-js/utils/universal/constants";
2
- export function createSocketUrl(resourceQuery) {
2
+ function createSocketUrl(resourceQuery) {
3
3
  const searchParams = resourceQuery.substr(1).split("&");
4
4
  const options = {};
5
5
  for (const pair of searchParams) {
@@ -9,7 +9,7 @@ export function createSocketUrl(resourceQuery) {
9
9
  const currentLocation = self.location;
10
10
  return getSocketUrl(options, currentLocation);
11
11
  }
12
- export function formatURL({ port, protocol, hostname, pathname }) {
12
+ function formatURL({ port, protocol, hostname, pathname }) {
13
13
  if (window.URL) {
14
14
  const url = new URL("http://localhost");
15
15
  url.port = port;
@@ -30,3 +30,7 @@ function getSocketUrl(urlParts, location) {
30
30
  pathname: path || HMR_SOCK_PATH
31
31
  });
32
32
  }
33
+ export {
34
+ createSocketUrl,
35
+ formatURL
36
+ };
@@ -1,137 +1,145 @@
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
+ };
1
5
  import stripAnsi from "@modern-js/utils/strip-ansi";
2
6
  import { formatWebpackMessages } from "@modern-js/utils/universal/format-webpack";
3
7
  import { createSocketUrl } from "./createSocketUrl";
4
- const hadRuntimeError = false;
5
- const socketUrl = createSocketUrl(__resourceQuery);
6
- const connection = new WebSocket(socketUrl);
7
- connection.onopen = function() {
8
- if (typeof console !== "undefined" && typeof console.info === "function") {
9
- console.info("[HMR] connected.");
10
- }
11
- };
12
- connection.onclose = function() {
13
- if (typeof console !== "undefined" && typeof console.info === "function") {
14
- console.info("[HMR] disconnected. Refresh the page if necessary.");
15
- }
16
- };
17
- let isFirstCompilation = true;
18
- let mostRecentCompilationHash = null;
19
- let hasCompileErrors = false;
20
- function clearOutdatedErrors() {
21
- if (typeof console !== "undefined" && typeof console.clear === "function") {
22
- if (hasCompileErrors) {
23
- console.clear();
8
+ var require_hmr_client = __commonJS({
9
+ "src/dev-tools/dev-middleware/hmr-client/index.ts"(exports, module) {
10
+ const hadRuntimeError = false;
11
+ const socketUrl = createSocketUrl(__resourceQuery);
12
+ const connection = new WebSocket(socketUrl);
13
+ connection.onopen = function() {
14
+ if (typeof console !== "undefined" && typeof console.info === "function") {
15
+ console.info("[HMR] connected.");
16
+ }
17
+ };
18
+ connection.onclose = function() {
19
+ if (typeof console !== "undefined" && typeof console.info === "function") {
20
+ console.info("[HMR] disconnected. Refresh the page if necessary.");
21
+ }
22
+ };
23
+ let isFirstCompilation = true;
24
+ let mostRecentCompilationHash = null;
25
+ let hasCompileErrors = false;
26
+ function clearOutdatedErrors() {
27
+ if (typeof console !== "undefined" && typeof console.clear === "function") {
28
+ if (hasCompileErrors) {
29
+ console.clear();
30
+ }
31
+ }
24
32
  }
25
- }
26
- }
27
- function handleSuccess() {
28
- clearOutdatedErrors();
29
- const isHotUpdate = !isFirstCompilation;
30
- isFirstCompilation = false;
31
- hasCompileErrors = false;
32
- if (isHotUpdate) {
33
- tryApplyUpdates();
34
- }
35
- }
36
- function handleWarnings(warnings) {
37
- clearOutdatedErrors();
38
- const isHotUpdate = !isFirstCompilation;
39
- isFirstCompilation = false;
40
- hasCompileErrors = false;
41
- function printWarnings() {
42
- const formatted = formatWebpackMessages({
43
- warnings,
44
- errors: []
45
- });
46
- if (typeof console !== "undefined" && typeof console.warn === "function") {
47
- for (let i = 0; i < formatted.warnings.length; i++) {
48
- if (i === 5) {
49
- console.warn("There were more warnings in other files.\nYou can find a complete log in the terminal.");
50
- break;
33
+ function handleSuccess() {
34
+ clearOutdatedErrors();
35
+ const isHotUpdate = !isFirstCompilation;
36
+ isFirstCompilation = false;
37
+ hasCompileErrors = false;
38
+ if (isHotUpdate) {
39
+ tryApplyUpdates();
40
+ }
41
+ }
42
+ function handleWarnings(warnings) {
43
+ clearOutdatedErrors();
44
+ const isHotUpdate = !isFirstCompilation;
45
+ isFirstCompilation = false;
46
+ hasCompileErrors = false;
47
+ function printWarnings() {
48
+ const formatted = formatWebpackMessages({
49
+ warnings,
50
+ errors: []
51
+ });
52
+ if (typeof console !== "undefined" && typeof console.warn === "function") {
53
+ for (let i = 0; i < formatted.warnings.length; i++) {
54
+ if (i === 5) {
55
+ console.warn("There were more warnings in other files.\nYou can find a complete log in the terminal.");
56
+ break;
57
+ }
58
+ console.warn(stripAnsi(formatted.warnings[i]));
59
+ }
51
60
  }
52
- console.warn(stripAnsi(formatted.warnings[i]));
61
+ }
62
+ printWarnings();
63
+ if (isHotUpdate) {
64
+ tryApplyUpdates();
53
65
  }
54
66
  }
55
- }
56
- printWarnings();
57
- if (isHotUpdate) {
58
- tryApplyUpdates();
59
- }
60
- }
61
- function handleErrors(errors) {
62
- clearOutdatedErrors();
63
- isFirstCompilation = false;
64
- hasCompileErrors = true;
65
- const formatted = formatWebpackMessages({
66
- errors,
67
- warnings: []
68
- });
69
- if (typeof console !== "undefined" && typeof console.error === "function") {
70
- for (const error of formatted.errors) {
71
- console.error(stripAnsi(error));
67
+ function handleErrors(errors) {
68
+ clearOutdatedErrors();
69
+ isFirstCompilation = false;
70
+ hasCompileErrors = true;
71
+ const formatted = formatWebpackMessages({
72
+ errors,
73
+ warnings: []
74
+ });
75
+ if (typeof console !== "undefined" && typeof console.error === "function") {
76
+ for (const error of formatted.errors) {
77
+ console.error(stripAnsi(error));
78
+ }
79
+ }
72
80
  }
73
- }
74
- }
75
- function handleAvailableHash(hash) {
76
- mostRecentCompilationHash = hash;
77
- }
78
- connection.onmessage = function(e) {
79
- const message = JSON.parse(e.data);
80
- switch (message.type) {
81
- case "hash":
82
- handleAvailableHash(message.data);
83
- break;
84
- case "still-ok":
85
- case "ok":
86
- handleSuccess();
87
- break;
88
- case "content-changed":
89
- window.location.reload();
90
- break;
91
- case "warnings":
92
- handleWarnings(message.data);
93
- break;
94
- case "errors":
95
- handleErrors(message.data);
96
- break;
97
- default:
98
- }
99
- };
100
- function isUpdateAvailable() {
101
- return mostRecentCompilationHash !== __webpack_hash__;
102
- }
103
- function canApplyUpdates() {
104
- return module.hot.status() === "idle";
105
- }
106
- function tryApplyUpdates() {
107
- var _result;
108
- if (!module.hot) {
109
- window.location.reload();
110
- return;
111
- }
112
- if (!isUpdateAvailable() || !canApplyUpdates()) {
113
- return;
114
- }
115
- function handleApplyUpdates(err, updatedModules) {
116
- const wantsForcedReload = err || !updatedModules || hadRuntimeError;
117
- if (wantsForcedReload) {
118
- window.location.reload();
119
- return;
81
+ function handleAvailableHash(hash) {
82
+ mostRecentCompilationHash = hash;
120
83
  }
121
- if (isUpdateAvailable()) {
122
- tryApplyUpdates();
84
+ connection.onmessage = function(e) {
85
+ const message = JSON.parse(e.data);
86
+ switch (message.type) {
87
+ case "hash":
88
+ handleAvailableHash(message.data);
89
+ break;
90
+ case "still-ok":
91
+ case "ok":
92
+ handleSuccess();
93
+ break;
94
+ case "content-changed":
95
+ window.location.reload();
96
+ break;
97
+ case "warnings":
98
+ handleWarnings(message.data);
99
+ break;
100
+ case "errors":
101
+ handleErrors(message.data);
102
+ break;
103
+ default:
104
+ }
105
+ };
106
+ function isUpdateAvailable() {
107
+ return mostRecentCompilationHash !== __webpack_hash__;
108
+ }
109
+ function canApplyUpdates() {
110
+ return module.hot.status() === "idle";
111
+ }
112
+ function tryApplyUpdates() {
113
+ if (!module.hot) {
114
+ window.location.reload();
115
+ return;
116
+ }
117
+ if (!isUpdateAvailable() || !canApplyUpdates()) {
118
+ return;
119
+ }
120
+ function handleApplyUpdates(err, updatedModules) {
121
+ const wantsForcedReload = err || !updatedModules || hadRuntimeError;
122
+ if (wantsForcedReload) {
123
+ window.location.reload();
124
+ return;
125
+ }
126
+ if (isUpdateAvailable()) {
127
+ tryApplyUpdates();
128
+ }
129
+ }
130
+ const result = module.hot.check(
131
+ /* autoApply */
132
+ true,
133
+ handleApplyUpdates
134
+ );
135
+ if (result === null || result === void 0 ? void 0 : result.then) {
136
+ result.then((updatedModules) => {
137
+ handleApplyUpdates(null, updatedModules);
138
+ }, (err) => {
139
+ handleApplyUpdates(err, null);
140
+ });
141
+ }
123
142
  }
124
143
  }
125
- const result = module.hot.check(
126
- /* autoApply */
127
- true,
128
- handleApplyUpdates
129
- );
130
- if ((_result = result) === null || _result === void 0 ? void 0 : _result.then) {
131
- result.then((updatedModules) => {
132
- handleApplyUpdates(null, updatedModules);
133
- }, (err) => {
134
- handleApplyUpdates(err, null);
135
- });
136
- }
137
- }
144
+ });
145
+ export default require_hmr_client();
@@ -1,17 +1,15 @@
1
1
  import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
- import { sep } from "path";
3
2
  import { EventEmitter } from "events";
4
3
  import SocketServer from "./socketServer";
5
4
  const noop = () => {
6
5
  };
7
6
  function getHMRClientPath(client) {
8
- var _client, _client1, _client2, _client3;
9
- const protocol = ((_client = client) === null || _client === void 0 ? void 0 : _client.protocol) ? `&protocol=${client.protocol}` : "";
10
- const host = ((_client1 = client) === null || _client1 === void 0 ? void 0 : _client1.host) ? `&host=${client.host}` : "";
11
- const path = ((_client2 = client) === null || _client2 === void 0 ? void 0 : _client2.path) ? `&path=${client.path}` : "";
12
- const port = ((_client3 = client) === null || _client3 === void 0 ? void 0 : _client3.port) ? `&port=${client.port}` : "";
7
+ const protocol = (client === null || client === void 0 ? void 0 : client.protocol) ? `&protocol=${client.protocol}` : "";
8
+ const host = (client === null || client === void 0 ? void 0 : client.host) ? `&host=${client.host}` : "";
9
+ const path = (client === null || client === void 0 ? void 0 : client.path) ? `&path=${client.path}` : "";
10
+ const port = (client === null || client === void 0 ? void 0 : client.port) ? `&port=${client.port}` : "";
13
11
  const clientEntry = `${require.resolve("@modern-js/server/hmr-client")}?${host}${path}${port}${protocol}`;
14
- return clientEntry.replace(`${sep}cjs${sep}dev-tools`, `${sep}esm${sep}dev-tools`);
12
+ return clientEntry;
15
13
  }
16
14
  class DevMiddleware extends EventEmitter {
17
15
  init(app) {
@@ -61,4 +59,6 @@ class DevMiddleware extends EventEmitter {
61
59
  }
62
60
  }
63
61
  }
64
- export { DevMiddleware as default };
62
+ export {
63
+ DevMiddleware as default
64
+ };
@@ -143,4 +143,6 @@ class SocketServer {
143
143
  this.options = options;
144
144
  }
145
145
  }
146
- export { SocketServer as default };
146
+ export {
147
+ SocketServer as default
148
+ };
@@ -1,5 +1,5 @@
1
1
  import { chalk, getPackageManager, logger } from "@modern-js/utils";
2
- export const genHttpsOptions = async (userOptions, pwd) => {
2
+ const genHttpsOptions = async (userOptions, pwd) => {
3
3
  const httpsOptions = typeof userOptions === "boolean" ? {} : userOptions;
4
4
  if (!httpsOptions.key || !httpsOptions.cert) {
5
5
  let devcertPath;
@@ -25,3 +25,6 @@ export const genHttpsOptions = async (userOptions, pwd) => {
25
25
  }
26
26
  return httpsOptions;
27
27
  };
28
+ export {
29
+ genHttpsOptions
30
+ };
@@ -25,7 +25,7 @@ const allowTypes = [
25
25
  "object",
26
26
  "function"
27
27
  ];
28
- export default (mockConfig) => Object.keys(mockConfig).reduce((acc, key) => {
28
+ var getMockData_default = (mockConfig) => Object.keys(mockConfig).reduce((acc, key) => {
29
29
  const handler = mockConfig[key];
30
30
  const type = typeof handler;
31
31
  if (!allowTypes.includes(type)) {
@@ -60,7 +60,7 @@ const parseKey = (key) => {
60
60
  path: key
61
61
  };
62
62
  };
63
- export const getMatched = (context, mockApiList) => {
63
+ const getMatched = (context, mockApiList) => {
64
64
  const { path: targetPathname, method: targetMethod } = context;
65
65
  const matched = mockApiList.find((mockApi) => {
66
66
  const { method, path: pathname } = mockApi;
@@ -74,3 +74,7 @@ export const getMatched = (context, mockApiList) => {
74
74
  });
75
75
  return matched;
76
76
  };
77
+ export {
78
+ getMockData_default as default,
79
+ getMatched
80
+ };
@@ -2,8 +2,7 @@ import path from "path";
2
2
  import { compatRequire, fs } from "@modern-js/utils";
3
3
  import { AGGRED_DIR } from "@modern-js/prod-server";
4
4
  import getMockData, { getMatched } from "./getMockData";
5
- export const createMockHandler = ({ pwd }) => {
6
- var _config;
5
+ const createMockHandler = ({ pwd }) => {
7
6
  const exts = [
8
7
  ".ts",
9
8
  ".js"
@@ -21,7 +20,7 @@ export const createMockHandler = ({ pwd }) => {
21
20
  }
22
21
  const mod = compatRequire(filepath, false);
23
22
  const { default: mockModule = mod, config } = mod;
24
- if (((_config = config) === null || _config === void 0 ? void 0 : _config.enable) === false) {
23
+ if ((config === null || config === void 0 ? void 0 : config.enable) === false) {
25
24
  return null;
26
25
  }
27
26
  if (!mockModule) {
@@ -32,8 +31,7 @@ export const createMockHandler = ({ pwd }) => {
32
31
  return null;
33
32
  }
34
33
  return async (context, next) => {
35
- var _config2;
36
- if (typeof ((_config2 = config) === null || _config2 === void 0 ? void 0 : _config2.enable) === "function") {
34
+ if (typeof (config === null || config === void 0 ? void 0 : config.enable) === "function") {
37
35
  const enableMock = config.enable(context.req, context.res);
38
36
  if (!enableMock) {
39
37
  return next();
@@ -48,3 +46,6 @@ export const createMockHandler = ({ pwd }) => {
48
46
  return matched.handler(context, next);
49
47
  };
50
48
  };
49
+ export {
50
+ createMockHandler
51
+ };
@@ -12,7 +12,7 @@ const checkDep = (depName, paths) => {
12
12
  }
13
13
  return Boolean(packagePath);
14
14
  };
15
- export const enableRegister = (projectRoot, config) => {
15
+ const enableRegister = (projectRoot, config) => {
16
16
  const registerDirs = [
17
17
  "./api",
18
18
  "./server",
@@ -107,3 +107,6 @@ export const enableRegister = (projectRoot, config) => {
107
107
  });
108
108
  }
109
109
  };
110
+ export {
111
+ enableRegister
112
+ };
@@ -1,13 +1,13 @@
1
1
  import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
2
  import minimatch from "minimatch";
3
- export const defaultIgnores = [
3
+ const defaultIgnores = [
4
4
  "**/coverage/**",
5
5
  "**/node_modules/**",
6
6
  "**/.*/**",
7
7
  "**/*.d.ts",
8
8
  "**/*.log"
9
9
  ];
10
- export class DependencyTree {
10
+ class DependencyTree {
11
11
  getNode(path) {
12
12
  return this.tree.get(path);
13
13
  }
@@ -64,3 +64,7 @@ export class DependencyTree {
64
64
  ];
65
65
  }
66
66
  }
67
+ export {
68
+ DependencyTree,
69
+ defaultIgnores
70
+ };
@@ -3,12 +3,12 @@ import path from "path";
3
3
  import { fs, chokidar } from "@modern-js/utils";
4
4
  import { DependencyTree } from "./dependencyTree";
5
5
  import { StatsCache } from "./statsCache";
6
- export const defaultWatchOptions = {
6
+ const defaultWatchOptions = {
7
7
  // 初始化的时候不触发 add、addDir 事件
8
8
  ignoreInitial: true,
9
9
  ignored: /api\/typings\/.*/
10
10
  };
11
- export const getWatchedFiles = (watcher) => {
11
+ const getWatchedFiles = (watcher) => {
12
12
  const watched = watcher.getWatched();
13
13
  const files = [];
14
14
  Object.keys(watched).forEach((dir) => {
@@ -18,7 +18,7 @@ export const getWatchedFiles = (watcher) => {
18
18
  });
19
19
  return files;
20
20
  };
21
- export const mergeWatchOptions = (options) => {
21
+ const mergeWatchOptions = (options) => {
22
22
  const watchOptions = {
23
23
  ...options
24
24
  };
@@ -94,4 +94,9 @@ class Watcher {
94
94
  _define_property(this, "watcher", void 0);
95
95
  }
96
96
  }
97
- export { Watcher as default };
97
+ export {
98
+ Watcher as default,
99
+ defaultWatchOptions,
100
+ getWatchedFiles,
101
+ mergeWatchOptions
102
+ };