Files
cypress/packages/server/lib/util/find_system_node.js
Gleb Bahmutov 4ec77e3d58 use Node path from config file to run plugins (#4436)
* use Node path from config file to run plugins

* add finding system node

* memoize node find, use fix-path if Node is not found

* find Node asynchronously

* update note on ENFILE

* print node version before executing registered event

* use nodeVersion option, add validator isOneOf

* linting

* remove resolve-dir

* debugging unit test

* resolve original promise to make the tests run correctly

* update second test

* add unit tests

* upgrade snap-shot-it package to be able to update snapshots

* make finding node path part of startup, merge into config

* update tests

* add node version & path to run output

* add node version display to desktop-gui

* add warnings, add tests, add learn more link in desktop-gui

* Revert "add node version & path to run output"

This reverts commit 40a3218175.

* only show Node Version if it is non-default

* Add e2e test for using system node

* cleanup

* add tests that resolvedNodePath and Version are available in tests

* assert nodeVersion == system

* add nodeVersion to schema

* add new configoptions to types

* add fallback if pluginsfile is disabled

* new package.json sorting

* update some of the wording/styling of Node Version panel

* remove ` from schema file

* clean up decaffeinated tests + update wording when no pluginsfile is present

* playing with messaging.

* push updated node version panel design

* update design + copy of Node panel again

* some more iteration on design (WIP)

* Finish design changes + fix tests

* add debug message

* linting problems

* add missed require

* Add comment to refactor the colWidths in this PR after another PR goes

* replace the exact length of Node version in specfiles

* print object for node version and path instead of %s %s

* update snapshot to match v12 length


Co-authored-by: Zach Bloomquist <github@chary.us>
Co-authored-by: Jennifer Shehane <jennifer@cypress.io>
2019-10-01 17:08:11 -04:00

84 lines
2.0 KiB
JavaScript

const debug = require('debug')('cypress:server:find_system_node')
const execa = require('execa')
const fixPath = require('fix-path')
const Promise = require('bluebird')
const which = require('which')
const NODE_VERSION_RE = /^v(\d+\.\d+\.\d+)/m
/*
* Find the full path to a `node` binary on the current PATH.
* Note about fix-path:
* while fix-path is good, it can cause unexpected behavior when running Cypress locally
* for example, using NVM we set local Node to 8
* then fix-path adds all user paths, and the found Node is whatever we have
* installed globally, like 6 or 10 (NVM path comes later)
* So this function only fixes the path, if the Node cannot be found on first attempt
*/
function findNodeInFullPath () {
debug('finding Node with $PATH %s', process.env.PATH)
return Promise.fromCallback((cb) => {
return which('node', cb)
})
.catch(() => {
debug('could not find Node, trying to fix path')
// Fix the $PATH on macOS when run from a GUI app
fixPath()
debug('searching again with fixed $PATH %s', process.env.PATH)
return Promise.fromCallback((cb) => {
return which('node', cb)
})
})
.tap((path) => {
debug('found Node %o', { path })
})
.catch((err) => {
debug('could not find Node %o', { err })
throw err
})
}
function findNodeVersionFromPath (path) {
if (!path) {
return Promise.resolve(null)
}
return execa.stdout(path, ['-v'])
.then((stdout) => {
debug('node -v returned %o', { stdout })
const matches = NODE_VERSION_RE.exec(stdout)
if (matches && matches.length === 2) {
const version = matches[1]
debug('found Node version', { version })
return version
}
})
.catch((err) => {
debug('could not resolve Node version %o', { err })
throw err
})
}
function findNodePathAndVersion () {
return findNodeInFullPath()
.then((path) => {
return findNodeVersionFromPath(path)
.then((version) => {
return {
path, version,
}
})
})
}
module.exports = {
findNodePathAndVersion,
}