Skip to content

Commit

Permalink
Update ydoc-server build (#11550)
Browse files Browse the repository at this point in the history
Changelog:
- update: Ydoc build inputs
- update: respect `pnpm` exit codes
  • Loading branch information
4e6 authored Nov 14, 2024
1 parent 7363377 commit 19f4242
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions project/Ydoc.scala
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ object Ydoc {
ydocServerResourceManaged: File,
streams: TaskStreams
): Seq[File] = {
val store = streams.cacheStoreFactory.make("ydoc-server-cache")
val store = streams.cacheStoreFactory.make("ydoc-server-npm-compile-cache")
val generator = Tracked.inputChanged[Seq[File], Seq[File]](store) {
case (changed, _) =>
val resourceYdocServerJs =
Expand All @@ -55,7 +55,12 @@ object Ydoc {
if (changed) {
val command = s"$pnpmCommand -r compile"
streams.log.info(command)
command ! streams.log
val exitCode = command ! streams.log

if (exitCode != 0) {
throw new CommandFailed(command, exitCode)
}

val generatedYdocServerJs =
base / "app" / "ydoc-server-polyglot" / "dist" / "main.cjs"
IO.copyFile(generatedYdocServerJs, resourceYdocServerJs)
Expand All @@ -64,18 +69,16 @@ object Ydoc {
Seq(resourceYdocServerJs)
}

val ydocServerPolyglot = base / "app" / "ydoc-server-polyglot"
val ydocServerPolyglotSrc =
ydocServerPolyglot * ("*.mjs" | "*.json") +++ (ydocServerPolyglot / "src") ** "*.ts"
val ydocShared = base / "app" / "ydoc-shared"
val ydocSharedSrc =
ydocShared * ("*.ts" || "*.json") +++
(ydocShared / "src") ** "*.ts" +++
(ydocShared / "parser-codegen") ** "*.ts"
val sharedSrc = (base / "app" / "gui2" / "shared") ** "*.ts"
val inputFiles = ydocServerPolyglotSrc +++ sharedSrc

generator(inputFiles.get)
val sourceFiles: PathFinder =
(base / "app") ** ("*.js" | "*.ts" | "*.json" | "*.rs" | "*.toml")
val nodeModulesFiles =
(base / "app") ** "node_modules" ** "*"
val ideDesktopFiles =
(base / "app") ** "ide-desktop" ** "*"

val inputFiles = sourceFiles --- nodeModulesFiles --- ideDesktopFiles

generator(inputFiles.get())
}

private def runNpmInstallCached(base: File, streams: TaskStreams): Unit = {
Expand All @@ -86,12 +89,23 @@ object Ydoc {
if (changed || !nodeModules.isDirectory) {
val command = s"$pnpmCommand i --frozen-lockfile"
streams.log.info(command)
command ! streams.log
val exitCode = command ! streams.log
if (exitCode != 0) {
throw new CommandFailed(command, exitCode)
}
}
}

val inputFile = base / "package-lock.json"
val inputFile = base / "pnpm-lock.json"

generator(inputFile)
}

final private class CommandFailed(command: String, exitCode: Int)
extends FeedbackProvidedException {

override def toString: String = {
s"Command [$command] failed with exit code [$exitCode]"
}
}
}

0 comments on commit 19f4242

Please sign in to comment.