« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/util/node-utils.js9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/util/node-utils.js b/src/util/node-utils.js
index 252e920a..76684827 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);
 }