From da9bf9323c78e7ee46b1be3e06231c59663f5593 Mon Sep 17 00:00:00 2001 From: Philipe Navarro Date: Wed, 9 Sep 2020 16:12:57 -0400 Subject: [PATCH 1/3] fix: config module parent filename location --- src/command/command.ts | 2 +- src/command/main.ts | 2 +- src/config/config.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/command/command.ts b/src/command/command.ts index 819bf63ff..e141501af 100644 --- a/src/command/command.ts +++ b/src/command/command.ts @@ -78,7 +78,7 @@ export default abstract class Command { */ static run: Config.Command.Class['run'] = async function (this: Config.Command.Class, argv?: string[], opts?) { if (!argv) argv = process.argv.slice(2) - const config = await Config.load(opts || (module.parent && module.parent.parent && module.parent.parent.filename) || __dirname) + const config = await Config.load(opts || (module.parent && module.parent.parent && module.parent.parent.parent && module.parent.parent.parent.filename) || __dirname) const cmd = new this(argv, config) return cmd._run(argv) } diff --git a/src/command/main.ts b/src/command/main.ts index 6c681b22b..5c5092273 100644 --- a/src/command/main.ts +++ b/src/command/main.ts @@ -8,7 +8,7 @@ const ROOT_INDEX_CMD_ID = '' export class Main extends Command { static run(argv = process.argv.slice(2), options?: Config.LoadOptions) { - return super.run(argv, options || (module.parent && module.parent.parent && module.parent.parent.filename) || __dirname) + return super.run(argv, options || (module.parent && module.parent.parent && module.parent.parent.parent && module.parent.parent.parent.filename) || __dirname) } async init() { diff --git a/src/config/config.ts b/src/config/config.ts index 3fd5c9b36..37725f81a 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -564,7 +564,7 @@ function isConfig(o: any): o is IConfig { } export type LoadOptions = Options | string | IConfig | undefined -export async function load(opts: LoadOptions = (module.parent && module.parent && module.parent.parent && module.parent.parent.filename) || __dirname) { +export async function load(opts: LoadOptions = (module.parent && module.parent && module.parent.parent && module.parent.parent.parent && module.parent.parent.parent.filename) || __dirname) { if (typeof opts === 'string') opts = {root: opts} if (isConfig(opts)) return opts const config = new Config(opts) From dcb42c2efcf0bea56b690df731434e9cbc0cf011 Mon Sep 17 00:00:00 2001 From: Philipe Navarro Date: Thu, 10 Sep 2020 09:32:20 -0400 Subject: [PATCH 2/3] Revert "fix: config module parent filename location" This reverts commit da9bf9323c78e7ee46b1be3e06231c59663f5593. --- src/command/command.ts | 2 +- src/command/main.ts | 2 +- src/config/config.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/command/command.ts b/src/command/command.ts index e141501af..819bf63ff 100644 --- a/src/command/command.ts +++ b/src/command/command.ts @@ -78,7 +78,7 @@ export default abstract class Command { */ static run: Config.Command.Class['run'] = async function (this: Config.Command.Class, argv?: string[], opts?) { if (!argv) argv = process.argv.slice(2) - const config = await Config.load(opts || (module.parent && module.parent.parent && module.parent.parent.parent && module.parent.parent.parent.filename) || __dirname) + const config = await Config.load(opts || (module.parent && module.parent.parent && module.parent.parent.filename) || __dirname) const cmd = new this(argv, config) return cmd._run(argv) } diff --git a/src/command/main.ts b/src/command/main.ts index 5c5092273..6c681b22b 100644 --- a/src/command/main.ts +++ b/src/command/main.ts @@ -8,7 +8,7 @@ const ROOT_INDEX_CMD_ID = '' export class Main extends Command { static run(argv = process.argv.slice(2), options?: Config.LoadOptions) { - return super.run(argv, options || (module.parent && module.parent.parent && module.parent.parent.parent && module.parent.parent.parent.filename) || __dirname) + return super.run(argv, options || (module.parent && module.parent.parent && module.parent.parent.filename) || __dirname) } async init() { diff --git a/src/config/config.ts b/src/config/config.ts index 37725f81a..3fd5c9b36 100644 --- a/src/config/config.ts +++ b/src/config/config.ts @@ -564,7 +564,7 @@ function isConfig(o: any): o is IConfig { } export type LoadOptions = Options | string | IConfig | undefined -export async function load(opts: LoadOptions = (module.parent && module.parent && module.parent.parent && module.parent.parent.parent && module.parent.parent.parent.filename) || __dirname) { +export async function load(opts: LoadOptions = (module.parent && module.parent && module.parent.parent && module.parent.parent.filename) || __dirname) { if (typeof opts === 'string') opts = {root: opts} if (isConfig(opts)) return opts const config = new Config(opts) From 360fc1982ad5be89c1eaf1f98eb54aa6a4b452b9 Mon Sep 17 00:00:00 2001 From: Philipe Navarro Date: Fri, 11 Sep 2020 09:19:52 -0400 Subject: [PATCH 3/3] fix: export run --- src/index.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/index.ts b/src/index.ts index 843fa35e9..036946b45 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ import * as Command from './command' +import {run} from './command' import * as Config from './config' import * as Errors from './errors' import * as Help from './help' @@ -10,4 +11,5 @@ export { Errors, Help, Parser, + run, }