@preventive/triage 1.0.0-alpha.73 → 1.0.0-alpha.74
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/common/bundle-compare-diff.d.ts +4 -1
- package/common/bundle-compare-diff.js +4 -3
- package/common/bundle-sources.js +4 -2
- package/out/activity.js +1 -1
- package/out/{chunk-5NUDNLJA.js → chunk-62QT2RXR.js} +2 -2
- package/out/{chunk-ROWUGPID.js → chunk-C6OPCPCA.js} +1 -1
- package/out/{chunk-BIWPZT4E.js → chunk-DQJEVHRE.js} +1 -1
- package/out/{chunk-YCEMQETS.js → chunk-ESJZZF2Y.js} +4 -4
- package/out/{chunk-PX5DLFSD.js → chunk-HLMQ7QYS.js} +1 -1
- package/out/{chunk-RLLA4GHZ.js → chunk-PLF4LBLE.js} +1 -1
- package/out/{chunk-ROHACH7V.js → chunk-VRAJCPV5.js} +1 -1
- package/out/{chunk-CXVBTUK3.js → chunk-VS7RV24Z.js} +1 -1
- package/out/{chunk-TD7RVUTT.js → chunk-W5PRH5D7.js} +1 -1
- package/out/{chunk-RGNF4OH6.js → chunk-YI4D6XVX.js} +1 -1
- package/out/client-managed.js +30 -30
- package/out/compare.js +1 -1
- package/out/dialogs.js +1 -1
- package/out/index.html +5 -5
- package/out/scan.js +1 -1
- package/out/view.js +1 -1
- package/package.json +4 -3
- package/risk/index.d.ts +3 -3
- package/risk/npm/assess.js +1 -1
- package/risk/npm/tarball.js +6 -6
- package/server-managed/comparison.ts +6 -5
- package/server-managed/http.ts +7 -5
- package/server-managed/npm-loads.ts +2 -2
- package/server-managed/npm-packages.ts +5 -1
- package/server-managed/npm-patch-paths.ts +57 -0
- package/server-managed/npm-patch.ts +71 -76
- package/server-managed/repository-code.ts +9 -6
- package/server-managed/repository-risk-read.ts +23 -2
- /package/out/{chunk-Y2XGV3RC.js → chunk-S5HSDGTP.js} +0 -0
package/risk/index.d.ts
CHANGED
|
@@ -194,12 +194,12 @@ export const NPM_SYMLINKS_ABOVE: number
|
|
|
194
194
|
// lay them out (npm/tarball.js): each entry's name as stored past its first
|
|
195
195
|
// component, whatever that is, and a file under no directory at its name, as
|
|
196
196
|
// pnpm installs it; a hard link is the file it names again, a symlink its
|
|
197
|
-
// target as stored (`link`)
|
|
197
|
+
// target as stored (`link`), a file with an execute bit `executable`. `refuse` is called, and throws, with
|
|
198
198
|
// `tarball-conflict` where the files conflict (two at one path that differ, a
|
|
199
199
|
// file within another), and with `package-too-large` past `maxFiles` files or
|
|
200
200
|
// `maxBytes` bytes.
|
|
201
|
-
export function npmTarLayout(entries: Iterable<Pick<Entry, 'name' | 'storedName' | 'type' | 'data' | 'linkname'>>, bounds: { maxFiles: number; maxBytes: number },
|
|
202
|
-
refuse: (code: 'tarball-conflict' | 'package-too-large') => never): Map<string, { bytes: Uint8Array; link?: string }>
|
|
201
|
+
export function npmTarLayout(entries: Iterable<Pick<Entry, 'name' | 'storedName' | 'type' | 'data' | 'linkname' | 'mode'>>, bounds: { maxFiles: number; maxBytes: number },
|
|
202
|
+
refuse: (code: 'tarball-conflict' | 'package-too-large') => never): Map<string, { bytes: Uint8Array; link?: string; executable?: true }>
|
|
203
203
|
|
|
204
204
|
// GitHub Actions (actions/), a workflow GitHub can't run thrown as
|
|
205
205
|
// @preventive/lockfile's YamlError. A finding of a workflow's, its `line` from 1; of a reference's own code,
|
package/risk/npm/assess.js
CHANGED
|
@@ -19,7 +19,7 @@ import { npmRiskScore } from './score.js'
|
|
|
19
19
|
// Which reading of a version an assessment kept (`risk/npm/assessments`) is:
|
|
20
20
|
// one more whenever a heuristic changes what it finds, so one kept by an
|
|
21
21
|
// older reading is read anew.
|
|
22
|
-
const RISK_VERSION =
|
|
22
|
+
const RISK_VERSION = 21
|
|
23
23
|
|
|
24
24
|
// How long an assessment kept may be as JSON, and what risk reads of either
|
|
25
25
|
// version's files: a package past it, whose files name thousands of hosts or
|
package/risk/npm/tarball.js
CHANGED
|
@@ -35,13 +35,13 @@ export function npmTarPath(storedName) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
const sameBytes = (a, b) => a.length === b.length && a.every((byte, at) => byte === b[at])
|
|
38
|
-
const sameFile = (a, b) => a.link === b.link && sameBytes(a.bytes, b.bytes)
|
|
38
|
+
const sameFile = (a, b) => a.link === b.link && a.executable === b.executable && sameBytes(a.bytes, b.bytes)
|
|
39
39
|
const encoder = new TextEncoder()
|
|
40
40
|
|
|
41
41
|
// Every file a tar archive holds, by package path (npmTarPath): `{ bytes }`,
|
|
42
|
-
// whether or not an installer installs it
|
|
43
|
-
//
|
|
44
|
-
// bun skip it). A hard link is the file it names again, as tar has it (npm and pnpm 12 skip it, pnpm 10 and 11
|
|
42
|
+
// whether or not an installer installs it, `executable` where its mode has an
|
|
43
|
+
// execute bit; a symlink `{ bytes, link }`, its target as stored and that
|
|
44
|
+
// target's UTF-8 (Yarn installs it; npm, pnpm and bun skip it). A hard link is the file it names again, as tar has it (npm and pnpm 12 skip it, pnpm 10 and 11
|
|
45
45
|
// write it empty); a file at the package's own place (`package/.`) sits at
|
|
46
46
|
// its name in the archive. Where the archive's own files conflict, it is
|
|
47
47
|
// refused as `tarball-conflict`, rather than read as one installer does: two
|
|
@@ -60,8 +60,8 @@ export function npmTarLayout(entries, { maxFiles, maxBytes }, refuse) {
|
|
|
60
60
|
// Each file by its name in the archive, which a hard link names.
|
|
61
61
|
const named = new Map()
|
|
62
62
|
let total = 0
|
|
63
|
-
for (const { name, storedName, type, data, linkname } of entries) {
|
|
64
|
-
const file = type === 'hardlink' ? named.get(linkname) : type === 'file' || type === 'contiguous-file' ? { bytes: data }
|
|
63
|
+
for (const { name, storedName, type, data, linkname, mode } of entries) {
|
|
64
|
+
const file = type === 'hardlink' ? named.get(linkname) : type === 'file' || type === 'contiguous-file' ? { bytes: data, ...mode & 0o111 ? { executable: true } : {} }
|
|
65
65
|
: type === 'symlink' ? { bytes: encoder.encode(linkname), link: linkname } : undefined
|
|
66
66
|
if (file === undefined) continue
|
|
67
67
|
named.set(name, file)
|
|
@@ -14,7 +14,7 @@ import { prepareComparison } from '../common/bundle-comparison.js'
|
|
|
14
14
|
import type { BundleDetails } from '../common/bundle-metadata.js'
|
|
15
15
|
import type { OpenedBlob } from './blob-store.ts'
|
|
16
16
|
import { encodeBrotli } from './brotli.ts'
|
|
17
|
-
import { type NpmPackageFile, type NpmVersionDocument, npmFileRows } from './npm-packages.ts'
|
|
17
|
+
import { type NpmPackageFile, type NpmVersionDocument, npmExecutablePaths, npmFileRows } from './npm-packages.ts'
|
|
18
18
|
import type { NpmPatch } from './npm-patch.ts'
|
|
19
19
|
import { opened } from './pretty-print.ts'
|
|
20
20
|
|
|
@@ -23,11 +23,11 @@ import { opened } from './pretty-print.ts'
|
|
|
23
23
|
export const emptySide = (): BundleDetails => ({ integrity: '(empty)', kind: 'sourcemap', size: 0, json: { version: 3, sources: [], sourcesContent: [] } })
|
|
24
24
|
|
|
25
25
|
// A version's files as the viewer reads them for a comparison (ui/view/npm-package.js
|
|
26
|
-
// npmPackageDetails): its texts, and those that are not text by their size and digest, a symlink's target too.
|
|
27
|
-
export function npmComparedSide(integrity: string, files: NpmPackageFile[]): BundleDetails & { npmBinaries: Map<string, { size: number; digest: string; link?: string }> } {
|
|
26
|
+
// npmPackageDetails): its texts, and those that are not text by their size and digest, a symlink's target too, and which are executable.
|
|
27
|
+
export function npmComparedSide(integrity: string, files: NpmPackageFile[]): BundleDetails & { npmBinaries: Map<string, { size: number; digest: string; link?: string }>; npmExecutable: Set<string> } {
|
|
28
28
|
const rows = npmFileRows(files)
|
|
29
29
|
return {
|
|
30
|
-
integrity, kind: 'sourcemap', size: 0,
|
|
30
|
+
integrity, kind: 'sourcemap', size: 0, npmExecutable: new Set(npmExecutablePaths(files)),
|
|
31
31
|
json: { version: 3, sources: rows.map(([path]) => path), sourcesContent: rows.map(([, , text]) => text) },
|
|
32
32
|
npmBinaries: new Map(rows.flatMap(([path, size, text, digest, link]) => (text === null ? [[path, { size, digest: digest!, ...link === undefined ? {} : { link } }] as const] : []))),
|
|
33
33
|
}
|
|
@@ -45,6 +45,7 @@ export async function comparisonBody(base: BundleDetails, other: BundleDetails,
|
|
|
45
45
|
// the viewer reads a version's (npm-loads.ts loadNpmPackageBody), with the
|
|
46
46
|
// patch, as sent: `{ name, version, private, integrity, patch, files }`.
|
|
47
47
|
export async function patchedVersionBody(doc: NpmVersionDocument, patch: NpmPatch, files: NpmPackageFile[]): Promise<OpenedBlob> {
|
|
48
|
-
const json = JSON.stringify({ name: doc.name, version: doc.version, private: doc.private, integrity: doc.dist.integrity, patch, files: npmFileRows(files)
|
|
48
|
+
const json = JSON.stringify({ name: doc.name, version: doc.version, private: doc.private, integrity: doc.dist.integrity, patch, files: npmFileRows(files),
|
|
49
|
+
executable: npmExecutablePaths(files) })
|
|
49
50
|
return opened(await encodeBrotli(Buffer.from(json)))
|
|
50
51
|
}
|
package/server-managed/http.ts
CHANGED
|
@@ -236,7 +236,7 @@ import { canDeleteComment, parseCommentBody } from '../common/managed/comments.t
|
|
|
236
236
|
import { ManagedMutationError, reportReferenceSnapshot } from './management.ts'
|
|
237
237
|
import { confirmedDefaultOffered, readConfirmedOffered, withConfirmedOffered } from './report-opening.ts'
|
|
238
238
|
import { BundleBuildError, buildRepositoryBundle, buildRepositoryLockfile, parseBundleBuild, withBundleBuildLease } from './bundle-build.ts'
|
|
239
|
-
import { NpmPackageError, type NpmReader, type NpmVersionDocument, type NpmVersionStore, VERSION_KEPT_MS, canReadPrivateNpm, npmFileRows, npmPublishTime, npmScopesCount, npmTarballFilename, readNpmVersion, readNpmVersions, readTogether } from './npm-packages.ts'
|
|
239
|
+
import { NpmPackageError, type NpmReader, type NpmVersionDocument, type NpmVersionStore, VERSION_KEPT_MS, canReadPrivateNpm, npmExecutablePaths, npmFileRows, npmPublishTime, npmScopesCount, npmTarballFilename, readNpmVersion, readNpmVersions, readTogether } from './npm-packages.ts'
|
|
240
240
|
import { loadNpmFiles, loadNpmPackageBody, loadNpmTarball } from './npm-loads.ts'
|
|
241
241
|
import { type ReadPatch, type RequestedPatch, foundPatch, keptPatch, patchedFiles, readPatch, requestedPatch, withPatchFiles } from './npm-patch.ts'
|
|
242
242
|
import { type RepositoryCodeKept, loadRepositoryCodeBody, repositoryCodeFits, repositoryCodeKept } from './repository-code.ts'
|
|
@@ -269,7 +269,7 @@ import { STAMP_READ, repositoryStamp } from './repository-stamp.ts'
|
|
|
269
269
|
import { ISSUES_LIST_READ_VERSION, type IssueList, type Listed, PULLS_READ_VERSION, type PullList, pullsReadTo, readIssues, readPulls } from './repository-pulls.ts'
|
|
270
270
|
import { AGENT_MARKS_READ } from './app-agents.ts'
|
|
271
271
|
import { releaseCommits } from './release-commits.ts'
|
|
272
|
-
import { computeBundleDiff } from '../common/bundle-compare-diff.js'
|
|
272
|
+
import { bundleFileMeta, computeBundleDiff } from '../common/bundle-compare-diff.js'
|
|
273
273
|
import type { ReviewChange, ReviewContext, ReviewInput, ReviewedTarballs } from './dependency-reviews.ts'
|
|
274
274
|
import { allowedReviewVerdicts, isReviewableFile, npmReviewVerdictLimit, npmTakenDown } from '../common/dependency-reviews.js'
|
|
275
275
|
import { type NpmAdvisoryOptions, npmAdvisories, npmCommitTags, npmDownloads, npmGithubStats, npmKnown, npmLatestRepo, npmSocketReport } from './npm-insights.ts'
|
|
@@ -5327,10 +5327,12 @@ async function handleNpmReviews(req: IncomingMessage, res: ServerResponse, deps:
|
|
|
5327
5327
|
}
|
|
5328
5328
|
if (change?.action === 'publish' || change?.action === 'save') {
|
|
5329
5329
|
const patchOf = [patchRead, basePatchRead]
|
|
5330
|
-
const
|
|
5331
|
-
|
|
5330
|
+
const lists = files.map((list, at) => patchOf[at] ? patchedFiles(list, patchOf[at].files) : list)
|
|
5331
|
+
const maps = lists.map(list => new Map<string, unknown>(npmFileRows(list).map(([path, size, text, digest]) => [path, text ?? { format: 'digest', size, digest }])))
|
|
5332
|
+
// A file made executable or not is one changed, as Compare shows it.
|
|
5333
|
+
const modes = lists.map(list => bundleFileMeta({ npmExecutable: new Set(npmExecutablePaths(list)) }))
|
|
5332
5334
|
const after = maps[0]!, before = maps[1] ?? new Map<string, unknown>()
|
|
5333
|
-
const diff = computeBundleDiff(before, after, () => '.')
|
|
5335
|
+
const diff = computeBundleDiff(before, after, () => '.', undefined, [modes[1] ?? null, modes[0]!])
|
|
5334
5336
|
const changed: { path: string; basePath?: string }[] = [...diff.files.onlyBase, ...diff.files.onlyOther, ...diff.files.changed]
|
|
5335
5337
|
const reviewable = (file: typeof changed[number]) => isReviewableFile(before.get(file.basePath ?? file.path), after.get(file.path))
|
|
5336
5338
|
const reviewedPath = change.action === 'save' ? change.entry.file : null
|
|
@@ -10,7 +10,7 @@ import { CompressionError, decompress } from '@preventive/archive/compression.js
|
|
|
10
10
|
import { encodeBrotli } from './brotli.ts'
|
|
11
11
|
import { keptBriefly } from './kept-briefly.ts'
|
|
12
12
|
import { MAX_NPM_PACKAGE_BYTES, MAX_NPM_PACKAGE_FILES, NPM_REGISTRY, NpmPackageError, type NpmPackageFile, type NpmVersionDocument, type TarReading,
|
|
13
|
-
askUpstream, npmFileRows, npmPublishTime, npmToken, readNpmTar } from './npm-packages.ts'
|
|
13
|
+
askUpstream, npmExecutablePaths, npmFileRows, npmPublishTime, npmToken, readNpmTar } from './npm-packages.ts'
|
|
14
14
|
import { keepFile, readKeptFile, upstreamCachePath } from './upstream-cache.ts'
|
|
15
15
|
|
|
16
16
|
// The tar stream a package's files may come in, headers and padding included.
|
|
@@ -253,7 +253,7 @@ export function loadNpmPackageBody(doc: NpmVersionDocument, known: () => object
|
|
|
253
253
|
const { files, tarballSize } = await unpackedOf(doc)
|
|
254
254
|
return encodeBrotli(Buffer.from(JSON.stringify({
|
|
255
255
|
name: doc.name, version: doc.version, private: doc.private, integrity: doc.dist.integrity, tarballSize,
|
|
256
|
-
published: await published(), manifest: doc.manifest, files: npmFileRows(files), known: known(),
|
|
256
|
+
published: await published(), manifest: doc.manifest, files: npmFileRows(files), executable: npmExecutablePaths(files), known: known(),
|
|
257
257
|
})))
|
|
258
258
|
})
|
|
259
259
|
}
|
|
@@ -381,7 +381,11 @@ export function npmPublishTime(doc: Pick<NpmVersionDocument, 'name' | 'version'
|
|
|
381
381
|
}
|
|
382
382
|
|
|
383
383
|
// A symlink's `link` is its target as stored, its bytes that target's: no text, whatever they spell.
|
|
384
|
-
|
|
384
|
+
// One with an execute bit is `executable`.
|
|
385
|
+
export interface NpmPackageFile { path: string; bytes: Uint8Array; link?: string; executable?: true }
|
|
386
|
+
|
|
387
|
+
// The paths of `files` that are executable, as the viewer gets them beside their rows.
|
|
388
|
+
export const npmExecutablePaths = (files: NpmPackageFile[]) => files.flatMap(file => file.executable ? [file.path] : [])
|
|
385
389
|
|
|
386
390
|
// Paths in the order a package's files are read in (readNpmTar), and
|
|
387
391
|
// Compare's: by their UTF-16 code units, as a plain sort orders them.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Paths as git writes them in a diff's headers (npm-patch.ts parsePatch):
|
|
2
|
+
// quoted as C writes a string where they need it, prefixed `a/` and `b/`.
|
|
3
|
+
import { Buffer } from 'node:buffer'
|
|
4
|
+
import { NpmPackageError } from './npm-packages.ts'
|
|
5
|
+
|
|
6
|
+
const unreadable = () => new NpmPackageError(422, 'patch-unreadable')
|
|
7
|
+
|
|
8
|
+
// A path as git writes it, unquoted where quoted (as C writes a string, its
|
|
9
|
+
// bytes past ASCII in octal); null where it is quoted otherwise.
|
|
10
|
+
const ESCAPES: Record<string, number> = { a: 7, b: 8, t: 9, n: 10, v: 11, f: 12, r: 13, '"': 34, '\\': 92 }
|
|
11
|
+
export function unquoted(path: string): string | null {
|
|
12
|
+
if (!path.startsWith('"')) return path
|
|
13
|
+
const bytes: number[] = []
|
|
14
|
+
for (let at = 1; at < path.length; at++) {
|
|
15
|
+
const char = path[at]!
|
|
16
|
+
if (char === '"') return at === path.length - 1 ? new TextDecoder().decode(Uint8Array.from(bytes)) : null
|
|
17
|
+
if (char !== '\\') { bytes.push(...Buffer.from(char)); continue }
|
|
18
|
+
const next = path[++at] ?? ''
|
|
19
|
+
const octal = /^[0-3][0-7]{2}/u.exec(path.slice(at))?.[0]
|
|
20
|
+
if (octal) { bytes.push(Number.parseInt(octal, 8)); at += 2 }
|
|
21
|
+
else if (next in ESCAPES) bytes.push(ESCAPES[next]!)
|
|
22
|
+
else return null
|
|
23
|
+
}
|
|
24
|
+
return null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// A side's path in the package, as a `---` or `+++` line names it after its
|
|
28
|
+
// prefix (`a/` or `b/`), git's tab after one with a space in it left out;
|
|
29
|
+
// null for none (`/dev/null`).
|
|
30
|
+
export function sidePath(named: string, prefix: string): string | null {
|
|
31
|
+
const path = unquoted(named.endsWith('\t') ? named.slice(0, -1) : named)
|
|
32
|
+
if (path === '/dev/null') return null
|
|
33
|
+
if (path === null || !path.startsWith(prefix)) throw unreadable()
|
|
34
|
+
return path.slice(prefix.length)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// The paths a `diff --git` line names, where they are the same, as git
|
|
38
|
+
// writes them for a file neither renamed nor copied: `a/<path> b/<path>`.
|
|
39
|
+
export function gitPath(named: string): string | null {
|
|
40
|
+
if (named.startsWith('"')) {
|
|
41
|
+
const quoted = /^("(?:[^"\\]|\\.)*") ("(?:[^"\\]|\\.)*")$/u.exec(named)
|
|
42
|
+
const [a, b] = quoted ? [unquoted(quoted[1]!), unquoted(quoted[2]!)] : []
|
|
43
|
+
return a?.startsWith('a/') && b?.startsWith('b/') && a.slice(2) === b.slice(2) ? a.slice(2) : null
|
|
44
|
+
}
|
|
45
|
+
const length = (named.length - 5) / 2
|
|
46
|
+
const path = named.slice(2, 2 + length)
|
|
47
|
+
return Number.isInteger(length) && named.startsWith('a/') && named.slice(2 + length) === ` b/${path}` ? path : null
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Whether a `diff --git` line's paths (`rest`, past `diff --git `) are
|
|
51
|
+
// `before` and `after`, as git writes them, either quoted or not.
|
|
52
|
+
export function namesBoth(rest: string, before: string, after: string): boolean {
|
|
53
|
+
const first = rest.startsWith('"') ? /^"(?:[^"\\]|\\.)*"/u.exec(rest)?.[0] : `a/${before}`
|
|
54
|
+
if (first === undefined || !rest.startsWith(`${first} `)) return false
|
|
55
|
+
const second = rest.slice(first.length + 1)
|
|
56
|
+
return unquoted(first) === `a/${before}` && unquoted(second) === `b/${after}`
|
|
57
|
+
}
|
|
@@ -6,14 +6,18 @@
|
|
|
6
6
|
// to the hash the lockfile names it by, as pnpm 10 and later hash it
|
|
7
7
|
// (hashOfPatch; one pnpm 9 names by an md5 isn't read), by which it is kept
|
|
8
8
|
// for good, read of GitHub once; and applied to the version's files as pnpm applies
|
|
9
|
-
// it as it installs it (patch-package's applyPatch, which pnpm 10
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
//
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
16
|
-
//
|
|
9
|
+
// it as it installs it (patch-package's applyPatch, which pnpm 10 bundles):
|
|
10
|
+
// each file it deletes, creates, renames or changes, a change's hunks each
|
|
11
|
+
// found in the file as it was, where its header says, else as many as FUZZ
|
|
12
|
+
// lines either side, its lines the same but for the space they end in, and
|
|
13
|
+
// those it keeps kept as the file has them. pnpm 10, 11 and 12 each read a
|
|
14
|
+
// patch their own way, so one is read only where none installs other than
|
|
15
|
+
// it shows (parsePatch): a line outside what git writes, paths that
|
|
16
|
+
// disagree, a rename that also creates or deletes, or a hunk whose missing
|
|
17
|
+
// final newline the file doesn't bear out, isn't read. A file it makes
|
|
18
|
+
// executable, or no longer, is so, as every pnpm makes it. Nor is a patch of
|
|
19
|
+
// a file's bytes (git's binary patch) or of a mode but 644 and 755, or of a
|
|
20
|
+
// file outside the package, read; and one that doesn't apply fails as a whole.
|
|
17
21
|
import { Buffer } from 'node:buffer'
|
|
18
22
|
import { createHash } from 'node:crypto'
|
|
19
23
|
import { YamlError, parseYaml } from '@preventive/lockfile/yaml.js'
|
|
@@ -27,6 +31,7 @@ import { type Lru, lru } from './lru.ts'
|
|
|
27
31
|
import type { KeptStore } from './npm-kept.ts'
|
|
28
32
|
import { plainObject } from './npm-manifest.ts'
|
|
29
33
|
import { NpmPackageError, type NpmPackageFile, npmFileText, pathOrder } from './npm-packages.ts'
|
|
34
|
+
import { gitPath, namesBoth, sidePath, unquoted } from './npm-patch-paths.ts'
|
|
30
35
|
import { type GithubAsked, type PullDependencies, lockfileFormat, repositoryFile } from './pull-dependencies.ts'
|
|
31
36
|
import { eachOf } from './queue.ts'
|
|
32
37
|
|
|
@@ -77,55 +82,14 @@ const patchFileAt = (fullName: string, token: string, path: string, commit: stri
|
|
|
77
82
|
// first's index, as it reads `-0`, the first line), how many it finds
|
|
78
83
|
// (`length`), and its lines, each without its LF, in runs of a kind
|
|
79
84
|
// (`parts`): those it keeps, removes or adds, the last of a side told where
|
|
80
|
-
// the file has no LF after it (`unended`)
|
|
85
|
+
// the file has no LF after it (`unended`); and whether it makes the file
|
|
86
|
+
// executable, or no longer (`executable`), where it says.
|
|
81
87
|
export interface HunkPart { kind: 'context' | 'deletion' | 'insertion'; lines: string[]; unended?: true }
|
|
82
88
|
export interface PatchHunk { at: number; length: number; parts: HunkPart[] }
|
|
83
|
-
export interface PatchedFile { path: string; from?: string; deleted?: true; created?: true; hunks: PatchHunk[] }
|
|
89
|
+
export interface PatchedFile { path: string; from?: string; deleted?: true; created?: true; executable?: boolean; hunks: PatchHunk[] }
|
|
84
90
|
|
|
85
91
|
const unreadable = () => new NpmPackageError(422, 'patch-unreadable')
|
|
86
92
|
|
|
87
|
-
// A path as git writes it, unquoted where quoted (as C writes a string, its
|
|
88
|
-
// bytes past ASCII in octal); null where it is quoted otherwise.
|
|
89
|
-
const ESCAPES: Record<string, number> = { a: 7, b: 8, t: 9, n: 10, v: 11, f: 12, r: 13, '"': 34, '\\': 92 }
|
|
90
|
-
function unquoted(path: string): string | null {
|
|
91
|
-
if (!path.startsWith('"')) return path
|
|
92
|
-
const bytes: number[] = []
|
|
93
|
-
for (let at = 1; at < path.length; at++) {
|
|
94
|
-
const char = path[at]!
|
|
95
|
-
if (char === '"') return at === path.length - 1 ? new TextDecoder().decode(Uint8Array.from(bytes)) : null
|
|
96
|
-
if (char !== '\\') { bytes.push(...Buffer.from(char)); continue }
|
|
97
|
-
const next = path[++at] ?? ''
|
|
98
|
-
const octal = /^[0-3][0-7]{2}/u.exec(path.slice(at))?.[0]
|
|
99
|
-
if (octal) { bytes.push(Number.parseInt(octal, 8)); at += 2 }
|
|
100
|
-
else if (next in ESCAPES) bytes.push(ESCAPES[next]!)
|
|
101
|
-
else return null
|
|
102
|
-
}
|
|
103
|
-
return null
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// A side's path in the package, as a `---` or `+++` line names it after its
|
|
107
|
-
// prefix (`a/` or `b/`), git's tab after one with a space in it left out;
|
|
108
|
-
// null for none (`/dev/null`).
|
|
109
|
-
function sidePath(named: string, prefix: string): string | null {
|
|
110
|
-
const path = unquoted(named.endsWith('\t') ? named.slice(0, -1) : named)
|
|
111
|
-
if (path === '/dev/null') return null
|
|
112
|
-
if (path === null || !path.startsWith(prefix)) throw unreadable()
|
|
113
|
-
return path.slice(prefix.length)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// The paths a `diff --git` line names, where they are the same, as git
|
|
117
|
-
// writes them for a file neither renamed nor copied: `a/<path> b/<path>`.
|
|
118
|
-
function gitPath(named: string): string | null {
|
|
119
|
-
if (named.startsWith('"')) {
|
|
120
|
-
const quoted = /^("(?:[^"\\]|\\.)*") ("(?:[^"\\]|\\.)*")$/u.exec(named)
|
|
121
|
-
const [a, b] = quoted ? [unquoted(quoted[1]!), unquoted(quoted[2]!)] : []
|
|
122
|
-
return a?.startsWith('a/') && b?.startsWith('b/') && a.slice(2) === b.slice(2) ? a.slice(2) : null
|
|
123
|
-
}
|
|
124
|
-
const length = (named.length - 5) / 2
|
|
125
|
-
const path = named.slice(2, 2 + length)
|
|
126
|
-
return Number.isInteger(length) && named.startsWith('a/') && named.slice(2 + length) === ` b/${path}` ? path : null
|
|
127
|
-
}
|
|
128
|
-
|
|
129
93
|
// The hunk whose `@@` line is at `at` of `lines`, those before `end` read,
|
|
130
94
|
// and the line after it, as patch-package reads it: a line of its own
|
|
131
95
|
// kind, else of those it keeps where it is empty, or a CR alone.
|
|
@@ -156,11 +120,16 @@ function readHunk(lines: string[], at: number, end: number): { hunk: PatchHunk;
|
|
|
156
120
|
}
|
|
157
121
|
|
|
158
122
|
// A patch's files as git's diff writes them, as pnpm writes a patch: a file's
|
|
159
|
-
// `diff --git` line, its headers, the paths its sides have, and its hunks
|
|
160
|
-
//
|
|
161
|
-
//
|
|
162
|
-
//
|
|
163
|
-
//
|
|
123
|
+
// `diff --git` line, its headers, the paths its sides have, and its hunks.
|
|
124
|
+
// One whose own lines end in CRLFs, as an editor or git's autocrlf leaves
|
|
125
|
+
// one, is read as patch-package reads it: its headers but their CRs, its
|
|
126
|
+
// hunks' lines with them. pnpm 10 and 11 also read hunks where git puts none
|
|
127
|
+
// (with no `diff --git` line, past a blank or `index` line, after another
|
|
128
|
+
// file's hunks) and pnpm 12 doesn't, so a line git doesn't write is refused,
|
|
129
|
+
// but blank lines at the end. So are a `diff --git` line naming other paths
|
|
130
|
+
// than its sides (pnpm 10 and 11 take one, pnpm 12 the other), a rename that
|
|
131
|
+
// also creates or deletes, and a `new mode` line without its `old mode`
|
|
132
|
+
// (pnpm 12 alone reads one). Throws for one it can't read, or of bytes.
|
|
164
133
|
export function parsePatch(patch: string): PatchedFile[] {
|
|
165
134
|
const lines = patch.split('\n')
|
|
166
135
|
// The lines read: those but the empty one past the patch's last ending.
|
|
@@ -170,37 +139,47 @@ export function parsePatch(patch: string): PatchedFile[] {
|
|
|
170
139
|
const files: PatchedFile[] = []
|
|
171
140
|
for (let at = 0; at < lines.length;) {
|
|
172
141
|
const head = headerAt(at++)
|
|
173
|
-
if (
|
|
174
|
-
|
|
142
|
+
if (head === '' && lines.slice(at, end).every((_, i) => headerAt(at + i) === '')) break
|
|
143
|
+
if (!head.startsWith('diff --git ')) throw unreadable()
|
|
144
|
+
let created = false, deleted = false, executable: boolean | undefined, from: string | null = null, to: string | null = null
|
|
175
145
|
let sides: [string | null, string | null] | null = null
|
|
176
|
-
|
|
146
|
+
const seen = new Set<string>()
|
|
147
|
+
for (; at < end && !/^(?:diff --git |@@ |--- )/u.test(lines[at]!); at++) {
|
|
177
148
|
const header = headerAt(at)
|
|
178
149
|
if (header === 'GIT binary patch' || header.startsWith('Binary files ')) throw new NpmPackageError(422, 'patch-unsupported')
|
|
179
|
-
|
|
180
|
-
if (
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
150
|
+
const kind = /^(?:index|similarity index|dissimilarity index|deleted file mode|new file mode|rename from|rename to|old mode|new mode|copy from|copy to) /u.exec(header)?.[0]
|
|
151
|
+
if (kind === undefined || seen.has(kind)) throw unreadable()
|
|
152
|
+
seen.add(kind)
|
|
153
|
+
// A mode it names: `100644`, or `100755` (executable).
|
|
154
|
+
const mode = kind.endsWith('mode ') ? header.slice(kind.length) : undefined
|
|
155
|
+
if (kind.startsWith('copy ') || (mode !== undefined && mode !== '100644' && mode !== '100755')) throw new NpmPackageError(422, 'patch-unsupported')
|
|
156
|
+
if (kind === 'deleted file mode ') deleted = true
|
|
157
|
+
else if (kind === 'new file mode ') { created = true; executable = mode === '100755' }
|
|
158
|
+
else if (kind === 'new mode ') executable = mode === '100755'
|
|
159
|
+
else if (kind === 'rename from ') from = unquoted(header.slice(kind.length))
|
|
160
|
+
else if (kind === 'rename to ') to = unquoted(header.slice(kind.length))
|
|
184
161
|
}
|
|
185
162
|
if (lines[at]?.startsWith('--- ')) {
|
|
186
163
|
if (!lines[at + 1]?.startsWith('+++ ')) throw unreadable()
|
|
187
164
|
sides = [sidePath(headerAt(at).slice(4), 'a/'), sidePath(headerAt(at + 1).slice(4), 'b/')]
|
|
188
165
|
at += 2
|
|
189
166
|
}
|
|
190
|
-
|
|
191
|
-
const
|
|
192
|
-
|
|
193
|
-
const
|
|
194
|
-
if (
|
|
195
|
-
|| (
|
|
167
|
+
if ((from === null) !== (to === null) || (deleted && created) || (from !== null && (deleted || created)) || seen.has('old mode ') !== seen.has('new mode ')) throw unreadable()
|
|
168
|
+
const rest = head.slice('diff --git '.length)
|
|
169
|
+
const path = sides ? (created ? sides[1] : sides[0]) : gitPath(rest)
|
|
170
|
+
const after = to ?? path, before = from ?? path
|
|
171
|
+
if (before == null || after == null || ![before, after].every(isPatchPath) || !namesBoth(rest, before, after)
|
|
172
|
+
|| (sides && (sides[0] !== (created ? null : before) || sides[1] !== (deleted ? null : after)))) throw unreadable()
|
|
196
173
|
const hunks: PatchHunk[] = []
|
|
197
174
|
while (lines[at]?.startsWith('@@ ')) {
|
|
198
175
|
const { hunk, next } = readHunk(lines, at, end)
|
|
199
176
|
hunks.push(hunk)
|
|
200
177
|
at = next
|
|
201
178
|
}
|
|
202
|
-
|
|
203
|
-
|
|
179
|
+
// A file created is its one hunk's lines, as git writes it, which pnpm 10 alone writes of a hunk otherwise.
|
|
180
|
+
if (created && (hunks.length > 1 || hunks.some(hunk => hunk.parts.some(part => part.kind !== 'insertion')))) throw unreadable()
|
|
181
|
+
files.push({ path: deleted ? before : after, ...from === null ? {} : { from: before }, ...deleted ? { deleted: true as const } : {},
|
|
182
|
+
...created ? { created: true as const } : {}, ...executable === undefined || deleted ? {} : { executable }, hunks: deleted ? [] : hunks })
|
|
204
183
|
}
|
|
205
184
|
return files
|
|
206
185
|
}
|
|
@@ -233,6 +212,18 @@ function changesAt(hunk: PatchHunk, lines: string[], at: number): LineChange[] |
|
|
|
233
212
|
return changes
|
|
234
213
|
}
|
|
235
214
|
|
|
215
|
+
// Whether `hunk`, found at `at` of `lines`, may say a side ends with no LF
|
|
216
|
+
// (`unended`): pnpm versions apply that mark alike only where the hunk ends
|
|
217
|
+
// where the file does, and the file agrees: no LF at its end for the old
|
|
218
|
+
// side's mark; one, or the old side's mark, for the new side's.
|
|
219
|
+
function endsAgree(hunk: PatchHunk, lines: string[], at: number): boolean {
|
|
220
|
+
const unended = lines.at(-1) !== ''
|
|
221
|
+
const ending = at + hunk.length === lines.length - (unended ? 0 : 1)
|
|
222
|
+
const pushes = hunk.parts.some(part => part.kind === 'deletion' && part.unended)
|
|
223
|
+
const pops = hunk.parts.some(part => part.kind === 'insertion' && part.unended)
|
|
224
|
+
return (!pushes || (ending && unended)) && (!pops || (ending && (pushes || !unended)))
|
|
225
|
+
}
|
|
226
|
+
|
|
236
227
|
// `text` with `hunks` applied as patch-package applies them (applyPatch):
|
|
237
228
|
// each one's lines found in the text as it was, where its header says, else
|
|
238
229
|
// as near as FUZZ lines either side, the nearer first, and the earlier of
|
|
@@ -243,6 +234,8 @@ function applied(text: string, hunks: PatchHunk[]): string {
|
|
|
243
234
|
const changes = hunks.flatMap(hunk => {
|
|
244
235
|
for (let offset = 0; Math.abs(offset) <= FUZZ; offset = offset < 0 ? -offset : -offset - 1) {
|
|
245
236
|
const found = changesAt(hunk, lines, hunk.at + offset)
|
|
237
|
+
// Where pnpm finds it, whatever its marks say, lest another place be shown changed than it changes.
|
|
238
|
+
if (found && !endsAgree(hunk, lines, hunk.at + offset)) throw doesNotApply()
|
|
246
239
|
if (found) return found
|
|
247
240
|
}
|
|
248
241
|
throw doesNotApply()
|
|
@@ -262,14 +255,16 @@ function applied(text: string, hunks: PatchHunk[]): string {
|
|
|
262
255
|
// A version's `files` with `patch` applied, in the order of their paths, as
|
|
263
256
|
// its tarball's are read; a file it changes the text of must be text. One it
|
|
264
257
|
// creates holds its first hunk's first lines, in place of any there, as
|
|
265
|
-
// patch-package writes it. A
|
|
258
|
+
// patch-package writes it. A file keeps its mode but where the patch says
|
|
259
|
+
// otherwise. A symlink, which pnpm never installs, is none to patch.
|
|
266
260
|
export function patchedFiles(files: NpmPackageFile[], patch: PatchedFile[]): NpmPackageFile[] {
|
|
267
261
|
const byPath = new Map(files.map(file => [file.path, file]))
|
|
268
262
|
const encoder = new TextEncoder()
|
|
269
263
|
for (const file of patch) {
|
|
270
264
|
if (file.created) {
|
|
271
265
|
const first = file.hunks[0]?.parts[0]
|
|
272
|
-
byPath.set(file.path, { path: file.path, bytes: encoder.encode(first ? `${first.lines.join('\n')}${first.unended ? '' : '\n'}` : '')
|
|
266
|
+
byPath.set(file.path, { path: file.path, bytes: encoder.encode(first ? `${first.lines.join('\n')}${first.unended ? '' : '\n'}` : ''),
|
|
267
|
+
...file.executable ? { executable: true as const } : {} })
|
|
273
268
|
continue
|
|
274
269
|
}
|
|
275
270
|
const source = file.from ?? file.path
|
|
@@ -286,7 +281,7 @@ export function patchedFiles(files: NpmPackageFile[], patch: PatchedFile[]): Npm
|
|
|
286
281
|
if (byPath.has(file.path)) throw doesNotApply()
|
|
287
282
|
byPath.delete(source)
|
|
288
283
|
}
|
|
289
|
-
byPath.set(file.path, { path: file.path, bytes: next })
|
|
284
|
+
byPath.set(file.path, { path: file.path, bytes: next, ...(file.executable ?? was.executable) ? { executable: true as const } : {} })
|
|
290
285
|
}
|
|
291
286
|
return [...byPath.values()].toSorted((a, b) => pathOrder(a.path, b.path))
|
|
292
287
|
}
|
|
@@ -13,7 +13,7 @@ import { CacheMissError, type CacheStorage } from './cache-storage.ts'
|
|
|
13
13
|
import { SHA } from './github-values.ts'
|
|
14
14
|
import type { KeptStore } from './npm-kept.ts'
|
|
15
15
|
import { plainObject } from './npm-manifest.ts'
|
|
16
|
-
import { MAX_NPM_JSON_LENGTH, NpmPackageError, npmFileRows } from './npm-packages.ts'
|
|
16
|
+
import { MAX_NPM_JSON_LENGTH, NpmPackageError, npmExecutablePaths, npmFileRows } from './npm-packages.ts'
|
|
17
17
|
import { type NpmLoad, loadPlaces, readTarballFiles, sharedLoad } from './npm-loads.ts'
|
|
18
18
|
|
|
19
19
|
// What a directory may hold, bounded apart from a package's (npm-packages.ts),
|
|
@@ -72,16 +72,19 @@ export function loadRepositoryCodeBody(input: RepositoryCodeInput, tarball: (sym
|
|
|
72
72
|
const places = loadPlaces(listed)
|
|
73
73
|
const maxLength = Math.min(MAX_REPOSITORY_CODE_JSON_LENGTH, places * MAX_NPM_JSON_LENGTH)
|
|
74
74
|
return sharedLoad(`repository ${repoId} ${repo} ${commit} ${path} ${tree}`, async () => {
|
|
75
|
-
let files
|
|
76
|
-
try {
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
let executable, files
|
|
76
|
+
try {
|
|
77
|
+
const read = await readTarballFiles(await tarball(symlinksAbove), { ...REPOSITORY_TAR, symlinksAbove })
|
|
78
|
+
files = npmFileRows(read, maxLength)
|
|
79
|
+
executable = npmExecutablePaths(read)
|
|
80
|
+
} catch (err) { throw directoryError(err) }
|
|
81
|
+
return encodeBrotli(Buffer.from(JSON.stringify({ repoId, repo, commit, path, tree, files, executable })))
|
|
79
82
|
}, 'repository-busy', { places })
|
|
80
83
|
}
|
|
81
84
|
|
|
82
85
|
// The form of the bodies kept, bumped as what a body holds changes
|
|
83
86
|
// (npmFileRows): one kept in another is none to read.
|
|
84
|
-
const KEPT_CODE_VERSION =
|
|
87
|
+
const KEPT_CODE_VERSION = 3
|
|
85
88
|
// The largest body kept. Source text runs, as brotli's JSON, to a third of
|
|
86
89
|
// its bytes or less, and a directory's binary files are named, not held, so
|
|
87
90
|
// this keeps one of some 200 MiB of text: nearly every directory that opens
|
|
@@ -49,7 +49,9 @@ export type RepositoryFailure = Extract<RepositoryRiskLine, { type: 'repo'; erro
|
|
|
49
49
|
// build of it tells (stasis-dependencies.ts): the versions it installs
|
|
50
50
|
// (`dependencies`), that its build is still to be made (`pending`), or why it
|
|
51
51
|
// failed.
|
|
52
|
-
|
|
52
|
+
// `lockfiles`, those its `lockfiles` names, from the repository's root,
|
|
53
|
+
// where it names some: those its builds install from (namedLockfiles).
|
|
54
|
+
export type StasisConfigRow = { path: string; lockfiles?: string[] } & ({ dependencies: StasisDependency[] } | { pending: true } | RiskFailure)
|
|
53
55
|
// A repository's stasis.config.json files, those of its `paths` alone, each
|
|
54
56
|
// what Stasis reaches of it, or why they couldn't be listed.
|
|
55
57
|
export type StasisConfigsRead = { configs: StasisConfigRow[] } | RiskFailure
|
|
@@ -182,10 +184,29 @@ async function readStasis(opened: OpenedRepository, paths: readonly string[] | u
|
|
|
182
184
|
}
|
|
183
185
|
if (configs.length === 0) return null
|
|
184
186
|
return { configs: await Promise.all(configs.map(async path => {
|
|
185
|
-
|
|
187
|
+
const lockfiles = await opened.file(path).then(namedLockfiles(path), () => null)
|
|
188
|
+
try { return { ...stasisConfigRow(path, await stasis(path)), ...lockfiles && { lockfiles } } } catch (error) { return { path, ...failureOf(error) } }
|
|
186
189
|
})) }
|
|
187
190
|
}
|
|
188
191
|
|
|
192
|
+
// The lockfiles a stasis.config.json at `path` names (`lockfiles`), from its
|
|
193
|
+
// directory, as Stasis installs from those alone, each from the repository's
|
|
194
|
+
// root; null where it names none, or isn't JSON, or one is out of the
|
|
195
|
+
// repository.
|
|
196
|
+
export const namedLockfiles = (path: string) => (text: string): string[] | null => {
|
|
197
|
+
let named: unknown
|
|
198
|
+
try { named = (JSON.parse(text) as { lockfiles?: unknown } | null)?.lockfiles } catch { return null }
|
|
199
|
+
if (!Array.isArray(named) || named.length === 0 || !named.every(each => typeof each === 'string' && each !== '')) return null
|
|
200
|
+
const resolved = (named as string[]).map(each => {
|
|
201
|
+
const parts = path.split('/').slice(0, -1)
|
|
202
|
+
for (const part of each.split('/')) {
|
|
203
|
+
if (part === '..') { if (parts.pop() === undefined) return null } else if (part !== '' && part !== '.') parts.push(part)
|
|
204
|
+
}
|
|
205
|
+
return parts.join('/')
|
|
206
|
+
})
|
|
207
|
+
return resolved.every(Boolean) ? resolved as string[] : null
|
|
208
|
+
}
|
|
209
|
+
|
|
189
210
|
// A repository read: its lockfiles listed and read, a few at once, its
|
|
190
211
|
// Dependabot alerts asked, its Actions read and its stasis.config.json files
|
|
191
212
|
// asked meanwhile; its line telling why where listing
|
|
File without changes
|