Fixes git listing

This commit is contained in:
Maël Nison 2020-08-03 20:41:02 +02:00
parent 8c29576ca8
commit 6f37218ff3
2 changed files with 19 additions and 10 deletions

View File

@ -51,9 +51,9 @@
"url": "https://raw.githubusercontent.com/yarnpkg/berry/%40yarnpkg/cli/{}/packages/yarnpkg-cli/bin/yarn.js", "url": "https://raw.githubusercontent.com/yarnpkg/berry/%40yarnpkg/cli/{}/packages/yarnpkg-cli/bin/yarn.js",
"bin": ["yarn", "yarnpkg"], "bin": ["yarn", "yarnpkg"],
"tags": { "tags": {
"type": "github", "type": "git",
"repository": "yarnpkg/berry", "repository": "https://github.com/yarnpkg/berry.git",
"pattern": "@yarnpkg-cli/{}" "pattern": "@yarnpkg/cli/{}"
} }
} }
} }

View File

@ -15,7 +15,7 @@ import { Context } from './main';
const execFileP = promisify(execFile); const execFileP = promisify(execFile);
const NL_REGEXP = /\n/; const NL_REGEXP = /\n/;
const REFS_TAGS_REGEXP = /^refs\/tags\//; const REFS_TAGS_REGEXP = /^[a-f0-9]+\trefs\/tags\/(.*)\^\{\}$/;
export async function fetchAvailableVersions(spec: TagSpec) { export async function fetchAvailableVersions(spec: TagSpec) {
switch (spec.type) { switch (spec.type) {
@ -26,20 +26,29 @@ export async function fetchAvailableVersions(spec: TagSpec) {
case `git`: { case `git`: {
const {stdout} = await execFileP(`git`, [`ls-remote`, `--tags`, spec.repository]); const {stdout} = await execFileP(`git`, [`ls-remote`, `--tags`, spec.repository]);
const lines = stdout.split(NL_REGEXP).slice(0, -1).map(line => line.replace(REFS_TAGS_REGEXP, ``)); const lines = stdout.split(NL_REGEXP);
const regexp = new RegExp(spec.pattern); const regexp = new RegExp(`^${spec.pattern.replace(`{}`, `(.*)`)}$`);
const results = []; const results = [];
for (const line of lines) { for (const line of lines) {
const match = line.match(regexp); const lv1 = line.match(REFS_TAGS_REGEXP);
if (match) { if (!lv1)
results.push(match[1]); continue;
}
const lv2 = lv1[1].match(regexp);
if (!lv2)
continue;
results.push(lv2[1]);
} }
return results; return results;
} break; } break;
default: {
throw new Error(`Unsupported specification ${JSON.stringify(spec)}`);
} break;
} }
} }