Skip to content

Commit 960422c

Browse files
fixes for node.js and npm custom path, added PATH in global settings
1 parent bae5edc commit 960422c

File tree

9 files changed

+175
-76
lines changed

9 files changed

+175
-76
lines changed

JavaScript Enhancements.sublime-settings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"enable_can_i_use_menu_option": true,
3+
"PATH": "",
34
"node_js_custom_path": "node",
45
"npm_custom_path": "npm",
56
"yarn_custom_path": "yarn",

_generated_2018_01_02_at_13_16_08.py renamed to _generated_2018_01_02_at_20_54_26.py

Lines changed: 44 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -135,24 +135,6 @@ def stop(self):
135135
NODE_MODULES_PATH = os.path.join(PACKAGE_PATH, NODE_MODULES_FOLDER_NAME)
136136
NODE_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-
156138
class 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\nDo 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\nIf you are using \"nvm\" or you have a different path for node.js and npm, please then change the path on:\n\nPreferences > Package Settings > JavaScript Enhancements > Settings\n\nand restart Sublime Text.\n\nIf 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\nDo 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\nIf you are using \"nvm\" or you have a different path for node.js and npm, please change their custom path on:\n\nPreferences > Package Settings > JavaScript Enhancements > Settings\n\nand restart Sublime Text.\n\nIf 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\nDo 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:

