cbst 1.0.1 → 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.
Files changed (3) hide show
  1. package/LICENSE.md +10 -2
  2. package/README.md +35 -32
  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 with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
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 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
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 from matching source files will be still be rewritten.
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 wildcards).
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 files.
98
- References are detected by scanning source files for **quoted strings** that
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
- the reference is rewritten with the versioned filename.
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
- of their contents, as well as the contents of any referenced files.
113
- Circular references are resolved deterministically.
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 example,
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
- requires browsers and proxies to revalidate the file in a timely fashion.
129
- Additional `E-Tag` or `Last-Modified` headers should be provided to
130
- allow conditional requests. For example:
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 Node.js resolution and/or bundling.
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 & egg problem here.
147
- The industry got used to bundlers and started building libraries for the web
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
- That will make all our lives easier.
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
- the first page visit may suffer,
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
- There are too many options to consider,
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
- > Why is this implemented with regular expressions? Everyone knows you can't parse HTML, CSS, and JS like that!!1
174
+ Instead, websites should be minified in a separate pass during a production
175
+ build, usually before cache busting.
175
176
 
176
- It's a trade-off.
177
- The RegExp-based implementation is simple, fast,
178
- and will only fail in obscure cases (hopefully).
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cbst",
3
- "version": "1.0.1",
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": "jest --runInBand --coverage"
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
- "ts-jest": "^29.0.3",
48
- "ts-node": "^10.9.1",
45
+ "tsx": "^4.16.2",
49
46
  "typescript": "^5.0.4"
50
47
  }
51
48
  }