From eac179c6ce8d8064774d06f20e2c3f77d61b4f80 Mon Sep 17 00:00:00 2001 From: Ramiro Silveyra d'Avila Date: Fri, 19 May 2017 09:00:37 -0300 Subject: [PATCH] Fix support for private git repos when using shorted repo syntax and lock file exists (#3425) Force git remote type if the resolved url it's a git private url. --- __tests__/package-request.js | 50 ++++++++++++++++++++++++++++++++++++ src/package-request.js | 4 ++- 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 __tests__/package-request.js diff --git a/__tests__/package-request.js b/__tests__/package-request.js new file mode 100644 index 0000000000..6c000a9d8e --- /dev/null +++ b/__tests__/package-request.js @@ -0,0 +1,50 @@ +/* @flow */ + +import PackageRequest from '../src/package-request.js'; +import * as reporters from '../src/reporters/index.js'; +import PackageResolver from '../src/package-resolver.js'; +import Lockfile from '../src/lockfile/wrapper.js'; +import Config from '../src/config.js'; + +async function prepareRequest(pattern, version, resolved): Object { + const privateDepCache = {[pattern]: {version, resolved}}; + const lockfile = new Lockfile(privateDepCache); + const reporter = new reporters.NoopReporter({}); + const depRequestPattern = { + pattern, + registry: 'npm', + hint: null, + optional: false, + }; + const config = await Config.create({}, reporter); + const resolver = new PackageResolver(config, lockfile); + const request = new PackageRequest(depRequestPattern, resolver); + + return {request, reporter}; +} + +test('Produce valid remote type for a git private dep', async () => { + const {request, reporter} = await prepareRequest( + 'private-dep@github:yarnpkg/private-dep#1.0.0', + '1.0.0', + 'git+ssh://git@github.com/yarnpkg/private-dep.git#d6c57894210c52be02da7859dbb5205feb85d8b0' + ); + + expect(request.getLocked('git')._remote.type).toBe('git'); + expect(request.getLocked('tarball')._remote.type).toBe('git'); + + await reporter.close(); +}); + +test('Produce valid remote type for a git public dep', async () => { + const {request, reporter} = await prepareRequest( + 'public-dep@yarnpkg/public-dep#1fde368', + '1.0.0', + 'https://codeload.github.com/yarnpkg/public-dep/tar.gz/1fde368' + ); + + expect(request.getLocked('git')._remote.type).toBe('git'); + expect(request.getLocked('tarball')._remote.type).toBe('tarball'); + + await reporter.close(); +}); diff --git a/src/package-request.js b/src/package-request.js index 15984c5ecf..8a3fec64b3 100644 --- a/src/package-request.js +++ b/src/package-request.js @@ -75,6 +75,8 @@ export default class PackageRequest { if (shrunk && shrunk.resolved) { const resolvedParts = versionUtil.explodeHashedUrl(shrunk.resolved); + // If it's a private git url set remote to 'git'. + const preferredRemoteType = resolvedParts.url.startsWith('git+ssh://') ? 'git' : remoteType; return { name: shrunk.name, @@ -82,7 +84,7 @@ export default class PackageRequest { _uid: shrunk.uid, _remote: { resolved: shrunk.resolved, - type: remoteType, + type: preferredRemoteType, reference: resolvedParts.url, hash: resolvedParts.hash, registry: shrunk.registry,