typescripttscjavascriptcore

How can I run tsserver as a background process on mobile (i.e. with JavaScriptCore but without node; and avoiding webview-based solutions)?


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)?


Solution

  • 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.