@johnhenry/sitefile 0.0.2 → 0.0.4
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 +516 -0
- package/README.md +59 -9
- package/lib/src/archive-writers.d.ts +12 -2
- package/lib/src/archive-writers.js +53 -10
- package/lib/src/bake.d.ts +2 -0
- package/lib/src/bake.js +30 -1
- package/lib/src/bcrypt.d.ts +25 -0
- package/lib/src/bcrypt.js +201 -0
- package/lib/src/canonical.d.ts +19 -0
- package/lib/src/canonical.js +60 -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 +6 -1
- package/lib/src/cli/index.js +34 -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 +119 -8
- package/lib/src/cli/servers.d.ts +130 -1
- package/lib/src/cli/servers.js +754 -72
- 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 +231 -24
- 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/hreflang.d.ts +25 -0
- package/lib/src/hreflang.js +72 -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 +126 -3
- package/lib/src/language/ast.js +7 -1
- package/lib/src/language/parser.js +189 -7
- package/lib/src/language/validate.js +24 -0
- package/lib/src/links.d.ts +47 -0
- package/lib/src/links.js +289 -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 +87 -2
- package/lib/src/planner.js +189 -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 +419 -0
- package/lib/src/resources/archive.d.ts +37 -1
- package/lib/src/resources/archive.js +353 -71
- 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 +33 -0
- package/lib/src/serve-auth.js +120 -0
- package/lib/src/serve-rules.d.ts +83 -7
- package/lib/src/serve-rules.js +264 -53
- package/lib/src/server.d.ts +529 -11
- package/lib/src/server.js +1439 -57
- package/lib/src/servers-file.d.ts +36 -0
- package/lib/src/servers-file.js +101 -0
- package/lib/src/servers.d.ts +115 -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 +58 -0
- package/lib/src/site.js +216 -5
- 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,106 @@ 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
|
+
/**
|
|
374
|
+
* `LANGUAGES <code>… [DEFAULT <code>]`: the site's language folders (`/en/…`, `/fr/…`, pages at the root in the
|
|
375
|
+
* DEFAULT language). CANONICAL and SITEMAP write hreflang alternates for the pages that translate each other.
|
|
376
|
+
*/
|
|
377
|
+
export interface LanguagesInstruction {
|
|
378
|
+
readonly kind: 'LANGUAGES';
|
|
379
|
+
readonly span: SourceSpan;
|
|
380
|
+
readonly codes: readonly Operand[];
|
|
381
|
+
readonly default?: Operand;
|
|
382
|
+
}
|
|
383
|
+
/** A PRECOMPRESS sidecar format: `gzip` writes `<file>.gz` (`br` and `zstd` are reserved: no encoder yet). */
|
|
384
|
+
export type PrecompressFormat = 'gzip';
|
|
385
|
+
/**
|
|
386
|
+
* `PRECOMPRESS [--overwrite] [gzip]… <pattern>… [MIN <bytes>]`: write a `.gz` sidecar next to each matching
|
|
387
|
+
* compressible file of at least MIN bytes, when it is smaller.
|
|
388
|
+
*/
|
|
389
|
+
export interface PrecompressInstruction {
|
|
390
|
+
readonly kind: 'PRECOMPRESS';
|
|
391
|
+
readonly span: SourceSpan;
|
|
392
|
+
/** In the order written, without repeats; `['gzip']` when none is given. */
|
|
393
|
+
readonly formats: readonly PrecompressFormat[];
|
|
394
|
+
/** Absolute path patterns, as FINGERPRINT's. */
|
|
395
|
+
readonly patterns: readonly Operand[];
|
|
396
|
+
/** `MIN <bytes>`: the smallest file compressed (default 1024). */
|
|
397
|
+
readonly min?: Operand;
|
|
398
|
+
readonly overwrite: boolean;
|
|
399
|
+
}
|
|
400
|
+
/** One `ALLOW <path>` / `DISALLOW <path>` of a ROBOTS. */
|
|
401
|
+
export interface RobotsRule {
|
|
402
|
+
readonly allow: boolean;
|
|
403
|
+
readonly path: Operand;
|
|
404
|
+
readonly span: SourceSpan;
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* `ROBOTS [--overwrite] [ALLOW <path> | DISALLOW <path>]… [SITEMAP] [TO <dest>]`: a `/robots.txt` for every
|
|
408
|
+
* user agent, with the rules in source order and, with SITEMAP, the URL of each SITEMAP of the Sitefile.
|
|
409
|
+
*/
|
|
410
|
+
export interface RobotsInstruction {
|
|
411
|
+
readonly kind: 'ROBOTS';
|
|
412
|
+
readonly span: SourceSpan;
|
|
413
|
+
readonly rules: readonly RobotsRule[];
|
|
414
|
+
readonly sitemap: boolean;
|
|
415
|
+
/** Default `/robots.txt`. */
|
|
416
|
+
readonly dest?: Operand;
|
|
417
|
+
readonly overwrite: boolean;
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* `SECURITY_TXT [--overwrite] CONTACT <uri>… EXPIRES <date> [ENCRYPTION <uri>]… [POLICY <uri>]… [TO <dest>]`:
|
|
421
|
+
* an RFC 9116 `/.well-known/security.txt`. CONTACT and EXPIRES are required; clauses in any order.
|
|
422
|
+
*/
|
|
423
|
+
export interface SecurityTxtInstruction {
|
|
424
|
+
readonly kind: 'SECURITY_TXT';
|
|
425
|
+
readonly span: SourceSpan;
|
|
426
|
+
readonly contact: readonly Operand[];
|
|
427
|
+
readonly expires: Operand;
|
|
428
|
+
readonly encryption: readonly Operand[];
|
|
429
|
+
readonly policy: readonly Operand[];
|
|
430
|
+
/** Default `/.well-known/security.txt`. */
|
|
431
|
+
readonly dest?: Operand;
|
|
432
|
+
readonly overwrite: boolean;
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* `PRECACHE [--overwrite] <pattern>… [TO <dest>] [INTO <service-worker>]`: a Workbox-style precache
|
|
436
|
+
* manifest (`[{url, revision}]`) of the matching files, written to TO (default `/sw-manifest.json`) and/or
|
|
437
|
+
* injected into a service worker at `self.__WB_MANIFEST`.
|
|
438
|
+
*/
|
|
439
|
+
export interface PrecacheInstruction {
|
|
440
|
+
readonly kind: 'PRECACHE';
|
|
441
|
+
readonly span: SourceSpan;
|
|
442
|
+
readonly patterns: readonly Operand[];
|
|
443
|
+
readonly dest?: Operand;
|
|
444
|
+
readonly into?: Operand;
|
|
445
|
+
readonly overwrite: boolean;
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* `CSP [POLICY <policy>] [META]`: a Content-Security-Policy for every exported page, with the SHA-256 of
|
|
449
|
+
* each of its inline scripts and styles; written to `/_headers` at EXPORT, or with META as a `<meta>`.
|
|
450
|
+
*/
|
|
451
|
+
export interface CspInstruction {
|
|
452
|
+
readonly kind: 'CSP';
|
|
453
|
+
readonly span: SourceSpan;
|
|
454
|
+
readonly policy?: Operand;
|
|
455
|
+
readonly meta: boolean;
|
|
456
|
+
}
|
|
334
457
|
/** `CHECKLINKS [--warn] [--external]`: report references in the stage's HTML and CSS that point at nothing. */
|
|
335
458
|
export interface CheckLinksInstruction {
|
|
336
459
|
readonly kind: 'CHECKLINKS';
|
|
@@ -340,7 +463,7 @@ export interface CheckLinksInstruction {
|
|
|
340
463
|
/** `--external`: also request http(s) links (under the network policy). */
|
|
341
464
|
readonly external: boolean;
|
|
342
465
|
}
|
|
343
|
-
export type Instruction = FromInstruction | ArgInstruction | LetInstruction | FragmentInstruction | ImportInstruction | CopyInstruction | RenderInstruction | PluginInstruction | ToolInstruction | TransformInstruction | SitemapInstruction | FeedInstruction | RedirectInstruction | HeaderInstruction | FingerprintInstruction | CheckLinksInstruction | ExportInstruction;
|
|
466
|
+
export type Instruction = FromInstruction | ArgInstruction | LetInstruction | FragmentInstruction | ImportInstruction | CopyInstruction | RenderInstruction | PluginInstruction | ToolInstruction | TransformInstruction | SitemapInstruction | FeedInstruction | RedirectInstruction | HeaderInstruction | MimeInstruction | FingerprintInstruction | CanonicalInstruction | LanguagesInstruction | PrecompressInstruction | RobotsInstruction | SecurityTxtInstruction | PrecacheInstruction | CspInstruction | CheckLinksInstruction | ExportInstruction;
|
|
344
467
|
/** A parsed and semantically validated Sitefile. */
|
|
345
468
|
export interface Program {
|
|
346
469
|
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,24 @@ 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 'LANGUAGES':
|
|
53
|
+
return parseLanguages(c, span);
|
|
54
|
+
case 'PRECOMPRESS':
|
|
55
|
+
return parsePrecompress(c, span);
|
|
56
|
+
case 'ROBOTS':
|
|
57
|
+
return parseRobots(c, span);
|
|
58
|
+
case 'SECURITY_TXT':
|
|
59
|
+
return parseSecurityTxt(c, span);
|
|
60
|
+
case 'PRECACHE':
|
|
61
|
+
return parsePrecache(c, span);
|
|
62
|
+
case 'CSP':
|
|
63
|
+
return parseCsp(c, span);
|
|
48
64
|
case 'CHECKLINKS':
|
|
49
65
|
return parseCheckLinks(c, span);
|
|
50
66
|
case 'RUN':
|
|
@@ -556,17 +572,158 @@ function parseHeader(c, span) {
|
|
|
556
572
|
throw c.error('E_SYNTAX', 'expected header value');
|
|
557
573
|
return { kind: 'HEADER', span, pattern, name: { parts, span: raw.span }, value, overwrite: flags.has('overwrite') };
|
|
558
574
|
}
|
|
559
|
-
/** `
|
|
575
|
+
/** `MIME <.ext> <type/subtype>` */
|
|
576
|
+
function parseMime(c, span) {
|
|
577
|
+
const ext = c.operand('extension (.ext)');
|
|
578
|
+
const type = c.operand('media type (type/subtype)');
|
|
579
|
+
c.expectEnd();
|
|
580
|
+
return { kind: 'MIME', span, ext, type };
|
|
581
|
+
}
|
|
582
|
+
/** `FINGERPRINT [--overwrite] [--no-cache-headers] <pattern>… [MANIFEST <dest>] [INTEGRITY]` */
|
|
560
583
|
function parseFingerprint(c, span) {
|
|
561
|
-
const flags = parseFlags(c, { overwrite: 'bare' });
|
|
584
|
+
const flags = parseFlags(c, { overwrite: 'bare', 'no-cache-headers': 'bare' });
|
|
562
585
|
const patterns = [];
|
|
563
|
-
while (!c.atEnd() && !c.peekKeyword('MANIFEST'))
|
|
586
|
+
while (!c.atEnd() && !c.peekKeyword('MANIFEST') && !c.peekKeyword('INTEGRITY'))
|
|
564
587
|
patterns.push(c.operand('path pattern'));
|
|
565
588
|
if (patterns.length === 0)
|
|
566
589
|
throw c.error('E_SYNTAX', 'expected a path pattern (FINGERPRINT /assets/ or FINGERPRINT /**/*.css)');
|
|
567
590
|
const manifest = c.keyword('MANIFEST') ? c.operand('manifest destination') : undefined;
|
|
591
|
+
const integrity = c.keyword('INTEGRITY');
|
|
592
|
+
c.expectEnd();
|
|
593
|
+
return {
|
|
594
|
+
kind: 'FINGERPRINT',
|
|
595
|
+
span,
|
|
596
|
+
patterns,
|
|
597
|
+
...(manifest ? { manifest } : {}),
|
|
598
|
+
...(integrity && { integrity: true }),
|
|
599
|
+
...(flags.has('no-cache-headers') && { noCacheHeaders: true }),
|
|
600
|
+
overwrite: flags.has('overwrite'),
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
/** `CANONICAL BASE <url> [PRETTY]` */
|
|
604
|
+
function parseCanonical(c, span) {
|
|
605
|
+
c.expectKeyword('BASE');
|
|
606
|
+
const base = c.operand('base URL');
|
|
607
|
+
const pretty = c.keyword('PRETTY');
|
|
608
|
+
c.expectEnd();
|
|
609
|
+
return { kind: 'CANONICAL', span, base, pretty };
|
|
610
|
+
}
|
|
611
|
+
/** `LANGUAGES <code>… [DEFAULT <code>]` */
|
|
612
|
+
function parseLanguages(c, span) {
|
|
613
|
+
const codes = [];
|
|
614
|
+
while (!c.atEnd() && !c.peekKeyword('DEFAULT'))
|
|
615
|
+
codes.push(c.operand('language code'));
|
|
616
|
+
if (codes.length === 0)
|
|
617
|
+
throw c.error('E_SYNTAX', 'expected a language code (LANGUAGES en fr de DEFAULT en)');
|
|
618
|
+
const dflt = c.keyword('DEFAULT') ? c.operand('default language code') : undefined;
|
|
619
|
+
c.expectEnd();
|
|
620
|
+
return { kind: 'LANGUAGES', span, codes, ...(dflt ? { default: dflt } : {}) };
|
|
621
|
+
}
|
|
622
|
+
/** Sidecar formats PRECOMPRESS knows; only gzip has an encoder (src/deflate.ts, shared with the Rust port). */
|
|
623
|
+
const PRECOMPRESS_FORMATS = ['gzip', 'br', 'zstd'];
|
|
624
|
+
/** `PRECOMPRESS [--overwrite] [gzip]… <pattern>… [MIN <bytes>]` */
|
|
625
|
+
function parsePrecompress(c, span) {
|
|
626
|
+
const flags = parseFlags(c, { overwrite: 'bare' });
|
|
627
|
+
const formats = [];
|
|
628
|
+
for (;;) {
|
|
629
|
+
const at = c.span;
|
|
630
|
+
const mark = c.mark();
|
|
631
|
+
const w = c.word().toLowerCase();
|
|
632
|
+
if (!PRECOMPRESS_FORMATS.includes(w)) {
|
|
633
|
+
c.reset(mark);
|
|
634
|
+
break;
|
|
635
|
+
}
|
|
636
|
+
if (w !== 'gzip') {
|
|
637
|
+
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);
|
|
638
|
+
}
|
|
639
|
+
if (formats.includes(w))
|
|
640
|
+
throw c.error('E_SYNTAX', `${w} given twice`, at);
|
|
641
|
+
formats.push(w);
|
|
642
|
+
}
|
|
643
|
+
const patterns = [];
|
|
644
|
+
while (!c.atEnd() && !c.peekKeyword('MIN'))
|
|
645
|
+
patterns.push(c.operand('path pattern'));
|
|
646
|
+
if (patterns.length === 0)
|
|
647
|
+
throw c.error('E_SYNTAX', 'expected a path pattern (PRECOMPRESS /assets/ or PRECOMPRESS gzip /**/*.css)');
|
|
648
|
+
const min = c.keyword('MIN') ? c.operand('minimum size in bytes') : undefined;
|
|
568
649
|
c.expectEnd();
|
|
569
|
-
return { kind: '
|
|
650
|
+
return { kind: 'PRECOMPRESS', span, formats: formats.length ? formats : ['gzip'], patterns, ...(min ? { min } : {}), overwrite: flags.has('overwrite') };
|
|
651
|
+
}
|
|
652
|
+
/** `ROBOTS [--overwrite] [ALLOW <path> | DISALLOW <path>]… [SITEMAP] [TO <dest>]` (in this order) */
|
|
653
|
+
function parseRobots(c, span) {
|
|
654
|
+
const flags = parseFlags(c, { overwrite: 'bare' });
|
|
655
|
+
const rules = [];
|
|
656
|
+
for (;;) {
|
|
657
|
+
const at = c.span;
|
|
658
|
+
if (c.keyword('ALLOW'))
|
|
659
|
+
rules.push({ allow: true, path: c.operand('path'), span: at });
|
|
660
|
+
else if (c.keyword('DISALLOW'))
|
|
661
|
+
rules.push({ allow: false, path: c.operand('path'), span: at });
|
|
662
|
+
else
|
|
663
|
+
break;
|
|
664
|
+
}
|
|
665
|
+
const sitemap = c.keyword('SITEMAP');
|
|
666
|
+
const dest = c.keyword('TO') ? c.operand('destination') : undefined;
|
|
667
|
+
if (!c.atEnd()) {
|
|
668
|
+
const at = c.span;
|
|
669
|
+
throw c.error('E_SYNTAX', `unexpected '${c.word()}' (expected ALLOW, DISALLOW, SITEMAP or TO, in this order)`, at);
|
|
670
|
+
}
|
|
671
|
+
return { kind: 'ROBOTS', span, rules, sitemap, ...(dest ? { dest } : {}), overwrite: flags.has('overwrite') };
|
|
672
|
+
}
|
|
673
|
+
/** `SECURITY_TXT [--overwrite] CONTACT <uri>… EXPIRES <date> [ENCRYPTION <uri>]… [POLICY <uri>]… [TO <dest>]` (any order) */
|
|
674
|
+
function parseSecurityTxt(c, span) {
|
|
675
|
+
const flags = parseFlags(c, { overwrite: 'bare' });
|
|
676
|
+
const contact = [];
|
|
677
|
+
const encryption = [];
|
|
678
|
+
const policy = [];
|
|
679
|
+
let expires;
|
|
680
|
+
let dest;
|
|
681
|
+
while (!c.atEnd()) {
|
|
682
|
+
const at = c.span;
|
|
683
|
+
if (c.keyword('CONTACT'))
|
|
684
|
+
contact.push(c.operand('contact URI'));
|
|
685
|
+
else if (c.keyword('ENCRYPTION'))
|
|
686
|
+
encryption.push(c.operand('encryption key URI'));
|
|
687
|
+
else if (c.keyword('POLICY'))
|
|
688
|
+
policy.push(c.operand('policy URI'));
|
|
689
|
+
else if (c.keyword('EXPIRES')) {
|
|
690
|
+
if (expires)
|
|
691
|
+
throw c.error('E_SYNTAX', 'EXPIRES given twice', at);
|
|
692
|
+
expires = c.operand('expiry date');
|
|
693
|
+
}
|
|
694
|
+
else if (c.keyword('TO')) {
|
|
695
|
+
if (dest)
|
|
696
|
+
throw c.error('E_SYNTAX', 'TO given twice', at);
|
|
697
|
+
dest = c.operand('destination');
|
|
698
|
+
}
|
|
699
|
+
else
|
|
700
|
+
throw c.error('E_SYNTAX', `unexpected '${c.word()}' (expected CONTACT, EXPIRES, ENCRYPTION, POLICY or TO)`, at);
|
|
701
|
+
}
|
|
702
|
+
if (contact.length === 0)
|
|
703
|
+
throw c.error('E_VALIDATION', 'SECURITY_TXT needs CONTACT <uri> (RFC 9116 requires at least one Contact field)', span);
|
|
704
|
+
if (!expires)
|
|
705
|
+
throw c.error('E_VALIDATION', 'SECURITY_TXT needs EXPIRES <date> (RFC 9116 requires an Expires field)', span);
|
|
706
|
+
return { kind: 'SECURITY_TXT', span, contact, expires, encryption, policy, ...(dest ? { dest } : {}), overwrite: flags.has('overwrite') };
|
|
707
|
+
}
|
|
708
|
+
/** `PRECACHE [--overwrite] <pattern>… [TO <dest>] [INTO <service-worker>]` (clauses in this order) */
|
|
709
|
+
function parsePrecache(c, span) {
|
|
710
|
+
const flags = parseFlags(c, { overwrite: 'bare' });
|
|
711
|
+
const patterns = [];
|
|
712
|
+
while (!c.atEnd() && !c.peekKeyword('TO') && !c.peekKeyword('INTO'))
|
|
713
|
+
patterns.push(c.operand('path pattern'));
|
|
714
|
+
if (patterns.length === 0)
|
|
715
|
+
throw c.error('E_SYNTAX', 'expected a path pattern (PRECACHE /assets/ or PRECACHE /**/*.css /index.html)');
|
|
716
|
+
const dest = c.keyword('TO') ? c.operand('destination') : undefined;
|
|
717
|
+
const into = c.keyword('INTO') ? c.operand('service worker path') : undefined;
|
|
718
|
+
c.expectEnd();
|
|
719
|
+
return { kind: 'PRECACHE', span, patterns, ...(dest ? { dest } : {}), ...(into ? { into } : {}), overwrite: flags.has('overwrite') };
|
|
720
|
+
}
|
|
721
|
+
/** `CSP [POLICY <policy>] [META]` */
|
|
722
|
+
function parseCsp(c, span) {
|
|
723
|
+
const policy = c.keyword('POLICY') ? c.operand('policy') : undefined;
|
|
724
|
+
const meta = c.keyword('META');
|
|
725
|
+
c.expectEnd();
|
|
726
|
+
return { kind: 'CSP', span, ...(policy ? { policy } : {}), meta };
|
|
570
727
|
}
|
|
571
728
|
/** `CHECKLINKS [--warn] [--external]` */
|
|
572
729
|
function parseCheckLinks(c, span) {
|
|
@@ -586,7 +743,7 @@ function parseExport(c, span) {
|
|
|
586
743
|
throw c.error('E_SYNTAX', 'expected export format after AS', at);
|
|
587
744
|
const f = parseExportFormat(name);
|
|
588
745
|
if (f === undefined) {
|
|
589
|
-
throw c.error('E_UNSUPPORTED', `export format '${name}' is not supported (expected directory, zip, tar, tgz, wbn or
|
|
746
|
+
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
747
|
}
|
|
591
748
|
format = f;
|
|
592
749
|
}
|
|
@@ -606,7 +763,32 @@ function parseExport(c, span) {
|
|
|
606
763
|
}
|
|
607
764
|
compression = { value, span: cspan };
|
|
608
765
|
}
|
|
766
|
+
let key;
|
|
767
|
+
if (c.keyword('KEY')) {
|
|
768
|
+
const kspan = c.span;
|
|
769
|
+
key = { id: c.ident('secret id'), span: kspan };
|
|
770
|
+
}
|
|
771
|
+
let forHost;
|
|
772
|
+
if (c.keyword('FOR')) {
|
|
773
|
+
const hspan = c.span;
|
|
774
|
+
const name = c.word();
|
|
775
|
+
const value = parseExportHost(name);
|
|
776
|
+
if (value === undefined) {
|
|
777
|
+
throw c.error('E_SYNTAX', name === '' ? `expected a host after FOR (${EXPORT_HOSTS.join(', ')})` : `unknown host '${name}' (expected ${EXPORT_HOSTS.join(', ')})`, hspan);
|
|
778
|
+
}
|
|
779
|
+
forHost = { value, span: hspan };
|
|
780
|
+
}
|
|
609
781
|
c.expectEnd();
|
|
610
|
-
return {
|
|
782
|
+
return {
|
|
783
|
+
kind: 'EXPORT',
|
|
784
|
+
span,
|
|
785
|
+
path,
|
|
786
|
+
format,
|
|
787
|
+
...(base ? { base } : {}),
|
|
788
|
+
...(at ? { at } : {}),
|
|
789
|
+
...(compression ? { compression } : {}),
|
|
790
|
+
...(key ? { key } : {}),
|
|
791
|
+
...(forHost ? { forHost } : {}),
|
|
792
|
+
};
|
|
611
793
|
}
|
|
612
794
|
//# sourceMappingURL=parser.js.map
|
|
@@ -46,8 +46,24 @@ 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 'LANGUAGES':
|
|
56
|
+
return [...ins.codes, ...(ins.default ? [ins.default] : [])];
|
|
57
|
+
case 'PRECOMPRESS':
|
|
58
|
+
return [...ins.patterns, ...(ins.min ? [ins.min] : [])];
|
|
59
|
+
case 'ROBOTS':
|
|
60
|
+
return [...ins.rules.map((r) => r.path), ...(ins.dest ? [ins.dest] : [])];
|
|
61
|
+
case 'SECURITY_TXT':
|
|
62
|
+
return [...ins.contact, ins.expires, ...ins.encryption, ...ins.policy, ...(ins.dest ? [ins.dest] : [])];
|
|
63
|
+
case 'PRECACHE':
|
|
64
|
+
return [...ins.patterns, ...(ins.dest ? [ins.dest] : []), ...(ins.into ? [ins.into] : [])];
|
|
65
|
+
case 'CSP':
|
|
66
|
+
return ins.policy ? [ins.policy] : [];
|
|
51
67
|
case 'CHECKLINKS':
|
|
52
68
|
return [];
|
|
53
69
|
case 'EXPORT':
|
|
@@ -275,7 +291,15 @@ export function validate(instructions, file) {
|
|
|
275
291
|
case 'SITEMAP':
|
|
276
292
|
case 'REDIRECT':
|
|
277
293
|
case 'HEADER':
|
|
294
|
+
case 'MIME':
|
|
278
295
|
case 'FINGERPRINT':
|
|
296
|
+
case 'CANONICAL':
|
|
297
|
+
case 'LANGUAGES':
|
|
298
|
+
case 'PRECOMPRESS':
|
|
299
|
+
case 'ROBOTS':
|
|
300
|
+
case 'SECURITY_TXT':
|
|
301
|
+
case 'PRECACHE':
|
|
302
|
+
case 'CSP':
|
|
279
303
|
case 'CHECKLINKS':
|
|
280
304
|
break;
|
|
281
305
|
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,51 @@ 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 CANONICAL needs from a page's head: see {@link headLinks}. */
|
|
53
|
+
export interface HeadLinks {
|
|
54
|
+
/** The offset of the first `</head` end tag; undefined when there is none. */
|
|
55
|
+
readonly at: number | undefined;
|
|
56
|
+
/** A `<link>` whose `rel` has the token `canonical` comes before it (or anywhere, without `</head>`). */
|
|
57
|
+
readonly canonical: boolean;
|
|
58
|
+
/** So does a `<link>` whose `rel` has the token `alternate` and that has an `hreflang` attribute. */
|
|
59
|
+
readonly hreflang: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Where links go in a page's head and which it already has (ASCII case-insensitive `rel` tokens). Comments,
|
|
63
|
+
* declarations and raw text are skipped as in {@link scanHtml}.
|
|
64
|
+
*/
|
|
65
|
+
export declare function headLinks(text: string): HeadLinks;
|
|
66
|
+
/** What CSP needs from a page: its inline script and style texts, in order, and where its `<head>` start tag ends. */
|
|
67
|
+
export interface InlineBlocks {
|
|
68
|
+
/** The contents of each `<script>` without a `src` attribute (also empty ones). */
|
|
69
|
+
readonly scripts: readonly string[];
|
|
70
|
+
/** The contents of each `<style>`. */
|
|
71
|
+
readonly styles: readonly string[];
|
|
72
|
+
/** The offset just after the first `<head …>` start tag, if there is one. */
|
|
73
|
+
readonly headEnd?: number;
|
|
74
|
+
}
|
|
75
|
+
/** The inline scripts and styles of an HTML text (comments and other raw text skipped as in {@link scanHtml}). */
|
|
76
|
+
export declare function inlineBlocks(text: string): InlineBlocks;
|
|
30
77
|
/** Whether a path is read by {@link scanFile}, and how. */
|
|
31
78
|
export declare function referenceKind(path: string): 'html' | 'css' | undefined;
|
|
32
79
|
/** A file's text and references; undefined when it is not HTML or CSS, or not valid UTF-8. */
|