Skip to content
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
2 changes: 2 additions & 0 deletions lib/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ Module._findPath = function(request, paths, isMain) {
if (exts === undefined)
exts = Object.keys(Module._extensions);
filename = tryPackage(basePath, exts, isMain);
} else if (rc === 2) {
filename = basePath;
}

if (!filename) {
Expand Down
12 changes: 10 additions & 2 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,8 @@ static void InternalModuleReadFile(const FunctionCallbackInfo<Value>& args) {
}

// Used to speed up module loading. Returns 0 if the path refers to
// a file, 1 when it's a directory or < 0 on error (usually -ENOENT.)
// a file, 1 when it's a directory, 2 when it's anything else, or < 0 on
// error (usually -ENOENT.)
// The speedup comes from not creating thousands of Stat and Error objects.
static void InternalModuleStat(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Expand All @@ -558,7 +559,14 @@ static void InternalModuleStat(const FunctionCallbackInfo<Value>& args) {
int rc = uv_fs_stat(env->event_loop(), &req, *path, nullptr);
if (rc == 0) {
const uv_stat_t* const s = static_cast<const uv_stat_t*>(req.ptr);
rc = !!(s->st_mode & S_IFDIR);

if (s->st_mode & S_IFREG) {
rc = 0;
} else if (s->st_mode & S_IFDIR) {
rc = 1;
} else {
rc = 2;
}
}
uv_fs_req_cleanup(&req);

Expand Down
23 changes: 23 additions & 0 deletions test/parallel/test-cli-arg-devstdin-posix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
'use strict';
const common = require('../common');

if (common.isWindows) {
common.skip('This test does not apply to Windows.');
return;
}

const assert = require('assert');

const expected = '--option-to-be-seen-on-child';

const { spawn } = require('child_process');
const child = spawn(process.execPath, ['/dev/stdin', expected], { stdio: 'pipe' });

child.stdin.end('console.log(process.argv[2])');

let actual = '';
child.stdout.setEncoding('utf8');
child.stdout.on('data', (chunk) => actual += chunk);
child.stdout.on('end', common.mustCall(() => {
assert.strictEqual(actual.trim(), expected);
}));