@modern-js/server 2.40.1-alpha.0 → 2.42.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 (31) hide show
  1. package/dist/cjs/dev-tools/dev-middleware/index.js +3 -2
  2. package/dist/cjs/dev-tools/dev-middleware/socketServer.js +3 -2
  3. package/dist/cjs/dev-tools/register/index.js +1 -5
  4. package/dist/cjs/dev-tools/watcher/index.js +3 -2
  5. package/dist/esm/dev-tools/dev-middleware/hmr-client/index.js +14 -14
  6. package/dist/esm/dev-tools/dev-middleware/index.js +2 -1
  7. package/dist/esm/dev-tools/dev-middleware/socketServer.js +2 -1
  8. package/dist/esm/dev-tools/register/index.js +0 -4
  9. package/dist/esm/dev-tools/watcher/index.js +2 -1
  10. package/dist/esm-node/dev-tools/dev-middleware/index.js +3 -2
  11. package/dist/esm-node/dev-tools/dev-middleware/socketServer.js +3 -2
  12. package/dist/esm-node/dev-tools/register/index.js +1 -5
  13. package/dist/esm-node/dev-tools/watcher/index.js +3 -2
  14. package/dist/types/constants.d.ts +1 -1
  15. package/dist/types/dev-tools/dev-middleware/hmr-client/createSocketUrl.d.ts +6 -11
  16. package/dist/types/dev-tools/dev-middleware/hmr-client/index.d.ts +1 -1
  17. package/dist/types/dev-tools/dev-middleware/index.d.ts +10 -13
  18. package/dist/types/dev-tools/dev-middleware/socketServer.d.ts +17 -17
  19. package/dist/types/dev-tools/https/index.d.ts +3 -3
  20. package/dist/types/dev-tools/mock/getMockData.d.ts +5 -5
  21. package/dist/types/dev-tools/mock/index.d.ts +3 -5
  22. package/dist/types/dev-tools/register/index.d.ts +1 -1
  23. package/dist/types/dev-tools/watcher/dependencyTree.d.ts +17 -17
  24. package/dist/types/dev-tools/watcher/index.d.ts +10 -10
  25. package/dist/types/dev-tools/watcher/statsCache.d.ts +9 -9
  26. package/dist/types/index.d.ts +1 -1
  27. package/dist/types/server/devServer.d.ts +28 -31
  28. package/dist/types/server/index.d.ts +2 -2
  29. package/dist/types/server/workerSSRRender.d.ts +5 -5
  30. package/dist/types/types.d.ts +17 -17
  31. package/package.json +13 -13
@@ -44,7 +44,8 @@ function getHMRClientPath(client) {
44
44
  const clientEntry = `${require.resolve("@modern-js/server/hmr-client")}?${host}${path}${port}${protocol}`;
45
45
  return clientEntry;
46
46
  }
