@modern-js/server 2.56.2 → 2.57.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.
@@ -37,9 +37,10 @@ var import_node = require("@modern-js/server-core/node");
37
37
  var import_helpers = require("./helpers");
38
38
  var import_dev = require("./dev");
39
39
  async function createDevServer(options, applyPlugins) {
40
- const { config, pwd, serverConfigFile, serverConfigPath } = options;
40
+ var _config_output_distPath;
41
+ const { config, pwd, serverConfigFile, serverConfigPath, builder } = options;
41
42
  const dev = (0, import_helpers.getDevOptions)(options);
42
- const distDir = import_node_path.default.resolve(pwd, config.output.path || "dist");
43
+ const distDir = import_node_path.default.resolve(pwd, ((_config_output_distPath = config.output.distPath) === null || _config_output_distPath === void 0 ? void 0 : _config_output_distPath.root) || "dist");
43
44
  const serverConfig = (0, import_node.loadServerRuntimeConfig)(distDir, serverConfigFile, serverConfigPath);
44
45
  const prodServerOptions = {
45
46
  ...options,
@@ -58,20 +59,24 @@ async function createDevServer(options, applyPlugins) {
58
59
  } else {
59
60
  nodeServer = await (0, import_node.createNodeServer)(server.handle.bind(server));
60
61
  }
62
+ const builderDevServer = await (builder === null || builder === void 0 ? void 0 : builder.createDevServer({
63
+ runCompile: options.runCompile
64
+ }));
61
65
  server.addPlugins([
62
- (0, import_dev.devPlugin)(options)
66
+ (0, import_dev.devPlugin)({
67
+ ...options,
68
+ builderDevServer
69
+ })
63
70
  ]);
64
71
  await applyPlugins(server, prodServerOptions, nodeServer);
65
72
  await server.init();
66
- nodeServer.listen({
67
- host: dev.host || "127.0.0.1",
68
- port: dev.port || "8080"
69
- }, (err) => {
70
- if (err) {
71
- throw err;
72
- }
73
- });
74
- return nodeServer;
73
+ const afterListen = async () => {
74
+ await (builderDevServer === null || builderDevServer === void 0 ? void 0 : builderDevServer.afterListen());
75
+ };
76
+ return {
77
+ server: nodeServer,
78
+ afterListen
79
+ };
75
80
  }
76
81
  // Annotate the CommonJS export names for ESM import in node:
77
82
  0 && (module.exports = {
package/dist/cjs/dev.js CHANGED
@@ -27,15 +27,12 @@ var import_helpers = require("./helpers");
27
27
  const devPlugin = (options) => ({
28
28
  name: "@modern-js/plugin-dev",
29
29
  setup(api) {
30
- const { config, pwd, builder } = options;
30
+ const { config, pwd, builder, builderDevServer } = options;
31
31
  const closeCb = [];
32
32
  const dev = (0, import_helpers.getDevOptions)(options);
33
33
  return {
34
34
  async prepare() {
35
35
  var _dev_after, _dev_before;
36
- const builderDevServer = await (builder === null || builder === void 0 ? void 0 : builder.createDevServer({
37
- runCompile: options.runCompile
38
- }));
39
36
  const { middlewares: builderMiddlewares, close, onHTTPUpgrade } = builderDevServer || {};
40
37
  close && closeCb.push(close);
41
38
  const { middlewares, distDirectory, nodeServer, apiDirectory, sharedDirectory, serverBase } = api.useAppContext();
@@ -12,13 +12,13 @@ function createDevServer(options, applyPlugins) {
12
12
  }
13
13
  function _createDevServer() {
14
14
  _createDevServer = _async_to_generator(function(options, applyPlugins) {
15
- var config, pwd, serverConfigFile, serverConfigPath, dev, distDir, serverConfig, prodServerOptions, server, devHttpsOption, nodeServer, genHttpsOptions, httpsOptions;
15
+ var _config_output_distPath, config, pwd, serverConfigFile, serverConfigPath, builder, dev, distDir, serverConfig, prodServerOptions, server, devHttpsOption, nodeServer, genHttpsOptions, httpsOptions, builderDevServer, afterListen;
16
16
  return _ts_generator(this, function(_state) {
17
17
  switch (_state.label) {
18
18
  case 0:
19
- config = options.config, pwd = options.pwd, serverConfigFile = options.serverConfigFile, serverConfigPath = options.serverConfigPath;
19
+ config = options.config, pwd = options.pwd, serverConfigFile = options.serverConfigFile, serverConfigPath = options.serverConfigPath, builder = options.builder;
20
20
  dev = getDevOptions(options);
21
- distDir = path.resolve(pwd, config.output.path || "dist");
21
+ distDir = path.resolve(pwd, ((_config_output_distPath = config.output.distPath) === null || _config_output_distPath === void 0 ? void 0 : _config_output_distPath.root) || "dist");
22
22
  serverConfig = loadServerRuntimeConfig(distDir, serverConfigFile, serverConfigPath);
23
23
  prodServerOptions = _object_spread_props(_object_spread({}, options), {
24
24
  pwd: distDir
@@ -64,32 +64,58 @@ function _createDevServer() {
64
64
  nodeServer = _state.sent();
65
65
  _state.label = 6;
66
66
  case 6:
67
+ return [
68
+ 4,
69
+ builder === null || builder === void 0 ? void 0 : builder.createDevServer({
70
+ runCompile: options.runCompile
71
+ })
72
+ ];
73
+ case 7:
74
+ builderDevServer = _state.sent();
67
75
  server.addPlugins([
68
- devPlugin(options)
76
+ devPlugin(_object_spread_props(_object_spread({}, options), {
77
+ builderDevServer
78
+ }))
69
79
  ]);
70
80
  return [
71
81
  4,
72
82
  applyPlugins(server, prodServerOptions, nodeServer)
73
83
  ];
74
- case 7:
84
+ case 8:
75
85
  _state.sent();
76
86
  return [
77
87
  4,
78
88
  server.init()
79
89
  ];
80
- case 8:
90
+ case 9:
81
91
  _state.sent();
82
- nodeServer.listen({
83
- host: dev.host || "127.0.0.1",
84
- port: dev.port || "8080"
85
- }, function(err) {
86
- if (err) {
87
- throw err;
88
- }
89
- });
92
+ afterListen = function() {
93
+ var _ref = _async_to_generator(function() {
94
+ return _ts_generator(this, function(_state2) {
95
+ switch (_state2.label) {
96
+ case 0:
97
+ return [
98
+ 4,
99
+ builderDevServer === null || builderDevServer === void 0 ? void 0 : builderDevServer.afterListen()
100
+ ];
101
+ case 1:
102
+ _state2.sent();
103
+ return [
104
+ 2
105
+ ];
106
+ }
107
+ });
108
+ });
109
+ return function afterListen2() {
110
+ return _ref.apply(this, arguments);
111
+ };
112
+ }();
90
113
  return [
91
114
  2,
92
- nodeServer
115
+ {
116
+ server: nodeServer,
117
+ afterListen
118
+ }
93
119
  ];
94
120
  }
95
121
  });
package/dist/esm/dev.js CHANGED
@@ -8,24 +8,16 @@ var devPlugin = function(options) {
8
8
  return {
9
9
  name: "@modern-js/plugin-dev",
10
10
  setup: function setup(api) {
11
- var config = options.config, pwd = options.pwd, builder = options.builder;
11
+ var config = options.config, pwd = options.pwd, builder = options.builder, builderDevServer = options.builderDevServer;
12
12
  var closeCb = [];
13
13
  var dev = getDevOptions(options);
14
14
  return {
15
15
  prepare: function prepare() {
16
16
  return _async_to_generator(function() {
17
- var _dev_after, _dev_before, builderDevServer, _ref, builderMiddlewares, close, onHTTPUpgrade, _api_useAppContext, middlewares, distDirectory, nodeServer, apiDirectory, sharedDirectory, serverBase, runner, watchOptions, watcher, before, after, _dev_setupMiddlewares, setupMiddlewares, mockMiddleware;
17
+ var _dev_after, _dev_before, _ref, builderMiddlewares, close, onHTTPUpgrade, _api_useAppContext, middlewares, distDirectory, nodeServer, apiDirectory, sharedDirectory, serverBase, runner, watchOptions, watcher, before, after, _dev_setupMiddlewares, setupMiddlewares, mockMiddleware;
18
18
  return _ts_generator(this, function(_state) {
19
19
  switch (_state.label) {
20
20
  case 0:
21
- return [
22
- 4,
23
- builder === null || builder === void 0 ? void 0 : builder.createDevServer({
24
- runCompile: options.runCompile
25
- })
26
- ];
27
- case 1:
28
- builderDevServer = _state.sent();
29
21
  _ref = builderDevServer || {}, builderMiddlewares = _ref.middlewares, close = _ref.close, onHTTPUpgrade = _ref.onHTTPUpgrade;
30
22
  close && closeCb.push(close);
31
23
  _api_useAppContext = api.useAppContext(), middlewares = _api_useAppContext.middlewares, distDirectory = _api_useAppContext.distDirectory, nodeServer = _api_useAppContext.nodeServer, apiDirectory = _api_useAppContext.apiDirectory, sharedDirectory = _api_useAppContext.sharedDirectory, serverBase = _api_useAppContext.serverBase;
@@ -96,7 +88,7 @@ var devPlugin = function(options) {
96
88
  4,
97
89
  getMockMiddleware(pwd)
98
90
  ];
99
- case 2:
91
+ case 1:
100
92
  mockMiddleware = _state.sent();
101
93
  middlewares.push({
102
94
  name: "mock-dev",
@@ -4,9 +4,10 @@ import { createNodeServer, loadServerRuntimeConfig } from "@modern-js/server-cor
4
4
  import { getDevOptions } from "./helpers";
5
5
  import { devPlugin } from "./dev";
6
6
  async function createDevServer(options, applyPlugins) {
7
- const { config, pwd, serverConfigFile, serverConfigPath } = options;
7
+ var _config_output_distPath;
8
+ const { config, pwd, serverConfigFile, serverConfigPath, builder } = options;
8
9
  const dev = getDevOptions(options);
9
- const distDir = path.resolve(pwd, config.output.path || "dist");
10
+ const distDir = path.resolve(pwd, ((_config_output_distPath = config.output.distPath) === null || _config_output_distPath === void 0 ? void 0 : _config_output_distPath.root) || "dist");
10
11
  const serverConfig = loadServerRuntimeConfig(distDir, serverConfigFile, serverConfigPath);
11
12
  const prodServerOptions = {
12
13
  ...options,
@@ -25,20 +26,24 @@ async function createDevServer(options, applyPlugins) {
25
26
  } else {
26
27
  nodeServer = await createNodeServer(server.handle.bind(server));
27
28
  }
29
+ const builderDevServer = await (builder === null || builder === void 0 ? void 0 : builder.createDevServer({
30
+ runCompile: options.runCompile
31
+ }));
28
32
  server.addPlugins([
29
- devPlugin(options)
33
+ devPlugin({
34
+ ...options,
35
+ builderDevServer
36
+ })
30
37
  ]);
31
38
  await applyPlugins(server, prodServerOptions, nodeServer);
32
39
  await server.init();
33
- nodeServer.listen({
34
- host: dev.host || "127.0.0.1",
35
- port: dev.port || "8080"
36
- }, (err) => {
37
- if (err) {
38
- throw err;
39
- }
40
- });
41
- return nodeServer;
40
+ const afterListen = async () => {
41
+ await (builderDevServer === null || builderDevServer === void 0 ? void 0 : builderDevServer.afterListen());
42
+ };
43
+ return {
44
+ server: nodeServer,
45
+ afterListen
46
+ };
42
47
  }
43
48
  export {
44
49
  createDevServer
@@ -4,15 +4,12 @@ import { startWatcher, onRepack, getDevOptions, initFileReader, getMockMiddlewar
4
4
  const devPlugin = (options) => ({
5
5
  name: "@modern-js/plugin-dev",
6
6
  setup(api) {
7
- const { config, pwd, builder } = options;
7
+ const { config, pwd, builder, builderDevServer } = options;
8
8
  const closeCb = [];
9
9
  const dev = getDevOptions(options);
10
10
  return {
11
11
  async prepare() {
12
12
  var _dev_after, _dev_before;
13
- const builderDevServer = await (builder === null || builder === void 0 ? void 0 : builder.createDevServer({
14
- runCompile: options.runCompile
15
- }));
16
13
  const { middlewares: builderMiddlewares, close, onHTTPUpgrade } = builderDevServer || {};
17
14
  close && closeCb.push(close);
18
15
  const { middlewares, distDirectory, nodeServer, apiDirectory, sharedDirectory, serverBase } = api.useAppContext();
@@ -1,7 +1,10 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
3
  import { ApplyPlugins, ModernDevServerOptions } from './types';
4
- export declare function createDevServer(options: ModernDevServerOptions, applyPlugins: ApplyPlugins): Promise<(import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | import("https").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>) & {
5
- getRequestListener: () => (req: import("http").IncomingMessage, res: import("http").ServerResponse) => Promise<void>;
6
- getRequestHandler: () => import("@modern-js/server-core/dist/types/types").RequestHandler;
4
+ export declare function createDevServer(options: ModernDevServerOptions, applyPlugins: ApplyPlugins): Promise<{
5
+ server: (import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse> | import("https").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>) & {
6
+ getRequestListener: () => (req: import("http").IncomingMessage, res: import("http").ServerResponse) => Promise<void>;
7
+ getRequestHandler: () => import("@modern-js/server-core/dist/types/types").RequestHandler;
8
+ };
9
+ afterListen: () => Promise<void>;
7
10
  }>;
@@ -1,3 +1,9 @@
1
1
  import { ServerPlugin, ServerBaseOptions } from '@modern-js/server-core';
2
+ import { UniBuilderInstance } from '@modern-js/uni-builder';
2
3
  import { ModernDevServerOptions } from './types';
3
- export declare const devPlugin: <O extends ServerBaseOptions>(options: ModernDevServerOptions<O>) => ServerPlugin;
4
+ type BuilderDevServer = Awaited<ReturnType<UniBuilderInstance['createDevServer']>>;
5
+ export type DevPluginOptions = ModernDevServerOptions<ServerBaseOptions> & {
6
+ builderDevServer?: BuilderDevServer;
7
+ };
8
+ export declare const devPlugin: (options: DevPluginOptions) => ServerPlugin;
9
+ export {};
@@ -1,2 +1,2 @@
1
1
  export { createDevServer } from './createDevServer';
2
- export type { ModernDevServerOptions } from './types';
2
+ export type { ModernDevServerOptions, ApplyPlugins } from './types';
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.56.2",
18
+ "version": "2.57.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -48,11 +48,11 @@
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.56.2",
52
- "@modern-js/server-utils": "2.56.2",
53
- "@modern-js/types": "2.56.2",
54
- "@modern-js/utils": "2.56.2",
55
- "@modern-js/server-core": "2.56.2"
51
+ "@modern-js/runtime-utils": "2.57.0",
52
+ "@modern-js/types": "2.57.0",
53
+ "@modern-js/utils": "2.57.0",
54
+ "@modern-js/server-core": "2.57.0",
55
+ "@modern-js/server-utils": "2.57.0"
56
56
  },
57
57
  "devDependencies": {
58
58
  "@types/connect-history-api-fallback": "^1.3.5",
@@ -67,9 +67,9 @@
67
67
  "typescript": "^5",
68
68
  "webpack": "^5.93.0",
69
69
  "websocket": "^1",
70
- "@modern-js/uni-builder": "2.56.2",
71
- "@scripts/jest-config": "2.56.2",
72
- "@scripts/build": "2.56.2"
70
+ "@modern-js/uni-builder": "2.57.0",
71
+ "@scripts/jest-config": "2.57.0",
72
+ "@scripts/build": "2.57.0"
73
73
  },
74
74
  "peerDependencies": {
75
75
  "devcert": "^1.2.2",