webjars / webjars-play

MIT License
80 stars 34 forks source link

Webjars importing versions other than those specified, and failing. #46

Closed oris4ecm closed 10 years ago

oris4ecm commented 10 years ago

My build.sbt section for the webjars looks like this:

"org.webjars" % "webjars-play_2.10" % "2.3.0-2",
"org.webjars" % "font-awesome" % "4.0.3",
"org.webjars" % "jquery" % "1.11.1",
"org.webjars" % "bootstrap" % "3.0.3",
"org.webjars" % "bootstrap-datepicker" % "1.3.0-3",
"org.webjars" % "bootstrap-switch" % "3.0.2",
"org.webjars" % "bootstrapvalidator" % "0.5.0",
"org.webjars" % "jasny-bootstrap" % "3.1.3-2",
"org.webjars" % "jquery-cookie" % "1.4.1",
"org.webjars" % "d3js" % "3.4.11",
"org.webjars" % "hoganjs" % "3.0.2",
"org.webjars" % "momentjs" % "2.8.3",
"org.webjars" % "tagmanager" % "3.0.1",
"org.webjars" % "typeaheadjs" % "0.10.4-1",
"org.webjars" % "zTree" % "3.5.15",

We configure the requirejs section in a page as follows:

<script type="application/javascript" rel="script">
var require = {
    callback : function ( ) {

        @for(webJarJson <- org.webjars.RequireJS.getSetupJson(routes.WebJarAssets.at("").url).values()) {
            requirejs.config ( @Html(webJarJson.toString) );
        }

        requirejs.config ({
            "paths" : {
                "passfield" : "@routes.Assets.at("javascripts/passfield")",
                "intro" : "@routes.Assets.at("javascripts/intro")",
                "pull-to-refresh" : "@routes.Assets.at("javascripts/pull-to-refresh")",
                "jstz" : "@routes.Assets.at("javascripts/jstz")",
                "dashboard-graph" : "@routes.Assets.at("javascripts/dashboard-graph")",
                "daterangepicker" : "@routes.Assets.at("javascripts/daterangepicker")"
            },
            "shim" : {
                "passfield" :[ "jquery", "bootstrap" ],
                "intro" :[ "jquery", "bootstrap" ],
                "pull-to-refresh" :[ "jquery" ]
                "dashboard-graph" :[ "d3js" ],
                "daterangepicker" :[ "jquery", "bootstrap", "moment" ]
            }
        });
        }
};
</script>
<script data-main="@routes.Assets.at("javascripts/index.js")" src="@routes.WebJarAssets.at(WebJarAssets.locate("require.min.js"))"></script>

When the page renders, the following is generated... (notice that there are ~8 missing configs, including jquery, zTree, etc):

requirejs.config (     {"paths":{"typeaheadjs":["/webjars/typeaheadjs/0.10.4-1/typeahead.jquery","typeahead.jquery"]}} );
requirejs.config ( {"paths":{"jasny-bootstrap":["/webjars/jasny-bootstrap/3.1.3/js/jasny-bootstrap","js/jasny-bootstrap"]},"shim":{"jasny-bootstrap":["bootstrap"]}} );
requirejs.config ( {"paths":{"bootstrap":["/webjars/bootstrap/3.1.1/js/bootstrap","js/bootstrap"],"bootstrap-css":["/webjars/bootstrap/3.1.1/css/bootstrap","css/bootstrap"]},"shim":{"bootstrap":["jquery"]}} );
requirejs.config ( {} );
requirejs.config ( {"paths":{"bootstrap-switch":["/webjars/bootstrap-switch/3.0.2/js/bootstrap-switch","js/bootstrap-switch"]},"shim":{"bootstrap-switch":["jquery"]}} );
requirejs.config ( {"paths":{"bootstrapvalidator":["/webjars/bootstrapvalidator/0.5.0/js/bootstrapValidator","js/bootstrapValidator"]},"shim":{"bootstrapvalidator":["bootstrap","jquery"]}} );
requirejs.config ( {} );
requirejs.config ( {"paths":{"d3js":["/webjars/d3js/3.4.11/d3","d3"]},"shim":{"d3js":{"exports":"d3"}}} );
requirejs.config ( {} );
requirejs.config ( {} );
requirejs.config ( {} );
requirejs.config ( {"paths":{"bootstrap-datepicker":["/webjars/bootstrap-datepicker/1.3.0/js/bootstrap-datepicker","js/bootstrap-datepicker"]},"shim":{"bootstrap-datepicker":["bootstrap"]}} );
requirejs.config ( {} );
requirejs.config ( {"paths":{"momentjs":["/webjars/momentjs/2.8.3/moment","moment"],"moment":["/webjars/momentjs/2.8.3/moment","moment"],"moment-with-locales":["/webjars/momentjs/2.8.3/min/moment-with-locales","min/moment-with-locales"]}} );
requirejs.config ( {} );
requirejs.config ( {} );

