Skip to content

Fallbacks to npm when COREPACK_NPM_REGISTRY is set - #339

Merged
aduh95 merged 1 commit into
mainfrom
mael/yarn-custom-npm-server
Dec 29, 2023
Merged

Fallbacks to npm when COREPACK_NPM_REGISTRY is set#339
aduh95 merged 1 commit into
mainfrom
mael/yarn-custom-npm-server

Conversation

@arcanis

Copy link
Copy Markdown
Contributor

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

@aduh95aduh95 left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
ContributorAuthor

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 mainDec 29, 2023
@aduh95
aduh95 deleted the mael/yarn-custom-npm-server branch December 29, 2023 11:28
@github-actionsgithub-actionsBot mentioned this pull request Dec 29, 2023
@aduh95aduh95 mentioned this pull request Feb 12, 2024
@PayBas

PayBas commented Feb 17, 2024

Copy link
Copy Markdown

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
Copy Markdown
Contributor

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

Sign up for freeto 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

@arcanis@PayBas@plumpNation@aduh95