Closed 1000hz closed 7 years ago
Thank you! Can you tweak this so that it only adds the node_modules
path if it actually exists? For folks who are not using Node.
To use the local version of eslint you can also specify it in the .tm_properties
file:
TM_JAVASCRIPT_ESLINT_ESLINT = "${TM_PROJECT_DIRECTORY}/node_modules/.bin/eslint"
option B: use npm bin
to get the closest node_modules/.bin
folder, check for eslint
there.
In my fork I’m adding the output of npm bin
to the front of my PATH
and then using which eslint
to get the binary path.
Thank you! I’ve added similar functionality to the master branch. @meyer: For now I’m just statically adding node_modules/.bin
(if it exists). Using npm bin
would be a good idea. It would require detecting if npm
is installed etc., so for now it was easier to just add the .bin path.
@natesilva I ended up ditching npm bin
because it took too long to run. I went with a more brute-force approach:
module_dirs = File.dirname(ENV['TM_FILEPATH']).split('/')
.inject([]) {|m,o| m.push([m.last, o].compact.join('/'))}
.reverse
.map {|e| e + '/node_modules/.bin'}
# .reject {|f| !File.directory? f}
ENV['PATH'] = module_dirs.join(':') + ':' + ENV['PATH']
ESLINT_BIN = `which eslint`.chomp
ENV['TM_FILEPATH']
with a value of /Repositories/smyte/lib/file.js
becomes the following array of paths:
/Repositories/smyte/lib/node_modules/.bin
/Repositories/smyte/node_modules/.bin
/Repositories/node_modules/.bin
/node_modules/.bin
The reject
line at the end isn’t really necessary—invalid PATH
entries don’t cause any kind of complaint or slowdown in bash.
I had to add the array of node_modules
paths because I have a few repositories with node_modules
in a JS-specific subdirectory (not in the root of TM_PROJECT_DIRECTORY
).
oh oops, has this project always been written in Python? sorry, that code snippet is useless ☹️. i forgot i rewrote my thing in Ruby 🙃️
This pull request adds the project's node_modules/.bin to $PATH to allow local versions of eslint to be used