Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] no way to npm publish a tarball whose package.json includes publishConfig.registry to a private registry #6400

Closed
2 tasks done
thw0rted opened this issue Apr 25, 2023 · 5 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 9.x work is associated with a specific npm 9 release

Comments

@thw0rted
Copy link

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

You can download the original TGZ format of a package using npm pack some-package. You can then re-publish this to a different registry using npm publish some-package*.tgz --registry=https://path/to/my/registry.

This works great for almost every public package, but there are a few that specify a registry with publishConfig.registry in their package.json. The problem is that npm publish peeks inside the tarball it's publishing to compute the final config used before uploading. I found this ancient, unresolved issue -- auto-closed while tagged "patch-welcome" -- about allowing the --registry command line option to overrule publishConfig.registry. As far as I can tell, nothing was ever done about it, so there seems to be no way to override this value without editing the TGZ, but that will change its integrity.

Expected Behavior

It should be possible to publish a TGZ package to any registry using some version of npm publish. The simplest solution is probably to fix precedence for --registry but any other workaround would also be acceptable.

Steps To Reproduce

  1. npm pack yargs, then npm publish yargs*.tgz --registry=https://path/to/my/other/registry
  2. npm pack zone.js, then npm publish zone.js*.tgz --registry=https://path/to/my/other/registry

The first commands should succeed while the second one fails with the error

npm ERR! code ENEEDAUTH
npm ERR! need auth This command requires you to be logged in to https://wombat-dressing-room.appspot.com
npm ERR! need auth You need to authorize this machine using `npm adduser`

due to the custom registry here.

Environment

  • npm: 9.6.2
  • Node.js: 18.16.0
  • OS Name: Windows 11
@thw0rted thw0rted added Bug thing that needs fixing Needs Triage needs review for next steps Release 9.x work is associated with a specific npm 9 release labels Apr 25, 2023
@ilichigor
Copy link

Maybe someone will come in handy, here is an example for npm 8.19.3.
You need to edit the publish.js file from the /usr/lib/node_modules/npm/lib/commands directory using any editor. Find the getManifest function and comment out the if (manifest.publishConfig) condition. Sample code for this action:

  async getManifest (spec, opts) {
    let manifest
    if (spec.type === 'directory') {
      manifest = await readJson(`${spec.fetchSpec}/package.json`)
    } else {
      manifest = await pacote.manifest(spec, {
        ...opts,
        fullmetadata: true,
        fullReadJson: true,
      })
    }
    //if (manifest.publishConfig) {
    //  flatten(manifest.publishConfig, opts)
    //}
    return manifest
  }

@GideonMax
Copy link

We have ran into this problem as well, as we need to publish packages to a private repo, and for some reason some packages have publishConfig.registry point to npm.
We have a workaround for it but it's time consuming and there is no reason why this bug should exist.
From a brief overview of the code, this can probably be fixed with a single line of code.
I might make a pr soon if this isn't fixed.

@EshginGuluzade
Copy link

@GideonMax, just wondering what was your workaround for this issue? of course, if your workaround doesn't involve editing *.tgz files)

@roni-berlin
Copy link
Contributor

@thw0rted I've opened this PR for this issue
#7306

wraithgar pushed a commit that referenced this issue Apr 9, 2024
This PR addresses an issue where CLI flags were not taking precedence
over publishConfig settings. To ensure CLI flags have higher priority,
properties from the publishConfig object that also exist in CLI flags
are filtered out.


  Related to #6400
@wraithgar
Copy link
Member

Fixed by #7321

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 9.x work is associated with a specific npm 9 release
Projects
None yet
Development

No branches or pull requests

6 participants