xshell 1.0.118 → 1.0.120

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.
Files changed (3) hide show
  1. package/builder.d.ts +46 -0
  2. package/builder.js +292 -0
  3. package/package.json +20 -9
package/builder.d.ts ADDED
@@ -0,0 +1,46 @@
1
+ import Webpack from 'webpack';
2
+ import { Lock } from './utils.js';
3
+ export interface BundlerOptions {
4
+ source_map?: boolean;
5
+ production?: boolean;
6
+ externals?: Record<string, string>;
7
+ sass?: typeof import('sass');
8
+ module_import?: boolean;
9
+ commonjs2?: boolean;
10
+ assets_stats?: boolean;
11
+ globals?: Record<string, string>;
12
+ analyzer?: boolean;
13
+ dts?: boolean;
14
+ cache_version?: string;
15
+ single_chunk?: boolean;
16
+ }
17
+ export declare class Bundler {
18
+ name: string;
19
+ fpd_root: string;
20
+ config: Webpack.Configuration;
21
+ analyzer: boolean;
22
+ lcompiler: Lock<Webpack.Compiler>;
23
+ /** 通过 webpack 从入口文件打包所有依赖生成单个 index.{mjs,cjs} 文件
24
+ - name: 项目名称
25
+ - target: 目标环境 nodejs | web
26
+ - fpd_root: 项目根目录
27
+ - fpd_out: 输出文件目录
28
+ - fpd_cache: webpack 缓存目录
29
+ - entry: 入口文件
30
+ - options?: 打包配置, 按常用顺序排列
31
+ - source_map?: `true` 启用源码映射 .map 文件
32
+ - globals?: 全局变量定义
33
+ - externals?: 配置外部模块
34
+ - commonjs2?: `false` 打包为 commonjs2 (.cjs) 的文件
35
+ - single_chunk?: `true` 输出为单个文件,将依赖也打包到其中,不要生成多个 chunk
36
+ - module_import?: `true` 对于 await import('...') 要不要打包外部模块到输出文件中
37
+ - assets_stats?: `true` 打印输出的文件信息
38
+ - analyzer?: `false` 启用 WebpackBundleAnalyzer 插件分析构建产物大小
39
+ - dts?: `false` 生成 .d.ts 文件
40
+ - cache_version?: webpack cache version, 用于区分同一个 name 的不同版本
41
+ - production?: `true` webpack mode 设置为 'production'
42
+ - sass?: 传入 sass 实例避免 webpack 重复加载 .cjs 版本 */
43
+ constructor(name: string, target: 'web' | 'nodejs', fpd_root: string, fpd_out: string, fpdt_cache: string, entry: Record<string, string>, { source_map, globals, externals, commonjs2, single_chunk, module_import, assets_stats, analyzer, dts, cache_version, production, sass, }?: BundlerOptions);
44
+ build(print?: boolean): Promise<void>;
45
+ close(): Promise<void>;
46
+ }
package/builder.js ADDED
@@ -0,0 +1,292 @@
1
+ import Webpack from 'webpack';
2
+ import { Lock, Timer, filter_values } from './utils.js';
3
+ export class Bundler {
4
+ name;
5
+ fpd_root;
6
+ config;
7
+ analyzer;
8
+ lcompiler;
9
+ /** 通过 webpack 从入口文件打包所有依赖生成单个 index.{mjs,cjs} 文件
10
+ - name: 项目名称
11
+ - target: 目标环境 nodejs | web
12
+ - fpd_root: 项目根目录
13
+ - fpd_out: 输出文件目录
14
+ - fpd_cache: webpack 缓存目录
15
+ - entry: 入口文件
16
+ - options?: 打包配置, 按常用顺序排列
17
+ - source_map?: `true` 启用源码映射 .map 文件
18
+ - globals?: 全局变量定义
19
+ - externals?: 配置外部模块
20
+ - commonjs2?: `false` 打包为 commonjs2 (.cjs) 的文件
21
+ - single_chunk?: `true` 输出为单个文件,将依赖也打包到其中,不要生成多个 chunk
22
+ - module_import?: `true` 对于 await import('...') 要不要打包外部模块到输出文件中
23
+ - assets_stats?: `true` 打印输出的文件信息
24
+ - analyzer?: `false` 启用 WebpackBundleAnalyzer 插件分析构建产物大小
25
+ - dts?: `false` 生成 .d.ts 文件
26
+ - cache_version?: webpack cache version, 用于区分同一个 name 的不同版本
27
+ - production?: `true` webpack mode 设置为 'production'
28
+ - sass?: 传入 sass 实例避免 webpack 重复加载 .cjs 版本 */
29
+ constructor(name, target, fpd_root, fpd_out, fpdt_cache, entry, { source_map = true, globals, externals, commonjs2 = false, single_chunk = true, module_import = true, assets_stats = true, analyzer = false, dts = false, cache_version, production = true, sass, } = {}) {
30
+ this.name = name;
31
+ this.analyzer = analyzer;
32
+ // let smp = new SpeedMeasurePlugin()
33
+ // const config: Webpack.Configuration = smp.wrap({
34
+ function get_loader(name) {
35
+ return name;
36
+ }
37
+ this.config = {
38
+ name,
39
+ mode: production ? 'production' : 'development',
40
+ devtool: source_map ? 'source-map' : false,
41
+ context: fpd_root,
42
+ entry,
43
+ experiments: {
44
+ outputModule: !commonjs2,
45
+ },
46
+ output: {
47
+ path: fpd_out,
48
+ filename: '[name]',
49
+ publicPath: '/',
50
+ pathinfo: true,
51
+ globalObject: 'globalThis',
52
+ module: !commonjs2,
53
+ // 在 bundle 中导出 entry 文件的 export
54
+ library: {
55
+ type: commonjs2 ? 'commonjs2' : 'module',
56
+ },
57
+ ...single_chunk ? {
58
+ chunkLoading: false
59
+ } : {},
60
+ },
61
+ target: [target === 'web' ? 'web' : 'node22', 'es2024'],
62
+ // 结合 output.globalObject, 会生成 globalThis['React'] 这样的引用
63
+ externalsType: target === 'nodejs' ? 'commonjs2' : 'global',
64
+ externals: filter_values({
65
+ react: 'React',
66
+ 'react-dom': 'ReactDOM',
67
+ jquery: '$',
68
+ ...target === 'web' ? {
69
+ lodash: '_',
70
+ } : {
71
+ vscode: 'commonjs2 vscode'
72
+ },
73
+ // import { Terminal } from 'xterm'
74
+ // 实际上 Terminal 直接暴露在了 window 上,而不是 window.Terminal.Terminal
75
+ xterm: 'window',
76
+ swiper: 'Swiper',
77
+ antd: 'antd',
78
+ '@ant-design/icons': 'icons',
79
+ '@ant-design/plots': 'Plots',
80
+ echarts: 'echarts',
81
+ dolphindb: 'dolphindb',
82
+ ...externals
83
+ }),
84
+ resolve: {
85
+ symlinks: true,
86
+ extensions: ['.js'],
87
+ extensionAlias: {
88
+ '.js': ['.js', '.ts', '.tsx']
89
+ },
90
+ // modules: [
91
+ // '',
92
+ // ],
93
+ // fallback: {
94
+ // os: false,
95
+ // }
96
+ },
97
+ ...sass ? {
98
+ loader: { sass }
99
+ } : {},
100
+ module: {
101
+ ...module_import === false ? {
102
+ parser: {
103
+ javascript: {
104
+ // 保留 await import() 这样的引用
105
+ import: false,
106
+ // dynamicImportMode: 'weak',
107
+ }
108
+ },
109
+ } : {},
110
+ rules: [
111
+ ...source_map ? [
112
+ {
113
+ test: /\.js$/,
114
+ enforce: 'pre',
115
+ use: [get_loader('source-map-loader')],
116
+ },
117
+ ] : [],
118
+ {
119
+ test: target === 'nodejs' ? /\.ts$/ : /\.tsx?$/,
120
+ exclude: /node_modules/,
121
+ loader: get_loader('ts-loader'),
122
+ // https://github.com/TypeStrong/ts-loader
123
+ options: {
124
+ configFile: `${fpd_root}tsconfig.json`,
125
+ onlyCompileBundledFiles: true,
126
+ transpileOnly: !dts,
127
+ compilerOptions: {
128
+ module: 'ESNext',
129
+ moduleResolution: 'Bundler',
130
+ declaration: dts,
131
+ ...commonjs2 ? {
132
+ // 编译为 commonjs 后 import 的依赖是通过 require 引入的,所以需要 interop 去生成 default
133
+ // nodejs 默认的 import 会自动加上 default,所以不需要 interop
134
+ esModuleInterop: true
135
+ } : {},
136
+ }
137
+ }
138
+ },
139
+ ...target === 'web' ? [
140
+ {
141
+ test: /\.s[ac]ss$/,
142
+ use: [
143
+ get_loader('style-loader'),
144
+ {
145
+ // https://github.com/webpack-contrib/css-loader
146
+ loader: get_loader('css-loader'),
147
+ options: {
148
+ url: false,
149
+ }
150
+ },
151
+ {
152
+ // https://webpack.js.org/loaders/sass-loader
153
+ loader: get_loader('sass-loader'),
154
+ options: {
155
+ ...sass ? {
156
+ implementation: sass
157
+ } : {},
158
+ // 解决 url(search.png) 打包出错的问题
159
+ webpackImporter: false,
160
+ sassOptions: {
161
+ indentWidth: 4,
162
+ }
163
+ }
164
+ },
165
+ ]
166
+ },
167
+ {
168
+ test: /\.css$/,
169
+ use: [get_loader('style-loader'), get_loader('css-loader')]
170
+ },
171
+ {
172
+ oneOf: [
173
+ {
174
+ test: /\.icon\.svg$/,
175
+ issuer: /\.[jt]sx?$/,
176
+ loader: get_loader('@svgr/webpack'),
177
+ options: {
178
+ icon: true,
179
+ }
180
+ },
181
+ {
182
+ test: /\.(svg|ico|png|jpe?g|gif|woff2?|ttf|eot|otf|mp4|webm|ogg|mp3|wav|flac|aac)$/,
183
+ type: 'asset/inline',
184
+ },
185
+ ]
186
+ },
187
+ ] : [],
188
+ {
189
+ test: /\.(txt|csv)$/,
190
+ type: 'asset/source',
191
+ }
192
+ ]
193
+ },
194
+ plugins: [
195
+ ...globals ? [
196
+ new Webpack.DefinePlugin({
197
+ ...globals
198
+ // process: { env: { }, argv: [] }
199
+ })
200
+ ] : []
201
+ // 使用 IgnorePlugin 能够不打包,但是一旦导入就会报错
202
+ // new Webpack.IgnorePlugin({
203
+ // checkResource: (resource, context) =>
204
+ // resource.startsWith('./vendors/') && !context.fp.startsWith(fpd_node_modules) ,
205
+ // }),
206
+ ],
207
+ optimization: {
208
+ minimize: false
209
+ },
210
+ cache: {
211
+ type: 'filesystem',
212
+ compression: false,
213
+ cacheDirectory: fpdt_cache,
214
+ ...cache_version ? {
215
+ version: cache_version
216
+ } : {}
217
+ },
218
+ ignoreWarnings: [
219
+ /Failed to parse source map/,
220
+ ...target === 'nodejs' ? [
221
+ /Can't resolve '(bufferutil|utf-8-validate)'/
222
+ ] : [],
223
+ // warning =>
224
+ // warning.message.includes('the request of a dependency is an expression') && warning.module?.context?.endsWith('any-promise')
225
+ ],
226
+ performance: {
227
+ hints: false,
228
+ },
229
+ stats: {
230
+ colors: true,
231
+ context: fpd_root,
232
+ entrypoints: false,
233
+ errors: true,
234
+ errorDetails: true,
235
+ hash: false,
236
+ version: false,
237
+ timings: true,
238
+ children: true,
239
+ assets: assets_stats,
240
+ assetsSpace: 20,
241
+ modules: false,
242
+ modulesSpace: 20,
243
+ cachedAssets: false,
244
+ cachedModules: false,
245
+ chunks: false,
246
+ // logging: 'info',
247
+ }
248
+ };
249
+ }
250
+ async build(print = true) {
251
+ let timer = new Timer();
252
+ if (!this.lcompiler) {
253
+ if (this.analyzer) {
254
+ const { BundleAnalyzerPlugin } = await import('webpack-bundle-analyzer');
255
+ this.config.plugins.push(new BundleAnalyzerPlugin({
256
+ analyzerPort: 8880,
257
+ openAnalyzer: false,
258
+ }));
259
+ }
260
+ this.lcompiler = new Lock(Webpack(this.config));
261
+ }
262
+ const stats = await this.lcompiler.request(async (compiler) => new Promise((resolve, reject) => {
263
+ compiler.run((error, stats) => {
264
+ if (error)
265
+ reject(error);
266
+ else if (stats.hasErrors()) {
267
+ console.log(stats.toString(compiler.options.stats));
268
+ reject(new Error(`${this.name} 构建失败`));
269
+ }
270
+ else
271
+ resolve(stats);
272
+ });
273
+ }));
274
+ if (print) {
275
+ const statstr = stats.toString(this.config.stats)
276
+ .replace(new RegExp(`\\n\\s*.*${this.name}.* compiled .*successfully.* in (.*)`), '').trimEnd();
277
+ console.log(`${statstr ? `${statstr}\n` : ''}` +
278
+ `${this.name} 构建成功, 用时 ${timer.getstr()}`.green);
279
+ }
280
+ }
281
+ async close() {
282
+ await this.lcompiler?.request(async (compiler) => new Promise((resolve, reject) => {
283
+ compiler.close(error => {
284
+ if (error)
285
+ reject(error);
286
+ else
287
+ resolve();
288
+ });
289
+ }));
290
+ }
291
+ }
292
+ //# sourceMappingURL=builder.js.map
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "xshell",
3
- "version": "1.0.118",
3
+ "version": "1.0.120",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "bin": {
7
- "xshell": "./xshell.js",
8
- "i18n-scan": "./i18n/i18n-scan.js"
7
+ "xshell": "xshell.js",
8
+ "i18n-scan": "i18n/i18n-scan.js"
9
9
  },
