ghtml 2.1.1 → 2.1.3

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/.eslintrc.json CHANGED
@@ -1,7 +1,4 @@
1
1
  {
2
2
  "root": true,
3
- "extends": ["plugin:grules/all"],
4
- "rules": {
5
- "prefer-template": "off"
6
- }
3
+ "extends": ["plugin:grules/all"]
7
4
  }
package/bin/README.md CHANGED
@@ -5,7 +5,7 @@ Append unique hashes to assets referenced in your views to aggressively cache th
5
5
  Running the following command will scan asset files found in the `roots` path(s) and replace their references with hashed versions in the `refs` path(s):
6
6
 
7
7
  ```sh
8
- npx ghtml --roots="path/to/scan/assets1/,path/to/scan/assets2/" --refs="views/path/to/append/hashes1/,views/path/to/append/hashes2/"
8
+ npx ghtml --roots="path/to/scan/assets/1/,path/to/scan/assets/2/" --refs="views/path/to/append/hashes/1/,views/path/to/append/hashes/2/"
9
9
  ```
10
10
 
11
11
  ## Example (Fastify)
package/bin/src/utils.js CHANGED
@@ -1,10 +1,7 @@
1
1
  import { createHash } from "node:crypto";
2
2
  import { readFile, writeFile } from "node:fs/promises";
3
3
  import { win32, posix } from "node:path";
4
- import { cpus } from "node:os";
5
4
  import { Glob } from "glob";
6
- import { promise as fastq } from "fastq";
7
- const fastqConcurrency = Math.max(1, cpus().length - 1);
8
5
 
9
6
  const generateFileHash = async (filePath) => {
10
7
  try {
@@ -91,10 +88,8 @@ const generateHashesAndReplace = async ({
91
88
  rootPath += "/";
92
89
  }
93
90
 
94
- const queue = fastq(generateFileHash, fastqConcurrency);
95
- const queuePromises = [];
91
+ const queue = [];
96
92
  const files = [];
97
-
98
93
  const filesIterable = new Glob("**/**", {
99
94
  nodir: true,
100
95
  follow: true,
@@ -104,13 +99,13 @@ const generateHashesAndReplace = async ({
104
99
  ignore: skipPatterns,
105
100
  });
106
101
 
107
- for await (let file of filesIterable) {
108
- file = file.split(win32.sep).join(posix.sep);
109
- files.push(file);
110
- queuePromises.push(queue.push(file));
102
+ for await (let filePath of filesIterable) {
103
+ filePath = filePath.split(win32.sep).join(posix.sep);
104
+ queue.push(generateFileHash(filePath));
105
+ files.push(filePath);
111
106
  }
112
107
 
113
- const hashes = await Promise.all(queuePromises);
108
+ const hashes = await Promise.all(queue);
114
109
 
115
110
  for (let i = 0; i < files.length; i++) {
116
111
  const fileRelativePath = posix.relative(rootPath, files[i]);
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Replace your template engine with fast JavaScript by leveraging the power of tagged templates.",
4
4
  "author": "Gürgün Dayıoğlu",
5
5
  "license": "MIT",
6
- "version": "2.1.1",
6
+ "version": "2.1.3",
7
7
  "type": "module",
8
8
  "bin": "./bin/src/index.js",
9
9
  "main": "./src/index.js",
@@ -21,13 +21,12 @@
21
21
  "lint:fix": "eslint --fix . && prettier --write ."
22
22
  },
23
23
  "dependencies": {
24
- "fastq": "^1.17.1",
25
- "glob": "^10.4.2"
24
+ "glob": "^10.4.5"
26
25
  },
27
26
  "devDependencies": {
28
27
  "@fastify/pre-commit": "^2.1.0",
29
28
  "c8": "^10.1.2",
30
- "grules": "^0.17.2",
29
+ "grules": "^0.17.3",
31
30
  "tinybench": "^2.8.0"
32
31
  },
33
32
  "repository": {
package/src/html.js CHANGED
@@ -1,11 +1,11 @@
1
1
  const escapeRegExp = /["&'<>`]/;
2
2
 
3
3
  const escapeFunction = (string) => {
4
- const stringLength = string.length;
5
- let start = 0;
6
4
  let escaped = "";
5
+ let start = 0;
6
+ let end = 0;
7
7
 
8
- for (let end = 0; end !== stringLength; ++end) {
8
+ for (; end !== string.length; ++end) {
9
9
  switch (string.charCodeAt(end)) {
10
10
  case 34: // "
11
11
  escaped += string.slice(start, end) + "&#34;";
@@ -34,7 +34,7 @@ const escapeFunction = (string) => {
34
34
  }
35
35
  }
36
36
 
37
- escaped += string.slice(start, stringLength);
37
+ escaped += string.slice(start, end);
38
38
 
39
39
  return escaped;
40
40
  };
@@ -45,10 +45,10 @@ const escapeFunction = (string) => {
45
45
  * @returns {string} The HTML string.
46
46
  */
47
47
  const html = ({ raw: literals }, ...expressions) => {
48
- const expressionsLength = expressions.length;
49
48
  let accumulator = "";
49
+ let index = 0;
50
50
 
51
- for (let index = 0; index !== expressionsLength; ++index) {
51
+ for (; index !== expressions.length; ++index) {
52
52
  const expression = expressions[index];
53
53
  let literal = literals[index];
54
54
  let string =
@@ -69,7 +69,7 @@ const html = ({ raw: literals }, ...expressions) => {
69
69
  accumulator += literal + string;
70
70
  }
71
71
 
72
- accumulator += literals[expressionsLength];
72
+ accumulator += literals[index];
73
73
 
74
74
  return accumulator;
75
75
  };
@@ -80,9 +80,9 @@ const html = ({ raw: literals }, ...expressions) => {
80
80
  * @yields {string} The HTML strings.
81
81
  */
82
82
  const htmlGenerator = function* ({ raw: literals }, ...expressions) {
83
- const expressionsLength = expressions.length;
83
+ let index = 0;
84
84
 
85
- for (let index = 0; index !== expressionsLength; ++index) {
85
+ for (; index !== expressions.length; ++index) {
86
86
  let expression = expressions[index];
87
87
  let literal = literals[index];
88
88
  let string;
@@ -165,8 +165,8 @@ const htmlGenerator = function* ({ raw: literals }, ...expressions) {
165
165
  }
166
166
  }
167
167
 
168
- if (literals[expressionsLength]) {
169
- yield literals[expressionsLength];
168
+ if (literals[index]) {
169
+ yield literals[index];
170
170
  }
171
171
  };
172
172
 
@@ -176,9 +176,9 @@ const htmlGenerator = function* ({ raw: literals }, ...expressions) {
176
176
  * @yields {string} The HTML strings.
177
177
  */
178
178
  const htmlAsyncGenerator = async function* ({ raw: literals }, ...expressions) {
179
- const expressionsLength = expressions.length;
179
+ let index = 0;
180
180
 
181
- for (let index = 0; index !== expressionsLength; ++index) {
181
+ for (; index !== expressions.length; ++index) {
182
182
  let expression = await expressions[index];
183
183
  let literal = literals[index];
184
184
  let string;
@@ -264,8 +264,8 @@ const htmlAsyncGenerator = async function* ({ raw: literals }, ...expressions) {
264
264
  }
265
265
  }
266
266
 
267
- if (literals[expressionsLength]) {
268
- yield literals[expressionsLength];
267
+ if (literals[index]) {
268
+ yield literals[index];
269
269
  }
270
270
  };
271
271