changelog/0.1.10.txt

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
v0.1.10
2+
3+
## Fixes
4+
5+
- fixed node.js and npm custom path
6+
- Added "PATH" key-value in the global setting
7+
8+
see the Wiki - Fixing node.js and npm custom path for the explanation:
9+
https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki/Installation#fixing-nodejs-and-npm-custom-path
10+
11+
12+
=================================================================
13+
** THIS PLUGIN IS IN BETA! Thanks for your support in advance! **
14+
=================================================================
15+
16+
If you like it, remember to star it ⭐ on GitHub: https://github.com/pichillilorenzo/JavaScriptEnhancements
17+
18+
** USAGE **
19+
===========
20+
21+
See how it works on the Wiki: 👉👉 https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki 👈👈
22+
23+
24+
** WHAT IS THIS? **
25+
===================
26+
27+
This plugin uses Flow (javascript static type checker from Facebook) under the hood.
28+
29+
It offers better javascript autocomplete and a lot of features about creating,
30+
developing and managing javascript projects, such as:
31+
32+
- Cordova projects (run cordova emulate, build, compile, serve, etc. directly from Sublime Text!)
33+
- Ionic v1 and v2 projects (same as Cordova projects!)
34+
- Angular v1 and v2 projects
35+
- React projects
36+
- Express projects
37+
- Yeoman generators
38+
- Local bookmarks project
39+
- JavaScript real-time errors
40+
- etc.
41+
42+
You could use it also in existing projects (see the Wiki - https://github.com/pichillilorenzo/JavaScriptEnhancements/wiki)!
43+
44+
It turns Sublime Text into a JavaScript IDE like!
45+
46+
This project is based on my other Sublime Text plugin JavaScript Completions (https://github.com/pichillilorenzo/JavaScript-Completions)
47+
48+
** NOTE **
49+
If you want use this plugin, you may want uninstall/disable the JavaScript Completions plugin, if installed.
50+
51+
** OS SUPPORTED NOW **
52+
======================
53+
54+
👉 Linux (64-bit)
55+
👉 Mac OS X
56+
57+
❗❗ Dependencies ❗❗
58+
=======================
59+
60+
In order to work properly, this plugin has some dependencies:
61+
62+
👉 Sublime Text 3 (build 3124 or newer)
63+
👉 Node.js and npm (https://nodejs.org or nvm (https://github.com/creationix/nvm))
64+
👉 TerminalView sublime text plugin (https://github.com/Wramberg/TerminalView)
65+
66+
Not required, but useful for typescript files (Flow wont work on this type of files):
67+
68+
👉 TypeScript sublime text plugin (https://github.com/Microsoft/TypeScript-Sublime-Plugin)
69+
70+
** Flow Requirements **
71+
=======================
72+
73+
It use [Flow](https://github.com/facebook/flow) for type checking and auto-completions.
74+
75+
👉 Mac OS X
76+
👉 Linux (64-bit)
77+
👉 Windows (64-bit)
78+
79+
Email me for any questions or doubts about this new project on: pichillilorenzo@gmail.com
80+
81+
Thanks for your support! 😄😄
82+
83+
MIT License

helper/node/main.py

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,6 @@
99
NODE_MODULES_PATH = os.path.join(PACKAGE_PATH, NODE_MODULES_FOLDER_NAME)
1010
NODE_MODULES_BIN_PATH = os.path.join(NODE_MODULES_PATH, ".bin")
1111

12-
def get_node_js_custom_path():
13-
json_file = Util.open_json(os.path.join(PACKAGE_PATH, "JavaScript Enhancements.sublime-settings"))
14-
if json_file and "node_js_custom_path" in json_file :
15-
return json_file.get("node_js_custom_path").strip()
16-
return ""
17-
18-
def get_npm_custom_path():
19-
json_file = Util.open_json(os.path.join(PACKAGE_PATH, "JavaScript Enhancements.sublime-settings"))
20-
if json_file and "npm_custom_path" in json_file :
21-
return json_file.get("npm_custom_path").strip()
22-
return ""
23-
24-
def get_yarn_custom_path():
25-
json_file = Util.open_json(os.path.join(PACKAGE_PATH, "JavaScript Enhancements.sublime-settings"))
26-
if json_file and "yarn_custom_path" in json_file :
27-
return json_file.get("yarn_custom_path").strip()
28-
return ""
29-
3012
class NodeJS(object):
3113
def __init__(self, check_local = False):
3214
self.check_local = check_local
@@ -35,11 +17,11 @@ def __init__(self, check_local = False):
3517
if self.check_local :
3618
settings = get_project_settings()
3719
if settings :
38-
self.node_js_path = settings["project_settings"]["node_js_custom_path"] or get_node_js_custom_path() or NODE_JS_EXEC
20+
self.node_js_path = settings["project_settings"]["node_js_custom_path"] or javascriptCompletions.get("node_js_custom_path") or NODE_JS_EXEC
3921
else :
40-
self.node_js_path = get_node_js_custom_path() or NODE_JS_EXEC
22+
self.node_js_path = javascriptCompletions.get("node_js_custom_path") or NODE_JS_EXEC
4123
else :
42-
self.node_js_path = get_node_js_custom_path() or NODE_JS_EXEC
24+
self.node_js_path = javascriptCompletions.get("node_js_custom_path") or NODE_JS_EXEC
4325

4426
def eval(self, js, eval_type="eval", strict_mode=False):
4527

@@ -182,26 +164,30 @@ def __init__(self, check_local = False):
182164
self.npm_path = ""
183165
self.yarn_path = ""
184166
self.cli_path = ""
167+
self.node_js_path = ""
185168

186169
if self.check_local :
187170
settings = get_project_settings()
188171
if settings :
189-
self.npm_path = settings["project_settings"]["npm_custom_path"] or get_npm_custom_path() or NPM_EXEC
190-
self.yarn_path = settings["project_settings"]["yarn_custom_path"] or get_yarn_custom_path() or YARN_EXEC
172+
self.node_js_path = settings["project_settings"]["node_js_custom_path"] or javascriptCompletions.get("node_js_custom_path") or NODE_JS_EXEC
173+
self.npm_path = settings["project_settings"]["npm_custom_path"] or javascriptCompletions.get("npm_custom_path") or NPM_EXEC
174+
self.yarn_path = settings["project_settings"]["yarn_custom_path"] or javascriptCompletions.get("yarn_custom_path") or YARN_EXEC
191175

192176
if settings["project_settings"]["use_yarn"] and self.yarn_path :
193177
self.cli_path = self.yarn_path
194178
else :
195179
self.cli_path = self.npm_path
196180

197181
else :
198-
self.npm_path = get_npm_custom_path() or NPM_EXEC
199-
self.yarn_path = get_yarn_custom_path() or YARN_EXEC
182+
self.node_js_path = javascriptCompletions.get("node_js_custom_path") or NODE_JS_EXEC
183+
self.npm_path = javascriptCompletions.get("npm_custom_path") or NPM_EXEC
184+
self.yarn_path = javascriptCompletions.get("yarn_custom_path") or YARN_EXEC
200185

201186
self.cli_path = self.npm_path
202187
else :
203-
self.npm_path = get_npm_custom_path() or NPM_EXEC
204-
self.yarn_path = get_yarn_custom_path() or YARN_EXEC
188+
self.node_js_path = javascriptCompletions.get("node_js_custom_path") or NODE_JS_EXEC
189+
self.npm_path = javascriptCompletions.get("npm_custom_path") or NPM_EXEC
190+
self.yarn_path = javascriptCompletions.get("yarn_custom_path") or YARN_EXEC
205191

206192
self.cli_path = self.npm_path
207193

@@ -212,7 +198,7 @@ def execute(self, command, command_args, chdir="", wait_terminate=True, func_std
212198
if sublime.platform() == 'windows':
213199
args = [self.cli_path, command] + command_args
214200
else :
215-
args = [self.cli_path, command] + command_args
201+
args = [self.node_js_path, self.cli_path, command] + command_args
216202

217203
return Util.execute(args[0], args[1:], chdir=chdir, wait_terminate=wait_terminate, func_stdout=func_stdout, args_func_stdout=args_func_stdout)
218204

@@ -251,7 +237,7 @@ def getCurrentNPMVersion(self) :
251237
if sublime.platform() == 'windows':
252238
args = [self.cli_path, "-v"]
253239
else :
254-
args = [self.node_js_path, self.cli_path, "-v"]
240+
args = [self.cli_path, "-v"]
255241

256242
result = Util.execute(args[0], args[1:])
257243

helper/util/main.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,11 @@ def execute(command, command_args, chdir="", wait_terminate=True, func_stdout=No
449449

450450
if wait_terminate :
451451

452-
with subprocess.Popen(args, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, cwd=(None if not chdir else chdir)) as p:
452+
env = os.environ.copy()
453+
env["PATH"] = env["PATH"] + javascriptCompletions.get("PATH")
454+
shell = os.getenv('SHELL')
455+
456+
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:
453457

454458
lines_output = []
455459
lines_error = []
@@ -475,7 +479,11 @@ def execute(command, command_args, chdir="", wait_terminate=True, func_stdout=No
475479
@staticmethod
476480
def _wrapper_func_stdout(args, func_stdout, args_func_stdout=[], chdir=""):
477481

478-
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:
482+
env = os.environ.copy()
483+
env["PATH"] = env["PATH"] + javascriptCompletions.get("PATH")
484+
shell = os.getenv('SHELL')
485+
486+
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:
479487

480488
func_stdout(None, p, *args_func_stdout)
481489

0 commit comments

Comments
 (0)