Skip to content

Commit

Permalink
add windows fnm support
Browse files Browse the repository at this point in the history
  • Loading branch information
flipatlas committed Feb 3, 2025
1 parent 4cb19bb commit 25759ab
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# Set the HOME directory to the directory of the script
$HOME = Split-Path -Parent $MyInvocation.MyCommand.Definition
$WORKING_DIR = Split-Path -Parent $MyInvocation.MyCommand.Definition

Write-Output $WORKING_DIR

# Set the FNM_DIR variable
$FNM_DIR = Join-Path -Path $HOME -ChildPath ".fnm"
$FNM_DIR = Join-Path -Path $WORKING_DIR -ChildPath ".fnm"

# Create the directory if it does not exist
if (-Not (Test-Path -Path $FNM_DIR)) {
Expand All @@ -11,12 +13,13 @@ if (-Not (Test-Path -Path $FNM_DIR)) {

# Download and execute the FNM install script
$zipUrl = "https://github.com/Schniz/fnm/releases/download/v1.38.1/fnm-windows.zip"
$zipFilePath = "$FNM_DIR\installer"
$zipFilePath = "$FNM_DIR\installer.zip"
Invoke-WebRequest -Uri $zipUrl -OutFile $zipFilePath

$destinationPath = $FNM_DIR
Expand-Archive -Path $zipFilePath -DestinationPath $destinationPath -Force

# Load the FNM environment and install Node.js version 20.15.1
"$FNM_DIR\fnm.exe" env --use-on-cd --shell powershell | Out-String | Invoke-Expression
"$FNM_DIR\fnm.exe" install 20.15.1
Invoke-Expression "$FNM_DIR\fnm.exe install 20.15.1 --fnm-dir $FNM_DIR"

Write-Output "Finished FNM installation"
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
invoker.environmentVariables.HOME=${basedir}/target/it/node-version-manager/fnm/with-npm
invoker.environmentVariables.FNM_DIR=${basedir}/target/it/node-version-manager/fnm/with-npm/.fnm
invoker.environmentVariables.XDG_DATA_HOME=${basedir}/target/it/node-version-manager/fnm/with-npm
invoker.environmentVariables.HOME=${basedir}/target/it/node-version-manager/windows/fnm
invoker.environmentVariables.FNM_DIR=${basedir}/target/it/node-version-manager/windows/fnm/.fnm
invoker.environmentVariables.XDG_DATA_HOME=${basedir}/target/it/node-version-manager/windows/fnm
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
def p = "powershell $basedir/install-fnm.ps1".execute()
def p = "powershell $basedir\\install-fnm.ps1".execute()
p.waitForProcessOutput(System.out, System.err)
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,33 @@ public File getNodeExecutable(String nodeVersion) {
String architecture = platform.getArchitectureName();
String osCodename = platform.getCodename();
String nodeOnPlatform = String.format("node-%s-%s-%s", nodeVersionWithV, osCodename, architecture);
Path path = Paths.get(fnmDir, "node-versions", nodeVersionWithV, nodeOnPlatform, "bin", "node");

if (installConfig.getPlatform().isWindows()) {
return Paths.get(fnmDir, "node-versions", nodeVersionWithV, "installation", "node.exe").toFile();
}

Path path = Paths.get(fnmDir, "node-versions", nodeVersionWithV, nodeOnPlatform, "bin", "node");
if (Files.exists(path)) {
return path.toFile();
}

return Paths.get(fnmDir, "node-versions", nodeVersionWithV, "installation", "bin", "node").toFile();
}

@Override
public File getNpmExecutable(String nodeVersion) {
File nodeExec = getNodeExecutable(nodeVersion);

if (installConfig.getPlatform().isWindows()) {
return Paths.get(nodeExec.getParent(), "node_modules", "npm", "bin", "npm-cli.js").toFile();
}

return new File(nodeExec.getParent(), "npm");
}

private String getFnmDir() {
String fnmDir = System.getenv("FNM_DIR");
System.out.println("XXX " + fnmDir);
if (fnmDir != null) {
Path path = Paths.get(fnmDir);
if (Files.exists(path)) {
Expand All @@ -60,19 +71,26 @@ private String getFnmDir() {

String home = System.getenv("HOME");
if (home != null) {
Path path = Paths.get(home, ".fnm");
if (Files.exists(path)) {
return path.toString();
}

path = Paths.get(home, "Library", "Application Support", "fnm");
if (Files.exists(path)) {
return path.toString();
}

path = Paths.get(home, ".local", "share", "fnm");
if (Files.exists(path)) {
return path.toString();
if (installConfig.getPlatform().isWindows()) {
Path path = Paths.get(home, "AppData", "Roaming", "fnm");
if (Files.exists(path)) {
return path.toString();
}
} else {
Path path = Paths.get(home, ".fnm");
if (Files.exists(path)) {
return path.toString();
}

path = Paths.get(home, "Library", "Application Support", "fnm");
if (Files.exists(path)) {
return path.toString();
}

path = Paths.get(home, ".local", "share", "fnm");
if (Files.exists(path)) {
return path.toString();
}
}
}

Expand Down

0 comments on commit 25759ab

Please sign in to comment.