Skip to content

Commit

Permalink
Merge pull request #775 from oclif/mdonnalley/deterministic-inspect
Browse files Browse the repository at this point in the history
fix: make dep resolution deterministic
  • Loading branch information
shetzel committed Jan 22, 2024
2 parents 160d4e2 + 3c02f0c commit 6eec1e8
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/commands/plugins/inspect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,21 @@ export default class PluginsInspect extends Command {
paths.push(start)
}

try {
return await Promise.any(
paths.map(async (p) => {
const fullPath = join(p, dependencyPath)
const pkgJsonPath = join(fullPath, 'package.json')
const pkgJson = JSON.parse(await readFile(pkgJsonPath, 'utf8'))
return {pkgPath: fullPath, version: pkgJson.version as string}
}),
)
} catch {
return {pkgPath: null, version: null}
// NOTE: we cannot parallelize this because we need to check the paths in the order they were found.
// Parallelizing this would be faster, but would make the result non-deterministic.
for (const p of paths) {
try {
const fullPath = join(p, dependencyPath)
const pkgJsonPath = join(fullPath, 'package.json')
// eslint-disable-next-line no-await-in-loop
const pkgJson = JSON.parse(await readFile(pkgJsonPath, 'utf8'))
return {pkgPath: fullPath, version: pkgJson.version as string}
} catch {
// try the next path
}
}

return {pkgPath: null, version: null}
}

findPlugin(pluginName: string): Plugin {
Expand Down

0 comments on commit 6eec1e8

Please sign in to comment.