Skip to content

Commit f6190b0

Browse files
authored
Replace process.mainModule with require.main (#1448)
1 parent afcecd6 commit f6190b0

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

index.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -1270,10 +1270,8 @@ class Command extends EventEmitter {
12701270
default:
12711271
throw new Error(`unexpected parse option { from: '${parseOptions.from}' }`);
12721272
}
1273-
// @ts-ignore: unknown property
1274-
if (!this._scriptPath && process.mainModule) {
1275-
// @ts-ignore: unknown property
1276-
this._scriptPath = process.mainModule.filename;
1273+
if (!this._scriptPath && require.main) {
1274+
this._scriptPath = require.main.filename;
12771275
}
12781276

12791277
// Guess name, used in usage in help.
@@ -1327,10 +1325,8 @@ class Command extends EventEmitter {
13271325
// Want the entry script as the reference for command name and directory for searching for other files.
13281326
let scriptPath = this._scriptPath;
13291327
// Fallback in case not set, due to how Command created or called.
1330-
// @ts-ignore: unknown property
1331-
if (!scriptPath && process.mainModule) {
1332-
// @ts-ignore: unknown property
1333-
scriptPath = process.mainModule.filename;
1328+
if (!scriptPath && require.main) {
1329+
scriptPath = require.main.filename;
13341330
}
13351331

13361332
let baseDir;

0 commit comments

Comments
 (0)