@preventive/triage 1.0.0-alpha.86 → 1.0.0-alpha.88
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/common/bundle-compare-diff.js +3 -2
- package/common/default-scan-models.ts +1 -0
- package/common/dependency-reviews.d.ts +1 -0
- package/common/dependency-reviews.js +3 -0
- package/common/github-issue-labels.d.ts +3 -1
- package/common/github-issue-labels.js +37 -6
- package/common/line-diff.d.ts +2 -1
- package/common/line-diff.js +12 -5
- package/common/managed/roles.ts +7 -0
- package/common/managed/routes.js +7 -6
- package/common/pretty-json.js +25 -0
- package/common/pretty-print.d.ts +1 -0
- package/common/pretty-print.js +5 -0
- package/out/activity.js +2 -2
- package/out/{chunk-ULI2BIWN.js → chunk-3TJCEPHF.js} +1 -1
- package/out/chunk-4GHLPL2P.js +1 -0
- package/out/chunk-5PWEAEA5.js +1 -0
- package/out/chunk-7KUZQB6S.js +267 -0
- package/out/{chunk-YU3IUQY6.js → chunk-A4HSJCXG.js} +1 -1
- package/out/{chunk-ZQQALNFP.js → chunk-BZJU5EEV.js} +1 -1
- package/out/{chunk-6CCSTJWB.js → chunk-ESXA7KID.js} +1 -1
- package/out/{chunk-CE2FMDK3.js → chunk-TKPNRQNN.js} +1 -1
- package/out/{chunk-GM6GP6TA.js → chunk-U6JONPTN.js} +2 -2
- package/out/chunk-VRFGZ6MV.js +1 -0
- package/out/{chunk-XHYX3Q34.js → chunk-XRAAYXPR.js} +1 -1
- package/out/chunk-ZPIUN4FW.js +55 -0
- package/out/client-managed-import.js +1 -1
- package/out/client-managed.js +28 -28
- package/out/compare.js +13 -13
- package/out/dialogs.js +38 -38
- package/out/graph.js +1 -1
- package/out/index.html +9 -9
- package/out/scan.js +2 -2
- package/out/view.css +1 -1
- package/out/view.js +15 -15
- package/package.json +2 -2
- package/risk/files/script.js +19 -9
- package/server-e2e/config.ts +3 -1
- package/server-managed/bundle-build-worker.js +13 -6
- package/server-managed/bundle-build.ts +7 -5
- package/server-managed/dependabot-access.ts +41 -17
- package/server-managed/dependabot-alerts.ts +19 -2
- package/server-managed/github-issues.ts +26 -14
- package/server-managed/github-users.ts +23 -0
- package/server-managed/http.ts +271 -123
- package/server-managed/npm-delta-worker.js +56 -8
- package/server-managed/npm-delta.ts +1 -1
- package/server-managed/npm-patch.ts +3 -1
- package/server-managed/pretty-format.d.ts +3 -2
- package/server-managed/pretty-format.js +17 -3
- package/server-managed/pretty-print.ts +18 -16
- package/server-managed/repository-browser.ts +3 -2
- package/server-managed/repository-risk-assess.ts +10 -0
- package/server-managed/stasis-dependencies.ts +14 -5
- package/server-managed/type-only-proof.js +22 -2
- package/out/chunk-2F7GGMMR.js +0 -266
- package/out/chunk-R7HUX4PF.js +0 -1
- package/out/chunk-V4U7URJF.js +0 -54
- package/out/chunk-WOCJFOXN.js +0 -1
- package/out/chunk-ZQHKSKD7.js +0 -1
- /package/out/{chunk-6WMQVUT2.js → chunk-WBK5ZN4K.js} +0 -0
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
// The lines a package's files change (npm-delta.ts), off the event loop, paired as Compare pairs them (rename-diff.ts
|
|
2
2
|
// comparedFiles); and each file's fewest (`best`): the least of the diffs Compare draws of it (drawn), one per setting of
|
|
3
|
-
// its toggles the comparison has (`proves` types, `prints` code
|
|
3
|
+
// its toggles the comparison has (`proves` types, `prints` code, JSON folded where it offers that: foldsOffered), those
|
|
4
|
+
// needing proofs or copies smallest first.
|
|
4
5
|
import { parentPort, workerData } from 'node:worker_threads'
|
|
5
6
|
import { treeLayout } from '@preventive/compare'
|
|
6
7
|
import { renamedDiff } from '@preventive/compare/names.js'
|
|
7
8
|
import { hidesMixedWhitespace } from '@preventive/compare/view.js'
|
|
8
9
|
import { computeBundleDiff } from '../common/bundle-compare-diff.js'
|
|
9
10
|
import { bundlePkgOf } from '../common/bundle-pkg-of.js'
|
|
10
|
-
import { blocksHold, changeBlocks, diffSize, isLargeDiff, markedCounts, textLines, typeFolds, withSharedBlankLines } from '../common/line-diff.js'
|
|
11
|
+
import { blocksHold, changeBlocks, copiesRuns, diffSize, isLargeDiff, markedCounts, textLines, typeFolds, withSharedBlankLines } from '../common/line-diff.js'
|
|
12
|
+
import { comparisonFolds, offersFold } from '../common/pretty-json.js'
|
|
11
13
|
import { viewerKind, viewerPrintable } from '../common/pretty-kinds.js'
|
|
12
14
|
import { prettyExtension, printableSize } from '../common/pretty-print.js'
|
|
13
15
|
import { whitespaceInsensitive } from '../common/whitespace-insensitive.js'
|
|
@@ -49,7 +51,7 @@ async function copyOf(at, path, text, layout) {
|
|
|
49
51
|
if (kind) return viewerPrintable(kind, text) ? { text: kind.copy(text, layout), blank: [] } : null
|
|
50
52
|
if (!prints || prettyExtension(path) === null || !printableSize(text)) return null
|
|
51
53
|
const known = kept.get(`${at}\0${path}`)
|
|
52
|
-
const copy = known ?? await prettyFormat(text, prettyExtension(path))
|
|
54
|
+
const copy = known ?? await prettyFormat(text, prettyExtension(path), path)
|
|
53
55
|
if ('error' in copy) return null
|
|
54
56
|
if (!known) made.push([at, path, copy])
|
|
55
57
|
return copy
|
|
@@ -69,21 +71,66 @@ async function printingOf(file, layout, ws) {
|
|
|
69
71
|
const copy = ([at, path, text]) => once(file, `copy\0${layout}\0${at}`, () => copyOf(at, path, text, layout))
|
|
70
72
|
const a = await copy(sides[0]), b = a && await copy(sides[1])
|
|
71
73
|
if (!a || !b) return null
|
|
72
|
-
const shown = file.generated ? { before: a.text, after: b.text } : withSharedBlankLines(a.text, b.text, a.blank, b.blank)
|
|
73
|
-
if (viewed || unreadable) return { ...shown, kind: viewed && kinds[0]
|
|
74
|
+
const shown = { ...file.generated ? { before: a.text, after: b.text } : withSharedBlankLines(a.text, b.text, a.blank, b.blank), copies: [a.text, b.text], runs: copiesRuns(a, b) }
|
|
75
|
+
if (viewed || unreadable) return { ...shown, kind: viewed && kinds[0] }
|
|
74
76
|
if (isLargeDiff(file.before, file.after) || isLargeDiff(shown.before, shown.after)) return null
|
|
75
77
|
const mode = ws && 'leading', now = diffSize(shown.before, shown.after, mode), was = diffSize(file.before, file.after, mode)
|
|
76
78
|
return now.lines < was.lines || (now.lines === was.lines && now.marks < was.marks) ? shown : null
|
|
77
79
|
}
|
|
78
80
|
|
|
81
|
+
// A JSON file's two sides' copies in both its layouts, `[indented, folded]` each, '' both for a side it lacks, as
|
|
82
|
+
// Compare's _folds reads them; null where a side isn't JSON or can't be printed.
|
|
83
|
+
async function layoutsOf(file) {
|
|
84
|
+
const sides = []
|
|
85
|
+
for (const [at, path, text] of [[0, file.basePath, file.before], [1, file.path, file.after]]) {
|
|
86
|
+
if (text !== '' && !viewerKind(path)?.layouts) return null
|
|
87
|
+
const pair = []
|
|
88
|
+
for (const layout of ['indented', 'folded']) {
|
|
89
|
+
const copy = await once(file, `copy\0${layout}\0${at}`, () => copyOf(at, path, text, layout))
|
|
90
|
+
if (!copy) return null
|
|
91
|
+
pair.push(copy.text)
|
|
92
|
+
}
|
|
93
|
+
sides.push(pair)
|
|
94
|
+
}
|
|
95
|
+
return sides
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Whether Compare's Diff view offers JSON folded, whitespace hidden (`ws`) or not: where any JSON file but a
|
|
99
|
+
// package.json folds enough (comparisonFolds), counted as Compare's _folds counts; its folded setting then draws every
|
|
100
|
+
// JSON file folded, a package.json too. Those smallest first, and none once past `prettyUntil`, as the count then ends.
|
|
101
|
+
const offered = new Map()
|
|
102
|
+
function foldsOffered(ws) {
|
|
103
|
+
if (!offered.has(ws)) {
|
|
104
|
+
offered.set(ws, (async () => {
|
|
105
|
+
for (const file of ordered) {
|
|
106
|
+
if (Date.now() >= prettyUntil) return false
|
|
107
|
+
if (!file.layouts || !offersFold(file.path) || !offersFold(file.basePath)) continue
|
|
108
|
+
const mode = ws && file.insensitive && 'leading', sides = await layoutsOf(file)
|
|
109
|
+
if (sides && comparisonFolds(sides, (before, after) => (isLargeDiff(before, after) ? null : diffSize(before, after, mode).lines))) return true
|
|
110
|
+
}
|
|
111
|
+
return false
|
|
112
|
+
})())
|
|
113
|
+
}
|
|
114
|
+
return offered.get(ws)
|
|
115
|
+
}
|
|
116
|
+
|
|
79
117
|
// The diff Compare draws of a file with its toggles so (_fileState): whitespace hidden (`ws`), type-only changes
|
|
80
|
-
// (`types`), renamed names (`renames`), printed in `layout` or not (null); null where it draws none
|
|
118
|
+
// (`types`), renamed names (`renames`), printed in `layout` or not (null); null where it draws none, or the same as
|
|
119
|
+
// another setting: folded where the comparison doesn't offer it (foldsOffered), drawn indented.
|
|
81
120
|
async function drawn(file, { ws, types, layout, renames }) {
|
|
121
|
+
if (layout === 'folded' && !await foldsOffered(ws)) return null
|
|
82
122
|
const proof = types ? (file.stamped || once(file, 'runs', () => typeOnlyRuns(file.from, file.to))) : null
|
|
83
123
|
if (proof === true) return NONE
|
|
84
124
|
const folds = proof && once(file, 'folds', () => typeFolds(file.before, file.after, proof))
|
|
85
|
-
if (folds) return diffed(file, 'folds', folds.before, folds.after, ws)
|
|
86
125
|
const printing = layout && await once(file, `printing\0${layout}\0${ws}`, () => printingOf(file, layout, ws))
|
|
126
|
+
if (folds) {
|
|
127
|
+
// As _fileState folds it: by its copies' own lines that run where they kept them, none apart its types alone
|
|
128
|
+
// changed, drawn as printed where their types read alike; else as published.
|
|
129
|
+
const printed = printing?.runs ? once(file, `printed folds\0${layout}`, () => typeFolds(...printing.copies, printing.runs)) : undefined
|
|
130
|
+
if (printed === false) return NONE
|
|
131
|
+
if (printed) return diffed(file, `printed folds\0${layout}`, printed.before, printed.after, ws)
|
|
132
|
+
if (printed === undefined) return diffed(file, 'folds', folds.before, folds.after, ws)
|
|
133
|
+
}
|
|
87
134
|
if (!printing) return diffed(file, 'texts', file.before, file.after, ws)
|
|
88
135
|
if (file.generated) {
|
|
89
136
|
const diff = await once(file, `renamed\0${layout}`, () => renamedDiff(printing.before, printing.after,
|
|
@@ -126,8 +173,9 @@ for (const { path, basePath = path, side } of [...files.changed, ...files.onlyBa
|
|
|
126
173
|
const count = complete => ({ ...total, best, complete })
|
|
127
174
|
tell({ sofar: count(false) })
|
|
128
175
|
|
|
176
|
+
const ordered = later.toSorted((a, b) => a.size - b.size)
|
|
129
177
|
let complete = true
|
|
130
|
-
for (const file of
|
|
178
|
+
for (const file of ordered) {
|
|
131
179
|
if (Date.now() >= prettyUntil) { complete = false; break }
|
|
132
180
|
let now = file.fewest
|
|
133
181
|
for (const setting of settingsOf(file)) {
|
|
@@ -38,7 +38,7 @@ const PRETTY_MARGIN_MS = 15_000
|
|
|
38
38
|
// The text the two sides may hold together, past which none is counted.
|
|
39
39
|
const MAX_TEXT_LENGTH = 64 * 1024 * 1024
|
|
40
40
|
// Bumped when what a delta counts changes; its keys carry it and PRETTY_VERSION, so none counted otherwise is read.
|
|
41
|
-
const DELTA_VERSION =
|
|
41
|
+
const DELTA_VERSION = 5
|
|
42
42
|
const COUNTING = `v${DELTA_VERSION}.${PRETTY_VERSION}`
|
|
43
43
|
const COPIES_AT_ONCE = 8
|
|
44
44
|
|
|
@@ -129,7 +129,9 @@ function readHunk(lines: string[], at: number, end: number): { hunk: PatchHunk;
|
|
|
129
129
|
// hunks' lines with them. pnpm 10 and 11 also read hunks where git puts none
|
|
130
130
|
// (with no `diff --git` line, past a blank or `index` line, after another
|
|
131
131
|
// file's hunks) and pnpm 12 doesn't, so a line git doesn't write is refused,
|
|
132
|
-
// but
|
|
132
|
+
// but an empty one within a hunk's count, git's ` ` as an editor trims it,
|
|
133
|
+
// which every pnpm reads as that, and blank lines at the end. So are a
|
|
134
|
+
// `diff --git` line naming other paths
|
|
133
135
|
// than its sides (pnpm 10 and 11 take one, pnpm 12 the other), a rename that
|
|
134
136
|
// also creates or deletes, and a `new mode` line without its `old mode`
|
|
135
137
|
// (pnpm 12 alone reads one). Throws for one it can't read, or of bytes.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export const PRETTY_VERSION: number
|
|
2
|
-
export
|
|
3
|
-
export
|
|
2
|
+
export function copyName(path: string, extension: string): string
|
|
3
|
+
export interface PrettyCopy { text: string; blank: number[]; runs?: [number, number][] }
|
|
4
|
+
export function prettyFormat(text: string, extension: string, path?: string): Promise<PrettyCopy | { error: 'unsupported' | 'unformattable' | 'pretty-mismatch' }>
|
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
// A file pretty-printed as Compare draws it, with its copy's layout blank lines: the server's
|
|
2
2
|
// copies (pretty-print.ts) and a delta's (npm-delta-worker.js) alike.
|
|
3
|
+
import { createHash } from 'node:crypto'
|
|
3
4
|
import { format, layoutBlankLines } from '@preventive/compare/pretty.js'
|
|
5
|
+
import { declarationRuns, runsName } from './type-only-proof.js'
|
|
4
6
|
|
|
5
7
|
// Part of every kept copy's name; bumped when what the formatter writes for
|
|
6
8
|
// the same file changes, or what its check lets through, so copies written
|
|
7
9
|
// before are no longer read.
|
|
8
|
-
export const PRETTY_VERSION =
|
|
10
|
+
export const PRETTY_VERSION = 8
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
// A copy's name but for its file's hash: a declaration file's kept apart by
|
|
13
|
+
// its name, which its lines that run depend on too (runsName), hashed, as a
|
|
14
|
+
// cache key takes no `_` (validateCacheKey) and a file's name is bounded.
|
|
15
|
+
export function copyName(path, extension) {
|
|
16
|
+
const name = runsName(path)
|
|
17
|
+
if (name === null) return extension
|
|
18
|
+
return name ? `d.${createHash('sha256').update(name).digest('hex').slice(0, 32)}.${extension}` : `d.${extension}`
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// A declaration file's copy keeps its lines that run, as the type-only proof finds a file's, for Compare to fold it by.
|
|
22
|
+
export async function prettyFormat(text, extension, path = '') {
|
|
11
23
|
const result = await format(text, extension)
|
|
12
|
-
|
|
24
|
+
if ('error' in result) return result
|
|
25
|
+
const runs = declarationRuns(path, result.code)
|
|
26
|
+
return { text: result.code, blank: await layoutBlankLines(result.code, extension), ...runs ? { runs } : {} }
|
|
13
27
|
}
|
|
@@ -16,7 +16,7 @@ import { computeFileHash } from '@preventive/report'
|
|
|
16
16
|
import { FILE_HASH, computeBundleFileHashes } from '../common/bundle-metadata.js'
|
|
17
17
|
import { bundleCompareFiles, bundleCompareSideScopes } from '../common/bundle-compare-inputs.js'
|
|
18
18
|
import { bundlePackageDirs, bundleSourcesAsMap } from '../common/bundle-sources.js'
|
|
19
|
-
import { MAX_PRETTY_BYTES, layoutBlankList, needsPrettyPrint, prettyExtension } from '../common/pretty-print.js'
|
|
19
|
+
import { MAX_PRETTY_BYTES, layoutBlankList, needsPrettyPrint, prettyExtension, runRangeList } from '../common/pretty-print.js'
|
|
20
20
|
import { type OpenedBlob, readBytes } from './blob-store.ts'
|
|
21
21
|
import { type BundleCacheStorage, readSizedBundleDetails } from './bundle-cache.ts'
|
|
22
22
|
import type { BundleStore } from './bundle-store.ts'
|
|
@@ -27,7 +27,7 @@ import { keptBriefly } from './kept-briefly.ts'
|
|
|
27
27
|
import { loadNpmFiles } from './npm-loads.ts'
|
|
28
28
|
import { type NpmVersionDocument, npmFileText, pathOrder } from './npm-packages.ts'
|
|
29
29
|
import { inTurns } from './queue.ts'
|
|
30
|
-
import { PRETTY_VERSION, type PrettyCopy, prettyFormat } from './pretty-format.js'
|
|
30
|
+
import { PRETTY_VERSION, type PrettyCopy, copyName, prettyFormat } from './pretty-format.js'
|
|
31
31
|
|
|
32
32
|
// Formats running at once per process, each holding its file's syntax tree,
|
|
33
33
|
// and those waiting their turn past them (a version's files are formatted one
|
|
@@ -58,8 +58,9 @@ export interface PrettyRequest { path: string; hash: string; extension: string }
|
|
|
58
58
|
|
|
59
59
|
// One of a version's files pretty-printed (npmAll), named by `source`, the
|
|
60
60
|
// hash of the file it was formatted from: its copy's text and layout blank
|
|
61
|
-
// lines
|
|
62
|
-
|
|
61
|
+
// lines, and a declaration file's its lines that run (prettyCopy), or why it
|
|
62
|
+
// has none, as a PrettyError tells it.
|
|
63
|
+
export type PrettyLine = ({ path: string; source: string } & PrettyCopy) | { path: string; source: string; error: string; status: number }
|
|
63
64
|
|
|
64
65
|
// Which of a comparison's two its files are of: the bundle or version asked
|
|
65
66
|
// about, or the `other`.
|
|
@@ -91,26 +92,27 @@ export function prettyRequest(params: URLSearchParams): PrettyRequest | null {
|
|
|
91
92
|
return extension !== null && FILE_HASH.test(hash) ? { path, hash, extension } : null
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
// A copy's name: its file's hash in hex, with the extension it was parsed by
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
// A copy's name: its file's hash in hex, with the extension it was parsed by,
|
|
96
|
+
// or a declaration file's name (copyName).
|
|
97
|
+
export const prettyFile = ({ path, hash, extension }: PrettyRequest) =>
|
|
98
|
+
`pretty-v${PRETTY_VERSION}/${Buffer.from(hash.slice('sha512-'.length), 'base64').toString('hex')}.${copyName(path, extension)}.br`
|
|
97
99
|
|
|
98
100
|
let activeFormats = 0
|
|
99
101
|
const waitingFormats: Array<() => void> = []
|
|
100
102
|
|
|
101
103
|
// The text formatted, where @preventive/compare's checks find formatting
|
|
102
|
-
// changed only its layout, its copy `{ text, blank }` (its layout blank
|
|
103
|
-
// lines' numbers) as JSON, Brotli-encoded:
|
|
104
|
+
// changed only its layout, its copy `{ text, blank, runs? }` (its layout blank
|
|
105
|
+
// lines' numbers, and a declaration file's lines that run) as JSON, Brotli-encoded:
|
|
104
106
|
// refused as `unsupported` where it has no check for the kind of file,
|
|
105
107
|
// `unformattable` or `pretty-mismatch`. Its blank lines are read in the
|
|
106
108
|
// same turn, as they parse and check the copy again.
|
|
107
|
-
export async function prettyBody(text: string, extension: string): Promise<Buffer> {
|
|
109
|
+
export async function prettyBody(text: string, extension: string, path = ''): Promise<Buffer> {
|
|
108
110
|
if (Buffer.byteLength(text) > MAX_PRETTY_BYTES) throw new PrettyError(413, 'file-too-large')
|
|
109
111
|
if (activeFormats < MAX_ACTIVE_FORMATS) activeFormats++
|
|
110
112
|
else if (waitingFormats.length >= MAX_WAITING_FORMATS) throw new PrettyError(429, 'pretty-busy')
|
|
111
113
|
else await new Promise<void>(resolve => { waitingFormats.push(resolve) })
|
|
112
114
|
let result
|
|
113
|
-
try { result = await prettyFormat(text, extension) }
|
|
115
|
+
try { result = await prettyFormat(text, extension, path) }
|
|
114
116
|
finally {
|
|
115
117
|
const next = waitingFormats.shift()
|
|
116
118
|
if (next) next()
|
|
@@ -142,10 +144,10 @@ const decompress = promisify(brotliDecompress)
|
|
|
142
144
|
// A pretty-printed copy's text and layout blank lines, from its Brotli-encoded
|
|
143
145
|
// bytes (prettyBody).
|
|
144
146
|
export async function prettyCopy(copy: OpenedBlob): Promise<PrettyCopy> {
|
|
145
|
-
const { text, blank } = JSON.parse((await decompress(await readBytes(copy))).toString()) as { text: unknown; blank: unknown }
|
|
146
|
-
const numbers = layoutBlankList(blank)
|
|
147
|
+
const { text, blank, runs } = JSON.parse((await decompress(await readBytes(copy))).toString()) as { text: unknown; blank: unknown; runs: unknown }
|
|
148
|
+
const numbers = layoutBlankList(blank), ranges = runRangeList(runs)
|
|
147
149
|
if (typeof text !== 'string' || !numbers) throw new Error('managed: a kept pretty-printed copy is not one')
|
|
148
|
-
return { text, blank: numbers }
|
|
150
|
+
return { text, blank: numbers, ...ranges ? { runs: ranges } : {} }
|
|
149
151
|
}
|
|
150
152
|
|
|
151
153
|
// A pretty-printed copy's text alone, as a rename diff reads it.
|
|
@@ -344,7 +346,7 @@ export function createPrettyCache(bundles: BundleCacheStorage, npm: CacheStorage
|
|
|
344
346
|
function bundleCopy(record: ManagedBundle, request: PrettyRequest, read: () => Promise<string>): Promise<Buffer> {
|
|
345
347
|
const file = prettyFile(request)
|
|
346
348
|
return shared(`bundle ${record.id} ${file}`, async () => {
|
|
347
|
-
const body = await prettyBody(await read(), request.extension)
|
|
349
|
+
const body = await prettyBody(await read(), request.extension, request.path)
|
|
348
350
|
// As for its metadata (bundle-cache.ts): a bundle deleted meanwhile
|
|
349
351
|
// keeps no copy, nor does one deleted while it was written.
|
|
350
352
|
if (!await db.getBundle(record.id)) throw new PrettyError(404, 'no-bundle')
|
|
@@ -369,7 +371,7 @@ export function createPrettyCache(bundles: BundleCacheStorage, npm: CacheStorage
|
|
|
369
371
|
async function npmMade(doc: NpmVersionDocument, request: PrettyRequest, read: () => Promise<string>): Promise<OpenedBlob> {
|
|
370
372
|
const file = prettyFile(request)
|
|
371
373
|
return opened(await shared(doc.private ? `npm ${doc.dist.integrity} ${file}` : `npm ${file}`, async () => {
|
|
372
|
-
const body = await prettyBody(await read(), request.extension)
|
|
374
|
+
const body = await prettyBody(await read(), request.extension, request.path)
|
|
373
375
|
if (!doc.private) await keep(() => npm.put(file, body))
|
|
374
376
|
return body
|
|
375
377
|
}))
|
|
@@ -142,10 +142,11 @@ export function createRepositoryBrowser(config: ManagedConfig, user: RepositoryB
|
|
|
142
142
|
return token
|
|
143
143
|
}
|
|
144
144
|
// Its Dependabot alerts, with the token of the installation GitHub tells
|
|
145
|
-
// covers it, where the user's own access lets them see them
|
|
145
|
+
// covers it, where the user's own access lets them see them, GitHub
|
|
146
|
+
// asked with their own token where their level doesn't tell
|
|
146
147
|
// (dependabot-access.ts).
|
|
147
148
|
return repositoryReader(repo, user.token, installationToken, getIdentity, fetchImpl, verdictCache(config, user, repo, fetchImpl), renamed).then(reader => ({ ...reader,
|
|
148
|
-
dependabotAlerts: () => appDependabotAlerts(config, repo, { identity: getIdentity, permission: reader.permission }, fetchImpl) }))
|
|
149
|
+
dependabotAlerts: () => appDependabotAlerts(config, repo, { identity: getIdentity, permission: reader.permission, userToken: () => user.token }, fetchImpl) }))
|
|
149
150
|
},
|
|
150
151
|
}
|
|
151
152
|
}
|
|
@@ -41,6 +41,16 @@ export function failureOf(error: unknown, doing?: string): RiskFailure {
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
export const isBusy = (error: unknown) => (error instanceof NpmPackageError && error.status === 429) || (error instanceof NpmRiskError && error.code === 'upstream-busy')
|
|
44
|
+
// `work` done, asked again a while after where it is refused as busy, as
|
|
45
|
+
// many times as `retries`, the wait given up with `signal`.
|
|
46
|
+
export async function notBusy<T>(work: () => Promise<T>, signal: AbortSignal, retries = BUSY_RETRIES): Promise<T> {
|
|
47
|
+
for (let attempt = 0; ; attempt++) {
|
|
48
|
+
try { return await work() } catch (error) {
|
|
49
|
+
if (!isBusy(error) || attempt >= retries) throw error
|
|
50
|
+
await delay(BUSY_WAIT_MS * Math.min(attempt + 1, 5), undefined, { signal })
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
44
54
|
|
|
45
55
|
// A package to assess: npm's of its name and version, or, with an
|
|
46
56
|
// `integrity`, a mirror's held to it.
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
// stasisConfigs): what the build worker tells of the lockfile it builds
|
|
4
4
|
// (bundle-build-worker.js buildStasisLockfile), kept by the repository, the
|
|
5
5
|
// commit and the file's path, which never change, in this instance and in
|
|
6
|
-
// the database, the versions alone
|
|
6
|
+
// the database, the versions alone (the files of each kept apart, filesKeyOf).
|
|
7
|
+
// A build takes minutes, so none is waited
|
|
7
8
|
// for: one not kept is told as pending (read), and its answer asks for it
|
|
8
9
|
// once its review is known (build), with a priority: how many versions the
|
|
9
10
|
// lockfiles beside it add that want reviews (wantingBeside). Those asked for
|
|
@@ -16,7 +17,7 @@
|
|
|
16
17
|
// so), is kept too, for it to tell what it reached while one of a later
|
|
17
18
|
// commit is still to be built (last): one read as the head later alone
|
|
18
19
|
// replaces it, whenever each is built.
|
|
19
|
-
import { BundleBuildError, type LockfileInput, type StasisDependency } from './bundle-build.ts'
|
|
20
|
+
import { BundleBuildError, type LockfileInput, type StasisDependency, type StasisReached } from './bundle-build.ts'
|
|
20
21
|
import { directoryOf, installsBundle, lockedVersions } from './bundle-dependency-reviews.ts'
|
|
21
22
|
import type { CommitLockfiles } from './commit-lockfiles.ts'
|
|
22
23
|
import type { LockedPackage } from './locked-packages.ts'
|
|
@@ -73,7 +74,7 @@ export interface StasisDependencyReader {
|
|
|
73
74
|
interface ReaderOptions {
|
|
74
75
|
store: KeptStore<unknown>
|
|
75
76
|
// Builds one, as the deployment's builds are admitted (http.ts stasisReader).
|
|
76
|
-
build(input: LockfileInput, github: string, token: string, signal: AbortSignal): Promise<
|
|
77
|
+
build(input: LockfileInput, github: string, token: string, signal: AbortSignal): Promise<StasisReached[]>
|
|
77
78
|
// Work going on behind an answer, handed to its owner (http.ts trackBehind).
|
|
78
79
|
behind(work: Promise<unknown>): void
|
|
79
80
|
stopping(): boolean
|
|
@@ -84,6 +85,10 @@ type Head = { branch: string; at: number }
|
|
|
84
85
|
type Job = { key: string; input: LockfileInput; github: string; token: string; priority: number; asked: number; head: Head | null }
|
|
85
86
|
const later = (one: Head | null, other: Head | null) => !one || (other && other.at > one.at) ? other : one
|
|
86
87
|
const keyOf = (repoId: number, commit: string, config: string) => `${repoId}\0${STASIS_DEPENDENCIES_READ}\0${commit}\0${config}`
|
|
88
|
+
// Where its versions are kept with the files of each the build reaches
|
|
89
|
+
// (StasisReached), in the database alone, apart from them as none of their
|
|
90
|
+
// reads need them; none of those built before they were kept.
|
|
91
|
+
export const filesKeyOf = (repoId: number, commit: string, config: string) => `${repoId}\0${STASIS_DEPENDENCIES_READ}\0files\0${commit}\0${config}`
|
|
87
92
|
// Where the commit it was last built of at a branch's head is kept.
|
|
88
93
|
const lastKeyOf = (repoId: number, branch: string, config: string) => `${repoId}\0${STASIS_DEPENDENCIES_READ}\0last\0${branch}\0${config}`
|
|
89
94
|
const optional = (value: unknown) => value === undefined || typeof value === 'string'
|
|
@@ -119,8 +124,12 @@ export function stasisDependencyReader({ store, build, behind, stopping }: Reade
|
|
|
119
124
|
const watching = setInterval(() => { if (stopping()) stop.abort() }, STOPPING_EVERY_MS)
|
|
120
125
|
watching.unref()
|
|
121
126
|
try {
|
|
122
|
-
const
|
|
123
|
-
|
|
127
|
+
const reached = await build(job.input, job.github, job.token, stop.signal)
|
|
128
|
+
const at = Date.now()
|
|
129
|
+
const dependencies = reached.map(({ files: _files, ...one }) => one)
|
|
130
|
+
// Its files first: where its versions are kept, so are they.
|
|
131
|
+
await store.write(filesKeyOf(job.input.repoId, job.input.commit, job.input.config), reached, at)
|
|
132
|
+
await store.write(job.key, dependencies, at)
|
|
124
133
|
hold(job.key, { status: 'ready', dependencies })
|
|
125
134
|
if (job.head) await lasts.keep({ ...job.input, branch: job.head.branch }, job.head.at)
|
|
126
135
|
} catch (err) {
|
|
@@ -54,10 +54,14 @@ const tree = file => (file ? [{ name: file.path, data: file.text }] : [])
|
|
|
54
54
|
// would end the comment within it, and what follows would run, so no other
|
|
55
55
|
// character than Latin letters, digits, `-`, `_` and `.` is taken in one.
|
|
56
56
|
const PLAIN_NAME = /^[A-Za-z0-9._-]+$/u
|
|
57
|
+
const plainName = path => {
|
|
58
|
+
const name = path.slice(path.lastIndexOf('/') + 1)
|
|
59
|
+
return PLAIN_NAME.test(name) ? name : null
|
|
60
|
+
}
|
|
57
61
|
function withoutOwnMap(file) {
|
|
58
62
|
if (file === null) return null
|
|
59
|
-
const name =
|
|
60
|
-
if (
|
|
63
|
+
const name = plainName(file.path)
|
|
64
|
+
if (name === null) return file
|
|
61
65
|
const comment = `//# sourceMappingURL=${name}.map`
|
|
62
66
|
for (const last of [comment, `${comment}\n`]) {
|
|
63
67
|
const before = file.text.endsWith(last) ? file.text.slice(0, -last.length) : null
|
|
@@ -142,6 +146,22 @@ function runLines(text) {
|
|
|
142
146
|
// line reads the same on both.
|
|
143
147
|
const moved = (one, other) => [...one.leading].some(comment => !other.leading.has(comment) && other.below.has(comment))
|
|
144
148
|
|
|
149
|
+
// A declaration file's lines that run, as the proof tells them, but for its own
|
|
150
|
+
// map comment; null for any other file, or where they can't be told.
|
|
151
|
+
export function declarationRuns(path, text) {
|
|
152
|
+
if (!DECLARATION.test(path)) return null
|
|
153
|
+
try {
|
|
154
|
+
return runLines(withoutOwnMap({ path, text }).text).lines
|
|
155
|
+
} catch {
|
|
156
|
+
return null
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// What a file's lines that run depend on besides its text: a declaration
|
|
161
|
+
// file's name, which its own map comment names, or '' where it is no plain
|
|
162
|
+
// name (withoutOwnMap); null for any other file.
|
|
163
|
+
export const runsName = path => (DECLARATION.test(path) ? plainName(path) ?? '' : null)
|
|
164
|
+
|
|
145
165
|
// `{ runs, otherRuns }` where each side there is a declaration file proven to
|
|
146
166
|
// hold types alone but for what runs, and no directive steers on one side
|
|
147
167
|
// alone unseen (`moved`); else false, and where the proof throws, as no
|