Skip to content
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

Make tsc runnable on Nashorn #1789

Closed
markelliot opened this issue Jan 23, 2015 · 21 comments
Closed

Make tsc runnable on Nashorn #1789

markelliot opened this issue Jan 23, 2015 · 21 comments
Labels
Good First Issue Well scoped, documented and has the green light Help Wanted You can do this Suggestion An idea for TypeScript Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it

Comments

@markelliot
Copy link

Would be useful to be able to use gradle+jvm to run tsc directly to reduce complexity in our build system (today we use gradle to run node to run grunt to run tsc).

Some recent improvements in the JDK suggest this is likely now a fast enough environment (1). Others have tried in the past, so it is definitely possible (2,3).

@bavardage
Copy link
Contributor

👍

@RyanCavanaugh
Copy link
Member

Looks like someone's done the basic work here: https://github.com/coudy/typescript . We can discuss whether or not taking a PR on this would be appropriate.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript In Discussion Not yet reached consensus Suggestion An idea for TypeScript and removed Bug A bug in TypeScript labels Jan 23, 2015
@DanielRosenwasser
Copy link
Member

First, before anyone tries to work with that directly, that Nashorn system implementation is for the old compiler. Still should be easy enough to rewrite.

Second, note the following from the somewhat recent Nashorn announcement:

These plans will also solidify more for future Java releases, and we hope that Nashorn eventually will turn into a kind of "LLVM for dynamic languages on the JVM". The optimistic typing problem comes back to every dynamic language. To prove this, our excellent thesis student Andreas Gabrielsson has successfully implemented almost everything required to run TypeScript on Nashorn. At the time of this writing, modules in the only large feature missing. Nashorn goes directly to bytecode from TypeScript without generating JavaScript in a mid-level compiler tier. This is pretty awesome and shows how extensible Nashorn already is. We have thought about Ruby and Groovy running in a similar environment. Nashorn TypeScript is still not open sourced, but we hope we have the chance to do it soon.

Not that this should dissuade contributions, but something we should consider discussing further.

@markelliot
Copy link
Author

My suspicion is that even when TS code is directly runnable on Nashorn that we would still need a Nashorn-specific IO module for tsc, so that tsc itself is also runnable.

@basarat
Copy link
Contributor

basarat commented Jan 23, 2015

@markelliot I suspect you will inevitably need node for some other project that does something useful with your JavaScript/CSS

@DanielRosenwasser
Copy link
Member

Nashorn-specific IO module for tsc

Or a Node-compatible interface exposed from Java.

@DanielRosenwasser
Copy link
Member

@wmono
Copy link

wmono commented Mar 28, 2015

I was able to run tsc on Avatar.js without much trouble, though I have not tested it thoroughly. You might be interested in a proof-of-concept Maven plugin that I put together this week: Maven TypeScript Compiler Plugin

@mhegazy
Copy link
Contributor

mhegazy commented Mar 29, 2015

thanks @wmono for sharing. You mention in your description you mention

What about watching the directory and recompiling when a file changes?

Actually tsc on node supports --watch mode that allows for that. just wanted to make sure you know about it.

@wmono
Copy link

wmono commented Mar 29, 2015

Thanks @mhegazy I've added a tsc:watch goal to run with that option and it does seem to work on Avatar.js.

@martyglaubitz
Copy link

That would enable Typescript Gradle Plugin to run the compiler without having nodejs installed on the system.

@Vadorequest
Copy link

👍 I also need to use Nashorn instead of Node to run TypeScript, in Gradle as well. Does the situation has changed since the Nashorn announcement?

@martyglaubitz
Copy link

@basarat not necessarily - alot of people (especially on the enterprise) are using JS for their frontend stuff only. Yet we'd like to use Typescript in our stack - which in turn requires the compiler to be a bit more agnostic about the environment in which he runs.

@RyanCavanaugh RyanCavanaugh added Help Wanted You can do this and removed In Discussion Not yet reached consensus labels Apr 27, 2015
@RyanCavanaugh RyanCavanaugh added this to the Community milestone Apr 27, 2015
@DanielRosenwasser DanielRosenwasser added the Good First Issue Well scoped, documented and has the green light label Sep 29, 2015
@ctaggart
Copy link
Contributor

This would be great to see! It would be nice to get contacts at Oracle to see if they still plan on open sourcing their Nashorn TypeScript. Otherwise, Apigee's rowboat project is set to use Nashorn instead of Rhino for the JavaScript Engine like trireme does. It may be worth trying out.

@angelozerr
Copy link

Just for your information, I have implemented ternjs server to consume it in Java context with tern.java with several JavaScript engine (node.js, J2V8, Nashorm and Rhino) and the performance is not very good with Nashorn (I have not benchamrk, but when I consume ternjs with Nashorm (like open completion with a lot of JS files), Eclipse freezes a little although with node.js it is very fast)

In other words with ternjs, for performance I have : node.js > J2V8 > Nashorm > Rhino.

@ctaggart
Copy link
Contributor

Thanks @angelozerr! Looking at the J2V8 docs, it looks similar to Edge.js, but for Java instead of .NET. I think that will work.

@vojtechhabarta
Copy link

I usually run TypeScript compiler using node. When I have Java project with TypeScript code and I don't want to force others to install Node.js I use frontend-maven-plugin which installs node and npm automatically.

But I also wanted to allow users to customize my Java application using TypeScript expressions, snippets, plugins... For this feature I need to run TypeScript compiler inside Java VM so I created PR.

With this PR it should be possible to implement for Java something like typescript-simple.

@vladima
Copy link
Contributor

vladima commented May 24, 2016

@vojtechhabarta for embedded scripting can you just load typescriptServices.js and then use ts.transpileModule to convert .ts to .js?

@vojtechhabarta
Copy link

@vladima I was thinking that TypeScript services also need System that's why I wanted first make tsc work. But apparently ts.transpileModule doesn't use System.

ts.transpileModule is probably sufficient in my case. I just tried to compile "Hello world" program with typescriptServices.js running on Nashorn and it worked. It took about 10 seconds which is about 4 times faster than tsc running on Nashorn. This might be usable in cases where caching is possible (and ts code doesn't change often).

Thanks

@mhegazy mhegazy added the Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it label May 24, 2016
@mhegazy
Copy link
Contributor

mhegazy commented May 24, 2016

Given the perf characteristics of running the compiler on nashorn (see more in #8565 (comment)), and the support requirements on the core ts team, we will have to decline this request in the time being. we can revisit this in the future if any of these assumptions change.

@wizawu
Copy link

wizawu commented Apr 30, 2017

https://1c.wizawu.com/

The purpose of this project is not just to Make tsc runnable on Nashorn. Just wanna make JDK and Maven libraries actually programmable in TypeScript (without quirky hacking).

@mhegazy mhegazy removed this from the Community milestone Apr 26, 2018
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Good First Issue Well scoped, documented and has the green light Help Wanted You can do this Suggestion An idea for TypeScript Won't Fix The severity and priority of this issue do not warrant the time or complexity needed to fix it
Projects
None yet
Development

No branches or pull requests