Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return async tagFormat => {
// Generate a regex to parse tags formatted with `tagFormat`
// by replacing the `version` variable in the template by `(.+)`.
// The `tagFormat` is compiled with space as the `version` as it's an invalid tag character,
// so it's guaranteed to no be present in the `tagFormat`.
const tagRegexp = escapeRegExp(template(tagFormat)({ version: " " })).replace(" ", "(.+)");
const tags = (await git.tags())
.map(tag => {
return { gitTag: tag, version: (tag.match(tagRegexp) || new Array(2))[1] };
})
.filter(tag => tag.version && semver.valid(semver.clean(tag.version)))
.sort((a, b) => semver.rcompare(a.version, b.version));
if (tags.length > 0) {
const { gitTag, version } = await pLocate(tags, tag => git.isRefInHistory(tag.gitTag), {
concurrency: 1,
preserveOrder: true
});
logger.log("Found git tag %s associated with version %s", gitTag, version);
return { gitHead: await git.tagHead(gitTag), gitTag, version };
}
logger.log("No git tag version found");
return {};
};
};
await ky
.get(`${JSDELIVR}${pathname}/${srcPath}`)
.then(() => {
res.send(`${JSDELIVR}${pathname}/${srcPath}`, 301);
})
.catch(() => {
res.send(
`Not found source path given in the "${field}" of package.json`,
404,
);
});
return;
}
}
const result = await pLocate(
['src/index.ts', 'src/index.js', 'index.ts', 'index.js'].map((fp) =>
ky
.get(`${JSDELIVR}${pathname}/${fp}`)
.then(async (x) => ({ file: fp, value: await x.text() }))
.catch(() => {}),
),
(val) => {
if (typeof val === 'undefined') {
return false;
}
return true;
},
);
if (result) {
console.log('found', `${JSDELIVR}${pathname}/${result.file}`);