"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/npm/lib/explore.js" (11 Apr 2017, 1668 Bytes) of package /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 // npm explore <pkg>[@<version>]
    2 // open a subshell to the package folder.
    3 
    4 module.exports = explore
    5 explore.usage = 'npm explore <pkg> [ -- <cmd>]'
    6 explore.completion = require('./utils/completion/installed-shallow.js')
    7 
    8 var npm = require('./npm.js')
    9 var spawn = require('./utils/spawn')
   10 var path = require('path')
   11 var fs = require('graceful-fs')
   12 var isWindowsShell = require('./utils/is-windows-shell.js')
   13 var escapeExecPath = require('./utils/escape-exec-path.js')
   14 var escapeArg = require('./utils/escape-arg.js')
   15 var output = require('./utils/output.js')
   16 
   17 function explore (args, cb) {
   18   if (args.length < 1 || !args[0]) return cb(explore.usage)
   19   var p = args.shift()
   20 
   21   var cwd = path.resolve(npm.dir, p)
   22   var opts = {cwd: cwd, stdio: 'inherit'}
   23 
   24   var shellArgs = []
   25   if (args) {
   26     if (isWindowsShell) {
   27       var execCmd = escapeExecPath(args.shift())
   28       var execArgs = [execCmd].concat(args.map(escapeArg))
   29       opts.windowsVerbatimArguments = true
   30       shellArgs = ['/d', '/s', '/c'].concat(execArgs)
   31     } else {
   32       shellArgs.unshift('-c')
   33       shellArgs = ['-c', args.map(escapeArg).join(' ').trim()]
   34     }
   35   }
   36 
   37   var sh = npm.config.get('shell')
   38   fs.stat(cwd, function (er, s) {
   39     if (er || !s.isDirectory()) {
   40       return cb(new Error(
   41         "It doesn't look like " + p + ' is installed.'
   42       ))
   43     }
   44 
   45     if (!shellArgs.length) {
   46       output(
   47         '\nExploring ' + cwd + '\n' +
   48           "Type 'exit' or ^D when finished\n"
   49       )
   50     }
   51 
   52     var shell = spawn(sh, shellArgs, opts)
   53     shell.on('close', function (er) {
   54       // only fail if non-interactive.
   55       if (!shellArgs.length) return cb()
   56       cb(er)
   57     })
   58   })
   59 }