[TIMOB-23382] Parity: Cannot require directory as done in NodeJS
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2016-06-10T08:07:56.000+0000 |
Affected Version/s | Release 5.3.0 |
Fix Version/s | Release 6.0.0 |
Components | Android, iOS |
Labels | notable, parity |
Reporter | Christopher Williams |
Assignee | Christopher Williams |
Created | 2016-05-16T17:13:43.000+0000 |
Updated | 2018-11-16T15:40:54.000+0000 |
Description
If you attempt to require a directory, NodeJS has well-defined behavior: https://nodejs.org/api/modules.html#modules_all_together
Namely:
- try to load
dir/package.json
and grab the main
property, load the file pointed to by that.
- try to load dir/index.js
as JS
- try to load dir/index.json
as JSON
Trying this on Android and iOS, it just throws a runtime error that the requested module was not found.
The NodeJS require algorithm _is_ implemented for Windows SDK.
https://github.com/appcelerator/titanium_mobile/pull/8004
Works great!
Steps to test
1. *appc new --classic* 2. Obtain this modulescapegoat
from https://github.com/brentertz/scapegoat 3. put the module in/Resources/scapegoat
4. put this in app.js5. *appc run -p ios*
Expected Result
An alert will show with this resultRepeat with *appc -run -p android* you can get the same result PR MERGED!!
Did the same for android. Same results.
Works well.
[~bimmel] probably need to be documented somehow like "hey, Titanium can require directory like what NodeJS does normally now"
Thanks for the heads up [~cng]. I'll add this to the docs when we get to 6.0.0 release.
Thanks [~cwilliams]. I'll take a look at it and write up a little something and post it back here for review.
[~cwilliams] and [~cng], I've written up a first draft of the changes per this ticket: https://wiki.appcelerator.org/display/~bimmel/2016/06/10/Daily+Update+6-10-16#DailyUpdate6-10-16-RequireDirectory Let me know what I got right and wrong. Thanks
Verified the fix. Used the test case above. Closing. Environment: Appc Studio : 4.7.0.201607250649 Ti SDK : 6.0.0.v20160814220332 Ti CLI : 5.0.9 Alloy : 1.9.1 MAC El Capitan : 10.11.6 Appc NPM : 4.2.7 Appc CLI : 6.0.0-24 Node: 4.4.4 Nexus 6 - Android 6.0.1 iOS simulator: Iphone 6s 9.3