Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DCA11Y-1145] Node version manager support #4

Open
wants to merge 74 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
74 commits
Select commit Hold shift + click to select a range
d2f488e
DCA11Y-1145: add tests for nvm and fnm
flipatlas Sep 16, 2024
0a771db
DCA11Y-1145: add node version manager support to node and npm installers
flipatlas Sep 16, 2024
a883c9c
DCA11Y-1145: fix setup for npm goal
flipatlas Sep 16, 2024
46b8a10
DCA11Y-1145: small CR tweaks
flipatlas Sep 19, 2024
348cd57
Issue/master/dca11 y 1145 node version manager support 2 (#5)
flipatlas Sep 19, 2024
c772fad
DCA11Y-1145: add test for yarn with fnm
flipatlas Sep 19, 2024
4180868
DCA11Y-1145: enable node version manager support by default
flipatlas Sep 19, 2024
b04f793
DCA11Y-1145: add NVS support
flipatlas Sep 19, 2024
bea814f
DCA11Y-1145: fix bun default setup
flipatlas Sep 19, 2024
5b8e67b
DCA11Y-1145: try with bash
flipatlas Sep 19, 2024
8ba94c9
DCA11Y-1145: run prebuild installation with bash
flipatlas Sep 19, 2024
7d36ade
DCA11Y-1145: mise support
flipatlas Sep 20, 2024
111d2f6
DCA11Y-1145: asdf support
flipatlas Sep 20, 2024
d946a7a
restructure invoker tests to be hierarchical and share invoker.proper…
flipatlas Sep 20, 2024
8a6d23c
DCA11Y-1145: use node version manager configured node version instead…
flipatlas Sep 20, 2024
cbf1733
DCA11Y-1145: fix java docs
flipatlas Sep 20, 2024
0e2c515
DCA11Y-1145: fail quickly when nvm can't fails, e.g. no versioning fi…
flipatlas Sep 20, 2024
f4a7b64
DCA11Y-1145: verify node version before installation
flipatlas Sep 20, 2024
729d407
DCA11Y-1145: cover test case with project with submodules
flipatlas Sep 20, 2024
b87ffe6
Merge branch 'master' into issue/master/DCA11Y-1145-node-version-mana…
flipatlas Sep 27, 2024
0c47434
DCA11Y-1145: add changelog and README.md
flipatlas Sep 27, 2024
1c5012a
DCA11Y-1145: fix test declarations
flipatlas Sep 27, 2024
8afed90
DCA11Y-1145: fall back to standard installation if no nvm found
flipatlas Sep 27, 2024
09c3b61
DCA11Y-1145: fix webpack mojo
flipatlas Sep 30, 2024
d65fdf0
Merge branch 'master' into issue/master/DCA11Y-1145-node-version-mana…
flipatlas Sep 30, 2024
5c58f3b
DCA11Y-1145: handle empty node version
flipatlas Sep 30, 2024
02f0008
DCA11Y-1145: move version setting to node installer
flipatlas Sep 30, 2024
e1f5598
DCA11Y-1145: extract node install mojo
flipatlas Sep 30, 2024
25a2d87
DCA11Y-1145: disable node version manager on file version tests
flipatlas Sep 30, 2024
1774147
DCA11Y-1145 node version manager support aui shell (#13)
flipatlas Oct 11, 2024
aa43844
DCA11Y-1145: chore: prepare for release of 1.15.0-atlassian-1-1774147f
flipatlas Oct 11, 2024
699476a
DCA11Y-1145: chore: clean up versions after release
flipatlas Oct 11, 2024
2b6a4f9
DCA11Y-1145: try shell without login for BB
flipatlas Oct 14, 2024
4e13098
DCA11Y-1145: chore: prepare for release 1.15.0-atlassian-1-2b6a4f95
flipatlas Oct 14, 2024
6a5a0eb
DCA11Y-1145: chore: clean up after release
flipatlas Oct 14, 2024
32f24e1
DCA11Y-1145: test: fnm with preinstalled node version
flipatlas Oct 14, 2024
f2b2fe1
DCA11Y-1145: source profile files manually + add dockerfiles for fnm …
flipatlas Oct 14, 2024
1144f26
DCA11Y-1145: dockerfiles for mise and nvs
flipatlas Oct 14, 2024
ca346b8
DCA11Y-1145: add node version check for debugging
flipatlas Oct 14, 2024
25d28da
DCA11Y-1145: chore: prepare for release 1.15.0-atlassian-1-ca346b89
flipatlas Oct 14, 2024
2a8065f
DCA11Y-1145: chore: clean up version after release
flipatlas Oct 14, 2024
26753ea
DCA11Y-1145: doc: add current limitation with nvms
flipatlas Oct 15, 2024
1182003
DCA11Y-1145: chore: try running fnm directly
flipatlas Oct 28, 2024
8ece418
DCA11Y-1145: chore: Prepare for release of 1.15.0-atlassian-1-11820033
flipatlas Oct 28, 2024
b418b20
DCA11Y-1145: chore: clean up after release
flipatlas Oct 28, 2024
d8b40b6
DCA11Y-1145: refactor: use shell only if node version manager require…
flipatlas Oct 28, 2024
6ddef59
fix fnm install (#15)
flipatlas Oct 29, 2024
22f9ba8
Merge branch 'master' into issue/master/DCA11Y-1145-node-version-mana…
flipatlas Nov 22, 2024
60125f1
fix after merge
flipatlas Nov 22, 2024
9103d2e
use version manager installation directory
flipatlas Nov 22, 2024
fff25fe
use version manager installation directory (asdf)
flipatlas Nov 22, 2024
e7125aa
use version manager installation directory (mise)
flipatlas Nov 22, 2024
05d12fb
use version manager installation directory (nvm)
flipatlas Nov 22, 2024
b1c76cc
use version manager installation directory (nvs)
flipatlas Nov 22, 2024
99beb02
clean up
flipatlas Nov 22, 2024
30afd62
fix fnm install
flipatlas Nov 22, 2024
d6fb44b
fix fnm install
flipatlas Nov 22, 2024
667c661
clean up abstractions
flipatlas Nov 22, 2024
48f6b7a
install correct node version for webpack
flipatlas Nov 22, 2024
0c3e834
chore: prepare for release of 1.15.1-atlassian-1-48f6b7a
flipatlas Nov 22, 2024
eabb449
chore: clean up after release
flipatlas Nov 25, 2024
6f623e1
clean up documentation
flipatlas Nov 25, 2024
1f0a3e7
install custom npm in nvm
flipatlas Dec 6, 2024
9e87cb2
Merge branch 'master' into issue/master/DCA11Y-1145-node-version-mana…
flipatlas Dec 6, 2024
0abce14
fix custom node assertion
flipatlas Dec 6, 2024
5a27505
try fix mise
flipatlas Dec 6, 2024
7b03cc8
revert AbstractNodeMojo.java
flipatlas Dec 6, 2024
70d139c
update mise client
flipatlas Dec 6, 2024
b9364f6
chore: prepare for release 1.15.1-atlassian-4-70d139cc
flipatlas Dec 6, 2024
0b29e57
chore: clean up after release
flipatlas Dec 6, 2024
c965cd2
minor tweaks based on CR
flipatlas Dec 9, 2024
c181728
configure installed node directory
flipatlas Dec 9, 2024
2169154
fix npe
flipatlas Dec 9, 2024
f94bf57
update node installer metrics if node already provided
flipatlas Jan 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FNM_DIR=$HOME/.fnm
PATH=$FNM_DIR:$PATH
eval "$(fnm env --use-on-cd --shell bash)"
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.15.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# invoker env variables are not loaded yet
export HOME="$(dirname "$0")"

export FNM_DIR="$HOME/.fnm";
mkdir "$FNM_DIR"

curl -fsSL https://fnm.vercel.app/install | bash -s -- --install-dir "$FNM_DIR" --skip-shell --force-install
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
invoker.environmentVariables.HOME=${basedir}/target/its/node-version-manager-install-with-fnm
invoker.environmentVariables.FNM_DIR=${basedir}/target/its/node-version-manager-install-with-fnm/.fnm
invoker.environmentVariables.XDG_DATA_HOME=${basedir}/target/its/node-version-manager-install-with-fnm
invoker.environmentVariables.SHELL=bash

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,46 @@
<?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>example</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>
<nodeVersion>20.15.1</nodeVersion>
<workingDirectory>${basedir}</workingDirectory>
<useNodeVersionManager>true</useNodeVersionManager>
</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,3 @@
def p = "sh $basedir/install-fnm.sh".execute()
p.waitFor()
println p.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import org.codehaus.plexus.util.FileUtils

// assert
assert !new File(basedir, 'node').exists() : "Node was installed in the custom install directory"
assert new File(basedir, 'node_modules').exists() : "Node modules were not installed in the base directory"

String buildLog = FileUtils.fileRead(new File(basedir, 'build.log'))
assert buildLog.contains('BUILD SUCCESS') : 'build was not successful'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm into the shell

# disable global fnm if installed
fnm() {
exit 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v20.15.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# invoker env variables are not loaded yet
export HOME="$(dirname "$0")"

export NVM_DIR="$HOME/.nvm";
mkdir "$NVM_DIR"
echo "NVM_DIR set";

(
git clone https://github.com/nvm-sh/nvm.git "$NVM_DIR" &&
cd "$NVM_DIR" &&
git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
);
echo "NVM checked out";


Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
invoker.environmentVariables.HOME=${basedir}/target/its/node-version-manager-install-with-nvm
invoker.environmentVariables.NVM_DIR=${basedir}/target/its/node-version-manager-install-with-nvm/.nvm
invoker.environmentVariables.SHELL=bash

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,46 @@
<?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>example</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>
<nodeVersion>20.15.1</nodeVersion>
<workingDirectory>${basedir}</workingDirectory>
<useNodeVersionManager>true</useNodeVersionManager>
</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,3 @@
def p = "sh $basedir/install-nvm.sh".execute()
p.waitFor()
println p.text
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import org.codehaus.plexus.util.FileUtils

// assert
assert !new File(basedir, 'node').exists() : "Node was installed in the custom install directory"
assert new File(basedir, 'node_modules').exists() : "Node modules were not installed in the base directory"

String buildLog = FileUtils.fileRead(new File(basedir, 'build.log'))
assert buildLog.contains('BUILD SUCCESS') : 'build was not successful'
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public abstract class AbstractFrontendMojo extends AbstractMojo {
@Parameter(defaultValue = "${repositorySystemSession}", readonly = true)
private RepositorySystemSession repositorySystemSession;

@Parameter(property = "useNodeVersionManager", readonly = true, defaultValue = "false")
flipatlas marked this conversation as resolved.
Show resolved Hide resolved
private boolean useNodeVersionManager;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do one more like you suggested before? Just direct path to where node binary is. Both Maven property and use System.getEnv. I'm worried that someone will use an old branch with old version of this in the future and it won't support new version of FNM/NVS/etc. If we can tell them "no worries" modify your .mvn/cnfig and/or shell envinroment, that will be a great get out of jail pass.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added installedNodeDirectory property and AFMP_INSTALLED_NODE_DIRECTORY env var for specifying node explicitly


/**
* Determines if this execution should be skipped.
*/
Expand Down Expand Up @@ -92,7 +95,7 @@ public void execute() throws MojoFailureException {
}
try {
execute(new FrontendPluginFactory(workingDirectory, installDirectory,
new RepositoryCacheResolver(repositorySystemSession)));
new RepositoryCacheResolver(repositorySystemSession), useNodeVersionManager));
} catch (TaskRunnerException e) {
if (testFailureIgnore && isTestingPhase()) {
getLog().error("There are test failures.\nFailed to run task: " + e.getMessage(), e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ public final class InstallNodeAndNpmMojo extends AbstractFrontendMojo {

/**
* The version of Node.js to install. IMPORTANT! Most Node.js version names start with 'v', for example 'v0.10.18'
* If set to `version_manager`, node version manager will be used to run installation commands
*/
@Parameter(property="nodeVersion", required = true)
@Parameter(property="nodeVersion", required = false)
flipatlas marked this conversation as resolved.
Show resolved Hide resolved
private String nodeVersion;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public synchronized void execute(FrontendPluginFactory factory) throws TaskRunne
File packageJson = new File(workingDirectory, "package.json");
if (buildContext == null || buildContext.hasDelta(packageJson) || !buildContext.isIncremental()) {
ProxyConfig proxyConfig = getProxyConfig();
factory.loadVersionManager();
factory.getNpmRunner(proxyConfig, getRegistryUrl()).execute(arguments, environmentVariables);
} else {
getLog().info("Skipping npm install as package.json unchanged");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package com.github.eirslett.maven.plugins.frontend.lib;

import com.github.eirslett.maven.plugins.frontend.lib.version.manager.VersionManagerCache;
import com.github.eirslett.maven.plugins.frontend.lib.version.manager.VersionManagerRunner;
import com.github.eirslett.maven.plugins.frontend.lib.version.manager.VersionManagerType;
import com.github.eirslett.maven.plugins.frontend.lib.version.manager.VersionManagerLocator;

import java.io.File;

public final class FrontendPluginFactory {
Expand All @@ -10,26 +15,49 @@ public final class FrontendPluginFactory {
private final File workingDirectory;
private final File installDirectory;
private final CacheResolver cacheResolver;
private final boolean useNodeVersionManager;

public FrontendPluginFactory(File workingDirectory, File installDirectory){
this(workingDirectory, installDirectory, getDefaultCacheResolver(installDirectory));
}

public FrontendPluginFactory(File workingDirectory, File installDirectory, CacheResolver cacheResolver){
this(workingDirectory, installDirectory, cacheResolver, false);
}
flipatlas marked this conversation as resolved.
Show resolved Hide resolved

public FrontendPluginFactory(File workingDirectory, File installDirectory, CacheResolver cacheResolver, boolean useNodeVersionManager){
this.workingDirectory = workingDirectory;
this.installDirectory = installDirectory;
this.cacheResolver = cacheResolver;
this.useNodeVersionManager = useNodeVersionManager;

initializeGlobalCache();
}

private void initializeGlobalCache() {
InstallConfig installConfig = new DefaultInstallConfig(installDirectory, workingDirectory, cacheResolver, defaultPlatform, useNodeVersionManager);
GlobalCache.setInstallConfig(installConfig);

if (installConfig.isUseNodeVersionManager()) {
VersionManagerLocator versionManagerLocator = new VersionManagerLocator(installConfig);
VersionManagerType versionManagerType = versionManagerLocator.findAvailable();
GlobalCache.setVersionManagerCache(
new VersionManagerCache(versionManagerType)
);
} else {
GlobalCache.setVersionManagerCache(new VersionManagerCache());
}
}

public BunInstaller getBunInstaller(ProxyConfig proxy) {
return new BunInstaller(getInstallConfig(), new DefaultArchiveExtractor(), new DefaultFileDownloader(proxy));
}
public NodeInstaller getNodeInstaller(ProxyConfig proxy) {
return new NodeInstaller(getInstallConfig(), new DefaultArchiveExtractor(), new DefaultFileDownloader(proxy));
return new NodeInstaller(getInstallConfig(), getVersionManagerCache(), new DefaultArchiveExtractor(), new DefaultFileDownloader(proxy));
}

public NPMInstaller getNPMInstaller(ProxyConfig proxy) {
return new NPMInstaller(getInstallConfig(), new DefaultArchiveExtractor(), new DefaultFileDownloader(proxy));
return new NPMInstaller(getInstallConfig(), getVersionManagerCache(), new DefaultArchiveExtractor(), new DefaultFileDownloader(proxy));
}

public PnpmInstaller getPnpmInstaller(ProxyConfig proxy) {
Expand Down Expand Up @@ -88,15 +116,29 @@ public WebpackRunner getWebpackRunner(){
return new DefaultWebpackRunner(getExecutorConfig());
}

public VersionManagerRunner getVersionManagerRunner() {
return new VersionManagerRunner(getInstallConfig(), getVersionManagerCache());
}

private NodeExecutorConfig getExecutorConfig() {
return new InstallNodeExecutorConfig(getInstallConfig());
return new InstallNodeExecutorConfig(getInstallConfig(), getVersionManagerCache());
}

private InstallConfig getInstallConfig() {
return new DefaultInstallConfig(installDirectory, workingDirectory, cacheResolver, defaultPlatform);
return GlobalCache.getInstallConfig();
}

private VersionManagerCache getVersionManagerCache() {
return GlobalCache.getVersionManagerCache();
}

private static final CacheResolver getDefaultCacheResolver(File root) {
return new DirectoryCacheResolver(new File(root, DEFAULT_CACHE_PATH));
}

public void loadVersionManager() {
if (getInstallConfig().isUseNodeVersionManager()) {
getVersionManagerRunner().populateCache();
}
}
}
Loading
Loading