From f6190b0bd155cc93e43fde86031bcb0e7c43293e Mon Sep 17 00:00:00 2001 From: John Gee Date: Fri, 29 Jan 2021 08:06:57 +1300 Subject: [PATCH] Replace process.mainModule with require.main (#1448) --- index.js | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/index.js b/index.js index 20110ff11..f1cf9eaa1 100644 --- a/index.js +++ b/index.js @@ -1270,10 +1270,8 @@ class Command extends EventEmitter { default: throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`); } - // @ts-ignore: unknown property - if (!this._scriptPath && process.mainModule) { - // @ts-ignore: unknown property - this._scriptPath = process.mainModule.filename; + if (!this._scriptPath && require.main) { + this._scriptPath = require.main.filename; } // Guess name, used in usage in help. @@ -1327,10 +1325,8 @@ class Command extends EventEmitter { // Want the entry script as the reference for command name and directory for searching for other files. let scriptPath = this._scriptPath; // Fallback in case not set, due to how Command created or called. - // @ts-ignore: unknown property - if (!scriptPath && process.mainModule) { - // @ts-ignore: unknown property - scriptPath = process.mainModule.filename; + if (!scriptPath && require.main) { + scriptPath = require.main.filename; } let baseDir;