5.9.1 • Published 3 months ago

lockfile-lint-api v5.9.1

Weekly downloads
70,026
License
Apache-2.0
Repository
github
Last release
3 months ago

About

Lints an npm or yarn lockfile to analyze and detect issues

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 APIdescriptionimplemented
ValidateHttpsvalidates the use of HTTPS as protocol schema for all resources
ValidateHostvalidates a whitelist of allowed hosts to be used for resources in the lockfile
ValidatePackageNamesvalidates that the resolved URL matches the package name
ValidateSchemevalidates a whitelist of allowed URI schemes to be used for hosts
ValidateIntegrityvalidates that the integrity hash type is sha512

NOTE: package entries without a resolved field (for example, those installed from the local filesystem) will automatically pass all url-based validators.

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) {
  // something bad happened during validation and the validation
  // process couldn't take place
}

console.log(result)
/* prints
{
  "type": "error",
  "errors": [
    {
      "message": "detected invalid origin for package: meow",
      "package": "meow"
    }
  ]
}
*/

Example

const {ValidateHost, ParseLockfile} = require('lockfile-lint-api')

// path to the lockfile
const yarnLockfilePath = '/path/to/my/yarn.lock'
const options = {
  lockfilePath: yarnLockfilePath
}

// instantiate a new parser with options object
const parser = new ParseLockfile(options)

// read the file synchronously and parses it
// providing back an object that is compatible
// with the @yarn/lockfile library which has
// all the packages listed in `lockfile.object`
const lockfile = parser.parseSync()

// now instantiate a validator object with those
// list of packages
const validator = new ValidateHost({packages: lockfile.object})
let result
try {
  // validation is synchronous and is being called
  // with 'npm' as a shortcut for the npm registry
  // host to validate all lockfile resources are
  // whitelisted to the npm host
  result = validator.validate(['npm'])
} catch (error) {
  // couldn't process the validation
}

if (result.type === 'success') {
  // validation succeeded
}

Contributing

Please consult CONTRIBUTING for guidelines on contributing to this project.

Author

lockfile-lint-api © Liran Tal, Released under the Apache-2.0 License.

5.9.1

3 months ago

5.9.0

3 months ago

5.8.0

9 months ago

5.6.0

9 months ago

5.5.5

12 months ago

5.5.4

12 months ago

5.5.3

12 months ago

5.7.0

9 months ago

5.5.2

12 months ago

5.5.1

1 year ago

5.5.0

1 year ago

5.4.6

2 years ago

5.4.2

2 years ago

5.4.1

2 years ago

5.4.0

2 years ago

5.4.5

2 years ago

5.4.4

2 years ago

5.4.3

2 years ago

5.3.0

2 years ago

5.2.7

2 years ago

5.2.6

2 years ago

5.2.5

2 years ago

5.2.4

2 years ago

5.2.3

2 years ago

5.1.7

3 years ago

5.1.6

4 years ago

5.1.5

4 years ago

5.1.2

4 years ago

5.1.1

4 years ago

5.1.0

4 years ago

5.0.12

4 years ago

5.0.11

4 years ago

5.0.10

4 years ago

5.0.9

4 years ago

5.0.8

4 years ago

5.0.7

4 years ago

5.0.6

4 years ago

5.0.5

4 years ago

5.0.4

4 years ago

5.0.3

4 years ago

5.0.2

4 years ago

5.0.0

4 years ago

2.3.0

4 years ago

2.2.0

5 years ago

2.1.4

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.0

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.1

5 years ago