Skip to content

Commit b0d6527

Browse files
committed
fix: clean up the syncVersions code
1 parent e550b92 commit b0d6527

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

dist/node12/setup_cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node12/setup_cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node16/setup_cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/node16/setup_cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/versions/versions.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,25 @@ export function isDefault(version: string | undefined, name: string) {
2929
return version === "true" || (version === undefined && name in DefaultVersions)
3030
}
3131

32+
/**
33+
* Sync the versions for the given inputs
34+
*
35+
* If the return is false, it means that versions don't match the target version
36+
*/
3237
export function syncVersions(opts: Opts, tools: Inputs[]): boolean {
3338
const toolsInUse = tools.filter((tool) => opts[tool] !== undefined)
3439
const toolsNonDefaultVersion = toolsInUse.filter((tool) => !isDefault(opts[tool], tool))
3540

36-
const targetVersion = toolsNonDefaultVersion.length ? opts[toolsNonDefaultVersion[0]] : "true"
41+
const targetVersion = toolsNonDefaultVersion.length >= 1 ? opts[toolsNonDefaultVersion[0]] : "true"
3742

38-
// return false if any explicit versions don't match the target version
39-
if (toolsNonDefaultVersion.findIndex((tool) => opts[tool] !== targetVersion) !== -1) {
43+
if (toolsNonDefaultVersion.some((tool) => opts[tool] !== targetVersion)) {
44+
// error if any explicit versions don't match the target version
4045
return false
4146
}
4247

43-
toolsInUse.forEach((tool) => (opts[tool] = targetVersion))
48+
toolsInUse.forEach((tool) => {
49+
opts[tool] = targetVersion
50+
})
51+
4452
return true
4553
}

0 commit comments

Comments
 (0)