@@ -24,6 +24,9 @@ export interface Options {
2424 /** The directory containing a tsconfig.json file. */
2525 projectRoot: string
2626
27+ /** Whether to infer the tsconfig.json file, if it's missing. */
28+ inferTSConfig: boolean
29+
2730 /**
2831 * Callback to consume the generated LSIF Typed payload in a streaming fashion.
2932 */
@@ -51,6 +54,11 @@ export function main(): void {
5154 default : 'false' ,
5255 describe : 'whether to index all yarn workspaces' ,
5356 } )
57+ yargs . option ( 'inferTSConfig' , {
58+ type : 'boolean' ,
59+ default : 'false' ,
60+ describe : "Whether to infer the tsconfig.json file, if it's missing" ,
61+ } )
5462 yargs . option ( 'output' , {
5563 type : 'string' ,
5664 default : 'dump.lsif-typed' ,
@@ -59,6 +67,8 @@ export function main(): void {
5967 } ,
6068 argv => {
6169 const workspaceRoot = argv . project as string
70+ const inferTSConfig =
71+ typeof argv . inferTSConfig === 'boolean' && argv . inferTSConfig
6272 const yarnWorkspaces =
6373 typeof argv . yarnWorkspaces === 'boolean' && argv . yarnWorkspaces
6474 const projects : string [ ] = yarnWorkspaces
@@ -73,6 +83,7 @@ export function main(): void {
7383 index ( {
7484 workspaceRoot,
7585 projectRoot,
86+ inferTSConfig,
7687 writeIndex : ( index ) : void => {
7788 fs. writeSync ( output , index . serializeBinary ( ) )
7889 } ,
@@ -125,10 +136,17 @@ export function index(options: Options): void {
125136 tsconfigFileName = projectPath
126137 }
127138 if ( ! ts . sys . fileExists ( tsconfigFileName ) ) {
128- console . error (
129- `skipping project '${ options . projectRoot } ' because it's missing tsconfig.json (expected at ${ tsconfigFileName } )`
130- )
131- return
139+ if ( options . inferTSConfig ) {
140+ fs . writeFileSync (
141+ tsconfigFileName ,
142+ '{"compilerOptions":{"allowJs":true}}'
143+ )
144+ } else {
145+ console . error (
146+ `skipping project '${ options . projectRoot } ' because it's missing tsconfig.json (expected at ${ tsconfigFileName } )`
147+ )
148+ return
149+ }
132150 }
133151 config = loadConfigFile ( tsconfigFileName )
134152 }
0 commit comments