@@ -49,7 +49,7 @@ function printSbtTaskImpl(
4949 let errorMessage = `sbt invocation for Scala.js compilation failed with exit code ${ code } .` ;
5050 if ( fullOutput . includes ( "Not a valid command: --" ) ) {
5151 errorMessage += "\nCause: Your sbt launcher script version is too old (<1.3.3)."
52- errorMessage += "\nFix: Re-install the latest version of sbt launcher script from https://www.scala-sbt.org/"
52+ errorMessage += "\nFix: Re-install the latest version of sbt launcher script from https://www.scala-sbt.org/"
5353 reject ( new Error ( errorMessage ) ) ;
5454 } else if ( fullOutput . includes ( "sbt thinks that server is already booting" ) ) {
5555 if ( remainingAttempts > 0 ) {
@@ -86,6 +86,7 @@ function printWarning(message: String): void {
8686export interface ScalaJSPluginOptions {
8787 cwd ?: string ,
8888 projectID ?: string ,
89+ task ?: string ,
8990 uriPrefix ?: string ,
9091 maxAttempts ?: number ,
9192 retryDelayMs ?: number ,
@@ -117,11 +118,22 @@ export function scalaJsSbtPlugin(options: ScalaJSPluginOptions = {}): VitePlugin
117118 } ,
118119
119120 // standard Rollup
120- async buildStart ( options ) {
121- if ( isDev === undefined )
121+ async buildStart ( buildOptions ) {
122+ if ( isDev === undefined ) {
122123 throw new Error ( "configResolved must be called before buildStart" ) ;
124+ }
123125
124- const task = isDev ? "fastLinkJSOutput" : "fullLinkJSOutput" ;
126+ const task = options . task ?. trim ( ) || ( isDev ? "fastLinkJSOutput" : "fullLinkJSOutput" ) ;
127+ if ( [ "fastLinkJS" , "fullLinkJS" , "fastOptJS" , "fullOptJS" ] . includes ( task ) ) {
128+ // Warn about known-bad tasks to help users out
129+ let errorMessage = `scalaJsSbtPlugin: you provided a known unsupported task '${ task } '.` ;
130+ errorMessage += "\nFix: Provide either 'fastLinkJSOutput' or 'fullLinkJSOutput'." ;
131+ errorMessage += "\n One of those is probably what you want." ;
132+ errorMessage += "\n By default, the plugin chooses between them depending on NODE_ENV." ;
133+ errorMessage += "\nOr: Provide a custom task that returns the Scala.js output directory," ;
134+ errorMessage += "\n either as a java.io.File, or as a String with its absolute path." ;
135+ throw new Error ( errorMessage ) ;
136+ }
125137 const projectTask = projectID ? `${ projectID } /${ task } ` : task ;
126138 scalaJsOutputDir = await printSbtTask ( projectTask , cwd , maxAttempts , retryDelayMs ) ;
127139 } ,
@@ -163,13 +175,15 @@ export function resolveModuleId(
163175 scalaJsOutputDir : string | undefined ,
164176 errorMessageIfNoOutputDir : string
165177) : string | null {
166- if ( scalaJsOutputDir === undefined )
178+ if ( scalaJsOutputDir === undefined ) {
167179 throw new Error ( errorMessageIfNoOutputDir ) ;
180+ }
168181
169182 const fullUriPrefix = uriPrefix ? ( uriPrefix + ':' ) : 'scalajs:' ;
170183
171- if ( ! moduleId . startsWith ( fullUriPrefix ) )
184+ if ( ! moduleId . startsWith ( fullUriPrefix ) ) {
172185 return null ;
186+ }
173187
174188 const path = moduleId . substring ( fullUriPrefix . length ) ;
175189
0 commit comments