{ "id": "163776", "key": "TIMOB-23995", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [ { "id": "20238", "description": "", "name": "Release 7.5.0", "archived": false, "released": true, "releaseDate": "2018-11-15" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2018-08-10T13:06:53.000+0000", "created": "2016-10-06T16:31:46.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "qe-6.0.0" ], "versions": [ { "id": "16980", "description": "New V8", "name": "Release 6.0.0", "archived": false, "released": true, "releaseDate": "2016-11-15" }, { "id": "18322", "name": "Release 5.5.1", "archived": false, "released": true, "releaseDate": "2016-09-28" } ], "issuelinks": [ { "id": "52999", "type": { "id": "10001", "name": "Cloners", "inward": "is cloned into", "outward": "is cloned from" }, "outwardIssue": { "id": "163773", "key": "TIMOB-23994", "fields": { "summary": "Android: Using __filename in app.js errors with Can't find variable: __filename", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "priority": { "name": "Medium", "id": "3" }, "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false } } } } ], "assignee": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "updated": "2018-09-24T14:16:17.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" }, { "id": "10206", "name": "iOS", "description": "iOS Platform" } ], "description": "h5.Description\r\n\r\n*This is not a regression occurs using 5.5.1.GA stack*\r\n\r\nWhen using {{__dirname}} in an app.js file the following is thrown\r\n\r\n*Using __dirname in any file other than app.js works*\r\n\r\n{code}\r\n[ERROR] : Application Error: {\r\n[ERROR] : \"line\": 2,\r\n[ERROR] : \"column\": 10,\r\n[ERROR] : \"message\": \"require: Error while require(/app) Can't find variable: __dirname\",\r\n[ERROR] : \"native_stack\": [\r\n[ERROR] : \"JSExportClass::CallNamedFunction\"\r\n[ERROR] : ]\r\n[ERROR] : }\r\n{code}\r\n\r\nh5.Steps to reproduce\r\n\r\n# In your app.js add {{console.log(__dirname)}}\r\n# Build for Android, iOS or Windows\r\n\r\nh5.Actual result\r\n\r\nThe above error is thrown\r\n\r\nh5.Expected result\r\n\r\n__dirname should be able to be used in app.js file", "attachment": [], "flagged": false, "summary": "iOS: Using __dirname in app.js errors with Can't find variable: __dirname ", "creator": { "name": "eharris", "key": "eharris", "displayName": "Ewan Harris", "active": true, "timeZone": "Europe/Dublin" }, "subtasks": [], "reporter": { "name": "eharris", "key": "eharris", "displayName": "Ewan Harris", "active": true, "timeZone": "Europe/Dublin" }, "environment": "OS: Microsoft Windows 10 Pro 10.0.14393\r\nAppc core: 6.0.0-56\r\nAppc NPM: 4.2.8-7\r\nTi SDK: 6.0.0.v20161006013211\r\nAppc Studio: 4.8.0.201610060953\r\niPhone 6: 10.02\r\nNote 4: 5.0.0\r\nLumia 550 10.0", "closedSprints": [ { "id": 1058, "state": "closed", "name": "2018 Sprint 16 SDK", "startDate": "2018-07-29T22:26:06.486Z", "endDate": "2018-08-12T22:26:00.000Z", "completeDate": "2018-08-13T17:38:16.757Z", "originBoardId": 114 }, { "id": 1045, "state": "closed", "name": "2018 Sprint 13 SDK", "startDate": "2018-06-17T20:47:13.621Z", "endDate": "2018-07-01T20:47:00.000Z", "completeDate": "2018-07-02T18:40:05.029Z", "originBoardId": 114 }, { "id": 1050, "state": "closed", "name": "2018 Sprint 14 SDK", "startDate": "2018-07-01T18:40:57.193Z", "endDate": "2018-07-15T18:40:00.000Z", "completeDate": "2018-07-16T03:27:08.720Z", "originBoardId": 114 }, { "id": 1053, "state": "closed", "name": "2018 Sprint 15 SDK", "startDate": "2018-07-15T21:52:05.453Z", "endDate": "2018-07-29T21:52:00.000Z", "completeDate": "2018-07-29T22:25:11.723Z", "originBoardId": 114 } ], "comment": { "comments": [ { "id": "401777", "author": { "name": "brentonhouse", "key": "brentonhouse", "displayName": "Brenton House", "active": true, "timeZone": "America/Chicago" }, "body": "[~cng] I am guessing this is the same issue, but {{__dirname}} is undefined (in any file) when using LiveView. When LiveView is not used, {{__dirname}} works as expected. ", "updateAuthor": { "name": "brentonhouse", "key": "brentonhouse", "displayName": "Brenton House", "active": true, "timeZone": "America/Chicago" }, "created": "2016-11-23T23:17:22.000+0000", "updated": "2016-11-23T23:17:22.000+0000" }, { "id": "403578", "author": { "name": "kiguchi", "key": "kota", "displayName": "Kota Iguchi", "active": false, "timeZone": "America/Los_Angeles" }, "body": "PR for Windows: https://github.com/appcelerator/titanium_mobile_windows/pull/903", "updateAuthor": { "name": "kiguchi", "key": "kota", "displayName": "Kota Iguchi", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2016-12-19T01:13:15.000+0000", "updated": "2016-12-19T01:13:15.000+0000" }, { "id": "403673", "author": { "name": "kiguchi", "key": "kota", "displayName": "Kota Iguchi", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Fixed for Windows: https://github.com/appcelerator/titanium_mobile_windows/pull/903", "updateAuthor": { "name": "kiguchi", "key": "kota", "displayName": "Kota Iguchi", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2016-12-20T12:28:30.000+0000", "updated": "2016-12-20T12:28:30.000+0000" }, { "id": "440600", "author": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "body": "PR: https://github.com/appcelerator/titanium_mobile/pull/10241\r\n\r\nTest-Case (use a classic \"app.js\" and create a \"test.js\" in a directory named \"dir\"): \r\n*app.js*\r\n{code:js}\r\nvar win = Ti.UI.createWindow({\r\n backgroundColor: '#fff'\r\n});\r\n\r\nvar btn1 = Ti.UI.createButton({\r\n title: 'Show __dirname and __filename',\r\n top: 100\r\n});\r\n\r\nbtn1.addEventListener('click', function() {\r\n alert('__dirname: ' + __dirname + '\\n__filename: ' + __filename);\r\n});\r\n\r\nvar btn2 = Ti.UI.createButton({\r\n title: 'require() other file',\r\n top: 200\r\n});\r\n\r\nbtn2.addEventListener('click', function() {\r\n var test = require('./dir/test');\r\n test.showProps();\r\n});\r\n\r\nwin.add(btn1);\r\nwin.add(btn2);\r\n\r\nwin.open();\r\n{code}\r\n*/dir/test.js*\r\n{code:js}\r\nexports.showProps = function () {\r\n alert('__dirname: ' + __dirname + '\\n__filename: ' + __filename);\r\n};\r\n{code}\r\n\r\n[~jquick] Are we good on Android already? The current unit-test assumes that.\r\n\r\n*EDIT*: Android does not seem to handle this so far. I'll check, but it may require some more attention from the Android team. I assumed this could work, but it does not:\r\n{code:cpp}\r\nkroll->Set(NEW_SYMBOL(isolate, \"__dirname\"), STRING_NEW(isolate, \"/\"));\r\nkroll->Set(NEW_SYMBOL(isolate, \"__filename\"), STRING_NEW(isolate, \"/app.js\"));\r\n{code}", "updateAuthor": { "name": "hknoechel", "key": "hansknoechel", "displayName": "Hans Knöchel", "active": true, "timeZone": "Europe/Berlin" }, "created": "2018-08-09T08:57:17.000+0000", "updated": "2018-08-09T12:34:48.000+0000" }, { "id": "440624", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Hmm... interesting.\r\n\r\nIn C/C\\+\\+, the equivalent would be done via macros. For example, the C/C\\+\\+ {{\\_\\_FILE\\_\\_}} preprocessor would be substituted with a string referencing the source file's path.\r\n\r\nSo, string substitution of {{\\_\\_dirname}} and {{\\_\\_filename}} in JavaScript would be an alternative solution when doing an app build, but would be problematic for LiveView. However, if there was a JavaScript equivalent of the C/C\\+\\+ {{\\_\\_LINE\\_\\_}} macro for line numbers, then string substitution would be the best solution if JS transpiling was involved.\r\n\r\nIf we were to do this natively on Android, then I believe we override the {{require()}} method in our \"module.js\" below. We should be able to set the properties per module there... or in 1 of the JS files in that directory. (I've never mucked with this part of the code, but I believe this is where the magic happens.)\r\nhttps://github.com/appcelerator/titanium_mobile/blob/master/android/runtime/common/src/js/module.js\r\n", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-08-09T19:18:27.000+0000", "updated": "2018-08-09T19:28:39.000+0000" }, { "id": "441971", "author": { "name": "smohammed", "key": "smohammed", "displayName": "Samir Mohammed", "active": true, "timeZone": "America/Los_Angeles" }, "body": "*Closing ticket.* Verified fix in SDK version {{7.5.0.v20180920040518}}. Able to use {{__dirname}} and {{__filename}} without any issues.\r\n\r\n*FR Passed (Test Steps)*\r\n# Created a new titanium application \r\n# Created a {{dir}} directory in the {{Resources}} folder and named it {{test.js}}\r\n# Copied the above code in to the files\r\n# Ran the program\r\n# Pressed {{Show __dirname and __filename}} button\r\n# {{Show __dirname and __filename}} values were returned \r\n# Pressed {{require() other file}} button \r\n# # {{Show __dirname and __filename}} values were returned \r\n\r\n*Test Environment*\r\n{code:java}\r\nAPPC Studio: 5.1.0.201808080937\r\niPhone 6 (12.0)\r\nAPPC CLI: 7.0.7-master.1\r\nOperating System Name: Mac OS High Sierra\r\nOperating System Version: 10.13.6\r\nNode.js Version: 8.9.1\r\nXcode 10.0\r\n{code}\r\n", "updateAuthor": { "name": "smohammed", "key": "smohammed", "displayName": "Samir Mohammed", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-09-24T14:16:03.000+0000", "updated": "2018-09-24T14:16:03.000+0000" } ], "maxResults": 9, "total": 9, "startAt": 0 } } }