x = await runtime.fs.init({
"package.json": JSON.stringify({
name: "nextjs-preview",
dependencies: {
react: "18.2.0",
"react-dom": "18.2.0",
typescript: "*",
"@types/react": "*",
"@types/lodash": "*",
"@typescript/vfs": "*",
serve: "*"
}
}),
"index.js": `
let ts = require("typescript")
let tsvfs = require("@typescript/vfs")
let path = require('path')
let createFSBackedSystem = tsvfs.createFSBackedSystem
let createVirtualTypeScriptEnvironment = tsvfs.createVirtualTypeScriptEnvironment
const compilerOpts = { target: ts.ScriptTarget.ES2016, esModuleInterop: true }
const fsMap = new Map()
// If using imports where the types don't directly match up to their FS representation (like the
// imports for node) then use triple-slash directives to make sure globals are set up first.
const content = \`
let xs = {
y: 10,
}
xs.
\`
fsMap.set("index.ts", content)
// By providing a project root, then the system knows how to resolve node_modules correctly
const projectRoot = path.join(__dirname)
console.log("AAAAA")
const system = createFSBackedSystem(fsMap, projectRoot, ts)
console.log("BBBBB")
const env = createVirtualTypeScriptEnvironment(system, ["index.ts"], ts, compilerOpts)
// Requests auto-completions at \`path.|\`
const completions = env.languageService.getCompletionsAtPosition("index.ts", content.length, {})
console.log('content:', content)
console.log('completions:', completions)
`
})