@preventive/triage 1.0.0-alpha.77 → 1.0.0-alpha.78
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/line-diff.d.ts +2 -0
- package/common/line-diff.js +54 -0
- package/common/managed/dependency-routes.js +25 -0
- package/common/managed/routes.js +9 -12
- package/common/pretty-json.js +95 -0
- package/common/pretty-print.d.ts +1 -0
- package/common/pretty-print.js +6 -0
- package/common/whitespace-insensitive.js +19 -0
- package/out/activity.js +2 -2
- package/out/{chunk-OCE6KQGJ.js → chunk-26W3E5JE.js} +1 -1
- package/out/chunk-3S4YWYOM.js +1 -0
- package/out/{chunk-OQS2USZM.js → chunk-55YIWY3H.js} +1 -1
- package/out/{chunk-IVDE66N5.js → chunk-6VXEPL32.js} +1 -1
- package/out/{chunk-XVKDPU4D.js → chunk-6Y6PZ2BU.js} +1 -1
- package/out/{chunk-S5PPXPAT.js → chunk-ATT2QA77.js} +1 -1
- package/out/{chunk-2V6Q4ZOZ.js → chunk-B64CTMVU.js} +1 -1
- package/out/{chunk-EXQQ5VQJ.js → chunk-BEKYZCPX.js} +1 -1
- package/out/{chunk-SDLETN3Z.js → chunk-BGLN56X6.js} +1 -1
- package/out/{chunk-S2ZIKK45.js → chunk-EEJA7JBI.js} +1 -1
- package/out/{chunk-4IW3VD3H.js → chunk-FSU2PLJL.js} +1 -1
- package/out/{chunk-5DWOFBKS.js → chunk-I4YPK32I.js} +1 -1
- package/out/{chunk-I6UQQKAH.js → chunk-LVSLM7HB.js} +1 -1
- package/out/{chunk-T6EXDRB7.js → chunk-MKX6JODK.js} +1 -1
- package/out/{chunk-N7TD27UJ.js → chunk-NCJQDKPK.js} +1 -1
- package/out/chunk-O2NYWLX3.js +259 -0
- package/out/{chunk-NEFCZAIY.js → chunk-PKLVXUEI.js} +1 -1
- package/out/chunk-QBIUW5EF.js +2 -0
- package/out/{chunk-ADMVRLNP.js → chunk-QD3IBSF4.js} +1 -1
- package/out/{chunk-GSNSP3EF.js → chunk-RPNO56H2.js} +1 -1
- package/out/{chunk-QBFT2DDR.js → chunk-UR4WYMIP.js} +1 -1
- package/out/{chunk-UH6NZBSU.js → chunk-VHEXSGGP.js} +1 -1
- package/out/chunk-XLX6XXJF.js +1 -0
- package/out/{chunk-BXQCCW7F.js → chunk-XM4RLC4A.js} +1 -1
- package/out/client-managed-import.js +1 -1
- package/out/client-managed.js +2 -2
- package/out/compare.js +14 -14
- package/out/dialogs.js +22 -22
- package/out/graph.js +1 -1
- package/out/index.html +9 -7
- package/out/scan.js +2 -2
- package/out/terminal.js +7 -7
- package/out/view.css +1 -1
- package/out/view.js +8 -8
- package/package.json +8 -2
- package/server-managed/http.ts +13 -11
- package/server-managed/npm-delta-worker.js +58 -12
- package/server-managed/npm-delta.ts +52 -28
- package/server-managed/pretty-copies.ts +22 -0
- package/server-managed/pretty-format.d.ts +3 -0
- package/server-managed/pretty-format.js +13 -0
- package/server-managed/pretty-print.ts +34 -24
- package/server-managed/public-workspace.ts +1 -1
- package/out/chunk-G6YPDPW7.js +0 -2
- package/out/chunk-JCIIBLKR.js +0 -1
- package/out/chunk-WGQ7D5DB.js +0 -1
- package/out/chunk-Z6DL5PPO.js +0 -255
- /package/out/{chunk-Z667U2UJ.js → chunk-SZWPYLPC.js} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preventive/triage",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.78",
|
|
4
4
|
"description": "Client & relay server for triaging of automated reports",
|
|
5
5
|
"license": "MIT OR Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -173,6 +173,9 @@
|
|
|
173
173
|
"server-managed/npm-patch-paths.ts",
|
|
174
174
|
"server-managed/npm-patch.ts",
|
|
175
175
|
"server-managed/package-entry-points.ts",
|
|
176
|
+
"server-managed/pretty-copies.ts",
|
|
177
|
+
"server-managed/pretty-format.d.ts",
|
|
178
|
+
"server-managed/pretty-format.js",
|
|
176
179
|
"server-managed/pretty-print.ts",
|
|
177
180
|
"server-managed/pull-reviews.ts",
|
|
178
181
|
"server-managed/rename-diff.ts",
|
|
@@ -294,6 +297,7 @@
|
|
|
294
297
|
"common/github-issue-labels.js",
|
|
295
298
|
"common/github-issue-labels.d.ts",
|
|
296
299
|
"common/gzip.js",
|
|
300
|
+
"common/pretty-json.js",
|
|
297
301
|
"common/pretty-print.d.ts",
|
|
298
302
|
"common/pretty-print.js",
|
|
299
303
|
"common/line-diff.d.ts",
|
|
@@ -301,6 +305,7 @@
|
|
|
301
305
|
"common/linked-workspace-groups.js",
|
|
302
306
|
"common/managed/agent-tasks.ts",
|
|
303
307
|
"common/managed/comments.ts",
|
|
308
|
+
"common/managed/dependency-routes.js",
|
|
304
309
|
"common/managed/directory-packages.ts",
|
|
305
310
|
"common/managed/finding-detail.d.ts",
|
|
306
311
|
"common/managed/finding-detail.js",
|
|
@@ -343,6 +348,7 @@
|
|
|
343
348
|
"common/stasis-tgz.js",
|
|
344
349
|
"common/utf8.d.ts",
|
|
345
350
|
"common/utf8.js",
|
|
351
|
+
"common/whitespace-insensitive.js",
|
|
346
352
|
"common/workspace-app.js",
|
|
347
353
|
"common/workspace-groups.js",
|
|
348
354
|
"risk/index.js",
|
|
@@ -446,7 +452,7 @@
|
|
|
446
452
|
"@exodus/stasis": "1.0.0-rc.10",
|
|
447
453
|
"@exodus/stasis-core": "1.0.0-rc.10",
|
|
448
454
|
"@preventive/archive": "^1.4.1",
|
|
449
|
-
"@preventive/compare": "^1.
|
|
455
|
+
"@preventive/compare": "^1.3.0",
|
|
450
456
|
"@preventive/diff": "^1.1.1",
|
|
451
457
|
"@preventive/lockfile": "^1.3.1",
|
|
452
458
|
"@preventive/publishers": "^1.1.0",
|
package/server-managed/http.ts
CHANGED
|
@@ -89,7 +89,8 @@
|
|
|
89
89
|
// GET /api/bundles/<id>/validation → its last validation the reader may see, else none; POST validates it anew: its own code
|
|
90
90
|
// as GitHub has it at its commit, its dependencies as upstream's packages have them, those covering every file | 401/403/404/409/422/429/502
|
|
91
91
|
// GET /api/bundles/<id>/download → authorized original upload | 401/404
|
|
92
|
-
// GET /api/bundles/<id>/pretty?path=&hash= → one of its files pretty-printed,
|
|
92
|
+
// GET /api/bundles/<id>/pretty?path=&hash= → one of its files pretty-printed, `{ text, blank }` (its layout blank lines),
|
|
93
|
+
// Brotli-encoded JSON | 400/401/404/409/413/422/429
|
|
93
94
|
// GET /api/bundles/<id>/pretty?other= → the files that changed between it and another bundle, both sides' pretty-printed,
|
|
94
95
|
// Brotli-encoded ndjson | 400/401/404/422/503
|
|
95
96
|
// GET /api/bundles/<id>/rename-diff?path=&hash=&other=&otherPath=&otherHash= → a JavaScript file diffed with another
|
|
@@ -134,7 +135,7 @@
|
|
|
134
135
|
// GET /api/npm/pretty?name=&version= → every one of its files that needs it pretty-printed, Brotli-encoded ndjson | 400/401/404/413/429/502/503
|
|
135
136
|
// GET /api/npm/pretty?name=&version=&otherVersion= → the files that changed between it and another version, both sides'
|
|
136
137
|
// pretty-printed, Brotli-encoded ndjson | 400/401/404/413/429/502/503
|
|
137
|
-
// GET /api/npm/pretty?name=&version=&path=&hash= → one of its files pretty-printed, Brotli-encoded | 400/401/404/409/413/422/429/502/503
|
|
138
|
+
// GET /api/npm/pretty?name=&version=&path=&hash= → one of its files pretty-printed, as a bundle's is, Brotli-encoded JSON | 400/401/404/409/413/422/429/502/503
|
|
138
139
|
// GET /api/npm/rename-diff?name=&version=&path=&hash=&otherVersion=&otherPath=&otherHash= → a JavaScript file diffed with
|
|
139
140
|
// another version's, both pretty-printed, renamed names hidden, whitespace changes shown and hidden | 400/401/404/409/413/422/429/502/503/504
|
|
140
141
|
// GET /api/npm/rename-diff?name=&version=&otherVersion= → every pair of their JavaScript files the viewer diffs so,
|
|
@@ -143,7 +144,7 @@
|
|
|
143
144
|
// or with otherVersion (empty) of the version against no files, each added, as Review reads one with no base; and
|
|
144
145
|
// with runs=1 those in types alone but for what runs, Brotli-encoded ndjson | 400/401/404/413/429/501/502/503
|
|
145
146
|
// GET /api/npm/delta?name=&version=&otherVersion= → the lines a version adds and removes against another, or `(empty)`, and
|
|
146
|
-
// those
|
|
147
|
+
// those of each file as Compare draws it with the fewest (`best`), and whether binary files changed
|
|
147
148
|
// | 400/401/404/413/422/429/502/503/504
|
|
148
149
|
// GET /api/npm/risk?name=&version=&otherVersion= → what calls for a look at a version, as risk tells it, against another where given | 400/401/404/413/429/502
|
|
149
150
|
// POST /api/auth/logout → same-origin + CSRF, drops the session (and any view)
|
|
@@ -280,6 +281,7 @@ import { npmProvenance } from './npm-provenance.ts'
|
|
|
280
281
|
import { npmReadyScanDownload, npmReadyScanDownloads, npmRisk, npmRiskRemoved } from './npm-risk.ts'
|
|
281
282
|
import { NpmRiskError } from '../risk/index.js'
|
|
282
283
|
import { type ComparedSide, type PrettyCache, PrettyError, type PrettyRequest, compared, prettyRequest, prettyText } from './pretty-print.ts'
|
|
284
|
+
import { npmCopies } from './pretty-copies.ts'
|
|
283
285
|
import { renameDiffOf, renameDiffRequest, renamedPairs } from './rename-diff.ts'
|
|
284
286
|
import { runsAsked, typeOnlyFiles } from './type-only.ts'
|
|
285
287
|
import { comparisonBody, emptySide, npmComparedSide, patchedVersionBody } from './comparison.ts'
|
|
@@ -5441,7 +5443,7 @@ const MAX_ASKED_DELTAS = 50
|
|
|
5441
5443
|
const DELTAS_AT_ONCE = 2
|
|
5442
5444
|
// A version as npmDelta takes it: its integrity, and its files, loaded as
|
|
5443
5445
|
// they are asked for and released once read.
|
|
5444
|
-
const deltaSide = (doc: NpmVersionDocument) => ({ integrity: doc.dist.integrity, files: async () => {
|
|
5446
|
+
const deltaSide = (doc: NpmVersionDocument, npm?: CacheStorage) => ({ integrity: doc.dist.integrity, copies: npm ? npmCopies(npm, doc) : null, files: async () => {
|
|
5445
5447
|
const load = loadNpmFiles(doc)
|
|
5446
5448
|
try { return await load.result } finally { load.release() }
|
|
5447
5449
|
} })
|
|
@@ -5479,10 +5481,10 @@ async function handleNpmDeltas(req: IncomingMessage, res: ServerResponse, deps:
|
|
|
5479
5481
|
isPrivate = doc.private
|
|
5480
5482
|
oldPrivate = old?.private === true
|
|
5481
5483
|
const patched = patch && await (patches.get(patch.hash) ?? patches.set(patch.hash, npmPatchOf(deps, cookie, patch)).get(patch.hash)!)
|
|
5482
|
-
const side = deltaSide(doc)
|
|
5484
|
+
const side = deltaSide(doc, deps.npmCacheStorage)
|
|
5483
5485
|
if (patched && 'error' in patched) line = { ...asOne, error: patched.error, status: patched.status }
|
|
5484
5486
|
else {
|
|
5485
|
-
const delta = await npmDelta(old ? deltaSide(old) : null,
|
|
5487
|
+
const delta = await npmDelta(old ? deltaSide(old, deps.npmCacheStorage) : null,
|
|
5486
5488
|
patched ? { integrity: `${side.integrity} patch:${patch.hash}`, files: async () => patchedFiles(await side.files(), patched.files) } : side, kept)
|
|
5487
5489
|
if (!patched && !doc.private && !old?.private) await byVersions.write(versionDeltaKey(doc.name, doc.version, old?.name ?? name, old?.version ?? '(empty)'), delta, Date.now())
|
|
5488
5490
|
line = { ...asOne, ...delta }
|
|
@@ -5642,12 +5644,12 @@ async function handleNpm(req: IncomingMessage, res: ServerResponse, deps: Manage
|
|
|
5642
5644
|
}
|
|
5643
5645
|
if (path === NPM_PROVENANCE_PATH) { await reply(doc.private, { name, version: doc.version, provenance: await provenanceOf() }); return }
|
|
5644
5646
|
// The lines it changes against `otherVersion`, or `(empty)`, its whole
|
|
5645
|
-
// package's, and those
|
|
5646
|
-
//
|
|
5647
|
+
// package's, and those of each file at its fewest (npm-delta.ts), as a
|
|
5648
|
+
// list of versions wanting reviews tells them.
|
|
5647
5649
|
if (path === NPM_DELTA_PATH) {
|
|
5648
5650
|
const old = otherSpec === '(empty)' ? null : await otherDoc()
|
|
5649
5651
|
dropIdle(res)
|
|
5650
|
-
const delta = await npmDelta(old ? deltaSide(old) : null, deltaSide(doc), npmDeltaStore<NpmDelta>(deps.db, deps.config.debug))
|
|
5652
|
+
const delta = await npmDelta(old ? deltaSide(old, deps.npmCacheStorage) : null, deltaSide(doc, deps.npmCacheStorage), npmDeltaStore<NpmDelta>(deps.db, deps.config.debug))
|
|
5651
5653
|
await reply(doc.private || old?.private === true, { name, version: doc.version, otherVersion: old?.version ?? null, ...delta })
|
|
5652
5654
|
return
|
|
5653
5655
|
}
|
|
@@ -5693,7 +5695,7 @@ async function handleNpm(req: IncomingMessage, res: ServerResponse, deps: Manage
|
|
|
5693
5695
|
if (!deps.prettyCache) { sendJson(res, 503, { error: 'unavailable' }); return }
|
|
5694
5696
|
const copy = await deps.prettyCache.npm(doc, file)
|
|
5695
5697
|
if (!(await recheck(doc.private))) { copy.stream.destroy(); return }
|
|
5696
|
-
await sendEncoded(req, res, copy, '
|
|
5698
|
+
await sendEncoded(req, res, copy, 'application/json', prettySource(file))
|
|
5697
5699
|
return
|
|
5698
5700
|
}
|
|
5699
5701
|
// Against another version, the pairs of its files that changed that the
|
|
@@ -6084,7 +6086,7 @@ export function createManagedRequestHandler(deps: ManagedHttpDeps): Handler {
|
|
|
6084
6086
|
if (part !== 'pretty') { await handleBundleCache(req, res, deps, session, id, bundleCache && (rec => bundleCache.open(rec, part as BundleCachePart))); return }
|
|
6085
6087
|
const file = prettyRequest(url.searchParams)
|
|
6086
6088
|
if (!file) { sendJson(res, 400, { error: 'bad-file' }); return }
|
|
6087
|
-
await handleBundleCache(req, res, deps, session, id, prettyCache && (rec => prettyCache.bundle(rec, file)), '
|
|
6089
|
+
await handleBundleCache(req, res, deps, session, id, prettyCache && (rec => prettyCache.bundle(rec, file)), 'application/json', prettySource(file))
|
|
6088
6090
|
return
|
|
6089
6091
|
}
|
|
6090
6092
|
if (path === BUNDLE_CREATE_PATH) {
|
|
@@ -1,23 +1,69 @@
|
|
|
1
1
|
// The lines a package's files change from one side to another (npm-delta.ts),
|
|
2
2
|
// as @preventive/compare's compareTrees counts them (git's --numstat), off
|
|
3
3
|
// the server's event loop: of its text files, renames found as git finds
|
|
4
|
-
// them, a side not there empty; and
|
|
5
|
-
//
|
|
4
|
+
// them, a side not there empty; and each file's fewest (`best`), as Compare
|
|
5
|
+
// can draw it: as published, without type-only and whitespace changes, or
|
|
6
|
+
// pretty-printed too: by Compare's copies where kept (`copies`), else made and
|
|
7
|
+
// told (`made`), as `complete` where none was left for want of time.
|
|
6
8
|
import { parentPort, workerData } from 'node:worker_threads'
|
|
7
9
|
import { compareTrees } from '@preventive/compare'
|
|
10
|
+
import { changeBlocks, indentHiddenBlocks, withSharedBlankLines } from '../common/line-diff.js'
|
|
11
|
+
import { jsonPrinted, prettyJsonText } from '../common/pretty-json.js'
|
|
12
|
+
import { prettyExtension, printableSize } from '../common/pretty-print.js'
|
|
13
|
+
import { whitespaceInsensitive } from '../common/whitespace-insensitive.js'
|
|
14
|
+
import { prettyFormat } from './pretty-format.js'
|
|
15
|
+
|
|
16
|
+
const { base, copies, other, prettyUntil } = workerData
|
|
17
|
+
const kept = new Map(copies.map(([at, path, copy]) => [`${at}\0${path}`, copy])), made = []
|
|
18
|
+
const NONE = { additions: 0, deletions: 0 }
|
|
19
|
+
const least = (a, b) => (b.additions < a.additions || (b.additions === a.additions && b.deletions < a.deletions) ? b : a)
|
|
20
|
+
const counted = (before, after, insensitive) => (insensitive ? indentHiddenBlocks(before, after) : changeBlocks(before, after))
|
|
21
|
+
.reduce((sum, { a0, a1, b0, b1 }) => ({ additions: sum.additions + b1 - b0, deletions: sum.deletions + a1 - a0 }), NONE)
|
|
22
|
+
|
|
23
|
+
// A side's file (`at` 0 the base, 1 the other) as Compare's pretty-print toggle prints it, or null.
|
|
24
|
+
async function printed(at, path, text) {
|
|
25
|
+
const copy = kept.get(`${at}\0${path}`)
|
|
26
|
+
if (copy) return copy
|
|
27
|
+
try {
|
|
28
|
+
if (!printableSize(text)) return null
|
|
29
|
+
const extension = prettyExtension(path), json = jsonPrinted(path) ? prettyJsonText(text, { width: 0 }) : null
|
|
30
|
+
if (json !== null) return { text: json, blank: [] }
|
|
31
|
+
const result = extension && await prettyFormat(text, extension)
|
|
32
|
+
if (!result || 'error' in result) return null
|
|
33
|
+
made.push([at, path, result])
|
|
34
|
+
return result
|
|
35
|
+
} catch {
|
|
36
|
+
return null
|
|
37
|
+
}
|
|
38
|
+
}
|
|
8
39
|
|
|
9
40
|
const tree = files => files.map(([name, data]) => ({ name, data }))
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
for (const change of changes) {
|
|
41
|
+
const best = { ...NONE }, printing = [], total = { ...NONE }
|
|
42
|
+
for (const change of compareTrees(tree(base), tree(other), { paths: 'keys', lines: true, renames: true })) {
|
|
13
43
|
if (change.binary) continue
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
44
|
+
const published = { additions: change.insertions ?? 0, deletions: change.deletions ?? 0 }
|
|
45
|
+
const after = change.new?.data ?? '', before = change.old?.data ?? ''
|
|
46
|
+
const insensitive = before !== '' && after !== '' && whitespaceInsensitive(change.old.path, before) && whitespaceInsensitive(change.new.path, after)
|
|
47
|
+
// Additions less deletions is the same for any diff, so one with none of either is at its least.
|
|
48
|
+
const fewest = change.typeOnly ? NONE : insensitive && published.additions && published.deletions ? least(published, counted(before, after, true)) : published
|
|
49
|
+
for (const [sum, count] of [[total, published], [best, fewest]]) {
|
|
50
|
+
sum.additions += count.additions
|
|
51
|
+
sum.deletions += count.deletions
|
|
52
|
+
}
|
|
53
|
+
// Compare prints a file one side alone has only where that lengthens it.
|
|
54
|
+
if (fewest.additions + fewest.deletions > 0 && before !== '' && after !== '') printing.push({ from: change.old.path, to: change.new.path, before, after, insensitive, fewest })
|
|
55
|
+
}
|
|
56
|
+
// Smallest first, so the time left goes to the most files.
|
|
57
|
+
let complete = true
|
|
58
|
+
for (const file of printing.toSorted((a, b) => a.before.length + a.after.length - b.before.length - b.after.length)) {
|
|
59
|
+
if (Date.now() >= prettyUntil) { complete = false; break }
|
|
60
|
+
const [a, b] = [await printed(0, file.from, file.before), await printed(1, file.to, file.after)]
|
|
61
|
+
if (a === null || b === null) continue
|
|
62
|
+
const { before, after } = withSharedBlankLines(a.text, b.text, a.blank, b.blank)
|
|
63
|
+
const now = least(file.fewest, counted(before, after, file.insensitive))
|
|
64
|
+
best.additions += now.additions - file.fewest.additions
|
|
65
|
+
best.deletions += now.deletions - file.fewest.deletions
|
|
20
66
|
}
|
|
21
67
|
// Node worker messages have no browser target origin.
|
|
22
68
|
// oxlint-disable-next-line unicorn/require-post-message-target-origin
|
|
23
|
-
parentPort.postMessage(
|
|
69
|
+
parentPort.postMessage({ ...total, best, complete, made })
|
|
@@ -2,33 +2,41 @@
|
|
|
2
2
|
// its whole package's (GET /api/npm/delta), as a list of versions wanting
|
|
3
3
|
// reviews tells them beside each: added and removed (`additions`,
|
|
4
4
|
// `deletions`), as git's --numstat counts them, of their text files, a
|
|
5
|
-
// renamed one diffed with what it was;
|
|
6
|
-
//
|
|
7
|
-
// types alone (`typeOnly`, proveTypeOnly: types and comments alone erased,
|
|
8
|
-
// the runtime they leave as it was, an added one's empty or a single bare
|
|
9
|
-
// `export {}`), those of the rest (`typeless`), what a reviewer may pass by
|
|
10
|
-
// leaving those out; and whether a binary file, which they count none of,
|
|
5
|
+
// renamed one diffed with what it was; each file's fewest as Compare can
|
|
6
|
+
// draw it (`best`); and whether a binary file, which they count none of,
|
|
11
7
|
// was added, removed or changed (`binary`), one moved as it was not. Worked
|
|
12
8
|
// out in a worker, off the event loop, as many at once per process as
|
|
13
9
|
// MAX_ACTIVE, both sides' files read together only once their turn has come,
|
|
14
10
|
// those waiting past MAX_WAITING refused, each waiting a minute at most and
|
|
15
11
|
// counting in a minute at most; one asked again meanwhile sharing the
|
|
16
12
|
// first's; and kept by both sides' integrities, in this instance and beyond
|
|
17
|
-
// it (`kept`), what a version holds never changing
|
|
18
|
-
//
|
|
13
|
+
// it (`kept`), what a version holds never changing, but for one whose copies
|
|
14
|
+
// weren't all printed in time (`partial`). Its pretty-printed copies are
|
|
15
|
+
// Compare's, read and kept as Compare keeps them (`copies`). Access is the
|
|
16
|
+
// caller's to check.
|
|
19
17
|
import { createHash } from 'node:crypto'
|
|
18
|
+
import { layoutBlankList, prettyExtension } from '../common/pretty-print.js'
|
|
20
19
|
import { type KeptStore, VERSION_DELTA_KEPT_MS } from './npm-kept.ts'
|
|
21
20
|
import { type Lru, lru } from './lru.ts'
|
|
22
21
|
import { NpmPackageError, type NpmPackageFile, npmFileText } from './npm-packages.ts'
|
|
22
|
+
import { PRETTY_VERSION, type PrettyCopy } from './pretty-format.js'
|
|
23
|
+
import type { KeptCopies } from './pretty-copies.ts'
|
|
24
|
+
import { eachOf } from './queue.ts'
|
|
23
25
|
import { workerTurns } from './worker-turns.ts'
|
|
24
26
|
|
|
25
|
-
export interface NpmDelta { additions: number; deletions: number;
|
|
27
|
+
export interface NpmDelta { additions: number; deletions: number; best: { additions: number; deletions: number }; binary: boolean; partial?: true }
|
|
26
28
|
|
|
27
29
|
const MAX_ACTIVE = 2
|
|
28
30
|
const MAX_WAITING = 64
|
|
29
31
|
const DELTA_TIMEOUT_MS = 60_000
|
|
32
|
+
// No file is begun pretty-printing in this last part of it, as one may take seconds.
|
|
33
|
+
const PRETTY_MARGIN_MS = 15_000
|
|
30
34
|
// The text the two sides may hold together, past which none is counted.
|
|
31
35
|
const MAX_TEXT_LENGTH = 64 * 1024 * 1024
|
|
36
|
+
// Bumped when what a delta counts changes; its keys carry it and PRETTY_VERSION, so none counted otherwise is read.
|
|
37
|
+
const DELTA_VERSION = 1
|
|
38
|
+
const COUNTING = `v${DELTA_VERSION}.${PRETTY_VERSION}`
|
|
39
|
+
const COPIES_AT_ONCE = 8
|
|
32
40
|
|
|
33
41
|
const deltas: Lru<NpmDelta> = lru(20_000)
|
|
34
42
|
const working = new Map<string, Promise<NpmDelta>>()
|
|
@@ -37,22 +45,25 @@ const workers = workerTurns({ what: 'package delta', active: MAX_ACTIVE, waiting
|
|
|
37
45
|
|
|
38
46
|
const lines = (told: unknown): told is { additions: number; deletions: number } => typeof told === 'object' && told !== null
|
|
39
47
|
&& Number.isSafeInteger((told as { additions?: unknown }).additions) && Number.isSafeInteger((told as { deletions?: unknown }).deletions)
|
|
40
|
-
// A delta as kept, none where it isn't one, or
|
|
41
|
-
// binary files.
|
|
48
|
+
// A delta as kept, none where it isn't one, or is partial.
|
|
42
49
|
function deltaOf(told: unknown): NpmDelta | null {
|
|
43
50
|
if (!lines(told)) return null
|
|
44
|
-
const {
|
|
45
|
-
return
|
|
51
|
+
const { best, binary, partial } = told as { best?: unknown; binary?: unknown; partial?: unknown }
|
|
52
|
+
return lines(best) && typeof binary === 'boolean' && partial === undefined
|
|
53
|
+
? { additions: told.additions, deletions: told.deletions, best: { additions: best.additions, deletions: best.deletions }, binary } : null
|
|
46
54
|
}
|
|
47
55
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
56
|
+
// A copy by side (0 the base, 1 the other) and path, as the worker reads and makes them.
|
|
57
|
+
type SideCopy = [number, string, PrettyCopy]
|
|
58
|
+
type Counted = Omit<NpmDelta, 'binary' | 'partial'> & { complete: boolean; made: SideCopy[] }
|
|
59
|
+
const isCounted = (told: unknown): told is Counted => lines(told) && lines((told as { best?: unknown }).best)
|
|
60
|
+
&& typeof (told as { complete?: unknown }).complete === 'boolean' && Array.isArray((told as { made?: unknown }).made)
|
|
61
|
+
const isCopy = (copy: unknown): copy is PrettyCopy => typeof (copy as { text?: unknown } | null)?.text === 'string' && layoutBlankList((copy as { blank?: unknown }).blank) !== null
|
|
51
62
|
|
|
52
|
-
// What the worker counts of `base` against `other`, each its text files' paths and texts.
|
|
53
|
-
function counted(base: [string, string][], other: [string, string][], deadline: number): Promise<Counted> {
|
|
63
|
+
// What the worker counts of `base` against `other`, each its text files' paths and texts, given the copies kept.
|
|
64
|
+
function counted(base: [string, string][], other: [string, string][], copies: SideCopy[], deadline: number): Promise<Counted> {
|
|
54
65
|
return workers.run(new URL('./npm-delta-worker.js', import.meta.url), {
|
|
55
|
-
workerData: { base, other }, execArgv: ['--disable-warning=ExperimentalWarning'], resourceLimits: { maxOldGenerationSizeMb: 1536 },
|
|
66
|
+
workerData: { base, other, copies, prettyUntil: deadline - PRETTY_MARGIN_MS }, execArgv: ['--disable-warning=ExperimentalWarning'], resourceLimits: { maxOldGenerationSizeMb: 1536 },
|
|
56
67
|
}, told => (isCounted(told) ? told : null), deadline)
|
|
57
68
|
}
|
|
58
69
|
|
|
@@ -100,15 +111,15 @@ function binaryChanged(olds: NpmPackageFile[], news: NpmPackageFile[]): boolean
|
|
|
100
111
|
})
|
|
101
112
|
}
|
|
102
113
|
|
|
103
|
-
type Side = { integrity: string; files: () => Promise<NpmPackageFile[]
|
|
114
|
+
type Side = { integrity: string; files: () => Promise<NpmPackageFile[]>; copies?: KeptCopies | null }
|
|
104
115
|
// A delta's key: the integrities of the version it is against, or none, and
|
|
105
116
|
// of the version.
|
|
106
|
-
export const deltaKey = (base: string | null, other: string) => `${base ?? '(empty)'}\0${other}`
|
|
117
|
+
export const deltaKey = (base: string | null, other: string) => `${COUNTING}\0${base ?? '(empty)'}\0${other}`
|
|
107
118
|
// The same of two public versions by their names and versions (`(empty)`
|
|
108
119
|
// for none), as npm never gives one other files: its key in
|
|
109
120
|
// npmVersionDeltaStore.
|
|
110
121
|
export const versionDeltaKey = (name: string, version: string, otherName: string, otherVersion: string) =>
|
|
111
|
-
`${name}@${version}\0${otherVersion === '(empty)' ? '(empty)' : `${otherName}@${otherVersion}`}`
|
|
122
|
+
`${COUNTING}\0${name}@${version}\0${otherVersion === '(empty)' ? '(empty)' : `${otherName}@${otherVersion}`}`
|
|
112
123
|
// Those of `keys` (versionDeltaKey) kept, by key, as of `now`: one kept past
|
|
113
124
|
// VERSION_DELTA_KEPT_MS not, though no write has pruned it yet.
|
|
114
125
|
export async function keptVersionDeltas(keys: string[], kept: KeptStore<NpmDelta>, now = Date.now()): Promise<Map<string, NpmDelta>> {
|
|
@@ -152,11 +163,21 @@ export async function keptNpmDeltas(sides: [string | null, string][], kept: Kept
|
|
|
152
163
|
return found
|
|
153
164
|
}
|
|
154
165
|
|
|
155
|
-
//
|
|
166
|
+
// Those kept of the printable files both sides have, changed, by side and path.
|
|
167
|
+
async function keptCopies(sides: (Side | null)[], files: Map<string, Uint8Array>[]): Promise<SideCopy[]> {
|
|
168
|
+
const changed = [...files[1]!].filter(([path, bytes]) => prettyExtension(path) !== null && files[0]!.has(path) && !same(files[0]!.get(path)!, bytes))
|
|
169
|
+
const asked = changed.flatMap(([path]) => [0, 1].map(at => [at, path] as const)).filter(([at]) => sides[at]?.copies)
|
|
170
|
+
const found = await eachOf(asked, COPIES_AT_ONCE, async ([at, path]) => [at, path, await sides[at]!.copies!.kept(path, files[at]!.get(path)!).catch(() => null)] as const)
|
|
171
|
+
return found.filter((copy): copy is SideCopy => copy[2] !== null)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// As kept, else its turn awaited, then both sides' files read, counted and
|
|
175
|
+
// kept, the copies it printed kept for Compare.
|
|
156
176
|
async function worked(key: string, base: Side | null, other: Side, kept: KeptStore<NpmDelta> | null): Promise<NpmDelta> {
|
|
157
177
|
const known = deltaOf((await kept?.read(key))?.value)
|
|
158
178
|
if (known) { deltas.set(key, known); return known }
|
|
159
|
-
const
|
|
179
|
+
const sides = [base, other]
|
|
180
|
+
const [delta, made, files] = await workers.inTurn(Date.now() + DELTA_TIMEOUT_MS, async () => {
|
|
160
181
|
// Its turn held till both sides are read, or have failed.
|
|
161
182
|
const [baseRead, otherRead] = await Promise.allSettled([base ? base.files() : Promise.resolve(null), other.files()])
|
|
162
183
|
if (baseRead.status === 'rejected') throw baseRead.reason
|
|
@@ -164,11 +185,14 @@ async function worked(key: string, base: Side | null, other: Side, kept: KeptSto
|
|
|
164
185
|
const [olds, news] = [texts(baseRead.value), texts(otherRead.value)]
|
|
165
186
|
if (olds.length + news.length > MAX_TEXT_LENGTH) throw new NpmPackageError(413, 'package-too-large')
|
|
166
187
|
const binary = binaryChanged(olds.binaries, news.binaries)
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
188
|
+
const byPath = [baseRead.value ?? [], otherRead.value].map(side => new Map(side.filter(file => file.link === undefined).map(file => [file.path, file.bytes])))
|
|
189
|
+
const told = await counted(olds.read, news.read, await keptCopies(sides, byPath), Date.now() + DELTA_TIMEOUT_MS)
|
|
190
|
+
const counts: NpmDelta = { additions: told.additions, deletions: told.deletions, best: told.best, binary, ...told.complete ? {} : { partial: true as const } }
|
|
191
|
+
return [counts, told.made, byPath] as const
|
|
170
192
|
})
|
|
171
193
|
deltas.set(key, delta)
|
|
172
|
-
await kept?.write(key, delta, Date.now())
|
|
194
|
+
if (!delta.partial) await kept?.write(key, delta, Date.now())
|
|
195
|
+
await eachOf(made.filter(([at, path, copy]) => sides[at]?.copies && files[at]?.has(path) && isCopy(copy)), COPIES_AT_ONCE,
|
|
196
|
+
([at, path, copy]) => sides[at]!.copies!.keep(path, files[at]!.get(path)!, copy))
|
|
173
197
|
return delta
|
|
174
198
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// A public version's pretty-printed copies as Compare keeps them (pretty-print.ts), by its files'
|
|
2
|
+
// paths and bytes, for a delta to read and keep (npm-delta.ts); none for a private version.
|
|
3
|
+
import { prettyExtension } from '../common/pretty-print.js'
|
|
4
|
+
import { encodeBrotli } from './brotli.ts'
|
|
5
|
+
import type { CacheStorage } from './cache-storage.ts'
|
|
6
|
+
import type { NpmVersionDocument } from './npm-packages.ts'
|
|
7
|
+
import type { PrettyCopy } from './pretty-format.js'
|
|
8
|
+
import { keep, kept, npmFileHash, prettyCopy, prettyFile } from './pretty-print.ts'
|
|
9
|
+
|
|
10
|
+
export interface KeptCopies { kept(path: string, bytes: Uint8Array): Promise<PrettyCopy | null>; keep(path: string, bytes: Uint8Array, copy: PrettyCopy): Promise<void> }
|
|
11
|
+
|
|
12
|
+
export function npmCopies(npm: CacheStorage, doc: NpmVersionDocument): KeptCopies | null {
|
|
13
|
+
if (doc.private) return null
|
|
14
|
+
const file = async (path: string, bytes: Uint8Array) => prettyFile({ path, hash: await npmFileHash(bytes), extension: prettyExtension(path) ?? '' })
|
|
15
|
+
return {
|
|
16
|
+
async kept(path, bytes) {
|
|
17
|
+
const copy = await kept(async () => npm.open(await file(path, bytes)))
|
|
18
|
+
return copy && prettyCopy(copy)
|
|
19
|
+
},
|
|
20
|
+
keep: (path, bytes, copy) => keep(async () => npm.put(await file(path, bytes), await encodeBrotli(Buffer.from(JSON.stringify(copy))))),
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// A file pretty-printed as Compare draws it, with its copy's layout blank lines: the server's
|
|
2
|
+
// copies (pretty-print.ts) and a delta's (npm-delta-worker.js) alike.
|
|
3
|
+
import { format, layoutBlankLines } from '@preventive/compare/pretty.js'
|
|
4
|
+
|
|
5
|
+
// Part of every kept copy's name; bumped when what the formatter writes for
|
|
6
|
+
// the same file changes, or what its check lets through, so copies written
|
|
7
|
+
// before are no longer read.
|
|
8
|
+
export const PRETTY_VERSION = 6
|
|
9
|
+
|
|
10
|
+
export async function prettyFormat(text, extension) {
|
|
11
|
+
const result = await format(text, extension)
|
|
12
|
+
return 'error' in result ? result : { text: result.code, blank: await layoutBlankLines(result.code, extension) }
|
|
13
|
+
}
|
|
@@ -2,7 +2,9 @@
|
|
|
2
2
|
// one file at a time, GET /api/npm/pretty all a version's at once), and the
|
|
3
3
|
// files that changed between two bundles or versions for Compare (the same
|
|
4
4
|
// with `other`, or `otherVersion`), named by path and content hash, formatted
|
|
5
|
-
// with oxfmt once
|
|
5
|
+
// with oxfmt once, with the copy's blank lines that are its layout alone
|
|
6
|
+
// (@preventive/compare layoutBlankLines), which Compare leaves out where one
|
|
7
|
+
// side alone has them, and kept Brotli-encoded by that hash: a bundle's in its
|
|
6
8
|
// cache directory (so only made from, and read by readers of, that bundle), a
|
|
7
9
|
// public npm version's under `cache/npm/`; a private version's are never
|
|
8
10
|
// kept. Access is the caller's to check.
|
|
@@ -10,12 +12,11 @@ import { Buffer } from 'node:buffer'
|
|
|
10
12
|
import { Readable } from 'node:stream'
|
|
11
13
|
import { promisify } from 'node:util'
|
|
12
14
|
import { brotliDecompress } from 'node:zlib'
|
|
13
|
-
import { format } from '@preventive/compare/pretty.js'
|
|
14
15
|
import { computeFileHash } from '@preventive/report'
|
|
15
16
|
import { FILE_HASH, computeBundleFileHashes } from '../common/bundle-metadata.js'
|
|
16
17
|
import { bundleCompareFiles, bundleCompareSideScopes } from '../common/bundle-compare-inputs.js'
|
|
17
18
|
import { bundlePackageDirs, bundleSourcesAsMap } from '../common/bundle-sources.js'
|
|
18
|
-
import { MAX_PRETTY_BYTES, needsPrettyPrint, prettyExtension } from '../common/pretty-print.js'
|
|
19
|
+
import { MAX_PRETTY_BYTES, layoutBlankList, needsPrettyPrint, prettyExtension } from '../common/pretty-print.js'
|
|
19
20
|
import { type OpenedBlob, readBytes } from './blob-store.ts'
|
|
20
21
|
import { type BundleCacheStorage, readSizedBundleDetails } from './bundle-cache.ts'
|
|
21
22
|
import type { BundleStore } from './bundle-store.ts'
|
|
@@ -26,11 +27,8 @@ import { keptBriefly } from './kept-briefly.ts'
|
|
|
26
27
|
import { loadNpmFiles } from './npm-loads.ts'
|
|
27
28
|
import { type NpmVersionDocument, npmFileText, pathOrder } from './npm-packages.ts'
|
|
28
29
|
import { inTurns } from './queue.ts'
|
|
30
|
+
import { PRETTY_VERSION, type PrettyCopy, prettyFormat } from './pretty-format.js'
|
|
29
31
|
|
|
30
|
-
// Part of every kept copy's name; bumped when what the formatter writes for
|
|
31
|
-
// the same file changes, or what its check lets through, so copies written
|
|
32
|
-
// before are no longer read.
|
|
33
|
-
const PRETTY_VERSION = 5
|
|
34
32
|
// Formats running at once per process, each holding its file's syntax tree,
|
|
35
33
|
// and those waiting their turn past them (a version's files are formatted one
|
|
36
34
|
// after another, beside other readers'), any more refused.
|
|
@@ -59,9 +57,9 @@ export class PrettyError extends Error {
|
|
|
59
57
|
export interface PrettyRequest { path: string; hash: string; extension: string }
|
|
60
58
|
|
|
61
59
|
// One of a version's files pretty-printed (npmAll), named by `source`, the
|
|
62
|
-
// hash of the file it was formatted from: its copy's text
|
|
63
|
-
// none, as a PrettyError tells it.
|
|
64
|
-
export type PrettyLine = { path: string; source: string; text: string } | { path: string; source: string; error: string; status: number }
|
|
60
|
+
// hash of the file it was formatted from: its copy's text and layout blank
|
|
61
|
+
// lines (prettyCopy), or why it has none, as a PrettyError tells it.
|
|
62
|
+
export type PrettyLine = { path: string; source: string; text: string; blank: number[] } | { path: string; source: string; error: string; status: number }
|
|
65
63
|
|
|
66
64
|
// Which of a comparison's two its files are of: the bundle or version asked
|
|
67
65
|
// about, or the `other`.
|
|
@@ -94,22 +92,25 @@ export function prettyRequest(params: URLSearchParams): PrettyRequest | null {
|
|
|
94
92
|
}
|
|
95
93
|
|
|
96
94
|
// A copy's name: its file's hash in hex, with the extension it was parsed by.
|
|
97
|
-
const prettyFile = ({ hash, extension }: PrettyRequest) =>
|
|
95
|
+
export const prettyFile = ({ hash, extension }: PrettyRequest) =>
|
|
98
96
|
`pretty-v${PRETTY_VERSION}/${Buffer.from(hash.slice('sha512-'.length), 'base64').toString('hex')}.${extension}.br`
|
|
99
97
|
|
|
100
98
|
let activeFormats = 0
|
|
101
99
|
const waitingFormats: Array<() => void> = []
|
|
102
100
|
|
|
103
|
-
// The text formatted
|
|
104
|
-
//
|
|
105
|
-
//
|
|
101
|
+
// 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
|
+
// refused as `unsupported` where it has no check for the kind of file,
|
|
105
|
+
// `unformattable` or `pretty-mismatch`. Its blank lines are read in the
|
|
106
|
+
// same turn, as they parse and check the copy again.
|
|
106
107
|
export async function prettyBody(text: string, extension: string): Promise<Buffer> {
|
|
107
108
|
if (Buffer.byteLength(text) > MAX_PRETTY_BYTES) throw new PrettyError(413, 'file-too-large')
|
|
108
109
|
if (activeFormats < MAX_ACTIVE_FORMATS) activeFormats++
|
|
109
110
|
else if (waitingFormats.length >= MAX_WAITING_FORMATS) throw new PrettyError(429, 'pretty-busy')
|
|
110
111
|
else await new Promise<void>(resolve => { waitingFormats.push(resolve) })
|
|
111
112
|
let result
|
|
112
|
-
try { result = await
|
|
113
|
+
try { result = await prettyFormat(text, extension) }
|
|
113
114
|
finally {
|
|
114
115
|
const next = waitingFormats.shift()
|
|
115
116
|
if (next) next()
|
|
@@ -119,7 +120,7 @@ export async function prettyBody(text: string, extension: string): Promise<Buffe
|
|
|
119
120
|
if (result.error === 'pretty-mismatch') console.warn(`managed: pretty-printing a .${extension} file changed more than its layout; not served`)
|
|
120
121
|
throw new PrettyError(422, result.error)
|
|
121
122
|
}
|
|
122
|
-
return encodeBrotli(Buffer.from(result
|
|
123
|
+
return encodeBrotli(Buffer.from(JSON.stringify(result)))
|
|
123
124
|
}
|
|
124
125
|
|
|
125
126
|
export const opened = (body: Buffer): OpenedBlob => ({ size: body.byteLength, stream: Readable.from([body]) })
|
|
@@ -127,7 +128,7 @@ export const opened = (body: Buffer): OpenedBlob => ({ size: body.byteLength, st
|
|
|
127
128
|
// A version's file's hash, by its bytes: those of a version's files loaded
|
|
128
129
|
// a little while since are the same bytes (npm-loads.ts), hashed once.
|
|
129
130
|
const fileHashes = new WeakMap<Uint8Array, Promise<string>>()
|
|
130
|
-
function npmFileHash(bytes: Uint8Array): Promise<string> {
|
|
131
|
+
export function npmFileHash(bytes: Uint8Array): Promise<string> {
|
|
131
132
|
let hash = fileHashes.get(bytes)
|
|
132
133
|
if (!hash) {
|
|
133
134
|
fileHashes.set(bytes, hash = computeFileHash(bytes))
|
|
@@ -138,9 +139,18 @@ function npmFileHash(bytes: Uint8Array): Promise<string> {
|
|
|
138
139
|
|
|
139
140
|
const decompress = promisify(brotliDecompress)
|
|
140
141
|
|
|
141
|
-
// A pretty-printed copy's text, from its Brotli-encoded
|
|
142
|
+
// A pretty-printed copy's text and layout blank lines, from its Brotli-encoded
|
|
143
|
+
// bytes (prettyBody).
|
|
144
|
+
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
|
+
if (typeof text !== 'string' || !numbers) throw new Error('managed: a kept pretty-printed copy is not one')
|
|
148
|
+
return { text, blank: numbers }
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// A pretty-printed copy's text alone, as a rename diff reads it.
|
|
142
152
|
export async function prettyText(copy: OpenedBlob): Promise<string> {
|
|
143
|
-
return (await
|
|
153
|
+
return (await prettyCopy(copy)).text
|
|
144
154
|
}
|
|
145
155
|
|
|
146
156
|
// Every file of a version that needs pretty-printing (needsPrettyPrint), read
|
|
@@ -159,10 +169,10 @@ async function npmPrintable(doc: NpmVersionDocument): Promise<Array<PrettyReques
|
|
|
159
169
|
return files.toSorted((a, b) => pathOrder(a.path, b.path))
|
|
160
170
|
}
|
|
161
171
|
|
|
162
|
-
// A file's line (PrettyLine): the text of its copy
|
|
163
|
-
// it has none.
|
|
172
|
+
// A file's line (PrettyLine): the text of its copy and its layout blank lines,
|
|
173
|
+
// as `copy` has them, or why it has none.
|
|
164
174
|
async function prettyLine({ path, hash }: PrettyRequest, copy: () => Promise<OpenedBlob>): Promise<PrettyLine> {
|
|
165
|
-
try { return { path, source: hash,
|
|
175
|
+
try { return { path, source: hash, ...await prettyCopy(await copy()) } }
|
|
166
176
|
catch (err) {
|
|
167
177
|
if (!(err instanceof PrettyError)) throw err
|
|
168
178
|
return { path, source: hash, error: err.message, status: err.status }
|
|
@@ -233,12 +243,12 @@ function sharing<T>(): (key: string, make: () => Promise<T>) => Promise<T> {
|
|
|
233
243
|
}
|
|
234
244
|
}
|
|
235
245
|
|
|
236
|
-
async function keep(put: () => Promise<void>) {
|
|
246
|
+
export async function keep(put: () => Promise<void>) {
|
|
237
247
|
try { await put() } catch (err) { console.warn('managed: pretty-print cache write failed:', err) }
|
|
238
248
|
}
|
|
239
249
|
|
|
240
250
|
// A copy kept, or null where none is.
|
|
241
|
-
async function kept(open: () => Promise<OpenedBlob>): Promise<OpenedBlob | null> {
|
|
251
|
+
export async function kept(open: () => Promise<OpenedBlob>): Promise<OpenedBlob | null> {
|
|
242
252
|
try { return await open() }
|
|
243
253
|
catch (err) { if (err instanceof CacheMissError) return null; throw err }
|
|
244
254
|
}
|
|
@@ -197,7 +197,7 @@ async function serveBundle(res: ServerResponse, deps: ManagedHttpDeps, bundle: M
|
|
|
197
197
|
if (!prettyCache) { json(res, 503, { error: 'unavailable' }); return }
|
|
198
198
|
const pretty = await prettyOr(res, () => prettyCache.bundle(bundle, file))
|
|
199
199
|
if (pretty === undefined) return
|
|
200
|
-
await stream(pretty, 'br', '
|
|
200
|
+
await stream(pretty, 'br', 'application/json'); return
|
|
201
201
|
}
|
|
202
202
|
if (!deps.bundleCache) { json(res, 503, { error: 'unavailable' }); return }
|
|
203
203
|
if (part === 'advisories') {
|
package/out/chunk-G6YPDPW7.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{c as e}from"./chunk-7YFJUT2P.js";import{a as t,g as n,h as r}from"./chunk-PQPKHAI5.js";import{l as i}from"./chunk-OWIBDEJJ.js";function a(e){let t=i(e),n=new Map;for(let[r,i]of Object.entries(e?.bundle?.reason??{})){let e=new Set(Array.isArray(i)?i.filter(e=>t.has(e)):[]);e.size>0&&n.set(r,e)}return{stasis:e?.kind===`stasis`,files:t,trees:n}}var o=[[`extra`,`add`],[`metro`,`bundle:metro`]];function s(e){if(e.length!==2)return e;let t=(t,n)=>e.find((r,i)=>r.trees.has(n)&&!r.trees.has(t)&&e[1-i].trees.has(t)&&!e[1-i].trees.has(n)),n=e.map(()=>new Map);for(let[r,i]of o){let a=t(r,i);a&&n[e.indexOf(a)].set(i,r)}let r=t(`metro`,`bundle:metro`);return r&&t(`run`,`bundle`)===r&&n[e.indexOf(r)].set(`bundle`,`run`),e.map((e,t)=>n[t].size===0?e:{...e,trees:new Map([...e.trees].map(([e,r])=>[n[t].get(e)??e,r])),actual:new Map([...n[t]].map(([e,t])=>[t,e]))})}function c(e,t){if(!e.stasis||e.trees.size!==1)return null;let[[n,r]]=e.trees;return r.size===e.files.size&&!t.some(t=>t!==e&&t.trees.has(n))?n:null}var l=e=>e.trees.size===0||e.trees.size===1&&[...e.trees.values()][0].size===e.files.size,u=`reasons:`,d=(e,t)=>`${u}${JSON.stringify([e,t].toSorted())}`;function f(e){if(!e.startsWith(u))return null;try{let t=JSON.parse(e.slice(u.length));return Array.isArray(t)&&t.length===2&&t.every(e=>typeof e==`string`)?t:null}catch{return null}}function p(...e){let t=s(e.map(a));if(t.length===2&&!t.some(l)){let[e,n]=t.map(e=>[...e.trees.keys()].toSorted()),r=e.filter(e=>n.includes(e)),[i,a]=[e,n].map(e=>e.filter(e=>!r.includes(e)));if(i.length>0&&a.length>0)return[...r.map(e=>({id:`reason:${e}`,label:e})),...i.flatMap(e=>a.map(t=>({id:d(e,t),label:`${e} \u2192 ${t}`})))]}let n=t.filter(e=>c(e,t)===null),r=new Set(n.flatMap(e=>[...e.trees.keys()])),i=e=>n.some(t=>t.stasis&&(t.trees.get(e)?.size??0)<t.files.size);return[...r].some(i)?[...r].toSorted().map(e=>({id:`reason:${e}`,label:e})):[]}function m(e,t,n=``){if(!n)return[``,``];let r=f(n),i=s([e,t].map(a)),o=n.startsWith(`reason:`)?n.slice(7):null;return i.map(e=>{let t=r?r.find(t=>e.trees.has(t)):c(e,i)??o;return t==null?n:`reason:${e.actual?.get(t)??t}`})}function h(e,t=``){let n=i(e);if(!t||e?.kind!==`stasis`)return n;let r=e?.bundle?.reason?.[t.replace(/^reason:/u,``)],a=new Set(Array.isArray(r)?r:[]);return new Map([...n].filter(([e])=>a.has(e)))}function g(e,t,n,r){return JSON.stringify([e,t,n,r])}function _(e,t=``){let n=new Map;if(e?.kind!==`stasis`||!e.bundle)return n;let r=t?i(e):null,a=t?h(e,t):null;for(let[t,i]of e.bundle.imports)for(let[e,o]of i)for(let[i,s]of o){let o=typeof s==`string`?[[null,s]]:s;for(let[s,c]of o){if(a&&!a.has(e)&&(r.has(e)||!a.has(c)))continue;let o=g(e,i,t,s);n.set(o,{key:o,parent:e,specifier:i,conditions:t,platform:s,target:c})}}return n}var v=(e,{lo:t,start:n},r)=>e[n+(r-t)/2];function y(e,t,{low:n,high:r},i,a){return e===-t||e-1<n||e!==t&&e+1<=r&&v(i,a,e-1)<v(i,a,e+1)?e+1:e-1}function b(e,t,n,{first:r,n:i,m:a,d:o,...s}){e.a.fill(1,0,r).fill(1,i),e.b.fill(1,0,r).fill(1,a);let c=i,l=a;for(let r=o;r>0;r--){let i=c-l,a=y(i,r,s,t,n[r]),o=v(t,n[r],a);for(let t=a>i?o:o+1;t<c;t++)e.a[t]=e.b[t-i]=1;c=o,l=c-a}for(let t=r;t<c;t++)e.a[t]=e.b[t]=1}function x(e,t,n){let r=0,i=t.length,a=e.length,o=2*(a+i);for(;r<a&&r<i&&e[r]===t[r];)r++;for(;a>r&&i>r&&e[a-1]===t[i-1];)a--,i--;let s={high:a-r,low:r-i},c=[r],l=[{lo:1,start:0}];for(let u=0;u<=s.high-s.low;u++){let d=l[u],f=Math.min(u,s.high),p=Math.max(-u,s.low+(s.low+u&1));l.push({lo:p,start:c.length});for(let m=p;m<=f;m+=2){let f=y(m,u,s,c,d),p=v(c,d,f),h=f>m?p:p+1,g=h;for(;h<a&&h-m<i&&e[h]===t[h-m];)h++;if(o+=2+h-g,c.push(h),h>=a&&h-m>=i)return b(n,c,l,{first:r,n:a,m:i,d:u,...s}),o}}throw Error(`no edit script between two lines`)}var S=/[\p{L}\p{N}_$]+|\s+|[^\p{L}\p{N}_$\s]/gu,C=2e3,w=800,T=.6;function E(e,t){if(e.length>C)return null;let n=e.match(S)??[];return n.length>w?null:{line:e,tokens:n,words:n.map(e=>(t.has(e)||t.set(e,t.size),t.get(e)))}}function D({tokens:e,line:t},n){let r=[];for(let i=0,a=0;a<e.length;i+=e[a++].length){if(n[a])continue;let o=r.at(-1);o&&/^\s*$/u.test(t.slice(o[1],i))?o[1]=i+e[a].length:r.push([i,i+e[a].length])}return r}var O=(e,t)=>e.reduce((e,[t,n])=>e+n-t,0)/Math.max(1,t.length);function k(e,t){let n={a:e.words.map(()=>0),b:t.words.map(()=>0)},r=x(e.words,t.words,n),i={a:D(e,n.a),b:D(t,n.b)};return{ranges:i,share:n.a.includes(1)?Math.min(O(i.a,e.line),O(i.b,t.line)):1,steps:r}}function A(e,t){if(e===t)return{a:[],b:[]};let n=new Map,r=E(e,n),i=E(t,n);if(r===null||i===null)return null;let{ranges:a,share:o}=k(r,i);return o<=T?a:null}var j=200,M=5e6,ee=6,te=60,ne=3;function re(e){let t=new Map;for(let n of e?.tokens??[])t.set(n,(t.get(n)??0)+1);return t}function N(e,t){let n=new Map,r=[e,t].map(e=>e.map(e=>E(e,n))),i=r.map(e=>e.map(re)),a=0,o=(e,t,n)=>{let r=0;for(let[i,o]of e)if(a+=ne,(r+=i.length*Math.max(0,o-(t.get(i)??0)))>T*n.length)return 1/0;return r/Math.max(1,n.length)},s=(n,a)=>r[0][n]===null||r[1][a]===null?1/0:Math.min(o(i[0][n],i[1][a],e[n]),o(i[1][a],i[0][n],t[a])),c=(e,t)=>{if(a+=te,s(e,t)===1/0)return 1/0;let{share:n,steps:i}=k(r[0][e],r[1][t]);return a+=i,n<=T?n:1/0},l=new Float64Array(e.length*t.length).fill(NaN);return{share:(n,r)=>{let i=n*t.length+r;return Number.isNaN(l[i])&&(l[i]=e[n]===t[r]?0:c(n,r)),l[i]},floor:s,spent:()=>a}}function P(e,t,{share:n,spent:r}){let i=Array.from({length:e+1},()=>new Float64Array(t+1)),a=(e,t)=>n(e,t)===1/0?-1/0:1e3-n(e,t)+i[e][t];for(let n=0;n<e;n++)for(let e=0;e<t;e++)if(i[n+1][e+1]=Math.max(i[n][e+1],i[n+1][e],a(n,e)),r()>M)return null;let o=[];for(let n=e,r=t;n>0&&r>0;)i[n][r]===i[n][r-1]?r--:i[n][r]===i[n-1][r]?n--:o.push([--n,--r]);return o.toReversed()}function F(e,t,{share:n,floor:r}){let i=[];for(let a=0,o=0;a<e&&o<t;a++){let e=null,s=1/0,c=Array.from({length:Math.min(t,o+ee)-o},(e,t)=>[o+t,r(a,o+t)]);for(let[t,r]of c.toSorted((e,t)=>e[1]-t[1]||e[0]-t[0])){if(r>s)break;(n(a,t)<s||n(a,t)===s&&t<e)&&([e,s]=[t,n(a,t)])}e!==null&&(i.push([a,e]),o=e+1)}return i}function I(e,t){if(e.length>j||t.length>j)return[];let n=N(e,t);return P(e.length,t.length,n)??F(e.length,t.length,n)}var L=(e,t,r)=>n(e,t,{...r,discard:!1});function R(t){if(t===null)return``;let n=t.type===`symlink`?t.target:t.data;if(typeof n==`string`)return n.includes(`\0`)?void 0:n;if(!n.includes(0))try{return e(n)}catch{return}}var z=new Set([`none`,`all`,`change`,`trailing`]);function B({horizon:e=1/0,whitespace:t=`none`,ignoreCase:n=!1}={}){if(e!==1/0&&!(Number.isSafeInteger(e)&&e>=0))throw RangeError(`horizon must be a whole number or Infinity, not ${e}`);if(!z.has(t))throw RangeError(`whitespace must be 'none', 'all', 'change' or 'trailing', not ${t}`);if(typeof n!=`boolean`)throw TypeError(`ignoreCase must be a boolean, not ${typeof n}`);return{horizon:e,whitespace:t,ignoreCase:n}}var V=e=>e.reduce((e,{a0:t,a1:n,b0:r,b1:i})=>e+n-t+i-r,0),H=e=>e===``?[]:e.split(/(?<=\n)/u),U=e=>({...e,ignoreCase:!1,whitespace:`none`}),W=e=>(e.whitespace??`none`)!==`none`||!!e.ignoreCase;function G(e,n,i,{whitespace:a,ignoreCase:o}){try{return r(e,n,i,{format:`normal`,ignoreCase:o,whitespace:a}),!0}catch(e){if(e instanceof t)return!1;throw e}}function K(e,t,n,r,i){let a=H(e),o=H(t),s=(e,t,n,r)=>({a0:e,a1:t,b0:n,b1:r,remove:a.slice(e,t),insert:o.slice(n,r)}),c=i.flatMap(({a0:e,a1:t,b0:r,b1:i})=>e===t||r===i?[s(e,t,r,i)]:L(a.slice(e,t).join(``),o.slice(r,i).join(``),n).map(t=>s(e+t.a0,e+t.a1,r+t.b0,r+t.b1))),l=V(c)<V(r)&&G(e,t,c,n)?c:r;return V(l)<V(i)?l:i}function q(e,t,n){let r=L(e,t,n);return W(n)?K(e,t,n,r,L(e,t,U(n))):r}function J(e,t,n){let r=R(e),i=R(t);if(r===void 0||i===void 0)return{binary:!0,blocks:[],insertions:null,deletions:null};let a=r===i?[]:q(r,i,n),o=0,s=0;for(let{a0:e,a1:t,b0:n,b1:r}of a)s+=r-n,o+=t-e;return{binary:!1,blocks:a,insertions:s,deletions:o}}function Y(e,t,n,r){return G(e,t,n,B(r))}var X=/[ \t\n\v\f\r]/u,Z=e=>{let t=e.split(`
|
|
2
|
-
`);return t.at(-1)===``&&t.pop(),t};function ie(e,t){for(let n=0,r=0;;n++,r++){let i=``,a=``;for(;n<e.length&&X.test(e[n]);)i+=e[n++];for(;r<t.length&&X.test(t[r]);)a+=t[r++];if(i!==a&&new Set(i+a).size>1)return!0;if(n>=e.length||r>=t.length)return!1}}function ae(e,t,n){try{if(!Y(e,t,n,{whitespace:`all`}))return!0}catch{return!0}let r=Z(e),i=Z(t),a=0,o=0;for(let e=0;e<=n.length;e++){let t=e<n.length?n[e].a0:r.length;for(;a<t;a++,o++)if(r[a]!==i[o]&&ie(r[a],i[o]))return!0;e<n.length&&({a1:a,b1:o}=n[e])}return!1}function oe(e,t,{extension:n=!0}={}){let r=e.split(`/`),i=t.split(`/`),a=0;for(;a<r.length-1&&a<i.length-1&&r[a]===i[a];)a++;let o=0;for(;o<r.length-a-1&&o<i.length-a-1&&r.at(-1-o)===i.at(-1-o);)o++;let s={head:a?`${r.slice(0,a).join(`/`)}/`:``,from:r.slice(a,r.length-o).join(`/`),to:i.slice(a,i.length-o).join(`/`),tail:o?`/${r.slice(-o).join(`/`)}`:``},c=s.from.lastIndexOf(`.`);return n&&!s.from.includes(`/`)&&!s.to.includes(`/`)&&c>0&&s.to.lastIndexOf(`.`)===c&&s.from.slice(0,c)===s.to.slice(0,c)?{...s,head:s.head+s.from.slice(0,c),from:s.from.slice(c),to:s.to.slice(c)}:s}function Q(e,t){return e?e.base===``?`${e.other}${t}`:t.startsWith(e.base)?t.slice(e.base.length):null:t}var $=(e,t)=>`${`../`.repeat(e.base.split(`/`).length-1)}${t}`;function se({root:e,paths:t},n,r){if(!e||n===`.`)return n;for(let e of r){let r=t.get(`${n}/${e}`);if(r?.endsWith(`/${e}`))return r.slice(0,-e.length-1)}let i=Q(e,`${n}/`);return i===null?$(e,n):i.slice(0,-1)||`.`}function ce(e,t){if(!e)return{prefix:t,from:null,to:null};let n=t.startsWith(e.other)?t:``;return{prefix:n,from:`./${e.base}${n.slice(e.other.length)}`,to:`./${n||e.other}`}}export{A as a,I as b,R as c,B as d,J as e,ae as f,oe as g,Q as h,$ as i,se as j,ce as k,p as l,m,h as n,g as o,_ as p};
|
package/out/chunk-JCIIBLKR.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
function e(e,t,a){let o=new Map;for(let t of e.onlyBase)o.set(t.pkg,{base:t.bytes,other:null});for(let t of e.onlyOther)o.set(t.pkg,{base:null,other:t.bytes});for(let t of e.changed)o.set(t.pkg,{base:t.baseBytes,other:t.otherBytes});for(let t of e.unchanged??[])o.set(t.pkg,{base:t.bytes,other:t.bytes});let s=(e,t)=>[...e.get(t)??[]].toSorted(n),c=new Set([...e.onlyBase,...e.onlyOther,...e.changed].map(e=>e.pkg));for(let e of new Set([...t.keys(),...a.keys()]))r(s(t,e),s(a,e))||c.add(e);let l=[],u=[],d=[];for(let e of c){let n=o.get(e)??{base:null,other:null},c=s(a,e),f=s(t,e),p=n.base!==null||f.length>0,m=n.other!==null||c.length>0;p&&!m?d.push({pkg:e,bytes:n.base,versions:f}):m&&!p?l.push({pkg:e,bytes:n.other,versions:c}):u.push({pkg:e,baseBytes:n.base,otherBytes:n.other,delta:n.base!==null&&n.other!==null?n.other-n.base:null,baseVersions:f,otherVersions:c,direction:f.length>0&&c.length>0&&!r(f,c)?i(f,c):null})}let f=(e,t)=>e.pkg.localeCompare(t.pkg);return{removed:d.toSorted(f),added:l.toSorted(f),changed:u.toSorted(f)}}function t(e){let t=String(e).trim().split(`+`,1)[0],n=t.indexOf(`-`);return n===-1?{core:t,pre:``}:{core:t.slice(0,n),pre:t.slice(n+1)}}function n(e,n){if(e===n)return 0;let r=t(e),i=t(n),a=r.core.split(`.`),o=i.core.split(`.`);for(let t=0;t<Math.max(a.length,o.length);t++){let r=Number(a[t]??0),i=Number(o[t]??0);if(Number.isNaN(r)||Number.isNaN(i))return e<n?-1:1;if(r!==i)return r<i?-1:1}if(r.pre===i.pre)return 0;if(!r.pre)return 1;if(!i.pre)return-1;let s=r.pre.split(`.`),c=i.pre.split(`.`);for(let e=0;e<Math.max(s.length,c.length);e++){let t=s[e],n=c[e];if(t===void 0)return-1;if(n===void 0)return 1;if(t===n)continue;let r=/^\d+$/u.test(t),i=/^\d+$/u.test(n);return r&&i?Number(t)<Number(n)?-1:1:r===i?t<n?-1:1:r?-1:1}return 0}function r(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function i(e,t){let r=e.filter(e=>!t.includes(e)).toSorted(n),i=t.filter(t=>!e.includes(t)).toSorted(n),a=e.filter(e=>t.includes(e)).toSorted(n),[o,s]=r.length>0&&i.length>0?[r,i]:r.length>0?[r,a]:[a,i];if(o.length===0||s.length===0)return`changed`;let c=(e,t)=>n(e.at(-1),t[0])<0;return c(o,s)?`up`:c(s,o)?`down`:`changed`}function a(e,t){let a=[],o=[],s=[],c=new Set([...e.keys(),...t.keys()]);for(let l of c){let c=e.get(l),u=t.get(l);if(c&&u){let e=[...c].toSorted(n),t=[...u].toSorted(n);if(r(e,t))continue;a.push({pkg:l,baseVersions:e,otherVersions:t,direction:i(e,t)})}else c?s.push({pkg:l,versions:[...c].toSorted(n)}):o.push({pkg:l,versions:[...u].toSorted(n)})}let l=(e,t)=>e.pkg.localeCompare(t.pkg);return a.sort(l),o.sort(l),s.sort(l),{updated:a,added:o,removed:s,totals:{baseDeps:e.size,otherDeps:t.size}}}export{e as a,n as b,a as c};
|