Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: allow long paths for require on Windows #1991

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function readPackage(requestPath) {
}

var jsonPath = path.resolve(requestPath, 'package.json');
var json = internalModuleReadFile(jsonPath);
var json = internalModuleReadFile(path._makeLong(jsonPath));

if (json === undefined) {
return false;
Expand Down Expand Up @@ -100,7 +100,7 @@ Module._realpathCache = {};

// check if the file exists and is not a directory
function tryFile(requestPath) {
const rc = internalModuleStat(requestPath);
const rc = internalModuleStat(path._makeLong(requestPath));
return rc === 0 && toRealPath(requestPath);
}

Expand Down Expand Up @@ -146,7 +146,7 @@ Module._findPath = function(request, paths) {
var filename;

if (!trailingSlash) {
const rc = internalModuleStat(basePath);
const rc = internalModuleStat(path._makeLong(basePath));
if (rc === 0) { // File.
filename = toRealPath(basePath);
} else if (rc === 1) { // Directory.
Expand Down
17 changes: 17 additions & 0 deletions test/parallel/test-require-long-path.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';
var common = require('../common');
var fs = require('fs');
var path = require('path');
var assert = require('assert');

// make a path that will be at least 260 chars long.
var fileNameLen = Math.max(260 - common.tmpDir.length - 1, 1);
var fileName = path.join(common.tmpDir, new Array(fileNameLen + 1).join('x'));
var fullPath = path.resolve(fileName);

common.refreshTmpDir();
fs.writeFileSync(fullPath, 'module.exports = 42;');

assert.equal(require(fullPath), 42);

fs.unlinkSync(fullPath);