Skip to content

Commit

Permalink
fix: broken CLI in ESM projects since version 0.3 (#8773)
Browse files Browse the repository at this point in the history
* fix: broken CLI in ESM projects

* style: formatting
  • Loading branch information
giladgd committed Mar 22, 2022
1 parent c8fb1bb commit 97699e8
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/commands/CacheClearCommand.ts
Expand Up @@ -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({
Expand Down
9 changes: 7 additions & 2 deletions src/commands/CommandUtils.ts
Expand Up @@ -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.`,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/MigrationGenerateCommand.ts
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/commands/MigrationRevertCommand.ts
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/commands/MigrationRunCommand.ts
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/commands/MigrationShowCommand.ts
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/commands/QueryCommand.ts
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/commands/SchemaDropCommand.ts
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/commands/SchemaLogCommand.ts
Expand Up @@ -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({
Expand Down
2 changes: 1 addition & 1 deletion src/commands/SchemaSyncCommand.ts
Expand Up @@ -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({
Expand Down

0 comments on commit 97699e8

Please sign in to comment.