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

Replace process.mainModule with require.main #1448

Merged
merged 1 commit into from Jan 28, 2021
Merged
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
12 changes: 4 additions & 8 deletions index.js
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down