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

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 (64) hide show
  1. package/common/bundle-imports.js +20 -0
  2. package/common/bundle-metadata.js +1 -1
  3. package/common/bundle-reasons.d.ts +4 -0
  4. package/common/bundle-reasons.js +38 -1
  5. package/common/bundle-sources.d.ts +1 -0
  6. package/common/bundle-sources.js +22 -0
  7. package/common/managed/npm-packages.js +3 -3
  8. package/common/managed/routes.js +23 -11
  9. package/common/managed/stasis-config.ts +7 -0
  10. package/out/activity.js +4 -4
  11. package/out/chunk-5F5FPI75.js +3 -0
  12. package/out/chunk-6ATPGDDI.js +1 -0
  13. package/out/chunk-6YGH7BJG.js +42 -0
  14. package/out/{chunk-ISXL3KOS.js → chunk-A5A3LEMV.js} +1 -1
  15. package/out/chunk-CGRIZ5M5.js +1 -0
  16. package/out/chunk-FUHRMY7R.js +247 -0
  17. package/out/{chunk-J2FWBXFV.js → chunk-LBJVV6UB.js} +1 -1
  18. package/out/chunk-LDO42LAC.js +1 -0
  19. package/out/{chunk-24AKGEH3.js → chunk-NB4JBTKK.js} +1 -1
  20. package/out/{chunk-IZ6MYRYB.js → chunk-R3WUYD4F.js} +1 -1
  21. package/out/chunk-U5C2TNNQ.js +52 -0
  22. package/out/chunk-VG5RH6KN.js +2 -0
  23. package/out/{chunk-XCWGOW63.js → chunk-VR3NRE5V.js} +1 -1
  24. package/out/chunk-WFDXHPT2.js +12 -0
  25. package/out/client-managed-import.js +2 -2
  26. package/out/client-managed.js +19 -19
  27. package/out/compare.js +15 -15
  28. package/out/dialogs.js +38 -38
  29. package/out/graph.js +8 -8
  30. package/out/index.html +9 -9
  31. package/out/scan.js +2 -2
  32. package/out/view.css +1 -1
  33. package/out/view.js +15 -15
  34. package/package.json +11 -8
  35. package/server-managed/activity.ts +21 -12
  36. package/server-managed/bundle-build-diagnostics.d.ts +1 -1
  37. package/server-managed/bundle-build-worker.js +84 -15
  38. package/server-managed/bundle-build.ts +95 -19
  39. package/server-managed/bundle-cache.ts +28 -6
  40. package/server-managed/bundle-dependency-reviews.ts +38 -22
  41. package/server-managed/commit-lockfiles.ts +2 -1
  42. package/server-managed/db-neon.ts +1 -1
  43. package/server-managed/dependency-review-comments.ts +31 -12
  44. package/server-managed/http.ts +127 -59
  45. package/server-managed/locked-packages.ts +34 -14
  46. package/server-managed/lockfile-scope.ts +10 -1
  47. package/server-managed/npm-kept.ts +10 -0
  48. package/server-managed/npm-patch.ts +127 -50
  49. package/server-managed/public-workspace.ts +3 -2
  50. package/server-managed/pull-dependencies.ts +55 -37
  51. package/server-managed/pull-dependency-reviews.ts +15 -11
  52. package/server-managed/report-sources.ts +6 -3
  53. package/server-managed/repository-issues.ts +14 -11
  54. package/server-managed/stasis-dependencies.ts +153 -0
  55. package/out/chunk-65PLAG3I.js +0 -12
  56. package/out/chunk-D34CUNO5.js +0 -247
  57. package/out/chunk-DCBXCBLL.js +0 -52
  58. package/out/chunk-F3UI65ZI.js +0 -42
  59. package/out/chunk-FAG6E5RC.js +0 -3
  60. package/out/chunk-PTFQKLKO.js +0 -1
  61. package/out/chunk-QVKFY4FA.js +0 -1
  62. package/out/chunk-SYXT3SFP.js +0 -2
  63. package/out/chunk-WL3SPQB4.js +0 -1
  64. /package/out/{chunk-WCPJDAYA.js → chunk-D6NVKGGG.js} +0 -0
