rotundasoftware / cartero

Modular front end development for multi-page web applications.
MIT License
204 stars 25 forks source link

Question Regarding Order of Dependencies #11

Closed lagoasoft-lucasschmidt closed 11 years ago

lagoasoft-lucasschmidt commented 11 years ago

Hey guys, I have the following structure of dependencies in my library folder. Below is just an example for discussion purposes:

app/ bootstrap/ jquery/ ...

inside app/ I have my application modules, lets say:

login/ index/ header/ ... bundle.json where here I add dependencies like boostrap and jquery

In the login page, I import "app/login", but the dependencies order are as follow:

login.js boostrap... jquery...

Meaning, all the "app" dependencies are added below the "app/login" dependencies. Is this the correct behavior? I was thinking that, by being inside "app", any module would automatically "extend" app.

What do you guys think about this?

go-oleg commented 11 years ago

Hi @lucastschmidt ,

Your expectations are correct, the "app" dependencies should come before login.js. I tried a scenario similar to yours but got the behavior we both expect (the "app" dependencies listed first).

Could you perhaps point me to a more specific code example?

Thanks, Oleg

lagoasoft-lucasschmidt commented 11 years ago

Hey @go-oleg, so here is a sample from one of the projects. Related to the weird behavior. It didnt happen to all files, so, I guess there is something here that is causing the problem.

cartero.json

    ".app/server/views/user/create.jade": {
        "js": [
            ".app/public/library-assets/app/user/view.js",
            ".app/public/library-assets/app/user/prefs.js",
            ".app/public/library-assets/app/user/create/create.js",
            ".app/public/view-assets/user/create.js",
            ".app/public/view-assets/user/details.js",
            ".app/public/view-assets/user/preferences.js",
            ".app/public/library-assets/bootstrap/bootstrap.min.js",
            ".app/public/library-assets/bootbox/bootbox.js",
            ".app/public/library-assets/pnotify/jquery.pnotify.min.js",
            ".app/public/library-assets/spin/spin.min.js",
            ".app/public/library-assets/jquery.bootpag/jquery.bootpag.min.js",
            ".app/public/library-assets/utils/utils.js",
            ".app/public/library-assets/utils/paginator.js",
            ".app/public/library-assets/utils/knockout-bindings.js",
            ".app/public/library-assets/app/i18n/i18n.js",
            ".app/public/library-assets/app/utils/utils.js",
            ".app/public/library-assets/app/utils/cities.js",
            ".app/public/view-assets/header.js"
        ],
        "css": [
            ".app/public/library-assets/bootstrap/bootstrap.min.css",
            ".app/public/library-assets/pnotify/jquery.pnotify.default.css"
        ],
        "tmpl": []
    },

create.jade

                 // ##cartero_extends "layout.jade"
                 // ##cartero_requires "app/user/create"

layout.jade

                  // ##cartero_requires "utils", "app/utils"

app/bundle.json

                    {
                     "dependencies" : [ "utils"]
                      }

app/user

             create/
             prefs.coffee
             view.coffee 

app/user/create

            create.coffee 

app/utils

             {
             "dependencies" : [ "app/i18n"]
               }

app/i18n

        i18n.coffee

utils/bundle.json

                    {
                  "dependencies" : [ "bootstrap", "bootbox", "pnotify", "spin", "jquery.bootpag" ]
                    }

Something that I just realized is that view assets are gathered based on folder. I thought it was based on filename. I will correct that, but that is not related to the dependency order problem.

I do have some weird dependencies here, where app/utils depends on app/i18n. But still, I dont think this is causing since I applied cartero to another existing project and I had similar problems. I was able to fix it somehow, but I have no idea why/how.

Thanks for the help!

lagoasoft-lucasschmidt commented 11 years ago

The really weird thing is that all setup in this project above that I just described comes from another project that I just copied/pasted and there it works great. I just took a look, and the project above, almost everything is out of order.

There must be an edge use-case that is breaking everything. I can even get view-assets first in the project above. Crazy thing.

I just tried to change a few things into this project with errors, but I got nothing, really crazy behavior.

lagoasoft-lucasschmidt commented 11 years ago

Ok, I was able to find out something:

By removing from layout.

     // ##cartero_requires "utils", "app/utils"

I was able to get everything almost 100%. But I still have an edge case where, lets say

app/todos/create

                {
                     "dependencies" : [ "bootstrap-datepicker"]
                }

In this case,

        ".app/server/views/todo/test.jade": {
            "js": [
                ".app/public/library-assets/bootstrap-datepicker/knockout-databind.js",
                ".app/public/library-assets/bootstrap-datepicker/bootstrap-datepicker.js",
                ".app/public/library-assets/bootstrap/bootstrap.min.js",
                ".app/public/library-assets/bootbox/bootbox.js",
                ".app/public/library-assets/pnotify/jquery.pnotify.min.js",
                ".app/public/library-assets/spin/spin.min.js",
                ".app/public/library-assets/jquery.bootpag/jquery.bootpag.min.js",
                ".app/public/library-assets/utils/utils.js",
                ".app/public/library-assets/utils/paginator.js",
                ".app/public/library-assets/utils/knockout-bindings.js",
                ".app/public/library-assets/app/todd/create/create.js",
                ".app/public/view-assets/header.js"

So, "app/todo/create" dependency is being imported before "app/todo" dependencies, and "app" dependencies. I think this is not correct.

Besides that, I still dont get why it would work by removing that import from layout.jade. I would guess that it means that we are importing the same library thought different "paths", but it shouldnt cause a problem, or should it?

Thanks.

go-oleg commented 11 years ago

@lucastschmidt ,

Importing through multiple "paths" should not be a problem. Any chance you can post a complete project somewhere that has this issue. Preferably one with the smallest number of files/dependencies that cause this issue.

Thanks, Oleg

lagoasoft-lucasschmidt commented 11 years ago

Well @go-oleg ... after some time analyzing, I was able to find the bug. But at the same time I realized that its very possible that the bug is already fixed and ... yeah that was the case. I was using an old version :+1: (0.1.0)

So, there is no problem, I just got lost between many projects and did add an old version of cartero. At least I did learn a bit about the internal structure.