diff options
-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) { |