Rewrite GitHub NPM plugin names to full GitHub tarball links

This allows those plugins to be installed from GitHub even without
having Git installed.
cshd
Dragory 2020-11-22 12:32:53 +02:00
parent 623ec15d13
commit 37cba80ed9
No known key found for this signature in database
GPG Key ID: 5F387BA66DF8AAC1
1 changed files with 15 additions and 1 deletions

View File

@ -16,11 +16,25 @@ const pluginSources = {
return new Promise((resolve, reject) => {
console.log(`Installing ${plugins.length} plugins from NPM...`);
// Rewrite GitHub npm package names to full GitHub tarball links to avoid
// needing to have Git installed to install these plugins.
// $1 package author, $2 package name, $3 branch (optional)
const npmGitHubPattern = /^([a-z0-9_.-]+)\/([a-z0-9_.-]+)(?:#([a-z0-9_.-]+))?$/i;
const rewrittenPluginNames = plugins.map(pluginName => {
const gitHubPackageParts = pluginName.match(npmGitHubPattern);
if (! gitHubPackageParts) {
return pluginName;
}
return `https://api.github.com/repos/${gitHubPackageParts[1]}/${gitHubPackageParts[2]}/tarball${gitHubPackageParts[3] ? "/" + gitHubPackageParts[3] : ""}`;
});
let stderr = "";
const npmProcessName = /^win/.test(process.platform) ? "npm.cmd" : "npm";
const npmProcess = childProcess.spawn(
npmProcessName,
["install", "--verbose", "--no-save", ...plugins],
["install", "--verbose", "--no-save", ...rewrittenPluginNames],
{ cwd: process.cwd() }
);
npmProcess.stderr.on("data", data => { stderr += String(data) });