Workaround bug with the versions subcomand of older npm versions

This commit is contained in:
Joseph Garrone 2025-01-10 19:07:11 +01:00
parent a085c8093e
commit 158275f5c2
2 changed files with 30 additions and 16 deletions

View File

@ -103,14 +103,21 @@ export async function command(params: { buildContext: BuildContext }) {
const moduleName = `@keycloakify/email-native`;
const [version] = (
JSON.parse(
child_process
.execSync(`npm show ${moduleName} versions --json`)
.toString("utf8")
.trim()
) as string[]
)
const [version] = ((): string[] => {
const cmdOutput = child_process
.execSync(`npm show ${moduleName} versions --json`)
.toString("utf8")
.trim();
const versions = JSON.parse(cmdOutput) as string | string[];
// NOTE: Bug in some older npm versions
if (typeof versions === "string") {
return [versions];
}
return versions;
})()
.reverse()
.filter(version => !version.includes("-"));

View File

@ -105,14 +105,21 @@ export async function initializeSpa(params: {
const moduleName = `@keycloakify/keycloak-${themeType}-ui`;
const version = (
JSON.parse(
child_process
.execSync(`npm show ${moduleName} versions --json`)
.toString("utf8")
.trim()
) as string[]
)
const version = ((): string[] => {
const cmdOutput = child_process
.execSync(`npm show ${moduleName} versions --json`)
.toString("utf8")
.trim();
const versions = JSON.parse(cmdOutput) as string | string[];
// NOTE: Bug in some older npm versions
if (typeof versions === "string") {
return [versions];
}
return versions;
})()
.reverse()
.filter(version => !version.includes("-"))
.find(version =>