From 37cba80ed9d469e767ba4f2f0923190fc56b5ff0 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Sun, 22 Nov 2020 12:32:53 +0200 Subject: [PATCH] Rewrite GitHub NPM plugin names to full GitHub tarball links This allows those plugins to be installed from GitHub even without having Git installed. --- src/plugins.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/plugins.js b/src/plugins.js index b09392e..aca0a98 100644 --- a/src/plugins.js +++ b/src/plugins.js @@ -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) });