[TIMOB-7833] Tooling: Add support for a "common" CommonJS module installation folder
GitHub Issue | n/a |
---|---|
Type | New Feature |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-03-09T14:49:57.000+0000 |
Affected Version/s | Release 2.0.0 |
Fix Version/s | Sprint 2012-05, Release 2.0.0 |
Components | Tooling |
Labels | look1, release-note-2.0.0 |
Reporter | Marshall Culpepper |
Assignee | Josh Roesslein |
Created | 2012-02-27T19:16:16.000+0000 |
Updated | 2017-03-16T22:03:45.000+0000 |
Description
With our current module system, modules must either be installed into a project or in the system Titanium folder. In both cases, modules are platform-specific compiled binaries (a static lib for iOS, shared lib for Android).
It would be nice to allow pure Javascript / CommonJS modules in a common place that could simply be distributed as JS files, for example a
common
or commonjs
folder under the system Titanium directory that would be analogous to today's iphone
and android
directories.
We chatted about implementation today, some notes: * We will also need a new "CommonJS" module project type that only has the common module structure (i.e. documentation, and assets), but no native code generation * We can safely copy the CommonJS module source code from the "common" module folder into the app's staging area unless the app has it's own version of the module. This allows the app to override with their own version if/when necessary, and for Android should ensure the JS gets properly obfuscated and embedded.
One more quick update: We don't need to support CommonJS module creation via module.py (or a project template) on this first revision, just pre-packaged CommonJS modules are good enough. Jeff plans to just modify the project template from an iOS or Android module project.
The installed commonjs module structure should be similar to the android and iphone module structure:
CommonJS modules will be referenced in the tiapp.xml as:
Let us know if the .js files are okay in the module folder or if they should be moved into an 'assets' folder. It is possible that there will be multiple .js files and perhaps even images/assets that need to be used with the module.
Would using a "Resources" folder like we do in the application folder structure work? Having all the resources (JavaScript, images, etc) in one folder would probably make copying of the files during packaging easier.
I suggested 'assets' because that is where we tell developers to put their javascript files when building a 'compiled' javascript module on iOS. 'assets' is the existing concept for module developers.
How would multiple JavaScript files work with our require()? I can see how a single file (ex: ti.cloud.js -> require('ti.clould')) would work. If you have multiple files, is there only one "index" file that is public. All the others are just for internal use in the module?
Yea, just the top-level module js file would be 'require'd by the developer. *If* there are any other js files they would be 'require'd internally by the module.
We have decided just to implement the single JS file use case for now. To support the more advance multiple file case will require a formal specification first and platform changes to support it. The only file that will be packaged then into the application is the
Mobile Web supports loading CommonJS and AMD modules synchronously and returns the module you requested (or undefined if it can't load it).
Mobile Web also supports loading AMD formatted modules asynchronously like this:
Resolved by PR 1625
Closing ticket as fixed.