clux / modul8

NO LONGER MAINTAINED - browserify is too similar and is better (see issues)
http://clux.github.com/modul8
MIT License
22 stars 4 forks source link

npm dependency issue (again) #15

Closed panosru closed 12 years ago

panosru commented 12 years ago

Hello, I have similar issue as in #11 the case is that I have require 'Helpers::dic' where Helpers is a registered domain in modul8, when this is processed by modul8 I get an error Error: modul8 resolver failed to resolve require('gerenuk') the file that I try to load uses require('gerenuk') and it seems that modul8 can't resolve that dependency but if I try to load that module directly in the file that is processed by modul8 like this require 'npm::gerenuk' it is loaded fine...

Thanks

clux commented 12 years ago

So dic is a file under the Helpers domain which requires gerenuk in the same directory, is that right? If so, try replacing require('gerenuk') with require('./gerenuk') to make it absolutely clear to the resolver. Strictly speaking that should work though. Is anything in those folders relying on package.json mechanics?

panosru commented 12 years ago

@clux not exactly like that, here is the paths:

dic is under /system/helpers/dic.js helpers are in /system/helpers/ node modules are in /node_modules/ the file that processed by modul8 is /front-end/app.coffee

clux commented 12 years ago

Is gerenuk a file on the helper domain or is it a subfolder of /system/helpers ?

clux commented 12 years ago

oh wait. I get it.

panosru commented 12 years ago

@clux gerenuk is a module located in /node_modules/gerenuk/

clux commented 12 years ago

@panosru You are requiring a npm module from a domain. That won't work. Domains are domain agnostic if that makes sense. Makes the dependency tree a little easier to model. They are designed to consist of standalone code only - as an alternative to modules. Obviously you could do what you do, but then it would either work only on the server or only on the client - defeating the purpose.

Perhaps there is functionality in the helpers domain that could work as an npm module instead?

panosru commented 12 years ago

@clux I'm not sure I get it, what you mean by "domain" ?

clux commented 12 years ago

A folder you've explicitly added (and are requiring code from) that you registered via .domain(). I.e. Helpers is your extra domain.

In the documentation, client side code code is said to be on the 'app' domain, and npm modules sort of lie on a specialized npm domain. Normal domains, i.e. not app or npm, could easily just have been another module node_modules. That way it can require code from npm seemlessly (without specifying npm::).

Domains are dumb because I didn't plan on having npm support. In that sense, using node modules is in that sense better. It can also pull in more than perhaps you want though. Domains allow strict control.

panosru commented 12 years ago

@clux ah sorry with all those things I'm involved I forgot about definition of domains in modul8 :) yes indeed that's the case... hmm so you suggest me to use that helper as a node module.. well if I do it it should be a private node_module since the functionality is not generic at all hmm damn :P

panosru commented 12 years ago

Currently my helper look like this:

var Container = require('gerenuk').Container;

function Dic () {

  //Apply Singleton Pattern
  this.getInstance = function () {
    if ('undefined' === typeof this.instance) {
      this.instance = new Container;
      this.instance.loadConfig($settings.paths.config + 'dic');
    }

    return this.instance;
  }
}

module.exports = new Dic(); //Initialize on call

So I changed it :

function Dic (Container, $settings) {

  //Apply Singleton Pattern
  this.getInstance = function () {
    if ('undefined' === typeof this.instance) {
      this.instance = new Container;
      this.instance.loadConfig($settings.paths.config + 'dic');
    }

    return this.instance;
  }
}

module.exports = function (Container, $settings) { return new Dic(Container, $settings); }; //Initialize on call

it worked since I was passing the dependencies to the helper but then I had problem with loadConfig method since the path scope is modified when the helper is used by modul8 :/

clux commented 12 years ago

Alternatively, you could load gerenuk from your client app, then inject it to the helper domain. Since you are a fan of dependency injection : )

panosru commented 12 years ago

I tried it with the above code :D I'm wondering though why the following is not working:

  .data({
    'DIC'       : require($settings.paths.helpers + 'dic').getInstance()
  })

I though that by doing that when I do require 'data::DIC' I would get the instance of the object but it seems that I don't...

EDIT: Ah of-course I forgot that everything passed in data is stringified :/

clux commented 12 years ago

I don't know much about iced or gerenuk, and I'm assuming you've figured it out by now. In general though, in cases like this, you could do:

require('helpers::dic')(require('npm::gerenuk'));

from the app code, where dic exports a function expecting gerenuk. Closing this issue for now.

panosru commented 12 years ago

@clux yeap this is what I done for now, but it gain other issues which I'll test them another time :)

Thanks :)