Adding Provided JS (under a directory) in SBT causing unexpected token - sbt

Invalid character is coming in the generated *-js-deps.js, when I am trying to add a ProvidedJS build.sbt
I tried with 0.6.9 & 0.6.11
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.11")
jsDependencies += ProvidedJS / "js/igniteui/infragistics.core.js"
Any clue why it is adding an invalid character in the generated *-js-deps.js ?
Thanks in advance
PS - I have used the normalized path as per this gissue
https://github.com/scala-js/scala-js/issues/2358

Related

How to use SBT's libraryDependencyScheme key

I'm in library dependency hell right now with the following error:
[error] (server / update) found version conflict(s) in library dependencies; some are suspected to be binary incompatible:
[error]
[error] * com.lihaoyi:geny_2.13:1.0.0 (early-semver) is selected over 0.6.10
[error] +- com.lihaoyi:scalatags_2.13:0.12.0 (depends on 1.0.0)
[error] +- com.lihaoyi:fastparse_2.13:2.3.3 (depends on 0.6.10)
[error]
[error]
[error] this can be overridden using libraryDependencySchemes or evictionErrorLevel
I'm still stymied by how to use libraryDependencySchemes, as the error message suggests.
A search for libraryDependencySchemes in the SBT documentation comes up empty.
Preventing Version Conflict with VersionScheme is aimed primarily at library authors, not users. It has a short section at the end for users, but focuses on how to impose a dependency scheme when the library author has not. There's only one example, how to impose early-semver if the library author has not:
ThisBuild / libraryDependencySchemes += "io.circe" %% "circe-core" % "early-semver"
From elsewhere (e.g. this sbt issue) I gather that replacing "early-semver" in the above with "always" or VersionScheme.Always is
the correct way to specify "don't check the version compatibility of this library"
Unfortunately, that hasn't worked for me -- I get the same error.
The build for this project has several subprojects. Here's the relevant part of the build. Can anyone explain what's wrong and why?
lazy val xplatform = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Full)
.in(file("_xplatform"))
.settings(commonSettings)
.settings(
libraryDependencySchemes += "com.lihaoyi" %% "geny" % VersionScheme.Always, // "early-semver",
libraryDependencies ++= Seq(
"com.lihaoyi" %%% "fastparse" % "2.3.3",
"com.lihaoyi" %%% "scalatags" % "0.12.0",
// some additional libraries omitted for brevity
),
jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv()
)
.jsSettings(
libraryDependencies ++= Seq(
"ca.bwbecker" %%% "jsFacadeOptionBuilder" % "0.9.6"
),
jsDependencies += "org.webjars" % "jquery" % "3.4.1" / "jquery.js" % "test"
)
.jsConfigure(_.enablePlugins(ScalaJSWeb, JSDependenciesPlugin))
Update:
After further testing, I realize that this is only occurring on the ScalaJS side of the project.
I've tried both of the following; no difference on the JVM side but neither work for ScalaJS.
libraryDependencySchemes += "com.lihaoyi" %% "geny" % VersionScheme.Always, // "early-semver",
libraryDependencySchemes += "com.lihaoyi" %%% "geny" % VersionScheme.Always, // "early-semver",
Turns out this is an SBT bug (as of 2023-01-26). Using
libraryDependencySchemes += "com.lihaoyi" %% "geny" % VersionScheme.Always
suppresses the error in a JVM-only build file. It doesn't work for anything involving Scala.JS.
See my bug report for a small working example (on the JVM) and failing (on Scala.JS).

What does "provided->default" mean in an sbt build file?

An example of this comes from a sample github project:
libraryDependencies ++= Seq(
"javax.servlet" % "servlet-api" % "2.5" % "provided->default",
...
}
I'm only vaguely clear on what the 'fourth column' in these configurations mean, but this is the first time I've seen either provided or provided->default, and it's unclear how I can go about finding what should be expected here in the documentation. Can anyone help explain this construct?
It means that your provided configuration depends on the default configuration of "java.servlet" % "servlet-api" % "2.5".
Maven scopes describe what these configurations or scopes mean.
For instance, if you're using a library to write your tests, you've probably come across something like "org.scalacheck" %% "scalacheck" % "1.13.2" % "test" or similar. Here, the second part of the configuration is omitted and refers to the default configuration (usually compile). Equivalently, you could write "org.scalacheck" %% "scalacheck" % "1.13.2" % "test->compile". It means that your test configuration depends on the default configuration of ScalaCheck: your tests need ScalaCheck on the class path to compile and run.
You may find more details in the Ivy documentation.

akka-http not showing metrics in NewRelic

