6
6
** |/____/ **
7
7
\* */
8
8
9
-
10
9
package org .scalajs .cli
11
10
12
11
import org .scalajs .ir .ScalaJSVersions
@@ -52,7 +51,10 @@ object Scalajsld {
52
51
logLevel : Level = Level .Info
53
52
)
54
53
55
- private def moduleInitializer (s : String , hasArgs : Boolean ): ModuleInitializer = {
54
+ private def moduleInitializer (
55
+ s : String ,
56
+ hasArgs : Boolean
57
+ ): ModuleInitializer = {
56
58
val lastDot = s.lastIndexOf('.' )
57
59
if (lastDot < 0 )
58
60
throw new IllegalArgumentException (s " $s is not a valid main method " )
@@ -67,21 +69,35 @@ object Scalajsld {
67
69
private implicit object ModuleKindRead extends scopt.Read [ModuleKind ] {
68
70
val arity = 1
69
71
val reads = { (s : String ) =>
70
- ModuleKind .All .find(_.toString() == s).getOrElse(
71
- throw new IllegalArgumentException (s " $s is not a valid module kind " ))
72
+ ModuleKind .All
73
+ .find(_.toString() == s)
74
+ .getOrElse(
75
+ throw new IllegalArgumentException (s " $s is not a valid module kind " )
76
+ )
72
77
}
73
78
}
74
79
75
80
private object ModuleSplitStyleRead {
76
- val All = List (ModuleSplitStyle .FewestModules .toString, ModuleSplitStyle .SmallestModules .toString, " SmallModulesFor" )
81
+ val All = List (
82
+ ModuleSplitStyle .FewestModules .toString,
83
+ ModuleSplitStyle .SmallestModules .toString,
84
+ " SmallModulesFor"
85
+ )
77
86
78
- def moduleSplitStyleRead (splitStyle : String , modulePackages : Seq [String ]): ModuleSplitStyle =
87
+ def moduleSplitStyleRead (
88
+ splitStyle : String ,
89
+ modulePackages : Seq [String ]
90
+ ): ModuleSplitStyle =
79
91
try {
80
- (new ModuleSplitStyleParser ).parse(splitStyle, modulePackages.toArray).underlying
81
- }
82
- catch {
92
+ (new ModuleSplitStyleParser )
93
+ .parse(splitStyle, modulePackages.toArray)
94
+ .underlying
95
+ } catch {
83
96
case e : NoClassDefFoundError =>
84
- throw new IllegalArgumentException (s " $splitStyle is not a valid module split style " , e.getCause)
97
+ throw new IllegalArgumentException (
98
+ s " $splitStyle is not a valid module split style " ,
99
+ e.getCause
100
+ )
85
101
}
86
102
}
87
103
@@ -128,14 +144,22 @@ object Scalajsld {
128
144
.text(" Don't optimize code" )
129
145
opt[String ](" moduleSplitStyle" )
130
146
.action { (x, c) => c.copy(moduleSplitStyle = x) }
131
- .text(" Module splitting style " + ModuleSplitStyleRead .All .mkString(" (" , " , " , " )" ))
147
+ .text(
148
+ " Module splitting style " + ModuleSplitStyleRead .All
149
+ .mkString(" (" , " , " , " )" )
150
+ )
132
151
opt[Seq [String ]](" smallModuleForPackages" )
133
152
.valueName(" <package1>,<package2>..." )
134
153
.action((x, c) => c.copy(smallModuleForPackages = x))
135
- .text(" Create as many small modules as possible for the classes in the passed packages and their subpackages." )
154
+ .text(
155
+ " Create as many small modules as possible for the classes in the passed packages and their subpackages."
156
+ )
136
157
opt[String ](" jsFilePattern" )
137
- .action { (x, c) => c.copy(outputPatterns = OutputPatterns .fromJSFile(x)) }
138
- .text(" Pattern for JS file names (default: `%s.js`). " +
158
+ .action { (x, c) =>
159
+ c.copy(outputPatterns = OutputPatterns .fromJSFile(x))
160
+ }
161
+ .text(
162
+ " Pattern for JS file names (default: `%s.js`). " +
139
163
" Expects a printf-style pattern with a single placeholder for the module ID. " +
140
164
" A typical use case is changing the file extension, e.g. `%.mjs` for Node.js modules."
141
165
)
@@ -154,15 +178,21 @@ object Scalajsld {
154
178
.action { (_, c) => c.copy(sourceMap = true ) }
155
179
.text(" Produce a source map for the produced code" )
156
180
opt[Unit ](" compliantAsInstanceOfs" )
157
- .action { (_, c) => c.copy(semantics =
158
- c.semantics.withAsInstanceOfs(Compliant ))
181
+ .action { (_, c) =>
182
+ c.copy(semantics = c. semantics.withAsInstanceOfs(Compliant ))
159
183
}
160
184
.text(" Use compliant asInstanceOfs" )
161
185
opt[Unit ](" es2015" )
162
- .action { (_, c) => c.copy(esFeatures = c.esFeatures.withESVersion(ESVersion .ES2015 )) }
186
+ .action { (_, c) =>
187
+ c.copy(esFeatures = c.esFeatures.withESVersion(ESVersion .ES2015 ))
188
+ }
163
189
.text(" Use ECMAScript 2015" )
164
190
opt[String ](" esVersion" )
165
- .action { (esV, c) => c.copy(esFeatures = c.esFeatures.withESVersion(EsVersionParser .parse(esV))) }
191
+ .action { (esV, c) =>
192
+ c.copy(esFeatures =
193
+ c.esFeatures.withESVersion(EsVersionParser .parse(esV))
194
+ )
195
+ }
166
196
.text(" EsVersion " + EsVersionParser .All .mkString(" (" , " , " , " )" ))
167
197
opt[ModuleKind ]('k' , " moduleKind" )
168
198
.action { (kind, c) => c.copy(moduleKind = kind) }
@@ -173,19 +203,25 @@ object Scalajsld {
173
203
opt[File ]('r' , " relativizeSourceMap" )
174
204
.valueName(" <path>" )
175
205
.action { (x, c) => c.copy(relativizeSourceMap = Some (x.toURI)) }
176
- .text(" Relativize source map with respect to given path (meaningful with -s)" )
206
+ .text(
207
+ " Relativize source map with respect to given path (meaningful with -s)"
208
+ )
177
209
opt[Unit ](" noStdlib" )
178
210
.action { (_, c) => c.copy(stdLib = Nil ) }
179
211
.text(" Don't automatically include Scala.js standard library" )
180
212
opt[String ](" stdlib" )
181
213
.valueName(" <scala.js stdlib jar>" )
182
214
.hidden()
183
- .action { (x, c) => c.copy(stdLib = x.split(File .pathSeparator).map(new File (_)).toSeq) }
184
- .text(" Location of Scala.js standard libarary. This is set by the " +
215
+ .action { (x, c) =>
216
+ c.copy(stdLib = x.split(File .pathSeparator).map(new File (_)).toSeq)
217
+ }
218
+ .text(
219
+ " Location of Scala.js standard libarary. This is set by the " +
185
220
" runner script and automatically prepended to the classpath. " +
186
- " Use -n to not include it." )
221
+ " Use -n to not include it."
222
+ )
187
223
opt[String ](" jsHeader" )
188
- .action { (jsHeader, c) => c.copy(jsHeader = jsHeader)}
224
+ .action { (jsHeader, c) => c.copy(jsHeader = jsHeader) }
189
225
.text(" A header that will be added at the top of generated .js files" )
190
226
opt[Unit ]('d' , " debug" )
191
227
.action { (_, c) => c.copy(logLevel = Level .Debug ) }
@@ -205,8 +241,10 @@ object Scalajsld {
205
241
.text(" prints this usage text" )
206
242
checkConfig { c =>
207
243
if (c.output.isDefined) {
208
- reportWarning(" using a single file as output (--output) is deprecated since Scala.js 1.3.0." +
209
- " Use --outputDir instead." )
244
+ reportWarning(
245
+ " using a single file as output (--output) is deprecated since Scala.js 1.3.0." +
246
+ " Use --outputDir instead."
247
+ )
210
248
}
211
249
212
250
if (c.outputDir.isDefined == c.output.isDefined)
@@ -225,7 +263,10 @@ object Scalajsld {
225
263
val semantics =
226
264
if (options.fullOpt) options.semantics.optimized
227
265
else options.semantics
228
- val moduleSplitStyle = ModuleSplitStyleRead .moduleSplitStyleRead(options.moduleSplitStyle, options.smallModuleForPackages)
266
+ val moduleSplitStyle = ModuleSplitStyleRead .moduleSplitStyleRead(
267
+ options.moduleSplitStyle,
268
+ options.smallModuleForPackages
269
+ )
229
270
230
271
val config = StandardConfig ()
231
272
.withSemantics(semantics)
@@ -253,10 +294,24 @@ object Scalajsld {
253
294
.flatMap { irFiles =>
254
295
(options.output, options.outputDir) match {
255
296
case (Some (jsFile), None ) =>
256
- (DeprecatedLinkerAPI : DeprecatedLinkerAPI ).link(linker, irFiles.toList, moduleInitializers, jsFile, logger)
297
+ (DeprecatedLinkerAPI : DeprecatedLinkerAPI ).link(
298
+ linker,
299
+ irFiles.toList,
300
+ moduleInitializers,
301
+ jsFile,
302
+ logger
303
+ )
257
304
case (None , Some (outputDir)) =>
258
- linker.link(irFiles, moduleInitializers, PathOutputDirectory (outputDir.toPath()), logger)
259
- case _ => throw new AssertionError (" Either output or outputDir have to be defined." )
305
+ linker.link(
306
+ irFiles,
307
+ moduleInitializers,
308
+ PathOutputDirectory (outputDir.toPath()),
309
+ logger
310
+ )
311
+ case _ =>
312
+ throw new AssertionError (
313
+ " Either output or outputDir have to be defined."
314
+ )
260
315
}
261
316
}
262
317
Await .result(result, Duration .Inf )
@@ -265,22 +320,26 @@ object Scalajsld {
265
320
266
321
// Covers deprecated api with not deprecated method. Suppresses warning.
267
322
private abstract class DeprecatedLinkerAPI {
268
- def link (linker : Linker ,
323
+ def link (
324
+ linker : Linker ,
269
325
irFiles : Seq [IRFile ],
270
326
moduleInitializers : Seq [ModuleInitializer ],
271
327
linkerOutputFile : File ,
272
- logger : Logger ): Future [Unit ]
328
+ logger : Logger
329
+ ): Future [Unit ]
273
330
}
274
331
275
332
private object DeprecatedLinkerAPI extends DeprecatedLinkerAPI {
276
333
def apply (): DeprecatedLinkerAPI = this
277
334
278
335
@ deprecated(" Deprecate to silence warnings" , " never/always" )
279
- def link (linker : Linker ,
336
+ def link (
337
+ linker : Linker ,
280
338
irFiles : Seq [IRFile ],
281
339
moduleInitializers : Seq [ModuleInitializer ],
282
340
linkerOutputFile : File ,
283
- logger : Logger ): Future [Unit ] = {
341
+ logger : Logger
342
+ ): Future [Unit ] = {
284
343
val js = linkerOutputFile.toPath()
285
344
val sm = js.resolveSibling(js.getFileName().toString() + " .map" )
286
345
0 commit comments