This finds the package.json
for any package installed in node_modules
so that if can be accessed by the running server.
It can also find the main
key and a style
key as well as
returning the package.json
as an object or the css as a
string.
This package uses native Promises throughout.
npm install package-resolve
The example is based on having installed bootstrap. It does
not need to have been require
d.
Pack = require('package-resolve');
pack = new Pack('bootstrap');
pack.package()
.then (file) =>
// file contains the path of the package.json file
.catch (err) =>
// err contains a descriptive error such as "File not found"
Pack = require('package-resolve');
pack = new Pack(<package to find>);
This should be passed the name of the package to find as listed under
dependencies
in our package.json
.
pack.package()
.then (file) =>
// file contains the path of the package.json file
.catch (err) =>
// err contains a descriptive error such as "File not found"
This returns a Promise that resolves to the full path of the package.json
file for this dependency.
pack.resolve()
.then (file) =>
// file contains the path of the `main` file in the package.json
.catch (err) =>
console.error(err);
pack.style()
.then (file) =>
// file contains the path of the file referred to in the style key
.catch (err) =>
console.error(err);
pack.readPackage()
.then (obj) =>
// obj contains the contents of package.json as an object
.catch (err) =>
console.error(err);
pack.readPackage()
.then (css) =>
// css contains the css as a string
.catch (err) =>
console.error(err);
Any issues or comments would be appreciated at Github
Pull requests are welcome.