@johnhenry/sitefile 0.0.0-stage → 0.0.1

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 (178) hide show
  1. package/CHANGELOG.md +152 -0
  2. package/LICENSE +21 -0
  3. package/README.md +513 -2
  4. package/lib/src/archive-writers.d.ts +31 -0
  5. package/lib/src/archive-writers.js +197 -0
  6. package/lib/src/attest.d.ts +126 -0
  7. package/lib/src/attest.js +220 -0
  8. package/lib/src/bake.d.ts +74 -0
  9. package/lib/src/bake.js +372 -0
  10. package/lib/src/base-image.d.ts +76 -0
  11. package/lib/src/base-image.js +138 -0
  12. package/lib/src/build-args.d.ts +26 -0
  13. package/lib/src/build-args.js +164 -0
  14. package/lib/src/cache-limit.d.ts +54 -0
  15. package/lib/src/cache-limit.js +239 -0
  16. package/lib/src/casefold-data.d.ts +2 -0
  17. package/lib/src/casefold-data.js +217 -0
  18. package/lib/src/cbor.d.ts +39 -0
  19. package/lib/src/cbor.js +174 -0
  20. package/lib/src/checklinks.d.ts +42 -0
  21. package/lib/src/checklinks.js +120 -0
  22. package/lib/src/cli/bake.d.ts +2 -0
  23. package/lib/src/cli/bake.js +179 -0
  24. package/lib/src/cli/build-image.d.ts +21 -0
  25. package/lib/src/cli/build-image.js +42 -0
  26. package/lib/src/cli/cache.d.ts +8 -0
  27. package/lib/src/cli/cache.js +119 -0
  28. package/lib/src/cli/common.d.ts +29 -0
  29. package/lib/src/cli/common.js +100 -0
  30. package/lib/src/cli/git-context.d.ts +18 -0
  31. package/lib/src/cli/git-context.js +48 -0
  32. package/lib/src/cli/images.d.ts +6 -0
  33. package/lib/src/cli/images.js +285 -0
  34. package/lib/src/cli/index.d.ts +10 -0
  35. package/lib/src/cli/index.js +95 -0
  36. package/lib/src/cli/network.d.ts +34 -0
  37. package/lib/src/cli/network.js +56 -0
  38. package/lib/src/cli/outdated.d.ts +5 -0
  39. package/lib/src/cli/outdated.js +99 -0
  40. package/lib/src/cli/registry.d.ts +2 -0
  41. package/lib/src/cli/registry.js +127 -0
  42. package/lib/src/cli/serve-worker.d.ts +2 -0
  43. package/lib/src/cli/serve-worker.js +42 -0
  44. package/lib/src/cli/servers.d.ts +15 -0
  45. package/lib/src/cli/servers.js +467 -0
  46. package/lib/src/cli/vendor.d.ts +2 -0
  47. package/lib/src/cli/vendor.js +97 -0
  48. package/lib/src/cli/watch.d.ts +26 -0
  49. package/lib/src/cli/watch.js +81 -0
  50. package/lib/src/cli.d.ts +12 -0
  51. package/lib/src/cli.js +522 -0
  52. package/lib/src/csv.d.ts +27 -0
  53. package/lib/src/csv.js +117 -0
  54. package/lib/src/deflate.d.ts +76 -0
  55. package/lib/src/deflate.js +604 -0
  56. package/lib/src/digest.d.ts +3 -0
  57. package/lib/src/digest.js +7 -0
  58. package/lib/src/errors.d.ts +56 -0
  59. package/lib/src/errors.js +29 -0
  60. package/lib/src/executor.d.ts +393 -0
  61. package/lib/src/executor.js +2201 -0
  62. package/lib/src/explain.d.ts +64 -0
  63. package/lib/src/explain.js +445 -0
  64. package/lib/src/export-formats.d.ts +23 -0
  65. package/lib/src/export-formats.js +63 -0
  66. package/lib/src/exporter.d.ts +103 -0
  67. package/lib/src/exporter.js +676 -0
  68. package/lib/src/fingerprint.d.ts +40 -0
  69. package/lib/src/fingerprint.js +168 -0
  70. package/lib/src/frontmatter.d.ts +22 -0
  71. package/lib/src/frontmatter.js +45 -0
  72. package/lib/src/index.d.ts +13 -0
  73. package/lib/src/index.js +13 -0
  74. package/lib/src/language/ast.d.ts +360 -0
  75. package/lib/src/language/ast.js +57 -0
  76. package/lib/src/language/parser.d.ts +3 -0
  77. package/lib/src/language/parser.js +612 -0
  78. package/lib/src/language/scanner.d.ts +110 -0
  79. package/lib/src/language/scanner.js +449 -0
  80. package/lib/src/language/validate.d.ts +13 -0
  81. package/lib/src/language/validate.js +367 -0
  82. package/lib/src/links.d.ts +79 -0
  83. package/lib/src/links.js +583 -0
  84. package/lib/src/lint.d.ts +10 -0
  85. package/lib/src/lint.js +223 -0
  86. package/lib/src/markdown.d.ts +29 -0
  87. package/lib/src/markdown.js +612 -0
  88. package/lib/src/media.d.ts +82 -0
  89. package/lib/src/media.js +650 -0
  90. package/lib/src/memo.d.ts +57 -0
  91. package/lib/src/memo.js +93 -0
  92. package/lib/src/oci.d.ts +178 -0
  93. package/lib/src/oci.js +380 -0
  94. package/lib/src/outdated.d.ts +46 -0
  95. package/lib/src/outdated.js +195 -0
  96. package/lib/src/pages.d.ts +10 -0
  97. package/lib/src/pages.js +54 -0
  98. package/lib/src/paths.d.ts +39 -0
  99. package/lib/src/paths.js +101 -0
  100. package/lib/src/planner.d.ts +297 -0
  101. package/lib/src/planner.js +410 -0
  102. package/lib/src/plugins/cache.d.ts +96 -0
  103. package/lib/src/plugins/cache.js +325 -0
  104. package/lib/src/plugins/exec.d.ts +51 -0
  105. package/lib/src/plugins/exec.js +144 -0
  106. package/lib/src/plugins/host.d.ts +75 -0
  107. package/lib/src/plugins/host.js +277 -0
  108. package/lib/src/plugins/wasm.d.ts +23 -0
  109. package/lib/src/plugins/wasm.js +249 -0
  110. package/lib/src/profile.d.ts +42 -0
  111. package/lib/src/profile.js +68 -0
  112. package/lib/src/ref.d.ts +40 -0
  113. package/lib/src/ref.js +79 -0
  114. package/lib/src/registry-auth.d.ts +32 -0
  115. package/lib/src/registry-auth.js +151 -0
  116. package/lib/src/registry-cache.d.ts +71 -0
  117. package/lib/src/registry-cache.js +333 -0
  118. package/lib/src/registry-ops.d.ts +51 -0
  119. package/lib/src/registry-ops.js +248 -0
  120. package/lib/src/registry.d.ts +115 -0
  121. package/lib/src/registry.js +524 -0
  122. package/lib/src/render.d.ts +134 -0
  123. package/lib/src/render.js +576 -0
  124. package/lib/src/resources/archive.d.ts +11 -0
  125. package/lib/src/resources/archive.js +306 -0
  126. package/lib/src/resources/bundle-data.d.ts +16 -0
  127. package/lib/src/resources/bundle-data.js +50 -0
  128. package/lib/src/resources/convert.d.ts +12 -0
  129. package/lib/src/resources/convert.js +63 -0
  130. package/lib/src/resources/documents.d.ts +35 -0
  131. package/lib/src/resources/documents.js +122 -0
  132. package/lib/src/resources/git.d.ts +103 -0
  133. package/lib/src/resources/git.js +720 -0
  134. package/lib/src/resources/https.d.ts +74 -0
  135. package/lib/src/resources/https.js +413 -0
  136. package/lib/src/resources/ignore.d.ts +33 -0
  137. package/lib/src/resources/ignore.js +119 -0
  138. package/lib/src/resources/local.d.ts +64 -0
  139. package/lib/src/resources/local.js +248 -0
  140. package/lib/src/resources/lockfile.d.ts +52 -0
  141. package/lib/src/resources/lockfile.js +172 -0
  142. package/lib/src/resources/netpolicy.d.ts +6 -0
  143. package/lib/src/resources/netpolicy.js +82 -0
  144. package/lib/src/resources/network.d.ts +70 -0
  145. package/lib/src/resources/network.js +304 -0
  146. package/lib/src/resources/types.d.ts +69 -0
  147. package/lib/src/resources/types.js +13 -0
  148. package/lib/src/resources/vendor.d.ts +94 -0
  149. package/lib/src/resources/vendor.js +296 -0
  150. package/lib/src/resources/wbn-reader.d.ts +44 -0
  151. package/lib/src/resources/wbn-reader.js +302 -0
  152. package/lib/src/schema.d.ts +25 -0
  153. package/lib/src/schema.js +169 -0
  154. package/lib/src/secrets.d.ts +21 -0
  155. package/lib/src/secrets.js +103 -0
  156. package/lib/src/serve-rules.d.ts +29 -0
  157. package/lib/src/serve-rules.js +123 -0
  158. package/lib/src/server.d.ts +45 -0
  159. package/lib/src/server.js +246 -0
  160. package/lib/src/servers.d.ts +85 -0
  161. package/lib/src/servers.js +225 -0
  162. package/lib/src/site.d.ts +60 -0
  163. package/lib/src/site.js +169 -0
  164. package/lib/src/store.d.ts +151 -0
  165. package/lib/src/store.js +596 -0
  166. package/lib/src/tree.d.ts +50 -0
  167. package/lib/src/tree.js +134 -0
  168. package/lib/src/values.d.ts +7 -0
  169. package/lib/src/values.js +37 -0
  170. package/lib/src/vendor.d.ts +19 -0
  171. package/lib/src/vendor.js +145 -0
  172. package/lib/src/watch.d.ts +44 -0
  173. package/lib/src/watch.js +137 -0
  174. package/lib/src/wbn.d.ts +26 -0
  175. package/lib/src/wbn.js +241 -0
  176. package/lib/src/yaml.d.ts +34 -0
  177. package/lib/src/yaml.js +562 -0
  178. package/package.json +59 -4