When the app loads (via run) we get the following messages:

[play-internal-execution-context-2] INFO play - Application started (Dev)
[play-akka.actor.default-dispatcher-31] WARN org.webjars.RequireJS - Could not read WebJar RequireJS config for: zTree 3.5.15
Please file a bug at: http://github.com/webjars/zTree/issues/new
[play-akka.actor.default-dispatcher-31] WARN org.webjars.RequireJS - The zTree 3.5.15 WebJar is using the legacy RequireJS config.
Please try a new version of the WebJar or file or file an issue at:
http://github.com/webjars/zTree/issues/new
[play-akka.actor.default-dispatcher-31] WARN org.webjars.RequireJS - Could not read WebJar RequireJS config for: npm 1.3.26
Please file a bug at: http://github.com/webjars/npm/issues/new
[play-akka.actor.default-dispatcher-31] WARN org.webjars.RequireJS - Could not read WebJar RequireJS config for: jquery 2.1.0
Please file a bug at: http://github.com/webjars/jquery/issues/new
[play-akka.actor.default-dispatcher-31] WARN org.webjars.RequireJS - The jquery 2.1.0 WebJar is using the legacy RequireJS config.
Please try a new version of the WebJar or file or file an issue at:
http://github.com/webjars/jquery/issues/new
[play-akka.actor.default-dispatcher-31] WARN org.webjars.RequireJS - Could not read WebJar RequireJS config for: font-awesome 4.0.3
Please file a bug at: http://github.com/webjars/font-awesome/issues/new
[play-akka.actor.default-dispatcher-31] WARN org.webjars.RequireJS - Could not read WebJar RequireJS config for: jquery-cookie 1.4.1
Please file a bug at: http://github.com/webjars/jquery-cookie/issues/new
[play-akka.actor.default-dispatcher-31] WARN org.webjars.RequireJS - The jquery-cookie 1.4.1 WebJar is using the legacy RequireJS config.
Please try a new version of the WebJar or file or file an issue at:
http://github.com/webjars/jquery-cookie/issues/new
[play-akka.actor.default-dispatcher-31] WARN org.webjars.RequireJS - Could not read WebJar RequireJS config for: hoganjs 3.0.2
Please file a bug at: http://github.com/webjars/hoganjs/issues/new
[play-akka.actor.default-dispatcher-31] WARN org.webjars.RequireJS - Could not read WebJar RequireJS config for: requirejs 2.1.10
Please file a bug at: http://github.com/webjars/requirejs/issues/new
[play-akka.actor.default-dispatcher-31] WARN org.webjars.RequireJS - Could not read WebJar RequireJS config for: tagmanager 3.0.1
Please file a bug at: http://github.com/webjars/tagmanager/issues/new
[play-akka.actor.default-dispatcher-31] WARN org.webjars.RequireJS - The tagmanager 3.0.1 WebJar is using the legacy RequireJS config.
Please try a new version of the WebJar or file or file an issue at:
http://github.com/webjars/tagmanager/issues/new

As you can see, the versions being reported by the activator ui are NOT those that were specified in the build.sbt

Any thoughts on what is going on?

jamesward commented 10 years ago

Transitive dependencies can override versions. You can exclude the transitive deps in artifact resolution. sbt produces some nice reports for looking at how the versions were selected. Look in your target/resolution-cache/reports dir.

Let me know if that helps.

oris4ecm commented 10 years ago

I tried making any webjar that depends on another intransitive() just as a test to see if that would solve the issue:

