@@ -29,6 +29,9 @@ import org.scalajs.linker.interface.ModuleInitializer
29
29
object DottyJSPlugin extends AutoPlugin {
30
30
import Build ._
31
31
32
+ val writePackageJSON = taskKey[Unit ](
33
+ " Write package.json to configure module type for Node.js" )
34
+
32
35
override def requires : Plugins = ScalaJSPlugin
33
36
34
37
override def projectSettings : Seq [Setting [_]] = Def .settings(
@@ -51,6 +54,21 @@ object DottyJSPlugin extends AutoPlugin {
51
54
52
55
// Typecheck the Scala.js IR found on the classpath
53
56
scalaJSLinkerConfig ~= (_.withCheckIR(true )),
57
+
58
+ Compile / jsEnvInput := (Compile / jsEnvInput).dependsOn(writePackageJSON).value,
59
+ Test / jsEnvInput := (Test / jsEnvInput).dependsOn(writePackageJSON).value,
60
+
61
+ writePackageJSON := {
62
+ val packageType = scalaJSLinkerConfig.value.moduleKind match {
63
+ case ModuleKind .NoModule => " commonjs"
64
+ case ModuleKind .CommonJSModule => " commonjs"
65
+ case ModuleKind .ESModule => " module"
66
+ }
67
+
68
+ val path = target.value / " package.json"
69
+
70
+ IO .write(path, s """ {"type": " $packageType"}\n """ )
71
+ },
54
72
)
55
73
}
56
74
@@ -1202,6 +1220,19 @@ object Build {
1202
1220
// A first blacklist of tests for those that do not compile or do not link
1203
1221
(Test / managedSources) ++= {
1204
1222
val dir = fetchScalaJSSource.value / " test-suite"
1223
+
1224
+ val linkerConfig = scalaJSStage.value match {
1225
+ case FastOptStage => (Test / fastLinkJS / scalaJSLinkerConfig).value
1226
+ case FullOptStage => (Test / fullLinkJS / scalaJSLinkerConfig).value
1227
+ }
1228
+
1229
+ val moduleKind = linkerConfig.moduleKind
1230
+ val hasModules = moduleKind != ModuleKind .NoModule
1231
+
1232
+ def conditionally (cond : Boolean , subdir : String ): Seq [File ] =
1233
+ if (! cond) Nil
1234
+ else (dir / subdir ** " *.scala" ).get
1235
+
1205
1236
(
1206
1237
(dir / " shared/src/test/scala" ** ((" *.scala" : FileFilter )
1207
1238
-- " ReflectiveCallTest.scala" // uses many forms of structural calls that are not allowed in Scala 3 anymore
@@ -1220,9 +1251,21 @@ object Build {
1220
1251
++ (dir / " js/src/test/require-2.12" ** " *.scala" ).get
1221
1252
++ (dir / " js/src/test/require-sam" ** " *.scala" ).get
1222
1253
++ (dir / " js/src/test/scala-new-collections" ** " *.scala" ).get
1223
- ++ (dir / " js/src/test/require-no-modules" ** " *.scala" ).get
1254
+
1255
+ ++ conditionally(! hasModules, " js/src/test/require-no-modules" )
1256
+ ++ conditionally(hasModules, " js/src/test/require-modules" )
1224
1257
)
1225
1258
},
1259
+
1260
+ Test / managedResources ++= {
1261
+ val testDir = fetchScalaJSSource.value / " test-suite/js/src/test"
1262
+
1263
+ scalaJSLinkerConfig.value.moduleKind match {
1264
+ case ModuleKind .NoModule => Nil
1265
+ case ModuleKind .CommonJSModule => (testDir / " resources-commonjs" ** " *.js" ).get
1266
+ case ModuleKind .ESModule => (testDir / " resources-esmodule" ** " *.js" ).get
1267
+ }
1268
+ },
1226
1269
)
1227
1270
1228
1271
lazy val sjsCompilerTests = project.in(file(" sjs-compiler-tests" )).
0 commit comments