Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
6ac0e97
Add standalone TypeScript 7.1 playground
jakebailey Sep 16, 2026
21f6e30
Integrate TS 7.1 playground into website
jakebailey Sep 16, 2026
5b0bda0
Vendor TypeScript 7 compiler for playground
jakebailey Sep 16, 2026
1360e9a
Add vendored TypeScript compiler artifacts
jakebailey Sep 16, 2026
e263e75
Remove internal playground README
jakebailey Sep 16, 2026
b105882
Add TypeScript 7 Monaco LSP support
jakebailey Sep 16, 2026
0bca0ef
Fix TypeScript 7 playground asset URLs
jakebailey Sep 16, 2026
fed0140
Fix playground COI redirect loop
jakebailey Sep 16, 2026
53eca8e
Turn TS7 playground into a project workspace
jakebailey Sep 16, 2026
d67f86b
Improve TypeScript 7 project UX
jakebailey Sep 16, 2026
cdda448
Fix TSConfig validation and saved emit
jakebailey Sep 16, 2026
eb6943b
Add truthful playground loading progress
jakebailey Sep 16, 2026
8639a6a
Cache TypeScript playground assets
jakebailey Sep 16, 2026
65665fd
Enable TS7 semantic editor features
jakebailey Sep 16, 2026
02ee465
Show playground while TypeScript loads
jakebailey Sep 16, 2026
6cfd09a
Clarify playground file tree nesting
jakebailey Sep 16, 2026
0be5f54
Support type queries in JavaScript files
jakebailey Sep 22, 2026
a38d170
Refresh vendored TypeScript WASI compiler
jakebailey Sep 24, 2026
3b18493
Add unified classic TypeScript versions
jakebailey Sep 24, 2026
cdd91f6
Make TS7 playground mobile responsive
jakebailey Sep 24, 2026
dc974e5
Add playground editor navigation history
jakebailey Sep 24, 2026
2c0f368
Add project file deletion
jakebailey Sep 24, 2026
38d49bf
Restore classic Monaco editor features
jakebailey Sep 24, 2026
2155152
Add project-wide Problems panel
jakebailey Sep 24, 2026
151543a
Add automatic package type acquisition
jakebailey Sep 24, 2026
cf26cf6
Integrate playground examples and help
jakebailey Sep 24, 2026
0eb90e5
Vendor the package type acquisition runtime
jakebailey Sep 24, 2026
6bb80a4
Wrap playground controls on tablets
jakebailey Sep 24, 2026
659b863
Add playground workspace layout controls
jakebailey Sep 24, 2026
a7334c0
Simplify playground compiler versions
jakebailey Sep 24, 2026
0ab90f8
Wrap playground code on mobile
jakebailey Sep 24, 2026
6d026df
Contain Monaco on mobile viewports
jakebailey Sep 24, 2026
b98a7e8
Keep Problems above emitted output
jakebailey Sep 24, 2026
85d9fc0
Expand the editor when panels are hidden
jakebailey Sep 24, 2026
653e0f0
Use disclosure controls for output sections
jakebailey Sep 24, 2026
53699e5
Confirm the initial compiler download
jakebailey Sep 24, 2026
16e24e7
Replace the new-file browser prompt
jakebailey Sep 24, 2026
0299dd3
Show the exact compiler version
jakebailey Sep 24, 2026
0a6be8c
Center the compiler download consent
jakebailey Sep 24, 2026
bd61e5f
Version multi-file playground URLs
jakebailey Sep 24, 2026
f5b0cc0
Add inline compiler option overrides
jakebailey Sep 24, 2026
49b8dae
Route legacy examples and handbook links
jakebailey Sep 24, 2026
fb54626
Load acquired package types into the live LSP
jakebailey Sep 24, 2026
5e0e760
Add persisted playground settings
jakebailey Sep 24, 2026
fcfa20f
Replace native playground dialogs
jakebailey Sep 24, 2026
a9e3f53
Replace the native compiler selector
jakebailey Sep 24, 2026
b3daccd
Add a compact playground site shell
jakebailey Sep 24, 2026
a92ba11
Persist editor selections in project links
jakebailey Sep 24, 2026
7de6b82
Restore reflect-metadata run compatibility
jakebailey Sep 24, 2026
c8a5bab
Rename the next-generation playground
jakebailey Sep 25, 2026
e263476
Move Playground v2 to its permanent route
jakebailey Sep 25, 2026
32ca7e0
Improve Playground v2 accessibility
jakebailey Sep 25, 2026
7f0e826
Build the Monaco LSP client from source
jakebailey Sep 30, 2026
80221c2
Patch the Monaco LSP client from git
jakebailey Sep 30, 2026
726e690
Generalize Monaco LSP model ownership
jakebailey Sep 30, 2026
1a332b3
Refresh the Playground v2 compiler
jakebailey Sep 30, 2026
a6d13f3
Include new Corsa API modules
jakebailey Sep 30, 2026
1d8f7c2
Resolve Node builtin package types
jakebailey Sep 30, 2026
86ba926
Make Problems messages copyable
jakebailey Sep 30, 2026
44ffd5e
Show automatic type configuration
jakebailey Sep 30, 2026
8376018
Replace Playground v2 type acquisition
jakebailey Oct 1, 2026
06701a6
Leave the legacy ATA package unchanged
jakebailey Oct 1, 2026
f8d20f6
Leave the legacy playground entry unchanged
jakebailey Oct 1, 2026
41a1f12
Make Playground v2 the default playground
jakebailey Oct 1, 2026
a04a799
Record a release for legacy plugin links
jakebailey Oct 1, 2026
76eebf1
Test compatibility redirects without parsing HTML
jakebailey Oct 1, 2026
bff3dcb
Keep package type acquisition off the startup path
jakebailey Oct 1, 2026
3f1c940
Refresh editor diagnostics after package acquisition
jakebailey Oct 1, 2026
e97206b
Use one compiler diagnostic source in the native editor
jakebailey Oct 1, 2026
1a3fa89
Tighten playground controls and pane layout
jakebailey Oct 1, 2026
14f8b78
Move automatic native compiler work off the UI thread
jakebailey Oct 2, 2026
95822df
Remove the playground's global compiler API
jakebailey Oct 2, 2026
0b4c065
Avoid redundant native program preparation
jakebailey Oct 2, 2026
20c3aa5
Coalesce playground project and selection saves
jakebailey Oct 2, 2026
7830149
Refresh Corsa with the revised WASI package layout
jakebailey Oct 2, 2026
ef43282
Batch acquired package files in the language server
jakebailey Oct 6, 2026
03d31ff
Keep Emit content beside its disclosure header
jakebailey Oct 7, 2026
e31ef51
Start playground projects with one source file
jakebailey Oct 7, 2026
2b62652
Wait for initial compilation before returning type-query hints
jakebailey Oct 7, 2026
0cb1aca
Remove the extra colon from type-query hints
jakebailey Oct 7, 2026
85407d5
Load the compiler from an unchanged runtime package distribution
jakebailey Oct 20, 2026
f014903
Refresh compiler tarballs with the final WASM import path
jakebailey Oct 20, 2026
ea99f00
Modernize the default playground compiler settings
jakebailey Oct 20, 2026
bd19edc
Refresh the vendored WASI compiler
jakebailey Oct 22, 2026
9436be0
Load the published native compiler from a pinned CDN distribution
jakebailey Oct 30, 2026
0da41cf
Keep the new Playground opt-in at /play/v2/
jakebailey Oct 30, 2026
e95f1fe
Keep playground colors readable across appearance changes
jakebailey Oct 30, 2026
b38cb9c
Improve playground keyboard and screen-reader access
jakebailey Oct 30, 2026
d7eaad3
Merge upstream v2 into ts7-playground
jakebailey Oct 30, 2026
c5090b8
Discover and load published native compiler versions
jakebailey Oct 30, 2026
7cd2a26
Document trusted compiler evaluation
jakebailey Oct 30, 2026
850f2fe
Size compiler version controls to their labels
jakebailey Oct 30, 2026
db5f8c1
Keep playground status focused on readiness
jakebailey Oct 30, 2026
0b65c29
Load legacy compiler libraries concurrently with progress
jakebailey Oct 30, 2026
d045f2b
Add emphasis to the new Playground invitation
jakebailey Oct 30, 2026
85a54c4
Preserve native TypeScript comment directives
jakebailey Oct 30, 2026
f6da52f
Parse legacy projects with the selected compiler
jakebailey Oct 30, 2026
a41ed93
Synchronize native editor documents without losing identity
jakebailey Oct 30, 2026
a3d7772
Use explicit Monaco navigation for definition results
jakebailey Oct 30, 2026
a061b7e
Parse list-valued compiler directives as arrays
jakebailey Oct 31, 2026
631d872
Query imported native files in their configured program
jakebailey Oct 31, 2026
0b00e17
Complete legacy standard-library dependency graphs
jakebailey Oct 31, 2026
8474668
Separate configured and inferred legacy language services
jakebailey Oct 31, 2026
495aa8e
Respect legacy compiler completion replacement spans
jakebailey Oct 31, 2026
dbf19ba
Keep native LSP stdin counters safe across wraparound
jakebailey Oct 31, 2026
d8ae22d
Read acquisition versions from actual trailing comments
jakebailey Oct 31, 2026
f9e22f2
Include native program-wide and global diagnostics
jakebailey Oct 31, 2026
58d796c
Reject legacy requests when the compiler worker fails
jakebailey Oct 31, 2026
b189dfe
Reuse declaration models created by concurrent navigation
jakebailey Oct 31, 2026
3e8b085
Synchronize legacy project changes incrementally
jakebailey Oct 31, 2026
08d355b
Track Monaco touch gestures in viewport coordinates
jakebailey Oct 31, 2026
2943255
Let mobile editor swipes continue scrolling the page
jakebailey Oct 31, 2026
7bc312c
Prioritize page swipes past a partially hidden mobile editor
jakebailey Oct 31, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* -text
patches/*.patch -whitespace
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ packages/documentation/output/attribution.json
packages/sandbox/src/releases.json
packages/sandbox/src/release_data.ts
packages/typescriptlang-org/src/lib/documentationNavigation.ts
packages/typescriptlang-org/static/play/v2/
packages/typescriptlang-org/static/play/7/
packages/typescriptlang-org/static/v2/

.idea/

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
"webpack": "^5.105.3"
},
"patchedDependencies": {
"gatsby-remark-shiki-twoslash@3.0.38": "patches/gatsby-remark-shiki-twoslash@3.0.38.patch"
"@vscode/monaco-lsp-client@0.1.0": "patches/@vscode__monaco-lsp-client@0.1.0.patch",
"gatsby-remark-shiki-twoslash@3.0.38": "patches/gatsby-remark-shiki-twoslash@3.0.38.patch",
"monaco-editor-core@0.56.0": "patches/monaco-editor-core@0.56.0.patch"
},
"ignoredBuiltDependencies": [
"@parcel/watcher",
Expand Down
35 changes: 35 additions & 0 deletions packages/playground-v2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "@typescript/playground-v2",
"private": true,
"type": "module",
"scripts": {
"build": "node scripts/build.mjs",
"dev": "node scripts/build.mjs --serve",
"test": "node scripts/test-ata.mjs && node scripts/smoke-test.mjs",
"typecheck": "node node_modules/typescript/bin/tsc --noEmit && node node_modules/typescript/bin/tsc -p tsconfig.test.json",
"vendor-resources": "node scripts/vendor-resources.mjs",
"update-compiler": "node scripts/update-compiler.mjs"
},
"dependencies": {
"@bjorn3/browser_wasi_shim": "^0.4.2",
"@fontsource/nunito-sans": "^5.2.6",
"@typescript/typescript": "npm:typescript@7.1.0-dev.20261030.1",
"@typescript/typescript-wasip1-wasm": "7.1.0-dev.20261030.1",
"@vscode/monaco-lsp-client": "github:microsoft/monaco-editor#13f0c872dcf352815cc28d92dfff496c9839ea5c&path:/monaco-lsp-client",
"coi-serviceworker": "^0.1.7",
"hack-font": "^3.3.0",
"jsonc-parser": "^3.3.1",
"lz-string": "^1.5.0",
"monaco-editor": "0.56.0",
"monaco-editor-core": "0.56.0",
"reflect-metadata": "^0.2.2",
"semver": "7.7.4",
"vscode-json-languageservice": "^5.3.11",
"vscode-languageserver-textdocument": "^1.0.11"
},
"devDependencies": {
"@types/semver": "^7.7.1",
"esbuild": "^0.27.3",
"typescript": "*"
}
}
96 changes: 96 additions & 0 deletions packages/playground-v2/scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { context } from "esbuild"
import { cp, mkdir, readFile, rm, writeFile } from "node:fs/promises"
import { dirname, resolve } from "node:path"
import { fileURLToPath } from "node:url"
import { compatibilityHtml, compatibilityPaths, playgroundPath } from "./routes.mjs"

const packageDirectory = resolve(dirname(fileURLToPath(import.meta.url)), "..")
const websiteDirectory = resolve(packageDirectory, "../..")
const vendorDirectory = resolve(packageDirectory, "vendor")
const outputDirectory = resolve(packageDirectory, "dist")
const websitePlayDirectory = resolve(websiteDirectory, "packages/typescriptlang-org/static/play")
const websiteStaticDirectory = resolve(websitePlayDirectory, "v2")
const compatibilityDirectories = compatibilityPaths.map(path =>
resolve(websiteDirectory, "packages/typescriptlang-org/static", path)
)
const serve = process.argv.includes("--serve")
const playgroundBase = serve ? "/" : process.env.PLAYGROUND_BASE ?? playgroundPath

const releaseIndex = resolve(packageDirectory, "vendor/versions.json")
const examplesIndex = resolve(packageDirectory, "vendor/examples.json")
const helpIndex = resolve(packageDirectory, "vendor/help.json")
const editorWorker = fileURLToPath(import.meta.resolve("monaco-editor/editor/editor.worker"))
const coiServiceWorker = fileURLToPath(import.meta.resolve("coi-serviceworker/coi-serviceworker.min.js"))

const distribution = JSON.parse(await readFile(resolve(vendorDirectory, "distribution.json"), "utf8"))
const version = distribution.version
const indexHtml = (await readFile(resolve(packageDirectory, "src/index.html"), "utf8"))
.replaceAll("__PLAYGROUND_BASE__", playgroundBase)
.replaceAll("__COMPILER_VERSION__", version)
.replace("<title>", `<title data-typescript-version="${version}">`)

await rm(outputDirectory, { force: true, recursive: true })
await mkdir(outputDirectory, { recursive: true })
await Promise.all([
writeFile(resolve(outputDirectory, "index.html"), indexHtml),
cp(coiServiceWorker, resolve(outputDirectory, "coi-serviceworker.min.js")),
cp(releaseIndex, resolve(outputDirectory, "versions.json")),
cp(examplesIndex, resolve(outputDirectory, "examples.json")),
cp(helpIndex, resolve(outputDirectory, "help.json")),
cp(resolve(vendorDirectory, "distribution.json"), resolve(outputDirectory, "distribution.json")),
])

const buildContext = await context({
absWorkingDir: packageDirectory,
bundle: true,
conditions: ["browser", "default"],
define: {
__COMPILER_DISTRIBUTION_URL__: JSON.stringify(process.env.COMPILER_DISTRIBUTION_URL || "./distribution.json"),
__TS_VERSION__: JSON.stringify(version),
},
entryNames: "[name]",
entryPoints: {
main: resolve(packageDirectory, "src/main.ts"),
"editor.worker": editorWorker,
"strada.worker": resolve(packageDirectory, "src/strada.worker.ts"),
"native.worker": resolve(packageDirectory, "src/native.worker.ts"),
"tsgo-lsp.worker": resolve(packageDirectory, "src/tsgo-lsp.worker.ts"),
},
format: "esm",
loader: {
".ttf": "file",
".woff": "file",
".woff2": "file",
},
outdir: outputDirectory,
metafile: true,
platform: "browser",
sourcemap: true,
target: ["es2022"],
})

if (serve) {
await buildContext.watch()
const server = await buildContext.serve({
host: "127.0.0.1",
port: 4173,
servedir: outputDirectory,
})
console.log(`TypeScript Playground v2: http://${server.host}:${server.port}`)
} else {
const result = await buildContext.rebuild()
const compilerInputs = Object.keys(result.metafile.inputs).filter(path =>
/(?:vendor|node_modules)\/(?:@typescript\/)?typescript(?:-wasip1-wasm)?\//.test(path)
)
if (compilerInputs.length) throw new Error(`Compiler implementation was bundled: ${compilerInputs.join(", ")}`)
await buildContext.dispose()
await rm(websitePlayDirectory, { force: true, recursive: true })
await cp(outputDirectory, websiteStaticDirectory, { recursive: true })
await Promise.all(
compatibilityDirectories.map(async directory => {
await mkdir(directory, { recursive: true })
await writeFile(resolve(directory, "index.html"), compatibilityHtml)
})
)
console.log(`Built TypeScript ${version} playground in ${outputDirectory}`)
}
14 changes: 14 additions & 0 deletions packages/playground-v2/scripts/routes.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export const playgroundPath = "/play/v2/"
export const compatibilityPaths = ["play/7", "v2"]
export const compatibilityScript = `location.replace(${JSON.stringify(
playgroundPath
)} + location.search + location.hash)`

export const compatibilityHtml = `<!doctype html>
<meta charset="utf-8">
<title>TypeScript Playground v2</title>
<script>
${compatibilityScript}
</script>
<noscript><a href="${playgroundPath}">Continue to TypeScript Playground v2</a></noscript>
`
86 changes: 86 additions & 0 deletions packages/playground-v2/scripts/smoke-test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import assert from "node:assert/strict"
import { readFile, readdir } from "node:fs/promises"
import { runInNewContext } from "node:vm"
import { compatibilityHtml, compatibilityPaths, compatibilityScript, playgroundPath } from "./routes.mjs"
import { API } from "@typescript/typescript/sync"
import { instantiateWasm, WasmTransport } from "@typescript/typescript/wasm"
import { wasmURL } from "@typescript/typescript-wasip1-wasm"

const wasm = await readFile(wasmURL)
const module = await WebAssembly.compile(wasm)
const instance = await instantiateWasm(module)
const transport = new WasmTransport({ instance, cwd: "/workspace" })
const api = new API({ transport })

try {
assert(compatibilityHtml.includes(`<script>\n ${compatibilityScript}\n</script>`))
for (const path of compatibilityPaths) {
const original = new URL(`https://example.test/${path}/?ts=6.0.3&target=99#code/v2/encoded+project`)
let redirected
runInNewContext(compatibilityScript, {
location: {
search: original.search,
hash: original.hash,
replace(value) {
redirected = value
},
},
})
assert.equal(redirected, `${playgroundPath}${original.search}${original.hash}`)
}

const libListURL = new URL(import.meta.resolve("@typescript/typescript-wasip1-wasm/lib/libFiles.json"))
const libFileNames = JSON.parse(await readFile(libListURL, "utf8"))
assert.deepEqual(
libFileNames,
(await readdir(new URL("./", libListURL))).filter(fileName => /^lib(?:\..+)?\.d\.ts$/.test(fileName)).sort()
)
for (const fileName of libFileNames) {
transport.setFile(`/${fileName}`, await readFile(new URL(fileName, libListURL), "utf8"))
}

const files = {
"/workspace/tsconfig.json": JSON.stringify({
compilerOptions: {
declaration: true,
module: "CommonJS",
strict: true,
target: "ES2022",
},
include: ["./src/**/*"],
}),
"/workspace/src/greet.ts": "export const greet = (name: string) => `Hello, ${name}!`;",
"/workspace/src/index.ts": 'import { greet } from "./greet"; console.log(greet("TS7"));',
}
for (const [fileName, source] of Object.entries(files)) {
transport.setFile(fileName, source)
}

