如何将 nodejs 和 npm 可执行文件上传到 artifactory

How can I upload nodejs and npm executables to artifactory

我们有一个公司代理阻止我按原样使用 maven-frontend-plugin。

问题是我们使用内部 Artifactory 来获取 npm 和 bower 依赖项,因此我们不应该为此设置任何代理。但是实际的可执行文件是直接获取的,因此要获取它们,我们需要代理。而且前端插件似乎不支持特定域的异常。

那么有没有一种简单的方法可以将 npm 和 nodejs 可执行文件上传到我们的内部工件,以便我们可以完全跳过代理?或者其他解决方法?

编辑

我在这里添加解决方案是为了方便,因为我需要修改我在下面批准的答案。

在 Artifactory 中设置两个远程存储库,一个到 nodejs (https://nodejs.org/dist/),一个到 npm (https://registry.npmjs.org/npm/-/)。

编辑您的 maven-frontend-plugin 配置:

<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>

可以只使用 nodejs 存储库(但 npm 仅适用于版本 1.4.9)将 npmDownloadRoot 更改为:

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

并且不要忘记从您的 maven 中删除代理设置 settings.xml

使用 Artifactory 代理 npm 注册表并托管您自己的 npm 和可执行文件是一个不错的决定,您的管理员做得很好。

要从 UI 将任何文件部署到 Artifactory,您可以使用“部署”选项卡 (Artifactory 3) 或 Artifact 浏览器 (Artifactory 4) 中的“部署”按钮。

另一个选项(可能更可取)将使用 npm publishUser Guide 提供了有关如何执行此操作的非常详细的说明。如果您使用的是 Artifactory 4,您还可以单击 Artifact Browser 屏幕中的 Set Me Up 按钮:

适用于任何文件的第三个选项是 a simple PUT HTTP request

要从 Artifactory 安装节点和 npm 可执行文件,您应该:

  1. 在 Artifactory 中创建一个新的存储库,它将用于节点和 npm 分发。如果您使用的是 Artifactory 4.x,您应该创建一个远程 generic repository (for older versions just create a remote repository).
    This repository should proxy the node and npm distribution server - https://nodejs.org/dist/
    另一种选择是创建本地存储库并手动将节点和 npm 分发部署到其中,同时保持与 https://nodejs.org/dist/
  2. 相同的布局
  3. 将 frontend-maven-plugin 配置为使用 Artifactory 而不是默认值。这应该通过设置 downloadRoot 属性 来完成,例如:
<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>

有关详细信息,请参阅插件文档中的 installing node and npm