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

Expand API to get access to dependencies or module #132

Open
alexander-alvarez opened this issue Nov 21, 2017 · 4 comments
Open

Expand API to get access to dependencies or module #132

alexander-alvarez opened this issue Nov 21, 2017 · 4 comments

Comments

@alexander-alvarez
Copy link

Currently we can only get to the exports of the module resolved, not the actual module itself.

My use case is this:
I have a series of tests cases that test default export of a module, who's classes changes depending on environment variable -- the "classes changing depending on environment variable" was the easiest way I could integrate these two different solutions (temporarily)

In order to do this, I have to unsee the imported modules, so that the next time ember tries to resolve them, they will be reevaluated. One of my problems is that since (to my knowledge) I can't access the dependencies of the file, and addon files are reexported app -> addon, I can't programatically get to the underlying addon file to have it reexported.

// right now I hard code, which is fine since this is temporary
require.unsee('my-addon/serializer/user');
require.unsee('my-app/serializer/user');

// I feel as though I should be able to do something like
const module = resolver.findModule('serializer:user');
// unsee module and it's deps so they are re-evaluated even if the serializer comes from an addon.

Thoughts or ideas?

@alexander-alvarez
Copy link
Author

@stefanpenner thoughts?

@rwjblue
Copy link
Member

rwjblue commented Nov 28, 2017

Based on a conversation with @krisselden, I believe that we should refactor things to essentially ref-count, so we can also unsee all modules which are no longer in use after unseeing the only module that depended on them. I believe that this would satisfy the issue you described above?

@alexander-alvarez
Copy link
Author

I think this would work for most cases.

Not sure if it still holds up when inheritance is in the picture:

BaseComponent
ClassA extends BaseComponent
ClassB extends BaseComponent
// my-addon/addon/component/base.js
class Base {}
// my-addon/addon/component/class-a.js 
import Base from './base';
// my-addon/addon/component/class-b.js 
import Base from './base';

// re-exports
// my-addon/app/component/base.js
export { default } from 'my-addon/base'
// my-addon/app/component/class-a.js
export { default } from 'my-addon/components/class-a'
// my-addon/app/component/class-b.js
export { default } from 'my-addon/components/class-b'

If we didn't have the other classes extending from base, and we unsee my-addon/app/component/base.js then my-addon/addon/components/base would have only been used in one place and should be unseen (given the logic explained above).

However with other classes importing my-addon/addon/components/base, then there would still be other modules that depend on it.

@stefanpenner
Copy link
Contributor

stefanpenner commented Nov 29, 2017

Based on a conversation with @krisselden, I believe that we should refactor things to essentially ref-count, so we can also unsee all modules which are no longer in use after unseeing the only module that depended on them. I believe that this would satisfy the issue you described above?

IMHO this to too much complexity to add.

If this is really needed, then in complex cases, why not just purge all modules that match some known prefix like <appname>?

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

3 participants