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

### Unreleased

* Explicitly inform the user to provide a corepack version when required

### 1.15.1

* Fix #1150: Update lifecycle-mapping-metadata.xml for npx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.apache.maven.settings.crypto.SettingsDecrypter;
import org.apache.maven.settings.Server;

import static com.github.eirslett.maven.plugins.frontend.lib.CorepackInstaller.BUNDLED_COREPACK_VERSION;

@Mojo(name="install-node-and-corepack", defaultPhase = LifecyclePhase.GENERATE_RESOURCES, threadSafe = true)
public final class InstallNodeAndCorepackMojo extends AbstractFrontendMojo {

Expand Down Expand Up @@ -43,7 +45,7 @@ public final class InstallNodeAndCorepackMojo extends AbstractFrontendMojo {
*
* If not provided, then the corepack version bundled with Node will be used.
*/
@Parameter(property = "corepackVersion", required = false, defaultValue = "provided")
@Parameter(property = "corepackVersion", required = false, defaultValue = BUNDLED_COREPACK_VERSION)
private String corepackVersion;

/**
Expand Down Expand Up @@ -79,7 +81,7 @@ public void execute(FrontendPluginFactory factory) throws InstallationException
NodeInstaller nodeInstaller = factory.getNodeInstaller(proxyConfig);
nodeInstaller.setNodeVersion(nodeVersion)
.setNodeDownloadRoot(resolvedNodeDownloadRoot);
if ("provided".equals(corepackVersion)) {
if (BUNDLED_COREPACK_VERSION.equals(corepackVersion)) {
// This causes the node installer to copy over the whole
// node_modules directory including the corepack module
nodeInstaller.setNpmVersion("provided");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

public class CorepackInstaller {

public static final String BUNDLED_COREPACK_VERSION = "provided";

private static final String VERSION = "version";

public static final String DEFAULT_COREPACK_DOWNLOAD_ROOT = "https://registry.npmjs.org/corepack/-/";
Expand All @@ -22,7 +24,7 @@ public class CorepackInstaller {
private String corepackVersion, corepackDownloadRoot, userName, password;

private Map<String, String> httpHeaders;

private final Logger logger;

private final InstallConfig config;
Expand Down Expand Up @@ -90,7 +92,7 @@ private boolean corepackIsAlreadyInstalled() {
final File corepackPackageJson = new File(
this.config.getInstallDirectory() + Utils.normalize("/node/node_modules/corepack/package.json"));
if (corepackPackageJson.exists()) {
if ("provided".equals(this.corepackVersion)) {
if (BUNDLED_COREPACK_VERSION.equals(this.corepackVersion)) {
// Since we don't know which version it should be, we must assume that we have
// correctly setup the packaged version
return true;
Expand Down Expand Up @@ -120,6 +122,10 @@ private boolean corepackIsAlreadyInstalled() {

private void installCorepack() throws InstallationException {
try {
if (BUNDLED_COREPACK_VERSION.equals(this.corepackVersion)) {
throw new InstallationException("The corepack version needs to be specified.");
}

this.logger.info("Installing corepack version {}", this.corepackVersion);
String corepackVersionClean = this.corepackVersion.replaceFirst("^v(?=[0-9]+)", "");
final String downloadUrl = this.corepackDownloadRoot + "corepack-" + corepackVersionClean + ".tgz";
Expand Down