Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Commit

Permalink
Replace string magic + path.join by path.resolve
Browse files Browse the repository at this point in the history
Because path.resolve is more elegant and windows-safe.
  • Loading branch information
piscisaureus authored and ry committed Jan 6, 2011
1 parent dea2331 commit 1ac133e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 deletions.
9 changes: 2 additions & 7 deletions lib/repl.js
Expand Up @@ -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) {
Expand All @@ -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 + '/');
Expand Down
21 changes: 10 additions & 11 deletions src/node.js
Expand Up @@ -132,11 +132,11 @@

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']) {
Expand Down Expand Up @@ -188,11 +188,11 @@
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;
Expand Down Expand Up @@ -220,7 +220,7 @@
// 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
Expand Down Expand Up @@ -557,10 +557,9 @@

} 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.
Expand Down

1 comment on commit 1ac133e

@Nomon
Copy link

@Nomon Nomon commented on 1ac133e Jan 27, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This patch changes the behavior of the loading system, I am not sure if it was intended but if you have file.js test.js test/index.js files and you require('./test/') from file.js the behavior before the patch was to find test/index.js after this it hits the test.js instead.
https://gist.github.com/798551

Please sign in to comment.