@evilmartians/lefthook-installer
Advanced tools
Comparing version 1.6.21 to 1.6.22
@@ -1,2 +0,5 @@ | ||
const { spawnSync } = require("child_process") | ||
const http = require('https') | ||
const fs = require('fs') | ||
const path = require("path") | ||
const chp = require("child_process") | ||
@@ -9,11 +12,15 @@ const iswin = ["win32", "cygwin"].includes(process.platform) | ||
} | ||
const exePath = await downloadBinary() | ||
const downloadURL = getDownloadURL() | ||
const extension = iswin ? ".exe" : "" | ||
const fileName = `lefthook${extension}` | ||
const exePath = path.join(__dirname, "bin", fileName) | ||
await downloadBinary(downloadURL, exePath) | ||
console.log('downloaded to', exePath) | ||
if (!iswin) { | ||
const { chmodSync } = require("fs") | ||
chmodSync(exePath, "755") | ||
fs.chmodSync(exePath, "755") | ||
} | ||
// run install | ||
spawnSync(exePath, ["install", "-f"], { | ||
chp.spawnSync(exePath, ['install', '-f'], { | ||
cwd: process.env.INIT_CWD || process.cwd(), | ||
stdio: "inherit", | ||
stdio: 'inherit', | ||
}) | ||
@@ -50,24 +57,27 @@ } | ||
const { DownloaderHelper } = require("node-downloader-helper") | ||
const path = require("path") | ||
async function downloadBinary(url, dest) { | ||
console.log('downloading', url) | ||
const file = fs.createWriteStream(dest) | ||
return new Promise((resolve, reject) => { | ||
http.get(url, function(response) { | ||
if (response.statusCode === 302 && response.headers.location) { | ||
// If the response is a 302 redirect, follow the new location | ||
downloadBinary(response.headers.location, dest) | ||
.then(resolve) | ||
.catch(reject) | ||
} else { | ||
response.pipe(file) | ||
async function downloadBinary() { | ||
// TODO zip the binaries to reduce the download size | ||
const downloadURL = getDownloadURL() | ||
const extension = iswin ? ".exe" : "" | ||
const fileName = `lefthook${extension}` | ||
const binDir = path.join(__dirname, "bin") | ||
const dl = new DownloaderHelper(downloadURL, binDir, { | ||
fileName, | ||
retry: { maxRetries: 5, delay: 50 }, | ||
file.on('finish', function() { | ||
file.close(() => { | ||
resolve(dest) | ||
}) | ||
}) | ||
} | ||
}).on('error', function(err) { | ||
fs.unlink(file, () => { | ||
reject(err) | ||
}) | ||
}) | ||
}) | ||
dl.on("end", () => console.log("lefthook binary was downloaded")) | ||
try { | ||
await dl.start() | ||
} catch(e) { | ||
const message = `Failed to download ${fileName}: ${e.message} while fetching ${downloadURL}` | ||
console.error(message) | ||
throw new Error(message) | ||
} | ||
return path.join(binDir, fileName) | ||
} | ||
@@ -74,0 +84,0 @@ |
{ | ||
"name": "@evilmartians/lefthook-installer", | ||
"version": "1.6.21", | ||
"version": "1.6.22", | ||
"description": "Simple git hooks manager", | ||
@@ -32,8 +32,4 @@ "main": "bin/index.js", | ||
"scripts": { | ||
"version": "cp -f ../../README.md ./", | ||
"install": "node install.js" | ||
}, | ||
"dependencies": { | ||
"node-downloader-helper": "^1.0.18" | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
11113
0
92
3
- Removednode-downloader-helper@^1.0.18
- Removednode-downloader-helper@1.0.19(transitive)