import { LeafTask } from "./leafTask" ; import { TscTask , TscDependentTask } from "./tscTask" ; import { existsSync , readFileSync } from "fs" ; import * as path from "path" ; import * as JSON5 from "json5" ; abstract class LintBaseTask extends TscDependentTask { protected addDependentTasks ( dependentTasks ) { for ( const child of this . node . dependentPackages ) { if ( this . addChildTask ( dependentTasks , child , "tsc" ) ) { this . logVerboseDependency ( child , "tsc" ) ; } } super . addDependentTasks ( dependentTasks ) ; } } ; export class TsLintTask extends LintBaseTask { protected get doneFile ( ) { return "tslint.done.build.log" ; } protected get configFileFullPath ( ) { return this . getPackageFileFullPath ( "tslint.json" ) ; } } export class EsLintTask extends LintBaseTask { private _configFileFullPath : string | undefined ; protected get doneFile ( ) { return "eslint.done.build.log" ; } protected get configFileFullPath ( ) { if ( ! this . _configFileFullPath ) { const possibleConfig = [ ".eslintrc.js" , ".eslintrc.json" , ".eslintrc" ] ; for ( const configFile of possibleConfig ) { const configFileFullPath = this . getPackageFileFullPath ( configFile ) ; if ( existsSync ( configFileFullPath ) ) { this . _configFileFullPath = configFileFullPath ; break ; } } if ( ! this . _configFileFullPath ) { throw new Error ( `Unable to find config file for eslint ${ this . command }` ) ; } } return this . _configFileFullPath ; } protected addDependentTasks ( dependentTasks ) { let config ; try { if ( path . parse ( this . configFileFullPath ) . ext !== ".js" ) { const configFile = readFileSync ( this . configFileFullPath , "utf8" ) ; config = JSON5 . parse ( configFile ) ; } else { config = require ( this . configFileFullPath ) ; if ( config === undefined ) { throw new Error ( "Exports not found" ) ; } } } catch ( e ) { throw new Error ( `Unable to parse options from ${ this . configFileFullPath }. ${ e }` ) ; } if ( config . parserOptions ?. project ) { for ( const tsConfigPath of config . parserOptions ?. project ) { this . addTscTask ( dependentTasks , { tsConfig : this . getPackageFileFullPath ( tsConfigPath ) } ) ; } } super . addDependentTasks ( dependentTasks ) ; } protected get useWorker ( ) { return this . node . buildContext . workerPool ?. useWorkerThreads === false ; } } export class TsFormatTask extends LintBaseTask { protected get doneFile ( ) { return "tsfmt.done.build.log" ; } protected get configFileFullPath ( ) { return this . getPackageFileFullPath ( "tsconfig.json" ) ; } }