cbst 1.0.0 → 1.0.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/LICENSE.md +10 -2
- package/README.md +35 -32
- package/dist/CacheBuster.d.ts +2 -2
- package/dist/CacheBuster.js +3 -3
- package/dist/CacheBusterCli.d.ts +2 -2
- package/dist/CacheBusterCli.js +3 -3
- package/dist/bin.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/package.json +3 -6
package/LICENSE.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
Copyright 2022-2024 Morris Brodersen <mb@morrisbrodersen.de>
|
|
2
2
|
|
|
3
|
-
Permission to use, copy, modify, and/or distribute this software for any purpose
|
|
3
|
+
Permission to use, copy, modify, and/or distribute this software for any purpose
|
|
4
|
+
with or without fee is hereby granted, provided that the above copyright notice
|
|
5
|
+
and this permission notice appear in all copies.
|
|
4
6
|
|
|
5
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
9
|
+
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
|
|
11
|
+
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
|
|
12
|
+
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
|
|
13
|
+
THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -81,7 +81,7 @@ The configuration file (JSON) supports the following properties:
|
|
|
81
81
|
- `dynamic`
|
|
82
82
|
- List of file patterns to treat as dynamic.
|
|
83
83
|
- Matching files will not be versioned.
|
|
84
|
-
- References
|
|
84
|
+
- References found in matching source files will be still be rewritten.
|
|
85
85
|
- Defaults to `["*.html"]`.
|
|
86
86
|
- `metadata`
|
|
87
87
|
- Metadata filename.
|
|
@@ -90,27 +90,29 @@ The configuration file (JSON) supports the following properties:
|
|
|
90
90
|
- Length of hashes in versioned filenames.
|
|
91
91
|
- Defaults to `10`.
|
|
92
92
|
|
|
93
|
-
File patterns support `*` (slash-free wildcards) and `/**/` (directory
|
|
93
|
+
File patterns support `*` (slash-free wildcards) and `/**/` (directory
|
|
94
|
+
wildcards).
|
|
94
95
|
|
|
95
96
|
## Versioning and References
|
|
96
97
|
|
|
97
|
-
As `cbst` transforms files, it also rewrites any references to other versioned
|
|
98
|
-
References are detected by scanning source files for **quoted strings**
|
|
98
|
+
As `cbst` transforms files, it also rewrites any references to other versioned
|
|
99
|
+
files. References are detected by scanning source files for **quoted strings**
|
|
100
|
+
that
|
|
99
101
|
|
|
100
102
|
- are double- or single-quoted,
|
|
101
103
|
- contain no whitespace or quotes,
|
|
102
104
|
- and have a file extension.
|
|
103
105
|
|
|
104
|
-
If a reference can be resolved to a file, and that file is not `dynamic`,
|
|
105
|
-
|
|
106
|
+
If a reference can be resolved to a file, and that file is not `dynamic`, the
|
|
107
|
+
reference is rewritten with the versioned filename.
|
|
106
108
|
|
|
107
109
|
If a reference cannot be resolved to a file, the reference is not modified.
|
|
108
110
|
|
|
109
111
|
## Static vs. Dynamic Files
|
|
110
112
|
|
|
111
|
-
**Static files** (not listed in `dynamic`) will be versioned based on a hash
|
|
112
|
-
|
|
113
|
-
|
|
113
|
+
**Static files** (not listed in `dynamic`) will be versioned based on a hash of
|
|
114
|
+
their contents, as well as the contents of any referenced files. Circular
|
|
115
|
+
references are resolved deterministically.
|
|
114
116
|
|
|
115
117
|
Static files should be delivered with a `Cache-Control` header that allows
|
|
116
118
|
browsers and proxies to cache them indefinitely. For example:
|
|
@@ -120,14 +122,14 @@ Cache-Control: public, max-age=31536000, immutable
|
|
|
120
122
|
```
|
|
121
123
|
|
|
122
124
|
**Dynamic files** (those listed in `dynamic`) will not be versioned, but any
|
|
123
|
-
references detected will be rewritten if necessary. For
|
|
124
|
-
`*.html` files are usually be marked dynamic because they are directly
|
|
125
|
+
references detected inside these files will be rewritten if necessary. For
|
|
126
|
+
example, `*.html` files are usually be marked dynamic because they are directly
|
|
125
127
|
visited, not indirectly requested like other files.
|
|
126
128
|
|
|
127
|
-
Dynamic files should be delivered with a `Cache-Control` header that
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
129
|
+
Dynamic files should be delivered with a `Cache-Control` header that requires
|
|
130
|
+
browsers and proxies to revalidate the file in a timely fashion. Additional
|
|
131
|
+
`E-Tag` or `Last-Modified` headers should be provided to allow conditional
|
|
132
|
+
requests. For example:
|
|
131
133
|
|
|
132
134
|
```
|
|
133
135
|
Cache-Control: public, max-age=604800, stale-while-revalidate=86400
|
|
@@ -141,16 +143,16 @@ See also
|
|
|
141
143
|
|
|
142
144
|
## Discussion
|
|
143
145
|
|
|
144
|
-
> I can't use my favorite libraries from NPM with this because they require
|
|
146
|
+
> I can't use my favorite libraries from NPM with this because they require
|
|
147
|
+
> Node.js resolution and/or bundling.
|
|
145
148
|
|
|
146
|
-
Chicken
|
|
147
|
-
|
|
148
|
-
assuming that everyone uses a bundler.
|
|
149
|
+
Chicken and egg problem here. The industry got used to bundlers and started
|
|
150
|
+
building libraries for the web assuming that everyone used a bundler.
|
|
149
151
|
|
|
150
|
-
Ask library authors to ship standard ESM modules.
|
|
151
|
-
|
|
152
|
+
Ask library authors to ship standard ESM modules. That will make all our lives
|
|
153
|
+
easier.
|
|
152
154
|
|
|
153
|
-
> Isn't bundling still more performant larger websites?
|
|
155
|
+
> Isn't bundling still more performant for larger websites?
|
|
154
156
|
|
|
155
157
|
You should be fine if your website is delivered via HTTP/2 with compression and
|
|
156
158
|
solid cache control.
|
|
@@ -158,21 +160,22 @@ solid cache control.
|
|
|
158
160
|
For recurring users, bundled websites that are modified regularly require
|
|
159
161
|
downloading/parsing the entire bundle after every modification.
|
|
160
162
|
|
|
161
|
-
With fine-grained file versioning and long-term caching,
|
|
162
|
-
|
|
163
|
-
but recurring users will have a better experience.
|
|
163
|
+
With fine-grained file versioning and long-term caching, the first page visit
|
|
164
|
+
may suffer, but recurring users will have a better experience.
|
|
164
165
|
|
|
165
166
|
Finally, avoiding frameworks and large dependencies is a much more effective
|
|
166
167
|
optimization in the first place.
|
|
167
168
|
|
|
168
169
|
> What about minification?
|
|
169
170
|
|
|
170
|
-
It's out of scope
|
|
171
|
-
|
|
172
|
-
and any integration with minifiers will probably result in config/plug-in hell.
|
|
171
|
+
It's out of scope for `cbst`. There are too many options to consider, and any
|
|
172
|
+
integration with minifiers will probably result in config/plug-in hell.
|
|
173
173
|
|
|
174
|
-
|
|
174
|
+
Instead, websites should be minified in a separate pass during a production
|
|
175
|
+
build, usually before cache busting.
|
|
175
176
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
177
|
+
> Why is this implemented with regular expressions? Everyone knows you can't
|
|
178
|
+
> parse HTML, CSS, and JS like that!!1
|
|
179
|
+
|
|
180
|
+
It's a trade-off. The RegExp-based implementation is simple, fast, and will only
|
|
181
|
+
fail in obscure cases (hopefully).
|
package/dist/CacheBuster.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import EventEmitter from 'events';
|
|
2
|
-
import { Cache } from './util/Cache';
|
|
3
|
-
import { Glob } from './util/Glob';
|
|
2
|
+
import { Cache } from './util/Cache.js';
|
|
3
|
+
import { Glob } from './util/Glob.js';
|
|
4
4
|
export interface CacheBusterConfig {
|
|
5
5
|
/**
|
|
6
6
|
* List of file patterns to exclude entirely.
|
package/dist/CacheBuster.js
CHANGED
|
@@ -2,9 +2,9 @@ import { createHash } from 'crypto';
|
|
|
2
2
|
import EventEmitter from 'events';
|
|
3
3
|
import { promises as fs } from 'fs';
|
|
4
4
|
import { posix as path } from 'path';
|
|
5
|
-
import { ReferenceError } from './ReferenceError';
|
|
6
|
-
import { Cache } from './util/Cache';
|
|
7
|
-
import { Glob } from './util/Glob';
|
|
5
|
+
import { ReferenceError } from './ReferenceError.js';
|
|
6
|
+
import { Cache } from './util/Cache.js';
|
|
7
|
+
import { Glob } from './util/Glob.js';
|
|
8
8
|
export class CacheBuster extends EventEmitter {
|
|
9
9
|
static defaultConfig = {
|
|
10
10
|
exclude: [],
|
package/dist/CacheBusterCli.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CacheBusterConfig } from './CacheBuster';
|
|
2
|
-
import { ConsoleLike } from './util/ConsoleLike';
|
|
1
|
+
import { CacheBusterConfig } from './CacheBuster.js';
|
|
2
|
+
import { ConsoleLike } from './util/ConsoleLike.js';
|
|
3
3
|
export declare class CacheBusterCli {
|
|
4
4
|
protected console: ConsoleLike;
|
|
5
5
|
constructor(console?: ConsoleLike);
|
package/dist/CacheBusterCli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { promises as fs } from 'fs';
|
|
2
|
-
import { CacheBuster } from './CacheBuster';
|
|
3
|
-
import { isRecord } from './util/isRecord';
|
|
4
|
-
import { isStringArray } from './util/isStringArray';
|
|
2
|
+
import { CacheBuster } from './CacheBuster.js';
|
|
3
|
+
import { isRecord } from './util/isRecord.js';
|
|
4
|
+
import { isStringArray } from './util/isStringArray.js';
|
|
5
5
|
export class CacheBusterCli {
|
|
6
6
|
console;
|
|
7
7
|
constructor(console = global.console) {
|
package/dist/bin.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './CacheBuster';
|
|
2
|
-
export * from './CacheBusterCli';
|
|
3
|
-
export * from './ReferenceError';
|
|
1
|
+
export * from './CacheBuster.js';
|
|
2
|
+
export * from './CacheBusterCli.js';
|
|
3
|
+
export * from './ReferenceError.js';
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './CacheBuster';
|
|
2
|
-
export * from './CacheBusterCli';
|
|
3
|
-
export * from './ReferenceError';
|
|
1
|
+
export * from './CacheBuster.js';
|
|
2
|
+
export * from './CacheBusterCli.js';
|
|
3
|
+
export * from './ReferenceError.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cbst",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "A cache buster that versions a website's files for immutable cache control",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"versioning",
|
|
@@ -34,18 +34,15 @@
|
|
|
34
34
|
"lint": "eslint .",
|
|
35
35
|
"format": "prettier --write .",
|
|
36
36
|
"format-check": "prettier --check .",
|
|
37
|
-
"test": "
|
|
37
|
+
"test": "node --import tsx --test test/*.test.ts test/*/*.test.ts"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/jest": "^29.1.2",
|
|
41
40
|
"@types/node": "^20.14.8",
|
|
42
41
|
"@typescript-eslint/eslint-plugin": "^7.13.1",
|
|
43
42
|
"@typescript-eslint/parser": "^7.13.1",
|
|
44
43
|
"eslint": "^8.15.0",
|
|
45
|
-
"jest": "^29.1.2",
|
|
46
44
|
"prettier": "^3.3.2",
|
|
47
|
-
"
|
|
48
|
-
"ts-node": "^10.9.1",
|
|
45
|
+
"tsx": "^4.16.2",
|
|
49
46
|
"typescript": "^5.0.4"
|
|
50
47
|
}
|
|
51
48
|
}
|