Replace string magic + path.join by path.resolve
authorBert Belder <bertbelder@gmail.com>
Thu, 6 Jan 2011 20:06:29 +0000 (21:06 +0100)
committerRyan Dahl <ry@tinyclouds.org>
Thu, 6 Jan 2011 23:39:51 +0000 (15:39 -0800)
Because path.resolve is more elegant and windows-safe.

lib/repl.js
src/node.js

index 83f52e81286fb091771fa308f0e33cdd1cec1d73..5b59d0ac9543d1bcd8464d63221a3b0ff4ea15f5 100644 (file)
@@ -247,12 +247,7 @@ REPLServer.prototype.complete = function(line) {
     var dir, files, f, name, base, ext, abs, subfiles, s;
     group = [];
     for (i = 0; i < require.paths.length; i++) {
-      dir = require.paths[i];
-      if (subdir && subdir[0] === '/') {
-        dir = subdir;
-      } else if (subdir) {
-        dir = path.join(dir, subdir);
-      }
+      dir = path.resolve(require.paths[i], subdir);
       try {
         files = fs.readdirSync(dir);
       } catch (e) {
@@ -271,7 +266,7 @@ REPLServer.prototype.complete = function(line) {
             group.push(subdir + base);
           }
         } else {
-          abs = path.join(dir, name);
+          abs = path.resolve(dir, name);
           try {
             if (fs.statSync(abs).isDirectory()) {
               group.push(subdir + name + '/');
index f6cc2392ceda19e7f1c79bd40813a5e9b21f90f3..13816642fe2f7c211cb7af396b3891ae32b3193f 100644 (file)
 
     var path = requireNative('path');
 
-    var modulePaths = [path.join(process.execPath, '..', '..', 'lib', 'node')];
+    var modulePaths = [path.resolve(process.execPath, '..', '..', 'lib', 'node')];
 
     if (process.env['HOME']) {
-      modulePaths.unshift(path.join(process.env['HOME'], '.node_libraries'));
-      modulePaths.unshift(path.join(process.env['HOME'], '.node_modules'));
+      modulePaths.unshift(path.resolve(process.env['HOME'], '.node_libraries'));
+      modulePaths.unshift(path.resolve(process.env['HOME'], '.node_modules'));
     }
 
     if (process.env['NODE_PATH']) {
       for (var i = 0, PL = paths.length; i < PL; i++) {
         var p = paths[i],
             // try to join the request to the path
-            f = tryFile(path.join(p, request)) ||
+            f = tryFile(path.resolve(p, request)) ||
             // try it with each of the extensions
-            tryExtensions(path.join(p, request)) ||
+            tryExtensions(path.resolve(p, request)) ||
             // try it with each of the extensions at "index"
-            tryExtensions(path.join(p, request, 'index'));
+            tryExtensions(path.resolve(p, request, 'index'));
         if (f) { return f; }
       }
       return false;
       // as it already has been accepted as a module.
       var isIndex = /^index\.\w+?$/.test(path.basename(parent.filename)),
           parentIdPath = isIndex ? parent.id : path.dirname(parent.id),
-          id = path.join(parentIdPath, request);
+          id = path.resolve(parentIdPath, request);
 
       // make sure require('./path') and require('path') get distinct ids, even
       // when called from the toplevel js file
 
     } else {
       // Load module
-      if ('/\\'.indexOf(process.argv[1].charAt(0)) < 0
-          && process.argv[1].charAt(1) != ':'
-          && !(/^http:\/\//).exec(process.argv[1])) {    
-        process.argv[1] = path.join(cwd, process.argv[1]);
+      // make process.argv[1] into a full path
+      if (!(/^http:\/\//).exec(process.argv[1])) {
+        process.argv[1] = path.resolve(process.argv[1]);
       }
       // REMOVEME: nextTick should not be necessary. This hack to get
       // test/simple/test-exception-handler2.js working.