@johnhenry/sitefile 0.0.2 → 0.0.3
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 +467 -0
- package/README.md +55 -6
- package/lib/src/archive-writers.d.ts +12 -2
- package/lib/src/archive-writers.js +53 -10
- package/lib/src/canonical.d.ts +16 -0
- package/lib/src/canonical.js +46 -0
- package/lib/src/car.d.ts +34 -0
- package/lib/src/car.js +203 -0
- package/lib/src/checklinks.js +8 -2
- package/lib/src/cli/bake.js +4 -3
- package/lib/src/cli/build-image.d.ts +1 -0
- package/lib/src/cli/build-image.js +1 -0
- package/lib/src/cli/common.js +4 -1
- package/lib/src/cli/hosts.d.ts +5 -0
- package/lib/src/cli/hosts.js +78 -0
- package/lib/src/cli/images.js +23 -5
- package/lib/src/cli/import-config.d.ts +2 -0
- package/lib/src/cli/import-config.js +56 -0
- package/lib/src/cli/index.d.ts +3 -1
- package/lib/src/cli/index.js +31 -2
- package/lib/src/cli/integrity.d.ts +2 -0
- package/lib/src/cli/integrity.js +77 -0
- package/lib/src/cli/network.d.ts +7 -0
- package/lib/src/cli/network.js +14 -3
- package/lib/src/cli/serve-keys.d.ts +39 -0
- package/lib/src/cli/serve-keys.js +106 -0
- package/lib/src/cli/serve-worker.js +46 -8
- package/lib/src/cli/servers.d.ts +124 -1
- package/lib/src/cli/servers.js +705 -62
- package/lib/src/cli/up.d.ts +2 -0
- package/lib/src/cli/up.js +193 -0
- package/lib/src/cli/watch.d.ts +14 -1
- package/lib/src/cli/watch.js +20 -3
- package/lib/src/cli.js +138 -18
- package/lib/src/csp.d.ts +17 -0
- package/lib/src/csp.js +52 -0
- package/lib/src/dictionary.d.ts +16 -0
- package/lib/src/dictionary.js +89 -0
- package/lib/src/epub.d.ts +5 -0
- package/lib/src/epub.js +113 -0
- package/lib/src/errors.d.ts +22 -9
- package/lib/src/errors.js +20 -1
- package/lib/src/executor.d.ts +31 -1
- package/lib/src/executor.js +192 -22
- package/lib/src/explain.js +33 -3
- package/lib/src/export-for.d.ts +42 -0
- package/lib/src/export-for.js +466 -0
- package/lib/src/export-formats.d.ts +2 -2
- package/lib/src/export-formats.js +52 -2
- package/lib/src/fingerprint.d.ts +3 -1
- package/lib/src/fingerprint.js +32 -5
- package/lib/src/host-config.d.ts +34 -0
- package/lib/src/host-config.js +645 -0
- package/lib/src/hosts.d.ts +47 -0
- package/lib/src/hosts.js +106 -0
- package/lib/src/index.d.ts +1 -1
- package/lib/src/index.js +1 -1
- package/lib/src/integrity.d.ts +115 -0
- package/lib/src/integrity.js +273 -0
- package/lib/src/language/ast.d.ts +116 -3
- package/lib/src/language/ast.js +7 -1
- package/lib/src/language/parser.js +176 -7
- package/lib/src/language/validate.js +21 -0
- package/lib/src/links.d.ts +33 -0
- package/lib/src/links.js +271 -3
- package/lib/src/lint.d.ts +1 -1
- package/lib/src/lint.js +26 -1
- package/lib/src/mime-data.d.ts +2 -0
- package/lib/src/mime-data.js +92 -0
- package/lib/src/oci.d.ts +20 -2
- package/lib/src/oci.js +70 -28
- package/lib/src/outdated.d.ts +3 -0
- package/lib/src/outdated.js +4 -4
- package/lib/src/planner.d.ts +69 -2
- package/lib/src/planner.js +150 -8
- package/lib/src/plugins/cache.d.ts +11 -0
- package/lib/src/plugins/cache.js +29 -0
- package/lib/src/plugins/host.d.ts +51 -2
- package/lib/src/plugins/host.js +141 -16
- package/lib/src/plugins/wasm.js +1 -3
- package/lib/src/portable.d.ts +8 -0
- package/lib/src/portable.js +47 -0
- package/lib/src/precache.d.ts +33 -0
- package/lib/src/precache.js +75 -0
- package/lib/src/precompress.d.ts +19 -0
- package/lib/src/precompress.js +35 -0
- package/lib/src/qr.d.ts +18 -0
- package/lib/src/qr.js +372 -0
- package/lib/src/registry-ops.js +4 -2
- package/lib/src/reload-client.d.ts +2 -0
- package/lib/src/reload-client.js +304 -0
- package/lib/src/resources/archive.d.ts +36 -0
- package/lib/src/resources/archive.js +338 -67
- package/lib/src/resources/convert.js +3 -1
- package/lib/src/resources/https.d.ts +9 -1
- package/lib/src/resources/https.js +36 -0
- package/lib/src/resources/network.d.ts +25 -3
- package/lib/src/resources/network.js +77 -6
- package/lib/src/secrets.d.ts +12 -3
- package/lib/src/secrets.js +18 -5
- package/lib/src/serve-auth.d.ts +32 -0
- package/lib/src/serve-auth.js +112 -0
- package/lib/src/serve-rules.d.ts +83 -7
- package/lib/src/serve-rules.js +264 -53
- package/lib/src/server.d.ts +437 -10
- package/lib/src/server.js +1236 -52
- package/lib/src/servers-file.d.ts +36 -0
- package/lib/src/servers-file.js +101 -0
- package/lib/src/servers.d.ts +109 -7
- package/lib/src/servers.js +151 -29
- package/lib/src/single-file.d.ts +12 -0
- package/lib/src/single-file.js +147 -0
- package/lib/src/site.d.ts +54 -0
- package/lib/src/site.js +204 -6
- package/lib/src/store.js +9 -5
- package/lib/src/swbn.d.ts +10 -0
- package/lib/src/swbn.js +86 -0
- package/lib/src/toml.d.ts +17 -0
- package/lib/src/toml.js +323 -0
- package/lib/src/wacz.d.ts +6 -0
- package/lib/src/wacz.js +96 -0
- package/lib/src/warc.d.ts +28 -0
- package/lib/src/warc.js +252 -0
- package/lib/src/watch.d.ts +12 -1
- package/lib/src/watch.js +67 -1
- package/lib/src/wbn.d.ts +9 -1
- package/lib/src/wbn.js +23 -33
- package/lib/src/zstd.d.ts +4 -0
- package/lib/src/zstd.js +328 -0
- package/package.json +1 -1
|
@@ -209,7 +209,22 @@ export interface ExportInstruction {
|
|
|
209
209
|
readonly value: OciCompression;
|
|
210
210
|
readonly span: SourceSpan;
|
|
211
211
|
};
|
|
212
|
+
/** `KEY <secret-id>` (`swbn` only): the build secret holding the Ed25519 signing key. */
|
|
213
|
+
readonly key?: {
|
|
214
|
+
readonly id: string;
|
|
215
|
+
readonly span: SourceSpan;
|
|
216
|
+
};
|
|
217
|
+
/** `FOR <host>`: write the host's own files for the REDIRECT and HEADER rules (docs/LANGUAGE.md). */
|
|
218
|
+
readonly forHost?: {
|
|
219
|
+
readonly value: ExportHost;
|
|
220
|
+
readonly span: SourceSpan;
|
|
221
|
+
};
|
|
212
222
|
}
|
|
223
|
+
/** `EXPORT ... FOR <host>`: whose config files the REDIRECT and HEADER rules become. */
|
|
224
|
+
export type ExportHost = 'netlify' | 'cloudflare' | 'vercel' | 'firebase' | 'azure' | 'github-pages' | 's3';
|
|
225
|
+
export declare const EXPORT_HOSTS: readonly ExportHost[];
|
|
226
|
+
/** An EXPORT host name (case-insensitive), or undefined. */
|
|
227
|
+
export declare function parseExportHost(name: string): ExportHost | undefined;
|
|
213
228
|
/**
|
|
214
229
|
* `EXPORT ... COMPRESSION`: for `oci`, the site layer encoding, `gzip` (tar+gzip, the default) or `none`
|
|
215
230
|
* (plain tar); for `wbn`, `gzip` wraps the bundle in gzip (the family's `.wbn.gz`) and `none` (the default)
|
|
@@ -219,7 +234,7 @@ export type OciCompression = 'gzip' | 'none';
|
|
|
219
234
|
export declare const OCI_COMPRESSIONS: readonly OciCompression[];
|
|
220
235
|
/** Parse a compression name (case-insensitive); undefined if unknown. */
|
|
221
236
|
export declare function parseOciCompression(name: string): OciCompression | undefined;
|
|
222
|
-
export type ExportFormat = 'directory' | 'zip' | 'tar' | 'tgz' | 'wbn' | 'oci';
|
|
237
|
+
export type ExportFormat = 'directory' | 'zip' | 'tar' | 'tgz' | 'wbn' | 'oci' | 'car' | 'html' | 'mhtml' | 'warc' | 'swbn' | 'wacz' | 'epub';
|
|
223
238
|
export declare const EXPORT_FORMATS: readonly ExportFormat[];
|
|
224
239
|
/** Parse a format name (`tar.gz` is an alias for `tgz`); undefined if unknown. */
|
|
225
240
|
export declare function parseExportFormat(name: string): ExportFormat | undefined;
|
|
@@ -321,7 +336,17 @@ export interface HeaderInstruction {
|
|
|
321
336
|
readonly value: readonly Operand[];
|
|
322
337
|
readonly overwrite: boolean;
|
|
323
338
|
}
|
|
324
|
-
/** `
|
|
339
|
+
/** `MIME <.ext> <type/subtype>`: the Content-Type of the files with that extension, as a `/_headers` rule. */
|
|
340
|
+
export interface MimeInstruction {
|
|
341
|
+
readonly kind: 'MIME';
|
|
342
|
+
readonly span: SourceSpan;
|
|
343
|
+
readonly ext: Operand;
|
|
344
|
+
readonly type: Operand;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* `FINGERPRINT [--overwrite] [--no-cache-headers] <pattern>… [MANIFEST <dest>] [INTEGRITY]`: rename matching
|
|
348
|
+
* files to `name.<hash>.ext` and rewrite the HTML and CSS that reference them.
|
|
349
|
+
*/
|
|
325
350
|
export interface FingerprintInstruction {
|
|
326
351
|
readonly kind: 'FINGERPRINT';
|
|
327
352
|
readonly span: SourceSpan;
|
|
@@ -329,8 +354,96 @@ export interface FingerprintInstruction {
|
|
|
329
354
|
readonly patterns: readonly Operand[];
|
|
330
355
|
/** `MANIFEST <dest>`: where to write the JSON map of old to new paths. */
|
|
331
356
|
readonly manifest?: Operand;
|
|
357
|
+
/** `INTEGRITY`: add `integrity="sha384-…"` to the `<script src>` and `<link rel=stylesheet|modulepreload>` tags that load a renamed file. */
|
|
358
|
+
readonly integrity?: true;
|
|
359
|
+
/** `--no-cache-headers`: EXPORT writes no `Cache-Control` lines to `/_headers` for this Sitefile's fingerprinted files. */
|
|
360
|
+
readonly noCacheHeaders?: true;
|
|
332
361
|
readonly overwrite: boolean;
|
|
333
362
|
}
|
|
363
|
+
/**
|
|
364
|
+
* `CANONICAL BASE <url> [PRETTY]`: add `<link rel="canonical" href="…">` before `</head>` of every page of
|
|
365
|
+
* the stage that has none. PRETTY drops `.html` from the URL (`/about.html` -> `/about`).
|
|
366
|
+
*/
|
|
367
|
+
export interface CanonicalInstruction {
|
|
368
|
+
readonly kind: 'CANONICAL';
|
|
369
|
+
readonly span: SourceSpan;
|
|
370
|
+
readonly base: Operand;
|
|
371
|
+
readonly pretty: boolean;
|
|
372
|
+
}
|
|
373
|
+
/** A PRECOMPRESS sidecar format: `gzip` writes `<file>.gz` (`br` and `zstd` are reserved: no encoder yet). */
|
|
374
|
+
export type PrecompressFormat = 'gzip';
|
|
375
|
+
/**
|
|
376
|
+
* `PRECOMPRESS [--overwrite] [gzip]… <pattern>… [MIN <bytes>]`: write a `.gz` sidecar next to each matching
|
|
377
|
+
* compressible file of at least MIN bytes, when it is smaller.
|
|
378
|
+
*/
|
|
379
|
+
export interface PrecompressInstruction {
|
|
380
|
+
readonly kind: 'PRECOMPRESS';
|
|
381
|
+
readonly span: SourceSpan;
|
|
382
|
+
/** In the order written, without repeats; `['gzip']` when none is given. */
|
|
383
|
+
readonly formats: readonly PrecompressFormat[];
|
|
384
|
+
/** Absolute path patterns, as FINGERPRINT's. */
|
|
385
|
+
readonly patterns: readonly Operand[];
|
|
386
|
+
/** `MIN <bytes>`: the smallest file compressed (default 1024). */
|
|
387
|
+
readonly min?: Operand;
|
|
388
|
+
readonly overwrite: boolean;
|
|
389
|
+
}
|
|
390
|
+
/** One `ALLOW <path>` / `DISALLOW <path>` of a ROBOTS. */
|
|
391
|
+
export interface RobotsRule {
|
|
392
|
+
readonly allow: boolean;
|
|
393
|
+
readonly path: Operand;
|
|
394
|
+
readonly span: SourceSpan;
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* `ROBOTS [--overwrite] [ALLOW <path> | DISALLOW <path>]… [SITEMAP] [TO <dest>]`: a `/robots.txt` for every
|
|
398
|
+
* user agent, with the rules in source order and, with SITEMAP, the URL of each SITEMAP of the Sitefile.
|
|
399
|
+
*/
|
|
400
|
+
export interface RobotsInstruction {
|
|
401
|
+
readonly kind: 'ROBOTS';
|
|
402
|
+
readonly span: SourceSpan;
|
|
403
|
+
readonly rules: readonly RobotsRule[];
|
|
404
|
+
readonly sitemap: boolean;
|
|
405
|
+
/** Default `/robots.txt`. */
|
|
406
|
+
readonly dest?: Operand;
|
|
407
|
+
readonly overwrite: boolean;
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* `SECURITY_TXT [--overwrite] CONTACT <uri>… EXPIRES <date> [ENCRYPTION <uri>]… [POLICY <uri>]… [TO <dest>]`:
|
|
411
|
+
* an RFC 9116 `/.well-known/security.txt`. CONTACT and EXPIRES are required; clauses in any order.
|
|
412
|
+
*/
|
|
413
|
+
export interface SecurityTxtInstruction {
|
|
414
|
+
readonly kind: 'SECURITY_TXT';
|
|
415
|
+
readonly span: SourceSpan;
|
|
416
|
+
readonly contact: readonly Operand[];
|
|
417
|
+
readonly expires: Operand;
|
|
418
|
+
readonly encryption: readonly Operand[];
|
|
419
|
+
readonly policy: readonly Operand[];
|
|
420
|
+
/** Default `/.well-known/security.txt`. */
|
|
421
|
+
readonly dest?: Operand;
|
|
422
|
+
readonly overwrite: boolean;
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* `PRECACHE [--overwrite] <pattern>… [TO <dest>] [INTO <service-worker>]`: a Workbox-style precache
|
|
426
|
+
* manifest (`[{url, revision}]`) of the matching files, written to TO (default `/sw-manifest.json`) and/or
|
|
427
|
+
* injected into a service worker at `self.__WB_MANIFEST`.
|
|
428
|
+
*/
|
|
429
|
+
export interface PrecacheInstruction {
|
|
430
|
+
readonly kind: 'PRECACHE';
|
|
431
|
+
readonly span: SourceSpan;
|
|
432
|
+
readonly patterns: readonly Operand[];
|
|
433
|
+
readonly dest?: Operand;
|
|
434
|
+
readonly into?: Operand;
|
|
435
|
+
readonly overwrite: boolean;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* `CSP [POLICY <policy>] [META]`: a Content-Security-Policy for every exported page, with the SHA-256 of
|
|
439
|
+
* each of its inline scripts and styles; written to `/_headers` at EXPORT, or with META as a `<meta>`.
|
|
440
|
+
*/
|
|
441
|
+
export interface CspInstruction {
|
|
442
|
+
readonly kind: 'CSP';
|
|
443
|
+
readonly span: SourceSpan;
|
|
444
|
+
readonly policy?: Operand;
|
|
445
|
+
readonly meta: boolean;
|
|
446
|
+
}
|
|
334
447
|
/** `CHECKLINKS [--warn] [--external]`: report references in the stage's HTML and CSS that point at nothing. */
|
|
335
448
|
export interface CheckLinksInstruction {
|
|
336
449
|
readonly kind: 'CHECKLINKS';
|
|
@@ -340,7 +453,7 @@ export interface CheckLinksInstruction {
|
|
|
340
453
|
/** `--external`: also request http(s) links (under the network policy). */
|
|
341
454
|
readonly external: boolean;
|
|
342
455
|
}
|
|
343
|
-
export type Instruction = FromInstruction | ArgInstruction | LetInstruction | FragmentInstruction | ImportInstruction | CopyInstruction | RenderInstruction | PluginInstruction | ToolInstruction | TransformInstruction | SitemapInstruction | FeedInstruction | RedirectInstruction | HeaderInstruction | FingerprintInstruction | CheckLinksInstruction | ExportInstruction;
|
|
456
|
+
export type Instruction = FromInstruction | ArgInstruction | LetInstruction | FragmentInstruction | ImportInstruction | CopyInstruction | RenderInstruction | PluginInstruction | ToolInstruction | TransformInstruction | SitemapInstruction | FeedInstruction | RedirectInstruction | HeaderInstruction | MimeInstruction | FingerprintInstruction | CanonicalInstruction | PrecompressInstruction | RobotsInstruction | SecurityTxtInstruction | PrecacheInstruction | CspInstruction | CheckLinksInstruction | ExportInstruction;
|
|
344
457
|
/** A parsed and semantically validated Sitefile. */
|
|
345
458
|
export interface Program {
|
|
346
459
|
readonly file: string;
|
package/lib/src/language/ast.js
CHANGED
|
@@ -9,13 +9,19 @@ export function isFragment(ins) {
|
|
|
9
9
|
export function isInline(x) {
|
|
10
10
|
return 'kind' in x && x.kind === 'inline';
|
|
11
11
|
}
|
|
12
|
+
export const EXPORT_HOSTS = ['netlify', 'cloudflare', 'vercel', 'firebase', 'azure', 'github-pages', 's3'];
|
|
13
|
+
/** An EXPORT host name (case-insensitive), or undefined. */
|
|
14
|
+
export function parseExportHost(name) {
|
|
15
|
+
const n = name.toLowerCase();
|
|
16
|
+
return EXPORT_HOSTS.includes(n) ? n : undefined;
|
|
17
|
+
}
|
|
12
18
|
export const OCI_COMPRESSIONS = ['gzip', 'none'];
|
|
13
19
|
/** Parse a compression name (case-insensitive); undefined if unknown. */
|
|
14
20
|
export function parseOciCompression(name) {
|
|
15
21
|
const n = name.toLowerCase();
|
|
16
22
|
return OCI_COMPRESSIONS.includes(n) ? n : undefined;
|
|
17
23
|
}
|
|
18
|
-
export const EXPORT_FORMATS = ['directory', 'zip', 'tar', 'tgz', 'wbn', 'oci'];
|
|
24
|
+
export const EXPORT_FORMATS = ['directory', 'zip', 'tar', 'tgz', 'wbn', 'oci', 'car', 'html', 'mhtml', 'warc', 'swbn', 'wacz', 'epub'];
|
|
19
25
|
/** Parse a format name (`tar.gz` is an alias for `tgz`); undefined if unknown. */
|
|
20
26
|
export function parseExportFormat(name) {
|
|
21
27
|
const n = name.toLowerCase();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { INTEGRITY_RE } from '../digest.js';
|
|
2
|
-
import { IDENT_RE, IMPORTED_STAGE_RE, isInline, literalText, parseExportFormat, parseOciCompression, REDIRECT_STATUSES, } from './ast.js';
|
|
2
|
+
import { IDENT_RE, IMPORTED_STAGE_RE, isInline, literalText, parseExportFormat, parseOciCompression, EXPORT_HOSTS, parseExportHost, REDIRECT_STATUSES, } from './ast.js';
|
|
3
3
|
import { isIgnorePattern } from '../resources/ignore.js';
|
|
4
4
|
import { Cursor, logicalLines } from './scanner.js';
|
|
5
5
|
const VALUE_TYPES = ['string', 'number', 'boolean'];
|
|
@@ -43,8 +43,22 @@ function parseInstruction(c) {
|
|
|
43
43
|
return parseRedirect(c, span);
|
|
44
44
|
case 'HEADER':
|
|
45
45
|
return parseHeader(c, span);
|
|
46
|
+
case 'MIME':
|
|
47
|
+
return parseMime(c, span);
|
|
46
48
|
case 'FINGERPRINT':
|
|
47
49
|
return parseFingerprint(c, span);
|
|
50
|
+
case 'CANONICAL':
|
|
51
|
+
return parseCanonical(c, span);
|
|
52
|
+
case 'PRECOMPRESS':
|
|
53
|
+
return parsePrecompress(c, span);
|
|
54
|
+
case 'ROBOTS':
|
|
55
|
+
return parseRobots(c, span);
|
|
56
|
+
case 'SECURITY_TXT':
|
|
57
|
+
return parseSecurityTxt(c, span);
|
|
58
|
+
case 'PRECACHE':
|
|
59
|
+
return parsePrecache(c, span);
|
|
60
|
+
case 'CSP':
|
|
61
|
+
return parseCsp(c, span);
|
|
48
62
|
case 'CHECKLINKS':
|
|
49
63
|
return parseCheckLinks(c, span);
|
|
50
64
|
case 'RUN':
|
|
@@ -556,17 +570,147 @@ function parseHeader(c, span) {
|
|
|
556
570
|
throw c.error('E_SYNTAX', 'expected header value');
|
|
557
571
|
return { kind: 'HEADER', span, pattern, name: { parts, span: raw.span }, value, overwrite: flags.has('overwrite') };
|
|
558
572
|
}
|
|
559
|
-
/** `
|
|
573
|
+
/** `MIME <.ext> <type/subtype>` */
|
|
574
|
+
function parseMime(c, span) {
|
|
575
|
+
const ext = c.operand('extension (.ext)');
|
|
576
|
+
const type = c.operand('media type (type/subtype)');
|
|
577
|
+
c.expectEnd();
|
|
578
|
+
return { kind: 'MIME', span, ext, type };
|
|
579
|
+
}
|
|
580
|
+
/** `FINGERPRINT [--overwrite] [--no-cache-headers] <pattern>… [MANIFEST <dest>] [INTEGRITY]` */
|
|
560
581
|
function parseFingerprint(c, span) {
|
|
561
|
-
const flags = parseFlags(c, { overwrite: 'bare' });
|
|
582
|
+
const flags = parseFlags(c, { overwrite: 'bare', 'no-cache-headers': 'bare' });
|
|
562
583
|
const patterns = [];
|
|
563
|
-
while (!c.atEnd() && !c.peekKeyword('MANIFEST'))
|
|
584
|
+
while (!c.atEnd() && !c.peekKeyword('MANIFEST') && !c.peekKeyword('INTEGRITY'))
|
|
564
585
|
patterns.push(c.operand('path pattern'));
|
|
565
586
|
if (patterns.length === 0)
|
|
566
587
|
throw c.error('E_SYNTAX', 'expected a path pattern (FINGERPRINT /assets/ or FINGERPRINT /**/*.css)');
|
|
567
588
|
const manifest = c.keyword('MANIFEST') ? c.operand('manifest destination') : undefined;
|
|
589
|
+
const integrity = c.keyword('INTEGRITY');
|
|
590
|
+
c.expectEnd();
|
|
591
|
+
return {
|
|
592
|
+
kind: 'FINGERPRINT',
|
|
593
|
+
span,
|
|
594
|
+
patterns,
|
|
595
|
+
...(manifest ? { manifest } : {}),
|
|
596
|
+
...(integrity && { integrity: true }),
|
|
597
|
+
...(flags.has('no-cache-headers') && { noCacheHeaders: true }),
|
|
598
|
+
overwrite: flags.has('overwrite'),
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
/** `CANONICAL BASE <url> [PRETTY]` */
|
|
602
|
+
function parseCanonical(c, span) {
|
|
603
|
+
c.expectKeyword('BASE');
|
|
604
|
+
const base = c.operand('base URL');
|
|
605
|
+
const pretty = c.keyword('PRETTY');
|
|
568
606
|
c.expectEnd();
|
|
569
|
-
return { kind: '
|
|
607
|
+
return { kind: 'CANONICAL', span, base, pretty };
|
|
608
|
+
}
|
|
609
|
+
/** Sidecar formats PRECOMPRESS knows; only gzip has an encoder (src/deflate.ts, shared with the Rust port). */
|
|
610
|
+
const PRECOMPRESS_FORMATS = ['gzip', 'br', 'zstd'];
|
|
611
|
+
/** `PRECOMPRESS [--overwrite] [gzip]… <pattern>… [MIN <bytes>]` */
|
|
612
|
+
function parsePrecompress(c, span) {
|
|
613
|
+
const flags = parseFlags(c, { overwrite: 'bare' });
|
|
614
|
+
const formats = [];
|
|
615
|
+
for (;;) {
|
|
616
|
+
const at = c.span;
|
|
617
|
+
const mark = c.mark();
|
|
618
|
+
const w = c.word().toLowerCase();
|
|
619
|
+
if (!PRECOMPRESS_FORMATS.includes(w)) {
|
|
620
|
+
c.reset(mark);
|
|
621
|
+
break;
|
|
622
|
+
}
|
|
623
|
+
if (w !== 'gzip') {
|
|
624
|
+
throw c.error('E_UNSUPPORTED', `PRECOMPRESS ${w} is not supported yet: sitefile has no ${w === 'br' ? 'Brotli' : 'Zstandard'} encoder that writes the same bytes in both implementations (use gzip)`, at);
|
|
625
|
+
}
|
|
626
|
+
if (formats.includes(w))
|
|
627
|
+
throw c.error('E_SYNTAX', `${w} given twice`, at);
|
|
628
|
+
formats.push(w);
|
|
629
|
+
}
|
|
630
|
+
const patterns = [];
|
|
631
|
+
while (!c.atEnd() && !c.peekKeyword('MIN'))
|
|
632
|
+
patterns.push(c.operand('path pattern'));
|
|
633
|
+
if (patterns.length === 0)
|
|
634
|
+
throw c.error('E_SYNTAX', 'expected a path pattern (PRECOMPRESS /assets/ or PRECOMPRESS gzip /**/*.css)');
|
|
635
|
+
const min = c.keyword('MIN') ? c.operand('minimum size in bytes') : undefined;
|
|
636
|
+
c.expectEnd();
|
|
637
|
+
return { kind: 'PRECOMPRESS', span, formats: formats.length ? formats : ['gzip'], patterns, ...(min ? { min } : {}), overwrite: flags.has('overwrite') };
|
|
638
|
+
}
|
|
639
|
+
/** `ROBOTS [--overwrite] [ALLOW <path> | DISALLOW <path>]… [SITEMAP] [TO <dest>]` (in this order) */
|
|
640
|
+
function parseRobots(c, span) {
|
|
641
|
+
const flags = parseFlags(c, { overwrite: 'bare' });
|
|
642
|
+
const rules = [];
|
|
643
|
+
for (;;) {
|
|
644
|
+
const at = c.span;
|
|
645
|
+
if (c.keyword('ALLOW'))
|
|
646
|
+
rules.push({ allow: true, path: c.operand('path'), span: at });
|
|
647
|
+
else if (c.keyword('DISALLOW'))
|
|
648
|
+
rules.push({ allow: false, path: c.operand('path'), span: at });
|
|
649
|
+
else
|
|
650
|
+
break;
|
|
651
|
+
}
|
|
652
|
+
const sitemap = c.keyword('SITEMAP');
|
|
653
|
+
const dest = c.keyword('TO') ? c.operand('destination') : undefined;
|
|
654
|
+
if (!c.atEnd()) {
|
|
655
|
+
const at = c.span;
|
|
656
|
+
throw c.error('E_SYNTAX', `unexpected '${c.word()}' (expected ALLOW, DISALLOW, SITEMAP or TO, in this order)`, at);
|
|
657
|
+
}
|
|
658
|
+
return { kind: 'ROBOTS', span, rules, sitemap, ...(dest ? { dest } : {}), overwrite: flags.has('overwrite') };
|
|
659
|
+
}
|
|
660
|
+
/** `SECURITY_TXT [--overwrite] CONTACT <uri>… EXPIRES <date> [ENCRYPTION <uri>]… [POLICY <uri>]… [TO <dest>]` (any order) */
|
|
661
|
+
function parseSecurityTxt(c, span) {
|
|
662
|
+
const flags = parseFlags(c, { overwrite: 'bare' });
|
|
663
|
+
const contact = [];
|
|
664
|
+
const encryption = [];
|
|
665
|
+
const policy = [];
|
|
666
|
+
let expires;
|
|
667
|
+
let dest;
|
|
668
|
+
while (!c.atEnd()) {
|
|
669
|
+
const at = c.span;
|
|
670
|
+
if (c.keyword('CONTACT'))
|
|
671
|
+
contact.push(c.operand('contact URI'));
|
|
672
|
+
else if (c.keyword('ENCRYPTION'))
|
|
673
|
+
encryption.push(c.operand('encryption key URI'));
|
|
674
|
+
else if (c.keyword('POLICY'))
|
|
675
|
+
policy.push(c.operand('policy URI'));
|
|
676
|
+
else if (c.keyword('EXPIRES')) {
|
|
677
|
+
if (expires)
|
|
678
|
+
throw c.error('E_SYNTAX', 'EXPIRES given twice', at);
|
|
679
|
+
expires = c.operand('expiry date');
|
|
680
|
+
}
|
|
681
|
+
else if (c.keyword('TO')) {
|
|
682
|
+
if (dest)
|
|
683
|
+
throw c.error('E_SYNTAX', 'TO given twice', at);
|
|
684
|
+
dest = c.operand('destination');
|
|
685
|
+
}
|
|
686
|
+
else
|
|
687
|
+
throw c.error('E_SYNTAX', `unexpected '${c.word()}' (expected CONTACT, EXPIRES, ENCRYPTION, POLICY or TO)`, at);
|
|
688
|
+
}
|
|
689
|
+
if (contact.length === 0)
|
|
690
|
+
throw c.error('E_VALIDATION', 'SECURITY_TXT needs CONTACT <uri> (RFC 9116 requires at least one Contact field)', span);
|
|
691
|
+
if (!expires)
|
|
692
|
+
throw c.error('E_VALIDATION', 'SECURITY_TXT needs EXPIRES <date> (RFC 9116 requires an Expires field)', span);
|
|
693
|
+
return { kind: 'SECURITY_TXT', span, contact, expires, encryption, policy, ...(dest ? { dest } : {}), overwrite: flags.has('overwrite') };
|
|
694
|
+
}
|
|
695
|
+
/** `PRECACHE [--overwrite] <pattern>… [TO <dest>] [INTO <service-worker>]` (clauses in this order) */
|
|
696
|
+
function parsePrecache(c, span) {
|
|
697
|
+
const flags = parseFlags(c, { overwrite: 'bare' });
|
|
698
|
+
const patterns = [];
|
|
699
|
+
while (!c.atEnd() && !c.peekKeyword('TO') && !c.peekKeyword('INTO'))
|
|
700
|
+
patterns.push(c.operand('path pattern'));
|
|
701
|
+
if (patterns.length === 0)
|
|
702
|
+
throw c.error('E_SYNTAX', 'expected a path pattern (PRECACHE /assets/ or PRECACHE /**/*.css /index.html)');
|
|
703
|
+
const dest = c.keyword('TO') ? c.operand('destination') : undefined;
|
|
704
|
+
const into = c.keyword('INTO') ? c.operand('service worker path') : undefined;
|
|
705
|
+
c.expectEnd();
|
|
706
|
+
return { kind: 'PRECACHE', span, patterns, ...(dest ? { dest } : {}), ...(into ? { into } : {}), overwrite: flags.has('overwrite') };
|
|
707
|
+
}
|
|
708
|
+
/** `CSP [POLICY <policy>] [META]` */
|
|
709
|
+
function parseCsp(c, span) {
|
|
710
|
+
const policy = c.keyword('POLICY') ? c.operand('policy') : undefined;
|
|
711
|
+
const meta = c.keyword('META');
|
|
712
|
+
c.expectEnd();
|
|
713
|
+
return { kind: 'CSP', span, ...(policy ? { policy } : {}), meta };
|
|
570
714
|
}
|
|
571
715
|
/** `CHECKLINKS [--warn] [--external]` */
|
|
572
716
|
function parseCheckLinks(c, span) {
|
|
@@ -586,7 +730,7 @@ function parseExport(c, span) {
|
|
|
586
730
|
throw c.error('E_SYNTAX', 'expected export format after AS', at);
|
|
587
731
|
const f = parseExportFormat(name);
|
|
588
732
|
if (f === undefined) {
|
|
589
|
-
throw c.error('E_UNSUPPORTED', `export format '${name}' is not supported (expected directory, zip, tar, tgz, wbn or
|
|
733
|
+
throw c.error('E_UNSUPPORTED', `export format '${name}' is not supported (expected directory, zip, tar, tgz, wbn, oci, car, html, mhtml, warc, swbn, wacz or epub)`, at);
|
|
590
734
|
}
|
|
591
735
|
format = f;
|
|
592
736
|
}
|
|
@@ -606,7 +750,32 @@ function parseExport(c, span) {
|
|
|
606
750
|
}
|
|
607
751
|
compression = { value, span: cspan };
|
|
608
752
|
}
|
|
753
|
+
let key;
|
|
754
|
+
if (c.keyword('KEY')) {
|
|
755
|
+
const kspan = c.span;
|
|
756
|
+
key = { id: c.ident('secret id'), span: kspan };
|
|
757
|
+
}
|
|
758
|
+
let forHost;
|
|
759
|
+
if (c.keyword('FOR')) {
|
|
760
|
+
const hspan = c.span;
|
|
761
|
+
const name = c.word();
|
|
762
|
+
const value = parseExportHost(name);
|
|
763
|
+
if (value === undefined) {
|
|
764
|
+
throw c.error('E_SYNTAX', name === '' ? `expected a host after FOR (${EXPORT_HOSTS.join(', ')})` : `unknown host '${name}' (expected ${EXPORT_HOSTS.join(', ')})`, hspan);
|
|
765
|
+
}
|
|
766
|
+
forHost = { value, span: hspan };
|
|
767
|
+
}
|
|
609
768
|
c.expectEnd();
|
|
610
|
-
return {
|
|
769
|
+
return {
|
|
770
|
+
kind: 'EXPORT',
|
|
771
|
+
span,
|
|
772
|
+
path,
|
|
773
|
+
format,
|
|
774
|
+
...(base ? { base } : {}),
|
|
775
|
+
...(at ? { at } : {}),
|
|
776
|
+
...(compression ? { compression } : {}),
|
|
777
|
+
...(key ? { key } : {}),
|
|
778
|
+
...(forHost ? { forHost } : {}),
|
|
779
|
+
};
|
|
611
780
|
}
|
|
612
781
|
//# sourceMappingURL=parser.js.map
|
|
@@ -46,8 +46,22 @@ export function operandsOf(ins) {
|
|
|
46
46
|
return [ins.from, ins.to];
|
|
47
47
|
case 'HEADER':
|
|
48
48
|
return [ins.pattern, ins.name, ...ins.value];
|
|
49
|
+
case 'MIME':
|
|
50
|
+
return [ins.ext, ins.type];
|
|
49
51
|
case 'FINGERPRINT':
|
|
50
52
|
return [...ins.patterns, ...(ins.manifest ? [ins.manifest] : [])];
|
|
53
|
+
case 'CANONICAL':
|
|
54
|
+
return [ins.base];
|
|
55
|
+
case 'PRECOMPRESS':
|
|
56
|
+
return [...ins.patterns, ...(ins.min ? [ins.min] : [])];
|
|
57
|
+
case 'ROBOTS':
|
|
58
|
+
return [...ins.rules.map((r) => r.path), ...(ins.dest ? [ins.dest] : [])];
|
|
59
|
+
case 'SECURITY_TXT':
|
|
60
|
+
return [...ins.contact, ins.expires, ...ins.encryption, ...ins.policy, ...(ins.dest ? [ins.dest] : [])];
|
|
61
|
+
case 'PRECACHE':
|
|
62
|
+
return [...ins.patterns, ...(ins.dest ? [ins.dest] : []), ...(ins.into ? [ins.into] : [])];
|
|
63
|
+
case 'CSP':
|
|
64
|
+
return ins.policy ? [ins.policy] : [];
|
|
51
65
|
case 'CHECKLINKS':
|
|
52
66
|
return [];
|
|
53
67
|
case 'EXPORT':
|
|
@@ -275,7 +289,14 @@ export function validate(instructions, file) {
|
|
|
275
289
|
case 'SITEMAP':
|
|
276
290
|
case 'REDIRECT':
|
|
277
291
|
case 'HEADER':
|
|
292
|
+
case 'MIME':
|
|
278
293
|
case 'FINGERPRINT':
|
|
294
|
+
case 'CANONICAL':
|
|
295
|
+
case 'PRECOMPRESS':
|
|
296
|
+
case 'ROBOTS':
|
|
297
|
+
case 'SECURITY_TXT':
|
|
298
|
+
case 'PRECACHE':
|
|
299
|
+
case 'CSP':
|
|
279
300
|
case 'CHECKLINKS':
|
|
280
301
|
break;
|
|
281
302
|
case 'EXPORT':
|
package/lib/src/links.d.ts
CHANGED
|
@@ -11,6 +11,8 @@ export interface Reference {
|
|
|
11
11
|
readonly line: number;
|
|
12
12
|
/** Written as CSS (a CSS file, a <style> element or a `style` attribute), so CSS escapes apply. */
|
|
13
13
|
readonly css: boolean;
|
|
14
|
+
/** For a URL in an HTML attribute (not CSS): the lower-case element and attribute names, `img src`. */
|
|
15
|
+
readonly element?: string;
|
|
14
16
|
}
|
|
15
17
|
/** Decoded text, and for each of its offsets (and its end) the offset in the source it came from. */
|
|
16
18
|
interface Mapped {
|
|
@@ -27,6 +29,37 @@ export declare const decodeCssText: (s: string) => string;
|
|
|
27
29
|
export declare function scanCss(text: string): Reference[];
|
|
28
30
|
/** The URLs an HTML file references, in order (including those of its CSS). */
|
|
29
31
|
export declare function scanHtml(text: string): Reference[];
|
|
32
|
+
/** A tag that loads a subresource Subresource Integrity can check: where to add the attribute, and the URL. */
|
|
33
|
+
export interface IntegrityTag {
|
|
34
|
+
/** The offset just after the tag name (`<script|`), where ` integrity="…"` goes. */
|
|
35
|
+
readonly at: number;
|
|
36
|
+
/** The URL (`src` of a script, `href` of a link), decoded and trimmed as {@link scanHtml} does. */
|
|
37
|
+
readonly url: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The start tags of an HTML text that load a script or stylesheet SRI applies to: `<script src>` and
|
|
41
|
+
* `<link href>` whose `rel` has the token `stylesheet` or `modulepreload` (ASCII case-insensitive).
|
|
42
|
+
* Tags that already have an `integrity` attribute are left out. Comments, declarations and raw text are
|
|
43
|
+
* skipped as in {@link scanHtml}; when an attribute is given twice, the first one counts.
|
|
44
|
+
*/
|
|
45
|
+
export declare function integrityTags(text: string): IntegrityTag[];
|
|
46
|
+
/**
|
|
47
|
+
* Where a canonical link goes in an HTML text: the offset of its first `</head` end tag, `'has'` when a
|
|
48
|
+
* `<link>` whose `rel` has the token `canonical` (ASCII case-insensitive) comes before it, or undefined when
|
|
49
|
+
* there is no `</head>`. Comments, declarations and raw text are skipped as in {@link scanHtml}.
|
|
50
|
+
*/
|
|
51
|
+
export declare function canonicalSlot(text: string): number | 'has' | undefined;
|
|
52
|
+
/** What CSP needs from a page: its inline script and style texts, in order, and where its `<head>` start tag ends. */
|
|
53
|
+
export interface InlineBlocks {
|
|
54
|
+
/** The contents of each `<script>` without a `src` attribute (also empty ones). */
|
|
55
|
+
readonly scripts: readonly string[];
|
|
56
|
+
/** The contents of each `<style>`. */
|
|
57
|
+
readonly styles: readonly string[];
|
|
58
|
+
/** The offset just after the first `<head …>` start tag, if there is one. */
|
|
59
|
+
readonly headEnd?: number;
|
|
60
|
+
}
|
|
61
|
+
/** The inline scripts and styles of an HTML text (comments and other raw text skipped as in {@link scanHtml}). */
|
|
62
|
+
export declare function inlineBlocks(text: string): InlineBlocks;
|
|
30
63
|
/** Whether a path is read by {@link scanFile}, and how. */
|
|
31
64
|
export declare function referenceKind(path: string): 'html' | 'css' | undefined;
|
|
32
65
|
/** A file's text and references; undefined when it is not HTML or CSS, or not valid UTF-8. */
|