Skip to content

Commit

Permalink
module: simplify createRequire() validation
Browse files Browse the repository at this point in the history
PR-URL: nodejs/node#27629
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
cjihrig authored and aduh95 committed Aug 27, 2020
1 parent 8beaac3 commit a3ca21e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/internal/modules/cjs/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -857,10 +857,9 @@ const createRequireError = 'must be a file URL object, file URL string, or' +

function createRequire(filename) {
let filepath;
if (typeof filename === 'object' && !(filename instanceof URL)) {
throw new ERR_INVALID_ARG_VALUE('filename', filename, createRequireError);
} else if (typeof filename === 'object' ||
typeof filename === 'string' && !path.isAbsolute(filename)) {

if (filename instanceof URL ||
(typeof filename === 'string' && !path.isAbsolute(filename))) {
try {
filepath = fileURLToPath(filename);
} catch {
Expand Down

0 comments on commit a3ca21e

Please sign in to comment.