diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 601b64e7..bea34578 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,8 @@ jobs: node-version: 16.14.2 - name: Setup yarn run: npm install -g yarn@1.22.15 + - name: Setup pnpm + run: npm install -g pnpm@7.0.1 - name: Unit tests run: sbt test - name: Scripted tests diff --git a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/ExternalCommand.scala b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/ExternalCommand.scala deleted file mode 100644 index 885483c6..00000000 --- a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/ExternalCommand.scala +++ /dev/null @@ -1,126 +0,0 @@ -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) - } - } -} diff --git a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/PackageJson.scala b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/PackageJson.scala index d8b34ab9..4f9fa07f 100644 --- a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/PackageJson.scala +++ b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/PackageJson.scala @@ -31,7 +31,8 @@ object PackageJson { currentConfiguration: Configuration, webpackVersion: String, webpackDevServerVersion: String, - webpackCliVersion: String + webpackCliVersion: String, + packageManager: PackageManager ): Unit = { val npmManifestDependencies = NpmDependencies.collectFromClasspath(fullClasspath) val dependencies = @@ -62,7 +63,7 @@ object PackageJson { val packageJson = JSON.obj( ( - additionalNpmConfig.toSeq :+ + (additionalNpmConfig.toSeq ++ packageManager.packageJsonContents.toSeq) :+ "dependencies" -> JSON.objStr(resolveDependencies(dependencies, npmResolutions, log)) :+ "devDependencies" -> JSON.objStr(resolveDependencies(devDependencies, npmResolutions, log)) ): _* diff --git a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/PackageManager.scala b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/PackageManager.scala new file mode 100644 index 00000000..1fc5412d --- /dev/null +++ b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/PackageManager.scala @@ -0,0 +1,163 @@ +package scalajsbundler + +import java.io.File + +import sbt._ +import scalajsbundler.util.Commands +import scalajsbundler.util.JSON + +abstract class PackageManager { + + val name: String + val installCommand: String + val installArgs: Seq[String] + + /** + * Runs the command `cmd` + * @param args Command arguments + * @param workingDir Working directory of the process + * @param logger Logger + */ + protected 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) + } + + def install(baseDir: File, + installDir: File, + logger: Logger): Unit = { + this match { + case lfs: LockFileSupport => + lfs.lockFileRead(baseDir, installDir, logger) + case _ => + () + } + + run(installCommand +: installArgs: _*)(installDir, logger) + + this match { + case lfs: LockFileSupport => + lfs.lockFileWrite(baseDir, installDir, logger) + case _ => + () + } + } + + val packageJsonContents: Map[String, JSON] +} + +trait AddPackagesSupport { this: PackageManager => + + val addPackagesCommand: String + val addPackagesArgs: Seq[String] + + /** + * 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 logger sbt logger + * @param npmPackages Packages to install (e.g. "webpack", "webpack@2.2.1") + */ + def addPackages(baseDir: File, + installDir: File, + logger: Logger, + )(npmPackages: String*): Unit = { + this match { + case lfs: LockFileSupport => + lfs.lockFileRead(baseDir, installDir, logger) + case _ => + () + } + + run(addPackagesCommand +: (addPackagesArgs ++ npmPackages): _*)(installDir, logger) + + this match { + case lfs: LockFileSupport => + lfs.lockFileWrite(baseDir, installDir, logger) + case _ => + () + } + } +} + +trait LockFileSupport { + val lockFileName: String + + def lockFileRead( + baseDir: File, + installDir: File, + logger: Logger + ): Unit = { + val sourceLockFile = baseDir / lockFileName + val targetLockFile = installDir / lockFileName + + if (sourceLockFile.exists()) { + logger.info("Using lockfile " + sourceLockFile) + IO.copyFile(sourceLockFile, targetLockFile) + } + } + + def lockFileWrite( + baseDir: File, + installDir: File, + logger: Logger + ): Unit = { + val sourceLockFile = baseDir / lockFileName + val targetLockFile = installDir / lockFileName + + if (targetLockFile.exists()) { + logger.debug("Wrote lockfile to " + sourceLockFile) + IO.copyFile(targetLockFile, sourceLockFile) + } + } +} + +case class Npm( + name: String = "npm", + lockFileName: String = "package-lock.json", + installCommand: String = "install", + installArgs: Seq[String] = Seq.empty, + addPackagesCommand: String = "install", + addPackagesArgs: Seq[String] = Seq.empty, +) extends PackageManager + with LockFileSupport + with AddPackagesSupport { + override val packageJsonContents: Map[String, JSON] = Map.empty +} + +case class Yarn( + name: String = "yarn", + version: Option[String] = None, + lockFileName: String = "yarn.lock", + installCommand: String = "install", + installArgs: Seq[String] = Yarn.DefaultArgs, + addPackagesCommand: String = "add", + addPackagesArgs: Seq[String] = Yarn.DefaultArgs +) extends PackageManager + with LockFileSupport + with AddPackagesSupport { + override val packageJsonContents: Map[String, JSON] = + version.map(v => Map("packageManager" -> JSON.str(s"$name@$v"))).getOrElse(Map.empty) +} +object Yarn { + val DefaultArgs: Seq[String] = Seq("--non-interactive", "--mutex", "network") +} + +case class Pnpm( + name: String = "pnpm", + version: Option[String] = None, + lockFileName: String = "pnpm-lock.yaml", + installCommand: String = "install", + installArgs: Seq[String] = Seq.empty, + addPackagesCommand: String = "add", + addPackagesArgs: Seq[String] = Seq.empty +) extends PackageManager + with LockFileSupport + with AddPackagesSupport { + override val packageJsonContents: Map[String, JSON] = + version.map(v => Map("packageManager" -> JSON.str(s"$name@$v"))).getOrElse(Map.empty) +} diff --git a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/NpmUpdateTasks.scala b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/NpmUpdateTasks.scala index cb4d5612..87eba104 100644 --- a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/NpmUpdateTasks.scala +++ b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/NpmUpdateTasks.scala @@ -1,8 +1,9 @@ package scalajsbundler.sbtplugin import java.nio.file.Path -import scalajsbundler.ExternalCommand + import sbt._ +import scalajsbundler.PackageManager object NpmUpdateTasks { @@ -21,12 +22,10 @@ object NpmUpdateTasks { 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) + packageManager: PackageManager): File = { + val dir = npmInstallDependencies(baseDir, targetDir, packageJsonFile, streams, packageManager) npmInstallJSResources(targetDir, jsResources, Seq.empty, streams) dir } @@ -45,10 +44,8 @@ object NpmUpdateTasks { def npmInstallDependencies(baseDir: File, targetDir: File, packageJsonFile: File, - useYarn: Boolean, streams: Keys.TaskStreams, - npmExtraArgs: Seq[String], - yarnExtraArgs: Seq[String]): File = { + packageManager: PackageManager): File = { val log = streams.log val cachedActionFunction = FileFunction.cached( @@ -56,7 +53,7 @@ object NpmUpdateTasks { inStyle = FilesInfo.hash ) { _ => log.info("Updating NPM dependencies") - ExternalCommand.install(baseDir, targetDir, useYarn, log, npmExtraArgs, yarnExtraArgs) + packageManager.install(baseDir, targetDir, log) Set.empty } cachedActionFunction(Set(packageJsonFile)) diff --git a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/PackageJsonTasks.scala b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/PackageJsonTasks.scala index e9754efd..dd7650a8 100644 --- a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/PackageJsonTasks.scala +++ b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/PackageJsonTasks.scala @@ -1,7 +1,7 @@ package scalajsbundler.sbtplugin import sbt._ - +import scalajsbundler.PackageManager import scalajsbundler.{BundlerFile, PackageJson} import scalajsbundler.util.{Caching, JSON} @@ -31,7 +31,8 @@ object PackageJsonTasks { webpackVersion: String, webpackDevServerVersion: String, webpackCliVersion: String, - streams: Keys.TaskStreams + streams: Keys.TaskStreams, + packageManager: PackageManager ): BundlerFile.PackageJson = { val hash = Seq( @@ -42,7 +43,8 @@ object PackageJsonTasks { fullClasspath.map(_.data.name).toString, webpackVersion, webpackDevServerVersion, - webpackCliVersion + webpackCliVersion, + packageManager.toString ).mkString(",") val packageJsonFile = targetDir / "package.json" @@ -63,7 +65,8 @@ object PackageJsonTasks { configuration, webpackVersion, webpackDevServerVersion, - webpackCliVersion + webpackCliVersion, + packageManager ) () } diff --git a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/ScalaJSBundlerPlugin.scala b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/ScalaJSBundlerPlugin.scala index fdda11e5..2a92e51f 100644 --- a/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/ScalaJSBundlerPlugin.scala +++ b/sbt-scalajs-bundler/src/main/scala/scalajsbundler/sbtplugin/ScalaJSBundlerPlugin.scala @@ -4,9 +4,10 @@ import org.scalajs.sbtplugin.ScalaJSPlugin.autoImport._ import org.scalajs.sbtplugin.{ScalaJSPlugin, Stage} import sbt.Keys._ import sbt.{Def, _} +import scalajsbundler.AddPackagesSupport import scalajsbundler.{BundlerFile, NpmDependencies, Webpack, WebpackDevServer} - -import scalajsbundler.ExternalCommand.addPackages +import scalajsbundler.Npm +import scalajsbundler.PackageManager import scalajsbundler.util.{JSON, ScalaJSNativeLibraries} @@ -205,18 +206,6 @@ object ScalaJSBundlerPlugin extends AutoPlugin { 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. * @@ -394,19 +383,10 @@ object ScalaJSBundlerPlugin extends AutoPlugin { "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") + val packageManager = SettingKey[PackageManager]( + "packageManager", + "Package manager which will be used for fetching dependencies. Constructor also allows definition of extra arguments." + ) /** * Port, on which webpack-dev-server will be launched. @@ -421,17 +401,6 @@ object ScalaJSBundlerPlugin extends AutoPlugin { "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. * @@ -568,7 +537,7 @@ object ScalaJSBundlerPlugin extends AutoPlugin { // Include the manifest in the produced artifact (products in Compile) := (products in Compile).dependsOn(scalaJSBundlerManifest).value, - useYarn := false, + packageManager := Npm(), ensureModuleKindIsCommonJSModule := { if (scalaJSLinkerConfig.value.moduleKind == ModuleKind.CommonJSModule) true @@ -585,9 +554,6 @@ object ScalaJSBundlerPlugin extends AutoPlugin { webpackExtraArgs := Seq.empty, webpackNodeArgs := Seq.empty, - npmExtraArgs := Seq.empty, - yarnExtraArgs := Seq.empty, - // The defaults are specified at top level. webpackDevServerPort := 8080, webpackDevServerExtraArgs := Seq(), @@ -612,7 +578,10 @@ object ScalaJSBundlerPlugin extends AutoPlugin { 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") + packageManager.value match { + case aps: AddPackagesSupport => + aps.addPackages(baseDir, installDir, log)(s"jsdom@$jsdomVersion") + } } installDir } @@ -644,10 +613,7 @@ object ScalaJSBundlerPlugin extends AutoPlugin { baseDirectory.value, (crossTarget in npmUpdate).value, scalaJSBundlerPackageJson.value.file, - useYarn.value, - streams.value, - npmExtraArgs.value, - yarnExtraArgs.value), + streams.value, packageManager.value), npmInstallJSResources := NpmUpdateTasks.npmInstallJSResources( (crossTarget in npmUpdate).value, @@ -667,7 +633,8 @@ object ScalaJSBundlerPlugin extends AutoPlugin { (version in webpack).value, (version in startWebpackDevServer).value, webpackCliVersion.value, - streams.value + streams.value, + packageManager.value ), diff --git a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/additonalNpmConfig/build.sbt b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/additonalNpmConfig/build.sbt index d0929914..7be317ad 100644 --- a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/additonalNpmConfig/build.sbt +++ b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/additonalNpmConfig/build.sbt @@ -1,4 +1,5 @@ import scalajsbundler.util.JSON._ +import scalajsbundler.Npm val checkPackageJson = taskKey[Unit]("Check that the package.json file does not contain duplicate entries for the 'react' dependency") @@ -8,7 +9,7 @@ lazy val npmConfig = .settings( scalaVersion := "2.13.1", npmDependencies in Compile += "react" -> "16.13.1", - npmExtraArgs in Compile := Seq("-silent"), + packageManager in Compile := Npm(installArgs = Seq("-silent"), addPackagesArgs = Seq("-silent")), additionalNpmConfig in Compile := Map( "name" -> str("foo"), "version" -> str("1.0.0"), diff --git a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/custom-test-config/build.sbt b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/custom-test-config/build.sbt index 13a4e1b8..c9064f5f 100644 --- a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/custom-test-config/build.sbt +++ b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/custom-test-config/build.sbt @@ -25,7 +25,7 @@ requireJsDomEnv in Test := true webpackBundlingMode := BundlingMode.LibraryAndApplication() -useYarn := true +packageManager := scalajsbundler.Yarn() npmDependencies in Compile ++= Seq( "react" -> reactJS, diff --git a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/global-namespace-with-jsdom-unit-testing/build.sbt b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/global-namespace-with-jsdom-unit-testing/build.sbt index e3e58a59..148c49d4 100644 --- a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/global-namespace-with-jsdom-unit-testing/build.sbt +++ b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/global-namespace-with-jsdom-unit-testing/build.sbt @@ -28,6 +28,6 @@ requireJsDomEnv in Test := true version in installJsdom := "12.0.0" -useYarn := true +packageManager := scalajsbundler.Yarn() ivyLoggingLevel in ThisBuild := UpdateLogging.Quiet diff --git a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/npm/build.sbt b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/npm/build.sbt new file mode 100644 index 00000000..1d34eafe --- /dev/null +++ b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/npm/build.sbt @@ -0,0 +1,11 @@ +scalaVersion := "2.12.8" + +packageManager := scalajsbundler.Npm() + +scalaJSUseMainModuleInitializer := true + +npmDependencies in Compile += "neat" -> "2.1.0" + +enablePlugins(ScalaJSBundlerPlugin) + +ivyLoggingLevel in ThisBuild := UpdateLogging.Quiet diff --git a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/npm/project/plugins.sbt b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/npm/project/plugins.sbt new file mode 100644 index 00000000..77ac06f1 --- /dev/null +++ b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/npm/project/plugins.sbt @@ -0,0 +1,8 @@ +val scalaJSVersion = sys.props.getOrElse("scalajs.version", sys.error("'scalajs.version' environment variable is not defined")) +val scalaJSBundlerVersion = sys.props.getOrElse("plugin.version", sys.error("'plugin.version' environment variable is not set")) + +addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion) + +addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % scalaJSBundlerVersion) + +ivyLoggingLevel in ThisBuild := UpdateLogging.Quiet diff --git a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/npm/src/main/scala/example/Main.scala b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/npm/src/main/scala/example/Main.scala new file mode 100644 index 00000000..5e8ae3ed --- /dev/null +++ b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/npm/src/main/scala/example/Main.scala @@ -0,0 +1,7 @@ +package example + +object Main { + def main(args: Array[String]): Unit = { + println("npm main") + } +} diff --git a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/npm/test b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/npm/test new file mode 100644 index 00000000..90e9ebc4 --- /dev/null +++ b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/npm/test @@ -0,0 +1,2 @@ +> fastOptJS::webpack +$ exists package-lock.json \ No newline at end of file diff --git a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/pnpm/build.sbt b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/pnpm/build.sbt new file mode 100644 index 00000000..b73d5d84 --- /dev/null +++ b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/pnpm/build.sbt @@ -0,0 +1,11 @@ +scalaVersion := "2.12.8" + +packageManager := scalajsbundler.Pnpm() + +scalaJSUseMainModuleInitializer := true + +npmDependencies in Compile += "neat" -> "2.1.0" + +enablePlugins(ScalaJSBundlerPlugin) + +ivyLoggingLevel in ThisBuild := UpdateLogging.Quiet diff --git a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/pnpm/project/plugins.sbt b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/pnpm/project/plugins.sbt new file mode 100644 index 00000000..77ac06f1 --- /dev/null +++ b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/pnpm/project/plugins.sbt @@ -0,0 +1,8 @@ +val scalaJSVersion = sys.props.getOrElse("scalajs.version", sys.error("'scalajs.version' environment variable is not defined")) +val scalaJSBundlerVersion = sys.props.getOrElse("plugin.version", sys.error("'plugin.version' environment variable is not set")) + +addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion) + +addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % scalaJSBundlerVersion) + +ivyLoggingLevel in ThisBuild := UpdateLogging.Quiet diff --git a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/pnpm/src/main/scala/example/Main.scala b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/pnpm/src/main/scala/example/Main.scala new file mode 100644 index 00000000..6aab86d7 --- /dev/null +++ b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/pnpm/src/main/scala/example/Main.scala @@ -0,0 +1,7 @@ +package example + +object Main { + def main(args: Array[String]): Unit = { + println("pnpm main") + } +} diff --git a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/pnpm/test b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/pnpm/test new file mode 100644 index 00000000..6a170d44 --- /dev/null +++ b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/pnpm/test @@ -0,0 +1,2 @@ +> fastOptJS::webpack +$ exists pnpm-lock.yaml \ No newline at end of file diff --git a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sharedconfig/build.sbt b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sharedconfig/build.sbt index d4d2b773..d66db05e 100644 --- a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sharedconfig/build.sbt +++ b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/sharedconfig/build.sbt @@ -33,7 +33,7 @@ requireJsDomEnv in Test := true webpackBundlingMode in fastOptJS := BundlingMode.LibraryAndApplication() -useYarn := true +packageManager := scalajsbundler.Yarn() // HtmlUnit does not support ECMAScript 2015 scalaJSLinkerConfig ~= { _.withESFeatures(_.withUseECMAScript2015(false)) } diff --git a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/static/build.sbt b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/static/build.sbt index 5498802e..7ec94fd7 100644 --- a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/static/build.sbt +++ b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/static/build.sbt @@ -17,7 +17,7 @@ version in installJsdom := "16.4.0" webpackBundlingMode := BundlingMode.LibraryAndApplication() -useYarn := true +packageManager := scalajsbundler.Yarn() // HtmlUnit does not support ECMAScript 2015 scalaJSLinkerConfig ~= { _.withESFeatures(_.withUseECMAScript2015(false)) } diff --git a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets/build.sbt b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets/build.sbt index 3d57c472..fac5cf48 100644 --- a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets/build.sbt +++ b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/webpack-assets/build.sbt @@ -31,7 +31,7 @@ npmDevDependencies in Compile += "mini-css-extract-plugin" -> "1.3.4" webpackDevServerPort := 7357 -useYarn := true +packageManager := scalajsbundler.Yarn() // HtmlUnit does not support ECMAScript 2015 scalaJSLinkerConfig ~= { _.withESFeatures(_.withUseECMAScript2015(false)) } diff --git a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/yarn-interactive/build.sbt b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/yarn-interactive/build.sbt index 85208d6c..5e14c4d6 100644 --- a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/yarn-interactive/build.sbt +++ b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/yarn-interactive/build.sbt @@ -1,8 +1,6 @@ scalaVersion := "2.12.8" -useYarn := true - -yarnExtraArgs in Compile := Seq("--silent") +packageManager := scalajsbundler.Yarn(installArgs = Seq("--silent"), addPackagesArgs = Seq("--silent")) scalaJSUseMainModuleInitializer := true diff --git a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/yarn-interactive/test b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/yarn-interactive/test index ddbbec9e..19a17428 100644 --- a/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/yarn-interactive/test +++ b/sbt-scalajs-bundler/src/sbt-test/sbt-scalajs-bundler/yarn-interactive/test @@ -1 +1,2 @@ > fastOptJS::webpack +$ exists yarn.lock \ No newline at end of file