xshell 1.2.42 → 1.2.44
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/apps.d.ts +1 -1
- package/apps.js +2 -2
- package/builder.d.ts +25 -18
- package/builder.js +318 -312
- package/net.js +1 -1
- package/package.json +6 -6
- package/process.js +1 -1
- package/prototype.browser.d.ts +3 -1
- package/prototype.browser.js +3 -3
- package/prototype.d.ts +3 -1
- package/prototype.js +3 -3
package/apps.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare let npm: {
|
|
|
5
5
|
/** node.exe E:/sdk/nodejs/node_modules/corepack/dist/pnpm.js install
|
|
6
6
|
- cwd
|
|
7
7
|
- pkgs?: `[ ]` */
|
|
8
|
-
install(
|
|
8
|
+
install(fpd: string, pkgs?: string[], { save_dev, save_peer, legacy, force, break: _break, }?: {
|
|
9
9
|
save_dev?: boolean;
|
|
10
10
|
save_peer?: boolean;
|
|
11
11
|
legacy?: boolean;
|
package/apps.js
CHANGED
|
@@ -8,7 +8,7 @@ export let npm = {
|
|
|
8
8
|
/** node.exe E:/sdk/nodejs/node_modules/corepack/dist/pnpm.js install
|
|
9
9
|
- cwd
|
|
10
10
|
- pkgs?: `[ ]` */
|
|
11
|
-
async install(
|
|
11
|
+
async install(fpd, pkgs = [], { save_dev = false, save_peer = false, legacy = false, force = false, break: _break = false, } = {}) {
|
|
12
12
|
const args = [
|
|
13
13
|
'install',
|
|
14
14
|
...util.inspect.defaultOptions.colors ? ['--color'] : [],
|
|
@@ -18,7 +18,7 @@ export let npm = {
|
|
|
18
18
|
...save_peer ? ['--save-peer'] : [],
|
|
19
19
|
...pkgs || []
|
|
20
20
|
];
|
|
21
|
-
await this.call(
|
|
21
|
+
await this.call(fpd, this.bin, args);
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
24
|
//# sourceMappingURL=apps.js.map
|
package/builder.d.ts
CHANGED
|
@@ -48,10 +48,6 @@ export interface HtmlOptions {
|
|
|
48
48
|
heads?: string[];
|
|
49
49
|
notice?: boolean;
|
|
50
50
|
}
|
|
51
|
-
export interface SingleJsConfig {
|
|
52
|
-
js: string;
|
|
53
|
-
entry: string;
|
|
54
|
-
}
|
|
55
51
|
interface AssetOption {
|
|
56
52
|
/** 相对 fpd_root 的路径,或者绝对路径 */
|
|
57
53
|
src: string;
|
|
@@ -68,7 +64,6 @@ export interface BundlerOptions {
|
|
|
68
64
|
production?: boolean;
|
|
69
65
|
external_dayjs?: boolean;
|
|
70
66
|
externals?: Record<string, string | string[]>;
|
|
71
|
-
sass?: typeof import('sass');
|
|
72
67
|
dynamic_import?: boolean;
|
|
73
68
|
commonjs2?: boolean;
|
|
74
69
|
expose?: boolean;
|
|
@@ -95,24 +90,37 @@ export interface BundlerOptions {
|
|
|
95
90
|
}
|
|
96
91
|
export declare class Bundler {
|
|
97
92
|
name: string;
|
|
98
|
-
fpd_root: string;
|
|
99
93
|
target: 'nodejs' | 'web';
|
|
100
|
-
|
|
94
|
+
fpd_root: string;
|
|
101
95
|
fpd_out: string;
|
|
102
|
-
|
|
96
|
+
fpdt_cache: string;
|
|
97
|
+
entry: Record<string, string>;
|
|
98
|
+
production: boolean;
|
|
103
99
|
dependencies: DependencyId[];
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
source_map: boolean;
|
|
101
|
+
globals?: BundlerOptions['globals'];
|
|
102
|
+
external_dayjs: boolean;
|
|
103
|
+
externals: BundlerOptions['externals'];
|
|
104
|
+
htmls?: BundlerOptions['htmls'];
|
|
107
105
|
assets?: Assets;
|
|
108
106
|
assets_root: string;
|
|
109
107
|
template: boolean;
|
|
110
108
|
single_js?: BundlerOptions['single_js'];
|
|
111
|
-
|
|
109
|
+
commonjs2: boolean;
|
|
110
|
+
expose: boolean;
|
|
111
|
+
single_chunk: boolean;
|
|
112
|
+
dynamic_import: boolean;
|
|
113
|
+
resolve_alias?: BundlerOptions['resolve_alias'];
|
|
114
|
+
resolve_fallback?: BundlerOptions['resolve_fallback'];
|
|
115
|
+
assets_stats: boolean;
|
|
116
|
+
analyzer: boolean;
|
|
117
|
+
dts: boolean;
|
|
112
118
|
exclude_modules?: BundlerOptions['exclude_modules'];
|
|
119
|
+
cache_version?: string;
|
|
113
120
|
plugins?: BundlerOptions['plugins'];
|
|
114
121
|
license?: boolean;
|
|
115
122
|
polyfill_node_sea?: boolean;
|
|
123
|
+
config: Webpack.Configuration;
|
|
116
124
|
lcompiler: Lock<Webpack.Compiler>;
|
|
117
125
|
/** 通过 webpack 从入口文件打包所有依赖生成单个 index.{mjs,cjs} 文件
|
|
118
126
|
- name: 项目名称
|
|
@@ -122,6 +130,8 @@ export declare class Bundler {
|
|
|
122
130
|
- fpd_cache: webpack 缓存目录
|
|
123
131
|
- entry: 入口文件
|
|
124
132
|
- options?: 打包配置, 按常用顺序排列
|
|
133
|
+
- production?: `true` webpack mode 设置为 'production'
|
|
134
|
+
- dependencies?: DependencyId[], 决定 bundler 在 build_all (copy_files) 时需要复制到 fpd_out 的资源
|
|
125
135
|
- source_map?: `true` 启用源码映射 .map 文件
|
|
126
136
|
- globals?: 全局变量定义
|
|
127
137
|
- external_dayjs?: `false` 配置 dayjs 为 external 来配合 antd 使用, 减小一点体积
|
|
@@ -130,14 +140,13 @@ export declare class Bundler {
|
|
|
130
140
|
- assets?: 项目中需要直接复制到输出目录的资源,有 productions 但无 devs 时 (是同一套),
|
|
131
141
|
在 dev 模式下会用 productions 中的资源,如果不需要 productions 资源, devs 可以设置为 [ ],
|
|
132
142
|
每一项是 string 或者 { src: '...', out: '...' },路径相对于 fpd_root 和 fpd_out
|
|
133
|
-
- assets_root?: `'/'` 生成的 html
|
|
134
|
-
|
|
143
|
+
- assets_root?: `'/'` 生成的 html 中替换 {root} 作为部署路径,以支持 browser router 路由能力
|
|
144
|
+
assets, html 中的 icon, scripts 路径直接在前面添加 assets_root 来生成最终 html href
|
|
135
145
|
未启用时使用相对 html 路径来生成最终 html href
|
|
136
146
|
- template?: `false` 除了生成对应的 html 之外,还生成所有路径为 `{root}/...` 的模板 html 文件, 方便后续 server 替换渲染
|
|
137
147
|
- single_js?: 设置生成的单个 js 入口文件,无其他依赖,通过 script module 作为入口加载,含有 import 加载其他 externals 和某个 entry,类似 htmls 配置要生成的 html
|
|
138
148
|
- js: js 入口文件名
|
|
139
149
|
- entry: 使用的 entry
|
|
140
|
-
- local_loaders?: `true` true 时使用项目 node_modules/ 中的 loader; false 时使用 D:/0/ 下面的
|
|
141
150
|
- commonjs2?: `false` 打包为 commonjs2 (.cjs) 的文件
|
|
142
151
|
- expose?: `false` 入口模块所有导出的属性赋值到全局对象 globalThis 上
|
|
143
152
|
- single_chunk?: `true` 输出为单个文件,将依赖也打包到其中,不要生成多个 chunk
|
|
@@ -149,12 +158,10 @@ export declare class Bundler {
|
|
|
149
158
|
- dts?: `false` 生成 .d.ts 文件
|
|
150
159
|
- exclude_modules?: 传入正则表达式 ,匹配时使用 IgnorePlugin 强制不打包这个模块,但是一旦导入就会报错
|
|
151
160
|
- cache_version?: webpack cache version, 用于区分同一个 name 的不同版本
|
|
152
|
-
- production?: `true` webpack mode 设置为 'production'
|
|
153
|
-
- sass?: 传入 sass 实例避免 webpack 重复加载 .cjs 版本
|
|
154
161
|
- plugins?: 可选传入的额外的 webpack 插件
|
|
155
162
|
- license?: 使用 license-webpack-plugin 构建 ThirdPartyNotice.txt
|
|
156
163
|
- polyfill_node_sea?: 避免依赖 node:sea 模块以兼容旧版本 node.js */
|
|
157
|
-
constructor(name: string, target: 'web' | 'nodejs', fpd_root: string, fpd_out: string, fpdt_cache: string, entry: Record<string, string>,
|
|
164
|
+
constructor(name: string, target: 'web' | 'nodejs', fpd_root: string, fpd_out: string, fpdt_cache: string, entry: Record<string, string>, options?: BundlerOptions);
|
|
158
165
|
build(print?: boolean): Promise<void>;
|
|
159
166
|
close(): Promise<void>;
|
|
160
167
|
build_all(print?: boolean): Promise<void>;
|
package/builder.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { fileURLToPath } from 'url';
|
|
2
2
|
import { not_empty } from "./prototype.js";
|
|
3
3
|
import { noprint } from "./process.js";
|
|
4
|
-
import { Lock,
|
|
4
|
+
import { Lock, filter_values } from "./utils.js";
|
|
5
5
|
import { fcopy, fmkdir, fwrite, fread } from "./file.js";
|
|
6
6
|
import { path } from "./path.js";
|
|
7
7
|
const monaco_files = [
|
|
@@ -125,24 +125,39 @@ function get_vendor_asset_out(asset) {
|
|
|
125
125
|
}
|
|
126
126
|
export class Bundler {
|
|
127
127
|
name;
|
|
128
|
-
fpd_root;
|
|
129
128
|
target;
|
|
130
|
-
|
|
129
|
+
fpd_root;
|
|
131
130
|
fpd_out;
|
|
132
|
-
|
|
131
|
+
fpdt_cache;
|
|
132
|
+
entry;
|
|
133
|
+
// --- BundlerOptions 开始
|
|
134
|
+
production = true;
|
|
133
135
|
dependencies = [];
|
|
134
|
-
|
|
135
|
-
|
|
136
|
+
source_map = true;
|
|
137
|
+
globals;
|
|
138
|
+
external_dayjs = false;
|
|
139
|
+
externals;
|
|
136
140
|
htmls;
|
|
137
141
|
assets;
|
|
138
|
-
assets_root;
|
|
139
|
-
template;
|
|
142
|
+
assets_root = '/';
|
|
143
|
+
template = false;
|
|
140
144
|
single_js;
|
|
141
|
-
|
|
145
|
+
commonjs2 = false;
|
|
146
|
+
expose = false;
|
|
147
|
+
single_chunk = true;
|
|
148
|
+
dynamic_import = true;
|
|
149
|
+
resolve_alias;
|
|
150
|
+
resolve_fallback;
|
|
151
|
+
assets_stats = true;
|
|
152
|
+
analyzer = false;
|
|
153
|
+
dts = false;
|
|
142
154
|
exclude_modules;
|
|
155
|
+
cache_version;
|
|
143
156
|
plugins;
|
|
144
157
|
license;
|
|
145
158
|
polyfill_node_sea;
|
|
159
|
+
// --- BundlerOptions 结束
|
|
160
|
+
config;
|
|
146
161
|
lcompiler;
|
|
147
162
|
/** 通过 webpack 从入口文件打包所有依赖生成单个 index.{mjs,cjs} 文件
|
|
148
163
|
- name: 项目名称
|
|
@@ -152,6 +167,8 @@ export class Bundler {
|
|
|
152
167
|
- fpd_cache: webpack 缓存目录
|
|
153
168
|
- entry: 入口文件
|
|
154
169
|
- options?: 打包配置, 按常用顺序排列
|
|
170
|
+
- production?: `true` webpack mode 设置为 'production'
|
|
171
|
+
- dependencies?: DependencyId[], 决定 bundler 在 build_all (copy_files) 时需要复制到 fpd_out 的资源
|
|
155
172
|
- source_map?: `true` 启用源码映射 .map 文件
|
|
156
173
|
- globals?: 全局变量定义
|
|
157
174
|
- external_dayjs?: `false` 配置 dayjs 为 external 来配合 antd 使用, 减小一点体积
|
|
@@ -160,14 +177,13 @@ export class Bundler {
|
|
|
160
177
|
- assets?: 项目中需要直接复制到输出目录的资源,有 productions 但无 devs 时 (是同一套),
|
|
161
178
|
在 dev 模式下会用 productions 中的资源,如果不需要 productions 资源, devs 可以设置为 [ ],
|
|
162
179
|
每一项是 string 或者 { src: '...', out: '...' },路径相对于 fpd_root 和 fpd_out
|
|
163
|
-
- assets_root?: `'/'` 生成的 html
|
|
164
|
-
|
|
180
|
+
- assets_root?: `'/'` 生成的 html 中替换 {root} 作为部署路径,以支持 browser router 路由能力
|
|
181
|
+
assets, html 中的 icon, scripts 路径直接在前面添加 assets_root 来生成最终 html href
|
|
165
182
|
未启用时使用相对 html 路径来生成最终 html href
|
|
166
183
|
- template?: `false` 除了生成对应的 html 之外,还生成所有路径为 `{root}/...` 的模板 html 文件, 方便后续 server 替换渲染
|
|
167
184
|
- single_js?: 设置生成的单个 js 入口文件,无其他依赖,通过 script module 作为入口加载,含有 import 加载其他 externals 和某个 entry,类似 htmls 配置要生成的 html
|
|
168
185
|
- js: js 入口文件名
|
|
169
186
|
- entry: 使用的 entry
|
|
170
|
-
- local_loaders?: `true` true 时使用项目 node_modules/ 中的 loader; false 时使用 D:/0/ 下面的
|
|
171
187
|
- commonjs2?: `false` 打包为 commonjs2 (.cjs) 的文件
|
|
172
188
|
- expose?: `false` 入口模块所有导出的属性赋值到全局对象 globalThis 上
|
|
173
189
|
- single_chunk?: `true` 输出为单个文件,将依赖也打包到其中,不要生成多个 chunk
|
|
@@ -179,330 +195,320 @@ export class Bundler {
|
|
|
179
195
|
- dts?: `false` 生成 .d.ts 文件
|
|
180
196
|
- exclude_modules?: 传入正则表达式 ,匹配时使用 IgnorePlugin 强制不打包这个模块,但是一旦导入就会报错
|
|
181
197
|
- cache_version?: webpack cache version, 用于区分同一个 name 的不同版本
|
|
182
|
-
- production?: `true` webpack mode 设置为 'production'
|
|
183
|
-
- sass?: 传入 sass 实例避免 webpack 重复加载 .cjs 版本
|
|
184
198
|
- plugins?: 可选传入的额外的 webpack 插件
|
|
185
199
|
- license?: 使用 license-webpack-plugin 构建 ThirdPartyNotice.txt
|
|
186
200
|
- polyfill_node_sea?: 避免依赖 node:sea 模块以兼容旧版本 node.js */
|
|
187
|
-
constructor(name, target, fpd_root, fpd_out, fpdt_cache, entry,
|
|
201
|
+
constructor(name, target, fpd_root, fpd_out, fpdt_cache, entry, options = {}) {
|
|
188
202
|
this.name = name;
|
|
189
|
-
this.analyzer = analyzer;
|
|
190
|
-
this.production = production;
|
|
191
203
|
this.target = target;
|
|
192
204
|
this.fpd_root = fpd_root;
|
|
193
205
|
this.fpd_out = fpd_out;
|
|
194
|
-
this.
|
|
195
|
-
this.
|
|
196
|
-
this
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
this.
|
|
200
|
-
this.globals = globals;
|
|
201
|
-
this.exclude_modules = exclude_modules;
|
|
202
|
-
this.plugins = plugins;
|
|
203
|
-
if (dependencies) {
|
|
204
|
-
check(target === 'web');
|
|
205
|
-
this.dependencies = dependencies;
|
|
206
|
-
}
|
|
207
|
-
if (expose && commonjs2)
|
|
206
|
+
this.fpdt_cache = fpdt_cache;
|
|
207
|
+
this.entry = entry;
|
|
208
|
+
Object.assign(this, options);
|
|
209
|
+
if (options.dependencies?.length && target !== 'web')
|
|
210
|
+
throw new Error('仅 target === web 时才需要配置 dependencies');
|
|
211
|
+
if (this.expose && this.commonjs2)
|
|
208
212
|
throw new Error('expose 和 commonjs2 不能同时启用');
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
this.
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
publicPath: '/',
|
|
229
|
-
pathinfo: true,
|
|
230
|
-
globalObject: 'globalThis',
|
|
231
|
-
module: output_module,
|
|
232
|
-
// 在 bundle 中导出 entry 文件的 export
|
|
233
|
-
library: {
|
|
234
|
-
type: commonjs2 ? 'commonjs2' : expose ? 'global' : 'module',
|
|
235
|
-
},
|
|
236
|
-
...single_chunk ? {
|
|
237
|
-
chunkLoading: false
|
|
238
|
-
} : {},
|
|
239
|
-
},
|
|
240
|
-
target: [target === 'web' ? 'web' : 'node23', 'es2024'],
|
|
241
|
-
// 结合 output.globalObject, 会生成 globalThis['React'] 这样的引用
|
|
242
|
-
externalsType: target === 'nodejs' ? 'commonjs2' : 'global',
|
|
243
|
-
// 以 react: 'React', 为例,含义为
|
|
244
|
-
// 取全局变量 window.React 的值作为 import { useState } from 'react' 中 { ... } 这部分的结果,再解构里面的 useState 属性
|
|
245
|
-
externals: filter_values({
|
|
246
|
-
react: 'React',
|
|
247
|
-
'react/jsx-runtime': 'ReactJSX',
|
|
248
|
-
'react-dom': 'ReactDOM',
|
|
249
|
-
'react-dom/client': 'ReactDOMClient',
|
|
250
|
-
jquery: '$',
|
|
251
|
-
...target === 'web' ? {
|
|
252
|
-
lodash: '_',
|
|
253
|
-
} : {
|
|
254
|
-
vscode: 'commonjs2 vscode'
|
|
255
|
-
},
|
|
256
|
-
// import { Terminal } from 'xterm'
|
|
257
|
-
// 实际上 Terminal 直接暴露在了 window 上,而不是 window.Terminal.Terminal
|
|
258
|
-
'@xterm/xterm': 'window',
|
|
259
|
-
swiper: 'Swiper',
|
|
260
|
-
...external_dayjs ? { dayjs: 'dayjs' } : {},
|
|
261
|
-
antd: 'antd',
|
|
262
|
-
'@ant-design/icons': 'icons',
|
|
263
|
-
'@ant-design/plots': 'Plots',
|
|
264
|
-
echarts: 'echarts',
|
|
265
|
-
...externals
|
|
266
|
-
}),
|
|
267
|
-
resolve: {
|
|
268
|
-
symlinks: true,
|
|
269
|
-
extensions: ['.js'],
|
|
270
|
-
extensionAlias: {
|
|
271
|
-
'.js': ['.js', '.ts', '.tsx']
|
|
272
|
-
},
|
|
273
|
-
...resolve_alias ? { alias: resolve_alias } : {},
|
|
274
|
-
// modules: [
|
|
275
|
-
// '',
|
|
276
|
-
// ],
|
|
277
|
-
...resolve_fallback ? { fallback: resolve_fallback } : {},
|
|
278
|
-
// fallback: {
|
|
279
|
-
// os: false,
|
|
280
|
-
// }
|
|
281
|
-
},
|
|
282
|
-
...sass ? {
|
|
283
|
-
loader: { sass }
|
|
284
|
-
} : {},
|
|
285
|
-
module: {
|
|
286
|
-
...dynamic_import === false ? {
|
|
287
|
-
parser: {
|
|
288
|
-
javascript: {
|
|
289
|
-
// 保留 await import() 这样的引用
|
|
290
|
-
import: false,
|
|
291
|
-
// dynamicImportMode: 'weak',
|
|
292
|
-
}
|
|
213
|
+
}
|
|
214
|
+
async build(print = true) {
|
|
215
|
+
if (!this.lcompiler)
|
|
216
|
+
await (this.lcompiler = new Lock()).request(async () => {
|
|
217
|
+
const { default: Webpack } = await import('webpack');
|
|
218
|
+
const output_module = !this.commonjs2 && !this.expose;
|
|
219
|
+
// let smp = new SpeedMeasurePlugin()
|
|
220
|
+
// const config: Webpack.Configuration = smp.wrap({
|
|
221
|
+
let resolve_cache = {};
|
|
222
|
+
const get_loader = (name) => resolve_cache[name] ??= fileURLToPath(import.meta.resolve(`${name}/package.json`)).fdir;
|
|
223
|
+
const sass = this.target === 'web' ? await import('sass') : undefined;
|
|
224
|
+
this.lcompiler.resource = Webpack(this.config = {
|
|
225
|
+
name: this.name,
|
|
226
|
+
mode: this.production ? 'production' : 'development',
|
|
227
|
+
devtool: this.source_map ? 'source-map' : false,
|
|
228
|
+
context: this.fpd_root,
|
|
229
|
+
entry: this.entry,
|
|
230
|
+
experiments: {
|
|
231
|
+
outputModule: output_module,
|
|
293
232
|
},
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
233
|
+
output: {
|
|
234
|
+
path: this.fpd_out,
|
|
235
|
+
filename: '[name]',
|
|
236
|
+
publicPath: '/',
|
|
237
|
+
pathinfo: true,
|
|
238
|
+
globalObject: 'globalThis',
|
|
239
|
+
module: output_module,
|
|
240
|
+
// 在 bundle 中导出 entry 文件的 export
|
|
241
|
+
library: {
|
|
242
|
+
type: this.commonjs2 ? 'commonjs2' : this.expose ? 'global' : 'module',
|
|
301
243
|
},
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
244
|
+
...this.single_chunk ? {
|
|
245
|
+
chunkLoading: false
|
|
246
|
+
} : {},
|
|
247
|
+
},
|
|
248
|
+
target: [this.target === 'web' ? 'web' : 'node23', 'es2024'],
|
|
249
|
+
// 结合 output.globalObject, 会生成 globalThis['React'] 这样的引用
|
|
250
|
+
externalsType: this.target === 'nodejs' ? 'commonjs2' : 'global',
|
|
251
|
+
// 以 react: 'React', 为例,含义为
|
|
252
|
+
// 取全局变量 window.React 的值作为 import { useState } from 'react' 中 { ... } 这部分的结果,再解构里面的 useState 属性
|
|
253
|
+
externals: filter_values({
|
|
254
|
+
react: 'React',
|
|
255
|
+
'react/jsx-runtime': 'ReactJSX',
|
|
256
|
+
'react-dom': 'ReactDOM',
|
|
257
|
+
'react-dom/client': 'ReactDOMClient',
|
|
258
|
+
jquery: '$',
|
|
259
|
+
...this.target === 'web' ? {
|
|
260
|
+
lodash: '_',
|
|
261
|
+
} : {
|
|
262
|
+
vscode: 'commonjs2 vscode'
|
|
263
|
+
},
|
|
264
|
+
// import { Terminal } from 'xterm'
|
|
265
|
+
// 实际上 Terminal 直接暴露在了 window 上,而不是 window.Terminal.Terminal
|
|
266
|
+
'@xterm/xterm': 'window',
|
|
267
|
+
swiper: 'Swiper',
|
|
268
|
+
...this.external_dayjs ? { dayjs: 'dayjs' } : {},
|
|
269
|
+
antd: 'antd',
|
|
270
|
+
'@ant-design/icons': 'icons',
|
|
271
|
+
'@ant-design/plots': 'Plots',
|
|
272
|
+
echarts: 'echarts',
|
|
273
|
+
...this.externals
|
|
274
|
+
}),
|
|
275
|
+
resolve: {
|
|
276
|
+
symlinks: true,
|
|
277
|
+
extensions: ['.js'],
|
|
278
|
+
extensionAlias: {
|
|
279
|
+
'.js': ['.js', '.ts', '.tsx']
|
|
280
|
+
},
|
|
281
|
+
...this.resolve_alias ? { alias: this.resolve_alias } : {},
|
|
282
|
+
// modules: [
|
|
283
|
+
// '',
|
|
284
|
+
// ],
|
|
285
|
+
...this.resolve_fallback ? { fallback: this.resolve_fallback } : {},
|
|
286
|
+
// fallback: {
|
|
287
|
+
// os: false,
|
|
288
|
+
// }
|
|
325
289
|
},
|
|
326
|
-
|
|
327
|
-
{
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
290
|
+
module: {
|
|
291
|
+
...this.dynamic_import === false ? {
|
|
292
|
+
parser: {
|
|
293
|
+
javascript: {
|
|
294
|
+
// 保留 await import() 这样的引用
|
|
295
|
+
import: false,
|
|
296
|
+
// dynamicImportMode: 'weak',
|
|
297
|
+
}
|
|
298
|
+
},
|
|
299
|
+
} : {},
|
|
300
|
+
rules: [
|
|
301
|
+
...this.source_map ? [
|
|
331
302
|
{
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
url: false,
|
|
336
|
-
}
|
|
303
|
+
test: /\.js$/,
|
|
304
|
+
enforce: 'pre',
|
|
305
|
+
use: [get_loader('source-map-loader')],
|
|
337
306
|
},
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
307
|
+
] : [],
|
|
308
|
+
{
|
|
309
|
+
test: this.target === 'nodejs' ? /\.ts$/ : /\.tsx?$/,
|
|
310
|
+
exclude: /node_modules/,
|
|
311
|
+
loader: get_loader('ts-loader'),
|
|
312
|
+
// https://github.com/TypeStrong/ts-loader
|
|
313
|
+
options: {
|
|
314
|
+
configFile: `${this.fpd_root}tsconfig.json`,
|
|
315
|
+
onlyCompileBundledFiles: true,
|
|
316
|
+
transpileOnly: !this.dts,
|
|
317
|
+
compilerOptions: {
|
|
318
|
+
module: 'ESNext',
|
|
319
|
+
moduleResolution: 'Bundler',
|
|
320
|
+
declaration: this.dts,
|
|
321
|
+
noEmit: false,
|
|
322
|
+
allowImportingTsExtensions: false,
|
|
323
|
+
...this.commonjs2 ? {
|
|
324
|
+
// 编译为 commonjs 后 import 的依赖是通过 require 引入的,所以需要 interop 去生成 default
|
|
325
|
+
// nodejs 默认的 import 会自动加上 default,所以不需要 interop
|
|
326
|
+
esModuleInterop: true
|
|
345
327
|
} : {},
|
|
346
|
-
// 解决 url(search.png) 打包出错的问题
|
|
347
|
-
webpackImporter: false,
|
|
348
|
-
sassOptions: {
|
|
349
|
-
indentWidth: 4,
|
|
350
|
-
}
|
|
351
328
|
}
|
|
352
|
-
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
{
|
|
356
|
-
test: /\.css$/,
|
|
357
|
-
use: [get_loader('style-loader'), get_loader('css-loader')]
|
|
358
|
-
},
|
|
359
|
-
{
|
|
360
|
-
oneOf: [
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
...this.target === 'web' ? [
|
|
361
332
|
{
|
|
362
|
-
test: /\.
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
333
|
+
test: /\.s[ac]ss$/,
|
|
334
|
+
use: [
|
|
335
|
+
get_loader('style-loader'),
|
|
336
|
+
{
|
|
337
|
+
// https://github.com/webpack-contrib/css-loader
|
|
338
|
+
loader: get_loader('css-loader'),
|
|
339
|
+
options: {
|
|
340
|
+
url: false,
|
|
341
|
+
}
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
// https://webpack.js.org/loaders/sass-loader
|
|
345
|
+
loader: get_loader('sass-loader'),
|
|
346
|
+
options: {
|
|
347
|
+
api: 'modern-compiler',
|
|
348
|
+
...sass ? {
|
|
349
|
+
implementation: sass
|
|
350
|
+
} : {},
|
|
351
|
+
// 解决 url(search.png) 打包出错的问题
|
|
352
|
+
webpackImporter: false,
|
|
353
|
+
sassOptions: {
|
|
354
|
+
indentWidth: 4,
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
},
|
|
358
|
+
]
|
|
366
359
|
},
|
|
367
360
|
{
|
|
368
|
-
test: /\.
|
|
369
|
-
|
|
361
|
+
test: /\.css$/,
|
|
362
|
+
use: [get_loader('style-loader'), get_loader('css-loader')]
|
|
370
363
|
},
|
|
371
364
|
{
|
|
372
|
-
|
|
373
|
-
|
|
365
|
+
oneOf: [
|
|
366
|
+
{
|
|
367
|
+
test: /\.icon\.svg$/,
|
|
368
|
+
issuer: /\.[jt]sx?$/,
|
|
369
|
+
loader: get_loader('@svgr/webpack'),
|
|
370
|
+
options: { icon: true }
|
|
371
|
+
},
|
|
372
|
+
{
|
|
373
|
+
test: /\.raw\.svg$/,
|
|
374
|
+
type: 'asset/source',
|
|
375
|
+
},
|
|
376
|
+
{
|
|
377
|
+
test: /\.(svg|ico|png|jpe?g|gif|woff2?|ttf|eot|otf|mp4|webm|ogg|mp3|wav|flac|aac)$/,
|
|
378
|
+
type: 'asset/inline',
|
|
379
|
+
},
|
|
380
|
+
]
|
|
374
381
|
},
|
|
375
|
-
]
|
|
382
|
+
] : [],
|
|
383
|
+
{
|
|
384
|
+
test: /\.(txt|csv|dos)$/,
|
|
385
|
+
type: 'asset/source',
|
|
386
|
+
}
|
|
387
|
+
]
|
|
388
|
+
},
|
|
389
|
+
...sass ? {
|
|
390
|
+
loader: {
|
|
391
|
+
sass
|
|
376
392
|
},
|
|
377
|
-
|
|
378
|
-
{
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
factory.hooks.beforeResolve.tap(external_polyfill_plugin_name, data => {
|
|
488
|
-
if (data.request === builtin_module) {
|
|
489
|
-
data.request = fp_polyfill;
|
|
490
|
-
// 一定要改 dependencies,否则会创建 ExternalModule,不走 NormalModule 的 resolve 过程
|
|
491
|
-
data.dependencies.forEach(dep => {
|
|
492
|
-
if (dep.request === builtin_module) {
|
|
493
|
-
dep.request = fp_polyfill;
|
|
494
|
-
dep.userRequest = fp_polyfill;
|
|
393
|
+
} : {},
|
|
394
|
+
optimization: {
|
|
395
|
+
minimize: false
|
|
396
|
+
},
|
|
397
|
+
cache: {
|
|
398
|
+
type: 'filesystem',
|
|
399
|
+
compression: false,
|
|
400
|
+
cacheDirectory: this.fpdt_cache,
|
|
401
|
+
...this.cache_version ? {
|
|
402
|
+
version: this.cache_version
|
|
403
|
+
} : {}
|
|
404
|
+
},
|
|
405
|
+
ignoreWarnings: [
|
|
406
|
+
...this.source_map ? [/Failed to parse source map/] : [],
|
|
407
|
+
...this.license ? [
|
|
408
|
+
/** LicenseWebpackPlugin 会添加过时的 string 类型的 warning,无法被正则表达式的逻辑匹配,这里只能手动用函数过滤 */
|
|
409
|
+
(warning) => typeof warning === 'string' && warning.startsWith('license-webpack-plugin: could not find any license ')
|
|
410
|
+
] : [],
|
|
411
|
+
...this.target === 'nodejs' ? [
|
|
412
|
+
/Can't resolve '(bufferutil|utf-8-validate)'/,
|
|
413
|
+
// 打包 ali-oss 时可能的报错
|
|
414
|
+
(warning) => {
|
|
415
|
+
if (!warning)
|
|
416
|
+
return false;
|
|
417
|
+
const { message, module } = warning;
|
|
418
|
+
if (!message)
|
|
419
|
+
return false;
|
|
420
|
+
const fp = module?.context?.fp || '';
|
|
421
|
+
if (message.includes('the request of a dependency is an expression'))
|
|
422
|
+
return fp.endsWith('any-promise') ||
|
|
423
|
+
fp.includes('/@sqltools/base-driver/');
|
|
424
|
+
else if (message.includes('require function is used in a way in which dependencies cannot be statically extracted'))
|
|
425
|
+
return fp.includes('/vscode-languageserver-types/');
|
|
426
|
+
else
|
|
427
|
+
return false;
|
|
428
|
+
}
|
|
429
|
+
] : [],
|
|
430
|
+
...this.name === 'react' ? [/export '(createRoot|hydrateRoot)' \(imported as 'ReactDOM'\) was not found in 'react-dom'/] : []
|
|
431
|
+
],
|
|
432
|
+
performance: {
|
|
433
|
+
hints: false,
|
|
434
|
+
},
|
|
435
|
+
stats: {
|
|
436
|
+
colors: true,
|
|
437
|
+
context: this.fpd_root,
|
|
438
|
+
entrypoints: false,
|
|
439
|
+
errors: true,
|
|
440
|
+
errorDetails: true,
|
|
441
|
+
hash: false,
|
|
442
|
+
version: false,
|
|
443
|
+
timings: true,
|
|
444
|
+
children: true,
|
|
445
|
+
assets: this.assets_stats,
|
|
446
|
+
assetsSpace: 20,
|
|
447
|
+
modules: false,
|
|
448
|
+
modulesSpace: 20,
|
|
449
|
+
cachedAssets: false,
|
|
450
|
+
cachedModules: false,
|
|
451
|
+
chunks: false,
|
|
452
|
+
// logging: 'info',
|
|
453
|
+
},
|
|
454
|
+
plugins: [
|
|
455
|
+
...this.globals ? [
|
|
456
|
+
new Webpack.DefinePlugin({
|
|
457
|
+
...this.globals
|
|
458
|
+
// process: { env: { }, argv: [] }
|
|
459
|
+
})
|
|
460
|
+
] : [],
|
|
461
|
+
// 使用 IgnorePlugin 能够不打包,但是一旦导入就会报错
|
|
462
|
+
...this.exclude_modules ? [
|
|
463
|
+
new Webpack.IgnorePlugin({
|
|
464
|
+
resourceRegExp: this.exclude_modules,
|
|
465
|
+
// checkResource: (resource, context) =>
|
|
466
|
+
// resource.startsWith('./vendors/') && !context.fp.startsWith(fpd_node_modules) ,
|
|
467
|
+
})
|
|
468
|
+
] : [],
|
|
469
|
+
...this.analyzer ? await (async () => {
|
|
470
|
+
const { BundleAnalyzerPlugin } = await import('webpack-bundle-analyzer');
|
|
471
|
+
return [
|
|
472
|
+
new BundleAnalyzerPlugin({
|
|
473
|
+
analyzerPort: 8880,
|
|
474
|
+
openAnalyzer: false,
|
|
475
|
+
})
|
|
476
|
+
];
|
|
477
|
+
})() : [],
|
|
478
|
+
...this.license ? await (async () => {
|
|
479
|
+
const { LicenseWebpackPlugin } = await import('license-webpack-plugin');
|
|
480
|
+
return [
|
|
481
|
+
new LicenseWebpackPlugin({
|
|
482
|
+
perChunkOutput: false,
|
|
483
|
+
outputFilename: 'ThirdPartyNotice.txt',
|
|
484
|
+
})
|
|
485
|
+
];
|
|
486
|
+
})() : [],
|
|
487
|
+
...this.polyfill_node_sea ? [{
|
|
488
|
+
apply(compiler) {
|
|
489
|
+
const external_polyfill_plugin_name = 'MyNodejsBuiltinModuleReplacementPlugin';
|
|
490
|
+
const builtin_module = 'node:sea';
|
|
491
|
+
const fp_polyfill = `${import.meta.dirname.fpd}node-sea.polyfill.js`;
|
|
492
|
+
compiler.hooks.normalModuleFactory.tap(external_polyfill_plugin_name, factory => {
|
|
493
|
+
factory.hooks.beforeResolve.tap(external_polyfill_plugin_name, data => {
|
|
494
|
+
if (data.request === builtin_module) {
|
|
495
|
+
data.request = fp_polyfill;
|
|
496
|
+
// 一定要改 dependencies,否则会创建 ExternalModule,不走 NormalModule 的 resolve 过程
|
|
497
|
+
data.dependencies.forEach(dep => {
|
|
498
|
+
if (dep.request === builtin_module) {
|
|
499
|
+
dep.request = fp_polyfill;
|
|
500
|
+
dep.userRequest = fp_polyfill;
|
|
501
|
+
}
|
|
502
|
+
});
|
|
495
503
|
}
|
|
496
504
|
});
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
this.lcompiler = new Lock(Webpack(this.config));
|
|
505
|
-
}
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
}] : [],
|
|
508
|
+
...this.plugins || [],
|
|
509
|
+
]
|
|
510
|
+
});
|
|
511
|
+
});
|
|
506
512
|
const stats = await this.lcompiler.request(async (compiler) => new Promise((resolve, reject) => {
|
|
507
513
|
compiler.run((error, stats) => {
|
|
508
514
|
if (error)
|
package/net.js
CHANGED
|
@@ -108,7 +108,7 @@ export async function request(url, options = {}) {
|
|
|
108
108
|
let headers = {
|
|
109
109
|
'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,ja-JP;q=0.6,ja;q=0.5',
|
|
110
110
|
'accept-encoding': 'gzip, deflate, br',
|
|
111
|
-
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/
|
|
111
|
+
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36',
|
|
112
112
|
'sec-ch-ua-platform': '"Windows"',
|
|
113
113
|
'sec-ch-ua-platform-version': '"15.0.0"',
|
|
114
114
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xshell",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.44",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|
|
@@ -64,15 +64,15 @@
|
|
|
64
64
|
"chalk": "^5.4.1",
|
|
65
65
|
"cli-table3": "^0.6.5",
|
|
66
66
|
"cli-truncate": "^4.0.0",
|
|
67
|
-
"commander": "^
|
|
67
|
+
"commander": "^14.0.0",
|
|
68
68
|
"css-loader": "^7.1.2",
|
|
69
69
|
"emoji-regex": "^10.4.0",
|
|
70
|
-
"eslint": "^9.
|
|
70
|
+
"eslint": "^9.27.0",
|
|
71
71
|
"eslint-plugin-import": "^2.31.0",
|
|
72
72
|
"eslint-plugin-react": "^7.37.5",
|
|
73
73
|
"gulp-sort": "^2.0.0",
|
|
74
74
|
"https-proxy-agent": "^7.0.6",
|
|
75
|
-
"i18next": "^25.
|
|
75
|
+
"i18next": "^25.2.0",
|
|
76
76
|
"i18next-scanner": "^4.6.0",
|
|
77
77
|
"koa": "^3.0.0",
|
|
78
78
|
"koa-compress": "^5.1.1",
|
|
@@ -84,7 +84,7 @@
|
|
|
84
84
|
"react-i18next": "^15.5.1",
|
|
85
85
|
"react-object-model": "^1.2.24",
|
|
86
86
|
"resolve-path": "^1.4.0",
|
|
87
|
-
"sass": "^1.
|
|
87
|
+
"sass": "^1.89.0",
|
|
88
88
|
"sass-loader": "^16.0.5",
|
|
89
89
|
"source-map-loader": "^5.0.0",
|
|
90
90
|
"strip-ansi": "^7.1.0",
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
"@types/koa": "^2.15.0",
|
|
113
113
|
"@types/koa-compress": "^4.0.6",
|
|
114
114
|
"@types/mime-types": "^2.1.4",
|
|
115
|
-
"@types/node": "^22.15.
|
|
115
|
+
"@types/node": "^22.15.19",
|
|
116
116
|
"@types/react": "^19.1.4",
|
|
117
117
|
"@types/through2": "^2.0.41",
|
|
118
118
|
"@types/tough-cookie": "^4.0.5",
|
package/process.js
CHANGED
|
@@ -47,7 +47,7 @@ input, stdin = Boolean(input), stdout = !detached, stderr = stdout, print = true
|
|
|
47
47
|
...proxy ? {
|
|
48
48
|
http_proxy: proxy,
|
|
49
49
|
https_proxy: proxy,
|
|
50
|
-
no_proxy: '127.0.0.1
|
|
50
|
+
no_proxy: 'localhost,127.0.0.1'
|
|
51
51
|
} : {},
|
|
52
52
|
...envs
|
|
53
53
|
});
|
package/prototype.browser.d.ts
CHANGED
|
@@ -170,7 +170,9 @@ declare global {
|
|
|
170
170
|
last: T;
|
|
171
171
|
indent(this: string[], width?: number, c?: string): string[];
|
|
172
172
|
/** 对数组中所有元素求和 (+), 返回结果,可传入 mapper 计算出某个值,用作求和 */
|
|
173
|
-
sum<
|
|
173
|
+
sum<TKey extends keyof T>(this: T[], zero: T[TKey], mapper: TKey): T[TKey];
|
|
174
|
+
sum<TMapper extends Mapper<T>>(this: T[], zero: ReturnType<TMapper>, mapper: TMapper): ReturnType<TMapper>;
|
|
175
|
+
sum<TReturn = T>(this: T[], zero: TReturn, mapper?: keyof T | Mapper<T>): TReturn;
|
|
174
176
|
/** 查找数组中最大的元素,可传入 mapper 计算出某个值,用作大小比较 */
|
|
175
177
|
max(this: T[], mapper?: keyof T | Mapper<T>): T;
|
|
176
178
|
/** 查找数组中最小的元素,可传入 mapper 计算出某个值,用作大小比较 */
|
package/prototype.browser.js
CHANGED
|
@@ -501,17 +501,17 @@ Object.defineProperties(Array.prototype, {
|
|
|
501
501
|
const indent = character.repeat(width);
|
|
502
502
|
return this.map(line => indent + line);
|
|
503
503
|
},
|
|
504
|
-
sum(mapper) {
|
|
504
|
+
sum(zero, mapper) {
|
|
505
505
|
if (!this.length)
|
|
506
506
|
return undefined;
|
|
507
507
|
// 快捷路径
|
|
508
508
|
const first = this[0];
|
|
509
509
|
if ((typeof first === 'number' || typeof first === 'bigint') && !mapper)
|
|
510
|
-
return this.reduce((acc, x) => acc + x,
|
|
510
|
+
return this.reduce((acc, x) => acc + x, zero);
|
|
511
511
|
if (is_key_type(mapper))
|
|
512
512
|
mapper = build_mapper(mapper);
|
|
513
513
|
mapper ??= ident;
|
|
514
|
-
return this.reduce((acc, x) => acc + mapper(x),
|
|
514
|
+
return this.reduce((acc, x) => acc + mapper(x), zero);
|
|
515
515
|
},
|
|
516
516
|
max(mapper = ident) {
|
|
517
517
|
if (!this.length)
|
package/prototype.d.ts
CHANGED
|
@@ -195,7 +195,9 @@ declare global {
|
|
|
195
195
|
indent(this: string[], width?: number, c?: string): string[];
|
|
196
196
|
indent2to4(this: string[]): string[];
|
|
197
197
|
/** 对数组中所有元素求和 (+), 返回结果,可传入 mapper 计算出某个值,用作求和 */
|
|
198
|
-
sum<
|
|
198
|
+
sum<TKey extends keyof T>(this: T[], zero: T[TKey], mapper: TKey): T[TKey];
|
|
199
|
+
sum<TMapper extends Mapper<T>>(this: T[], zero: ReturnType<TMapper>, mapper: TMapper): ReturnType<TMapper>;
|
|
200
|
+
sum<TReturn = T>(this: T[], zero: TReturn, mapper?: keyof T | Mapper<T>): TReturn;
|
|
199
201
|
/** 查找数组中最大的元素,可传入 mapper 计算出某个值,用作大小比较 */
|
|
200
202
|
max(this: T[], mapper?: keyof T | Mapper<T>): T;
|
|
201
203
|
/** 查找数组中最小的元素,可传入 mapper 计算出某个值,用作大小比较 */
|
package/prototype.js
CHANGED
|
@@ -574,17 +574,17 @@ if (!globalThis.my_prototype_defined) {
|
|
|
574
574
|
return this.split_indents()
|
|
575
575
|
.map(line => ' '.repeat(line.indent * 2) + line.text);
|
|
576
576
|
},
|
|
577
|
-
sum(mapper) {
|
|
577
|
+
sum(zero, mapper) {
|
|
578
578
|
if (!this.length)
|
|
579
579
|
return undefined;
|
|
580
580
|
// 快捷路径
|
|
581
581
|
const first = this[0];
|
|
582
582
|
if ((typeof first === 'number' || typeof first === 'bigint') && !mapper)
|
|
583
|
-
return this.reduce((acc, x) => acc + x,
|
|
583
|
+
return this.reduce((acc, x) => acc + x, zero);
|
|
584
584
|
if (is_key_type(mapper))
|
|
585
585
|
mapper = build_mapper(mapper);
|
|
586
586
|
mapper ??= ident;
|
|
587
|
-
return this.reduce((acc, x) => acc + mapper(x),
|
|
587
|
+
return this.reduce((acc, x) => acc + mapper(x), zero);
|
|
588
588
|
},
|
|
589
589
|
max(mapper = ident) {
|
|
590
590
|
if (!this.length)
|