const config = api.readConfigFile("/workspace/tsconfig.json")
assert.equal(config.error, undefined)
const parsed = api.parseJsonConfigFileContent(config.config, {
configFileName: "/workspace/tsconfig.json",
})
assert.deepEqual(parsed.fileNames, ["/workspace/src/greet.ts", "/workspace/src/index.ts"])
const program = api.createProgram(parsed.fileNames, parsed.options, {
projectReferences: parsed.projectReferences,
configFileParsingDiagnostics: parsed.errors,
})
try {
assert.equal(program.getSyntacticDiagnostics().length, 0)
assert.equal(program.getSemanticDiagnostics().length, 0)
const emit = program.emitToString()
assert.equal(emit.emitSkipped, false)
assert.deepEqual(
[...emit.outputFiles.keys()],
["/workspace/src/greet.d.ts", "/workspace/src/greet.js", "/workspace/src/index.d.ts", "/workspace/src/index.js"]
)
assert.match(emit.outputFiles.get("/workspace/src/index.js").text, /require\("\.\/greet"\)/)
} finally {
program.dispose()
}
} finally {
api.close()
}

console.log("TypeScript WASM API smoke test passed")
32 changes: 32 additions & 0 deletions packages/playground-v2/scripts/test-ata.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { build } from "esbuild"
import { spawnSync } from "node:child_process"
import { mkdir, rm } from "node:fs/promises"
import { resolve } from "node:path"

