hyperbuild 0.1.8 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf56e4e3ef3a4d85fb29001ce6414edc7459e7eabcecd3d91aea9ac328636a58
4
- data.tar.gz: 7b354352afb385250008b6441ef5049f55a7f3aeca961b09c417b1dea0175e10
3
+ metadata.gz: 47317f7fad5e5633c4f962895d67a580dedb973ff1b124cf26415b5bc0a75bf6
4
+ data.tar.gz: 54c8be85456af68447db90121e38b9faa90f5ea69c23f10c58a2d911d8d7b217
5
5
  SHA512:
6
- metadata.gz: edcb75247975e1cebf8be8717f6858c1fe19dbbbb42f463d4e5b687f1c883bfee643ae0d12c0cb561ec3e219f663a34030cb49fcf2fcb277d747ff41d295061e
7
- data.tar.gz: c19fad266ab12e32112b1ec2a92f48e238c7e8c52a0084d1d27ed994ac4f22d80ffeb2d034e2292c60ea50588d15951359531f81f314473cef8c72d080c886ad
6
+ metadata.gz: 8a74b8742c441a840017fb309e5d571376d34d48ac533e4f240ccf46e6731a9f815ce36734513b2a21ad9151c0486ad5263cfcd6a75b766e3208cb9f3d020866
7
+ data.tar.gz: 3c0feacc11bd5f91be61f0bbaf53c7c2c2bb5b0bb06e56644504da6f9f534b2836073359c4bcc4324c55440f19b5addea0c225cc4d2e4352e8edbdd549e71988
data/README.md CHANGED
@@ -2,8 +2,10 @@
2
2
 
3
3
  A fast one-pass in-place HTML minifier written in Rust with context-aware whitespace handling.
4
4
 
