Skip to content
This repository has been archived by the owner on Mar 8, 2024. It is now read-only.
/ package-resolve Public archive

Simple way to get the package.json for any installed package.

License

Notifications You must be signed in to change notification settings

CliffS/package-resolve

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

package-resolve

Simple way to get the package.json for any installed package.

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.

Install

npm install package-resolve

Example

The example is based on having installed bootstrap. It does not need to have been required.

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"

Usage

new

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.

package

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.

resolve

pack.resolve()
.then (file) =>
  // file contains the path of the `main` file in the package.json
.catch (err) =>
  console.error(err);

style

pack.style()
.then (file) =>
  // file contains the path of the file referred to in the style key
.catch (err) =>
  console.error(err);

readPackage

pack.readPackage()
.then (obj) =>
  // obj contains the contents of package.json as an object
.catch (err) =>
  console.error(err);

readStyle

pack.readPackage()
.then (css) =>
  // css contains the css as a string
.catch (err) =>
  console.error(err);

Problems

Any issues or comments would be appreciated at Github

Pull requests are welcome.

About

Simple way to get the package.json for any installed package.

Resources

License

Stars

Watchers

Forks

Packages

No packages published