Skip to content

Commit f31e9fa

Browse files
committed
dynamic import に変更
1 parent 461a1b0 commit f31e9fa

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

app/terminal/typescript/runtime.tsx

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
"use client";
22

3-
import ts, { CompilerOptions } from "typescript";
4-
import {
5-
createSystem,
6-
createVirtualTypeScriptEnvironment,
7-
knownLibFilesForCompilerOptions,
8-
VirtualTypeScriptEnvironment,
9-
} from "@typescript/vfs";
3+
import { type CompilerOptions } from "typescript";
4+
import { type VirtualTypeScriptEnvironment } from "@typescript/vfs";
105
import {
116
createContext,
127
ReactNode,
138
useCallback,
149
useContext,
1510
useEffect,
16-
useRef,
1711
useState,
1812
} from "react";
1913
import { useEmbedContext } from "../embedContext";
@@ -31,6 +25,12 @@ export function TypeScriptProvider({ children }: { children: ReactNode }) {
3125
if (tsEnv === null) {
3226
const abortController = new AbortController();
3327
(async () => {
28+
const ts = (await import("typescript")).default;
29+
const {
30+
createSystem,
31+
createVirtualTypeScriptEnvironment,
32+
knownLibFilesForCompilerOptions,
33+
} = await import("@typescript/vfs");
3434
const system = createSystem(new Map());
3535
const libFiles = knownLibFilesForCompilerOptions(compilerOptions, ts);
3636
const libFileContents = await Promise.all(
@@ -117,10 +117,17 @@ export function useTypeScript(jsEval: RuntimeContext): RuntimeContext {
117117
}
118118

119119
const emitOutput = tsEnv.languageService.getEmitOutput(filenames[0]);
120-
files = await writeFile(Object.fromEntries(emitOutput.outputFiles.map((of) => [of.name, of.text])));
120+
files = await writeFile(
121+
Object.fromEntries(
122+
emitOutput.outputFiles.map((of) => [of.name, of.text])
123+
)
124+
);
121125

122-
console.log(emitOutput)
123-
const jsOutputs = jsEval.runFiles([emitOutput.outputFiles[0].name], files);
126+
console.log(emitOutput);
127+
const jsOutputs = jsEval.runFiles(
128+
[emitOutput.outputFiles[0].name],
129+
files
130+
);
124131

125132
return outputs.concat(await jsOutputs);
126133
},

0 commit comments

Comments
 (0)