-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: wrap yarn parser to return patterns + compare patterns
- Loading branch information
1 parent
0e286f0
commit 160ab40
Showing
3 changed files
with
33 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -269,7 +269,7 @@ func parseDependency(line string) (string, error) { | |
} | ||
} | ||
|
||
func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependency, error) { | ||
func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependency, map[string]string, error) { | ||
lineNumber := 1 | ||
var pkgs []ftypes.Package | ||
|
||
|
@@ -285,7 +285,7 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependenc | |
lib, deps, newLine, err := p.parseBlock(block, lineNumber) | ||
lineNumber = newLine + 2 | ||
if err != nil { | ||
return nil, nil, err | ||
return nil, nil, nil, err | ||
} else if lib.Name == "" { | ||
continue | ||
} | ||
|
@@ -310,13 +310,13 @@ func (p *Parser) Parse(r xio.ReadSeekerAt) ([]ftypes.Package, []ftypes.Dependenc | |
} | ||
|
||
if err := scanner.Err(); err != nil { | ||
return nil, nil, xerrors.Errorf("failed to scan yarn.lock, got scanner error: %s", err.Error()) | ||
return nil, nil, nil, xerrors.Errorf("failed to scan yarn.lock, got scanner error: %s", err.Error()) | ||
} | ||
|
||
// Replace dependency patterns with library IDs | ||
// e.g. ajv@^6.5.5 => [email protected] | ||
deps := parseResults(patternIDs, dependsOn) | ||
return pkgs, deps, nil | ||
return pkgs, deps, lo.Invert(patternIDs), nil | ||
} | ||
|
||
func packageID(name, version string) string { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters