« get me outta code hell

hsmusic-wiki - HSMusic - static wiki software cataloguing collaborative creation
about summary refs log tree commit diff
path: root/src/util/node-utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/node-utils.js')
-rw-r--r--src/util/node-utils.js10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/util/node-utils.js b/src/util/node-utils.js
index d660612..a46d614 100644
--- a/src/util/node-utils.js
+++ b/src/util/node-utils.js
@@ -1,5 +1,7 @@
 // Utility functions which are only relevant to particular Node.js constructs.
 
+import { fileURLToPath } from 'url';
+
 // Very cool function origin8ting in... http-music pro8a8ly!
 // Sorry if we happen to 8e violating past-us's copyright, lmao.
 export function promisifyProcess(proc, showLogging = true) {
@@ -25,3 +27,11 @@ export function promisifyProcess(proc, showLogging = true) {
         })
     })
 }
+
+// Handy-dandy utility function for detecting whether the passed URL is the
+// running JavaScript file. This takes `import.meta.url` from ES6 modules, which
+// is great 'cuz (module === require.main) doesn't work without CommonJS
+// modules.
+export function isMain(importMetaURL) {
+    return (process.argv[1] === fileURLToPath(importMetaURL));
+}