Skip to content

feat(sbt): add "--server" - #37

Open
cheleb wants to merge 1 commit into
scala-js:mainfrom
cheleb:sbt-2-server-mode
Open

feat(sbt): add "--server"#37
cheleb wants to merge 1 commit into
scala-js:mainfrom
cheleb:sbt-2-server-mode

Conversation

@cheleb

@cheleb cheleb commented Jun 22, 2026

Copy link
Copy Markdown
  • Add --server flag to sbt command arguments to run sbt server in foreground.

sbt 2 by default runs sbtn (thin client)

- Add `--server` flag to sbt command arguments to run sbt server in foreground.

sbt 2 by default runs sbtn (thin client)
Comment thread index.ts Outdated
// Utility to invoke a given sbt task and fetch its output
function printSbtTask(task: string, cwd?: string): Promise<string> {
const args = ["--batch", "-no-colors", "-Dsbt.supershell=false", `print ${task}`];
const args = ["--server", "--batch", "-no-colors", "-J-Dsbt.supershell=false", `print ${task}`];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that the correct solution here is to use --server. If we take a look at SBT 2 output:

aly@hydrogen ~/D/d/scalajs (main)> sbt --batch -no-colors -Dsbt.supershell=false "print fullLinkJSOutput" | hexdump -C
00000000  2f 68 6f 6d 65 2f 61 6c  79 2f 44 6f 63 75 6d 65  |/home/aly/Docume|
00000010  6e 74 73 2f 64 70 66 2d  70 6c 61 79 67 72 6f 75  |nts/dpf-playgrou|
00000020  6e 64 2f 73 63 61 6c 61  6a 73 2f 74 61 72 67 65  |nd/scalajs/targe|
00000030  74 2f 6f 75 74 2f 73 6a  73 31 2f 73 63 61 6c 61  |t/out/sjs1/scala|
00000040  2d 33 2e 38 2e 34 2f 64  70 66 70 6c 61 79 67 72  |-3.8.4/dpfplaygr|
00000050  6f 75 6e 64 2f 64 70 66  70 6c 61 79 67 72 6f 75  |ound/dpfplaygrou|
00000060  6e 64 2d 6f 70 74 0a 5b  73 75 63 63 65 73 73 5d  |nd-opt.[success]|
00000070  20 65 6c 61 70 73 65 64  20 74 69 6d 65 3a 20 30  | elapsed time: 0|
00000080  20 73 0a 1b 5b 30 4a                              | s..[0J|
00000087

There's an \x1b[0J here in the thin client that doesn't appear in the output when using --server, but otherwise the thin client's output is correct & is much faster to execute than the server.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One solution would be to write the task output to a temporary file instead:

aly@hydrogen ~/D/d/scalajs (main) [1]> sbt --batch -no-colors -Dsbt.supershell=false 'set TaskKey[Unit]("dummy") := sbt.IO.write(file("/tmp/tmp.TFqXG6olui"), (Compile / fullLinkJSOutput).value.absolutePath);' 'dummy'
[info] Defining dummy
[info] The new value will be used by no settings or tasks.
[info] Reapplying settings...
[info] set current project to dpfPlayground (in build file:/home/aly/Documents/dpf-playground/scalajs/)
[success] elapsed time: 2 s
aly@hydrogen ~/D/d/scalajs (main)> cat /tmp/tmp.TFqXG6olui
/home/aly/Documents/dpf-playground/scalajs/target/out/sjs1/scala-3.8.4/dpfplayground/dpfplayground-opt⏎

Comment thread index.ts Outdated
// Utility to invoke a given sbt task and fetch its output
function printSbtTask(task: string, cwd?: string): Promise<string> {
const args = ["--batch", "-no-colors", "-Dsbt.supershell=false", `print ${task}`];
const args = ["--server", "--batch", "-no-colors", "-J-Dsbt.supershell=false", `print ${task}`];

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The -J here is incorrect, if you read sbt --help:

  -Dkey=val           pass -Dkey=val directly to the java runtime
  -J-X                pass option -X directly to the java runtime
                      (-J is stripped)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants