11'use strict'
22const path = require ( 'path' )
33const fs = require ( 'fs' )
4+ const { spawnSync } = require ( 'child_process' )
45const process = require ( 'process' )
5- const git = require ( 'isomorphic-git' )
6- const { spawnSync } = require ( 'exec-inline' )
6+ const exec = require ( 'exec-inline' ) . spawnSync
77const command = require . resolve ( '@sane-fmt/wasm32-wasi/bin' )
88const { project } = require ( '@tools/places' )
99
1010const argvPrefix = process . argv . slice ( 2 )
1111const TARGET_REGEX = / \. ( j s | t s ) x ? $ / i
1212
13+ function execCmd ( command , args , options ) {
14+ const { error, status, stdout } = spawnSync ( command , args , {
15+ encoding : 'utf8' ,
16+ stdio : [ 'pipe' , 'pipe' , 'inherit' ] ,
17+ ...options ,
18+ } )
19+
20+ if ( error ) throw error
21+ if ( status ) throw new Error ( `Failed to execute ${ command } ${ args . join ( ' ' ) } ` )
22+
23+ return stdout
24+ }
25+
1326async function listTargets ( ) {
14- const fromLS = ( await git . listFiles ( { fs, dir : project } ) )
27+ const fromLS = execCmd ( 'git' , [ 'ls-files' ] , { cwd : project } )
28+ . split ( '\n' )
29+ . map ( line => line . trim ( ) )
30+ . filter ( Boolean )
1531 . filter ( filename => TARGET_REGEX . test ( filename ) )
1632
17- const fromStatus = (
18- await git . statusMatrix ( {
19- fs,
20- dir : project ,
21- filter : filename => TARGET_REGEX . test ( filename ) ,
22- } )
23- ) . map ( ( [ filename ] ) => filename )
33+ const fromStatus = execCmd ( 'git' , [ 'status' , '--porcelain=v1' ] , { cwd : project } )
34+ . split ( '\n' )
35+ . map ( line => line . trim ( ) )
36+ . filter ( Boolean )
37+ . map ( line => line . slice ( 3 ) )
38+ . filter ( filename => TARGET_REGEX . test ( filename ) )
2439
2540 return [ ...new Set ( [ ...fromLS , ...fromStatus ] ) ]
2641 . filter ( filename => fs . existsSync ( path . resolve ( project , filename ) ) )
@@ -33,7 +48,7 @@ async function createArgv() {
3348
3449async function execute ( ) {
3550 const argv = await createArgv ( )
36- return spawnSync ( process . execPath , command , ...argv ) . exit ( )
51+ return exec ( process . execPath , command , ...argv ) . exit ( )
3752}
3853
3954module . exports = {
0 commit comments