cbst 0.2.0 → 0.2.2
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/CHANGELOG.md +11 -0
- package/LICENSE.md +1 -1
- package/dist/CacheBuster.d.ts +3 -1
- package/dist/CacheBuster.js +9 -5
- package/dist/bin.js +1 -1
- package/package.json +7 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
# 0.2.2
|
|
4
|
+
|
|
5
|
+
- Fix CLI exit code
|
|
6
|
+
- Fix `exclude` not excluding some references
|
|
7
|
+
- Fix identification of external references
|
|
8
|
+
|
|
9
|
+
# 0.2.1
|
|
10
|
+
|
|
11
|
+
- Ignore `mailto:` and other protocols properly
|
|
12
|
+
- Update deps
|
|
13
|
+
|
|
3
14
|
# 0.2.0
|
|
4
15
|
|
|
5
16
|
- Exit with code 1 on errors (including unresolved references)
|
package/LICENSE.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2022 Morris Brodersen <mb@morrisbrodersen.de>
|
|
1
|
+
Copyright 2022-2023 Morris Brodersen <mb@morrisbrodersen.de>
|
|
2
2
|
|
|
3
3
|
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
4
4
|
|
package/dist/CacheBuster.d.ts
CHANGED
|
@@ -63,6 +63,7 @@ export declare class CacheBuster extends EventEmitter {
|
|
|
63
63
|
protected map: Map<string, string>;
|
|
64
64
|
protected unresolved: Map<string, Set<string>>;
|
|
65
65
|
protected referenceRx: RegExp;
|
|
66
|
+
protected externalReferenceRx: RegExp;
|
|
66
67
|
protected baseRx: RegExp;
|
|
67
68
|
protected extensionRx: RegExp;
|
|
68
69
|
constructor(options: CacheBusterOptions);
|
|
@@ -76,7 +77,8 @@ export declare class CacheBuster extends EventEmitter {
|
|
|
76
77
|
hashRawFile(file: string): Promise<string>;
|
|
77
78
|
handleReferenceError(error: Error, source: string, reference: string): void;
|
|
78
79
|
getReferences(file: string): Promise<string[]>;
|
|
79
|
-
|
|
80
|
+
isResolvableReference(reference: string): boolean;
|
|
81
|
+
isExternalReference(reference: string): boolean;
|
|
80
82
|
resolveReference(base: string, reference: string): string;
|
|
81
83
|
getBase(file: string): Promise<string>;
|
|
82
84
|
formatVersion(hash: string): string;
|
package/dist/CacheBuster.js
CHANGED
|
@@ -21,6 +21,7 @@ class CacheBuster extends events_1.default {
|
|
|
21
21
|
this.map = new Map();
|
|
22
22
|
this.unresolved = new Map();
|
|
23
23
|
this.referenceRx = /((")(([^"\s]+)\.([a-zA-Z0-9]+))")|((')(([^'\s]+)\.([a-zA-Z0-9]+))')|# sourceMappingURL=(([^\s]+)\.([a-zA-Z0-9]+))/g;
|
|
24
|
+
this.externalReferenceRx = /^([a-zA-Z][a-zA-Z0-9+.\-]*:|\/\/)/;
|
|
24
25
|
this.baseRx = /<base[^<>]+href\s*=\s*"([^"]+)"[^<>]*>/i;
|
|
25
26
|
this.extensionRx = /(?<=\.)[^.]+$/;
|
|
26
27
|
const o = { ...CacheBuster.defaultConfig, ...options };
|
|
@@ -85,7 +86,7 @@ class CacheBuster extends events_1.default {
|
|
|
85
86
|
const reference = groups[2] || groups[7] || groups[10];
|
|
86
87
|
const filename = groups[3] || groups[8] || groups[11];
|
|
87
88
|
const extension = groups[4] || groups[9] || groups[12];
|
|
88
|
-
if (!this.
|
|
89
|
+
if (!this.isResolvableReference(reference))
|
|
89
90
|
return match;
|
|
90
91
|
const hash = hashes[i++];
|
|
91
92
|
if (!hash)
|
|
@@ -143,14 +144,17 @@ class CacheBuster extends events_1.default {
|
|
|
143
144
|
const references = [];
|
|
144
145
|
for (const match of source.matchAll(this.referenceRx)) {
|
|
145
146
|
const reference = match[3] || match[8] || match[11];
|
|
146
|
-
if (this.
|
|
147
|
+
if (this.isResolvableReference(reference)) {
|
|
147
148
|
references.push(this.resolveReference(base, reference));
|
|
148
149
|
}
|
|
149
150
|
}
|
|
150
151
|
return references;
|
|
151
152
|
}
|
|
152
|
-
|
|
153
|
-
return !reference.
|
|
153
|
+
isResolvableReference(reference) {
|
|
154
|
+
return (!this.isExternalReference(reference) && !this.excludeGlob.match(reference));
|
|
155
|
+
}
|
|
156
|
+
isExternalReference(reference) {
|
|
157
|
+
return !!reference.match(this.externalReferenceRx);
|
|
154
158
|
}
|
|
155
159
|
resolveReference(base, reference) {
|
|
156
160
|
if (reference[0] === '/')
|
|
@@ -199,7 +203,6 @@ class CacheBuster extends events_1.default {
|
|
|
199
203
|
return s;
|
|
200
204
|
}
|
|
201
205
|
}
|
|
202
|
-
exports.CacheBuster = CacheBuster;
|
|
203
206
|
CacheBuster.defaultConfig = {
|
|
204
207
|
exclude: [],
|
|
205
208
|
source: ['*.html', '*.css', '*.js', '*.svg'],
|
|
@@ -208,3 +211,4 @@ CacheBuster.defaultConfig = {
|
|
|
208
211
|
manifest: '.manifest.json',
|
|
209
212
|
hashLength: 10,
|
|
210
213
|
};
|
|
214
|
+
exports.CacheBuster = CacheBuster;
|
package/dist/bin.js
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
const CacheBusterCli_1 = require("./CacheBusterCli");
|
|
5
5
|
const cli = new CacheBusterCli_1.CacheBusterCli();
|
|
6
|
-
cli.run(process.argv.slice(2));
|
|
6
|
+
cli.run(process.argv.slice(2)).then((exitCode) => process.exit(exitCode));
|
package/package.json
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cbst",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "A cache buster that versions a website's files for immutable cache control",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"versioning",
|
|
7
|
+
"revving",
|
|
8
|
+
"cache busting"
|
|
9
|
+
],
|
|
5
10
|
"author": "Morris Brodersen <mb@morrisbrodersen.de>",
|
|
6
11
|
"license": "ISC",
|
|
7
12
|
"repository": {
|
|
@@ -35,6 +40,6 @@
|
|
|
35
40
|
"prettier": "^2.6.2",
|
|
36
41
|
"ts-jest": "^29.0.3",
|
|
37
42
|
"ts-node": "^10.9.1",
|
|
38
|
-
"typescript": "^
|
|
43
|
+
"typescript": "^5.0.4"
|
|
39
44
|
}
|
|
40
45
|
}
|