-
Notifications
You must be signed in to change notification settings - Fork 70
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
Crazy relative paths for some people #233
Comments
Interesting. I'd be surprised if it goes all the way to the root, because we strip out (at least from what it looks like) the path up until (and including) the project path. It would be interesting to see what ruby versions they use, though I doubt that's the problem. In order to track this down, it would be great if you could try a few things:
# @param make_relative_to [String]
def make_relative_to(make_relative_to)
return unless lookup_path
# Prevent mutating the argument that was passed in
make_relative_to = make_relative_to.dup
# First, strip out any absolute path up until the current directory
make_relative_to.sub!("#{Dir.pwd}/", '')
# Ignore if the file to relate to is part of a different lookup_path
return unless make_relative_to.start_with? lookup_path
# Strip out the lookup_path
make_relative_to.sub!(%r{^#{Regexp.escape(lookup_path)}/}, '')
puts 'DEBUG INFO'
puts lookup_path
puts Dir.pwd
puts import_path
puts make_relative_to
path = Pathname.new(import_path).relative_path_from(
Pathname.new(File.dirname(make_relative_to))
).to_s
# `Pathname.relative_path_from` will not add "./" automatically
path = './' + path unless path.start_with?('.')
self.import_path = path
end |
I should have mentioned that when I looked at this with @ljharb, we tried the CLI tool and everything was good there, which makes me think that there might be something weird going on with the Update: I was unable to reproduce through symlink shenanigans. |
As for Ruby versions, this was the same with system 2.3 and 2.0 (working on the CLI, not in sublime). It didn't work in 1.9.3 at all. |
@ljharb can you try adding the debugging code and reporting back here what On Sat, Mar 19, 2016, 3:27 PM Jordan Harband notifications@github.com
|
Where does that debug output end up? |
It should appear at the top of the file you are editing On Sat, Mar 19, 2016, 5:20 PM Jordan Harband notifications@github.com
|
ok so while trying to add the debug code, I ended up removing every copy of the import_js gem, and reinstalling it just under I can now use "goto module" in sublime somewhat (sometimes it opens a new file at the path but without the extension) but the linter still doesn't work, and when i select "fix all", i get: Error when executing import-js:
/usr/local/lib/ruby/gems/2.3.0/gems/import_js-0.6.0/lib/import_js/importer.rb:190:in `run_eslint_command': env: node: No such file or directory (ImportJS::ParseError)
from /usr/local/lib/ruby/gems/2.3.0/gems/import_js-0.6.0/lib/import_js/importer.rb:78:in `fix_imports'
from /usr/local/lib/ruby/gems/2.3.0/gems/import_js-0.6.0/bin/import-js:66:in `<top (required)>'
from /usr/local/bin/import-js:23:in `load'
from /usr/local/bin/import-js:23:in `<main>' Let's debug this in person on Monday :-) |
It would be interesting to see if this is still an issue with the new Node binary. |
Yeah, I'm hoping we've resolved this. We are currently blocked on wbond/package_control_channel#5463 being merged. |
Doesn't seem to be resolved for me! 😮 |
We had code in place which would strip out the path to the current directory from the path to the current file. That bit of code wasn't working, since we were feeding the String.replace with a string instead of a regexp. This resulted in relative paths not working correctly in Sublime (which passes in absolute paths for pathToCurrentFile). We could make that plugin also pass local paths, but I figured it was worth fixing this in the main project anyway, because the command-line tool needs to support these paths. Fixes #263, which is likely a duplicate of #233.
I believe 599a684 should fix this issue. Sorry for the long wait. |
I've been working with some folks to get import-js set up, and I've seen this happen with @ljharb and @iancmyers. It is a bit puzzling to me, and I have not figured out how to reproduce in my environment, but here's what I know.
Symptoms
ImportJS seems to work pretty okay, except when resolving relative paths, we end up seeing a LOT of
../../../
. It looks like it goes all the way up to/
and then back into the project. This is very obvious when there are multiple modules to pick from, and definitely not what we want to be happening. This includes files that should be in the same directory (e.g../foo
comes up as `../../../../../../path/to/the/thing/foo').@ljharb
Jordan is using Sublime, rvm, and nvm. He has no system node installed.
@iancmyers
Ian is using Atom, rbenv, and I'm not sure about other details.
These are all happening in the same project that I am working with, and are using version 0.6.0 of the gem.
The text was updated successfully, but these errors were encountered: