@@ -135,24 +135,6 @@ def stop(self):
135135NODE_MODULES_PATH = os .path .join (PACKAGE_PATH , NODE_MODULES_FOLDER_NAME )
136136NODE_MODULES_BIN_PATH = os .path .join (NODE_MODULES_PATH , ".bin" )
137137
138- def get_node_js_custom_path ():
139- json_file = Util .open_json (os .path .join (PACKAGE_PATH , "JavaScript Enhancements.sublime-settings" ))
140- if json_file and "node_js_custom_path" in json_file :
141- return json_file .get ("node_js_custom_path" ).strip ()
142- return ""
143-
144- def get_npm_custom_path ():
145- json_file = Util .open_json (os .path .join (PACKAGE_PATH , "JavaScript Enhancements.sublime-settings" ))
146- if json_file and "npm_custom_path" in json_file :
147- return json_file .get ("npm_custom_path" ).strip ()
148- return ""
149-
150- def get_yarn_custom_path ():
151- json_file = Util .open_json (os .path .join (PACKAGE_PATH , "JavaScript Enhancements.sublime-settings" ))
152- if json_file and "yarn_custom_path" in json_file :
153- return json_file .get ("yarn_custom_path" ).strip ()
154- return ""
155-
156138class NodeJS (object ):
157139 def __init__ (self , check_local = False ):
158140 self .check_local = check_local
@@ -161,11 +143,11 @@ def __init__(self, check_local = False):
161143 if self .check_local :
162144 settings = get_project_settings ()
163145 if settings :
164- self .node_js_path = settings ["project_settings" ]["node_js_custom_path" ] or get_node_js_custom_path ( ) or NODE_JS_EXEC
146+ self .node_js_path = settings ["project_settings" ]["node_js_custom_path" ] or javascriptCompletions . get ( "node_js_custom_path" ) or NODE_JS_EXEC
165147 else :
166- self .node_js_path = get_node_js_custom_path ( ) or NODE_JS_EXEC
148+ self .node_js_path = javascriptCompletions . get ( "node_js_custom_path" ) or NODE_JS_EXEC
167149 else :
168- self .node_js_path = get_node_js_custom_path ( ) or NODE_JS_EXEC
150+ self .node_js_path = javascriptCompletions . get ( "node_js_custom_path" ) or NODE_JS_EXEC
169151
170152 def eval (self , js , eval_type = "eval" , strict_mode = False ):
171153
@@ -308,26 +290,30 @@ def __init__(self, check_local = False):
308290 self .npm_path = ""
309291 self .yarn_path = ""
310292 self .cli_path = ""
293+ self .node_js_path = ""
311294
312295 if self .check_local :
313296 settings = get_project_settings ()
314297 if settings :
315- self .npm_path = settings ["project_settings" ]["npm_custom_path" ] or get_npm_custom_path () or NPM_EXEC
316- self .yarn_path = settings ["project_settings" ]["yarn_custom_path" ] or get_yarn_custom_path () or YARN_EXEC
298+ self .node_js_path = settings ["project_settings" ]["node_js_custom_path" ] or javascriptCompletions .get ("node_js_custom_path" ) or NODE_JS_EXEC
299+ self .npm_path = settings ["project_settings" ]["npm_custom_path" ] or javascriptCompletions .get ("npm_custom_path" ) or NPM_EXEC
300+ self .yarn_path = settings ["project_settings" ]["yarn_custom_path" ] or javascriptCompletions .get ("yarn_custom_path" ) or YARN_EXEC
317301
318302 if settings ["project_settings" ]["use_yarn" ] and self .yarn_path :
319303 self .cli_path = self .yarn_path
320304 else :
321305 self .cli_path = self .npm_path
322306
323307 else :
324- self .npm_path = get_npm_custom_path () or NPM_EXEC
325- self .yarn_path = get_yarn_custom_path () or YARN_EXEC
308+ self .node_js_path = javascriptCompletions .get ("node_js_custom_path" ) or NODE_JS_EXEC
309+ self .npm_path = javascriptCompletions .get ("npm_custom_path" ) or NPM_EXEC
310+ self .yarn_path = javascriptCompletions .get ("yarn_custom_path" ) or YARN_EXEC
326311
327312 self .cli_path = self .npm_path
328313 else :
329- self .npm_path = get_npm_custom_path () or NPM_EXEC
330- self .yarn_path = get_yarn_custom_path () or YARN_EXEC
314+ self .node_js_path = javascriptCompletions .get ("node_js_custom_path" ) or NODE_JS_EXEC
315+ self .npm_path = javascriptCompletions .get ("npm_custom_path" ) or NPM_EXEC
316+ self .yarn_path = javascriptCompletions .get ("yarn_custom_path" ) or YARN_EXEC
331317
332318 self .cli_path = self .npm_path
333319
@@ -338,7 +324,7 @@ def execute(self, command, command_args, chdir="", wait_terminate=True, func_std
338324 if sublime .platform () == 'windows' :
339325 args = [self .cli_path , command ] + command_args
340326 else :
341- args = [self .cli_path , command ] + command_args
327+ args = [self .node_js_path , self . cli_path , command ] + command_args
342328
343329 return Util .execute (args [0 ], args [1 :], chdir = chdir , wait_terminate = wait_terminate , func_stdout = func_stdout , args_func_stdout = args_func_stdout )
344330
@@ -377,7 +363,7 @@ def getCurrentNPMVersion(self) :
377363 if sublime .platform () == 'windows' :
378364 args = [self .cli_path , "-v" ]
379365 else :
380- args = [self .node_js_path , self . cli_path , "-v" ]
366+ args = [self .cli_path , "-v" ]
381367
382368 result = Util .execute (args [0 ], args [1 :])
383369
@@ -837,7 +823,11 @@ def execute(command, command_args, chdir="", wait_terminate=True, func_stdout=No
837823
838824 if wait_terminate :
839825
840- with subprocess .Popen (args , shell = True , stdin = subprocess .PIPE , stdout = subprocess .PIPE , stderr = subprocess .PIPE , cwd = (None if not chdir else chdir )) as p :
826+ env = os .environ .copy ()
827+ env ["PATH" ] = env ["PATH" ] + javascriptCompletions .get ("PATH" )
828+ shell = os .getenv ('SHELL' )
829+
830+ with subprocess .Popen (args , shell = True , executable = shell , env = env , stdin = subprocess .PIPE , stdout = subprocess .PIPE , stderr = subprocess .PIPE , cwd = (None if not chdir else chdir )) as p :
841831
842832 lines_output = []
843833 lines_error = []
@@ -863,7 +853,11 @@ def execute(command, command_args, chdir="", wait_terminate=True, func_stdout=No
863853 @staticmethod
864854 def _wrapper_func_stdout (args , func_stdout , args_func_stdout = [], chdir = "" ):
865855
866- with subprocess .Popen (args , shell = True , stdin = subprocess .PIPE , stdout = subprocess .PIPE , stderr = subprocess .PIPE , bufsize = 1 , preexec_fn = os .setsid , cwd = (None if not chdir else chdir )) as p :
856+ env = os .environ .copy ()
857+ env ["PATH" ] = env ["PATH" ] + javascriptCompletions .get ("PATH" )
858+ shell = os .getenv ('SHELL' )
859+
860+ with subprocess .Popen (args , shell = True , executable = shell , env = env , stdin = subprocess .PIPE , stdout = subprocess .PIPE , stderr = subprocess .PIPE , bufsize = 1 , preexec_fn = os .setsid , cwd = (None if not chdir else chdir )) as p :
867861
868862 func_stdout (None , p , * args_func_stdout )
869863
@@ -1550,12 +1544,12 @@ def run(self, **kwargs):
15501544 self .working_directory = self .settings [self .settings_name ]["working_directory" ]
15511545
15521546 if self .isNode :
1553- self .path_cli = self .settings ["project_settings" ]["node_js_custom_path" ] or get_node_js_custom_path ( ) or NODE_JS_EXEC
1547+ self .path_cli = self .settings ["project_settings" ]["node_js_custom_path" ] or javascriptCompletions . get ( "node_js_custom_path" ) or NODE_JS_EXEC
15541548 elif self .isNpm :
15551549 if self .settings ["project_settings" ]["use_yarn" ]:
1556- self .path_cli = self .settings ["project_settings" ]["yarn_custom_path" ] or get_yarn_custom_path ( ) or YARN_EXEC
1550+ self .path_cli = self .settings ["project_settings" ]["yarn_custom_path" ] or javascriptCompletions . get ( "yarn_custom_path" ) or YARN_EXEC
15571551 else :
1558- self .path_cli = self .settings ["project_settings" ]["npm_custom_path" ] or get_npm_custom_path ( ) or NPM_EXEC
1552+ self .path_cli = self .settings ["project_settings" ]["npm_custom_path" ] or javascriptCompletions . get ( "npm_custom_path" ) or NPM_EXEC
15591553 else :
15601554 self .path_cli = self .settings [self .settings_name ]["cli_custom_path" ] if self .settings [self .settings_name ]["cli_custom_path" ] else ( javascriptCompletions .get (self .custom_name + "_custom_path" ) if javascriptCompletions .get (self .custom_name + "_custom_path" ) else self .cli )
15611555 self .command = kwargs .get ("command" )
@@ -4863,7 +4857,7 @@ def start():
48634857 try :
48644858 sys .modules ["TerminalView" ]
48654859 except Exception as err :
4866- response = sublime .yes_no_cancel_dialog ("TerminalView plugin is missing. TerminalView is required to be able to use \" JavaScript Enhancements\" plugin. Do you want open the github repo of it?" , "Yes, open it" , "No" )
4860+ response = sublime .yes_no_cancel_dialog ("TerminalView plugin is missing. TerminalView is required to be able to use \" JavaScript Enhancements\" plugin.\n \n Do you want open the github repo of it?" , "Yes, open it" , "No" )
48674861 if response == sublime .DIALOG_YES :
48684862 sublime .active_window ().run_command ("open_url" , args = {"url" : "https://github.com/Wramberg/TerminalView" })
48694863 return
@@ -4877,9 +4871,22 @@ def start():
48774871
48784872 node = NodeJS (check_local = True )
48794873 try :
4880- node .getCurrentNodeJSVersion ()
4874+ print (node .getCurrentNodeJSVersion ())
4875+ except Exception as err :
4876+ print (err )
4877+ response = sublime .yes_no_cancel_dialog ("Error during installation: \" node.js\" seems not installed on your system. Node.js and npm are required to be able to use JavaScript Enhancements plugin.\n \n If you are using \" nvm\" or you have a different path for node.js and npm, please then change the path on:\n \n Preferences > Package Settings > JavaScript Enhancements > Settings\n \n and restart Sublime Text.\n \n If this doesn't work then try also to add the path of their binaries in the PATH key-value on the same JavaScript Enhancements settings file. This variable will be used to add them in the $PATH environment variable, so put the symbol \" :\" in front of your path.\n \n Do you want open the website of node.js?" , "Yes, open it" , "Or use nvm" )
4878+ if response == sublime .DIALOG_YES :
4879+ sublime .active_window ().run_command ("open_url" , args = {"url" : "https://nodejs.org" })
4880+ elif response == sublime .DIALOG_NO :
4881+ sublime .active_window ().run_command ("open_url" , args = {"url" : "https://github.com/creationix/nvm" })
4882+ return
4883+
4884+ npm = NPM (check_local = True )
4885+ try :
4886+ print (npm .getCurrentNPMVersion ())
48814887 except Exception as err :
4882- response = sublime .yes_no_cancel_dialog ("Error during installation: node.js is not installed on your system. Node.js and npm are required to be able to use JavaScript Enhancements plugin. Do you want open the website of node.js?" , "Yes, open it" , "Or use nvm" )
4888+ print (err )
4889+ response = sublime .yes_no_cancel_dialog ("Error during installation: \" npm\" seems not installed on your system. Node.js and npm are required to be able to use JavaScript Enhancements plugin.\n \n If you are using \" nvm\" or you have a different path for node.js and npm, please change their custom path on:\n \n Preferences > Package Settings > JavaScript Enhancements > Settings\n \n and restart Sublime Text.\n \n If this doesn't work then try also to add the path of their binaries in the PATH key-value on the same JavaScript Enhancements settings file. This variable will be used to add them in the $PATH environment variable, so put the symbol \" :\" in front of your path.\n \n Do you want open the website of node.js?" , "Yes, open it" , "Or use nvm" )
48834890 if response == sublime .DIALOG_YES :
48844891 sublime .active_window ().run_command ("open_url" , args = {"url" : "https://nodejs.org" })
48854892 elif response == sublime .DIALOG_NO :
0 commit comments