-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Refs #58
- Loading branch information
Showing
5 changed files
with
132 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { | ||
createDefaultMapFromCDN, | ||
createSystem, | ||
createVirtualTypeScriptEnvironment, | ||
} from "@typescript/vfs"; | ||
import * as Comlink from "comlink"; | ||
import ts from "typescript"; | ||
import { createWorker } from "../src/worker/createWorker.js"; | ||
import type { Remote } from "comlink"; | ||
|
||
const _env = (async () => { | ||
const fsMap = await createDefaultMapFromCDN( | ||
{ target: ts.ScriptTarget.ES2022 }, | ||
ts.version, | ||
false, | ||
ts, | ||
); | ||
const system = createSystem(fsMap); | ||
return createVirtualTypeScriptEnvironment(system, [], ts, { | ||
lib: ["ES2022"], | ||
}); | ||
})(); | ||
|
||
const exposed = { | ||
async getTranspiledFile(path: string) { | ||
const env = await _env; | ||
const file = env.getSourceFile(path); | ||
if (!file) throw new Error(`File not found for path ${path}`); | ||
return ts.transpileModule(file.text, { | ||
compilerOptions: { | ||
target: ts.ScriptTarget.ES2015, | ||
module: ts.ModuleKind.None, | ||
}, | ||
}); | ||
}, | ||
worker: createWorker({ | ||
env: _env, | ||
}), | ||
}; | ||
|
||
export type Exposed = Remote<typeof exposed>; | ||
|
||
Comlink.expose(exposed); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters