@preventive/triage 1.0.0-alpha.67 → 1.0.0-alpha.69

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/common/managed/routes.js +19 -12
  2. package/out/activity.js +3 -3
  3. package/out/{chunk-LBJVV6UB.js → chunk-2F3CYNPZ.js} +1 -1
  4. package/out/{chunk-U5C2TNNQ.js → chunk-2HGKTQ5Q.js} +1 -1
  5. package/out/chunk-4RS3NDOG.js +1 -0
  6. package/out/{chunk-VR3NRE5V.js → chunk-DVIYJG3F.js} +1 -1
  7. package/out/{chunk-LDO42LAC.js → chunk-GZ46SSTF.js} +1 -1
  8. package/out/{chunk-R3WUYD4F.js → chunk-HETCVNO4.js} +1 -1
  9. package/out/{chunk-5F5FPI75.js → chunk-MPXVKVPF.js} +1 -1
  10. package/out/{chunk-FUHRMY7R.js → chunk-NA3BSFFM.js} +6 -6
  11. package/out/{chunk-6YGH7BJG.js → chunk-QPGM3DTI.js} +1 -1
  12. package/out/{chunk-A5A3LEMV.js → chunk-Y3MWMG7M.js} +1 -1
  13. package/out/client-managed-import.js +1 -1
  14. package/out/client-managed.js +2 -2
  15. package/out/compare.js +8 -8
  16. package/out/dialogs.js +38 -38
  17. package/out/graph.js +1 -1
  18. package/out/index.html +7 -7
  19. package/out/scan.js +1 -1
  20. package/out/view.css +1 -1
  21. package/out/view.js +15 -15
  22. package/package.json +1 -1
  23. package/server-managed/bundle-build-worker.js +59 -7
  24. package/server-managed/bundle-build.ts +9 -4
  25. package/server-managed/db-neon.ts +4 -1
  26. package/server-managed/dependency-review-comments.ts +18 -13
  27. package/server-managed/dependency-reviews.ts +17 -14
  28. package/server-managed/http.ts +93 -42
  29. package/server-managed/npm-patch.ts +101 -43
  30. package/server-managed/pull-dependencies.ts +30 -21
  31. package/server-managed/pull-dependency-reviews.ts +63 -26
  32. package/server-managed/repository-dependency-reviews.ts +4 -2
  33. package/server-managed/repository-issues.ts +3 -3
  34. package/server-managed/reviewed-dependencies.ts +44 -24
  35. package/server-managed/stasis-dependencies.ts +34 -16
  36. package/server.ts +1 -1
  37. package/out/chunk-6ATPGDDI.js +0 -1
@@ -115,7 +115,7 @@
115
115
  // reads them there | 400/401/404
116
116
  // GET /api/npm/package?name=&version= → a published version's manifest and files | 400/401/404/413/429/502
117
117
  // GET /api/npm/package?name=&version=&patchHash=&patchRepoId=&patchCommit=&patchPath= → its files as a pnpm patch of a
118
- // repository the reader reads all of changes them | 400/401/403/404/409/413/422/429/502
118
+ // repository the reader reads all of changes them, its path looked for where left out, as kept where all three are | 400/401/403/404/409/413/422/429/502
119
119
  // GET /api/npm/versions?name= → its dist-tags, versions, when each was published and its first was, and whether a team lists its scope | 400/401/404/429/502
120
120
  // GET /api/npm/download?name=&version= → its tarball | 400/401/404/413/429/502
121
121
  // GET /api/npm/stats?name= → its downloads over the last year and its GitHub repository's figures | 400/401/404/429/502
@@ -229,7 +229,7 @@ import { ManagedMutationError, reportReferenceSnapshot } from './management.ts'
229
229
  import { BundleBuildError, buildRepositoryBundle, buildRepositoryLockfile, parseBundleBuild, withBundleBuildLease } from './bundle-build.ts'
230
230
  import { NpmPackageError, type NpmReader, type NpmVersionDocument, type NpmVersionStore, VERSION_KEPT_MS, canReadPrivateNpm, npmFileRows, npmPublishTime, npmScopesCount, npmTarballFilename, readNpmVersion, readNpmVersions, readTogether } from './npm-packages.ts'
231
231
  import { loadNpmFiles, loadNpmPackageBody, loadNpmTarball } from './npm-loads.ts'
232
- import { type ReadPatch, type RequestedPatch, patchedFiles, readPatch, requestedPatch, withPatchFiles } from './npm-patch.ts'
232
+ import { type ReadPatch, type RequestedPatch, foundPatch, keptPatch, patchedFiles, readPatch, requestedPatch, withPatchFiles } from './npm-patch.ts'
233
233
  import { type RepositoryCodeKept, loadRepositoryCodeBody, repositoryCodeFits, repositoryCodeKept } from './repository-code.ts'
234
234
  import { type ChangesStore, type CommitChanges, type CommitTree, TREES_READ, changesAsked, changesWithin, directoryFiles, repositoryChanges, repositoryTree } from './repository-changes.ts'
235
235
  import { COAUTHORS_READ, coauthorsOf } from './commit-coauthors.ts'
