Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I upload nodejs and npm executables to artifactory

We have a company proxy that prevents me from using the maven-frontend-plugin as it is.

The problem is that to fetch npm and bower dependencies we use an internal Artifactory so we should not have any proxy settings for that. But the actual executables are fetched directly thus to fetch them we need the proxy. And the frontend-plugin doesn't seem to support exceptions for specific domains.

So is there an easy way to upload npm and nodejs executables to our internal artifactory so that we can skip the proxy altogether? Or another way of solving this?

Edit

I add the solution here for ease since I needed to modify the answer I approved below.

Set up two remote repositories in Artifactory, one to nodejs (https://nodejs.org/dist/) and one to npm (https://registry.npmjs.org/npm/-/).

The edit your maven-frontend-plugin configuration:

<execution>
    <!-- optional: you don't really need execution ids,
    but it looks nice in your build log. -->
    <id>install node and npm</id>
    <goals>
        <goal>install-node-and-npm</goal>
    </goals>
    <!-- optional: default phase is "generate-resources" -->
    <phase>generate-resources</phase>
    <configuration>
        <nodeVersion>v0.12.1</nodeVersion>
        <npmVersion>2.14.1</npmVersion>
        <!-- use the URL for the repository you created in step 1 -->
        <nodeDownloadRoot>https://artifactory.my company.com/artifactory/nodejs.dist/</nodeDownloadRoot>
        <npmDownloadRoot>https://artifactory.my company.com/artifactory/npm.dist/</npmDownloadRoot>
    </configuration>
</execution>

It was possible to only use only the nodejs repo (but then npm is available only to version 1.4.9) Change npmDownloadRoot to:

<npmDownloadRoot>https://artifactory.my company.com/artifactory/nodejs.dist/npm/</npmDownloadRoot>

And don't forget to remove the proxy settings from your maven settings.xml

like image 843
osundblad Avatar asked Aug 28 '15 13:08

osundblad


1 Answers

To install the node and npm executables from Artifactory you should:

  1. Create a new repository in Artifactory which will be used for the node and npm distributions. If you are using Artifactory 4.x, you should create a remotegeneric repository (for older versions just create a remote repository).
    This repository should proxy the node and npm distribution server - https://nodejs.org/dist/
    Another option is creating a local repository and manually deploying the node and npm distribution into it while keeping the same layout as https://nodejs.org/dist/
  2. Configure the frontend-maven-plugin to use Artifactory instead of the default. This should be done by setting the downloadRoot property, for example:
<execution>
    <!-- optional: you don't really need execution ids,
    but it looks nice in your build log. -->
    <id>install node and npm</id>
    <goals>
        <goal>install-node-and-npm</goal>
    </goals>
    <!-- optional: default phase is "generate-resources" -->
    <phase>generate-resources</phase>
    <configuration>
        <nodeVersion>v0.10.18</nodeVersion>
        <npmVersion>1.3.8</npmVersion>
        <!-- use the URL for the repository you created in step 1 -->
        <downloadRoot>http://localhost:8081/artifactory/repo-id/</downloadRoot>
    </configuration>
</execution>

For more info see installing node and npm in the plugin documentation

like image 107
Dror Bereznitsky Avatar answered Nov 14 '22 22:11

Dror Bereznitsky