@johnhenry/sitefile 0.0.4 → 0.0.5
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 +10 -0
- package/README.md +1 -1
- package/lib/src/explain.js +2 -1
- package/lib/src/language/ast.d.ts +3 -3
- package/lib/src/language/parser.js +5 -4
- package/lib/src/precompress.d.ts +11 -2
- package/lib/src/precompress.js +36 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.0.5 (2026-11-09)
|
|
4
|
+
|
|
5
|
+
- **`PRECOMPRESS br`** (johnhenry/sitefile#203): Brotli sidecars `<file>.br`, alone or with gzip
|
|
6
|
+
(`PRECOMPRESS br gzip /`), each written only when smaller. Byte-identical in both
|
|
7
|
+
implementations because both run libbrotli 1.2.0 with the same settings (quality 11, window 22,
|
|
8
|
+
generic mode): node:zlib in TypeScript, Google's C encoder vendored in `rust/vendor/brotli` and
|
|
9
|
+
compiled by `rust/build.rs` in Rust (approved by the owner; building the Rust port now needs a C
|
|
10
|
+
compiler). Checked over about 1,250 inputs (`rust/tests/fixtures/brotli/corpus.mjs`).
|
|
11
|
+
`PRECOMPRESS zstd` is still `E_UNSUPPORTED`.
|
|
12
|
+
|
|
3
13
|
## 0.0.4 (2026-11-09)
|
|
4
14
|
|
|
5
15
|
- **`.tar.zst` / `.tzst` archives** (johnhenry/sitefile#221): `IMPORT … AS tree`, `serve`, `verify` and
|
package/README.md
CHANGED
|
@@ -92,7 +92,7 @@ no runtime dependencies.
|
|
|
92
92
|
| `MIME <.ext> <type/subtype>` | yes; a custom Content-Type (`.usdz`, `.ts` as MPEG-TS) as a `/_headers` rule, which also types the files in a Web Bundle export |
|
|
93
93
|
| `CHECKLINKS [--warn] [--external]` | yes; fails (or warns) on links to files that do not exist, with file and line; `--external` requests http(s) links under the network policy |
|
|
94
94
|
| `FINGERPRINT [--overwrite] [--no-cache-headers] <pattern>… [MANIFEST <dest>] [INTEGRITY]` | yes; renames assets to `name.<hash>.ext` and rewrites the HTML and CSS that reference them, plus a JSON manifest, `Cache-Control` lines in `/_headers` and (INTEGRITY) SRI attributes |
|
|
95
|
-
| `PRECOMPRESS [--overwrite] [gzip] <pattern>… [MIN <bytes>]` | yes; deterministic `.gz` sidecars of text files for hosts that serve them in place of the file (nginx `gzip_static`, Caddy `precompressed`); `
|
|
95
|
+
| `PRECOMPRESS [--overwrite] [gzip] [br] <pattern>… [MIN <bytes>]` | yes; deterministic `.gz` and `.br` sidecars of text files for hosts that serve them in place of the file (nginx `gzip_static`, Caddy `precompressed`); `zstd` is not supported yet |
|
|
96
96
|
| `PRECACHE [--overwrite] <pattern>… [TO <dest>] [INTO <service-worker>]` | yes; a Workbox-style `[{url, revision}]` precache manifest (fingerprinted files get `revision: null`), or injected at `self.__WB_MANIFEST` |
|
|
97
97
|
| `EXPORT <path> [AS directory\|zip\|tar\|tgz\|wbn\|oci\|car\|html\|mhtml\|warc\|swbn\|wacz\|epub] [BASE <https-url>] [AT <root>] [COMPRESSION gzip\|none] [KEY <secret-id>] [FOR <host>]` | yes; `FOR netlify\|cloudflare\|vercel\|firebase\|azure\|github-pages\|s3` writes REDIRECT and HEADER as that host reads them (a rule it cannot express is an error, a warning with `--lossy`); archives are deterministic, `wbn` is an unsigned Web Bundle (needs `BASE` or `--base-url`; `COMPRESSION gzip` gzips it, default `none`), `oci` is a single-layer OCI image of the files (under `AT`, default `/srv/www`; `COMPRESSION` sets its layer, default `gzip`), `car` is an IPFS CARv1 file whose root CID matches kubo's `ipfs add -r --cid-version=1`, `html` is `index.html` with its assets inlined as `data:` URIs, `mhtml` the same page and assets as one MHTML file, `warc` a WARC/1.1 web archive of every file at `BASE` (also imported and served), `swbn` a Signed Web Bundle for an Isolated Web App, signed with the Ed25519 key in `--secret` `KEY`, `wacz` that WARC as a WACZ package for ReplayWeb.page, `epub` an EPUB 3 book of the XHTML pages |
|
|
98
98
|
|
package/lib/src/explain.js
CHANGED
|
@@ -2,6 +2,7 @@ import { statSync } from 'node:fs';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { SitefileError } from './errors.js';
|
|
4
4
|
import { joinVirtual, normalizeVirtual } from './paths.js';
|
|
5
|
+
import { sidecarSource } from './precompress.js';
|
|
5
6
|
import { importedStageRefs } from './planner.js';
|
|
6
7
|
import { importedStage } from './language/ast.js';
|
|
7
8
|
// `sitefile graph` and `sitefile why` (issue #94): the dependency graph of a plan, and the history of one
|
|
@@ -421,7 +422,7 @@ export function why(result, raw, contextDir) {
|
|
|
421
422
|
else if (op.kind === 'FINGERPRINT')
|
|
422
423
|
inputs.push(op.manifest === file ? 'the files it renamed' : 'references to renamed files');
|
|
423
424
|
else if (op.kind === 'PRECOMPRESS')
|
|
424
|
-
inputs.push(`${file
|
|
425
|
+
inputs.push(`${sidecarSource(file)} (compressed)`);
|
|
425
426
|
else
|
|
426
427
|
inputs.push(`list ${op.list}`);
|
|
427
428
|
events.push({ location: at(op.span.line), instruction: operationLabel(op), stage: display, path: file, action: prev ? 'overwrite' : 'write', digest: next.digest, inputs });
|
|
@@ -380,10 +380,10 @@ export interface LanguagesInstruction {
|
|
|
380
380
|
readonly codes: readonly Operand[];
|
|
381
381
|
readonly default?: Operand;
|
|
382
382
|
}
|
|
383
|
-
/** A PRECOMPRESS sidecar format: `gzip` writes `<file>.gz
|
|
384
|
-
export type PrecompressFormat = 'gzip';
|
|
383
|
+
/** A PRECOMPRESS sidecar format: `gzip` writes `<file>.gz`, `br` writes `<file>.br` (`zstd` is reserved: no encoder yet). */
|
|
384
|
+
export type PrecompressFormat = 'gzip' | 'br';
|
|
385
385
|
/**
|
|
386
|
-
* `PRECOMPRESS [--overwrite] [gzip]
|
|
386
|
+
* `PRECOMPRESS [--overwrite] [gzip] [br] <pattern>… [MIN <bytes>]`: write a `.gz` and/or `.br` sidecar next to each matching
|
|
387
387
|
* compressible file of at least MIN bytes, when it is smaller.
|
|
388
388
|
*/
|
|
389
389
|
export interface PrecompressInstruction {
|
|
@@ -619,9 +619,10 @@ function parseLanguages(c, span) {
|
|
|
619
619
|
c.expectEnd();
|
|
620
620
|
return { kind: 'LANGUAGES', span, codes, ...(dflt ? { default: dflt } : {}) };
|
|
621
621
|
}
|
|
622
|
-
/** Sidecar formats PRECOMPRESS knows
|
|
622
|
+
/** Sidecar formats PRECOMPRESS knows. gzip uses src/deflate.ts (shared with the Rust port), br node:zlib's Brotli
|
|
623
|
+
* (the Rust port vendors the same C encoder); zstd has no encoder yet. */
|
|
623
624
|
const PRECOMPRESS_FORMATS = ['gzip', 'br', 'zstd'];
|
|
624
|
-
/** `PRECOMPRESS [--overwrite] [gzip]
|
|
625
|
+
/** `PRECOMPRESS [--overwrite] [gzip] [br] <pattern>… [MIN <bytes>]` */
|
|
625
626
|
function parsePrecompress(c, span) {
|
|
626
627
|
const flags = parseFlags(c, { overwrite: 'bare' });
|
|
627
628
|
const formats = [];
|
|
@@ -633,8 +634,8 @@ function parsePrecompress(c, span) {
|
|
|
633
634
|
c.reset(mark);
|
|
634
635
|
break;
|
|
635
636
|
}
|
|
636
|
-
if (w
|
|
637
|
-
throw c.error('E_UNSUPPORTED',
|
|
637
|
+
if (w === 'zstd') {
|
|
638
|
+
throw c.error('E_UNSUPPORTED', 'PRECOMPRESS zstd is not supported yet: sitefile has no Zstandard encoder that writes the same bytes in both implementations (use gzip or br)', at);
|
|
638
639
|
}
|
|
639
640
|
if (formats.includes(w))
|
|
640
641
|
throw c.error('E_SYNTAX', `${w} given twice`, at);
|
package/lib/src/precompress.d.ts
CHANGED
|
@@ -1,18 +1,27 @@
|
|
|
1
1
|
import type { SourceSpan } from './errors.js';
|
|
2
|
+
import type { PrecompressFormat } from './language/ast.js';
|
|
2
3
|
import { type Tree } from './tree.js';
|
|
3
4
|
/** Extensions (lowercase, after the last dot) of the file types PRECOMPRESS compresses: text, scripts, data, fonts without their own compression. */
|
|
4
5
|
export declare const COMPRESSIBLE: Set<string>;
|
|
5
6
|
/** Whether a path names a compressible file type (by its extension, ASCII case-insensitive). */
|
|
6
7
|
export declare function compressible(path: string): boolean;
|
|
8
|
+
/** The Brotli encoder version rust/vendor/brotli holds; br sidecars match the Rust port's only while Node bundles it. */
|
|
9
|
+
export declare const BROTLI_VERSION = "1.2.0";
|
|
10
|
+
/** `data` as Brotli: quality 11, window 22 (4 MiB), generic mode, one FINISH over the whole input (rust/src/brotli.rs). */
|
|
11
|
+
export declare function brotli(data: Uint8Array): Uint8Array;
|
|
12
|
+
/** The file a sidecar compresses: `path` without its `.gz` or `.br`. */
|
|
13
|
+
export declare function sidecarSource(path: string): string;
|
|
7
14
|
export interface PrecompressOp {
|
|
15
|
+
readonly formats: readonly PrecompressFormat[];
|
|
8
16
|
readonly patterns: readonly string[];
|
|
9
17
|
readonly min: number;
|
|
10
18
|
readonly overwrite: boolean;
|
|
11
19
|
readonly span: SourceSpan;
|
|
12
20
|
}
|
|
13
21
|
/**
|
|
14
|
-
* The tree with a `<path>.gz
|
|
15
|
-
*
|
|
22
|
+
* The tree with a sidecar per format (`<path>.gz`: gzip, fixed header; `<path>.br`: Brotli) for every file
|
|
23
|
+
* that matches a pattern, is compressible and has at least `min` bytes, when that format compresses it to
|
|
24
|
+
* fewer bytes than it has. Sidecars keep the
|
|
16
25
|
* file's mode and get the origin `origin`; one that would replace a different file is a conflict unless
|
|
17
26
|
* `overwrite`. Warns when no file matches the patterns.
|
|
18
27
|
*/
|
package/lib/src/precompress.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
// PRECOMPRESS (docs/LANGUAGE.md, "Precompressed sidecars"): write `<file>.gz` and/or `<file>.br` next to
|
|
2
|
+
// compressible files, for hosts and servers that serve them in place of the file (nginx gzip_static,
|
|
3
|
+
// Caddy precompressed, sirv). Ported as rust/src/precompress.rs. gzip uses the shared deflate encoder
|
|
4
|
+
// (src/deflate.ts); br uses node:zlib's Brotli, and the Rust port compiles the same C encoder at the
|
|
5
|
+
// same version (rust/vendor/brotli, rust/src/brotli.rs) with the same settings, so the sidecars are
|
|
6
|
+
// byte-identical.
|
|
7
|
+
import { brotliCompressSync, constants } from 'node:zlib';
|
|
1
8
|
import { gzip } from './deflate.js';
|
|
2
9
|
import { globMatches } from './fingerprint.js';
|
|
3
10
|
import { makeFile } from './tree.js';
|
|
@@ -12,9 +19,30 @@ export function compressible(path) {
|
|
|
12
19
|
const dot = base.lastIndexOf('.');
|
|
13
20
|
return dot > 0 && COMPRESSIBLE.has(base.slice(dot + 1).toLowerCase());
|
|
14
21
|
}
|
|
22
|
+
/** The Brotli encoder version rust/vendor/brotli holds; br sidecars match the Rust port's only while Node bundles it. */
|
|
23
|
+
export const BROTLI_VERSION = '1.2.0';
|
|
24
|
+
/** `data` as Brotli: quality 11, window 22 (4 MiB), generic mode, one FINISH over the whole input (rust/src/brotli.rs). */
|
|
25
|
+
export function brotli(data) {
|
|
26
|
+
return new Uint8Array(brotliCompressSync(data, {
|
|
27
|
+
params: {
|
|
28
|
+
[constants.BROTLI_PARAM_QUALITY]: 11,
|
|
29
|
+
[constants.BROTLI_PARAM_LGWIN]: 22,
|
|
30
|
+
[constants.BROTLI_PARAM_MODE]: constants.BROTLI_MODE_GENERIC,
|
|
31
|
+
},
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
const ENCODERS = {
|
|
35
|
+
gzip: { ext: '.gz', encode: gzip },
|
|
36
|
+
br: { ext: '.br', encode: brotli },
|
|
37
|
+
};
|
|
38
|
+
/** The file a sidecar compresses: `path` without its `.gz` or `.br`. */
|
|
39
|
+
export function sidecarSource(path) {
|
|
40
|
+
return path.endsWith('.gz') || path.endsWith('.br') ? path.slice(0, -3) : path;
|
|
41
|
+
}
|
|
15
42
|
/**
|
|
16
|
-
* The tree with a `<path>.gz
|
|
17
|
-
*
|
|
43
|
+
* The tree with a sidecar per format (`<path>.gz`: gzip, fixed header; `<path>.br`: Brotli) for every file
|
|
44
|
+
* that matches a pattern, is compressible and has at least `min` bytes, when that format compresses it to
|
|
45
|
+
* fewer bytes than it has. Sidecars keep the
|
|
18
46
|
* file's mode and get the origin `origin`; one that would replace a different file is a conflict unless
|
|
19
47
|
* `overwrite`. Warns when no file matches the patterns.
|
|
20
48
|
*/
|
|
@@ -26,9 +54,12 @@ export function precompress(tree, op, origin, warn) {
|
|
|
26
54
|
for (const [p, node] of matched) {
|
|
27
55
|
if (!compressible(p) || node.bytes.byteLength < op.min)
|
|
28
56
|
continue;
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
57
|
+
for (const format of op.formats) {
|
|
58
|
+
const { ext, encode } = ENCODERS[format];
|
|
59
|
+
const out = encode(node.bytes);
|
|
60
|
+
if (out.byteLength < node.bytes.byteLength)
|
|
61
|
+
files.push([p + ext, makeFile(out, origin, node.mode)]);
|
|
62
|
+
}
|
|
32
63
|
}
|
|
33
64
|
return files.length ? tree.withFiles(files, op.overwrite ? 'overwrite' : 'error', op.span) : tree;
|
|
34
65
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@johnhenry/sitefile",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Docker-inspired static artifact builder: compose immutable file trees from local and remote sources, render templates, and export a deployable site. No container runtime, no shell, no runtime dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"static-site",
|