sbt/sbt-web

NPM webjars expanding to directories with wrong name

jclyons opened this issue · 3 comments

Some npm webjars randomly expand to a directory with the name of the author of that module rather than to a directory with the name of the module, breaking some transitive dependencies for npm webjars.

For example, if you add the "org.webjars" % "tough-cookie" % "2.2.1" module as a libraryDependency, tough-cookie expands to a directory inside of target/node-modules/main/webjars called Jeremy Stashewsky. The 'author' section of this module's package.json file looks like this:

"author": {
    "name": "Jeremy Stashewsky",
    "email": "jstashewsky@salesforce.com",
    "website": "https://github.com/stash"
  }

so it's clear that sbt-web is using the author's name for the directory name.

This also affects the module 'node-util' ("org.webjars.npm % "util" % "0.10.3") which expands to a director called 'Joyent.'

On the other hand, other modules such as "org.webjars.npm" % "underscore" % "1.8.3" and "org.webjars.npm" % "backbone" % "1.2.3" expand, correctly, to a directory with the module's name, i.e. underscore, backbone. It is not clear from the package.json why this behavior is different for these modules.

This is a big problem because if you have another module that has tough-cookie as a transitive dependency it cannot find the package when it invokes require("tough-cookie") unless you rename the directory. It would be great if the modules expanded to the correct directory, target/web/node-modules/main/webjars/<module_name> no matter what.

The problem is most likely that sbt-web is using a regex to discover the name, instead of properly parsing the json. It's expecting that there is only one name field possible in the json, but that assumption is clearly wrong.

This has been fixed in webjars-locator-core I think.

mkurz commented

Assuming this has been fixed, according to the previous comment.