@@ -0,0 +1,20 @@
1
+ import { bundleSourcemapImports } from './bundle-sourcemap.js'
2
+
3
+ // Include every recorded platform/condition variant; a Metro resolution can
4
+ // be a platform -> file map instead of a single resolved path. A sourcemap
5
+ // records no imports: its edges are what bundle-sourcemap.js reads of it.
6
+ export function bundleImportsAsMap(details) {
7
+ if (details?.kind === 'sourcemap') return bundleSourcemapImports(details)
8
+ const result = new Map()
9
+ if (details?.kind !== 'stasis' || !details.bundle) return result
10
+ for (const byParent of details.bundle.imports.values()) {
11
+ for (const [parent, specMap] of byParent) {
12
+ if (!result.has(parent)) result.set(parent, new Set())
13
+ for (const resolved of specMap.values()) {
14
+ const targets = typeof resolved === 'string' ? [resolved] : resolved instanceof Map ? resolved.values() : []
15
+ for (const target of targets) if (typeof target === 'string') result.get(parent).add(target)
16
+ }
17
+ }
18
+ }
19
+ return result
20
+ }
@@ -210,7 +210,7 @@ export function parseBundleMetadata(data, integrity) {
210
210
  }
211
211
 
212
212
  function parseSourcemapEdges(rows, files) {
213
- if (!Array.isArray(rows)) throw new Error('Invalid sourcemap edges')
213
+ if (!Array.isArray(rows)) throw new TypeError('Invalid sourcemap edges')
214
214
  return rows.map((row) => {
215
215
  if (!Array.isArray(row) || ![2, 3].includes(row.length) || row[0] === row[1] || (row.length === 3 && typeof row[2] !== 'string')
216
216
  || row.slice(0, 2).some((i) => !Number.isSafeInteger(i) || i < 0 || i >= files.length)) throw new Error('Invalid sourcemap edges')
@@ -1,2 +1,6 @@
1
1
  import type { BundleDetails } from './bundle-metadata.js'
2
2
  export function bundleReasons(details: BundleDetails, sourcePaths?: Iterable<string>): Map<string, Set<string>>
3
+ export interface BundleScopes { ids: string[]; has(id: unknown): boolean; files(id: string): Set<string> | null }
4
+ export function bundleScopes(details: BundleDetails, sourcePaths?: Iterable<string>): BundleScopes
5
+ export function scopeLabel(id: string): string
6
+ export function scopeOptions(scopes: BundleScopes): { id: string; label: string }[]
@@ -1,4 +1,7 @@
1
1
  import { bundleFileSizes } from './bundle-sources.js'
2
+ import { bundleImportsAsMap } from './bundle-imports.js'
3
+
4
+ const sizedPaths = (details) => [...bundleFileSizes(details)].filter(([, size]) => size != null).map(([path]) => path)
2
5
 
3
6
  // Reason metadata attributes files to consumers (run, build plugins, etc.).
4
7
  // It is informational and can be absent on older/single-consumer bundles.
@@ -6,7 +9,7 @@ export function bundleReasons(details, sourcePaths) {
6
9
  const reasons = new Map()
7
10
  const raw = details?.kind === 'stasis' ? details.bundle?.reason : null
8
11
  if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return reasons
9
- const paths = new Set(sourcePaths ?? [...bundleFileSizes(details)].filter(([, size]) => size != null).map(([path]) => path))
12
+ const paths = new Set(sourcePaths ?? sizedPaths(details))
10
13
  for (const [reason, files] of Object.entries(raw).toSorted(([a], [b]) => a.localeCompare(b))) {
11
14
  if (!reason || !Array.isArray(files)) continue
12
15
  const present = new Set(files.filter((file) => typeof file === 'string' && paths.has(file)))
@@ -19,3 +22,37 @@ export function bundleReasons(details, sourcePaths) {
19
22
  return reasons
20
23
  }
21
24
 
25
+ // What a bundle's views filter by, each by its id: a reason (`reason:<name>`),
26
+ // or one of its entry points instead (`entry:<path>`), by the files it reaches
27
+ // through the recorded imports. Entry points are offered only where some
28
+ // reason records more than one of them, a bundle recording no reasons
29
+ // counting as one: with one each, a reason's files already are its entry
30
+ // point's.
31
+ export function bundleScopes(details, sourcePaths) {
32
+ const given = sourcePaths && [...sourcePaths]
33
+ const reasons = bundleReasons(details, given)
34
+ const recorded = details?.kind === 'stasis' ? [...details.bundle?.entries ?? []] : []
35
+ const paths = new Set(recorded.length > 1 ? given ?? sizedPaths(details) : [])
36
+ const entries = new Set(recorded.filter((entry) => paths.has(entry)))
37
+ const lists = Object.values(details?.bundle?.reason ?? {}).filter(Array.isArray)
38
+ const several = (files) => new Set(files.filter((file) => entries.has(file))).size > 1
39
+ if (entries.size < 2 || (lists.length > 0 && !lists.some(several))) entries.clear()
40
+ const ids = [...[...reasons.keys()].map((reason) => `reason:${reason}`), ...[...entries].toSorted().map((entry) => `entry:${entry}`)]
41
+ return {
42
+ ids,
43
+ has: (id) => ids.includes(id),
44
+ // A scope's files; null, for every file, for an id that is none of them.
45
+ files(id) {
46
+ if (!ids.includes(id)) return null
47
+ if (id.startsWith('reason:')) return reasons.get(scopeLabel(id))
48
+ const imports = bundleImportsAsMap(details), reached = new Set([scopeLabel(id)])
49
+ // A Set is walked through what is added to it on the way.
50
+ for (const file of reached) for (const target of imports.get(file) ?? []) reached.add(target)
51
+ return new Set([...reached].filter((file) => paths.has(file)))
52
+ },
53
+ }
54
+ }
55
+
56
+ // A scope's name as shown: its reason's, or its entry point's path.
57
+ export const scopeLabel = (id) => id.slice(id.indexOf(':') + 1)
58
+ export const scopeOptions = (scopes) => scopes.ids.map((id) => ({ id, label: scopeLabel(id) }))
@@ -4,4 +4,5 @@ export function bundleSourceLines(content: string): number
4
4
  export function bundleSourceOrder(sources: Map<string, string>): { paths: string[]; numbers: Map<string, number> }
5
5
  export function bundleFilesAsMap(details: BundleDetails): Map<string, string | { format: 'base64'; data: string }>
6
6
  export function bundlePackageDirs(details: BundleDetails): Map<string, string> | null
7
+ export function bundlePackageRepos(details: BundleDetails, dirs?: ReadonlySet<string> | null): Map<string, { github: string; directory?: string; commit: string }>
7
8
  export function bundlePackageVersions(details: BundleDetails, paths?: Iterable<string> | null, keyOf?: (dir: string, info: { name: string; version: string }) => string): Map<string, Set<string>>
@@ -27,6 +27,7 @@
27
27
  // a new bundle kind or field handled here is visible to both.
28
28
 
29
29
  import { Bundle } from '@exodus/stasis-core/bundle'
30
+ import { bundleCommitHash } from './bundle-commit.js'
30
31
  import { sourcemapEntries } from './bundle-sourcemap.js'
31
32
  import { utf8ByteLength } from './utf8.js'
32
33
 
@@ -298,6 +299,27 @@ export function bundlePackageDirs(details) {
298
299
  return map
299
300
  }
300
301
 
302
+ // The repository and commit each package in a (stasis) bundle records
303
+ // for itself, by its module directory (bundlePackageDirs's values): what
304
+ // Stasis stamps on a module from its package.json `repository`, at its
305
+ // `gitHead`. Only modules recording both a GitHub repository and a full
306
+ // commit, and never the root module, whose repository is the bundle's.
307
+ // `dirs`, when given, limits it to those directories. Empty for anything
308
+ // else, sourcemaps and v0 bundles among them.
309
+ export function bundlePackageRepos(details, dirs = null) {
310
+ const repos = new Map()
311
+ if (details?.kind !== 'stasis' || !details.bundle?.modules) return repos
312
+ for (const [dir, info] of details.bundle.modules) {
313
+ if (dir === '.' || (dirs && !dirs.has(dir))) continue
314
+ const github = info?.repo?.github
315
+ const commit = bundleCommitHash(info?.repo?.commit)
316
+ if (typeof github !== 'string' || github === '' || !commit) continue
317
+ const directory = typeof info.repo.directory === 'string' ? info.repo.directory : ''
318
+ repos.set(dir, { github, ...(directory ? { directory } : {}), commit })
319
+ }
320
+ return repos
321
+ }
322
+
301
323
  // Map each named npm dependency a (stasis) bundle carries to the set of
302
324
  // concrete versions present for it: `Map<name, Set<version>>`. Only
303
325
  // `node_modules/...` modules that carry both a name and a non-empty
@@ -10,9 +10,9 @@ const PACKAGE_SPEC = /^(?=.{1,256}$)[\dA-Za-z][\w.+-]*$/u
10
10
  // npm's rule for a scope: lowercase, and not starting with `.` or `_`.
11
11
  const SCOPE = /^@[\da-z~-][\w.~-]*$/u
12
12
  export const MAX_TEAM_NPM_SCOPES = 100
13
- // A pnpm patch's hash as a lockfile names it: a sha256 in hex, or pnpm 9's
14
- // md5 in base32.
15
- const PATCH_HASH = /^(?:[\da-f]{64}|[2-7a-z]{26})$/u
13
+ // A pnpm patch's hash as a lockfile of pnpm 10 or later names it, by which
14
+ // its reviews read it: a sha256 in hex. One pnpm 9 names by an md5 is none.
15
+ const PATCH_HASH = /^[\da-f]{64}$/u
16
16
 
17
17
  export function isNpmPackageName(value) {
18
18
  return typeof value === 'string' && PACKAGE_NAME.test(value)
@@ -1,6 +1,7 @@
1
1
  // Managed client pages only. API paths and E2E share hashes are not routes.
2
2
  import { BUNDLE_TABS } from '../bundle-tabs.js'
3
3
  import { MAX_FINDING_ID_LENGTH, isLinkableFindingId } from '../finding-id.js'
4
+ import { isGithubRepoName } from '../github-pr.ts'
4
5
  import { isNpmPackageName, isNpmPackageSpec, isPatchHash, isPatchPath } from './npm-packages.js'
5
6
  import { filtersOf, filtersQuery } from './team-filters.js'
6
7
 
@@ -101,11 +102,13 @@ export function managedRoutePath(route) {
101
102
  // its mode past the Overview: `/compare/<version>/code` or `/diff`. Review
102
103
  // names the version reviewed against, and, of a version as a pnpm patch
103
104
  // changes it, the patch (`patch`): its hash, and where it is read, a
104
- // repository by its id, a commit and its file's path there,
105
- // `?patch=<hash>&repo=<repo id>&commit=<commit>&path=<path>`.
105
+ // repository by its id, or by its name (`owner/name`) in its place, a commit
106
+ // and its file's path there,
107
+ // `?patch=<hash>&repo=<repo id or name>&commit=<commit>&path=<path>`.
106
108
  export const NPM_TABS = new Set(['overview', 'code', 'search', 'compare', 'review', 'treemap'])
107
109
  // A patch as the server reads one (server-managed/npm-patch.ts requestedPatch).
108
- const isPatch = patch => isPatchHash(patch?.hash) && isRepoId(patch.repoId) && COMMIT.test(patch.commit ?? '') && isPatchPath(patch.path)
110
+ const isPatch = patch => isPatchHash(patch?.hash) && (isRepoId(patch.repoId) || typeof patch.repoId === 'string' && isGithubRepoName(patch.repoId))
111
+ && COMMIT.test(patch.commit ?? '') && isPatchPath(patch.path)
109
112
  function npmPackagePath(route) {
110
113
  if (route.packageName == null) return '/npm'
111
114
  const tab = route.bundleTab ?? 'overview'
@@ -134,7 +137,7 @@ function parseNpmRoute(path, hash, search) {
134
137
  // The full dependency form is canonical; a bare version is a shortcut.
135
138
  const versionOnly = review[3] && /^\d+\.\d+\.\d+(?:[-+].*)?$/u.test(review[3]) && review[4] == null
136
139
  const patch = search.has('patch')
137
- ? { hash: search.get('patch'), repoId: /^[1-9]\d*$/u.test(search.get('repo') ?? '') ? Number(search.get('repo')) : null, commit: search.get('commit'), path: search.get('path') } : null
140
+ ? { hash: search.get('patch'), repoId: /^[1-9]\d*$/u.test(search.get('repo') ?? '') ? Number(search.get('repo')) : search.get('repo'), commit: search.get('commit'), path: search.get('path') } : null
138
141
  if (patch && !isPatch(patch)) return null
139
142
  return { view: 'npm', packageName: review[1], packageSpec: review[2] ?? null, bundleTab: 'review',
140
143
  ...(review[3] ? { reviewPackage: versionOnly ? review[1] : review[3], reviewSpec: versionOnly ? review[3] : review[4] ?? null } : {}), ...(patch ? { patch } : {}) }
@@ -319,13 +322,19 @@ export function resolveManagedRoute(route, teams, adminBundles = []) {
319
322
  if (!['findings', 'files'].includes(route.view)) return route
320
323
  const { teamSlug, reportSlug, ...rest } = route
321
324
  const matches = teams.filter(team => team.slug === teamSlug)
322
- if (!teamSlug || matches.length !== 1) return null
323
- const team = matches[0]
325
+ const team = teamSlug && matches.length === 1 ? matches[0] : null
326
+ const ids = new Set(teams.flatMap(entry => entry.reports ?? []).filter(report => report.slug === reportSlug).map(report => report.id))
327
+ const reportId = reportSlug != null && ids.size === 1 ? [...ids][0] : null
328
+ // A finding's link has to name its finding alone. Its team and report are
329
+ // where it was copied, and its reader may hold the finding elsewhere: each
330
+ // resolves where its slug names one alone, the report in any team, and
331
+ // else to null, for the finding's lookup to prefer
332
+ // (ui/view/managed-finding-link.js). `teamOnly` tells a link to a team's
333
+ // own findings from one whose report resolved to none.
334
+ if (rest.finding) return { ...rest, teamId: team?.id ?? null, reportId, teamOnly: reportSlug == null }
335
+ if (!team) return null
324
336
  if (reportSlug == null) return { ...rest, teamId: team.id, reportId: null }
325
- const reports = teams.flatMap(entry => entry.reports ?? []).filter(report => report.slug === reportSlug)
326
- const ids = new Set(reports.map(report => report.id))
327
- const report = (team.reports ?? []).find(entry => entry.slug === reportSlug)
328
- return report && ids.size === 1 ? { ...rest, teamId: team.id, reportId: report.id } : null
337
+ return (team.reports ?? []).some(entry => entry.id === reportId) ? { ...rest, teamId: team.id, reportId } : null
329
338
  }
330
339
 
331
340
  export function managedRouteForIds(route, teams, adminBundles = []) {
@@ -359,5 +368,8 @@ export function managedRouteForIds(route, teams, adminBundles = []) {
359
368
  const report = reportId == null ? null : team?.reports?.find(entry => entry.id === reportId)
360
369
  if (!team?.slug || (reportId != null && !report?.slug)) return null
361
370
  const result = { ...rest, teamSlug: team.slug, reportSlug: report?.slug ?? null }
362
- return resolveManagedRoute(result, teams) ? result : null
371
+ // Its slugs have to name this team and report, which a finding's link
372
+ // resolves without.
373
+ const resolved = resolveManagedRoute(result, teams)
374
+ return resolved?.teamId === team.id && resolved.reportId === (report?.id ?? null) ? result : null
363
375
  }
@@ -0,0 +1,7 @@
1
+ // Whether `path` names a stasis.config.json a repository's dependency review
2
+ // may hold to in a lockfile's place (server-managed/lockfile-scope.ts): a
3
+ // file of that name, none of a package installed, under a node_modules.
4
+ export function isStasisConfig(path: string): boolean {
5
+ const names = path.split('/')
6
+ return names.at(-1) === 'stasis.config.json' && !names.includes('node_modules')
7
+ }