ef4 / ember-browserify

ember-cli addon for easily loading CommonJS packages from npm via browserify.
MIT License
172 stars 28 forks source link

Error when consumed by an addon and not an app #29

Closed asakusuma closed 9 years ago

asakusuma commented 9 years ago

In /lib/index.js, the included hook appears to assume that the passed argument is an app.

This is true if an app is directly consuming ember-browserify. From what I can tell, if an addon is consuming ember-browserify, the passed argument has a property called app, but is not an app object itself. This causes an error on the first line of the included hook because app.options is undefined.

included: function(app){
    var enableSourcemaps = app.options.sourcemaps && app.options.sourcemaps.enabled && app.options.sourcemaps.extensions.indexOf('js') > -1;

    this.app = app;
...
}
Cannot read property 'sourcemaps' of undefined
TypeError: Cannot read property 'sourcemaps' of undefined
ef4 commented 9 years ago

This is a problem in general with ember-cli addons. There is not a good API yet. See also https://github.com/ember-cli/ember-cli/issues/3718

asakusuma commented 9 years ago

I see. Are you opposed to a temp solution like this?

//edit: at the top of included hook
if (typeof app.import !== 'function' && app.app) {
   app = app.app;
}

Tried that locally and it works. If app.import isn't a function, the thing won't work anyways.

chadhietala commented 9 years ago

I think the reason why this doesn't currently work in ember-cli is because you enter in the "deps of deps" problem and currently there is no way to dedupe. Your hack may need to do for now.

ef4 commented 9 years ago

@asakusuma that seems ok to me.

asakusuma commented 9 years ago

Great, I will open a PR