Closed lencioni closed 8 years ago
This is something I've been thinking about too. I think it should be fairly simple to implement. We just have to take the path to the current file into account when resolving the import. One thing that worries me though is how do we know when it's okay to do a relative import? Is lookup_path != 'node_modules'
okay?
Yep, I think that's all you need to do.
How would you feel about changing the lookup_paths
to allow something like this:
"lookup_paths": [
"foo",
{ "path": "bar", "use_relative_paths": true },
"baz"
]
I'm a little scared that it will end up creating imports that look something like this:
import Foo from '../../../../bar/baz/Foo'
. Or perhaps this sort of thing is mostly suited for smaller projects, in which case we could just add a global use_relative_paths
configuration. node_modules
isn't meant to be part of lookup_paths
anyway.
How would you feel about changing the
lookup_paths
to allow something like this
I feel like people are going to probably want this on a per-project level with the only exception being node_modules (which is already treated specially in import-js). I think the option should likely be at the top level.
We may eventually want to add options per lookup path, but I don't think we should until we actually have a real need for it.
I'm a little scared that it will end up creating imports that look something like this:
import Foo from '../../../../bar/baz/Foo'
Yeah, it might create imports looking like that, depending on how your project is structured. But, I think it should be up to the consumer to decide if that is acceptable or not.
We may eventually want to add options per lookup path, but I don't think we should until we actually have a real need for it.
Agreed
Yeah, it might create imports looking like that, depending on how your project is structured. But, I think it should be up to the consumer to decide if that is acceptable or not.
Yep
Fixed by fd81fffe06d3e39599347b7fe11004daa78c040f
As seen in this code snippet, some projects prefer relative paths for non-node_modules modules:
It would be nice if ImportJS was able to support this.