10
10
  "description": "xshell is a shell designed to provide a brand new human-computer interaction experience.",
11
11
  "keywords": [
@@ -57,10 +57,12 @@
57
57
  "@babel/parser": "^7.24.7",
58
58
  "@babel/traverse": "^7.24.7",
59
59
  "@koa/cors": "^5.0.0",
60
+ "@svgr/webpack": "^8.1.0",
61
+ "@types/sass-loader": "^8.0.8",
60
62
  "@types/ws": "^8.5.10",
61
- "@typescript-eslint/eslint-plugin": "^7.12.0",
62
- "@typescript-eslint/parser": "^7.12.0",
63
- "@typescript-eslint/utils": "^7.12.0",
63
+ "@typescript-eslint/eslint-plugin": "^7.13.0",
64
+ "@typescript-eslint/parser": "^7.13.0",
65
+ "@typescript-eslint/utils": "^7.13.0",
64
66
  "@xterm/addon-fit": "^0.10.0",
65
67
  "@xterm/addon-web-links": "^0.11.0",
66
68
  "@xterm/addon-webgl": "^0.18.0",
@@ -74,6 +76,7 @@
74
76
  "cli-truncate": "^4.0.0",
75
77
  "colors": "^1.4.0",
76
78
  "commander": "^12.1.0",
79
+ "css-loader": "^7.1.2",
77
80
  "emoji-regex": "^10.3.0",
78
81
  "eslint": "^9.4.0",
79
82
  "eslint-plugin-import": "^2.29.1",
@@ -93,15 +96,22 @@
93
96
  "react-i18next": "^14.1.2",
94
97
  "react-object-model": "^1.2.6",
95
98
  "resolve-path": "^1.4.0",
99
+ "sass": "^1.77.5",
100
+ "sass-loader": "^14.2.1",
101
+ "source-map-loader": "^5.0.0",
96
102
  "strip-ansi": "^7.1.0",
103
+ "style-loader": "^4.0.0",
97
104
  "through2": "^4.0.2",
98
105
  "tough-cookie": "^4.1.4",
106
+ "ts-loader": "^9.5.1",
99
107
  "tslib": "^2.6.3",
100
108
  "typescript": "^5.4.5",
101
- "ua-parser-js": "^2.0.0-beta.2",
109
+ "ua-parser-js": "^2.0.0-beta.3",
102
110
  "undici": "^6.18.2",
103
111
  "vinyl": "^3.0.0",
104
112
  "vinyl-fs": "^4.0.0",
113
+ "webpack": "^5.92.0",
114
+ "webpack-bundle-analyzer": "^4.10.2",
105
115
  "ws": "^8.17.0"
106
116
  },
107
117
  "devDependencies": {
@@ -116,7 +126,7 @@
116
126
  "@types/gulp-sort": "^2.0.4",
117
127
  "@types/koa": "^2.15.0",
118
128
  "@types/koa-compress": "^4.0.6",
119
- "@types/lodash": "^4.17.4",
129
+ "@types/lodash": "^4.17.5",
120
130
  "@types/mime-types": "^2.1.4",
121
131
  "@types/node": "^20.14.2",
122
132
  "@types/react": "^18.3.3",
@@ -124,7 +134,8 @@
124
134
  "@types/tough-cookie": "^4.0.5",
125
135
  "@types/ua-parser-js": "^0.7.39",
126
136
  "@types/vinyl-fs": "^3.0.5",
127
- "@types/vscode": "^1.89.0"
137
+ "@types/vscode": "^1.90.0",
138
+ "@types/webpack-bundle-analyzer": "^4.7.0"
128
139
  },
129
140
  "pnpm": {
130
141
  "patchedDependencies": {