-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running TypeScript compiler on Java Nashorn #8565
Conversation
Hi @vojtechhabarta, I'm your friendly neighborhood Microsoft Pull Request Bot (You can call me MSBOT). Thanks for your contribution! TTYL, MSBOT; |
even when execution time might not be the best, this deserves some love as it would enable CI servers & dev machines without node to run the compiler |
I've tried to compile the compiler on Ubuntu using Nashorn (nashorn 1.8.0_91) and node (node 5.7.0) and results that I got:
If we add Nashorn support then we need to use it when running our test suite on the CI server to make sure that we won't accidentally break something. Currently test run on Travis takes roughly 8 minutes so if we throw Nashorn into mix it presumably will be ( I can suggest the following: currently compiler checks for presence of |
Thanks for trying this PR and confirming the performance problem with Nashorn. I agree that it is unusably slow. Also thank you for the hint with |
@vojtechhabarta This is brilliant and exactly what we need. Can I suggest splitting this off as an independent Java project? I think you'd only need a small driver class to create a Nashorn instance, load your System object, then load tsc.js. Let me know if you want to do that. If not, I wouldn't mind giving it a shot myself. |
@wmono we use @vladima do you think this could be changed so that @wmono second possibility is provide |
Indeed, it's the interaction between always setting ts.sys and including the ts.executeCommandLine call in tsc.js that is causing a problem here. Either setting ts.sys conditionally or moving the ts.executeCommandLine call to bin/tsc (and other entry points, if any) would effectively make the System implementation pluggable. The latter option makes everything else pluggable, too. (Sort of.) I don't really consider making Nashorn pretend to be Chakra to be a proper solution. It looks like it could work for now, but how long until something is added to System that is implemented as a not-so-thin wrapper? I have gotten as far as getting the usage message to appear by removing the last line of tsc.js and loading in a somewhat stubbed out System object. (There were a couple of gotchas due to this version of System living outside of TypeScript, both in language and in environment, so I left a few things out for the moment.) I haven't looked into the lib.d.ts issue yet but I can confirm that it still exists. |
When you set I realized there is a bug in getJavaSystem().readDirectory(). Here is a fix: |
If anyone is still interested, I've been tinkering with this again and have a proof of concept at https://github.com/wmono/jtsc. |
Fixes #1789.
This PR allows TypeScript compiler to run on Java 8 Nashorn JavaScript engine. Implementation of
ts.System
interface for Java environment is quite straightforward with one exception. There is no way to get the path of executing file (needed ints.System.getExecutingFilePath()
function) so I usedexecutingFilePath
Java system property to pass this information in.Running from command line
Java provides
jjs
command which runs specified JavaScript files but unfortunately it cannot be used ashost
inJakefile.js
directly because it doesn't have the same parameters asnode
. Therefore I createdjjs-host.cmd
(not part of the PR) which passes parameters tojjs
the way it expects them. It also addsexecutingFilePath
property:Test
Then it is possible to test compiler on Java using following commands in PowerShell:
Performance
Unfortunately running
tsc.js
on Java is very slow when compared to Node.js. I tried to compile TypeScript compiler itself usingjake local
and I also tried to compile single-line "Hello world" program. Results are in table bellow.jake local
)I didn't expect it to be that bad. I hope it will improve in the future.