@@ -65,45 +65,60 @@ export async function writeOxlintFixture({
6565}
6666
6767export async function runOxlint ( input ) {
68- const fixture =
69- 'filePath' in input && 'configPath' in input
70- ? input
71- : await writeOxlintFixture ( input )
72-
73- const args = [ '--config' , fixture . configPath , '--format' , 'json' , fixture . filePath ]
74-
75- if ( fixture . typeAware ) args . unshift ( '--type-aware' )
76-
77- const result = await new Promise ( ( resolve , reject ) => {
78- const child = spawn ( oxlintBinary , args , {
79- cwd : rootDirectory ,
80- stdio : [ 'ignore' , 'pipe' , 'pipe' ] ,
68+ const fixtureWasProvided = 'filePath' in input && 'configPath' in input
69+ const fixture = fixtureWasProvided ? input : await writeOxlintFixture ( input )
70+
71+ try {
72+ const args = [
73+ '--config' ,
74+ fixture . configPath ,
75+ '--format' ,
76+ 'json' ,
77+ fixture . filePath ,
78+ ]
79+
80+ if ( fixture . typeAware ) args . unshift ( '--type-aware' )
81+
82+ const result = await new Promise ( ( resolve , reject ) => {
83+ const child = spawn ( oxlintBinary , args , {
84+ cwd : rootDirectory ,
85+ stdio : [ 'ignore' , 'pipe' , 'pipe' ] ,
86+ } )
87+ let stdout = ''
88+ let stderr = ''
89+
90+ child . stdout . on ( 'data' , ( chunk ) => {
91+ stdout += chunk
92+ } )
93+ child . stderr . on ( 'data' , ( chunk ) => {
94+ stderr += chunk
95+ } )
96+ child . on ( 'error' , reject )
97+ child . on ( 'close' , ( exitCode ) => {
98+ resolve ( { exitCode, stderr, stdout } )
99+ } )
81100 } )
82- let stdout = ''
83- let stderr = ''
84101
85- child . stdout . on ( 'data' , ( chunk ) => {
86- stdout += chunk
87- } )
88- child . stderr . on ( 'data' , ( chunk ) => {
89- stderr += chunk
90- } )
91- child . on ( 'error' , reject )
92- child . on ( 'close' , ( exitCode ) => {
93- resolve ( { exitCode, stderr, stdout } )
94- } )
95- } )
102+ if ( result . stderr ) {
103+ throw new Error ( result . stderr )
104+ }
96105
97- if ( result . stderr ) {
98- throw new Error ( result . stderr )
99- }
106+ if ( result . exitCode && result . exitCode !== 0 ) {
107+ throw new Error ( result . stdout || `Oxlint exited with code ${ result . exitCode } ` )
108+ }
100109
101- if ( result . exitCode && result . exitCode !== 0 ) {
102- throw new Error ( result . stdout || `Oxlint exited with code ${ result . exitCode } ` )
110+ const stdout = result . stdout . trim ( )
111+ return stdout ? JSON . parse ( stdout ) : { diagnostics : [ ] }
112+ } finally {
113+ if ( ! fixtureWasProvided ) {
114+ await disposeOxlintFixture ( fixture )
115+ }
103116 }
117+ }
104118
105- const stdout = result . stdout . trim ( )
106- return stdout ? JSON . parse ( stdout ) : { diagnostics : [ ] }
119+ export async function disposeOxlintFixture ( fixture ) {
120+ // oxlint-disable-next-line epic-web/no-manual-dispose
121+ await fixture [ Symbol . asyncDispose ] ( )
107122}
108123
109124export async function readLockfile ( ) {
0 commit comments