@mailwoman/core 10.4.0 → 10.6.0

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 (76) hide show
  1. package/lib/api/ckan.ts +1 -1
  2. package/lib/decoder/serialize/json.ts +1 -1
  3. package/lib/env/env-file.ts +71 -0
  4. package/lib/env.ts +15 -9
  5. package/lib/fs/readers/stat.ts +16 -1
  6. package/lib/fs/readers.ts +15 -0
  7. package/lib/geocode/result.ts +46 -0
  8. package/lib/git.ts +357 -55
  9. package/lib/layers/manifest.ts +31 -0
  10. package/lib/layers/schema.ts +14 -0
  11. package/lib/license/docs-site.ts +1 -1
  12. package/lib/module/compiled-freshness.ts +5 -1
  13. package/lib/process.ts +320 -0
  14. package/lib/resources/git.ts +9 -5
  15. package/lib/types/classifier.ts +1 -1
  16. package/lib/utils/events.ts +23 -0
  17. package/out/api/ckan.d.ts +1 -1
  18. package/out/decoder/serialize/json.js +1 -1
  19. package/out/env/env-file.d.ts +26 -0
  20. package/out/env/env-file.d.ts.map +1 -0
  21. package/out/env/env-file.js +60 -0
  22. package/out/env/env-file.js.map +1 -0
  23. package/out/env.d.ts.map +1 -1
  24. package/out/env.js +15 -10
  25. package/out/env.js.map +1 -1
  26. package/out/fs/readers/stat.d.ts +9 -1
  27. package/out/fs/readers/stat.d.ts.map +1 -1
  28. package/out/fs/readers/stat.js +16 -0
  29. package/out/fs/readers/stat.js.map +1 -1
  30. package/out/fs/readers.d.ts +11 -0
  31. package/out/fs/readers.d.ts.map +1 -1
  32. package/out/fs/readers.js +14 -0
  33. package/out/fs/readers.js.map +1 -1
  34. package/out/geocode/result.d.ts +25 -0
  35. package/out/geocode/result.d.ts.map +1 -1
  36. package/out/geocode/result.js +40 -0
  37. package/out/geocode/result.js.map +1 -1
  38. package/out/git.d.ts +180 -4
  39. package/out/git.d.ts.map +1 -1
  40. package/out/git.js +227 -37
  41. package/out/git.js.map +1 -1
  42. package/out/layers/manifest.d.ts +19 -0
  43. package/out/layers/manifest.d.ts.map +1 -1
  44. package/out/layers/manifest.js +12 -0
  45. package/out/layers/manifest.js.map +1 -1
  46. package/out/layers/schema.d.ts +10 -0
  47. package/out/layers/schema.d.ts.map +1 -1
  48. package/out/layers/schema.js +4 -0
  49. package/out/layers/schema.js.map +1 -1
  50. package/out/license/docs-site.d.ts +1 -1
  51. package/out/license/docs-site.js +1 -1
  52. package/out/module/compiled-freshness.d.ts.map +1 -1
  53. package/out/module/compiled-freshness.js +5 -1
  54. package/out/module/compiled-freshness.js.map +1 -1
  55. package/out/process.d.ts +146 -0
  56. package/out/process.d.ts.map +1 -1
  57. package/out/process.js +158 -0
  58. package/out/process.js.map +1 -1
  59. package/out/resources/git.d.ts +5 -1
  60. package/out/resources/git.d.ts.map +1 -1
  61. package/out/resources/git.js +8 -5
  62. package/out/resources/git.js.map +1 -1
  63. package/out/tools/coarse-placer/paths.d.ts +2 -2
  64. package/out/tools/coarse-placer/paths.js +2 -2
  65. package/out/tools/download/libpostal-resources.d.ts +2 -2
  66. package/out/tools/download/libpostal-resources.d.ts.map +1 -1
  67. package/out/tools/download/libpostal-resources.js +4 -4
  68. package/out/tools/download/libpostal-resources.js.map +1 -1
  69. package/out/types/classifier.d.ts +1 -1
  70. package/out/utils/events.d.ts +13 -0
  71. package/out/utils/events.d.ts.map +1 -1
  72. package/out/utils/events.js +19 -0
  73. package/out/utils/events.js.map +1 -1
  74. package/package.json +7 -7
  75. package/tools/coarse-placer/paths.ts +2 -2
  76. package/tools/download/libpostal-resources.ts +4 -4
