From ca69d96b2ad34ca7bc0ba47da63b18c449055dbb Mon Sep 17 00:00:00 2001 From: Corey Butler Date: Tue, 22 Nov 2022 20:16:21 -0600 Subject: [PATCH] Added simple PATH troubleshooter --- utilities/pathfinder/README.md | 18 ++++++++++ utilities/pathfinder/src/pathfinder.js | 48 ++++++++++++++++++++++++++ utilities/pathfinder/start.bat | 4 +++ 3 files changed, 70 insertions(+) create mode 100644 utilities/pathfinder/README.md create mode 100644 utilities/pathfinder/src/pathfinder.js create mode 100644 utilities/pathfinder/start.bat diff --git a/utilities/pathfinder/README.md b/utilities/pathfinder/README.md new file mode 100644 index 0000000..79576e4 --- /dev/null +++ b/utilities/pathfinder/README.md @@ -0,0 +1,18 @@ +# pathfinder + +This app is used to help identify NVM4W installation problems. The executable is not signed and is intended for troubleshooting purposes only. It is just a troubleshooting tool which is not an officially a supported part of NVM for Windows. + +## Usage + +Download pathfinder.exe and run it. + +The output will look like: + +``` +> .\pathfinder.exe +PATH directories containing node.exe: + + 1. C:\Program Files\nodejs (NVM_SYMLINK) + +NVM for Windows is correctly positioned in the PATH. +``` \ No newline at end of file diff --git a/utilities/pathfinder/src/pathfinder.js b/utilities/pathfinder/src/pathfinder.js new file mode 100644 index 0000000..e571bf4 --- /dev/null +++ b/utilities/pathfinder/src/pathfinder.js @@ -0,0 +1,48 @@ +const paths = new Set() +const symlinks = new Set() +const nvm4w = new Set() + +// Identify paths with node.exe +const sources = new Set(Deno.env.get('PATH').split(';')) +for (const dir of sources.values()) { + try { + await Deno.stat(`${dir}\\node.exe`) + paths.add(dir) + + const i = await Deno.lstat(dir) + if (i.isSymlink) { + symlinks.add(dir) + const real = await Deno.realPath(dir) + + try { + await Deno.stat(`${real}\\..\\nvm.exe`) + nvm4w.add(dir) + } catch (e) {} + } + } catch (e) {} +} + +const directories = Array.from(paths) + +let ok = false + +console.log('PATH directories containing node.exe:\n') + +for (const key in directories) { + const dir = directories[key] + const isnvm4w = nvm4w.has(dir) + const i = parseInt(key, 10) + + if (i === 0 && isnvm4w) { + ok = true + } + + console.log(` ${i + 1}. ${dir}${isnvm4w ? ' (NVM_SYMLINK)' : ''}`) +} + +if (ok) { + console.log('\nNVM for Windows is correctly positioned in the PATH.') +} else { + console.log('\nNVM for Windows is INCORRECTLY positioned in the PATH (must be first)') + console.log('A prior/alternative installation of Node.js may be preventing NVM for Windows from functioning.') +} diff --git a/utilities/pathfinder/start.bat b/utilities/pathfinder/start.bat new file mode 100644 index 0000000..abed5e5 --- /dev/null +++ b/utilities/pathfinder/start.bat @@ -0,0 +1,4 @@ +@echo off +cls +deno run --allow-all ./src/pathfinder.js +@echo on