Full Code of scalacenter/scalajs-bundler for AI

main 2d9cbce21781 cached
193 files
276.1 KB
80.3k tokens
1 requests
Download .txt
Showing preview only (338K chars total). Download the full file or copy to clipboard to get everything.
Repository: scalacenter/scalajs-bundler
Branch: main
Commit: 2d9cbce21781
Files: 193
Total size: 276.1 KB

Directory structure:
gitextract_pvw7avpo/

├── .drone.yml
├── .github/
│   ├── dependabot.yml
│   └── workflows/
│       ├── ci.yml
│       ├── ghpages.yml
│       └── release.yml
├── .gitignore
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── build.sbt
├── manual/
│   └── src/
│       ├── ornate/
│       │   ├── changelog.md
│       │   ├── community.md
│       │   ├── cookbook.md
│       │   ├── getting-started.md
│       │   ├── index.md
│       │   ├── motivation.md
│       │   └── reference.md
│       └── ornate.conf
├── project/
│   ├── build.properties
│   └── plugins.sbt
├── sbt-scalajs-bundler/
│   └── src/
│       ├── main/
│       │   └── scala/
│       │       └── scalajsbundler/
│       │           ├── BundlerFile.scala
│       │           ├── BundlerFileType.scala
│       │           ├── BundlingMode.scala
│       │           ├── ExternalCommand.scala
│       │           ├── JSDOMNodeJSEnv.scala
│       │           ├── JsDomTestEntries.scala
│       │           ├── NpmDependencies.scala
│       │           ├── NpmPackage.scala
│       │           ├── PackageJson.scala
│       │           ├── Stats.scala
│       │           ├── Webpack.scala
│       │           ├── WebpackDevServer.scala
│       │           ├── WebpackEntryPoint.scala
│       │           ├── sbtplugin/
│       │           │   ├── LibraryTasks.scala
│       │           │   ├── NpmUpdateTasks.scala
│       │           │   ├── PackageJsonTasks.scala
│       │           │   ├── SBTBundlerFile.scala
│       │           │   ├── ScalaJSBundlerPlugin.scala
│       │           │   ├── Settings.scala
│       │           │   └── WebpackTasks.scala
│       │           └── util/
│       │               ├── CachedBundleFiles.scala
│       │               ├── Caching.scala
│       │               ├── Commands.scala
│       │               ├── JS.scala
│       │               ├── JSBundler.scala
│       │               ├── JSPrinters.scala
│       │               ├── JSTrees.scala
│       │               └── ScalaJSNativeLibraries.scala
│       └── sbt-test/
│           └── sbt-scalajs-bundler/
│               ├── additonalNpmConfig/
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   └── test
│               ├── browserless/
│               │   ├── README.md
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   ├── main/
│               │   │   │   └── scala/
│               │   │   │       ├── example/
│               │   │   │       │   ├── Foo.scala
│               │   │   │       │   └── Main.scala
│               │   │   │       └── uuid/
│               │   │   │           └── uuid.scala
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── FooTest.scala
│               │   └── test
│               ├── custom-test-config/
│               │   ├── README.md
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   ├── main/
│               │   │   │   └── scala/
│               │   │   │       └── example/
│               │   │   │           └── Component.scala
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── SomeTest.scala
│               │   ├── test
│               │   └── test.webpack.config.js
│               ├── facade/
│               │   ├── build.sbt
│               │   ├── facade/
│               │   │   └── src/
│               │   │       └── main/
│               │   │           └── scala/
│               │   │               └── uuid/
│               │   │                   └── uuid.scala
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── test
│               │   └── usage/
│               │       └── src/
│               │           ├── main/
│               │           │   └── scala/
│               │           │       └── example/
│               │           │           ├── Foo.scala
│               │           │           └── Main.scala
│               │           └── test/
│               │               └── scala/
│               │                   └── example/
│               │                       └── FooTest.scala
│               ├── facade-examples/
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   ├── main/
│               │   │   │   ├── resources/
│               │   │   │   │   ├── class.js
│               │   │   │   │   ├── foo.js
│               │   │   │   │   └── function.js
│               │   │   │   └── scala/
│               │   │   │       └── example/
│               │   │   │           ├── Main.scala
│               │   │   │           └── facades.scala
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── FacadesTest.scala
│               │   └── test
│               ├── generated-sources/
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   └── test
│               ├── global-namespace-with-jsdom-unit-testing/
│               │   ├── build.sbt
│               │   ├── common.webpack.config.js
│               │   ├── dev.webpack.config.js
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   ├── main/
│               │   │   │   └── scala/
│               │   │   │       └── example/
│               │   │   │           └── Main.scala
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── MainTest.scala
│               │   ├── test
│               │   └── test.webpack.config.js
│               ├── js-resources/
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   ├── main/
│               │   │   │   ├── resources/
│               │   │   │   │   └── my-module.js
│               │   │   │   └── scala/
│               │   │   │       └── example/
│               │   │   │           ├── Main.scala
│               │   │   │           └── MyModule.scala
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── MyModuleTest.scala
│               │   └── test
│               ├── js-source-directory/
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   ├── main/
│               │   │   │   ├── js/
│               │   │   │   │   ├── config.json
│               │   │   │   │   ├── my-module.js
│               │   │   │   │   └── nested/
│               │   │   │   │       └── config2.json
│               │   │   │   └── scala/
│               │   │   │       └── example/
│               │   │   │           ├── Main.scala
│               │   │   │           └── MyModule.scala
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── MyModuleTest.scala
│               │   └── test
│               ├── library/
│               │   ├── build.sbt
│               │   ├── index.html
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   └── main/
│               │   │       └── scala/
│               │   │           ├── example/
│               │   │           │   └── Library.scala
│               │   │           └── uuid/
│               │   │               └── uuid.scala
│               │   └── test
│               ├── newer-linker/
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   ├── newer-scala-js.sbt
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── NewerLinkerTest.scala
│               │   └── test
│               ├── sbt-1.8/
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   ├── build.properties
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── BasicTest.scala
│               │   └── test
│               ├── sharedconfig/
│               │   ├── README.md
│               │   ├── build.sbt
│               │   ├── common.webpack.config.js
│               │   ├── dev.webpack.config.js
│               │   ├── index-prod.html
│               │   ├── index.html
│               │   ├── prod.webpack.config.js
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   ├── main/
│               │   │   │   └── scala/
│               │   │   │       ├── example/
│               │   │   │       │   └── Main.scala
│               │   │   │       └── leaflet/
│               │   │   │           └── modules/
│               │   │   │               └── modules.scala
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── SomeTest.scala
│               │   └── test
│               ├── static/
│               │   ├── README.md
│               │   ├── build.sbt
│               │   ├── index-prod.html
│               │   ├── index.html
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   ├── main/
│               │   │   │   └── scala/
│               │   │   │       ├── example/
│               │   │   │       │   └── Main.scala
│               │   │   │       └── snabbdom/
│               │   │   │           ├── modules/
│               │   │   │           │   └── modules.scala
│               │   │   │           └── snabbdom.scala
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── SomeTest.scala
│               │   └── test
│               ├── transitive/
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   └── test
│               ├── webpack-assets/
│               │   ├── README.md
│               │   ├── badconfig1.js
│               │   ├── badconfig2.js
│               │   ├── build.sbt
│               │   ├── dev.config.js
│               │   ├── prod.config.js
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   └── main/
│               │   │       ├── resources/
│               │   │       │   ├── entry.js
│               │   │       │   └── styles.css
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── Main.scala
│               │   └── test
│               ├── webpack-assets-cookbook/
│               │   ├── README.md
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   ├── ZipHelper.scala
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   ├── main/
│               │   │   │   └── scala/
│               │   │   │       └── example/
│               │   │   │           └── Main.scala
│               │   │   └── universal/
│               │   │       └── index.html
│               │   └── test
│               ├── webpack-dev-server/
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   └── main/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── Main.scala
│               │   ├── test
│               │   └── webpack.config.js
│               └── yarn-interactive/
│                   ├── build.sbt
│                   ├── project/
│                   │   └── plugins.sbt
│                   ├── src/
│                   │   └── main/
│                   │       └── scala/
│                   │           └── example/
│                   │               └── Main.scala
│                   └── test
├── sbt-web-scalajs-bundler/
│   └── src/
│       ├── main/
│       │   └── scala/
│       │       └── scalajsbundler/
│       │           └── sbtplugin/
│       │               ├── NpmAssets.scala
│       │               └── WebScalaJSBundlerPlugin.scala
│       └── sbt-test/
│           └── sbt-web-scalajs-bundler/
│               └── play/
│                   ├── build.sbt
│                   ├── client/
│                   │   └── src/
│                   │       └── main/
│                   │           └── scala/
│                   │               ├── example/
│                   │               │   └── Main.scala
│                   │               └── snabbdom/
│                   │                   ├── modules/
│                   │                   │   └── modules.scala
│                   │                   └── snabbdom.scala
│                   ├── project/
│                   │   └── plugins.sbt
│                   ├── server/
│                   │   └── src/
│                   │       ├── main/
│                   │       │   ├── resources/
│                   │       │   │   ├── application.conf
│                   │       │   │   └── router.routes
│                   │       │   └── scala/
│                   │       │       └── example/
│                   │       │           ├── ExampleController.scala
│                   │       │           └── Loader.scala
│                   │       └── test/
│                   │           ├── resources/
│                   │           │   └── logback.xml
│                   │           └── scala/
│                   │               └── example/
│                   │                   └── ExampleSpec.scala
│                   └── test
└── scalajs-bundler-linker/
    └── src/
        └── main/
            └── scala/
                └── scalajsbundler/
                    └── bundlerlinker/
                        ├── BundlerLinkerImpl.scala
                        └── EntryPointAnalyzerBackend.scala

================================================
FILE CONTENTS
================================================

================================================
FILE: .drone.yml
================================================
build:
  image: julienrf/docker-scala-sbt-git
  commands:
    - sbt clean test scripted

cache:
  mount:
    - .git
    - /drone/.ivy2
    - /drone/.sbt

================================================
FILE: .github/dependabot.yml
================================================
version: 2
updates:
  - package-ecosystem: "github-actions"
    directory: "/"
    schedule:
      interval: "weekly"


================================================
FILE: .github/workflows/ci.yml
================================================
name: CI
on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main
jobs:
  build:
    strategy:
      matrix:
        os: [ubuntu-latest, windows-latest]
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v4
      - uses: coursier/cache-action@v5
      - uses: actions/setup-java@v4
        with:
          java-version: "11"
          distribution: "adopt"
      - uses: actions/setup-node@v4
        with:
          node-version: 16.14.2
      - name: Setup yarn
        run: npm install -g yarn@1.22.15
      - name: Unit tests
        run: sbt test
      - name: Scripted tests
        run: sbt scripted
      - name: Build the manual
        run: sbt manual/makeSite


================================================
FILE: .github/workflows/ghpages.yml
================================================

name: Build and Deploy GhPages docs

on:
  push:
    branches:
      - main

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: actions/setup-java@v4
        with:
          java-version: "11"
          distribution: "adopt"
      - uses: coursier/cache-action@v5
      - name: Build
        run: sbt manual/makeSite
      - name: Deploy
        uses: JamesIves/github-pages-deploy-action@3.6.2
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          BRANCH: gh-pages
          FOLDER: manual/target/site


================================================
FILE: .github/workflows/release.yml
================================================
name: Release
on:
  push:
    branches: [main]
    tags: ["*"]
jobs:
  publish:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          # fetches all tags, required to correctly set the version
          fetch-depth: 0
      - uses: actions/setup-java@v4
        with:
          java-version: "8"
          distribution: "adopt"
      - uses: olafurpg/setup-gpg@v3
      - uses: coursier/cache-action@v5
      - name: Publish
        run: sbt clean ci-release
        env:
          PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
          PGP_SECRET: ${{ secrets.PGP_SECRET }}
          SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
          SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
          CI_RELEASE: "; scalajs-bundler-linker/publishSigned; sbt-scalajs-bundler/publishSigned; sbt-web-scalajs-bundler/publishSigned"
          CI_SNAPSHOT_RELEASE: "; scalajs-bundler-linker/publish; sbt-scalajs-bundler/publish; sbt-web-scalajs-bundler/publish"




================================================
FILE: .gitignore
================================================
target/
.idea
local.*

================================================
FILE: CONTRIBUTING.md
================================================
Contributing
===========

## General recommendations

Test and document each added feature.

## Organization of the repository

