fix: disable stdin for programatic usage
This commit is contained in:
+1
-1
@@ -2,7 +2,7 @@
|
||||
"name": "nexe",
|
||||
"description": "Create a single executable out of your Node.js application",
|
||||
"license": "MIT",
|
||||
"version": "2.0.0-rc.9",
|
||||
"version": "2.0.0-rc.10",
|
||||
"contributors": [
|
||||
"Craig Condon <craig.j.condon@gmail.com> (http://crcn.io)",
|
||||
"Jared Allard <jaredallard@outlook.com>",
|
||||
|
||||
+2
-1
@@ -34,6 +34,7 @@ export interface NexeOptions {
|
||||
native: any
|
||||
empty: boolean
|
||||
sourceUrl?: string
|
||||
enableStdIn?: boolean
|
||||
python?: string
|
||||
loglevel: 'info' | 'silent' | 'verbose'
|
||||
silent?: boolean
|
||||
@@ -82,7 +83,7 @@ const alias = {
|
||||
l: 'loglevel',
|
||||
'fake-argv': 'fakeArgv'
|
||||
}
|
||||
const argv = parseArgv(process.argv, { alias, default: defaults })
|
||||
const argv = parseArgv(process.argv, { alias, default: { ...defaults, enableStdIn: true } })
|
||||
const g = c.gray
|
||||
let help = `
|
||||
${c.bold('nexe <entry-file> [options]')}
|
||||
|
||||
+15
-12
@@ -5,15 +5,18 @@ import { readFileAsync, dequote, isWindows } from '../util'
|
||||
import { NexeCompiler } from '../compiler'
|
||||
import { NexeTarget } from '../target'
|
||||
|
||||
function readStreamAsync(stream: NodeJS.ReadableStream): PromiseLike<string> {
|
||||
function getStdIn(stdin: NodeJS.ReadStream): Promise<string> {
|
||||
return new Promise(resolve => {
|
||||
let input = ''
|
||||
stream.setEncoding('utf-8')
|
||||
stream.on('data', (x: string) => {
|
||||
input += x
|
||||
})
|
||||
stream.once('end', () => resolve(dequote(input)))
|
||||
stream.resume && stream.resume()
|
||||
let out = ''
|
||||
stdin
|
||||
.setEncoding('utf8')
|
||||
.on('readable', () => {
|
||||
let current
|
||||
while ((current = stdin.read())) {
|
||||
out += current
|
||||
}
|
||||
})
|
||||
.on('end', () => resolve(out))
|
||||
})
|
||||
}
|
||||
|
||||
@@ -34,9 +37,9 @@ function readStreamAsync(stream: NodeJS.ReadableStream): PromiseLike<string> {
|
||||
export default async function cli(compiler: NexeCompiler, next: () => Promise<void>) {
|
||||
const { log } = compiler
|
||||
let stdInUsed = false
|
||||
if (!process.stdin.isTTY) {
|
||||
if (!process.stdin.isTTY && compiler.options.enableStdIn) {
|
||||
stdInUsed = true
|
||||
compiler.input = await readStreamAsync(process.stdin)
|
||||
compiler.input = await getStdIn(process.stdin)
|
||||
}
|
||||
|
||||
await next()
|
||||
@@ -53,10 +56,10 @@ export default async function cli(compiler: NexeCompiler, next: () => Promise<vo
|
||||
if (e) {
|
||||
reject(e)
|
||||
} else if (compiler.output) {
|
||||
chmodSync(compiler.output, '755')
|
||||
chmodSync(compiler.output, '755') //todo fix erroneous rw mode change
|
||||
step.log(
|
||||
`Entry: '${stdInUsed
|
||||
? '[stdin]'
|
||||
? compiler.options.empty ? '[empty]' : '[stdin]'
|
||||
: compiler.options.input}' written to: ${compiler.output}`
|
||||
)
|
||||
resolve(compiler.quit())
|
||||
|
||||
Reference in New Issue
Block a user