@@ -238,8 +238,9 @@ import { type AllHeads, type HistoryCommit, type HistoryPages, MAX_HISTORY_PAGE,
238
238
  import { type KnownMerges, type SquashedPull, type Squashes, squashedPulls } from './repository-squashes.ts'
239
239
  import { AGENTS_READ_VERSION, type AuthoredCommit, type BranchTip, type BranchTips, COMMITS_CURSOR, type CommitPulls, repositoryAgents } from './repository-agents.ts'
240
240
  import { DEPENDENCIES_LABEL, ISSUES_CURSOR, ISSUES_READ_VERSION, OPEN_PULLS_READ, OPEN_PULLS_SIZES, repositoryIssues, repositoryItem, repositoryLabel, repositoryOpenPulls } from './repository-issues.ts'
241
- import { type GithubAsked, type ListedLockfile, type LockfileRead, type LockfileStore, MAX_LOCKED, PULL_DEPENDENCIES_READ, type PullCommits, type PullDependencies,
242
- type PullDependencyStore, type PullRefs, lockfileFormat, pullDependenciesAt, pullRefs } from './pull-dependencies.ts'
241
+ import { type DirectoryDependencies, type GithubAsked, type ListedLockfile, type LockfileRead, type LockfileStore, MAX_LOCKED, PULL_DEPENDENCIES_READ, type PullCommits,
242
+ type PullDependencies,
243
+ type PullDependencyStore, type PullRefs, lockfileFormat, pullDependenciesAt, pullKey, pullRefs } from './pull-dependencies.ts'
243
244
  import { eachOf } from './queue.ts'
244
245
  import { lockedAt, lockedIn, lockfilesAt } from './commit-lockfiles.ts'
245
246
  import { MAX_REQUIRED_REVIEWS, type PublishedReview, type RepoDependencyReview } from './repository-dependency-reviews.ts'
@@ -248,7 +249,7 @@ import { type StasisDependencyReader, stasisDependencyReader, stasisDirectory, w
248
249
  import { type BundledVersion, bundleDependencies, installsBundle } from './bundle-dependency-reviews.ts'
249
250
  import { type CommentReviews, type ReviewBaselineStore, baselineFor, heldDependencies, reviewedDependencies, reviewedPackages } from './pull-dependency-reviews.ts'
250
251
  import { formattedPull, withFormatted } from './dependency-review-comments.ts'
251
- import type { ReviewedDependencies } from './reviewed-dependencies.ts'
252
+ import type { ReviewedBase, ReviewedDependencies } from './reviewed-dependencies.ts'
252
253
  import { commentReviews } from './pull-comment-reviews.ts'
253
254
  import { PULSE_WEEKS, PULSE_YEAR_VERSION, type PulseNarrowing, type PulseStats, StatsPending, commitStats, defaultHead, periodStats, pulseSince,
254
255
  repositoryActivity, repositoryLines,
@@ -2438,18 +2439,42 @@ async function readWholeRepositoryOf<T>(deps: ManagedHttpDeps, access: WholeAcce
2438
2439
  // The patch `patch` names (npm-patch.ts), and where it was read (`source`),
2439
2440
  // read of the whole of its repository as readWholeRepositoryOf reads it,
2440
2441
  // with its reader's own GitHub access, and held to its hash: as kept, for
2441
- // good (patchStore), else with that access checked again after; else why it
2442
- // was refused. Its failing to read or to apply throws.
2442
+ // good (patchStore), else with that access checked again after; one named
2443
+ // without its path looked for among its commit's patches (foundPatch), of a
2444
+ // repository whose dependency review is on alone; one named by its hash
2445
+ // alone as kept alone (keptPatchOf); else why it was refused. Its failing to
2446
+ // read or to apply throws.
2443
2447
  async function npmPatchOf(deps: ManagedHttpDeps, cookie: string | undefined, patch: RequestedPatch): Promise<ReadPatch | Refusal> {
2448
+ if (!('repoId' in patch)) return keptPatchOf(deps, cookie, patch.hash)
2444
2449
  const access = await wholeRepositoryAccess(deps, cookie, patch.repoId)
2445
2450
  if ('error' in access) return access
2446
- const { repoId } = access.repo
2451
+ const { repoId } = access.repo, { hash, commit, path } = patch
2447
2452
  const read = await readWholeRepositoryOf(deps, access, async (fullName, token) => {
2448
- const asked: GithubAsked = { github: false }
2449
- return { value: await readPatch(fullName, token, { ...patch, repoId }, patchStore(deps.db, deps.config.debug), asked), kept: !asked.github }
2453
+ const asked: GithubAsked = { github: false }, kept = patchStore(deps.db, deps.config.debug)
2454
+ const listed = async () => (await deps.db.repoDependencyReview(repoId))?.enabled ? repositoryTree(fullName, token, commit, commitTreeKept(deps, repoId)) : null
2455
+ const value = path === undefined ? await foundPatch(fullName, token, { hash, repoId, commit }, kept, listed, asked)
2456
+ : await readPatch(fullName, token, { hash, repoId, commit, path }, kept, asked)
2457
+ return { value, kept: !asked.github }
2450
2458
  }, () => wholeRepositoryAccess(deps, cookie, repoId))
2451
2459
  return 'error' in read ? read : read.value
2452
2460
  }
2461
+ // The patch `hash` names as kept, of a connected repository its reader may
2462
+ // read all of, the first of theirs that keeps it (npm-patch.ts keptPatch), as
2463
+ // readWholeRepositoryOf reads what is kept, GitHub asked for none of it; else
2464
+ // `404 patch-not-kept`, as one never read here, or read only of a repository
2465
+ // they can't read all of, is none of theirs.
2466
+ async function keptPatchOf(deps: ManagedHttpDeps, cookie: string | undefined, hash: string): Promise<ReadPatch | Refusal> {
2467
+ const s = await readSession(deps.config, deps.db, cookie, Date.now())
2468
+ if (s == null) return refusal(401, 'unauthenticated')
2469
+ if (!roleAtLeast(s.user.role, 'view')) return refusal(403, 'forbidden')
2470
+ const grants = await repositoryGrants(deps, s.user)
2471
+ const readable = grants.repos.flatMap(repo => { const whole = wholeAccessIn(grants, s.user, repo.repoId); return 'error' in whole ? [] : [whole] })
2472
+ const held = await keptPatch(readable.map(one => one.repo.repoId), hash, patchStore(deps.db, deps.config.debug))
2473
+ const access = held && readable.find(one => one.repo.repoId === held.source.repoId)
2474
+ if (!access) return refusal(404, 'patch-not-kept')
2475
+ const read = await readWholeRepositoryOf(deps, access, () => Promise.resolve({ value: held, kept: true }), () => wholeRepositoryAccess(deps, cookie, access.repo.repoId))
2476
+ return 'error' in read ? read : read.value
2477
+ }
2453
2478
  // The patch a request's fields name, as npm-patch.ts requestedPatch takes them.
2454
2479
  const patchFields = (field: (key: string) => unknown) => requestedPatch({ hash: field('patchHash'), repoId: field('patchRepoId'), commit: field('patchCommit'), path: field('patchPath') })
2455
2480
 
@@ -2581,26 +2606,33 @@ async function pullDependencyAnswer(deps: ManagedHttpDeps, fullName: string, tok
2581
2606
  commits?: PullCommits) {
2582
2607
  const kept = pullDependencyKept(deps, repoId)
2583
2608
  const reading: { told?: PullDependencies } = {}
2609
+ // Where its review is on, those of lockfiles it leaves out told to none,
2610
+ // whoever asks.
2611
+ const setting = await deps.db.repoDependencyReview(repoId)
2612
+ // Where the host names bases and its review is asked for and on, one into
2613
+ // the default branch is read without its merge base (`baseless`,
2614
+ // pull-dependencies.ts): the branch's own state is told apart.
2615
+ const repo = review && deps.reviewedDependencies?.base && setting?.enabled ? (await deps.db.listSelectedRepos()).find(row => row.repoId === repoId) : undefined
2616
+ const into = repo ? repo.cachedDefaultBranch ?? repo.defaultBranch : null
2584
2617
  // With the branches they are of, where told, kept with them.
2585
- const answered = commits ? { value: { baseRef: commits.baseRef, headRef: commits.headRef, commits: `${commits.base}...${commits.head}` }, kept: true }
2618
+ const answered = commits ? { value: { baseRef: commits.baseRef, headRef: commits.headRef, fork: commits.fork, commits: `${commits.base}...${commits.head}` }, kept: true }
2586
2619
  : await keptAnswer(deps, `${repoId}\0pull-commits\0${PULL_DEPENDENCIES_READ}\0${number}`, async () => {
2587
- const { told, ...read } = await pullDependenciesAt(fullName, token, number, kept)
2620
+ const { told, ...read } = await pullDependenciesAt(fullName, token, number, kept, undefined, undefined, into)
2588
2621
  reading.told = told
2589
2622
  return read
2590
2623
  }, undefined, false, stampOf(deps, repoId, fullName, token))
2591
2624
  // What its commits tell, as read, else as kept by them, else, no longer
2592
2625
  // kept, read again: by those given, without asking GitHub for them.
2593
- const held = reading.told ?? (typeof answered.value.commits === 'string' ? await kept.read(answered.value.commits) : null)
2594
- const pulled = { number, ...held ?? (await pullDependenciesAt(fullName, token, number, kept, undefined, commits)).told }
2595
- // Where its review is on, those of lockfiles it leaves out told to none,
2596
- // whoever asks.
2597
- const setting = await deps.db.repoDependencyReview(repoId)
2626
+ const baseless = into !== null && answered.value.baseRef === into
2627
+ const held = reading.told ?? (typeof answered.value.commits === 'string' ? await kept.read(pullKey(answered.value.commits, baseless)) : null)
2628
+ const pulled = { number, ...held ?? (await pullDependenciesAt(fullName, token, number, kept, undefined, commits, into)).told }
2598
2629
  // With what the stasis.config.json files it holds to reach, each a
2599
2630
  // directory of its own, none waited for; a lockfile's versions those reach
2600
2631
  // not marked as its package manager's alone (withReach).
2601
2632
  const asked: GithubAsked = { github: false }
2602
2633
  const scoped = setting?.enabled ? withReach(heldDependencies({ ...pulled, lockfiles: [...pulled.lockfiles,
2603
- ...await stasisDirectories(deps, fullName, token, repoId, setting.lockfiles, pulled.base, pulled.head, asked, pullRefs(answered.value.baseRef, answered.value.headRef))] },
2634
+ ...await stasisDirectories(deps, fullName, token, repoId, setting.lockfiles, pulled.base, pulled.head, asked, pullRefs(answered.value.baseRef, answered.value.headRef, answered.value.fork),
2635
+ pulled.baseless === true)] },
2604
2636
  setting.lockfiles)) : pulled
2605
2637
  const now = review ? await deps.db.repoDependencyReviewState(repoId, user.id, reviewedPackages(scoped)) : null
2606
2638
  // Its review by the lockfiles they were told by, though they have changed
@@ -2623,25 +2655,29 @@ async function pullDependencyAnswer(deps: ManagedHttpDeps, fullName: string, tok
2623
2655
  })
2624
2656
  // Each patch its lockfiles name by its hash alone with its file (npm-patch.ts), where its review is in effect.
2625
2657
  const patched = state ? await withPatchFiles(told, repoId, fullName, token, patchStore(deps.db, deps.config.debug), asked) : told
2626
- const dependencies = await reviewedDependencies(patched, state, { baseline, baselineUnread: unread, baselineError: error, reviewed, commentReviews: noting })
2658
+ const bases = new Map<string, ReviewedBase>()
2659
+ const dependencies = await reviewedDependencies(patched, state, { baseline, baselineUnread: unread, baselineError: error, reviewed, commentReviews: noting, namedBases: bases })
2627
2660
  // The comment the host formats of the reader's reviews of its versions, for
2628
2661
  // its copy button, but those its comments make of theirs already.
2629
- const formatted = await formattedPull(reviewed, deps.db, user.id, told, state, { repository: fullName, number }, commented)
2662
+ const formatted = await formattedPull(reviewed, deps.db, user.id, told, state, { repository: fullName, number }, commented, bases)
2630
2663
  return { value: { number: told.number, ...dependencies, ...formatted ? { formatted } : {} }, kept: answered.kept && held !== null && !asked.github }
2631
2664
  }
2632
2665
 
2633
2666
  // What the stasis.config.json files repository `repoId`'s review holds to
2634
2667
  // (`scope`) have Stasis reach, each a directory of dependencies by its own
2635
2668
  // path (stasis-dependencies.ts stasisDirectory): at `head`, against `base`
2636
- // where one is given. None is waited for: one not built yet is built behind
2669
+ // where one is given and it isn't read without it (`baseless`). None is waited for: one not built yet is built behind
2637
2670
  // the answer (stasisReader), told the branch its commit is of where `refs`
2638
- // names it, a pull request's head's, or its base's, which holds `base`.
2671
+ // names it, a pull request's head's, or its base's, which holds `base`. An
2672
+ // open pull request's head that is a fork's (`refs.fork`) is no commit of
2673
+ // the repository's own, which Stasis refuses: nothing is built for it.
2639
2674
  function stasisDirectories(deps: ManagedHttpDeps, fullName: string, token: string, repoId: number, scope: LockfileScope, base: string | null, head: string,
2640
- asked: GithubAsked, refs: PullRefs = {}) {
2675
+ asked: GithubAsked, refs: PullRefs = {}, baseless = false): Promise<DirectoryDependencies[]> {
2676
+ if (refs.fork) return Promise.resolve(stasisConfigs(scope).map(config => ({ paths: [config], error: 'stasis-failed', detail: 'commit-not-own' })))
2641
2677
  const reader = stasisReader(deps), reads = lockfileKept(deps, repoId)
2642
2678
  return Promise.all(stasisConfigs(scope).map(config => stasisDirectory(config, base, head,
2643
2679
  commit => reader.read({ repoId, fullName }, token, commit, config, commit === head ? refs.headRef : refs.baseRef),
2644
- (commit, held) => lockedAt(fullName, token, commit, reads, held, asked))))
2680
+ (commit, held) => lockedAt(fullName, token, commit, reads, held, asked), baseless)))
2645
2681
  }
