{"action":"opened","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/5924","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/5924/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/5924/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/5924/events","html_url":"https://github.com/Microsoft/TypeScript/issues/5924","id":120376704,"number":5924,"title":"Make new ChakraHost a generic extension point for platform hosting","user":{"login":"mihailik","id":4041967,"avatar_url":"https://avatars.githubusercontent.com/u/4041967?v=3","gravatar_id":"","url":"https://api.github.com/users/mihailik","html_url":"https://github.com/mihailik","followers_url":"https://api.github.com/users/mihailik/followers","following_url":"https://api.github.com/users/mihailik/following{/other_user}","gists_url":"https://api.github.com/users/mihailik/gists{/gist_id}","starred_url":"https://api.github.com/users/mihailik/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mihailik/subscriptions","organizations_url":"https://api.github.com/users/mihailik/orgs","repos_url":"https://api.github.com/users/mihailik/repos","events_url":"https://api.github.com/users/mihailik/events{/privacy}","received_events_url":"https://api.github.com/users/mihailik/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-04T10:47:22Z","updated_at":"2015-12-04T10:47:22Z","closed_at":null,"body":"A separate issue to follow on [my comment](https://github.com/Microsoft/TypeScript/commit/2799d2e561358321281669dc58e226f4d0981fee#commitcomment-14783754) on #5880 \r\n\r\n> How about making this useful for other non-Chakra scenarios?\r\n>\r\n> You could make your actual Chakra host to export `ts.sys` directly instead of `ChakraHost`. Then have this code here at line 66 instead of the whole Chakra handling:\r\n>\r\n> ```typescript\r\n> if (ts.sys) return ts.sys;\r\n> ```\r\n>\r\n>The benefit is that a whole host of other platform-hosting scenarios become easily possible:\r\n> * emulated environment in browser\r\n> * [Rhino](https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino)\r\n> * [Nashorn](http://openjdk.java.net/projects/nashorn/)\r\n> * [nginxScript](https://www.nginx.com/blog/launching-nginscript-and-looking-ahead/)\r\n> * ActionScript/Flash\r\n> * JScript.NET\r\n> * [Jint](https://github.com/sebastienros/jint)\r\n> * [IronJS](https://github.com/fholm/IronJS)\r\n> * [Jurassic](https://github.com/prepare/Jurassic)\r\n\r\nAlso note that @DanielRosenwasser [commented](https://github.com/Microsoft/TypeScript/pull/5880#issuecomment-161199473) on the original PR:\r\n> Should this be called `NativeHost`? It's not unreasonable to expect another host that exposes the same functionality.\r\n\r\nAnd @yuit [replied](https://github.com/Microsoft/TypeScript/pull/5880#issuecomment-161402902):\r\n> @DanielRosenwasser is that what interface `System` for ?\r\n\r\nSo that is exactly my suggestion: use `System` interface and `ts.sys` variable as an extension point for interested parties to implement a host for the whole `tsc.js` compiler.\r\n\r\nCurrently the way to run tsc.js on an 'exotic' host you need to emulate WScript or node, or now also ChakraHost with this latest feature. But only node emulation gives fully-functional host, with the main downside is lack of `watchFile/watchDirectory` in both WScript and ChakraHost. And node emulation is actually a bit of a pain, particularly with the need to implement [Buffer](https://github.com/Microsoft/TypeScript/blob/2799d2e561358321281669dc58e226f4d0981fee/src/compiler/sys.ts#L39) at least partially, as `getNodeSystem` in fact relies on it for BOF detection and whatnot.\r\n\r\nWhen I need to run tsc from within an embedded/emulated/hosted environment, I am up for pain dealing with peculiarities of WScript or node semantics — even as I might not be using neither.\r\n\r\nTypeScript has a lot of potential in enterprise, as a loose analog of VBA for user-authored scripting. And that often means compiling on-demand in embedded scenarios.\r\n\r\nIf you make `ts.sys` and `System` interface a proper extension point, it would help a lot."}}