Typescript: Directly using process.argv in typescript.js

Created on 29 Aug 2019  Â·  5Comments  Â·  Source: microsoft/TypeScript


TypeScript Version: 3.6.2 (offending code is still in repo when writing this)

Search Terms:
process argv etw

Code

https://github.com/microsoft/TypeScript/blob/01e1b1bb276f48eaa0612a34dd8f1eec5d86bd49/src/compiler/perfLogger.ts#L42

    perfLogger.logInfoEvent(`Starting TypeScript v${versionMajorMinor} with command line: ${JSON.stringify(process.argv)}`);

Expected behavior:
Should not use process directly.

Actual behavior:
It crashes in hosts which does not have process like browsers or any other than nodejs.

Bug Fix Available

Most helpful comment

Yes, this fix is plastering over the cracks. As I mentioned in the PR, I plastered over the cracks because we’re about to release 3.6.3 and the other people involved were out of town. Knowing it’s not the fix we want, I opened #33246.

All 5 comments

Just ran into this when trying to update Deno to 3.6.

Looking at the fix available, it still assumes that every runtime with have process.argv as the way to get the command line arguments or it is a browser. Everything else in TypeScript like this is generally abstracted away from that through CompilerHost or System. Wouldn't it make sense here too? Or this code should detect that it wasn't invoked via tsc.

This fix, IMO, is plastering over the cracks.

@kitsonk agree.

Also, might be better to move this to log in the cli part (executeCommandLine in tsc.ts? Seems like that uses ts.sys.args) rather than when typescript is imported. Or is there a reason for this to log the process command line arguments even when not launched from tsc?

Yes, this fix is plastering over the cracks. As I mentioned in the PR, I plastered over the cracks because we’re about to release 3.6.3 and the other people involved were out of town. Knowing it’s not the fix we want, I opened #33246.

Yeah, I’m also going to need to a proper fix for this in order to integrate TypeScript in miniSphere, which also doesn’t implement process.argv. For now I’m using 3.5, which doesn’t have the issue.

Definitely seems like typescript.js shouldn’t be responsible for this in the first place though - that’s the part that’s meant to be embedded so it’s not guaranteed that the concept of “command line arguments” even makes sense in a given environment.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

blendsdk picture blendsdk  Â·  3Comments

weswigham picture weswigham  Â·  3Comments

manekinekko picture manekinekko  Â·  3Comments

wmaurer picture wmaurer  Â·  3Comments

bgrieder picture bgrieder  Â·  3Comments