solve problem isntall shadowCljs and npm

This commit is contained in:
ansgarz 2025-01-24 11:44:35 +01:00
parent a35b9552d6
commit 58e413bcab
4 changed files with 18 additions and 12 deletions
src
main
kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure
resources
test/kotlin/org/domaindrivenarchitecture/provs/desktop/infrastructure
testFixtures/kotlin/org/domaindrivenarchitecture/provs/test

View file

@ -2,27 +2,32 @@ package org.domaindrivenarchitecture.provs.desktop.infrastructure
import org.domaindrivenarchitecture.provs.framework.core.Prov
import org.domaindrivenarchitecture.provs.framework.core.ProvResult
import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.aptInstall
import org.domaindrivenarchitecture.provs.framework.ubuntu.install.base.isPackageInstalled
fun Prov.installShadowCljs(): ProvResult = task {
if (!isPackageInstalled("npm")) {
aptInstall("npm")
// installation of npm is too chatty even with quite install and will hang when using Java ProcessBuilder => install with output must be ignored
optional {
// may fail for some packages, but this should in general not be an issue
cmd("sudo apt-get update")
}
cmd("sudo apt-get install -qy apt-utils")
cmd("sudo DEBIAN_FRONTEND=noninteractive apt-get install -qy npm > /dev/null")
cmd("sudo npm install -g npx")
cmd("sudo npm install -g shadow-cljs")
} else {
val npmVersion = cmd("npm --version")
ProvResult(true, out = "Package npm v$npmVersion already installed. Checking shadow-cljs now.")
if (chk("npm list -g shadow-cljs|grep empty")) {
addResultToEval(ProvResult(true, out = "Package npm v$npmVersion already installed. Checking shadow-cljs now."))
if (chk("npm list -g shadow-cljs | grep empty")) {
cmd("sudo npm install -g shadow-cljs")
} else {
ProvResult(true, out = "Package shadow-cljs already installed.")
addResultToEval(ProvResult(true, out = "Package shadow-cljs already installed."))
}
if (chk("npm list -g npx|grep empty")) {
cmd("sudo npm install -g npx")
} else {
ProvResult(true, out = "Package npx already installed.")
addResultToEval(ProvResult(true, out = "Package npx already installed."))
}
}
}

View file

@ -1 +1 @@
0.39.6-SNAPSHOT
0.39.7-SNAPSHOT

View file

@ -1,22 +1,23 @@
package org.domaindrivenarchitecture.provs.desktop.infrastructure
import org.domaindrivenarchitecture.provs.framework.core.processors.ContainerStartMode
import org.domaindrivenarchitecture.provs.test.defaultTestContainer
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
internal class ClojureScriptKtTest {
@Test
@Disabled // does not run the first time, probably hanging due to "E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 700 (apt-get)"
fun installShadowCljs() {
// given
defaultTestContainer().cmd("sudo apt-get upgrade")
val prov = defaultTestContainer(ContainerStartMode.CREATE_NEW_KILL_EXISTING)
// when
val res = defaultTestContainer().installShadowCljs()
val res = prov.installShadowCljs()
val res2 = prov.installShadowCljs() // check if it can be run twice successfully
// then
assertTrue(res.success)
assertTrue(res2.success)
}
}

View file

@ -41,7 +41,7 @@ private fun initDefaultTestContainer(startMode: ContainerStartMode): Prov {
containerProv.sh("""
sudo apt-get update
sudo apt-get upgrade -qqq
sudo apt-get upgrade -qq
""".trimIndent())
return containerProv