Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2010-08-25 08:36:41 +0400
committerisaacs <i@izs.me>2010-08-25 16:21:52 +0400
commit741745279bb3108bc7e1f67a0508411ba03505bb (patch)
treef9b2d391aa9021b75795ca407cb0282bad321b99 /lib
parent5628f8a0641a08b7234c608a5e420fcf1c02c1d1 (diff)
Make the dep path absolute at run-time
Diffstat (limited to 'lib')
-rw-r--r--lib/utils/write-shim.js32
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) {