Skip to content

Commit 671e64a

Browse files
targospiscisaureus
authored andcommitted
module: allow long paths for require on Windows
#1801 introduced internal fs methods to speed up require. The methods do not call path._makeLong like their counterpart from the fs module. This brings back the old behaviour. Fixes: #1990 Fixes: #1980 Fixes: #1849 PR-URL: https://github.com/nodejs/io.js/pull/1991/files Reviewed-By: Bert Belder <[email protected]>
1 parent 52a822d commit 671e64a

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/module.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ function readPackage(requestPath) {
6767
}
6868

6969
var jsonPath = path.resolve(requestPath, 'package.json');
70-
var json = internalModuleReadFile(jsonPath);
70+
var json = internalModuleReadFile(path._makeLong(jsonPath));
7171

7272
if (json === undefined) {
7373
return false;
@@ -100,7 +100,7 @@ Module._realpathCache = {};
100100

101101
// check if the file exists and is not a directory
102102
function tryFile(requestPath) {
103-
const rc = internalModuleStat(requestPath);
103+
const rc = internalModuleStat(path._makeLong(requestPath));
104104
return rc === 0 && toRealPath(requestPath);
105105
}
106106

@@ -146,7 +146,7 @@ Module._findPath = function(request, paths) {
146146
var filename;
147147

148148
if (!trailingSlash) {
149-
const rc = internalModuleStat(basePath);
149+
const rc = internalModuleStat(path._makeLong(basePath));
150150
if (rc === 0) { // File.
151151
filename = toRealPath(basePath);
152152
} else if (rc === 1) { // Directory.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
var common = require('../common');
3+
var fs = require('fs');
4+
var path = require('path');
5+
var assert = require('assert');
6+
7+
// make a path that is more than 260 chars long.
8+
var fileNameLen = Math.max(261 - common.tmpDir.length - 1, 1);
9+
var fileName = path.join(common.tmpDir, new Array(fileNameLen + 1).join('x'));
10+
var fullPath = path.resolve(fileName);
11+
12+
common.refreshTmpDir();
13+
fs.writeFileSync(fullPath, 'module.exports = 42;');
14+
15+
assert.equal(require(fullPath), 42);
16+
17+
fs.unlinkSync(fullPath);

0 commit comments

Comments
 (0)