Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27150] Add ability to alias required modules in Titanium

GitHub Issuen/a
TypeNew Feature
PriorityNone
StatusClosed
ResolutionFixed
Resolution Date2019-07-08T16:45:21.000+0000
Affected Version/sn/a
Fix Version/sRelease 8.1.0
Componentsn/a
Labelsn/a
ReporterBrenton House
AssigneeChristopher Williams
Created2019-06-14T17:41:02.000+0000
Updated2019-07-16T10:16:38.000+0000

Description

With 8.0.X versions of the SDK, I could include a bootstrap file with my package before I published it to npm which then allowed me to define an alias for use with Titanium. require('/ti.internal/extensions/binding')('axios', '/node_modules/@titanium/axios'); With the 8.1.x releases, the code has changed and is rolled up, which blocks access to the functions necessary to do this. I will submit a PR that modifies the code to allow it.

Comments

  1. Brenton House 2019-06-14

    Added PR: https://github.com/appcelerator/titanium_mobile/pull/10961
  2. Christopher Williams 2019-06-28

    New PR: https://github.com/appcelerator/titanium_mobile/pull/11009
  3. Christopher Williams 2019-07-08

    merged to master and 8_1_X. This is an unadvertised/un-documented new "feature" that we use internally to register our Node compatible shims so they get returned by calls to require. Per Brenton's request, the API is now available to users, but I don't know how much we want to advertise this. cc [~emerriman] [~amukherjee] Basically it's now accessed via:
       // to hijack require('original.module.id') to actually load some specific JS file...
       global.binding.redirect('original.module.id', '/my/special/override');
       // or to hijack require('original.module.id') to return a specific object/value acting like module.exports...
       global.binding.register('original.module.id', value);
       
  4. Brenton House 2019-07-08

    (*) (*) Thank you [~cwilliams] !!! (*) (*)
  5. Samir Mohammed 2019-07-16

    *Closing ticket*, feature verified in SDK version 8.1.0.v20190715143102 and SDK version 8.2.0.v20190712143331 Was able to alias required modules in Titanium using the following test case: *app.js*
       global.binding.redirect('appc.rocks', '/afile.js');
       global.binding.register('appc.super.rocks', 'appc truly does rock');
       var win = Ti.UI.createWindow({
           backgroundColor: '#fff'
       });
       win.open();
       win.addEventListener('click', () => {
           require('appc.rocks');
       });
       
    *afile.js*
       const whatDoesappcDo = require('appc.super.rocks');
       console.log(whatDoesappcDo);
       
    *Test Environment*
       iPhone 6 12.2 sim
       Android pixel XL 7.1.1. Emulator 
       MacOS Mojave version 10.14.4
       Xcode 11 Beta 3
       Node.js ^8.12.0
       "NPM":"4.2.13","CLI":"7.1.0-master.24"
       

JSON Source