5
+ Also supports JS minification by plugging into [esbuild](https://github.com/evanw/esbuild).
6
+
5
7
  Available as:
6
- - CLI for Windows, macOS, and Linux.
8
+ - CLI for macOS and Linux.
7
9
  - Rust library.
8
10
  - Native library for Node.js, Python, Java, and Ruby.
9
11
 
@@ -12,27 +14,31 @@ Available as:
12
14
  - Minification is done in one pass with no backtracking or DOM/AST building.
13
15
  - No extra heap memory is allocated during processing, which increases performance.
14
16
  - Context-aware whitespace handling allows maximum minification while retaining desired spaces.
17
+ - Well tested with a large test suite and extensive [fuzzing](./fuzz).
15
18
 
16
19
  ## Performance
17
20
 
18
21
  Speed and effectiveness of Node.js version compared to [html-minfier](https://github.com/kangax/html-minifier) and [minimize](https://github.com/Swaagie/minimize), run on popular already-minified web pages. See [bench](./bench) folder for more details.
19
22
 
20
- <img width="435" alt="Chart showing speed of HTML minifiers" src="https://wilsonl.in/hyperbuild/bench/0.1.8/average-speeds.png"> <img width="435" alt="Chart showing effectiveness of HTML minifiers" src="https://wilsonl.in/hyperbuild/bench/0.1.8/average-sizes.png">
23
+ <img width="435" alt="Chart showing speed of HTML minifiers" src="https://wilsonl.in/hyperbuild/bench/0.2.3/average-speeds.png"> <img width="435" alt="Chart showing effectiveness of HTML minifiers" src="https://wilsonl.in/hyperbuild/bench/0.2.3/average-sizes.png">
21
24
 
22
25
  ## Usage
23
26
 
24
27
  ### CLI
25
28
 
26
- Precompiled binaries are available for x86-64 Windows, macOS, and Linux.
29
+ Precompiled binaries are available for x86-64 macOS and Linux.
30
+
31
+ Building from source currently requires the Go compiler to be installed as well, to build the [JS minifier](https://github.com/evanw/esbuild).
27
32
 
28
33
  ##### Get
29
34
 
30
- [Windows](https://wilsonl.in/hyperbuild/bin/0.1.8-windows-x86_64.exe) |
31
- [macOS](https://wilsonl.in/hyperbuild/bin/0.1.8-macos-x86_64) |
32
- [Linux](https://wilsonl.in/hyperbuild/bin/0.1.8-linux-x86_64)
35
+ [macOS](https://wilsonl.in/hyperbuild/bin/0.2.3-macos-x86_64) |
36
+ [Linux](https://wilsonl.in/hyperbuild/bin/0.2.3-linux-x86_64)
33
37
 
34
38
  ##### Use
35
39
 
40
+ Use the `--help` argument for more details.
41
+
36
42
  ```bash
37
43
  hyperbuild --src /path/to/src.html --out /path/to/output.min.html
38
44
  ```
@@ -46,34 +52,37 @@ hyperbuild --src /path/to/src.html --out /path/to/output.min.html
46
52
 
47
53
  ```toml
48
54
  [dependencies]
49
- hyperbuild = "0.1.8"
55
+ hyperbuild = "0.2.3"
50
56
  ```
51
57
 
52
58
  ##### Use
53
59
 
54
60
  ```rust
55
- use hyperbuild::{FriendlyError, hyperbuild};
61
+ use hyperbuild::{Cfg, FriendlyError, hyperbuild, hyperbuild_copy, hyperbuild_friendly_error, hyperbuild_truncate};
56
62
 
57
63
  fn main() {
58
64
  let mut code = b"<p> Hello, world! </p>".to_vec();
65
+ let cfg = &Cfg {
66
+ minify_js: false,
67
+ };
59
68
 
60
69
  // Minifies a slice in-place and returns the new minified length,
61
70
  // but leaves any original code after the minified code intact.
62
- match hyperbuild(&mut code) {
71
+ match hyperbuild(&mut code, cfg) {
63
72
  Ok(minified_len) => {}
64
73
  Err((error_type, error_position)) => {}
65
74
  };
66
75
 
67
76
  // Creates a vector copy containing only minified code
68
77
  // instead of minifying in-place.
69
- match hyperbuild_copy(&code) {
78
+ match hyperbuild_copy(&code, cfg) {
70
79
  Ok(minified) => {}
71
80
  Err((error_type, error_position)) => {}
72
81
  };
73
82
 
74
83
  // Minifies a vector in-place, and then truncates the
75
84
  // vector to the new minified length.
76
- match hyperbuild_truncate(&mut code) {
85
+ match hyperbuild_truncate(&mut code, cfg) {
77
86
  Ok(()) => {}
78
87
  Err((error_type, error_position)) => {}
79
88
  };
@@ -81,7 +90,7 @@ fn main() {
81
90
  // Identical to `hyperbuild` except with FriendlyError instead.
82
91
  // `code_context` is a string of a visual representation of the source,
83
92
  // with line numbers and position markers to aid in debugging syntax.
84
- match hyperbuild_friendly_error(&mut code) {
93
+ match hyperbuild_friendly_error(&mut code, cfg) {
85
94
  Ok(minified_len) => {}
86
95
  Err(FriendlyError { position, message, code_context }) => {
87
96
  eprintln!("Failed at character {}:", position);
@@ -118,10 +127,11 @@ yarn add hyperbuild
118
127
  ```js
119
128
  const hyperbuild = require("hyperbuild");
120
129
 
121
- const minified = hyperbuild.minify("<p> Hello, world! </p>");
130
+ const cfg = { minifyJs: false };
131
+ const minified = hyperbuild.minify("<p> Hello, world! </p>", cfg);
122
132
 
123
133
  // Alternatively, minify in place to avoid copying.
124
- const source = Buffer.from("<p> Hello, world! </p>");
134
+ const source = Buffer.from("<p> Hello, world! </p>", cfg);
125
135
  hyperbuild.minifyInPlace(source);
126
136
  ```
127
137
 
@@ -131,8 +141,9 @@ hyperbuild is also available for TypeScript:
131
141
  import * as hyperbuild from "hyperbuild";
132
142
  import * as fs from "fs";
133
143
 
134
- const minified = hyperbuild.minify("<p> Hello, world! </p>");
135
- hyperbuild.minifyInPlace(fs.readFileSync("source.html"));
144
+ const cfg = { minifyJs: false };
145
+ const minified = hyperbuild.minify("<p> Hello, world! </p>", cfg);
146
+ hyperbuild.minifyInPlace(fs.readFileSync("source.html"), cfg);
136
147
  ```
137
148
 
138
149
  </details>
@@ -150,7 +161,7 @@ Add as a Maven dependency:
150
161
  <dependency>
151
162
  <groupId>in.wilsonl.hyperbuild</groupId>
152
163
  <artifactId>hyperbuild</artifactId>
153
- <version>0.1.8</version>
164
+ <version>0.2.3</version>
154
165
  </dependency>
155
166
  ```
156
167
 
@@ -159,15 +170,18 @@ Add as a Maven dependency:
159
170
  ```java
160
171
  import in.wilsonl.hyperbuild.Hyperbuild;
161
172
 
173
+ Hyperbuild.Configuration cfg = new Hyperbuild.Configuration.Builder()
174
+ .setMinifyJs(false)
175
+ .build();
162
176
  try {
163
- String minified = Hyperbuild.minify("<p> Hello, world! </p>");
177
+ String minified = Hyperbuild.minify("<p> Hello, world! </p>", cfg);
164
178
  } catch (Hyperbuild.SyntaxException e) {
165
179
  System.err.println(e.getMessage());
166
180
  }
167
181
 
168
182
  // Alternatively, minify in place:
169
183
  assert source instanceof ByteBuffer && source.isDirect();
170
- Hyperbuild.minifyInPlace(source);
184
+ Hyperbuild.minifyInPlace(source, cfg);
171
185
  ```
172
186
 
173
187
  </details>
@@ -187,7 +201,7 @@ Add the PyPI project as a dependency and install it using `pip` or `pipenv`.
187
201
  import hyperbuild
188
202
 
189
203
  try:
190
- minified = hyperbuild.minify("<p> Hello, world! </p>")
204
+ minified = hyperbuild.minify("<p> Hello, world! </p>", minify_js=False)
191
205
  except SyntaxError as e:
192
206
  print(e)
193
207
  ```
@@ -208,17 +222,13 @@ Add the library as a dependency to `Gemfile` or `*.gemspec`.
208
222
  ```ruby
209
223
  require 'hyperbuild'
210
224
 
211
- print Hyperbuild.minify "<p> Hello, world! </p>"
225
+ print Hyperbuild.minify("<p> Hello, world! </p>", { :minify_js => false })
212
226
  ```
213
227
 
214
228
  </details>
215
229
 
216
230
  ## Minification
217
231
 
218
- ### Configurability
219
-
220
- Configuration of minification is currently WIP across all languages. The behaviour mentioned below is the default.
221
-
222
232
  ### Whitespace
223
233
 
224
234
  hyperbuild has advanced context-aware whitespace minification that does things such as:
@@ -440,6 +450,8 @@ Numeric entities that do not refer to a valid [Unicode Scalar Value](https://www
440
450
 
441
451
  If an entity is unintentionally formed after decoding, the leading ampersand is encoded, e.g. `&&#97;&#109;&#112;;` becomes `&ampamp;`. This is done as `&amp` is equal to or shorter than all other entity representations of characters part of an entity (`[&#a-zA-Z0-9;]`), and there is no other conflicting entity name that starts with `amp`.
442
452
 
453
+ It's possible to get an unintentional entity after removing comments, e.g. `&am<!-- -->p`.
454
+
443
455
  Left chevrons after any decoding in text are encoded to `&LT` if possible or `&LT;` otherwise.
444
456
 
445
457
  ### Comments
@@ -454,7 +466,7 @@ Bangs, [processing instructions](https://en.wikipedia.org/wiki/Processing_Instru
454
466
 
455
467
  Only UTF-8/ASCII-encoded HTML code is supported.
456
468
 
457
- hyperbuild simply does HTML minification, and almost does no syntax checking or standards enforcement for performance and code complexity reasons.
469
+ hyperbuild does no syntax checking or standards enforcement for performance and code complexity reasons.
458
470
 
459
471
  For example, this means that it's not an error to have self-closing tags, declare multiple `<body>` elements, use incorrect attribute names and values, or write something like `<br>alert('');</br>`
460
472
 
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperbuild
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Wilson Lin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-04 00:00:00.000000000 Z
11
+ date: 2020-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fiddle
@@ -62,6 +62,5 @@ rubyforge_project:
62
62
  rubygems_version: 2.7.6.2
63
63
  signing_key:
64
64
  specification_version: 4
65
- summary: Fast one-pass in-place HTML minifier written in Rust with context-aware whitespace
66
- handling
65
+ summary: Fast allocation-less HTML minifier with smart whitespace handling
67
66
  test_files: []