(ctx context.Context, parent *model.File, files []*model.File, call model.ResCallback)
| 24 | } |
| 25 | |
| 26 | func (sca Sca) Sca(ctx context.Context, parent *model.File, files []*model.File, call model.ResCallback) { |
| 27 | |
| 28 | // map[dirpath] |
| 29 | jsonMap := map[string]*PackageJson{} |
| 30 | jsonNameMap := map[string]*PackageJson{} |
| 31 | // map[dirpath] |
| 32 | lockMap := map[string]*PackageLock{} |
| 33 | // map[dirpath] |
| 34 | nodeMap := map[string]*PackageJson{} |
| 35 | // map[dirpath] |
| 36 | yarnMap := map[string]map[string]*YarnLock{} |
| 37 | |
| 38 | // 将npm相关文件按上述方案分类 |
| 39 | for _, f := range files { |
| 40 | |
| 41 | dir := filepath.Dir(strings.ReplaceAll(f.Relpath(), `\`, `/`)) |
| 42 | |
| 43 | if filter.JavaScriptYarnLock(f.Relpath()) { |
| 44 | yarnMap[dir] = ParseYarnLock(f) |
| 45 | } |
| 46 | |
| 47 | if filter.JavaScriptPackageJson(f.Relpath()) { |
| 48 | var js *PackageJson |
| 49 | f.OpenReader(func(reader io.Reader) { |
| 50 | js = readJson[PackageJson](reader) |
| 51 | if js == nil { |
| 52 | return |
| 53 | } |
| 54 | if js.Dependencies == nil { |
| 55 | js.Dependencies = map[string]string{} |
| 56 | } |
| 57 | // 记录peerDependencies |
| 58 | for k, v := range js.PeerDependencies { |
| 59 | js.Dependencies[k] = v |
| 60 | } |
| 61 | js.File = f |
| 62 | if strings.Contains(f.Relpath(), "node_modules") { |
| 63 | nodeMap[dir] = js |
| 64 | } else { |
| 65 | jsonMap[dir] = js |
| 66 | jsonNameMap[js.Name] = js |
| 67 | } |
| 68 | }) |
| 69 | } |
| 70 | |
| 71 | if filter.JavaScriptPackageLock(f.Relpath()) { |
| 72 | f.OpenReader(func(reader io.Reader) { |
| 73 | lock := readJson[PackageLock](reader) |
| 74 | if lock == nil { |
| 75 | return |
| 76 | } |
| 77 | lockMap[dir] = lock |
| 78 | }) |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | // 遍历非node_modules下的package.json |
| 83 | for dir, js := range jsonMap { |
nothing calls this directly
no test coverage detected