const packageDirectory = resolve(import.meta.dirname, "..")
const testFiles = ["ata.test.mjs", "native-compiler.test.mjs", "lsp-filesystem.test.mjs"].map(name =>
resolve(packageDirectory, "dist", name)
)
await mkdir(resolve(packageDirectory, "dist"), { recursive: true })
try {
await build({
absWorkingDir: packageDirectory,
bundle: true,
conditions: ["browser"],
entryPoints: ["src/ata/ata.test.ts", "src/native-compiler.test.ts", "src/lsp-filesystem.test.ts"],
entryNames: "[name]",
outExtension: { ".js": ".mjs" },
external: ["jsonc-parser"],
format: "esm",
outdir: resolve(packageDirectory, "dist"),
platform: "node",
target: ["es2022"],
})
const result = spawnSync(process.execPath, ["--test", ...testFiles], {
stdio: "inherit",
})
if (result.error) throw result.error
if (result.status !== 0) process.exitCode = result.status ?? 1
} finally {
await Promise.all(testFiles.map(file => rm(file, { force: true })))
}
76 changes: 76 additions & 0 deletions packages/playground-v2/scripts/update-compiler.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { createHash } from "node:crypto"
import { readFile, writeFile } from "node:fs/promises"
import { dirname, resolve } from "node:path"
import { fileURLToPath } from "node:url"

