xshell 1.0.129 → 1.0.131
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 +20 -4
- package/builder.js +51 -6
- package/package.json +2 -1
package/builder.d.ts
CHANGED
|
@@ -4,23 +4,30 @@ export interface BundlerOptions {
|
|
|
4
4
|
source_map?: boolean;
|
|
5
5
|
production?: boolean;
|
|
6
6
|
external_dayjs?: boolean;
|
|
7
|
-
externals?: Record<string, string>;
|
|
7
|
+
externals?: Record<string, string | string[]>;
|
|
8
8
|
sass?: typeof import('sass');
|
|
9
9
|
dynamic_import?: boolean;
|
|
10
10
|
commonjs2?: boolean;
|
|
11
11
|
assets_stats?: boolean;
|
|
12
12
|
globals?: Record<string, string>;
|
|
13
|
+
resolve_alias?: Record<string, string>;
|
|
13
14
|
analyzer?: boolean;
|
|
14
15
|
dts?: boolean;
|
|
15
16
|
cache_version?: string;
|
|
16
17
|
single_chunk?: boolean;
|
|
17
18
|
exclude_modules?: RegExp;
|
|
19
|
+
license?: {
|
|
20
|
+
ignores?: string[];
|
|
21
|
+
};
|
|
18
22
|
}
|
|
19
23
|
export declare class Bundler {
|
|
20
24
|
name: string;
|
|
21
25
|
fpd_root: string;
|
|
22
26
|
config: Webpack.Configuration;
|
|
23
27
|
analyzer: boolean;
|
|
28
|
+
license?: {
|
|
29
|
+
ignores?: string[];
|
|
30
|
+
};
|
|
24
31
|
lcompiler: Lock<Webpack.Compiler>;
|
|
25
32
|
/** 通过 webpack 从入口文件打包所有依赖生成单个 index.{mjs,cjs} 文件
|
|
26
33
|
- name: 项目名称
|
|
@@ -36,15 +43,24 @@ export declare class Bundler {
|
|
|
36
43
|
- externals?: 配置外部模块
|
|
37
44
|
- commonjs2?: `false` 打包为 commonjs2 (.cjs) 的文件
|
|
38
45
|
- single_chunk?: `true` 输出为单个文件,将依赖也打包到其中,不要生成多个 chunk
|
|
39
|
-
- dynamic_import
|
|
46
|
+
- dynamic_import?: `true` 对于 await import('...') 要不要打包外部模块到输出文件中
|
|
47
|
+
- resolve_alias?: 配置 resolve alias
|
|
40
48
|
- assets_stats?: `true` 打印输出的文件信息
|
|
41
49
|
- analyzer?: `false` 启用 WebpackBundleAnalyzer 插件分析构建产物大小
|
|
42
50
|
- dts?: `false` 生成 .d.ts 文件
|
|
43
51
|
- exclude_modules?: 传入正则表达式 ,匹配时使用 IgnorePlugin 强制不打包这个模块,但是一旦导入就会报错
|
|
44
52
|
- cache_version?: webpack cache version, 用于区分同一个 name 的不同版本
|
|
45
53
|
- production?: `true` webpack mode 设置为 'production'
|
|
46
|
-
- sass?: 传入 sass 实例避免 webpack 重复加载 .cjs 版本
|
|
47
|
-
|
|
54
|
+
- sass?: 传入 sass 实例避免 webpack 重复加载 .cjs 版本
|
|
55
|
+
- license?: 使用 license-webpack-plugin 构建 ThirdPartyNotice.txt */
|
|
56
|
+
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, commonjs2, single_chunk, dynamic_import, resolve_alias, assets_stats, analyzer, dts, exclude_modules, cache_version, production, sass, license, }?: BundlerOptions);
|
|
57
|
+
/** 获取构建时 git 仓库的最新提交、分支信息 */
|
|
58
|
+
get_git_info(version?: string): Promise<{
|
|
59
|
+
version: string;
|
|
60
|
+
branch: string;
|
|
61
|
+
time: string;
|
|
62
|
+
commit: string;
|
|
63
|
+
}>;
|
|
48
64
|
build(print?: boolean): Promise<void>;
|
|
49
65
|
close(): Promise<void>;
|
|
50
66
|
build_and_close(print?: boolean): Promise<void>;
|
package/builder.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { fileURLToPath } from 'url';
|
|
2
2
|
import Webpack from 'webpack';
|
|
3
3
|
import { Lock, Timer, filter_values } from './utils.js';
|
|
4
|
+
import { Git } from './git.js';
|
|
4
5
|
export class Bundler {
|
|
5
6
|
name;
|
|
6
7
|
fpd_root;
|
|
7
8
|
config;
|
|
8
9
|
analyzer;
|
|
10
|
+
license;
|
|
9
11
|
lcompiler;
|
|
10
12
|
/** 通过 webpack 从入口文件打包所有依赖生成单个 index.{mjs,cjs} 文件
|
|
11
13
|
- name: 项目名称
|
|
@@ -21,17 +23,20 @@ export class Bundler {
|
|
|
21
23
|
- externals?: 配置外部模块
|
|
22
24
|
- commonjs2?: `false` 打包为 commonjs2 (.cjs) 的文件
|
|
23
25
|
- single_chunk?: `true` 输出为单个文件,将依赖也打包到其中,不要生成多个 chunk
|
|
24
|
-
- dynamic_import
|
|
26
|
+
- dynamic_import?: `true` 对于 await import('...') 要不要打包外部模块到输出文件中
|
|
27
|
+
- resolve_alias?: 配置 resolve alias
|
|
25
28
|
- assets_stats?: `true` 打印输出的文件信息
|
|
26
29
|
- analyzer?: `false` 启用 WebpackBundleAnalyzer 插件分析构建产物大小
|
|
27
30
|
- dts?: `false` 生成 .d.ts 文件
|
|
28
31
|
- exclude_modules?: 传入正则表达式 ,匹配时使用 IgnorePlugin 强制不打包这个模块,但是一旦导入就会报错
|
|
29
32
|
- cache_version?: webpack cache version, 用于区分同一个 name 的不同版本
|
|
30
33
|
- production?: `true` webpack mode 设置为 'production'
|
|
31
|
-
- sass?: 传入 sass 实例避免 webpack 重复加载 .cjs 版本
|
|
32
|
-
|
|
34
|
+
- sass?: 传入 sass 实例避免 webpack 重复加载 .cjs 版本
|
|
35
|
+
- license?: 使用 license-webpack-plugin 构建 ThirdPartyNotice.txt */
|
|
36
|
+
constructor(name, target, fpd_root, fpd_out, fpdt_cache, entry, { source_map = true, globals, external_dayjs = false, externals, commonjs2 = false, single_chunk = true, dynamic_import = true, resolve_alias, assets_stats = true, analyzer = false, dts = false, exclude_modules, cache_version, production = true, sass, license, } = {}) {
|
|
33
37
|
this.name = name;
|
|
34
38
|
this.analyzer = analyzer;
|
|
39
|
+
this.license = license;
|
|
35
40
|
// let smp = new SpeedMeasurePlugin()
|
|
36
41
|
// const config: Webpack.Configuration = smp.wrap({
|
|
37
42
|
let resolve_cache = {};
|
|
@@ -65,6 +70,8 @@ export class Bundler {
|
|
|
65
70
|
target: [target === 'web' ? 'web' : 'node22', 'es2024'],
|
|
66
71
|
// 结合 output.globalObject, 会生成 globalThis['React'] 这样的引用
|
|
67
72
|
externalsType: target === 'nodejs' ? 'commonjs2' : 'global',
|
|
73
|
+
// 以 react: 'React', 为例,含义为
|
|
74
|
+
// 取全局变量 window.React 的值作为 import { useState } from 'react' 中 { ... } 这部分的结果,再解构里面的 useState 属性
|
|
68
75
|
externals: filter_values({
|
|
69
76
|
react: 'React',
|
|
70
77
|
'react-dom': 'ReactDOM',
|
|
@@ -92,6 +99,7 @@ export class Bundler {
|
|
|
92
99
|
extensionAlias: {
|
|
93
100
|
'.js': ['.js', '.ts', '.tsx']
|
|
94
101
|
},
|
|
102
|
+
...resolve_alias ? { alias: resolve_alias } : {},
|
|
95
103
|
// modules: [
|
|
96
104
|
// '',
|
|
97
105
|
// ],
|
|
@@ -179,9 +187,7 @@ export class Bundler {
|
|
|
179
187
|
test: /\.icon\.svg$/,
|
|
180
188
|
issuer: /\.[jt]sx?$/,
|
|
181
189
|
loader: get_loader('@svgr/webpack'),
|
|
182
|
-
options: {
|
|
183
|
-
icon: true,
|
|
184
|
-
}
|
|
190
|
+
options: { icon: true }
|
|
185
191
|
},
|
|
186
192
|
{
|
|
187
193
|
test: /\.(svg|ico|png|jpe?g|gif|woff2?|ttf|eot|otf|mp4|webm|ogg|mp3|wav|flac|aac)$/,
|
|
@@ -256,6 +262,21 @@ export class Bundler {
|
|
|
256
262
|
}
|
|
257
263
|
};
|
|
258
264
|
}
|
|
265
|
+
/** 获取构建时 git 仓库的最新提交、分支信息 */
|
|
266
|
+
async get_git_info(version) {
|
|
267
|
+
let git = new Git(this.fpd_root);
|
|
268
|
+
const branch = await git.get_branch();
|
|
269
|
+
const { hash, time } = (await git.get_last_commits(1))[0];
|
|
270
|
+
version ||= branch;
|
|
271
|
+
const timestr = time.to_formal_str();
|
|
272
|
+
const commit = hash.slice(0, 6);
|
|
273
|
+
return {
|
|
274
|
+
version: version,
|
|
275
|
+
branch,
|
|
276
|
+
time: timestr,
|
|
277
|
+
commit
|
|
278
|
+
};
|
|
279
|
+
}
|
|
259
280
|
async build(print = true) {
|
|
260
281
|
let timer = new Timer();
|
|
261
282
|
if (!this.lcompiler) {
|
|
@@ -266,6 +287,30 @@ export class Bundler {
|
|
|
266
287
|
openAnalyzer: false,
|
|
267
288
|
}));
|
|
268
289
|
}
|
|
290
|
+
if (this.license) {
|
|
291
|
+
const { LicenseWebpackPlugin } = await import('license-webpack-plugin');
|
|
292
|
+
const ignores = new Set([
|
|
293
|
+
'xshell',
|
|
294
|
+
'react-object-model',
|
|
295
|
+
'@ant-design/icons-svg',
|
|
296
|
+
'@ant-design/pro-layout',
|
|
297
|
+
'@ant-design/pro-provider',
|
|
298
|
+
'@ant-design/pro-table',
|
|
299
|
+
'@ant-design/pro-utils',
|
|
300
|
+
'@ant-design/pro-form',
|
|
301
|
+
'@ant-design/pro-card',
|
|
302
|
+
'@ant-design/pro-field',
|
|
303
|
+
'toggle-selection',
|
|
304
|
+
'ahooks',
|
|
305
|
+
'size-sensor',
|
|
306
|
+
...this.license.ignores || []
|
|
307
|
+
]);
|
|
308
|
+
this.config.plugins.push(new LicenseWebpackPlugin({
|
|
309
|
+
perChunkOutput: false,
|
|
310
|
+
outputFilename: 'ThirdPartyNotice.txt',
|
|
311
|
+
excludedPackageTest: pkgname => ignores.has(pkgname),
|
|
312
|
+
}));
|
|
313
|
+
}
|
|
269
314
|
this.lcompiler = new Lock(Webpack(this.config));
|
|
270
315
|
}
|
|
271
316
|
const stats = await this.lcompiler.request(async (compiler) => new Promise((resolve, reject) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xshell",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.131",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./index.js",
|
|
6
6
|
"bin": {
|
|
@@ -84,6 +84,7 @@
|
|
|
84
84
|
"i18next-scanner": "^4.4.0",
|
|
85
85
|
"koa": "^2.15.3",
|
|
86
86
|
"koa-compress": "^5.1.1",
|
|
87
|
+
"license-webpack-plugin": "^4.0.2",
|
|
87
88
|
"lodash": "^4.17.21",
|
|
88
89
|
"map-stream": "^0.0.7",
|
|
89
90
|
"mime-types": "^2.1.35",
|