From 159313193103ba27f8c5fed5915e0a88552e617e Mon Sep 17 00:00:00 2001 From: Lennart Date: Fri, 5 Jul 2024 10:20:42 +0200 Subject: [PATCH] feat: Support for yarn berry (#99) --- .changeset/cool-actors-visit.md | 5 +++++ .github/workflows/integration-testing.yml | 11 +++++++++-- src/verdaccio/install-packages.ts | 13 +++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 .changeset/cool-actors-visit.md diff --git a/.changeset/cool-actors-visit.md b/.changeset/cool-actors-visit.md new file mode 100644 index 0000000..4faea9f --- /dev/null +++ b/.changeset/cool-actors-visit.md @@ -0,0 +1,5 @@ +--- +"secco": minor +--- + +Support Yarn Berry (currently v3 & v4) by modyfing the .yarnrc.yml file inside the destination before trying to install packages from the local Verdaccio registry diff --git a/.github/workflows/integration-testing.yml b/.github/workflows/integration-testing.yml index bebb5bf..6b348fa 100644 --- a/.github/workflows/integration-testing.yml +++ b/.github/workflows/integration-testing.yml @@ -9,20 +9,27 @@ jobs: matrix: pm: - name: npm + displayName: npm version: 10.8.1 - name: pnpm + displayName: pnpm version: 9.4.0 - name: yarn + displayName: yarn (classic) version: 1.22.22 + - name: yarn + displayName: yarn (berry) + version: 4.3.1 - name: bun + displayName: bun version: 1.1.17 - name: ${{ matrix.pm.name }} + name: ${{ matrix.pm.displayName }} steps: - name: Checkout uses: actions/checkout@v4 - name: Install dependencies uses: ./.github/actions/pnpm-install - - name: Install Bun + - name: Install Bun (optional) uses: oven-sh/setup-bun@v2 if: ${{ matrix.pm.name == 'bun' }} - uses: actions/download-artifact@v4 diff --git a/src/verdaccio/install-packages.ts b/src/verdaccio/install-packages.ts index d53444b..2b523a0 100644 --- a/src/verdaccio/install-packages.ts +++ b/src/verdaccio/install-packages.ts @@ -1,4 +1,5 @@ import process from 'node:process' +import { execa } from 'execa' import { detectPackageManager } from 'nypm' import { logger } from '../utils/logger' import type { PromisifiedSpawnArgs } from '../utils/promisified-spawn' @@ -31,13 +32,13 @@ If you have control over the destination, manually add the "packageManager" key let externalRegistry = false let env: NodeJS.ProcessEnv = {} - // The combination of name and majorVersion allows us to detect yarn 3 - if (name === 'yarn' && majorVersion === '3') + // Yarn Berry + if (name === 'yarn' && (majorVersion === '3' || majorVersion === '4')) { externalRegistry = true - // TODO(feature): Handle externalRegistry case by detecting yarn 2/3 and modify yarn config - // We need to set programatically: - // yarn config set npmRegistryServer http://localhost:4873 - // unsafeHttpWhitelist:\n - "localhost" + + await execa`yarn config set npmRegistryServer ${REGISTRY_URL}` + await execa`yarn config set unsafeHttpWhitelist --json ["localhost"]` + } if (name === 'bun') { externalRegistry = true