]> gerrit.simantics Code Review - simantics/district.git/blob - org.simantics.maps.server/node/node-v4.8.0-win-x64/node_modules/npm/node_modules/realize-package-specifier/index.js
Adding integrated tile server
[simantics/district.git] / org.simantics.maps.server / node / node-v4.8.0-win-x64 / node_modules / npm / node_modules / realize-package-specifier / index.js
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(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") dep.spec = specpath
37     cb(null, dep)
38   }
39 }