Skip to content

Commit

Permalink
DCA11Y-1145: Support standard Node version files (#3)
Browse files Browse the repository at this point in the history
* DCA11Y-1145: Support standard files

* DCA11Y-1145: Validate and fixup node versions

* DCA11Y-1145: Log where the version of Node was found

* DCA11Y-1145: Fix .tools-version filename

* DCA11Y-1145: Support node version file being specified

* DCA11Y-1145: Fix compiling node version file

* DCA11Y-1145: Fix name to 'tool versions' inline with the file

* DCA11Y-1145: Add .tool-versions IT

* DCA11Y-1145: Add support for comments on the main line of .nvmrc like files

* DCA11Y-1145: Add IT for .nvmrc files

* DCA11Y-1145: Fix nodeVersion being a readOnly property

* DCA11Y-1145: Add empty line UT

* DCA11Y-1145: Add specified version file IT

* DCA11Y-1145: Use the working directory

This is more likely to contain the files we're after as they're often colocated

* DCA11Y-1145: Update the CHANGELOG

* DCA11Y-1145: Update the README.md with usage guidance

* DCA11Y-1145: Work around test runner setup

* DCA11Y-1145: Fix unreadable version file exception message to include "not"

* DCA11Y-1145: Add support for mise config files

* DCA11Y-1145: Add future code name releases

* DCA11Y-1145: Comment reason for lowercasing the version

* DCA11Y-1145: Add handling of loosely-defined major versions

* DCA11Y-1145: normalize printed paths

---------

Co-authored-by: fnowakowski <[email protected]>
  • Loading branch information
atl-mk and flipatlas authored Sep 30, 2024
1 parent f877a50 commit 3a101cc
Show file tree
Hide file tree
Showing 39 changed files with 1,193 additions and 30 deletions.
12 changes: 11 additions & 1 deletion FORK_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

## [Unreleased]

[unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.1.1...HEAD
### Added

- [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]: Now tolerant of `v` missing or present at the start of a Node version

[DCA11Y-1145]: https://hello.jira.atlassian.cloud/browse/DCA11Y-1145
[unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/v1.15.0...HEAD
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,24 @@ Only Atlassians may release a new version, [follow this guide](https://hello.atl

## Usage guidance

### 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
6 changes: 6 additions & 0 deletions frontend-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,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"
}
34 changes: 34 additions & 0 deletions frontend-maven-plugin/src/it/tool-versions-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/tool-versions-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('.tool-versions') : 'The wrong file was used'
assert buildLog.contains('Installing node version v22.5.1') : 'The correct node version was not detected'
Loading

0 comments on commit 3a101cc

Please sign in to comment.