[TIMOB-23383] Parity: Titanium CommonJS modules cannot require relative files
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-07-14T04:43:46.000+0000 |
Affected Version/s | Release 5.3.0 |
Fix Version/s | Release 6.0.0 |
Components | Android, iOS |
Labels | n/a |
Reporter | Christopher Williams |
Assignee | Christopher Williams |
Created | 2016-05-16T17:21:03.000+0000 |
Updated | 2016-10-05T17:41:32.000+0000 |
Description
Titanium CommonJS modules have a hard limit to effectively all be contained in a single JS file whose base name matches the module.id. If you have a CommonJS module, not only does it have to have an entry file matching the module id(TIMOB-23382), but that file will fail to require any other files relative to it.
For a simple example, I have a
modules/commonjs/ti.commonjs.require/1.0.0
folder and inside is:
- ti.commonjs.require.js
- main.js
I can do require('ti.commonjs.require');
from my Titanium app, and it'll load the modules/commonjs/ti.commonjs.require/1.0.0/ti.commonjs.require.js
file (regardless of whether I have a package.json pointing to another file or an index.js file there). But if that file has a require('./main');
it'll throw a Runtime error that it's unable to load the main.js module.
Just for testing sake, doing a
require('main')
orrequire('/main')
as fails.On Android this appears to be the case because CommonJS modules are actually placed as a single file into the Resources folder of the generated app. One possible fix is to actually retain the module's full contents filtered down to just the *.js and *.json files, as a whole folder under the Resources folder?
Verified fixed, using: MacOS 10.12 (16A323) Studio 4.7.1.201609100950 Ti SDK 6.0.0.v20161005072811 Appc NPM 4.2.7 Appc CLI 6.0.0-55 Alloy 1.9.2 Xcode 8.0 (8A218a) CommonJS modules can include relative files, without error (if specified as
require('./main')
). Tested by adding a log and require statement to a commonJS module then doing the same in the relative file. No errors were encountered and all logs were printed. Tested on both android and iOS simulators/emulators.