mirror of
https://github.com/electron/node-gyp.git
synced 2025-08-15 12:58:19 +02:00
src: implement standard.js linting
In addition: * moved module.exports to the bottom * no single-line if statements * no if statements without a { * const for requires * array declarations get spaces inside [ ] * 'use strict' in all .js files PR-URL: https://github.com/nodejs/node-gyp/pull/1794 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: João Reis <reis@janeasystems.com>
This commit is contained in:
parent
7e8127068f
commit
e40c99e283
28 changed files with 739 additions and 661 deletions
|
@ -1,7 +1,9 @@
|
|||
var path = require('path')
|
||||
, log = require('npmlog')
|
||||
'use strict'
|
||||
|
||||
module.exports = function findNodeDirectory(scriptLocation, processObj) {
|
||||
const path = require('path')
|
||||
const log = require('npmlog')
|
||||
|
||||
function findNodeDirectory (scriptLocation, processObj) {
|
||||
// set dirname and process if not passed in
|
||||
// this facilitates regression tests
|
||||
if (scriptLocation === undefined) {
|
||||
|
@ -12,48 +14,50 @@ module.exports = function findNodeDirectory(scriptLocation, processObj) {
|
|||
}
|
||||
|
||||
// Have a look to see what is above us, to try and work out where we are
|
||||
npm_parent_directory = path.join(scriptLocation, '../../../..')
|
||||
log.verbose('node-gyp root', 'npm_parent_directory is '
|
||||
+ path.basename(npm_parent_directory))
|
||||
node_root_dir = ""
|
||||
var npmParentDirectory = path.join(scriptLocation, '../../../..')
|
||||
log.verbose('node-gyp root', 'npm_parent_directory is ' +
|
||||
path.basename(npmParentDirectory))
|
||||
var nodeRootDir = ''
|
||||
|
||||
log.verbose('node-gyp root', 'Finding node root directory')
|
||||
if (path.basename(npm_parent_directory) === 'deps') {
|
||||
if (path.basename(npmParentDirectory) === 'deps') {
|
||||
// We are in a build directory where this script lives in
|
||||
// deps/npm/node_modules/node-gyp/lib
|
||||
node_root_dir = path.join(npm_parent_directory, '..')
|
||||
log.verbose('node-gyp root', 'in build directory, root = '
|
||||
+ node_root_dir)
|
||||
} else if (path.basename(npm_parent_directory) === 'node_modules') {
|
||||
nodeRootDir = path.join(npmParentDirectory, '..')
|
||||
log.verbose('node-gyp root', 'in build directory, root = ' +
|
||||
nodeRootDir)
|
||||
} else if (path.basename(npmParentDirectory) === 'node_modules') {
|
||||
// We are in a node install directory where this script lives in
|
||||
// lib/node_modules/npm/node_modules/node-gyp/lib or
|
||||
// node_modules/npm/node_modules/node-gyp/lib depending on the
|
||||
// platform
|
||||
if (processObj.platform === 'win32') {
|
||||
node_root_dir = path.join(npm_parent_directory, '..')
|
||||
nodeRootDir = path.join(npmParentDirectory, '..')
|
||||
} else {
|
||||
node_root_dir = path.join(npm_parent_directory, '../..')
|
||||
nodeRootDir = path.join(npmParentDirectory, '../..')
|
||||
}
|
||||
log.verbose('node-gyp root', 'in install directory, root = '
|
||||
+ node_root_dir)
|
||||
log.verbose('node-gyp root', 'in install directory, root = ' +
|
||||
nodeRootDir)
|
||||
} else {
|
||||
// We don't know where we are, try working it out from the location
|
||||
// of the node binary
|
||||
var node_dir = path.dirname(processObj.execPath)
|
||||
var directory_up = path.basename(node_dir)
|
||||
if (directory_up === 'bin') {
|
||||
node_root_dir = path.join(node_dir, '..')
|
||||
} else if (directory_up === 'Release' || directory_up === 'Debug') {
|
||||
var nodeDir = path.dirname(processObj.execPath)
|
||||
var directoryUp = path.basename(nodeDir)
|
||||
if (directoryUp === 'bin') {
|
||||
nodeRootDir = path.join(nodeDir, '..')
|
||||
} else if (directoryUp === 'Release' || directoryUp === 'Debug') {
|
||||
// If we are a recently built node, and the directory structure
|
||||
// is that of a repository. If we are on Windows then we only need
|
||||
// to go one level up, everything else, two
|
||||
if (processObj.platform === 'win32') {
|
||||
node_root_dir = path.join(node_dir, '..')
|
||||
nodeRootDir = path.join(nodeDir, '..')
|
||||
} else {
|
||||
node_root_dir = path.join(node_dir, '../..')
|
||||
nodeRootDir = path.join(nodeDir, '../..')
|
||||
}
|
||||
}
|
||||
// Else return the default blank, "".
|
||||
}
|
||||
return node_root_dir
|
||||
return nodeRootDir
|
||||
}
|
||||
|
||||
module.exports = findNodeDirectory
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue