MCPcopy Create free account
hub / github.com/XmirrorSecurity/OpenSCA-cli / findFromNodeModules

Function findFromNodeModules

opensca/sca/javascript/npm.go:393–409  ·  view source on GitHub ↗

findFromNodeModules 从node_modules中查找使用的package.json name: 查找的组件名 basedir: 当前package.json所在路径 nodePathMap: node_modules中package.json文件的目录映射 例/node_modules/demo jspath: 查找到的package.json所在目录 js: 查找到的package.json

(name, basedir string, nodePathMap map[string]*PackageJson)

Source from the content-addressed store, hash-verified

391// jspath: 查找到的package.json所在目录
392// js: 查找到的package.json
393func findFromNodeModules(name, basedir string, nodePathMap map[string]*PackageJson) (jspath string, js *PackageJson) {
394 const node_modules = "node_modules"
395 paths := strings.Split(strings.ReplaceAll(basedir, `\`, `/`), "/")
396 for i := range paths {
397 tail := len(paths) - i
398 dirs := paths[:tail]
399 if paths[tail-1] != node_modules {
400 dirs = append(dirs, node_modules)
401 }
402 dirs = append(dirs, name)
403 jspath = strings.TrimLeft(strings.Join(dirs, "/"), "/")
404 if js, ok := nodePathMap[jspath]; ok {
405 return jspath, js
406 }
407 }
408 return
409}

Callers 2

ParsePackageJsonWithNodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected