any-promise icon indicating copy to clipboard operation
any-promise copied to clipboard

Try to require from the main modules view point

Open maxnordlund opened this issue 8 years ago • 7 comments

This should make it more robust, since it will more closely match the applications require behaviour.

maxnordlund avatar Jul 03 '16 21:07 maxnordlund

Thanks. I haven't had a chance to really look at this, but seems like a good idea. I'll have to look at why the tests are failing though.

kevinbeaty avatar Jul 11 '16 23:07 kevinbeaty

In what situation would require.main.require work? I didn't really see anything documented in that regard on a quick look.

kevinbeaty avatar Jul 11 '16 23:07 kevinbeaty

It doesn't work in the REPL, but other then that it should always work. Basically, if there's an entry point (unlike the REPL), there's an main module. E.g. node foo.js -> foo.js is the main module.

maxnordlund avatar Jul 12 '16 09:07 maxnordlund

Regarding the tests, it may be that it tries to require from within mocha, which should be solvable by using a local copy instead of the global one.

maxnordlund avatar Jul 12 '16 09:07 maxnordlund

@jamestalmage Do you have any thoughts on preferring require.main.require for use with auto-detection of an implementation? This would apply more to any-observable since global Promise are more common and would be preferred.

kevinbeaty avatar Jul 20 '16 15:07 kevinbeaty

Hmm. I think I would be tempted to use caller instead of main.

jamestalmage avatar Jul 20 '16 15:07 jamestalmage

@sindresorhus

jamestalmage avatar Jul 20 '16 15:07 jamestalmage