Skip to content

Seemingly-inconsistent fallback behavior #15

@jugglinmike

Description

@jugglinmike

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions