Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Mar 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/commands/CacheClearCommand.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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