@@ -135,24 +135,6 @@ def stop(self):
135
135
NODE_MODULES_PATH = os .path .join (PACKAGE_PATH , NODE_MODULES_FOLDER_NAME )
136
136
NODE_MODULES_BIN_PATH = os .path .join (NODE_MODULES_PATH , ".bin" )
137
137
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
-
156
138
class NodeJS (object ):
157
139
def __init__ (self , check_local = False ):
158
140
self .check_local = check_local
@@ -161,11 +143,11 @@ def __init__(self, check_local = False):
161
143
if self .check_local :
162
144
settings = get_project_settings ()
163
145
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
165
147
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
167
149
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
169
151
170
152
def eval (self , js , eval_type = "eval" , strict_mode = False ):
171
153
@@ -308,26 +290,30 @@ def __init__(self, check_local = False):
308
290
self .npm_path = ""
309
291
self .yarn_path = ""
310
292
self .cli_path = ""
293
+ self .node_js_path = ""
311
294
312
295
if self .check_local :
313
296
settings = get_project_settings ()
314
297
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
317
301
318
302
if settings ["project_settings" ]["use_yarn" ] and self .yarn_path :
319
303
self .cli_path = self .yarn_path
320
304
else :
321
305
self .cli_path = self .npm_path
322
306
323
307
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
326
311
327
312
self .cli_path = self .npm_path
328
313
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
331
317
332
318
self .cli_path = self .npm_path
333
319
@@ -338,7 +324,7 @@ def execute(self, command, command_args, chdir="", wait_terminate=True, func_std
338
324
if sublime .platform () == 'windows' :
339
325
args = [self .cli_path , command ] + command_args
340
326
else :
341
- args = [self .cli_path , command ] + command_args
327
+ args = [self .node_js_path , self . cli_path , command ] + command_args
342
328
343
329
return Util .execute (args [0 ], args [1 :], chdir = chdir , wait_terminate = wait_terminate , func_stdout = func_stdout , args_func_stdout = args_func_stdout )
344
330
@@ -377,7 +363,7 @@ def getCurrentNPMVersion(self) :
377
363
if sublime .platform () == 'windows' :
378
364
args = [self .cli_path , "-v" ]
379
365
else :
380
- args = [self .node_js_path , self . cli_path , "-v" ]
366
+ args = [self .cli_path , "-v" ]
381
367
382
368
result = Util .execute (args [0 ], args [1 :])
383
369
@@ -837,7 +823,11 @@ def execute(command, command_args, chdir="", wait_terminate=True, func_stdout=No
837
823
838
824
if wait_terminate :
839
825
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 :
841
831
842
832
lines_output = []
843
833
lines_error = []
@@ -863,7 +853,11 @@ def execute(command, command_args, chdir="", wait_terminate=True, func_stdout=No
863
853
@staticmethod
864
854
def _wrapper_func_stdout (args , func_stdout , args_func_stdout = [], chdir = "" ):
865
855
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 :
867
861
868
862
func_stdout (None , p , * args_func_stdout )
869
863
@@ -1550,12 +1544,12 @@ def run(self, **kwargs):
1550
1544
self .working_directory = self .settings [self .settings_name ]["working_directory" ]
1551
1545
1552
1546
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
1554
1548
elif self .isNpm :
1555
1549
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
1557
1551
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
1559
1553
else :
1560
1554
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 )
1561
1555
self .command = kwargs .get ("command" )
@@ -4863,7 +4857,7 @@ def start():
4863
4857
try :
4864
4858
sys .modules ["TerminalView" ]
4865
4859
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" )
4867
4861
if response == sublime .DIALOG_YES :
4868
4862
sublime .active_window ().run_command ("open_url" , args = {"url" : "https://github.com/Wramberg/TerminalView" })
4869
4863
return
@@ -4877,9 +4871,22 @@ def start():
4877
4871
4878
4872
node = NodeJS (check_local = True )
4879
4873
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 ())
4881
4887
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" )
4883
4890
if response == sublime .DIALOG_YES :
4884
4891
sublime .active_window ().run_command ("open_url" , args = {"url" : "https://nodejs.org" })
4885
4892
elif response == sublime .DIALOG_NO :
0 commit comments