[ALOY-1206] Alloy compiler doesn't regenerate controllers if only change is made to the distribution target

GitHub Issuen/a
Resolution Date2015-01-13T08:09:27.000+0000
Affected Version/sAlloy 1.5.1
Fix Version/sAlloy 1.7.0
Labelscompiler, optimalization
ReporterFokke Zandbergen
AssigneeTim Poulsen


When building for a different target environment (development, test or production) conditional code in app/alloy.js is not updated in Resources/\[platform\]/app.js. This can cause serious errors when relying on the conditions for particular behaviour in ad-hoc and app store builds.

Test case

1. Create a project: ti create -t app -p ios -n conditions --id test.conditions -d . 2. Make it Alloy: cd conditions && alloy new 3. Insert the following snippet in both app/alloy.js and app/controllers/index.js:
if (ENV_PRODUCTION) console.debug('if (ENV_PRODUCTION)');
if (ENV_TEST) console.debug('if (ENV_TEST)');
if (ENV_DEV) console.debug('if (ENV_DEVELOPMENT)');
4. Build the production for Simulator: ti build -p ios -b 5. Confirm that both Resources/iphone/app.js and Resources/iphone/alloy/controllers/index.js only have console.debug("if (ENV_DEVELOPMENT)"); which is correct 6. Build for ad-hoc or to device: ti build -p ios --target dist-adhoc 7. Confirm that Resources/iphone/app.js still has console.debug("if (ENV_DEVELOPMENT)"); while Resources/iphone/alloy/controllers/index.js is correctly updated to have console.debug("if (ENV_PRODUCTION)");


  1. Tim Poulsen 2014-12-17 Alloy's compilation process attempts to speed the operation by skipping some portions of the process if files are reasonably expected to be unchanged. The algorithm does not currently consider build target changes, though it appears it should. As a workaround, update one or more JS files in your app so that the app's controllers are regenerated with the updated values.
  2. Fokke Zandbergen 2014-12-18 That workaround doesn't work... it's about the alloy.js. The related code is at: https://github.com/appcelerator/alloy/blob/master/Alloy/commands/compile/index.js#L349-L352
  3. Tim Poulsen 2014-12-29 PR https://github.com/appcelerator/alloy/pull/646 What I've done is update the Orphanage / controller-reuse logic to always regenerate app.js & controllers/index.js when building for something other than a development target (test, dist-adhoc, dist-appstore, etc.). Functional test using Fokke's steps above. Additionally, you can/should check that controllers are regenerated with ti build -p ios -T device
  4. Feon Sua Xin Miao 2015-01-13 PR merged.

JSON Source