Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdin and stdout cannot be process.stdin or process.stdout..? #308

Closed
busticated opened this issue Aug 9, 2020 · 2 comments
Closed

stdin and stdout cannot be process.stdin or process.stdout..? #308

busticated opened this issue Aug 9, 2020 · 2 comments
Labels

Comments

@busticated
Copy link
Contributor

hi there 馃憢

thanks for the awesome lib 馃檹

i ran into some odd behavior and i'm wondering what's up. using this script:

#!/usr/bin/env node

const Enquirer = require('enquirer');


(async () => {
	console.log(':::: Running repro script....');
	try {
		const stdin = process.stdin;
		const stdout = process.stdout;
		const enquirer = new Enquirer({ stdin, stdout });
		const answer = await enquirer.prompt({
			type: 'input',
			name: 'test',
			message: 'Type something...'
		});
		console.log(answer);
	} catch (error){
		console.error(':::: ERROR:', error);
		return process.exit(1);
	}
})();

...i get the following output:

:::: Running repro script....
:::: ERROR: RangeError: Maximum call stack size exceeded
    at Function.keys (<anonymous>)
    at Object.exports.mixin (/Users/me/test/node_modules/enquirer/lib/utils.js:193:26)
    at Object.exports.merge (/Users/me/test/node_modules/enquirer/lib/utils.js:215:33)
    at Object.exports.mixin (/Users/me/test/node_modules/enquirer/lib/utils.js:199:33)
    at Object.exports.merge (/Users/me/test/node_modules/enquirer/lib/utils.js:215:33)
    at Object.exports.mixin (/Users/me/test/node_modules/enquirer/lib/utils.js:199:33)
    at Object.exports.merge (/Users/me/test/node_modules/enquirer/lib/utils.js:215:33)
    at Object.exports.mixin (/Users/me/test/node_modules/enquirer/lib/utils.js:199:33)
    at Object.exports.merge (/Users/me/test/node_modules/enquirer/lib/utils.js:215:33)
    at Object.exports.mixin (/Users/me/test/node_modules/enquirer/lib/utils.js:199:33)

when i delete console.log(':::: Running repro script....');, i get:

(node:13715) UnhandledPromiseRejectionWarning: TypeError: stream.listenerCount is not a function
    at emitKeypressEvents (readline.js:1165:14)
    at new Interface (readline.js:241:5)
    at Object.createInterface (readline.js:92:10)
    at Function.keypress.listen (/Users/me/test/node_modules/enquirer/lib/keypress.js:202:21)
    at Input.start (/Users/me/test/node_modules/enquirer/lib/prompt.js:180:28)
    at Input.initialize (/Users/me/test/node_modules/enquirer/lib/prompt.js:220:16)
    at /Users/me/test/node_modules/enquirer/lib/prompt.js:236:18

when i don't pass in stdin (e.g. new Enquirer({ stdout });), i get:

(node:13725) UnhandledPromiseRejectionWarning: TypeError: this.stdout.write is not a function
    at Input.cursorHide (/Users/me/test/node_modules/enquirer/lib/prompt.js:59:17)
    at module.exports (/Users/me/test/node_modules/enquirer/lib/placeholder.js:19:10)
    at Input.format (/Users/me/test/node_modules/enquirer/lib/types/string.js:156:14)
    at async Input.render (/Users/me/test/node_modules/enquirer/lib/types/string.js:172:18)
    at async Input.initialize (/Users/me/test/node_modules/enquirer/lib/prompt.js:221:5)
    at async /Users/me/test/node_modules/enquirer/lib/prompt.js:236:7

...and the process hangs until i press CTRL+C.

ultimately, i'm trying to wrap enquirer such that a series of ui helpers all use the same stdin, stdout, and stderr in order to make testing easier, etc.

my env info:

  • macOS v10.15.6
  • Node v12.18.3
  • Enquirer v2.3.6
@doowb
Copy link
Member

doowb commented Aug 9, 2020

Hi @busticated and thanks for the issue.

It looks like the merge/mixin logic here needs to take into account that existing.value and desc.value may already be the same object.

Changing the if expression to the following seems to fix it (your repro works and the tests still pass):

if (isObject(existing.value) && existing.value !== desc.value) { ... }

A PR with this change is welcome, otherwise, someone here will try to get it fixed as soon as possible. In the meantime, are you able to write your tests without passing the stdin and stdout into Enquirer?

//edit: btw... huge fan of Particle 馃榾 ... I participated in the original Spark kickstarter, but haven't actively kept up with the latest changes, but looking through the GitHub org, it's great to see all of the Node.js packages.

@doowb doowb added the bug label Aug 9, 2020
@busticated
Copy link
Contributor Author

hi @doowb 馃憢 thanks for taking a look 馃檹

Changing the if expression to the following seems to fix it

yep, that seems to do it - i threw together a PR over here 馃憠 #309 - all feedback welcome.

btw... huge fan of Particle 馃榾

awesome! sent ya an email 馃榿

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants