Replace string magic + path.join by path.resolve
Because path.resolve is more elegant and windows-safe.
This commit is contained in:
parent
dea2331377
commit
1ac133ea6f
@ -247,12 +247,7 @@ REPLServer.prototype.complete = function(line) {
|
|||||||
var dir, files, f, name, base, ext, abs, subfiles, s;
|
var dir, files, f, name, base, ext, abs, subfiles, s;
|
||||||
group = [];
|
group = [];
|
||||||
for (i = 0; i < require.paths.length; i++) {
|
for (i = 0; i < require.paths.length; i++) {
|
||||||
dir = require.paths[i];
|
dir = path.resolve(require.paths[i], subdir);
|
||||||
if (subdir && subdir[0] === '/') {
|
|
||||||
dir = subdir;
|
|
||||||
} else if (subdir) {
|
|
||||||
dir = path.join(dir, subdir);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
files = fs.readdirSync(dir);
|
files = fs.readdirSync(dir);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -271,7 +266,7 @@ REPLServer.prototype.complete = function(line) {
|
|||||||
group.push(subdir + base);
|
group.push(subdir + base);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
abs = path.join(dir, name);
|
abs = path.resolve(dir, name);
|
||||||
try {
|
try {
|
||||||
if (fs.statSync(abs).isDirectory()) {
|
if (fs.statSync(abs).isDirectory()) {
|
||||||
group.push(subdir + name + '/');
|
group.push(subdir + name + '/');
|
||||||
|
21
src/node.js
21
src/node.js
@ -132,11 +132,11 @@
|
|||||||
|
|
||||||
var path = requireNative('path');
|
var path = requireNative('path');
|
||||||
|
|
||||||
var modulePaths = [path.join(process.execPath, '..', '..', 'lib', 'node')];
|
var modulePaths = [path.resolve(process.execPath, '..', '..', 'lib', 'node')];
|
||||||
|
|
||||||
if (process.env['HOME']) {
|
if (process.env['HOME']) {
|
||||||
modulePaths.unshift(path.join(process.env['HOME'], '.node_libraries'));
|
modulePaths.unshift(path.resolve(process.env['HOME'], '.node_libraries'));
|
||||||
modulePaths.unshift(path.join(process.env['HOME'], '.node_modules'));
|
modulePaths.unshift(path.resolve(process.env['HOME'], '.node_modules'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.env['NODE_PATH']) {
|
if (process.env['NODE_PATH']) {
|
||||||
@ -188,11 +188,11 @@
|
|||||||
for (var i = 0, PL = paths.length; i < PL; i++) {
|
for (var i = 0, PL = paths.length; i < PL; i++) {
|
||||||
var p = paths[i],
|
var p = paths[i],
|
||||||
// try to join the request to the path
|
// 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
|
// 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"
|
// 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; }
|
if (f) { return f; }
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@ -220,7 +220,7 @@
|
|||||||
// as it already has been accepted as a module.
|
// as it already has been accepted as a module.
|
||||||
var isIndex = /^index\.\w+?$/.test(path.basename(parent.filename)),
|
var isIndex = /^index\.\w+?$/.test(path.basename(parent.filename)),
|
||||||
parentIdPath = isIndex ? parent.id : path.dirname(parent.id),
|
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
|
// make sure require('./path') and require('path') get distinct ids, even
|
||||||
// when called from the toplevel js file
|
// when called from the toplevel js file
|
||||||
@ -557,10 +557,9 @@
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// Load module
|
// Load module
|
||||||
if ('/\\'.indexOf(process.argv[1].charAt(0)) < 0
|
// make process.argv[1] into a full path
|
||||||
&& process.argv[1].charAt(1) != ':'
|
if (!(/^http:\/\//).exec(process.argv[1])) {
|
||||||
&& !(/^http:\/\//).exec(process.argv[1])) {
|
process.argv[1] = path.resolve(process.argv[1]);
|
||||||
process.argv[1] = path.join(cwd, process.argv[1]);
|
|
||||||
}
|
}
|
||||||
// REMOVEME: nextTick should not be necessary. This hack to get
|
// REMOVEME: nextTick should not be necessary. This hack to get
|
||||||
// test/simple/test-exception-handler2.js working.
|
// test/simple/test-exception-handler2.js working.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user