tonylukasavage / ti-commonjs

node.js-style commonjs implementation for Titanium 3.X
MIT License
35 stars 8 forks source link

Organization of app/lib files when adopting ti-commonjs #29

Open ghost opened 9 years ago

ghost commented 9 years ago

http://docs.appcelerator.com/titanium/latest/#!/api/Global-method-require says:

Alloy For Alloy, place the CommonJS modules in the app/lib directory of your Alloy project, then load the module with the require method without the app/lib path and .js extension.

For example, a module file app/lib/myModule/module.js may be loaded by app/controllers/index.js using:

require('myModule/module');

What is the best way to organize things that were in app/lib when adopting ti-commonjs? There doesn't appear to be a way to add another search path, and ti-commonjs uses Resources whereas traditional Alloy appears to use both Resources and app/lib.

The options as I see them:

Are there any other options? Any suggestions? Thanks!

yuchi commented 9 years ago

You pointed what in my humble opinion is the biggest issue with the current resolving algorithm.

Currently it resolves things as they are in the resulting app, that means that in a controller to reference a file in the lib directory you’ll need to do require('../../filename'). That’s because files in the lib dir will be placed inside the root of the Resources while controllers will be placed in Resources/alloy/controllers/*.

This is madness.