From 0646c921c22160cd536d98c6f831f8d43e5ead0a Mon Sep 17 00:00:00 2001 From: xv2 <29576033+xv2@users.noreply.github.com> Date: Sun, 1 Sep 2019 17:37:12 +0300 Subject: [PATCH] Fixes offline mirror filename calculation for scoped packages URLs in Verdaccio (private npm repository) (#7499) * Fixes offline mirror filename calculation for scoped packages URLs in Verdaccio (private npm repository) * Fixed test * Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ __tests__/fetchers.js | 19 +++++++++++++++++++ src/fetchers/tarball-fetcher.js | 2 +- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf5b2d07f5..a3649cf249 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa ## Master +- Fixes the offline mirror filenames when using Verdaccio + + [#7499](https://github.com/yarnpkg/yarn/pull/7499) - [**xv2**](https://github.com/xv2) + - Update fixture certificates to prevent false negatives during testing [#7457](https://github.com/yarnpkg/yarn/pull/7457) - [**Thomas Jouannic**](https://github.com/eilgin) diff --git a/__tests__/fetchers.js b/__tests__/fetchers.js index 55d171b3f0..5c95c6af7f 100644 --- a/__tests__/fetchers.js +++ b/__tests__/fetchers.js @@ -312,6 +312,25 @@ test('TarballFetcher.fetch properly stores tarball of scoped package in offline expect(exists).toBe(true); }); +test('TarballFetcher.fetch properly stores tarball of scoped package in offline mirror for Verdaccio', async () => { + const dir = await mkdir('git-fetcher'); + const config = await Config.create(); + config.registries.yarn.config['yarn-offline-mirror'] = 'test'; + + const fetcher = new TarballFetcher( + dir, + { + type: 'tarball', + hash: '6f0ab73cdd7b82d8e81e80838b49e9e4c7fbcc44', + reference: 'http://npm.xxxyyyzzz.ru/@types%2fevents/-/events-3.0.0.tgz', + registry: 'npm', + }, + config, + ); + const cachePath = fetcher.getTarballMirrorPath(); + expect(cachePath).toBe(path.join('test', '@types-events-3.0.0.tgz')); +}); + test('TarballFetcher.fetch properly stores tarball for scoped package resolved from artifactory registry', async () => { const dir = await mkdir('tarball-fetcher'); const offlineMirrorDir = await mkdir('offline-mirror'); diff --git a/src/fetchers/tarball-fetcher.js b/src/fetchers/tarball-fetcher.js index b3d76c8bba..4f65dad7db 100644 --- a/src/fetchers/tarball-fetcher.js +++ b/src/fetchers/tarball-fetcher.js @@ -18,7 +18,7 @@ const gunzip = require('gunzip-maybe'); const invariant = require('invariant'); const ssri = require('ssri'); -const RE_URL_NAME_MATCH = /\/(?:(@[^/]+)\/)?[^/]+\/(?:-|_attachments)\/(?:@[^/]+\/)?([^/]+)$/; +const RE_URL_NAME_MATCH = /\/(?:(@[^/]+)(?:\/|%2f))?[^/]+\/(?:-|_attachments)\/(?:@[^/]+\/)?([^/]+)$/; const isHashAlgorithmSupported = name => { const cachedResult = isHashAlgorithmSupported.__cache[name];