Skip to content

Commit 2d3cfc7

Browse files
committed
Adds support for dev builds of TS
1 parent 3e37a18 commit 2d3cfc7

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

packages/playground/README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
This is the JS tooling which powers the https://www.typescriptlang.org/play/
44

55
It is more or less vanilla DOM-oriented JavaScript with as few dependencies as possible. Originally based on the
6-
work by [Artem Tyurin](https://github.com/agentcooper/typescript-play) but now it's pretty far from that fork.
6+
work by [Artem Tyurin](https://github.com/agentcooper/typescript-play) but now it's diverged far from that fork.
77

88
## Architecture
99

@@ -17,3 +17,29 @@ The playground library sits above the [TypeScript sandbox](../Sandbox), and prov
1717
When deciding where to add a feature to the TypeScript playground, consider if it would be useful to anyone showing
1818
TypeScript in a REPL. If yes, add it to the playground and expose a function for this library to use. For example
1919
Automatic Type Acquisition is a feature which lives in the sandbox and not the playground.
20+
21+
## Link Syntax
22+
23+
The Playground supports a set of query inputs from the URL. The hash is used to reflect the code:
24+
25+
- `#code/PRA` - A base64 and zipped version of the code which should live in the editor
26+
- `#src/The%20code` - URLEncoded way to have the code for the editor
27+
- `#example/generic-functions` - Grab the code from an example with the id generic-functions
28+
29+
Or to trigger some action by default:
30+
31+
- `#show-examples` - When the app is loaded, show the examples popover
32+
- `#show-whatisnew` - When the app is loaded, show the examples popover
33+
34+
Then queries tend to be about changing the state of the Playground setup from the default:
35+
36+
- `?ts=3.9.2` - Sets the TypeScript version, the list of supported versions is in these [two](https://typescript.azureedge.net/indexes/pre-releases.json) [json](https://typescript.azureedge.net/indexes/releases.json) files.
37+
38+
There are two special cases for the `ts` option:
39+
40+
- `ts=Nightly` where it will switch to most recently the nightly version.
41+
- `ts=dev` where it uses your local developer's build of TypeScript (docs coming later)
42+
43+
- `?flag=value` - Any compiler flag referenced in can be set from a query
44+
- `?useJavaScript=true` - Tells the Playground to treat the editor's code as a JS file instead of a TS one
45+
- `?install-plugin=npm-module` - Checks to see if there is an installed playground plugin of that name, and if not offers to install it in a modal.

packages/typescriptlang-org/src/templates/play.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,28 @@ const Play: React.FC<Props> = (props) => {
4141
window.react = React
4242
// @ts-ignore - for React-based plugins
4343
window.reactDOM = ReactDOM
44-
// @ts-ignore - so that plugins etc can use local functions
44+
// @ts-ignore - so that plugins etc can use i8n
4545
window.i = i
4646

4747
const getLoaderScript = document.createElement('script');
4848
getLoaderScript.src = withPrefix("/js/vs.loader.js");
4949
getLoaderScript.async = true;
5050
getLoaderScript.onload = () => {
5151
const params = new URLSearchParams(location.search)
52-
// nothing || Nightly -> next || original ts param
52+
// nothing || Nightly -> next || original ts param which should be a release of monaco
5353
const supportedVersion = !params.get("ts") ? undefined : params.get("ts") === "Nightly" ? "next" : params.get("ts")
5454
const tsVersion = supportedVersion || playgroundReleases.versions.sort().pop()
5555

56+
// Because we can reach to localhost ports from the site, it's possible for the locally built compiler to
57+
// be hosted and to power the editor with a bit of elbow grease.
58+
const useLocalCompiler = tsVersion === "dev"
59+
const urlForMonaco = useLocalCompiler ? "http://localhost:5615/dev/vs" : `https://typescript.azureedge.net/cdn/${tsVersion}/monaco/dev/vs`
60+
5661
// @ts-ignore
5762
const re: any = global.require
5863
re.config({
5964
paths: {
60-
vs: `https://typescript.azureedge.net/cdn/${tsVersion}/monaco/min/vs`,
65+
vs: urlForMonaco,
6166
"typescript-sandbox": withPrefix('/js/sandbox'),
6267
"typescript-playground": withPrefix('/js/playground'),
6368
"unpkg": "https://unpkg.com/",

0 commit comments

Comments
 (0)