@preventive/triage 1.0.0-alpha.77 → 1.0.0-alpha.79
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/common/line-diff.d.ts +2 -0
- package/common/line-diff.js +54 -0
- package/common/managed/dependency-routes.js +25 -0
- package/common/managed/finding-values.d.ts +2 -2
- package/common/managed/finding-values.js +128 -34
- package/common/managed/routes.js +9 -12
- package/common/pretty-json.js +95 -0
- package/common/pretty-print.d.ts +1 -0
- package/common/pretty-print.js +6 -0
- package/common/whitespace-insensitive.js +19 -0
- package/out/activity.js +2 -2
- package/out/{chunk-OCE6KQGJ.js → chunk-26W3E5JE.js} +1 -1
- package/out/chunk-3S4YWYOM.js +1 -0
- package/out/{chunk-OQS2USZM.js → chunk-55YIWY3H.js} +1 -1
- package/out/{chunk-IVDE66N5.js → chunk-6VXEPL32.js} +1 -1
- package/out/{chunk-XVKDPU4D.js → chunk-6Y6PZ2BU.js} +1 -1
- package/out/{chunk-S5PPXPAT.js → chunk-ATT2QA77.js} +1 -1
- package/out/{chunk-2V6Q4ZOZ.js → chunk-B64CTMVU.js} +1 -1
- package/out/{chunk-EXQQ5VQJ.js → chunk-BEKYZCPX.js} +1 -1
- package/out/{chunk-S2ZIKK45.js → chunk-EEJA7JBI.js} +1 -1
- package/out/{chunk-4IW3VD3H.js → chunk-FSU2PLJL.js} +1 -1
- package/out/{chunk-N7TD27UJ.js → chunk-IIJK4F4U.js} +1 -1
- package/out/{chunk-I6UQQKAH.js → chunk-LVSLM7HB.js} +1 -1
- package/out/{chunk-T6EXDRB7.js → chunk-MKX6JODK.js} +1 -1
- package/out/chunk-NTJJIEHS.js +259 -0
- package/out/{chunk-NEFCZAIY.js → chunk-PKLVXUEI.js} +1 -1
- package/out/chunk-QBIUW5EF.js +2 -0
- package/out/{chunk-ADMVRLNP.js → chunk-QD3IBSF4.js} +1 -1
- package/out/{chunk-GSNSP3EF.js → chunk-RPNO56H2.js} +1 -1
- package/out/{chunk-QBFT2DDR.js → chunk-UR4WYMIP.js} +1 -1
- package/out/{chunk-5DWOFBKS.js → chunk-V43XH2JQ.js} +1 -1
- package/out/{chunk-UH6NZBSU.js → chunk-VHEXSGGP.js} +1 -1
- package/out/chunk-XLX6XXJF.js +1 -0
- package/out/{chunk-BXQCCW7F.js → chunk-XM4RLC4A.js} +1 -1
- package/out/chunk-Z54AXVCK.js +3 -0
- package/out/client-managed-import.js +1 -1
- package/out/client-managed.js +4 -4
- package/out/compare.js +14 -14
- package/out/dialogs.js +37 -37
- package/out/graph.js +1 -1
- package/out/index.html +9 -7
- package/out/scan.js +2 -2
- package/out/terminal.js +7 -7
- package/out/view.css +1 -1
- package/out/view.js +8 -8
- package/package.json +8 -2
- package/server-managed/dependency-review-comments.ts +17 -10
- package/server-managed/http.ts +83 -19
- package/server-managed/npm-delta-worker.js +58 -12
- package/server-managed/npm-delta.ts +52 -28
- package/server-managed/npm-kept.ts +11 -1
- package/server-managed/pretty-copies.ts +22 -0
- package/server-managed/pretty-format.d.ts +3 -0
- package/server-managed/pretty-format.js +13 -0
- package/server-managed/pretty-print.ts +34 -24
- package/server-managed/public-workspace.ts +1 -1
- package/server-managed/team-reports.ts +25 -15
- package/out/chunk-G6YPDPW7.js +0 -2
- package/out/chunk-JCIIBLKR.js +0 -1
- package/out/chunk-SDLETN3Z.js +0 -3
- package/out/chunk-WGQ7D5DB.js +0 -1
- package/out/chunk-Z6DL5PPO.js +0 -255
- /package/out/{chunk-Z667U2UJ.js → chunk-SZWPYLPC.js} +0 -0
package/common/line-diff.d.ts
CHANGED
|
@@ -5,4 +5,6 @@ export interface ChangeBlock { a0: number; a1: number; b0: number; b1: number }
|
|
|
5
5
|
|
|
6
6
|
export function textLines(text: string): string[]
|
|
7
7
|
export function changeBlocks(before: string, after: string, ignoreWhitespace?: boolean | 'leading'): ChangeBlock[]
|
|
8
|
+
export function indentHiddenBlocks(before: string, after: string): ChangeBlock[]
|
|
9
|
+
export function withSharedBlankLines(before: string, after: string, blankBefore: readonly number[], blankAfter: readonly number[]): { before: string; after: string }
|
|
8
10
|
export function blocksHold(before: string, after: string, blocks: unknown, ignoreWhitespace?: boolean | 'leading'): boolean
|
package/common/line-diff.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
// Lines are numbered the way the diff numbers them: from zero, a final
|
|
7
7
|
// newline ending the last line rather than starting an empty one.
|
|
8
8
|
import { changeSet } from '@preventive/diff'
|
|
9
|
+
import { hidesMixedWhitespace } from '@preventive/compare/view.js'
|
|
9
10
|
|
|
10
11
|
export function textLines(text) {
|
|
11
12
|
if (text === '') return []
|
|
@@ -42,6 +43,59 @@ export function changeBlocks(before, after, ignoreWhitespace = false) {
|
|
|
42
43
|
.map(({ a0, a1, b0, b1 }) => ({ a0, a1, b0, b1 }))
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
// The blocks Compare draws with whitespace hidden: indentation set aside, but
|
|
47
|
+
// not where that would hide blanks of more than one kind changing.
|
|
48
|
+
export function indentHiddenBlocks(before, after) {
|
|
49
|
+
const blocks = changeBlocks(before, after, 'leading')
|
|
50
|
+
return hidesMixedWhitespace(before, after, blocks) ? changeBlocks(before, after) : blocks
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Two printed copies as Compare draws their diff, `{ before, after }`: each
|
|
54
|
+
// without those of its blank lines that are its layout alone (`blankBefore`,
|
|
55
|
+
// `blankAfter`, their numbers: @preventive/compare layoutBlankLines) that the
|
|
56
|
+
// other has none of there. The copies without any are diffed: a blank line
|
|
57
|
+
// stays between two lines that diff leaves alike, where both sides have one
|
|
58
|
+
// there (as many as the side with fewer), and between two lines of one change
|
|
59
|
+
// on its side; one beside a change, or that one side alone has, goes. A
|
|
60
|
+
// printer keeps one wherever the file it printed has one, so blank lines alone
|
|
61
|
+
// then change nothing; and each side drawn is its copy but for blank lines its
|
|
62
|
+
// layout alone holds, those kept drawn empty. A side with no numbers is ''.
|
|
63
|
+
export function withSharedBlankLines(before, after, blankBefore, blankAfter) {
|
|
64
|
+
if (blankBefore.length === 0 && blankAfter.length === 0) return { before, after }
|
|
65
|
+
const [a, b] = [[before, blankBefore], [after, blankAfter]].map(([text, blank]) => {
|
|
66
|
+
const gaps = [], layout = new Set(blank), lines = []
|
|
67
|
+
let run = 0
|
|
68
|
+
textLines(text).forEach((line, i) => {
|
|
69
|
+
if (layout.has(i)) run++
|
|
70
|
+
else {
|
|
71
|
+
lines.push(line)
|
|
72
|
+
gaps.push(run)
|
|
73
|
+
run = 0
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
return { lines, gaps, ends: text.endsWith('\n') }
|
|
77
|
+
})
|
|
78
|
+
const joined = (lines, ends) => (lines.length === 0 ? '' : `${lines.join('\n')}${ends ? '\n' : ''}`)
|
|
79
|
+
// Blank lines drawn before each line of either side without them.
|
|
80
|
+
const [keptA, keptB] = [a, b].map(side => side.gaps.map(() => 0))
|
|
81
|
+
let i = 0, j = 0
|
|
82
|
+
const end = { a0: a.lines.length, a1: a.lines.length, b0: b.lines.length, b1: b.lines.length }
|
|
83
|
+
for (const block of [...changeBlocks(joined(a.lines, a.ends), joined(b.lines, b.ends)), end]) {
|
|
84
|
+
// Lines alike, past the first after a change (or the start).
|
|
85
|
+
for (let k = i + 1, l = j + 1; k < block.a0; k++, l++) keptA[k] = keptB[l] = Math.min(a.gaps[k], b.gaps[l])
|
|
86
|
+
for (let k = block.a0 + 1; k < block.a1; k++) keptA[k] = a.gaps[k]
|
|
87
|
+
for (let k = block.b0 + 1; k < block.b1; k++) keptB[k] = b.gaps[k]
|
|
88
|
+
i = block.a1
|
|
89
|
+
j = block.b1
|
|
90
|
+
}
|
|
91
|
+
// A side as drawn, the text it came as where that is the same: kept by what keeps the drawn texts, a copy alone.
|
|
92
|
+
const drawn = (side, kept, text) => {
|
|
93
|
+
const out = joined(side.lines.map((line, k) => `${'\n'.repeat(kept[k])}${line}`), side.ends)
|
|
94
|
+
return out === text ? text : out
|
|
95
|
+
}
|
|
96
|
+
return { before: drawn(a, keptA, before), after: drawn(b, keptB, after) }
|
|
97
|
+
}
|
|
98
|
+
|
|
45
99
|
// Whether `blocks` take `before`'s lines to `after`'s: each in order and apart
|
|
46
100
|
// from the last, within both texts, and every line between them alike on both
|
|
47
101
|
// sides (alike but for how much whitespace they have where `ignoreWhitespace`,
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// A team's Dependencies: its sub-tabs, `/team/<slug>/dependencies[/<tab>]`, and a pull request's
|
|
2
|
+
// versions reviewed together, `/team/<slug>/dependencies/review/<repo id>/<number>` (`pullReview`).
|
|
3
|
+
export const DEPENDENCY_TABS = new Set(['pulls', 'versions', 'branch', 'reviews'])
|
|
4
|
+
const isPullReview = pull => [pull?.repoId, pull?.number].every(id => Number.isSafeInteger(id) && id > 0)
|
|
5
|
+
|
|
6
|
+
export function dependencyFields(route) {
|
|
7
|
+
if (route.view !== 'workspace-dependencies') return {}
|
|
8
|
+
if (isPullReview(route.pullReview)) return { pullReview: { repoId: route.pullReview.repoId, number: route.pullReview.number } }
|
|
9
|
+
return route.dependencyTab == null ? {} : { dependencyTab: route.dependencyTab }
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function dependenciesPath(slug, route) {
|
|
13
|
+
const { dependencyTab: tab = 'pulls', pullReview } = dependencyFields(route)
|
|
14
|
+
if (!DEPENDENCY_TABS.has(tab)) return null
|
|
15
|
+
if (pullReview) return `/team/${slug}/dependencies/review/${pullReview.repoId}/${pullReview.number}`
|
|
16
|
+
return `/team/${slug}/dependencies${tab === 'pulls' ? '' : `/${tab}`}`
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Undefined where `path` is none of these.
|
|
20
|
+
export function parseDependenciesRoute(path) {
|
|
21
|
+
const match = /^\/team\/([A-Za-z0-9_-]+)\/dependencies\/(?:([a-z]+)|review\/([1-9]\d{0,14})\/([1-9]\d{0,14}))$/u.exec(path)
|
|
22
|
+
if (!match) return undefined
|
|
23
|
+
if (match[3]) return { view: 'workspace-dependencies', teamSlug: match[1], pullReview: { repoId: Number(match[3]), number: Number(match[4]) } }
|
|
24
|
+
return DEPENDENCY_TABS.has(match[2]) ? { view: 'workspace-dependencies', teamSlug: match[1], dependencyTab: match[2] } : null
|
|
25
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export function
|
|
2
|
-
export function
|
|
1
|
+
export function packTeamReports<T extends { repo?: unknown; data: unknown }>(reports: readonly T[]): { reports: T[]; values: Record<string, unknown[]> | null; keys: string[][] | null }
|
|
2
|
+
export function unpackTeamReport<T>(report: T, sent?: { values?: unknown; keys?: unknown }): T | null
|
|
@@ -1,44 +1,138 @@
|
|
|
1
|
-
// A
|
|
2
|
-
// findings
|
|
3
|
-
//
|
|
4
|
-
// (server-managed/team-reports.ts)
|
|
5
|
-
// (client/managed/session.js)
|
|
6
|
-
|
|
1
|
+
// A team's reports tell the same few values over and over across their many
|
|
2
|
+
// findings: their severity, model, type and effort, the files they are in,
|
|
3
|
+
// their packages, repositories and bundles; and each finding tells the same
|
|
4
|
+
// few field names. A team response (server-managed/team-reports.ts) sends
|
|
5
|
+
// each once, read back as it is read (client/managed/session.js):
|
|
6
|
+
//
|
|
7
|
+
// - `values`: by field, the values told of it, the most told first, so that
|
|
8
|
+
// the commonest are a single digit, and each place one is told as its index
|
|
9
|
+
// there. A field is pooled where that sends fewer characters than its
|
|
10
|
+
// values in place, and then every value it is told but null is an index: a
|
|
11
|
+
// report's own `repo`, its data's own fields (but its entries and links)
|
|
12
|
+
// and its findings'.
|
|
13
|
+
// - `keys`: the field names of its findings, by shape, the most told first,
|
|
14
|
+
// and each finding as an array, its shape's index there and then its
|
|
15
|
+
// values in that shape's order. An entry of a report's data that is an
|
|
16
|
+
// array is a group of them; anything in a group that is not a finding is
|
|
17
|
+
// sent as `[-1, it]`.
|
|
7
18
|
|
|
19
|
+
// A report's data's fields holding its entries and links, never pooled.
|
|
20
|
+
const STRUCTURE = new Set(['findings', 'groups', 'links'])
|
|
21
|
+
const NOT_A_FINDING = -1
|
|
22
|
+
|
|
23
|
+
const isObject = value => value !== null && typeof value === 'object' && !Array.isArray(value)
|
|
8
24
|
const entriesKey = data => Array.isArray(data?.findings) ? 'findings' : Array.isArray(data?.groups) ? 'groups' : null
|
|
25
|
+
const findingsOf = data => { const key = entriesKey(data); return key ? data[key].flat().filter(isObject) : [] }
|
|
26
|
+
// A finding's fields as JSON writes them: those holding a value.
|
|
27
|
+
const fieldsOf = finding => Object.keys(finding).filter(field => finding[field] !== undefined)
|
|
9
28
|
|
|
10
|
-
//
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const copy = { ...finding }
|
|
22
|
-
for (const field of FIELDS) if (finding[field] != null) copy[field] = indexOf(finding[field])
|
|
23
|
-
return copy
|
|
29
|
+
// Values as they are counted, each kept by itself: a string as it is, and
|
|
30
|
+
// anything else by its JSON. The most told first, then the first told.
|
|
31
|
+
function counter() {
|
|
32
|
+
const others = new Map(), strings = new Map()
|
|
33
|
+
let seen = 0
|
|
34
|
+
const entryOf = (value, create) => {
|
|
35
|
+
const map = typeof value === 'string' ? strings : others
|
|
36
|
+
const key = typeof value === 'string' ? value : JSON.stringify(value)
|
|
37
|
+
let entry = map.get(key)
|
|
38
|
+
if (!entry && create) map.set(key, entry = { value, count: 0, first: seen++, size: typeof value === 'string' ? JSON.stringify(value).length : key.length, index: -1 })
|
|
39
|
+
return entry
|
|
24
40
|
}
|
|
25
41
|
return {
|
|
26
|
-
|
|
27
|
-
index(
|
|
28
|
-
|
|
29
|
-
|
|
42
|
+
count(value) { entryOf(value, true).count++ },
|
|
43
|
+
index: value => entryOf(value, false).index,
|
|
44
|
+
ranked() {
|
|
45
|
+
const entries = [...strings.values(), ...others.values()].toSorted((a, b) => b.count - a.count || a.first - b.first)
|
|
46
|
+
for (const [index, entry] of entries.entries()) entry.index = index
|
|
47
|
+
return entries
|
|
30
48
|
},
|
|
31
49
|
}
|
|
32
50
|
}
|
|
33
51
|
|
|
34
|
-
// A
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
52
|
+
// A field set as JSON.parse sets it: an own field, whatever its name.
|
|
53
|
+
function put(record, field, value) {
|
|
54
|
+
if (field === '__proto__') Object.defineProperty(record, field, { value, enumerable: true, writable: true, configurable: true })
|
|
55
|
+
else record[field] = value
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// `reports` as a team response sends them, `{ id, filename, repo, data, ... }`
|
|
59
|
+
// each: copies, their values pooled in `values` (null where none is) and their
|
|
60
|
+
// findings shaped by `keys` (null where there are none), the reports
|
|
61
|
+
// themselves left as they are.
|
|
62
|
+
export function packTeamReports(reports) {
|
|
63
|
+
const fields = new Map(), shapes = counter()
|
|
64
|
+
const count = (field, value) => {
|
|
65
|
+
if (value == null) return
|
|
66
|
+
let values = fields.get(field)
|
|
67
|
+
if (!values) fields.set(field, values = counter())
|
|
68
|
+
values.count(value)
|
|
69
|
+
}
|
|
70
|
+
for (const report of reports) {
|
|
71
|
+
count('repo', report.repo)
|
|
72
|
+
if (!isObject(report.data)) continue
|
|
73
|
+
for (const field in report.data) if (!STRUCTURE.has(field)) count(field, report.data[field])
|
|
74
|
+
for (const finding of findingsOf(report.data)) {
|
|
75
|
+
const named = fieldsOf(finding)
|
|
76
|
+
shapes.count(named)
|
|
77
|
+
for (const field of named) count(field, finding[field])
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
const values = {}
|
|
81
|
+
for (const [field, counted] of fields) {
|
|
82
|
+
const entries = counted.ranked()
|
|
83
|
+
let inline = 0, pooled = JSON.stringify(field).length + 3 + entries.length
|
|
84
|
+
for (const [index, entry] of entries.entries()) { inline += entry.count * entry.size; pooled += entry.size + entry.count * String(index).length }
|
|
85
|
+
if (pooled < inline) put(values, field, entries.map(entry => entry.value))
|
|
86
|
+
else fields.delete(field)
|
|
87
|
+
}
|
|
88
|
+
const keys = shapes.ranked().map(entry => entry.value)
|
|
89
|
+
const sent = (field, value) => value != null && fields.has(field) ? fields.get(field).index(value) : value
|
|
90
|
+
const finding = value => {
|
|
91
|
+
const named = fieldsOf(value)
|
|
92
|
+
return [shapes.index(named), ...named.map(field => sent(field, value[field]))]
|
|
93
|
+
}
|
|
94
|
+
const entry = value => Array.isArray(value) ? value.map(inGroup => isObject(inGroup) ? finding(inGroup) : [NOT_A_FINDING, inGroup])
|
|
95
|
+
: isObject(value) ? finding(value) : value
|
|
96
|
+
return {
|
|
97
|
+
values: fields.size > 0 ? values : null,
|
|
98
|
+
keys: keys.length > 0 ? keys : null,
|
|
99
|
+
reports: reports.map(report => {
|
|
100
|
+
const copy = { ...report }
|
|
101
|
+
if (report.repo != null) copy.repo = sent('repo', report.repo)
|
|
102
|
+
if (!isObject(report.data)) return copy
|
|
103
|
+
copy.data = { ...report.data }
|
|
104
|
+
for (const field in report.data) if (!STRUCTURE.has(field) && fields.has(field)) put(copy.data, field, sent(field, report.data[field]))
|
|
105
|
+
const key = entriesKey(report.data)
|
|
106
|
+
if (key) copy.data[key] = report.data[key].map(entry)
|
|
107
|
+
return copy
|
|
108
|
+
}),
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// A report of a team response, as read, given the response's `values` and
|
|
113
|
+
// `keys`: its findings objects again, their values in place of their index;
|
|
114
|
+
// one sent without either as it is. Null where its findings cannot be read.
|
|
115
|
+
export function unpackTeamReport(report, { values = null, keys = null } = {}) {
|
|
116
|
+
if (!isObject(report)) return report
|
|
117
|
+
const pools = new Map(isObject(values) ? Object.entries(values).filter(([, list]) => Array.isArray(list)) : [])
|
|
118
|
+
const shaped = Array.isArray(keys)
|
|
119
|
+
let readable = true
|
|
120
|
+
const value = (field, sent) => Number.isInteger(sent) && pools.has(field) ? pools.get(field)[sent] : sent
|
|
121
|
+
const expanded = record => { for (const [field, list] of pools) if (Number.isInteger(record[field])) put(record, field, list[record[field]]); return record }
|
|
122
|
+
const tuple = sent => {
|
|
123
|
+
const named = keys[sent[0]]
|
|
124
|
+
if (!Array.isArray(named) || named.length !== sent.length - 1) { readable = false; return null }
|
|
125
|
+
const read = {}
|
|
126
|
+
for (const [index, field] of named.entries()) put(read, field, value(field, sent[index + 1]))
|
|
127
|
+
return read
|
|
128
|
+
}
|
|
129
|
+
const isTuple = sent => shaped && Array.isArray(sent) && Number.isInteger(sent[0])
|
|
130
|
+
const inGroup = sent => isTuple(sent) ? sent[0] === NOT_A_FINDING ? sent[1] : tuple(sent) : isObject(sent) ? expanded(sent) : sent
|
|
131
|
+
const entry = sent => Array.isArray(sent) && !isTuple(sent) ? sent.map(inGroup) : inGroup(sent)
|
|
132
|
+
if (report.repo != null) report.repo = value('repo', report.repo)
|
|
133
|
+
if (!isObject(report.data)) return report
|
|
134
|
+
for (const field in report.data) if (!STRUCTURE.has(field) && pools.has(field)) put(report.data, field, value(field, report.data[field]))
|
|
135
|
+
const key = entriesKey(report.data)
|
|
136
|
+
if (key) report.data[key] = report.data[key].map(entry)
|
|
137
|
+
return readable ? report : null
|
|
44
138
|
}
|
package/common/managed/routes.js
CHANGED
|
@@ -5,6 +5,7 @@ import { isGithubRepoName } from '../github-pr.ts'
|
|
|
5
5
|
import { isNpmPackageName, isNpmPackageSpec, isPatchHash, isPatchPath } from './npm-packages.js'
|
|
6
6
|
import { parseRiskRoute, riskPath } from './risk-routes.js'
|
|
7
7
|
import { reviewViewOf, reviewViewQuery } from './review-view-routes.js'
|
|
8
|
+
import { dependenciesPath, dependencyFields, parseDependenciesRoute } from './dependency-routes.js'
|
|
8
9
|
import { filtersOf, filtersQuery } from './team-filters.js'
|
|
9
10
|
|
|
10
11
|
// How Compare reviews the changes, past its Overview: `code`, beside the
|
|
@@ -33,12 +34,9 @@ export const MANAGED_PAGES = Object.freeze({
|
|
|
33
34
|
})
|
|
34
35
|
|
|
35
36
|
// A team's lists, each at /team/<slug>/<what it lists>; its dependencies'
|
|
36
|
-
//
|
|
37
|
-
// scanned at /team/<slug>/risk.
|
|
37
|
+
// pages (dependency-routes.js); and its risk, scanned at /team/<slug>/risk.
|
|
38
38
|
const WORKSPACE_CONTENT_VIEWS = new Set(['workspace-reports', 'workspace-bundles', 'workspace-repositories', 'workspace-dependencies', 'workspace-risk'])
|
|
39
|
-
export
|
|
40
|
-
// A route's `dependencyTab` field, where it names one.
|
|
41
|
-
const dependencyTabField = route => route.view === 'workspace-dependencies' && route.dependencyTab != null ? { dependencyTab: route.dependencyTab } : {}
|
|
39
|
+
export { DEPENDENCY_TABS } from './dependency-routes.js'
|
|
42
40
|
|
|
43
41
|
// Dot-only path components are normalised away by URL parsers, even escaped.
|
|
44
42
|
function findingPath(id) {
|
|
@@ -54,9 +52,8 @@ export function managedRoutePath(route) {
|
|
|
54
52
|
if (route.view === 'npm') return npmPackagePath(route)
|
|
55
53
|
if (route.view === 'repository-code') return repositoryCodePath(route)
|
|
56
54
|
if (WORKSPACE_CONTENT_VIEWS.has(route.view)) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return `/team/${route.teamSlug}/${route.view.slice(10)}${tab === 'pulls' ? '' : `/${tab}`}`
|
|
55
|
+
if (!/^[A-Za-z0-9_-]+$/u.test(route.teamSlug ?? '')) return null
|
|
56
|
+
return route.view === 'workspace-dependencies' ? dependenciesPath(route.teamSlug, route) : `/team/${route.teamSlug}/${route.view.slice(10)}`
|
|
60
57
|
}
|
|
61
58
|
if (route.view === 'bundles') {
|
|
62
59
|
if (!/^[A-Za-z0-9_-]+$/u.test(route.bundleSlug ?? '')
|
|
@@ -291,8 +288,8 @@ export function parseManagedRoute(url) {
|
|
|
291
288
|
if (code !== undefined) return code
|
|
292
289
|
const contentList = /^\/team\/([A-Za-z0-9_-]+)\/(reports|bundles|repositories|dependencies|risk)$/u.exec(path)
|
|
293
290
|
if (contentList) return { view: `workspace-${contentList[2]}`, teamSlug: contentList[1] }
|
|
294
|
-
const dependencies =
|
|
295
|
-
if (dependencies
|
|
291
|
+
const dependencies = parseDependenciesRoute(path)
|
|
292
|
+
if (dependencies !== undefined) return dependencies
|
|
296
293
|
const match = /^\/team\/([^/]+)(?:\/report\/([^/]+))?(?:\/(files)|\/finding\/([^/]+))?$/u.exec(path)
|
|
297
294
|
// Risk's scopes, past its own page (MANAGED_PAGES).
|
|
298
295
|
if (!match) return parseRiskRoute(path) ?? null
|
|
@@ -314,7 +311,7 @@ export function parseManagedRoute(url) {
|
|
|
314
311
|
export function resolveManagedRoute(route, teams, adminBundles = []) {
|
|
315
312
|
if (WORKSPACE_CONTENT_VIEWS.has(route.view)) {
|
|
316
313
|
const matches = teams.filter(team => team.slug === route.teamSlug)
|
|
317
|
-
return matches.length === 1 ? { view: route.view, teamId: matches[0].id, ...
|
|
314
|
+
return matches.length === 1 ? { view: route.view, teamId: matches[0].id, ...dependencyFields(route) } : null
|
|
318
315
|
}
|
|
319
316
|
if (route.view === 'bundles') {
|
|
320
317
|
const { teamSlug, bundleSlug, compareSlug, compareMode, ...rest } = route
|
|
@@ -353,7 +350,7 @@ export function resolveManagedRoute(route, teams, adminBundles = []) {
|
|
|
353
350
|
export function managedRouteForIds(route, teams, adminBundles = []) {
|
|
354
351
|
if (WORKSPACE_CONTENT_VIEWS.has(route.view)) {
|
|
355
352
|
const team = teams.find(entry => entry.id === route.teamId)
|
|
356
|
-
const result = { view: route.view, teamSlug: team?.slug, ...
|
|
353
|
+
const result = { view: route.view, teamSlug: team?.slug, ...dependencyFields(route) }
|
|
357
354
|
return team?.slug && resolveManagedRoute(result, teams) ? result : null
|
|
358
355
|
}
|
|
359
356
|
if (route.view === 'bundles') {
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// JSON pretty-printed for reading, by the viewer (ui/view/pretty-source.js).
|
|
2
|
+
|
|
3
|
+
// Whether a path is JSON, which the viewer formats rather than the server.
|
|
4
|
+
export const jsonPrinted = path => /\.json$/iu.test(path)
|
|
5
|
+
|
|
6
|
+
const isContainer = value => value !== null && typeof value === 'object'
|
|
7
|
+
|
|
8
|
+
// `value` on one line, `{ "a": [1, 2] }`, or null where that is longer than
|
|
9
|
+
// `room`: given up on as soon as it is, as a long one is tried at every level.
|
|
10
|
+
function oneLine(value, room) {
|
|
11
|
+
if (!isContainer(value)) {
|
|
12
|
+
if (typeof value === 'string' && value.length + 2 > room) return null
|
|
13
|
+
const text = JSON.stringify(value)
|
|
14
|
+
return text.length <= room ? text : null
|
|
15
|
+
}
|
|
16
|
+
const array = Array.isArray(value), keys = array ? null : Object.keys(value)
|
|
17
|
+
const count = array ? value.length : keys.length
|
|
18
|
+
if (count === 0) return array ? '[]' : '{}'
|
|
19
|
+
let text = array ? '[' : '{ '
|
|
20
|
+
for (let i = 0; i < count && text.length <= room; i++) {
|
|
21
|
+
if (i > 0) text += ', '
|
|
22
|
+
if (!array) text += `${JSON.stringify(keys[i])}: `
|
|
23
|
+
const part = oneLine(array ? value[i] : value[keys[i]], room - text.length - (array ? 1 : 2))
|
|
24
|
+
if (part === null) return null
|
|
25
|
+
text += part
|
|
26
|
+
}
|
|
27
|
+
text += array ? ']' : ' }'
|
|
28
|
+
return text.length <= room ? text : null
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// `data`, a value JSON.parse returned, laid out as `JSON.stringify(data,
|
|
32
|
+
// undefined, 2)` does, but for each object or array whose one-line form fits
|
|
33
|
+
// its line within `width`, kept on it, and an array of strings alone that
|
|
34
|
+
// doesn't, as many to a line as fit. Throws past `limit` characters, which
|
|
35
|
+
// deep nesting can run to from a short text.
|
|
36
|
+
export function prettyJSON(data, { width = 120, limit = Infinity } = {}) {
|
|
37
|
+
const lines = []
|
|
38
|
+
let length = -1 // no line end before the first line
|
|
39
|
+
const push = line => {
|
|
40
|
+
if ((length += line.length + 1) > limit) throw new RangeError(`The copy would run past ${limit.toLocaleString('en')} characters.`)
|
|
41
|
+
lines.push(line)
|
|
42
|
+
}
|
|
43
|
+
const write = (value, indent, head, tail) => {
|
|
44
|
+
const line = oneLine(value, width - indent.length - head.length - tail.length)
|
|
45
|
+
if (line !== null || !isContainer(value)) {
|
|
46
|
+
push(`${indent}${head}${line ?? JSON.stringify(value)}${tail}`)
|
|
47
|
+
return
|
|
48
|
+
}
|
|
49
|
+
const array = Array.isArray(value), keys = array ? null : Object.keys(value)
|
|
50
|
+
const count = array ? value.length : keys.length
|
|
51
|
+
push(`${indent}${head}${array ? '[' : '{'}`)
|
|
52
|
+
if (array && value.every(item => typeof item === 'string')) {
|
|
53
|
+
const room = width - indent.length - 2
|
|
54
|
+
let row = ''
|
|
55
|
+
for (const [i, item] of value.entries()) {
|
|
56
|
+
const part = `${JSON.stringify(item)}${i < count - 1 ? ',' : ''}`
|
|
57
|
+
if (row && row.length + 1 + part.length > room) {
|
|
58
|
+
push(`${indent} ${row}`)
|
|
59
|
+
row = ''
|
|
60
|
+
}
|
|
61
|
+
row = row ? `${row} ${part}` : part
|
|
62
|
+
}
|
|
63
|
+
push(`${indent} ${row}`)
|
|
64
|
+
} else {
|
|
65
|
+
for (let i = 0; i < count; i++) {
|
|
66
|
+
write(array ? value[i] : value[keys[i]], `${indent} `, array ? '' : `${JSON.stringify(keys[i])}: `, i < count - 1 ? ',' : '')
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
push(`${indent}${array ? ']' : '}'}${tail}`)
|
|
70
|
+
}
|
|
71
|
+
write(data, '', '', '')
|
|
72
|
+
return lines.join('\n')
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// The most characters a text's copy (prettyJsonText, and a source map's
|
|
76
|
+
// listing: sourcemap-listing.js) runs to: four times the largest file
|
|
77
|
+
// formatted, far past what a file not nested hundreds deep needs.
|
|
78
|
+
export const COPY_LIMIT = 16 * 1024 * 1024
|
|
79
|
+
|
|
80
|
+
// A JSON text without the blanks between its tokens.
|
|
81
|
+
const blankless = text => text.replaceAll(/("(?:[^"\\]+|\\.)*")|[\t\n\r ]+/gu, '$1')
|
|
82
|
+
|
|
83
|
+
// A JSON text pretty-printed (prettyJSON, `width` 0 for JSON.stringify's
|
|
84
|
+
// layout), keeping whether it ends in a line end, or null where it isn't JSON.
|
|
85
|
+
// Throws where the copy would read otherwise than the text: a key given
|
|
86
|
+
// twice, an escape or a number respelled.
|
|
87
|
+
export function prettyJsonText(text, { width } = {}) {
|
|
88
|
+
let value
|
|
89
|
+
try { value = JSON.parse(text) } catch { return null }
|
|
90
|
+
if (!text.isWellFormed()) throw new Error('Its text has lone surrogates.')
|
|
91
|
+
const copy = `${prettyJSON(value, { width, limit: COPY_LIMIT })}${text.endsWith('\n') ? '\n' : ''}`
|
|
92
|
+
if (JSON.stringify(JSON.parse(copy)) !== JSON.stringify(value)) throw new Error('The copy reads as another value.')
|
|
93
|
+
if (blankless(text) !== blankless(copy)) throw new Error('The copy would change more than its layout: a key given twice, or an escape, a number or the order of keys written otherwise.')
|
|
94
|
+
return copy
|
|
95
|
+
}
|
package/common/pretty-print.d.ts
CHANGED
|
@@ -3,3 +3,4 @@
|
|
|
3
3
|
export const MAX_PRETTY_BYTES: number
|
|
4
4
|
export function prettyExtension(path: string): string | null
|
|
5
5
|
export function needsPrettyPrint(path: string, text: string, read?: () => { category: string }): boolean
|
|
6
|
+
export function layoutBlankList(blank: unknown): number[] | null
|
package/common/pretty-print.js
CHANGED
|
@@ -28,3 +28,9 @@ export function prettyExtension(path) {
|
|
|
28
28
|
export function needsPrettyPrint(path, text, read = () => npmFileReadability(path, text)) {
|
|
29
29
|
return prettyExtension(path) !== null && printableSize(text) && read().category === 'minified'
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
// The numbers of a copy's blank lines that are its layout alone
|
|
33
|
+
// (@preventive/compare layoutBlankLines), as the server keeps and sends them
|
|
34
|
+
// with its text (server-managed/pretty-print.ts, `{ text, blank }`): `blank`
|
|
35
|
+
// where it is lines' numbers in order, else null.
|
|
36
|
+
export const layoutBlankList = blank => (Array.isArray(blank) && blank.every((line, i) => Number.isSafeInteger(line) && line > (blank[i - 1] ?? -1)) ? blank : null)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// The files a view hides whitespace changes in, their lines' indentation
|
|
2
|
+
// alone (changeBlocks' `leading`): JS/TS, JSON, CSS, HTML/XML, PHP, shell and
|
|
3
|
+
// the brace languages, where indentation means nothing outside a string or
|
|
4
|
+
// text that runs over lines, which is not read (a template's, a heredoc's,
|
|
5
|
+
// `<pre>`). Anything else (Python's or YAML's indentation, a Makefile's tabs)
|
|
6
|
+
// shows all of it. Told by the format a stasis bundle records, else by
|
|
7
|
+
// extension, or by a whole #! line known to run Node, Deno, Bun or a shell.
|
|
8
|
+
const INSENSITIVE_FORMATS = new Set(['module', 'commonjs', 'module-typescript', 'commonjs-typescript', 'json', 'xml', 'php', 'shell', 'gradle', 'cmake',
|
|
9
|
+
'solidity', 'rust', 'java', 'kotlin', 'objc', 'objcpp', 'swift', 'c', 'cpp', 'c-header', 'cpp-header', 'pbxproj'])
|
|
10
|
+
const INSENSITIVE = /\.(?:[cm]?js|jsx|[cm]?ts|tsx|json5?|jsonc|css|scss|less|html?|xhtml|xml|svg|php|sh|bash|zsh|c|h|cc|cpp|cxx|hh|hpp|hxx|java|kts?|go|rs|cs|swift)$/u
|
|
11
|
+
const INSENSITIVE_SCRIPTS = new Set([
|
|
12
|
+
'#!/usr/bin/env node', '#! /usr/bin/env node', '#!/usr/bin/node', '#!/usr/local/bin/node', '#!/usr/bin/env nodejs', '#!/usr/bin/env deno', '#!/usr/bin/env bun',
|
|
13
|
+
'#!/bin/sh', '#! /bin/sh', '#!/bin/sh -e', '#!/usr/bin/env sh', '#!/bin/bash', '#! /bin/bash', '#!/bin/bash -e', '#!/usr/bin/env bash',
|
|
14
|
+
'#!/bin/zsh', '#!/usr/bin/env zsh', '#!/bin/dash',
|
|
15
|
+
])
|
|
16
|
+
export function whitespaceInsensitive(path, text = '', format = undefined) {
|
|
17
|
+
if (typeof format === 'string') return INSENSITIVE_FORMATS.has(format)
|
|
18
|
+
return INSENSITIVE.test(path.toLowerCase()) || (typeof text === 'string' && INSENSITIVE_SCRIPTS.has(text.split('\n', 1)[0]))
|
|
19
|
+
}
|