@modern-js/server 2.41.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.
@@ -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.41.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",
@@ -47,11 +47,11 @@
47
47
  "path-to-regexp": "^6.2.0",
48
48
  "ws": "^8.13.0",
49
49
  "axios": "^1.6.0",
50
- "@modern-js/prod-server": "2.41.0",
51
- "@modern-js/server-utils": "2.41.0",
52
- "@modern-js/types": "2.41.0",
53
- "@modern-js/utils": "2.41.0",
54
- "@modern-js/runtime-utils": "2.41.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",
@@ -66,9 +66,9 @@
66
66
  "typescript": "^5",
67
67
  "webpack": "^5.88.1",
68
68
  "websocket": "^1",
69
- "@modern-js/server-core": "2.41.0",
70
- "@scripts/build": "2.41.0",
71
- "@scripts/jest-config": "2.41.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",