Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use isexe module #1404

Merged
merged 1 commit into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 2 additions & 23 deletions src/lib/exec-fetcher.js
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ENOENT check is the reason we use ignoreErrors: true. However, this will ignore all errors, not only ENOENT.
Without that option, only EACCESS is ignored.

throw error
}
}

const isVersionOutdated = async ({ packageName, currentVersion }) => {
const options = getOptions()
const outdated = await updateAvailable(getRepository({ packageName }), currentVersion, options)
Expand All @@ -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
}
Expand Down