- `sbt-scalajs-bundler/` The scalajs-bundler sbt plugin
- `sbt-web-scalajs-bundler/` sbt plugin for integrating scalajs-bundler and
[sbt-web-scalajs](https://github.com/vmunier/sbt-web-scalajs)
- `manual/` Sources of the documentation

## Build the project

~~~ sh
$ sbt package
~~~

## Run the tests

We use [sbt-scripted](http://eed3si9n.com/testing-sbt-plugins) to test the plugins. However, we customized
the way tests are launched to filter tests according to their compatibility with major versions of sbt and Scala.js:

- tests can have a `project/build.properties` file defining a specific sbt version they are compatible with,

To run all the tests:

~~~ sh
$ sbt scripted
~~~

To run a single test:

~~~ sh
$ sbt "sbt-scalajs-bundler/scripted sbt-scalajs-bundler/<test-name>"
~~~

(where `<test-name>` is replaced by one of the
[tests](https://github.com/scalacenter/scalajs-bundler/tree/main/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler)).

Sometimes you would like to open an interactive sbt shell and manually play with
sbt tasks instead of writing them into a sbt-scripted test. In such a case, you
can start with an existing sbt-scripted test and add the following commands at
the top of its `test` file:

~~~
$ pause
$ fail
~~~

Then, when you will run the scripted task on this this test, it will start by
making a pause. You can then open a new sbt shell in the running test:

~~~
$ cd /tmp/sbt_fa1e13d43/test-name
$ sbt -Dplugin.version=x.y.z-SNAPSHOT
~~~

(where `x.y.z` is replaced by the current version of sbt-scalajs-bundler)

## Publish locally

~~~ sh
$ sbt publishLocal
~~~

## Preview the documentation

~~~ sh
$ sbt manual/previewSite
~~~

## Publish a release

- Check that the `changelog.md` file is up to date (in the `manual` project)
- Push a Git tag (name it `vX.Y.Z`, where `X`, `Y`, `Z` are major, minor and revision numbers, respectively)
  - Either from GitHub [web interface](https://github.com/scalacenter/scalajs-bundler/releases/new),
  - Or from the Git CLI: `$ git tag v1.0.0; git push --tags`


================================================
FILE: LICENSE
================================================
scalajs-bundler is licensed under the [BSD 3-Clause License](http://opensource.org/licenses/BSD-3-Clause).

Copyright (c) 2016 EPFL

All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice,
    this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.
  3. Neither the name of the EPFL nor the names of its contributors
    may be used to endorse or promote products derived from this software
    without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

================================================
FILE: README.md
================================================
scalajs-bundler [![](https://index.scala-lang.org/scalacenter/scalajs-bundler/sbt-scalajs-bundler/latest.svg)](https://index.scala-lang.org/scalacenter/scalajs-bundler) [![Gitter](https://img.shields.io/badge/gitter-join%20chat-green.svg)](https://gitter.im/scalacenter/scalajs-bundler) [![CI](https://github.com/scalacenter/scalajs-bundler/actions/workflows/ci.yml/badge.svg)](https://github.com/scalacenter/scalajs-bundler/actions/workflows/ci.yml)
==============

Module bundler for Scala.js projects that use NPM packages.

Uses [npm](https://www.npmjs.com) and [webpack](https://webpack.github.io/) under the hood.

## Documentation

More information on how to use it in the [documentation](https://scalacenter.github.io/scalajs-bundler).

## Contributing

scalajs-bundler is community-maintained.

Contributions are welcome! See the [open issues](https://github.com/scalacenter/scalajs-bundler/issues) and
the [CONTRIBUTING.md](CONTRIBUTING.md) file.

## License

This content is released under the [BSD 3-Clause License](http://opensource.org/licenses/BSD-3-Clause).


================================================
FILE: build.sbt
================================================
val scalaJSVersion = sys.env.getOrElse("SCALAJS_VERSION", "1.3.0")

lazy val `scalajs-bundler-linker` =
  project.in(file("scalajs-bundler-linker"))
    .settings(
      scalaVersion := "2.12.11",
      libraryDependencies += "org.scala-js" %% "scalajs-linker" % scalaJSVersion
    )

val `sbt-scalajs-bundler` =
  project.in(file("sbt-scalajs-bundler"))
    .enablePlugins(SbtPlugin, BuildInfoPlugin)
    .settings(commonSettings)
    .settings(
      description := "Module bundler for Scala.js projects",
      libraryDependencies += "com.google.jimfs" % "jimfs" % "1.2",
      libraryDependencies += "com.typesafe.play" %% "play-json" % "2.9.4",
      addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion),
      buildInfoKeys := Seq[BuildInfoKey](version),
      buildInfoPackage := "scalajsbundler.sbtplugin.internal",
      // When supported, add: buildInfoOptions += sbtbuildinfo.BuildInfoOption.PackagePrivate
      scriptedDependencies := {
        val () = scriptedDependencies.value
        val () = publishLocal.value
        val () = (`scalajs-bundler-linker` / publishLocal).value
      },
    )

val `sbt-web-scalajs-bundler` =
  project.in(file("sbt-web-scalajs-bundler"))
    .enablePlugins(SbtPlugin)
    .settings(commonSettings)
    .settings(
      // sbt-web-scalajs does not support sbt 1.2.x
      scriptedDependencies := {
        val () = scriptedDependencies.value
        val () = publishLocal.value
        val () = (`sbt-scalajs-bundler` / publishLocal).value
        val () = (`scalajs-bundler-linker` / publishLocal).value
      },
      description := "Module bundler for Scala.js projects (integration with sbt-web-scalajs)",
      addSbtPlugin("com.vmunier" % "sbt-web-scalajs" % "1.1.0")
    )
    .dependsOn(`sbt-scalajs-bundler`)

// Dummy project that exists just for the purpose of aggregating the two sbt
// plugins. I can not do that in the `doc` project below because the
// scalaVersion is not compatible.
val apiDoc =
  project.in(file("api-doc"))
    .enablePlugins(ScalaUnidocPlugin)
    .settings(noPublishSettings: _*)
    .settings(
      (ScalaUnidoc / unidoc / scalacOptions) ++= Seq(
        "-groups",
        "-doc-source-url", s"https://github.com/scalacenter/scalajs-bundler/blob/v${version.value}€{FILE_PATH}.scala",
        "-sourcepath", (ThisBuild / baseDirectory).value.absolutePath
      ),
      (ScalaUnidoc / unidoc / unidocProjectFilter) := inAnyProject -- inProjects(`scalajs-bundler-linker`)
    )
    .aggregate(`sbt-scalajs-bundler`, `sbt-web-scalajs-bundler`)

val ornateTarget = Def.setting(target.value / "ornate")

val manual =
  project.in(file("manual"))
    .enablePlugins(OrnatePlugin)
    .settings(noPublishSettings: _*)
    .settings(
      scalaVersion := "2.12.11",
      ornateSourceDir := Some(sourceDirectory.value / "ornate"),
      ornateTargetDir := Some(ornateTarget.value),
      ornateSettings := Map("version" -> version.value),
      ornate / siteSubdirName := "",
      addMappingsToSiteDir(ornate / mappings, ornate / siteSubdirName),
      ornate / mappings := {
        val _ = ornate.value
        val output = ornateTarget.value
        output ** AllPassFilter --- output pair Path.relativeTo(output)
      },
      packageDoc / siteSubdirName := "api/latest",
      addMappingsToSiteDir(mappings in ScalaUnidoc in packageDoc in apiDoc, packageDoc / siteSubdirName)
    )

val `scalajs-bundler` =
  project.in(file("."))
    .settings(noPublishSettings: _*)
    .aggregate(`sbt-scalajs-bundler`, `sbt-web-scalajs-bundler`)

inThisBuild(List(
  scalacOptions ++= Seq(
    "-feature",
    "-deprecation",
    "-encoding", "UTF-8",
    "-unchecked",
    "-Xlint",
    "-Yno-adapted-args",
    "-Ywarn-dead-code",
    "-Ywarn-numeric-widen",
    "-Ywarn-value-discard",
    "-Xfuture"
  ),
  scmInfo := Some(
    ScmInfo(
      url("https://github.com/scalacenter/scalajs-bundler"),
      "scm:git@github.com:scalacenter/scalajs-bundler.git"
    )
  ),
  organization := "ch.epfl.scala",
  homepage := Some(url(s"https://github.com/scalacenter/scalajs-bundler")),
  licenses := Seq("MIT License" -> url("http://opensource.org/licenses/mit-license.php")),
  developers := List(Developer("julienrf", "Julien Richard-Foy", "julien.richard-foy@epfl.ch", url("http://julien.richard-foy.fr")))
))

lazy val commonSettings = List(
  scriptedLaunchOpts ++= Seq(
    "-Dplugin.version=" + version.value,
    s"-Dscalajs.version=$scalaJSVersion",
    "-Dsbt.execute.extrachecks=true" // Avoid any deadlocks.
  ),
  scriptedBufferLog := false,
)

lazy val noPublishSettings =
  Seq(
    publishArtifact := false,
    publish := {},
    publishLocal := {}
  )

ThisBuild / ivyLoggingLevel := UpdateLogging.Quiet


================================================
FILE: manual/src/ornate/changelog.md
================================================
# Changelog

## Version 0.20.0

> 2020 October 22

This release upgrades to Scala.js 1.3.0.

- Drop support for Scala.js 0.6.x
- Drop support for Scala.js 1.0.x through 1.2.x
- Add support for Scala.js 1.3.x

## Version 0.19.0

> 2020 October 16

This release drops support for sbt 0.13.x, and adds support for sbt-web-scalajs 1.1.0+.

## Version 0.18.0

> 2020 May 16

This release adds support for scala.js 1.1.0

## Version 0.17.0

> 2020 Feb 24

The main highlight of this release is better support for Scala.js 1.0.0+ out of the box.
We still support Scala.js 0.6.31+ as well.

- With Scala.js 1.x, dynamically load the appropriate scalajs-linker, removing the need for the
  `libraryDependencies += "org.scala-js" %% "scalajs-linker" % scalaVersion`
  workaround.
- With Scala.js 1.x, do not internally link twice when using the `LibraryOnly` and
  `LibraryAndApplication` bundling modes, improving performance.
- With Scala.js 1.x, better integrate with the `jsEnv` and `jsEnvInput` tasks of
  Scala.js when using `requireJsDomEnv`.

You can find the complete list of commits since the last release
[here](https://github.com/scalacenter/scalajs-bundler/compare/v0.16.0...v0.17.0).

## Version 0.16.0

> 2019 Dec 09

The main highlight of this release is the support of Scala.js 1.0.0-RC1 instead of 1.0.0-M7.
We still support Scala.js 0.6.x, but we require at least version 0.6.31.

- Add support for Scala.js 1.0.0-RC1 (drop support for 1.0.0-M7)
- Require Scala.js 0.6.31 or later in the 0.6.x branch
- Require sbt 1.2.1 or later in the sbt 1.x branch (sbt 0.13.17+ is still supported)

You can find the complete list of commits since the last release
[here](https://github.com/scalacenter/scalajs-bundler/compare/v0.15.0...v0.16.0).

## Version 0.15.0

> 2019 May 21

The main highlight of this release is the support of Scala.js 1.x. We still support Scala.js 0.6.x, but
we require at least version 0.6.26.

New features:
- [#201](https://github.com/scalacenter/scalajs-bundler/issues/201): Introduce a `jsSourceDirectories` setting,
  which points to a list of directories containing files (`.js`, `.json`, etc.) that can be used by Scala.js
  projects.
- [#246](https://github.com/scalacenter/scalajs-bundler/issues/246): Support Scala.js 1.0.0-M7.

You can find the complete list of commits since the last release
[here](https://github.com/scalacenter/scalajs-bundler/compare/v0.14.0...v0.15.0).

## Version 0.14.0

> 2018 Nov 5

This release modifies the `npmUpdate` task and splits the logic into two separate tasks; `npmInstallDependencies` and
`npmInstallJSResources`. `npmUpdate` has a less obvious side effect that, not only does it run `npm install`, it would
also copy all the JavaScript resources to the `node_modules` directory. This behaviour is fine except that it is not
suitable for use in `sourceGenerators` and would cause a cycle in the tasks. `npmInstallDependencies` should be used in
cases where you want to want to use a npm module from a sbt task.

This fixes the following bugs:
 - [#258](https://github.com/scalacenter/scalajs-bundler/issues/258): Unable to use npmUpdate in sourceGenerators
 - [#261](https://github.com/scalacenter/scalajs-bundler/issues/261): Support jsdom v12.x
 - [#267](https://github.com/scalacenter/scalajs-bundler/issues/267): Support JDK9+

New features:
  - [#264](https://github.com/scalacenter/scalajs-bundler/issues/264): Ability to set `node` [flags](https://nodejs.org/api/cli.html)
  - [#266](https://github.com/scalacenter/scalajs-bundler/issues/266): Custom setting for DOM enabled `JSEnv` in `test`. (`requiresDOM` is deprecated)

And documentation fixes:
  - [#269](https://github.com/scalacenter/scalajs-bundler/issues/269): Update docs

You can find the complete list of commits since the last release
[here](https://github.com/scalacenter/scalajs-bundler/compare/v0.13.1...v0.14.0).

## Version 0.13.1

> 2018 Jul 13

This fixes the following bugs:

  - [#224](https://github.com/scalacenter/scalajs-bundler/issues/224): Use project-level custom NPM registry

The following PRs are included in this release

- [#254](https://github.com/scalacenter/scalajs-bundler/pull/254): Npm/yarn args
- [#251](https://github.com/scalacenter/scalajs-bundler/pull/251): Fix typo
- [#249](https://github.com/scalacenter/scalajs-bundler/pull/249): Sync yarn.lock between baseDir and installDir

You can find the complete list of commits since the last release
[here](https://github.com/scalacenter/scalajs-bundler/compare/v0.13.0...v0.14.1).

## Version 0.13.0

> 2018 Jun 5

This release contains an important revamp on the way webpack support works.
Webpack produces a json [stats output](https://webpack.js.org/api/stats) which
describes in detail the results of processing your application. Thus, parsing
stats we can learn exactly what files are produced rather than guessing.

Due to the very nature of parsing the output, and the wide variety of webpack
configurations this process may not work in all cases. Please lets us know if
you find any issues.

**Note:** `Stats` parsing has been tested mostly in Webpack 4. The results may vary with
older versions.

**Note:** If your webpack produces any kind of std output, parsing stats will likely break.

This fixes the following bugs:

- [#192](https://github.com/scalacenter/scalajs-bundler/issues/192): Webpack failed to create application bundle
- [#111](https://github.com/scalacenter/scalajs-bundler/issues/111): Lots of warnings about source map URLs

The following PRs are included in this release

- [#247](https://github.com/scalacenter/scalajs-bundler/pull/247): Assets to sbt
- [#242](https://github.com/scalacenter/scalajs-bundler/pull/242): Better error display when the webpack call fails
- [#241](https://github.com/scalacenter/scalajs-bundler/pull/241): Use Public path from webpack stats
- [#240](https://github.com/scalacenter/scalajs-bundler/pull/240): Update concat-with-sourcemaps
- [#239](https://github.com/scalacenter/scalajs-bundler/pull/239): Bugfix parsing errors on the output
- [#238](https://github.com/scalacenter/scalajs-bundler/pull/238): Fix thread leak
- [#237](https://github.com/scalacenter/scalajs-bundler/pull/237): add function as a module example
- [#234](https://github.com/scalacenter/scalajs-bundler/pull/234): Read application asset name from stats

You can find the complete list of commits since the last release
[here](https://github.com/scalacenter/scalajs-bundler/compare/v0.12.0...v0.13.0).

## Version 0.12.0

> 2018 March 27

- [#223](https://github.com/scalacenter/scalajs-bundler/pull/223): Webpack4 support

You can find the complete list of commits since the last release
[here](https://github.com/scalacenter/scalajs-bundler/compare/v0.11.0...v0.12.0).

## Version 0.11.0

> 2018 March 15

- [#228](https://github.com/scalacenter/scalajs-bundler/pull/228): Implements npmUdpdate in a separate object;
- [#225](https://github.com/scalacenter/scalajs-bundler/pull/225): Add --mutex to yarn command;
- [#222](https://github.com/scalacenter/scalajs-bundler/pull/222): Make library example work in OSX;
- [#220](https://github.com/scalacenter/scalajs-bundler/pull/220): Support passing an extra list of arguments to webpack;
- [#218](https://github.com/scalacenter/scalajs-bundler/pull/218): Fix [#136](https://github.com/scalacenter/scalajs-bundler/issues/136): Add more precise jsdom detection:
- [#216](https://github.com/scalacenter/scalajs-bundler/pull/216): Fix [#200](https://github.com/scalacenter/scalajs-bundler/issues/200): current webpack devserver version does not accept watchOptions;
- [#215](https://github.com/scalacenter/scalajs-bundler/pull/215): Fix [#99](https://github.com/scalacenter/scalajs-bundler/issues/99): Relax NPM dependency version conflict resolution;
- [#213](https://github.com/scalacenter/scalajs-bundler/pull/213): Fix [#168](https://github.com/scalacenter/scalajs-bundler/issues/168): Update the snabbdom facade for Scala.js 1.0

You can find the complete list of commits since the last release
[here](https://github.com/scalacenter/scalajs-bundler/compare/v0.10.0...v0.11.0).

## Version 0.10.0

> 2018 January 31

This release requires sbt 0.13.16+ and adds support for Scala.js 0.6.22.

- [#210](https://github.com/scalacenter/scalajs-bundler/pull/210): Bundler doesn't support version of jsdom more than 9;
- [#185](https://github.com/scalacenter/scalajs-bundler/pull/185): Correct webpackBundlingMode key in docs;
- [#212](https://github.com/scalacenter/scalajs-bundler/pull/212): Migrate to sbt-scalajs 0.6.22;

You can find the complete list of commits since the last release
[here](https://github.com/scalacenter/scalajs-bundler/compare/v0.9.0...v0.10.0).

## Version 0.9.0

> 2017 October 12

When upgrading to this release, make sure to migrate your webpack configuration to [webpack 3.X](https://webpack.js.org/guides/migrating/).

This version works with both sbt version 0.13 and 1.0. In order to support sbt 1.0,
Scala.js has been upgraded to [0.6.19](https://www.scala-js.org/news/2017/07/29/announcing-scalajs-0.6.19/).

- [#175](https://github.com/scalacenter/scalajs-bundler/pull/175): Set webpack 3.X as default version;
- [#179](https://github.com/scalacenter/scalajs-bundler/pull/179): Cross publish for sbt 1.0;
- [#176](https://github.com/scalacenter/scalajs-bundler/pull/176): Run webpack-dev-server from the scalajs-bundler folder;
- [#177](https://github.com/scalacenter/scalajs-bundler/pull/176): Scope webpackBundlingMode per Scala.js stage (`fastOptJS` or `fullOptJS`);

You can find the complete list of commits since the last release
[here](https://github.com/scalacenter/scalajs-bundler/compare/v0.8.0...v0.9.0).

## Version 0.8.0

> 2017 September 10

When upgrading to this release, make sure to check out the new [webpackBundlingMode](reference.md#bundling-mode)
configuration value. The old `enableReloadWorkflow` key has been removed, in favor
of `BundlingMode.LibraryAndApplication()`.

- [#143](https://github.com/scalacenter/scalajs-bundler/pull/143): Document the compatible versions of npm;
- [#146](https://github.com/scalacenter/scalajs-bundler/pull/146): Document how to use global modules with jsdom in tests;
- [#149](https://github.com/scalacenter/scalajs-bundler/pull/149): Introduce `webpackBundlingMode` to finely control whether to bundle the output of Scala.js or not;
- [#153](https://github.com/scalacenter/scalajs-bundler/pull/153): Use the non interactive mode of Yarn;
- [#161](https://github.com/scalacenter/scalajs-bundler/pull/161): Set `"private": true` in generated `package.json` file to eliminate errors from npm;
- [#162](https://github.com/scalacenter/scalajs-bundler/pull/162): Differentiate between missing and unsupported Webpack versions;
- [#166](https://github.com/scalacenter/scalajs-bundler/pull/166): Move to Travis-CI;
- [#167](https://github.com/scalacenter/scalajs-bundler/pull/167): Upgrade tests that use `uuid`;
- [#171](https://github.com/scalacenter/scalajs-bundler/pull/171): Add `scalaJSProjects` resource directories to `monitoredScalaJSDirectories`;
- [#172](https://github.com/scalacenter/scalajs-bundler/pull/172): Use `npm install` command instead of `npm update`.

You can find the complete list of commits since the last release
[here](https://github.com/scalacenter/scalajs-bundler/compare/v0.7.0...v0.8.0).

## Version 0.7.0

> 2017 July 4

When upgrading to this release, make sure to enable `scalaJSUseMainModuleInitializer := true` in your build if you have a `main` method.

- [#125](https://github.com/scalacenter/scalajs-bundler/pull/125): Copy `webpackResources` only if a custom webpack config file is used ;
- [#126](https://github.com/scalacenter/scalajs-bundler/pull/126): Ability to add custom `package.json` entries ;
- [#129](https://github.com/scalacenter/scalajs-bundler/pull/129): Generate a JavaScript array of webpack entries rather than a string ;
- [#140](https://github.com/scalacenter/scalajs-bundler/pull/140): Upgrade to Scala.js 0.6.18 ;
- [#141](https://github.com/scalacenter/scalajs-bundler/pull/141): Handle `ImportWithGlobalFallback` in reload workflow.

You can find the complete list of commits since the last release
[here](https://github.com/scalacenter/scalajs-bundler/compare/v0.6.0...v0.7.0).

## Version 0.6.0

> 2017 April 26

- [#96](https://github.com/scalacenter/scalajs-bundler/pull/96): webpack-dev-server integration ;
- [#102](https://github.com/scalacenter/scalajs-bundler/pull/102): Make it possible to set the version of jsdom and webpack-dev-server to use ;
- [#106](https://github.com/scalacenter/scalajs-bundler/pull/106): Add a [Community](community.md) page ;
- [#108](https://github.com/scalacenter/scalajs-bundler/pull/108): Add gitter badge to the README ;
- [#121](https://github.com/scalacenter/scalajs-bundler/pull/121): Make the sbt task fail when webpack fails ;
- [#119](https://github.com/scalacenter/scalajs-bundler/pull/119): Add support for custom webpack config files in tests and in the reload workflow ;

You can find the complete list of commits since the last release
[here](https://github.com/scalacenter/scalajs-bundler/compare/v0.5.0...v0.6.0).

## Version 0.5.0

> 2017 January 18

- [#57](https://github.com/scalacenter/scalajs-bundler/pull/57): Webpack 2.x support ;
- [#80](https://github.com/scalacenter/scalajs-bundler/pull/80): Upgrade to Scala.js 0.6.14 ;
- [#81](https://github.com/scalacenter/scalajs-bundler/pull/81): Disable the reload workflow by default ;
- [#94](https://github.com/scalacenter/scalajs-bundler/pull/94): Improve caching of tasks ;
- [#95](https://github.com/scalacenter/scalajs-bundler/pull/95): Fix support for spaces in paths ;

You can find the complete list of commits since the last release
[here](https://github.com/scalacenter/scalajs-bundler/compare/v0.4.0...v0.5.0).

## Version 0.4.0

> 2016 December 15

- [#53](https://github.com/scalacenter/scalajs-bundler/pull/53): Fix cache invalidation when .js resources change ;
- [#54](https://github.com/scalacenter/scalajs-bundler/pull/54): Add support for importing assets from NPM packages ;
- [#56](https://github.com/scalacenter/scalajs-bundler/pull/56): Add [Yarn](https://yarnpkg.com/) support ;
- [#65](https://github.com/scalacenter/scalajs-bundler/pull/65): Use distinct target directories for `npmUpdate in Compile` and `npmUpdate in Test` ;
- [#69](https://github.com/scalacenter/scalajs-bundler/pull/69): Publish the API documentation ;
- [#70](https://github.com/scalacenter/scalajs-bundler/pull/70): Ensure that there is no duplicates in NPM dependencies ;
- [#71](https://github.com/scalacenter/scalajs-bundler/pull/71): Add a resolution mechanism for conflicting dependencies.

You can find the complete list of commits since the last release
[here](https://github.com/scalacenter/scalajs-bundler/compare/v0.3.1...v0.4.0).

## Version 0.3.1

> 2016 December 2

- [#51](https://github.com/scalacenter/scalajs-bundler/pull/51): Support history API within jsdom.

You can find the complete list of commits since the last release
[here](https://github.com/scalacenter/scalajs-bundler/compare/v0.3.0...v0.3.1).

## Version 0.3.0

> 2016 November 29

- [#32](https://github.com/scalacenter/scalajs-bundler/pull/32): Add a detailed documentation
section on how to write a facade with `@JSImport` (see it [here](cookbook.md#facade)) ;
- [#33](https://github.com/scalacenter/scalajs-bundler/pull/33): Fix cache invalidation
  after custom webpack config file is changed ;
- [#35](https://github.com/scalacenter/scalajs-bundler/pull/35): Fix tests on Windows ;
- [#37](https://github.com/scalacenter/scalajs-bundler/pull/37): Throw an error if there is no main class ;
- [#39](https://github.com/scalacenter/scalajs-bundler/pull/39): Add support for jsdom in tests ;
- [#45](https://github.com/scalacenter/scalajs-bundler/pull/45): Forbid `scalaJSModuleKind`
  to be different from `CommonJSModule` on projects where `ScalaJSBundler` plugin is enabled.

You can find the complete list of commits since the last release
[here](https://github.com/scalacenter/scalajs-bundler/compare/v0.2.1...v0.3.0).

## Version 0.2.1

> 2016 November 2

- [#24](https://github.com/scalacenter/scalajs-bundler/pull/24): Fixed npm command in Windows (thanks
  to [@DylanArnold](https://github.com/DylanArnold)) ;
- [#25](https://github.com/scalacenter/scalajs-bundler/pull/25): Fixed the `scalaJSPipeline` task
  to correctly support source maps.

You can find the complete list of commits since the last release
[here](https://github.com/scalacenter/scalajs-bundler/compare/v0.2...v0.2.1).

## Version 0.2

> 2016 November 1

- [#14](https://github.com/scalacenter/scalajs-bundler/pull/14): Improved documentation ;
- [#17](https://github.com/scalacenter/scalajs-bundler/pull/17): Faster live-reloading workflow
  (`fastOptJS::webpack` is ~10x faster) ;
- [#18](https://github.com/scalacenter/scalajs-bundler/pull/18): `ScalaJSBundlerPlugin` is not
  anymore automatically triggered: you have to manually enable it on your projects.
  `scalaJSModuleKind` is automatically set to `ModuleKind.CommonJSModule` when `ScalaJSBundlerPlugin`
  is enabled, so you don’t anymore have to set it in your build ;
- [#20](https://github.com/scalacenter/scalajs-bundler/pull/20): JavaScript files that are on
  the classpath can be `@JSImport`ed by your Scala facades.

You can find the complete list of commits since the last release
[here](https://github.com/scalacenter/scalajs-bundler/compare/v0.1...v0.2).


================================================
FILE: manual/src/ornate/community.md
================================================
# Community

- [![Gitter](https://badges.gitter.im/scalacenter/scalajs-bundler.svg)](https://gitter.im/scalacenter/scalajs-bundler?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
- [![Stackoverflow](https://img.shields.io/badge/ask-on%20stackoverflow-blue.svg)](http://stackoverflow.com/questions/tagged/scalajs-bundler)
- [![Github](https://img.shields.io/badge/contribute-on%20github-green.svg)](https://github.com/scalacenter/scalajs-bundler)

================================================
FILE: manual/src/ornate/cookbook.md
================================================
# Cookbook

![](toctree:local=true,mergeFirst=true)

## How to use a custom webpack configuration file? {#custom-config}

First, configure the `webpackConfigFile` setting to refer to your configuration file:

~~~ scala
webpackConfigFile in fastOptJS := Some(baseDirectory.value / "my.custom.webpack.config.js")
~~~

Or, if you want to use the same configuration file for both `fastOptJS` and `fullOptJS`:

~~~ scala
webpackConfigFile := Some(baseDirectory.value / "my.custom.webpack.config.js")
~~~

Then, you can write your configuration in file `my.custom.webpack.config.js`.
We recommend that you reuse the configuration file generated by scalajs-bundler
and extend it, rather than writing a configuration file from scratch.

You can do so as follows (in file `my.custom.webpack.config.js``):

~~~ javascript
var webpack = require('webpack');

module.exports = require('./scalajs.webpack.config');

// And then modify `module.exports` to extend the configuration
~~~

The key part is the `require('./scalajs.webpack.config')`. It loads the configuration
file generated by scalajs-bundler so that you can tweak it. It works because your configuration
file will be copied into the internal target directory, where the scalajs-bundler generates
its configuration file, and where all the npm dependencies have been downloaded (so you can
also `require` these dependencies).

By default `webpack` task only actually launches webpack if it detects changes in
settings or in the custom webpack config file. Depending on your usage scenario, you might
want to monitor some other files as well (for example, if your webpack config references
some additional resources). This can be achieved by using `webpackMonitoredDirectories`
setting:

~~~ scala
webpackMonitoredDirectories += baseDirectory.value / "my-scss"
includeFilter in webpackMonitoredFiles := "*.scss"
~~~

More fine-grained control over the list of monitored files is possible by overriding the
`webpackMonitoredFiles` task.

You can find a working example of custom configuration file
[here](https://github.com/scalacenter/scalajs-bundler/blob/main/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/static/prod.webpack.config.js).

It is also possible to configure a webpack config file to be used in reload workflow and when running the tests.
This configuration may not contain `entry` and `output` configuration but can be used to configure loaders etc.

These configuration files are configured using `webpackConfigFile in reloadTask` or `webpackConfigFile in Test`.
For example:

~~~ scala
webpackConfigFile in webpackReload := Some(baseDirectory.value / "common.webpack.config.js")

webpackConfigFile in Test := Some(baseDirectory.value / "common.webpack.config.js")
~~~

## Sharing webpack configuration among configuration files {#shared-config}

In addition to the configured webpack config file, all .js files in the project base directory
(as configured using the `webpackResources` setting) are copied to the target directory so they can be imported
from the various configuration files.

Here are the steps to share the loader configuration among your prod and dev config files. This
uses webpack-merge for convenience. The same result could be accomplished using plain js only.

1. Put configuration in a common.webpack.config.js file:

~~~ javascript
module.exports = {
  module: {
    loaders: [
        ...
    ],
    rules: [
        ...
    ]
  }
}
~~~

2. Add webpack-merge to your `npmDevDependencies`:

~~~
npmDevDependencies in Compile += "webpack-merge" -> "4.1.0"
~~~

3. Merge in the common configuration in your dev.webpack.js file:

~~~ javascript
var merge = require("webpack-merge")
var commonConfig = require("./common.webpack.config.js")

module.exports = merge(commonConfig, {
    ...
})
~~~

You can find a working example of a project using a shared configuration file
[here](https://github.com/scalacenter/scalajs-bundler/blob/main/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sharedconfig).


## How to use npm modules from Scala code? {#facade}

Once you have [added npm dependencies](getting-started.md) to the packages you are interested
in, you have to *import* them from your code to effectively use them.

The recommended way to do that is to:

1. Write a [Scala.js](https://www.scala-js.org/doc/interoperability/facade-types.html)
  facade annotated with
  [`@JSImport`](https://www.scala-js.org/doc/interoperability/facade-types.html#a-nameimporta-imports-from-other-javascript-modules) ;
2. Refer to this facade from your code.

Let’s illustrate this with an example. Say that you want to write a facade for the following
npm module:

~~~ javascript tab="foo.js (CommonJS)"
exports.bar = function (i) { return i + 1 };
~~~

~~~ javascript tab="foo.js (ES6)"
export const bar = i => i + 1;
~~~

The corresponding Scala.js facade looks like the following:

~~~ scala
import scala.scalajs.js
import scala.scalajs.js.annotation.JSImport

@JSImport("foo", JSImport.Namespace)
@js.native
object foo extends js.Object {
  def bar(i: Int): Int = js.native
}
~~~

There are several points worth highlighting:

- The first parameter of the `@JSImport` annotation is the npm module path. This is
  the value you would pass to the
  [Nodejs `require`](https://nodejs.org/docs/latest/api/modules.html#modules_all_together)
  function ;
- The second parameter of `@JSImport` is the name of the imported member, or like in our
  case, `JSImport.Namespace`, to import the whole module instead of just one particular
  member ;
- The facade is concrete. It can either be a Scala `object` or a `class` ;
- The facade has a
  [“JS native” type](https://www.scala-js.org/doc/interoperability/facade-types.html).

> {.note}
> Other styles of facades (importing a member in particular, importing functions and classes,
> importing local JavaScript files, etc.) can be found in
> [these tests](https://github.com/scalacenter/scalajs-bundler/blob/main/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/facade-examples).

Finally, in your Scala code, just refer to the `foo` object:

~~~ scala
object Main {
  def main(args: Array[String]): Unit = {
    println(foo.bar(42))
  }
}
~~~

## How to publish a facade for an npm module? {#publish}

Create a project for the facade and enable the `ScalaJSBundlerPlugin` as described
[here](getting-started.md).

Implement the facade as explained in the [above section](cookbook.md#facade).

Publish the Scala.js project [as usual](http://www.scala-sbt.org/1.0/docs/Publishing.html).

Finally, to use the facade from another Scala.js project, this one needs both to add a
dependency on the facade and to enable the `ScalaJSBundlerPlugin` plugin.

> {.warning}
> Projects that **use** the facade also have to enable the `ScalaJSBundlerPlugin` plugin,
> otherwise the dependencies of the facade will not be resolved.

## How to use an existing facade assuming the JS library to be exposed to the global namespace? {#global-namespace}

Webpack is able to require external modules by using [imports-loader](https://github.com/webpack-contrib/imports-loader)
and expose them to the global namespace by using [expose-loader](https://github.com/webpack/expose-loader).
Thus, you can write a custom webpack configuration file that uses this loaders to expose the required
modules to the global namespace. Typically, this file will look like this:

~~~ javascript src=../../../sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/global-namespace-with-jsdom-unit-testing/common.webpack.config.js
~~~

Also, tweak your `build.sbt` to add the corresponding NPM dependencies and to use the
custom webpack configuration file:

~~~ scala src=../../../sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/global-namespace-with-jsdom-unit-testing/build.sbt#relevant-settings
~~~

You can find a fully working example
[here](https://github.com/scalacenter/scalajs-bundler/blob/main/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/global-namespace-with-jsdom-unit-testing).

## How to bundle an application having several entry points as exports? {#several-entry-points}

By default, `ScalaJSBundlerPlugin` assumes that your application only has a main class, activated through
`scalaJSUseMainModuleInitializer := true`, and disregards top-level *exports*. If you have exports that
need to be exposed as several entry points, this will not work.

In such a case, you can use `BundlingMode.LibraryAndApplication()`.

`build.sbt`:
~~~ scala src=../../../sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/library/build.sbt#relevant-settings
~~~

Then, assuming that you defined the following library:

~~~ scala src="../../../sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/library/src/main/scala/example/Library.scala#library-definition"
~~~

You can call its methods as follows from your JavaScript code:

~~~ scala src="../../../sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/library/index.html#library-usage"
~~~

## How to improve the performance of the bundling process? {#performance}

You can enable the [library-only bundling mode](reference.md#bundling-mode-library-only) and disable source maps:

~~~ scala
webpackBundlingMode := BundlingMode.LibraryOnly()
emitSourceMaps := false
~~~

## How to select specific files from the `BundlingMode.Library` output

In [library-only bundling mode](reference.md#bundling-mode-library-only) and
[library with application bundling mode](reference.md#bundling-mode-library-and-application), the `webpack` task
produces multiple files. In order to determine which of these files is, for instance, the
[BundlerFileType.Application](api:scalajsbundler.BundlerFileType$$Application$), you
can use the `_.metadata` property of the files, like this:

~~~ scala src="../../../sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/static/build.sbt#filter-files"
~~~

## How to rebuild and reload your page on code changes? {#webpack-dev-server}

`scalajs-bundler` includes a simple wrapper over webpack-dev-server to simplify your
workflow. It is exposed as two stage-level tasks (`startWebpackDevServer` and
`stopWebpackDevServer`).
The standard work session looks like this:

1. Spawn background server process:
    ~~~
    > fastOptJS::startWebpackDevServer
    ~~~
    By default the server is started on port `8080`. Use `webpackDevServerPort` setting to change this.
2. Instruct SBT to rebuild on source changes:
    ~~~
    > ~fastOptJS
    ~~~
3. Now each time you change a source file, Scala.js recompiles it, and webpack-dev-server
    switches to the updated version.
4. Shut down the background process:
    ~~~
    > fastOptJS::stopWebpackDevServer
    ~~~

Additional arguments can be passed to webpack-dev-server via `webpackDevServerExtraArgs`
setting. For example, you can add the following to your `build.sbt` to make your page
reload on every change:
~~~
webpackDevServerExtraArgs := Seq("--inline")
~~~

## How to pass extra parameters to webpack

`scalajs-bundler` invokes `webpack` with a configuration generated either automatically from the build or set with `webpackConfigFile`.
`webpack` is then called with the following arguments:

~~~
--config <configfile>
~~~

You can add extra params to the `webpack` call, for example, to increase debugging

~~~
webpackExtraArgs := Seq("--profile", "--progress", "true")
~~~

**Note** Params are passed verbatim, they are not sanitized and could produce errors when passed to webpack.
In particular, don't attempt to override the `--config` param.

## How to use webpack 4

`scalajs-bundler` (version 0.12.0 onwards) supports webpack 4. To enable webpack 4, set the correct versions in `build.sbt`

~~~ scala
version in webpack := "4.8.1"

version in startWebpackDevServer := "3.1.4"
~~~

Additionally, you need to update any webpack plugins your config uses, to Webpack 4 compatible versions.

Webpack 4 has the potential to substantially reduce your webpack compilation times (80% reductions have been observed but your mileage may vary)

## How to get and use a list of assets

`scalajs-bundler` (version 0.13.0 onwards) will export a list of all assets produced by webpack. You can read that list on sbt

~~~ scala
val files = (webpack in (Compile, fullOptJS)).value
~~~

You can this list e.g. with [sbt-native-packager](https://github.com/sbt/sbt-native-packager)` to add mappings as:
~~~ scala src="../../../sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets-cookbook/build.sbt#scalajs-files"
~~~

This will add all artifacts produced by the fully optimized Scala.JS run to the 'assets' directory of the target archive.

If you need to package additional libraries that have been downloaded by `scalajs-bundler`, you can do something like:
~~~ scala src="../../../sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets-cookbook/build.sbt#additional-files"
~~~
Also, any static resources that you would like to have in the resulting archive (i.e. `index.html`), should live inside the `src/universal` directory of your project.


================================================
FILE: manual/src/ornate/getting-started.md
================================================
# Getting started

## Basic setup

You need to have `npm` installed on your system.

Add the `sbt-scalajs-bundler` plugin to your Scala.js project, in your `project/plugins.sbt` file:

~~~ scala expandVars=true
// For Scala.js 1.x
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "{{version}}")
// Or, for Scala.js 0.6.x
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler-sjs06" % "{{version}}")
~~~

> {.note}
> The plugin requires Scala.js 0.6.26+ or 1.0.0-RC1 and either
> sbt 0.13.17+ or 1.2.1+.

Enable the `ScalaJSBundlerPlugin`, in your `build.sbt` file:

~~~ scala
enablePlugins(ScalaJSBundlerPlugin)
~~~

If you have a `main` method, make sure that you enable the Scala.js main module initializer with the following setting:

~~~ scala
scalaJSUseMainModuleInitializer := true
~~~

Add dependencies to the npm packages your application requires, in your `build.sbt` file, e.g.:

~~~ scala
npmDependencies in Compile += "snabbdom" -> "0.5.3"
~~~

> {.note}
> You will most probably want to write a [Scala.js facade](https://www.scala-js.org/doc/interoperability/facade-types.html#-imports-from-other-javascript-modules)
> for the JavaScript module. You can find information on how to do that in the
> [cookbook](cookbook.md#facade), or draw inspiration from
> [this example](https://github.com/scalacenter/scalajs-bundler/blob/main/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/browserless/src/main/scala/uuid/uuid.scala).

Then, use the `fastOptJS::webpack` sbt command to download the npm packages and bundle your Scala.js
application and its dependencies into a single JavaScript file executable by a web browser.

In this example, the `webpack` sbt task produces a single file located at
`target/scala-2.12/scalajs-bundler/main/<project-id>-fastopt-bundle.js`.

See complete examples in the [tests](https://github.com/scalacenter/scalajs-bundler/tree/main/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler).

## Integrating with sbt-web {#sbt-web}

For sbt-web integration use the `sbt-web-scalajs-bundler` plugin instead of `sbt-scalajs-bundler`:

~~~ scala expandVars=true
// For Scala.js 1.x
addSbtPlugin("ch.epfl.scala" % "sbt-web-scalajs-bundler" % "{{version}}")
// Or, for Scala.js 0.6.x
addSbtPlugin("ch.epfl.scala" % "sbt-web-scalajs-bundler-sjs06" % "{{version}}")
~~~

Then, enable the `WebScalaJSBundlerPlugin` on the project that uses sbt-web:

~~~ scala
lazy val server = project
  .settings(
    scalaJSProjects := Seq(client),
    pipelineStages in Assets := Seq(scalaJSPipeline)
  )
  .enablePlugins(WebScalaJSBundlerPlugin)

lazy val client = project.enablePlugins(ScalaJSBundlerPlugin)
~~~

You also need to setup the `ScalaJSBundlerPlugin` on the Scala.js project, as described in the preceding section, and
the `sbt-web-scalajs` plugins as described in [their documentation](https://github.com/vmunier/sbt-web-scalajs).
Note that `sbt-web-scalajs`'s `ScalaJSWeb` plugin must **not** be enabled, because `ScalaJSWeb` will create source
mappings to source files copied to a hash path, which conflict with `ScalaJSBundlerPlugin`'s webpack-based source mappings.

The `WebScalaJSBundlerPlugin` plugin automatically configures the `scalaJSPipeline` task to use
the bundles rather than the output of the Scala.js compilation.

You can see a complete example [here](https://github.com/scalacenter/scalajs-bundler/tree/ma/sbt-web-scalajs-bundler/src/sbt-test/sbt-web-scalajs-bundler/play).


================================================
FILE: manual/src/ornate/index.md
================================================
# scalajs-bundler

scalajs-bundler is a module bundler for Scala.js projects that use npm packages: it bundles the .js file
emitted by the Scala.js compiler with its npm dependencies into a single .js file executable by Web browsers.

scalajs-bundler uses [npm](https://www.npmjs.com) and [webpack](https://webpack.github.io/) under the hood.

Last stable version is ![](config:version):

~~~ scala expandVars=true
// For Scala.js 1.x
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "{{version}}")
// Or, for Scala.js 0.6.x
addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler-sjs06" % "{{version}}")
~~~

If you're using [sbt-crossproject](https://github.com/portable-scala/sbt-crossproject) you need to add plugin via `jsConfigure`:

~~~ scala expandVars=true
lazy val cross = crossProject(JSPlatform, JVMPlatform).in(file("."))
  .jvmSettings(BuildSettings.jvmSettings)
  .jsSettings(BuildSettings.jsSettings)
  .jsConfigure { project => project.enablePlugins(ScalaJSBundlerPlugin) }
~~~

See the [**getting started**](getting-started.md) page for more details about
the setup process.


================================================
FILE: manual/src/ornate/motivation.md
================================================
# Motivation

The most popular JavaScript package registry is npm. Scala.js projects are usually based on sbt,
which has no knowledge of npm. So, how can Scala.js developers get an *integrated experience* when
they use libraries published on npm?

## WebJars

A first solution is to use [WebJars](http://www.webjars.org/). WebJars wrap .js files into .jar
archives published on maven central, so that Scala developers can depend on them just like
they depend on JVM libraries. However, WebJars have limitations.

First, npm packages are not automatically available as WebJars as soon as they are published on
the npm registry. So, WebJars users have to explicitly publish these npm packages as .jar packages.
This is just a matter of filling and submitting a form with the name and version of the package, 
but, still, this is one extra step.

Second, the tool that re-publishes npm packages as .jar packages does not keep track of
[transitive dependencies](https://github.com/webjars/webjars/issues/1186).
It means that when your program depends on a library `foo` that itself depends on a library `bar`,
then you have to explicitly convert both and depend on both in your program. This situation
might turn into a dependency management hell.

## Double build

Another solution consists in having two build systems: one for the Scala world and one for
the npm world. At some point, the npm build writes files consumed by the Scala application.

Typically, the npm build defines npm dependencies and bundles them into a single .js
file suitable for web browser consumption and that the Scala.js program can depend
on (e.g. using `jsDependencies`).

This approach works well and allows developers to use whatever tools they want to process
the npm dependencies.

However, having two build systems is not really an _integrated_ developer experience:
developers have to setup two builds, run two shells, and manually take care of the
relationship between the two builds.

## scalajs-bundler

scalajs-bundler aims to provide an integrated solution to work with npm packages from
Scala.js projects. It lets developers define their npm dependencies from within their sbt build,
fetches them (using npm itself), and bundles them with the output of the Scala.js compilation.
The result is a single .js file suitable for web browser consumption.


================================================
FILE: manual/src/ornate/reference.md
================================================
# Reference

## `ScalaJSBundlerPlugin`

The `ScalaJSBundlerPlugin` sbt plugin automatically enables `ScalaJSPlugin` on the project. It configures
the kind of output of the project to be `ModuleKind.CommonJSModule`. Finally, it also configures its
execution environment so that npm packages are fetched (by running the `npm update` command in the
project’s target directory) before the project is `run` or `test`ed.

It is also possible to bundle the application and its dependencies into a single .js file by using
the `webpack` task scoped to a Scala.js stage (`fastOptJS` or `fullOptJS`):

~~~
> fastOptJS::webpack
~~~

The `webpack` task returns a list of artifacts produced by the bundling process.

### JavaScript Dependencies {#npm-dependencies}

To define the npm packages your project depends on, use the `npmDependencies` key:

~~~ scala
npmDependencies in Compile += "uuid" -> "~3.1.0"
~~~

You can also scope dependencies to `Test`:

~~~ scala
npmDependencies in Test += "jasmine" -> "2.5.2"
~~~

> {.note}
> Your facades must use
> [`@JSImport`](https://www.scala-js.org/doc/interoperability/facade-types.html#a-nameimporta-imports-from-other-javascript-modules)
> in order to work with the npm modules, otherwise you will need some additional configuration, as explained
> [here](cookbook.md#global-namespace).

Last but not least, the `.js` files that are in your classpath and in the `jsSourceDirectories` are automatically
copied to the working directory of the `node` command. This means that you can also `@JSImport` these modules from
your Scala facades (you can see an example
[here](https://github.com/scalacenter/scalajs-bundler/blob/main/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/js-resources/src/main/scala/example/MyModule.scala#L6)).

### jsdom Support for Tests {#jsdom}

If your tests execution environment require the DOM, add the following line to your build:

~~~ scala
requireJsDomEnv in Test := true
~~~

Then, `ScalaJSBundlerPlugin` will automatically download jsdom and bundle the tests before
their execution so that they can be loaded by jsdom.

You can find an example of project requiring the DOM for its tests
[here](https://github.com/scalacenter/scalajs-bundler/blob/main/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/static/).

### Yarn {#yarn}

By default, `npm` is used to fetch the dependencies but you can use [Yarn](https://yarnpkg.com/) by setting the
`useYarn` key to `true`:

~~~ scala
useYarn := true
~~~

If your sbt (sub-)project directory contains a `yarn.lock`, it will be used. Else, a new one will be created. You should check `yarn.lock` into source control.

Yarn 0.22.0+ must be available on your machine.

### Bundling Mode {#bundling-mode}

Each time you change something in your application source code and compile the project, Scala.js emits a new .js 
file that can weigh several MBs if your application is large. Scalajs-bundler provides
a few different options with respect to handling this large output file, controlled by setting the optional
`webpackBundlingMode` key and can be scoped to a Scala.js stage (`fastOptJS` or `fullOptJS`).

#### Application (default) {#bundling-mode-application}

`webpackBundlingMode := BundlingMode.Application` generates a webpack config that simply processes the Scala.js output file as an 
entrypoint. This means that webpack loaders, plugins, etc will work as usual. It also means that webpack will 
have to process a very large Scala.Js output file.

Turning this CommonJS module into code executable by web browsers takes time, often upwards of a minute. 

Nonetheless, this is identical to what you'd get if were to duplicate your workflow outside scalajs-bundler, 
so it remains the default.

#### Library Only {#bundling-mode-library-only}

You can get a much faster “change source and reload application” workflow by setting the 
`webpackBundlingMode := BundlingMode.LibraryOnly()` key. This bundling mode avoids having webpack process the entire
Scala.js output, but instead uses webpack to bundle all the javascript dependencies (determined via `@JSImport` 
and any changes to the `webpack.config.js`). This is accomplished by setting the webpack `output.library` and 
`output.libraryTarget` keys in the webpack.config. By default, this generates a global variable named
`ScalaJSBundlerLibrary`, but if needed, that variable name can be overridden via the `exportedName` 
parameter provided to `BundlingMode.LibraryOnly`.

The drawback of this mode is that because the output of Scala.js is not processed by Webpack, it is
still a CommonJS module that is not directly executable by web browsers. This problem is addressed
by including a special “loader” before including the Scala.js module.

> {.warning}
> The inclusion of a CommonJS module in the web browser is not guaranteed to work. In particular,
> in `fullOptJS` mode the name mangler might produce names that could clash with other existing
> global names. For this reason, we don’t recommend using the `LibraryOnly` bundling mode in `fullOptJS`,
> or in production.

In order to use this mode, instead of including `yourapp-bundle.js` in your page, you will need to include
`yourapp-library.js` (which contains all the application libraries bundled into a single file),
`yourapp-loader.js` (which contains a hack to make the application work), and `yourapp-fastopt.js` or
`yourapp-opt.js` (which contains the output of Scala.js, that is a CommonJS module). If you're using Play 
Framework, you could use a twirl template similar to this one:

~~~ html
@(projectName: String,
  assets: String => String,
  resourceExists: String => Boolean,
  htmlAttributes: Html = Html("")
)

@defining(s"${projectName.toLowerCase}") { name =>
  @Seq(s"$name-opt-library.js", s"$name-fastopt-library.js").find(resourceExists).map(name => jsScript(assets(name), htmlAttributes))
}
<script language="JavaScript">
var exports = window;
exports.require = window["ScalaJSBundlerLibrary"].require;
</script>
@defining(s"${projectName.toLowerCase}") { name =>
  @Seq(s"$name-opt.js", s"$name-fastopt.js").find(resourceExists).map(name => jsScript(assets(name), htmlAttributes))
}
~~~

The default variable global for the library is `ScalaJsBundlerDependencies`. Should you need to change it, 
you can provide a new variable name to the configuration, such as `webpackBundlingMode := BundlingMode.LibrariesOnly("myLib")`.

##### Benefits

By avoiding processing the entire Scala.js output file, webpack times from 10's of seconds to minutes to 
a couple of seconds, depending on how many dependencies webpack has to resolve. In addition, since the 
module references are all still managed by webpack, any custom loaders such as the `html-loader` or `text-loader`
will work as usual. Other webpack configuration such as external modules also work out of the box.

By splitting the output into a separate library and Scala.js app we are able to leverage browser caching for most
reloads, since it's seldom that both .js assets and Scala.js assets change at the same time. 

By avoiding any post-processing of the Scala.js output, we leave the sourcemap generated by the Scala.js compiler
entirely intact. This means we avoid any translation or lookup errors introduced by webpack, and also means
we save a bunch more processing time even if sourcemaps are enabled.

##### How It Works
Scalajs-bundler has a unique advantage in the JavaScript build ecosystem in that it runs inside SBT and has
access to the Scala.Js compiler internals. By leveraging these, we can generate a fake `entrypoint.js` file that 
represents all the `@JSImport`s from a Scala.JS project. We can use this entrypoint to generate a library file
that provides access to all those imports without webpack having to ever process the entire Scala.js output. 

Inside the `entrypoint.js` file we also provide a trivial `require` implementation that provides access to the
modules which were imported.

All that remains is to provide an `exports` variable with a reference to the `require` implementation
for the Scala.js out to hang onto, which is what the loader provides.

#### Library and Application {#bundling-mode-library-and-application}

`bundlingMode := BundlingMode.LibraryAndApplication()` builds on `BundlingMode.LibraryOnly` and attempts to 
produce only one artifact (like the `Application` bundling mode) without the overhead processing the entire
Scala.js output file. 
It uses the same library file generation process as `BundlingMode.LibraryOnly`. It then bundles that library, 
the loader, and the Scala.js output into a `yourapp-bundle` file by concatenating them. If `enableSourceMaps := true`, 
it will attempt to use the node.js `concat-with-sourcemaps` module to combine the sourcemaps as well. 

If you need interoperability with the full `Application` mode or somehow can't handle the two files generated
by the `LibraryOnly()` mode, this mode may be useful for you. However, it relies on post-processing and eliminates
some of the benefits of the `LibraryOnly` mode, so consider carefully if you really need it before turning it on.

### Tasks and Settings {#tasks-and-settings}

The tasks and settings that control the plugin are documented in the API documentation
of the [ScalaJSBundlerPlugin](api:scalajsbundler.sbtplugin.ScalaJSBundlerPlugin$).

## `WebScalaJSBundlerPlugin`

The `WebScalaJSBundlerPlugin` provides integration with [sbt-web-scalajs](https://github.com/vmunier/sbt-web-scalajs).
Enable this plugin on JVM projects that need to use .js artifacts produced by Scala.js projects (ie in places
where you used to enable `WebScalaJS`).

The plugin tunes the `scalaJSPipeline` to use the bundles produced by webpack rather than the direct
output of the Scala.js compilation.

### Importing Assets from NPM Packages {#npm-assets}

Some NPM packages also contain static assets (e.g. fonts, stylesheets, images, etc.). You can make them available
as sbt-web assets as follows:

~~~ scala
npmAssets ++= NpmAssets.ofProject(client) { nodeModules =>
  (nodeModules / "font-awesome").allPaths // sbt 1.0.0+
}.value
~~~

> Note: for older sbt versions use `(nodeModules / "font-awesome").***` instead.

Where `client` is the identifier of an sbt project that uses the `ScalaJSBundlerPlugin`. The above configuration
makes all the files within the `font-awesome` package available as sbt-web assets.
These assets keep their path prefix relative to the `node_modules` directory: for instance the asset path of the
`css/font-awesome.min.css` resource is `font-awesome/css/font-awesome.min.css`.

### Tasks and Settings {#web-tasks-and-settings}

The tasks and settings that control the plugin are documented in the API documentation
of the [WebScalaJSBundlerPlugin](api:scalajsbundler.sbtplugin.WebScalaJSBundlerPlugin$).


================================================
FILE: manual/src/ornate.conf
================================================
global {
  toc = [
    { title = "Introduction", url = "index.md" }
    motivation.md
    getting-started.md
    reference.md
    cookbook.md
    community.md
    changelog.md
  ]
}

meta {
  siteTitle = "scalajs-bundler"
}

version = ${version}

extension.scaladocLinks {
  api {
    index = "unchecked:/api/latest/index.html"
  }
}

================================================
FILE: project/build.properties
================================================
sbt.version = 1.8.2


================================================
FILE: project/plugins.sbt
================================================
addSbtPlugin("com.typesafe.sbt"  % "sbt-site"       % "1.4.1")
addSbtPlugin("com.novocode"      % "sbt-ornate"     % "0.6")
addSbtPlugin("com.github.sbt"      % "sbt-unidoc"     % "0.5.0")
addSbtPlugin("com.eed3si9n"      % "sbt-buildinfo"  % "0.11.0")
addSbtPlugin("com.github.sbt"      % "sbt-ci-release" % "1.5.12")

ivyLoggingLevel in ThisBuild := UpdateLogging.Quiet


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/BundlerFile.scala
================================================
package scalajsbundler

import java.io.File
import java.nio.file.Path

import scalajsbundler.Stats.WebpackStats
import scalajsbundler.util.CachedBundleFiles
import scala.collection.immutable.ListSet

/**
  * Files used in the `ScalaJSBundler` pipeline.
  */
sealed trait BundlerFile extends Product with Serializable {
  def file: File
}

object BundlerFile {
  /**
    * Files that may be inputs to the webpack process
    */
  sealed trait WebpackInput extends BundlerFile {
    def project: String
  }

  /**
    * Internal-only files
    */
  sealed abstract class Internal extends BundlerFile

  /**
    * A library-mode entrypoint file
    * @param application The [[Application]] this entrypoint was generated from
    * @param file The file containing the entry point
    */
  case class EntryPoint(application: Application, file: java.io.File)
      extends Internal
      with WebpackInput {
    def project: String = application.project
  }

  object EntryPoint {
    /** Filename of the generated bundle, given its module entry name */
    def fileName(entry: String): String = s"$entry-entrypoint.js"
  }

  /**
    * The package.json file, used for populating the node_modules folder
    *
    * @param file The file reference for the package.json
    */
  case class PackageJson(file: java.io.File) extends Internal

  /**
    * A webpack configuration file.
    *
    * @param application The [[Application]] this file runs webpack for
    * @param file The webpack.config.js file reference
    */
  case class WebpackConfig(application: Application, file: java.io.File)
      extends Internal {
    def project: String = application.project

    def targetDir: Path = file.getParentFile.toPath

    /**
      * Returns the Library identifying the asset produced by scala.js through webpack stats
      */
    def asLibrary(stats: Option[WebpackStats]): Library =
      Library(project,
              stats.flatMap { s =>
                s.resolveAsset(targetDir, project)
              }.getOrElse(targetDir.resolve(Library.fileName(project)).toFile),
              stats.map { s =>
                s.resolveAllAssets(targetDir)
              }.getOrElse(Nil)
            )

    /**
      * Returns library from a set of cached files
      * By convention the first element is the `file` and the rest are the assets
      */
    def asLibraryFromCached(cached: Set[File]): Library = {
      assert(cached.size >= 1)
      val assets = if (cached.size == 1) Nil else cached.tail.toList
      Library(project, cached.head, assets)
    }

    /**
      * Returns the Application for this configuration identifying the asset produced by scala.js through webpack stats
      */
    def asApplicationBundle(stats: Option[WebpackStats]): ApplicationBundle =
      ApplicationBundle(project,
                        stats.flatMap { s =>
                          s.resolveAsset(targetDir, project)
                        }.getOrElse(targetDir.resolve(ApplicationBundle.fileName(project)).toFile),
                        stats.map { s =>
                          s.resolveAllAssets(targetDir)
                        }.getOrElse(Nil))

    /**
      * Returns an application bundle from a set of cached files
      * By convention the first element is the `file` and the rest are the assets
      */
    def asApplicationBundleFromCached(cached: Set[File]): ApplicationBundle = {
      assert(cached.size >= 1)
      val assets = if (cached.size == 1) Nil else cached.tail.toList
      ApplicationBundle(project, cached.head, assets)
    }
  }

  /**
    * Public webpack artifacts -- those that might be served to clients or packaged
    */
  sealed abstract class Public extends BundlerFile {
    def project: String
    // Attributed files, the first is the main file and the rest are assets
    def attributedFiles: (File, Seq[File]) = (file, Seq.empty)
    def `type`: BundlerFileType
  }

  /**
    * The Scala.js application itself, aka -fastopt.js or -opt.js
    *
    * @param project The application project name
    * @param file The file containing the application javascript
    * @param assets All the assets on the application
    */
  case class Application(project: String, file: File, assets: List[java.io.File])
      extends Public
      with WebpackInput {

    def targetDir: Path = file.getParentFile.toPath

    val `type`: BundlerFileType = BundlerFileType.Application
    def asLoader: Loader =
      Loader(this,
             targetDir
               .resolve(Loader.fileName(project))
               .toFile)

    def asEntryPoint: EntryPoint =
      EntryPoint(this,
                 targetDir
                   .resolve(EntryPoint.fileName(project))
                   .toFile)

    def asApplicationBundle: ApplicationBundle =
      ApplicationBundle(project,
                        targetDir
                          .resolve(ApplicationBundle.fileName(project))
                          .toFile,
                        assets)

    /**
      * Returns an application bundle from a set of cached files
      */
    def asApplicationBundleFromCached(cached: Set[File]): ApplicationBundle = {
      assert(cached.size >= 1)
      val assets = if (cached.size == 1) Nil else cached.tail.toList
      ApplicationBundle(project, cached.head, assets)
    }
  }

  /**
    * A webpack library bundle, containing only libraries
    * @param project The project the library bundle was generated for
    * @param file The file containing the application javascript
    * @param assets All the assets on the application
    */
  case class Library(project: String, file: File, assets: List[java.io.File]) extends Public {
    val `type`: BundlerFileType = BundlerFileType.Library
    val cached: ListSet[File] = CachedBundleFiles.cached(file, assets)

    override def attributedFiles: (File, Seq[File]) = (file, assets)
  }

  object Library {

    /** Suffix to apply to the libraries bundle */
    val suffix: String = "-library.js"

    /** Filename of the generated libraries bundle, given its module entry name */
    def fileName(entry: String): String = s"$entry$suffix"
  }

  /**
    * A webpack loader file. Allows an [[Application]] to access the dependencies bundled
    * into a [[Library]]
    * @param application Application to be loaded
    * @param file Loader file
    */
  case class Loader(application: Application, file: java.io.File)
      extends Public {
    val `type`: BundlerFileType = BundlerFileType.Loader
    def project: String = application.project
  }

  object Loader {

    /** Suffix to apply to the loaders file */
    val suffix: String = "-loader.js"

    /** Filename of the generated bundle, given its module entry name */
    def fileName(entry: String): String = s"$entry$suffix"
  }

  /**
    * A fully self-contained application bundle, including all dependencies.
    *
    * @param project The project name
    * @param file The file containing the application javascript
    * @param assets All the assets on the application
    */
  case class ApplicationBundle(project: String, file: File, assets: List[java.io.File])
      extends Public {
    val `type`: BundlerFileType = BundlerFileType.ApplicationBundle

    val cached: ListSet[File] = CachedBundleFiles.cached(file, assets)

    override def attributedFiles: (File, Seq[File]) = (file, assets)
  }

  object ApplicationBundle {

    /** Filename of the generated bundle, given its module entry name */
    def fileName(entry: String): String = s"$entry-bundle.js"
  }
}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/BundlerFileType.scala
================================================
package scalajsbundler

/**
  * The type of a given [[BundlerFile.Public]]. Used for tagging files when they are produced by
  * the ScalaJsBundler and handed off to other SBT tasks.
  */
sealed abstract class BundlerFileType

object BundlerFileType {

  /**
    * Scala.js application
    */
  case object Application extends BundlerFileType

  /**
    * Library dependencies provided by webpack
    */
  case object Library extends BundlerFileType

  /**
    * Dependency loader, provides [[Library]] dependencies to [[Application]]
    */
  case object Loader extends BundlerFileType

  /**
    * Fully linked application bundle, containing [[Application]] and all it's dependencies
    */
  case object ApplicationBundle extends BundlerFileType

  /**
    * An asset of the bundled application
    */
  case object Asset extends BundlerFileType
}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/BundlingMode.scala
================================================
package scalajsbundler

/**
  * The BundlingMode dictates how webpack is configured for bundling. Please refer
  * to the members of the sealed family details.
  */
sealed trait BundlingMode

object BundlingMode {

  /**
    * Bundle the entire application with webpack. Using this mode, the webpack `entry` key will
    * contain the Scala.js output file. All dependencies will be resolved via webpack, and the entire
    * bundle will be processed by any plugins. The output will be a runnable bundle, not a library.
    *
    * To see the specific webpack configuration that will be generated, refer to [[Webpack.writeConfigFile]].
    */
  case object Application extends BundlingMode

  /**
    * Shared base class for [[LibraryOnly]] and [[LibraryAndApplication]]. Both
    * must provide an `exportedName` field indicating what javascript global
    * the libraries will be exported to. Both library modes will generate an `entrypoints` file based
    * on the Scala.js imports and use that as the `entrypoint` for the generated `webpack.config.js`. The webpack
    * output will be a library, which will assign itself to a global variable when loaded.
    *
    * The `entrypoints` file also contains a `require` implementation, which can be exposed globally by including
    * the `loader` file. Refer to [[util.JSBundler.loaderScript]] for an example of such a script.
    *
    * To see the specific webpack configuration that will be generated, refer to [[Webpack.writeConfigFile]].
    */
  sealed trait Library extends BundlingMode {

    /**
      * Name of the global variable containing the dependencies
      */
    def exportedName: String
  }

  /**
    * Bundle only the libraries used by the application. This mode will generate an `entrypoints` file based
    * on the Scala.js imports and use that as the entrypoint for the generated `webpack.config.js`. The webpack
    * output will be a library, which will assign itself to a global variable when loaded.
    *
    * The `library` file produce in this mode must be combined with the `loader` and the Scala.js output in order
    * to fully duplicate the usability of [[Application]] mode.
    *
    * Refer to [[Library]] for additional details.
    *
    */
  case class LibraryOnly(exportedName: String = defaultLibraryExportedName) extends Library

  /**
    * Builds on [[LibraryOnly]] by generating the `loader` and concatenating it with the Scala.js output file. This
    * output is designed to be a drop-in replacement for fully processing the file via webpack ([[Application]] mode). When
    * `webpackEmitSourceMaps := true`, this mode will attempt to merge all the files using the node.js
    * 'concat-with-sourcemaps' module.
    *
    * Refer to [[Library]] for additional details.
    */
  case class LibraryAndApplication(exportedName: String = defaultLibraryExportedName) extends Library

  /**
    * The default exported library name, used by [[LibraryOnly]] and [[LibraryAndApplication]]
    */
  val defaultLibraryExportedName = "ScalaJSBundlerLibrary"

  /**
    * The default BundlingMode used by the ScalaJSBundler
    */
  val Default: BundlingMode = Application

}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/ExternalCommand.scala
================================================
package scalajsbundler

import java.io.File

import sbt._
import scalajsbundler.util.Commands

/**
  * Attempts to smoothen platform-specific differences when invoking commands.
  *
  * @param name Name of the command to run
  */
class ExternalCommand(name: String) {

  /**
    * Runs the command `cmd`
    * @param args Command arguments
    * @param workingDir Working directory of the process
    * @param logger Logger
    */
  def run(args: String*)(workingDir: File, logger: Logger): Unit =
    Commands.run(cmd ++: args, workingDir, logger)

  private val cmd = sys.props("os.name").toLowerCase match {
    case os if os.contains("win") => Seq("cmd", "/c", name)
    case _                        => Seq(name)
  }

}

object Npm extends ExternalCommand("npm")

object Yarn extends ExternalCommand("yarn")

object ExternalCommand {
  private val yarnOptions = List("--non-interactive", "--mutex", "network")

  private def syncLockfile(
    lockFileName: String,
    baseDir: File,
    installDir: File,
    logger: Logger
  )(
      command: => Unit
  ): Unit = {
    val sourceLockFile = baseDir / lockFileName
    val targetLockFile = installDir / lockFileName

    if (sourceLockFile.exists()) {
      logger.info("Using lockfile " + sourceLockFile)
      IO.copyFile(sourceLockFile, targetLockFile)
    }

    command

    if (targetLockFile.exists()) {
      logger.debug("Wrote lockfile to " + sourceLockFile)
      IO.copyFile(targetLockFile, sourceLockFile)
    }
  }

  private def syncYarnLockfile(
    baseDir: File,
    installDir: File,
    logger: Logger
  )(
    command: => Unit
  ): Unit = {
    syncLockfile("yarn.lock", baseDir, installDir, logger)(command)
  }

  private def syncNpmLockfile(
    baseDir: File,
    installDir: File,
    logger: Logger
  )(
    command: => Unit
  ): Unit = {
    syncLockfile("package-lock.json", baseDir, installDir, logger)(command)
  }

  /**
    * Locally install NPM packages
    *
    * @param baseDir The (sub-)project directory which contains yarn.lock
    * @param installDir The directory in which to install the packages
    * @param useYarn Whether to use yarn or npm
    * @param logger sbt logger
    * @param npmExtraArgs Additional arguments to pass to npm
    * @param npmPackages Packages to install (e.g. "webpack", "webpack@2.2.1")
    */
  def addPackages(baseDir: File,
                  installDir: File,
                  useYarn: Boolean,
                  logger: Logger,
                  npmExtraArgs: Seq[String],
                  yarnExtraArgs: Seq[String])(npmPackages: String*): Unit =
    if (useYarn) {
      syncYarnLockfile(baseDir, installDir, logger) {
        Yarn.run("add" +: (yarnOptions ++ yarnExtraArgs ++ npmPackages): _*)(
          installDir,
          logger)
      }
    } else {
      syncNpmLockfile(baseDir, installDir, logger) {
        Npm.run("install" +: (npmPackages ++ npmExtraArgs): _*)(installDir, logger)
      }
    }

  def install(baseDir: File,
              installDir: File,
              useYarn: Boolean,
              logger: Logger,
              npmExtraArgs: Seq[String],
              yarnExtraArgs: Seq[String]): Unit =
    if (useYarn) {
      syncYarnLockfile(baseDir, installDir, logger) {
        Yarn.run("install" +: (yarnOptions ++ yarnExtraArgs): _*)(installDir,
                                                                  logger)
      }
    } else {
      syncNpmLockfile(baseDir, installDir, logger) {
        Npm.run("install" +: npmExtraArgs: _*)(installDir, logger)
      }
    }
}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/JSDOMNodeJSEnv.scala
================================================
package scalajsbundler

import scala.util.control.NonFatal

import sbt._

import java.io._
import java.nio.charset.StandardCharsets
import java.nio.file.{Files, Path, StandardCopyOption}
import java.net.URI

import org.scalajs.jsenv._
import org.scalajs.jsenv.nodejs._
import org.scalajs.jsenv.JSUtils.escapeJS

// HACK Copy of Scala.js’ JSDOMNodeJSEnv. The only change is the ability to pass the directory in which jsdom has been installed
class JSDOMNodeJSEnv(config: JSDOMNodeJSEnv.Config) extends JSEnv {

  val name: String = "Node.js with JSDOM"

  def start(input: Seq[Input], runConfig: RunConfig): JSRun = {
    JSDOMNodeJSEnv.validator.validate(runConfig)
    val scripts = validateInput(input)
    try {
      internalStart(codeWithJSDOMContext(scripts), runConfig)
    } catch {
      case NonFatal(t) =>
        JSRun.failed(t)
    }
  }

  def startWithCom(input: Seq[Input], runConfig: RunConfig,
      onMessage: String => Unit): JSComRun = {
    JSDOMNodeJSEnv.validator.validate(runConfig)
    val scripts = validateInput(input)
    ComRun.start(runConfig, onMessage) { comLoader =>
      internalStart(comLoader :: codeWithJSDOMContext(scripts), runConfig)
    }
  }

  private def validateInput(input: Seq[Input]): List[Path] = {
    input.map {
      case Input.Script(script) =>
        script

      case _ =>
        throw new UnsupportedInputException(input)
    }.toList
  }

  private def internalStart(files: List[Path], runConfig: RunConfig): JSRun = {
    val command = config.executable :: config.args
    val externalConfig = ExternalJSRun.Config()
      .withEnv(env)
      .withRunConfig(runConfig)
    ExternalJSRun.start(command, externalConfig)(JSDOMNodeJSEnv.write(files))
  }

  private def env: Map[String, String] =
    Map("NODE_MODULE_CONTEXTS" -> "0") ++ config.env

  private def codeWithJSDOMContext(scripts: List[Path]): List[Path] = {
    val scriptsURIs = scripts.map(JSDOMNodeJSEnv.materialize(_))
    val scriptsURIsAsJSStrings =
      scriptsURIs.map(uri => "\"" + escapeJS(uri.toASCIIString) + "\"")
    val scriptsURIsJSArray = scriptsURIsAsJSStrings.mkString("[", ", ", "]")
    val jsDOMCode = {
      s"""
         |
         |(function () {
         |  var jsdom = require("jsdom");
         |
         |  if (typeof jsdom.JSDOM === "function") {
         |    // jsdom >= 10.0.0
         |    var virtualConsole = new jsdom.VirtualConsole()
         |      .sendTo(console, { omitJSDOMErrors: true });
         |    virtualConsole.on("jsdomError", function (error) {
         |      try {
         |        // Display as much info about the error as possible
         |        if (error.detail && error.detail.stack) {
         |          console.error("" + error.detail);
         |          console.error(error.detail.stack);
         |        } else {
         |          console.error(error);
         |        }
         |      } finally {
         |        // Whatever happens, kill the process so that the run fails
         |        process.exit(1);
         |      }
         |    });
         |
         |    var dom = new jsdom.JSDOM("", {
         |      virtualConsole: virtualConsole,
         |      url: "http://localhost/",
         |
         |      /* Allow unrestricted <script> tags. This is exactly as
         |       * "dangerous" as the arbitrary execution of script files we
         |       * do in the non-jsdom Node.js env.
         |       */
         |      resources: "usable",
         |      runScripts: "dangerously"
         |    });
         |
         |    var window = dom.window;
         |    window["scalajsCom"] = global.scalajsCom;
         |
         |    var scriptsSrcs = $scriptsURIsJSArray;
         |    for (var i = 0; i < scriptsSrcs.length; i++) {
         |      var script = window.document.createElement("script");
         |      script.src = scriptsSrcs[i];
         |      window.document.body.appendChild(script);
         |    }
         |  } else {
         |    // jsdom v9.x
         |    var virtualConsole = jsdom.createVirtualConsole()
         |      .sendTo(console, { omitJsdomErrors: true });
         |    virtualConsole.on("jsdomError", function (error) {
         |      /* This inelegant if + console.error is the only way I found
         |       * to make sure the stack trace of the original error is
         |       * printed out.
         |       */
         |      if (error.detail && error.detail.stack)
         |        console.error(error.detail.stack);
         |
         |      // Throw the error anew to make sure the whole execution fails
         |      throw error;
         |    });
         |
         |    jsdom.env({
         |      html: "",
         |      virtualConsole: virtualConsole,
         |      url: "http://localhost/",
         |      created: function (error, window) {
         |        if (error == null) {
         |          window["scalajsCom"] = global.scalajsCom;
         |        } else {
         |          throw error;
         |        }
         |      },
         |      scripts: $scriptsURIsJSArray
         |    });
         |  }
         |})();
         |""".stripMargin
    }

    val codeFile = config.jsDomDirectory / "codeWithJSDOMContext.js"
    IO.write(codeFile, jsDOMCode)
    List(codeFile.toPath())
  }
}

object JSDOMNodeJSEnv {
  private lazy val validator = ExternalJSRun.supports(RunConfig.Validator())

  /* Unlike NodeJSEnv.scala upstream, we use `require` to load files on-disk
   * rather than `runInThisContext`. We do this to preserve the enclosing
   * directory of the scripts, which is necessary for Node.js to find npm
   * packages in the directory hierarchy.
   *
   * We can do this in `JSDOMNodeJSEnv` because all the `files` are under our
   * control, and we know that none of them declares `var`s at the top-level
   * that would need to be accessed from other scripts.
   */
  private def write(files: List[Path])(out: OutputStream): Unit = {
    val p = new PrintStream(out, false, "UTF8")
    try {
      def writeRunScript(path: Path): Unit = {
        try {
          val f = path.toFile
          val pathJS = "\"" + escapeJS(f.getAbsolutePath) + "\""
          p.println(s"""require($pathJS);""")
        } catch {
          case _: UnsupportedOperationException =>
            val code = new String(Files.readAllBytes(path), StandardCharsets.UTF_8)
            val codeJS = "\"" + escapeJS(code) + "\""
            val pathJS = "\"" + escapeJS(path.toString) + "\""
            p.println(s"""
              require('vm').runInThisContext(
                $codeJS,
                { filename: $pathJS, displayErrors: true }
              );
            """)
        }
      }

      for (file <- files)
        writeRunScript(file)
    } finally {
      p.close()
    }
  }

  // tmpSuffixRE and tmpFile copied from HTMLRunnerBuilder.scala in Scala.js

  private val tmpSuffixRE = """[a-zA-Z0-9-_.]*$""".r

  private def tmpFile(path: String, in: InputStream): URI = {
    try {
      /* - createTempFile requires a prefix of at least 3 chars
       * - we use a safe part of the path as suffix so the extension stays (some
       *   browsers need that) and there is a clue which file it came from.
       */
      val suffix = tmpSuffixRE.findFirstIn(path).orNull

      val f = File.createTempFile("tmp-", suffix)
      f.deleteOnExit()
      Files.copy(in, f.toPath(), StandardCopyOption.REPLACE_EXISTING)
      f.toURI()
    } finally {
      in.close()
    }
  }

  private def materialize(path: Path): URI = {
    try {
      path.toFile.toURI
    } catch {
      case _: UnsupportedOperationException =>
        tmpFile(path.toString, Files.newInputStream(path))
    }
  }

  final class Config private (
    val jsDomDirectory: File,
    val executable: String,
    val args: List[String],
    val env: Map[String, String]
  ) {
    private def this(jsDomDirectory: File) = {
      this(
        jsDomDirectory,
        executable = "node",
        args = Nil,
        env = Map.empty
      )
    }

    def withExecutable(executable: String): Config =
      copy(executable = executable)

    def withArgs(args: List[String]): Config =
      copy(args = args)

    def withEnv(env: Map[String, String]): Config =
      copy(env = env)

    private def copy(
      executable: String = executable,
      args: List[String] = args,
      env: Map[String, String] = env
    ): Config = {
      new Config(jsDomDirectory, executable, args, env)
    }
  }

  object Config {
    /** Returns a default configuration for a [[JSDOMNodeJSEnv]].
      *
      *  The defaults are:
      *
      *  - `executable`: `"node"`
      *  - `args`: `Nil`
      *  - `env`: `Map.empty`
      */
    def apply(jsDomDirectory: File): Config = new Config(jsDomDirectory)
  }
}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/JsDomTestEntries.scala
================================================
package scalajsbundler

import sbt._

import scalajsbundler.util.JS

object JsDomTestEntries {

  /**
    * Loads the output of Scala.js and exports all its exported properties to the global namespace,
    * so that they are found by jsdom.
    * @param sjsOutput Scala.js output
    * @param loaderFile File to write the loader to
    */
  def writeLoader(sjsOutput: File, loaderFile: File): Unit = {
    val window = JS.ref("window")
    val require = JS.ref("require")
    val Object = JS.ref("Object")
    val loader =
      JS.let(
        require.apply(JS.str(sjsOutput.absolutePath))
      ) { tests =>
        Object.dot("keys").apply(tests).dot("forEach").apply(JS.fun { key =>
          window.bracket(key).assign(tests.bracket(key)) // Export all properties of the Scala.js module to the global namespace
        })
      }

    IO.write(loaderFile, loader.show)
  }

}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/NpmDependencies.scala
================================================
package scalajsbundler

import java.io.{BufferedInputStream, FileInputStream}
import java.util.zip.ZipInputStream

import play.api.libs.functional.syntax._
import play.api.libs.json.{Format, JsPath, Json, OFormat}
import sbt._
import scalajsbundler.NpmDependencies.Dependencies

/**
  * NPM dependencies, for each configuration.
  * This information can not be included in the pom.xml, so we
  * serialize for each Scala.js artifact into an additional file
  * in the artifact .jar.
  */
case class NpmDependencies(
  compileDependencies: Dependencies,
  testDependencies: Dependencies,
  compileDevDependencies: Dependencies,
  testDevDependencies: Dependencies
) {
  /** Merge operator */
  def ++ (that: NpmDependencies): NpmDependencies =
    NpmDependencies(
      compileDependencies ++ that.compileDependencies,
      testDependencies ++ that.testDependencies,
      compileDevDependencies ++ that.compileDevDependencies,
      testDevDependencies ++ that.testDevDependencies
    )
}

object NpmDependencies {

  /** Name of the file containing the NPM dependencies */
  val manifestFileName = "NPM_DEPENDENCIES"

  type Dependencies = List[(String, String)]

  implicit val serializer: OFormat[NpmDependencies] = (
    (JsPath \ "compile-dependencies").format[Dependencies] and
    (JsPath \ "test-dependencies").format[Dependencies] and
    (JsPath \ "compile-devDependencies").format[Dependencies] and
    (JsPath \ "test-devDependencies").format[Dependencies]
  )(NpmDependencies.apply, Function.unlift(NpmDependencies.unapply))

  implicit def tuple2Serializer[A](implicit aSerializer: Format[A]): Format[(String, A)] =
    implicitly[Format[Map[String, A]]].inmap(_.head, Map(_))

  /**
    * @param cp Classpath
    * @return All the NPM dependencies found in the given classpath
    */
  def collectFromClasspath(cp: Def.Classpath): NpmDependencies =
    (
      for {
        cpEntry <- Attributed.data(cp) if cpEntry.exists
        results <-
          if (cpEntry.isFile && cpEntry.name.endsWith(".jar")) {
            val stream = new ZipInputStream(new BufferedInputStream(new FileInputStream(cpEntry)))
            try {
              Iterator.continually(stream.getNextEntry())
                .takeWhile(_ != null)
                .filter(_.getName == NpmDependencies.manifestFileName)
                .map(_ => Json.parse(IO.readStream(stream)).as[NpmDependencies])
                .to[Seq]
            } finally {
              stream.close()
            }
          } else if (cpEntry.isDirectory) {
            for {
              (file, _) <- Path.selectSubpaths(cpEntry, new ExactFilter(NpmDependencies.manifestFileName))
            } yield {
              Json.parse(IO.read(file)).as[NpmDependencies]
            }
          } else sys.error(s"Illegal classpath entry: ${cpEntry.absolutePath}")
      } yield results
    ).fold(NpmDependencies(Nil, Nil, Nil, Nil))(_ ++ _)

  /**
    * Writes the given dependencies into a manifest file
    */
  def writeManifest(
    npmDependencies: NpmDependencies,
    classDirectory: File
  ): File = {
    val manifestFile = classDirectory / manifestFileName
    IO.write(manifestFile, Json.stringify(Json.toJson(npmDependencies)))
    manifestFile
  }

}

================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/NpmPackage.scala
================================================
package scalajsbundler

import play.api.libs.json.{JsPath, Json, Reads}
import sbt._

import scala.util.Try

case class NpmPackage(version: String) {
  def major: Option[Int] = {
    val r = """^(\d+)(\..*|)$""".r
    version match {
      case r(v, _) => Try(v.toInt).toOption
      case _ => None
    }
  }
}

object NpmPackage {
  implicit val npmPackageDeserializer: Reads[NpmPackage] =
    (JsPath \ "version").read[String].map(NpmPackage.apply)

  def getForModule(targetDir: File, module: String): Option[NpmPackage] = {
    val webpackPackageJsonFilePath = targetDir / "node_modules" / module / "package.json"

    Try(Json.parse(IO.read(webpackPackageJsonFilePath)).as[NpmPackage]).toOption
  }
}

================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/PackageJson.scala
================================================
package scalajsbundler

import sbt._

import scalajsbundler.util.JSON

object PackageJson {

  /**
    * Write a package.json file defining the NPM dependencies of the application, plus the ones
    * required to do the bundling.
    *
    * @param log Logger
    * @param targetFile File to write into
    * @param npmDependencies NPM dependencies
    * @param npmDevDependencies NPM devDependencies
    * @param npmResolutions Resolutions to use in case of conflicting dependencies
    * @param additionalNpmConfig Additional options to include in 'package.json'
    * @param fullClasspath Classpath (used to look for dependencies of Scala.js libraries this project depends on)
    * @param currentConfiguration Current configuration
    * @return The created package.json file
    */
  def write(
    log: Logger,
    targetFile: File,
    npmDependencies: Seq[(String, String)],
    npmDevDependencies: Seq[(String, String)],
    npmResolutions: Map[String, String],
    additionalNpmConfig: Map[String, JSON],
    fullClasspath: Seq[Attributed[File]],
    currentConfiguration: Configuration,
    webpackVersion: String,
    webpackDevServerVersion: String,
    webpackCliVersion: String
  ): Unit = {
    val npmManifestDependencies = NpmDependencies.collectFromClasspath(fullClasspath)
    val dependencies =
      npmDependencies ++ (
        if (currentConfiguration == Compile) npmManifestDependencies.compileDependencies
        else npmManifestDependencies.testDependencies
      )

    val sourceMapLoaderVersion =
      NpmPackage(webpackVersion).major match {
        case Some(5) => "2.0.0"
        case Some(x) => sys.error(s"Unsupported webpack major version $x")
        case None    => sys.error("No webpack version defined")
      }

    val devDependencies =
      npmDevDependencies ++ (
        if (currentConfiguration == Compile) npmManifestDependencies.compileDevDependencies
        else npmManifestDependencies.testDevDependencies
      ) ++ Seq(
        "webpack" -> webpackVersion,
        "webpack-cli" -> webpackCliVersion,
        "webpack-dev-server" -> webpackDevServerVersion,
        "concat-with-sourcemaps" -> "1.0.7", // Used by the reload workflow
        "source-map-loader" -> sourceMapLoaderVersion // Used by webpack when emitSourceMaps is enabled
      )

    val packageJson =
      JSON.obj(
        (
          additionalNpmConfig.toSeq :+
          "dependencies" -> JSON.objStr(resolveDependencies(dependencies, npmResolutions, log)) :+
          "devDependencies" -> JSON.objStr(resolveDependencies(devDependencies, npmResolutions, log))
        ): _*
      )

    log.debug("Writing 'package.json'")
    IO.write(targetFile, packageJson.toJson)
  }

  /**
    * Resolves multiple occurrences of a dependency to a same package.
    *
    *  - If all the occurrences refer to the same version, pick this one ;
    *  - If they refer to different versions, pick the one defined in `resolutions` (or fail
    *    if there is no such resolution).
    *
    * @return The resolved dependencies
    * @param dependencies The dependencies to resolve
    * @param resolutions The resolutions to use in case of conflict (they will be ignored if there are no conflicts)
    * @param log Logger
    */
  def resolveDependencies(
    dependencies: Seq[(String, String)],
    resolutions: Map[String, String],
    log: Logger
  ): List[(String, String)] ={
    val resolvedDependencies =
      dependencies
        .groupBy { case (name, version) => name }
        .mapValues(_.map(_._2).distinct)
        .foldRight(List.empty[(String, String)]) { case ((name, versions), result) =>
          val resolvedDependency =
            versions match {
              case Seq(single) =>
                name -> single
              case _ =>
                val resolution = resolutions.get(name) match {
                  case Some(v) => v
                  case None => versions.mkString(" ")
                }
                name -> resolution
            }
          resolvedDependency :: result
        }

    // Add a warning in case a resolution was defined but not used because the corresponding
    // dependency was not in conflict.
    val unusedResolutions =
      resolutions.filter { case (name, resolution) =>
        resolvedDependencies.exists { case (n, v) => n == name && v != resolution }
      }
    if (unusedResolutions.nonEmpty) {
      log.warn(s"Unused resolutions: $unusedResolutions")
    }

    log.debug(s"Resolved the following dependencies: $resolvedDependencies")

    resolvedDependencies
  }

}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/Stats.scala
================================================

package scalajsbundler

import play.api.libs.json._
import play.api.libs.functional.syntax._
import sbt.Logger
import scala.math.max
import java.io.File
import java.nio.file.Path

/**
 * Webpack stats model and json parsers
 */
object Stats {

  final case class Asset(name: String, size: Long, emitted: Boolean, chunkNames: List[String]) {
    def formattedSize: String = {
      val oneKiB = 1024L
      val oneMiB = oneKiB * oneKiB

      if (size < oneKiB) s"$size bytes"
      else if (size < oneMiB) f"${size / oneKiB.toFloat}%1.2f KiB"
      else f"${size / oneMiB.toFloat}%1.2f MiB"
    }
  }

  object formatting {

    final case class Part(t: String, l: Int) {
      def maxL(p: Part): Part =
        copy(l = max(l, p.l))

      def leftPad: String =
        // String interpolation doesn't support dynamic padding
        t.reverse.padTo(l, ' ').reverse.mkString
    }

    object Part {
      def apply(t: String) = new Part(t, t.length)
    }

    final case class AssetLine(asset: Part, size: Part, emitted: Part, chunks: Part) {
      def adjustPadding(p: AssetLine): AssetLine = copy(asset.maxL(p.asset), size.maxL(p.size), emitted.maxL(p.emitted), chunks.maxL(p.chunks))
      def show: String = List(asset, size, emitted, chunks).map(_.leftPad).mkString("   ")
    }

    object AssetLine {
      val Zero: AssetLine = AssetLine(Part("Asset"), Part("Size"), Part(""), Part("Chunks"))
    }

  }

  final case class WebpackError(moduleName: String, message: String, loc: String)

  final case class WebpackWarning(moduleName: String, message: String)

  final case class WebpackStats(
    version: String,
    hash: String,
    time: Long,
    outputPath: Option[Path],
    errors: List[WebpackError],
    warnings: List[WebpackWarning],
    assets: List[Asset]
  ) {

    /**
      * Prints to the log an output similar to what webpack pushes to stdout
      */
    def print(log: Logger): Unit = {
      import formatting._
      // Print base info
      List(s"Version: $version", s"Hash: $hash", s"Time: ${time}ms", s"Path: ${outputPath.getOrElse("<default>")}").foreach(x => log.info(x))
      log.info("")
      // Print the assets
      assets.map { a =>
        val emitted = if (a.emitted) "[emitted]" else ""
        AssetLine(Part(a.name), Part(a.formattedSize), Part(emitted), Part(a.chunkNames.mkString("[", ",", "]")))
      }.foldLeft(List(AssetLine.Zero)) {
        case (lines, curr) =>
          val adj = lines.map(_.adjustPadding(curr))
          val adjNew = adj.headOption.fold(curr)(curr.adjustPadding)
          (adjNew :: adj.reverse).reverse
      }.foreach { l =>
        log.info(l.show)
      }
      log.info("")
    }

    /**
      * Attempts to find the name of the asset for the project name
      * Note that we only search on files ending on .js skipping e.g. map files
      */
    def assetName(project: String): Option[String] =
      assets.find(a => a.chunkNames.contains(project) && a.name.endsWith(".js")).map(_.name)

    /**
     * Resolve the asset on the output path or the target dir if unavailable
     */
    def resolveAsset(altDir: Path, asset: String): Option[File] =
      assetName(asset).map(a => outputPath.getOrElse(altDir).resolve(a).toFile)

    /**
     * Resolve alles asset on the output path or the target dir if unavailable
     */
    def resolveAllAssets(altDir: Path): List[File] =
      assets.map(a => outputPath.getOrElse(altDir).resolve(a.name).toFile)
  }

  implicit val assetsReads: Reads[Asset] = (
    (JsPath \ "name").read[String] and
    (JsPath \ "size").read[Long] and
    (JsPath \ "emitted").read[Boolean] and
    (JsPath \ "chunkNames").read[List[String]]
  )(Asset.apply _)

  implicit val errorReads: Reads[WebpackError] = (
    (JsPath \ "moduleName").read[String] and
      (JsPath \ "message").read[String] and
      (JsPath \ "loc").read[String]
    )(WebpackError.apply _)

  implicit val warningReads: Reads[WebpackWarning] = (
    (JsPath \ "moduleName").read[String] and
      (JsPath \ "message").read[String]
    )(WebpackWarning.apply _)

  implicit val statsReads: Reads[WebpackStats] = (
    (JsPath \ "version").read[String] and
    (JsPath \ "hash").read[String] and
    (JsPath \ "time").read[Long] and
    (JsPath \ "outputPath").readNullable[String].map(x => x.map(new File(_).toPath)) and // It seems webpack 2 doesn't produce outputPath
    (JsPath \ "errors").read[List[WebpackError]] and
    (JsPath \ "warnings").read[List[WebpackWarning]] and
    (JsPath \ "assets").read[List[Asset]]
  )(WebpackStats.apply _)

}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/Webpack.scala
================================================
package scalajsbundler

import sbt._
import scalajsbundler.util.{Commands, JS}
import java.io.InputStream

import play.api.libs.json._
import Stats._

import scala.util.{Failure, Success, Try}

object Webpack {
  // Represents webpack 5 modes
  sealed trait WebpackMode {
    def mode: String
  }
  case object DevelopmentMode extends WebpackMode {
    val mode = "development"
  }
  case object ProductionMode extends WebpackMode {
    val mode = "production"
  }
  object WebpackMode {
    def fromBooleanProductionMode(productionMode: Boolean): WebpackMode =
      if (productionMode) ProductionMode
      else DevelopmentMode
  }

  /**
    * Copies the custom webpack configuration file and the webpackResources to the target dir
    *
    * @param targetDir target directory
    * @param webpackResources Resources to copy
    * @param customConfigFile User supplied config file
    * @return The copied config file.
    */
  def copyCustomWebpackConfigFiles(targetDir: File, webpackResources: Seq[File])(customConfigFile: File): File = {
    def copyToWorkingDir(targetDir: File)(file: File): File = {
      val copy = targetDir / file.name
      IO.copyFile(file, copy)
      copy
    }

    webpackResources.foreach(copyToWorkingDir(targetDir))
    copyToWorkingDir(targetDir)(customConfigFile)
  }

  /**
    * Writes the webpack configuration file. The output file is designed to be minimal, and to be extended,
    * however, the `entry` and `output` keys must be preserved in order for the bundler to work as expected.
    *
    * @param emitSourceMaps Whether source maps is enabled at all
    * @param entry The input entrypoint file to process via webpack
    * @param webpackConfigFile webpack configuration file to write to
    * @param libraryBundleName If defined, generate a library bundle named `libraryBundleName`
    * @param log Logger
    */
  def writeConfigFile(
    emitSourceMaps: Boolean,
    entry: BundlerFile.WebpackInput,
    webpackConfigFile: BundlerFile.WebpackConfig,
    libraryBundleName: Option[String],
    mode: WebpackMode,
    devServerPort: Int,
    log: Logger
  ): Unit = {
    val webpackConfigContent = generateConfigFile(emitSourceMaps, entry, webpackConfigFile, libraryBundleName, mode,
      devServerPort)

    log.info("Writing scalajs.webpack.config.js")
    IO.write(webpackConfigFile.file, webpackConfigContent.show)
  }

  private def generateConfigFile(
    emitSourceMaps: Boolean,
    entry: BundlerFile.WebpackInput,
    webpackConfigFile: BundlerFile.WebpackConfig,
    libraryBundleName: Option[String],
    mode: WebpackMode,
    devServerPort: Int
  ): JS = {
    val webpackNpmPackage = NpmPackage.getForModule(webpackConfigFile.targetDir.toFile, "webpack")
    webpackNpmPackage.flatMap(_.major) match {
      case Some(5) =>
        // Build the output configuration, configured for library output
        // if a library bundle name is provided
        val output = libraryBundleName match {
          case Some(bundleName) =>
            JS.obj(
              "path" -> JS.str(webpackConfigFile.targetDir.toAbsolutePath.toString),
              "filename" -> JS.str(BundlerFile.Library.fileName("[name]")),
              "library" -> JS.str(bundleName),
              "libraryTarget" -> JS.str("var")
            )
          case None =>
            JS.obj(
              "path" -> JS.str(webpackConfigFile.targetDir.toAbsolutePath.toString),
              "filename" -> JS.str(BundlerFile.ApplicationBundle.fileName("[name]"))
            )
        }

        JS.ref("module").dot("exports").assign(JS.obj(Seq(
          "entry" -> JS.obj(
            entry.project -> JS.arr(JS.str(entry.file.absolutePath))
          ),
          "output" -> output,
          "mode" -> JS.str(mode.mode),
          "devServer" -> JS.obj("port" -> JS.int(devServerPort)),
        ) ++ (
          if (emitSourceMaps) {
            Seq(
              "devtool" -> JS.str("source-map"),
              "module" -> JS.obj(
                "rules" -> JS.arr(
                  JS.obj(
                    "test" -> JS.regex("\\.js$"),
                    "enforce" -> JS.str("pre"),
                    "use" -> JS.arr(JS.str("source-map-loader"))
                  )
                )
              )
            )
          } else Nil
          ): _*))

      case Some(x) =>
        sys.error(s"Unsupported webpack major version $x")

      case None =>
        sys.error("No webpack version defined")
    }
  }

  /**
    * Run webpack to bundle the application.
    *
    * @param emitSourceMaps Whether or not source maps are enabled
    * @param generatedWebpackConfigFile Webpack config file generated by scalajs-bundler
    * @param customWebpackConfigFile User supplied config file
    * @param webpackResources Additional resources to be copied to the working folder
    * @param entry Scala.js application to bundle
    * @param targetDir Target directory (and working directory for Nodejs)
    * @param extraArgs Extra arguments passed to webpack
    * @param mode Mode for webpack 5
    * @param devServerPort Port used by webpack-dev-server
    * @param log Logger
    * @return The generated bundles
    */
  def bundle(
     emitSourceMaps: Boolean,
     generatedWebpackConfigFile: BundlerFile.WebpackConfig,
     customWebpackConfigFile: Option[File],
     webpackResources: Seq[File],
     entry: BundlerFile.Application,
     targetDir: File,
     extraArgs: Seq[String],
     nodeArgs: Seq[String],
     mode: WebpackMode,
     devServerPort: Int,
     log: Logger
  ): BundlerFile.ApplicationBundle = {
    writeConfigFile(emitSourceMaps, entry, generatedWebpackConfigFile, None, mode, devServerPort, log)

    val configFile = customWebpackConfigFile
      .map(Webpack.copyCustomWebpackConfigFiles(targetDir, webpackResources))
      .getOrElse(generatedWebpackConfigFile.file)

    log.info("Bundling the application with its NPM dependencies")
    val args = extraArgs ++: Seq("--config", configFile.absolutePath)
    val stats = Webpack.run(nodeArgs: _*)(args: _*)(targetDir, log)
    stats.foreach(_.print(log))

    // Attempt to discover the actual name produced by webpack indexing by chunk name and discarding maps
    val bundle = generatedWebpackConfigFile.asApplicationBundle(stats)
    assert(bundle.file.exists(), "Webpack failed to create application bundle")
    assert(bundle.assets.forall(_.exists()), "Webpack failed to create application assets")
    bundle
  }

  /**
    * Run webpack to bundle the application.
    *
    * @param emitSourceMaps Are source maps enabled?
    * @param generatedWebpackConfigFile Webpack config file generated by scalajs-bundler
    * @param customWebpackConfigFile User supplied config file
    * @param webpackResources Additional webpack resources to include in the working directory
    * @param entryPointFile The entrypoint file to bundle dependencies for
    * @param libraryModuleName The library module name to assign the webpack bundle to
    * @param extraArgs Extra arguments passed to webpack
    * @param mode Mode for webpack 5
    * @param log Logger
    * @return The generated bundle
    */
  def bundleLibraries(
    emitSourceMaps: Boolean,
    generatedWebpackConfigFile: BundlerFile.WebpackConfig,
    customWebpackConfigFile: Option[File],
    webpackResources: Seq[File],
    entryPointFile: BundlerFile.EntryPoint,
    libraryModuleName: String,
    extraArgs: Seq[String],
    nodeArgs: Seq[String],
    mode: WebpackMode,
    devServerPort: Int,
    log: Logger
  ): BundlerFile.Library = {
    writeConfigFile(
      emitSourceMaps,
      entryPointFile,
      generatedWebpackConfigFile,
      Some(libraryModuleName),
      mode,
      devServerPort,
      log
    )

    val configFile = customWebpackConfigFile
      .map(Webpack.copyCustomWebpackConfigFiles(generatedWebpackConfigFile.targetDir.toFile, webpackResources))
      .getOrElse(generatedWebpackConfigFile.file)

    val args = extraArgs ++: Seq("--config", configFile.absolutePath)
    val stats = Webpack.run(nodeArgs: _*)(args: _*)(generatedWebpackConfigFile.targetDir.toFile, log)
    stats.foreach(_.print(log))

    val library = generatedWebpackConfigFile.asLibrary(stats)
    assert(library.file.exists, "Webpack failed to create library file")
    assert(library.assets.forall(_.exists), "Webpack failed to create library assets")
    library
  }

  private def jsonOutput(cmd: Seq[String], logger: Logger)(in: InputStream): Option[WebpackStats] = {
    Try {
      val parsed = Json.parse(in)
      parsed.validate[WebpackStats] match {
        case JsError(e) =>
          logger.error("Error parsing webpack stats output")
          // In case of error print the result and return None. it will be ignored upstream
          e.foreach {
            case (p, v) => logger.error(s"$p: ${v.mkString(",")}")
          }
          None
        case JsSuccess(p, _) =>
          if (p.warnings.nonEmpty || p.errors.nonEmpty) {
            logger.info("")
            // Filtering is a workaround for #111
            p.warnings.filterNot(_.message.contains("https://raw.githubusercontent.com")).foreach { warning =>
              logger.warn(s"WARNING in ${warning.moduleName}")
              logger.warn(warning.message)
              logger.warn("\n")
            }
            p.errors.foreach { error =>
              logger.error(s"ERROR in ${error.moduleName} ${error.loc}")
              logger.error(error.message)
              logger.error("\n")
            }
          }
          Some(p)
      }
    } match {
      case Success(x) =>
        x
      case Failure(e) =>
        // In same cases errors are not reported on the json output but comes on stdout
        // where they cannot be parsed as json. The best we can do here is to suggest
        // running the command manually
        logger.error(s"Failure on parsing the output of webpack: ${e.getMessage}")
        logger.error(s"You can try to manually execute the command")
        logger.error(cmd.mkString(" "))
        logger.error("\n")
        None
    }
  }

  /**
    * Runs the webpack command.
    *
    * @param nodeArgs node.js cli flags
    * @param args Arguments to pass to the webpack command
    * @param workingDir Working directory in which the Nodejs will be run (where there is the `node_modules` subdirectory)
    * @param log Logger
    */
  def run(nodeArgs: String*)(args: String*)(workingDir: File, log: Logger): Option[WebpackStats] = {
    val webpackBin = workingDir / "node_modules" / "webpack" / "bin" / "webpack"
    val params = nodeArgs ++ Seq(webpackBin.absolutePath, "--profile", "--json") ++ args
    val cmd = "node" +: params
    Commands.run(cmd, workingDir, log, jsonOutput(cmd, log)).fold(sys.error, _.flatten)
  }

}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/WebpackDevServer.scala
================================================
package scalajsbundler

import sbt._
import java.io.File

/**
  * Simple wrapper over webpack-dev-server
  */
private [scalajsbundler] class WebpackDevServer {

  private var worker: Option[Worker] = None

  /**
    * @param workDir - path to working directory for webpack-dev-server
    * @param configPath - path to webpack config.
    * @param extraArgs - additional arguments for webpack-dev-server.
    * @param logger - a logger to use for output
    * @param globalLogger - a global logger to use for output even when the task is terminated
    */
  def start(
    workDir: File,
    configPath: File,
    extraArgs: Seq[String],
    logger: Logger,
    globalLogger: Logger,
  ) = this.synchronized {
    stop()
    worker = Some(new Worker(
      workDir,
      configPath,
      extraArgs,
      logger,
      globalLogger
    ))
  }

  def stop() = this.synchronized {
    worker.foreach { w => {
      w.stop()
      worker = None
    }}
  }

  private class Worker(
    workDir: File,
    configPath: File,
    extraArgs: Seq[String],
    logger: Logger,
    globalLogger: Logger,
  ) {
    logger.info("Starting webpack-dev-server");

    val command = Seq(
      "node",
      "node_modules/webpack/bin/webpack",
      "serve",
      "--config",
      configPath.getAbsolutePath
    ) ++ extraArgs

    val process = util.Commands.start(command, workDir, globalLogger)

    def stop() = {
      logger.info("Stopping webpack-dev-server");
      process.destroy()
    }
  }

  override def finalize() = stop()
}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/WebpackEntryPoint.scala
================================================
package scalajsbundler

import sbt.{IO, Logger}

import scalajsbundler.util.JS

object WebpackEntryPoint {

  /**
    * @return The written loader file (faking a `require` implementation)
    * @param entryPoint File to write the loader to
    * @param logger Logger
    */
  def writeEntryPoint(
      imports: Seq[String],
      entryPoint: BundlerFile.EntryPoint,
      logger: Logger
  ): Unit = {
    logger.info(s"Writing module entry point for ${entryPoint.file.getName}")
    val depsFileContent =
      JS.ref("module")
        .dot("exports")
        .assign(
          JS.obj(
            Seq(
              "require" -> JS.fun(name =>
                JS.obj(imports.map { moduleName =>
                    moduleName -> JS.ref("require").apply(JS.str(moduleName))
                  }: _*)
                  .bracket(name))): _*)
        )
    IO.write(entryPoint.file, depsFileContent.show)
  }
}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/LibraryTasks.scala
================================================
package scalajsbundler.sbtplugin

import sbt.Keys._
import sbt.{Def, _}

import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport.scalaJSLinkerConfig
import scalajsbundler.{BundlerFile, Webpack, WebpackEntryPoint}
import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin.autoImport._
import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin._
import scalajsbundler.util.{Caching, JSBundler}

object LibraryTasks {

  private[sbtplugin] def entryPoint(stage: TaskKey[Attributed[File]])
    : Def.Initialize[Task[BundlerFile.EntryPoint]] =
    Def.task {
      val s = streams.value
      val importedModules = (scalaJSBundlerImportedModules in stage).value
      val entry = WebpackTasks.entry(stage).value
      val cacheLocation = streams.value.cacheDirectory / s"${stage.key.label}-webpack-entrypoint"
      val entryPointFile = entry.asEntryPoint

      // Avoid re-writing the entrypoint file if the list of modules hasn't changed
      // allowing downstream caching to detect change reliably
      Caching.cached(entryPointFile.file, importedModules.mkString(","), cacheLocation)(
        () =>
          WebpackEntryPoint.writeEntryPoint(
            importedModules,
            entryPointFile,
            s.log
        ))
      entryPointFile
    }.dependsOn(npmUpdate in stage)

  private[sbtplugin] def bundle(
      stage: TaskKey[Attributed[File]],
      mode: BundlingMode.Library): Def.Initialize[Task[BundlerFile.Library]] =
    Def.task {
      assert(ensureModuleKindIsCommonJSModule.value)
      val log = streams.value.log
      val emitSourceMaps = (finallyEmitSourceMaps in stage).value
      val customWebpackConfigFile = (webpackConfigFile in stage).value
      val generatedWebpackConfigFile =
        (scalaJSBundlerWebpackConfig in stage).value
      val compileResources = (resources in Compile).value
      val webpackResourceFiles = (webpackResources in stage).value.get
      val entryPointFile = entryPoint(stage).value
      val monitoredFiles = customWebpackConfigFile.toSeq ++
        Seq(generatedWebpackConfigFile.file, entryPointFile.file) ++
        webpackResourceFiles ++ compileResources
      val cacheLocation = streams.value.cacheDirectory / s"${stage.key.label}-webpack-libraries"
      val extraArgs = (webpackExtraArgs in stage).value
      val nodeArgs = (webpackNodeArgs in stage).value
      val webpackMode =
        Webpack.WebpackMode.fromBooleanProductionMode((scalaJSLinkerConfig in stage).value.semantics.productionMode)
      val devServerPort = webpackDevServerPort.value

      val cachedActionFunction =
        FileFunction.cached(
          cacheLocation,
          inStyle = FilesInfo.hash
        ) { _ =>
          log.info(s"Building webpack library bundles for ${entryPointFile.project} in $cacheLocation")

          Webpack.bundleLibraries(
            emitSourceMaps,
            generatedWebpackConfigFile,
            customWebpackConfigFile,
            webpackResourceFiles,
            entryPointFile,
            mode.exportedName,
            extraArgs,
            nodeArgs,
            webpackMode,
            devServerPort,
            log
          ).cached
        }
      val cached = cachedActionFunction(monitoredFiles.to[Set])
      generatedWebpackConfigFile.asLibraryFromCached(cached)
    }

  private[sbtplugin] def loader(
      stage: TaskKey[Attributed[File]],
      mode: BundlingMode.Library): Def.Initialize[Task[BundlerFile.Loader]] =
    Def.task {
      assert(ensureModuleKindIsCommonJSModule.value)
      val entry = WebpackTasks.entry(stage).value
      val loaderFile = entry.asLoader

      JSBundler.writeLoader(
        loaderFile,
        mode.exportedName
      )
      loaderFile
    }

  private[sbtplugin] def bundleAll(stage: TaskKey[Attributed[File]],
                                   mode: BundlingMode.LibraryAndApplication)
    : Def.Initialize[Task[Seq[BundlerFile.Public]]] =
    Def.task {
      assert(ensureModuleKindIsCommonJSModule.value)
      val cacheLocation = streams.value.cacheDirectory / s"${stage.key.label}-webpack-bundle-all"
      val targetDir = npmUpdate.value
      val entry = WebpackTasks.entry(stage).value
      val library = bundle(stage, mode).value
      val emitSourceMaps = (finallyEmitSourceMaps in stage).value
      val log = streams.value.log
      val filesToMonitor = Seq(entry.file, library.file)

      val cachedActionFunction =
        FileFunction.cached(
          cacheLocation,
          inStyle = FilesInfo.hash
        ) { _ =>
          JSBundler.bundle(
            targetDir = targetDir,
            entry,
            library,
            emitSourceMaps,
            mode.exportedName,
            log
          ).cached
        }
      val cached = cachedActionFunction(filesToMonitor.toSet)
      Seq(entry.asApplicationBundleFromCached(cached), entry.asLoader, library, entry)
    }

  private[sbtplugin] def librariesAndLoaders(stage: TaskKey[Attributed[File]],
                                             mode: BundlingMode.LibraryOnly)
    : Def.Initialize[Task[Seq[Attributed[File]]]] =
    Def.task {
      Seq(WebpackTasks.entry(stage).value,
        loader(stage, mode).value,
        bundle(stage, mode).value).flatMap(_.asAttributedFiles)
    }

  private[sbtplugin] def libraryAndLoadersBundle(
      stage: TaskKey[Attributed[File]],
      mode: BundlingMode.LibraryAndApplication)
    : Def.Initialize[Task[Seq[Attributed[File]]]] =
    Def.task {
      bundleAll(stage, mode).value.flatMap(_.asAttributedFiles)
    }
}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/NpmUpdateTasks.scala
================================================
package scalajsbundler.sbtplugin

import java.nio.file.Path
import scalajsbundler.ExternalCommand
import sbt._

object NpmUpdateTasks {

  /**
    * Runs either `npm install` or `yarn install` and installs JavaScript resources as node packages.
    *
    * @param targetDir npm directory
    * @param packageJsonFile Json file containing NPM dependencies
    * @param useYarn Whether to use yarn or npm
    * @param jsResources A sequence of JavaScript resources
    * @param streams A sbt TaskStream
    * @param npmExtraArgs Additional arguments to pass to npm
    * @param yarnExtraArgs Additional arguments to pass to yarn
    * @return The written npm directory
    */
  def npmUpdate(baseDir: File,
                targetDir: File,
                packageJsonFile: File,
                useYarn: Boolean,
                jsResources: Seq[(String, Path)],
                streams: Keys.TaskStreams,
                npmExtraArgs: Seq[String],
                yarnExtraArgs: Seq[String]): File = {
    val dir = npmInstallDependencies(baseDir, targetDir, packageJsonFile, useYarn, streams, npmExtraArgs, yarnExtraArgs)
    npmInstallJSResources(targetDir, jsResources, Seq.empty, streams)
    dir
  }

  /**
    * Runs either `npm install` or `yarn install`.
    *
    * @param targetDir npm directory
    * @param packageJsonFile Json file containing NPM dependencies
    * @param useYarn Whether to use yarn or npm
    * @param streams A sbt TaskStream
    * @param npmExtraArgs Additional arguments to pass to npm
    * @param yarnExtraArgs Additional arguments to pass to yarn
    * @return The written npm directory
    */
  def npmInstallDependencies(baseDir: File,
                             targetDir: File,
                             packageJsonFile: File,
                             useYarn: Boolean,
                             streams: Keys.TaskStreams,
                             npmExtraArgs: Seq[String],
                             yarnExtraArgs: Seq[String]): File = {
    val log = streams.log
    val cachedActionFunction =
      FileFunction.cached(
        streams.cacheDirectory / "scalajsbundler-npm-install",
        inStyle = FilesInfo.hash
      ) { _ =>
        log.info("Updating NPM dependencies")
        ExternalCommand.install(baseDir, targetDir, useYarn, log, npmExtraArgs, yarnExtraArgs)
        Set.empty
      }
    cachedActionFunction(Set(packageJsonFile))
    targetDir
  }

  private object PathWithFile {
    def unapply(path: Path): Option[File] = {
      try {
        Some(path.toFile())
      } catch {
        case _: UnsupportedOperationException => None
      }
    }
  }

  /**
    * Installs JavaScript resources as node packages.
    *
    * @param targetDir npm directory
    * @param jsResources The JavaScript resources
    * @param streams A sbt TaskStream
    * @return The paths to the node packages
    */
  def npmInstallJSResources(targetDir: File,
                            jsResources: Seq[(String, Path)],
                            jsSourceDirectories: Seq[File],
                            streams: Keys.TaskStreams): Seq[File] = {
    val jsFileResources =   jsResources.collect {
      case (relativePath, PathWithFile(jsfile)) => jsfile -> relativePath
    }.toSet ++ jsSourceDirectories.flatMap { f =>
      if (f.isDirectory)
        sbt.Path.allSubpaths(f).filterNot(_._1.isDirectory)
      else Seq.empty
    }.toSet

    val cachedActionFunction = FileFunction.cached(
        streams.cacheDirectory / "scalajsbundler-npm-install-resources",
        inStyle = FilesInfo.hash
      ) { _ =>
      jsFileResources.map { case (file, relativePath) =>
        val resourcePath = targetDir / relativePath
        IO.copyFile(file, resourcePath)
        resourcePath
        }
      }
    val files = jsFileResources.map { case (rFile, _) => rFile }
    cachedActionFunction(files).toSeq
  }
}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/PackageJsonTasks.scala
================================================
package scalajsbundler.sbtplugin

import sbt._

import scalajsbundler.{BundlerFile, PackageJson}
import scalajsbundler.util.{Caching, JSON}

object PackageJsonTasks {

  /**
    * Writes the package.json file that describes the project dependencies
    * @param targetDir Directory in which write the file
    * @param npmDependencies NPM dependencies
    * @param npmDevDependencies NPM devDependencies
    * @param npmResolutions Resolutions to use in case of conflicts
    * @param additionalNpmConfig Additional options to include in 'package.json'
    * @param fullClasspath Classpath
    * @param configuration Current configuration (Compile or Test)
    * @param webpackVersion Webpack version
    * @param webpackDevServerVersion Webpack development server version
    * @return The written package.json file
    */
  def writePackageJson(
    targetDir: File,
    npmDependencies: Seq[(String, String)],
    npmDevDependencies: Seq[(String, String)],
    npmResolutions: Map[String, String],
    additionalNpmConfig: Map[String, JSON],
    fullClasspath: Seq[Attributed[File]],
    configuration: Configuration,
    webpackVersion: String,
    webpackDevServerVersion: String,
    webpackCliVersion: String,
    streams: Keys.TaskStreams
  ): BundlerFile.PackageJson = {

    val hash = Seq(
      configuration.name,
      npmDependencies.toString,
      npmDevDependencies.toString,
      npmResolutions.toString,
      fullClasspath.map(_.data.name).toString,
      webpackVersion,
      webpackDevServerVersion,
      webpackCliVersion
    ).mkString(",")

    val packageJsonFile = targetDir / "package.json"

    Caching.cached(
      packageJsonFile,
      hash,
      streams.cacheDirectory / s"scalajsbundler-package-json-${if (configuration == Compile) "main" else "test"}"
    ) { () =>
      PackageJson.write(
        streams.log,
        packageJsonFile,
        npmDependencies,
        npmDevDependencies,
        npmResolutions,
        additionalNpmConfig,
        fullClasspath,
        configuration,
        webpackVersion,
        webpackDevServerVersion,
        webpackCliVersion
      )
      ()
    }

    BundlerFile.PackageJson(packageJsonFile)
  }

}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/SBTBundlerFile.scala
================================================
package scalajsbundler.sbtplugin

import sbt.{AttributeKey, Attributed}

import scalajsbundler.{BundlerFile, BundlerFileType}

/**
  * SBT Specific Extensions to [[scalajsbundler.BundlerFile]]
  *
  * @param f The BundlerFile to enrich
  */
class SBTBundlerFile(f: BundlerFile.Public) {
    import SBTBundlerFile._

    def asAttributedFiles: Seq[sbt.Attributed[sbt.File]] = {
      val main = Attributed
        .blank(f.attributedFiles._1)
        .put(ProjectNameAttr, f.project)
        .put(BundlerFileTypeAttr, f.`type`)
      val assets = Attributed
        .blankSeq(f.attributedFiles._2).map {
          _
          .put(ProjectNameAttr, f.project)
          .put(BundlerFileTypeAttr, BundlerFileType.Asset)
        }
      main +: assets
    }
}

object SBTBundlerFile {

  /**
    * A string attribute describing the project and output stage (fastopt vs. opt)
    */
  val ProjectNameAttr: AttributeKey[String] = AttributeKey("project-name")

  /**
    * A [[scalajsbundler.BundlerFileType]], allowing unambigiuous selection of output files
    * downstream from the plugin.
    */
  val BundlerFileTypeAttr: AttributeKey[BundlerFileType] = AttributeKey(
    "bundler-file-type")
}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/ScalaJSBundlerPlugin.scala
================================================
package scalajsbundler.sbtplugin

import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
import org.scalajs.sbtplugin.{ScalaJSPlugin, Stage}
import sbt.Keys._
import sbt.{Def, _}
import scalajsbundler.{BundlerFile, NpmDependencies, Webpack, WebpackDevServer}

import scalajsbundler.ExternalCommand.addPackages
import scalajsbundler.util.{JSON, ScalaJSNativeLibraries}


/**
  * This plugin enables `ScalaJSPlugin` and sets the `scalaJSModuleKind` to `CommonJSModule`. It also makes it
  * possible to define dependencies to NPM packages and provides tasks to fetch them or to bundle the application
  * with its dependencies.
  *
  * = Tasks and Settings =
  *
  * The [[ScalaJSBundlerPlugin.autoImport autoImport]] member documents the keys provided by this plugin. Besides these keys, the
  * following existing keys also control the plugin:
  *
  * == `version in webpack` ==
  *
  * Version of webpack to use. Example:
  *
  * {{{
  *   version in webpack := "3.5.5"
  * }}}
  *
  * == `version in installJsdom` ==
  *
  * Version of jsdom to use.
  *
  * == `version in startWebpackDevServer` ==
  *
  * Version of webpack-dev-server to use.
  *
  * {{{
  *   version in startWebpackDevServer := "2.11.1"
  * }}}
  *
  * == `crossTarget in npmUpdate` ==
  *
  * The directory in which NPM dependencies will be fetched, and where all the .js files
  * will be generated. The directory is different according to the current `Configuration`
  * (either `Compile` or `Test`).
  *
  * Defaults to `crossTarget.value / "scalajs-bundler" / "main"` for `Compile` and
  * `crossTarget.value / "scalajs-bundler" / "test"` for `Test`.
  */
object ScalaJSBundlerPlugin extends AutoPlugin {

  override lazy val requires = ScalaJSPlugin

  // Exported keys
  /**
    * @groupname tasks Tasks
    * @groupname settings Settings
    */
  object autoImport {
    type BundlingMode = scalajsbundler.BundlingMode
    val BundlingMode = scalajsbundler.BundlingMode
    type BundlerFile = scalajsbundler.BundlerFile
    val BundlerFile = scalajsbundler.BundlerFile
    type BundlerFileType = scalajsbundler.BundlerFileType
    val BundlerFileType = scalajsbundler.BundlerFileType
    val ProjectNameAttr: AttributeKey[String] = SBTBundlerFile.ProjectNameAttr
    val BundlerFileTypeAttr: AttributeKey[BundlerFileType] = SBTBundlerFile.BundlerFileTypeAttr
    implicit class RichBundlerFile(f: BundlerFile.Public) extends SBTBundlerFile(f)

    /**
      * Installs NPM dependencies and all JavaScript resources found on the classpath as node packages.
      *
      * The JavaScript resources are installed locally in `node_modules` and can be used any other node package,
      * such as to load a module using `require()`.
      *
      * Do not use this from `sourceGenerators` or any other task that is used either directly or indirectly by
      * `fullClasspath` otherwise it will result in a deadlock. For this, use [[npmInstallDependencies]] instead.
      *
      * The plugin uses different directories according to the configuration (`Compile` or `Test`). Thus,
      * this setting is scoped by a `Configuration`.
      *
      * The task returns the directory in which the dependencies have been fetched (the directory
      * that contains the `node_modules` directory).
      *
      * @group tasks
      */
    val npmUpdate: TaskKey[File] =
      taskKey[File]("Install NPM dependencies and JavaScript resources")

    /**
      * Installs NPM dependencies.
      *
      * Unlike [[npmUpdate]] this does not stage the javascript resources and so is safe to use in `sourceGenerators`
      * or any other task that is used by `fullClasspath`.
      *
      * The plugin uses different directories according to the configuration (`Compile` or `Test`). Thus,
      * this setting is scoped by a `Configuration`.
      *
      * Typically, if you want to define a task that uses the downloaded NPM packages you should
      * specify the `Configuration` you are interested in:
      *
      * {{{
      *   myCustomTask := {
      *     val npmDirectory = (npmInstallDependencies in Compile).value
      *     doSomething(npmDirectory / "node_modules" / "some-package")
      *   }
      * }}}
      *
      * The task returns the directory in which the dependencies have been fetched (the directory
      * that contains the `node_modules` directory).
      *
      * @group tasks
      */
    val npmInstallDependencies: TaskKey[File] =
      taskKey[File]("Install NPM dependencies")

    /**
      * Installs all JavaScript resources found on the classpath as node packages.
      *
      * Additionally, it installs also the resources found under [[jsSourceDirectories]]
      *
      * The JavaScript resources are installed locally in `node_modules` and can be used any other node package,
      * such as to load a module using `require()`.
      *
      * The plugin uses different directories according to the configuration (`Compile` or `Test`). Thus,
      * this setting is scoped by a `Configuration`.
      *
      * The task returns the path to each JavaScript resource within the `node_modules` directory.
      *
      * @group tasks
      */
    val npmInstallJSResources: TaskKey[Seq[File]] =
      taskKey[Seq[File]]("Install JavaScript resources found on the classpath")

    /**
      * List of the NPM packages (name and version) your application depends on.
      * You can use [semver](https://docs.npmjs.com/misc/semver) versions:
      *
      * {{{
      *   npmDependencies in Compile += "uuid" -> "~3.0.0"
      * }}}
      *
      * Note that this key must be scoped by a `Configuration` (either `Compile` or `Test`).
      *
      * @group settings
      */
    val npmDependencies: SettingKey[Seq[(String, String)]] =
      settingKey[Seq[(String, String)]]("NPM dependencies (libraries that your program uses)")

    /** @group settings */
    val npmDevDependencies: SettingKey[Seq[(String, String)]] =
      settingKey[Seq[(String, String)]]("NPM dev dependencies (libraries that the build uses)")

    /**
      * Map of NPM packages (name -> version) to use in case transitive NPM dependencies
      * refer to a same package but with different version numbers. In such a
      * case, this setting defines which version should be used for the conflicting
      * package. Example:
      *
      * {{{
      *   npmResolutions in Compile := Map("react" -> "15.4.1")
      * }}}
      *
      * If several Scala.js projects depend on different versions of `react`, the version `15.4.1`
      * will be picked. But if all the projects depend on the same version of `react`, the version
      * given in `npmResolutions` will be ignored.
      *
      * If different versions of the packages are referred but the package is NOT configured in `npmResolutions`,
      * a version conflict resolution is delegated to npm/yarn. This behavior may reduce a need to configure
      * `npmResolutions` explicitly. E.g. "14.4.2" can be automatically-picked for ">=14.0.0 14.4.2 ^14.4.1".
      *
      * Note that this key must be scoped by a `Configuration` (either `Compile` or `Test`).
      *
      * @group settings
      */
    val npmResolutions: SettingKey[Map[String, String]] =
      settingKey[Map[String, String]]("NPM dependencies resolutions in case of conflict")

    /**
      * List of the additional configuration options to include in the generated 'package.json'.
      * Note that package dependencies are automatically generated from `npmDependencies` and
      * `npmDevDependencies` and should '''not''' be specified in this setting.
      *
      * {{{
      *   import scalajsbundler.util.JSON._
      *   additionalNpmConfig in Compile := Map(
      *     "name"        -> str(name.value),
      *     "version"     -> str(version.value),
      *     "description" -> str("Awesome ScalaJS project..."),
      *     "other"       -> obj(
      *       "value0" -> bool(true),
      *       "value1" -> obj(
      *         "foo" -> str("bar")
      *       )
      *     )
      *   )
      * }}}
      *
      * Note that this key must be scoped by a `Configuration` (either `Compile` or `Test`).
      *
      * @group settings
      */
    val additionalNpmConfig: SettingKey[Map[String, JSON]] =
      settingKey[Map[String, JSON]]("Additional option to include in the generated 'package.json'")

    /**
      * Additional arguments for npm
      *
      * Defaults to an empty list.
      *
      * @group settings
      */
    val npmExtraArgs = SettingKey[Seq[String]](
      "npmExtraArgs",
      "Custom arguments for npm"
    )

    /**
      * [[scalajsbundler.BundlingMode]] to use.
      *
      * Must be one of:
      *   `Application`             - Process the entire Scala.js output file with webpack, producing a bundle including all dependencies
      *   `LibraryOnly()`           - Process only the entrypoints via webpack and produce a library of dependencies
      *   `LibraryAndApplication()  - Process only the entrypoints, concatenating the library with the application to produce a bundle
      *
      * The default value is `Application`
      */
    val webpackBundlingMode: SettingKey[BundlingMode] =
      settingKey[BundlingMode]("Bundling mode, one of BundlingMode.{ Application,  LibraryOnly, LibraryAndApplication }.")

    /**
      * Bundles the output of a Scala.js stage.
      *
      * This task must be scoped by a Scala.js stage (either `fastOptJS` or `fullOptJS`) and
      * a `Configuration` (either `Compile` or `Test`).
      *
      * For instance, to bundle the output of `fastOptJS`, run the following task from the sbt shell:
      *
      * {{{
      *   fastOptJS::webpack
      * }}}
      *
      * Or, in an sbt build definition:
      *
      * {{{
      *   webpack in (Compile, fastOptJS)
      * }}}
      *
      * Note that to scope the task to a different project than the “current” sbt project, you
      * have to write the following:
      *
      * {{{
      *   webpack in (projectRef, Compile, fastOptJS in projectRef)
      * }}}
      *
      * The task returns the produced bundles.
      *
      * The task is cached, so webpack is only launched when some of the
      * used files have changed. The list of files to be monitored is
      * provided by webpackMonitoredFiles
      *
      * The files produced are wrapped in `sbt.Attributed`, and tagged with
      * [[scalajsbundler.sbtplugin.SBTBundlerFile.ProjectNameAttr]] and
      * [[scalajsbundler.sbtplugin.SBTBundlerFile.BundlerFileTypeAttr]]. The
      * [[scalajsbundler.sbtplugin.SBTBundlerFile.ProjectNameAttr]] contains the "prefix" of the file names, such
      * as `yourapp-fastopt`, while the
      * [[scalajsbundler.sbtplugin.SBTBundlerFile.BundlerFileTypeAttr]] contains the bundle file type, which can be
      * used to filter the list of files by their [[scalajsbundler.BundlerFileType]]. For example:
      *
      * {{{
      *   webpack.value.find(_.metadata.get(BundlerFileTypeAttr).exists(_ == BundlerFileType.ApplicationBundle))
      * }}}
      *
      * @group tasks
      */
    val webpack: TaskKey[Seq[Attributed[File]]] =
      taskKey[Seq[Attributed[File]]]("Bundle the output of a Scala.js stage using webpack")

    /**
      * configuration file to use with webpack. By default, the plugin generates a
      * configuration file, but you can supply your own file via this setting. Example of use:
      *
      * {{{
      *   webpackConfigFile in fullOptJS := Some(baseDirectory.value / "my.dev.webpack.config.js")
      * }}}
      *
      * You can find more insights on how to write a custom configuration file in the
      * [[http://scalacenter.github.io/scalajs-bundler/cookbook.html#custom-config cookbook]].
      *
      * @group settings
      */
    val webpackConfigFile: SettingKey[Option[File]] =
      settingKey[Option[File]]("Configuration file to use with webpack")

    /**
      * Webpack configuration files to copy to the target directory. These files can be merged into the main
      * configuration file.
      *
      * By default all .js files in the project base directory are copied:
      *
      * {{{
      *   baseDirectory.value * "*.js"
      * }}}
      *
      * How to share these configuration files among your webpack config files is documented in the
      * [[http://scalacenter.github.io/scalajs-bundler/cookbook.html#shared-config cookbook]].
      *
      * @group settings
      */
    val webpackResources: SettingKey[PathFinder] =
      settingKey[PathFinder]("Webpack resources to copy to target directory (defaults to *.js)")

    /**
      * whether to enable (or not) source-map in
      * a given configuration (`Compile` or `Test`) and stage (`fastOptJS` or `fullOptJS`). Example
      * of use:
      *
      * {{{
      *   webpackEmitSourceMaps in (Compile, fullOptJS) := false
      * }}}
      *
      * By default, this setting is undefined and scalajs-bundler fallbacks to Scala.js’ `sourceMap`
      * setting, so, to globally disable source maps you can just configure the `sourceMap`
      * setting:
      *
      * {{{
      *   scalaJSLinkerConfig ~= _.withSourceMap(false)
      * }}}
      *
      * @group settings
      */
    val webpackEmitSourceMaps: SettingKey[Boolean] =
      settingKey[Boolean]("Whether webpack should emit source maps at all")

    private[scalajsbundler] val finallyEmitSourceMaps: SettingKey[Boolean] =
      SettingKey("finallyEmitSourceMaps", rank = KeyRanks.Invisible)

    /**
      * Additional directories, monitored for webpack launch.
      *
      * Changes to files in these directories that match
      * `includeFilter` scoped to `webpackMonitoredFiles` enable
      *  webpack launch in `webpack` task.
      *
      * Defaults to an empty `Seq`.
      *
      * @group settings
      * @see [[webpackMonitoredFiles]]
      */
    val webpackMonitoredDirectories: SettingKey[Seq[File]] =
      settingKey[Seq[File]]("Directories, monitored for webpack launch")

    /**
      * List of files, monitored for webpack launch.
      *
      * By default includes the following files:
      *  - Generated `package.json`
      *  - Generated webpack config
      *  - Custom webpack config (if any)
      *  - Files, provided by `webpackEntries` task.
      *  - Files from `webpackMonitoredDirectories`, filtered by
      *    `includeFilter`
      *
      * @group settings
      * @see [[webpackMonitoredDirectories]]
      * @see [[webpack]]
      */
    val webpackMonitoredFiles: TaskKey[Seq[File]] =
      taskKey[Seq[File]]("Files that trigger webpack launch")

    /**
      * Additional arguments to webpack
      *
      * Defaults to an empty list.
      *
      * @group settings
      */
    val webpackExtraArgs = SettingKey[Seq[String]](
      "webpackExtraArgs",
      "Custom arguments to webpack"
    )

    /**
      * node.js cli custom arguments as described in https://nodejs.org/api/cli.html
      *
      * Defaults to an empty list.
      *
      * @group settings
      */
    val webpackNodeArgs = SettingKey[Seq[String]](
      "webpackNodeArgs",
      "Custom arguments to node.js when running webpack tasks"
    )

    /**
      * Whether to use [[https://yarnpkg.com/ Yarn]] to fetch dependencies instead
      * of `npm`. Yarn has a caching mechanism that makes the process faster.
      *
      * If set to `true`, it requires Yarn 0.22.0+ to be available on the
      * host platform.
      *
      * Defaults to `false`.
      *
      * @group settings
      */
    val useYarn: SettingKey[Boolean] =
      settingKey[Boolean]("Whether to use yarn for updates")

    /**
      * Port, on which webpack-dev-server will be launched.
      *
      * Defaults to 8080.
      *
      * @see [[startWebpackDevServer]]
      * @group settings
      */
    val webpackDevServerPort = SettingKey[Int](
      "webpackDevServerPort",
      "Port, on which webpack-dev-server operates"
    )

    /**
      * Additional arguments for yarn
      *
      * Defaults to an empty list.
      *
      * @group settings
      */
    val yarnExtraArgs = SettingKey[Seq[String]](
      "yarnExtraArgs",
      "Custom arguments for yarn"
    )
    /**
      * Additional arguments to webpack-dev-server.
      *
      * Defaults to an empty list.
      *
      * @see [[startWebpackDevServer]]
      * @group settings
      */
    val webpackDevServerExtraArgs = SettingKey[Seq[String]](
      "webpackDevServerExtraArgs",
      "Custom arguments to webpack-dev-server"
    )

    /**
      * Version of webpack-cli
      *
      * @group settings
      */
    val webpackCliVersion: SettingKey[String] =
      settingKey[String]("Version of webpack-cli to use")

    /**
      * Start background webpack-dev-server process.
      *
      * If webpack-dev-server is already running, it will be restarted.
      *
      * The started webpack-dev-server receives the following arguments:
      * - `--config` is set to value of `webpackConfigFile` setting.
      * - `--port` is set to value of `webpackDevServerPort` setting.
      * - Contents of `webpackDevServerExtraArgs` setting.
      *
      * @see [[stopWebpackDevServer]]
      * @see [[webpackDevServerPort]]
      * @see [[webpackDevServerExtraArgs]]
      * @group tasks
      */
    val startWebpackDevServer = TaskKey[Unit](
      "startWebpackDevServer",
      "(Re)start webpack-dev-server process"
    )

    /**
      * Stop running webpack-dev-server process.
      *
      * Does nothing if the server is not running.
      *
      * @see [[startWebpackDevServer]]
      * @group tasks
      */
    val stopWebpackDevServer = TaskKey[Unit](
      "stopWebpackDevServer",
      "Stop webpack-dev-server process (if running)"
    )

    /**
      * Locally install jsdom.
      *
      * You can set the jsdom package version to install with the key `version in installJsdom`.
      *
      * Returns the installation directory.
      *
      * @group tasks
      */
    val installJsdom = taskKey[File]("Locally install jsdom")

    /**
      * A flag to indicate the need to use a DOM enabled JS environment in test.
      *
      * Default is false.
      *
      * @group tasks
      */
    val requireJsDomEnv = taskKey[Boolean]("Require DOM enabled environment in test")

    /**
      * Local js source directories to be collected by the bundler
      *
      * Default is `src/main/js`
      *
      * @group settings
      */
    val jsSourceDirectories = settingKey[Seq[File]]("Local js source directories to be collected by the bundler")
  }

  private[sbtplugin] val scalaJSBundlerImportedModules =
    TaskKey[List[String]]("scalaJSBundlerImportedModules",
      "Computes the list of imported modules",
      KeyRanks.Invisible
    )

  private val scalaJSBundlerPackageJson =
    TaskKey[BundlerFile.PackageJson]("scalaJSBundlerPackageJson",
      "Write a package.json file defining the NPM dependencies of project",
      KeyRanks.Invisible
    )

  private[sbtplugin] val scalaJSBundlerWebpackConfig =
    TaskKey[BundlerFile.WebpackConfig]("scalaJSBundlerWebpackConfig",
      "Write the webpack configuration file",
      KeyRanks.Invisible
    )

  private val webpackDevServer = SettingKey[WebpackDevServer](
    "webpackDevServer",
    "Global WebpackDevServer instance",
    KeyRanks.Invisible
  )

  private[scalajsbundler] val ensureModuleKindIsCommonJSModule =
    SettingKey[Boolean](
      "ensureModuleKindIsCommonJSModule",
      "Checks that scalaJSModuleKind is set to CommonJSModule",
      KeyRanks.Invisible
    )

  import autoImport.{BundlerFile => _, _}

  override lazy val projectSettings: Seq[Def.Setting[_]] = Seq(

    scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule) },

    version in webpack := "5.75.0",

    webpackCliVersion := "4.5.0",

    version in startWebpackDevServer := "3.11.2",

    version in installJsdom := "9.9.0",

    webpackConfigFile := None,

    webpackResources := baseDirectory.value * "*.js",

    // Include the manifest in the produced artifact
    (products in Compile) := (products in Compile).dependsOn(scalaJSBundlerManifest).value,

    useYarn := false,

    ensureModuleKindIsCommonJSModule := {
      if (scalaJSLinkerConfig.value.moduleKind == ModuleKind.CommonJSModule) true
      else sys.error(s"scalaJSModuleKind must be set to ModuleKind.CommonJSModule in projects where ScalaJSBundler plugin is enabled")
    },

    webpackBundlingMode := BundlingMode.Default,

    // Make these settings project-level, since we don't expect much
    // difference between configurations/stages. This way the
    // API user can modify it just once.
    webpackMonitoredDirectories := Seq(),
    (includeFilter in webpackMonitoredFiles) := AllPassFilter,
    webpackExtraArgs := Seq.empty,
    webpackNodeArgs := Seq.empty,

    npmExtraArgs := Seq.empty,
    yarnExtraArgs := Seq.empty,

    // The defaults are specified at top level.
    webpackDevServerPort := 8080,
    webpackDevServerExtraArgs := Seq(),

    // We can only have one server per project - for simplicity
    webpackDevServer := new WebpackDevServer(),

    (onLoad in Global) := {
      (onLoad in Global).value.compose(
        _.addExitHook {
          webpackDevServer.value.stop()
        }
      )
    },

    installJsdom := {
      val installDir = target.value / "scalajs-bundler-jsdom"
      val baseDir = baseDirectory.value
      val jsdomDir = installDir / "node_modules" / "jsdom"
      val log = streams.value.log
      val jsdomVersion = (version in installJsdom).value
      if (!jsdomDir.exists()) {
        log.info(s"Installing jsdom in ${installDir.absolutePath}")
        IO.createDirectory(installDir)
        addPackages(baseDir, installDir, useYarn.value, log, npmExtraArgs.value, yarnExtraArgs.value)(s"jsdom@$jsdomVersion")
      }
      installDir
    }
  ) ++
    inConfig(Compile)(perConfigSettings) ++
    inConfig(Test)(perConfigSettings ++ testSettings)

  private lazy val perConfigSettings: Seq[Def.Setting[_]] =
    Def.settings(
      npmDependencies := Seq.empty,

      npmDevDependencies := Seq.empty,

      npmResolutions := Map.empty,

      additionalNpmConfig := Map(
        "private" -> JSON.bool(true),
        "license" -> JSON.str("UNLICENSED")
      ),

      jsSourceDirectories := Seq(sourceDirectory.value  / "js"),

      npmUpdate := {
        val _ = npmInstallJSResources.value
        npmInstallDependencies.value
      },

      npmInstallDependencies := NpmUpdateTasks.npmInstallDependencies(
        baseDirectory.value,
        (crossTarget in npmUpdate).value,
        scalaJSBundlerPackageJson.value.file,
        useYarn.value,
        streams.value,
        npmExtraArgs.value,
        yarnExtraArgs.value),

      npmInstallJSResources := NpmUpdateTasks.npmInstallJSResources(
        (crossTarget in npmUpdate).value,
        ScalaJSNativeLibraries(fullClasspath.value),
        jsSourceDirectories.value,
        streams.value),

      scalaJSBundlerPackageJson :=
        PackageJsonTasks.writePackageJson(
          (crossTarget in npmUpdate).value,
          npmDependencies.value,
          npmDevDependencies.value,
          npmResolutions.value,
          additionalNpmConfig.value,
          dependencyClasspath.value,
          configuration.value,
          (version in webpack).value,
          (version in startWebpackDevServer).value,
          webpackCliVersion.value,
          streams.value
        ),


      crossTarget in npmUpdate := {
        crossTarget.value / "scalajs-bundler" / (if (configuration.value == Compile) "main" else "test")
      },

      Settings.configSettings
    ) ++
    perScalaJSStageSettings(Stage.FastOpt) ++
    perScalaJSStageSettings(Stage.FullOpt)

  override def globalSettings: Seq[Def.Setting[_]] =
    Settings.globalSettings

  private lazy val testSettings: Seq[Setting[_]] =
    Def.settings(
      npmDependencies ++= (npmDependencies in Compile).value,

      npmDevDependencies ++= (npmDevDependencies in Compile).value,

      jsSourceDirectories ++= (jsSourceDirectories in Compile).value,

      requireJsDomEnv := false,

      Settings.testConfigSettings

    )

  private def perScalaJSStageSettings(stage: Stage): Seq[Def.Setting[_]] = {

    val stageTask = stage match {
      case Stage.FastOpt => fastOptJS
      case Stage.FullOpt => fullOptJS
    }

    Seq(
      // Ask Scala.js to output its result in our target directory
      crossTarget in stageTask := (crossTarget in npmUpdate).value,

      finallyEmitSourceMaps in stageTask := {
        (webpackEmitSourceMaps in stageTask).?.value
          .getOrElse((scalaJSLinkerConfig in stageTask).value.sourceMap)
      },

      // Override Scala.js’ relativeSourceMaps in case we have to emit source maps in the webpack task, because it does not work with absolute source maps
      scalaJSLinkerConfig in stageTask := {
        val prev = (scalaJSLinkerConfig in stageTask).value
        val relSourceMaps = (webpackEmitSourceMaps in stageTask).?.value.getOrElse(prev.sourceMap)
        val relSourceMapBase = (artifactPath in stageTask).value.toURI
        if (!relSourceMaps) {
          prev
        } else {
          prev.withRelativizeSourceMapBase(Some(relSourceMapBase))
        }
      },

      scalaJSBundlerWebpackConfig in stageTask := BundlerFile.WebpackConfig(
        WebpackTasks.entry(stageTask).value,
        npmUpdate.value / "scalajs.webpack.config.js"
      ),

      webpack in stageTask := Def.taskDyn {
        (webpackBundlingMode in stageTask).value match {
          case scalajsbundler.BundlingMode.Application =>
            WebpackTasks.webpack(stageTask)
          case mode: scalajsbundler.BundlingMode.LibraryOnly =>
            LibraryTasks.librariesAndLoaders(stageTask, mode)
          case mode: scalajsbundler.BundlingMode.LibraryAndApplication =>
            LibraryTasks.libraryAndLoadersBundle(stageTask, mode)
        }
      }.value,

      webpackMonitoredFiles in stageTask := {
        val generatedWebpackConfigFile = (scalaJSBundlerWebpackConfig in stageTask).value
        val customWebpackConfigFile = (webpackConfigFile in stageTask).value
        val packageJsonFile = scalaJSBundlerPackageJson.value
        val entry = WebpackTasks.entry(stageTask).value
        val filter = (includeFilter in webpackMonitoredFiles).value
        val dirs = (webpackMonitoredDirectories in stageTask).value

        val generatedFiles: Seq[File] = Seq(
          packageJsonFile.file,
          generatedWebpackConfigFile.file,
          entry.file)
        val additionalFiles: Seq[File] = dirs.flatMap(
          dir => (dir ** filter).get
        )
        generatedFiles ++
          customWebpackConfigFile.toSeq ++
          webpackResources.value.get ++
          additionalFiles
      },

      // webpack-dev-server wiring
      startWebpackDevServer in stageTask := Def.task {
        val extraArgs = (webpackDevServerExtraArgs in stageTask).value

        // This duplicates file layout logic from `Webpack`
        val targetDir = (npmUpdate in stageTask).value
        val customConfigOption = (webpackConfigFile in stageTask).value
        val generatedConfig = (scalaJSBundlerWebpackConfig in stageTask).value

        val config = customConfigOption
          .map(Webpack.copyCustomWebpackConfigFiles(targetDir, webpackResources.value.get))
          .getOrElse(generatedConfig.file)

        // To match `webpack` task behavior
        val workDir = targetDir

        // Server instance is project-level
        val server = webpackDevServer.value
        val logger = (streams in stageTask).value.log
        val globalLogger = state.value.globalLogging.full

        server.start(
          workDir,
          config,
          extraArgs,
          logger,
          globalLogger
        )
      }.dependsOn(
        // We need to execute the full webpack task once, since it generates
        // the required config file
        (webpack in stageTask),

        npmUpdate
      ).value,

      // Stops the global server instance, but is defined on stage
      // level to match `startWebpackDevServer`
      stopWebpackDevServer in stageTask := {
        webpackDevServer.value.stop()
      }
    )
  }

  /**
    * Writes the scalajs-bundler manifest file.
    */
  val scalaJSBundlerManifest: Def.Initialize[Task[File]] =
    Def.task {
      NpmDependencies.writeManifest(
        NpmDependencies(
          (npmDependencies in Compile).value.to[List],
          (npmDependencies in Test).value.to[List],
          (npmDevDependencies in Compile).value.to[List],
          (npmDevDependencies in Test).value.to[List]
        ),
        (classDirectory in Compile).value
      )
    }

}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/Settings.scala
================================================
package scalajsbundler.sbtplugin

import java.nio.charset.StandardCharsets
import java.nio.file.{Files, Path}
import scala.collection.JavaConverters._
import org.scalajs.jsenv.Input._
import org.scalajs.linker.interface._
import org.scalajs.sbtplugin._
import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._
import sbt.Keys._
import sbt._
import scalajsbundler.{JSDOMNodeJSEnv, Webpack, JsDomTestEntries, NpmPackage}
import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin.autoImport.{installJsdom, npmUpdate, requireJsDomEnv, webpackConfigFile, webpackNodeArgs, webpackResources, webpack}
import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin.{ensureModuleKindIsCommonJSModule, scalaJSBundlerImportedModules}
import scalajsbundler.sbtplugin.internal.BuildInfo

private[sbtplugin] object Settings {

  private class BundlerLinkerImpl(base: LinkerImpl.Reflect)
      extends LinkerImpl.Forwarding(base) {

    private val loader = base.loader

    private val clearableLinkerMethod = {
      Class.forName("scalajsbundler.bundlerlinker.BundlerLinkerImpl", true, loader)
        .getMethod("clearableLinker", classOf[StandardConfig], classOf[Path])
    }

    def bundlerLinker(config: StandardConfig, entryPointOutputFile: Path): ClearableLinker = {
      clearableLinkerMethod.invoke(null, config, entryPointOutputFile)
        .asInstanceOf[ClearableLinker]
    }
  }

  // Settings that must be applied in Global
  val globalSettings: Seq[Setting[_]] =
    Def.settings(
      fullClasspath in scalaJSLinkerImpl := {
        val s = streams.value
        val log = s.log
        val retrieveDir = s.cacheDirectory / "scalajs-bundler-linker"
        val lm = (dependencyResolution in scalaJSLinkerImpl).value
        val dummyModuleID =
          "ch.epfl.scala" % "scalajs-bundler-linker-and-scalajs-linker_2.12" % s"${BuildInfo.version}-$scalaJSVersion"
        val dependencies = Vector(
            // Load our linker back-end
            "ch.epfl.scala" % "scalajs-bundler-linker_2.12" % BuildInfo.version,
            // And force-bump the dependency on scalajs-linker to match the version of sbt-scalajs
            "org.scala-js" % "scalajs-linker_2.12" % scalaJSVersion
        )
        val moduleDescriptor = lm.moduleDescriptor(dummyModuleID, dependencies, scalaModuleInfo = None)
        lm.retrieve(moduleDescriptor, retrieveDir, log)
          .fold(w => throw w.resolveException, Attributed.blankSeq(_))
      },

      scalaJSLinkerImpl := {
        val cp = (fullClasspath in scalaJSLinkerImpl).value
        scalaJSLinkerImplBox.value.ensure {
          new BundlerLinkerImpl(LinkerImpl.reflect(Attributed.data(cp)))
        }
      }
    )

  // Settings that must be applied for each stage in each configuration
  private def scalaJSStageSettings(stage: Stage, key: TaskKey[Attributed[Report]],
      legacyKey: TaskKey[Attributed[File]]): Seq[Setting[_]] = {
    val entryPointOutputFileName =
      s"entrypoints-${stage.toString.toLowerCase}.txt"

    Def.settings(
      scalaJSLinker in legacyKey := {
        val config = (scalaJSLinkerConfig in key).value
        val box = (scalaJSLinkerBox in key).value
        val linkerImpl = (scalaJSLinkerImpl in key).value
        val entryPointOutputFile = crossTarget.value / entryPointOutputFileName

        box.ensure {
          linkerImpl.asInstanceOf[BundlerLinkerImpl]
            .bundlerLinker(config, entryPointOutputFile.toPath)
        }
      },

      scalaJSBundlerImportedModules in legacyKey := {
        val _ = legacyKey.value
        val entryPointOutputFile = crossTarget.value / entryPointOutputFileName
        val lines = Files.readAllLines(entryPointOutputFile.toPath, StandardCharsets.UTF_8)
        lines.asScala.toList
      }
    )
  }

  // Settings that must be applied for each configuration
  val configSettings: Seq[Setting[_]] =
    Def.settings(
      // Override Scala.js’ jsEnvInput to first run `npm update`
      jsEnvInput := jsEnvInput.dependsOn(npmUpdate).value,

      /* Moreover, force it to use the output of the legacy key, because lots
       * of things in scalajs-bundler assume that there is only one .js file
       * that we can put in a specific directory to make things work.
       */
      jsEnvInput := {
        val prev = jsEnvInput.value
        val linkingResult = scalaJSLinkerResult.value
        val legacyKeyOutput = scalaJSLinkedFile.value

        // Compute the path to the `main` module, which is what sbt-scalajs puts in jsEnvInput
        val report = linkingResult.data
        val optMainModule = report.publicModules.find(_.moduleID == "main")
        val optMainModulePath = optMainModule.map { mainModule =>
          val linkerOutputDirectory = linkingResult.get(scalaJSLinkerOutputDirectory.key).getOrElse {
            throw new MessageOnlyException(
                "Linking report was not attributed with output directory. " +
                "Please report this as a Scala.js bug.")
          }
          (linkerOutputDirectory / mainModule.jsFileName).toPath
        }

        // Replace the path to the `main` module by the path to the legacy key output
        optMainModulePath match {
          case Some(mainModulePath) =>
            prev.map {
              case CommonJSModule(module) if module == mainModulePath =>
                CommonJSModule(legacyKeyOutput.data.toPath())
              case inputItem =>
                inputItem
            }
          case None =>
            prev
        }
      },

      scalaJSStageSettings(FastOptStage, fastLinkJS, fastOptJS),
      scalaJSStageSettings(FullOptStage, fullLinkJS, fullOptJS)
    )

  // Settings that must be applied in the Test configuration
  val testConfigSettings: Seq[Setting[_]] =
    Def.settings(
      // Configure a JSDOMNodeJSEnv with an installation of jsdom if requireJsDomEnv is true
      jsEnv := {
        val defaultJSEnv = jsEnv.value
        val optJsdomDir = Def.taskDyn[Option[File]] {
          if (requireJsDomEnv.value)
            installJsdom.map(Some(_))
          else
            Def.task(None)
        }.value
        optJsdomDir match {
          case Some(jsdomDir) => new JSDOMNodeJSEnv(JSDOMNodeJSEnv.Config(jsdomDir))
          case None           => defaultJSEnv
        }
      },

      // Use the product of bundling in jsEnvInput if requireJsDomEnv is true
      jsEnvInput := Def.task {
        assert(ensureModuleKindIsCommonJSModule.value)
        val prev = jsEnvInput.value
        val sjsOutput = scalaJSLinkedFile.value.data

        val optBundle = {
          Def.taskDyn[Option[org.scalajs.jsenv.Input]] {
            val sjsOutput = scalaJSLinkedFile.value.data
            // If jsdom is going to be used, then we should bundle the test module
            if (requireJsDomEnv.value) Def.task {
              val logger = streams.value.log
              val targetDir = npmUpdate.value
              val sjsOutputName = sjsOutput.name.stripSuffix(".js")
              val bundle = targetDir / s"$sjsOutputName-bundle.js"
              val webpackVersion = (version in webpack).value

              val customWebpackConfigFile = (webpackConfigFile in Test).value
              val nodeArgs = (webpackNodeArgs in Test).value

              val writeTestBundleFunction =
                FileFunction.cached(
                  streams.value.cacheDirectory / "test-loader",
                  inStyle = FilesInfo.hash
                ) { _ =>
                  logger.info("Writing and bundling the test loader")
                  val loader = targetDir / s"$sjsOutputName-loader.js"
                  JsDomTestEntries.writeLoader(sjsOutput, loader)

                  val configArgs = customWebpackConfigFile match {
                    case Some(configFile) =>
                      val customConfigFileCopy = Webpack.copyCustomWebpackConfigFiles(targetDir, webpackResources.value.get)(configFile)
                      Seq("--config", customConfigFileCopy.getAbsolutePath)

                    case None =>
                      Seq.empty
                  }

                  // TODO: It assumes tests are run on development mode. It should instead use build settings
                  val allArgs = Seq(
                    "--mode", "development",
                    "--entry", loader.absolutePath,
                    "--output-path", bundle.getParentFile.absolutePath,
                    "--output-filename", bundle.name
                  ) ++ configArgs

                  NpmPackage(webpackVersion).major match {
                    case Some(5) =>
                      Webpack.run(nodeArgs: _*)(allArgs: _*)(targetDir, logger)
                    case Some(x) =>
                      sys.error(s"Unsupported webpack major version $x")
                    case None =>
                      sys.error("No webpack version defined")
                  }

                  Set.empty
                }
              writeTestBundleFunction(Set(sjsOutput))

              Some(Script(bundle.toPath))
            } else Def.task {
              None
            }
          }.value
        }

        optBundle match {
          case Some(bundle) =>
            prev.map {
              case CommonJSModule(module) if module == sjsOutput.toPath() =>
                bundle
              case inputItem =>
                inputItem
            }
          case None =>
            prev
        }
      }.dependsOn(npmUpdate).value
    )

}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/WebpackTasks.scala
================================================
package scalajsbundler.sbtplugin
import sbt.Keys._
import sbt.{Def, _}

import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport.scalaJSLinkerConfig
import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin._
import scalajsbundler.sbtplugin.ScalaJSBundlerPlugin.autoImport._
import scalajsbundler.Webpack

object WebpackTasks {
  private[sbtplugin] def entry(stage: TaskKey[Attributed[File]])
  : Def.Initialize[Task[BundlerFile.Application]] =
    Def.task {
      val projectName = stage.value.data.name.stripSuffix(".js")
      BundlerFile.Application(projectName, stage.value.data, Nil)
    }

  private[sbtplugin] def webpack(
      stage: TaskKey[Attributed[File]]): Def.Initialize[Task[Seq[Attributed[File]]]] =
    Def.task {
      assert(ensureModuleKindIsCommonJSModule.value)
      val cacheLocation = streams.value.cacheDirectory / s"${stage.key.label}-webpack"
      val generatedWebpackConfigFile =
        (scalaJSBundlerWebpackConfig in stage).value
      val emitSourceMaps = (finallyEmitSourceMaps in stage).value
      val customWebpackConfigFile = (webpackConfigFile in stage).value
      val webpackResourceFiles = webpackResources.value.get
      val entriesList = entry(stage).value
      val targetDir = npmUpdate.value
      val log = streams.value.log
      val monitoredFiles = (webpackMonitoredFiles in stage).value
      val extraArgs = (webpackExtraArgs in stage).value
      val nodeArgs = (webpackNodeArgs in stage).value
      val webpackMode =
        Webpack.WebpackMode.fromBooleanProductionMode((scalaJSLinkerConfig in stage).value.semantics.productionMode)
      val devServerPort = webpackDevServerPort.value

      val cachedActionFunction =
        FileFunction.cached(
          cacheLocation,
          inStyle = FilesInfo.hash
        ) { _ =>
          Webpack.bundle(
            emitSourceMaps,
            generatedWebpackConfigFile,
            customWebpackConfigFile,
            webpackResourceFiles,
            entriesList,
            targetDir,
            extraArgs,
            nodeArgs,
            webpackMode,
            devServerPort,
            log
          ).cached
        }
      val cached = cachedActionFunction(monitoredFiles.to[Set])
      generatedWebpackConfigFile.asApplicationBundleFromCached(cached).asAttributedFiles
    }
}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/util/CachedBundleFiles.scala
================================================
package scalajsbundler.util

import java.io.File
import scala.collection.immutable.ListSet

object CachedBundleFiles {
  def cached(file: File, assets: List[File]): ListSet[File] = {
    // Let's put the main file first
    val sortedAssets = file :: assets.filterNot(_ == file)
    // use list set to preserve the order
    ListSet(sortedAssets: _*)
  }
}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/util/Caching.scala
================================================
package scalajsbundler.util

import sbt._

object Caching {

  def cached(
    fileToWrite: File,
    hash: String,
    cache: File
  )(
    write: () => Unit
  ): Unit = {
    if (!fileToWrite.exists() || (cache.exists() && IO.read(cache) != hash)) {
      write()
      IO.write(cache, hash)
    }
  }

}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/util/Commands.scala
================================================
package scalajsbundler.util

import sbt.Logger
import java.io.{InputStream, File}
import scala.sys.process.Process
import scala.sys.process.BasicIO
import scala.sys.process.ProcessLogger

object Commands {

  def run[A](cmd: Seq[String], cwd: File, logger: Logger, outputProcess: InputStream => A): Either[String, Option[A]] = {
    val toErrorLog = (is: InputStream) => {
      scala.io.Source.fromInputStream(is).getLines.foreach(msg => logger.error(msg))
      is.close()
    }

    // Unfortunately a var is the only way to capture the result
    var result: Option[A] = None
    def outputCapture(o: InputStream): Unit = {
      result = Some(outputProcess(o))
      o.close()
      ()
    }

    logger.debug(s"Command: ${cmd.mkString(" ")}")
    val process = Process(cmd, cwd)
    val processIO = BasicIO.standard(false).withOutput(outputCapture).withError(toErrorLog)
    val code: Int = process.run(processIO).exitValue()
    if (code != 0) {
      Left(s"Non-zero exit code: $code")
    } else {
      Right(result)
    }
  }

  def run(cmd: Seq[String], cwd: File, logger: Logger): Unit = {
    val toInfoLog = (is: InputStream) => scala.io.Source.fromInputStream(is).getLines.foreach(msg => logger.info(msg))
    run(cmd, cwd, logger, toInfoLog).fold(sys.error, _ => ())
  }

  def start(cmd: Seq[String], cwd: File, logger: Logger): Process =
    Process(cmd, cwd).run(toProcessLogger(logger))

  private def toProcessLogger(logger: Logger): ProcessLogger =
    ProcessLogger(msg => logger.info(msg), msg => logger.error(msg))

}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/util/JS.scala
================================================
package scalajsbundler.util

import java.util.concurrent.atomic.AtomicInteger

import JSTrees._

private[util] sealed abstract class JSLike(val tree: Tree) {
  def show: String = tree.show
  def show(isStat: Boolean = true): String = JSLike.show(tree, isStat)
  def toJson: String = JSLike.show(tree, isStat = false)
}

object JSLike {
  private def show(tree: Tree, isStat: Boolean): String = {
    val writer = new java.io.StringWriter
    val printer = new JSPrinters.JSTreePrinter(writer)
    printer.printTree(tree, isStat)
    writer.toString
  }
}

/** A convenient wrapper around JS trees */
final class JS private(tree: Tree) extends JSLike(tree) {
  def dot(ident: String): JS = JS(DotSelect(tree, Ident(ident)))
  def bracket(ident: String): JS = JS(BracketSelect(tree, StringLiteral(ident)))
  def bracket(ident: JSLike): JS = JS(BracketSelect(tree, ident.tree))
  def assign(rhs: JSLike): JS = JS(Assign(tree, rhs.tree))
  def apply(args: JSLike*): JS = JS(Apply(tree, args.map(_.tree).to[List]))
}

object JS {

  private[util] def apply(tree: Tree): JS = new JS(tree)

  /** Array literal. */
  def arr(elems: JSLike*): JS = JS(ArrayConstr(elems.map(_.tree).to[List]))

  /** Boolean literal */
  def bool(value: Boolean): JS = JS(BooleanLiteral(value))

  /** Object literal */
  def obj(fields: (String, JSLike)*): JS =
    JS(ObjectConstr(fields.map { case (ident, value) => (StringLiteral(ident), value.tree) }.to[List]))

  /** Object literal */
  def objStr(fields: Seq[(String, String)]): JS =
    obj(fields.map { case (k, v) => k -> JS.str(v) }: _*)

  /** String literal */
  def str(value: String): JS = JS(StringLiteral(value))

  /** Numeric literal */
  def int(value: Int): JS = JS(IntLiteral(value))

  /** Variable reference */
  def ref(ident: String): JS =
    JS(varRef(ident))

  private def varRef(ident: String): VarRef = VarRef(Ident(ident))

  /** Variable definition */
  def `var`(ident: String, rhs: Option[JSLike] = None): JS =
    JS(VarDef(Ident(ident), rhs.map(_.tree)))

  def regex(value: String): JS =
    JS(New(varRef("RegExp"), List(StringLiteral(value))))

  /** Block of several statements */
  def block(stats: JS*): JS = JS(Block(stats.map(_.tree).to[List]))

  /** Anonymous function definition */
  def fun(body: JS => JSLike): JS = {
    val param = freshIdentifier()
    JS(Function(arrow = false, List(ParamDef(Ident(param), rest = false)), Return(body(ref(param)).tree)))
  }

  /** Name binding */
  def let(value: JS)(usage: JS => JS): JS = {
    val ident = freshIdentifier()
    JS(Block(VarDef(Ident(ident), Some(value.tree)), usage(ref(ident)).tree))
  }

  /** Name binding */
  def let(value1: JS, value2: JS)(usage: (JS, JS) => JS): JS = {
    val ident1 = freshIdentifier()
    val ident2 = freshIdentifier()
    JS(
      Block(
        VarDef(Ident(ident1), Some(value1.tree)),
        VarDef(Ident(ident2), Some(value2.tree)),
        usage(ref(ident1), ref(ident2)).tree
      )
    )
  }

  def `new`(ctor: JS, args: JSLike*): JS = JS(New(ctor.tree, args.map(_.tree).to[List]))

  private val identifierSeq = new AtomicInteger(0)
  private def freshIdentifier(): String =
    s"x${identifierSeq.getAndIncrement()}"

}

final class JSON private(tree: Tree) extends JSLike(tree)

object JSON {

  private[util] def apply(tree: Tree): JSON = new JSON(tree)

  /** Array literal. */
  def arr(elems: JSON*): JSON = JSON(ArrayConstr(elems.map(_.tree).to[List]))

  /** Boolean literal */
  def bool(value: Boolean): JSON = JSON(BooleanLiteral(value))

  /** Object literal */
  def obj(fields: (String, JSON)*): JSON =
    JSON(ObjectConstr(fields.map { case (ident, value) => (StringLiteral(ident), value.tree) }.to[List]))

  /** Object literal */
  def objStr(fields: Seq[(String, String)]): JSON =
    obj(fields.map { case (k, v) => k -> JSON.str(v) }: _*)

  /** String literal */
  def str(value: String): JSON = JSON(StringLiteral(value))

}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/util/JSBundler.scala
================================================
package scalajsbundler.util

import sbt._

import scalajsbundler.BundlerFile

object JSBundler {

  def loaderScript(bundleName: String): String =
    s"""
       |var exports = window;
       |exports.require = window["$bundleName"].require;
    """.stripMargin

  def writeLoader(
      loaderFile: BundlerFile.Loader,
      bundleName: String
  ): Unit =
    IO.write(loaderFile.file, loaderScript(bundleName))

  /**
    * Run webpack to bundle the application.
    *
    * @param targetDir Target directory (and working directory for Nodejs)
    * @param logger Logger
    * @return The generated bundles
    */
  def bundle(
      targetDir: File,
      entry: BundlerFile.Application,
      libraryFile: BundlerFile.Library,
      emitSourceMaps: Boolean = false,
      libraryBundleName: String,
      logger: Logger
  ): BundlerFile.ApplicationBundle = {
    val bundleFile = entry.asApplicationBundle
    val loaderFile = entry.asLoader
    writeLoader(loaderFile, libraryBundleName)
    if (emitSourceMaps) {
      logger.info("Bundling dependencies with source maps")
      val concatContent =
        JS.let(
          JS.ref("require")(JS.str("concat-with-sourcemaps")),
          JS.ref("require")(JS.str("fs"))
        ) { (Concat, fs) =>
          JS.let(
            JS.`new`(Concat,
                     JS.bool(true),
                     JS.str(bundleFile.file.name),
                     JS.str(";\n"))) { concat =>
            JS.block(
              concat
                .dot("add")
                .apply(
                  JS.str(""),
                  fs.dot("readFileSync")
                    .apply(JS.str(libraryFile.file.absolutePath),
                           JS.str("utf-8")),
                  fs.dot("readFileSync")
                    .apply(JS.str(libraryFile.file.absolutePath ++ ".map"))
                ),
              concat
                .dot("add")
                .apply(JS.str(loaderFile.file.name),
                       fs.dot("readFileSync")
                         .apply(JS.str(loaderFile.file.absolutePath))),
              concat
                .dot("add")
                .apply(
                  JS.str(""),
                  fs.dot("readFileSync")
                    .apply(JS.str(entry.file.absolutePath), JS.str("utf-8")),
                  fs.dot("readFileSync")
                    .apply(JS.str(entry.file.absolutePath ++ ".map"),
                           JS.str("utf-8"))
                ),
              JS.let(JS.ref("Buffer").dot("from").apply(
                JS.str(s"\n//# sourceMappingURL=${bundleFile.file.name ++ ".map"}\n"))
              ) { endBuffer =>
                  JS.let(
                    JS.ref("Buffer")
                      .dot("concat")
                      .apply(JS.arr(concat.dot("content"), endBuffer))) {
                    result =>
                      fs.dot("writeFileSync")
                        .apply(JS.str(bundleFile.file.absolutePath), result)
                  }
              },
              fs.dot("writeFileSync")
                .apply(JS.str(bundleFile.file.absolutePath ++ ".map"),
                       concat.dot("sourceMap"))
            )
          }
        }
      val concatFile = targetDir / s"scalajsbundler-concat-${bundleFile.file.name}"
      IO.write(concatFile, concatContent.show)
      Commands.run(Seq("node", concatFile.absolutePath), targetDir, logger)
    } else {
      logger.info("Bundling dependencies without source maps")
      IO.withTemporaryFile("scalajs-bundler", entry.project) { tmpFile =>
        IO.append(tmpFile, IO.readBytes(libraryFile.file))
        IO.append(tmpFile, "\n")
        IO.append(tmpFile, IO.readBytes(loaderFile.file))
        IO.append(tmpFile, "\n")
        IO.append(tmpFile, IO.readBytes(entry.file))
        IO.move(tmpFile, bundleFile.file)
      }
    }
    bundleFile
  }
}


================================================
FILE: sbt-scalajs-bundler/src/main/scala/scalajsbundler/util/JSPrinters.scala
================================================
package scalajsbundler.util

import scala.annotation.switch

// Unimport default print and println to avoid invoking them by mistake
import scala.Predef.{print => _, println => _, _}

import java.io.Writer

import JSTrees._

// This is copied from `org.scalajs.linker.backend.javascript.Printers` in Scala.js.
private[util] object JSPrinters {

  abstract class IndentationManager {
    protected val out: Writer

    private var indentMargin = 0
    private val indentStep = 2
    private var indentString = "                                        " // 40

    protected def indent(): Unit = indentMargin += indentStep
    protected def undent(): Unit = indentMargin -= indentStep

    protected def getIndentMargin(): Int = indentMargin

    protected def println(): Unit = {
      out.write('\n')
      while (indentMargin > indentString.length())
        indentString += indentString
      if (indentMargin > 0)
        out.write(indentString, 0, indentMargin)
    }
  }

  class JSTreePrinter(protected val out: Writer) extends IndentationManager {

    def printTopLevelTree(tree: Tree): Unit = {
      tree match {
        case Skip() =>
          // do not print anything
        case tree: Block =>
          var rest = tree.stats
          while (rest.nonEmpty) {
            printTopLevelTree(rest.head)
            rest = rest.tail
          }
        case _ =>
          printStat(tree)
          if (shouldPrintSepAfterTree(tree))
            print(';')
          println()
      }
    }

    protected def shouldPrintSepAfterTree(tree: Tree): Boolean = tree match {
      case _:DocComment | _:FunctionDef | _:ClassDef => false
      case _                                         => true
    }

    protected def printRow(ts: List[Tree], start: Char, end: Char): Unit = {
      print(start.toInt)
      var rest = ts
      while (rest.nonEmpty) {
        print(rest.head)
        rest = rest.tail
        if (rest.nonEmpty)
          print(", ")
      }
      print(end.toInt)
    }

    protected def printBlock(tree: Tree): Unit = {
      print('{'); indent(); println()
      tree match {
        case tree: Block =>
          var rest = tree.stats
          while (rest.nonEmpty) {
            val x = rest.head
            rest = rest.tail
            printStat(x)
            if (rest.nonEmpty) {
              if (shouldPrintSepAfterTree(x))
                print(';')
              println()
            }
          }

        case _ =>
          printStat(tree)
      }
      undent(); println(); print('}')
    }

    protected def printSig(args: List[ParamDef]): Unit = {
      printRow(args, '(', ')')
      print(' ')
    }

    protected def printArgs(args: List[Tree]): Unit =
      printRow(args, '(', ')')

    protected def printStat(tree: Tree): Unit =
      printTree(tree, isStat = true)

    protected def print(tree: Tree): Unit =
      printTree(tree, isStat = false)

    def printTree(tree: Tree, isStat: Boolean): Unit = {
      tree match {
        // Comments

        case DocComment(text) =>
          val lines = text.split("\n").toList
          if (lines.tail.isEmpty) {
            print("/** ")
            print(lines.head)
            print(" */")
          } else {
            print("/** ")
            print(lines.head)
            println()
            var rest = lines.tail
            while (rest.nonEmpty) {
              print(" *  ")
              print(rest.head)
              println()
              rest = rest.tail
            }
            print(" */")
          }

        // Definitions

        case VarDef(ident, optRhs) =>
          print("var ")
          print(ident)
          optRhs foreach { rhs =>
            print(" = ")
            print(rhs)
          }

        case Let(ident, mutable, optRhs) =>
          print(if (mutable) "let " else "const ")
          print(ident)
          optRhs foreach { rhs =>
            print(" = ")
            print(rhs)
          }

        case ParamDef(ident, rest) =>
          if (rest)
            print("...")
          print(ident)

        // Control flow constructs

        case Skip() =>
          print("/*<skip>*/")

        case tree: Block =>
          if (isStat)
            printBlock(tree)
          else
            printRow(tree.stats, '(', ')')

        case Labeled(label, body) =>
          print(label)
          print(": ")
          printBlock(body)

        case Assign(lhs, rhs) =>
          print(lhs)
          print(" = ")
          print(rhs)

        case Return(expr) =>
          print("return ")
          print(expr)

        case If(cond, thenp, elsep) =>
          if (isStat) {
            print("if (")
            print(cond)
            print(") ")
            printBlock(thenp)
            elsep match {
              case Skip() => ()
              case _: If =>
                print(" else ")
                printTree(elsep, isStat)
              case _ =>
                print(" else ")
                printBlock(elsep)
            }
          } else {
            print('(')
            print(cond)
            print(" ? ")
            print(thenp)
            print(" : ")
            print(elsep)
            print(')')
          }

        case While(cond, body, label) =>
          if (label.isDefined) {
            print(label.get)
            print(": ")
          }
          print("while (")
          print(cond)
          print(") ")
          printBlock(body)

        case DoWhile(body, cond, label) =>
          if (label.isDefined) {
            print(label.get)
            print(": ")
          }
          print("do ")
          printBlock(body)
          print(" while (")
          print(cond)
          print(')')

        case ForIn(lhs, obj, body) =>
          print("for (")
          print(lhs)
          print(" in ")
          print(obj)
          print(") ")
          printBlock(body)

        case For(init, guard, update, body) =>
          print("for (")
          print(init)
          print("; ")
          print(guard)
          print("; ")
          print(update)
          print(") ")
          printBlock(body)

        case TryFinally(TryCatch(block, errVar, handler), finalizer) =>
          print("try ")
          printBlock(block)
          print(" catch (")
          print(errVar)
          print(") ")
          printBlock(handler)
          print(" finally ")
          printBlock(finalizer)

        case TryCatch(block, errVar, handler) =>
          print("try ")
          printBlock(block)
          print(" catch (")
          print(errVar)
          print(") ")
          printBlock(handler)

        case TryFinally(block, finalizer) =>
          print("try ")
          printBlock(block)
          print(" finally ")
          printBlock(finalizer)

        case Throw(expr) =>
          print("throw ")
          print(expr)

        case Break(label) =>
          if (label.isEmpty) print("break")
          else {
            print("break ")
            print(label.get)
          }

        case Continue(label) =>
          if (label.isEmpty) print("continue")
          else {
            print("continue ")
            print(label.get)
          }

        case Switch(selector, cases, default) =>
          print("switch (")
          print(selector)
          print(") ")
          print('{')
          indent()
          var rest = cases
          while (rest.nonEmpty) {
            val next = rest.head
            rest = rest.tail
            println()
            print("case ")
            print(next._1)
            print(':')
            if (!next._2.isInstanceOf[Skip]) {
              print(' ')
              printBlock(next._2)
            }
          }

          default match {
            case Skip() =>
            case _ =>
              println()
              print("default: ")
              printBlock(default)
          }

          undent()
          println()
          print('}')

        case Debugger() =>
          print("debugger")

        // Expressions

        case New(ctor, args) =>
          def containsOnlySelectsFromAtom(tree: Tree): Boolean = tree match {
            case DotSelect(qual, _)     => containsOnlySelectsFromAtom(qual)
            case BracketSelect(qual, _) => containsOnlySelectsFromAtom(qual)
            case VarRef(_)              => true
            case This()                 => true
            case _                      => false // in particular, Apply
          }
          if (containsOnlySelectsFromAtom(ctor)) {
            print("new ")
            print(ctor)
          } else {
            print("new (")
            print(ctor)
            print(')')
          }
          printArgs(args)

        case DotSelect(qualifier, item) =>
          qualifier match {
            case _:IntLiteral | _:DoubleLiteral =>
              print("(")
              print(qualifier)
              print(")")
            case _ =>
              print(qualifier)
          }
          print(".")
          print(item)

        case BracketSelect(qualifier, item) =>
          print(qualifier)
          print('[')
          print(item)
          print(']')

        case Apply(fun, args) =>
          print(fun)
          printArgs(args)

        case ImportCall(arg) =>
          print("import(")
          print(arg)
          print(')')

        case Spread(items) =>
          print("...")
          print(items)

        case Delete(prop) =>
          print("delete ")
          print(prop)

        case UnaryOp(op, lhs) =>
          import UnaryOp._
          print('(')
          if (op == `typeof`) {
            print("typeof ")
          } else {
            (op: @switch) match {
              case + => print('+')
              case - => print('-')
              case ~ => print('~')
              case ! => print('!')
              case `typeof` => print("typeof ")
            }
          }
          print(lhs)
          print(')')

        case IncDec(prefix, inc, arg) =>
          val op = if (inc) "++" else "--"
          print('(')
          if (prefix)
            print(op)
          print(arg)
          if (!prefix)
            print(op)
          print(')')

        case BinaryOp(op, lhs, rhs) =>
          import BinaryOp._
          print('(')
          print(lhs)
          print(' ')
          print((op: @switch) match {
            case === => "==="
            case !== => "!=="

            case + => "+"
            case - => "-"
            case * => "*"
            case / => "/"
            case % => "%"

            case |   => "|"
            case &   => "&"
            case ^   => "^"
            case <<  => "<<"
            case >>  => ">>"
            case >>> => ">>>"

            case <  => "<"
            case <= => "<="
            case >  => ">"
            case >= => ">="

            case && => "&&"
            case || => "||"

            case `in`         => "in"
            case `instanceof` => "instanceof"
          })
          print(' ')
          print(rhs)
          print(')')

        case ArrayConstr(items) =>
          printRow(items, '[', ']')

        case ObjectConstr(Nil) =>
          if (isStat)
            print("({})") // force expression position for the object literal
          else
            print("{}")

        case ObjectConstr(fields) =>
          if (isStat)
            print('(') // force expression position for the object literal
          print('{')
          indent()
          println()
          var rest = fields
          while (rest.nonEmpty) {
            val x = rest.head
            rest = rest.tail
            print(x._1)
            print(": ")
            print(x._2)
            if (rest.nonEmpty) {
              print(',')
              println()
            }
          }
          undent()
          println()
          print('}')
          if (isStat)
            print(')')

        // Literals

        case Undefined() =>
          print("(void 0)")

        case Null() =>
          print("null")

        case BooleanLiteral(value) =>
          print(if (value) "true" else "false")

        case IntLiteral(value) =>
          if (value >= 0) {
            print(value.toString)
          } else {
            print('(')
            print(value.toString)
            print(')')
          }

        case DoubleLiteral(value) =>
          if (value == 0 && 1 / value < 0) {
            print("(-0)")
          } else if (value >= 0) {
            print(value.toString)
          } else {
            print('(')
            print(value.toString)
            print(')')
          }

        case StringLiteral(value) =>
          print('\"')
          printEscapeJS(value)
          print('\"')

        case BigIntLiteral(value) =>
          if (value >= 0) {
            print(value.toString)
            print('n')
          } else {
            print('(')
            print(value.toString)
            print("n)")
          }

        // Atomic expressions

        case VarRef(ident) =>
          print(ident)

        case This() =>
          print("this")

        case Function(arrow, args, body) =>
          if (arrow) {
            print('(')
            printSig(args)
            print("=> ")
            body match {
              case Return(expr: ObjectConstr) =>
                /* #3926 An ObjectConstr needs to be wrapped in () not to be
                 * parsed as a block.
                 */
                print('(')
                print(expr)
                print(')')
              case Return(expr) =>
                print(expr)
              case _ =>
                printBlock(body)
            }
            print(')')
          } else {
            print("(function")
            printSig(args)
            printBlock(body)
            print(')')
          }

        // Named function definition

        case FunctionDef(name, args, body) =>
          if (!isStat)
            print('(')
          print("function ")
          print(name)
          printSig(args)
          printBlock(body)
          if (!isStat)
            print(')')

        // ECMAScript 6 classes

        case ClassDef(optClassName, optParentClass, members) =>
          print("class")
          if (optClassName.isDefined) {
            print(' ')
            print(optClassName.get)
          }
          if (optParentClass.isDefined) {
            print(" extends ")
            print(optParentClass.get)
          }
          print(" {"); indent()
          var rest = members
          while (rest.nonEmpty) {
            println()
            print(rest.head)
            print(';')
            rest = rest.tail
          }
          undent(); println(); print('}')

        case MethodDef(static, name, params, body) =>
          if (static)
            print("static ")
          print(name)
          printSig(params)
          printBlock(body)

        case GetterDef(static, name, body) =>
          if (static)
            print("static ")
          print("get ")
          print(name)
          printSig(Nil)
          printBlock(body)

        case SetterDef(static, name, param, body) =>
          if (static)
            print("static ")
          print("set ")
          print(name)
          print('(')
          print(param)
          print(") ")
          printBlock(body)

        case Super() =>
          print("super")

        // ECMAScript 6 modules

        case Import(bindings, from) =>
          print("import { ")
          var first = true
          var rest = bindings
          while (rest.nonEmpty) {
            val binding = rest.head
            if (first)
              first = false
            else
              print(", ")
            print(binding._1)
            print(" as ")
            print(binding._2)
            rest = rest.tail
          }
          print(" } from ")
          print(from: Tree)

        case ImportNamespace(binding, from) =>
          print("import * as ")
          print(binding)
          print(" from ")
          print(from: Tree)

        case Export(bindings) =>
          print("export { ")
          var first = true
          var rest = bindings
          while (rest.nonEmpty) {
            val binding = rest.head
            if (first)
              first = false
            else
              print(", ")
            print(binding._1)
            print(" as ")
            print(binding._2)
            rest = rest.tail
          }
          print(" }")
      }
    }

    protected def printEscapeJS(s: String): Unit =
      JSPrinters.printEscapeJS(s, out)

    protected def print(ident: Ident): Unit =
      printEscapeJS(ident.name)

    private final def print(propName: PropertyName): Unit = propName match {
      case lit: StringLiteral => print(lit: Tree)
      case ident: Ident       => print(ident)

      case ComputedName(tree) =>
        print("[")
        print(tree)
        print("]")
    }

    protected def print(exportName: ExportName): Unit =
      printEscapeJS(exportName.name)

    protected def print(s: String): Unit =
      out.write(s)

    protected d
Download .txt
gitextract_pvw7avpo/

├── .drone.yml
├── .github/
│   ├── dependabot.yml
│   └── workflows/
│       ├── ci.yml
│       ├── ghpages.yml
│       └── release.yml
├── .gitignore
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── build.sbt
├── manual/
│   └── src/
│       ├── ornate/
│       │   ├── changelog.md
│       │   ├── community.md
│       │   ├── cookbook.md
│       │   ├── getting-started.md
│       │   ├── index.md
│       │   ├── motivation.md
│       │   └── reference.md
│       └── ornate.conf
├── project/
│   ├── build.properties
│   └── plugins.sbt
├── sbt-scalajs-bundler/
│   └── src/
│       ├── main/
│       │   └── scala/
│       │       └── scalajsbundler/
│       │           ├── BundlerFile.scala
│       │           ├── BundlerFileType.scala
│       │           ├── BundlingMode.scala
│       │           ├── ExternalCommand.scala
│       │           ├── JSDOMNodeJSEnv.scala
│       │           ├── JsDomTestEntries.scala
│       │           ├── NpmDependencies.scala
│       │           ├── NpmPackage.scala
│       │           ├── PackageJson.scala
│       │           ├── Stats.scala
│       │           ├── Webpack.scala
│       │           ├── WebpackDevServer.scala
│       │           ├── WebpackEntryPoint.scala
│       │           ├── sbtplugin/
│       │           │   ├── LibraryTasks.scala
│       │           │   ├── NpmUpdateTasks.scala
│       │           │   ├── PackageJsonTasks.scala
│       │           │   ├── SBTBundlerFile.scala
│       │           │   ├── ScalaJSBundlerPlugin.scala
│       │           │   ├── Settings.scala
│       │           │   └── WebpackTasks.scala
│       │           └── util/
│       │               ├── CachedBundleFiles.scala
│       │               ├── Caching.scala
│       │               ├── Commands.scala
│       │               ├── JS.scala
│       │               ├── JSBundler.scala
│       │               ├── JSPrinters.scala
│       │               ├── JSTrees.scala
│       │               └── ScalaJSNativeLibraries.scala
│       └── sbt-test/
│           └── sbt-scalajs-bundler/
│               ├── additonalNpmConfig/
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   └── test
│               ├── browserless/
│               │   ├── README.md
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   ├── main/
│               │   │   │   └── scala/
│               │   │   │       ├── example/
│               │   │   │       │   ├── Foo.scala
│               │   │   │       │   └── Main.scala
│               │   │   │       └── uuid/
│               │   │   │           └── uuid.scala
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── FooTest.scala
│               │   └── test
│               ├── custom-test-config/
│               │   ├── README.md
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   ├── main/
│               │   │   │   └── scala/
│               │   │   │       └── example/
│               │   │   │           └── Component.scala
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── SomeTest.scala
│               │   ├── test
│               │   └── test.webpack.config.js
│               ├── facade/
│               │   ├── build.sbt
│               │   ├── facade/
│               │   │   └── src/
│               │   │       └── main/
│               │   │           └── scala/
│               │   │               └── uuid/
│               │   │                   └── uuid.scala
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── test
│               │   └── usage/
│               │       └── src/
│               │           ├── main/
│               │           │   └── scala/
│               │           │       └── example/
│               │           │           ├── Foo.scala
│               │           │           └── Main.scala
│               │           └── test/
│               │               └── scala/
│               │                   └── example/
│               │                       └── FooTest.scala
│               ├── facade-examples/
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   ├── main/
│               │   │   │   ├── resources/
│               │   │   │   │   ├── class.js
│               │   │   │   │   ├── foo.js
│               │   │   │   │   └── function.js
│               │   │   │   └── scala/
│               │   │   │       └── example/
│               │   │   │           ├── Main.scala
│               │   │   │           └── facades.scala
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── FacadesTest.scala
│               │   └── test
│               ├── generated-sources/
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   └── test
│               ├── global-namespace-with-jsdom-unit-testing/
│               │   ├── build.sbt
│               │   ├── common.webpack.config.js
│               │   ├── dev.webpack.config.js
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   ├── main/
│               │   │   │   └── scala/
│               │   │   │       └── example/
│               │   │   │           └── Main.scala
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── MainTest.scala
│               │   ├── test
│               │   └── test.webpack.config.js
│               ├── js-resources/
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   ├── main/
│               │   │   │   ├── resources/
│               │   │   │   │   └── my-module.js
│               │   │   │   └── scala/
│               │   │   │       └── example/
│               │   │   │           ├── Main.scala
│               │   │   │           └── MyModule.scala
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── MyModuleTest.scala
│               │   └── test
│               ├── js-source-directory/
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   ├── main/
│               │   │   │   ├── js/
│               │   │   │   │   ├── config.json
│               │   │   │   │   ├── my-module.js
│               │   │   │   │   └── nested/
│               │   │   │   │       └── config2.json
│               │   │   │   └── scala/
│               │   │   │       └── example/
│               │   │   │           ├── Main.scala
│               │   │   │           └── MyModule.scala
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── MyModuleTest.scala
│               │   └── test
│               ├── library/
│               │   ├── build.sbt
│               │   ├── index.html
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   └── main/
│               │   │       └── scala/
│               │   │           ├── example/
│               │   │           │   └── Library.scala
│               │   │           └── uuid/
│               │   │               └── uuid.scala
│               │   └── test
│               ├── newer-linker/
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   ├── newer-scala-js.sbt
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── NewerLinkerTest.scala
│               │   └── test
│               ├── sbt-1.8/
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   ├── build.properties
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── BasicTest.scala
│               │   └── test
│               ├── sharedconfig/
│               │   ├── README.md
│               │   ├── build.sbt
│               │   ├── common.webpack.config.js
│               │   ├── dev.webpack.config.js
│               │   ├── index-prod.html
│               │   ├── index.html
│               │   ├── prod.webpack.config.js
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   ├── main/
│               │   │   │   └── scala/
│               │   │   │       ├── example/
│               │   │   │       │   └── Main.scala
│               │   │   │       └── leaflet/
│               │   │   │           └── modules/
│               │   │   │               └── modules.scala
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── SomeTest.scala
│               │   └── test
│               ├── static/
│               │   ├── README.md
│               │   ├── build.sbt
│               │   ├── index-prod.html
│               │   ├── index.html
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   ├── main/
│               │   │   │   └── scala/
│               │   │   │       ├── example/
│               │   │   │       │   └── Main.scala
│               │   │   │       └── snabbdom/
│               │   │   │           ├── modules/
│               │   │   │           │   └── modules.scala
│               │   │   │           └── snabbdom.scala
│               │   │   └── test/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── SomeTest.scala
│               │   └── test
│               ├── transitive/
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   └── test
│               ├── webpack-assets/
│               │   ├── README.md
│               │   ├── badconfig1.js
│               │   ├── badconfig2.js
│               │   ├── build.sbt
│               │   ├── dev.config.js
│               │   ├── prod.config.js
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   └── main/
│               │   │       ├── resources/
│               │   │       │   ├── entry.js
│               │   │       │   └── styles.css
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── Main.scala
│               │   └── test
│               ├── webpack-assets-cookbook/
│               │   ├── README.md
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   ├── ZipHelper.scala
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   ├── main/
│               │   │   │   └── scala/
│               │   │   │       └── example/
│               │   │   │           └── Main.scala
│               │   │   └── universal/
│               │   │       └── index.html
│               │   └── test
│               ├── webpack-dev-server/
│               │   ├── build.sbt
│               │   ├── project/
│               │   │   └── plugins.sbt
│               │   ├── src/
│               │   │   └── main/
│               │   │       └── scala/
│               │   │           └── example/
│               │   │               └── Main.scala
│               │   ├── test
│               │   └── webpack.config.js
│               └── yarn-interactive/
│                   ├── build.sbt
│                   ├── project/
│                   │   └── plugins.sbt
│                   ├── src/
│                   │   └── main/
│                   │       └── scala/
│                   │           └── example/
│                   │               └── Main.scala
│                   └── test
├── sbt-web-scalajs-bundler/
│   └── src/
│       ├── main/
│       │   └── scala/
│       │       └── scalajsbundler/
│       │           └── sbtplugin/
│       │               ├── NpmAssets.scala
│       │               └── WebScalaJSBundlerPlugin.scala
│       └── sbt-test/
│           └── sbt-web-scalajs-bundler/
│               └── play/
│                   ├── build.sbt
│                   ├── client/
│                   │   └── src/
│                   │       └── main/
│                   │           └── scala/
│                   │               ├── example/
│                   │               │   └── Main.scala
│                   │               └── snabbdom/
│                   │                   ├── modules/
│                   │                   │   └── modules.scala
│                   │                   └── snabbdom.scala
│                   ├── project/
│                   │   └── plugins.sbt
│                   ├── server/
│                   │   └── src/
│                   │       ├── main/
│                   │       │   ├── resources/
│                   │       │   │   ├── application.conf
│                   │       │   │   └── router.routes
│                   │       │   └── scala/
│                   │       │       └── example/
│                   │       │           ├── ExampleController.scala
│                   │       │           └── Loader.scala
│                   │       └── test/
│                   │           ├── resources/
│                   │           │   └── logback.xml
│                   │           └── scala/
│                   │               └── example/
│                   │                   └── ExampleSpec.scala
│                   └── test
└── scalajs-bundler-linker/
    └── src/
        └── main/
            └── scala/
                └── scalajsbundler/
                    └── bundlerlinker/
                        ├── BundlerLinkerImpl.scala
                        └── EntryPointAnalyzerBackend.scala
Condensed preview — 193 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (315K chars).
[
  {
    "path": ".drone.yml",
    "chars": 152,
    "preview": "build:\n  image: julienrf/docker-scala-sbt-git\n  commands:\n    - sbt clean test scripted\n\ncache:\n  mount:\n    - .git\n    "
  },
  {
    "path": ".github/dependabot.yml",
    "chars": 118,
    "preview": "version: 2\nupdates:\n  - package-ecosystem: \"github-actions\"\n    directory: \"/\"\n    schedule:\n      interval: \"weekly\"\n"
  },
  {
    "path": ".github/workflows/ci.yml",
    "chars": 717,
    "preview": "name: CI\non:\n  push:\n    branches:\n      - main\n  pull_request:\n    branches:\n      - main\njobs:\n  build:\n    strategy:\n"
  },
  {
    "path": ".github/workflows/ghpages.yml",
    "chars": 626,
    "preview": "\nname: Build and Deploy GhPages docs\n\non:\n  push:\n    branches:\n      - main\n\njobs:\n  build-and-deploy:\n    runs-on: ubu"
  },
  {
    "path": ".github/workflows/release.yml",
    "chars": 1008,
    "preview": "name: Release\non:\n  push:\n    branches: [main]\n    tags: [\"*\"]\njobs:\n  publish:\n    runs-on: ubuntu-latest\n    steps:\n  "
  },
  {
    "path": ".gitignore",
    "chars": 21,
    "preview": "target/\n.idea\nlocal.*"
  },
  {
    "path": "CONTRIBUTING.md",
    "chars": 2175,
    "preview": "Contributing\n===========\n\n## General recommendations\n\nTest and document each added feature.\n\n## Organization of the repo"
  },
  {
    "path": "LICENSE",
    "chars": 1593,
    "preview": "scalajs-bundler is licensed under the [BSD 3-Clause License](http://opensource.org/licenses/BSD-3-Clause).\n\nCopyright (c"
  },
  {
    "path": "README.md",
    "chars": 1074,
    "preview": "scalajs-bundler [![](https://index.scala-lang.org/scalacenter/scalajs-bundler/sbt-scalajs-bundler/latest.svg)](https://i"
  },
  {
    "path": "build.sbt",
    "chars": 4706,
    "preview": "val scalaJSVersion = sys.env.getOrElse(\"SCALAJS_VERSION\", \"1.3.0\")\n\nlazy val `scalajs-bundler-linker` =\n  project.in(fil"
  },
  {
    "path": "manual/src/ornate/changelog.md",
    "chars": 17451,
    "preview": "# Changelog\n\n## Version 0.20.0\n\n> 2020 October 22\n\nThis release upgrades to Scala.js 1.3.0.\n\n- Drop support for Scala.js"
  },
  {
    "path": "manual/src/ornate/community.md",
    "chars": 454,
    "preview": "# Community\n\n- [![Gitter](https://badges.gitter.im/scalacenter/scalajs-bundler.svg)](https://gitter.im/scalacenter/scala"
  },
  {
    "path": "manual/src/ornate/cookbook.md",
    "chars": 13005,
    "preview": "# Cookbook\n\n![](toctree:local=true,mergeFirst=true)\n\n## How to use a custom webpack configuration file? {#custom-config}"
  },
  {
    "path": "manual/src/ornate/getting-started.md",
    "chars": 3431,
    "preview": "# Getting started\n\n## Basic setup\n\nYou need to have `npm` installed on your system.\n\nAdd the `sbt-scalajs-bundler` plugi"
  },
  {
    "path": "manual/src/ornate/index.md",
    "chars": 1095,
    "preview": "# scalajs-bundler\n\nscalajs-bundler is a module bundler for Scala.js projects that use npm packages: it bundles the .js f"
  },
  {
    "path": "manual/src/ornate/motivation.md",
    "chars": 2337,
    "preview": "# Motivation\n\nThe most popular JavaScript package registry is npm. Scala.js projects are usually based on sbt,\nwhich has"
  },
  {
    "path": "manual/src/ornate/reference.md",
    "chars": 10786,
    "preview": "# Reference\n\n## `ScalaJSBundlerPlugin`\n\nThe `ScalaJSBundlerPlugin` sbt plugin automatically enables `ScalaJSPlugin` on t"
  },
  {
    "path": "manual/src/ornate.conf",
    "chars": 333,
    "preview": "global {\n  toc = [\n    { title = \"Introduction\", url = \"index.md\" }\n    motivation.md\n    getting-started.md\n    referen"
  },
  {
    "path": "project/build.properties",
    "chars": 20,
    "preview": "sbt.version = 1.8.2\n"
  },
  {
    "path": "project/plugins.sbt",
    "chars": 372,
    "preview": "addSbtPlugin(\"com.typesafe.sbt\"  % \"sbt-site\"       % \"1.4.1\")\naddSbtPlugin(\"com.novocode\"      % \"sbt-ornate\"     % \"0."
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/BundlerFile.scala",
    "chars": 7518,
    "preview": "package scalajsbundler\n\nimport java.io.File\nimport java.nio.file.Path\n\nimport scalajsbundler.Stats.WebpackStats\nimport s"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/BundlerFileType.scala",
    "chars": 851,
    "preview": "package scalajsbundler\n\n/**\n  * The type of a given [[BundlerFile.Public]]. Used for tagging files when they are produce"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/BundlingMode.scala",
    "chars": 3168,
    "preview": "package scalajsbundler\n\n/**\n  * The BundlingMode dictates how webpack is configured for bundling. Please refer\n  * to th"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/ExternalCommand.scala",
    "chars": 3541,
    "preview": "package scalajsbundler\n\nimport java.io.File\n\nimport sbt._\nimport scalajsbundler.util.Commands\n\n/**\n  * Attempts to smoot"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/JSDOMNodeJSEnv.scala",
    "chars": 8793,
    "preview": "package scalajsbundler\n\nimport scala.util.control.NonFatal\n\nimport sbt._\n\nimport java.io._\nimport java.nio.charset.Stand"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/JsDomTestEntries.scala",
    "chars": 881,
    "preview": "package scalajsbundler\n\nimport sbt._\n\nimport scalajsbundler.util.JS\n\nobject JsDomTestEntries {\n\n  /**\n    * Loads the ou"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/NpmDependencies.scala",
    "chars": 3227,
    "preview": "package scalajsbundler\n\nimport java.io.{BufferedInputStream, FileInputStream}\nimport java.util.zip.ZipInputStream\n\nimpor"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/NpmPackage.scala",
    "chars": 705,
    "preview": "package scalajsbundler\n\nimport play.api.libs.json.{JsPath, Json, Reads}\nimport sbt._\n\nimport scala.util.Try\n\ncase class "
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/PackageJson.scala",
    "chars": 4567,
    "preview": "package scalajsbundler\n\nimport sbt._\n\nimport scalajsbundler.util.JSON\n\nobject PackageJson {\n\n  /**\n    * Write a package"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/Stats.scala",
    "chars": 4545,
    "preview": "\npackage scalajsbundler\n\nimport play.api.libs.json._\nimport play.api.libs.functional.syntax._\nimport sbt.Logger\nimport s"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/Webpack.scala",
    "chars": 10763,
    "preview": "package scalajsbundler\n\nimport sbt._\nimport scalajsbundler.util.{Commands, JS}\nimport java.io.InputStream\n\nimport play.a"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/WebpackDevServer.scala",
    "chars": 1526,
    "preview": "package scalajsbundler\n\nimport sbt._\nimport java.io.File\n\n/**\n  * Simple wrapper over webpack-dev-server\n  */\nprivate [s"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/WebpackEntryPoint.scala",
    "chars": 909,
    "preview": "package scalajsbundler\n\nimport sbt.{IO, Logger}\n\nimport scalajsbundler.util.JS\n\nobject WebpackEntryPoint {\n\n  /**\n    * "
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/LibraryTasks.scala",
    "chars": 5497,
    "preview": "package scalajsbundler.sbtplugin\n\nimport sbt.Keys._\nimport sbt.{Def, _}\n\nimport org.scalajs.sbtplugin.ScalaJSPlugin.auto"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/NpmUpdateTasks.scala",
    "chars": 3877,
    "preview": "package scalajsbundler.sbtplugin\n\nimport java.nio.file.Path\nimport scalajsbundler.ExternalCommand\nimport sbt._\n\nobject N"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/PackageJsonTasks.scala",
    "chars": 2189,
    "preview": "package scalajsbundler.sbtplugin\n\nimport sbt._\n\nimport scalajsbundler.{BundlerFile, PackageJson}\nimport scalajsbundler.u"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/SBTBundlerFile.scala",
    "chars": 1193,
    "preview": "package scalajsbundler.sbtplugin\n\nimport sbt.{AttributeKey, Attributed}\n\nimport scalajsbundler.{BundlerFile, BundlerFile"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/ScalaJSBundlerPlugin.scala",
    "chars": 28730,
    "preview": "package scalajsbundler.sbtplugin\n\nimport org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._\nimport org.scalajs.sbtplugin.{"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/Settings.scala",
    "chars": 9421,
    "preview": "package scalajsbundler.sbtplugin\n\nimport java.nio.charset.StandardCharsets\nimport java.nio.file.{Files, Path}\nimport sca"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/WebpackTasks.scala",
    "chars": 2296,
    "preview": "package scalajsbundler.sbtplugin\nimport sbt.Keys._\nimport sbt.{Def, _}\n\nimport org.scalajs.sbtplugin.ScalaJSPlugin.autoI"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/util/CachedBundleFiles.scala",
    "chars": 357,
    "preview": "package scalajsbundler.util\n\nimport java.io.File\nimport scala.collection.immutable.ListSet\n\nobject CachedBundleFiles {\n "
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/util/Caching.scala",
    "chars": 307,
    "preview": "package scalajsbundler.util\n\nimport sbt._\n\nobject Caching {\n\n  def cached(\n    fileToWrite: File,\n    hash: String,\n    "
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/util/Commands.scala",
    "chars": 1544,
    "preview": "package scalajsbundler.util\n\nimport sbt.Logger\nimport java.io.{InputStream, File}\nimport scala.sys.process.Process\nimpor"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/util/JS.scala",
    "chars": 3923,
    "preview": "package scalajsbundler.util\n\nimport java.util.concurrent.atomic.AtomicInteger\n\nimport JSTrees._\n\nprivate[util] sealed ab"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/util/JSBundler.scala",
    "chars": 3869,
    "preview": "package scalajsbundler.util\n\nimport sbt._\n\nimport scalajsbundler.BundlerFile\n\nobject JSBundler {\n\n  def loaderScript(bun"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/util/JSPrinters.scala",
    "chars": 18684,
    "preview": "package scalajsbundler.util\n\nimport scala.annotation.switch\n\n// Unimport default print and println to avoid invoking the"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/util/JSTrees.scala",
    "chars": 11962,
    "preview": "package scalajsbundler.util\n\n// This is copied from `org.scalajs.linker.backend.javascript.Trees` in Scala.js.\nprivate[u"
  },
  {
    "path": "sbt-scalajs-bundler/src/main/scala/scalajsbundler/util/ScalaJSNativeLibraries.scala",
    "chars": 3336,
    "preview": "package scalajsbundler.util\n\nimport com.google.common.jimfs.Jimfs\n\nimport java.io.{BufferedInputStream, ByteArrayOutputS"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/additonalNpmConfig/build.sbt",
    "chars": 1524,
    "preview": "import scalajsbundler.util.JSON._\n\nval checkPackageJson = taskKey[Unit](\"Check that the package.json file does not conta"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/additonalNpmConfig/project/plugins.sbt",
    "chars": 452,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/additonalNpmConfig/test",
    "chars": 51,
    "preview": "> npmConfig/npmUpdate\n> npmConfig/checkPackageJson\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/browserless/README.md",
    "chars": 247,
    "preview": "scalajs-bundler/browserless\n==========================\n\nAn application that uses npm packages and\nthat does not target W"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/browserless/build.sbt",
    "chars": 293,
    "preview": "name := \"browserless\"\n\nenablePlugins(ScalaJSBundlerPlugin, ScalaJSJUnitPlugin)\n\nscalaVersion := \"2.13.2\"\n\nscalaJSUseMain"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/browserless/project/plugins.sbt",
    "chars": 452,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/browserless/src/main/scala/example/Foo.scala",
    "chars": 84,
    "preview": "package example\n\nimport uuid.uuid\n\nobject Foo {\n\n  def bar(): String = uuid.v4()\n\n}\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/browserless/src/main/scala/example/Main.scala",
    "chars": 103,
    "preview": "package example\n\nobject Main {\n\n  def main(args: Array[String]): Unit = {\n    println(Foo.bar())\n  }\n\n}"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/browserless/src/main/scala/uuid/uuid.scala",
    "chars": 1290,
    "preview": "package uuid\n\nimport scala.annotation.meta.field\nimport scala.scalajs.js\nimport scala.scalajs.js.annotation.JSImport.Nam"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/browserless/src/test/scala/example/FooTest.scala",
    "chars": 147,
    "preview": "package example\n\nimport org.junit.Assert._\nimport org.junit.Test\n\nclass FooTest {\n\n  @Test def bar(): Unit = {\n    asser"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/browserless/test",
    "chars": 189,
    "preview": "> run\n> test\n\n# Deactivated because `clean` followed by `run` kills the AppVeyor build.\n# Testing yarn support is done e"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/custom-test-config/README.md",
    "chars": 274,
    "preview": "# scalajs-bundler/custom-test-config\n\nAn application that uses webpack 4 and requires a custom test configuration\n\nDemon"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/custom-test-config/build.sbt",
    "chars": 920,
    "preview": "name := \"custom-test\"\n\nval reactJS = \"16.13.1\"\nval scalaJsReact = \"1.7.0\"\n\nenablePlugins(ScalaJSBundlerPlugin)\n\nscalaVer"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/custom-test-config/project/plugins.sbt",
    "chars": 452,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/custom-test-config/src/main/scala/example/Component.scala",
    "chars": 299,
    "preview": "package example\n\nimport japgolly.scalajs.react._\nimport japgolly.scalajs.react.vdom.html_<^._\n\nobject Component {\n\n  pri"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/custom-test-config/src/test/scala/example/SomeTest.scala",
    "chars": 360,
    "preview": "package example\n\nimport utest._\nimport japgolly.scalajs.react.test._\n\nimport scala.scalajs.js\n\nobject RenderTest extends"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/custom-test-config/test",
    "chars": 15,
    "preview": "> clean\n> test\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/custom-test-config/test.webpack.config.js",
    "chars": 206,
    "preview": "const Webpack = require(\"webpack\");\n\nconst Test = {\n  plugins: [\n    new Webpack.DefinePlugin({\n      \"process.env\": {\n "
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/facade/build.sbt",
    "chars": 612,
    "preview": "val `facade-project` =\n  project.in(file(\".\"))\n    .aggregate(usage)\n\nlazy val usage =\n  project.in(file(\"usage\"))\n    ."
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/facade/facade/src/main/scala/uuid/uuid.scala",
    "chars": 1290,
    "preview": "package uuid\n\nimport scala.annotation.meta.field\nimport scala.scalajs.js\nimport scala.scalajs.js.annotation.JSImport.Nam"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/facade/project/plugins.sbt",
    "chars": 452,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/facade/test",
    "chars": 39,
    "preview": "> usage/run\n> usage/clean\n> usage/test\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/facade/usage/src/main/scala/example/Foo.scala",
    "chars": 84,
    "preview": "package example\n\nimport uuid.uuid\n\nobject Foo {\n\n  def bar(): String = uuid.v4()\n\n}\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/facade/usage/src/main/scala/example/Main.scala",
    "chars": 103,
    "preview": "package example\n\nobject Main {\n\n  def main(args: Array[String]): Unit = {\n    println(Foo.bar())\n  }\n\n}"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/facade/usage/src/test/scala/example/FooTest.scala",
    "chars": 147,
    "preview": "package example\n\nimport org.junit.Assert._\nimport org.junit.Test\n\nclass FooTest {\n\n  @Test def bar(): Unit = {\n    asser"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/facade-examples/build.sbt",
    "chars": 253,
    "preview": "name := \"facade-examples\"\n\nenablePlugins(ScalaJSBundlerPlugin, ScalaJSJUnitPlugin)\n\nscalaVersion := \"2.11.12\"\n\nscalaJSUs"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/facade-examples/project/plugins.sbt",
    "chars": 452,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/facade-examples/src/main/resources/class.js",
    "chars": 80,
    "preview": "module.exports = function (name, age) {\n  this.name = name;\n  this.age = age;\n};"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/facade-examples/src/main/resources/foo.js",
    "chars": 44,
    "preview": "exports.bar = function (i) { return i + 1 };"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/facade-examples/src/main/resources/function.js",
    "chars": 95,
    "preview": "module.exports = (first, second) => `Konrad says ${first} plus ${second} is ${first + second}`;"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/facade-examples/src/main/scala/example/Main.scala",
    "chars": 215,
    "preview": "package example\n\nobject Main {\n\n  def main(args: Array[String]): Unit = {\n    println(Obj.bar(42))\n    println(Member(42"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/facade-examples/src/main/scala/example/facades.scala",
    "chars": 874,
    "preview": "package example\n\nimport scala.scalajs.js\nimport scala.scalajs.js.annotation.JSImport\n\n// Note: the corresponding JS modu"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/facade-examples/src/test/scala/example/FacadesTest.scala",
    "chars": 474,
    "preview": "package example\n\nimport org.junit.Assert._\nimport org.junit.Test\n\nclass FacadesTest {\n\n  @Test def testObj(): Unit = {\n "
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/facade-examples/test",
    "chars": 20,
    "preview": "> run\n> clean\n> test"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/generated-sources/build.sbt",
    "chars": 177,
    "preview": "enablePlugins(ScalaJSBundlerPlugin)\n\nscalaVersion := \"2.12.8\"\n\nsourceGenerators in Compile += Def.task {\n  val _ = (npmI"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/generated-sources/project/plugins.sbt",
    "chars": 399,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/generated-sources/test",
    "chars": 127,
    "preview": "# Tests that it is possible to use npm dev dependencies to generate sources\n# without creating a cycle in the tasks.\n> s"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/global-namespace-with-jsdom-unit-testing/build.sbt",
    "chars": 772,
    "preview": "\nname := \"global-namespace-with-jsdom-unit-testing\"\n\nenablePlugins(ScalaJSBundlerPlugin, ScalaJSJUnitPlugin)\n\nscalaVersi"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/global-namespace-with-jsdom-unit-testing/common.webpack.config.js",
    "chars": 775,
    "preview": "var globalModules = {\n  moment: \"moment\"\n};\n\nconst importRule = {\n  // Force require global modules\n  test: /.*-(fast|fu"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/global-namespace-with-jsdom-unit-testing/dev.webpack.config.js",
    "chars": 213,
    "preview": "var { merge } = require('webpack-merge');\n\nvar commonConfig = require('./common.webpack.config');\nvar generatedConfig = "
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/global-namespace-with-jsdom-unit-testing/project/plugins.sbt",
    "chars": 452,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/global-namespace-with-jsdom-unit-testing/src/main/scala/example/Main.scala",
    "chars": 533,
    "preview": "package example\n\nimport scala.scalajs.js\nimport scala.scalajs.js.annotation._\n\n// Emulate a Scala.js facade library that"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/global-namespace-with-jsdom-unit-testing/src/test/scala/example/MainTest.scala",
    "chars": 374,
    "preview": "package example\n\nimport org.junit.Assert._\nimport org.junit.Test\n\nimport scala.scalajs.js\nimport scala.scalajs.js.Date\n\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/global-namespace-with-jsdom-unit-testing/test",
    "chars": 28,
    "preview": "> fastOptJS::webpack\n> test\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/global-namespace-with-jsdom-unit-testing/test.webpack.config.js",
    "chars": 141,
    "preview": "var { merge } = require('webpack-merge');\n\nvar commonConfig = require('./common.webpack.config');\n\nmodule.exports = merg"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/js-resources/build.sbt",
    "chars": 250,
    "preview": "name := \"js-resources\"\n\nenablePlugins(ScalaJSBundlerPlugin, ScalaJSJUnitPlugin)\n\nscalaVersion := \"2.11.12\"\n\nscalaJSUseMa"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/js-resources/project/plugins.sbt",
    "chars": 452,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/js-resources/src/main/resources/my-module.js",
    "chars": 73,
    "preview": "var uuid = require('uuid');\n\nmodule.exports = {\n  someUuid: uuid.v4()\n};\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/js-resources/src/main/scala/example/Main.scala",
    "chars": 111,
    "preview": "package example\n\nobject Main {\n\n  def main(args: Array[String]): Unit = {\n    println(MyModule.someUuid)\n  }\n\n}"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/js-resources/src/main/scala/example/MyModule.scala",
    "chars": 215,
    "preview": "package example\n\nimport scala.scalajs.js\nimport scala.scalajs.js.annotation.JSImport\n\n@JSImport(\"./my-module\", JSImport."
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/js-resources/src/test/scala/example/MyModuleTest.scala",
    "chars": 165,
    "preview": "package example\n\nimport org.junit.Assert._\nimport org.junit.Test\n\nclass MyModuleTest {\n\n  @Test def someUuid(): Unit = {"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/js-resources/test",
    "chars": 21,
    "preview": "> run\n> clean\n> test\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/js-source-directory/build.sbt",
    "chars": 250,
    "preview": "name := \"js-resources\"\n\nenablePlugins(ScalaJSBundlerPlugin, ScalaJSJUnitPlugin)\n\nscalaVersion := \"2.11.12\"\n\nscalaJSUseMa"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/js-source-directory/project/plugins.sbt",
    "chars": 452,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/js-source-directory/src/main/js/config.json",
    "chars": 16,
    "preview": "{\n  \"value\": 1\n}"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/js-source-directory/src/main/js/my-module.js",
    "chars": 302,
    "preview": "var uuid = require('uuid');\nvar config = require('./config.json');\nvar nestedConfig = require('./nested/config2.json');\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/js-source-directory/src/main/js/nested/config2.json",
    "chars": 16,
    "preview": "{\n  \"value\": 2\n}"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/js-source-directory/src/main/scala/example/Main.scala",
    "chars": 111,
    "preview": "package example\n\nobject Main {\n\n  def main(args: Array[String]): Unit = {\n    println(MyModule.someUuid)\n  }\n\n}"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/js-source-directory/src/main/scala/example/MyModule.scala",
    "chars": 301,
    "preview": "package example\n\nimport scala.scalajs.js\nimport scala.scalajs.js.annotation.JSImport\n\n@JSImport(\"./my-module\", JSImport."
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/js-source-directory/src/test/scala/example/MyModuleTest.scala",
    "chars": 335,
    "preview": "package example\n\nimport org.junit.Assert._\nimport org.junit.Test\n\nclass MyModuleTest {\n\n  @Test def someUuid(): Unit = {"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/js-source-directory/test",
    "chars": 21,
    "preview": "> run\n> clean\n> test\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/library/build.sbt",
    "chars": 807,
    "preview": "name := \"library\"\n\nenablePlugins(ScalaJSBundlerPlugin)\n\nscalaVersion := \"2.11.12\"\n\nnpmDependencies in Compile += \"uuid\" "
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/library/index.html",
    "chars": 350,
    "preview": "<!DOCTYPE html>\n<html>\n  <head>\n    <title>Example</title>\n  </head>\n  <body>\n    <script src=\"target/scala-2.11/scalajs"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/library/project/plugins.sbt",
    "chars": 527,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/library/src/main/scala/example/Library.scala",
    "chars": 414,
    "preview": "//#library-definition\npackage example\n\nimport scala.scalajs.js.annotation.{JSExportTopLevel, JSExportAll}\n\n@JSExportTopL"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/library/src/main/scala/uuid/uuid.scala",
    "chars": 1290,
    "preview": "package uuid\n\nimport scala.annotation.meta.field\nimport scala.scalajs.js\nimport scala.scalajs.js.annotation.JSImport.Nam"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/library/test",
    "chars": 39,
    "preview": "> fullOptJS::webpack\n> html index.html\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/newer-linker/build.sbt",
    "chars": 294,
    "preview": "name := \"newer-linker\"\n\nenablePlugins(ScalaJSBundlerPlugin, ScalaJSJUnitPlugin)\n\nscalaVersion := \"2.13.1\"\n\nscalaJSUseMai"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/newer-linker/project/newer-scala-js.sbt",
    "chars": 111,
    "preview": "// TODO Set this to a version > 1.3.0 when there is one\naddSbtPlugin(\"org.scala-js\" % \"sbt-scalajs\" % \"1.3.0\")\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/newer-linker/project/plugins.sbt",
    "chars": 452,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/newer-linker/src/test/scala/example/NewerLinkerTest.scala",
    "chars": 577,
    "preview": "package example\n\nimport org.junit.Assert._\nimport org.junit.Test\n\nclass NewerLinkerTest {\n\n  @Test def newerLinker(): Un"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/newer-linker/test",
    "chars": 7,
    "preview": "> test\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sbt-1.8/build.sbt",
    "chars": 294,
    "preview": "name := \"newer-linker\"\n\nenablePlugins(ScalaJSBundlerPlugin, ScalaJSJUnitPlugin)\n\nscalaVersion := \"2.13.1\"\n\nscalaJSUseMai"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sbt-1.8/project/build.properties",
    "chars": 18,
    "preview": "sbt.version=1.8.2\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sbt-1.8/project/plugins.sbt",
    "chars": 452,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sbt-1.8/src/test/scala/example/BasicTest.scala",
    "chars": 166,
    "preview": "package example\n\nimport org.junit.Assert._\nimport org.junit.Test\n\nclass BasicTest {\n\n  @Test def newerLinker(): Unit = {"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sbt-1.8/test",
    "chars": 7,
    "preview": "> test\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sharedconfig/README.md",
    "chars": 319,
    "preview": "scalajs-bundler/sharedconfig\n=====================\n\nAn application that uses npm packages and that produces\na static HTM"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sharedconfig/build.sbt",
    "chars": 2054,
    "preview": "\nname := \"sharedconfig\"\n\nenablePlugins(ScalaJSBundlerPlugin, ScalaJSJUnitPlugin)\n\nscalaVersion := \"2.11.12\"\n\nscalaJSUseM"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sharedconfig/common.webpack.config.js",
    "chars": 998,
    "preview": "module.exports = {\n  module: {\n    rules: [\n      {\n        test: /\\.(jpe?g|png|gif|svg)$/i,\n        use: [\n          {\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sharedconfig/dev.webpack.config.js",
    "chars": 211,
    "preview": "var merge = require(\"webpack-merge\");\n\nvar generatedConfig = require('./scalajs.webpack.config');\nvar commonConfig = req"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sharedconfig/index-prod.html",
    "chars": 314,
    "preview": "<!DOCTYPE html>\n<html>\n  <head>\n    <title>Example</title>\n    <style>\n      #container {\n        width: 12cm;\n        h"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sharedconfig/index.html",
    "chars": 318,
    "preview": "<!DOCTYPE html>\n<html>\n  <head>\n    <title>Example</title>\n    <style>\n      #container {\n        width: 12cm;\n        h"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sharedconfig/prod.webpack.config.js",
    "chars": 211,
    "preview": "var merge = require(\"webpack-merge\");\n\nvar generatedConfig = require(\"./scalajs.webpack.config\");\nvar commonConfig = req"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sharedconfig/project/plugins.sbt",
    "chars": 527,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sharedconfig/src/main/scala/example/Main.scala",
    "chars": 345,
    "preview": "package example\n\nimport scala.scalajs.js\nimport leaflet.modules._\n\nobject Main {\n  def main(args: Array[String]): Unit ="
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sharedconfig/src/main/scala/leaflet/modules/modules.scala",
    "chars": 763,
    "preview": "package leaflet\npackage modules\n\nimport scala.scalajs.js\nimport scala.scalajs.js.annotation.JSImport\nimport scala.scalaj"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sharedconfig/src/test/scala/example/SomeTest.scala",
    "chars": 430,
    "preview": "package example\n\nimport org.junit.Assert._\nimport org.junit.Test\n\nimport org.scalajs.dom.document\n\nimport scala.scalajs."
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sharedconfig/test",
    "chars": 629,
    "preview": "$ absent target/scala-2.11/scalajs-bundler/main/sharedconfig-fastopt-bundle.js target/scala-2.11/scalajs-bundler/main/sh"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/static/README.md",
    "chars": 170,
    "preview": "scalajs-bundler/static\n=====================\n\nAn application that uses npm packages and that produces\na static HTML page"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/static/build.sbt",
    "chars": 1597,
    "preview": "name := \"static\"\n\nenablePlugins(ScalaJSBundlerPlugin, ScalaJSJUnitPlugin)\n\nscalaVersion := \"2.11.12\"\n\nscalaJSUseMainModu"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/static/index-prod.html",
    "chars": 214,
    "preview": "<!DOCTYPE html>\n<html>\n  <head>\n    <title>Example</title>\n  </head>\n  <body>\n    <div id=\"container\"></div>\n    <script"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/static/index.html",
    "chars": 218,
    "preview": "<!DOCTYPE html>\n<html>\n  <head>\n    <title>Example</title>\n  </head>\n  <body>\n    <div id=\"container\"></div>\n    <script"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/static/project/plugins.sbt",
    "chars": 527,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/static/src/main/scala/example/Main.scala",
    "chars": 1739,
    "preview": "package example\n\nimport scala.scalajs.js\nimport scala.scalajs.js.Dynamic.literal\n\nimport snabbdom.{snabbdom, h, modules}"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/static/src/main/scala/snabbdom/modules/modules.scala",
    "chars": 535,
    "preview": "package snabbdom\npackage modules\n\nimport scala.scalajs.js\nimport scala.scalajs.js.annotation.JSImport\nimport scala.scala"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/static/src/main/scala/snabbdom/snabbdom.scala",
    "chars": 1039,
    "preview": "package snabbdom\n\nimport org.scalajs.dom.{Element, Text}\n\nimport scala.scalajs.js\nimport scala.scalajs.js.annotation.JSI"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/static/src/test/scala/example/SomeTest.scala",
    "chars": 618,
    "preview": "package example\n\nimport org.junit.Assert._\nimport org.junit.Test\n\nimport org.scalajs.dom.document\n\nimport scala.scalajs."
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/static/test",
    "chars": 1739,
    "preview": "$ absent target/scala-2.11/scalajs-bundler/main/static-fastopt-bundle.js target/scala-2.11/scalajs-bundler/main/static-f"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/transitive/build.sbt",
    "chars": 1321,
    "preview": "val sub1 =\n  proj(\"sub1\")\n    .settings(\n      npmDependencies in Compile += \"react\" -> \"15.4.1\"\n    )\n\nval sub2 =\n  pro"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/transitive/project/plugins.sbt",
    "chars": 452,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/transitive/test",
    "chars": 140,
    "preview": "> no-conflicts/npmUpdate\n> no-conflicts/checkPackageJson\n-> conflict/npmUpdate\n> resolution/npmUpdate\n> delegatedToPacka"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets/README.md",
    "chars": 261,
    "preview": "# scalajs-bundler/webpack-assets\n\nAn application that uses an advanced webpack configuration\n\nDemonstrates how to:\n\n* se"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets/badconfig1.js",
    "chars": 417,
    "preview": "const ScalaJS = require(\"./scalajs.webpack.config\");\nconst { merge } = require(\"webpack-merge\");\nconst HtmlWebpackPlugin"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets/badconfig2.js",
    "chars": 613,
    "preview": "const ScalaJS = require(\"./scalajs.webpack.config\");\nconst { merge } = require(\"webpack-merge\");\nconst HtmlWebpackPlugin"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets/build.sbt",
    "chars": 3626,
    "preview": "import com.gargoylesoftware.htmlunit.WebClient\nimport com.gargoylesoftware.htmlunit.WebConsole.Logger\n\nname := \"webpack-"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets/dev.config.js",
    "chars": 299,
    "preview": "const ScalaJS = require(\"./scalajs.webpack.config\");\nconst { merge } = require(\"webpack-merge\");\nconst HtmlWebpackPlugin"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets/prod.config.js",
    "chars": 800,
    "preview": "const ScalaJS = require(\"./scalajs.webpack.config\");\nconst { merge } = require(\"webpack-merge\");\nconst HtmlWebpackPlugin"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets/project/plugins.sbt",
    "chars": 527,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets/src/main/resources/entry.js",
    "chars": 23,
    "preview": "import \"./styles.css\";\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets/src/main/resources/styles.css",
    "chars": 23,
    "preview": "body {\n  color: red;\n}\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets/src/main/scala/example/Main.scala",
    "chars": 131,
    "preview": "package example\n\nobject Main {\n  def main(args: Array[String]): Unit = {\n    println(\"6051a036-bfb4-4158-a171-950416b5bd"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets/test",
    "chars": 442,
    "preview": "# the server should properly start\n> fastOptJS::webpack\n# 1 assets and 3 for library, loader and app\n> html index.html 4"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets-cookbook/README.md",
    "chars": 348,
    "preview": "scalajs-bundler/webpack-assets-cookbook\n=====================\n\nAn application to demonstrate how to package up the relev"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets-cookbook/build.sbt",
    "chars": 2184,
    "preview": "import java.util.zip.ZipFile\n\nimport com.typesafe.sbt.packager.SettingsHelper._\n\nname := \"webpack-assets\"\n\nscalaVersion "
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets-cookbook/project/ZipHelper.scala",
    "chars": 249,
    "preview": "import java.io.File\nimport java.util.zip.ZipFile\n\nimport scala.collection.JavaConverters._\n\nclass ZipHelper(f: File) {\n\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets-cookbook/project/plugins.sbt",
    "chars": 520,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets-cookbook/src/main/scala/example/Main.scala",
    "chars": 352,
    "preview": "package example\n\nimport com.github.ahnfelt.react4s._\n\ncase class HelloComponent() extends Component[NoEmit] {\n\n  overrid"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets-cookbook/src/universal/index.html",
    "chars": 568,
    "preview": "<!DOCTYPE html>\n<!--suppress ALL -->\n<html>\n<head>\n  <meta charset=\"UTF-8\">\n  <title>WebAsset Demo </title>\n</head>\n<bod"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets-cookbook/test",
    "chars": 45,
    "preview": "> clean\n> universal:packageBin\n> checkArchive"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-dev-server/build.sbt",
    "chars": 2398,
    "preview": "import com.gargoylesoftware.htmlunit.WebClient\nimport com.gargoylesoftware.htmlunit.WebConsole.Logger\n\nname := \"webpack-"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-dev-server/project/plugins.sbt",
    "chars": 527,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-dev-server/src/main/scala/example/Main.scala",
    "chars": 131,
    "preview": "package example\n\nobject Main {\n  def main(args: Array[String]): Unit = {\n    println(\"6051a036-bfb4-4158-a171-950416b5bd"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-dev-server/test",
    "chars": 527,
    "preview": "# keep at least this test while the rest is disabled\n> fastOptJS::webpack\n\n# disabled because Webpack/webpack-cli/htmlun"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-dev-server/webpack.config.js",
    "chars": 238,
    "preview": "// Load the config generated by scalajs-bundler\nvar config = require('./scalajs.webpack.config');\n\nvar HtmlWebpackPlugin"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/yarn-interactive/build.sbt",
    "chars": 267,
    "preview": "scalaVersion := \"2.12.8\"\n\nuseYarn := true\n\nyarnExtraArgs in Compile := Seq(\"--silent\")\n\nscalaJSUseMainModuleInitializer "
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/yarn-interactive/project/plugins.sbt",
    "chars": 452,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/yarn-interactive/src/main/scala/example/Main.scala",
    "chars": 116,
    "preview": "package example\n\nobject Main {\n  def main(args: Array[String]): Unit = {\n    println(\"yarn-interactive main\")\n  }\n}\n"
  },
  {
    "path": "sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/yarn-interactive/test",
    "chars": 21,
    "preview": "> fastOptJS::webpack\n"
  },
  {
    "path": "sbt-web-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/NpmAssets.scala",
    "chars": 947,
    "preview": "package scalajsbundler.sbtplugin\n\nimport com.typesafe.sbt.web.PathMapping\nimport sbt._\n\nimport scalajsbundler.sbtplugin."
  },
  {
    "path": "sbt-web-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/WebScalaJSBundlerPlugin.scala",
    "chars": 4205,
    "preview": "package scalajsbundler.sbtplugin\n\nimport com.typesafe.sbt.web.PathMapping\nimport com.typesafe.sbt.web.pipeline.Pipeline\n"
  },
  {
    "path": "sbt-web-scalajs-bundler/src/sbt-test/sbt-web-scalajs-bundler/play/build.sbt",
    "chars": 1471,
    "preview": "val client =\n  project.in(file(\"client\"))\n    .enablePlugins(ScalaJSBundlerPlugin)\n    .settings(\n      // Required to s"
  },
  {
    "path": "sbt-web-scalajs-bundler/src/sbt-test/sbt-web-scalajs-bundler/play/client/src/main/scala/example/Main.scala",
    "chars": 365,
    "preview": "package example\n\nimport snabbdom.{snabbdom, modules, h}\n\nimport scala.scalajs.js\n\nimport org.scalajs.dom.document\n\nobjec"
  },
  {
    "path": "sbt-web-scalajs-bundler/src/sbt-test/sbt-web-scalajs-bundler/play/client/src/main/scala/snabbdom/modules/modules.scala",
    "chars": 527,
    "preview": "package snabbdom.modules\n\nimport scala.scalajs.js\nimport scala.scalajs.js.annotation.JSImport\nimport scala.scalajs.js.an"
  },
  {
    "path": "sbt-web-scalajs-bundler/src/sbt-test/sbt-web-scalajs-bundler/play/client/src/main/scala/snabbdom/snabbdom.scala",
    "chars": 1037,
    "preview": "package snabbdom\n\nimport org.scalajs.dom.{Element, Text}\n\nimport scala.scalajs.js\nimport scala.scalajs.js.annotation.JSI"
  },
  {
    "path": "sbt-web-scalajs-bundler/src/sbt-test/sbt-web-scalajs-bundler/play/project/plugins.sbt",
    "chars": 632,
    "preview": "val scalaJSVersion = sys.props.getOrElse(\"scalajs.version\", sys.error(\"'scalajs.version' environment variable is not def"
  },
  {
    "path": "sbt-web-scalajs-bundler/src/sbt-test/sbt-web-scalajs-bundler/play/server/src/main/resources/application.conf",
    "chars": 75,
    "preview": "play {\n  crypto.secret = \"abc123\"\n  application.loader = \"example.Loader\"\n}"
  },
  {
    "path": "sbt-web-scalajs-bundler/src/sbt-test/sbt-web-scalajs-bundler/play/server/src/main/resources/router.routes",
    "chars": 162,
    "preview": "GET     /                           example.ExampleController.index\nGET     /assets/*file               controllers.Asse"
  },
  {
    "path": "sbt-web-scalajs-bundler/src/sbt-test/sbt-web-scalajs-bundler/play/server/src/main/scala/example/ExampleController.scala",
    "chars": 608,
    "preview": "package example\n\nimport play.api.mvc.{AbstractController, ControllerComponents}\nimport play.twirl.api.StringInterpolatio"
  },
  {
    "path": "sbt-web-scalajs-bundler/src/sbt-test/sbt-web-scalajs-bundler/play/server/src/main/scala/example/Loader.scala",
    "chars": 625,
    "preview": "package example\n\nimport play.api.ApplicationLoader.Context\nimport play.api.{Application, ApplicationLoader, BuiltInCompo"
  },
  {
    "path": "sbt-web-scalajs-bundler/src/sbt-test/sbt-web-scalajs-bundler/play/server/src/test/resources/logback.xml",
    "chars": 501,
    "preview": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<configuration debug=\"false\">\n    <appender name=\"CONSOLE\" class=\"ch.qos.logback."
  },
  {
    "path": "sbt-web-scalajs-bundler/src/sbt-test/sbt-web-scalajs-bundler/play/server/src/test/scala/example/ExampleSpec.scala",
    "chars": 650,
    "preview": "package example\n\nimport org.scalatestplus.play.guice.GuiceOneServerPerSuite\nimport org.scalatestplus.play.{HtmlUnitFacto"
  },
  {
    "path": "sbt-web-scalajs-bundler/src/sbt-test/sbt-web-scalajs-bundler/play/test",
    "chars": 636,
    "preview": "> server/assets\n$ exists client/target/scala-2.13/scalajs-bundler/main/client-fastopt-bundle.js\n$ absent client/target/s"
  },
  {
    "path": "scalajs-bundler-linker/src/main/scala/scalajsbundler/bundlerlinker/BundlerLinkerImpl.scala",
    "chars": 625,
    "preview": "package scalajsbundler.bundlerlinker\n\nimport java.nio.file.Path\n\nimport org.scalajs.linker._\nimport org.scalajs.linker.i"
  },
  {
    "path": "scalajs-bundler-linker/src/main/scala/scalajsbundler/bundlerlinker/EntryPointAnalyzerBackend.scala",
    "chars": 1030,
    "preview": "package scalajsbundler.bundlerlinker\n\nimport scala.concurrent.{ExecutionContext, Future}\nimport scala.collection.JavaCon"
  }
]

About this extraction

This page contains the full source code of the scalacenter/scalajs-bundler GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 193 files (276.1 KB), approximately 80.3k tokens. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!