Resolve the path of a package regardless of it having an entry point
Some packages like CLI tools and grunt tasks don't have a entry point, like
"main": "foo.js" in package.json, resulting in them not being resolvable by
require.resolve(), this module also resolves packages without an entry point, returns
null instead of throwing when the module can't be found, and resolves from
__dirname by default.
$ npm install --save resolve-pkg
const resolvePkg = ;// $ npm install --save-dev grunt-svgmin;//=> '/Users/sindresorhus/unicorn/node_modules/grunt-svgmin/tasks'// Fails here as Grunt tasks usually don't have a defined main entry pointrequire;//=> Error: Cannot find module 'grunt-svgmin'
What you would use in
Directory to resolve from.
- resolve-cwd - Resolve the path of a module from the current working directory
- resolve-from - Resolve the path of a module from a given path
- req-from - Require a module from a given path
- req-cwd - Require a module from the current working directory
- lazy-req - Require modules lazily
MIT © Sindre Sorhus