@@ -14,16 +14,12 @@ import {
1414 ExtractorConfig ,
1515} from '@microsoft/api-extractor' ;
1616import chalk from 'chalk' ;
17+ import { ESLint } from 'eslint' ;
1718import { glob } from 'glob' ;
1819import fs from 'graceful-fs' ;
1920import pkgDir from 'pkg-dir' ;
20- import prettier from 'prettier' ;
2121import { rimraf } from 'rimraf' ;
22- import { copyrightSnippet , getPackages } from './buildUtils.mjs' ;
23-
24- const prettierConfig = await prettier . resolveConfig (
25- fileURLToPath ( import . meta. url ) . replace ( / \. j s $ / , '.d.ts' ) ,
26- ) ;
22+ import { copyrightSnippet , getPackagesWithTsConfig } from './buildUtils.mjs' ;
2723
2824const require = createRequire ( import . meta. url ) ;
2925const typescriptCompilerFolder = await pkgDir ( require . resolve ( 'typescript' ) ) ;
@@ -32,13 +28,8 @@ const typesNodeReferenceDirective = '/// <reference types="node" />';
3228
3329const excludedPackages = new Set ( [ '@jest/globals' , '@jest/test-globals' ] ) ;
3430
35- const packages = getPackages ( ) ;
36-
37- const isTsPackage = p =>
38- fs . existsSync ( path . resolve ( p . packageDir , 'tsconfig.json' ) ) ;
39-
40- const packagesToBundle = packages . filter (
41- p => isTsPackage ( p ) && ! excludedPackages . has ( p . pkg . name ) ,
31+ const packagesToBundle = getPackagesWithTsConfig ( ) . filter (
32+ p => ! excludedPackages . has ( p . pkg . name ) ,
4233) ;
4334
4435console . log ( chalk . inverse ( ' Extracting TypeScript definition files ' ) ) ;
@@ -108,6 +99,20 @@ await fs.promises.writeFile(
10899 JSON . stringify ( sharedExtractorConfig , null , 2 ) ,
109100) ;
110101
102+ const eslint = new ESLint ( {
103+ cwd : process . cwd ( ) ,
104+ fix : true ,
105+ overrideConfig : {
106+ rules : {
107+ // `d.ts` files are by nature `type` only imports, so it's just noise when looking at the file
108+ '@typescript-eslint/consistent-type-imports' : [
109+ 'error' ,
110+ { prefer : 'no-type-imports' } ,
111+ ] ,
112+ } ,
113+ } ,
114+ } ) ;
115+
111116let compilerState ;
112117
113118await Promise . all (
@@ -205,14 +210,17 @@ await Promise.all(
205210
206211 definitionFile = [
207212 copyrightSnippet ,
213+ '' ,
208214 ...definitionFile . split ( copyrightSnippet ) ,
209215 ] . join ( '\n' ) ;
210216
211- const formattedContent = await prettier . format ( definitionFile , {
212- ...prettierConfig ,
213- filepath,
217+ const [ lintResult ] = await eslint . lintText ( definitionFile , {
218+ filePath : 'some-file.ts' ,
214219 } ) ;
215220
221+ // if the autofixer did anything, the result is in `output`
222+ const formattedContent = lintResult . output || definitionFile ;
223+
216224 await fs . promises . writeFile (
217225 filepath . replace (
218226 `${ path . sep } dist${ path . sep } ` ,
0 commit comments