I'm trying to monitor my akka-http Rest web-service with NewRelic
The application has only one GET url (defined with akka-http)
I have the following configuration in the plugins.sbt
logLevel := Level.Warn
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.4")
addSbtPlugin("com.gilt.sbt" % "sbt-newrelic" % "0.1.4")
I have the following configuration in the build.sbt
scalaVersion := "2.11.7"
name := "recommender-api"
...blablabla...
libraryDependencies += "com.typesafe.akka" % "akka-actor_2.11" % "2.4.2"
libraryDependencies += "com.typesafe.akka" % "akka-http-experimental_2.11" % "2.4.2"
libraryDependencies += "com.typesafe.akka" % "akka-http-spray-json-experimental_2.11" % "2.4.2"
libraryDependencies += "com.typesafe.akka" % "akka-slf4j_2.11" % "2.4.2"
newrelicIncludeApi := true
newrelicAppName := name.toString
enablePlugins(JavaServerAppPackaging, UniversalDeployPlugin, NewRelic)
I compile (and deploy) the code with sbt universal:publish, it creates a .zip, inside the .zip there is an executable file.
I pass the newRelic licenceKey by enviroment (NEW_RELIC_LICENSE_KEY)
The program starts and all works fine, the newRelic key is found (because the log dosen't say that it didn't find the key)
The aplication apears in the newRelic monitor system with the correct name
BUT NewRelic dosen't show any metrics
what I have to do to see some metrics on NewRelic?
When you specify the value of newrelicAppName as name.toString, you are not doing what you expect.
name is a value of type sbt.SettingKey, this contains details of a setting's name, type, and a short description of what the key is used for.
The type that actually contains a value is an sbt.Setting. You can get a Setting from a SettingKey (in the current project and configuration) by calling the .value method.
So when you set the value like this:
newrelicAppName := name.toString
the value looks something like this:
$ show newrelicAppName
[info] sbt.SettingKey$$anon$4#54ec2887
Yes, that is actually a string containing lots of strange characters.
On the other hand, if you used the .value call:
newrelicAppName := name.value
the value then looks like:
$ show newrelicAppName
[info] my-project
My best guess is that New Relic doesn't like application names with strange characters (like dollar signs and ampersands). By setting a more normal string, you made it more likely that New Relic would accept such a name as input.
Note: the default value for newrelicAppName is the name for the containing project, so not setting the value at all in the first example would probably have "just worked" as you would have liked.
I realy don't know what I did to make it work, the changes I made were:
In the build.sbt
newrelicVersion := "3.26.1"
newrelicAppName := "recommenders-jobs-api-monitor"
In the plugin.sbt
addSbtPlugin("com.gilt.sbt" % "sbt-newrelic" % "0.1.5")
(I updated de sbt-newrelic version)
(I harcoded the name of the new relic app)
(I specified the version of the Java Agent)

How can I include individual javascript files in jsDependencies when using ScalaJSPlugin with SBT?

I'm trying use 'ProvidedJS' like this:
jsDependencies ++= Seq(
...,
ProvidedJS / "my-script.js"
)
and put the javascript file under src/main/resources
Getting the following error:
(client/compile:scalaJSPreLinkClasspath)
org.scalajs.core.tools.classpath.JSLibResolveException:
Some references to JS libraries could not be resolved:
- Missing JS library: my-script.js
just put it into ./src/main/resources/my-script.js
Add addSbtPlugin("org.scala-js" % "sbt-jsdependencies" % "1.0.2") and addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.5.0") to plugins.sbt
Add jsDependencies += ProvidedJS / "my-script.js" to settings project in build.sbt
Put your file to /src/main/resources/my-script.js
run sbt clean compile fastOptJS
Search your file <project_dir>/target/scala-2.12/<your_project>_js-jsdeps.js

Hide Google Library's warnings

I'm using Google Closure and Google Library with my projects and I'm meeting troubles with warnings.
My project is made of ~50 files with somme small warnings (JSDoc mistakes). The problem is Google Library, when I'm compiling my project, a huge list of warnings come from the google's library, like this :
../Libs/Closure/closure/goog/uri/utils.js:255: WARNING - inconsistent return type
found : (null|string|undefined)
required: (null|string)
return uri && decodeURIComponent(uri);
^
../Libs/Closure/closure/goog/uri/utils.js:634: WARNING - inconsistent return type
found : (Array.<(string|undefined)>|undefined)
required: Array.<(string|undefined)>
return buffer;
^
../Libs/Closure/closure/goog/uri/utils.js:671: WARNING - inconsistent return type
found : (Array.<(string|undefined)>|undefined)
required: Array.<(string|undefined)>
return buffer;
^
../Libs/Closure/third_party/closure/goog/mochikit/async/deferred.js:623: WARNING - assignment to property deferred of goog.async.Deferred.AlreadyCalledError
found : (goog.async.Deferred|undefined)
required: (goog.async.Deferred|null)
this.deferred = deferred;
^
../Libs/Closure/third_party/closure/goog/mochikit/async/deferred.js:651: WARNING - assignment to property deferred of goog.async.Deferred.CancelledError
found : (goog.async.Deferred|undefined)
required: (goog.async.Deferred|null)
this.deferred = deferred;
^
I've got more than 300 warnings from Google Library and ~50 from my project. So, how can I hide google's library warnings and show my project warnings ?
I've tried to build my project with the stable Google Library and with the last from the SVN repository but I've always all this warning.
My compilation configuration :
../Libs/Closure/closure/bin/build/closurebuilder.py \
--root=../Libs/Closure/ \
--root=../Projects/myProject/ \
--namespace="Project" \
--output_mode=compiled \
--compiler_jar=../Libs/Closure/compiler.jar \
--compiler_flags="--third_party=../Libs/Raphael/raphaeljs_extern.js" \
--compiler_flags="--compilation_level=SIMPLE_OPTIMIZATIONS" \
--compiler_flags="--warning_level=VERBOSE" \
> ../../Projects/js/project_release.js
Thanks for your time!
To suppress all warning messages you should use:
--compiler_flags="--warning_level=QUIET"
instead of the verbose setting you currently have.
You may also want to check the grunt-closure-tools plugin for grunt that automates using closure's tools like the builder, compiler and depswritter.
You can use the #suppress tag in a file overview.
http://code.google.com/p/closure-compiler/wiki/Warnings##suppress_Tags
Another way is using --warnings_whitelist_file. Though, it's kind of tricky to make it working as expected. See details here: Supressing or resolving compiler errors in goog.base

Resources