From 83b146d633a6e45ce8727b5876036d0d0d9930f2 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Tue, 7 Jul 2020 10:49:58 +0300 Subject: [PATCH] feat: install git-hosted dep through the repo URL close #2627 PR #2670 --- .changeset/early-pumpkins-smoke.md | 5 +++++ packages/supi/test/install/fromRepo.ts | 10 ++++++++++ packages/tarball-resolver/src/index.ts | 16 ++++++++++++++++ packages/tarball-resolver/test/index.ts | 8 ++++++++ 4 files changed, 39 insertions(+) create mode 100644 .changeset/early-pumpkins-smoke.md diff --git a/.changeset/early-pumpkins-smoke.md b/.changeset/early-pumpkins-smoke.md new file mode 100644 index 0000000000..7c7e84d1f3 --- /dev/null +++ b/.changeset/early-pumpkins-smoke.md @@ -0,0 +1,5 @@ +--- +"@pnpm/tarball-resolver": patch +--- + +Ignore URLs to repositories. diff --git a/packages/supi/test/install/fromRepo.ts b/packages/supi/test/install/fromRepo.ts index 677dac266c..cd3c2ceb00 100644 --- a/packages/supi/test/install/fromRepo.ts +++ b/packages/supi/test/install/fromRepo.ts @@ -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) diff --git a/packages/tarball-resolver/src/index.ts b/packages/tarball-resolver/src/index.ts index e5ed510767..b7efaadfff 100644 --- a/packages/tarball-resolver/src/index.ts +++ b/packages/tarball-resolver/src/index.ts @@ -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])) +} diff --git a/packages/tarball-resolver/test/index.ts b/packages/tarball-resolver/test/index.ts index c0eab25aaf..36445b9519 100644 --- a/packages/tarball-resolver/test/index.ts +++ b/packages/tarball-resolver/test/index.ts @@ -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() +})