@@ -170,26 +170,33 @@ function compileImportedFile({
170
170
171
171
for ( const importedFile of importedFiles ) {
172
172
const importedFilePath = path . resolve ( path . dirname ( filePath ) , importedFile ) ;
173
- const importedFilePathWithoutExtension = path . join ( path . dirname ( importedFilePath ) , path . basename ( importedFilePath , path . extname ( importedFilePath ) ) ) ;
174
- const importedFilePathWithExtension = importedFilePathWithoutExtension + '.ts' ;
173
+ let importedFilePathResolved : string ;
174
+ if ( importedFilePath . endsWith ( '.ts' ) ) {
175
+ importedFilePathResolved = importedFilePath ;
176
+ } else if ( importedFilePath . endsWith ( '.js' ) ) {
177
+ importedFilePathResolved = `${ path . join ( path . dirname ( importedFilePath ) , path . basename ( importedFilePath , path . extname ( importedFilePath ) ) ) } .ts` ;
178
+ } else {
179
+ importedFilePathResolved = `${ importedFilePath } .ts` ;
180
+ }
175
181
176
- /// if it is a library import then we can skip it
177
- if ( ! fs . existsSync ( importedFilePathWithExtension ) ) {
182
+ if ( ! fs . existsSync ( importedFilePathResolved ) ) {
178
183
// if the library is not allowed then we should let the user know
179
184
// that it is not allowed and won't work early on
180
185
if ( ! ALLOWED_IMPORTS . includes ( importedFile ) ) {
181
186
console . log ( chalk . red ( `Importing libraries is not allowed. Please remove the import "${ importedFile } " from "${ path . basename ( filePath ) } "` ) ) ;
182
187
return false ;
183
188
}
189
+
190
+ // if it is a library import then we can skip it
184
191
continue ;
185
192
}
186
193
187
194
// if the file is not in the nango-integrations directory
188
195
// then we should not compile it
189
196
// if the parts of the path are shorter than the current that means it is higher
190
197
// than the nango-integrations directory
191
- if ( importedFilePathWithExtension . split ( path . sep ) . length < fullPath . split ( path . sep ) . length ) {
192
- const importedFileName = path . basename ( importedFilePathWithExtension ) ;
198
+ if ( importedFilePathResolved . split ( path . sep ) . length < fullPath . split ( path . sep ) . length ) {
199
+ const importedFileName = path . basename ( importedFilePathResolved ) ;
193
200
194
201
console . log (
195
202
chalk . red (
@@ -199,14 +206,14 @@ function compileImportedFile({
199
206
return false ;
200
207
}
201
208
202
- if ( importedFilePathWithExtension . includes ( 'models.ts' ) ) {
209
+ if ( importedFilePathResolved . includes ( 'models.ts' ) ) {
203
210
continue ;
204
211
}
205
212
206
- compiler . compile ( fs . readFileSync ( importedFilePathWithExtension , 'utf8' ) , importedFilePathWithExtension ) ;
207
- console . log ( chalk . green ( `Compiled "${ importedFilePathWithExtension } " successfully` ) ) ;
213
+ compiler . compile ( fs . readFileSync ( importedFilePathResolved , 'utf8' ) , importedFilePathResolved ) ;
214
+ console . log ( chalk . green ( `Compiled "${ importedFilePathResolved } " successfully` ) ) ;
208
215
209
- finalResult = compileImportedFile ( { fullPath, filePath : importedFilePathWithExtension , compiler, type, parsed } ) ;
216
+ finalResult = compileImportedFile ( { fullPath, filePath : importedFilePathResolved , compiler, type, parsed } ) ;
210
217
}
211
218
212
219
return finalResult ;
0 commit comments