forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
module: accept Windows relative path
Before this change, require('.\\test.js') failed while require('./test.js') succeeded. This changes _resolveLookupPaths so that both ways are accepted on Windows. Fixes: nodejs#21918 PR-URL: nodejs#22186 Reviewed-By: Phillip Johnsen <[email protected]> Reviewed-By: John-David Dalton <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
- Loading branch information
1 parent
3993793
commit b36c581
Showing
3 changed files
with
46 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,25 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const _module = require('module'); // avoid collision with global.module | ||
const lookupResults = _module._resolveLookupPaths('./lodash'); | ||
let paths = lookupResults[1]; | ||
|
||
// Current directory gets highest priority for local modules | ||
assert.strictEqual(paths[0], '.'); | ||
function testFirstInPath(moduleName, isLocalModule) { | ||
const assertFunction = isLocalModule ? | ||
assert.strictEqual : | ||
assert.notStrictEqual; | ||
|
||
paths = _module._resolveLookupPaths('./lodash', null, true); | ||
const lookupResults = _module._resolveLookupPaths(moduleName); | ||
|
||
// Current directory gets highest priority for local modules | ||
assert.strictEqual(paths && paths[0], '.'); | ||
let paths = lookupResults[1]; | ||
assertFunction(paths[0], '.'); | ||
|
||
paths = _module._resolveLookupPaths(moduleName, null, true); | ||
assertFunction(paths && paths[0], '.'); | ||
} | ||
|
||
testFirstInPath('./lodash', true); | ||
|
||
// Relative path on Windows, but a regular file name elsewhere | ||
testFirstInPath('.\\lodash', common.isWindows); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters