@exodus/stasis 1.0.0-beta.13 → 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 +5 -1
- package/bin/stasis.js +191 -149
- package/package.json +31 -7
- package/src/audit.js +224 -90
- package/src/babel.js +44 -37
- package/src/bundle-reader.js +24 -4
- package/src/cmd/build.js +218 -8
- package/src/cmd/bundle-options.js +31 -25
- package/src/cmd/bundle.js +1147 -311
- package/src/cmd/github-bundle.js +17 -9
- package/src/cmd/output.js +10 -3
- package/src/cmd/tokens.js +73 -0
- package/src/define.js +5 -0
- package/src/diff.js +2 -2
- package/src/flow.js +42 -0
- package/src/installed-commits.js +4 -2
- package/src/loaders/bash.js +2 -27
- package/src/loaders/cargo.js +6 -6
- package/src/loaders/foundry.js +4 -6
- package/src/loaders/paths.js +4 -15
- package/src/loaders/php.js +3 -5
- package/src/loaders/rust.js +19 -39
- package/src/loaders/solidity-ownership.js +4 -15
- package/src/loaders/solidity.js +4 -67
- package/src/metro-assets.js +65 -0
- package/src/metro-resolver.js +76 -123
- package/src/parse.js +7 -3
- package/src/resolve-fields.js +133 -366
- package/src/resolve-node.js +9 -7
- package/src/resolve-typescript.js +102 -30
- package/src/scan.js +154 -54
- package/src/sixel.js +333 -0
- package/src/table.js +116 -0
- 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 +1349 -0
- package/src/vfs-bundle/entries.js +5 -2
- package/src/vfs-bundle/github.js +68 -19
- package/src/vfs-bundle/glob.js +420 -0
- package/src/vfs-bundle/lazy.js +128 -0
- package/src/vfs-bundle/prisma.js +102 -29
- package/src/vfs-bundle/tree.js +238 -75
- package/src/vfs-bundle/yarnclean.js +100 -0
- package/src/vfs-bundle.js +16 -7
- package/src/why.js +9 -7
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
|
+
}
|
package/src/table.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// A report's tables, as `stasis audit` and `stasis validate` print them, and their colours where the
|
|
2
|
+
// stream they go to takes colours.
|
|
3
|
+
import { styleText } from 'node:util'
|
|
4
|
+
|
|
5
|
+
// Strip line breaks (LF/CR/CRLF, U+2028/U+2029) from a cell (an advisory's title, say) so they can't
|
|
6
|
+
// break the box layout.
|
|
7
|
+
const cell = (v) => String(v ?? '').replace(/[\r\n\u2028\u2029]+/gu, ' ')
|
|
8
|
+
|
|
9
|
+
// Split a value into the physical lines a cell occupies. Non-multiline columns
|
|
10
|
+
// collapse every line break to a space via `cell` (one line). A column named in
|
|
11
|
+
// `multiline` (the `--why` reason column) keeps intentional `\n` breaks -- one
|
|
12
|
+
// physical line per entry -- while still flattening stray CR/separators in each.
|
|
13
|
+
const cellLines = (v, multiline) =>
|
|
14
|
+
multiline ? String(v ?? '').split('\n').map((s) => cell(s)) : [cell(v)]
|
|
15
|
+
|
|
16
|
+
// The longest of `items` by `lengthOf` (a string's or an array's length), 0 for none: a fold, as a column
|
|
17
|
+
// (a --why cell of 2000 chains, say) may hold more lines and words than one call takes arguments.
|
|
18
|
+
const longest = (items, lengthOf = (item) => item.length) => items.reduce((max, item) => Math.max(max, lengthOf(item)), 0)
|
|
19
|
+
|
|
20
|
+
// A column that wraps narrows no further than its header, and its longest word up to this, so that only
|
|
21
|
+
// a longer word is ever cut.
|
|
22
|
+
const MAX_WHOLE_WORD = 20
|
|
23
|
+
|
|
24
|
+
// What a `multiline` column's entry wrapped starts its further lines with.
|
|
25
|
+
const INDENT = ' '
|
|
26
|
+
|
|
27
|
+
// `text` cut into lines of at most `width`, at spaces where it has them, a word wider than a line cut where
|
|
28
|
+
// it must be; each line after the first starts with `indent`.
|
|
29
|
+
function wrapLine(text, width, indent = '') {
|
|
30
|
+
const lines = []
|
|
31
|
+
let rest = text
|
|
32
|
+
let prefix = ''
|
|
33
|
+
while (prefix.length + rest.length > width) {
|
|
34
|
+
const room = width - prefix.length
|
|
35
|
+
const space = rest.lastIndexOf(' ', room)
|
|
36
|
+
const at = space > 0 ? space : room
|
|
37
|
+
lines.push(prefix + rest.slice(0, at).trimEnd())
|
|
38
|
+
rest = rest.slice(at).trimStart()
|
|
39
|
+
prefix = indent
|
|
40
|
+
}
|
|
41
|
+
if (rest !== '' || lines.length === 0) lines.push(prefix + rest)
|
|
42
|
+
return lines
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// `rows` as a boxed table of `columns`, its header their names. `paint(text, column, row)`, where
|
|
46
|
+
// given, styles the text of each cell of a row (with colour, say), its padding after, unstyled;
|
|
47
|
+
// `paintHeader(text, column)` each name in the header, and `paintFrame(text)` the box drawn around them.
|
|
48
|
+
// Where `width` is given and the table is wider, the `wrap` columns narrow, the widest first, to fit it
|
|
49
|
+
// where they can (see MAX_WHOLE_WORD), their text wrapped (see wrapLine); a `multiline` column's further
|
|
50
|
+
// lines of an entry indented, so they don't read as entries of their own.
|
|
51
|
+
export function formatTable(rows, columns, { multiline = [], paint, paintHeader, paintFrame, width, wrap = [] } = {}) {
|
|
52
|
+
if (rows.length === 0) return ''
|
|
53
|
+
const ml = new Set(multiline)
|
|
54
|
+
const linesOf = (obj) => columns.map((c) => cellLines(obj[c], ml.has(c)))
|
|
55
|
+
const header = columns.map((c) => [c])
|
|
56
|
+
let body = rows.map((r) => linesOf(r))
|
|
57
|
+
const measure = () => columns.map((c, i) =>
|
|
58
|
+
Math.max(c.length, longest(body, (cells) => longest(cells[i])))
|
|
59
|
+
)
|
|
60
|
+
let widths = measure()
|
|
61
|
+
// Each column's text, a space either side, and a border after it; one more border before the first.
|
|
62
|
+
const total = () => widths.reduce((sum, w) => sum + w + 3, 1)
|
|
63
|
+
const wrapping = columns.flatMap((c, i) => (wrap.includes(c) ? [i] : []))
|
|
64
|
+
if (width !== undefined && wrapping.length > 0 && total() > width) {
|
|
65
|
+
const indent = (i) => (ml.has(columns[i]) ? INDENT : '')
|
|
66
|
+
const longestWord = (i) => longest(body, (cells) => longest(cells[i], (line) => longest(line.split(' '))))
|
|
67
|
+
const floors = new Map(wrapping.map((i) => [i, Math.max(columns[i].length, indent(i).length + Math.min(MAX_WHOLE_WORD, longestWord(i)))]))
|
|
68
|
+
while (total() > width) {
|
|
69
|
+
const widest = wrapping.filter((i) => widths[i] > floors.get(i)).toSorted((a, b) => widths[b] - widths[a])[0]
|
|
70
|
+
if (widest === undefined) break
|
|
71
|
+
widths[widest]--
|
|
72
|
+
}
|
|
73
|
+
const narrowed = widths
|
|
74
|
+
body = body.map((cells) => cells.map((lines, i) =>
|
|
75
|
+
wrapping.includes(i) ? lines.flatMap((l) => wrapLine(l, narrowed[i], indent(i))) : lines))
|
|
76
|
+
widths = measure()
|
|
77
|
+
}
|
|
78
|
+
const frame = (text) => (paintFrame ? paintFrame(text) : text)
|
|
79
|
+
const bar = frame('│')
|
|
80
|
+
const line = (l, m, r, fill) => frame(l + widths.map((w) => fill.repeat(w + 2)).join(m) + r)
|
|
81
|
+
// A row spans as many physical lines as its tallest cell; shorter cells pad
|
|
82
|
+
// out with blanks so the borders stay aligned.
|
|
83
|
+
const render = (cells, style) => {
|
|
84
|
+
const height = longest(cells)
|
|
85
|
+
const out = []
|
|
86
|
+
for (let i = 0; i < height; i++) {
|
|
87
|
+
out.push(`${bar} ${cells.map((c, j) => {
|
|
88
|
+
const text = c[i] ?? ''
|
|
89
|
+
return (style && text !== '' ? style(text, columns[j]) : text) + ' '.repeat(widths[j] - text.length)
|
|
90
|
+
}).join(` ${bar} `)} ${bar}`)
|
|
91
|
+
}
|
|
92
|
+
return out.join('\n')
|
|
93
|
+
}
|
|
94
|
+
return [
|
|
95
|
+
line('┌', '┬', '┐', '─'),
|
|
96
|
+
render(header, paintHeader),
|
|
97
|
+
line('├', '┼', '┤', '─'),
|
|
98
|
+
...body.map((cells, at) => render(cells, paint && ((text, column) => paint(text, column, rows[at])))),
|
|
99
|
+
line('└', '┴', '┘', '─'),
|
|
100
|
+
].join('\n')
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Whether `stream` takes colours, as @exodus/test tells it: CI's logs do, though no terminal; a
|
|
104
|
+
// terminal that has them does (a TTY's hasColors); a pipe, or a file, doesn't.
|
|
105
|
+
export function takesColors(stream) {
|
|
106
|
+
return Boolean(process.env.CI) || Boolean(stream?.hasColors?.())
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Dimmed text's format: CI's logs show gray, not faint.
|
|
110
|
+
export const DIM = process.env.CI ? 'gray' : 'dim'
|
|
111
|
+
|
|
112
|
+
// `paint(format, text)`: `text` in `format` (util.styleText's: a colour, `bold`, or a list of them)
|
|
113
|
+
// where `colors` (else as `stream` takes them, takesColors), else as it is.
|
|
114
|
+
export function painter(stream, colors = takesColors(stream)) {
|
|
115
|
+
return (format, text) => (colors && format && text !== '' ? styleText(format, text, { validateStream: false }) : text)
|
|
116
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Types of `@exodus/stasis/validate-notes` (validate-notes.js), whose comments tell what each does.
|
|
2
|
+
|
|
3
|
+
export const OWN_REASONS: Readonly<Record<string, string>>
|
|
4
|
+
export const PACKAGE_REASONS: Readonly<Record<string, string>>
|
|
5
|
+
export const PATCH_ERRORS: Readonly<Record<string, string>>
|
|
6
|
+
export const FILE_REASONS: Readonly<Record<string, string>>
|
|
7
|
+
export const LOCKFILE_ERRORS: Readonly<Record<string, string>>
|
|
8
|
+
|
|
9
|
+
// A package as a report tells it, as much as its note reads.
|
|
10
|
+
export interface NotedPackage {
|
|
11
|
+
reason?: string
|
|
12
|
+
at?: string
|
|
13
|
+
directory?: string
|
|
14
|
+
patch?: { path?: string; from?: string; error?: string; verified?: boolean; applied?: boolean }
|
|
15
|
+
}
|
|
16
|
+
export type NotePart = string | { path: string }
|
|
17
|
+
export function noteOf(pkg: NotedPackage): NotePart[]
|
|
18
|
+
export function noteText(pkg: NotedPackage): string
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// What a validation's report (validate.js's) tells, in words: why own code, a package or a file
|
|
2
|
+
// wasn't checked or is as it is, why no lockfile was held to, and a package's note beside its status.
|
|
3
|
+
// Of no module, for a browser too (`@exodus/stasis/validate-notes`), as printValidationReport tells it.
|
|
4
|
+
|
|
5
|
+
// Why own code wasn't checked, by `own.reason`.
|
|
6
|
+
export const OWN_REASONS = {
|
|
7
|
+
skipped: 'skipped (--only-deps): its dependencies alone validated',
|
|
8
|
+
'no-repository': 'no repository to read it of',
|
|
9
|
+
'no-commit': 'no commit to read it at',
|
|
10
|
+
'commit-not-in-history': 'its commit is in the history of no branch or tag of its repository (a fork\'s, say)',
|
|
11
|
+
'history-unread': 'its commit is at no tag or branch head, nor in its default branch\'s history, and not every other branch was compared',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// A package's reason, unverified (the first) or failing its lockfile (the last four).
|
|
15
|
+
export const PACKAGE_REASONS = {
|
|
16
|
+
local: 'installed from a directory of the repository, which isn\'t read',
|
|
17
|
+
'patch-unverified': 'as patched by the bundle\'s patch, which isn\'t verified against the repository',
|
|
18
|
+
git: 'locked from git, not a registry',
|
|
19
|
+
'not-registry': 'locked from elsewhere than its registry',
|
|
20
|
+
'no-integrity': 'locked with no sha512 to hold its tarball to',
|
|
21
|
+
unsupported: 'no upstream package for its ecosystem',
|
|
22
|
+
unnamed: 'no name or version recorded',
|
|
23
|
+
'not-published': 'not published',
|
|
24
|
+
unreadable: 'its registry refused it',
|
|
25
|
+
timeout: 'not reached in time',
|
|
26
|
+
failed: 'could not be fetched',
|
|
27
|
+
'alias-unverified': 'installed under another name, an alias no lockfile read tells of',
|
|
28
|
+
misplaced: 'installed where its path or its lockfile names another package or version',
|
|
29
|
+
'not-locked': 'not locked by the lockfile',
|
|
30
|
+
'integrity-mismatch': 'its registry\'s tarball is not the one the lockfile locks',
|
|
31
|
+
'integrity-conflict': 'locked with two integrities',
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Why a patch wasn't applied, told after `its patch` and its path.
|
|
35
|
+
export const PATCH_ERRORS = {
|
|
36
|
+
'patch-not-in-repository': 'is the bundle\'s, not the repository\'s',
|
|
37
|
+
'patch-not-found': 'is in no file of its hash (the bundle\'s, or the patches directory\'s)',
|
|
38
|
+
'patch-mismatch': 'is not of the hash its lockfile locks',
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Why a file is as it is, by a problem's `reason`.
|
|
42
|
+
export const FILE_REASONS = { symlink: 'a symlink in the repository', submodule: 'in a submodule', 'tree-cut': 'the repository\'s tree was too large to list whole' }
|
|
43
|
+
|
|
44
|
+
// Why the dependencies were held to no lockfile, by a report's `lockfileError` (a ValidateError's code).
|
|
45
|
+
export const LOCKFILE_ERRORS = {
|
|
46
|
+
'no-lockfile': 'no lockfile of its repository locks them',
|
|
47
|
+
'lockfile-ambiguous': 'more than one package manager\'s lockfile installs it',
|
|
48
|
+
'lockfile-unreadable': 'its lockfile couldn\'t be read',
|
|
49
|
+
'lockfile-unsupported': 'its lockfile is of a kind validate doesn\'t read',
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// What a report tells of a package beside its status, as parts: text, and the paths in it as `{ path }`,
|
|
53
|
+
// for a caller to set apart: why it is unverified or fails its lockfile, its patch, or the directory
|
|
54
|
+
// it is held to; none where nothing more.
|
|
55
|
+
export function noteOf(pkg) {
|
|
56
|
+
const { patch } = pkg
|
|
57
|
+
if (pkg.reason) return [PACKAGE_REASONS[pkg.reason] ?? pkg.reason, ...(pkg.at ? [': ', { path: pkg.at }] : [])]
|
|
58
|
+
if (patch?.error) return ['its patch', ...(patch.path ? [' ', { path: patch.path }] : []), ` ${PATCH_ERRORS[patch.error] ?? `could not be applied (${patch.error})`}`]
|
|
59
|
+
// A patch the bundle holds, as checked against the repository.
|
|
60
|
+
const whose = patch?.from !== 'bundle' ? [] : [patch.verified ? ' (the bundle\'s, as the repository has it)' : ' (the bundle\'s, not verified against the repository)']
|
|
61
|
+
if (patch) return [patch.applied === false ? 'locked patched, bundled as published' : 'patched', ...(patch.path ? [' by ', { path: patch.path }, ...whose] : [])]
|
|
62
|
+
return pkg.directory ? ['held to ', { path: pkg.directory }, ' of the repository'] : []
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// A package's note as text: '' where nothing more.
|
|
66
|
+
export const noteText = (pkg) => noteOf(pkg).map((part) => (typeof part === 'string' ? part : part.path)).join('')
|