[TIMOB-27150] Add ability to alias required modules in Titanium
| GitHub Issue | n/a |
|---|---|
| Type | New Feature |
| Priority | None |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2019-07-08T16:45:21.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | Release 8.1.0 |
| Components | n/a |
| Labels | n/a |
| Reporter | Brenton House |
| Assignee | Christopher Williams |
| Created | 2019-06-14T17:41:02.000+0000 |
| Updated | 2019-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.
Added PR: https://github.com/appcelerator/titanium_mobile/pull/10961
New PR: https://github.com/appcelerator/titanium_mobile/pull/11009
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);(*) (*) Thank you [~cwilliams] !!! (*) (*)
*Closing ticket*, feature verified in SDK version
8.1.0.v20190715143102and SDK version8.2.0.v20190712143331Was able to alias required modules in Titanium using the following test case: *app.js**afile.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'); });*Test Environment*const whatDoesappcDo = require('appc.super.rocks'); console.log(whatDoesappcDo);