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

Code before:
    const { name, version, path, workspaces, dependencies, _dependencies, optionalDependencies, peerDependencies } = npmTree
    const tree: DependencyTree = {
      name,
      version,
      path,
      workspaces,
      implicitDependenciesInjected: false,
    }

    const extractInternal = (deps: NpmDependency["dependencies"]) =>
      deps && Object.keys(deps).length > 0
        ? Object.entries(deps).reduce((accum, [packageName, depObjectOrVersionString]) => {
            return {
              ...accum,
              [packageName]:
                typeof depObjectOrVersionString === "object" && Object.keys(depObjectOrVersionString).length > 0
                  ? this.extractDependencyTree(depObjectOrVersionString as any)
                  : depObjectOrVersionString,
            }
          }, {})
        : undefined

    // only set property if existing, skip undefined (at minimum, it helps in Variables debugger window)
    use(_dependencies, v => (tree._dependencies = v))
    use(optionalDependencies, v => (tree.optionalDependencies = v))
    use(peerDependencies, v => (tree.peerDependencies = v))

    // DFS extract subtree
    use(extractInternal(dependencies), v => (tree.dependencies = v))

    return tree
  }

  protected resolvePath(filePath: string) {
    try {
      const stats = fs.lstatSync(filePath)
      if (stats.isSymbolicLink()) {
        return fs.realpathSync(filePath)
      } else {
        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)

Review comment (suggestion):
We can delete `peerDependencies`. There is no place referencing this peerDependencies, so we can remove it.

Code after:
    // Do not use `...npmTree` as we are explicitly extracting the data we need
    const { name, version, path, workspaces, dependencies } = npmTree
    const tree: Dependency<T, OptionalsType> = {
      name,
      version,
      path,
      workspaces,
      // DFS extract subtree
      dependencies: this.extractInternal(dependencies),
    }

    return tree
  }

  protected extractInternal(deps: T["dependencies"]): T["dependencies"] {
    return deps && Object.keys(deps).length > 0
      ? Object.entries(deps).reduce((accum, [packageName, depObjectOrVersionString]) => {
          return {
            ...accum,
            [packageName]:
              typeof depObjectOrVersionString === "object" && Object.keys(depObjectOrVersionString).length > 0
                ? this.extractRelevantData(depObjectOrVersionString)
                : depObjectOrVersionString,
          }
        }, {})
      : undefined
  }

  protected resolvePath(filePath: string): string {
    try {
      const stats = fs.lstatSync(filePath)
      if (stats.isSymbolicLink()) {
        return fs.realpathSync(filePath)
      } else {
        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}`