From 5817e810c1418a51d03af49a23a0bc871b2cd7cc Mon Sep 17 00:00:00 2001 From: ehmicky Date: Thu, 15 Oct 2020 20:30:42 +0200 Subject: [PATCH] chore(lint): use `isexe` module --- package.json | 1 + src/lib/exec-fetcher.js | 25 ++----------------------- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/package.json b/package.json index 0121f4669a7..46cc07041e9 100644 --- a/package.json +++ b/package.json @@ -120,6 +120,7 @@ "inquirer": "^6.5.1", "inquirer-autocomplete-prompt": "^1.0.1", "is-docker": "^2.0.0", + "isexe": "^2.0.0", "jwt-decode": "^3.0.0", "lambda-local": "^1.7.1", "lodash.debounce": "^4.0.8", diff --git a/src/lib/exec-fetcher.js b/src/lib/exec-fetcher.js index 1b4dd2de560..37244fdf787 100644 --- a/src/lib/exec-fetcher.js +++ b/src/lib/exec-fetcher.js @@ -1,9 +1,9 @@ const path = require('path') const execa = require('execa') const { fetchLatest, updateAvailable } = require('gh-release-fetch') +const isExe = require('isexe') const { NETLIFYDEVWARN } = require('../utils/logo') -const fs = require('./fs') const isWindows = () => { return process.platform === 'win32' @@ -25,27 +25,6 @@ const getOptions = () => { } } -const isExe = (mode, gid, uid) => { - if (isWindows()) { - return true - } - - const isGroup = gid ? process.getgid && gid === process.getgid() : true - const isUser = uid ? process.getuid && uid === process.getuid() : true - - return Boolean(mode & 0o0001 || (mode & 0o0010 && isGroup) || (mode & 0o0100 && isUser)) -} - -const execExist = async (binPath) => { - try { - const stat = await fs.statAsync(binPath) - return stat.isFile() && isExe(stat.mode, stat.gid, stat.uid) - } catch (error) { - if (error.code === 'ENOENT') return false - throw error - } -} - const isVersionOutdated = async ({ packageName, currentVersion }) => { const options = getOptions() const outdated = await updateAvailable(getRepository({ packageName }), currentVersion, options) @@ -55,7 +34,7 @@ const isVersionOutdated = async ({ packageName, currentVersion }) => { const shouldFetchLatestVersion = async ({ binPath, packageName, execName, execArgs, pattern, log }) => { const execPath = path.join(binPath, getExecName({ execName })) - const exists = await execExist(execPath) + const exists = await isExe(execPath, { ignoreErrors: true }) if (!exists) { return true }