ghtml 2.2.0 → 2.2.1
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/bin/README.md +1 -1
- package/bin/example/routes/index.js +2 -0
- package/bin/example/server.js +2 -0
- package/bin/src/utils.js +24 -32
- package/package.json +1 -1
package/bin/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
Lets you append unique hashes to assets referenced in your views to aggressively cache them while guaranteeing that clients receive the most recent versions.
|
|
2
2
|
|
|
3
3
|
## Usage
|
|
4
4
|
|
package/bin/example/server.js
CHANGED
package/bin/src/utils.js
CHANGED
|
@@ -38,42 +38,34 @@ const updateFilePathsWithHashes = async (
|
|
|
38
38
|
|
|
39
39
|
for await (const filePath of filesIterable) {
|
|
40
40
|
let content = await readFile(filePath, "utf8");
|
|
41
|
-
let
|
|
41
|
+
let found = false;
|
|
42
42
|
|
|
43
43
|
for (const [originalPath, hash] of fileHashes) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
`hash=${hash}`,
|
|
67
|
-
);
|
|
68
|
-
content = `${beforePath}${originalPath}?${newQueryString}${afterPath.slice(queryStart + queryString.length + 1)}`;
|
|
69
|
-
continue;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
content = `${beforePath}${originalPath}?hash=${hash}&${afterPath.slice(queryStart + 1)}`;
|
|
73
|
-
}
|
|
44
|
+
const escapedPath = originalPath.replace(
|
|
45
|
+
/[$()*+.?[\\\]^{|}]/gu,
|
|
46
|
+
"\\$&",
|
|
47
|
+
);
|
|
48
|
+
const regex = new RegExp(
|
|
49
|
+
`(?<path>${escapedPath})(\\?(?<queryString>[^#"'\`]*))?`,
|
|
50
|
+
"gu",
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
content = content.replace(
|
|
54
|
+
regex,
|
|
55
|
+
(match, p1, p2, p3, offset, string, groups) => {
|
|
56
|
+
found = true;
|
|
57
|
+
const { path, queryString } = groups;
|
|
58
|
+
|
|
59
|
+
return !queryString
|
|
60
|
+
? `${path}?hash=${hash}`
|
|
61
|
+
: queryString.includes("hash=")
|
|
62
|
+
? `${path}?${queryString.replace(/(?<hash>hash=)[\dA-Fa-f]*/u, `$1${hash}`)}`
|
|
63
|
+
: `${path}?hash=${hash}&${queryString}`;
|
|
64
|
+
},
|
|
65
|
+
);
|
|
74
66
|
}
|
|
75
67
|
|
|
76
|
-
if (
|
|
68
|
+
if (found) {
|
|
77
69
|
await writeFile(filePath, content);
|
|
78
70
|
}
|
|
79
71
|
}
|
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.2.
|
|
6
|
+
"version": "2.2.1",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"bin": "./bin/src/index.js",
|
|
9
9
|
"main": "./src/index.js",
|