@@ -7,31 +7,39 @@ const vars = {
77 error : process . env [ "JUST_ERROR" ] || "" ,
88} ;
99
10- console . debug = ( ...args : any [ ] ) => { } // comment out to debug script
10+ console . debug = ( ...args : any [ ] ) => { } ; // comment out to debug script
1111const old_console_error = console . error ;
1212console . error = ( message : string ) => {
1313 old_console_error ( vars . error + message ) ;
1414} ;
1515
16-
17- function checkJustCommand ( justfile : string , command : string , postitionalArgs : string [ ] ) : boolean {
16+ function checkJustCommand (
17+ justfile : string ,
18+ command : string ,
19+ postitionalArgs : string [ ] ,
20+ ) : boolean {
1821 if ( ! fs . existsSync ( justfile ) ) {
1922 return false ;
2023 }
21- let { cwd, args} = getJustContext ( justfile , command , [ ] , postitionalArgs ) ;
22- console . debug ( `Checking: ${ cwd ? `cd ${ cwd } ; ` : "" } just ${ args . join ( ", " ) } ` ) ;
24+ let { cwd, args } = getJustContext ( justfile , command , [ ] , postitionalArgs ) ;
25+ console . debug (
26+ `Checking: ${ cwd ? `cd ${ cwd } ; ` : "" } just ${ args . join ( ", " ) } ` ,
27+ ) ;
2328 const res = child_process . spawnSync ( vars . just , [ "--dry-run" , ...args ] , {
2429 stdio : [ "ignore" , "ignore" , "pipe" ] ,
2530 encoding : "utf8" ,
2631 cwd,
2732 } ) ;
2833 console . debug ( "result:" , res ) ;
2934 // avoid having the forwarder find itself
30- return res . status === 0 && ! res . stderr . includes ( `forward-command.ts" ${ command } "$@"` ) ;
35+ return (
36+ res . status === 0 &&
37+ ! res . stderr . includes ( `forward-command.ts" ${ command } "$@"` )
38+ ) ;
3139}
3240
3341function findJustfile ( command : string , arg : string ) : string | undefined {
34- for ( let p = arg ; ; p = path . dirname ( p ) ) {
42+ for ( let p = arg ; ; p = path . dirname ( p ) ) {
3543 const candidate = path . join ( p , "justfile" ) ;
3644 if ( checkJustCommand ( candidate , command , [ arg ] ) ) {
3745 return candidate ;
@@ -54,23 +62,28 @@ function forward(cmd: string, args: string[]): number {
5462 // non-positional arguments are flags, + (used by language tests) or environment variable settings
5563 const is_non_positional = / ^ ( - .* | \+ | [ A - Z _ ] [ A - Z _ 0 - 9 ] * = .* ) $ / ;
5664 const flags = args . filter ( ( arg ) => is_non_positional . test ( arg ) ) ;
57- const positionalArgs = args . filter (
58- ( arg ) => ! is_non_positional . test ( arg ) ,
59- ) ;
65+ const positionalArgs = args . filter ( ( arg ) => ! is_non_positional . test ( arg ) ) ;
6066 let justfiles : Map < string , string [ ] > = new Map ( ) ;
61- for ( const arg of positionalArgs . length > 0 ? positionalArgs : [ "." ] ) {
67+ for ( const arg of positionalArgs . length > 0 ? positionalArgs : [ "." ] ) {
6268 const justfile = findJustfile ( cmd , arg ) ;
6369 if ( ! justfile ) {
6470 console . error ( `No justfile found for ${ cmd } on ${ arg } ` ) ;
6571 return 1 ;
6672 }
67- justfiles . set ( justfile , [ ...justfiles . get ( justfile ) || [ ] , arg ] ) ;
73+ justfiles . set ( justfile , [ ...( justfiles . get ( justfile ) || [ ] ) , arg ] ) ;
6874 }
69- const invocations = Array . from ( justfiles . entries ( ) ) . map ( ( [ justfile , positionalArgs ] ) => {
70- const { cwd, args} = getJustContext ( justfile , cmd , flags , positionalArgs ) ;
71- console . log ( `-> ${ cwd ? `cd ${ cwd } ; ` : "" } just ${ args . join ( " " ) } ` ) ;
72- return { cwd, args } ;
73- } ) ;
75+ const invocations = Array . from ( justfiles . entries ( ) ) . map (
76+ ( [ justfile , positionalArgs ] ) => {
77+ const { cwd, args } = getJustContext (
78+ justfile ,
79+ cmd ,
80+ flags ,
81+ positionalArgs ,
82+ ) ;
83+ console . log ( `-> ${ cwd ? `cd ${ cwd } ; ` : "" } just ${ args . join ( " " ) } ` ) ;
84+ return { cwd, args } ;
85+ } ,
86+ ) ;
7487 for ( const { cwd, args } of invocations ) {
7588 if ( invokeJust ( cwd , args ) !== 0 ) {
7689 return 1 ;
@@ -79,27 +92,26 @@ function forward(cmd: string, args: string[]): number {
7992 return 0 ;
8093}
8194
82- function getJustContext ( justfile : string , cmd : string , flags : string [ ] , positionalArgs : string [ ] ) : { args : string [ ] , cwd ?: string } {
83- if ( positionalArgs . length === 1 && justfile == path . join ( positionalArgs [ 0 ] , "justfile" ) ) {
95+ function getJustContext (
96+ justfile : string ,
97+ cmd : string ,
98+ flags : string [ ] ,
99+ positionalArgs : string [ ] ,
100+ ) : { args : string [ ] ; cwd ?: string } {
101+ if (
102+ positionalArgs . length === 1 &&
103+ justfile == path . join ( positionalArgs [ 0 ] , "justfile" )
104+ ) {
84105 // If there's only one positional argument and it matches the justfile path, suppress arguments
85106 // so for example `just build ql/rust` becomes `just build` in the `ql/rust` directory
86107 return {
87108 cwd : positionalArgs [ 0 ] ,
88- args : [
89- cmd ,
90- ...flags ,
91- ] ,
109+ args : [ cmd , ...flags ] ,
92110 } ;
93111 } else {
94112 return {
95113 cwd : undefined ,
96- args : [
97- "--justfile" ,
98- justfile ,
99- cmd ,
100- ...flags ,
101- ...positionalArgs ,
102- ] ,
114+ args : [ "--justfile" , justfile , cmd , ...flags , ...positionalArgs ] ,
103115 } ;
104116 }
105117}
0 commit comments