cbst 0.2.0 → 0.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/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ # 0.2.1
4
+
5
+ - Ignore `mailto:` and other protocols properly
6
+ - Update deps
7
+
3
8
  # 0.2.0
4
9
 
5
10
  - 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
 
@@ -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,7 @@ 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
- isReference(reference: string): boolean;
80
+ isResolvableReference(reference: string): boolean;
80
81
  resolveReference(base: string, reference: string): string;
81
82
  getBase(file: string): Promise<string>;
82
83
  formatVersion(hash: string): string;
@@ -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-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.isReference(reference))
89
+ if (!this.isResolvableReference(reference))
89
90
  return match;
90
91
  const hash = hashes[i++];
91
92
  if (!hash)
@@ -143,14 +144,14 @@ 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.isReference(reference)) {
147
+ if (this.isResolvableReference(reference)) {
147
148
  references.push(this.resolveReference(base, reference));
148
149
  }
149
150
  }
150
151
  return references;
151
152
  }
152
- isReference(reference) {
153
- return !reference.includes('//');
153
+ isResolvableReference(reference) {
154
+ return !reference.match(this.externalReferenceRx);
154
155
  }
155
156
  resolveReference(base, reference) {
156
157
  if (reference[0] === '/')
@@ -199,7 +200,6 @@ class CacheBuster extends events_1.default {
199
200
  return s;
200
201
  }
201
202
  }
202
- exports.CacheBuster = CacheBuster;
203
203
  CacheBuster.defaultConfig = {
204
204
  exclude: [],
205
205
  source: ['*.html', '*.css', '*.js', '*.svg'],
@@ -208,3 +208,4 @@ CacheBuster.defaultConfig = {
208
208
  manifest: '.manifest.json',
209
209
  hashLength: 10,
210
210
  };
211
+ exports.CacheBuster = CacheBuster;
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "cbst",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
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": "^4.6.4"
43
+ "typescript": "^5.0.4"
39
44
  }
40
45
  }