-
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.
Signed-off-by: knqyf263 <[email protected]>
- Loading branch information
Showing
17 changed files
with
56 additions
and
58 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,21 +132,21 @@ func (p *Parser) parseV2(packages map[string]Package) ([]ftypes.Package, []ftype | |
|
||
// There are cases when similar libraries use same dependencies | ||
// we need to add location for each these dependencies | ||
if savedPkgs, ok := libs[pkgID]; ok { | ||
savedLib.Dev = savedLib.Dev && pkg.Dev | ||
if savedLib.Relationship == ftypes.RelationshipIndirect && !pkgIndirect { | ||
savedLib.Relationship = ftypes.RelationshipDirect | ||
if savedPkg, ok := pkgs[pkgID]; ok { | ||
savedPkg.Dev = savedPkg.Dev && pkg.Dev | ||
if savedPkg.Relationship == ftypes.RelationshipIndirect && !pkgIndirect { | ||
savedPkg.Relationship = ftypes.RelationshipDirect | ||
} | ||
|
||
if ref.URL != "" && !slices.Contains(savedLib.ExternalReferences, ref) { | ||
savedLib.ExternalReferences = append(savedLib.ExternalReferences, ref) | ||
sortExternalReferences(savedLib.ExternalReferences) | ||
if ref.URL != "" && !slices.Contains(savedPkg.ExternalReferences, ref) { | ||
savedPkg.ExternalReferences = append(savedPkg.ExternalReferences, ref) | ||
sortExternalReferences(savedPkg.ExternalReferences) | ||
} | ||
|
||
savedLib.Locations = append(savedLib.Locations, location) | ||
sort.Sort(savedLib.Locations) | ||
savedPkg.Locations = append(savedPkg.Locations, location) | ||
sort.Sort(savedPkg.Locations) | ||
|
||
libs[pkgID] = savedLib | ||
pkgs[pkgID] = savedPkg | ||
continue | ||
} | ||
|
||
|
@@ -159,7 +159,7 @@ func (p *Parser) parseV2(packages map[string]Package) ([]ftypes.Package, []ftype | |
ExternalReferences: lo.Ternary(ref.URL != "", []ftypes.ExternalRef{ref}, nil), | ||
Locations: []ftypes.Location{location}, | ||
} | ||
libs[pkgID] = lib | ||
pkgs[pkgID] = lib | ||
|
||
// npm builds graph using optional deps. e.g.: | ||
// └─┬ [email protected] | ||
|
@@ -186,7 +186,7 @@ func (p *Parser) parseV2(packages map[string]Package) ([]ftypes.Package, []ftype | |
|
||
} | ||
|
||
return maps.Values(libs), deps | ||
return maps.Values(pkgs), deps | ||
} | ||
|
||
// for local package npm uses links. e.g.: | ||
|
@@ -299,7 +299,7 @@ func (p *Parser) parseV1(dependencies map[string]Dependency, versions map[string | |
}, | ||
}, | ||
} | ||
pkgs = append(pkgs, lib) | ||
pkgs = append(pkgs, pkg) | ||
|
||
dependsOn := make([]string, 0, len(dep.Requires)) | ||
for libName, requiredVer := range dep.Requires { | ||
|
@@ -323,15 +323,15 @@ func (p *Parser) parseV1(dependencies map[string]Dependency, versions map[string | |
|
||
if len(dependsOn) > 0 { | ||
deps = append(deps, ftypes.Dependency{ | ||
ID: packageID(lib.Name, lib.Version), | ||
ID: packageID(pkg.Name, pkg.Version), | ||
DependsOn: dependsOn, | ||
}) | ||
} | ||
|
||
if dep.Dependencies != nil { | ||
// Recursion | ||
childLibs, childDeps := p.parseV1(dep.Dependencies, maps.Clone(versions)) | ||
pkgs = append(pkgs, childLibs...) | ||
childpkgs, childDeps := p.parseV1(dep.Dependencies, maps.Clone(versions)) | ||
pkgs = append(pkgs, childpkgs...) | ||
deps = append(deps, childDeps...) | ||
} | ||
} | ||
|
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
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
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 |
---|---|---|
|
@@ -20,7 +20,7 @@ func TestParse(t *testing.T) { | |
{ | ||
name: "happy path", | ||
inputFile: "testdata/happy.lock", | ||
wantLibs: []ftypes.Package{ | ||
wantPkgs: []ftypes.Package{ | ||
{ | ||
ID: "[email protected]", | ||
Name: "AppCenter", | ||
|
@@ -88,7 +88,7 @@ func TestParse(t *testing.T) { | |
gotLibs, gotDeps, err := cocoapods.NewParser().Parse(f) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, tt.wantLibs, gotLibs) | ||
assert.Equal(t, tt.wantPkgs, gotLibs) | ||
assert.Equal(t, tt.wantDeps, gotDeps) | ||
}) | ||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ func TestUniqueLibraries(t *testing.T) { | |
}{ | ||
{ | ||
name: "happy path merge locations", | ||
libs: []ftypes.Package{ | ||
pkgs: []ftypes.Package{ | ||
{ | ||
ID: "[email protected]", | ||
Name: "asn1", | ||
|
@@ -38,7 +38,7 @@ func TestUniqueLibraries(t *testing.T) { | |
}, | ||
}, | ||
}, | ||
wantLibs: []ftypes.Package{ | ||
wantPkgs: []ftypes.Package{ | ||
{ | ||
ID: "[email protected]", | ||
Name: "asn1", | ||
|
@@ -58,7 +58,7 @@ func TestUniqueLibraries(t *testing.T) { | |
}, | ||
{ | ||
name: "happy path Dev and Root deps", | ||
libs: []ftypes.Package{ | ||
pkgs: []ftypes.Package{ | ||
{ | ||
ID: "[email protected]", | ||
Name: "asn1", | ||
|
@@ -72,7 +72,7 @@ func TestUniqueLibraries(t *testing.T) { | |
Dev: false, | ||
}, | ||
}, | ||
wantLibs: []ftypes.Package{ | ||
wantPkgs: []ftypes.Package{ | ||
{ | ||
ID: "[email protected]", | ||
Name: "asn1", | ||
|
@@ -83,7 +83,7 @@ func TestUniqueLibraries(t *testing.T) { | |
}, | ||
{ | ||
name: "happy path Root and Dev deps", | ||
libs: []ftypes.Package{ | ||
pkgs: []ftypes.Package{ | ||
{ | ||
ID: "[email protected]", | ||
Name: "asn1", | ||
|
@@ -97,7 +97,7 @@ func TestUniqueLibraries(t *testing.T) { | |
Dev: true, | ||
}, | ||
}, | ||
wantLibs: []ftypes.Package{ | ||
wantPkgs: []ftypes.Package{ | ||
{ | ||
ID: "[email protected]", | ||
Name: "asn1", | ||
|
@@ -110,8 +110,8 @@ func TestUniqueLibraries(t *testing.T) { | |
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
gotLibs := UniquePackages(tt.libs) | ||
require.Equal(t, tt.wantLibs, gotLibs) | ||
gotLibs := UniquePackages(tt.pkgs) | ||
require.Equal(t, tt.wantPkgs, gotLibs) | ||
}) | ||
} | ||
} |
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
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
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