Skip to content

Expose execa Options for Configuring Its Child Process Spawning BehaviorΒ #1019

Closed
@ZheyangSong

Description

Description

I try to use lint-staged to run a custom script. The script reads input from different source based on process.stdin.isTTY.

The code structure is roughly like this:

// custom-script.js
...
const inputStream = process.stdin.isTTY ? Readable.from(process.argv.slice(2)) : process.stdin;

inputStream.on('data', ...);
...

However, when this script is invoked by lint-staged with configured command node custome-script.js, it wrongfully expects input from process.stdin while the input is from process.argv. This is due to how nodeJS's child_process module works: https://nodejs.org/api/child_process.html#child_process_options_stdio

The default pipe stdio option marks process.stdin.isTTY false in spawned child process. Hence, my script gets confused and waits for input while letting lint-staged hang forever...

I'd like to be able to adjust the child_process.spawn's behavior via lint-staged's configuration somehow.

Related code segment: https://github.com/okonet/lint-staged/blob/0ef25e81a150ae59749d28565b305c97ec932baa/lib/resolveTaskFn.js#L92-L105

Steps to reproduce

Try to invoke below script with lint-staged:

const { once } = require('events');
const { Readable } = require('stream');

const inputStream = process.stdin.isTTY ? Readable.from(process.argv.slice(2)) : process.stdin;

(async () => {
  inputStream.on('data', console.log);
  await once(inputStream, 'end');
}())

Debug Logs

N/A

Environment

  • OS: macOS Big Sur
  • Node.js: v12.13.1
  • lint-staged: 11.1.2

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions