Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ Last public release: [![Maven Central](https://maven-badges.herokuapp.com/maven-

## Changelog

### 1.14.3

* if upgrading, first delete the full "node" dir ([#994](https://github.com/eirslett/frontend-maven-plugin/issues/994))

### 1.14.2

* Prevent corrupt downloaded files by waiting for the download to complete before writing the file to disk.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# first install v14
invoker.goals.1 = generate-resources -DnodeVersion=v14.21.3
# then upgrade to v18
invoker.goals.2 = generate-resources -DnodeVersion=v18.18.2

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": "node-provided-npm-upgrades",
"version": "0.0.1",
"dependencies": {
"classnames": "^2.3.2"
},
"scripts": {
"prebuild": "npm install"
}
}
48 changes: 48 additions & 0 deletions frontend-maven-plugin/src/it/node-provided-npm-upgrades/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?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.it</groupId>
<artifactId>node-provided-npm-upgrades</artifactId>
<version>0</version>
<packaging>pom</packaging>

<properties>
<!-- will be overwritten from command line via -DnodeVersion=... -->
<nodeVersion>v14.21.3</nodeVersion>
</properties>

<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<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>

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

import org.codehaus.plexus.util.FileUtils;

String buildLog = FileUtils.fileRead(new File(basedir, 'build.log'));

assert !buildLog.contains('TypeError: Class extends value undefined is not a constructor or null') : 'old npm version still seems to be used'
assert buildLog.contains('BUILD SUCCESS') : 'build was not successful'
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,32 @@ private void installNodeDefault() throws InstallationException {
} else {
File destinationDirectory = getInstallDirectory();

// We need to delete the previous node installation first, as it might contain packages
// from a previous installation, e.g. if npm is provided
this.logger.info("Deleting previous node installation in directory {}", destinationDirectory);
try {
File[] filelist = destinationDirectory.listFiles();
if (filelist == null) {
filelist = new File[0];
}
for (File child : filelist) {
if (child.isDirectory()) {
// skip temp directory...
if (!child.getAbsoluteFile().equals(tmpDirectory.getAbsoluteFile())) {
this.logger.debug("Deleting directory {}", child);
FileUtils.deleteDirectory(child);
}
} else {
this.logger.debug("Deleting file {}", child);
if (!child.delete()) {
this.logger.warn("Couldn't delete {}", child);
}
}
}
} catch (IOException e) {
this.logger.warn("Failed to delete previous node installation in directory {}", destinationDirectory, e);
}

File destination = new File(destinationDirectory, "node");
this.logger.info("Copying node binary from {} to {}", nodeBinary, destination);
if (destination.exists() && !destination.delete()) {
Expand All @@ -174,7 +200,7 @@ private void installNodeDefault() throws InstallationException {
Files.move(nodeBinary.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new InstallationException("Could not install Node: Was not allowed to rename "
+ nodeBinary + " to " + destination);
+ nodeBinary + " to " + destination, e);
}

if (!destination.setExecutable(true, false)) {
Expand All @@ -183,14 +209,16 @@ private void installNodeDefault() throws InstallationException {
}

if (npmProvided()) {
this.logger.info("Extracting NPM");
File tmpNodeModulesDir = new File(tmpDirectory,
longNodeFilename + File.separator + "lib" + File.separator + "node_modules");
File nodeModulesDirectory = new File(destinationDirectory, "node_modules");
File npmDirectory = new File(nodeModulesDirectory, "npm");
// Copy the provided npm from the new node installation
FileUtils.copyDirectory(tmpNodeModulesDir, nodeModulesDirectory);
this.logger.info("Extracting NPM");
// create a copy of the npm scripts next to the node executable
for (String script : Arrays.asList("npm", "npm.cmd")) {
// Make sure the npm scripts are executable
// the scripts will be copied next to the node executable by NPMInstaller.copyNpmScripts
File npmDirectory = new File(nodeModulesDirectory, "npm");
for (String script : Arrays.asList("npm", "npm.cmd", "npx", "npx.cmd")) {
File scriptFile = new File(npmDirectory, "bin" + File.separator + script);
if (scriptFile.exists()) {
scriptFile.setExecutable(true);
Expand Down