"org.webjars" % "font-awesome" % "4.0.3" intransitive(),
"org.webjars" % "jquery" % "1.11.1",
"org.webjars" % "bootstrap" % "3.0.3" intransitive(),
"org.webjars" % "bootstrap-datepicker" % "1.3.0-3" intransitive(),
"org.webjars" % "bootstrapvalidator" % "0.5.0" intransitive(),
"org.webjars" % "jquery-cookie" % "1.4.1" intransitive(),
"org.webjars" % "d3js" % "3.4.11",
"org.webjars" % "hoganjs" % "3.0.2",
"org.webjars" % "momentjs" % "2.8.3",
"org.webjars" % "tagmanager" % "3.0.1" intransitive(),
"org.webjars" % "typeaheadjs" % "0.10.4-1",
"org.webjars" % "zTree" % "3.5.15" intransitive(),

However, the compiled output is similar (but with different libs missing):

requirejs.config ( {"paths":{"typeaheadjs":["/webjars/typeaheadjs/0.10.4-1/typeahead.jquery","typeahead.jquery"]}} );
requirejs.config ( {} );
requirejs.config ( {} );
requirejs.config ( {"paths":{"bootstrapvalidator":["/webjars/bootstrapvalidator/0.5.0/js/bootstrapValidator","js/bootstrapValidator"]},"shim":{"bootstrapvalidator":["bootstrap","jquery"]}} );
requirejs.config ( {} );
requirejs.config ( {"paths":{"d3js":["/webjars/d3js/3.4.11/d3","d3"]},"shim":{"d3js":{"exports":"d3"}}} );
requirejs.config ( {"paths":{"jquery":["/webjars/jquery/1.11.1/jquery","jquery"]},"shim":{"jquery":{"exports":"$"}}} );
requirejs.config ( {} );
requirejs.config ( {} );
requirejs.config ( {"paths":{"bootstrap-datepicker":["/webjars/bootstrap-datepicker/1.3.0/js/bootstrap-datepicker","js/bootstrap-datepicker"]},"shim":{"bootstrap-datepicker":["bootstrap"]}} );
requirejs.config ( {} );
requirejs.config ( {"paths":{"momentjs":["/webjars/momentjs/2.8.3/moment","moment"],"moment":["/webjars/momentjs/2.8.3/moment","moment"],"moment-with-locales":["/webjars/momentjs/2.8.3/min/moment-with-locales","min/moment-with-locales"]}} );
requirejs.config ( {} );
requirejs.config ( {} );

(note that the typeahead module doesn't have deps in its POM, thought it should be dependant on bootstrap??)

EDIT: I should note that the files simply aren't loading (404 error) eg: http://localhost:9000/assets/javascripts/bootstrap.js

jamesward commented 10 years ago

Can you file a bug about typeahead not having the right transitive dep?

I'm not seeing the version mismatch. Which versions are different?

oris4ecm commented 10 years ago

AFAIK, there should be no version mismatch now (since every webjar that would declare a dependency is marked intransitive()). However, most of the webjars fail to load (404) errors. The only webjar that is loading is zTree (the last one in the list).

jamesward commented 10 years ago

Hmm... There shouldn't be any 404ing for this setup. Did you restart your Play app after you changed the deps?

oris4ecm commented 10 years ago

I've restarted (CTRL-D), reloaded, exited activator entirely, cleaned & compiled, etc...

I still get the "Could not read WebJar RequireJS config for" messages too for:

However, everything resolves fine. The jars in the ivy2 cache look fine.

jamesward commented 10 years ago

So that means the require config doesn't exist for those WebJars. You can see if the newest version has the require config. If you not can shim your own config in. Or you can file a bug on the WebJar to have it added.

oris4ecm commented 10 years ago

Ok, so I'm trying to shim in the webjars' sources... eg:

requirejs.config ({
    "paths" : {
        "jquery" : "@routes.WebJarAssets.at(WebJarAssets.locate("jquery.min.js"))",
        ...
    }
});

However, that renders to "jquery/1.11.1/jquery.min.js" which require then attempts to drop append a .js to. Any idea how i get the locate to NOT provide the .js or to tell require to not append it?

I'm beginning to think perhaps webjars isn't the way to go for us, though the niceness of having the sources download as part of our dep management is really killer.

jamesward commented 10 years ago

The jquery 1.11.1 WebJar should have the correct require config. For others that don't you can just remove the .js suffix, like:

routes.WebJarAssets.at(WebJarAssets.locate("foo.min.js").stripSuffix(".js"))