Skip to content

Commit

Permalink
Issue/master/dca11 y 1145 node version manager support windows (#21)
Browse files Browse the repository at this point in the history
* add fnm test for windows

* add windows fnm support
  • Loading branch information
flipatlas authored Feb 3, 2025
1 parent d95f665 commit 8d90da8
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.15.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Set the HOME directory to the directory of the script
$WORKING_DIR = Split-Path -Parent $MyInvocation.MyCommand.Definition

Write-Output $WORKING_DIR

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

# Create the directory if it does not exist
if (-Not (Test-Path -Path $FNM_DIR)) {
New-Item -ItemType Directory -Path $FNM_DIR | Out-Null
}

# 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.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
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
@@ -0,0 +1,3 @@
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "example",
"version": "0.0.1",
"dependencies": {
"classnames": "^2.3.2"
},
"scripts": {
"prebuild": "npm install"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.eirslett</groupId>
<artifactId>fnm-with-npm</artifactId>
<version>0</version>
<packaging>pom</packaging>

<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<!-- NB! Set <version> to the latest released version of frontend-maven-plugin, like in README.md -->
<version>@project.version@</version>

<configuration>
<workingDirectory>${basedir}</workingDirectory>
</configuration>

<executions>
<execution>
<id>install node</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
<execution>
<id>npm ci</id>
<goals>
<goal>npm</goal>
</goals>
<!-- Optional configuration which provides for running any npm command -->
<configuration>
<arguments>ci</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def p = "powershell $basedir\\install-fnm.ps1".execute()
p.waitForProcessOutput(System.out, System.err)
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import org.codehaus.plexus.util.FileUtils

String buildLog = FileUtils.fileRead(new File(basedir, 'build.log'))
assert buildLog.contains('Using FNM version manager') : 'Node has been installed with a different version manager'

assert !new File(basedir, 'node/node').exists() : "Node was installed bypassing version manager"
assert new File(basedir, 'node_modules').exists() : "Node modules were not installed in the base directory"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# ignoring windows for now
invoker.os.family=windows
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 8d90da8

Please sign in to comment.