-
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.
- Loading branch information
1 parent
f83ca44
commit 2c73669
Showing
22 changed files
with
93 additions
and
93 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
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 |
---|---|---|
|
@@ -128,9 +128,9 @@ func (p *Parser) parseV2(packages map[string]Package) ([]ftypes.Package, []ftype | |
} | ||
} | ||
|
||
pkgIndirect := isIndirectLib(pkgPath, directDeps) | ||
pkgIndirect := isIndirectPkg(pkgPath, directDeps) | ||
|
||
// There are cases when similar libraries use same dependencies | ||
// There are cases when similar packages use same dependencies | ||
// we need to add location for each these dependencies | ||
if savedPkg, ok := pkgs[pkgID]; ok { | ||
savedPkg.Dev = savedPkg.Dev && pkg.Dev | ||
|
@@ -150,7 +150,7 @@ func (p *Parser) parseV2(packages map[string]Package) ([]ftypes.Package, []ftype | |
continue | ||
} | ||
|
||
lib := ftypes.Package{ | ||
newPkg := ftypes.Package{ | ||
ID: pkgID, | ||
Name: pkgName, | ||
Version: pkg.Version, | ||
|
@@ -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}, | ||
} | ||
pkgs[pkgID] = lib | ||
pkgs[pkgID] = newPkg | ||
|
||
// npm builds graph using optional deps. e.g.: | ||
// └─┬ [email protected] | ||
|
@@ -179,7 +179,7 @@ func (p *Parser) parseV2(packages map[string]Package) ([]ftypes.Package, []ftype | |
|
||
if len(dependsOn) > 0 { | ||
deps = append(deps, ftypes.Dependency{ | ||
ID: lib.ID, | ||
ID: newPkg.ID, | ||
DependsOn: dependsOn, | ||
}) | ||
} | ||
|
@@ -302,23 +302,23 @@ func (p *Parser) parseV1(dependencies map[string]Dependency, versions map[string | |
pkgs = append(pkgs, pkg) | ||
|
||
dependsOn := make([]string, 0, len(dep.Requires)) | ||
for libName, requiredVer := range dep.Requires { | ||
for pName, requiredVer := range dep.Requires { | ||
// Try to resolve the version with nested dependencies first | ||
if resolvedDep, ok := dep.Dependencies[libName]; ok { | ||
libID := packageID(libName, resolvedDep.Version) | ||
dependsOn = append(dependsOn, libID) | ||
if resolvedDep, ok := dep.Dependencies[pName]; ok { | ||
pkgID := packageID(pName, resolvedDep.Version) | ||
dependsOn = append(dependsOn, pkgID) | ||
continue | ||
} | ||
|
||
// Try to resolve the version with the higher level dependencies | ||
if ver, ok := versions[libName]; ok { | ||
dependsOn = append(dependsOn, packageID(libName, ver)) | ||
if ver, ok := versions[pName]; ok { | ||
dependsOn = append(dependsOn, packageID(pName, ver)) | ||
continue | ||
} | ||
|
||
// It should not reach here. | ||
p.logger.Warn("Unable to resolve the version", | ||
log.String("name", libName), log.String("version", requiredVer)) | ||
log.String("name", pName), log.String("version", requiredVer)) | ||
} | ||
|
||
if len(dependsOn) > 0 { | ||
|
@@ -370,10 +370,10 @@ func uniqueDeps(deps []ftypes.Dependency) []ftypes.Dependency { | |
return uniqDeps | ||
} | ||
|
||
func isIndirectLib(pkgPath string, directDeps map[string]struct{}) bool { | ||
func isIndirectPkg(pkgPath string, directDeps map[string]struct{}) bool { | ||
// A project can contain 2 different versions of the same dependency. | ||
// e.g. `node_modules/string-width/node_modules/strip-ansi` and `node_modules/string-ansi` | ||
// direct dependencies always have root path (`node_modules/<lib_name>`) | ||
// direct dependencies always have root path (`node_modules/<pkg_name>`) | ||
if _, ok := directDeps[pkgPath]; ok { | ||
return false | ||
} | ||
|
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 |
---|---|---|
|
@@ -10,7 +10,7 @@ var ( | |
// npm install --save-dev [email protected] | ||
// npm install --save-optional promise | ||
// npm i --lockfile-version 1 | ||
// libraries are filled manually | ||
// packages are filled manually | ||
|
||
npmV1Pkgs = []ftypes.Package{ | ||
{ | ||
|
@@ -694,7 +694,7 @@ var ( | |
|
||
// ... and | ||
// npm i --lockfile-version 2 | ||
// same as npmV1Pkgs but change `Indirect` field to false for `[email protected]`, `[email protected]`, `@babel/[email protected]`, `[email protected]` and `[email protected]` libraries. | ||
// same as npmV1Pkgs but change `Indirect` field to false for `[email protected]`, `[email protected]`, `@babel/[email protected]`, `[email protected]` and `[email protected]` packages. | ||
// also need to get locations from `packages` struct | ||
// --- lockfile version 3 --- | ||
// npm i --lockfile-version 3 | ||
|
@@ -1312,7 +1312,7 @@ var ( | |
// grep -v "functions/func1" ./package.json > tmpfile && mv tmpfile ./package.json | ||
// sed -i 's/functions\/nested_func/functions\/*/g' package.json | ||
// npm update | ||
// libraries are filled manually | ||
// packages are filled manually | ||
npmV3WithWorkspacePkgs = []ftypes.Package{ | ||
{ | ||
ID: "[email protected]", | ||
|
@@ -1448,7 +1448,7 @@ var ( | |
// npm init --force | ||
// npm init -w ./functions/func1 --force | ||
// npm install --save [email protected] -w func1 | ||
// libraries are filled manually | ||
// packages are filled manually | ||
npmV3WithoutRootDepsField = []ftypes.Package{ | ||
{ | ||
ID: "[email protected]", | ||
|
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
Oops, something went wrong.