Skip to content

Commit

Permalink
module: fix createRequireFromPath() slash logic
Browse files Browse the repository at this point in the history
The trailing slash detection logic in createRequireFromPath()
seemed slightly incorrect. This commit reworks the logic.

PR-URL: #27634
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
cjihrig committed May 13, 2019
1 parent 6be5c3b commit ef51cc8
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ Module.runMain = function() {
function createRequireFromPath(filename) {
// Allow a directory to be passed as the filename
const trailingSlash =
filename.endsWith(path.sep) || path.sep !== '/' && filename.endsWith('\\');
filename.endsWith('/') || (isWindows && filename.endsWith('\\'));

const proxyPath = trailingSlash ?
path.join(filename, 'noop.js') :
Expand Down

0 comments on commit ef51cc8

Please sign in to comment.