0

I have made a simple JS text editor app for iOS; I'd like to use tsserver to get intellisense and transpilation. I can see how to run tsserver via node or via the browser (as part of TypeScript Playground – however, it comes along with the Monaco editor, and I want it headless, but I don't immediately see how to separate them).

One of the difficulties to consider is that it will presumably need file-system access to load any TypeScript libs (I will be loading it with many custom ones) – I'm not sure how to elegantly solve this with a purely JavaScriptCore solution.

Is there a way to set up just tsserver to run on mobile, ideally without getting a webview involved (as it's unnecessary overhead)?

Jamie Birch
  • 5,839
  • 1
  • 46
  • 60

1 Answers1

1

I can see how to run tsserver via node or via the browser (as part of TypeScript Playground)

Micsonception here. tsserver only runs in node : https://github.com/Microsoft/TypeScript/wiki/Standalone-Server-(tsserver) The TypeScript standalone server (aka tsserver) is a node executable

What runs on the playground?

The TypeScript language service https://github.com/Microsoft/TypeScript/wiki/Using-the-Language-Service-API is what is run on the playground. It allows you to intercept calls like "does this file exist" or "please read this file" and redirect them to (disk for node, server for in browser) etc.

Is there a way to set up just tsserver to run on mobile, ideally without getting a webview involved (as it's unnecessary overhead)?

So fundamentally no. tsserver is not for non node enviroments.

however, it comes along with the Monaco editor, and I want it headless, but I don't immediately see how to separate them

If you want in browser IDE here is a nice free OSS one that does use monaco : https://github.com/agentcooper/typescript-play (but at least its open source through and through ). Monaco is not that bad. You have to start somewhere ❤

More

In order to run TypeScript compiler over some set of files without running tsc or tsserver you have two options:

I think for your case (no IDE / live code editing etc) the compiler api would be sufficient.

basarat
  • 261,912
  • 58
  • 460
  • 511
  • Hi basarat, thanks immensely for clearing that up. I see now that actually what I am trying to run is the TS compiler (i.e., I want to make [these](https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API) API calls) on a mobile device (which also must host the service). The tricky part is that mobile devices don’t have node (they can only run JS via a browser or a runtime like JavaScriptCore). I’m wondering whether there is any way to set up tsc just via JavaScriptCore, rather than via a webview. And if it must be a webview, what are the minimal JS modules needed in the webpage? – Jamie Birch Mar 18 '19 at 00:39
  • Sorry. I was wrong, I forgot about the *must work in JavaScript core*. `tsc` requires node as well. Correcting the answer. – basarat Mar 18 '19 at 00:47
  • @JamieBirch sounds like you want the compiler API. Answer updated. Thanks – basarat Mar 18 '19 at 00:51