Skip to content

Commit

Permalink
Merge pull request #146 from snyk/feat/revert-to-old-package-name-par…
Browse files Browse the repository at this point in the history
…sing-method

feat: remove npa package name parser and revert to old method
  • Loading branch information
xzhou-snyk authored Jun 8, 2022
2 parents 0737f0b + 1ee56f4 commit 10b17e3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
15 changes: 12 additions & 3 deletions lib/cli-parsers/cli-parser-utils.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
import * as semver from 'semver';
import * as npa from 'npm-package-arg';

export const extractNameAndIdentifier = (
candidate: string,
): { name: string; identifier: string } => {
const parsed = npa(candidate);
return { name: parsed.name, identifier: parsed.rawSpec };
let name, identifier;

if (candidate.includes('@')) {
const index = candidate.indexOf('@', 1);
name = candidate.slice(0, index);
identifier = candidate.slice(index + 1);
} else {
name = candidate;
identifier = 'unknown';
}

return { name, identifier };
};

// This function will choose an item in a particular list that satisfies the semver provided
Expand Down
2 changes: 1 addition & 1 deletion lib/parsers/lock-parser-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ export abstract class LockParserBase implements LockfileParser {

subDep = {
name: name,
version: identifier || 'unknown',
version: identifier,
dependencies: {},
labels: {
missingLockFileEntry: 'true',
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
"lodash.flatmap": "^4.5.0",
"lodash.isempty": "^4.4.0",
"lodash.topairs": "^4.3.0",
"npm-package-arg": "^9.0.2",
"semver": "^7.3.5",
"snyk-config": "^4.0.0-rc.2",
"tslib": "^1.9.3",
Expand Down

0 comments on commit 10b17e3

Please sign in to comment.