joyent/node — pull request #4752 by hueniverse (2013-02-11 18:08:34+00:00)
Title: Add require.package() for access to the package.json used by require()

Adds the require.package() method, setup similar to require.resolve(). The method returns the package.json file that is used when loading a module using require(). If the module did not have a package.json, returns undefined. If the module fails to resolve, throws (same as require).

This is useful for building framework plugins utilizing extension keys in package.json, instead of requiring yet another manifest document. My use case is that I need access to the name, version, and dependencies already specified in package.json. I can manually load package.json if the require() call uses absolute path, but that's usually impractical.