@1-/minify_size 0.1.4 → 0.1.5

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 (4) hide show
  1. package/README.md +15 -21
  2. package/_.js +12 -46
  3. package/cli.js +1 -1
  4. package/package.json +1 -2
package/README.md CHANGED
@@ -18,10 +18,10 @@
18
18
 
19
19
  Evaluates JavaScript library size under modern network transmission environments supporting Brotli. For all `.js` files in the specified directory, performs:
20
20
 
21
- - Bundling using `@1-/rolldown` (Rust-based JavaScript bundler wrapping rolldown v1.1.3)
21
+ - Bundling using `@1-/rolldown` (Rust-based JavaScript bundler)
22
22
  - UTF-8 encoding of the bundled code
23
23
  - Brotli compression via Node.js built-in `node:zlib.brotliCompress` to compute final byte length
24
- - Aggregation of per-bundle sizes and calculation of total bundled compressed size
24
+ - Returns total bundled compressed size (bytes)
25
25
 
26
26
  ## 2. Usage Demo
27
27
 
@@ -46,26 +46,23 @@ minify_size ./src
46
46
  Example output:
47
47
 
48
48
  ```
49
- index.js 400
50
- utils.js 250
51
- Total bundled size 650
49
+ 650
52
50
  ```
53
51
 
54
52
  ## 3. Design Concept
55
53
 
56
54
  Execution flow (vertical Mermaid diagram):
57
55
 
