xshell 1.0.178 → 1.0.179
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 +6 -3
- package/builder.js +19 -19
- package/file.d.ts +5 -4
- package/file.js +16 -11
- package/package.json +1 -1
- package/path.d.ts +2 -2
- package/server.d.ts +1 -0
- package/server.js +14 -5
- package/utils.browser.d.ts +1 -1
- package/utils.d.ts +1 -1
package/builder.d.ts
CHANGED
|
@@ -74,6 +74,7 @@ export interface BundlerOptions {
|
|
|
74
74
|
exclude_modules?: RegExp;
|
|
75
75
|
assets?: Assets;
|
|
76
76
|
assets_root?: string;
|
|
77
|
+
template?: boolean;
|
|
77
78
|
license?: {
|
|
78
79
|
ignores?: string[];
|
|
79
80
|
};
|
|
@@ -91,7 +92,8 @@ export declare class Bundler {
|
|
|
91
92
|
config: Webpack.Configuration;
|
|
92
93
|
htmls?: Record<string, HtmlOptions>;
|
|
93
94
|
assets?: Assets;
|
|
94
|
-
assets_root
|
|
95
|
+
assets_root: string;
|
|
96
|
+
template: boolean;
|
|
95
97
|
globals?: BundlerOptions['globals'];
|
|
96
98
|
exclude_modules?: BundlerOptions['exclude_modules'];
|
|
97
99
|
license?: {
|
|
@@ -114,9 +116,10 @@ export declare class Bundler {
|
|
|
114
116
|
- assets?: 项目中需要直接复制到输出目录的资源,有 productions 但无 devs 时 (是同一套),
|
|
115
117
|
在 dev 模式下会用 productions 中的资源,如果不需要 productions 资源, devs 可以设置为 [ ],
|
|
116
118
|
每一项是 string 或者 { src: '...', out: '...' },路径相对于 fpd_root 和 fpd_out
|
|
117
|
-
- assets_root?: `''` 生成的 html 中是否使用 / 开头的绝对路径,以支持 browser router 路由能力
|
|
119
|
+
- assets_root?: `'/'` 生成的 html 中是否使用 / 开头的绝对路径,以支持 browser router 路由能力
|
|
118
120
|
启用后 assets, html 中的 icon, scripts 路径直接在前面添加 assets_root 来生成最终 html href
|
|
119
121
|
未启用时使用相对 html 路径来生成最终 html href
|
|
122
|
+
- template?: `false` 除了生成对应的 html 之外,还生成所有路径为 `{root}/...` 的模板 html 文件, 方便后续 server 替换渲染
|
|
120
123
|
- local_loaders?: `true` true 时使用项目 node_modules/ 中的 loader; false 时使用 D:/0/ 下面的
|
|
121
124
|
- commonjs2?: `false` 打包为 commonjs2 (.cjs) 的文件
|
|
122
125
|
- single_chunk?: `true` 输出为单个文件,将依赖也打包到其中,不要生成多个 chunk
|
|
@@ -131,7 +134,7 @@ export declare class Bundler {
|
|
|
131
134
|
- production?: `true` webpack mode 设置为 'production'
|
|
132
135
|
- sass?: 传入 sass 实例避免 webpack 重复加载 .cjs 版本
|
|
133
136
|
- license?: 使用 license-webpack-plugin 构建 ThirdPartyNotice.txt */
|
|
134
|
-
constructor(name: string, target: 'web' | 'nodejs', fpd_root: string, fpd_out: string, fpdt_cache: string, entry: Record<string, string>, { source_map, globals, external_dayjs, externals, htmls, assets, assets_root, commonjs2, single_chunk, dynamic_import, resolve_alias, resolve_fallback, assets_stats, analyzer, dts, exclude_modules, cache_version, production, sass, dependencies, license, }?: BundlerOptions);
|
|
137
|
+
constructor(name: string, target: 'web' | 'nodejs', fpd_root: string, fpd_out: string, fpdt_cache: string, entry: Record<string, string>, { source_map, globals, external_dayjs, externals, htmls, assets, assets_root, template, commonjs2, single_chunk, dynamic_import, resolve_alias, resolve_fallback, assets_stats, analyzer, dts, exclude_modules, cache_version, production, sass, dependencies, license, }?: BundlerOptions);
|
|
135
138
|
build(print?: boolean): Promise<void>;
|
|
136
139
|
close(): Promise<void>;
|
|
137
140
|
build_all(print?: boolean): Promise<void>;
|
package/builder.js
CHANGED
|
@@ -117,6 +117,7 @@ export class Bundler {
|
|
|
117
117
|
htmls;
|
|
118
118
|
assets;
|
|
119
119
|
assets_root;
|
|
120
|
+
template;
|
|
120
121
|
globals;
|
|
121
122
|
exclude_modules;
|
|
122
123
|
license;
|
|
@@ -137,9 +138,10 @@ export class Bundler {
|
|
|
137
138
|
- assets?: 项目中需要直接复制到输出目录的资源,有 productions 但无 devs 时 (是同一套),
|
|
138
139
|
在 dev 模式下会用 productions 中的资源,如果不需要 productions 资源, devs 可以设置为 [ ],
|
|
139
140
|
每一项是 string 或者 { src: '...', out: '...' },路径相对于 fpd_root 和 fpd_out
|
|
140
|
-
- assets_root?: `''` 生成的 html 中是否使用 / 开头的绝对路径,以支持 browser router 路由能力
|
|
141
|
+
- assets_root?: `'/'` 生成的 html 中是否使用 / 开头的绝对路径,以支持 browser router 路由能力
|
|
141
142
|
启用后 assets, html 中的 icon, scripts 路径直接在前面添加 assets_root 来生成最终 html href
|
|
142
143
|
未启用时使用相对 html 路径来生成最终 html href
|
|
144
|
+
- template?: `false` 除了生成对应的 html 之外,还生成所有路径为 `{root}/...` 的模板 html 文件, 方便后续 server 替换渲染
|
|
143
145
|
- local_loaders?: `true` true 时使用项目 node_modules/ 中的 loader; false 时使用 D:/0/ 下面的
|
|
144
146
|
- commonjs2?: `false` 打包为 commonjs2 (.cjs) 的文件
|
|
145
147
|
- single_chunk?: `true` 输出为单个文件,将依赖也打包到其中,不要生成多个 chunk
|
|
@@ -154,7 +156,7 @@ export class Bundler {
|
|
|
154
156
|
- production?: `true` webpack mode 设置为 'production'
|
|
155
157
|
- sass?: 传入 sass 实例避免 webpack 重复加载 .cjs 版本
|
|
156
158
|
- license?: 使用 license-webpack-plugin 构建 ThirdPartyNotice.txt */
|
|
157
|
-
constructor(name, target, fpd_root, fpd_out, fpdt_cache, entry, { source_map = true, globals, external_dayjs = false, externals, htmls, assets, assets_root = '', commonjs2 = false, single_chunk = true, dynamic_import = true, resolve_alias, resolve_fallback, assets_stats = true, analyzer = false, dts = false, exclude_modules, cache_version, production = true, sass, dependencies, license, } = {}) {
|
|
159
|
+
constructor(name, target, fpd_root, fpd_out, fpdt_cache, entry, { source_map = true, globals, external_dayjs = false, externals, htmls, assets, assets_root = '/', template = false, commonjs2 = false, single_chunk = true, dynamic_import = true, resolve_alias, resolve_fallback, assets_stats = true, analyzer = false, dts = false, exclude_modules, cache_version, production = true, sass, dependencies, license, } = {}) {
|
|
158
160
|
this.name = name;
|
|
159
161
|
this.analyzer = analyzer;
|
|
160
162
|
this.production = production;
|
|
@@ -165,6 +167,7 @@ export class Bundler {
|
|
|
165
167
|
this.htmls = htmls;
|
|
166
168
|
this.assets = assets;
|
|
167
169
|
this.assets_root = assets_root;
|
|
170
|
+
this.template = template;
|
|
168
171
|
this.globals = globals;
|
|
169
172
|
this.exclude_modules = exclude_modules;
|
|
170
173
|
if (dependencies) {
|
|
@@ -175,9 +178,7 @@ export class Bundler {
|
|
|
175
178
|
// let smp = new SpeedMeasurePlugin()
|
|
176
179
|
// const config: Webpack.Configuration = smp.wrap({
|
|
177
180
|
let resolve_cache = {};
|
|
178
|
-
|
|
179
|
-
return resolve_cache[name] ??= fileURLToPath(import.meta.resolve(`${name}/package.json`)).fdir;
|
|
180
|
-
}
|
|
181
|
+
const get_loader = (name) => resolve_cache[name] ??= fileURLToPath(import.meta.resolve(`${name}/package.json`)).fdir;
|
|
181
182
|
this.config = {
|
|
182
183
|
name,
|
|
183
184
|
mode: production ? 'production' : 'development',
|
|
@@ -493,25 +494,21 @@ export class Bundler {
|
|
|
493
494
|
}
|
|
494
495
|
async build_htmls(print = { info: true, files: false }) {
|
|
495
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
|
-
const
|
|
497
|
-
const
|
|
498
|
-
`${this.assets_root}${typeof asset === 'string' ? asset : asset.out}`
|
|
499
|
-
:
|
|
500
|
-
path.relative(fpd_html, `${this.fpd_out}${typeof asset === 'string' ? asset : asset.out}`);
|
|
501
|
-
const html = '<!doctype html>\n' +
|
|
497
|
+
const get = (asset) => typeof asset === 'string' ? asset : asset.out;
|
|
498
|
+
const html_template = '<!doctype html>\n' +
|
|
502
499
|
'<html>\n' +
|
|
503
500
|
' <head>\n' +
|
|
504
501
|
` <title>${title}</title>\n` +
|
|
505
502
|
" <meta charset='utf-8' />\n" +
|
|
506
503
|
(heads ? heads.map(head => ` ${head}`).join_lines() : '') +
|
|
507
504
|
(device_width ? " <meta name='viewport' content='width=device-width, initial-scale=1.0' />\n" : '') +
|
|
508
|
-
(icon ? ` <link rel='icon' href='${
|
|
509
|
-
(manifest ? ` <link rel='manifest' href='${
|
|
510
|
-
this.resolve_dependency_files(_dependencies, false, { production: this.production }).map(fp => ` <script src='
|
|
511
|
-
(scripts?.before ? scripts.before.map(asset => ` <script src='${
|
|
512
|
-
(mscripts ? mscripts.map(mscript => ` <script src='${
|
|
513
|
-
` <script src='
|
|
514
|
-
(scripts?.after ? scripts.after.map(asset => ` <script src='${
|
|
505
|
+
(icon ? ` <link rel='icon' href='{root}${icon}' />\n` : '') +
|
|
506
|
+
(manifest ? ` <link rel='manifest' href='{root}${manifest}' />\n` : '') +
|
|
507
|
+
this.resolve_dependency_files(_dependencies, false, { production: this.production }).map(fp => ` <script src='{root}vendors/${fp}' defer></script>`).join_lines() +
|
|
508
|
+
(scripts?.before ? scripts.before.map(asset => ` <script src='{root}${get(asset)}' defer></script>`).join_lines() : '') +
|
|
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` +
|
|
511
|
+
(scripts?.after ? scripts.after.map(asset => ` <script src='{root}${get(asset)}' defer></script>`).join_lines() : '') +
|
|
515
512
|
' </head>\n' +
|
|
516
513
|
' <body>\n' +
|
|
517
514
|
" <div class='root'>\n" +
|
|
@@ -522,7 +519,10 @@ export class Bundler {
|
|
|
522
519
|
' </div>\n' +
|
|
523
520
|
' </body>\n' +
|
|
524
521
|
'</html>\n';
|
|
525
|
-
await
|
|
522
|
+
await Promise.all([
|
|
523
|
+
fwrite(`${this.fpd_out}${fp_html}`, html_template.replaceAll('{root}', this.assets_root), noprint),
|
|
524
|
+
this.template && fwrite(`${this.fpd_out}${fp_html.strip_end('.html', true)}.template.html`, html_template, noprint)
|
|
525
|
+
]);
|
|
526
526
|
if (print.files)
|
|
527
527
|
console.log(`已构建 ${fp_html}`);
|
|
528
528
|
}));
|
package/file.d.ts
CHANGED
|
@@ -176,12 +176,13 @@ export declare function fmkdir(fpd: string, { print, mode, }?: {
|
|
|
176
176
|
/** `0o777` A file mode. If a string is passed, it is parsed as an octal integer. */
|
|
177
177
|
mode?: string | number;
|
|
178
178
|
}): Promise<string>;
|
|
179
|
-
/** 创建软链接
|
|
180
|
-
- fp_real: 现在真实文件/文件夹的路径
|
|
181
|
-
- fp_link: 目标链接文件/文件夹的路径
|
|
182
|
-
export declare function flink(fp_real: string, fp_link: string, { junction, print }?: {
|
|
179
|
+
/** 创建软链接
|
|
180
|
+
- fp_real: 现在真实文件/文件夹的路径
|
|
181
|
+
- fp_link: 目标链接文件/文件夹的路径 */
|
|
182
|
+
export declare function flink(fp_real: string, fp_link: string, { junction, print, skip_existing }?: {
|
|
183
183
|
junction?: boolean;
|
|
184
184
|
print?: boolean;
|
|
185
|
+
skip_existing?: boolean;
|
|
185
186
|
}): Promise<void>;
|
|
186
187
|
export interface ZipOptions {
|
|
187
188
|
dirname?: string;
|
package/file.js
CHANGED
|
@@ -372,22 +372,27 @@ export async function fmkdir(fpd, { print = true, mode, } = {}) {
|
|
|
372
372
|
console.log(t('已存在文件夹'), fpd);
|
|
373
373
|
return fpd_;
|
|
374
374
|
}
|
|
375
|
-
/** 创建软链接
|
|
376
|
-
- fp_real: 现在真实文件/文件夹的路径
|
|
377
|
-
- fp_link: 目标链接文件/文件夹的路径
|
|
378
|
-
export async function flink(fp_real, fp_link, { junction = false, print = true } = {}) {
|
|
379
|
-
assert(path.isAbsolute(fp_real) && path.isAbsolute(fp_link),
|
|
375
|
+
/** 创建软链接
|
|
376
|
+
- fp_real: 现在真实文件/文件夹的路径
|
|
377
|
+
- fp_link: 目标链接文件/文件夹的路径 */
|
|
378
|
+
export async function flink(fp_real, fp_link, { junction = false, print = true, skip_existing = false } = {}) {
|
|
379
|
+
assert(path.isAbsolute(fp_real) && path.isAbsolute(fp_link), 'fp 必须是绝对路径');
|
|
380
380
|
const is_fpd_real = fp_real.isdir;
|
|
381
381
|
const is_fpd_link = fp_link.isdir;
|
|
382
|
-
assert(is_fpd_real === is_fpd_link,
|
|
383
|
-
if (fexists(fp_link))
|
|
384
|
-
|
|
382
|
+
assert(is_fpd_real === is_fpd_link, 'fp_real 和 fp_link 必须同为文件路径或文件夹路径');
|
|
383
|
+
if (fexists(fp_link, { print: false }))
|
|
384
|
+
if (!skip_existing)
|
|
385
|
+
throw new Error(`存在同名${is_fpd_link ? '文件夹' : '文件'}: ${fp_link},无法创建链接`);
|
|
386
|
+
else {
|
|
387
|
+
console.log('跳过已存在: ', fp_link);
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
385
390
|
if (print)
|
|
386
|
-
console.log(
|
|
391
|
+
console.log(`已将源文件 ${fp_real} 链接到 ${fp_link}`);
|
|
387
392
|
if (junction)
|
|
388
|
-
fsp.symlink(fp_real, fp_link, 'junction');
|
|
393
|
+
await fsp.symlink(fp_real, fp_link, 'junction');
|
|
389
394
|
else
|
|
390
|
-
fsp.symlink(fp_real, fp_link, is_fpd_real ? 'dir' : 'file');
|
|
395
|
+
await fsp.symlink(fp_real, fp_link, is_fpd_real ? 'dir' : 'file');
|
|
391
396
|
}
|
|
392
397
|
/** 将文件夹或文件列表压缩为 zip,返回生成的压缩包路径 (fp_zip)
|
|
393
398
|
- data:
|
package/package.json
CHANGED
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
|
@@ -52,6 +52,7 @@ export declare class Server {
|
|
|
52
52
|
stdio_subscribable?: boolean;
|
|
53
53
|
stdio_subscribers: (((chunk: Uint8Array | string) => Promise<void>) & {
|
|
54
54
|
id: number;
|
|
55
|
+
closer: (event: any) => void;
|
|
55
56
|
})[];
|
|
56
57
|
/** 原始 process.stdout.write 函数 bind 后的备份 */
|
|
57
58
|
stdout_write: Function;
|
package/server.js
CHANGED
|
@@ -167,18 +167,27 @@ export class Server {
|
|
|
167
167
|
};
|
|
168
168
|
// 让后续可以通过 unsubscribe_stdio 取消订阅
|
|
169
169
|
subscriber.id = id;
|
|
170
|
-
|
|
171
|
-
websocket.addEventListener('close', () => {
|
|
170
|
+
const closer = subscriber.closer = () => {
|
|
172
171
|
const length = this.stdio_subscribers.length;
|
|
173
172
|
const stdio_subscribers_ = this.stdio_subscribers.filter(s => s !== subscriber);
|
|
174
173
|
if (stdio_subscribers_.length !== length) {
|
|
175
|
-
console.log(
|
|
174
|
+
console.log('由于 websocket 连接关闭,stdio 订阅被关闭');
|
|
176
175
|
this.stdio_subscribers = stdio_subscribers_;
|
|
177
176
|
}
|
|
178
|
-
}
|
|
177
|
+
};
|
|
178
|
+
this.stdio_subscribers.push(subscriber);
|
|
179
|
+
websocket.addEventListener('close', closer, { once: true });
|
|
179
180
|
},
|
|
181
|
+
/** 主动取消订阅,需要清理 stdio listener, websocket close lisener */
|
|
180
182
|
unsubscribe_stdio: ({ data: [id] }, websocket) => {
|
|
181
|
-
this.stdio_subscribers = this.stdio_subscribers.filter(s =>
|
|
183
|
+
this.stdio_subscribers = this.stdio_subscribers.filter(s => {
|
|
184
|
+
if (s.id === id) {
|
|
185
|
+
websocket.removeEventListener('close', s.closer);
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
else
|
|
189
|
+
return true;
|
|
190
|
+
});
|
|
182
191
|
console.log(t('已取消订阅 stdio'));
|
|
183
192
|
return [];
|
|
184
193
|
},
|
package/utils.browser.d.ts
CHANGED
|
@@ -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):
|
|
78
|
+
export declare function strcmp(l: string, r: string): 1 | 0 | -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):
|
|
45
|
+
export declare function strcmp(l: string, r: string): 1 | 0 | -1;
|
|
46
46
|
/** 比较 1.10.02 这种版本号
|
|
47
47
|
- l, r: 两个版本号字符串
|
|
48
48
|
- loose?: 宽松模式,允许两个版本号格式(位数)不一致 */
|