Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding an array as property of a new key #20

Closed
amir-rahnama opened this issue Apr 24, 2014 · 2 comments
Closed

Adding an array as property of a new key #20

amir-rahnama opened this issue Apr 24, 2014 · 2 comments

Comments

@amir-rahnama
Copy link

gruntConfig = {
        env: {
            //dynamically created. 
            chrome: {
                CAPS: []
            }
        }
};

grunt.registerTask('test:sauce:' + key, ['env:' + key + ':CAPS']);

I dynamically create the above config for grunt-dev but when later I wanna grab the CAPS in my test file, I realize that it is empty.

Why is that?
When I set the gruntConfig.env

screen shot 2014-04-25 at 10 27 03

When I wanna get the gruntConfig.env
screen shot 2014-04-25 at 10 27 25

@amir-rahnama
Copy link
Author

Any updates on this?

This is happening because you are not deep extending the object in the following code chunk:

function add(value, key) {
    if (process.env[key]) return grunt.log.writeln(key + ' already exists, leaving unchanged.');

    var data = {};
    data[key] = value;
    _.extend(process.env, data);
  }

@jsoverson
Copy link
Owner

This is expected behavior outside of grunt-env. Environment variables are strings only, so your array is being toString()ed into an empty ""

I'll add this as a reminder in the readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants