@@ -24,6 +24,9 @@ export interface Options {
24
24
/** The directory containing a tsconfig.json file. */
25
25
projectRoot: string
26
26
27
+ /** Whether to infer the tsconfig.json file, if it's missing. */
28
+ inferTSConfig: boolean
29
+
27
30
/**
28
31
* Callback to consume the generated LSIF Typed payload in a streaming fashion.
29
32
*/
@@ -51,6 +54,11 @@ export function main(): void {
51
54
default : 'false' ,
52
55
describe : 'whether to index all yarn workspaces' ,
53
56
} )
57
+ yargs . option ( 'inferTSConfig' , {
58
+ type : 'boolean' ,
59
+ default : 'false' ,
60
+ describe : "Whether to infer the tsconfig.json file, if it's missing" ,
61
+ } )
54
62
yargs . option ( 'output' , {
55
63
type : 'string' ,
56
64
default : 'dump.lsif-typed' ,
@@ -59,6 +67,8 @@ export function main(): void {
59
67
} ,
60
68
argv => {
61
69
const workspaceRoot = argv . project as string
70
+ const inferTSConfig =
71
+ typeof argv . inferTSConfig === 'boolean' && argv . inferTSConfig
62
72
const yarnWorkspaces =
63
73
typeof argv . yarnWorkspaces === 'boolean' && argv . yarnWorkspaces
64
74
const projects : string [ ] = yarnWorkspaces
@@ -73,6 +83,7 @@ export function main(): void {
73
83
index ( {
74
84
workspaceRoot,
75
85
projectRoot,
86
+ inferTSConfig,
76
87
writeIndex : ( index ) : void => {
77
88
fs. writeSync ( output , index . serializeBinary ( ) )
78
89
} ,
@@ -125,10 +136,17 @@ export function index(options: Options): void {
125
136
tsconfigFileName = projectPath
126
137
}
127
138
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
+ }
132
150
}
133
151
config = loadConfigFile ( tsconfigFileName )
134
152
}
0 commit comments