58
- ![](https://fastly.jsdelivr.net/gh/webc-fs/-@mF/8IyEaPelxy8ant9q1lyA.svg)
56
+ ![](https://fastly.jsdelivr.net/gh/webc-fs/-@D7/nQLapVbeR_9qMiOldgug.svg)
59
57
 
60
58
  ## 4. Tech Stack
61
59
 
62
60
  - **Runtime**: Node.js / Bun
63
- - **Bundler**: `@1-/rolldown` v0.1.7 (Rust-based JavaScript bundler wrapping rolldown v1.1.3)
61
+ - **Bundler**: `@1-/rolldown` v0.1.7 (Rust-based JavaScript bundler)
64
62
  - **Brotli Engine**: Built-in `node:zlib` (Brotli compression)
65
63
  - **Arg Parser**: `yargs` v18.0.0
66
64
  - **Encoding**: `@3-/utf8` v0.1.1 (TextEncoder-based UTF-8 encoding)
67
- - **Output Formatting**: `cli-table3` v0.6.5 (Formatted tabular output)
68
- - **File Walking**: `@1-/walk` v0.1.1 (Directory traversal utility with concurrency control)
65
+ - **File Walking**: `@1-/walk` v0.1.2 (Directory traversal utility)
69
66
  - **Dependency Management**: npm
70
67
  - **Testing**: bun:test
71
68
 
@@ -74,7 +71,7 @@ Execution flow (vertical Mermaid diagram):
74
71
  ```
75
72
  src/
76
73
  ├── cli.js # CLI entrypoint, parses directory parameter and invokes main function
77
- └── _.js # Directory traversal, bundling, Brotli compression calculation and formatted output
74
+ └── _.js # Directory traversal, bundling, Brotli compression calculation
78
75
  ```
79
76
 
80
77
  ## 6. History
@@ -106,10 +103,10 @@ This library is developed by [WebC.site](https://webc.site).
106
103
 
107
104
  评估 JavaScript 库在支持 Brotli 的网络传输环境下的实际传输体积。对指定目录中所有 `.js` 文件执行以下操作:
108
105
 
109
- - 使用 `@1-/rolldown`(Rust 实现的 JavaScript 打包器)进行打包和语法感知压缩
106
+ - 使用 `@1-/rolldown`(Rust 实现的 JavaScript 打包器)进行打包
110
107
  - 将打包后代码编码为 UTF-8 字节流
111
108
  - 使用 Node.js 内置 `node:zlib.brotliCompress` 计算 Brotli 压缩后字节长度
112
- - 汇总各打包产物大小,并计算整体打包压缩后大小
109
+ - 返回整体打包压缩后大小(字节)
113
110
 
114
111
  ## 2. 使用演示
115
112
 
@@ -134,26 +131,23 @@ minify_size ./src
134
131
  输出示例:
135
132
 
136
133
  ```
137
- index.js 400
138
- utils.js 250
139
- 整体打包压缩后大小 650
134
+ 650
140
135
  ```
141
136
 
142
137
  ## 3. 设计思路
143
138
 
144
139
  系统执行流程如下(垂直 Mermaid 流程图):
145
140
 
146
- ![](https://fastly.jsdelivr.net/gh/webc-fs/-@Cg/dFGhNxdolTp2uwIBl2vg.svg)
141
+ ![](https://fastly.jsdelivr.net/gh/webc-fs/-@Qx/di2QsMfRjPdfYr2IasNQ.svg)
147
142
 
148
143
  ## 4. 技术栈
149
144
 
150
145
  - **Runtime**: Node.js / Bun
151
- - **Bundler**: `@1-/rolldown` v0.1.7 (Rust-based JavaScript bundler wrapping rolldown v1.1.3)
152
- - **Brotli Engine**: 内置 `node:zlib` (Brotli 压缩)
146
+ - **Bundler**: `@1-/rolldown` v0.1.7 (Rust-based JavaScript bundler)
147
+ - **Brotli Engine**: 内置 `node:zlib` (Brotli compression)
153
148
  - **Arg Parser**: `yargs` v18.0.0
154
149
  - **Encoding**: `@3-/utf8` v0.1.1 (TextEncoder-based UTF-8 encoding)
155
- - **Output Formatting**: `cli-table3` v0.6.5 (Formatted tabular output)
156
- - **File Walking**: `@1-/walk` v0.1.1 (Directory traversal utility with concurrency control)
150
+ - **File Walking**: `@1-/walk` v0.1.2 (Directory traversal utility)
157
151
  - **Dependency Management**: npm
158
152
  - **Testing**: bun:test
159
153
 
@@ -162,7 +156,7 @@ utils.js 250
162
156
  ```
163
157
  src/
164
158
  ├── cli.js # CLI 命令行入口,解析目录参数并调用主函数
165
- └── _.js # 目录遍历、打包处理、Brotli压缩计算及格式化输出
159
+ └── _.js # 目录遍历、打包处理、Brotli压缩计算
166
160
  ```
167
161
 
168
162
  ## 6. 历史故事
package/_.js CHANGED
@@ -1,50 +1,19 @@
1
- import { relative, join } from "node:path";
1
+ import { join, isAbsolute } from "node:path";
2
2
  import { realpathSync } from "node:fs";
3
3
  import { promisify } from "node:util";
4
4
  import { brotliCompress } from "node:zlib";
5
- import Table from "cli-table3";
6
5
  import { FILE } from "@1-/walk";
7
6
  import walkRelIgnore from "@1-/walk/walkRelIgnore.js";
8
7
  import utf8e from "@3-/utf8";
9
8
  import bundle from "@1-/rolldown";
10
9
 
11
10
  const BROTLI = promisify(brotliCompress),
12
- TABLE_STYLE = { "padding-left": 0, "padding-right": 0 },
13
- NO_BORDER = {
14
- top: "",
15
- "top-mid": "",
16
- "top-left": "",
17
- "top-right": "",
18
- bottom: "",
19
- "bottom-mid": "",
20
- "bottom-left": "",
21
- "bottom-right": "",
22
- left: "",
23
- "left-mid": "",
24
- mid: "",
25
- "mid-mid": "",
26
- right: "",
27
- "right-mid": "",
28
- middle: " ",
29
- },
30
11
  /*
31
12
  获取字符串 brotli 压缩后大小
32
13
  参数: str 待压缩字符串
33
14
  返回值: 字节数
34
15
  */
35
- br = async (str) => (await BROTLI(utf8e(str))).length,
36
- /*
37
- 输出打包大小表格
38
- 参数:
39
- list 包含 [相对路径, 大小] 的数组
40
- total 整体压缩后大小
41
- */
42
- show = (list, total) => {
43
- const table = new Table({ chars: NO_BORDER, style: TABLE_STYLE });
44
- list.forEach(([rel_path, size]) => table.push([rel_path, size]));
45
- table.push(["整体打包压缩后大小", total]);
46
- console.log(table.toString());
47
- };
16
+ br = async (str) => (await BROTLI(utf8e(str))).length;
48
17
 
49
18
  /*
50
19
  打包并计算指定目录下 JS 文件压缩后大小
@@ -64,7 +33,6 @@ export default async (dir) => {
64
33
  });
65
34
 
66
35
  if (!files.length) {
67
- show([], 0);
68
36
  return 0;
69
37
  }
70
38
 
@@ -74,18 +42,16 @@ export default async (dir) => {
74
42
  out_map[abs] = abs;
75
43
  });
76
44
 
77
- const chunks = await bundle(input, {}, true, undefined, out_map),
78
- sizes = (
79
- await Promise.all(
80
- chunks.map(async ([abs_out_path, code]) => [
81
- relative(real_dir, abs_out_path),
82
- await br(code),
83
- code,
84
- ]),
85
- )
86
- ).sort((a, b) => a[0].localeCompare(b[0])),
87
- total_size = await br(sizes.map(([, , code]) => code).join(""));
88
- show(sizes, total_size);
45
+ const chunks = await bundle(
46
+ input,
47
+ {
48
+ external: (id) => !id.startsWith(".") && !isAbsolute(id),
49
+ },
50
+ true,
51
+ undefined,
52
+ out_map,
53
+ ),
54
+ total_size = await br(chunks.map(([, code]) => code).join(""));
89
55
 
90
56
  return total_size;
91
57
  };
package/cli.js CHANGED
@@ -16,4 +16,4 @@ const { dir } = yargs(hideBin(process.argv))
16
16
  .help()
17
17
  .alias("h", "help").argv;
18
18
 
19
- await minify(dir);
19
+ console.log(await minify(dir));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1-/minify_size",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Minify JS and output brotli compressed size | 压缩 JS 并输出 brotli 压缩后大小",
5
5
  "keywords": [
6
6
  "br",
@@ -28,7 +28,6 @@
28
28
  "@1-/rolldown": "^0.1.7",
29
29
  "@1-/walk": "^0.1.2",
30
30
  "@3-/utf8": "^0.1.1",
31
- "cli-table3": "^0.6.5",
32
31
  "yargs": "^18.0.0"
33
32
  }
34
33
  }