lockfile-lint-api
Lint an npm or yarn lockfile to analyze and detect issues
About
Lints an npm or yarn lockfile to analyze and detect issues
NOTE: currently only yarn's yarn.lock
is supported. PRs to support npm's package-lock.json
are welcome 🤗
Install
npm install --save lockfile-lint-api
Usage
lockfile-lint-api
exposes a set of validator APIs that can be used for programmatic use-cases, such as being employed by other tools and programs if needed.
Validators
The following lockfile validators are supported
Validator API | description | implemented |
---|
ValidateHttps | validates the use of HTTPS as protocol schema for all resources | ✅ |
ValidateHost | validates a whitelist of allowed hosts to be used for resources in the lockfile | ✅ |
Success and failures
When validators encounter errors they will throw an exception, and on either success or failure in validating data they will always return a descriptive object for the validation task.
Successful validation
When validation is successful the following object will be returned from the validating function:
{
"type": "success",
"errors": []
}
Failed validation
When validation has failed the following object will be returned from the validating function:
{
"type": "error",
"errors": [
{
"package": "@babel/cli",
"message": "detected invalid origin for package: @babel/cli"
}
]
}
Notes about the returned object:
- An errors object will always return an array of errors metadata, even if there's only one error associated with the validation being performed
- All errors should always have a message
- The availability of the
package
property and other metadata depends on the specific validators being used
Example
const validator = new ValidateHost({packages: lockfile.object})
let result
try {
result = validator.validate(['npm'])
} catch (error) {
}
console.log(result)
Example
const {ValidateHost, ParseLockFile} = require('lockfile-lint-api')
const yarnLockFilePath = '/path/to/my/yarn.lock'
const options = {
lockFilePath: yarnLockFilePath
}
const parser = new ParseLockFile(options)
const lockfile = parser.parseSync()
const validator = new ValidateHost({packages: lockfile.object})
let result
try {
result = validator.validate(['npm'])
} catch (error) {
}
if (result.type === 'success') {
}
Contributing
Please consult CONTIRBUTING for guidelines on contributing to this project.
Author
lockfile-lint-api © Liran Tal, Released under the Apache-2.0 License.