11import type { ESLint , Linter } from 'eslint' ;
22import { platform } from 'node:os' ;
3+ import { join } from 'node:path' ;
34import {
45 distinct ,
56 executeProcess ,
@@ -10,20 +11,21 @@ import type { ESLintTarget } from '../config.js';
1011import { setupESLint } from '../setup.js' ;
1112import type { LinterOutput , RuleOptionsPerFile } from './types.js' ;
1213
13- export async function lint ( {
14- eslintrc,
15- patterns ,
16- } : ESLintTarget ) : Promise < LinterOutput > {
17- const results = await executeLint ( { eslintrc, patterns } ) ;
14+ export async function lint (
15+ { eslintrc, patterns } : ESLintTarget ,
16+ opt ?: { cwd ?: string } ,
17+ ) : Promise < LinterOutput > {
18+ const results = await executeLint ( { eslintrc, patterns } , opt ) ;
1819 const eslint = await setupESLint ( eslintrc ) ;
1920 const ruleOptionsPerFile = await loadRuleOptionsPerFile ( eslint , results ) ;
2021 return { results, ruleOptionsPerFile } ;
2122}
2223
23- async function executeLint ( {
24- eslintrc,
25- patterns,
26- } : ESLintTarget ) : Promise < ESLint . LintResult [ ] > {
24+ async function executeLint (
25+ { eslintrc, patterns } : ESLintTarget ,
26+ opt ?: { cwd ?: string } ,
27+ ) : Promise < ESLint . LintResult [ ] > {
28+ const { cwd = process . cwd ( ) } = opt ?? { } ;
2729 // running as CLI because ESLint#lintFiles() runs out of memory
2830 const { stdout } = await executeProcess ( {
2931 command : 'npx' ,
@@ -33,13 +35,14 @@ async function executeLint({
3335 ...( typeof eslintrc === 'object' ? [ '--no-eslintrc' ] : [ ] ) ,
3436 '--no-error-on-unmatched-pattern' ,
3537 '--format=json' ,
38+ `--output-file=${ join ( cwd , '.eslint-results.json' ) } ` ,
3639 ...toArray ( patterns ) . map ( pattern =>
3740 // globs need to be escaped on Unix
3841 platform ( ) === 'win32' ? pattern : `'${ pattern } '` ,
3942 ) ,
4043 ] ,
4144 ignoreExitCode : true ,
42- cwd : process . cwd ( ) ,
45+ cwd,
4346 } ) ;
4447
4548 return JSON . parse ( stdout ) as ESLint . LintResult [ ] ;
0 commit comments