@@ -11,10 +11,8 @@ const {extname, join} = require('path');
1111const globby = require ( 'globby' ) ;
1212const yargs = require ( 'yargs/yargs' ) ;
1313const { hideBin} = require ( 'yargs/helpers' ) ;
14- const childProcess = require ( 'child_process' ) ;
15- const { promisify} = require ( 'util' ) ;
14+ const { spawn} = require ( 'child_process' ) ;
1615const { readFileSync} = require ( 'fs' ) ;
17- const spawnAsync = promisify ( childProcess . spawnSync ) ;
1816
1917const {
2018 devtoolsRootPath,
@@ -102,11 +100,17 @@ async function runStylelint(files) {
102100 */
103101async function runLitAnalyzer ( files ) {
104102 const readLitAnalyzerConfigFromCompilerOptions = ( ) => {
105- const { compilerOptions} = JSON . parse ( readFileSync ( tsconfigJsonPath ( ) , 'utf-8' ) ) ;
103+ const { compilerOptions} = JSON . parse (
104+ readFileSync ( tsconfigJsonPath ( ) , 'utf-8' ) ,
105+ ) ;
106106 const { plugins} = compilerOptions ;
107- const tsLitPluginOptions = plugins . find ( plugin => plugin . name === 'ts-lit-plugin' ) ;
107+ const tsLitPluginOptions = plugins . find (
108+ plugin => plugin . name === 'ts-lit-plugin' ,
109+ ) ;
108110 if ( tsLitPluginOptions === null ) {
109- throw new Error ( `Failed to find ts-lit-plugin options in ${ tsconfigJsonPath ( ) } ` ) ;
111+ throw new Error (
112+ `Failed to find ts-lit-plugin options in ${ tsconfigJsonPath ( ) } ` ,
113+ ) ;
110114 }
111115 return tsLitPluginOptions ;
112116 } ;
@@ -118,12 +122,36 @@ async function runLitAnalyzer(files) {
118122 ...Object . entries ( rules ) . flatMap ( ( [ k , v ] ) => [ `--rules.${ k } ` , v ] ) ,
119123 ...subsetFiles ,
120124 ] ;
121- const result = await spawnAsync ( nodePath ( ) , args , {
122- encoding : 'utf-8' ,
123- cwd : devtoolsRootPath ( ) ,
124- stdio : 'inherit' ,
125+
126+ const result = {
127+ output : '' ,
128+ error : '' ,
129+ status : false ,
130+ } ;
131+
132+ return await new Promise ( resolve => {
133+ const litAnalyzerProcess = spawn ( nodePath ( ) , args , {
134+ encoding : 'utf-8' ,
135+ cwd : devtoolsRootPath ( ) ,
136+ } ) ;
137+
138+ litAnalyzerProcess . stdout . on ( 'data' , data => {
139+ result . output += `\n${ data . toString ( ) } ` ;
140+ } ) ;
141+ litAnalyzerProcess . stderr . on ( 'data' , data => {
142+ result . error += `\n${ data . toString ( ) } ` ;
143+ } ) ;
144+
145+ litAnalyzerProcess . on ( 'error' , message => {
146+ result . error += `\n${ message } ` ;
147+ resolve ( result ) ;
148+ } ) ;
149+
150+ litAnalyzerProcess . on ( 'exit' , code => {
151+ result . status = code === 0 ;
152+ resolve ( result ) ;
153+ } ) ;
125154 } ) ;
126- return result . status === 0 ;
127155 } ;
128156
129157 const getSplitFiles = filesToSplit => {
@@ -145,13 +173,21 @@ async function runLitAnalyzer(files) {
145173 return splitFiles ;
146174 } ;
147175
148- const result = await Promise . all (
176+ const results = await Promise . all (
149177 getSplitFiles ( files ) . map ( filesBatch => {
150178 return getLitAnalyzerResult ( filesBatch ) ;
151179 } ) ,
152180 ) ;
181+ for ( const result of results ) {
182+ if ( result . output ) {
183+ console . log ( result . output ) ;
184+ }
185+ if ( result . error ) {
186+ console . log ( result . error ) ;
187+ }
188+ }
153189
154- return result . every ( r => r ) ;
190+ return results . every ( r => r . status ) ;
155191}
156192
157193async function run ( ) {
0 commit comments