File tree Expand file tree Collapse file tree 3 files changed +16
-11
lines changed
Expand file tree Collapse file tree 3 files changed +16
-11
lines changed Original file line number Diff line number Diff line change @@ -19,16 +19,12 @@ export function fixImports(generatedCodeList: types.GeneratedCode[]) {
1919 project . createSourceFile (
2020 generatedCode . filePath ,
2121 generatedCode . fileContent ,
22- {
23- overwrite : true ,
24- } ,
22+ { overwrite : true } ,
2523 ) ;
2624 }
2725
2826 try {
2927 for ( const sourceFile of project . getSourceFiles ( ) ) {
30- sourceFile . fixMissingImports ( ) . organizeImports ( ) ;
31-
3228 // find the source file in the generated code file list
3329 let curSourceFile =
3430 generatedCodeList . filter (
@@ -41,12 +37,18 @@ export function fixImports(generatedCodeList: types.GeneratedCode[]) {
4137 path . basename ( sourceFile . getFilePath ( ) ) ,
4238 ) [ 0 ] ;
4339
44- if ( curSourceFile ) {
40+ if ( curSourceFile ) { // if the current file is either functions.ts or api.ts, fix imports and organize them
41+ sourceFile . fixMissingImports ( ) . organizeImports ( ) ;
4542 curSourceFile ! . fileContent = sourceFile . getFullText ( ) ;
4643 } else {
47- logger . error (
48- `Error while fixing imports: Unable to find the source file for ${ sourceFile . getFilePath ( ) } \n\nSkipping import fixing and cleanup for this file` ,
49- ) ;
44+ if (
45+ path . basename ( sourceFile . getFilePath ( ) ) === "functions.ts" ||
46+ path . basename ( sourceFile . getFilePath ( ) ) === "api.ts"
47+ ) { // we only want to show this error if we're unable to find functions.ts or api.ts
48+ logger . error (
49+ `Error while fixing imports: Unable to find the source file for ${ sourceFile . getFilePath ( ) } \n\nSkipping import fixing and cleanup for this file` ,
50+ ) ;
51+ }
5052 }
5153 }
5254 } catch ( error ) {
Original file line number Diff line number Diff line change @@ -26,5 +26,8 @@ export function preserveUserChanges(
2626 morph . preserveSavedVariables ( staleSourceFile , freshSourceFile ) ;
2727 morph . preserveSavedFunctions ( staleSourceFile , freshSourceFile ) ;
2828
29+ // imports don't need @save annotation, they are always preserved and organized
30+ morph . preserveImportDeclarations ( staleSourceFile , freshSourceFile ) ;
31+
2932 return freshSourceFile . getFullText ( ) ;
3033}
Original file line number Diff line number Diff line change @@ -16,10 +16,10 @@ export async function writeToFileSystem(codeToWrite: types.GeneratedCode[]) {
1616 ( element ) => element . fileType === "functions-ts" ,
1717 ) [ 0 ] ! ;
1818
19- await apiWriter . writeToFileSystem ( apiTsCode ) ;
20- await functionsWriter . writeToFileSystem ( functionsTsCode , apiTsCode ) ;
2119 await packageJsonWriter . writeToFileSystem ( ) ;
2220 tsConfigWriter . writeToFileSystem ( ) ;
21+ await apiWriter . writeToFileSystem ( apiTsCode ) ;
22+ await functionsWriter . writeToFileSystem ( functionsTsCode , apiTsCode ) ;
2323
2424 logger . info ( "running npm install :: installing dependencies" ) ;
2525 if ( process . env . HASURA_PLUGIN_CONNECTOR_CONTEXT_PATH ) {
You can’t perform that action at this time.
0 commit comments