diff options
author | isaacs <i@izs.me> | 2011-09-26 22:06:37 +0400 |
---|---|---|
committer | isaacs <i@izs.me> | 2011-09-26 22:06:37 +0400 |
commit | 344649dd145ab331a5ff7a2032c100ca62dc1227 (patch) | |
tree | dba228b88dd16dcba8e91d04fbdc231e7d31590d | |
parent | c3d3b7ee8b3d006acc33f053d808b7a1f5409207 (diff) | |
parent | b3d4ca8606b7b7fdee36e25bd883f4d6db2b3b7f (diff) |
Merge remote branch 'deanlandolt/winbin' into winbin
Conflicts:
lib/utils/mkdir-p.js
lib/utils/output.js
-rw-r--r-- | README.md | 31 | ||||
-rw-r--r-- | bin/npm.bat | 1 | ||||
-rw-r--r-- | bin/npm.cmd | 1 | ||||
-rw-r--r-- | lib/utils/lifecycle.js | 12 | ||||
-rw-r--r-- | lib/utils/mkdir-p.js | 5 | ||||
-rw-r--r-- | lib/utils/tar.js | 40 | ||||
-rw-r--r-- | npm.js | 27 | ||||
-rw-r--r-- | package.json | 2 | ||||
-rwxr-xr-x | test/run (renamed from test/run.sh) | 0 |
9 files changed, 101 insertions, 18 deletions
@@ -62,6 +62,37 @@ However, note that github tarballs **do not contain submodules**, so those won't work. You'll have to also fetch the appropriate submodules listed in the .gitmodules file. +### Installing on Windows + +The easiest way to get up and running with npm on Windows is to clone the +[github repository](https://github.com/isaacs/npm). If you don't already have +git, [install it](https://git.wiki.kernel.org/index.php/MSysGit:InstallMSysGit) and run: + + git clone --recursive git://github.com/isaacs/npm + +If this fails with a message about "error setting certificate verify locations" +remove the failed install, set a config entry and retry, like so: + + rm -rf npm + git config --system http.sslcainfo \\bin\curl-ca-bundle.crt + git clone --recursive git://github.com/isaacs/npm + +Congratulations -- you should now have a (still very broken) npm install. Now +navigate into the newly installed npm folder: + + cd npm + +To run npm from the command line be sure to add it your PATH: + + set path="%PATH%;%CD%\bin" + +If available you can use `setx` to make this PATH addition permanent: + + setx path "%PATH%" + +Otherwise you can make this change manually in "Advanced System Settings". + + ## Permissions **tl;dr** diff --git a/bin/npm.bat b/bin/npm.bat deleted file mode 100644 index d5a4b974c..000000000 --- a/bin/npm.bat +++ /dev/null @@ -1 +0,0 @@ -node Z:\dev\js\npm\npm.js %* diff --git a/bin/npm.cmd b/bin/npm.cmd new file mode 100644 index 000000000..387fc26fa --- /dev/null +++ b/bin/npm.cmd @@ -0,0 +1 @@ +@node %~dp0\..\npm.js %* diff --git a/lib/utils/lifecycle.js b/lib/utils/lifecycle.js index 36fcc5607..879ef78c1 100644 --- a/lib/utils/lifecycle.js +++ b/lib/utils/lifecycle.js @@ -63,7 +63,7 @@ function lifecycle_ (pkg, stage, wd, env, unsafe, failOk, cb) { }) PATH.unshift(path.join(acc, "node_modules", ".bin")) if (env.PATH) PATH.push(env.PATH) - env.PATH = PATH.join(":") + env.PATH = PATH.join(process.platform === "win32" ? ";" : ":") var packageLifecycle = pkg.scripts && pkg.scripts.hasOwnProperty(stage) @@ -111,12 +111,20 @@ function runPackageLifecycle (pkg, env, wd, unsafe, cb) { , user = unsafe ? null : npm.config.get("user") , group = unsafe ? null : npm.config.get("group") , cmd = env.npm_lifecycle_script + , sh = "sh" + , shFlag = "-c" + + if (process.platform === "win32") { + sh = "cmd" + shFlag = "/c" + } log.verbose(unsafe, "unsafe-perm in lifecycle") output.write("\n> "+pkg._id+" " + stage+" "+wd+"\n> "+cmd+"\n", function (er) { if (er) return cb(er) - exec( "sh", ["-c", cmd], env, true, wd + + exec( sh, [shFlag, cmd], env, true, wd , user, group , function (er, code, stdout, stderr) { if (er && !npm.ROLLBACK) { diff --git a/lib/utils/mkdir-p.js b/lib/utils/mkdir-p.js index dff3d48ba..e5245da71 100644 --- a/lib/utils/mkdir-p.js +++ b/lib/utils/mkdir-p.js @@ -25,8 +25,7 @@ function mkdir (ensure, mode, uid, gid, cb_) { } } - ensure = ensure.replace(/\/+$/, '') - ensure = path.resolve(ensure) + ensure = path.resolve(ensure).replace(/\/+$/, '') if (mkdirCache.hasOwnProperty(ensure)) { return mkdirCache[ensure].push(cb_) @@ -101,7 +100,7 @@ function walkDirs (ensure, mode, uid, gid, cb) { // get the absolute dir for the next piece being stat'd walker.push(d) - var dir = walker.join("/") + var dir = walker.join(path.SPLIT_CHAR) // stat callback lambda fs.stat(dir, function STATCB (er, s) { diff --git a/lib/utils/tar.js b/lib/utils/tar.js index 6ecc37be3..618920934 100644 --- a/lib/utils/tar.js +++ b/lib/utils/tar.js @@ -27,8 +27,7 @@ exports.makeList = makeList function pack (targetTarball, folder, pkg, dfc, cb) { if (typeof cb !== "function") cb = dfc, dfc = true - if (folder.charAt(0) !== "/") folder = path.resolve(process.cwd(), folder) - if (folder.slice(-1) === "/") folder = folder.slice(0, -1) + folder = path.resolve(process.cwd(), folder) if (typeof pkg === "function") { cb = pkg, pkg = null return readJson(path.resolve(folder, "package.json"), function (er, pkg) { @@ -65,9 +64,13 @@ function packFiles (targetTarball, parent, files, pkg, cb) { log.verbose(path.dirname(targetTarball), "mkdir'ed") // tar xf - --strip-components=1 -C {unpackTarget} \ // | gzip {tarball} > targetTarball + // HACK tar on windows likes forward slashes + if (process.platform === "win32") files = files.map(function(f) { + return f.replace(/\\/g, "/") + }) var target = fs.createWriteStream(targetTarball) , unPacked = false - , args = [ "-cvf", "-"].concat(files) + , args = [ "-czvf", "-"].concat(files) , tarEnv = {} for (var i in process.env) { tarEnv[i] = process.env[i] @@ -79,22 +82,35 @@ function packFiles (targetTarball, parent, files, pkg, cb) { log.verbose("about to write tar and gzip it.", "tar") log.silly(args, "tar args") + + // HACK bypass the whole gzip piping mess as it locks up on windows + /* var tar = spawn( npm.config.get("tar") , args, tarEnv, false, parent ) , gzip = spawn( npm.config.get("gzipbin") , ["--stdout"] , null, false, parent ) , errState - tar.name = "tar -cvf - <file list elided>" + */ + var tar = spawn( npm.config.get("tar") + , args, tarEnv, false, parent) + , errState + //tar.name = "tar -cvf - <file list elided>" + tar.name = "tar -czvf - <file list elided>" + /* pipe(tar, gzip, function (er) { //clearTimeout(gzipTimeout) if (errState) return if (er) return cb(errState = er) }) - gzip.stdout.pipe(target) + */ + //gzip.stdout.pipe(target) + tar.stdout.pipe(target) + /* //var gzipTimeout = setTimeout(function () { // gzip.kill("SIGKILL") // gzip.emit("error", new Error("gzip timeout")) //}, 10000) + */ target.on("close", function (er, ok) { if (errState) return if (er) return cb(errState = er) @@ -167,18 +183,20 @@ function gunzTarPerm (tarball, tmp, dMode, fMode, uid, gid, cb) { //console.error(npm.config.get("gzipbin")+" --decompress --stdout " // +tarball+" | "+npm.config.get("tar")+" -mvxpf - -o -C " // +tmp) + // HACK tar on windows prefers forward slashes (or double backslashes) + var tmpTar = process.platform === "win32" ? tmp.replace(/\\/g, "/") : tmp pipe( spawn( npm.config.get("gzipbin") , ["--decompress", "--stdout", tarball] , process.env, false ) , spawn( npm.config.get("tar") - , ["-mvxpf", "-", "-o", "-C", tmp] + , ["-mvxpf", "-", "-o", "-C", tmpTar] , process.env, false ) , function (er) { // if we're not doing ownership management, // then we're done now. - if (er) return log.er(cb, - "Failed unpacking "+tarball)(er) - if (npm.config.get("unsafe-perm")) { + if (er) return log.er(cb, "Failed unpacking "+tarball)(er) + // HACK skip on windows + if (npm.config.get("unsafe-perm") && process.platform !== "win32") { if (!process.getuid || !process.getgid) return cb(er) uid = process.getuid() gid = process.getgid() @@ -192,6 +210,7 @@ function gunzTarPerm (tarball, tmp, dMode, fMode, uid, gid, cb) { }, function (er, files) { if (er) return cb(er) asyncMap(files, function (f, cb) { + f = path.resolve(f) // FIXME this should really be done in node log.silly(f, "asyncMap in gTP") fs.lstat(f, function (er, stat) { if (er || stat.isSymbolicLink()) return cb(er) @@ -208,8 +227,7 @@ function gunzTarPerm (tarball, tmp, dMode, fMode, uid, gid, cb) { }) }, function (er) { if (er) return cb(er) - fs.chown(tmp, process.getuid(), process.getgid() - ,function (er) { + fs.chown(tmp, process.getuid(), process.getgid(), function (er) { if (er) return cb(er) fs.readdir(tmp, function (er, folder) { folder = folder.filter(function (f) { @@ -1,6 +1,10 @@ process.title = "npm" + +// FIXME there really ought to be a path.split in node core +require("path").SPLIT_CHAR = process.platform === "win32" ? "\\" : "/" + var EventEmitter = require("events").EventEmitter , npm = module.exports = new EventEmitter , config = require("./lib/config.js") @@ -26,6 +30,29 @@ npm.EISGIT = {} npm.ECYCLE = {} npm.EENGINE = {} +// HACK for windows +if (process.platform === "win32") { + // stub in unavailable methods from process and fs binding + if (!process.getuid) process.getuid = function() {} + if (!process.getgid) process.getgid = function() {} + var fsBinding = process.binding("fs") + if (!fsBinding.chown) fsBinding.chown = function() { + var cb = arguments[arguments.length - 1] + if (typeof cb == "function") cb() + } + + // patch rename/renameSync, but this should really be fixed in node + var _fsRename = fs.rename + , _fsPathPatch + _fsPathPatch = function(p) { + return p && p.replace(/\\/g, "/") || p; + } + fs.rename = function(p1, p2) { + arguments[0] = _fsPathPatch(p1) + arguments[1] = _fsPathPatch(p2) + return _fsRename.apply(fs, arguments); + } +} try { // startup, ok to do this synchronously diff --git a/package.json b/package.json index c859efaed..59c6e3cc0 100644 --- a/package.json +++ b/package.json @@ -51,7 +51,7 @@ , "which" ] , "devDependencies" : { "ronn" : "" } , "engines" : { "node" : "0.4 || 0.5", "npm" : "1" } -, "scripts" : { "test" : "./test/run.sh" +, "scripts" : { "test" : "./test/run" , "prepublish" : "make doc" , "dumpconf": "env | grep npm | sort | uniq" } |