cbst 2.0.1 → 3.0.0
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/LICENSE.md +1 -1
- package/README.md +3 -6
- package/dist/CacheBuster.d.ts +4 -3
- package/dist/CacheBuster.js +7 -1
- package/package.json +7 -4
package/LICENSE.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Copyright 2022-
|
|
1
|
+
Copyright 2022-2026 Morris Brodersen <mb@morrisbrodersen.de>
|
|
2
2
|
|
|
3
3
|
Permission to use, copy, modify, and/or distribute this software for any purpose
|
|
4
4
|
with or without fee is hereby granted, provided that the above copyright notice
|
package/README.md
CHANGED
|
@@ -95,19 +95,16 @@ wildcards).
|
|
|
95
95
|
|
|
96
96
|
## Versioning and References
|
|
97
97
|
|
|
98
|
-
As `cbst` transforms files, it
|
|
99
|
-
|
|
100
|
-
that
|
|
98
|
+
As `cbst` transforms files, it rewrites any references to other versioned files.
|
|
99
|
+
References are detected by scanning source files for **quoted strings** that
|
|
101
100
|
|
|
102
101
|
- are double- or single-quoted,
|
|
103
102
|
- contain no whitespace or quotes,
|
|
104
|
-
- and have a file extension.
|
|
103
|
+
- and have a file extension resolving to a known MIME type.
|
|
105
104
|
|
|
106
105
|
If a reference can be resolved to a file, and that file is not `dynamic`, the
|
|
107
106
|
reference is rewritten with the versioned filename.
|
|
108
107
|
|
|
109
|
-
If a reference cannot be resolved to a file, the reference is not modified.
|
|
110
|
-
|
|
111
108
|
## Static vs. Dynamic Files
|
|
112
109
|
|
|
113
110
|
**Static files** (not listed in `dynamic`) will be versioned based on a hash of
|
package/dist/CacheBuster.d.ts
CHANGED
|
@@ -56,7 +56,7 @@ export declare class CacheBuster extends EventEmitter {
|
|
|
56
56
|
protected hashFileCache: Cache<string | undefined>;
|
|
57
57
|
protected getReferencesCache: Cache<string[]>;
|
|
58
58
|
protected hashRawFileCache: Cache<string>;
|
|
59
|
-
protected readFileCache: Cache<
|
|
59
|
+
protected readFileCache: Cache<NonSharedBuffer>;
|
|
60
60
|
protected map: Map<string, string>;
|
|
61
61
|
protected unresolved: Map<string, Set<string>>;
|
|
62
62
|
protected referenceRx: RegExp;
|
|
@@ -68,7 +68,7 @@ export declare class CacheBuster extends EventEmitter {
|
|
|
68
68
|
writeMetadata(file: string): Promise<void>;
|
|
69
69
|
handleDir(dir: string): Promise<void>;
|
|
70
70
|
handleFile(file: string): Promise<void>;
|
|
71
|
-
transformFile(file: string): Promise<string |
|
|
71
|
+
transformFile(file: string): Promise<string | NonSharedBuffer>;
|
|
72
72
|
hashFile(file: string): Promise<string | undefined>;
|
|
73
73
|
hashFileReferences(file: string, exclude: string[]): Promise<string[]>;
|
|
74
74
|
hashRawFile(file: string): Promise<string>;
|
|
@@ -76,11 +76,12 @@ export declare class CacheBuster extends EventEmitter {
|
|
|
76
76
|
getReferences(file: string): Promise<string[]>;
|
|
77
77
|
isResolvableReference(reference: string): boolean;
|
|
78
78
|
isExternalReference(reference: string): boolean;
|
|
79
|
+
hasKnownMIME(reference: string): boolean;
|
|
79
80
|
resolveReference(base: string, reference: string): string;
|
|
80
81
|
getBase(file: string): Promise<string>;
|
|
81
82
|
formatVersion(hash: string): string;
|
|
82
83
|
hash(inputs: (string | Buffer)[]): string;
|
|
83
|
-
readFile(file: string): Promise<
|
|
84
|
+
readFile(file: string): Promise<NonSharedBuffer>;
|
|
84
85
|
readDir(dir: string): Promise<import("fs").Dirent<string>[]>;
|
|
85
86
|
writeFile(file: string, data: string | Buffer): Promise<void>;
|
|
86
87
|
safePath(rootDir: string, candidate: string): string;
|
package/dist/CacheBuster.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import mime from 'mime';
|
|
1
2
|
import { createHash } from 'node:crypto';
|
|
2
3
|
import EventEmitter from 'node:events';
|
|
3
4
|
import { promises as fs } from 'node:fs';
|
|
@@ -171,11 +172,16 @@ export class CacheBuster extends EventEmitter {
|
|
|
171
172
|
return references;
|
|
172
173
|
}
|
|
173
174
|
isResolvableReference(reference) {
|
|
174
|
-
return (!this.isExternalReference(reference) &&
|
|
175
|
+
return (!this.isExternalReference(reference) &&
|
|
176
|
+
!this.excludeGlob.match(reference) &&
|
|
177
|
+
this.hasKnownMIME(reference));
|
|
175
178
|
}
|
|
176
179
|
isExternalReference(reference) {
|
|
177
180
|
return !!reference.match(this.externalReferenceRx);
|
|
178
181
|
}
|
|
182
|
+
hasKnownMIME(reference) {
|
|
183
|
+
return !!mime.getType(reference);
|
|
184
|
+
}
|
|
179
185
|
resolveReference(base, reference) {
|
|
180
186
|
if (reference[0] === '/') {
|
|
181
187
|
return reference.slice(1);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cbst",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "A cache buster that versions a website's files for immutable cache control",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"versioning",
|
|
@@ -37,13 +37,16 @@
|
|
|
37
37
|
"test": "node --import tsx --test test/*.test.ts test/*/*.test.ts"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@eslint/js": "^
|
|
40
|
+
"@eslint/js": "^10.0.1",
|
|
41
41
|
"@types/eslint__js": "^8.42.3",
|
|
42
42
|
"@types/node": "^20.14.8",
|
|
43
|
-
"eslint": "^
|
|
43
|
+
"eslint": "^10.16.0",
|
|
44
44
|
"prettier": "^3.3.2",
|
|
45
45
|
"tsx": "^4.16.2",
|
|
46
|
-
"typescript": "^
|
|
46
|
+
"typescript": "^6.0.3",
|
|
47
47
|
"typescript-eslint": "^8.3.0"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"mime": "^4.1.2"
|
|
48
51
|
}
|
|
49
52
|
}
|