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
cmd: support dash as stdin alias #13012
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,10 @@ node \- Server-side JavaScript runtime | |
.RI [ v8\ options ] | ||
.RI [ script.js \ | | ||
.B -e | ||
.RI \&" script \&"] | ||
.RI \&" script \&" | ||
.R | | ||
.B - | ||
.R ] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be condensed into one line as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Never had experience of doc writing using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just took a look and this does appear to be correct. |
||
.B [--] | ||
.RI [ arguments ] | ||
.br | ||
|
@@ -225,6 +228,12 @@ See \fBSSL_CERT_DIR\fR and \fBSSL_CERT_FILE\fR. | |
.BR \-\-icu\-data\-dir =\fIfile\fR | ||
Specify ICU data load path. (overrides \fBNODE_ICU_DATA\fR) | ||
|
||
.TP | ||
.BR \-\fR | ||
Alias for stdin, analogous to the use of - in other command line utilities, | ||
meaning that the script will be read from stdin, and the rest of the options | ||
are passed to that script. | ||
|
||
.TP | ||
.BR \-\-\fR | ||
Indicate the end of node options. Pass the rest of the arguments to the script. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,7 +123,7 @@ | |
const internalModule = NativeModule.require('internal/module'); | ||
internalModule.addBuiltinLibsToObject(global); | ||
evalScript('[eval]'); | ||
} else if (process.argv[1]) { | ||
} else if (process.argv[1] && process.argv[1] !== '-') { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got you There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We already use |
||
// make process.argv[1] into a full path | ||
const path = NativeModule.require('path'); | ||
process.argv[1] = path.resolve(process.argv[1]); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3586,7 +3586,7 @@ void LoadEnvironment(Environment* env) { | |
static void PrintHelp() { | ||
// XXX: If you add an option here, please also add it to doc/node.1 and | ||
// doc/api/cli.md | ||
printf("Usage: node [options] [ -e script | script.js ] [arguments]\n" | ||
printf("Usage: node [options] [ -e script | script.js | - ] [arguments]\n" | ||
" node inspect script.js [arguments]\n" | ||
"\n" | ||
"Options:\n" | ||
|
@@ -3598,6 +3598,8 @@ static void PrintHelp() { | |
" does not appear to be a terminal\n" | ||
" -r, --require module to preload (option can be " | ||
"repeated)\n" | ||
" - script read from stdin (default; " | ||
"interactive mode if a tty)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just added this line from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I meant I've copied this literally from the similar place on |
||
#if HAVE_INSPECTOR | ||
" --inspect[=[host:]port] activate inspector on host:port\n" | ||
" (default: 127.0.0.1:9229)\n" | ||
|
@@ -3903,6 +3905,8 @@ static void ParseArgs(int* argc, | |
} else if (strcmp(arg, "--expose-internals") == 0 || | ||
strcmp(arg, "--expose_internals") == 0) { | ||
config_expose_internals = true; | ||
} else if (strcmp(arg, "-") == 0) { | ||
break; | ||
} else if (strcmp(arg, "--") == 0) { | ||
index += 1; | ||
break; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const expected = '--option-to-be-seen-on-child'; | ||
|
||
const { spawn } = require('child_process'); | ||
const child = spawn(process.execPath, ['-', 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); | ||
})); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,31 +2,32 @@ | |
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const spawn = require('child_process').spawn; | ||
const child = spawn(process.execPath, [], { | ||
env: Object.assign(process.env, { | ||
NODE_DEBUG: process.argv[2] | ||
}) | ||
}); | ||
const wanted = `${child.pid}\n`; | ||
let found = ''; | ||
const { spawn } = require('child_process'); | ||
for (const args of [[], ['-']]) { | ||
const child = spawn(process.execPath, args, { | ||
env: Object.assign(process.env, { | ||
NODE_DEBUG: process.argv[2] | ||
}) | ||
}); | ||
const wanted = `${child.pid}\n`; | ||
let found = ''; | ||
|
||
child.stdout.setEncoding('utf8'); | ||
child.stdout.on('data', function(c) { | ||
found += c; | ||
}); | ||
child.stdout.setEncoding('utf8'); | ||
child.stdout.on('data', function(c) { | ||
found += c; | ||
}); | ||
|
||
child.stderr.setEncoding('utf8'); | ||
child.stderr.on('data', function(c) { | ||
console.error(`> ${c.trim().split(/\n/).join('\n> ')}`); | ||
}); | ||
child.stderr.setEncoding('utf8'); | ||
child.stderr.on('data', function(c) { | ||
console.error(`> ${c.trim().split(/\n/).join('\n> ')}`); | ||
}); | ||
|
||
child.on('close', common.mustCall(function(c) { | ||
assert.strictEqual(c, 0); | ||
assert.strictEqual(found, wanted); | ||
console.log('ok'); | ||
})); | ||
child.on('close', common.mustCall(function(c) { | ||
assert.strictEqual(c, 0); | ||
assert.strictEqual(found, wanted); | ||
})); | ||
|
||
setTimeout(function() { | ||
child.stdin.end('console.log(process.pid)'); | ||
}, 1); | ||
setTimeout(function() { | ||
child.stdin.end('console.log(process.pid)'); | ||
}, 1); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: We like an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done for both |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed space after the dash as its section start also is not space padded.