package/lib/git.ts CHANGED
@@ -2,18 +2,343 @@
2
2
  * @copyright Sister Software
3
3
  * @license AGPL-3.0
4
4
  * @author Teffen Ellis, et al.
5
- * @file The working tree's own git state: head, the current branch, dirty tracked files, tracked paths.
5
+ * @file The one home for running git: {@linkcode GitClient} and the readers built on it.
6
6
  *
7
- * Every reader here is one `git` invocation with its output shaped for the caller, so the seven sites that each
8
- * spelled `git rev-parse head` through their own wrapper share one. A resource repository clone and pull is a
9
- * different concern and lives in `resources/git.ts`.
7
+ * A `GitClient` is bound to one directory. Short reads such as `rev-parse` answer their stdout.
8
+ * Long transfers such as `clone` and `fetch` run as a {@linkcode ProcessTask} with `--progress`,
9
+ * and the client re-dispatches each parsed progress line, so a command renders one stream for every repository it touches.
10
+ * Disposing the client stops every git process it started.
11
+ *
12
+ * The free functions below are the same readers for a caller that needs one answer about the working tree.
10
13
  */
11
14
 
15
+ import { asyncInit } from "async-init"
12
16
  import type { PathBuilderLike } from "path-ts"
13
17
  import { TextSpliterator } from "spliterator"
14
18
 
19
+ import type { IRuntimeLogger } from "#logging"
15
20
  import { repoRootPathBuilder } from "#paths"
