Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

jsEnvInput crashes when one of the JS libs has a commonJSName #40

Closed
sjrd opened this issue May 21, 2020 · 2 comments
Closed

jsEnvInput crashes when one of the JS libs has a commonJSName #40

sjrd opened this issue May 21, 2020 · 2 comments
Assignees
Labels

Comments

@sjrd
Copy link
Member

sjrd commented May 21, 2020

Reproducible with the following command in the sbt-plugin-test directory:

> jsDependenciesTest/jsEnvInput

causes the following error:

sbt:sbt-plugin-test> jsDependenciesTest/jsEnvInput
[info] jsDependencies resolution test passed
[error] java.nio.file.InvalidPathException: Illegal char <:> at index 12: require-file:/C:/.../Temp/tmp-8249423672271761065mustache.js
[error]         at com.google.common.jimfs.WindowsPathType.parsePath(WindowsPathType.java:92)
[error]         at com.google.common.jimfs.PathService.parsePath(PathService.java:209)
[error]         at com.google.common.jimfs.JimfsFileSystem.getPath(JimfsFileSystem.java:270)
[error]         at com.google.common.jimfs.JimfsFileSystem.getPath(JimfsFileSystem.java:171)
[error]         at org.scalajs.jsdependencies.sbtplugin.JSDependenciesPlugin$.$anonfun$configSettings$28(JSDependenciesPlugin.scala:409)
[error]         at scala.Option.fold(Option.scala:251)
[error]         at org.scalajs.jsdependencies.sbtplugin.JSDependenciesPlugin$.$anonfun$configSettings$26(JSDependenciesPlugin.scala:407)
[error]         at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:238)
[error]         at scala.collection.immutable.List.foreach(List.scala:392)
[error]         at scala.collection.TraversableLike.map(TraversableLike.scala:238)
[error]         at scala.collection.TraversableLike.map$(TraversableLike.scala:231)
[error]         at scala.collection.immutable.List.map(List.scala:298)
[error]         at org.scalajs.jsdependencies.sbtplugin.JSDependenciesPlugin$.$anonfun$configSettings$25(JSDependenciesPlugin.scala:404)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:49)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:40)
[error]         at sbt.std.Transform$$anon$4.work(System.scala:67)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:269)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error]         at sbt.Execute.work(Execute.scala:278)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:269)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error]         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error]         at java.lang.Thread.run(Thread.java:748)
[error] (jsDependenciesTest / Compile / jsEnvInput) java.nio.file.InvalidPathException: Illegal char <:> at index 12: require-file:/C:/.../Temp/tmp-8249423672271761065mustache.js
[error] Total time: 1 s, completed 21 mai 2020 19:53:36

That's on Windows. On Linux a different error is thrown, but for essentially the same reasons:

sbt:sbt-plugin-test> jsDependenciesTest/jsEnvInput
[info] jsDependencies resolution test passed
[error] java.nio.file.NoSuchFileException: require-file:/tmp/tmp-2507161652009558960mustache.js
[error]         at com.google.common.jimfs.FileTree.lookUp(FileTree.java:91)
[error]         at com.google.common.jimfs.JimfsFileStore.lookUp(JimfsFileStore.java:142)
[error]         at com.google.common.jimfs.FileSystemView.lookUp(FileSystemView.java:123)
[error]         at com.google.common.jimfs.FileSystemView.lookUpRegularFile(FileSystemView.java:331)
[error]         at com.google.common.jimfs.FileSystemView.getOrCreateRegularFile(FileSystemView.java:309)
[error]         at com.google.common.jimfs.JimfsFileSystemProvider.newOutputStream(JimfsFileSystemProvider.java:209)
[error]         at java.nio.file.Files.newOutputStream(Files.java:216)
[error]         at java.nio.file.Files.write(Files.java:3292)
[error]         at org.scalajs.jsdependencies.sbtplugin.JSDependenciesPlugin$.$anonfun$configSettings$28(JSDependenciesPlugin.scala:410)
[error]         at scala.Option.fold(Option.scala:158)
[error]         at org.scalajs.jsdependencies.sbtplugin.JSDependenciesPlugin$.$anonfun$configSettings$26(JSDependenciesPlugin.scala:407)
[error]         at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:233)
[error]         at scala.collection.immutable.List.foreach(List.scala:388)
[error]         at scala.collection.TraversableLike.map(TraversableLike.scala:233)
[error]         at scala.collection.TraversableLike.map$(TraversableLike.scala:226)
[error]         at scala.collection.immutable.List.map(List.scala:294)
[error]         at org.scalajs.jsdependencies.sbtplugin.JSDependenciesPlugin$.$anonfun$configSettings$25(JSDependenciesPlugin.scala:404)
[error]         at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error]         at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:40)
[error]         at sbt.std.Transform$$anon$4.work(System.scala:67)
[error]         at sbt.Execute.$anonfun$submit$2(Execute.scala:269)
[error]         at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error]         at sbt.Execute.work(Execute.scala:278)
[error]         at sbt.Execute.$anonfun$submit$1(Execute.scala:269)
[error]         at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:178)
[error]         at sbt.CompletionService$$anon$2.call(CompletionService.scala:37)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error]         at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
[error]         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
[error]         at java.lang.Thread.run(Thread.java:748)
[error] (jsDependenciesTest / Compile / jsEnvInput) java.nio.file.NoSuchFileException: require-file:/tmp/tmp-2507161652009558960mustache.js
[error] Total time: 0 s, completed May 21, 2020 7:58:14 PM

In both cases, the issue is that the following line:

Files.write(memFS.getPath(s"require-$fname"),
s"""$commonJSName = require("${escapeJS(fname)}");""".getBytes(StandardCharsets.UTF_8))

attempts to create a Path with an illegal file name.

This used to be fine when we had our own virtual file abstraction, whose in-memory files accepted any string as path. It's not OK anymore, now that we use Jimfs.

@sjrd sjrd added the bug label May 21, 2020
@sjrd sjrd self-assigned this May 21, 2020
sjrd added a commit to sjrd/jsdependencies that referenced this issue May 21, 2020
We used to embed the target URI in the file name, which generates
invalid paths. This used to be fine when we used our own virtual
files, whose in-memory files accepted any string as path. Since we
are now using Jimfs, we need to use correct path names.

We now generate file names based on the `commonJSName`. Since
`commonJSName` must be a valid JavaScript identifier, it is also a
valid file name (in particular, it cannot contain the characters
`: ; / \`). In the unlikely event that two libraries have the same
`commonJSName` (which would probably be erroneous anyway, but
still), we use suffixes to generated distinct file names.
sjrd added a commit to sjrd/jsdependencies that referenced this issue May 22, 2020
We used to embed the target URI in the file name, which generates
invalid paths. This used to be fine when we used our own virtual
files, whose in-memory files accepted any string as path. Since we
are now using Jimfs, we need to use correct path names.

We now generate file names based on the `commonJSName`. Since
`commonJSName` must be a valid JavaScript identifier, it is also a
valid file name (in particular, it cannot contain the characters
`: ; / \`). In the unlikely event that two libraries have the same
`commonJSName` (which would probably be erroneous anyway, but
still), we use suffixes to generated distinct file names.
@sjrd sjrd closed this as completed in 18e76ab May 22, 2020
sjrd added a commit that referenced this issue May 22, 2020
Fix #40: Generate valid path names for `require-$name.js` files.
@sjrd
Copy link
Member Author

sjrd commented May 22, 2020

@japgolly This is now fixed in the released version 1.0.1. It's on its way to Maven Central.

@japgolly
Copy link

Sweet! Thanks @sjrd !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants