import { relative , resolve } from 'path' ; import { REPO_ROOT } from '@kbn/utils' ; import { File } from '../file' ; import { Project } from './project' ; import { PROJECTS } from './projects' ; param path export function getTsProjectForAbsolutePath ( path ) { const relPath = relative ( REPO_ROOT , path ) ; const file = new File ( resolve ( REPO_ROOT , path ) ) ; const projects = PROJECTS . filter ( ( p ) => p . isAbsolutePathSelected ( path ) ) ; if ( ! projects . length ) { throw new Error ( `Unable to find tsconfig.json file selecting "${ relPath }". Ensure one exists and it is listed in "src/dev/typescript/projects.ts"` ) ; } if ( projects . length !== 1 && ! file . isTypescriptAmbient ( ) ) { const configPaths = projects . map ( ( p ) => `"${ relative ( REPO_ROOT , p . tsConfigPath ) }"` ) ; const pathsMsg = `${ configPaths . slice ( 0 , - 1 ) . join ( ', ' ) } or ${ configPaths [ configPaths . length - 1 ] }` ; throw new Error ( `"${ relPath }" is selected by multiple tsconfig.json files. This probably means the includes/excludes in ${ pathsMsg } are too broad and include the code from multiple projects.` ) ; } return projects [ 0 ] ; }