@modern-js/server 2.49.3 → 2.49.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -57,7 +57,15 @@ const createDevServer = async (options, initProdMiddlewares) => {
57
57
  });
58
58
  server.use("*", (0, import_helpers.initFileReader)());
59
59
  await server.init();
60
- const nodeServer = (0, import_node.createNodeServer)(server.handle.bind(server));
60
+ const devHttpsOption = typeof dev === "object" && dev.https;
61
+ let nodeServer;
62
+ if (devHttpsOption) {
63
+ const { genHttpsOptions } = await Promise.resolve().then(() => __toESM(require("./dev-tools/https")));
64
+ const httpsOptions = await genHttpsOptions(devHttpsOption, pwd);
65
+ nodeServer = await (0, import_node.createNodeServer)(server.handle.bind(server), httpsOptions);
66
+ } else {
67
+ nodeServer = await (0, import_node.createNodeServer)(server.handle.bind(server));
68
+ }
61
69
  rsbuild === null || rsbuild === void 0 ? void 0 : rsbuild.onDevCompileDone(({ stats }) => {
62
70
  if (stats.toJson({
63
71
  all: false
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var https_exports = {};
20
+ __export(https_exports, {
21
+ genHttpsOptions: () => genHttpsOptions
22
+ });
23
+ module.exports = __toCommonJS(https_exports);
24
+ var import_utils = require("@modern-js/utils");
25
+ const genHttpsOptions = async (userOptions, pwd) => {
26
+ const httpsOptions = typeof userOptions === "boolean" ? {} : userOptions;
27
+ if (!httpsOptions.key || !httpsOptions.cert) {
28
+ let devcertPath;
29
+ try {
30
+ devcertPath = require.resolve("devcert", {
31
+ paths: [
32
+ pwd,
33
+ __dirname
34
+ ]
35
+ });
36
+ } catch (err) {
37
+ const packageManager = await (0, import_utils.getPackageManager)(pwd);
38
+ const command = import_utils.chalk.yellow.bold(`${packageManager} add devcert@1.2.2 -D`);
39
+ import_utils.logger.error(`You have enabled "dev.https" option, but the "devcert" package is not installed.`);
40
+ import_utils.logger.error(`Please run ${command} to install manually, otherwise the https can not work.`);
41
+ throw new Error('[https] "devcert" is not found.');
42
+ }
43
+ const devcert = require(devcertPath);
44
+ const selfsign = await devcert.certificateFor([
45
+ "localhost"
46
+ ]);
47
+ return selfsign;
48
+ }
49
+ return httpsOptions;
50
+ };
51
+ // Annotate the CommonJS export names for ESM import in node:
52
+ 0 && (module.exports = {
53
+ genHttpsOptions
54
+ });
@@ -9,7 +9,7 @@ import { API_DIR, SHARED_DIR } from "@modern-js/utils";
9
9
  import { startWatcher, onRepack, getDevOptions, initFileReader } from "./helpers";
10
10
  var createDevServer = function() {
11
11
  var _ref = _async_to_generator(function(options, initProdMiddlewares) {
12
- var config, pwd, _options_routes, routes, getMiddlewares, rsbuild, appContext, dev, distDir, apiDir, sharedDir, prodServerOptions, server, closeCb, _ref2, rsbuildMiddlewares, close, onHTTPUpgrade, nodeServer, watchOptions, watcher;
12
+ var config, pwd, _options_routes, routes, getMiddlewares, rsbuild, appContext, dev, distDir, apiDir, sharedDir, prodServerOptions, server, closeCb, _ref2, rsbuildMiddlewares, close, onHTTPUpgrade, devHttpsOption, nodeServer, genHttpsOptions, httpsOptions, watchOptions, watcher;
13
13
  return _ts_generator(this, function(_state) {
14
14
  switch (_state.label) {
15
15
  case 0:
@@ -42,7 +42,43 @@ var createDevServer = function() {
42
42
  ];
43
43
  case 2:
44
44
  _state.sent();
45
- nodeServer = createNodeServer(server.handle.bind(server));
45
+ devHttpsOption = typeof dev === "object" && dev.https;
46
+ if (!devHttpsOption)
47
+ return [
48
+ 3,
49
+ 6
50
+ ];
51
+ return [
52
+ 4,
53
+ import("./dev-tools/https")
54
+ ];
55
+ case 3:
56
+ genHttpsOptions = _state.sent().genHttpsOptions;
57
+ return [
58
+ 4,
59
+ genHttpsOptions(devHttpsOption, pwd)
60
+ ];
61
+ case 4:
62
+ httpsOptions = _state.sent();
63
+ return [
64
+ 4,
65
+ createNodeServer(server.handle.bind(server), httpsOptions)
66
+ ];
67
+ case 5:
68
+ nodeServer = _state.sent();
69
+ return [
70
+ 3,
71
+ 8
72
+ ];
73
+ case 6:
74
+ return [
75
+ 4,
76
+ createNodeServer(server.handle.bind(server))
77
+ ];
78
+ case 7:
79
+ nodeServer = _state.sent();
80
+ _state.label = 8;
81
+ case 8:
46
82
  rsbuild === null || rsbuild === void 0 ? void 0 : rsbuild.onDevCompileDone(function(param) {
47
83
  var stats = param.stats;
48
84
  if (stats.toJson({
@@ -58,13 +94,13 @@ var createDevServer = function() {
58
94
  app: nodeServer
59
95
  })
60
96
  ];
61
- case 3:
97
+ case 9:
62
98
  _state.sent();
63
99
  return [
64
100
  4,
65
101
  initProdMiddlewares(server, prodServerOptions)
66
102
  ];
67
- case 4:
103
+ case 10:
68
104
  _state.sent();
69
105
  if (dev.watch) {
70
106
  watchOptions = config.server.watchOptions;
@@ -0,0 +1,74 @@
1
+ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
3
+ import { chalk, getPackageManager, logger } from "@modern-js/utils";
4
+ var genHttpsOptions = function() {
5
+ var _ref = _async_to_generator(function(userOptions, pwd) {
6
+ var httpsOptions, devcertPath, err, packageManager, command, devcert, selfsign;
7
+ return _ts_generator(this, function(_state) {
8
+ switch (_state.label) {
9
+ case 0:
10
+ httpsOptions = typeof userOptions === "boolean" ? {} : userOptions;
11
+ if (!(!httpsOptions.key || !httpsOptions.cert))
12
+ return [
13
+ 3,
14
+ 6
15
+ ];
16
+ _state.label = 1;
17
+ case 1:
18
+ _state.trys.push([
19
+ 1,
20
+ 2,
21
+ ,
22
+ 4
23
+ ]);
24
+ devcertPath = require.resolve("devcert", {
25
+ paths: [
26
+ pwd,
27
+ __dirname
28
+ ]
29
+ });
30
+ return [
31
+ 3,
32
+ 4
33
+ ];
34
+ case 2:
35
+ err = _state.sent();
36
+ return [
37
+ 4,
38
+ getPackageManager(pwd)
39
+ ];
40
+ case 3:
41
+ packageManager = _state.sent();
42
+ command = chalk.yellow.bold("".concat(packageManager, " add devcert@1.2.2 -D"));
43
+ logger.error('You have enabled "dev.https" option, but the "devcert" package is not installed.');
44
+ logger.error("Please run ".concat(command, " to install manually, otherwise the https can not work."));
45
+ throw new Error('[https] "devcert" is not found.');
46
+ case 4:
47
+ devcert = require(devcertPath);
48
+ return [
49
+ 4,
50
+ devcert.certificateFor([
51
+ "localhost"
52
+ ])
53
+ ];
54
+ case 5:
55
+ selfsign = _state.sent();
56
+ return [
57
+ 2,
58
+ selfsign
59
+ ];
60
+ case 6:
61
+ return [
62
+ 2,
63
+ httpsOptions
64
+ ];
65
+ }
66
+ });
67
+ });
68
+ return function genHttpsOptions2(userOptions, pwd) {
69
+ return _ref.apply(this, arguments);
70
+ };
71
+ }();
72
+ export {
73
+ genHttpsOptions
74
+ };
@@ -24,7 +24,15 @@ const createDevServer = async (options, initProdMiddlewares) => {
24
24
  });
25
25
  server.use("*", initFileReader());
26
26
  await server.init();
27
- const nodeServer = createNodeServer(server.handle.bind(server));
27
+ const devHttpsOption = typeof dev === "object" && dev.https;
28
+ let nodeServer;
29
+ if (devHttpsOption) {
30
+ const { genHttpsOptions } = await import("./dev-tools/https");
31
+ const httpsOptions = await genHttpsOptions(devHttpsOption, pwd);
32
+ nodeServer = await createNodeServer(server.handle.bind(server), httpsOptions);
33
+ } else {
34
+ nodeServer = await createNodeServer(server.handle.bind(server));
35
+ }
28
36
  rsbuild === null || rsbuild === void 0 ? void 0 : rsbuild.onDevCompileDone(({ stats }) => {
29
37
  if (stats.toJson({
30
38
  all: false
@@ -0,0 +1,30 @@
1
+ import { chalk, getPackageManager, logger } from "@modern-js/utils";
2
+ const genHttpsOptions = async (userOptions, pwd) => {
3
+ const httpsOptions = typeof userOptions === "boolean" ? {} : userOptions;
4
+ if (!httpsOptions.key || !httpsOptions.cert) {
5
+ let devcertPath;
6
+ try {
7
+ devcertPath = require.resolve("devcert", {
8
+ paths: [
9
+ pwd,
10
+ __dirname
11
+ ]
12
+ });
13
+ } catch (err) {
14
+ const packageManager = await getPackageManager(pwd);
15
+ const command = chalk.yellow.bold(`${packageManager} add devcert@1.2.2 -D`);
16
+ logger.error(`You have enabled "dev.https" option, but the "devcert" package is not installed.`);
17
+ logger.error(`Please run ${command} to install manually, otherwise the https can not work.`);
18
+ throw new Error('[https] "devcert" is not found.');
19
+ }
20
+ const devcert = require(devcertPath);
21
+ const selfsign = await devcert.certificateFor([
22
+ "localhost"
23
+ ]);
24
+ return selfsign;
25
+ }
26
+ return httpsOptions;
27
+ };
28
+ export {
29
+ genHttpsOptions
30
+ };
@@ -0,0 +1,7 @@
1
+ /// <reference types="node" />
2
+ import type Buffer from 'buffer';
3
+ import type { DevServerHttpsOptions } from '../../types';
4
+ export declare const genHttpsOptions: (userOptions: DevServerHttpsOptions, pwd: string) => Promise<{
5
+ key?: Buffer | string;
6
+ cert?: Buffer | string;
7
+ }>;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.49.3",
18
+ "version": "2.49.4",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -48,14 +48,14 @@
48
48
  "minimatch": "^3.0.4",
49
49
  "path-to-regexp": "^6.2.0",
50
50
  "ws": "^8.13.0",
51
- "@modern-js/runtime-utils": "2.49.3",
52
- "@modern-js/server-utils": "2.49.3",
53
- "@modern-js/types": "2.49.3",
54
- "@modern-js/utils": "2.49.3",
55
- "@modern-js/server-core": "2.49.3"
51
+ "@modern-js/server-utils": "2.49.4",
52
+ "@modern-js/runtime-utils": "2.49.4",
53
+ "@modern-js/types": "2.49.4",
54
+ "@modern-js/utils": "2.49.4",
55
+ "@modern-js/server-core": "2.49.4"
56
56
  },
57
57
  "devDependencies": {
58
- "@rsbuild/shared": "0.6.11",
58
+ "@rsbuild/shared": "0.6.15",
59
59
  "@types/connect-history-api-fallback": "^1.3.5",
60
60
  "@types/jest": "^29",
61
61
  "@types/minimatch": "^3.0.5",
@@ -68,8 +68,8 @@
68
68
  "typescript": "^5",
69
69
  "webpack": "^5.91.0",
70
70
  "websocket": "^1",
71
- "@scripts/build": "2.49.3",
72
- "@scripts/jest-config": "2.49.3"
71
+ "@scripts/build": "2.49.4",
72
+ "@scripts/jest-config": "2.49.4"
73
73
  },
74
74
  "peerDependencies": {
75
75
  "devcert": "^1.2.2",