 module.exports = (opts) -> new Wrap(opts)
 
 idFromPath = (path) -> path.replace(/\\/g, '/')
+pkgbasedir = (dir) ->
+    dn = path.dirname(dir)
+    while path.basename(dn) isnt "node_modules"
+        dir = dn
+        dn = path.dirname(dir)
+    return dir
+
 
 class Wrap extends EventEmitter
     constructor: (opts = {}) ->


                params.target = idFromPath(reqFilenameWithoutDriveLetter)
            @require(req, params)

        return this



        return Object.keys(@files).some((key) => @files[key].target is file)

    end: () =>
        @installscript = yes unless Object.keys(@skip).length
        unless @installscript # veryPrimitive™
            # generate an installscript to get all nodejs bindings with npm
            @installscript = yes
            src = ["#!/bin/sh", "cwd=`pwd`"]
            for pkgname,pkgs of @skip
                src.push("echo 'install #{pkgname} …'")
                for pkgpath in pkgs
                    parentpkgpath = path.join(pkgpath, "../..")
                    src.push("cd #{path.relative(@dirname, parentpkgpath)}")
                    src.push("npm install #{pkgname}")
                    src.push("cd $cwd")
            src.push("echo 'done.'")
            entry = @append("install", src.join("\n"))
            entry.name = "main"
        if @working
            @ending = yes
            @emit('wait')
