char/avril
(wip) why'd you have to go and make things so complicaaaaated?
git clone https://git.t4t.associates/char/avril
7325e8c
main
1use std:: path:: Path ; 2use std:: process:: Command ; 3 4use anyhow::{ Context , Result , ensure}; 5 6pub fn check_public_types ( manifest_dir : impl AsRef < Path >, declarations : & [ & str ]) ->Result <()> { 7let root = manifest_dir. as_ref (); 8check_types ( root. join ( "tsconfig.json" )) ?; 9let directory = tempfile:: tempdir () ?; 10let mut files =Vec :: new (); 11for ( index, declaration) in declarations. iter (). enumerate () { 12let path = directory. path (). join ( format! ( "module_{index}.d.ts" )); 13 std:: fs:: write ( & path, declaration) ?; 14 files. push ( path); 15} 16 files. push ( root. join ( "tests/public.ts" )); 17let config = directory. path (). join ( "tsconfig.json" ); 18 std:: fs:: write ( 19& config, 20 serde_json:: to_vec_pretty ( & serde_json:: json!({ 21"extends" : root. join ( "../../lib/ext_build/tsconfig.harness.json" ), 22"files" : files, 23})) ?, 24) ?; 25check_types ( config) 26} 27 28/// Check an extension's tsconfig with the native TypeScript backend. 29/// Returns early when AVRIL_TEST_TYPESCRIPT is unset, like the backend test suite. 30pub fn check_types ( config : impl AsRef < Path >) ->Result <()> { 31let Some ( backend) = std:: env:: var_os ( "AVRIL_TEST_TYPESCRIPT" ). filter ( |path| !path. is_empty ()) 32else { 33eprintln! ( "skipping: AVRIL_TEST_TYPESCRIPT is not set" ); 34return Ok (()); 35}; 36let config = config. as_ref (); 37let output =Command :: new ( & backend) 38. arg ( "--project" ) 39. arg ( config) 40. args ([ "--noEmit" , "--pretty" , "false" ]) 41. output () 42. with_context ( ||format! ( "Type-checking {} with {backend:?}" , config. display ())) ?; 43ensure! ( 44 output. status . success (), 45"{}:\n{}{}" , 46 config. display (), 47String :: from_utf8_lossy ( & output. stdout ), 48String :: from_utf8_lossy ( & output. stderr ), 49); 50Ok (()) 51}