-
Couldn't load subscription status.
- Fork 9
Description
As of version 1.0.2, this module returns the current working directory when the "main" module cannot be identified:
if (main && isIISNode(main)) return handleIISNode(main)
else return main ? main.filename : process.cwd()This means the return value may describe a file or a directory; consumers must determine which before they can use it safely. Because this behavior is undocumented, I first guessed this was an oversight. However, there is an explicit test for it:
it('should default to process.cwd() if require.main is undefined', function () {
requireMainFilename({}).should.match(/require-main-filename/)
})Can any of the maintainers explain the rationale for this behavior? And since it differs from the Node.js feature that this module is intended to mimic, can that be added to the project documentation?
I'm also curious if the function signature could be extended with an "options" object to enable "strict" behavior, where undefined is returned in cases where the main module is undefined.