16
- import { runFile } from "#process"
21
+ import {
22
+ type ProcessProgress,
23
+ type ProcessResult,
24
+ ProcessTask,
25
+ type ProcessTaskOptions,
26
+ runFile,
27
+ runFileSync,
28
+ } from "#process"
29
+ import { TypedEventTarget } from "#utils/events"
30
+
31
+ /**
32
+ * The stdout ceiling for a git read that lists paths or history.
33
+ */
34
+ const LISTING_MAX_BUFFER = 64 * 1024 * 1024
35
+
36
+ /**
37
+ * Git's progress meter, as it writes one redraw to stderr under `--progress`:
38
+ * `Receiving objects: 45% (450/1000), 1.20 MiB | 2.40 MiB/s`, or the same line
39
+ * prefixed with `remote: ` when the server reports it.
40
+ */
41
+ const GIT_PROGRESS_PATTERN = /^(?:remote: )?([A-Z][A-Za-z ]+):\s+(\d{1,3})% \((\d+)\/(\d+)\)/u
42
+
43
+ /**
44
+ * Read one stderr line of a git transfer as progress, or `null` for any other line.
45
+ */
46
+ export function parseGitProgress(line: string): ProcessProgress | null {
47
+ const match = GIT_PROGRESS_PATTERN.exec(line)
48
+
49
+ if (!match) return null
50
+
51
+ return {
52
+ stage: match[1]!,
53
+ percent: Number(match[2]),
54
+ processed: Number(match[3]),
55
+ total: Number(match[4]),
56
+ }
57
+ }
58
+
59
+ /**
60
+ * One progress step from a git transfer, with the command line it came from.
61
+ */
62
+ export interface GitProgress extends ProcessProgress {
63
+ command: string
64
+ }
65
+
66
+ /**
67
+ * The events a {@linkcode GitClient} dispatches, keyed by type, with each event's `detail`.
68
+ */
69
+ export interface GitClientEventMap {
70
+ progress: GitProgress
71
+ }
72
+
73
+ /**
74
+ * Options for {@linkcode GitClient}.
75
+ */
76
+ export interface GitClientOptions {
77
+ /**
78
+ * The directory git runs in.
79
+ *
80
+ * @defaultValue the repository root
81
+ */
82
+ cwd?: PathBuilderLike
83
+ logger?: IRuntimeLogger
84
+ /**
85
+ * Aborting the signal stops every git process the client started.
86
+ */
87
+ signal?: AbortSignal
88
+ }
89
+
90
+ /**
91
+ * Options for a single git read.
92
+ */
93
+ export interface GitReadOptions {
94
+ /**
95
+ * The stdout ceiling in bytes.
96
+ *
97
+ * A read past it rejects rather than answering a truncated listing.
98
+ */
99
+ maxBuffer?: number
100
+ /**
101
+ * Whether to remove surrounding whitespace from stdout.
102
+ *
103
+ * Porcelain output starts with a status column that may be a space, so a porcelain read passes `false`.
104
+ *
105
+ * @defaultValue `true`
106
+ */
107
+ trim?: boolean
108
+ }
109
+
110
+ /**
111
+ * Options for a git transfer.
112
+ */
113
+ export interface GitTransferOptions extends Pick<ProcessTaskOptions, "stdin" | "stdout" | "rawStdout"> {
114
+ /**
115
+ * Whether a non-zero exit rejects the transfer.
116
+ *
117
+ * @defaultValue `true`
118
+ */
119
+ reject?: boolean
120
+ }
121
+
122
+ /**
123
+ * A git runner bound to one directory, modeled on `APIClient`.
124
+ *
125
+ * Its reads answer stdout with the trailing newline removed.
126
+ * Its transfers report progress as `progress` events.
127
+ *
128
+ * Disposal stops every process the client started and waits for each to exit.
129
+ *
130
+ * Initialize it with `construct(GitClient, options)` from `async-init` to resolve
131
+ * {@linkcode GitClient.root} and {@linkcode GitClient.commonDirectory} before use.
132
+ * A client that will clone into a directory that does not exist yet is used without initialization.
133
+ */
134
+ export class GitClient extends TypedEventTarget<GitClientEventMap> implements AsyncDisposable {
135
+ public readonly cwd: PathBuilderLike
136
+ public readonly logger: IRuntimeLogger | undefined
137
+
138
+ /**
139
+ * The working-tree root, set by initialization.
140
+ */
141
+ public root: string | null = null
142
+ /**
143
+ * The shared `.git` directory, set by initialization.
144
+ *
145
+ * The main checkout and each of its worktrees report the same directory.
146
+ */
147
+ public commonDirectory: string | null = null
148
+
149
+ readonly #shutdown = new AbortController()
150
+ readonly #tasks = new Set<ProcessTask>()
151
+ #disposePromise: Promise<void> | null = null
152
+
153
+ constructor(options: GitClientOptions = {}) {
154
+ super()
155
+
156
+ this.cwd = options.cwd ?? repoRootPathBuilder
157
+ this.logger = options.logger
158
+
159
+ options.signal?.addEventListener("abort", () => void this[Symbol.asyncDispose](), { once: true })
160
+ }
161
+
162
+ public async [asyncInit](): Promise<void> {
163
+ this.root = await this.read(["rev-parse", "--show-toplevel"])
164
+ this.commonDirectory = await this.read(["rev-parse", "--path-format=absolute", "--git-common-dir"])
165
+ }
166
+
167
+ /**
168
+ * Run git to completion and answer stdout with surrounding whitespace removed.
169
+ *
170
+ * A non-zero exit rejects with a `ProcessError` carrying git's stderr.
171
+ */
172
+ public async read(args: string | readonly string[], options: GitReadOptions = {}): Promise<string> {
173
+ this.#shutdown.signal.throwIfAborted()
174
+
175
+ const argumentList = typeof args === "string" ? [args] : args
176
+
177
+ this.logger?.debug(`$ git ${argumentList.join(" ")}`)
178
+
179
+ const { stdout } = await runFile("git", argumentList, {
180
+ cwd: this.cwd,
181
+ maxBuffer: options.maxBuffer,
182
+ signal: this.#shutdown.signal,
183
+ })
184
+
185
+ return options.trim === false ? stdout : stdout.trim()
186
+ }
187
+
188
+ /**
189
+ * Start git as a {@linkcode ProcessTask} whose parsed progress lines the client re-dispatches.
190
+ *
191
+ * The caller passes `--progress` where the subcommand accepts it.
192
+ * Git writes the meter only to a terminal unless asked.
193
+ */
194
+ public start(args: readonly string[], options: GitTransferOptions = {}): ProcessTask {
195
+ this.#shutdown.signal.throwIfAborted()
196
+
197
+ const task = new ProcessTask("git", args, {
198
+ stdin: options.stdin,
199
+ stdout: options.stdout,
200
+ rawStdout: options.rawStdout,
201
+ cwd: this.cwd,
202
+ logger: this.logger,
203
+ reject: options.reject,
204
+ signal: this.#shutdown.signal,
205
+ progress: parseGitProgress,
206
+ })
207
+
208
+ this.#tasks.add(task)
209
+
210
+ task.on("progress", (step) => this.emit("progress", { ...step, command: task.command }))
211
+ void task.result.finally(() => this.#tasks.delete(task)).catch(() => undefined)
212
+
213
+ return task
214
+ }
215
+
216
+ /**
217
+ * Clone `url` into `directory`, shallow when `depth` is given.
218
+ */
219
+ public clone(
220
+ url: string,
221
+ directory: PathBuilderLike,
222
+ options: GitTransferOptions & { depth?: number } = {}
223
+ ): Promise<ProcessResult> {
224
+ const depth = options.depth === undefined ? [] : ["--depth", String(options.depth)]
225
+
226
+ return this.start(["clone", "--progress", ...depth, url, directory.toString()], options).result
227
+ }
228
+
229
+ /**
230
+ * Fetch `remote` into the client's repository.
231
+ */
232
+ public fetch(remote = "origin", options: GitTransferOptions = {}): Promise<ProcessResult> {
233
+ return this.start(["fetch", "--progress", remote], options).result
234
+ }
235
+
236
+ /**
237
+ * Pull the current branch's upstream into the client's repository.
238
+ */
239
+ public pull(options: GitTransferOptions = {}): Promise<ProcessResult> {
240
+ return this.start(["pull", "--progress"], options).result
241
+ }
242
+
243
+ /**
244
+ * The commit `HEAD` refers to, as a full SHA or, with `short`, git's abbreviation.
245
+ */
246
+ public head(options: { short?: boolean } = {}): Promise<string> {
247
+ return this.read(options.short ? ["rev-parse", "--short", "HEAD"] : ["rev-parse", "HEAD"])
248
+ }
249
+
250
+ /**
251
+ * The checked-out branch name, or `HEAD` when the tree is detached.
252
+ */
253
+ public currentBranch(): Promise<string> {
254
+ return this.read(["rev-parse", "--abbrev-ref", "HEAD"])
255
+ }
256
+
257
+ /**
258
+ * `git status --porcelain` lines, narrowed by pathspecs.
259
+ *
260
+ * Untracked files are included unless `untracked` is `false`.
261
+ */
262
+ public async status(pathspecs: readonly string[] = [], options: { untracked?: boolean } = {}): Promise<string[]> {
263
+ const scope = pathspecs.length ? ["--", ...pathspecs] : []
264
+ const untracked = options.untracked === false ? ["--untracked-files=no"] : []
265
+ const output = await this.read(["status", "--porcelain", ...untracked, ...scope], { trim: false })
266
+
267
+ // `trim: false` keeps the status column, whose first character is a space for an unstaged change.
268
+ return TextSpliterator.from(output, { trim: false })
269
+ .map((line) => line.trimEnd())
270
+ .filter((line) => line.length)
271
+ .toArray()
272
+ }
273
+
274
+ /**
275
+ * Run git and split its NUL-delimited stdout into the non-empty fields.
276
+ */
277
+ public async readNulDelimited(args: readonly string[]): Promise<string[]> {
278
+ const output = await this.read(args, { maxBuffer: LISTING_MAX_BUFFER })
279
+
280
+ return output.split("\0").filter((field) => field.length)
281
+ }
282
+
283
+ /**
284
+ * Run git and answer its stdout's non-empty lines.
285
+ */
286
+ public async readLines(args: readonly string[]): Promise<string[]> {
287
+ const output = await this.read(args, { maxBuffer: LISTING_MAX_BUFFER })
288
+
289
+ return TextSpliterator.from(output)
290
+ .map((line) => line.trimEnd())
291
+ .filter((line) => line.length)
292
+ .toArray()
293
+ }
294
+
295
+ /**
296
+ * Disposal stops every git process the client started and waits for each to exit.
297
+ * Repeated calls return the same promise.
298
+ */
299
+ public [Symbol.asyncDispose](): Promise<void> {
300
+ if (this.#disposePromise) return this.#disposePromise
301
+
302
+ this.#shutdown.abort(new Error(`git client for ${this.cwd} is disposed`))
303
+
304
+ this.#disposePromise = Promise.all([...this.#tasks].map((task) => task[Symbol.asyncDispose]())).then(
305
+ () => undefined
306
+ )
307
+
308
+ return this.#disposePromise
309
+ }
310
+ }
311
+
312
+ /**
313
+ * Options for {@linkcode gitSync}.
314
+ */
315
+ export interface GitSyncOptions {
316
+ cwd?: PathBuilderLike
317
+ env?: NodeJS.ProcessEnv
318
+ /**
319
+ * Whether to remove surrounding whitespace from stdout.
320
+ *
321
+ * @defaultValue `true`
322
+ */
323
+ trim?: boolean
324
+ }
325
+
326
+ /**
327
+ * Run git synchronously and answer stdout, for a slot whose caller is synchronous.
328
+ *
329
+ * Git's stderr is captured rather than written to the terminal.
330
+ * A non-zero exit throws the builtin's error, which carries that stderr.
331
+ */
332
+ export function gitSync(args: readonly string[], options: GitSyncOptions = {}): string {
333
+ const stdout = runFileSync("git", args, {
334
+ cwd: options.cwd ?? repoRootPathBuilder,
335
+ env: options.env,
336
+ stdio: "pipe",
337
+ maxBuffer: LISTING_MAX_BUFFER,
338
+ })
339
+
340
+ return options.trim === false ? stdout : stdout.trim()
341
+ }
17
342
 
18
343
  /**
19
344
  * Run a git command in the given repository.
@@ -25,11 +350,7 @@ export async function git(
25
350
  repoRoot: PathBuilderLike = repoRootPathBuilder,
26
351
  maxBuffer?: number
27
352
  ): Promise<string> {
28
- const argumentList = Array.isArray(args) ? args : [args]
29
-
30
- const { stdout } = await runFile("git", argumentList, { cwd: repoRoot, encoding: "utf8", maxBuffer })
31
-
32
- return stdout.trim()
353
+ return new GitClient({ cwd: repoRoot }).read(args, { maxBuffer })
33
354
  }
34
355
 
35
356
  /**
@@ -39,16 +360,14 @@ export async function gitHead(
39
360
  repoRoot: PathBuilderLike = repoRootPathBuilder,
40
361
  options: { short?: boolean } = {}
41
362
  ): Promise<string> {
42
- const args = options.short ? ["rev-parse", "--short", "HEAD"] : ["rev-parse", "HEAD"]
43
-
44
- return git(args, repoRoot)
363
+ return new GitClient({ cwd: repoRoot }).head(options)
45
364
  }
46
365
 
47
366
  /**
48
367
  * The checked-out branch name, or `head` when the tree is detached.
49
368
  */
50
369
  export async function currentBranch(repoRoot: PathBuilderLike = repoRootPathBuilder): Promise<string> {
51
- return git(["rev-parse", "--abbrev-ref", "HEAD"], repoRoot)
370
+ return new GitClient({ cwd: repoRoot }).currentBranch()
52
371
  }
53
372
 
54
373
  /**
@@ -79,13 +398,7 @@ export async function dirtyTrackedFiles(
79
398
  repoRoot: PathBuilderLike = repoRootPathBuilder,
80
399
  pathspecs: string[] = []
81
400
  ): Promise<string[]> {
82
- const scope = pathspecs.length ? ["--", ...pathspecs] : []
83
- const output = await git(["status", "--porcelain", "--untracked-files=no", ...scope], repoRoot)
84
-
85
- return TextSpliterator.from(output)
86
- .map((line) => line.trimEnd())
87
- .filter((line) => line.length)
88
- .toArray()
401
+ return new GitClient({ cwd: repoRoot }).status(pathspecs, { untracked: false })
89
402
  }
90
403
 
91
404
  /**
@@ -103,13 +416,7 @@ export async function workingTreeStatus(
103
416
  repoRoot: PathBuilderLike = repoRootPathBuilder,
104
417
  pathspecs: string[] = []
105
418
  ): Promise<string[]> {
106
- const scope = pathspecs.length ? ["--", ...pathspecs] : []
107
- const output = await git(["status", "--porcelain", ...scope], repoRoot)
108
-
109
- return TextSpliterator.from(output)
110
- .map((line) => line.trimEnd())
111
- .filter((line) => line.length)
112
- .toArray()
419
+ return new GitClient({ cwd: repoRoot }).status(pathspecs)
113
420
  }
114
421
 
115
422
  /**
@@ -124,9 +431,7 @@ export async function changedFiles(
124
431
  base: string,
125
432
  head: string
126
433
  ): Promise<string[]> {
127
- const output = await git(["diff", "--name-only", "-z", base, head], repoRoot, 64 * 1024 * 1024)
128
-
129
- return output.split("\0").filter((path) => path.length)
434
+ return new GitClient({ cwd: repoRoot }).readNulDelimited(["diff", "--name-only", "-z", base, head])
130
435
  }
131
436
 
132
437
  /**
@@ -139,7 +444,7 @@ export async function renamesSince(
139
444
  ref: string,
140
445
  repoRoot: PathBuilderLike = repoRootPathBuilder
141
446
  ): Promise<Array<{ from: string; to: string }>> {
142
- const fields = (await git(["diff", "--name-status", "-M", "-z", ref], repoRoot, 64 * 1024 * 1024)).split("\0")
447
+ const fields = (await git(["diff", "--name-status", "-M", "-z", ref], repoRoot, LISTING_MAX_BUFFER)).split("\0")
143
448
  const renames: Array<{ from: string; to: string }> = []
144
449
 
145
450
  for (let index = 0; index < fields.length;) {
@@ -165,9 +470,7 @@ export async function renamesSince(
165
470
  * Every path `ref` tracks, repo-relative, read NUL-delimited.
166
471
  */
167
472
  export async function filesAtRef(ref: string, repoRoot: PathBuilderLike = repoRootPathBuilder): Promise<string[]> {
168
- const output = await git(["ls-tree", "-r", "--name-only", "-z", ref], repoRoot, 64 * 1024 * 1024)
169
-
170
- return output.split("\0").filter((path) => path.length)
473
+ return new GitClient({ cwd: repoRoot }).readNulDelimited(["ls-tree", "-r", "--name-only", "-z", ref])
171
474
  }
172
475
 
173
476
  /**
@@ -180,9 +483,7 @@ export async function trackedFiles(
180
483
  repoRoot: PathBuilderLike = repoRootPathBuilder,
181
484
  pathspecs: string[] = []
182
485
  ): Promise<string[]> {
183
- const output = await git(["ls-files", "-z", ...pathspecs], repoRoot, 64 * 1024 * 1024)
184
-
185
- return output.split("\0").filter((path) => path.length)
486
+ return new GitClient({ cwd: repoRoot }).readNulDelimited(["ls-files", "-z", ...pathspecs])
186
487
  }
187
488
 
188
489
  /**
@@ -200,13 +501,14 @@ export async function workingTreeFiles(
200
501
  pathspecs: string[] = [],
201
502
  repoRoot: PathBuilderLike = repoRootPathBuilder
202
503
  ): Promise<string[]> {
203
- const output = await git(
204
- ["ls-files", "-z", "--cached", "--others", "--exclude-standard", ...pathspecs],
205
- repoRoot,
206
- 64 * 1024 * 1024
207
- )
208
-
209
- return output.split("\0").filter((path) => path.length)
504
+ return new GitClient({ cwd: repoRoot }).readNulDelimited([
505
+ "ls-files",
506
+ "-z",
507
+ "--cached",
508
+ "--others",
509
+ "--exclude-standard",
510
+ ...pathspecs,
511
+ ])
210
512
  }
211
513
 
212
514
  /**
@@ -229,14 +531,14 @@ export async function workingTreeFiles(
229
531
  * against 11,483 for the reading that answers the wrong set.
230
532
  */
231
533
  export async function movedAwayPaths(repoRoot: PathBuilderLike = repoRootPathBuilder): Promise<Set<string>> {
232
- const output = await git(
233
- ["log", "--all", "--no-renames", "--diff-filter=D", "--name-only", "--format="],
234
- repoRoot,
235
- 64 * 1024 * 1024
236
- )
237
-
238
- return TextSpliterator.from(output)
239
- .map((line) => line.trimEnd())
240
- .filter((line) => line.length)
241
- .toSet()
534
+ const lines = await new GitClient({ cwd: repoRoot }).readLines([
535
+ "log",
536
+ "--all",
537
+ "--no-renames",
538
+ "--diff-filter=D",
539
+ "--name-only",
540
+ "--format=",
541
+ ])
542
+
543
+ return new Set(lines)
242
544
  }
@@ -65,6 +65,22 @@ export interface LayerManifest {
65
65
  * A reader distinguishes that from a recorded zero and never reports the two the same way.
66
66
  */
67
67
  sourceRecords: Readonly<Record<string, number>> | null
68
+ /**
69
+ * The URL the build downloaded its input file from, such as a Geofabrik extract's address.
70
+ *
71
+ * `null` or absent means the build did not record it.
72
+ * A build whose input has a share-alike license records it, because the license's database-access
73
+ * terms are met by pointing a recipient at the exact input that produced the artifact.
74
+ */
75
+ sourceURL?: string | null
76
+ /**
77
+ * The SHA-256 of the build's input file as lowercase hex.
78
+ *
79
+ * `null` or absent means the build did not record it.
80
+ * With {@link LayerManifest.sourceURL} it identifies the bytes the artifact was built from,
81
+ * which the URL alone does not when the publisher replaces the file at the same address.
82
+ */
83
+ sourceSHA256?: string | null
68
84
  }
69
85
 
70
86
  export interface CoverageCell {
@@ -195,6 +211,8 @@ export function toLayerManifest(row: Record<string, string | number | null>): La
195
211
  createdAt: String(row.created_at),
196
212
  sourceRecords:
197
213
  row.source_records == null ? null : parseJSONStrict<Record<string, number>>(String(row.source_records)),
214
+ sourceURL: row.source_url == null ? null : String(row.source_url),
215
+ sourceSHA256: row.source_sha256 == null ? null : String(row.source_sha256),
198
216
  }
199
217
 
200
218
  assertManifestInvariants(manifest)
@@ -316,10 +334,19 @@ export function polygonLayerManifest(
316
334
 
317
335
  /**
318
336
  * Insert one validated manifest row.
337
+ *
338
+ * The input-file columns are written only when the manifest carries them.
339
+ * A row stamped into a `layer_manifest` table created before those columns existed then still inserts.
319
340
  */
320
341
  export async function writeLayerManifest(db: layerschemahandle, manifest: LayerManifest): Promise<void> {
321
342
  assertManifestInvariants(manifest)
322
343
 
344
+ if (manifest.sourceSHA256 && !/^[0-9a-f]{64}$/.test(manifest.sourceSHA256)) {
345
+ throw new Error(
346
+ `layer manifest: sourceSHA256 must be 64 lowercase hex characters, got ${stringifyJSON(manifest.sourceSHA256)}`
347
+ )
348
+ }
349
+
323
350
  await db
324
351
  .insertInto("layer_manifest")
325
352
  .values({
@@ -337,6 +364,8 @@ export async function writeLayerManifest(db: layerschemahandle, manifest: LayerM
337
364
  spine_keys: stringifyJSON(manifest.spineKeys),
338
365
  created_at: manifest.createdAt,
339
366
  source_records: manifest.sourceRecords ? stringifyJSON(manifest.sourceRecords) : null,
367
+ ...(manifest.sourceURL ? { source_url: manifest.sourceURL } : {}),
368
+ ...(manifest.sourceSHA256 ? { source_sha256: manifest.sourceSHA256 } : {}),
340
369
  })
341
370
  .execute()
342
371
  }
@@ -370,6 +399,8 @@ export async function readLayerManifest(db: layerschemahandle): Promise<LayerMan
370
399
  // NULL and a missing column both mean the build recorded no count.
371
400
  // An empty object would make the build appear to have counted its publishers and found none.
372
401
  sourceRecords: row.source_records ? parseJSONStrict<Record<string, number>>(row.source_records) : null,
402
+ sourceURL: row.source_url ?? null,
403
+ sourceSHA256: row.source_sha256 ?? null,
373
404
  }
374
405
 
375
406
  assertManifestInvariants(manifest)
@@ -93,6 +93,16 @@ export interface LayerManifestTable {
93
93
  * See `LayerManifest.sourceRecords` in `manifest.ts`.
94
94
  */
95
95
  source_records?: string | null
96
+ /**
97
+ * The URL the build's input file was downloaded from, or NULL when the build did not record it.
98
+ * See `LayerManifest.sourceURL` in `manifest.ts`.
99
+ */
100
+ source_url?: string | null
101
+ /**
102
+ * The SHA-256 of the build's input file as lowercase hex, or NULL when the build did not record it.
103
+ * See `LayerManifest.sourceSHA256` in `manifest.ts`.
104
+ */
105
+ source_sha256?: string | null
96
106
  }
97
107
 
98
108
  /**
@@ -201,6 +211,10 @@ export async function createLayerManifestTable(db: layerschemahandle): Promise<v
201
211
  // Those artifacts read NULL, and `readLayerManifest` returns `sourceRecords: null`.
202
212
  // A build that counted records and found no publishers writes `{}`.
203
213
  .addColumn("source_records", "text")
214
+ // Nullable for the same reason: artifacts built before these columns read NULL, which states
215
+ // that the input file was not recorded rather than that it had no URL or digest.
216
+ .addColumn("source_url", "text")
217
+ .addColumn("source_sha256", "text")
204
218
  .execute()
205
219
  }
206
220
 
@@ -4,7 +4,7 @@
4
4
  * @author Teffen Ellis, et al.
5
5
  *
6
6
  * Where the docs site lives, for every URL the license posture points at: the well-known key register and the
7
- * `/license` page. One derivation, so a configured `MAILWOMAN_DOCS_URL` moves both together.
7
+ * `/license` page. One derivation serves both, so a configured `MAILWOMAN_DOCS_URL` moves them together.
8
8
  */
9
9
 
10
10
  import { $public } from "#env"
@@ -124,6 +124,7 @@ export async function checkCompiledFreshness(
124
124
  workspaces: readonly string[]
125
125
  ): Promise<CompiledFreshness> {
126
126
  let newestSource: TimestampedFile | null = null
127
+ let newestSourceWorkspace: string | null = null
127
128
  let newestCompiled: TimestampedFile | null = null
128
129
 
129
130
  const root = PathBuilder.from(repoRoot)
@@ -142,6 +143,7 @@ export async function checkCompiledFreshness(
142
143
 
143
144
  if (source && (!newestSource || source.mtimeMs > newestSource.mtimeMs)) {
144
145
  newestSource = source
146
+ newestSourceWorkspace = workspace
145
147
  }
146
148
 
147
149
  if (compiled && (!newestCompiled || compiled.mtimeMs > newestCompiled.mtimeMs)) {
@@ -167,7 +169,9 @@ export async function checkCompiledFreshness(
167
169
  newestCompiled,
168
170
  reason:
169
171
  `Compiled output is ${driftSeconds}s older than source: ${newestSource.path} was modified after ` +
170
- `${newestCompiled.path}. Run \`yarn compile\` and re-run.`,
172
+ `${newestCompiled.path}. Run \`yarn compile\` and re-run. When the source reverted to content ` +
173
+ `that is already compiled, \`tsc -b\` skips the emit and the output stays stale, so run ` +
174
+ `\`yarn tsc -b ${newestSourceWorkspace} --force\` instead.`,
171
175
  }
172
176
  }
173
177