Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define buildInfoKeys per Task (or per "Custom" Config) scope #143

Open
evbo opened this issue Jan 17, 2019 · 2 comments
Open

Define buildInfoKeys per Task (or per "Custom" Config) scope #143

evbo opened this issue Jan 17, 2019 · 2 comments

Comments

@evbo
Copy link

evbo commented Jan 17, 2019

Using scalajs, I think sbt-buildinfo is the perfect solution for incorporating compile-time environment overrides. For instance, webpack has the DefinePlugin which injects global vars as environment-specific overrides (e.g. to compile with either dev/qa/prod hostnames). But global vars is just starting to get support in scalajs, and I'm not totally liking the idea of global vars anyway.

So to use sbt-buildinfo to fulfill this need, I just need to be able to configure compile-time env constants like:

buildInfoKeys in (Compile, fastOptJS) := Seq[BuildInfoKey]("contentHost" -> "localhost"),
buildInfoKeys in (Compile, fullOptJS) := Seq[BuildInfoKey]("contentHost" -> "http://example.com"),

Is there an easy fix for supporting setting buildInfoKeys when different scalajs tasks are being run? Any potential workarounds?

@evbo
Copy link
Author

evbo commented Jan 18, 2019

I luckily found a potential answer thanks to @eed3si9n that allows me to set either "dev" or "prod" values for buildInfoKeys, as shown in this answer

However, I'm only able to change the buildIntoKeys in Compile. Any other config is ignored and so again I need a way to run BuildInfoPlugin for specific Task or Config.

  lazy val Prod = config("Prod") describedAs("prod environment settings") extend(Compile)


  lazy val client = (project in file("app"))
    .configs(Prod)
    .enablePlugins(BuildInfoPlugin)
    .enablePlugins(ScalaJSBundlerPlugin)
    // default settings here
    .settings(clientSettings)
    
   // setting overrides
    .settings(
      inConfig(Prod)(
        Seq(
          // need to reference compile config for it to have any effect
          buildInfoKeys in Compile := Seq[BuildInfoKey]("contentHost" -> "prodHost")
        )
      )
    )

Thanks, and perhaps this is a feature enhancement? Was it ever intended to run BuildInfo for multiple configs/tasks?

@evbo
Copy link
Author

evbo commented Jan 25, 2019

I think I found a reference showing this was done before: #61

While it does work using Test configuration I am still not able to provide a custom configuration:

// from my example above

.settings(
    addBuildInfoToConfig(Prod),
    buildInfoKeys in Prod := Seq[BuildInfoKey]("contentHost" -> "prodHost")
  )

when I run: Prod:fullOptJS, I still get default buildInfoKeys

when I run: test I do get overrides (if I use Test in place of Prod above)

Is there a way to get it to work for custom config that extends Compile? I couldn't find any documentation and the above doesn't seem to be overriding the default keys that get generated other than that PR.

@evbo evbo changed the title Define buildInfoKeys per Task in Compile scope Define buildInfoKeys per Task (or per "Custom" Config) in Compile scope Jan 25, 2019
@evbo evbo changed the title Define buildInfoKeys per Task (or per "Custom" Config) in Compile scope Define buildInfoKeys per Task (or per "Custom" Config) scope Jan 25, 2019
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

No branches or pull requests

1 participant