"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/node-gyp/lib/find-node-directory.js" (8 Mar 2017, 2389 Bytes) of archive /windows/misc/atom-windows.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Javascript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 var path = require('path')
    2   , log = require('npmlog')
    3 
    4 function findNodeDirectory(scriptLocation, processObj) {
    5   // set dirname and process if not passed in
    6   // this facilitates regression tests
    7   if (scriptLocation === undefined) {
    8     scriptLocation = __dirname
    9   }
   10   if (processObj === undefined) {
   11     processObj = process
   12   }
   13 
   14   // Have a look to see what is above us, to try and work out where we are
   15   npm_parent_directory = path.join(scriptLocation, '../../../..')
   16   log.verbose('node-gyp root', 'npm_parent_directory is '
   17               + path.basename(npm_parent_directory))
   18   node_root_dir = ""
   19 
   20   log.verbose('node-gyp root', 'Finding node root directory')
   21   if (path.basename(npm_parent_directory) === 'deps') {
   22     // We are in a build directory where this script lives in
   23     // deps/npm/node_modules/node-gyp/lib
   24     node_root_dir = path.join(npm_parent_directory, '..')
   25     log.verbose('node-gyp root', 'in build directory, root = '
   26                 + node_root_dir)
   27   } else if (path.basename(npm_parent_directory) === 'node_modules') {
   28     // We are in a node install directory where this script lives in
   29     // lib/node_modules/npm/node_modules/node-gyp/lib or
   30     // node_modules/npm/node_modules/node-gyp/lib depending on the
   31     // platform
   32     if (processObj.platform === 'win32') {
   33       node_root_dir = path.join(npm_parent_directory, '..')
   34     } else {
   35       node_root_dir = path.join(npm_parent_directory, '../..')
   36     }
   37     log.verbose('node-gyp root', 'in install directory, root = '
   38                 + node_root_dir)
   39   } else {
   40     // We don't know where we are, try working it out from the location
   41     // of the node binary
   42     var node_dir = path.dirname(processObj.execPath)
   43     var directory_up = path.basename(node_dir)
   44     if (directory_up === 'bin') {
   45       node_root_dir = path.join(node_dir, '..')
   46     } else if (directory_up === 'Release' || directory_up === 'Debug') {
   47       // If we are a recently built node, and the directory structure
   48       // is that of a repository. If we are on Windows then we only need
   49       // to go one level up, everything else, two
   50       if (processObj.platform === 'win32') {
   51         node_root_dir = path.join(node_dir, '..')
   52       } else {
   53         node_root_dir = path.join(node_dir, '../..')
   54       }
   55     }
   56     // Else return the default blank, "".
   57   }
   58   return node_root_dir
   59 }
   60 
   61 module.exports = findNodeDirectory