Skip to content

Commit

Permalink
fix: support async import for DataSource in CLI typeorm#8914 (typeorm…
Browse files Browse the repository at this point in the history
…#8917)

* Fix: await DataSource from export file to support async loading

* fix: prettier errors

* updated code style

Co-authored-by: Umed Khudoiberdiev <pleerock.me@gmail.com>
  • Loading branch information
2 people authored and wirekang committed Aug 25, 2022
1 parent c447373 commit dd8c2ba
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/commands/CommandUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ export class CommandUtils {
}

const dataSourceExports = []
for (let fileExport in dataSourceFileExports) {
if (
InstanceChecker.isDataSource(dataSourceFileExports[fileExport])
) {
dataSourceExports.push(dataSourceFileExports[fileExport])
for (const fileExport of dataSourceFileExports) {
// It is necessary to await here in case of the exported async value (Promise<DataSource>).
// e.g. the DataSource is instantiated with an async factory in the source file
const awaitedFileExport =
fileExport instanceof Promise ? await fileExport : fileExport
if (InstanceChecker.isDataSource(awaitedFileExport)) {
dataSourceExports.push(awaitedFileExport)
}
}

Expand Down

0 comments on commit dd8c2ba

Please sign in to comment.