@@ -0,0 +1,29 @@
1
+ export function needsPlugin(name) {
2
+ return { kind: 'plugin', name, flag: '--allow-plugin' };
3
+ }
4
+ export function needsTool(name) {
5
+ return { kind: 'tool', name, flag: '--allow-exec' };
6
+ }
7
+ export class SitefileError extends Error {
8
+ code;
9
+ span;
10
+ /** The message without the location prefix. */
11
+ detail;
12
+ /** For a permission error (`E_UNSUPPORTED` at a PLUGIN or TOOL line): what must be allowed. Not part of the message. */
13
+ needs;
14
+ constructor(code, detail, span, options) {
15
+ super(span ? `${formatSpan(span)}: ${detail}` : detail, options);
16
+ this.name = 'SitefileError';
17
+ this.code = code;
18
+ this.span = span;
19
+ this.detail = detail;
20
+ this.needs = options?.needs;
21
+ }
22
+ }
23
+ export function formatSpan(span) {
24
+ return `${span.file}:${span.line}:${span.column}`;
25
+ }
26
+ export function isSitefileError(e, code) {
27
+ return e instanceof SitefileError && (code === undefined || e.code === code);
28
+ }
29
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1,393 @@
1
+ import { type ExportFormat, type OciCompression, type Program } from './language/ast.js';
2
+ import { type ImageStageBase, type ImportedStageRef, type ImportSpec, type Plan } from './planner.js';
3
+ import { type PluginPolicy } from './plugins/host.js';
4
+ import { type CacheStats, type RemoteCache } from './plugins/cache.js';
5
+ import { type ResolvedTool, type ToolPolicy } from './plugins/exec.js';
6
+ import { type Secrets } from './secrets.js';
7
+ import { type GitLocation, type GitSelection } from './resources/git.js';
8
+ import { LocalContext } from './resources/local.js';
9
+ import { Lockfile } from './resources/lockfile.js';
10
+ import { Vendor } from './resources/vendor.js';
11
+ import { type ArchiveLimits, type FetchPolicy, type Resource } from './resources/types.js';
12
+ import { Tree } from './tree.js';
13
+ import { type AttestRequest, type Referrer } from './attest.js';
14
+ import { type BaseImage, type OciImage } from './oci.js';
15
+ import type { Credentials } from './registry-auth.js';
16
+ import type { RegistryOptions } from './registry.js';
17
+ import { Store } from './store.js';
18
+ import { type Profiler } from './profile.js';
19
+ import { BuildMemo, type MemoStats } from './memo.js';
20
+ import type { TemplateNode } from './render.js';
21
+ export interface BuildOptions {
22
+ /** Build context directory; local paths resolve from here. */
23
+ readonly contextDir: string;
24
+ /** Sitefile path. Default: `<contextDir>/Sitefile`. */
25
+ readonly sitefile?: string;
26
+ /** How messages name the Sitefile (default: its path relative to the working directory). */
27
+ readonly label?: string;
28
+ /**
29
+ * Build secrets by id (`--secret id=…,env=…|src=…`, see src/secrets.ts): sent only as the request
30
+ * headers that `IMPORT … SECRET` clauses name, and redacted from every warning and error.
31
+ */
32
+ readonly secrets?: Secrets;
33
+ readonly buildArgs?: Readonly<Record<string, string>>;
34
+ /** `--target <stage>`: build up to this named stage and export its whole tree (planner `targetPlan`). */
35
+ readonly target?: string;
36
+ /** Export destination; skipped when walking the context if it lies inside it. */
37
+ readonly outDir?: string;
38
+ readonly fetchPolicy?: Partial<FetchPolicy>;
39
+ /** Limits for extracting archives imported AS tree. */
40
+ readonly archiveLimits?: Partial<ArchiveLimits>;
41
+ /** Lockfile path, or false to disable. Default: `Sitefile.lock` next to the Sitefile. */
42
+ readonly lockfile?: string | false;
43
+ /** Fail instead of adding or changing lockfile entries. */
44
+ readonly frozenLockfile?: boolean;
45
+ /** Re-record unpinned URLs whose content changed. */
46
+ readonly updateLock?: boolean;
47
+ /**
48
+ * Context-relative vendor directory written by `sitefile vendor` (default `vendor/sitefile`, used when
49
+ * its manifest.json exists; a directory given here must exist). Remote IMPORTs and BASE blobs found
50
+ * there are read from it instead of the network, verified as usual. It is never part of a directory copy.
51
+ */
52
+ readonly vendorDir?: string;
53
+ /**
54
+ * `--strict-pins`: fail (E_UNPINNED) before fetching anything when a remote IMPORT has neither
55
+ * INTEGRITY nor a lockfile entry, or the BASE image is neither `@sha256:`-pinned nor locked.
56
+ */
57
+ readonly strictPins?: boolean;
58
+ /** Maximum imports resolved at once (default 4). */
59
+ readonly concurrency?: number;
60
+ /** Plugin process limits (per-call timeout, maximum result size). */
61
+ readonly pluginPolicy?: Partial<PluginPolicy>;
62
+ /** Permit hard-linked files in the context (you assert they are safe). Default false. */
63
+ readonly allowHardlinks?: boolean;
64
+ /**
65
+ * External programs TOOL may use: `name` (looked up on PATH) or `name=/absolute/path`,
66
+ * like the CLI's `--allow-exec`. A TOOL not listed here fails the build.
67
+ */
68
+ readonly allowExec?: readonly string[];
69
+ /**
70
+ * JavaScript PLUGINs allowed to run, by declared name, like the CLI's `--allow-plugin`.
71
+ * A JS PLUGIN not listed here (and without `allowAllPlugins`) fails the build.
72
+ * WebAssembly plugins need no permission.
73
+ */
74
+ readonly allowPlugin?: readonly string[];
75
+ /** Allow every JavaScript PLUGIN, like the CLI's `--allow-plugins`. */
76
+ readonly allowAllPlugins?: boolean;
77
+ /** External tool limits (per-call timeout, maximum output size). */
78
+ readonly toolPolicy?: Partial<ToolPolicy>;
79
+ /** Directory of the TRANSFORM result cache. Omit to disable caching (the CLI sets `$SITEFILE_HOME/cache/transform`). */
80
+ readonly cacheDir?: string;
81
+ /** Consulted on a local cache miss and told about every entry used (`--cache-from` / `--cache-to`). Needs `cacheDir`. */
82
+ readonly remoteCache?: RemoteCache;
83
+ readonly onWarning?: (message: string) => void;
84
+ /** oci: `os/arch` of the image (and of the BASE to pull); default linux/amd64. */
85
+ readonly platform?: string;
86
+ /** `--base`: build the oci image on this image, overriding the Sitefile's `AS oci BASE`. */
87
+ readonly baseImage?: string;
88
+ /** Do not resolve a BASE (the output will not be an oci image). */
89
+ readonly skipBase?: boolean;
90
+ /** Registry transport/auth options for pulling the BASE. */
91
+ readonly registry?: RegistryOptions & {
92
+ readonly explicitCredentials?: Credentials;
93
+ };
94
+ /** The image store used for BASE pulls (default: $SITEFILE_HOME). */
95
+ readonly store?: Store;
96
+ /** Informational lines (e.g. the path each allowed tool resolved to). */
97
+ readonly onNotice?: (message: string) => void;
98
+ /** `--profile`: record a timing trace of the build here (src/profile.ts). */
99
+ readonly profiler?: Profiler;
100
+ /** Other paths this command writes (e.g. the --profile file): skipped when walking the context, like `outDir`. */
101
+ readonly alsoWrites?: readonly string[];
102
+ /**
103
+ * Incremental rebuilds: reuse the results of steps whose inputs did not change since an
104
+ * earlier build with the same memo (watch mode keeps one per session; src/memo.ts).
105
+ */
106
+ readonly memo?: BuildMemo;
107
+ /** Keep every intermediate tree in {@link BuildResult.steps} (for `sitefile why`). */
108
+ readonly recordSteps?: boolean;
109
+ }
110
+ export interface BuildResult {
111
+ readonly plan: Plan;
112
+ /** The final stage's whole tree. */
113
+ readonly tree: Tree;
114
+ /** The exported subtree. */
115
+ readonly output: Tree;
116
+ readonly resources: ReadonlyMap<string, Resource>;
117
+ readonly warnings: readonly string[];
118
+ readonly lockfileWritten: boolean;
119
+ /** The resolved BASE image (EXPORT ... AS oci BASE <image> or --base), whose blobs are in the store. */
120
+ readonly base?: BaseImage;
121
+ /** The `FROM image` stage bases this build read, in stage order (name and image digest). */
122
+ readonly images?: readonly FromImageUse[];
123
+ /** Allow-listed tools this build resolved. */
124
+ readonly tools: readonly ResolvedTool[];
125
+ /** What the TRANSFORMs did: processes started, calls made, cache activity. */
126
+ readonly transformStats: TransformStats;
127
+ /** With `memo`: how many steps were reused and how many ran. */
128
+ readonly memoStats?: MemoStats;
129
+ /**
130
+ * With `recordSteps`: per stage of `plan.stages`, the tree it starts from, then the tree after each of its
131
+ * operations (`steps[s][i + 1]` follows `operations[i]`). `tree` is the last one plus the EXPORT site files.
132
+ */
133
+ readonly steps?: readonly (readonly Tree[])[];
134
+ /** `--strict-pins`: how each remote input was pinned (recorded in the provenance). */
135
+ readonly pins?: Pins;
136
+ /** The Sitefiles imported AS sitefile, by import name (each with its own imports, plan and, with `recordSteps`, steps). */
137
+ readonly imported?: ReadonlyMap<string, ImportedSitefile>;
138
+ /** What each FINGERPRINT renamed (old path, new path), by its line. */
139
+ readonly renames?: ReadonlyMap<number, ReadonlyArray<readonly [string, string]>>;
140
+ }
141
+ /** A `FROM image` base a build used. */
142
+ export interface FromImageUse {
143
+ /** `registry/name:tag`, or the local name as written. */
144
+ readonly name: string;
145
+ readonly digest: string;
146
+ /** The FROM line. */
147
+ readonly line: number;
148
+ readonly local: boolean;
149
+ /** Set for a stage of an imported Sitefile: the import's qualified name (`theme`). */
150
+ readonly import?: string;
151
+ }
152
+ export interface TransformStats extends CacheStats {
153
+ /** Plugin processes started (0 when every result came from the cache). */
154
+ pluginsSpawned: number;
155
+ /** transform() calls made to plugin processes. */
156
+ pluginCalls: number;
157
+ /** External tool invocations. */
158
+ toolRuns: number;
159
+ }
160
+ interface Loaded {
161
+ readonly program: Program;
162
+ readonly sitefilePath: string;
163
+ readonly label: string;
164
+ readonly source: string;
165
+ }
166
+ /** Read, parse and validate a Sitefile. */
167
+ export declare function loadProgram(options: Pick<BuildOptions, 'contextDir' | 'sitefile' | 'label'>): Promise<Loaded>;
168
+ /** Parse, validate and evaluate variables, without reading any sources. */
169
+ export declare function planBuild(options: BuildOptions): Promise<Plan>;
170
+ /** `validate`'s lint warnings (src/lint.ts) for the whole Sitefile (a `--target` does not narrow them). */
171
+ export declare function lintBuild(options: BuildOptions, disabled?: readonly string[]): Promise<string[]>;
172
+ /** `validate --strict-pins`: check the pins of `p` against the lockfile without building or fetching. */
173
+ export declare function checkPlanPins(options: BuildOptions, p: Plan): Promise<void>;
174
+ /** Run a build in memory. */
175
+ export declare function build(options: BuildOptions): Promise<BuildResult>;
176
+ /** How the remote inputs of a `--strict-pins` build are pinned: remote IMPORTs by name, and the BASE. */
177
+ export interface Pins {
178
+ readonly imports: Readonly<Record<string, 'integrity' | 'lockfile' | 'commit'>>;
179
+ readonly base?: 'digest' | 'lockfile';
180
+ /** `FROM image` bases with a registry, by FROM line. */
181
+ readonly images?: Readonly<Record<number, 'digest' | 'lockfile'>>;
182
+ }
183
+ /** The Sitefile.lock `images` key of a registry `FROM image` reference. */
184
+ export declare function imageLockKey(b: ImageStageBase): string;
185
+ /**
186
+ * `--strict-pins`: every remote input must be pinned, so the build is reproducible. A remote IMPORT
187
+ * needs INTEGRITY or a `Sitefile.lock` entry; a BASE image needs `@sha256:` or a lockfile `images`
188
+ * entry. `lock` is undefined with --no-lockfile (only the Sitefile's own pins count then). Checked in
189
+ * source order, before anything is fetched; the first unpinned input fails with E_UNPINNED.
190
+ */
191
+ export declare function checkPins(p: Plan, lock: Lockfile | undefined, baseRef: string | undefined): Pins;
192
+ export interface ExportTarget {
193
+ /** Overrides the Sitefile's EXPORT format. */
194
+ readonly format?: ExportFormat;
195
+ /** Overrides the Sitefile's EXPORT ... BASE (wbn). */
196
+ readonly baseUrl?: string;
197
+ /** oci: root directory inside the layer (overrides EXPORT ... AT; default /srv/www). */
198
+ readonly ociRoot?: string;
199
+ /** oci: site layer encoding (overrides EXPORT ... COMPRESSION; default gzip). */
200
+ readonly ociCompression?: OciCompression;
201
+ /** wbn: `gzip` wraps the bundle in gzip (overrides EXPORT ... COMPRESSION; default none). */
202
+ readonly wbnCompression?: OciCompression;
203
+ /** Extra OCI config labels. */
204
+ readonly imageLabels?: Readonly<Record<string, string>>;
205
+ /** Add org.opencontainers.image.source/revision from the git checkout (opt-in). */
206
+ readonly gitLabels?: boolean;
207
+ /** oci: `name:tag` recorded as org.opencontainers.image.ref.name in index.json. */
208
+ readonly ociRefName?: string;
209
+ /** oci: attach a provenance and/or SBOM attestation (`--provenance`, `--sbom`). */
210
+ readonly attest?: AttestRequest;
211
+ }
212
+ export interface ExportedBuild extends BuildResult {
213
+ readonly format: ExportFormat;
214
+ /** Real path written: a directory for `directory`, otherwise the archive file. */
215
+ readonly outDir: string;
216
+ /** Archive size in bytes (archive formats only). */
217
+ readonly bytes?: number;
218
+ /** `sha256:<hex>` of the archive file (archive formats only). */
219
+ readonly fileDigest?: string;
220
+ /** oci: the image's manifest digest (its image ID). */
221
+ readonly manifestDigest?: string;
222
+ /** Watch mode: set when the directory export applied only the changes (src/exporter.ts). */
223
+ readonly incremental?: {
224
+ readonly written: number;
225
+ readonly removed: number;
226
+ };
227
+ }
228
+ /**
229
+ * Build, then write the exported tree to `outDir`: a directory for the
230
+ * `directory` format, a single file for zip, tar, tgz and wbn.
231
+ */
232
+ export declare function buildToDirectory(options: BuildOptions & ExportTarget & {
233
+ readonly outDir: string;
234
+ readonly force?: boolean;
235
+ }): Promise<ExportedBuild>;
236
+ /**
237
+ * The Sitefile's `EXPORT ... COMPRESSION` for an export in `format`: it belongs to the EXPORT's own format,
238
+ * so a `--format` override to another format does not inherit it (undefined: that format's default).
239
+ */
240
+ export declare function sitefileCompression(plan: Pick<Plan, 'exportFormat' | 'exportCompression'>, format: ExportFormat): OciCompression | undefined;
241
+ /**
242
+ * The attestations (`--provenance`, `--sbom`) of an image built from `result`: in-toto statements
243
+ * whose subject is the image manifest. They never change the image itself.
244
+ */
245
+ export declare function imageAttestations(result: BuildResult, img: Pick<OciImage, 'manifestDigest' | 'manifestBytes' | 'configBytes' | 'root'>, options: Pick<BuildOptions, 'contextDir' | 'sitefile' | 'label' | 'buildArgs' | 'platform'>, request: AttestRequest): Promise<Referrer[]>;
246
+ /** What fetching a remote IMPORT needs: the network policy and the lockfile rules (and, for builds, the vendor directory). */
247
+ export interface RemoteEnv {
248
+ readonly policy: FetchPolicy;
249
+ readonly lock: Lockfile | undefined;
250
+ readonly label: string;
251
+ readonly warn: (m: string) => void;
252
+ readonly frozen: boolean;
253
+ readonly update: boolean;
254
+ /** Vendored copies (`sitefile vendor`), preferred over the network. */
255
+ readonly vendor?: Vendor | undefined;
256
+ /** Limits for Git trees (file count, total size; default DEFAULT_ARCHIVE_LIMITS). */
257
+ readonly archiveLimits?: ArchiveLimits;
258
+ /** Build secrets by id (`--secret`), sent as the headers of IMPORT … SECRET clauses. */
259
+ readonly secrets?: Secrets | undefined;
260
+ }
261
+ /** `--secret` ids that no IMPORT … SECRET names (likely a typo). */
262
+ export declare function warnUnusedSecrets(p: Plan, secrets: Secrets | undefined, warn: (m: string) => void): void;
263
+ /**
264
+ * The bytes of a remote IMPORT, checked against its INTEGRITY and the lockfile (and recorded there):
265
+ * read from the vendor directory when it has the URL, otherwise fetched.
266
+ */
267
+ export declare function fetchRemoteImport(spec: ImportSpec, url: string, env: RemoteEnv): Promise<{
268
+ bytes: Uint8Array;
269
+ finalUrl: string;
270
+ }>;
271
+ /** The canonical bytes `sitefile vendor` stores for a Git selection: a file's bytes, or a tree as a deterministic tar. */
272
+ export declare function gitSelectionBytes(selection: GitSelection): Uint8Array;
273
+ /**
274
+ * The content of a Git IMPORT, checked against the lockfile (and recorded there). The commit is the
275
+ * one in the URL, else the locked one (unless --update-lock), else what the ref names now. A vendored
276
+ * copy of that commit is read instead of the network (a ref with no lockfile entry uses the vendored
277
+ * commit, as a BASE tag uses the vendored digest).
278
+ */
279
+ export declare function fetchGitImport(spec: ImportSpec, loc: GitLocation, env: RemoteEnv): Promise<{
280
+ commit: string;
281
+ selection: GitSelection;
282
+ }>;
283
+ /** How deep Sitefile imports may nest (an imported Sitefile importing another counts one more level). */
284
+ export declare const MAX_SITEFILE_IMPORT_DEPTH = 8;
285
+ /**
286
+ * Where a Sitefile lives, for the labels of the Sitefiles it imports: `<prefix><dir>/Sitefile`.
287
+ * Local Sitefiles have no prefix and `dir` relative to the working directory; a Git checkout has
288
+ * `git+https://host/repo.git#<commit>:` and the directory inside the repository.
289
+ */
290
+ export interface LabelScope {
291
+ readonly prefix: string;
292
+ readonly dir: string;
293
+ }
294
+ /** The label an imported Sitefile's messages and file origins use. */
295
+ export declare function sitefileLabel(scope: LabelScope): string;
296
+ /** The ARG values an `IMPORT … AS sitefile` passes, checked against the imported Sitefile's ARGs. */
297
+ export declare function importedArgs(spec: ImportSpec, program: Program): Record<string, string>;
298
+ /**
299
+ * Parse, check and plan an imported Sitefile: no PLUGIN or TOOL, the IMPORT's ARG clauses, and the
300
+ * stages `refs` (references from the importing Sitefile) must exist.
301
+ */
302
+ export declare function planImportedSitefile(spec: ImportSpec, source: string, label: string, refs: readonly ImportedStageRef[]): {
303
+ program: Program;
304
+ plan: Plan;
305
+ };
306
+ /** A Sitefile imported AS sitefile: loaded, its imports resolved; its stages are built when first needed. */
307
+ export interface ImportedSitefile {
308
+ /** The import's name as the build's own Sitefile sees it: `theme`, or `theme+inner` for one imported by `theme`. */
309
+ readonly name: string;
310
+ readonly label: string;
311
+ /** Its whole plan (every stage). */
312
+ readonly plan: Plan;
313
+ /**
314
+ * What the import stands for in the provenance and memo keys: the sha256 of its Sitefile (a local
315
+ * directory) or the digest of the checked-out tree (Git).
316
+ */
317
+ readonly digest: string;
318
+ /** Whether a path of its context is a directory (`why` lists the file a directory COPY placed). */
319
+ isDirectory(rel: string): boolean;
320
+ /** Its imports by name (an `AS sitefile` one as its Sitefile, see {@link unitResource}). */
321
+ readonly resources: ReadonlyMap<string, Resource>;
322
+ /** The Sitefiles it imports, by import name. */
323
+ readonly imported: ReadonlyMap<string, ImportedSitefile>;
324
+ /** With `recordSteps`: like {@link BuildResult.steps}, for the stages built (a prefix of `plan.stages`). */
325
+ readonly steps?: Tree[][];
326
+ /** What each of its FINGERPRINTs renamed (old path, new path), by its line. */
327
+ readonly renames: ReadonlyMap<number, ReadonlyArray<readonly [string, string]>>;
328
+ }
329
+ /**
330
+ * Where an imported Sitefile is read from by `vendor` and `outdated`, which never build it: a directory of
331
+ * a local context, or a directory of a Git tree held in memory.
332
+ */
333
+ export type SitefileSource = {
334
+ readonly kind: 'local';
335
+ readonly local: LocalContext;
336
+ readonly scope: LabelScope;
337
+ readonly label: string;
338
+ readonly chain: ReadonlyArray<{
339
+ readonly id: string;
340
+ readonly label: string;
341
+ }>;
342
+ } | {
343
+ readonly kind: 'tree';
344
+ readonly tree: Tree;
345
+ readonly dir: string;
346
+ readonly scope: LabelScope;
347
+ readonly label: string;
348
+ readonly chain: ReadonlyArray<{
349
+ readonly id: string;
350
+ readonly label: string;
351
+ }>;
352
+ };
353
+ /** The source of the build's own Sitefile, for {@link readImportedSitefile}. */
354
+ export declare function rootSitefileSource(options: BuildOptions, label: string, sitefilePath: string): Promise<SitefileSource>;
355
+ /**
356
+ * Read and plan the Sitefile an `IMPORT … AS sitefile` of `from` names, without building it (for `vendor`
357
+ * and `outdated`): the same location, cycle, depth and ARG rules as a build. A Git one is fetched with
358
+ * `fetchGit` (the commit a build would use). Returns its plan and the source its own imports read from.
359
+ */
360
+ export declare function readImportedSitefile(spec: ImportSpec, from: SitefileSource, refs: readonly ImportedStageRef[], fetchGit: (spec: ImportSpec, loc: GitLocation) => Promise<{
361
+ commit: string;
362
+ selection: GitSelection;
363
+ }>): Promise<{
364
+ plan: Plan;
365
+ source: SitefileSource;
366
+ }>;
367
+ /** Top-level names a template reads (variables, #each lists, #if conditions). */
368
+ export declare function templateNames(nodes: readonly TemplateNode[], out?: Set<string>): Set<string>;
369
+ /**
370
+ * The last segment of a TRANSFORM destination when it names each file of a directory source:
371
+ * `*` (the file's own name) or `*.ext` (its name with the extension replaced). Undefined otherwise.
372
+ */
373
+ export declare function starName(dest: string): string | undefined;
374
+ /**
375
+ * Where one file of a directory TRANSFORM goes: `rel` is its path inside the source directory.
376
+ * `TO /out/*` keeps its relative path, `TO /out/*.ext` replaces its extension, and any other
377
+ * destination is the directory `<dest>/<relative dir>/` (the plugin names the files).
378
+ */
379
+ export declare function fileDest(dest: string, rel: string): string;
380
+ type Settled<T> = {
381
+ readonly ok: true;
382
+ readonly value: T;
383
+ } | {
384
+ readonly ok: false;
385
+ readonly error: unknown;
386
+ };
387
+ /**
388
+ * Run `fn(0..n)` at most `limit` at a time, starting them in index order. After a failure no
389
+ * later index starts, so the lowest failing index is always among the results (and every index
390
+ * below it has run): callers report that one, whatever order the calls finished in.
391
+ */
392
+ export declare function runBounded<T>(n: number, limit: number, fn: (i: number) => Promise<T>): Promise<Array<Settled<T> | undefined>>;
393
+ export {};