@@ -42,8 +42,7 @@ export function deriveSchema(functionsFilePath: string): SchemaDerivationResults
4242}
4343
4444function createTsProgram ( functionsFilePath : string ) : Result < [ ts . Program , ts . Diagnostic [ ] ] , ts . Diagnostic [ ] > {
45- const fileDirectory = path . dirname ( functionsFilePath ) ;
46- return loadTsConfig ( fileDirectory ) . bind ( parsedCommandLine => {
45+ return loadTsConfig ( functionsFilePath ) . bind ( parsedCommandLine => {
4746 const compilerHost = ts . createCompilerHost ( parsedCommandLine . options ) ;
4847 const program = ts . createProgram ( [ functionsFilePath ] , parsedCommandLine . options , compilerHost ) ;
4948 const compilerDiagnostics = ts . getPreEmitDiagnostics ( program ) ;
@@ -53,12 +52,24 @@ function createTsProgram(functionsFilePath: string): Result<[ts.Program, ts.Diag
5352 } )
5453}
5554
56- function loadTsConfig ( functionsDir : string ) : Result < ts . ParsedCommandLine , ts . Diagnostic [ ] > {
57- const configPath = ts . findConfigFile ( functionsDir , ts . sys . fileExists ) ?? path . resolve ( require . resolve ( "@tsconfig/node18/tsconfig.json" ) ) ;
55+ function loadTsConfig ( functionsFilePath : string ) : Result < ts . ParsedCommandLine , ts . Diagnostic [ ] > {
56+ const functionsDir = path . dirname ( functionsFilePath ) ;
57+ const userTsConfig = ts . findConfigFile ( functionsDir , ts . sys . fileExists ) ;
58+ // If the user doesn't have a tsconfig, use this one as a fallback. The TypeScript defaults are bad
59+ // (eg. strict and strictNullChecks is off by default)
60+ const fallbackTsConfig = path . resolve ( require . resolve ( "@tsconfig/node18/tsconfig.json" ) ) ;
61+ const configPath = userTsConfig ?? fallbackTsConfig ;
5862 const configFile = ts . readConfigFile ( configPath , ts . sys . readFile )
5963 if ( configFile . error ) {
6064 return new Err ( [ configFile . error ] )
6165 }
66+
67+ // If we're using the fallback tsconfig, override the include path to point to the user's
68+ // functions directory, otherwise it will look in the fallback tsconfig's directory
69+ if ( userTsConfig === undefined ) {
70+ configFile . config . include = [ path . join ( functionsDir , "./**/*" ) ] ;
71+ }
72+
6273 const parsedCommandLine = ts . parseJsonConfigFileContent ( configFile . config , ts . sys , path . dirname ( configPath ) ) ;
6374 if ( parsedCommandLine . errors . find ( d => d . category === ts . DiagnosticCategory . Error ) !== undefined ) {
6475 return new Err ( [ ...parsedCommandLine . errors ] ) ;
0 commit comments