2646
2682
 
2647
2683
  // What reads repositories' Stasis dependencies, one a database: kept by it,
@@ -2701,7 +2737,8 @@ async function branchDependencyAnswer(deps: ManagedHttpDeps, fullName: string, t
2701
2737
  ...await stasisDirectories(deps, fullName, token, repoId, setting.lockfiles, null, head, asked)] }, read.lockfiles)
2702
2738
  const now = await deps.db.repoDependencyReviewState(repoId, user.id, reviewedPackages(locked))
2703
2739
  if (!now) return { value: { head, review: null }, kept: !asked.github }
2704
- const told = await withPatchFiles(locked, repoId, fullName, token, patchStore(deps.db, deps.config.debug), asked)
2740
+ // Every patch there kept, those its lockfiles name the files of too, for a link to find by its hash alone.
2741
+ const told = await withPatchFiles(locked, repoId, fullName, token, patchStore(deps.db, deps.config.debug), asked, { keepNamed: true })
2705
2742
  // Told by the lockfiles it held to as they were read, though they have
2706
2743
  // changed since.
2707
2744
  const state = { ...now, lockfiles: setting.lockfiles }
@@ -2894,10 +2931,10 @@ type OpenPullsPage = { items?: unknown; more?: unknown; after?: unknown; commits
2894
2931
  // Each open pull request's base's and head's commits a page of them names,
2895
2932
  // into `commits` by its number.
2896
2933
  function pageCommits(page: OpenPullsPage, commits: Map<number, PullCommits>) {
2897
- for (const pull of Array.isArray(page.commits) ? page.commits as { number?: unknown; base?: unknown; head?: unknown; baseRef?: unknown; headRef?: unknown }[] : []) {
2898
- const { number, base, head, baseRef, headRef } = pull ?? {}
2934
+ for (const pull of Array.isArray(page.commits) ? page.commits as { number?: unknown; base?: unknown; head?: unknown; baseRef?: unknown; headRef?: unknown; fork?: unknown }[] : []) {
2935
+ const { number, base, head, baseRef, headRef, fork } = pull ?? {}
2899
2936
  if (Number.isSafeInteger(number) && typeof base === 'string' && SHA.test(base) && typeof head === 'string' && SHA.test(head)) {
2900
- commits.set(number as number, { base, head, ...pullRefs(baseRef, headRef) })
2937
+ commits.set(number as number, { base, head, ...pullRefs(baseRef, headRef, fork) })
2901
2938
  }
2902
2939
  }
2903
2940
  }
@@ -2923,21 +2960,24 @@ async function keptPullCommits(deps: ManagedHttpDeps, repoId: number, numbers: n
2923
2960
  }
2924
2961
 
2925
2962
  // The lines the versions wanting reviews of `answers` change, as their rows
2926
- // show them (npm-delta.js deltaBase), a patched one's none, where they are
2963
+ // show them (npm-delta.js reviewBase), a patched one's none, where they are
2927
2964
  // counted already: of public versions alone, those npm answered for in a day
2928
2965
  // (npmVersionStore), their integrities those npmDelta keys them by. `[name,
2929
2966
  // version, base, delta]` each, none counted here.
2930
2967
  async function teamDeltas(deps: ManagedHttpDeps, answers: object[]) {
2931
2968
  const asked = new Map<string, [string, string, string]>()
2932
- for (const answer of answers as { lockfiles?: { added?: unknown; unreviewed?: unknown }[]; review?: { required?: number } }[]) {
2969
+ for (const answer of answers as { lockfiles?: { added?: unknown; unreviewed?: unknown }[]; review?: { required?: number; reviewedBases?: true } }[]) {
2933
2970
  const required = answer.review?.required
2934
2971
  if (!Number.isSafeInteger(required)) continue
2935
2972
  for (const pkg of (answer.lockfiles ?? []).flatMap(dir => [...Array.isArray(dir.added) ? dir.added : [], ...Array.isArray(dir.unreviewed) ? dir.unreviewed : []]) as
2936
- { name?: unknown; version?: unknown; source?: unknown; was?: unknown; reviews?: unknown; rejected?: unknown; baseline?: unknown; reviewed?: unknown; unsupported?: unknown
2937
- patch?: unknown }[]) {
2973
+ { name?: unknown; version?: unknown; source?: unknown; was?: unknown; base?: { name?: unknown; version?: unknown }; reviews?: unknown; rejected?: unknown; baseline?: unknown
2974
+ reviewed?: unknown; unsupported?: unknown; patch?: unknown }[]) {
2938
2975
  if (pkg.source !== 'registry' || pkg.patch || typeof pkg.name !== 'string' || typeof pkg.version !== 'string' || !isExactVersion(pkg.version)) continue
2939
2976
  if (pkg.unsupported || pkg.baseline || pkg.reviewed || typeof pkg.reviews !== 'number' || (pkg.reviews >= required! && !pkg.rejected)) continue
2940
- const was = Array.isArray(pkg.was) ? pkg.was.find(prior => typeof prior === 'string' && prior !== pkg.version) as string | undefined : undefined
2977
+ // Against the base the host names, where it names them; one of another package's not counted.
2978
+ if (answer.review?.reviewedBases && pkg.base && pkg.base.name !== pkg.name) continue
2979
+ const was = answer.review?.reviewedBases ? pkg.base?.version as string | undefined
2980
+ : Array.isArray(pkg.was) ? pkg.was.find(prior => typeof prior === 'string' && prior !== pkg.version) as string | undefined : undefined
2941
2981
  asked.set(`${pkg.name}\0${pkg.version}\0${was ?? '(empty)'}`, [pkg.name, pkg.version, was ?? '(empty)'])
2942
2982
  }
2943
2983
  }
@@ -4939,7 +4979,8 @@ function reviewChange(res: ServerResponse, body: Record<string, unknown>): Revie
4939
4979
  // its files as its patch changes them, the patch read as kept, else where the
4940
4980
  // request says (`patchRepoId`, `patchCommit`, `patchPath`), of the whole of a
4941
4981
  // repository its reader reads (npmPatchOf), the review keeping where it was
4942
- // read. Access to both versions is rechecked before returning or saving annotations.
4982
+ // read; and a patched base's (`basePatchHash`) as its patch, kept, changes
4983
+ // them. Access to both versions is rechecked before returning or saving annotations.
4943
4984
  async function handleNpmReviews(req: IncomingMessage, res: ServerResponse, deps: ManagedHttpDeps, cookie: string | undefined, params: URLSearchParams): Promise<void> {
4944
4985
  const method = req.method ?? 'GET'
4945
4986
  if (!['GET', 'POST'].includes(method)) { send405(res, 'GET, POST'); return }
@@ -4957,17 +4998,19 @@ async function handleNpmReviews(req: IncomingMessage, res: ServerResponse, deps:
4957
4998
  const baseVersion = field('baseVersion') ?? null
4958
4999
  const baseIntegrity = field('baseIntegrity') ?? null
4959
5000
  const patchHash = field('patchHash') ?? null
5001
+ const basePatchHash = field('basePatchHash') ?? null
4960
5002
  // Where its patch is, where it names that: its hash alone where only listed.
4961
5003
  const patch = patchFields(field)
4962
5004
  const validIntegrity = (value: unknown): value is string => typeof value === 'string' && value.length > 0 && value.length <= 1024
4963
5005
  if (field('ecosystem') !== 'npm' || !isNpmPackageName(name) || !isNpmPackageSpec(version) || !validIntegrity(integrity)
4964
5006
  || (basePackage !== null || baseVersion !== null || baseIntegrity !== null)
4965
5007
  && (!isNpmPackageName(basePackage) || !isNpmPackageSpec(baseVersion) || !validIntegrity(baseIntegrity))
4966
- || (patchHash !== null && !isPatchHash(patchHash)) || patch === 'invalid') {
5008
+ || (patchHash !== null && !isPatchHash(patchHash)) || patch === 'invalid' || (basePatchHash !== null && (!isPatchHash(basePatchHash) || basePackage === null))) {
4967
5009
  sendJson(res, 400, { error: 'bad-review-context' }); return
4968
5010
  }
4969
5011
  const context: ReviewContext = { ecosystem: 'npm', package: name, version, integrity, patchHash: patchHash as string | null,
4970
- basePackage: basePackage as string | null, baseVersion: baseVersion as string | null, baseIntegrity: baseIntegrity as string | null }
5012
+ basePackage: basePackage as string | null, baseVersion: baseVersion as string | null, baseIntegrity: baseIntegrity as string | null,
5013
+ basePatchHash: basePatchHash as string | null }
4971
5014
  let change: ReviewChange | null = null
4972
5015
  if (mutation) {
4973
5016
  change = reviewChange(res, body)
@@ -4994,6 +5037,8 @@ async function handleNpmReviews(req: IncomingMessage, res: ServerResponse, deps:
4994
5037
  const reading = change && change.action !== 'revoke'
4995
5038
  const patchRead = reading && patch ? await npmPatchOf(deps, cookie, patch) : null
4996
5039
  if (patchRead && 'error' in patchRead) { sendRefusal(res, patchRead); return }
5040
+ const basePatchRead = reading && basePatchHash ? await npmPatchOf(deps, cookie, { hash: basePatchHash as string }) : null
5041
+ if (basePatchRead && 'error' in basePatchRead) { sendRefusal(res, basePatchRead); return }
4997
5042
  const loads = reading ? [doc, ...base ? [base] : []].map(loadNpmFiles) : []
4998
5043
  let tarballs: ReviewedTarballs | undefined
4999
5044
  try {
@@ -5002,7 +5047,8 @@ async function handleNpmReviews(req: IncomingMessage, res: ServerResponse, deps:
5002
5047
  tarballs = { shasum: doc.dist.shasum, baseShasum: base?.dist.shasum ?? null, ...patchRead ? { patch: patchRead.source } : {} }
5003
5048
  }
5004
5049
  if (change?.action === 'publish' || change?.action === 'save') {
5005
- const maps = files.map((list, at) => new Map<string, unknown>(npmFileRows(at === 0 && patchRead ? patchedFiles(list, patchRead.files) : list)
5050
+ const patchOf = [patchRead, basePatchRead]
5051
+ const maps = files.map((list, at) => new Map<string, unknown>(npmFileRows(patchOf[at] ? patchedFiles(list, patchOf[at].files) : list)
5006
5052
  .map(([path, size, text, digest]) => [path, text ?? { format: 'digest', size, digest }])))
5007
5053
  const after = maps[0]!, before = maps[1] ?? new Map<string, unknown>()
5008
5054
  const diff = computeBundleDiff(before, after, () => '.')
@@ -5126,9 +5172,12 @@ async function handleNpm(req: IncomingMessage, res: ServerResponse, deps: Manage
5126
5172
  const diffed = path === NPM_RENAME_DIFF_PATH && params.has('path') ? renameDiffRequest(params) : null
5127
5173
  if (path === NPM_RENAME_DIFF_PATH && params.has('path') && !diffed) { sendJson(res, 400, { error: 'bad-file' }); return }
5128
5174
  // The patch a patched version's files and comparison are of, where named
5129
- // (`patchHash`, `patchRepoId`, `patchCommit`, `patchPath`), as Review reads them.
5175
+ // (`patchHash`, `patchRepoId`, `patchCommit`, `patchPath`), as Review reads them;
5176
+ // and the one a comparison's other version is of, by its hash alone, as kept (`otherPatchHash`).
5130
5177
  const patch = patchFields(key => params.get(key))
5131
- if (patch === 'invalid' || (params.has('patchHash') && !patch) || (patch && path !== NPM_PACKAGE_PATH && path !== NPM_COMPARISON_PATH)) {
5178
+ const otherPatch = params.has('otherPatchHash') ? requestedPatch({ hash: params.get('otherPatchHash') }) : null
5179
+ if (patch === 'invalid' || (patch && path !== NPM_PACKAGE_PATH && path !== NPM_COMPARISON_PATH)
5180
+ || otherPatch === 'invalid' || (otherPatch && (path !== NPM_COMPARISON_PATH || otherSpec === '(empty)'))) {
5132
5181
  sendJson(res, 400, { error: 'bad-patch' }); return
5133
5182
  }
5134
5183
  const reader = await npmReader(deps, cookie, otherName === name ? [name] : [name, otherName], { handed: true })
@@ -5255,18 +5304,20 @@ async function handleNpm(req: IncomingMessage, res: ServerResponse, deps: Manage
5255
5304
  // Overview reads beside them (comparison.ts): the version shown against
5256
5305
  // the one compared with, or `(empty)`, none, as Review reads a first
5257
5306
  // version; as `patch` changes its files, where named, the patch read
5258
- // first (npmPatchOf). Read of both, each package's access checked again
5259
- // once worked out.
5307
+ // first (npmPatchOf), and `otherPatch` the other's. Read of both, each
5308
+ // package's access checked again once worked out.
5260
5309
  if (path === NPM_COMPARISON_PATH) {
5261
5310
  const old = otherSpec === '(empty)' ? null : await otherDoc()
5262
5311
  const patched = patch ? await npmPatchOf(deps, cookie, patch) : null
5263
5312
  if (patched && 'error' in patched) { sendRefusal(res, patched); return }
5313
+ const oldPatched = otherPatch ? await npmPatchOf(deps, cookie, otherPatch) : null
5314
+ if (oldPatched && 'error' in oldPatched) { sendRefusal(res, oldPatched); return }
5264
5315
  dropIdle(res)
5265
5316
  const loads = [doc, ...old ? [old] : []].map(loadNpmFiles)
5266
5317
  let body
5267
5318
  try {
5268
5319
  const [files, oldFiles] = await Promise.all(loads.map(load => load.result))
5269
- body = await comparisonBody(old ? npmComparedSide(old.dist.integrity, oldFiles!) : emptySide(),
5320
+ body = await comparisonBody(old ? npmComparedSide(old.dist.integrity, oldPatched ? patchedFiles(oldFiles!, oldPatched.files) : oldFiles!) : emptySide(),
5270
5321
  npmComparedSide(doc.dist.integrity, patched ? patchedFiles(files!, patched.files) : files!))
5271
5322
  } finally { for (const load of loads) load.release() }
5272
5323
  const current = await npmReader(deps, cookie, otherName === name ? [name] : [name, otherName])
@@ -1,11 +1,11 @@
1
1
  // A pnpm patch of an npm package version (patchedDependencies), as its
2
2
  // dependency review reads it (pull-dependency-reviews.ts): its file, which a
3
3
  // lockfile names (locked-packages.ts `patchPath`), or which is found where it
4
- // names it by its hash alone (withPatchFiles), read of a repository at a
5
- // commit, and held to the hash the lockfile names it by, as pnpm 10 and
6
- // later hash it, a sha256 in hex of its text with its CRLFs read as LFs
7
- // (one pnpm 9 names by an md5 isn't read), by which it is kept for good,
8
- // read of GitHub once; and applied to the version's files as pnpm applies
4
+ // names it by its hash alone (withPatchFiles), or by its hash among a
5
+ // commit's patches (foundPatch), read of a repository at a commit, and held
6
+ // to the hash the lockfile names it by, as pnpm 10 and later hash it
7
+ // (hashOfPatch; one pnpm 9 names by an md5 isn't read), by which it is kept
8
+ // for good, read of GitHub once; and applied to the version's files as pnpm applies
9
9
  // it as it installs it (patch-package's applyPatch, which pnpm 10 and 11
10
10
  // bundle): each file it deletes, creates, renames or changes, a change's
11
11
  // hunks each found in the file as it was, where its header says, else as
@@ -20,22 +20,25 @@ import { YamlError, parseYaml } from '@preventive/lockfile/yaml.js'
20
20
  import { isGithubRepoName } from '../common/github-pr.ts'
21
21
  import { isPatchHash, isPatchPath } from '../common/managed/npm-packages.js'
22
22
  import { GithubApiError } from './github-errors.ts'
23
+ import { isStasisConfig } from '../common/managed/stasis-config.ts'
23
24
  import { SHA, isId } from './github-values.ts'
24
25
  import { type LockedPackage, pathFrom } from './locked-packages.ts'
25
26
  import { type Lru, lru } from './lru.ts'
26
27
  import type { KeptStore } from './npm-kept.ts'
27
28
  import { plainObject } from './npm-manifest.ts'
28
29
  import { NpmPackageError, type NpmPackageFile, npmFileText, pathOrder } from './npm-packages.ts'
29
- import { type GithubAsked, type PullDependencies, repositoryFile } from './pull-dependencies.ts'
30
+ import { type GithubAsked, type PullDependencies, lockfileFormat, repositoryFile } from './pull-dependencies.ts'
30
31
  import { eachOf } from './queue.ts'
31
32
 
32
33
  // Where a patch is read: its file in a repository (by its id) at a commit,
33
34
  // from the repository's root; and the patch, by its hash besides. A request
34
35
  // names its repository by its id, or by its name (`owner/name`) in its place
35
- // (http.ts wholeRepositoryAccess).
36
+ // (http.ts wholeRepositoryAccess), and may leave its path out, the patch
37
+ // looked for there (foundPatch); or the patch by its hash alone, which only
38
+ // one kept answers (keptPatch).
36
39
  export interface PatchSource { repoId: number; commit: string; path: string }
37
40
  export interface NpmPatch extends PatchSource { hash: string }
38
- export type RequestedPatch = Omit<NpmPatch, 'repoId'> & { repoId: number | string }
41
+ export type RequestedPatch = (Omit<NpmPatch, 'repoId' | 'path'> & { repoId: number | string; path?: string }) | { hash: string }
39
42
 
40
43
  // The most a patch's file may hold, and how many lines either side of where a
41
44
  // hunk says its lines are they are looked for; and how many patches an
@@ -47,21 +50,26 @@ const FIND_AT_ONCE = 4
47
50
 
48
51
  // The patch a request names, by its hash (`hash`), its repository's id
49
52
  // (`repoId`, a number or its digits) or name, the commit and its file's
50
- // path; null where it names none of where it is, and 'invalid' where it
51
- // names one otherwise.
52
- export function requestedPatch({ hash, repoId, commit, path }: { hash: unknown; repoId: unknown; commit: unknown; path: unknown }): RequestedPatch | null | 'invalid' {
53
- if ([repoId, commit, path].every(field => field == null)) return null
53
+ // path or none, or by its hash alone; null where it names none, and
54
+ // 'invalid' where it names one otherwise.
55
+ export function requestedPatch({ hash, repoId, commit, path }: { hash: unknown; repoId?: unknown; commit?: unknown; path?: unknown }): RequestedPatch | null | 'invalid' {
56
+ if ([repoId, commit, path].every(field => field == null)) return hash == null ? null : isPatchHash(hash) ? { hash } : 'invalid'
54
57
  const id = typeof repoId === 'string' && /^[1-9]\d{0,15}$/u.test(repoId) ? Number(repoId) : repoId
55
58
  if (!isPatchHash(hash) || !(isId(id) || typeof id === 'string' && isGithubRepoName(id)) || typeof commit !== 'string' || !SHA.test(commit)
56
- || !isPatchPath(path)) return 'invalid'
57
- return { hash, repoId: id, commit, path }
59
+ || path != null && !isPatchPath(path)) return 'invalid'
60
+ return { hash, repoId: id, commit, ...typeof path === 'string' ? { path } : {} }
58
61
  }
59
62
 
60
- // Whether `text` is the patch `hash` names, its sha256 in hex: of its text
61
- // with its CRLFs as LFs, as pnpm reads it, or as it is.
62
- export function isPatchOf(text: string, hash: string): boolean {
63
- return [...new Set([text.replaceAll('\r\n', '\n'), text])].some(read => createHash('sha256').update(read).digest('hex') === hash)
64
- }
63
+ // The hash pnpm names a patch's text by, a sha256 in hex of it with its
64
+ // CRLFs as LFs, as pnpm 10 and later read a patch's file (the CRs of lines
65
+ // it ends otherwise kept); and whether `text` is the patch `hash` names.
66
+ export const hashOfPatch = (text: string) => createHash('sha256').update(text.replaceAll('\r\n', '\n')).digest('hex')
67
+ export const isPatchOf = (text: string, hash: string) => hashOfPatch(text) === hash
68
+
69
+ // The text of a patch's file in repository `fullName` at `commit`, read with
70
+ // `token`; null where GitHub has no text of it, or it is past MAX_PATCH_BYTES.
71
+ const patchFileAt = (fullName: string, token: string, path: string, commit: string) => repositoryFile(fullName, token, path, commit).then(text => text !== null
72
+ && Buffer.byteLength(text) > MAX_PATCH_BYTES ? null : text, (err: unknown) => { if (err instanceof GithubApiError && err.message === 'github-malformed') return null; throw err })
65
73
 
66
74
  // A change a patch makes to a file at `path` of the package: deleting it,
67
75
  // creating it, renaming it from another (`from`), and its hunks, as
@@ -302,7 +310,8 @@ export const patchKey = (repoId: number, hash: string) => `${repoId}\0${hash}`
302
310
  // Patches read lately, with where each was read, by their keys, as many as
303
311
  // MAX_KEPT_PATCHES of the bytes they take (patchWeight); and the path each
304
312
  // found or kept is at (`located`): '' by its key and a commit for one not
305
- // found there, lest each telling look again, none for one not looked for.
313
+ // found there, lest each telling look again, none for one not looked for;
314
+ // and '' by its repository's key and a commit whose patches were all kept.
306
315
  const MAX_KEPT_PATCHES = 64 * 1024 * 1024
307
316
  export interface ReadPatch { source: PatchSource; files: PatchedFile[] }
308
317
  const patches: Lru<ReadPatch> = lru(MAX_KEPT_PATCHES, read => patchWeight(read.files))
@@ -334,6 +343,52 @@ export async function readPatch(fullName: string, token: string, patch: NpmPatch
334
343
  return read
335
344
  }
336
345
 
346
+ // The patch `hash` names as kept, of the first of repositories `repoIds`
347
+ // that keeps it, in this instance, else beyond it (`kept`, held to its hash
348
+ // again), GitHub asked for none of it; null where none does.
349
+ export async function keptPatch(repoIds: number[], hash: string, kept: KeptStore<KeptPatch>): Promise<ReadPatch | null> {
350
+ const keys = repoIds.map(repoId => patchKey(repoId, hash))
351
+ const known = keys.map(key => patches.get(key)).find(Boolean)
352
+ if (known) return known
353
+ const stored = keys.length > 0 ? await kept.readMany(keys) : new Map()
354
+ for (const [at, key] of keys.entries()) {
355
+ const patch = stored.get(key)?.value
356
+ if (typeof patch?.text !== 'string' || !isPatchOf(patch.text, hash)) continue
357
+ const read = { source: { repoId: repoIds[at]!, commit: patch.commit, path: patch.path }, files: parsePatch(patch.text) }
358
+ patches.set(key, read)
359
+ return read
360
+ }
361
+ return null
362
+ }
363
+
364
+ // The patch `patch` names by its hash at a commit of its repository, its
365
+ // file unnamed: as kept by its repository and hash (keptPatch); else among
366
+ // the patches of the commit's files (`listed` lists them, with their bytes;
367
+ // null where its repository isn't looked in), each `.patch` file in a
368
+ // `patches` directory beside a pnpm lockfile or a stasis.config.json, where
369
+ // pnpm patch-commit writes them, as many as MAX_FOUND, read of repository
370
+ // `fullName` with `token` and each kept for good by its own hash, so a
371
+ // commit is looked in once; `asked` told where GitHub was. One none of them
372
+ // is fails as not found.
373
+ export async function foundPatch(fullName: string, token: string, patch: Omit<NpmPatch, 'path'>, kept: KeptStore<KeptPatch>,
374
+ listed: () => Promise<{ files: string[]; sizes: number[] } | null>, asked?: GithubAsked): Promise<ReadPatch> {
375
+ const ofIt = () => keptPatch([patch.repoId], patch.hash, kept), searched = `${patchKey(patch.repoId, '')}\0${patch.commit}`
376
+ let found = await ofIt()
377
+ const tree = found || located.get(searched) !== undefined ? null : await listed()
378
+ if (tree) {
379
+ if (asked) asked.github = true
380
+ const dirOf = (path: string) => path.slice(0, path.lastIndexOf('/') + 1)
381
+ const beside = new Set(tree.files.filter(path => lockfileFormat(path) === 'pnpm' || isStasisConfig(path)).map(path => `${dirOf(path)}patches/`))
382
+ const paths = tree.files.filter((path, at) => path.endsWith('.patch') && beside.has(dirOf(path)) && (tree.sizes[at] ?? 0) <= MAX_PATCH_BYTES)
383
+ await eachOf(paths.slice(0, MAX_FOUND), FIND_AT_ONCE, path => patchFileAt(fullName, token, path, patch.commit)
384
+ .then(text => text === null ? undefined : kept.write(patchKey(patch.repoId, hashOfPatch(text)), { commit: patch.commit, path, text }, Date.now())))
385
+ located.set(searched, '')
386
+ found = await ofIt()
387
+ }
388
+ if (!found) throw new NpmPackageError(404, 'patch-not-found')
389
+ return found
390
+ }
391
+
337
392
  // The files a pnpm-workspace.yaml (`workspace`, its text, null for none)
338
393
  // names its patches by, as pnpm 11 and later read their patchedDependencies
339
394
  // there alone, by a version or a package; none where its reader refuses it.
@@ -346,48 +401,51 @@ function patchedBy(workspace: string | null): Record<string, unknown> {
346
401
  return plainObject(patched) ? patched : {}
347
402
  }
348
403
 
349
- // A version pnpm patches by a patch its lockfile names by its hash alone
350
- // (pnpm 11's and later), a sha256, with its lockfile's directory.
351
- type Unnamed = LockedPackage & { patchHash: string; patchDir: string; version: string }
352
- const unnamed = (pkg: LockedPackage): pkg is Unnamed => pkg.patchPath === undefined && pkg.patchDir !== undefined && pkg.version !== null && isPatchHash(pkg.patchHash)
404
+ // A version pnpm patches by a patch named by a sha256, with its lockfile's
405
+ // directory: one its lockfile names by its hash alone (pnpm 11's and later),
406
+ // which wants its file found; and, `keepNamed`, one whose file it names.
407
+ type Patched = LockedPackage & { patchHash: string; patchDir: string; version: string }
408
+ const patchedBy256 = (pkg: LockedPackage, keepNamed = false): pkg is Patched => (pkg.patchPath === undefined || keepNamed) && pkg.patchDir !== undefined
409
+ && pkg.version !== null && isPatchHash(pkg.patchHash)
353
410
 
354
- // `told`, each such version of its with its patch's file (`patchPath`), as
355
- // a lockfile naming one tells it: as kept by its repository and hash, else
356
- // the file the pnpm-workspace.yaml beside its lockfile names of it
357
- // (patchedBy: its version's, else its package's) at `told.head`, held to
358
- // its hash and kept for good, so each is found once, as many an answer as
359
- // MAX_FOUND; one not found left with none. `asked` told where GitHub was.
360
- // A file GitHub has no text of, or past MAX_PATCH_BYTES, is none; any other
361
- // failure of GitHub's is the whole answer's, as a lockfile's is.
411
+ // `told`, each version of its that pnpm patches by a patch its lockfile names
412
+ // by its hash alone with its patch's file (`patchPath`), as a lockfile naming
413
+ // one tells it: as kept by its repository and hash, else the file the
414
+ // pnpm-workspace.yaml beside its lockfile names of it (patchedBy: its
415
+ // version's, else its package's) at `told.head`, held to its hash and kept
416
+ // for good, so each is found once, as many an answer as MAX_FOUND; one not
417
+ // found left with none. With `keepNamed`, as a default branch's are told,
418
+ // each patch whose file a lockfile names is read there and kept as well, so
419
+ // that a link naming it by its hash alone finds it later (keptPatch).
420
+ // `asked` told where GitHub was. A file GitHub has no text of, or past
421
+ // MAX_PATCH_BYTES, is none; any other failure of GitHub's is the whole
422
+ // answer's, as a lockfile's is.
362
423
  export async function withPatchFiles<T extends PullDependencies>(told: T, repoId: number, fullName: string, token: string, kept: KeptStore<KeptPatch>,
363
- asked?: GithubAsked): Promise<T> {
364
- const wanted = new Map<string, Unnamed>()
424
+ asked?: GithubAsked, { keepNamed = false } = {}): Promise<T> {
425
+ const wanted = new Map<string, Patched>()
365
426
  for (const dir of told.lockfiles) {
366
- for (const pkg of 'error' in dir ? [] : [...dir.added, ...dir.locked]) if (unnamed(pkg)) wanted.set(patchKey(repoId, pkg.patchHash), pkg)
427
+ for (const pkg of 'error' in dir ? [] : [...dir.added, ...dir.locked]) if (patchedBy256(pkg, keepNamed)) wanted.set(patchKey(repoId, pkg.patchHash), pkg)
367
428
  }
368
429
  if (wanted.size === 0) return told
369
430
  const at = (key: string) => located.get(key) ?? located.get(`${key}\0${told.head}`)
370
431
  const unknown = [...wanted.keys()].filter(key => at(key) === undefined)
371
432
  for (const [key, { value }] of unknown.length > 0 ? await kept.readMany(unknown) : []) if (typeof value?.path === 'string') located.set(key, value.path)
372
- const files = new Map<string, Promise<string | null>>()
373
- const read = (path: string) => files.get(path) ?? files.set(path, repositoryFile(fullName, token, path, told.head).then(
374
- text => text !== null && Buffer.byteLength(text) > MAX_PATCH_BYTES ? null : text,
375
- (err: unknown) => { if (err instanceof GithubApiError && err.message === 'github-malformed') return null; throw err })).get(path)!
433
+ const files = new Map<string, Promise<string | null>>(), read = (path: string) => files.get(path) ?? files.set(path, patchFileAt(fullName, token, path, told.head)).get(path)!
376
434
  const workspaces = new Map<string, Promise<Record<string, unknown>>>()
377
435
  const namedIn = (dir: string) => workspaces.get(dir) ?? workspaces.set(dir, read(pathFrom(dir, 'pnpm-workspace.yaml')!).then(patchedBy)).get(dir)!
378
436
  await eachOf(unknown.filter(key => at(key) === undefined).slice(0, MAX_FOUND), FIND_AT_ONCE, async key => {
379
437
  const pkg = wanted.get(key)!
380
438
  if (asked) asked.github = true
381
- const patched = await namedIn(pkg.patchDir)
382
- const file = patched[`${pkg.name}@${pkg.version}`] ?? patched[pkg.name]
383
- const path = typeof file === 'string' ? pathFrom(pkg.patchDir, file) : null
439
+ const patched = pkg.patchPath === undefined ? await namedIn(pkg.patchDir) : {}
440
+ const file = pkg.patchPath ?? patched[`${pkg.name}@${pkg.version}`] ?? patched[pkg.name]
441
+ const path = typeof file === 'string' ? pkg.patchPath ?? pathFrom(pkg.patchDir, file) : null
384
442
  const text = path === null ? null : await read(path)
385
443
  if (path === null || text === null || !isPatchOf(text, pkg.patchHash)) { located.set(`${key}\0${told.head}`, ''); return }
386
444
  await kept.write(key, { commit: told.head, path, text }, Date.now())
387
445
  located.set(key, path)
388
446
  })
389
447
  const named = <P extends LockedPackage>(pkg: P): P => {
390
- const patchPath = unnamed(pkg) && at(patchKey(repoId, pkg.patchHash))
448
+ const patchPath = patchedBy256(pkg) && at(patchKey(repoId, pkg.patchHash))
391
449
  return patchPath ? { ...pkg, patchPath } : pkg
392
450
  }
393
451
  return { ...told, lockfiles: told.lockfiles.map(dir => 'error' in dir ? dir : { ...dir, added: dir.added.map(named), locked: dir.locked.map(named) }) }