@@ -7,7 +7,7 @@ const oxlintPlugin = (options = {}) => {
77 let timeoutId = null ;
88 const debounceTime = 300 ;
99 const executeCommand = async ( ) => {
10- const { path = '' , ignorePattern = '' , configFile = 'oxlintrc.json' , deny = [ ] , allow = [ ] , warn = [ ] , params = '' } = options ;
10+ const { path = '' , ignorePattern = '' , configFile = 'oxlintrc.json' , deny = [ ] , allow = [ ] , warn = [ ] , params = '' , oxlintPath = '' } = options ;
1111 const args = [ ] ;
1212 if ( ignorePattern ) {
1313 args . push ( `--ignore-pattern=${ ignorePattern } ` ) ;
@@ -27,35 +27,52 @@ const oxlintPlugin = (options = {}) => {
2727 if ( ! pm )
2828 throw new Error ( 'Could not detect package manager' ) ;
2929 return new Promise ( ( resolve , reject ) => {
30- const { command : cmd , args : cmdArgs } = resolveCommand ( pm . agent , 'execute-local' , [ 'oxlint' , ...args ] ) ;
31- const child = spawn ( cmd , cmdArgs , {
32- cwd,
33- stdio : 'pipe' ,
34- shell : false ,
35- env : {
36- ...process . env ,
37- FORCE_COLOR : '1'
38- }
39- } ) ;
40- child . stdout ?. pipe ( process . stdout ) ;
41- let stderrOutput = '' ;
42- child . stderr ?. on ( 'data' , data => {
43- stderrOutput += data . toString ( ) ;
44- process . stderr . write ( data ) ; // Forward stderr with formatting intact
45- } ) ;
46- child . on ( 'error' , error => {
47- console . error ( `oxlint Error: ${ error . message } ` ) ;
48- reject ( error ) ;
49- } ) ;
50- child . on ( 'exit' , code => {
51- if ( code === 0 ) {
52- console . log ( '\nOxlint successfully finished.' ) ;
53- }
54- else {
55- console . warn ( `\n\x1b[33mOxlint finished with exit code: ${ code } \x1b[0m` ) ;
56- }
57- resolve ( ) ;
58- } ) ;
30+ let isExecuteLocal = true ;
31+ const executeWithFallback = ( useExecuteLocal ) => {
32+ const { command : cmd , args : cmdArgs } = resolveCommand ( pm . agent , useExecuteLocal ? 'execute-local' : 'execute' , [ useExecuteLocal ? oxlintPath || 'oxlint' : 'oxlint' , ...args ] ) ;
33+ const child = spawn ( cmd , cmdArgs , {
34+ cwd,
35+ stdio : 'pipe' ,
36+ shell : false ,
37+ env : {
38+ ...process . env ,
39+ FORCE_COLOR : '1'
40+ }
41+ } ) ;
42+ // child.stdout?.pipe(process.stdout)
43+ let stderrOutput = '' ;
44+ child . stdout ?. on ( 'data' , data => {
45+ const dataString = data . toString ( ) ;
46+ if ( ! dataString . includes ( 'undefined' ) &&
47+ ! ( dataString . includes ( 'not found' ) && useExecuteLocal ) ) {
48+ stderrOutput += dataString ;
49+ process . stdout . write ( data ) ;
50+ }
51+ } ) ;
52+ child . stderr ?. on ( 'data' , data => {
53+ stderrOutput += data . toString ( ) ;
54+ process . stderr . write ( data ) ;
55+ } ) ;
56+ child . on ( 'error' , error => {
57+ console . error ( `oxlint Error: ${ error . message } ` ) ;
58+ reject ( error ) ;
59+ } ) ;
60+ child . on ( 'exit' , code => {
61+ if ( code === 0 ) {
62+ console . log ( '\nOxlint successfully finished.' ) ;
63+ resolve ( ) ;
64+ }
65+ else if ( useExecuteLocal && code !== 1 ) {
66+ isExecuteLocal = false ;
67+ executeWithFallback ( isExecuteLocal ) ;
68+ }
69+ else {
70+ console . warn ( `\n\x1b[33mOxlint finished with exit code: ${ code } \x1b[0m` ) ;
71+ resolve ( ) ;
72+ }
73+ } ) ;
74+ } ;
75+ executeWithFallback ( isExecuteLocal ) ;
5976 } ) ;
6077 } ;
6178 const handleCommandExecution = async ( ) => {
0 commit comments