Skip to content

Commit

Permalink
Merge branch 'master' into issue/master/DCA11Y-1145-node-version-mana…
Browse files Browse the repository at this point in the history
…ger-support

# Conflicts:
#	FORK_CHANGELOG.md
#	README.md
#	frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallNodeAndNpmMojo.java
#	frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallNodeAndPnpmMojo.java
#	frontend-maven-plugin/src/main/java/com/github/eirslett/maven/plugins/frontend/mojo/InstallNodeAndYarnMojo.java
  • Loading branch information
flipatlas committed Sep 30, 2024
2 parents 09c3b61 + 3a101cc commit d65fdf0
Show file tree
Hide file tree
Showing 40 changed files with 1,230 additions and 111 deletions.
6 changes: 5 additions & 1 deletion FORK_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
### Added

- [DCA11Y-1145]: Added support for node version managers (fnm, mise, asdf, nvm, nvs) to install node and run npm tasks. Use of version manager is enabled by default and can be controlled with `useNodeVersionManager` configuration property.
- [DCA11Y-1145]: Automatic version detection of the Node version from `.tool-versions`, `.node-version`, and `.nvmrc` files
- [DCA11Y-1145]: The configuration property `nodeVersionFile` to specify a file that can be read in `install-node-and-npm`, `install-node-and-pnpm`, and `install-node-and-yarn`


### Changed

- [DCA11Y-1145]: `nodeVersion` property is not required any more, if `useNodeVersionManager` is not set to false.
- [DCA11Y-1145]: `nodeVersion` property is not required any more, if `useNodeVersionManager` is not set to false
- [DCA11Y-1145]: Now tolerant of `v` missing or present at the start of a Node version.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,30 @@ Only Atlassians may release a new version, [follow this guide](https://hello.atl

## Usage guidance

### Using Node Version Manager

By default, node based goals will try to use one of supported node version managers (`fnm`, `mise`, `asdf`, `nvm`, `nvs`) to install node and to find npm. You can disable node version manager usage with `useNodeVersionManager` configuration property.

If you're using `fnm`, make sure to have `--version-file-strategy=recursive` enabled in your shell profile file so that fnm can find node version files in higher levels of the project.

### Format of the Node version

It shouldn't matter if the `v` prefix is present, e.g. `14.8.0` and `v14.8.0`.

Old, non-standard, and codename versions are also supported if they're [available](https://nodejs.org/dist), e.g. `latest-v12.x`.

### Using Node version files

The plugin should automatically detect the version from files like: `.node-version`, `.nvmrc`, and `.tool-versions`. Comments in the files should be ignored. If the file is not in the working directory, nor any of the parent directories, it can be manually set in the configuration like so:

```xml
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<configuration>
<nodeVersionFile>${project.basedir}/dotfiles/.nvmrc</nodeVersionFile>
</configuration>
</plugin>
```

[![Cheers from Atlassian](https://raw.githubusercontent.com/atlassian-internal/oss-assets/master/banner-cheers-light.png)](https://www.atlassian.com)
4 changes: 4 additions & 0 deletions frontend-maven-plugin/.nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# comment

v22.5.1 ! comment
// comment
16 changes: 7 additions & 9 deletions frontend-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<dependency>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-plugin-core</artifactId>
<version>${project.parent.version}</version>
<scope>compile</scope>
</dependency>

<dependency>
Expand Down Expand Up @@ -79,14 +79,6 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
</plugin>
</plugins>
</build>

Expand Down Expand Up @@ -144,6 +136,12 @@
<goal>run</goal>
<goal>verify</goal>
</goals>
<configuration>
<environmentVariables>
<MISE_CONFIG_DIR>TESTDIR</MISE_CONFIG_DIR>
<MISE_ENV>TESTPROFILE</MISE_ENV>
</environmentVariables>
</configuration>
</execution>
</executions>
</plugin>
Expand Down
10 changes: 10 additions & 0 deletions frontend-maven-plugin/src/it/mise-config-file/.mise.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tools]
java = "temurin-21"
maven = "3.9"
pre-commit = "latest"
ktlint = "latest"
python = "3.12"
# node 22.5.1
node = "22.5.1"
# node 22.5.1
yarn = "1.22.22"
12 changes: 12 additions & 0 deletions frontend-maven-plugin/src/it/mise-config-file/package-lock.json

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

4 changes: 4 additions & 0 deletions frontend-maven-plugin/src/it/mise-config-file/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "example",
"version": "0.0.1"
}
34 changes: 34 additions & 0 deletions frontend-maven-plugin/src/it/mise-config-file/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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>
<installDirectory>target</installDirectory>
</configuration>

<executions>

<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
5 changes: 5 additions & 0 deletions frontend-maven-plugin/src/it/mise-config-file/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
assert new File(basedir, 'target/node').exists() : "Node was not installed in the custom install directory";

String buildLog = new File(basedir, 'build.log').text
assert buildLog.contains('.mise.toml') : 'The wrong file was used'
assert buildLog.contains('Installing node version v22.5.1') : 'The correct node version was not detected'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[tools]
java = "temurin-21"
maven = "3.9"
pre-commit = "latest"
ktlint = "latest"
python = "3.12"
# node 22.5.1
node = "22.5.1"
# node 22.5.1
yarn = "1.22.22"

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,4 @@
{
"name": "example",
"version": "0.0.1"
}
34 changes: 34 additions & 0 deletions frontend-maven-plugin/src/it/mise-env-config-file/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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>
<installDirectory>target</installDirectory>
</configuration>

<executions>

<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
assert new File(basedir, 'target/node').exists() : "Node was not installed in the custom install directory";

String buildLog = new File(basedir, 'build.log').text
assert buildLog.contains(['TESTDIR','mise.TESTPROFILE.toml'].join(File.separator)) : 'The wrong file was used'
assert buildLog.contains('Installing node version v22.5.1') : 'The correct node version was not detected'

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,4 @@
{
"name": "example",
"version": "0.0.1"
}
34 changes: 34 additions & 0 deletions frontend-maven-plugin/src/it/nested-project-nvmrc-file/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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>
<installDirectory>target</installDirectory>
</configuration>

<executions>

<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
assert new File(basedir, 'target/node').exists() : "Node was not installed in the custom install directory";

String buildLog = new File(basedir, 'build.log').text
assert buildLog.contains(['frontend-maven-plugin','.nvmrc'].join(File.separator)) : 'The wrong file was used'
assert buildLog.contains('Installing node version v22.5.1') : 'The correct node version was not detected'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v22.5.1

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,4 @@
{
"name": "example",
"version": "0.0.1"
}
35 changes: 35 additions & 0 deletions frontend-maven-plugin/src/it/specified-node-version-file/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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>
<nodeVersionFile>${project.basedir}/dotfiles/.nvmrc</nodeVersionFile>
<installDirectory>target</installDirectory>
</configuration>

<executions>

<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
assert new File(basedir, 'target/node').exists() : "Node was not installed in the custom install directory";

String buildLog = new File(basedir, 'build.log').text
assert buildLog.contains(['specified-node-version-file', 'dotfiles', '.nvmrc'].join(File.separator)) : 'The wrong file was used'
assert buildLog.contains('Installing node version v22.5.1') : 'The correct node version was not detected'
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node v22.5.1
12 changes: 12 additions & 0 deletions frontend-maven-plugin/src/it/tool-versions-file/package-lock.json

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

4 changes: 4 additions & 0 deletions frontend-maven-plugin/src/it/tool-versions-file/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "example",
"version": "0.0.1"
}
Loading

0 comments on commit d65fdf0

Please sign in to comment.