medikoo / cli-color

Colors and formatting for the console
ISC License
676 stars 34 forks source link

Fix compatibility issue with modules that have google/traceur-compiler as a dependency #10

Closed jas closed 10 years ago

jas commented 10 years ago

traceur-compiler adds a polyfill for Object.defineProperty, which breaks cli-color by causing the color functions on the clc object to be undefined.

Example:

TypeError: Property 'green' of object function (/*…msg*/) {
        var data = fn._cliColorData, close = '';
        return reduce(data, function (str, mod) {
            close = '\x1b[' + mod[1] + 'm' + close;
            return str + '\x1b[' + mod[0] + 'm';
        }, '', true) + join.call(arguments, ' ') + close;
    } is not a function

It appears that the polyfill doesn't properly return an object. This commit rearranges cli-color's use of Object.defineProperty slightly in order to fix this rather unfortunate compatibility issue.

Object.defineProperties isn't affected.

I realize this is not an issue with cli-color in itself, but given how far down the dependency chain the real issue is, I'm hoping this change is trivial and will be acceptable here.

I opened several issues on other repos as I searched to figure out what exactly was causing this. Here they are for reference:

medikoo commented 10 years ago

@jas to me it looks as terrible bug in traceur-compiler, have you opened issue over there?

I'm reluctant to accept patches which workaround issues of other third-party modules

jas commented 10 years ago

That's understandable.

There may me a way to fix this in es6ify, which is the module that has traceur-compiler as a dependency, or es6-module-transpiler, which has es6ify as a dependency.

I actually ran into this issue when I tried to use cli-color and es6-module-transpiler together (I'm not directly using traceur-compiler, and it's 3 levels deep in dependencies, so I have very little control over all of this unfortunately).

I'll look into opening an issue on traceur-compiler. I've opened several issues on other repos (linked above). Hopefully I will be able to continue to use cli-color.

Thank you for taking the time to look at this pull request!