geoffdavis92 / require.mjs

Require local JSON files in files utilizing the Node.js v8.5.0 .mjs/--experimental module system
MIT License
2 stars 0 forks source link

Use v8 internals to figure out caller path #1

Open zcei opened 7 years ago

zcei commented 7 years ago

Just stumbled across your post about this repo, so here are my 2 cents:

If you don't mind using VM specifics (i.e. v8 specifics, might not work out of the box with chakra for example), you can use internal stack properties to get the file path of the caller.

By now there are multiple implementations utilizing this, where the most used is callsites, followed by stack-trace.

Might not be the best solution in terms of performance (tbh: no clue), but for just "shimming" the JSON requires on start-up time, it should be sufficient.

geoffdavis92 commented 7 years ago

@zcei thanks for dropping a line!

This is pretty interesting, and I'll check that how this may be implemented in a module; callsites looks promising, but I like that stack-traces allows for error handling.