From 0bc52b8d8fb15c4420e49a2503f82e799a18e20d Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Tue, 6 Dec 2022 08:41:53 -0400 Subject: isMain true if directory of index.js targetted --- src/util/node-utils.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/util/node-utils.js b/src/util/node-utils.js index 252e920..7668482 100644 --- a/src/util/node-utils.js +++ b/src/util/node-utils.js @@ -1,6 +1,7 @@ // Utility functions which are only relevant to particular Node.js constructs. import {fileURLToPath} from 'url'; +import * as path from 'path'; import _commandExists from 'command-exists'; @@ -45,5 +46,11 @@ export function promisifyProcess(proc, showLogging = true) { // is great 'cuz (module === require.main) doesn't work without CommonJS // modules. export function isMain(importMetaURL) { - return process.argv[1] === fileURLToPath(importMetaURL); + const metaPath = fileURLToPath(importMetaURL); + const relative = path.relative(process.argv[1], metaPath); + const isIndexJS = path.basename(metaPath) === 'index.js'; + return [ + '', + isIndexJS && 'index.js' + ].includes(relative); } -- cgit 1.3.0-6-gf8a5