const packageDirectory = resolve(dirname(fileURLToPath(import.meta.url)), "..")
const mainURL = new URL(import.meta.resolve("@typescript/typescript/package.json"))
const artifactURL = new URL(import.meta.resolve("@typescript/typescript-wasip1-wasm/package.json"))
const main = JSON.parse(await readFile(mainURL, "utf8"))
const artifact = JSON.parse(await readFile(artifactURL, "utf8"))
const dependencies = JSON.parse(await readFile(resolve(packageDirectory, "package.json"), "utf8")).dependencies
const version = main.version
const revision = main.gitHead
if (
dependencies["@typescript/typescript"] !== `npm:typescript@${version}` ||
dependencies["@typescript/typescript-wasip1-wasm"] !== version
) {
throw new Error("Install the pinned compiler dependencies before updating the distribution")
}
if (version !== artifact.version || !revision || revision !== artifact.gitHead) {
throw new Error("TypeScript API and WASI artifact versions and revisions must match")
}
if (main.imports) throw new Error("The compiler distribution must not require package-private imports")

function entry(manifest, subpath) {
const value = manifest.exports[subpath]
const path = typeof value === "string" ? value : value?.default
if (typeof path !== "string" || !path.startsWith("./")) throw new Error(`Missing package export: ${subpath}`)
return path
}

