summaryrefslogtreecommitdiff
path: root/core/runtime.js
diff options
context:
space:
mode:
Diffstat (limited to 'core/runtime.js')
-rw-r--r--core/runtime.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/core/runtime.js b/core/runtime.js
new file mode 100644
index 0000000..11742dc
--- /dev/null
+++ b/core/runtime.js
@@ -0,0 +1,41 @@
+const nodePath = require('path');
+const fs = require('fs');
+
+global.resolve = (command) => {
+ let commands = getCommands();
+
+ let resolved = null;
+
+ for (let file of commands) {
+ if (nodePath.basename(file) === command) {
+ if (fs.lstatSync(file).isSymbolicLink()) {
+ try {
+ resolved = fs.realpathSync(file);
+ break;
+ } catch (e) {}
+ } else {
+ resolved = file;
+ break;
+ }
+ }
+ }
+
+ return resolved;
+}
+
+global.getCommands = () => {
+ let path = (process.env ?? global.env).PATH.split(":");
+ let commands = [];
+
+ for (let dir of path) {
+ try {
+ let list = fs.readdirSync(dir);
+
+ for (let file of list) {
+ commands.push(dir + "/" + file);
+ }
+ } catch (e) {}
+ }
+
+ return commands;
+} \ No newline at end of file