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

Fallbacks to npm when COREPACK_NPM_REGISTRY is set #339

Merged
merged 1 commit into from
Dec 29, 2023

Conversation

arcanis
Copy link
Contributor

@arcanis arcanis commented Dec 11, 2023

It's been mentioned a couple of times that Yarn publishing its versions on its own was inconvenient for people using private npm mirrors. I'd prefer to keep using our store by default, but it makes sense to offer a way to fallback to the npm store when requested. This diff changes the logic so that we use the @yarnpkg/cli-dist package when the COREPACK_NPM_REGISTRY variable is set. It should be backward-compatible, since the registry field is still the same.

Fixes #337

Copy link
Contributor

@aduh95 aduh95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that means that corepack use yarn@latest will now work, but only when COREPACK_NPM_REGISTRY is set 😅

@arcanis
Copy link
Contributor Author

arcanis commented Dec 11, 2023

I'm starting to desentangle that in #340, although I'll also need to tweak @yarnpkg/cli-dist so that its tags match the ones from /repo (latest currently points to canary on our npm releases, whereas we'd want them to point to stable instead).

@aduh95 aduh95 merged commit 0717c6a into main Dec 29, 2023
7 checks passed
@aduh95 aduh95 deleted the mael/yarn-custom-npm-server branch December 29, 2023 11:28
@PayBas
Copy link

PayBas commented Feb 17, 2024

I feel like I'm missing something here:

USER root

...

ARG NODEJS_VERSION='18.19.0'
ENV PATH "/opt/node/bin:$PATH"
RUN  mkdir -p /opt/node \
  && tar -xzf /installers/node-v${NODEJS_VERSION}-linux-x64.tar.gz --directory=/opt/node --strip-components=1 --no-same-owner

USER jenkins

# Configure npm & install+configure Yarn.
ARG YARN_VERSION='4.1.0'
ARG NPM_REGISTRY_URL='https://nexus.corp.internal/repository/npmjs-proxy/'
ENV COREPACK_NPM_REGISTRY $NPM_REGISTRY_URL
ENV NPM_CONFIG_PREFIX ${HOME}/.npm-global
ENV PATH ${NPM_CONFIG_PREFIX}/bin:$PATH
RUN  npm config set registry $NPM_REGISTRY_URL \
  # Node 18.19.0 ships with corepack 0.22.0, but we need corepack 0.24.0+
  && npm install --global corepack@latest \
  && corepack enable \
  && corepack --version \
  && corepack install --global yarn@${YARN_VERSION} \
  && yarn config set --home npmRegistryServer $NPM_REGISTRY_URL

Results in:

0.24.1
Installing yarn@4.1.0...
Internal Error: Error when performing the request to https://repo.yarnpkg.com/4.1.0/packages/yarnpkg-cli/bin/yarn.js; for troubleshooting help, see https://github.com/nodejs/corepack#troubleshooting
    at ClientRequest.<anonymous> (/home/jenkins/.npm-global/lib/node_modules/corepack/dist/lib/corepack.cjs:42208:16)
    at ClientRequest.emit (node:events:517:28)
    at TLSSocket.socketErrorListener (node:_http_client:501:9)
    at TLSSocket.emit (node:events:517:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

@arcanis I'm not sure why corepack is still trying to connect to repo.yarnpkg.com instead of respecting the COREPACK_NPM_REGISTRY.
This is a corporate machine with no direct internet access ;).

@plumpNation
Copy link
Contributor

@PayBas did you ever find out why this was happening?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature request: use default npm registry for Yarn
4 participants