xshell 1.0.179 → 1.0.181

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/builder.d.ts CHANGED
@@ -24,8 +24,8 @@ export interface Dependency {
24
24
  type DependencyId = 'react' | 'react-dom' | 'lodash' | 'jquery' | 'xterm' | 'swiper' | 'dayjs' | 'antd' | 'antd-icons' | 'vscode-oniguruma' | 'antd-plots' | 'gridstack' | 'quill' | 'monaco' | 'echarts';
25
25
  export interface HtmlOptions {
26
26
  title: string;
27
- /** `./index.js` 也可以设置 entries 中的其他项, 应填写相对于 .html 的路径 */
28
- fp_entry?: string;
27
+ /** `index.js` 也可以设置 entries 中的其他项, 应填写相对于 fpd_out 的路径 */
28
+ entry?: string;
29
29
  device_viewport?: boolean;
30
30
  /** 也会在 copy_files 中一并被复制,应填写相对于 fpd_root 和 fpd_out 的路径 */
31
31
  icon?: string | AssetOption;
package/builder.js CHANGED
@@ -493,7 +493,7 @@ export class Bundler {
493
493
  ]);
494
494
  }
495
495
  async build_htmls(print = { info: true, files: false }) {
496
- await Promise.all(Object.entries(this.htmls).map(async ([fp_html, { fp_entry = 'index.js', device_viewport: device_width = false, icon, manifest, dependencies: _dependencies = this.dependencies, title, scripts, mscripts, notice = false, heads, }]) => {
496
+ await Promise.all(Object.entries(this.htmls).map(async ([fp_html, { entry = 'index.js', device_viewport: device_width = false, icon, manifest, dependencies: _dependencies = this.dependencies, title, scripts, mscripts, notice = false, heads, }]) => {
497
497
  const get = (asset) => typeof asset === 'string' ? asset : asset.out;
498
498
  const html_template = '<!doctype html>\n' +
499
499
  '<html>\n' +
@@ -507,7 +507,7 @@ export class Bundler {
507
507
  this.resolve_dependency_files(_dependencies, false, { production: this.production }).map(fp => ` <script src='{root}vendors/${fp}' defer></script>`).join_lines() +
508
508
  (scripts?.before ? scripts.before.map(asset => ` <script src='{root}${get(asset)}' defer></script>`).join_lines() : '') +
509
509
  (mscripts ? mscripts.map(mscript => ` <script src='{root}${get(mscript)}' type='module'></script>`).join_lines() : '') +
510
- ` <script src='{root}${fp_entry}' type='module'></script>\n` +
510
+ ` <script src='{root}${entry}' type='module'></script>\n` +
511
511
  (scripts?.after ? scripts.after.map(asset => ` <script src='{root}${get(asset)}' defer></script>`).join_lines() : '') +
512
512
  ' </head>\n' +
513
513
  ' <body>\n' +
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.0.179",
3
+ "version": "1.0.181",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
package/path.d.ts CHANGED
@@ -55,7 +55,7 @@ export declare function extname(path: string): string;
55
55
  /** `/` */
56
56
  export declare const sep = "/";
57
57
  /** The platform-specific file delimiter. ';' or ':'. */
58
- export declare const delimiter: ";" | ":";
58
+ export declare const delimiter: ":" | ";";
59
59
  /** Returns an object from a path string - the opposite of format().
60
60
  @param path path to evaluate.
61
61
  @throws {TypeError} if `path` is not a string. */
@@ -83,7 +83,7 @@ export declare let path: {
83
83
  basename: typeof basename;
84
84
  extname: typeof extname;
85
85
  sep: string;
86
- delimiter: ";" | ":";
86
+ delimiter: ":" | ";";
87
87
  parse: typeof parse;
88
88
  format: typeof format;
89
89
  toNamespacedPath: typeof toNamespacedPath;
package/server.d.ts CHANGED
@@ -117,7 +117,7 @@ export declare class Server {
117
117
  )
118
118
  return
119
119
  } */
120
- try_send(ctx: Context, fpd_root: string, fp: string, log_404: boolean): Promise<boolean>;
120
+ try_send(ctx: Context, fpd_root: string, fp: string, log_404: boolean, assets_root?: string): Promise<boolean>;
121
121
  /** 将 body 设置为 fp 所指文件的 ReadStream
122
122
  检查 fp 是否合法,设置对应的 content-type,支持缓存,支持分块下载
123
123
  - ctx: Koa.Context
@@ -125,11 +125,13 @@ export declare class Server {
125
125
  - options?:
126
126
  - root?: 只能访问 root 下面的文件
127
127
  - absolute?: `false` 使用绝对路径指定发送的文件
128
- - download?: `undefined` 在 response.headers 中加上 content-disposition: attachment 指示浏览器下载文件 */
129
- fsend(ctx: Context, fp: string, { root, absolute, download, }?: {
128
+ - download?: `undefined` 在 response.headers 中加上 content-disposition: attachment 指示浏览器下载文件
129
+ - assets_root?: 替换模板 xxx.template.html {root} 占位符 */
130
+ fsend(ctx: Context, fp: string, { root, absolute, download, assets_root, }?: {
130
131
  root?: string;
131
132
  absolute?: boolean;
132
133
  download?: boolean;
134
+ assets_root?: string;
133
135
  }): Promise<string>;
134
136
  /** - range: 取值为逗号分割的多个可用端口或端口区间 (不能含有空格,包含区间右值),比如:`8321,8322,8300-8310,11000-11999
135
137
  - reverse?: `false` 在 range 内从后往前尝试 */
package/server.js CHANGED
@@ -535,14 +535,14 @@ export class Server {
535
535
  )
536
536
  return
537
537
  } */
538
- async try_send(ctx, fpd_root, fp, log_404) {
538
+ async try_send(ctx, fpd_root, fp, log_404, assets_root) {
539
539
  const { request: { _path, path, method }, response, } = ctx;
540
540
  if (response.body !== undefined || response.status !== 404)
541
541
  return true;
542
542
  if (method !== 'HEAD' && method !== 'GET')
543
543
  return false;
544
544
  try {
545
- await this.fsend(ctx, fp, { root: fpd_root });
545
+ await this.fsend(ctx, fp, { root: fpd_root, assets_root });
546
546
  return true;
547
547
  }
548
548
  catch (error) {
@@ -564,8 +564,9 @@ export class Server {
564
564
  - options?:
565
565
  - root?: 只能访问 root 下面的文件
566
566
  - absolute?: `false` 使用绝对路径指定发送的文件
567
- - download?: `undefined` 在 response.headers 中加上 content-disposition: attachment 指示浏览器下载文件 */
568
- async fsend(ctx, fp, { root, absolute, download, } = {}) {
567
+ - download?: `undefined` 在 response.headers 中加上 content-disposition: attachment 指示浏览器下载文件
568
+ - assets_root?: 替换模板 xxx.template.html 中 {root} 占位符 */
569
+ async fsend(ctx, fp, { root, absolute, download, assets_root, } = {}) {
569
570
  assert(absolute || root?.isdir, t('fsend 必须传 absolute 选项或 root 文件夹'));
570
571
  const { request, request: { method } } = ctx;
571
572
  let { response } = ctx;
@@ -624,6 +625,11 @@ export class Server {
624
625
  // 以上会自动设置 response.body = null
625
626
  return fp;
626
627
  }
628
+ if (assets_root) {
629
+ response.body = (await fread(fp, { print: false }))
630
+ .replaceAll('{root}', assets_root);
631
+ return fp;
632
+ }
627
633
  const range_header = request.headers.range;
628
634
  if (range_header)
629
635
  try {
@@ -75,7 +75,7 @@ export declare function encode(str: string): Uint8Array;
75
75
  在流式处理 (buffer 可能不完整) 时,应使用独立的 TextDecoder 实例调用 decode(buffer, { stream: true }) */
76
76
  export declare function decode(buffer: Uint8Array): string;
77
77
  /** 字符串字典序比较 */
78
- export declare function strcmp(l: string, r: string): 1 | 0 | -1;
78
+ export declare function strcmp(l: string, r: string): 0 | 1 | -1;
79
79
  /** 比较 1.10.02 这种版本号
80
80
  - l, r: 两个版本号字符串
81
81
  - loose?: 宽松模式,允许两个版本号格式(位数)不一致 */
package/utils.d.ts CHANGED
@@ -42,7 +42,7 @@ export declare function filter_values<TObj extends Record<string, any>>(obj: TOb
42
42
  /** 忽略对象中的 keys, 返回新对象 */
43
43
  export declare function omit<TObj>(obj: TObj, omit_keys: string[]): TObj;
44
44
  /** 字符串字典序比较 */
45
- export declare function strcmp(l: string, r: string): 1 | 0 | -1;
45
+ export declare function strcmp(l: string, r: string): 0 | 1 | -1;
46
46
  /** 比较 1.10.02 这种版本号
47
47
  - l, r: 两个版本号字符串
48
48
  - loose?: 宽松模式,允许两个版本号格式(位数)不一致 */