Skip to content

Commit ebbc200

Browse files
authored
Prefer bundled version of tsc (emscripten-core#24001)
I'm seeing issues with an older version of tsc being present in the PATH on my workstation.
1 parent 42e3d7f commit ebbc200

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

tools/emscripten.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -628,12 +628,16 @@ def create_tsd_exported_runtime_methods(metadata):
628628
js_doc_file = in_temp('jsdoc.js')
629629
tsc_output_file = in_temp('jsdoc.d.ts')
630630
utils.write_file(js_doc_file, js_doc)
631-
tsc = shutil.which('tsc')
632-
if tsc:
631+
tsc = shared.get_npm_cmd('tsc', missing_ok=True)
632+
# Prefer the npm install'd version of tsc since we know that one is compatible
633+
# with emscripten output.
634+
if not tsc:
635+
# Fall back to tsc in the user's PATH.
636+
tsc = shutil.which('tsc')
637+
if not tsc:
638+
exit_with_error('tsc executable not found in node_modules or in $PATH')
633639
# Use the full path from the which command so windows can find tsc.
634640
tsc = [tsc]
635-
else:
636-
tsc = shared.get_npm_cmd('tsc')
637641
cmd = tsc + ['--outFile', tsc_output_file,
638642
'--skipLibCheck', # Avoid checking any of the user's types e.g. node_modules/@types.
639643
'--declaration',

tools/shared.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,16 @@ def run_js_tool(filename, jsargs=[], node_args=[], **kw): # noqa: B006
262262
return check_call(command, **kw).stdout
263263

264264

265-
def get_npm_cmd(name):
265+
def get_npm_cmd(name, missing_ok=False):
266266
if WINDOWS:
267267
cmd = [path_from_root('node_modules/.bin', name + '.cmd')]
268268
else:
269269
cmd = config.NODE_JS + [path_from_root('node_modules/.bin', name)]
270270
if not os.path.exists(cmd[-1]):
271-
exit_with_error(f'{name} was not found! Please run "npm install" in Emscripten root directory to set up npm dependencies')
271+
if missing_ok:
272+
return None
273+
else:
274+
exit_with_error(f'{name} was not found! Please run "npm install" in Emscripten root directory to set up npm dependencies')
272275
return cmd
273276

274277

0 commit comments

Comments
 (0)