kimroen / ember-cli-coffeescript

Adds precompilation of CoffeeScript files and all the basic generation types to the ember generate command.
MIT License
72 stars 49 forks source link

ember-cli-coffeescript addons, can't import from addon folder.. #75

Closed artsyca closed 9 years ago

artsyca commented 9 years ago

This may not be an ember-cli-coffeescript issue per se, but I really want to make ember-cli addons more compatible for users of this excellent addon.

Steps to reproduce:

ember g my-crafty-addon and npm install --save-dev ember-cli-coffeescript inside the addon.

So far so good. Begin coding away.

Create (for example) a component in the addon/components folder. (Manually since components can't be generated inside addons?).

Mirror this component in app/components and import/export as described here: http://edgycircle.com/blog/2014-creating-a-datepicker-ember-addon/ (a common practice for merging into the application namespace while still allowing further subclassing)

addon/components/my-component:

`import Ember from 'ember'`

MyComponent = Ember.Component.extend( ... )

`export default MyComponent`

app/components/my-component:

`import MyComponent from 'my-crafty-component/components/my-component'`

`export default MyComponent`

my-crafty-addon no longer functions! The importing app will complain about not be able to find my-crafty-addon/components/my-component

While the above steps work great for .js files, there seems to be a globbing issue that doesn't pick up .coffee files in the same configuration.

I believe this is an issue somewhat closer to the ember-cli core but I really would like to know what steps we can take to increase compatibility?

artsyca commented 9 years ago

OK! After much research, and looking at the ember-cli branch of EmberUI, Here are the steps needed to use coffeescript in your addons!

  1. Create the addon code as usual in the /addon directory of your addon.
  2. Rather than having a .coffee file in your app/ folder that imports from the folder above, make it a .js file, with the following syntax:
import Ember from 'ember';
import MySnazzyComponent from 'my-addon/components/my-snazzy-component';
export default MySnazzyComponent;
  1. Make sure to add "ember-cli-coffeescript": "^0.XX.X" to dependencies (not devDependencies!) in package.json
  2. Tests can be created in .coffee within the addon and should continue working as usual!
kimroen commented 9 years ago

Thank you very much for looking in to this! I started researching some on friday, but had to stop because of some work things that came up.

I pretty much came to the same conclusion you did, but I think this might be a slightly nicer syntax that would allow for the same overriding:

export { default } from 'my-crafty-addon/components/my-component';

This is actually the default in ember-cli as of not very long ago.

I'll finish up the pull request for in-addon component generators to be the way you suggest here (#67) (I actually ran in to this exact issue there, but the syntax was a bit in flux so I put it on hold), and then it should all be good times :)

Almost midnight here though, so I'll do this tomorrow morning and then release a new version with this and some other things.

Thanks again!

artsyca commented 9 years ago

:+1: awesome! look forward to pulling the latest release!