mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fix: broken CLI in ESM projects since version 0.3 (#8773)
* fix: broken CLI in ESM projects * style: formatting
This commit is contained in:
parent
c8fb1bbe21
commit
97699e816e
@ -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({
|
||||
|
||||
@ -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.`,
|
||||
|
||||
@ -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({
|
||||
|
||||
@ -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({
|
||||
|
||||
@ -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({
|
||||
|
||||
@ -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({
|
||||
|
||||
@ -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({
|
||||
|
||||
@ -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({
|
||||
|
||||
@ -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({
|
||||
|
||||
@ -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({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user