@rowanmanning/package-json-github
v1.0.3
Published
Load and parse package.json and package-lock.json files from GitHub repositories
Downloads
14
Readme
@rowanmanning/package-json-github
Load and parse package.json
and package-lock.json
files from GitHub repositories.
Requirements
This library requires the following to run:
- Node.js 18+
Usage
Install with npm:
npm install @rowanmanning/package-json-github
Load into your code with import
or require
:
import { packageJson, packageLock } from '@rowanmanning/package-json-github';
// or
const { packageJson, packageLock } = require('@rowanmanning/package-json-github');
The following exports are available.
packageJson.fromGitHub()
Load the package.json
file present in a GitHub repo.
(options: GitHubOptions) => Promise<PackageJson>
The options
argument must be an object. The available options are documented here.
const pkg = await packageJson.fromGitHub({
auth: process.env.GITHUB_AUTH_TOKEN,
owner: 'rowanmanning',
repo: 'yeehaw'
});
// { name: '@rowanmanning/yeehaw', version: '2.0.0', ... }
packageLock.fromGitHub()
Load the package-lock.json
file present in a GitHub repo.
(options: GitHubOptions) => Promise<PackageLock>
The options
argument must be an object. The available options are documented here.
const pkg = await packageLock.fromGitHub({
auth: process.env.GITHUB_AUTH_TOKEN,
owner: 'rowanmanning',
repo: 'yeehaw'
});
// { lockfileVersion: 2, name: '@rowanmanning/yeehaw', version: '2.0.0', ... }
Options
The options
argument must be an object. It's required and has the following properties. These are passed directly to the GitHub REST API, please consult the API documentation for more information.
auth
(string
, required). A GitHub token with read access to the repo you specifyowner
(string
, required). The name of the GitHub user or organisation that the repo belongs torepo
(string
, required). The name of the GitHub repopath
(string
, optional). The path to the file you'd like to read. Defaults topackage.json
orpackage-lock.json
depending on the method you're usingref
(string
, optional). The name of the commit, branch, or tag to fetch the file from. Defaults to the repo's default branch
Contributing
See the central README for a contribution guide and code of conduct.
License
Licensed under the MIT license. Copyright © 2024, Rowan Manning