AndreasMadsen / trace

Creates super long stack traces
https://trace.js.org
MIT License
194 stars 18 forks source link

Add an `install` method #43

Closed ehmicky closed 6 years ago

ehmicky commented 6 years ago

Would it be a good idea to add an install method that performs asyncHook.createHook() and modifies Error.prepareStackTrace (through stack-chain) instead of automatically doing it when the module is required?

It can already be done right now by conditionally calling require() but this might be problematic when using ES modules and import (until dynamic imports become more supported).

Also it goes against the assumption some users may have, that when they require() a module, it only defines functions and constants and does not perform significant logic.

A good compromise to support both behaviors is often to add a register.js file that performs the modification automatically, and offer an install method in the main export.

There could also be an uninstall method.

AndreasMadsen commented 6 years ago

@ehmicky The reason that if a user does a late install it is impossible to track the async operations.

It also has the added benefit that you can do node -r trace script.js.