xshell 1.0.70 → 1.0.71

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.0.70",
3
+ "version": "1.0.71",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
package/repl.js CHANGED
@@ -31,6 +31,7 @@ export async function start_repl() {
31
31
  let { Server } = await import('./server.js');
32
32
  server = new Server({
33
33
  name: 'repl',
34
+ http: true,
34
35
  http_port: 8421,
35
36
  funcs: {
36
37
  echo({ data: [data] }) {
package/server.d.ts CHANGED
@@ -35,6 +35,10 @@ export declare class Server {
35
35
  js_exts: Set<string>;
36
36
  app: Koa;
37
37
  handler: ReturnType<Koa['callback']>;
38
+ /** 启用 http server */
39
+ http: boolean;
40
+ /** 启用 http2 server */
41
+ http2: boolean;
38
42
  http_port: number;
39
43
  http2_port: number;
40
44
  /** http2 server 证书文件夹路径,设置后才会启用 http2 server */
@@ -55,8 +59,10 @@ export declare class Server {
55
59
  stdout_write: Function;
56
60
  stderr_write: Function;
57
61
  encoder: TextEncoder;
58
- constructor({ name, http_port, http2_port, fpd_certs, default_hostnames, remote, funcs, stdio_subscribable, }: {
62
+ constructor({ name, http, http2, http_port, http2_port, fpd_certs, default_hostnames, remote, funcs, stdio_subscribable, }: {
59
63
  name: string;
64
+ http?: boolean;
65
+ http2?: boolean;
60
66
  http_port?: number;
61
67
  http2_port?: number;
62
68
  fpd_certs?: string;
package/server.js CHANGED
@@ -26,6 +26,10 @@ export class Server {
26
26
  js_exts = new Set(['.js', '.mjs', '.cjs']);
27
27
  app;
28
28
  handler;
29
+ /** 启用 http server */
30
+ http = false;
31
+ /** 启用 http2 server */
32
+ http2 = false;
29
33
  http_port = 80;
30
34
  http2_port = 443;
31
35
  /** http2 server 证书文件夹路径,设置后才会启用 http2 server */
@@ -44,8 +48,13 @@ export class Server {
44
48
  stdout_write;
45
49
  stderr_write;
46
50
  encoder = new TextEncoder();
47
- constructor({ name, http_port, http2_port, fpd_certs, default_hostnames, remote, funcs, stdio_subscribable, }) {
51
+ constructor({ name, http, http2, http_port, http2_port, fpd_certs, default_hostnames, remote, funcs, stdio_subscribable, }) {
48
52
  this.name = name;
53
+ if (http)
54
+ this.http = http;
55
+ if (http2)
56
+ this.http2 = http2;
57
+ assert(this.http || this.http2, 'http 和 http2 至少启用一个');
49
58
  if (http_port !== undefined)
50
59
  this.http_port = http_port;
51
60
  if (http2_port !== undefined)
@@ -95,8 +104,9 @@ export class Server {
95
104
  this.app = app;
96
105
  this.handler = this.app.callback();
97
106
  this.http_server = http_create_server(this.handler);
98
- const { fpd_certs } = this;
99
- if (fpd_certs) {
107
+ const { http, http2 } = this;
108
+ if (http2) {
109
+ const { fpd_certs } = this;
100
110
  let lazy_secure_ctxs = Object.fromEntries(await Promise.all(
101
111
  // fpd_certs 文件夹下面的每个 .key 对应一个证书及域名
102
112
  (await flist(fpd_certs, { print: false, filter: /\.key$/ }))
@@ -196,16 +206,19 @@ export class Server {
196
206
  }
197
207
  }
198
208
  await Promise.all([
199
- new Promise(resolve => {
209
+ http && new Promise(resolve => {
200
210
  this.http_server.listen(this.http_port, resolve);
201
211
  }),
202
- fpd_certs && new Promise(resolve => {
212
+ http2 && new Promise(resolve => {
203
213
  this.http2_server.listen(this.http2_port, resolve);
204
214
  }),
205
215
  ]);
206
216
  console.log(t('{{name}} 启动成功,正在监听 {{ports}} 端口', {
207
217
  name: this.name,
208
- ports: `${this.http_port}${fpd_certs ? `, ${this.http2_port}` : ''}`
218
+ ports: [
219
+ ...http ? [this.http_port] : [],
220
+ ...http2 ? [this.http2_port] : []
221
+ ].join(', ')
209
222
  }));
210
223
  }
211
224
  stop() {
@@ -51,7 +51,7 @@ export declare class Lock<TResource = void> {
51
51
  }
52
52
  export declare function pause(milliseconds?: number): Promise<void>;
53
53
  /** 字符串字典序比较 */
54
- export declare function strcmp(l: string, r: string): 1 | 0 | -1;
54
+ export declare function strcmp(l: string, r: string): 0 | 1 | -1;
55
55
  /** 比较 1.10.02 这种版本号 */
56
56
  export declare function vercmp(l: string, r: string): number;
57
57
  export declare function get<TReturn = any>(obj: any, keypath: string): TReturn;
package/utils.d.ts CHANGED
@@ -22,7 +22,7 @@ export declare function unique<T>(iterable: T[] | Iterable<T>, selector?: string
22
22
  /** 排序对象中 key 的顺序,返回新的对象 */
23
23
  export declare function sort_keys<T>(obj: T): T;
24
24
  /** 字符串字典序比较 */
25
- export declare function strcmp(l: string, r: string): 1 | 0 | -1;
25
+ export declare function strcmp(l: string, r: string): 0 | 1 | -1;
26
26
  /** 比较 1.10.02 这种版本号 */
27
27
  export declare function vercmp(l: string, r: string): number;
28
28
  export declare function get<TReturn = any>(obj: any, keypath: string): TReturn;