feat: install git-hosted dep through the repo URL

close #2627
PR #2670
This commit is contained in:
Zoltan Kochan
2020-07-07 10:49:58 +03:00
committed by GitHub
parent d9310c034c
commit 83b146d633
4 changed files with 39 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
---
"@pnpm/tarball-resolver": patch
---
Ignore URLs to repositories.

View File

@@ -26,6 +26,16 @@ test('from a github repo', async (t: tape.Test) => {
t.deepEqual(manifest.dependencies, { 'is-negative': 'github:kevva/is-negative' }, 'has been added to dependencies in package.json')
})
test('from a github repo through URL', async (t: tape.Test) => {
const project = prepareEmpty(t)
const manifest = await addDependenciesToPackage({}, ['https://github.com/kevva/is-negative'], await testDefaults())
await project.has('is-negative')
t.deepEqual(manifest.dependencies, { 'is-negative': 'github:kevva/is-negative' }, 'has been added to dependencies in package.json')
})
test('from a github repo with different name via named installation', async (t: tape.Test) => {
const project = prepareEmpty(t)

View File

@@ -7,6 +7,8 @@ export default async function resolveTarball (
return null
}
if (isRepository(wantedDependency.pref)) return null
return {
id: `@${wantedDependency.pref.replace(/^.*:\/\/(git@)?/, '')}`,
normalizedPref: wantedDependency.pref,
@@ -16,3 +18,17 @@ export default async function resolveTarball (
resolvedVia: 'url',
}
}
const GIT_HOSTERS = new Set([
'github.com',
'gitlab.com',
'bitbucket.org',
])
function isRepository (pref: string) {
if (pref.endsWith('/')) {
pref = pref.substr(0, pref.length - 1)
}
const parts = pref.split('/')
return (parts.length === 5 && GIT_HOSTERS.has(parts[2]))
}

View File

@@ -46,3 +46,11 @@ test('tarballs from GitHub (is-negative)', async t => {
t.end()
})
test('ignore direct URLs to repositories', async t => {
t.equal(await resolveFromTarball({ pref: 'https://github.com/foo/bar' }), null)
t.equal(await resolveFromTarball({ pref: 'https://github.com/foo/bar/' }), null)
t.equal(await resolveFromTarball({ pref: 'https://gitlab.com/foo/bar' }), null)
t.equal(await resolveFromTarball({ pref: 'https://bitbucket.org/foo/bar' }), null)
t.end()
})