function cdnEntry(manifest, subpath) {
return new URL(entry(manifest, subpath), `https://unpkg.com/${manifest.name}@${version}/`).href
}

const libraryIndexURL = new URL(entry(artifact, "./lib/libFiles.json"), artifactURL)
const libraries = JSON.parse(await readFile(libraryIndexURL, "utf8"))
if (
!Array.isArray(libraries) ||
libraries.length === 0 ||
libraries.some(name => typeof name !== "string" || !/^lib(?:\.[\w.]+)?\.d\.ts$/.test(name))
) {
throw new Error("Invalid WASI library index")
}
const paths = {
sync: cdnEntry(main, "./sync"),
async: cdnEntry(main, "./async"),
ast: cdnEntry(main, "./ast"),
host: cdnEntry(main, "./wasm"),
wasm: cdnEntry(artifact, "./lib/tsc.wasm"),
libraryIndex: cdnEntry(artifact, "./lib/libFiles.json"),
schema: cdnEntry(main, "./schemas/tsconfig.schema.json"),
}
const files = [
new URL(entry(artifact, "./lib/tsc.wasm"), artifactURL),
libraryIndexURL,
new URL(entry(main, "./schemas/tsconfig.schema.json"), mainURL),
...libraries.map(name => new URL(name, libraryIndexURL)),
]
const bytes = await Promise.all(files.map(url => readFile(url)))
const cacheKey = createHash("sha256").update(`${version}\0${revision}`).digest("hex").slice(0, 16)
await writeFile(
resolve(packageDirectory, "vendor/distribution.json"),
`${JSON.stringify(
{
version,
revision,
cacheKey,
...paths,
downloadBytes: bytes.reduce((sum, value) => sum + value.byteLength, 0),
},
undefined,
2
)}\n`
)
console.log(`Pinned the CDN distribution to TypeScript ${version} at ${revision}`)
Loading
Loading