Can a package be published to both github and npm? (with a single `npm publish`)
Asked Answered
I

0

14

I got access to the github package registry beta, just fiddled with it and followed the configuration steps to publish.

The thing is, I published it correctly, but noticed it didn't publish to npm. Is there a way to publish in both registries with the same command? Does it make sense to have the package published in both registries?


Also, my package name in the package.json is @alvarocastro/quicksort (as stated in the doc) and the name in the github page ends up being that, but in the command example to install, the scope is duplicated, eg: @alvarocastro/@alvarocastro/quicksort


Here is the complete package.json file as a reference:

{
  "name": "@alvarocastro/quicksort",
  "version": "1.0.1",
  "description": "An implementation of the quicksort algorithm",
  "main": "index.js",
  "scripts": {
    "performance": "node performance.js",
    "test": "xo && nyc ava",
    "coverage": "nyc report --reporter=text-lcov | coveralls"
  },
  "publishConfig": {
    "registry":"https://npm.pkg.github.com/@alvarocastro"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/alvarocastro/quicksort.git"
  },
  "keywords": [
    "quicksort",
    "sort",
    "algorithm"
  ],
  "author": "Alvaro Castro",
  "license": "MIT",
  "bugs": {
    "url": "https://github.com/alvarocastro/quicksort/issues"
  },
  "homepage": "https://github.com/alvarocastro/quicksort#readme",
  "devDependencies": {
    "ava": "2.3.0",
    "coveralls": "3.0.6",
    "nyc": "14.1.1",
    "xo": "0.24.0"
  }
}
Invocate answered 14/9, 2019 at 0:7 Comment(7)
I saw you're in the GitHub Actions beta: if you want to automate the whole thing you could create a workflow that checks for the version & then runs two commands to publish to both registries.Osuna
@FedericoGrandi but to change the registry I have to modify the publishConfig property in the package.json, you say I should make an action that does that? Also, I'm a total noob of github actions, will do a bit of research later.Invocate
For that you don't need to change package.json, since you can simply reset npm to use GPR as default registry: there's an example you can check in the "Usage" section of actions/setup-node, here. The part that will be more tricky is checking whether you pushed a new version: the easiest way would be to just run the thing when you create a new release, but that will force you to manually add a release every time you want to publish a new version...Osuna
There is another conflict: GitHub requires package name to be scoped whereas npm considers scoped name "private".Consolatory
@AlvaroCastro, did you solved this issue? If yes, can you post an answer? I am exactly in the same situation as you! Thanks!Alisonalissa
@PauloCoghi-ReinstateMonica, no, still didn't manage to solve this. I'm sticking with npm for the moment. Now that npm is part of github maybe they get more integrated in the future as a single registry and none of this is needed.Invocate
@AlvaroCastro, thanks for the update!Alisonalissa

© 2022 - 2024 — McMap. All rights reserved.