Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-27888] iOS: circular references in require don't work

GitHub Issuen/a
TypeBug
PriorityNone
StatusClosed
ResolutionFixed
Resolution Date2021-01-13T16:11:56.000+0000
Affected Version/sn/a
Fix Version/sRelease 10.0.0
ComponentsiOS
LabelsengSchedule
ReporterChristopher Williams
AssigneeChristopher Williams
Created2020-05-07T15:53:01.000+0000
Updated2021-01-29T17:11:53.000+0000

Description

While Android's require implementation is able to handle circular references - iOS is not. This is due to the underlying implementations - where Android is written in JS and mimics Node.js, while iOS is native. There's multiple possible solutions here: - Use rollup under the hood on apps as part of our build process. - Migrate iOS to use a shared require implementation with Android I personally prefer the second, but it'd take some re-architecting of how iOS starts up - and it's unclear to me how we'd tweak Android to use a require implementation under common rather than the one baked into the the runtime (the JS is baked in as bytes and executed early).

Comments

  1. Christopher Williams 2021-01-13

    Merged to master (along with large refactor to help unify require implementations cross-platform). Unit tests confirm the fix.
  2. Samir Mohammed 2021-01-29

    *Closing ticket*, verified in SDK version 10.0.0.v20210126123332. *+Test case:+* app.js
       const b = require('./b');
       
       b.log();
       
       exports.value = 'a thing';
       
       b.log();
       
       
    b.js
       const a = require('./app.js');
       
       exports.log = function () {
        console.log(a.value);
       }
       
       
    *+Test Environment+*
       MacOS Big Sur: 11.1 
       Xcode: 12.3
       Java Version: 1.8.0_242
       Android NDK: 21.3.6528147
       Node.js: 12.18.1
       ""NPM":"5.0.0","CLI":"8.1.1""
       iPhone 8 14.4
       

JSON Source