Titanium JIRA Archive
Alloy (ALOY)

[ALOY-1199] Deep merge config.json

GitHub Issuen/a
TypeImprovement
PriorityMedium
StatusOpen
ResolutionUnresolved
Affected Version/sAlloy 1.11.0
Fix Version/sn/a
ComponentsRuntime
Labelscompile, compiler
Reporterme@gmail.com
AssigneeTim Poulsen
Created2014-08-13T02:07:22.000+0000
Updated2020-11-17T22:14:36.000+0000

Description

Action: A config.json file with the following contents is added to the project:
{
    "global": {
        "theme":"default",
        "dir": {
            "template": "/"
        }
    },
    "env:development": {},
    "env:test": {},
    "env:production": {},
    "os:ios": {
        "theme":"ios"
    },
    "os:android": {
        "theme":"android"
    },
    "os:mobileweb":{
        "theme":"mobileweb"
    },
    "dependencies": {}
}
Expected result: Should result in alloy looking for templates in the root directory of the system. Actual result: An error is thrown of "Arguments to path.join must be strings" in the alloy compile due to the rest of the dir paths not being set in the config.json file. allow uses _.defaults and this does a "shallow" style clone rather then deep. lo-dash has a fix for this already (well... provided a workaround, the community has made modules from this workaround) ... sadly underscore has not yet fixed this as far as I can tell. Creating a workaround for underscore should not be difficult though Example use case: Wanting to override the alloy templates for a project, and so wanting to change the template directory for the project to a custom one

Comments

  1. Mauro Parra-Miranda 2014-12-10

    Original Reporter: me@mattapperson.com
  2. Fokke Zandbergen 2015-02-14

    Another use case is to have platform-specific widget-dependencies:
       {
         "global": {
           "dependencies": {
             "foo": "1.0"
           }
         },
         "os:ios": {
           "dependencies": {
             "bar": "1.0"
           }
         }
       }
       
    Right now the result is:
       module.exports = {
         "dependencies": {
           "bar": "1.0"
         }
       };
       
    Where with deep merge you'd get:
       module.exports = {
         "dependencies": {
           "foo": "1.0",
           "bar": "1.0"
         }
       };
       
  3. Fokke Zandbergen 2015-02-14

    A sub-task should be created to document the added support for platform/environment specific widget-dependencies.
  4. Creative 2015-07-23

    Why is this actually being generated form a json file? It would be much more convenient to just use a config.js file with some exports for each of the platforms/deployment-types. Then we can also use variables and the likes. This, together with a deep-merge functionality will make this a much better setup!
  5. Fokke Zandbergen 2015-08-13

    [~uzbbert] that's actually a good idea and also what we do for Arrow. Can you create a new JIRA ticket requesting this and link it to this one?
  6. Creative 2016-11-17

    bump can this priority be increased? If we could change this file to a config.js I could actually use my own implementation, which is using Lodash's _.merge() or _.extend() which can deep merge the config files. Sadly underscore doesnt have deep merge at the moment
  7. Creative 2017-10-09

    can this priority be increased? Also please consider TIMOB-24162
  8. Muhammad Qasim 2020-11-17

    In my case it is multiple themes. config.json files from different themes are not truly merged so you can't inherit common configs from global config.json so have to copy over full file per theme. I think its related to this ticket.
  9. Creative 2020-11-17

    ---
  10. Muhammad Qasim 2020-11-17

    There are no limitations if you could write native modules or use Hyperloop. Thanks for the suggestion though :)

JSON Source