@exodus/stasis 1.0.0-beta.14 → 1.0.0-beta.15
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/README.md +1 -0
- package/bin/stasis.js +84 -14
- package/package.json +17 -5
- package/src/audit.js +222 -51
- package/src/cmd/build.js +53 -29
- package/src/cmd/bundle-options.js +10 -7
- package/src/cmd/bundle.js +255 -116
- package/src/cmd/github-bundle.js +7 -8
- package/src/cmd/tokens.js +12 -6
- package/src/define.js +5 -0
- package/src/flow.js +24 -4
- package/src/metro-assets.js +4 -354
- package/src/metro-resolver.js +75 -124
- package/src/parse.js +3 -0
- package/src/resolve-fields.js +107 -372
- package/src/resolve-typescript.js +99 -27
- package/src/scan.js +19 -14
- package/src/sixel.js +333 -0
- package/src/table.js +66 -13
- package/src/validate-notes.d.ts +18 -0
- package/src/validate-notes.js +66 -0
- package/src/validate.d.ts +132 -0
- package/src/validate.js +221 -113
- package/src/vfs-bundle/github.js +3 -1
- package/src/vfs-bundle/prisma.js +102 -29
- package/src/why.js +9 -7
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { basename, dirname, extname, isAbsolute, join, resolve as resolvePath } from 'node:path'
|
|
1
|
+
import { basename, dirname, extname, isAbsolute, join, relative, resolve as resolvePath } from 'node:path'
|
|
2
2
|
|
|
3
|
-
import { isTypeDeclaration } from '@exodus/stasis-core/util'
|
|
3
|
+
import { isTypeDeclaration, relativeEscapes } from '@exodus/stasis-core/util'
|
|
4
4
|
import { diskHost } from '@exodus/stasis-core/host'
|
|
5
|
+
import { untouchedMemo } from './vfs-bundle/lazy.js'
|
|
5
6
|
|
|
6
7
|
// tsc-style module resolution (`--typescript`), shared by BOTH JS resolvers -- scan.js's built-in
|
|
7
8
|
// Node resolver and resolve-fields.js's legacy-field resolver -- so the flag means one thing
|
|
@@ -15,6 +16,9 @@ import { diskHost } from '@exodus/stasis-core/host'
|
|
|
15
16
|
// `./dir` -> `./dir/index.ts`), incl. through a directory's package.json `main`;
|
|
16
17
|
// - the same substitution applied to manifest-declared targets: a package `main`, an `exports`
|
|
17
18
|
// target, a `#name` `imports` target naming a compiled file whose only on-disk form is TS;
|
|
19
|
+
// - tsc's `outDir` -> `rootDir` inversion: a workspace package's unbuilt output (`./dist/x.js`)
|
|
20
|
+
// maps to the source tsc builds it from (`./src/x.ts`; see fromOutputSource), here and in the
|
|
21
|
+
// field resolvers' own probes;
|
|
18
22
|
// - tsconfig `compilerOptions.paths` aliases (see loadTsconfigPaths), consulted for bare
|
|
19
23
|
// specifiers nothing else resolved. Node never probed an alias target, so its completion also
|
|
20
24
|
// tries the JS extensions after the TS ones (`@/x` -> x.ts, then x.js), as tsc does.
|
|
@@ -145,8 +149,10 @@ function probeIndex(dir, exts, host) {
|
|
|
145
149
|
// directory-only ('.', '..', a trailing '/'), so './' never probes the pathological '.ts' dotfile.
|
|
146
150
|
// `completion`/`dir` are off for exports/imports targets: Node requires those to name exact files,
|
|
147
151
|
// so only substitution applies (matching tsc's node16 rules). `js` completes JS extensions too, for
|
|
148
|
-
// a base Node never probed (see completionExts).
|
|
149
|
-
|
|
152
|
+
// a base Node never probed (see completionExts). `outputs` maps what still misses to an unbuilt
|
|
153
|
+
// output's source (fromOutputSource).
|
|
154
|
+
function probeTypescriptTarget(base, { js = false, dirOnly = false, completion = true, dir = true, outputs = null, host = diskHost } = {}) {
|
|
155
|
+
const rules = { js, dirOnly, completion, dir, host }
|
|
150
156
|
const exts = completionExts(js)
|
|
151
157
|
if (!dirOnly) {
|
|
152
158
|
const literal = probe(base, host)
|
|
@@ -166,17 +172,83 @@ function probeTypescriptTarget(base, { js = false, dirOnly = false, completion =
|
|
|
166
172
|
const pkg = readJson(join(base, 'package.json'), host)
|
|
167
173
|
const main = typeof pkg?.main === 'string' && pkg.main.length > 0 ? pkg.main : null
|
|
168
174
|
if (main) {
|
|
169
|
-
// LOAD_AS_FILE(main) with substitution/completion, then LOAD_INDEX(main)
|
|
170
|
-
// falls through to the package index, like Node.
|
|
175
|
+
// LOAD_AS_FILE(main) with substitution/completion, then LOAD_INDEX(main), each of its source
|
|
176
|
+
// too where it is unbuilt; a broken main falls through to the package index, like Node.
|
|
171
177
|
const entry = resolvePath(base, main)
|
|
172
|
-
const
|
|
178
|
+
const fromMain = (path) => probeTypescriptTarget(path, { js, dir: false, host }) ?? probeIndex(path, exts, host)
|
|
179
|
+
const hit = fromMain(entry) ?? fromOutputSource(entry, fromMain, { outputs, host, pkgDir: base })
|
|
173
180
|
if (hit) return hit
|
|
174
181
|
}
|
|
175
|
-
|
|
182
|
+
const hit = probeIndex(base, exts, host)
|
|
183
|
+
if (hit) return hit
|
|
184
|
+
}
|
|
185
|
+
return fromOutputSource(base, (input) => probeTypescriptTarget(input, rules), { outputs, host })
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// --- tsc's `outDir` -> `rootDir` inversion ---
|
|
189
|
+
|
|
190
|
+
// A package's tsc layout, by the tsconfig.json beside its package.json; null without `outDir`
|
|
191
|
+
// (outputs then sit beside their sources, which substitution maps) or in node_modules (installed
|
|
192
|
+
// packages are used as published). Without `rootDir` the root is the tsconfig's directory, as
|
|
193
|
+
// TypeScript 6 takes it; an older tsc infers it from its inputs, which this cannot.
|
|
194
|
+
export function tsconfigOutputs(pkgDir, host = diskHost) {
|
|
195
|
+
const dir = realpathOr(pkgDir, host)
|
|
196
|
+
if (IN_NODE_MODULES.test(dir)) return null
|
|
197
|
+
const file = join(dir, 'tsconfig.json')
|
|
198
|
+
if (!isFile(file, host)) return null
|
|
199
|
+
const { outDir, rootDir } = loadTsconfigCompilerOptions(file, host)
|
|
200
|
+
if (typeof outDir !== 'string') return null
|
|
201
|
+
return { dir, outDir, rootDir: typeof rootDir === 'string' ? rootDir : dir }
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function leniently(lenient, read) {
|
|
205
|
+
try {
|
|
206
|
+
return read()
|
|
207
|
+
} catch (error) {
|
|
208
|
+
if (!lenient) throw error
|
|
209
|
+
return null
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// tsconfigOutputs, cached as a lazy tree allows (untouchedMemo). `lenient` is for builds that only
|
|
214
|
+
// hint, where a tsconfig.json that does not load maps nothing rather than failing the build.
|
|
215
|
+
export function tsconfigOutputsOf({ host = diskHost, lenient = false } = {}) {
|
|
216
|
+
const layouts = untouchedMemo(host.touches, { retouch: host.retouch })
|
|
217
|
+
return (pkgDir) => {
|
|
218
|
+
const dir = realpathOr(pkgDir, host)
|
|
219
|
+
return layouts(dir, () => leniently(lenient, () => tsconfigOutputs(dir, host)))
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// The package whose tsc build `path` would be an output of: the nearest package.json beside a
|
|
224
|
+
// tsconfig.json, named or not. One without (a `type` marker, a manifest copied into `dist/` to
|
|
225
|
+
// publish from) builds nothing. An installed package is none.
|
|
226
|
+
function packageHolding(path, host) {
|
|
227
|
+
for (let dir = dirname(path); basename(dir) !== 'node_modules'; dir = dirname(dir)) {
|
|
228
|
+
if (isFile(join(dir, 'package.json'), host)) {
|
|
229
|
+
if (inNodeModules(dir, host)) return null
|
|
230
|
+
if (isFile(join(dir, 'tsconfig.json'), host)) return dir
|
|
231
|
+
}
|
|
232
|
+
if (dirname(dir) === dir) return null
|
|
176
233
|
}
|
|
177
234
|
return null
|
|
178
235
|
}
|
|
179
236
|
|
|
237
|
+
// tsc's mapping of an output back to its input (tryLoadInputFileForPath): where `path` lies under
|
|
238
|
+
// its package's `outDir`, `probeSource` of the same place under `rootDir` (`dist/x.js` ->
|
|
239
|
+
// `src/x.js`, whose TS siblings substitution finds), else null. Call it only once `path` itself
|
|
240
|
+
// missed: the tsconfig.json is read, and can throw, only then. `pkgDir` is the package that names
|
|
241
|
+
// `path` (its `main`, an `exports` target), where known: its `outDir` may lie outside it
|
|
242
|
+
// (`../../dist/dep`).
|
|
243
|
+
export function fromOutputSource(path, probeSource, { outputs, host = diskHost, pkgDir } = {}) {
|
|
244
|
+
if (outputs == null) return null
|
|
245
|
+
const owner = pkgDir ?? packageHolding(path, host)
|
|
246
|
+
const layout = owner === null ? null : outputs(owner)
|
|
247
|
+
if (layout === null) return null
|
|
248
|
+
const rel = relative(layout.outDir, join(layout.dir, relative(owner, path))) // by the package's real path
|
|
249
|
+
return relativeEscapes(rel) ? null : probeSource(join(layout.rootDir, rel))
|
|
250
|
+
}
|
|
251
|
+
|
|
180
252
|
// --- package `exports`/`imports` map resolution (candidate generation) ---
|
|
181
253
|
|
|
182
254
|
// Expand a target value (string | array | conditions object | null) to the target strings the
|
|
@@ -242,10 +314,13 @@ function manifestTargets(map, subpathKey, conditions) {
|
|
|
242
314
|
|
|
243
315
|
// tsc's mapping of `key` ('.' or './sub') through the `exports` of the package in `pkgDir` (or of
|
|
244
316
|
// a '#name' key through its `imports`): the targets `conditions` select, substitution only (Node
|
|
245
|
-
// requires exports/imports targets to name exact files)
|
|
246
|
-
|
|
317
|
+
// requires exports/imports targets to name exact files) or an unbuilt output's source (`outputs`);
|
|
318
|
+
// the first on disk, or null.
|
|
319
|
+
export function typescriptExportsTarget(pkgDir, exports, key, { conditions = new Set(), outputs = (dir) => tsconfigOutputs(dir, host), host = diskHost } = {}) {
|
|
320
|
+
const probeTarget = (path) => probeTypescriptTarget(path, { completion: false, dir: false, host })
|
|
247
321
|
for (const target of manifestTargets(exports, key, conditions)) {
|
|
248
|
-
const
|
|
322
|
+
const base = resolvePath(pkgDir, target)
|
|
323
|
+
const hit = probeTarget(base) ?? fromOutputSource(base, probeTarget, { outputs, host, pkgDir })
|
|
249
324
|
if (hit) return hit
|
|
250
325
|
}
|
|
251
326
|
return null
|
|
@@ -431,7 +506,8 @@ const declaresWorkspaces = (dir, host) => isFile(join(dir, 'pnpm-workspace.yaml'
|
|
|
431
506
|
// the nearest named package.json at or above `cwd` (or the top-most package.json, where none is
|
|
432
507
|
// named). Never in node_modules: no walk enters a node_modules directory, and resolveTypescriptFallback
|
|
433
508
|
// matches no alias for a file under one. Each config loads once, when first matched; with `lenient`,
|
|
434
|
-
// one that doesn't load matches nothing instead of throwing.
|
|
509
|
+
// one that doesn't load matches nothing instead of throwing. `outputs` is tsconfigOutputsOf's, as
|
|
510
|
+
// lenient.
|
|
435
511
|
export function packageTsconfigPaths(cwd, { host = diskHost, lenient = false, projectCwd } = {}) {
|
|
436
512
|
const stop = projectCwd ? realpathOr(resolvePath(projectCwd), host) : null
|
|
437
513
|
const dirs = [] // cwd and above, while the State's walk would go on; real paths, as importers are read
|
|
@@ -460,15 +536,7 @@ export function packageTsconfigPaths(cwd, { host = diskHost, lenient = false, pr
|
|
|
460
536
|
const matcherOf = (dir) => {
|
|
461
537
|
if (!matchers.has(dir)) {
|
|
462
538
|
const file = join(dir, 'tsconfig.json')
|
|
463
|
-
|
|
464
|
-
if (isFile(file, host)) {
|
|
465
|
-
try {
|
|
466
|
-
matcher = loadTsconfigPaths(file, host)
|
|
467
|
-
} catch (error) {
|
|
468
|
-
if (!lenient) throw error
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
matchers.set(dir, matcher)
|
|
539
|
+
matchers.set(dir, isFile(file, host) ? leniently(lenient, () => loadTsconfigPaths(file, host)) : null)
|
|
472
540
|
}
|
|
473
541
|
return matchers.get(dir)
|
|
474
542
|
}
|
|
@@ -477,6 +545,7 @@ export function packageTsconfigPaths(cwd, { host = diskHost, lenient = false, pr
|
|
|
477
545
|
const dir = packageOf(parentFile)
|
|
478
546
|
return dir === null ? [] : (matcherOf(dir)?.matchPaths(spec) ?? [])
|
|
479
547
|
},
|
|
548
|
+
outputs: tsconfigOutputsOf({ host, lenient }),
|
|
480
549
|
}
|
|
481
550
|
}
|
|
482
551
|
|
|
@@ -505,6 +574,8 @@ export const inNodeModules = (file, host = diskHost) => IN_NODE_MODULES.test(rea
|
|
|
505
574
|
// completion too, as Node never probed the target), then
|
|
506
575
|
// the named package: its `exports` targets (substitution only) when it has
|
|
507
576
|
// them, else its `main`/index (bare root) or subpath (substitution/completion).
|
|
577
|
+
// Any path naming a package's unbuilt output maps to its source (fromOutputSource), by
|
|
578
|
+
// `paths.outputs` where `paths` has it.
|
|
508
579
|
export function resolveTypescriptFallback(parentFile, spec, { conditions = new Set(), paths = null, host = diskHost } = {}) {
|
|
509
580
|
if (inNodeModules(parentFile, host)) return null
|
|
510
581
|
const hit = typescriptTarget(parentFile, spec, { conditions, paths, host })
|
|
@@ -512,17 +583,18 @@ export function resolveTypescriptFallback(parentFile, spec, { conditions = new S
|
|
|
512
583
|
}
|
|
513
584
|
|
|
514
585
|
function typescriptTarget(parentFile, spec, { conditions, paths, host }) {
|
|
586
|
+
const outputs = paths?.outputs ?? ((dir) => tsconfigOutputs(dir, host))
|
|
515
587
|
if (spec.startsWith('#')) {
|
|
516
588
|
const scope = nearestPackage(parentFile, host)
|
|
517
|
-
return scope?.pkg.imports ? typescriptExportsTarget(scope.pkgDir, scope.pkg.imports, spec, { conditions, host }) : null
|
|
589
|
+
return scope?.pkg.imports ? typescriptExportsTarget(scope.pkgDir, scope.pkg.imports, spec, { conditions, outputs, host }) : null
|
|
518
590
|
}
|
|
519
591
|
if (spec.startsWith('./') || spec.startsWith('../') || spec === '.' || spec === '..' || isAbsolute(spec)) {
|
|
520
592
|
const base = isAbsolute(spec) ? spec : resolvePath(dirname(parentFile), spec)
|
|
521
|
-
return probeTypescriptTarget(base, { dirOnly: DIR_ONLY_SPEC.test(spec), host })
|
|
593
|
+
return probeTypescriptTarget(base, { dirOnly: DIR_ONLY_SPEC.test(spec), outputs, host })
|
|
522
594
|
}
|
|
523
595
|
if (paths) {
|
|
524
596
|
for (const target of paths.matchPaths(spec, parentFile)) {
|
|
525
|
-
const hit = probeTypescriptTarget(target, { js: true, dirOnly: target.endsWith('/'), host })
|
|
597
|
+
const hit = probeTypescriptTarget(target, { js: true, dirOnly: target.endsWith('/'), outputs, host })
|
|
526
598
|
if (hit) return hit
|
|
527
599
|
}
|
|
528
600
|
}
|
|
@@ -531,11 +603,11 @@ function typescriptTarget(parentFile, spec, { conditions, paths, host }) {
|
|
|
531
603
|
const pkg = readJson(join(loc.pkgDir, 'package.json'), host) ?? {}
|
|
532
604
|
if (pkg.exports != null) {
|
|
533
605
|
// `exports` fully governs a bare import (main is not a fallback); targets name exact files.
|
|
534
|
-
return typescriptExportsTarget(loc.pkgDir, pkg.exports, loc.subpath === '' ? '.' : `./${loc.subpath}`, { conditions, host })
|
|
606
|
+
return typescriptExportsTarget(loc.pkgDir, pkg.exports, loc.subpath === '' ? '.' : `./${loc.subpath}`, { conditions, outputs, host })
|
|
535
607
|
}
|
|
536
608
|
if (loc.subpath === '') {
|
|
537
609
|
// Bare package root: LOAD_AS_DIRECTORY only (never `node_modules/dep.ts`).
|
|
538
|
-
return probeTypescriptTarget(loc.pkgDir, { dirOnly: true, host })
|
|
610
|
+
return probeTypescriptTarget(loc.pkgDir, { dirOnly: true, outputs, host })
|
|
539
611
|
}
|
|
540
|
-
return probeTypescriptTarget(join(loc.pkgDir, loc.subpath), { dirOnly: DIR_ONLY_SPEC.test(spec), host })
|
|
612
|
+
return probeTypescriptTarget(join(loc.pkgDir, loc.subpath), { dirOnly: DIR_ONLY_SPEC.test(spec), outputs, host })
|
|
541
613
|
}
|
package/src/scan.js
CHANGED
|
@@ -8,7 +8,7 @@ import { inNodeModules, resolveTypescriptFallback, typescriptSiblings } from './
|
|
|
8
8
|
import { branchFolder, parseDefine } from './define.js'
|
|
9
9
|
import { diskHost } from '@exodus/stasis-core/host'
|
|
10
10
|
import { untouchedMemo } from './vfs-bundle/lazy.js'
|
|
11
|
-
import { FLOW_EXTS, stripFlowTypes } from './flow.js'
|
|
11
|
+
import { FLOW_EXTS, hasFlowPragma, stripFlowTypes } from './flow.js'
|
|
12
12
|
|
|
13
13
|
// Static require/import graph walker: parses source, never loads or executes user code.
|
|
14
14
|
// Dynamic specifiers (`require(name)`, `import('./'+x)`) are recorded as unresolved. With
|
|
@@ -18,6 +18,8 @@ import { FLOW_EXTS, stripFlowTypes } from './flow.js'
|
|
|
18
18
|
// -- e.g. a package whose React Native entry is src/index.tsx -- is parsed and carried like any .ts.
|
|
19
19
|
const SCRIPT_EXTS = new Set(['.js', '.cjs', '.mjs', '.ts', '.cts', '.mts', '.jsx', '.tsx'])
|
|
20
20
|
const RESOLVABLE_EXTS = new Set([...SCRIPT_EXTS, '.json'])
|
|
21
|
+
// Whether a file of extension `ext` (`.mjs`) is code a bundle carries as such.
|
|
22
|
+
export const isResolvableExt = (ext) => RESOLVABLE_EXTS.has(ext)
|
|
21
23
|
// The extensions whose name can't tell whether they hold JSX, parsed with JSX enabled only under
|
|
22
24
|
// `jsx` (React Native's JSX-in-.js convention). Excludes the .ts family: TypeScript's `<T>`
|
|
23
25
|
// generics collide with JSX, so tsc/oxc reserve JSX for .tsx — JSX-in-TS belongs in a .tsx file.
|
|
@@ -205,7 +207,7 @@ export class Scan {
|
|
|
205
207
|
// (`empty` = a browser/react-native `false` redirect) and owns builtin handling when set.
|
|
206
208
|
// `jsx` opts the .js/.cjs/.mjs family into JSX syntax (React Native's JSX-in-.js convention);
|
|
207
209
|
// off by default because oxc, like tsc, only auto-enables JSX for .jsx/.tsx by extension.
|
|
208
|
-
// `flow`: strip Flow type syntax from JS-family sources
|
|
210
|
+
// `flow`: strip Flow type syntax from JS-family sources, as Metro's Babel does (see parseFile).
|
|
209
211
|
// `typescript`: retry a failed resolution with tsc's mapping (see #typescriptResolve), with
|
|
210
212
|
// `typescriptPaths` (a tsconfig paths matcher; see resolveTypescriptFallback) adding tsconfig alias support; only consulted
|
|
211
213
|
// on the built-in (Node) resolver -- a custom `resolve` owns its own TS handling. Without it, the
|
|
@@ -383,15 +385,15 @@ export class Scan {
|
|
|
383
385
|
return hit == null ? null : pathToFileURL(hit).toString()
|
|
384
386
|
}
|
|
385
387
|
|
|
386
|
-
// Strip Flow type syntax to plain JS (flow.js's stripFlowTypes)
|
|
387
|
-
//
|
|
388
|
-
//
|
|
389
|
-
//
|
|
390
|
-
#stripFlow(src, file) {
|
|
388
|
+
// Strip Flow type syntax to plain JS (flow.js's stripFlowTypes): of a file marked `@flow`, or as a
|
|
389
|
+
// parse fallback (see parseFile), so plain-JS files never reach it. Returns the rewritten source, or
|
|
390
|
+
// null when the transform itself fails on this file -- the caller then keeps oxc's original parse,
|
|
391
|
+
// saying so where that failed (`failed`).
|
|
392
|
+
#stripFlow(src, file, failed) {
|
|
391
393
|
try {
|
|
392
394
|
return stripFlowTypes(src)
|
|
393
395
|
} catch (cause) {
|
|
394
|
-
console.warn(`[stasis] --flow: could not strip Flow types from ${file}; leaving it to oxc (${cause.message})`)
|
|
396
|
+
if (failed) console.warn(`[stasis] --flow: could not strip Flow types from ${file}; leaving it to oxc (${cause.message})`)
|
|
395
397
|
return null
|
|
396
398
|
}
|
|
397
399
|
}
|
|
@@ -464,15 +466,18 @@ export class Scan {
|
|
|
464
466
|
} catch { /* keep the script parse and its recorded errors */ }
|
|
465
467
|
}
|
|
466
468
|
|
|
467
|
-
// --flow: oxc parses JS/TS but not Flow, so a Flow-typed .js/.cjs/.mjs file lands here
|
|
468
|
-
// parse errors.
|
|
469
|
-
//
|
|
469
|
+
// --flow: oxc parses JS/TS but not Flow, so a Flow-typed .js/.cjs/.mjs/.jsx file lands here
|
|
470
|
+
// with parse errors. Strip Flow types and re-parse as Metro's Babel reads the file: one marked
|
|
471
|
+
// `@flow` (hasFlowPragma) is Flow, stripped whether or not oxc parses it as it is (where
|
|
472
|
+
// `f<T>(x)` is a comparison, not Flow's call), as Babel parses it with hermes-parser; any other
|
|
473
|
+
// only now, after a raw oxc parse actually failed, as Babel's own Flow parser takes annotations
|
|
474
|
+
// in any file, so plain-JS files never pay the transform cost. Only the parse input is rewritten;
|
|
470
475
|
// the bundle stores the pristine on-disk source (State/buildResolvedJsBundle re-read it), so
|
|
471
|
-
// attestation still covers the real bytes. A clean re-parse replaces the
|
|
476
|
+
// attestation still covers the real bytes. A clean re-parse replaces the original one; otherwise
|
|
472
477
|
// we keep the original result so a genuine (non-Flow) parse error still surfaces.
|
|
473
478
|
let strippedSource = null
|
|
474
|
-
if (
|
|
475
|
-
const flowSrc = this.#stripFlow(src, file)
|
|
479
|
+
if (this.flow && FLOW_EXTS.has(ext) && (errors.length > 0 || hasFlowPragma(src))) {
|
|
480
|
+
const flowSrc = this.#stripFlow(src, file, errors.length > 0)
|
|
476
481
|
if (flowSrc !== null) {
|
|
477
482
|
try {
|
|
478
483
|
const asFlow = parser.parseSync(file, flowSrc, parseOptions(baseSourceType))
|
package/src/sixel.js
ADDED
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
// Logos for where an advisory comes from, as `stasis audit` may draw them beside it: sixel images, for a
|
|
2
|
+
// terminal that draws them, as supported() asks it.
|
|
3
|
+
|
|
4
|
+
// Each a sixel image 16 pixels square, prepared once (nothing here converts one): its pixels square (P1 9,
|
|
5
|
+
// and raster attributes 1:1), its background left as the terminal has it (P2 1), in 8 colours at most.
|
|
6
|
+
// Its edges inside are blended; its outline isn't, as nothing tells a sixel image what it's drawn over, so
|
|
7
|
+
// a pixel is drawn where at least half of it is covered.
|
|
8
|
+
|
|
9
|
+
// npm's registry (upstream's `registry` source): simple-icons' npm (16.36.0, CC0-1.0), #CB3837, its
|
|
10
|
+
// knocked-out n filled white.
|
|
11
|
+
export const NPM = '\x1bP9;1q"1;1;16;16#1;2;80;22;22#2;2;100;100;100#3;2;91;66;66#4;2;94;78;77#5;2;89;56;56#6;2;92;71;71#7;2;97;88;88#8;2;85;42;42' +
|
|
12
|
+
'#1~~~!10F~~~$#2!4?!4oOOoo$#3???o$#5!4?!8G$#6!12?o$#7!8?__$#8???G!8?G-' +
|
|
13
|
+
'#1~~~!5?~~???~~~$#2!4?!4~???~$#3???~$#4!10?~$#6!12?~-' +
|
|
14
|
+
'#1NNN!5MNNMMMNNN$#3!10?@?@$#4!4?!4@$#5???@$#7!11?@' +
|
|
15
|
+
'\x1b\\'
|
|
16
|
+
|
|
17
|
+
// A GitHub repository's advisories (`repository`): simple-icons' GitHub (16.36.0, CC0-1.0), #181717, its
|
|
18
|
+
// knocked-out Octocat filled white, so that the mark shows on a dark terminal too.
|
|
19
|
+
export const GITHUB = '\x1bP9;1q"1;1;16;16#1;2;9;9;9#2;2;100;100;100#3;2;15;15;15#4;2;90;90;90#5;2;45;45;45#6;2;26;26;26#7;2;80;80;80#8;2;57;57;57' +
|
|
20
|
+
'#1_o{CEE!4NEEC{o_$#2!4?o!6_o$#3!5?G!4?G$#4!5?O?OO?O$#5???oG!6?Go$#6???G!8?G$#7!6?O??O-' +
|
|
21
|
+
'#1^~X!9?_x~^$#2???E^^^~~^^^E$#3??E!10?E$#4???H??_??_$#5??_$#6???o_!6?_O$#7!12?H$#8!5?_!4?_-' +
|
|
22
|
+
'#1?@AC!6?FFFB@$#2!4?AAMNNG$#3??@?CL!4?G$#4!6?@??F$#5???A$#6!4?@$#7???@' +
|
|
23
|
+
'\x1b\\'
|
|
24
|
+
|
|
25
|
+
// OSV (`osv`): OSV's logo as @preventive/triage draws an advisory's source (viewBox 0 75 405 400), its
|
|
26
|
+
// ring, `currentColor` there, triage's muted grey (#8b949e).
|
|
27
|
+
export const OSV = '\x1bP9;1q"1;1;16;16#1;2;55;58;62#2;2;88;13;16#3;2;98;86;86#4;2;92;43;45#5;2;94;62;63#6;2;88;17;20#7;2;96;74;75#8;2;99;95;95' +
|
|
28
|
+
'#1?o{{MM!4FEM[{o$#2!5?__OO__$#6!7?__-' +
|
|
29
|
+
'#1N~~O!8?o~~N$#2!5?^PooP^E$#3!7?IK$#4!6?I??I$#5!6?C@@C$#7!8?A$#8!7?C-' +
|
|
30
|
+
'#1???CEF!4MFFB@' +
|
|
31
|
+
'\x1b\\'
|
|
32
|
+
|
|
33
|
+
// The three at each size, made as those above are (simple-icons' and triage's paths, at least half a
|
|
34
|
+
// pixel covered for a pixel to be drawn, in 8 colours at most): 16 pixels for the cells most terminals
|
|
35
|
+
// draw sixel images over, more for larger ones, as a Retina screen's are in iTerm2, two pixels a point.
|
|
36
|
+
const LOGOS = {
|
|
37
|
+
12: {
|
|
38
|
+
npm: '\x1bP9;1q"1;1;12;12#1;2;80;22;22#2;2;100;100;100#3;2;84;40;40#4;2;93;71;71#5;2;90;61;61#6;2;89;56;56#7;' +
|
|
39
|
+
'2;89;57;57#8;2;89;59;59#1~~F!3BbBBF~~$#2!3?!3wGGw$#3!3?!4CcC$#4!7?O$#5!6?O$#6??w$#8!9?w-#1~~!4o~!3o~' +
|
|
40
|
+
'~$#2!3?!3F??F$#3??G!4?N?G$#5!3?!3G??G$#7??F$#8!9?F\x1b\\',
|
|
41
|
+
github: '\x1bP9;1q"1;1;12;12#1;2;99;99;99#2;2;9;9;9#3;2;14;13;13#4;2;42;42;42#5;2;11;10;10#6;2;73;73;73#1!3?!6w$' +
|
|
42
|
+
'#2owAABEEBAAwO$#3?CC??@@??CC$#4??WC!4?CW$#5!4?C??C!3?_$#6??_!6?_-#1!3?BB^^BB$#2CB!6?WKFE$#3?CO_$#4??' +
|
|
43
|
+
'E[_??wCA$#5BG!7?OG@$#6??H?[??C?@\x1b\\',
|
|
44
|
+
osv: '\x1bP9;1q"1;1;12;12#1;2;99;89;89#2;2;55;58;62#3;2;54;58;62#4;2;94;54;55#5;2;88;18;20#2??G?@?@??O$#3o{EE' +
|
|
45
|
+
'ABABEM{o$#4!5?__$#5!3?_oWWo_-#1!5?@@$#2!4?_??_?A?@$#3BFEOOooWW[NA$#4!6?A$#5!3?@BECB@\x1b\\',
|
|
46
|
+
},
|
|
47
|
+
14: {
|
|
48
|
+
npm: '\x1bP9;1q"1;1;14;14#1;2;80;22;22#2;2;100;100;100#3;2;84;38;37#4;2;80;25;24#5;2;80;23;23#6;2;79;22;21#1}' +
|
|
49
|
+
'~~!9F~}$#2!3?!4wWWww$#3!7?__$#4!11?w$#6@!12?@-#1~~@!4?_~??_~~$#2!3?!4^??^^$#3!3?!4_??__$#4!11?^$#5??' +
|
|
50
|
+
']!4?^$#6??_-#1!13B@$#6!13?A\x1b\\',
|
|
51
|
+
github: '\x1bP9;1q"1;1;14;14#1;2;10;9;9#2;2;99;99;99#3;2;9;9;9#4;2;20;20;20#5;2;45;45;45#6;2;77;77;77#1_w[C!6EC[' +
|
|
52
|
+
'w$#2!3?_!6o_$#3!3?A??@@??A??_$#4??_!8?_$#5!5?!4G$#6!3?WG!4?GW-#1B^g?O!4?oowNB$#2!3?FNn~~NNF$#3K_!10?' +
|
|
53
|
+
'oK$#4??C!8?C$#5??RW!4?O?GB$#6!3?__O??_-#1!9?@@$#2!6?@@$#3??@@A!4?A?@$#4!4?@$#6!5?@??@\x1b\\',
|
|
54
|
+
osv: '\x1bP9;1q"1;1;14;14#1;2;99;91;91#2;2;54;58;62#3;2;88;12;16#4;2;95;62;63#5;2;55;58;62#6;2;90;31;34#2?GcG' +
|
|
55
|
+
'D@@?@?A_G_$#3!4?_oOOo_$#4!6?__$#5_oWE!3ABEEK[o-#1!6?AA$#2@?A?!4_!3?DOE$#3!4?F!4GF$#4!6?DD$#5E^L!5?__' +
|
|
56
|
+
'oyN@$#6!5?F??F-#2!5?!4A?@$#5!3?!7@\x1b\\',
|
|
57
|
+
},
|
|
58
|
+
16: { npm: NPM, github: GITHUB, osv: OSV },
|
|
59
|
+
20: {
|
|
60
|
+
npm: '\x1bP9;1q"1;1;20;20#1;2;80;22;22#2;2;100;100;100#3;2;89;58;58#4;2;80;22;21#5;2;95;79;79#6;2;80;24;24#7;' +
|
|
61
|
+
'2;82;31;31#8;2;96;84;84#1|!3~!12N!4~$#2!5?!10_$#3!4?!12O$#4A$#5!4?_$#8!15?_-#1!4~!7?{!4?!4~$#2!5?!5~' +
|
|
62
|
+
'!3@~~$#3!12?A$#5!4?~$#6!10?{$#7!10?AA{$#8!15?~-#1!4~!7o~!4o!4~$#2!5?!5N!3?NN$#5!4?N$#6!10?N$#7!12?N$' +
|
|
63
|
+
'#8!15?N-#1?@!16B@@$#4@A!16?A\x1b\\',
|
|
64
|
+
github: '\x1bP9;1q"1;1;20;20#1;2;18;18;18#2;2;100;100;100#3;2;9;9;9#4;2;33;33;33#5;2;52;52;52#6;2;74;73;73#2!5?_' +
|
|
65
|
+
'_?!4_?__$#3?_owKMM]!4^]MMKwo_$#4!4?O?O!6?O?O$#5!4?_!10?_$#6!5?O?_!4?_?O-#1!3?c!12?c$#2!4?{!10~{$#3}~' +
|
|
66
|
+
'~B!12?B~~}$#4!3?W!12?W$#5!4?@!10?@$#6!4?A!10?A-#1??C?EG!9?A$#2!5?PBR!4~BB@$#3@FZr_CG!6?w{{~^F@$#4!3?' +
|
|
67
|
+
'G??CG!4?GC$#5!3?C?_?C!4?s$#6!4?XAo_!6?A@-#2!8?!4@$#3!4?@@B!6?B@$#4!12?@$#5!7?@\x1b\\',
|
|
68
|
+
osv: '\x1bP9;1q"1;1;20;20#1;2;54;58;62#2;2;88;14;17#3;2;97;76;77#4;2;91;38;41#5;2;55;58;62#1?_OC?A?@H@!3H?Q??' +
|
|
69
|
+
'W_$#2!9?!3_$#5??_w{[]MEM!3EMK{w_-#1C??{@!11?U??[$#2!6?}nF@@FN}G$#3!8?o{{w$#4!7?OGAA?o$#5w~~B!12?h~~_' +
|
|
70
|
+
'-#1?EG?AOG!4?O?GCa?G$#2!6?@BBAABB@$#4!9?@@$#5?@FF__!5o_oow[^FF-#1!4?!3@??A?A?@@$#5!7?@B@B@@\x1b\\',
|
|
71
|
+
},
|
|
72
|
+
24: {
|
|
73
|
+
npm: '\x1bP9;1q"1;1;24;24#1;2;80;22;22#2;2;100;100;100#3;2;93;73;73#4;2;84;40;40#5;2;79;22;22#6;2;99;96;96#7;' +
|
|
74
|
+
'2;98;91;91#8;2;99;97;97#1}!4~!14^!3~}{$#3!5?!14_$#5!22?@A-#1!5~!7?!3w!4?!5~$#2!6?!6~!4B~~$#3!12?!3Cw' +
|
|
75
|
+
'$#7!5?~!9?C$#8!18?~-#1!5~!7?!3~!4?!5~$#2!6?!6~!4?~~$#3!15?~$#6!18?~$#7!5?~-#1^!4~!7{!3~!4{!3~^N$#2!6' +
|
|
76
|
+
'?!6@!4?@@$#3!15?@$#4!5?!7A!3?!4A$#5!22?_O$#6!18?@$#7!5?@\x1b\\',
|
|
77
|
+
github: '\x1bP9;1q"1;1;24;24#1;2;10;9;9#2;2;100;100;100#3;2;9;9;9#4;2;73;73;73#5;2;55;55;55#6;2;30;29;29#1??_ooW' +
|
|
78
|
+
'[[!8}][Ww__$#3!4?GC?A??!4@!4?C?O$#4!6?_!10?_$#5!16?_$#6!5?_?_!10?_-#1G}~~N!14?N~~}$#2!5?w~~}}!4~}}~~' +
|
|
79
|
+
'w$#3o@!21?w$#4!4?_B??@@!4?@@$#5!4?OC!12?Fo-#1@^~^Wo_!10?_o{~~^D$#2!5?FN!3^!4~!3^NF$#3M_!20?_A$#4!4?_' +
|
|
80
|
+
'?O??_!4?_$#5!3?_BG??_!6?_?OGB$#6!4?C??_!8?_-#1!3?BEGHPX!6?^^NNFB@$#2!5?A!3CM!4^M$#3??@CG?O?_!6?_?O?G' +
|
|
81
|
+
'C$#4!4?@@A??@!4?@$#5!7?AA$#6!5?C?G\x1b\\',
|
|
82
|
+
osv: '\x1bP9;1q"1;1;24;24#1;2;98;87;88#2;2;88;13;16#3;2;89;24;27#4;2;54;58;62#5;2;55;58;62#6;2;93;50;52#4!4?G' +
|
|
83
|
+
'C?a?!6@OaAC??_$#5??_oow}[]!7M[{wwo-#1!10?_gg_$#2!7?w{]ABFA]}w$#3!10?[C?[$#4o!3?O!13?AK??AO$#5?}~~NB@' +
|
|
84
|
+
'!11?@B~~{g$#6!9?_?OO?_-#1!10?BFFB$#2!7?FN!6WNF$#4?W_?aO!11?_OC??OD$#5@F^~[!13?_w~~NA$#6!9?FC??CF-#4?' +
|
|
85
|
+
'?@@GCA@?AA?__??@?GCA@$#5!5?GK]][{{[[!3]NFB@\x1b\\',
|
|
86
|
+
},
|
|
87
|
+
28: {
|
|
88
|
+
npm: '\x1bP9;1q"1;1;28;28#1;2;80;22;22#2;2;100;100;100#3;2;95;80;80#4;2;85;41;41#5;2;80;25;25#6;2;80;25;24#7;' +
|
|
89
|
+
'2;82;31;30#8;2;80;24;23#1}!26~}-#1!5~!10?!3_!5?!5~$#2!6?!8}!4M!4}$#3!6?!16@$#4!14?!4O$#5!14?_$#7!22?' +
|
|
90
|
+
'~$#8!5?~-#1!5~!10?!3~!5?!5~$#2!6?!8~!4?!4~$#5!14?~$#6!5?{$#7!22?~$#8!5?B-#1!5~o!8_o!3~!5_!5~$#2!6?!8' +
|
|
91
|
+
'N!4?!4N$#4!6?!8O!4?!4O$#5!5?K!8?@$#6!5?B!8?M$#7!22?N$#8!22?O-#1F!26NF\x1b\\',
|
|
92
|
+
github: '\x1bP9;1q"1;1;28;28#1;2;43;43;43#2;2;100;100;100#3;2;9;9;9#4;2;20;20;20#5;2;9;8;8#6;2;67;66;66#7;2;82;8' +
|
|
93
|
+
'1;81#3!3?_oww{!4}!4~!4}{wwo_$#5!11?@!4?@-#1!6?@!14?@_$#2!6?o~}}{{!4}{{}}~o$#3_{!3~N!4?!8@!4?N!3~{_$#' +
|
|
94
|
+
'4!5?O!3?@!8?@!3?O$#6!5?_G?@?A!6?A?@?M$#7!6?E!4?A!4?A-#1!5?O!16?O$#2!5?A!16~$#3!5~!17?_!5~$#4!5?_$#6!' +
|
|
95
|
+
'22?G$#7!5?L!16?F-#1!5?O@?OOC!6?s$#2!6?O``bbz!4~zBB@@$#3?BN~pbEKKG!8?!3{}~~^NB$#4!4?I??A?CG!6?G??A@$#' +
|
|
96
|
+
'5?C!24?C$#6!6?gO??O!8?A$#7!4?CK??A??C!4?C-#1!7?@??A!6?B$#2!11?B!4FB$#3!4?@@BEEM!8?!3FB@@$#4!10?C!6?C' +
|
|
97
|
+
'$#6!8?@@$#7!10?@\x1b\\',
|
|
98
|
+
osv: '\x1bP9;1q"1;1;28;28#1;2;93;52;53#2;2;88;15;18#3;2;54;58;62#4;2;99;89;89#5;2;55;58;62#3!3?_oww{!3}!6^~}{' +
|
|
99
|
+
'{woo_$#5!19?A?CG-#1!12?OO?O$#2!8?_w{{kM[k{{w_$#3?w}~~^FB@!10?@BB^!3~{_$#4!13?__$#5!21?C-#1!11?M?``@]' +
|
|
100
|
+
'G$#2!8?^~~``??_`v~^$#3A!4~_!16?_!4~B$#4!11?O!4]$#5!5?O!21?K-#2!10?@!6B@@$#3?@BNFB?_!4o!5_ooww{~~^FA$' +
|
|
101
|
+
'#5??C!17?CA!4?@-#3!5?A!3B!4F!3N!4FBB@$#5!12?G!3?G\x1b\\',
|
|
102
|
+
},
|
|
103
|
+
32: {
|
|
104
|
+
npm: '\x1bP9;1q"1;1;32;32#1;2;80;22;22#2;2;100;100;100#3;2;91;65;65#4;2;81;26;26#5;2;85;44;43#6;2;83;34;34#7;' +
|
|
105
|
+
'2;86;48;48#8;2;83;36;35#1}!30~}-#1!6~!20@!6~$#2!7?!9}!4]!5}$#3!16?!4_$#5!25?}$#6!6?]$#8!6?_-#1!6~!11' +
|
|
106
|
+
'?!3~!6?!6~$#2!7?!9~!5?!4~$#4!16?~$#5!25?~$#7!20?~$#8!6?~-#1!6~!11?!3~!6?!6~$#2!7?!9~!5?!4~$#4!16?~$#' +
|
|
107
|
+
'5!25?~$#7!20?~$#8!6?~-#1!6~!10{}!3~!6{!6~$#2!7?!9@!5?!4@$#3!7?!9A!5?!4A$#4!6?A!9?@$#5!25?@$#6!25?A$#' +
|
|
108
|
+
'7!20?@$#8!6?@!13?A-#1@!30B@\x1b\\',
|
|
109
|
+
github: '\x1bP9;1q"1;1;32;32#1;2;30;30;30#2;2;100;100;100#3;2;9;9;9#4;2;10;9;9#5;2;92;92;92#6;2;57;56;56#7;2;77;' +
|
|
110
|
+
'77;77#3!4?_?OGC?AA!8?A??C?O$#4!5?__ow!3{!8}!3{ww__-#1!10?A?C!6?C?A$#2!8?}{{!10w{{}$#3?OCA!24?ACO$#4?' +
|
|
111
|
+
'_w{!3~!4@!10B!4@!3~{w_$#5!7?G$#6!7?A!3?C?CC??CC?C!3?A$#7!7?s?A!5?CC!5?A?{-#1!5?[!19?@G$#2!6?{!18~{$#' +
|
|
112
|
+
'3U!30?e$#4g!4~b!20?v!4~W$#5!6?A$#6!6?@$#7!25?A-#1!4?o!4?O?_!10?O??A$#2!7?BFNN^^!6~^^NNFB$#3AO!28?O$#' +
|
|
113
|
+
'4@N~~N^[wo__!9?!3_ow{!4~NB$#5!5?_$#6!6?A!5?_!6?_$#7!6?`CG?O!10?O?GC@-#1!5?@CG?OOQ$#2!6?@EC!3K{!6~$#3' +
|
|
114
|
+
'!5?O!18?_!3?A$#4??@BNMWopbb`!8?!4~^^NF@@$#5!8?G!3?A!6?{$#6!6?A@A!3?@!6?@$#7!19?A-#2!14?!4@$#3!8?@@$#' +
|
|
115
|
+
'4!10?@@!8?!4@\x1b\\',
|
|
116
|
+
osv: '\x1bP9;1q"1;1;32;32#1;2;99;92;92#2;2;92;42;44#3;2;88;13;16#4;2;95;64;66#5;2;54;58;62#5!4?_oww{{}}!8~}}{' +
|
|
117
|
+
'{wwo_-#2!14?_??_$#3!10?_owwW{wWwwo_$#5?o{}!3~NFB@@!8?@@BFN!4~{o-#1!14?wyAwG$#2!12?W?B?@??W$#3!9?}~~F' +
|
|
118
|
+
'F!4?FF~~}$#4!12?_wCD{Fo_$#5?!5~!20?!5~}-#1!13?@@BB@@$#2!12?B!6?B$#3!9?@FNK]!4[]KNF@$#4!14?A??A$#5?F!' +
|
|
119
|
+
'4~]!16?_w{!4~N-#5!3?@@_ow{}~}!8{}}~~^NNF@-#5!10?!4@!5B!3@\x1b\\',
|
|
120
|
+
},
|
|
121
|
+
40: {
|
|
122
|
+
npm: '\x1bP9;1q"1;1;40;40#1;2;80;22;22#2;2;100;100;100#3;2;83;35;35#4;2;95;81;81#5;2;92;69;69#6;2;89;58;58#7;' +
|
|
123
|
+
'2;79;22;21#8;2;92;68;68#1w}}!34~}}{$#7E@@!34?@@A-#1!8~!15B!9F!8~$#2!9?!22w$#3!8?!15C$#5!31?w$#6!8?w-' +
|
|
124
|
+
'#1!8~!12?!5w!7?!8~$#2!9?!11~!6B!5~$#3!25?w$#4!20?!6C$#5!31?~$#6!8?~-#1!8~!12?!5~!7?!8~$#2!9?!11~!6?!' +
|
|
125
|
+
'5~$#3!25?~$#5!31?F$#6!8?~$#8!31?w-#1!8~!12?!5~!7?!8~$#2!9?!11~!6?!5~$#3!25?~$#6!8?~$#8!31?~-#1!8~!12' +
|
|
126
|
+
'{!5~!7{!8~$#2!9?!11B!6?!5B$#3!25?B$#6!8?B$#8!31?B-#1@FF!34NFF@$#7EGG!34?G?E\x1b\\',
|
|
127
|
+
github: '\x1bP9;1q"1;1;40;40#1;2;9;9;9#2;2;100;100;100#3;2;51;51;51#4;2;27;26;26#5;2;73;73;73#1!7?_oow!3{!4}!4~!' +
|
|
128
|
+
'4}!3{woo_-#1??_w{}!3~BBFF!13N!3FBB!3~}{w_$#2!9?owwoo!12_oowwo$#3!14?O?OO!4?OO?O$#4!9?CC!4?O!8?O?G??C' +
|
|
129
|
+
'C$#5!9?G??G!5?!4O!5?G??G-#1o}!5~NB!22?BN!5~}_$#2!8?o!21~|o$#3!7?_!24?_$#4!7?OC!22?CO$#5!8?G!21?AG-#1' +
|
|
130
|
+
'!7~!25?_!7~$#2!8?!24~$#3!7?O!24?W$#4!7?_$#5!7?N!24?F-#1@N!3~!3N[woo__!11?!3_oow{!6~N@$#2!7?_?BFNN!3^' +
|
|
131
|
+
'!8~^^!3NFB$#3!5?O!3?CG?O!14?O?GC$#4!5?_?OA!5?__!8?_!6?A$#5!6?o?`!17?O!4?@-#1!3?BFN^{o_`!4B!10?!8~^NF' +
|
|
132
|
+
'B$#2!8?BM[!4W{!8~{$#3!9?@A?C??@!8?@$#4!7?AGO?!4_$#5!7?@C??C?CCA!8?A-#1!8?@BB!4F!10?!4FB@@$#2!15?@!8B' +
|
|
133
|
+
'@\x1b\\',
|
|
134
|
+
osv: '\x1bP9;1q"1;1;40;40#1;2;55;58;62#2;2;91;33;35#3;2;88;13;16#4;2;99;93;94#5;2;94;57;58#6;2;54;58;62#1!8?o' +
|
|
135
|
+
'!3w{!5}!3~!6}{w{wo__$#6!7?_!3?C!4?@@!3?!3@!4?C!3?O-#1!3?_w{!4~^NNFB!3@!3?!5@BFF^^!3~}{o$#3!16?!8_$#6' +
|
|
136
|
+
'!3?OCA!9?A??!3@!3?AA??G?_!3?@?G_-#1?c}!4~NB@!21?@N!5~w$#2!18?CGGCK$#3!11?_w{}!3~BFFBr!3~}{o$#4!19?OO' +
|
|
137
|
+
'G$#5!18?w__o$#6?W@!4?o!23?A!6?E_-#1?^!5~g!25?!6~$#2!15?i?@!5?S$#3!11?N!3~@T!6?@@!3~^$#4!16?i}~~_~}i$' +
|
|
138
|
+
'#5!15?S!4?^?@?}$#6?_!5?O!24?_!6?N-#1?@F!4~^K!20?_ow!5~N@$#2!17?@??A?@$#3!12?@BFMN!3][]]NMFB@$#4!18?!' +
|
|
139
|
+
'4@$#5!15?@!8?@$#6??G!4?_Q!19?_?GE!5?OE-#1!5?@!3?_o{}!3{!8w{{}}!4~NNB@@$#6!4?@?@?_OG??AA?CC!5?C!3?@!4' +
|
|
140
|
+
'?O?CA-#1!8?!4@!4B!9FBB!3@$#6!7?@!6?CC!4?GG!3?C?AA\x1b\\',
|
|
141
|
+
},
|
|
142
|
+
48: {
|
|
143
|
+
npm: '\x1bP9;1q"1;1;48;48#1;2;80;22;22#2;2;100;100;100#3;2;85;41;41#4;2;95;82;82#5;2;90;61;61#6;2;79;22;21#7;' +
|
|
144
|
+
'2;81;29;28#8;2;81;28;28#1w}!43~}}w$#6C!44?@?C-#1!10~!28N!10~$#2!11?!27_$#3!10?!28O$#4!10?_-#1!10~!28' +
|
|
145
|
+
'?!10~$#2!11?!13~!7^!7~$#4!10?~$#5!24?!7_-#1!10~!15?!6~!7?!10~$#2!11?!13~!7?!7~$#4!10?~$#7!24?~-#1!10' +
|
|
146
|
+
'~!15?!6~!7?!10~$#2!11?!13~!7?!7~$#4!10?~$#7!24?N$#8!24?o-#1!10~!15?!6~!7?!10~$#2!11?!13~!7?!7~$#4!10' +
|
|
147
|
+
'?~$#8!24?~-#1!10~!14w{!6~!7w!10~$#2!11?!13B!7?!7B$#3!10?!14C!7?!7C$#4!10?B$#8!24?B-#1N^^!42~^^F$#6??' +
|
|
148
|
+
'_!42?_?G\x1b\\',
|
|
149
|
+
github: '\x1bP9;1q"1;1;48;48#1;2;27;26;26#2;2;100;100;100#3;2;9;9;9#4;2;67;67;67#5;2;45;44;44#6;2;86;86;86#3!9?_' +
|
|
150
|
+
'_ooww{{!5}!4~!5}{{wwoo__-#1!13?O!20?O$#2!12?__!20?__$#3!4?ow{}!3~!3N^^!16~^^!3N!3~}{w_$#5!11?OO??_!1' +
|
|
151
|
+
'6?_??OO$#6!11?_??_!18?_??_-#1!10?j!6?@?@!8?@!8?m$#2!11?!5~!16}!4~n$#3?o{!7~O!7?@!10?@!7?P!7~{o$#4!21' +
|
|
152
|
+
'?!6@$#5!10?C!9?@!6?@??@$#6!16?@!14?@!4?O-#1!8?W!30?o$#2!9?w!27~}w$#3}!7~F@!28?@N!7~{$#4!9?A$#5!8?_!2' +
|
|
153
|
+
'9?A$#6!9?C!27?@C-#1!8?B_!29?@$#2!9?F!28~F$#3^!7~{!29?_}!7~^$#4!38?G$#5!9?O!28?O$#6!9?G-#1!9?O!5?O!16' +
|
|
154
|
+
'?O?G$#2!7?O__?@BFF!3N^^!8~^^!3NFFB@$#3?F^!3~n!3N]{woo!4_!10?!4_oow{}!7~^F$#4!6?O_O?@?C!4?O!10?_?O??G' +
|
|
155
|
+
'?CA$#5!10?_??G??O!14?O!5?@$#6!11?A??G!4?_-#1!10?O`!5?C!11?@$#2!9?@F[W!5w{!10~$#3!3?@FN^~}w_?BB!3FB!1' +
|
|
156
|
+
'2?!11~^NB@$#4!8?@!9?A!10?A$#5!9?C!3?C!4?@$#6!9?AGAc!16?{-#1!13?@$#2!18?FF!8NF$#3!8?@BBFFMM!3]!12?!3^' +
|
|
157
|
+
'NNFFB@@$#5!14?!4@$#6!29?F\x1b\\',
|
|
158
|
+
osv: '\x1bP9;1q"1;1;48;48#1;2;55;58;62#2;2;90;32;34#3;2;88;13;16#4;2;99;93;93#5;2;54;58;62#6;2;94;59;60#1!9?!' +
|
|
159
|
+
'3_!3w{!4}!5~}}~!3}{{!3woo$#5!11?O??C!10?@@?@??A?CC!3?_-#1!4?_o{}!7~^N!3F!7B!3F!3N!6~}}wo_$#5!17?G??C' +
|
|
160
|
+
'!11?O!6?@?CGO-#1??w{!6~^F@!22?@FN^!6~w$#2!22?_$#3!15?_ow{{}]]!3}]}{{wo_$#5!3?A!8?A@!21?A??_!6?C_$#6!' +
|
|
161
|
+
'21?_!4?_-#1?}!7~!30?J!6~}O$#2!18?_OOK?@??GOO$#3!13?o!4~^NNA??@?ANN^!4~w$#4!19?__otyA~o_$#5?@!7?@!29?' +
|
|
162
|
+
'S!6?@_$#6!21?@IC{?D?__-#1?V!7~_!29?}!7~B$#2!18?G`?_!4?_?KI$#3!13?@^!3~A?_!6?_`?!3~^F$#4!19?QI^~~o~^N' +
|
|
163
|
+
'AC$#5?G!7?O!28?_@$#6!18?tKT!3?N??OOp-#1??@V^!3~^NM!24?ow}!6~^F@$#2!23?@@$#3!15?@BFF!3N^]]^^!3NFB@$#5' +
|
|
164
|
+
'??AG_!3?_O!24?_-#1!5?BB@??__o{{}!3{!3woowooww{{!3}!5~^NFB$#5!11?OG?A?A!5?GG?GG!6?@!6?O??@-#1!9?!4BFF' +
|
|
165
|
+
'NN^N!10^!3N!3FB@$#5!8?!5C!5?O!10?O??G!3?A@\x1b\\',
|
|
166
|
+
},
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const SIZES = Object.keys(LOGOS).map(Number)
|
|
170
|
+
|
|
171
|
+
// An image's size, its colours by register, and each pixel's register (0 for none), as sixel data draws
|
|
172
|
+
// them: in bands of six rows, a character's bits a band's column, top first.
|
|
173
|
+
function decode(image) {
|
|
174
|
+
const header = image.slice(0, image.indexOf('#'))
|
|
175
|
+
const [width, height] = header.split(';').slice(-2).map(Number)
|
|
176
|
+
const colours = new Map()
|
|
177
|
+
const pixels = new Uint8Array(width * height)
|
|
178
|
+
let register = 0
|
|
179
|
+
let x = 0
|
|
180
|
+
let y = 0
|
|
181
|
+
for (const [, at, rgb, count = '1', sixel, control] of image.slice(header.length, -2).matchAll(/#(\d+)(?:;2;([\d;]+))?|(?:!(\d+))?([?-~])|([$-])/gu)) {
|
|
182
|
+
if (at !== undefined) {
|
|
183
|
+
register = Number(at)
|
|
184
|
+
if (rgb !== undefined) colours.set(register, rgb)
|
|
185
|
+
} else if (control !== undefined) {
|
|
186
|
+
x = 0
|
|
187
|
+
if (control === '-') y += 6
|
|
188
|
+
} else {
|
|
189
|
+
const bits = sixel.charCodeAt(0) - 0x3f
|
|
190
|
+
for (let n = 0; n < Number(count); n++, x++) {
|
|
191
|
+
for (let bit = 0; bit < 6; bit++) if (bits & (1 << bit)) pixels[(y + bit) * width + x] = register
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return { width, height, colours, pixels }
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// decode()'s image as sixel data, as the logos above are written: square pixels, the background left as
|
|
199
|
+
// it is, a band's registers each a line, runs of three or more counted.
|
|
200
|
+
function encode({ width, height, colours, pixels }) {
|
|
201
|
+
const bands = []
|
|
202
|
+
for (let y = 0; y < height; y += 6) {
|
|
203
|
+
const lines = []
|
|
204
|
+
for (const register of colours.keys()) {
|
|
205
|
+
let line = ''
|
|
206
|
+
for (let x = 0; x < width; x++) {
|
|
207
|
+
let bits = 0
|
|
208
|
+
for (let bit = 0; bit < 6 && y + bit < height; bit++) if (pixels[(y + bit) * width + x] === register) bits |= 1 << bit
|
|
209
|
+
line += String.fromCharCode(0x3f + bits)
|
|
210
|
+
}
|
|
211
|
+
line = line.replace(/\?+$/u, '')
|
|
212
|
+
if (line !== '') lines.push(`#${register}${line.replaceAll(/(.)\1{2,}/gu, (run, sixel) => `!${run.length}${sixel}`)}`)
|
|
213
|
+
}
|
|
214
|
+
bands.push(lines.join('$'))
|
|
215
|
+
}
|
|
216
|
+
const defined = [...colours].map(([register, rgb]) => `#${register};2;${rgb}`).join('')
|
|
217
|
+
return `\x1bP9;1q"1;1;${width};${height}${defined}${bands.join('-')}\x1b\\`
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// `image` lowered by `top` pixels, the rows above it left as the terminal has them.
|
|
221
|
+
function lowered(image, top) {
|
|
222
|
+
const { width, height, colours, pixels } = decode(image)
|
|
223
|
+
const below = new Uint8Array(width * (height + top))
|
|
224
|
+
below.set(pixels, width * top)
|
|
225
|
+
return encode({ width, height: height + top, colours, pixels: below })
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// A register above the logos' own (8 at most), for the terminal's background: iTerm2 draws what a sixel image
|
|
229
|
+
// leaves undrawn in the highest register drawn with (libsixel's index for none, 255, cut to the highest),
|
|
230
|
+
// where other terminals leave it as it is; so it is drawn with, a blank character, which draws nothing.
|
|
231
|
+
const BACKGROUND = 9
|
|
232
|
+
|
|
233
|
+
// The logos to draw over two of the terminal's cells, `cell` (its `width` and `height` in the pixels it
|
|
234
|
+
// draws sixel images in, as capabilities() tells them): the largest that fits two cells, a gap of an eighth
|
|
235
|
+
// of a row (two pixels at least) left over, lowered by half of it, so that it sits in the middle of its row,
|
|
236
|
+
// apart from those on the lines above and below; the smallest where none fits. With `background` (`r;g;b`
|
|
237
|
+
// in percent, as capabilities() tells it), what a logo leaves undrawn is that, for iTerm2. Those 16 pixels
|
|
238
|
+
// square, as they are, where `cell` isn't known.
|
|
239
|
+
export function logos(cell, background) {
|
|
240
|
+
let size = 16
|
|
241
|
+
let top = 0
|
|
242
|
+
if (cell) {
|
|
243
|
+
const room = cell.height - Math.max(2, Math.ceil(cell.height / 8))
|
|
244
|
+
size = SIZES.findLast((each) => each <= room && each <= 2 * cell.width) ?? SIZES[0]
|
|
245
|
+
top = Math.floor((cell.height - size) / 2)
|
|
246
|
+
}
|
|
247
|
+
const fitted = (image) => {
|
|
248
|
+
const placed = top > 0 ? lowered(image, top) : image
|
|
249
|
+
return background ? `${placed.slice(0, -2)}$#${BACKGROUND};2;${background}?\x1b\\` : placed
|
|
250
|
+
}
|
|
251
|
+
return Object.fromEntries(Object.entries(LOGOS[size]).map(([name, image]) => [name, fitted(image)]))
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Primary Device Attributes (DA1), which a terminal answers `CSI ? 62 ; 4 ; 22 c`, say: its class, then
|
|
255
|
+
// what it has, 4 being sixel graphics (tmux's `CSI ? 1 ; 2 ; 4 c` too). Every terminal answers it, so it is
|
|
256
|
+
// asked last, its answer telling the others have come, or won't.
|
|
257
|
+
const DA1 = '\x1b[c'
|
|
258
|
+
const SIXEL = '4'
|
|
259
|
+
|
|
260
|
+
// iTerm2's report of its cells' size, answered `OSC 1337 ; ReportCellSize=height;width;scale ST`: in points,
|
|
261
|
+
// `scale` the screen's pixels to a point, which it draws a sixel image's pixels as (two on a Retina screen).
|
|
262
|
+
const REPORT_CELL_SIZE = '\x1b]1337;ReportCellSize\x1b\\'
|
|
263
|
+
// A cell's size in pixels (XTWINOPS 16), answered `CSI 6 ; height ; width t`: as xterm.js draws sixel images,
|
|
264
|
+
// in CSS pixels; but iTerm2's in points, which it doesn't draw them in.
|
|
265
|
+
const CELL_SIZE = '\x1b[16t'
|
|
266
|
+
// The terminal's background colour (OSC 11), answered `OSC 11 ; rgb:RRRR/GGGG/BBBB ST`, each of 1 to 4 hex
|
|
267
|
+
// digits.
|
|
268
|
+
const BACKGROUND_COLOUR = '\x1b]11;?\x1b\\'
|
|
269
|
+
|
|
270
|
+
// The first reply in `read` that `pattern` matches after an ESC, its parameters; text like a reply,
|
|
271
|
+
// without its ESC, is not one.
|
|
272
|
+
const reply = (read, pattern) => [...read.matchAll(pattern)].find(({ index }) => read[index - 1] === '\x1b')
|
|
273
|
+
|
|
274
|
+
// Whether DA1's answer in `read` has sixel graphics among what the terminal has.
|
|
275
|
+
const sixelIn = (read) => reply(read, /\[\?([\d;]*)c/gu)?.[1].split(';').slice(1).includes(SIXEL) ?? false
|
|
276
|
+
|
|
277
|
+
// A cell's size in the pixels the terminal draws sixel images in: iTerm2's, its points by its scale; else
|
|
278
|
+
// XTWINOPS 16's; null where neither is answered.
|
|
279
|
+
function cellIn(read) {
|
|
280
|
+
const iterm2 = reply(read, /\]1337;ReportCellSize=([\d.]+);([\d.]+)(?:;([\d.]+))?/gu)
|
|
281
|
+
if (iterm2) return { height: iterm2[1] * (iterm2[3] ?? 1), width: iterm2[2] * (iterm2[3] ?? 1) }
|
|
282
|
+
const xtwinops = reply(read, /\[6;(\d+);(\d+)t/gu)
|
|
283
|
+
return xtwinops ? { height: Number(xtwinops[1]), width: Number(xtwinops[2]) } : null
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// What the terminal `output` writes to answers `question` with, DA1 last, read on `input` up to DA1's answer;
|
|
287
|
+
// null where either is no terminal (a pipe, a file) or it is a dumb one (Emacs' shell), and nothing is asked,
|
|
288
|
+
// or it hasn't answered in `timeout` ms. Meanwhile `input` is raw, as a terminal answers there, and read, as
|
|
289
|
+
// it is left; a key pressed in that time is read with the answer and dropped.
|
|
290
|
+
function ask(question, { input = process.stdin, output = process.stdout, env = process.env, timeout = 1000 } = {}) {
|
|
291
|
+
if (!input?.isTTY || !output?.isTTY || env.TERM === 'dumb') return Promise.resolve(null)
|
|
292
|
+
const { promise, resolve } = Promise.withResolvers()
|
|
293
|
+
const raw = input.isRaw
|
|
294
|
+
const flowing = input.readableFlowing === true
|
|
295
|
+
let read = ''
|
|
296
|
+
const finish = (answer) => {
|
|
297
|
+
clearTimeout(timer)
|
|
298
|
+
input.off('data', onData)
|
|
299
|
+
input.setRawMode(raw)
|
|
300
|
+
if (!flowing) input.pause()
|
|
301
|
+
resolve(answer)
|
|
302
|
+
}
|
|
303
|
+
// DA1's answer, `CSI ? Ps ; ... c`, may come in pieces, and after a key or another report.
|
|
304
|
+
const onData = (chunk) => {
|
|
305
|
+
read += chunk.toString('latin1')
|
|
306
|
+
if (reply(read, /\[\?[\d;]*c/gu)) finish(read)
|
|
307
|
+
}
|
|
308
|
+
const timer = setTimeout(finish, timeout, null)
|
|
309
|
+
input.setRawMode(true)
|
|
310
|
+
input.on('data', onData)
|
|
311
|
+
input.resume()
|
|
312
|
+
output.write(question)
|
|
313
|
+
return promise
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Whether the terminal `output` writes to draws sixel images: whether it answers DA1 with sixel graphics
|
|
317
|
+
// among what it has (see ask(), for `options`).
|
|
318
|
+
export const supported = async (options) => sixelIn((await ask(DA1, options)) ?? '')
|
|
319
|
+
|
|
320
|
+
// The background colour in `read`, `r;g;b` in percent, as a sixel image's colours are; null where it isn't
|
|
321
|
+
// answered.
|
|
322
|
+
function backgroundIn(read) {
|
|
323
|
+
const colour = reply(read, /\]11;rgb:([\da-f]{1,4})\/([\da-f]{1,4})\/([\da-f]{1,4})/giu)
|
|
324
|
+
return colour ? colour.slice(1).map((hex) => Math.round((Number.parseInt(hex, 16) / (16 ** hex.length - 1)) * 100)).join(';') : null
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
// What the terminal `output` writes to tells of its images, in one round trip: whether it draws sixel images
|
|
328
|
+
// (`sixel`, as supported()), its cells' size in the pixels it draws them in (`cell`, `{ width, height }`, see
|
|
329
|
+
// cellIn), and its background colour (`background`, see backgroundIn), each null where it doesn't tell.
|
|
330
|
+
export async function capabilities(options) {
|
|
331
|
+
const read = (await ask(REPORT_CELL_SIZE + CELL_SIZE + BACKGROUND_COLOUR + DA1, options)) ?? ''
|
|
332
|
+
return { sixel: sixelIn(read), cell: cellIn(read), background: backgroundIn(read) }
|
|
333
|
+
}
|