"Fossies" - the Fresh Open Source Software Archive

Member "Atom/resources/app/apm/node_modules/realize-package-specifier/index.js" (8 Mar 2017, 1165 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 "use strict"
    2 var fs = require("fs")
    3 var path = require("path")
    4 var dz = require("dezalgo")
    5 var npa = require("npm-package-arg")
    6 
    7 module.exports = function (spec, where, cb) {
    8   if (where instanceof Function) { cb = where; where = null }
    9   if (where == null) where = "."
   10   cb = dz(cb)
   11   try {
   12     var dep = npa(spec)
   13   }
   14   catch (e) {
   15     return cb(e)
   16   }
   17   if ((dep.type == "range" || dep.type == "version") && dep.name != dep.raw) return cb(null, dep)
   18   var specpath = dep.type == "local"
   19                ? path.resolve(where, dep.spec)
   20                : path.resolve(where, dep.rawSpec? dep.rawSpec: dep.name)
   21   fs.stat(specpath, function (er, s) {
   22     if (er) return finalize()
   23     if (!s.isDirectory()) return finalize("local")
   24     fs.stat(path.join(specpath, "package.json"), function (er) {
   25       finalize(er ? null : "directory")
   26     })
   27   })
   28   function finalize(type) {
   29     if (type != null && type != dep.type) {
   30       dep.type = type
   31       if (! dep.rawSpec) {
   32         dep.rawSpec = dep.name
   33         dep.name = null
   34       }
   35     }
   36     if (dep.type == "local" || dep.type == "directory") {
   37       dep.spec = path.resolve(specpath)
   38     }
   39     cb(null, dep)
   40   }
   41 }