@@ -12,6 +12,9 @@ const globby = require('globby');
1212const yargs = require ( 'yargs/yargs' ) ;
1313const { hideBin} = require ( 'yargs/helpers' ) ;
1414const childProcess = require ( 'child_process' ) ;
15+ const { promisify} = require ( 'util' ) ;
16+ const spawnAsync = promisify ( childProcess . spawnSync ) ;
17+
1518const {
1619 devtoolsRootPath,
1720 litAnalyzerExecutablePath,
@@ -30,12 +33,7 @@ const flags = yargs(hideBin(process.argv))
3033 yargs . positional ( 'files' , {
3134 describe : 'File(s), glob(s), or directories' ,
3235 type : 'array' ,
33- default : [
34- 'front_end' ,
35- 'inspector_overlay' ,
36- 'scripts' ,
37- 'test' ,
38- ] ,
36+ default : [ 'front_end' , 'inspector_overlay' , 'scripts' , 'test' ] ,
3937 } ) ;
4038 } )
4139 . parse ( ) ;
@@ -56,7 +54,9 @@ async function runESLint(files) {
5654 // This was originally reported in https://github.com/eslint/eslint/issues/9977
5755 // The suggested workaround is to use the CLIEngine to pre-emptively filter out these
5856 // problematic paths.
59- files = await Promise . all ( files . map ( async file => ( await cli . isPathIgnored ( file ) ) ? null : file ) ) ;
57+ files = await Promise . all (
58+ files . map ( async file => ( ( await cli . isPathIgnored ( file ) ) ? null : file ) ) ,
59+ ) ;
6060 files = files . filter ( file => file !== null ) ;
6161
6262 const results = await cli . lintFiles ( files ) ;
@@ -90,19 +90,63 @@ async function runStylelint(files) {
9090 return ! errored ;
9191}
9292
93- function runLitAnalyzer ( files ) {
94- const rules = { 'no-missing-import' : 'error' , 'no-unknown-tag-name' : 'error' , 'no-complex-attribute-binding' : 'off' } ;
95- const args =
96- [ litAnalyzerExecutablePath ( ) , ...Object . entries ( rules ) . flatMap ( ( [ k , v ] ) => [ `--rules.${ k } ` , v ] ) , ...files ] ;
97- const result =
98- childProcess . spawnSync ( nodePath ( ) , args , { encoding : 'utf-8' , cwd : devtoolsRootPath ( ) , stdio : 'inherit' } ) ;
99- return result . status === 0 ;
93+ /**
94+ * @param {string[] } files
95+ */
96+ async function runLitAnalyzer ( files ) {
97+ const rules = {
98+ 'no-missing-import' : 'error' ,
99+ 'no-unknown-tag-name' : 'error' ,
100+ 'no-complex-attribute-binding' : 'off' ,
101+ } ;
102+ const getLitAnalyzerResult = async subsetFiles => {
103+ const args = [
104+ litAnalyzerExecutablePath ( ) ,
105+ ...Object . entries ( rules ) . flatMap ( ( [ k , v ] ) => [ `--rules.${ k } ` , v ] ) ,
106+ ...subsetFiles ,
107+ ] ;
108+ const result = await spawnAsync ( nodePath ( ) , args , {
109+ encoding : 'utf-8' ,
110+ cwd : devtoolsRootPath ( ) ,
111+ stdio : 'inherit' ,
112+ } ) ;
113+ return result . status === 0 ;
114+ } ;
115+
116+ const getSplitFiles = filesToSplit => {
117+ if ( process . platform !== 'win32' ) {
118+ return [ filesToSplit ] ;
119+ }
120+
121+ const splitFiles = [ [ ] ] ;
122+ let index = 0 ;
123+ for ( const file of filesToSplit ) {
124+ // Windows max input is 8191 so we should be conservative
125+ if ( splitFiles [ index ] . join ( ' ' ) . length + file . length < 6144 ) {
126+ splitFiles [ index ] . push ( file ) ;
127+ } else {
128+ index ++ ;
129+ splitFiles [ index ] = [ file ] ;
130+ }
131+ }
132+ return splitFiles ;
133+ } ;
134+
135+ const result = await Promise . all (
136+ getSplitFiles ( files ) . map ( filesBatch => {
137+ return getLitAnalyzerResult ( filesBatch ) ;
138+ } ) ,
139+ ) ;
140+
141+ return result . every ( r => r ) ;
100142}
101143
102144async function run ( ) {
103145 const scripts = [ ] ;
104146 const styles = [ ] ;
105- for ( const path of globby . sync ( flags . files , { expandDirectories : { extensions : [ 'css' , 'js' , 'ts' ] } } ) ) {
147+ for ( const path of globby . sync ( flags . files , {
148+ expandDirectories : { extensions : [ 'css' , 'js' , 'ts' ] } ,
149+ } ) ) {
106150 if ( extname ( path ) === '.css' ) {
107151 styles . push ( path ) ;
108152 } else {
@@ -113,7 +157,7 @@ async function run() {
113157 let succeed = true ;
114158 if ( scripts . length !== 0 ) {
115159 succeed &&= await runESLint ( scripts ) ;
116- succeed &&= runLitAnalyzer ( scripts ) ;
160+ succeed &&= await runLitAnalyzer ( scripts ) ;
117161 }
118162 if ( styles . length !== 0 ) {
119163 succeed &&= await runStylelint ( styles ) ;
0 commit comments