Repository: electron-userland/electron-builder
File: packages/app-builder-lib/src/node-module-collector/nodeModulesCollector.ts (TypeScript)

Code before:
        return filePath
      }
    } catch (error: any) {
      log.debug({ message: error.message || error.stack }, "error resolving path")
      return filePath
    }
  }

  private convertToDependencyGraph(tree: DependencyTree, parentKey = "."): DependencyGraph {
    return Object.entries(tree.dependencies || {}).reduce<DependencyGraph>((acc, curr) => {
      const [packageName, dependencies] = curr
      // Skip empty dependencies (like some optionalDependencies)
      if (Object.keys(dependencies).length === 0) {
        return acc
      }
      const version = dependencies.version || ""
      const newKey = `${packageName}@${version}`
      // Map dependency details: name, version and path to the dependency tree
      this.dependencyPathMap.set(newKey, path.normalize(this.resolvePath(dependencies.path)))
      if (!acc[parentKey]) {
        acc[parentKey] = { dependencies: [] }
      }
      acc[parentKey].dependencies.push(newKey)
      if (tree.implicitDependenciesInjected) {
        log.debug(
          {
            dependency: packageName,
            version,
            path: dependencies.path,
            parentModule: tree.name,
            parentVersion: tree.version,
          },
          "converted implicit dependency"
        )
        return acc
      }

      return { ...acc, ...this.convertToDependencyGraph(dependencies, newKey) }
    }, {})
  }

  private collectAllDependencies(tree: DependencyTree) {
    for (const [key, value] of Object.entries(tree.dependencies || {})) {
      if (Object.keys(value.dependencies ?? {}).length > 0) {
        this.allDependencies.set(`${key}@${value.version}`, value)
        this.collectAllDependencies(value)
      }
    }
  }

  private getTreeFromWorkspaces(tree: NpmDependency): NpmDependency {

Review comment (bug):
If the `path` is empty or `undefined`, could we add a debug log here? Several bugs that have been discovered recently often occur when the `path` is empty.


Code after:
    }
  }

  private convertToDependencyGraph(tree: DependencyTree, parentKey = "."): DependencyGraph {
    return Object.entries(tree.dependencies || {}).reduce<DependencyGraph>((acc, curr) => {
      const [packageName, dependencies] = curr
      // Skip empty dependencies (like some optionalDependencies)
      if (Object.keys(dependencies).length === 0) {
        return acc
      }
      const version = dependencies.version || ""
      const newKey = `${packageName}@${version}`
      if (!dependencies.path) {
        log.error(
          {
            packageName,
            data: dependencies,
            parentModule: tree.name,
            parentVersion: tree.version,
          },
          "dependency path is undefined"
        )
        throw new Error("unable to parse `path` during `tree.dependencies` reduce")
      }
      // Map dependency details: name, version and path to the dependency tree
      this.dependencyPathMap.set(newKey, path.normalize(this.resolvePath(dependencies.path)))
      if (!acc[parentKey]) {
        acc[parentKey] = { dependencies: [] }
      }
      acc[parentKey].dependencies.push(newKey)
      if (tree.implicitDependenciesInjected) {
        log.debug(
          {
            dependency: packageName,
            version,
            path: dependencies.path,
            parentModule: tree.name,
            parentVersion: tree.version,
          },
          "converted implicit dependency"
        )
        return acc
      }

      return { ...acc, ...this.convertToDependencyGraph(dependencies, newKey) }
    }, {})
  }

  private collectAllDependencies(tree: Dependency<T, OptionalsType>) {
    for (const [key, value] of Object.entries(tree.dependencies || {})) {
      if (Object.keys(value.dependencies ?? {}).length > 0) {