diff options
author | isaacs <i@izs.me> | 2010-08-25 08:36:41 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2010-08-25 16:21:52 +0400 |
commit | 741745279bb3108bc7e1f67a0508411ba03505bb (patch) | |
tree | f9b2d391aa9021b75795ca407cb0282bad321b99 /lib/utils/write-shim.js | |
parent | 5628f8a0641a08b7234c608a5e420fcf1c02c1d1 (diff) |
Make the dep path absolute at run-time
Diffstat (limited to 'lib/utils/write-shim.js')
-rw-r--r-- | lib/utils/write-shim.js | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/lib/utils/write-shim.js b/lib/utils/write-shim.js index 8941de023..038e85cbb 100644 --- a/lib/utils/write-shim.js +++ b/lib/utils/write-shim.js @@ -6,6 +6,7 @@ var fs = require("./graceful-fs") , path = require("path") , relativize = require("./relativize") , mkdir = require("./mkdir-p") + , log = require("./log") function shimIfExists (from, to, dep, cb) { if (!cb) cb = dep, dep = false @@ -17,23 +18,28 @@ function shimIfExists (from, to, dep, cb) { function writeShim (from, to, dep, cb) { if (!cb) cb = dep, dep = false - if (dep) dep = JSON.stringify(relativize(dep, to)) - from = JSON.stringify(relativize(from, to).replace(/\.(js|node)$/, '')) + log.silly([from,to], "writeShim") + if (dep) dep = relativize(dep, to) + from = relativize(from, to).replace(/\.(js|node)$/, '') var nodePath = process.execPath || path.join(process.installPrefix, "bin", "node") , code = "#!"+nodePath+"\n" + "// generated by npm, please don't touch!\n" - + (dep ? "var depMet = require.paths.indexOf("+dep+") !== -1\n" - + "if (!depMet) require.paths.unshift("+dep+")\n" - : "" - ) - + "module.exports = require(" + from + ")\n" - + ( dep ? "if (!depMet) {\n" // get the possibly-changed location - + " var i = require.paths.indexOf("+dep+")\n" - + " if (i !== -1) require.paths.splice(i, 1)\n" - + "}" - : "\n" - ) + + (dep ? "var dep = require('path').join(__dirname, " + + JSON.stringify(dep || null) + ")\n" + + "var depMet = require.paths.indexOf(dep) !== -1\n" + : "") + + "var from = "+JSON.stringify(from)+"\n" + + "\n" + + (dep ? "if (!depMet) require.paths.unshift(dep)\n" : "") + + "module.exports = require(from)\n" + + "\n" + + (dep ? "if (!depMet) {\n" + + " var i = require.paths.indexOf(dep)\n" + + " if (i !== -1) require.paths.splice(i, 1)\n" + + "}\n" + : "") + mkdir(path.dirname(to), function (er) { if (er) return cb(er) fs.writeFile(to, code, "ascii", function (er, ok) { |