NodeSecure / scanner

⚡️ A package API to run a static analysis of your module's dependencies. This is the CLI engine!
MIT License
27 stars 14 forks source link

[Tree-walker] Do not use resolveDependencyVersion with local scan strategy #257

Open fraxken opened 1 week ago

fraxken commented 1 week ago

The current implementation of the walk() method uses resolveDependencyVersion, which is useful when combined with walkRemoteDependency.

However, in scenarios where we provide a package-lock.json (or node_modules directory) location to be scanned by Arborist, we could simply iterate over edgesOut.

It should be quite similar to the implementation in walkLocalDependency

for (const [packageName, { to: toNode }] of node.edgesOut) {
  if (toNode === null || (!includeDevDeps && toNode.dev)) {
    continue;
  }
  const spec: NpmSpec = `${packageName}@${toNode.package.version}`;

  if (this.relationsMap.has(spec)) {
    this.relationsMap.get(spec)!.add(current.spec);
  }
}

However not sure how we should re-implement hasOutdatedDependency flag.