Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-7833] Tooling: Add support for a "common" CommonJS module installation folder

GitHub Issuen/a
TypeNew Feature
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2012-03-09T14:49:57.000+0000
Affected Version/sRelease 2.0.0
Fix Version/sSprint 2012-05, Release 2.0.0
ComponentsTooling
Labelslook1, release-note-2.0.0
ReporterMarshall Culpepper
AssigneeJosh Roesslein
Created2012-02-27T19:16:16.000+0000
Updated2017-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.

Comments

  1. Marshall Culpepper 2012-02-28

    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.
  2. Marshall Culpepper 2012-03-06

    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.
  3. Jeff English 2012-03-07

    The installed commonjs module structure should be similar to the android and iphone module structure:
       modules
           commonjs
               ti.cloud
                   2.0
                       documentation (folder)
                       example (folder)
                       LICENSE
                       manifest
                       ti.cloud.js
       
  4. Jeff English 2012-03-08

    CommonJS modules will be referenced in the tiapp.xml as:
       <module platform="commonjs" version="2.0">ti.cloud</module>
       
  5. Jeff English 2012-03-08

    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.
  6. Josh Roesslein 2012-03-08

    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.
  7. Jeff English 2012-03-08

    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.
  8. Josh Roesslein 2012-03-08

    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?
  9. Jeff English 2012-03-08

    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.
  10. Josh Roesslein 2012-03-08

    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 .js file in the root of the module folder.
  11. Chris Barber 2012-03-08

    Mobile Web supports loading CommonJS and AMD modules synchronously and returns the module you requested (or undefined if it can't load it).
        // sync
        var mymodule = require("my/module");
        
    Mobile Web also supports loading AMD formatted modules asynchronously like this:
        // async
        require(["my/module1", "my/module2", "my/module3"], function(module1, module2, module3) {
            // do magical things
        });
        
  12. Vishal Duggal 2012-03-09

    Resolved by PR 1625
  13. Lee Morris 2017-03-16

    Closing ticket as fixed.

JSON Source