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

Support Linked addons #11

Open
ctataryn opened this issue Apr 11, 2017 · 5 comments
Open

Support Linked addons #11

ctataryn opened this issue Apr 11, 2017 · 5 comments

Comments

@ctataryn
Copy link

I use npm link while in development so I can develop my addons and realize the changes immediately when running ember serve against my application that uses them.

I was wondering if it is possible to have this plugin "know about" the source folder for my addon such that when I use gf on a HandleBars component it'll find the source for it in the addon folder?

@ctataryn
Copy link
Author

Even if I have to specify the extra addon paths manually for the plugin to use, that's fine

@AndrewRadev
Copy link
Owner

AndrewRadev commented Apr 12, 2017

This seems like a nice functionality to have. Just to be clear, the addon is installed somewhere in the node_modules directory, correct? The npm link command creates a symlink to it? So, the logic could be something like:

  • gf on a component
  • Check if there is a component under app/components/<component-name>
  • If not, check if there's a component somewhere under node_modules, following symlinks

For the last step, could you describe what the path to this component would look like? To be honest, I've never written an addon, so I'm not sure what to look for. A guide to writing addons might help, but a concrete example would be even more useful (something like, "here's the github repo of one such addon, it would be installed under node_modules/foo/bar/...").

@ctataryn
Copy link
Author

@AndrewRadev You got it. the entry in my application's node_modules for the addon in question (after doing the npm link) is as follows:

$ ls node_modules
lrwxrwxrwx 1 ctatar01 Domain Users 69 Apr  3 11:36 my-ui-addon -> /c/Users/ctatar01/AppData/Roaming/npm/node_modules/my-ui-addon//

Not sure what the deal is with the double // at the end of the target, but essentially it's a symlink as you described. If you take a look at the folder it's linking to, it symlinks to the actual folder on my hard drive where my addon is located:

$ls -al /c/Users/ctatar01/AppData/Roaming/npm/node_modules/my-ui-addon
lrwxrwxrwx 1 ctatar01 Domain Users 31 Apr  3 11:34 /c/Users/ctatar01/AppData/Roaming/npm/node_modules/my-ui-addon -> /c/workspace/my-ui-addon//

It'd actually be a good idea to detect whether the current project is itself an addon (i.e. check for the existence of an addon folder). The reason being is, when you are developing an addon, the app folder basically just contains a bunch of shim files that extend from the actual files located under ../addon. For instance:

// app/components/api-version-check.js
export { default } from 'my-ui-addon/components/api-version-check';

I guess this all gets transpiled properly to fulfill that export, but really the code for api-version-check is really in addon/components/api-version-check.js not app/components/api-version-check.js. So for gf and :A you'd want to be able to navigate to the file in the proper folder. ( I realize :A is from a different plugin, but if you know how to facilitate what I've described through the .projections.json file I'd be much appreciative.

Adding this bit of functionality would be great for me, a heavy user of custom addons. 👍

@ctataryn
Copy link
Author

@AndrewRadev if you'd like I can take a shot at implementing this

@AndrewRadev
Copy link
Owner

Well, I created a test addon to experiment with, but I give no guarantees about when I'd really get around to it. If you'd like to try it out yourself, I'd certainly appreciate a PR, even if it's incomplete. There are tests, if you can get a ruby environment going, so you'd have some feedback if you accidentally break something. You might even write a test or two to guide you as you work, I think they're fairly straightforward to write for the gf cases in particular.

Either way, I'll see when I can get around to it as well and I'll let you know if I have something working.

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