47
- class DevMiddleware extends import_events.EventEmitter {
47
+ var DevMiddleware;
48
+ DevMiddleware = class DevMiddleware2 extends import_events.EventEmitter {
48
49
  init(app) {
49
50
  app.on("listening", () => {
50
51
  this.socketServer.prepare(app);
@@ -91,4 +92,4 @@ class DevMiddleware extends import_events.EventEmitter {
91
92
  this.middleware = this.setupDevMiddleware(devMiddleware);
92
93
  }
93
94
  }
94
- }
95
+ };
@@ -34,7 +34,8 @@ module.exports = __toCommonJS(socketServer_exports);
34
34
  var import_define_property = require("@swc/helpers/_/_define_property");
35
35
  var import_ws = __toESM(require("ws"));
36
36
  var import_utils = require("@modern-js/utils");
37
- class SocketServer {
37
+ var SocketServer;
38
+ SocketServer = class SocketServer2 {
38
39
  // create socket, install socket handler, bind socket event
39
40
  prepare(app) {
40
41
  var _this_options_client;
@@ -175,4 +176,4 @@ class SocketServer {
175
176
  (0, import_define_property._)(this, "timer", null);
176
177
  this.options = options;
177
178
  }
178
- }
179
+ };
@@ -53,11 +53,7 @@ const enableRegister = (projectRoot, config) => {
53
53
  "./shared"
54
54
  ];
55
55
  const TS_CONFIG_FILENAME = `tsconfig.json`;
56
- let tsconfigPath = import_path.default.resolve(projectRoot, TS_CONFIG_FILENAME);
57
- const serverTsconfigPath = import_path.default.resolve(projectRoot, "tsconfig.server.json");
58
- if (import_utils.fs.existsSync(serverTsconfigPath)) {
59
- tsconfigPath = serverTsconfigPath;
60
- }
56
+ const tsconfigPath = import_path.default.resolve(projectRoot, TS_CONFIG_FILENAME);
61
57
  const isTsProject = import_utils.fs.existsSync(tsconfigPath);
62
58
  const existTsNode = checkDep("ts-node", [
63
59
  projectRoot
@@ -76,7 +76,8 @@ const mergeWatchOptions = (options) => {
76
76
  };
77
77
  return finalWatchOptions;
78
78
  };
79
- class Watcher {
79
+ var Watcher;
80
+ Watcher = class Watcher2 {
80
81
  listen(files, options, callback) {
81
82
  const watched = files.filter(Boolean);
82
83
  const filenames = watched.map((filename) => filename.replace(/\\/g, "/"));
@@ -129,7 +130,7 @@ class Watcher {
129
130
  (0, import_define_property._)(this, "dependencyTree", null);
130
131
  (0, import_define_property._)(this, "watcher", void 0);
131
132
  }
132
- }
133
+ };
133
134
  // Annotate the CommonJS export names for ESM import in node:
134
135
  0 && (module.exports = {
135
136
  defaultWatchOptions,
@@ -40,7 +40,11 @@ var require_hmr_client = __commonJS({
40
40
  }
41
41
  }
42
42
  function handleWarnings(warnings) {
43
- var printWarnings = function printWarnings2() {
43
+ clearOutdatedErrors();
44
+ var isHotUpdate = !isFirstCompilation;
45
+ isFirstCompilation = false;
46
+ hasCompileErrors = false;
47
+ function printWarnings() {
44
48
  var formatted = formatWebpackMessages({
45
49
  warnings,
46
50
  errors: []
@@ -54,11 +58,7 @@ var require_hmr_client = __commonJS({
54
58
  console.warn(stripAnsi(formatted.warnings[i]));
55
59
  }
56
60
  }
57
- };
58
- clearOutdatedErrors();
59
- var isHotUpdate = !isFirstCompilation;
60
- isFirstCompilation = false;
61
- hasCompileErrors = false;
61
+ }
62
62
  printWarnings();
63
63
  if (isHotUpdate) {
64
64
  tryApplyUpdates();
@@ -127,7 +127,14 @@ var require_hmr_client = __commonJS({
127
127
  return module.hot.status() === "idle";
128
128
  }
129
129
  function tryApplyUpdates() {
130
- var handleApplyUpdates = function handleApplyUpdates2(err, updatedModules) {
130
+ if (!module.hot) {
131
+ window.location.reload();
132
+ return;
133
+ }
134
+ if (!isUpdateAvailable() || !canApplyUpdates()) {
135
+ return;
136
+ }
137
+ function handleApplyUpdates(err, updatedModules) {
131
138
  var wantsForcedReload = err || !updatedModules || hadRuntimeError;
132
139
  if (wantsForcedReload) {
133
140
  window.location.reload();
@@ -136,13 +143,6 @@ var require_hmr_client = __commonJS({
136
143
  if (isUpdateAvailable()) {
137
144
  tryApplyUpdates();
138
145
  }
139
- };
140
- if (!module.hot) {
141
- window.location.reload();
142
- return;
143
- }
144
- if (!isUpdateAvailable() || !canApplyUpdates()) {
145
- return;
146
146
  }
147
147
  var result = module.hot.check(
148
148
  /* autoApply */
@@ -19,7 +19,8 @@ function getHMRClientPath(client) {
19
19
  var clientEntry = "".concat(require.resolve("@modern-js/server/hmr-client"), "?").concat(host).concat(path).concat(port).concat(protocol);
20
20
  return clientEntry;
21
21
  }
22
- var DevMiddleware = /* @__PURE__ */ function(EventEmitter2) {
22
+ var DevMiddleware;
23
+ DevMiddleware = /* @__PURE__ */ function(EventEmitter2) {
23
24
  "use strict";
24
25
  _inherits(DevMiddleware2, EventEmitter2);
25
26
  var _super = _create_super(DevMiddleware2);
@@ -3,7 +3,8 @@ import { _ as _create_class } from "@swc/helpers/_/_create_class";
3
3
  import { _ as _define_property } from "@swc/helpers/_/_define_property";
4
4
  import ws from "ws";
5
5
  import { logger } from "@modern-js/utils";
6
- var SocketServer = /* @__PURE__ */ function() {
6
+ var SocketServer;
7
+ SocketServer = /* @__PURE__ */ function() {
7
8
  "use strict";
8
9
  function SocketServer2(options) {
9
10
  _class_call_check(this, SocketServer2);
@@ -24,10 +24,6 @@ var enableRegister = function(projectRoot, config) {
24
24
  ];
25
25
  var TS_CONFIG_FILENAME = "tsconfig.json";
26
26
  var tsconfigPath = path.resolve(projectRoot, TS_CONFIG_FILENAME);
27
- var serverTsconfigPath = path.resolve(projectRoot, "tsconfig.server.json");
28
- if (fs.existsSync(serverTsconfigPath)) {
29
- tsconfigPath = serverTsconfigPath;
30
- }
31
27
  var isTsProject = fs.existsSync(tsconfigPath);
32
28
  var existTsNode = checkDep("ts-node", [
33
29
  projectRoot
@@ -38,7 +38,8 @@ var mergeWatchOptions = function(options) {
38
38
  var finalWatchOptions = _object_spread({}, defaultWatchOptions, watchOptions);
39
39
  return finalWatchOptions;
40
40
  };
41
- var Watcher = /* @__PURE__ */ function() {
41
+ var Watcher;
42
+ Watcher = /* @__PURE__ */ function() {
42
43
  "use strict";
43
44
  function Watcher2() {
44
45
  _class_call_check(this, Watcher2);
@@ -11,7 +11,8 @@ function getHMRClientPath(client) {
11
11
  const clientEntry = `${require.resolve("@modern-js/server/hmr-client")}?${host}${path}${port}${protocol}`;
12
12
  return clientEntry;
13
13
  }
14
- class DevMiddleware extends EventEmitter {
14
+ var DevMiddleware;
15
+ DevMiddleware = class DevMiddleware2 extends EventEmitter {
15
16
  init(app) {
16
17
  app.on("listening", () => {
17
18
  this.socketServer.prepare(app);
@@ -58,7 +59,7 @@ class DevMiddleware extends EventEmitter {
58
59
  this.middleware = this.setupDevMiddleware(devMiddleware);
59
60
  }
60
61
  }
61
- }
62
+ };
62
63
  export {
63
64
  DevMiddleware as default
64
65
  };
@@ -1,7 +1,8 @@
1
1
  import { _ as _define_property } from "@swc/helpers/_/_define_property";
2
2
  import ws from "ws";
3
3
  import { logger } from "@modern-js/utils";
4
- class SocketServer {
4
+ var SocketServer;
5
+ SocketServer = class SocketServer2 {
5
6
  // create socket, install socket handler, bind socket event
6
7
  prepare(app) {
7
8
  var _this_options_client;
@@ -142,7 +143,7 @@ class SocketServer {
142
143
  _define_property(this, "timer", null);
143
144
  this.options = options;
144
145
  }
145
- }
146
+ };
146
147
  export {
147
148
  SocketServer as default
148
149
  };
@@ -20,11 +20,7 @@ const enableRegister = (projectRoot, config) => {
20
20
  "./shared"
21
21
  ];
22
22
  const TS_CONFIG_FILENAME = `tsconfig.json`;
23
- let tsconfigPath = path.resolve(projectRoot, TS_CONFIG_FILENAME);
24
- const serverTsconfigPath = path.resolve(projectRoot, "tsconfig.server.json");
25
- if (fs.existsSync(serverTsconfigPath)) {
26
- tsconfigPath = serverTsconfigPath;
27
- }
23
+ const tsconfigPath = path.resolve(projectRoot, TS_CONFIG_FILENAME);
28
24
  const isTsProject = fs.existsSync(tsconfigPath);
29
25
  const existTsNode = checkDep("ts-node", [
30
26
  projectRoot
@@ -40,7 +40,8 @@ const mergeWatchOptions = (options) => {
40
40
  };
41
41
  return finalWatchOptions;
42
42
  };
43
- class Watcher {
43
+ var Watcher;
44
+ Watcher = class Watcher2 {
44
45
  listen(files, options, callback) {
45
46
  const watched = files.filter(Boolean);
46
47
  const filenames = watched.map((filename) => filename.replace(/\\/g, "/"));
@@ -93,7 +94,7 @@ class Watcher {
93
94
  _define_property(this, "dependencyTree", null);
94
95
  _define_property(this, "watcher", void 0);
95
96
  }
96
- }
97
+ };
97
98
  export {
98
99
  Watcher as default,
99
100
  defaultWatchOptions,
@@ -1,2 +1,2 @@
1
1
  import { DevServerOptions } from './types';
2
- export declare const getDefaultDevOptions: () => DevServerOptions;
2
+ export declare const getDefaultDevOptions: () => DevServerOptions;
@@ -1,12 +1,7 @@
1
1
  export declare function createSocketUrl(resourceQuery: string): string;
2
- export declare function formatURL({
3
- port,
4
- protocol,
5
- hostname,
6
- pathname
7
- }: {
8
- port: string;
9
- protocol: string;
10
- hostname: string;
11
- pathname: string;
12
- }): string;
2
+ export declare function formatURL({ port, protocol, hostname, pathname, }: {
3
+ port: string;
4
+ protocol: string;
5
+ hostname: string;
6
+ pathname: string;
7
+ }): string;
@@ -1 +1 @@
1
- export {};
1
+ export {};
@@ -4,19 +4,16 @@ import { Server } from 'http';
4
4
  import { EventEmitter } from 'events';
5
5
  import { DevServerOptions, DevMiddlewareAPI, DevMiddleware as CustomDevMiddleware } from '../../types';
6
6
  type Options = {
7
- dev: DevServerOptions;
8
- devMiddleware?: CustomDevMiddleware;
7
+ dev: DevServerOptions;
8
+ devMiddleware?: CustomDevMiddleware;
9
9
  };
10
10
  export default class DevMiddleware extends EventEmitter {
11
- middleware?: DevMiddlewareAPI;
12
- private devOptions;
13
- private socketServer;
14
- constructor({
15
- dev,
16
- devMiddleware
17
- }: Options);
18
- init(app: Server): void;
19
- sockWrite(type: string, data?: Record<string, any> | string | boolean): void;
20
- private setupDevMiddleware;
11
+ middleware?: DevMiddlewareAPI;
12
+ private devOptions;
13
+ private socketServer;
14
+ constructor({ dev, devMiddleware }: Options);
15
+ init(app: Server): void;
16
+ sockWrite(type: string, data?: Record<string, any> | string | boolean): void;
17
+ private setupDevMiddleware;
21
18
  }
22
- export {};
19
+ export {};
@@ -4,20 +4,20 @@ import ws from 'ws';
4
4
  import type webpack from 'webpack';
5
5
  import type { DevServerOptions } from '../../types';
6
6
  export default class SocketServer {
7
- private wsServer;
8
- private readonly sockets;
9
- private readonly options;
10
- private app?;
11
- private stats?;
12
- private timer;
13
- constructor(options: DevServerOptions);
14
- prepare(app: Server): void;
15
- updateStats(stats: webpack.Stats): void;
16
- sockWrite(type: string, data?: Record<string, any> | string | boolean): void;
17
- singleWrite(socket: ws, type: string, data?: Record<string, any> | string | boolean): void;
18
- close(): void;
19
- private onConnect;
20
- private getStats;
21
- private sendStats;
22
- private send;
23
- }
7
+ private wsServer;
8
+ private readonly sockets;
9
+ private readonly options;
10
+ private app?;
11
+ private stats?;
12
+ private timer;
13
+ constructor(options: DevServerOptions);
14
+ prepare(app: Server): void;
15
+ updateStats(stats: webpack.Stats): void;
16
+ sockWrite(type: string, data?: Record<string, any> | string | boolean): void;
17
+ singleWrite(socket: ws, type: string, data?: Record<string, any> | string | boolean): void;
18
+ close(): void;
19
+ private onConnect;
20
+ private getStats;
21
+ private sendStats;
22
+ private send;
23
+ }
@@ -1,6 +1,6 @@
1
1
  import type Buffer from 'buffer';
2
2
  import type { DevServerHttpsOptions } from '../../types';
3
3
  export declare const genHttpsOptions: (userOptions: DevServerHttpsOptions, pwd: string) => Promise<{
4
- key?: Buffer | string;
5
- cert?: Buffer | string;
6
- }>;
4
+ key?: Buffer | string;
5
+ cert?: Buffer | string;
6
+ }>;
@@ -2,15 +2,15 @@
2
2
  import { IncomingMessage, ServerResponse } from 'http';
3
3
  import type { ModernServerContext, NextFunction } from '@modern-js/types';
4
4
  export type MockConfig = Record<string, {
5
- data: any;
5
+ data: any;
6
6
  } | ((req: IncomingMessage, res: ServerResponse, next: NextFunction) => Promise<void>)>;
7
7
  export type MockApi = {
8
- method: string;
9
- path: string;
10
- handler: ReturnType<typeof createFunctionDataHandler | typeof createStaticDataHandler>;
8
+ method: string;
9
+ path: string;
10
+ handler: ReturnType<typeof createFunctionDataHandler | typeof createStaticDataHandler>;
11
11
  };
12
12
  declare const createFunctionDataHandler: (method: string, handler: (req: IncomingMessage, res: ServerResponse, next: NextFunction) => void) => (context: ModernServerContext, next: NextFunction) => Promise<void>;
13
13
  declare const createStaticDataHandler: (method: string, handler: Record<string, any>) => (context: ModernServerContext) => void;
14
14
  declare const _default: (mockConfig: MockConfig) => MockApi[];
15
15
  export default _default;
16
- export declare const getMatched: (context: ModernServerContext, mockApiList: MockApi[]) => MockApi | undefined;
16
+ export declare const getMatched: (context: ModernServerContext, mockApiList: MockApi[]) => MockApi | undefined;
@@ -1,6 +1,4 @@
1
1
  import type { ModernServerContext, NextFunction } from '@modern-js/types';
2
- export declare const createMockHandler: ({
3
- pwd
4
- }: {
5
- pwd: string;
6
- }) => ((context: ModernServerContext, next: NextFunction) => Promise<void>) | null;
2
+ export declare const createMockHandler: ({ pwd }: {
3
+ pwd: string;
4
+ }) => ((context: ModernServerContext, next: NextFunction) => Promise<void>) | null;
@@ -1,2 +1,2 @@
1
1
  import { ModernServerOptions } from '@modern-js/prod-server';
2
- export declare const enableRegister: (projectRoot: string, config: ModernServerOptions['config']) => any;
2
+ export declare const enableRegister: (projectRoot: string, config: ModernServerOptions['config']) => any;
@@ -1,13 +1,13 @@
1
1
  /// <reference types="node" />
2
2
  export declare const defaultIgnores: string[];
3
3
  export interface DependencyTreeOptions {
4
- root: string;
5
- ignore?: string[];
4
+ root: string;
5
+ ignore?: string[];
6
6
  }
7
7
  export interface TreeNode {
8
- module: NodeModule;
9
- parent: Set<TreeNode>;
10
- children: Set<TreeNode>;
8
+ module: NodeModule;
9
+ parent: Set<TreeNode>;
10
+ children: Set<TreeNode>;
11
11
  }
12
12
  /**
13
13
  * `require.cache` already is a dependency tree, however require cache's
@@ -15,15 +15,15 @@ export interface TreeNode {
15
15
  * a new tree which revisit the cache tree to find all parent node
16
16
  */
17
17
  export declare class DependencyTree {
18
- private readonly tree;
19
- private readonly ignore;
20
- constructor();
21
- getNode(path: string): TreeNode | undefined;
22
- /**
23
- * update dependency tree
24
- *
25
- * @param cache
26
- */
27
- update(cache: any): void;
28
- private shouldIgnore;
29
- }
18
+ private readonly tree;
19
+ private readonly ignore;
20
+ constructor();
21
+ getNode(path: string): TreeNode | undefined;
22
+ /**
23
+ * update dependency tree
24
+ *
25
+ * @param cache
26
+ */
27
+ update(cache: any): void;
28
+ private shouldIgnore;
29
+ }
@@ -1,17 +1,17 @@
1
1
  import { FSWatcher, WatchOptions } from '@modern-js/utils';
2
2
  export type WatchEvent = 'add' | 'change' | 'unlink';
3
3
  export declare const defaultWatchOptions: {
4
- ignoreInitial: boolean;
5
- ignored: RegExp;
4
+ ignoreInitial: boolean;
5
+ ignored: RegExp;
6
6
  };
7
7
  export declare const getWatchedFiles: (watcher: FSWatcher) => string[];
8
8
  export declare const mergeWatchOptions: (options?: WatchOptions) => WatchOptions;
9
9
  export default class Watcher {
10
- private dependencyTree;
11
- private watcher;
12
- listen(files: string[], options: WatchOptions, callback: (changed: string, event: WatchEvent) => void): void;
13
- createDepTree(): void;
14
- updateDepTree(): void;
15
- cleanDepCache(filepath: string): void;
16
- close(): Promise<void>;
17
- }
10
+ private dependencyTree;
11
+ private watcher;
12
+ listen(files: string[], options: WatchOptions, callback: (changed: string, event: WatchEvent) => void): void;
13
+ createDepTree(): void;
14
+ updateDepTree(): void;
15
+ cleanDepCache(filepath: string): void;
16
+ close(): Promise<void>;
17
+ }
@@ -1,10 +1,10 @@
1
1
  export declare class StatsCache {
2
- private readonly cachedHash;
3
- private readonly cachedSize;
4
- add(files: string[]): void;
5
- refresh(filename: string): void;
6
- del(filename: string): void;
7
- isDiff(filename: string): boolean;
8
- has(filename: string): boolean;
9
- private hash;
10
- }
2
+ private readonly cachedHash;
3
+ private readonly cachedSize;
4
+ add(files: string[]): void;
5
+ refresh(filename: string): void;
6
+ del(filename: string): void;
7
+ isDiff(filename: string): boolean;
8
+ has(filename: string): boolean;
9
+ private hash;
10
+ }
@@ -3,4 +3,4 @@ import type { ModernDevServerOptions } from './types';
3
3
  export { Server };
4
4
  export type { ModernDevServerOptions };
5
5
  declare const _default: (options: ModernDevServerOptions) => Promise<Server>;
6
- export default _default;
6
+ export default _default;
@@ -7,34 +7,31 @@ import { RenderHandler } from '@modern-js/prod-server/src/libs/render';
7
7
  import { WatchEvent } from '../dev-tools/watcher';
8
8
  import type { ModernDevServerOptions } from '../types';
9
9
  export declare class ModernDevServer extends ModernServer {
10
- private mockHandler;
11
- private readonly dev;
12
- private readonly useWorkerSSR;
13
- private readonly appContext;
14
- private readonly devMiddleware;
15
- private watcher?;
16
- constructor(options: ModernDevServerOptions);
17
- private getDevOptions;
18
- private addMiddlewareHandler;
19
- private applySetupMiddlewares;
20
- onInit(runner: ServerHookRunner, app: Server): Promise<void>;
21
- getRenderHandler(): RenderHandler;
22
- private applyDefaultMiddlewares;
23
- onRepack(options?: BuildOptions): void;
24
- createHTTPServer(handler: (req: IncomingMessage, res: ServerResponse, next?: () => void) => void): Promise<Server<typeof IncomingMessage, typeof ServerResponse> | import("https").Server<typeof IncomingMessage, typeof ServerResponse>>;
25
- protected warmupSSRBundle(): void;
26
- protected initReader(): void;
27
- protected onServerChange({
28
- filepath,
29
- event
30
- }: {
31
- filepath: string;
32
- event: WatchEvent;
33
- }): Promise<void>;
34
- protected createContext(req: IncomingMessage, res: ServerResponse): import("@modern-js/prod-server/src/libs/context").ModernServerContext;
35
- protected setupStaticMiddleware(_: string): (context: ModernServerContext, next: NextFunction) => Promise<void>;
36
- private setupBeforeDevMiddleware;
37
- private setupAfterDevMiddleware;
38
- private cleanSSRCache;
39
- private startWatcher;
40
- }
10
+ private mockHandler;
11
+ private readonly dev;
12
+ private readonly useWorkerSSR;
13
+ private readonly appContext;
14
+ private readonly devMiddleware;
15
+ private watcher?;
16
+ constructor(options: ModernDevServerOptions);
17
+ private getDevOptions;
18
+ private addMiddlewareHandler;
19
+ private applySetupMiddlewares;
20
+ onInit(runner: ServerHookRunner, app: Server): Promise<void>;
21
+ getRenderHandler(): RenderHandler;
22
+ private applyDefaultMiddlewares;
23
+ onRepack(options?: BuildOptions): void;
24
+ createHTTPServer(handler: (req: IncomingMessage, res: ServerResponse, next?: () => void) => void): Promise<Server<typeof IncomingMessage, typeof ServerResponse> | import("https").Server<typeof IncomingMessage, typeof ServerResponse>>;
25
+ protected warmupSSRBundle(): void;
26
+ protected initReader(): void;
27
+ protected onServerChange({ filepath, event, }: {
28
+ filepath: string;
29
+ event: WatchEvent;
30
+ }): Promise<void>;
31
+ protected createContext(req: IncomingMessage, res: ServerResponse): import("@modern-js/prod-server/src/libs/context").ModernServerContext;
32
+ protected setupStaticMiddleware(_: string): (context: ModernServerContext, next: NextFunction) => Promise<void>;
33
+ private setupBeforeDevMiddleware;
34
+ private setupAfterDevMiddleware;
35
+ private cleanSSRCache;
36
+ private startWatcher;
37
+ }
@@ -1,5 +1,5 @@
1
1
  import { Server } from '@modern-js/prod-server';
2
2
  import type { ModernDevServerOptions } from '../types';
3
3
  export declare class DevServer extends Server {
4
- constructor(options: ModernDevServerOptions);
5
- }
4
+ constructor(options: ModernDevServerOptions);
5
+ }
@@ -1,9 +1,9 @@
1
1
  import { ServerHookRunner } from '@modern-js/prod-server';
2
2
  import { ModernServerContext } from '@modern-js/types/server';
3
3
  export declare function workerSSRRender(ctx: ModernServerContext, renderOptions: {
4
- urlPath: string;
5
- [props: string]: any;
4
+ urlPath: string;
5
+ [props: string]: any;
6
6
  }, _runner: ServerHookRunner): Promise<{
7
- content: any;
8
- contentType: string;
9
- }>;
7
+ content: any;
8
+ contentType: string;
9
+ }>;
@@ -5,23 +5,23 @@ import type { ModernServerOptions } from '@modern-js/prod-server';
5
5
  export type { DevServerOptions, DevServerHttpsOptions };
6
6
  type Middleware = (req: IncomingMessage, res: ServerResponse, next: NextFunction) => Promise<void>;
7
7
  export type DevMiddlewareAPI = Middleware & {
8
- close: (callback: (err: Error | null | undefined) => void) => any;
8
+ close: (callback: (err: Error | null | undefined) => void) => any;
9
9
  };
10
10
  export type MiddlewareCallbacks = {
11
- onInvalid: () => void;
12
- onDone: (stats: any) => void;
11
+ onInvalid: () => void;
12
+ onDone: (stats: any) => void;
13
13
  };
14
14
  export type DevMiddlewareOptions = {
15
- /** To ensure HMR works, the devMiddleware need inject the hmr client path into page when HMR enable. */
16
- hmrClientPath?: string;
17
- /** The options need by compiler middleware (like webpackMiddleware) */
18
- headers?: Record<string, string | string[]>;
19
- writeToDisk?: boolean | ((filename: string) => boolean);
20
- stats?: boolean;
21
- /** should trigger when compiler hook called */
22
- callbacks: MiddlewareCallbacks;
23
- /** whether use Server Side Render */
24
- serverSideRender?: boolean;
15
+ /** To ensure HMR works, the devMiddleware need inject the hmr client path into page when HMR enable. */
16
+ hmrClientPath?: string;
17
+ /** The options need by compiler middleware (like webpackMiddleware) */
18
+ headers?: Record<string, string | string[]>;
19
+ writeToDisk?: boolean | ((filename: string) => boolean);
20
+ stats?: boolean;
21
+ /** should trigger when compiler hook called */
22
+ callbacks: MiddlewareCallbacks;
23
+ /** whether use Server Side Render */
24
+ serverSideRender?: boolean;
25
25
  };
26
26
  /**
27
27
  * The modern/server do nothing about compiler, the devMiddleware need do such things to ensure dev works well:
@@ -31,8 +31,8 @@ export type DevMiddlewareOptions = {
31
31
  */
32
32
  export type DevMiddleware = (options: DevMiddlewareOptions) => DevMiddlewareAPI;
33
33
  export type ExtraOptions = {
34
- dev: boolean | Partial<DevServerOptions>;
35
- devMiddleware?: DevMiddleware;
36
- useWorkerSSR?: boolean;
34
+ dev: boolean | Partial<DevServerOptions>;
35
+ devMiddleware?: DevMiddleware;
36
+ useWorkerSSR?: boolean;
37
37
  };
38
- export type ModernDevServerOptions = ModernServerOptions & ExtraOptions;
38
+ export type ModernDevServerOptions = ModernServerOptions & ExtraOptions;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.40.1-alpha.0",
18
+ "version": "2.42.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -40,25 +40,25 @@
40
40
  "dependencies": {
41
41
  "@babel/core": "^7.23.2",
42
42
  "@babel/register": "^7.22.15",
43
- "@swc/helpers": "0.5.1",
43
+ "@swc/helpers": "0.5.3",
44
44
  "connect-history-api-fallback": "^2.0.0",
45
45
  "http-compression": "1.0.6",
46
46
  "minimatch": "^3.0.4",
47
47
  "path-to-regexp": "^6.2.0",
48
- "ws": "^8.2.0",
49
- "axios": "^1.2.1",
50
- "@modern-js/utils": "2.40.0",
51
- "@modern-js/runtime-utils": "2.40.0",
52
- "@modern-js/types": "2.40.0",
53
- "@modern-js/prod-server": "2.40.0",
54
- "@modern-js/server-utils": "2.40.0"
48
+ "ws": "^8.13.0",
49
+ "axios": "^1.6.0",
50
+ "@modern-js/server-utils": "2.42.0",
51
+ "@modern-js/types": "2.42.0",
52
+ "@modern-js/prod-server": "2.42.0",
53
+ "@modern-js/utils": "2.42.0",
54
+ "@modern-js/runtime-utils": "2.42.0"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@types/connect-history-api-fallback": "^1.3.5",
58
58
  "@types/jest": "^29",
59
59
  "@types/minimatch": "^3.0.5",
60
60
  "@types/node": "^14",
61
- "@types/ws": "^7.4.7",
61
+ "@types/ws": "^8.5.5",
62
62
  "jest": "^29",
63
63
  "node-mocks-http": "^1.11.0",
64
64
  "ts-node": "^10.9.1",
@@ -66,9 +66,9 @@
66
66
  "typescript": "^5",
67
67
  "webpack": "^5.88.1",
68
68
  "websocket": "^1",
69
- "@scripts/build": "2.40.0",
70
- "@modern-js/server-core": "2.40.0",
71
- "@scripts/jest-config": "2.40.0"
69
+ "@modern-js/server-core": "2.42.0",
70
+ "@scripts/build": "2.42.0",
71
+ "@scripts/jest-config": "2.42.0"
72
72
  },
73
73
  "peerDependencies": {
74
74
  "devcert": "^1.0.0",