@preventive/triage 1.0.0-alpha.76 → 1.0.0-alpha.78

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/common/code-language.js +3 -2
  2. package/common/line-diff.d.ts +2 -0
  3. package/common/line-diff.js +54 -0
  4. package/common/managed/dependency-routes.js +25 -0
  5. package/common/managed/routes.js +9 -12
  6. package/common/pretty-json.js +95 -0
  7. package/common/pretty-print.d.ts +1 -0
  8. package/common/pretty-print.js +6 -0
  9. package/common/whitespace-insensitive.js +19 -0
  10. package/out/activity.js +2 -2
  11. package/out/{chunk-OCE6KQGJ.js → chunk-26W3E5JE.js} +1 -1
  12. package/out/chunk-3S4YWYOM.js +1 -0
  13. package/out/{chunk-OQS2USZM.js → chunk-55YIWY3H.js} +1 -1
  14. package/out/{chunk-IVDE66N5.js → chunk-6VXEPL32.js} +1 -1
  15. package/out/{chunk-XVKDPU4D.js → chunk-6Y6PZ2BU.js} +1 -1
  16. package/out/{chunk-HLMQ7QYS.js → chunk-ATT2QA77.js} +1 -1
  17. package/out/{chunk-2V6Q4ZOZ.js → chunk-B64CTMVU.js} +1 -1
  18. package/out/{chunk-EXQQ5VQJ.js → chunk-BEKYZCPX.js} +1 -1
  19. package/out/{chunk-EYTPAODY.js → chunk-BGLN56X6.js} +1 -1
  20. package/out/{chunk-S2ZIKK45.js → chunk-EEJA7JBI.js} +1 -1
  21. package/out/{chunk-O6FA2R5G.js → chunk-EMNIV37E.js} +1 -1
  22. package/out/{chunk-4IW3VD3H.js → chunk-FSU2PLJL.js} +1 -1
  23. package/out/{chunk-MFAB7P3T.js → chunk-I4YPK32I.js} +1 -1
  24. package/out/{chunk-I6UQQKAH.js → chunk-LVSLM7HB.js} +1 -1
  25. package/out/{chunk-T6EXDRB7.js → chunk-MKX6JODK.js} +1 -1
  26. package/out/{chunk-24LZZYAP.js → chunk-NCJQDKPK.js} +1 -1
  27. package/out/chunk-O2NYWLX3.js +259 -0
  28. package/out/{chunk-62QT2RXR.js → chunk-OWIBDEJJ.js} +1 -1
  29. package/out/{chunk-NEFCZAIY.js → chunk-PKLVXUEI.js} +1 -1
  30. package/out/chunk-QBIUW5EF.js +2 -0
  31. package/out/{chunk-ADMVRLNP.js → chunk-QD3IBSF4.js} +1 -1
  32. package/out/{chunk-GSNSP3EF.js → chunk-RPNO56H2.js} +1 -1
  33. package/out/{chunk-QBFT2DDR.js → chunk-UR4WYMIP.js} +1 -1
  34. package/out/{chunk-UH6NZBSU.js → chunk-VHEXSGGP.js} +1 -1
  35. package/out/{chunk-RHOQDAU4.js → chunk-WB3NRZL7.js} +1 -1
  36. package/out/chunk-XLX6XXJF.js +1 -0
  37. package/out/{chunk-BXQCCW7F.js → chunk-XM4RLC4A.js} +1 -1
  38. package/out/client-managed-import.js +1 -1
  39. package/out/client-managed.js +2 -2
  40. package/out/compare.js +14 -14
  41. package/out/dialogs.js +22 -22
  42. package/out/graph.js +1 -1
  43. package/out/index.html +11 -9
  44. package/out/prism.js +1 -1
  45. package/out/scan.js +2 -2
  46. package/out/terminal.js +7 -7
  47. package/out/view.css +1 -1
  48. package/out/view.js +8 -8
  49. package/package.json +8 -2
  50. package/server-managed/dependency-review-comments.ts +35 -27
  51. package/server-managed/http.ts +13 -11
  52. package/server-managed/npm-delta-worker.js +58 -12
  53. package/server-managed/npm-delta.ts +52 -28
  54. package/server-managed/pretty-copies.ts +22 -0
  55. package/server-managed/pretty-format.d.ts +3 -0
  56. package/server-managed/pretty-format.js +13 -0
  57. package/server-managed/pretty-print.ts +34 -24
  58. package/server-managed/public-workspace.ts +1 -1
  59. package/server-managed/pull-dependency-reviews.ts +23 -12
  60. package/out/chunk-JCIIBLKR.js +0 -1
  61. package/out/chunk-UZC7POI4.js +0 -255
  62. package/out/chunk-W5PRH5D7.js +0 -2
  63. package/out/chunk-WGQ7D5DB.js +0 -1
  64. /package/out/{chunk-Z667U2UJ.js → chunk-SZWPYLPC.js} +0 -0
@@ -13,9 +13,10 @@ const EXT_TO_LANG = {
13
13
  sol: 'solidity',
14
14
  php: 'php', phtml: 'php',
15
15
  rs: 'rust',
16
- rb: 'ruby',
16
+ rb: 'ruby', podspec: 'ruby',
17
17
  py: 'python', pyw: 'python', pyi: 'python',
18
18
  java: 'java',
19
+ swift: 'swift',
19
20
  // .h is claimed by C, C++ and Objective-C alike. The C++ grammar
20
21
  // extends the C one, so it is the superset that colours a header
21
22
  // from any of the three; the C grammar would leave a C++ header's
@@ -33,7 +34,7 @@ const FORMAT_TO_LANG = {
33
34
  module: 'javascript', commonjs: 'javascript',
34
35
  'module-typescript': 'typescript', 'commonjs-typescript': 'typescript',
35
36
  json: 'json', solidity: 'solidity', php: 'php', shell: 'bash', rust: 'rust',
36
- java: 'java', objc: 'objectivec', objcpp: 'objectivec',
37
+ java: 'java', swift: 'swift', objc: 'objectivec', objcpp: 'objectivec',
37
38
  c: 'c', 'c-header': 'c', cpp: 'cpp', 'cpp-header': 'cpp',
38
39
  ruby: 'ruby', podspec: 'ruby', podfile: 'ruby', fastlane: 'ruby',
39
40
  'podfile-lock': 'yaml', xml: 'markup',
@@ -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
@@ -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
+ }
@@ -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
- // sub-tabs past the first at /team/<slug>/dependencies/<tab>; and its risk,
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 const DEPENDENCY_TABS = new Set(['pulls', 'versions', 'branch', 'reviews'])
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
- const tab = dependencyTabField(route).dependencyTab ?? 'pulls'
58
- if (!/^[A-Za-z0-9_-]+$/u.test(route.teamSlug ?? '') || !DEPENDENCY_TABS.has(tab)) return null
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 = /^\/team\/([A-Za-z0-9_-]+)\/dependencies\/([a-z]+)$/u.exec(path)
295
- if (dependencies) return DEPENDENCY_TABS.has(dependencies[2]) ? { view: 'workspace-dependencies', teamSlug: dependencies[1], dependencyTab: dependencies[2] } : null
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, ...dependencyTabField(route) } : null
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, ...dependencyTabField(route) }
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
+ }
@@ -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
@@ -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
+ }