Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Jan 16, 2022
1 parent 3b3e290 commit 96a9ed4
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/top/system/versions/compute.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import mapObj from 'map-obj'
import pProps from 'p-props'

import { PluginError } from '../../../error/main.js'
import { mapValues } from '../../../utils/map.js'
import { mapValues, mapKeys } from '../../../utils/map.js'
import { spawnProcess } from '../../../utils/spawn.js'

import { VERSIONS_VALUE_SEPARATOR } from './merge.js'
Expand All @@ -24,13 +23,14 @@ export const computeRunnerVersions = async function ({
spawnOptions,
cwd,
}) {
const dedupedVersions = mapObj(versions, dedupeVersion)
const dedupedVersionsA = await pProps(dedupedVersions, ({ name, version }) =>
const dedupedVersions = mapValues(versions, keepOriginalName)
const dedupedVersionsA = mapKeys(dedupedVersions, dedupeVersion)
const dedupedVersionsB = await pProps(dedupedVersionsA, ({ name, version }) =>
computeRunnerVersion({ name, version, id, spawnOptions, cwd }),
)
const versionsA = mapValues(
versions,
(version) => dedupedVersionsA[serializeVersion(version)],
(version) => dedupedVersionsB[serializeVersion(version)],
)
return { ...versionsA, ...commonVersions }
}
Expand All @@ -43,8 +43,12 @@ export const computeRunnerVersions = async function ({
// - The performance benefit is minimal, since it would reduce the
// parallelization of retrieving task paths, which is much slower
// - Runners have different `id` to report in the error message
const dedupeVersion = function (name, version) {
return [serializeVersion(version), { name, version }]
const keepOriginalName = function (version, name) {
return { version, name }
}

const dedupeVersion = function (name, { version }) {
return serializeVersion(version)
}

const serializeVersion = function (version) {
Expand Down

0 comments on commit 96a9ed4

Please sign in to comment.