@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.
- package/lib/api/ckan.ts +1 -1
- package/lib/decoder/serialize/json.ts +1 -1
- package/lib/env/env-file.ts +71 -0
- package/lib/env.ts +15 -9
- package/lib/fs/readers/stat.ts +16 -1
- package/lib/fs/readers.ts +15 -0
- package/lib/geocode/result.ts +46 -0
- package/lib/git.ts +357 -55
- package/lib/layers/manifest.ts +31 -0
- package/lib/layers/schema.ts +14 -0
- package/lib/license/docs-site.ts +1 -1
- package/lib/module/compiled-freshness.ts +5 -1
- package/lib/process.ts +320 -0
- package/lib/resources/git.ts +9 -5
- package/lib/types/classifier.ts +1 -1
- package/lib/utils/events.ts +23 -0
- package/out/api/ckan.d.ts +1 -1
- package/out/decoder/serialize/json.js +1 -1
- package/out/env/env-file.d.ts +26 -0
- package/out/env/env-file.d.ts.map +1 -0
- package/out/env/env-file.js +60 -0
- package/out/env/env-file.js.map +1 -0
- package/out/env.d.ts.map +1 -1
- package/out/env.js +15 -10
- package/out/env.js.map +1 -1
- package/out/fs/readers/stat.d.ts +9 -1
- package/out/fs/readers/stat.d.ts.map +1 -1
- package/out/fs/readers/stat.js +16 -0
- package/out/fs/readers/stat.js.map +1 -1
- package/out/fs/readers.d.ts +11 -0
- package/out/fs/readers.d.ts.map +1 -1
- package/out/fs/readers.js +14 -0
- package/out/fs/readers.js.map +1 -1
- package/out/geocode/result.d.ts +25 -0
- package/out/geocode/result.d.ts.map +1 -1
- package/out/geocode/result.js +40 -0
- package/out/geocode/result.js.map +1 -1
- package/out/git.d.ts +180 -4
- package/out/git.d.ts.map +1 -1
- package/out/git.js +227 -37
- package/out/git.js.map +1 -1
- package/out/layers/manifest.d.ts +19 -0
- package/out/layers/manifest.d.ts.map +1 -1
- package/out/layers/manifest.js +12 -0
- package/out/layers/manifest.js.map +1 -1
- package/out/layers/schema.d.ts +10 -0
- package/out/layers/schema.d.ts.map +1 -1
- package/out/layers/schema.js +4 -0
- package/out/layers/schema.js.map +1 -1
- package/out/license/docs-site.d.ts +1 -1
- package/out/license/docs-site.js +1 -1
- package/out/module/compiled-freshness.d.ts.map +1 -1
- package/out/module/compiled-freshness.js +5 -1
- package/out/module/compiled-freshness.js.map +1 -1
- package/out/process.d.ts +146 -0
- package/out/process.d.ts.map +1 -1
- package/out/process.js +158 -0
- package/out/process.js.map +1 -1
- package/out/resources/git.d.ts +5 -1
- package/out/resources/git.d.ts.map +1 -1
- package/out/resources/git.js +8 -5
- package/out/resources/git.js.map +1 -1
- package/out/tools/coarse-placer/paths.d.ts +2 -2
- package/out/tools/coarse-placer/paths.js +2 -2
- package/out/tools/download/libpostal-resources.d.ts +2 -2
- package/out/tools/download/libpostal-resources.d.ts.map +1 -1
- package/out/tools/download/libpostal-resources.js +4 -4
- package/out/tools/download/libpostal-resources.js.map +1 -1
- package/out/types/classifier.d.ts +1 -1
- package/out/utils/events.d.ts +13 -0
- package/out/utils/events.d.ts.map +1 -1
- package/out/utils/events.js +19 -0
- package/out/utils/events.js.map +1 -1
- package/package.json +7 -7
- package/tools/coarse-placer/paths.ts +2 -2
- package/tools/download/libpostal-resources.ts +4 -4
package/lib/process.ts
CHANGED
|
@@ -34,6 +34,9 @@ import { promisify } from "node:util"
|
|
|
34
34
|
|
|
35
35
|
import type { PathBuilderLike } from "path-ts"
|
|
36
36
|
|
|
37
|
+
import type { IRuntimeLogger } from "#logging"
|
|
38
|
+
import { TypedEventTarget } from "#utils/events"
|
|
39
|
+
|
|
37
40
|
export type {
|
|
38
41
|
ChildProcess,
|
|
39
42
|
ChildProcessByStdio,
|
|
@@ -219,6 +222,323 @@ export function spawnProcessSync(
|
|
|
219
222
|
)
|
|
220
223
|
}
|
|
221
224
|
|
|
225
|
+
/**
|
|
226
|
+
* One step of a long-running command's progress, as a {@linkcode ProgressParser}
|
|
227
|
+
* reads it from a line of output.
|
|
228
|
+
*/
|
|
229
|
+
export interface ProcessProgress {
|
|
230
|
+
/**
|
|
231
|
+
* The phase the command reports, such as git's `Receiving objects`.
|
|
232
|
+
*/
|
|
233
|
+
stage: string
|
|
234
|
+
/**
|
|
235
|
+
* Completion of the stage, from 0 to 100, when the command states it.
|
|
236
|
+
*/
|
|
237
|
+
percent?: number
|
|
238
|
+
processed?: number
|
|
239
|
+
total?: number
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Reads one line of a command's stderr and answers the progress it reports, or `null` for any other line.
|
|
244
|
+
*/
|
|
245
|
+
export type ProgressParser = (line: string) => ProcessProgress | null
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* How a {@linkcode ProcessTask} ended.
|
|
249
|
+
*
|
|
250
|
+
* `exitCode` is `null` when a signal ended the process, and `signal` is `null` when it exited on its own.
|
|
251
|
+
*/
|
|
252
|
+
export interface ProcessResult extends ProcessOutput {
|
|
253
|
+
command: string
|
|
254
|
+
exitCode: number | null
|
|
255
|
+
signal: NodeJS.Signals | null
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* The stream a line of output arrived on.
|
|
260
|
+
*/
|
|
261
|
+
export const OutputStream = {
|
|
262
|
+
Stdout: "stdout",
|
|
263
|
+
Stderr: "stderr",
|
|
264
|
+
} as const
|
|
265
|
+
|
|
266
|
+
export type OutputStream = (typeof OutputStream)[keyof typeof OutputStream]
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* The events a {@linkcode ProcessTask} dispatches, keyed by type, with each event's `detail`.
|
|
270
|
+
*/
|
|
271
|
+
export interface ProcessTaskEventMap {
|
|
272
|
+
/**
|
|
273
|
+
* One line of piped output.
|
|
274
|
+
*
|
|
275
|
+
* A carriage return ends a line as a newline does, so each redraw of a progress meter arrives separately.
|
|
276
|
+
*/
|
|
277
|
+
line: { stream: OutputStream; text: string }
|
|
278
|
+
progress: ProcessProgress
|
|
279
|
+
exit: ProcessResult
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Options for {@linkcode ProcessTask}.
|
|
284
|
+
*/
|
|
285
|
+
export interface ProcessTaskOptions extends Omit<SpawnOptions, "cwd" | "stdio" | "signal"> {
|
|
286
|
+
cwd?: PathBuilderLike
|
|
287
|
+
/**
|
|
288
|
+
* Aborting the signal stops the process as disposal does.
|
|
289
|
+
*/
|
|
290
|
+
signal?: AbortSignal
|
|
291
|
+
/**
|
|
292
|
+
* Receives the command line at debug level when the process starts and the result when it ends.
|
|
293
|
+
*/
|
|
294
|
+
logger?: IRuntimeLogger
|
|
295
|
+
/**
|
|
296
|
+
* Whether a non-zero exit or a terminating signal rejects `result` with a {@linkcode ProcessError}.
|
|
297
|
+
*
|
|
298
|
+
* With `false`, `result` resolves with the {@linkcode ProcessResult}, and the caller reads `exitCode`.
|
|
299
|
+
*
|
|
300
|
+
* A command that could not start always rejects with the spawn error.
|
|
301
|
+
*
|
|
302
|
+
* @defaultValue `true`
|
|
303
|
+
*/
|
|
304
|
+
reject?: boolean
|
|
305
|
+
/**
|
|
306
|
+
* `"pipe"` captures a stream and dispatches its lines.
|
|
307
|
+
* `"inherit"` writes it to this process's terminal.
|
|
308
|
+
*
|
|
309
|
+
* @defaultValue `"ignore"` for stdin, `"pipe"` for stdout and stderr
|
|
310
|
+
*/
|
|
311
|
+
stdin?: "ignore" | "inherit" | "pipe"
|
|
312
|
+
stdout?: "ignore" | "inherit" | "pipe"
|
|
313
|
+
stderr?: "ignore" | "inherit" | "pipe"
|
|
314
|
+
/**
|
|
315
|
+
* Leave a piped stdout unread, so the caller consumes `child.stdout` as bytes,
|
|
316
|
+
* such as an archive piped into another process.
|
|
317
|
+
*
|
|
318
|
+
* The task then dispatches no stdout lines, and `result.stdout` is empty.
|
|
319
|
+
*/
|
|
320
|
+
rawStdout?: boolean
|
|
321
|
+
/**
|
|
322
|
+
* Reads each stderr line for progress and dispatches a `progress` event for each match.
|
|
323
|
+
*/
|
|
324
|
+
progress?: ProgressParser
|
|
325
|
+
/**
|
|
326
|
+
* How long disposal waits after SIGTERM before it sends SIGKILL.
|
|
327
|
+
*
|
|
328
|
+
* @defaultValue 5000
|
|
329
|
+
*/
|
|
330
|
+
killGraceMs?: number
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
const DEFAULT_KILL_GRACE_MS = 5000
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* A running command that reports its output as events, settles `result` with its
|
|
337
|
+
* {@linkcode ProcessResult}, and is stopped by disposal.
|
|
338
|
+
*
|
|
339
|
+
* It follows the shape of `APIClient`: an `EventTarget` that owns its work
|
|
340
|
+
* and implements `AsyncDisposable`.
|
|
341
|
+
* A caller renders the `line` and `progress` events while the command runs.
|
|
342
|
+
*
|
|
343
|
+
* `await using` stops the command when the caller's scope ends early.
|
|
344
|
+
*
|
|
345
|
+
* Reach for {@linkcode runFile} when the caller needs only the finished output.
|
|
346
|
+
*/
|
|
347
|
+
export class ProcessTask extends TypedEventTarget<ProcessTaskEventMap> implements AsyncDisposable {
|
|
348
|
+
public readonly command: string
|
|
349
|
+
public readonly child: ChildProcess
|
|
350
|
+
/**
|
|
351
|
+
* Settles once the process has exited and both streams have closed.
|
|
352
|
+
*/
|
|
353
|
+
public readonly result: Promise<ProcessResult>
|
|
354
|
+
|
|
355
|
+
readonly #exited: Promise<void>
|
|
356
|
+
readonly #killGraceMs: number
|
|
357
|
+
readonly #signal: AbortSignal | undefined
|
|
358
|
+
readonly #onAbort = (): void => {
|
|
359
|
+
void this[Symbol.asyncDispose]()
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
#disposePromise: Promise<void> | null = null
|
|
363
|
+
|
|
364
|
+
constructor(file: PathBuilderLike, args: readonly PathBuilderLike[] = [], options: ProcessTaskOptions = {}) {
|
|
365
|
+
super()
|
|
366
|
+
|
|
367
|
+
const {
|
|
368
|
+
cwd,
|
|
369
|
+
signal,
|
|
370
|
+
logger,
|
|
371
|
+
reject = true,
|
|
372
|
+
stdin = "ignore",
|
|
373
|
+
stdout = "pipe",
|
|
374
|
+
stderr = "pipe",
|
|
375
|
+
progress,
|
|
376
|
+
rawStdout = false,
|
|
377
|
+
killGraceMs = DEFAULT_KILL_GRACE_MS,
|
|
378
|
+
...spawnOptions
|
|
379
|
+
} = options
|
|
380
|
+
|
|
381
|
+
const argStrings = args.map((arg) => arg.toString())
|
|
382
|
+
|
|
383
|
+
this.command = [file.toString(), ...argStrings].join(" ")
|
|
384
|
+
this.#killGraceMs = killGraceMs
|
|
385
|
+
this.#signal = signal
|
|
386
|
+
|
|
387
|
+
signal?.throwIfAborted()
|
|
388
|
+
|
|
389
|
+
logger?.debug(`$ ${this.command}`)
|
|
390
|
+
|
|
391
|
+
this.child = spawn(file.toString(), argStrings, {
|
|
392
|
+
...spawnOptions,
|
|
393
|
+
cwd: cwd?.toString(),
|
|
394
|
+
stdio: [stdin, stdout, stderr],
|
|
395
|
+
})
|
|
396
|
+
|
|
397
|
+
const captured: Record<OutputStream, string[]> = { stdout: [], stderr: [] }
|
|
398
|
+
|
|
399
|
+
const readLines = (stream: OutputStream, readable: Readable | null): void => {
|
|
400
|
+
if (!readable) return
|
|
401
|
+
|
|
402
|
+
let pending = ""
|
|
403
|
+
|
|
404
|
+
const emit = (text: string): void => {
|
|
405
|
+
captured[stream].push(text)
|
|
406
|
+
this.emit("line", { stream, text })
|
|
407
|
+
|
|
408
|
+
if (stream === OutputStream.Stderr && progress) {
|
|
409
|
+
const step = progress(text)
|
|
410
|
+
|
|
411
|
+
if (step) {
|
|
412
|
+
this.emit("progress", step)
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
readable.setEncoding("utf8")
|
|
418
|
+
|
|
419
|
+
readable.on("data", (chunk: string) => {
|
|
420
|
+
const pieces = (pending + chunk).split(/\r\n|\r|\n/u)
|
|
421
|
+
|
|
422
|
+
pending = pieces.pop() ?? ""
|
|
423
|
+
|
|
424
|
+
for (const piece of pieces) {
|
|
425
|
+
emit(piece)
|
|
426
|
+
}
|
|
427
|
+
})
|
|
428
|
+
|
|
429
|
+
readable.on("end", () => {
|
|
430
|
+
if (pending) {
|
|
431
|
+
emit(pending)
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
pending = ""
|
|
435
|
+
})
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
readLines(OutputStream.Stdout, rawStdout ? null : this.child.stdout)
|
|
439
|
+
readLines(OutputStream.Stderr, this.child.stderr)
|
|
440
|
+
|
|
441
|
+
this.#exited = new Promise<void>((resolve) => {
|
|
442
|
+
this.child.once("close", () => resolve())
|
|
443
|
+
// A process that never started emits `error` and no `close`.
|
|
444
|
+
this.child.once("error", () => resolve())
|
|
445
|
+
})
|
|
446
|
+
|
|
447
|
+
this.result = new Promise<ProcessResult>((resolve, rejectCompletion) => {
|
|
448
|
+
this.child.once("error", rejectCompletion)
|
|
449
|
+
|
|
450
|
+
this.child.once("close", (exitCode: number | null, exitSignal: NodeJS.Signals | null) => {
|
|
451
|
+
const result: ProcessResult = {
|
|
452
|
+
command: this.command,
|
|
453
|
+
exitCode,
|
|
454
|
+
signal: exitSignal,
|
|
455
|
+
stdout: captured.stdout.join("\n"),
|
|
456
|
+
stderr: captured.stderr.join("\n"),
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
logger?.debug(`${this.command} exited with ${exitSignal ?? exitCode}`)
|
|
460
|
+
this.emit("exit", result)
|
|
461
|
+
|
|
462
|
+
if (reject && exitCode !== 0) {
|
|
463
|
+
const error = new Error(
|
|
464
|
+
`Command failed with ${exitSignal ? `signal ${exitSignal}` : `exit code ${exitCode}`}: ${this.command}`
|
|
465
|
+
) as ProcessError
|
|
466
|
+
|
|
467
|
+
error.stdout = result.stdout
|
|
468
|
+
error.stderr = result.stderr
|
|
469
|
+
error.code = exitCode ?? undefined
|
|
470
|
+
error.signal = exitSignal ?? undefined
|
|
471
|
+
|
|
472
|
+
rejectCompletion(error)
|
|
473
|
+
|
|
474
|
+
return
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
resolve(result)
|
|
478
|
+
})
|
|
479
|
+
}).finally(() => {
|
|
480
|
+
this.#signal?.removeEventListener("abort", this.#onAbort)
|
|
481
|
+
})
|
|
482
|
+
|
|
483
|
+
// A task that is only disposed, never awaited, must not raise an unhandled rejection.
|
|
484
|
+
// Awaiting callers still receive the rejection through `result`.
|
|
485
|
+
this.result.catch(() => undefined)
|
|
486
|
+
|
|
487
|
+
signal?.addEventListener("abort", this.#onAbort, { once: true })
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Disposal sends SIGTERM to a running process, sends SIGKILL if it has not exited
|
|
492
|
+
* after `killGraceMs`, and resolves once it has exited.
|
|
493
|
+
* A process that already exited is left alone.
|
|
494
|
+
*
|
|
495
|
+
* Disposal never rejects.
|
|
496
|
+
* The `result` promise still reports how the process ended.
|
|
497
|
+
* Repeated calls return the same promise.
|
|
498
|
+
*/
|
|
499
|
+
public [Symbol.asyncDispose](): Promise<void> {
|
|
500
|
+
if (this.#disposePromise) return this.#disposePromise
|
|
501
|
+
|
|
502
|
+
this.#disposePromise = this.#stop()
|
|
503
|
+
|
|
504
|
+
return this.#disposePromise
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
async #stop(): Promise<void> {
|
|
508
|
+
const { child } = this
|
|
509
|
+
|
|
510
|
+
if (child.exitCode === null && child.signalCode === null && child.pid !== undefined) {
|
|
511
|
+
child.kill("SIGTERM")
|
|
512
|
+
|
|
513
|
+
const escalation = setTimeout(() => child.kill("SIGKILL"), this.#killGraceMs)
|
|
514
|
+
|
|
515
|
+
escalation.unref()
|
|
516
|
+
await this.#exited
|
|
517
|
+
clearTimeout(escalation)
|
|
518
|
+
} else {
|
|
519
|
+
await this.#exited
|
|
520
|
+
}
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
public override toString(): string {
|
|
524
|
+
return this.command
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* Run a command to completion as a {@linkcode ProcessTask} and answer its {@linkcode ProcessResult}.
|
|
530
|
+
*
|
|
531
|
+
* With `reject: false` a non-zero exit resolves, and the caller reads `exitCode`.
|
|
532
|
+
* Reach for the task itself when the caller renders its lines or progress while it runs.
|
|
533
|
+
*/
|
|
534
|
+
export function runProcess(
|
|
535
|
+
file: PathBuilderLike,
|
|
536
|
+
args: readonly PathBuilderLike[] = [],
|
|
537
|
+
options: ProcessTaskOptions = {}
|
|
538
|
+
): Promise<ProcessResult> {
|
|
539
|
+
return new ProcessTask(file, args, options).result
|
|
540
|
+
}
|
|
541
|
+
|
|
222
542
|
/**
|
|
223
543
|
* Options for {@linkcode forkProcess}.
|
|
224
544
|
*/
|
package/lib/resources/git.ts
CHANGED
|
@@ -8,7 +8,7 @@ import { PathBuilder, type PathBuilderLike } from "path-ts"
|
|
|
8
8
|
|
|
9
9
|
import { tryStat } from "#fs/readers/stat"
|
|
10
10
|
import { makeDirectories } from "#fs/writers"
|
|
11
|
-
import {
|
|
11
|
+
import { GitClient } from "#git"
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Metadata for a repository source.
|
|
@@ -44,22 +44,26 @@ export type SynchronizeAction = "cloned" | "pulled" | "skipped"
|
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Synchronize a repository source, i.e. clone or pull the repository.
|
|
47
|
+
*
|
|
48
|
+
* The transfer runs through `client`, so a caller that watches the client's `progress`
|
|
49
|
+
* events sees the clone or pull advance, and disposing the client stops it.
|
|
47
50
|
*/
|
|
48
51
|
export async function synchronizeRepo(
|
|
49
52
|
source: RepositorySource,
|
|
50
|
-
localRepoDirectory: PathBuilderLike
|
|
53
|
+
localRepoDirectory: PathBuilderLike,
|
|
54
|
+
client: GitClient = new GitClient({ cwd: localRepoDirectory })
|
|
51
55
|
): Promise<SynchronizeAction> {
|
|
52
56
|
if (source.name.includes("deprecated")) return "skipped"
|
|
53
57
|
|
|
54
|
-
const {
|
|
58
|
+
const { repoDirectory, exists } = await prepareRepositoryDirectories(source, localRepoDirectory)
|
|
55
59
|
|
|
56
60
|
if (exists) {
|
|
57
|
-
await
|
|
61
|
+
await client.start(["-C", repoDirectory.toString(), "pull", "--progress"]).result
|
|
58
62
|
|
|
59
63
|
return "pulled"
|
|
60
64
|
}
|
|
61
65
|
|
|
62
|
-
await
|
|
66
|
+
await client.clone(source.url, repoDirectory, { depth: 1 })
|
|
63
67
|
|
|
64
68
|
return "cloned"
|
|
65
69
|
}
|
package/lib/types/classifier.ts
CHANGED
|
@@ -36,7 +36,7 @@ export type Section = Span
|
|
|
36
36
|
export type ClassificationProposalSource = "neural" | "merged"
|
|
37
37
|
|
|
38
38
|
/**
|
|
39
|
-
* A typed classification candidate
|
|
39
|
+
* A classifier produces this typed classification candidate.
|
|
40
40
|
*
|
|
41
41
|
* `source` and `source_id` identify the origin of each proposal without external state.
|
|
42
42
|
*/
|
package/lib/utils/events.ts
CHANGED
|
@@ -9,3 +9,26 @@
|
|
|
9
9
|
* `await once(child, "exit")` — rejecting on its `error`.
|
|
10
10
|
*/
|
|
11
11
|
export { once } from "node:events"
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* An `EventTarget` whose events hold a typed `detail`, keyed by type in `EventMap`.
|
|
15
|
+
*
|
|
16
|
+
* Subclasses dispatch with `emit`, and listeners subscribe with `on`.
|
|
17
|
+
* The base `addEventListener` still works for a caller that wants the `CustomEvent` itself.
|
|
18
|
+
*/
|
|
19
|
+
export class TypedEventTarget<EventMap extends object> extends EventTarget {
|
|
20
|
+
/**
|
|
21
|
+
* Listen for one event type with its typed `detail`, answering a function that removes the listener.
|
|
22
|
+
*/
|
|
23
|
+
public on<K extends keyof EventMap & string>(type: K, listener: (detail: EventMap[K]) => void): () => void {
|
|
24
|
+
const handler = (event: Event): void => listener((event as CustomEvent<EventMap[K]>).detail)
|
|
25
|
+
|
|
26
|
+
this.addEventListener(type, handler)
|
|
27
|
+
|
|
28
|
+
return () => this.removeEventListener(type, handler)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected emit<K extends keyof EventMap & string>(type: K, detail: EventMap[K]): void {
|
|
32
|
+
this.dispatchEvent(new CustomEvent(type, { detail }))
|
|
33
|
+
}
|
|
34
|
+
}
|
package/out/api/ckan.d.ts
CHANGED
|
@@ -30,7 +30,7 @@ import { unknownSpans } from "#decoder/unknown-spans";
|
|
|
30
30
|
*/
|
|
31
31
|
export const DroppedSpanSchema = z.object({
|
|
32
32
|
/**
|
|
33
|
-
* The tag
|
|
33
|
+
* The tag the span holds.
|
|
34
34
|
*
|
|
35
35
|
* It is always one already present in the output, because a drop happens only when the slot was taken.
|
|
36
36
|
*/
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The `.env` file a process started in `workingDirectory` reads, or `null` when there is none.
|
|
8
|
+
*
|
|
9
|
+
* `process.loadEnvFile` reads the working directory's own `.env`.
|
|
10
|
+
* A git worktree has none, because the file is untracked and sits in the main checkout,
|
|
11
|
+
* so repository code run from a worktree would read the platform-default data root
|
|
12
|
+
* while the operator's data root is one `.git` pointer away.
|
|
13
|
+
*
|
|
14
|
+
* This resolves the file the way git resolves its common directory.
|
|
15
|
+
* A `.git` file in the working tree holds the path of the worktree's git directory.
|
|
16
|
+
*
|
|
17
|
+
* That directory's `commondir` file holds the path of the shared git directory.
|
|
18
|
+
* The main checkout is the shared directory's parent.
|
|
19
|
+
*
|
|
20
|
+
* A `.env` beside the working directory wins over the main checkout's, so a worktree can carry its own.
|
|
21
|
+
*
|
|
22
|
+
* The reads are synchronous because the env module folds the file into `process.env`
|
|
23
|
+
* at import time, ahead of any `await`.
|
|
24
|
+
*/
|
|
25
|
+
export declare function resolveEnvFile(workingDirectory?: string): string | null;
|
|
26
|
+
//# sourceMappingURL=env-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-file.d.ts","sourceRoot":"","sources":["../../lib/env/env-file.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,cAAc,CAAC,gBAAgB,GAAE,MAAsB,GAAG,MAAM,GAAG,IAAI,CAYtF"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright Sister Software
|
|
3
|
+
* @license AGPL-3.0
|
|
4
|
+
* @author Teffen Ellis, et al.
|
|
5
|
+
*/
|
|
6
|
+
import { dirname, resolvePath } from "path-ts";
|
|
7
|
+
import { readLocalTextFileSync } from "#fs/readers";
|
|
8
|
+
import { isFileSync } from "#fs/readers/stat";
|
|
9
|
+
/**
|
|
10
|
+
* The `.env` file a process started in `workingDirectory` reads, or `null` when there is none.
|
|
11
|
+
*
|
|
12
|
+
* `process.loadEnvFile` reads the working directory's own `.env`.
|
|
13
|
+
* A git worktree has none, because the file is untracked and sits in the main checkout,
|
|
14
|
+
* so repository code run from a worktree would read the platform-default data root
|
|
15
|
+
* while the operator's data root is one `.git` pointer away.
|
|
16
|
+
*
|
|
17
|
+
* This resolves the file the way git resolves its common directory.
|
|
18
|
+
* A `.git` file in the working tree holds the path of the worktree's git directory.
|
|
19
|
+
*
|
|
20
|
+
* That directory's `commondir` file holds the path of the shared git directory.
|
|
21
|
+
* The main checkout is the shared directory's parent.
|
|
22
|
+
*
|
|
23
|
+
* A `.env` beside the working directory wins over the main checkout's, so a worktree can carry its own.
|
|
24
|
+
*
|
|
25
|
+
* The reads are synchronous because the env module folds the file into `process.env`
|
|
26
|
+
* at import time, ahead of any `await`.
|
|
27
|
+
*/
|
|
28
|
+
export function resolveEnvFile(workingDirectory = process.cwd()) {
|
|
29
|
+
const local = resolvePath(workingDirectory, ".env");
|
|
30
|
+
if (isFileSync(local))
|
|
31
|
+
return local;
|
|
32
|
+
const mainCheckout = mainCheckoutOf(workingDirectory);
|
|
33
|
+
if (!mainCheckout)
|
|
34
|
+
return null;
|
|
35
|
+
const shared = resolvePath(mainCheckout, ".env");
|
|
36
|
+
return isFileSync(shared) ? shared : null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* The line of a worktree's `.git` file that holds its git directory.
|
|
40
|
+
*/
|
|
41
|
+
const GIT_DIRECTORY_LINE = /^gitdir:[\t ]*(.+?)[\t ]*$/mu;
|
|
42
|
+
/**
|
|
43
|
+
* The main checkout of the repository whose worktree is `workingDirectory`,
|
|
44
|
+
* or `null` when the directory is not a worktree's root.
|
|
45
|
+
*/
|
|
46
|
+
function mainCheckoutOf(workingDirectory) {
|
|
47
|
+
const pointer = resolvePath(workingDirectory, ".git");
|
|
48
|
+
if (!isFileSync(pointer))
|
|
49
|
+
return null;
|
|
50
|
+
const gitDirectoryLine = GIT_DIRECTORY_LINE.exec(readLocalTextFileSync(pointer));
|
|
51
|
+
if (!gitDirectoryLine)
|
|
52
|
+
return null;
|
|
53
|
+
const gitDirectory = resolvePath(workingDirectory, gitDirectoryLine[1]);
|
|
54
|
+
const commonDirectoryPath = resolvePath(gitDirectory, "commondir");
|
|
55
|
+
if (!isFileSync(commonDirectoryPath))
|
|
56
|
+
return null;
|
|
57
|
+
const commonDirectory = resolvePath(gitDirectory, readLocalTextFileSync(commonDirectoryPath).trim());
|
|
58
|
+
return dirname(commonDirectory);
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=env-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-file.js","sourceRoot":"","sources":["../../lib/env/env-file.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAE9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,M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AC,CAAA;IAEpG,OAAO,OAAO,CAAC,eAAe,CAAC,CAAA;AAChC,CAAC"}
|
package/out/env.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../lib/env.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../lib/env.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAKxB,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AA2BlD;;;;;;;;;;;;GAYG;AACH,wBAAgB,OAAO,CAAC,KAAK,SAAS,CAAC,CAAC,WAAW,EAAE,IAAI,SAAS,MAAM,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAC9F,MAAM,EAAE,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,EAC1B,IAAI,CAAC,EAAE,IAAI,GACT,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAgCpC;AAED;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,OAAO;;;;;;;;;CAA2B,CAAA;AAE/C;;;;;;;;;;GAUG;AACH,eAAO,MAAM,QAAQ,8CAA4B,CAAA"}
|
package/out/env.js
CHANGED
|
@@ -3,27 +3,32 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @author Teffen Ellis, et al.
|
|
5
5
|
*/
|
|
6
|
+
import { resolveEnvFile } from "#env/env-file";
|
|
6
7
|
import { PrivateEnvSchema, PublicEnvSchema } from "#env/schema";
|
|
7
8
|
export { DefaultMailwomanPaths } from "#env/paths";
|
|
8
9
|
/**
|
|
9
10
|
* The `.env` layer, folded into `process.env` when this module is evaluated — process-startup semantics.
|
|
10
11
|
*
|
|
11
12
|
* `process.loadEnvFile` is the runtime's own reader: synchronous, so the views below can expose
|
|
12
|
-
* synchronous getters without a top-level `await` (which the Docusaurus config loader cannot evaluate)
|
|
13
|
-
*
|
|
13
|
+
* synchronous getters without a top-level `await` (which the Docusaurus config loader cannot evaluate).
|
|
14
|
+
* `resolveEnvFile` picks the working directory's `.env`, or the main checkout's
|
|
15
|
+
* when the working directory is a git worktree, which carries no `.env` of its own.
|
|
16
|
+
*
|
|
14
17
|
* A variable already in `process.env` wins over the file.
|
|
15
18
|
* The views have always used this precedence.
|
|
16
19
|
*
|
|
17
20
|
* An absent `.env` is the common case and is not an error.
|
|
18
21
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
22
|
+
const envFile = resolveEnvFile();
|
|
23
|
+
if (envFile) {
|
|
24
|
+
try {
|
|
25
|
+
// oxlint-disable-next-line sister-software/no-process-globals -- this module is the typed process.env boundary
|
|
26
|
+
process.loadEnvFile(envFile);
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// The file exists and the runtime could not read it.
|
|
30
|
+
// The process environment comes from `process.env` only.
|
|
31
|
+
}
|
|
27
32
|
}
|
|
28
33
|
/**
|
|
29
34
|
* Create a live environment view, optionally extending another view without evaluating its getters.
|
package/out/env.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.js","sourceRoot":"","sources":["../lib/env.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAE/D,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAElD
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../lib/env.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAC9C,OAAO,EAAE,g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GAAG,IAAI,IAAI,CAAC,KAAK,QAAQ,EAAE,CAAC;oBAC3C,MAAM,GAAG,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,CAAA;oBAC9C,QAAQ,GAAG,GAAG,IAAI,IAAI,CAAA;gBACvB,CAAC;gBAED,IAAI,CAAC,MAAM,CAAC,OAAO;oBAAE,MAAM,MAAM,CAAC,KAAK,CAAA;gBAEvC,OAAO,MAAM,CAAC,IAAI,CAAC,GAA+B,CAAC,CAAA;YACpD,CAAC;SACD,CAAC,CAAA;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACZ,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;AAE/C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAA"}
|
package/out/fs/readers/stat.d.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @license AGPL-3.0
|
|
4
4
|
* @file Filesystem metadata readers.
|
|
5
5
|
*/
|
|
6
|
-
import type
|
|
6
|
+
import { type Dirent, type Mode, type Stats } from "node:fs";
|
|
7
7
|
import { type FileHandle } from "node:fs/promises";
|
|
8
8
|
import { type PathBuilderLike } from "path-ts";
|
|
9
9
|
import { type ByteFormatterOptions } from "#fs/formatters";
|
|
@@ -69,6 +69,14 @@ export declare function assertIsFile(path: PathBuilderLike | URL, message?: stri
|
|
|
69
69
|
* Whether a path exists and is a file.
|
|
70
70
|
*/
|
|
71
71
|
export declare function isFile(path: PathBuilderLike | URL): Promise<boolean>;
|
|
72
|
+
/**
|
|
73
|
+
* Whether a path exists and is a file, read synchronously.
|
|
74
|
+
*
|
|
75
|
+
* The env module folds `.env` into `process.env` when it is imported,
|
|
76
|
+
* ahead of any `await`, so it cannot use {@linkcode isFile}.
|
|
77
|
+
* Every other caller can, and should.
|
|
78
|
+
*/
|
|
79
|
+
export declare function isFileSync(path: PathBuilderLike): boolean;
|
|
72
80
|
/**
|
|
73
81
|
* Whether a path exists and is a symbolic link.
|
|
74
82
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stat.d.ts","sourceRoot":"","sources":["../../../lib/fs/readers/stat.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"stat.d.ts","sourceRoot":"","sources":["../../../lib/fs/readers/stat.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,IAAI,EAAE,KAAK,KAAK,EAAY,MAAM,SAAS,CAAA;AACtE,OAAO,EAQN,KAAK,UAAU,EACf,MAAM,kBAAkB,CAAA;AAEzB,OAAO,EAAE,KAAK,eAAe,EAAe,MAAM,SAAS,CAAA;AAE3D,OAAO,EAAiB,KAAK,oBAAoB,EAAE,MAAM,gBAAgB,CAAA;AAIzE;;;;;;;;;GASG;AACH,wBAAgB,OAAO,CAAC,eAAe,EAAE,eAAe,GAAG,GAAG,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAQrF;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAEpE;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAEpE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,GAAG,GAAG,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC,CAM9E;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,eAAe,GAAG,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,CAExE;AAMD;;GAEG;AACH,wBAAgB,gBAA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GAAG,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,CAEzE;AAED;;;;GAIG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,eAAe,GAAG,GAAG,EAAE,OAAO,CAAC,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,CAEjH;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAE/D;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAMzE;AAED,wBAAgB,IAAI,CAAC,IAAI,EAAE,eAAe,GAAG,GAAG,EAAE,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,EAAE,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,CAE3G;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CAE/D;AAED;;GAEG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,eAAe,GAAG,GAAG,GAAG,GAAG,GAAG,MAAM,CAElE"}
|
package/out/fs/readers/stat.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* @file Filesystem metadata readers.
|
|
5
5
|
*/
|
|
6
6
|
import { AssertionError } from "node:assert";
|
|
7
|
+
import { statSync } from "node:fs";
|
|
7
8
|
import { open as openNative, access, constants, lstat, readlink, realpath, stat, } from "node:fs/promises";
|
|
8
9
|
import { resolvePath } from "path-ts";
|
|
9
10
|
import { ByteFormatter } from "#fs/formatters";
|
|
@@ -159,6 +160,21 @@ export function assertIsFile(path, message, cachedStats) {
|
|
|
159
160
|
export function isFile(path) {
|
|
160
161
|
return tryStat(path).then((stats) => stats?.isFile() ?? false);
|
|
161
162
|
}
|
|
163
|
+
/**
|
|
164
|
+
* Whether a path exists and is a file, read synchronously.
|
|
165
|
+
*
|
|
166
|
+
* The env module folds `.env` into `process.env` when it is imported,
|
|
167
|
+
* ahead of any `await`, so it cannot use {@linkcode isFile}.
|
|
168
|
+
* Every other caller can, and should.
|
|
169
|
+
*/
|
|
170
|
+
export function isFileSync(path) {
|
|
171
|
+
try {
|
|
172
|
+
return statSync(resolvePath(path)).isFile();
|
|
173
|
+
}
|
|
174
|
+
catch {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
162
178
|
/**
|
|
163
179
|
* Whether a path exists and is a symbolic link.
|
|
164
180
|
*/
|