Search code examples
npmazure-artifacts

Publishing npm packages offline


I'm running TFS 2018 on-premise, which is offline and has no access to nuget.org. One of our struggles was to coordinate open-sourced npm packages between the dev team. With TFS 201 I can now setup an npm feed in Package Management, which may be a solution. The idea is to get all the npm packages in the feed.

What I've done so far is to retrieve these packages (using npm install) on an internet facing box, then transfer them to the offline box (copying over the entire npm-cache folder). Then I would iterate over all the npm packages and run npm publish to my TFS registry.

For most packages, this works well. There are a number of packages with prepublish scripts or likewise that error out. I can still get them in the registry with --force (npm publish -f). However, I'm not sure this is truly working as I'm unable to install some of these. I get an ENOENT errno -4058. One example is the acorn repo.

I'm wondering if there is a better way to go about this? Possibly there is a bulk upload option for these packages.


Solution

  • Answering my own question here as the only other proposed answer did not address the idea to get the packages into the TFS Packages feed and remain offline.

    Publishing npm tarballs (.tgz) to the TFS npm package repository worked without fail. Whereas before, I was trying to publish using the package I had in my cache. I found a particular npm package (npm-package-downloader) which allowed me to download the necessary npm packages and their dependencies. I then transferred these tarballs to the offline tfs box and published them using npm publish <package>.

    The full workflow was:

    1. (Internet accessible box) npm install -global npm-package-downloader
    2. (Internet accessible box) npmDownload -d -e -a -o "<path>" -p "pkg1 pkg2 etc"
    3. (Internet accessible box) Zip from #2 (even though there is a zip option for npmDownload, this always broke)
    4. (Internet accessible box) Transfer zip to offline box
    5. (Offline box) Unzip files
    6. (Offline box) npm set registry <tfs registry>
    7. (Offline box) For each .tgz npm publish <pkg.tgz>. Note, I used powershell to do this for me.