fix: broken CLI in ESM projects since version 0.3 (#8773)

* fix: broken CLI in ESM projects

* style: formatting
This commit is contained in:
Gilad S 2022-03-22 05:04:47 +02:00 committed by GitHub
parent c8fb1bbe21
commit 97699e816e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 16 additions and 11 deletions

View File

@ -25,7 +25,7 @@ export class CacheClearCommand implements yargs.CommandModule {
async handler(args: yargs.Arguments) {
let dataSource: DataSource | undefined = undefined
try {
dataSource = CommandUtils.loadDataSource(
dataSource = await CommandUtils.loadDataSource(
path.resolve(process.cwd(), args.dataSource as string),
)
dataSource.setOptions({

View File

@ -4,15 +4,20 @@ import mkdirp from "mkdirp"
import { TypeORMError } from "../error"
import { DataSource } from "../data-source"
import { InstanceChecker } from "../util/InstanceChecker"
import { importOrRequireFile } from "../util/ImportUtils"
/**
* Command line utils functions.
*/
export class CommandUtils {
static loadDataSource(dataSourceFilePath: string): DataSource {
static async loadDataSource(
dataSourceFilePath: string,
): Promise<DataSource> {
let dataSourceFileExports
try {
dataSourceFileExports = require(dataSourceFilePath)
;[dataSourceFileExports] = await importOrRequireFile(
dataSourceFilePath,
)
} catch (err) {
throw new Error(
`Invalid file path given: "${dataSourceFilePath}". File must contain a TypeScript / JavaScript code and export a DataSource instance.`,

View File

@ -70,7 +70,7 @@ export class MigrationGenerateCommand implements yargs.CommandModule {
let dataSource: DataSource | undefined = undefined
try {
dataSource = CommandUtils.loadDataSource(
dataSource = await CommandUtils.loadDataSource(
path.resolve(process.cwd(), args.dataSource as string),
)
dataSource.setOptions({

View File

@ -31,7 +31,7 @@ export class MigrationRevertCommand implements yargs.CommandModule {
async handler(args: yargs.Arguments) {
let dataSource: DataSource | undefined = undefined
try {
dataSource = CommandUtils.loadDataSource(
dataSource = await CommandUtils.loadDataSource(
path.resolve(process.cwd(), args.dataSource as string),
)
dataSource.setOptions({

View File

@ -31,7 +31,7 @@ export class MigrationRunCommand implements yargs.CommandModule {
async handler(args: yargs.Arguments) {
let dataSource: DataSource | undefined = undefined
try {
dataSource = CommandUtils.loadDataSource(
dataSource = await CommandUtils.loadDataSource(
path.resolve(process.cwd(), args.dataSource as string),
)
dataSource.setOptions({

View File

@ -24,7 +24,7 @@ export class MigrationShowCommand implements yargs.CommandModule {
async handler(args: yargs.Arguments) {
let dataSource: DataSource | undefined = undefined
try {
dataSource = CommandUtils.loadDataSource(
dataSource = await CommandUtils.loadDataSource(
path.resolve(process.cwd(), args.dataSource as string),
)
dataSource.setOptions({

View File

@ -33,7 +33,7 @@ export class QueryCommand implements yargs.CommandModule {
let queryRunner: QueryRunner | undefined = undefined
let dataSource: DataSource | undefined = undefined
try {
dataSource = CommandUtils.loadDataSource(
dataSource = await CommandUtils.loadDataSource(
path.resolve(process.cwd(), args.dataSource as string),
)
dataSource.setOptions({

View File

@ -27,7 +27,7 @@ export class SchemaDropCommand implements yargs.CommandModule {
async handler(args: yargs.Arguments) {
let dataSource: DataSource | undefined = undefined
try {
dataSource = CommandUtils.loadDataSource(
dataSource = await CommandUtils.loadDataSource(
path.resolve(process.cwd(), args.dataSource as string),
)
dataSource.setOptions({

View File

@ -28,7 +28,7 @@ export class SchemaLogCommand implements yargs.CommandModule {
async handler(args: yargs.Arguments) {
let dataSource: DataSource | undefined = undefined
try {
dataSource = CommandUtils.loadDataSource(
dataSource = await CommandUtils.loadDataSource(
path.resolve(process.cwd(), args.dataSource as string),
)
dataSource.setOptions({

View File

@ -27,7 +27,7 @@ export class SchemaSyncCommand implements yargs.CommandModule {
async handler(args: yargs.Arguments) {
let dataSource: DataSource | undefined = undefined
try {
dataSource = CommandUtils.loadDataSource(
dataSource = await CommandUtils.loadDataSource(
path.resolve(process.cwd(), args.dataSource as string),
)
dataSource.setOptions({