moroshko / react-scanner

Extract React components and props usage from code.
MIT License
563 stars 40 forks source link

Remove exit(1) when no files found to scan #64

Open Janey2022 opened 1 year ago

Janey2022 commented 1 year ago

With the origin logic, if I run it in the cases that contains several dirs, it will break when found one has no matched file to scan.

Janey2022 commented 1 year ago

It seems not a good approach. But still need to handle the issue when the loop exit in some cases.

FelipeNasci commented 1 year ago

How about throwing an exception in this case?

That way, we can catch the error with a try{} catch(){}

Janey2022 commented 1 year ago

How about throwing an exception in this case?

That way, we can catch the error with a try{} catch(){}

Good point, yes, if we use process.exit instead of exception, try catch can't catch process.exit(1). Should throw exception instead.

gyfchong commented 1 year ago

Fixes https://github.com/moroshko/react-scanner/issues/68

JulianNymark commented 4 months ago

For those waiting for this to merge; we use the following monkey patch at work. 🐒

  {
    const old_exit = process.exit;
    // @ts-ignore monkey patching
    process.exit = () => {};

    await scanner.run(/* ...code... */);

    process.exit = old_exit;
  }