Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23543] TiAPI: require implementation uses incorrect __filename values

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-07-20T13:47:21.000+0000
Affected Version/sn/a
Fix Version/sRelease 6.0.0
ComponentsAndroid, iOS, Windows
Labelsbreaking-change, parity
ReporterChristopher Williams
AssigneeChristopher Williams
Created2016-06-20T16:09:41.000+0000
Updated2017-03-31T22:15:31.000+0000

Description

Our require implementation uses different values for __filename than what may be expected from an implementation like NodeJS. Additionally, our values differ between platforms. On Windows, we get the base name of the file ('filename'). On iOS and Android we get the filename with no path info ('filename.js'). To match Node, we should be giving the absolute path to the resolved file ('/path/to/filename.js').

Comments

  1. Kota Iguchi 2016-06-27

    Windows: https://github.com/appcelerator/titanium_mobile_windows/pull/750
  2. Kota Iguchi 2016-06-28

    Let me clear on the __filename spec for Windows: Does that need to be "Windows full path" or "path from application directory"? What I mean here is: Let say we have
       app.js
         - hello/
           - index.js
       
    * Windows full path = C:\Data\SharedData\PhoneTools\AppxLayouts\xxx\hello\index.js * Path for the application directory = /hello/index.js [My current PR](https://github.com/appcelerator/titanium_mobile_windows/pull/750) implements __filename from path for the application directory.
  3. Christopher Williams 2016-06-28

    [~kota] Your implementation is correct. The __filename path is supposed to be the resolved absolute path, but I think on mobile OSes like we deal with, we effectively want it as "absolute" from the app root, not the underlying OS path with scheme. To the user the app root is typically their Resources folder (in terms of how they refer to files), we really want the resolved path from that as root.
  4. Christopher Williams 2016-06-28

    This is resolved fro Windows, but still need fixes from Android and iOS for parity.
  5. Hans Knöchel 2016-07-01

    iOS PR: https://github.com/appcelerator/titanium_mobile/pull/8098 My test-case:
       app.js
         - tmp/
           - sub/
               - index.js
       
    Old __filename: index.js <-- Only filename New __filename: /tmp/sub/index.js <-- Concatenation of the relative path from Resources plus the filename
  6. Christopher Williams 2016-07-01

    Hans' PR fixed the behavior for iOS. Just Android left.
  7. Ashraf Abu 2016-07-04

    Is there any hint or location that I should be looking at for this in Android? I'm looking and found this portion https://github.com/appcelerator/titanium_mobile/blob/415bd6c66dcc55b1a59a59574f3babd3c3a84ede/android/runtime/common/src/js/kroll.js#L119-L121 I'm trying to see what's needed to be done to get this to work in Android.
  8. Christopher Williams 2016-07-06

    [~msamah] That is one possible location, but I think the fix is likely inside https://github.com/appcelerator/titanium_mobile/blob/415bd6c66dcc55b1a59a59574f3babd3c3a84ede/android/runtime/common/src/js/module.js I haven't looked close enough to see where we need to change the value for filename (in _runScript()? in load()?). It'd be good to test what we do report for Android locally to see what exactly needs to change (maybe it just needs a leading slash?). It appeared to only report the last path segment to me, but maybe it was reporting the full path on Android, just missing the leading slash?
  9. Christopher Williams 2016-07-18

    Working on Android version...
  10. Christopher Williams 2016-07-18

    https://github.com/appcelerator/titanium_mobile/pull/8141
  11. Ashraf Abu 2016-08-04

    Testing steps is mentioned in the PR using the test scripts. Refer to https://github.com/appcelerator/titanium_mobile/pull/8141
  12. Lee Morris 2017-03-31

    Closing ticket as fixed, if there are any problems, please file a new ticket.

JSON Source