Socket
Socket
Sign inDemoInstall

lockfile-lint-api

Package Overview
Dependencies
Maintainers
1
Versions
55
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lockfile-lint-api - npm Package Compare versions

Comparing version 2.1.4 to 2.2.0

src/common/constants.js

11

CHANGELOG.md

@@ -6,2 +6,13 @@ # Change Log

# [2.2.0](https://github.com/lirantal/lockfile-lint/compare/lockfile-lint-api@2.1.4...lockfile-lint-api@2.2.0) (2019-10-24)
### Features
* **errors:** user friendly error messages in lockfile parsing ([#22](https://github.com/lirantal/lockfile-lint/issues/22)) ([17654d0](https://github.com/lirantal/lockfile-lint/commit/17654d0))
## [2.1.4](https://github.com/lirantal/lockfile-lint/compare/lockfile-lint-api@2.1.3...lockfile-lint-api@2.1.4) (2019-10-15)

@@ -8,0 +19,0 @@

4

package.json
{
"name": "lockfile-lint-api",
"version": "2.1.4",
"version": "2.2.0",
"description": "Lint an npm or yarn lockfile to analyze and detect issues",

@@ -176,3 +176,3 @@ "main": "index.js",

},
"gitHead": "ff32753afa5881b06fff6cefa1f19662d561f468"
"gitHead": "dfa2a3021c4567860d3a59f81efea0cef76ec61c"
}

@@ -7,3 +7,3 @@ 'use strict'

* @param {string} packageName - the name of the package where the error occured
* @param {string} error - the original error object
* @param {Error} error - the original error object
*/

@@ -10,0 +10,0 @@ constructor (packageName = '', error = {}) {

@@ -7,2 +7,11 @@ /* eslint-disable security/detect-object-injection */

const yarnLockfileParser = require('@yarnpkg/lockfile')
const {ParsingError, ERROR_MESSAGES} = require('./common/ParsingError')
const {
NO_OPTIONS,
NO_PARSER_FOR_PATH,
NO_PARSER_FOR_TYPE,
READ_FAILED,
PARSE_NPMLOCKFILE_FAILED,
PARSE_YARNLOCKFILE_FAILED
} = ERROR_MESSAGES

@@ -18,3 +27,3 @@ class ParseLockfile {

if (!options || typeof options !== 'object') {
throw new Error('expecting options object')
throw new ParsingError(NO_OPTIONS)
}

@@ -28,2 +37,10 @@

/**
* Checks if lockfile type option was provided
* @return boolean
*/
isLockfileTypeGiven () {
return typeof this.options.lockfileType === 'string' && this.options.lockfileType
}
/**
* Synchronously parses a lockfile

@@ -35,7 +52,16 @@ * @return {object} parsed file

if (!lockfileParser) {
throw new Error('unable to find relevant lockfile parser')
if (this.isLockfileTypeGiven()) {
throw new ParsingError(NO_PARSER_FOR_TYPE, this.options.lockfileType)
}
throw new ParsingError(NO_PARSER_FOR_PATH, this.options.lockfilePath)
}
// eslint-disable-next-line security/detect-non-literal-fs-filename
const file = fs.readFileSync(this.options.lockfilePath, 'utf8')
let file
try {
// eslint-disable-next-line security/detect-non-literal-fs-filename
file = fs.readFileSync(this.options.lockfilePath, 'utf8')
} catch (error) {
throw new ParsingError(READ_FAILED, this.options.lockfilePath, error)
}
return lockfileParser.call(this, file)

@@ -53,3 +79,3 @@ }

let resolver
if (typeof this.options.lockfileType === 'string' && this.options.lockfileType) {
if (this.isLockfileTypeGiven()) {
resolver = lockfileResolversByPackageManager[this.options.lockfileType]

@@ -78,13 +104,23 @@ }

parseYarnLockfile (lockfileBuffer) {
return yarnLockfileParser.parse(lockfileBuffer)
let parsedFile
try {
parsedFile = yarnLockfileParser.parse(lockfileBuffer)
} catch (error) {
throw new ParsingError(PARSE_YARNLOCKFILE_FAILED, this.options.lockfilePath, error)
}
return parsedFile
}
parseNpmLockfile (lockfileBuffer) {
const packageJsonParsed = JSON.parse(lockfileBuffer)
let flattenedDepTree
try {
const packageJsonParsed = JSON.parse(lockfileBuffer)
// transform original format of npm's package-json
// to match yarns so we have a unified format to validate
// against
const npmDepsTree = packageJsonParsed.dependencies
const flattenedDepTree = this._flattenNpmDepsTree(npmDepsTree)
// transform original format of npm's package-json to match yarns
// so we have a unified format to validate against
const npmDepsTree = packageJsonParsed.dependencies
flattenedDepTree = this._flattenNpmDepsTree(npmDepsTree)
} catch (error) {
throw new ParsingError(PARSE_NPMLOCKFILE_FAILED, this.options.lockfilePath, error)
}

@@ -91,0 +127,0 @@ return {

@@ -5,9 +5,4 @@ 'use strict'

const PackageError = require('../common/PackageError')
const {REGISTRY} = require('../common/constants')
const REGISTRY = {
npm: 'registry.npmjs.org',
yarn: 'registry.yarnpkg.com',
verdaccio: 'registry.verdaccio.org'
}
module.exports = class ValidateHost {

@@ -14,0 +9,0 @@ constructor ({packages} = {}) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc