|
| 1 | +import { dedent } from "../../_namespaces/Utils"; |
| 2 | +import { FsContents, libContent } from "./contents"; |
| 3 | +import { loadProjectFromFiles } from "./vfs"; |
| 4 | +import { createServerHost, createWatchedSystem } from "./virtualFileSystemWithWatch"; |
| 5 | + |
| 6 | +function getFsContentsForLibResolution(libRedirection?: boolean): FsContents { |
| 7 | + return { |
| 8 | + "/home/src/projects/project1/utils.d.ts": `export const y = 10;`, |
| 9 | + "/home/src/projects/project1/file.ts": `export const file = 10;`, |
| 10 | + "/home/src/projects/project1/core.d.ts": `export const core = 10;`, |
| 11 | + "/home/src/projects/project1/index.ts": `export const x = "type1";`, |
| 12 | + "/home/src/projects/project1/file2.ts": dedent` |
| 13 | + /// <reference lib="webworker"/> |
| 14 | + /// <reference lib="scripthost"/> |
| 15 | + /// <reference lib="es5"/> |
| 16 | + `, |
| 17 | + "/home/src/projects/project1/tsconfig.json": JSON.stringify({ |
| 18 | + compilerOptions: { composite: true, typeRoots: ["./typeroot1"], lib: ["es5", "dom"], traceResolution: true }, |
| 19 | + }), |
| 20 | + "/home/src/projects/project1/typeroot1/sometype/index.d.ts": `export type TheNum = "type1";`, |
| 21 | + "/home/src/projects/project2/utils.d.ts": `export const y = 10;`, |
| 22 | + "/home/src/projects/project2/index.ts": `export const y = 10`, |
| 23 | + "/home/src/projects/project2/tsconfig.json": JSON.stringify({ |
| 24 | + compilerOptions: { composite: true, lib: ["es5", "dom"], traceResolution: true }, |
| 25 | + }), |
| 26 | + "/home/src/projects/project3/utils.d.ts": `export const y = 10;`, |
| 27 | + "/home/src/projects/project3/index.ts": `export const z = 10`, |
| 28 | + "/home/src/projects/project3/tsconfig.json": JSON.stringify({ |
| 29 | + compilerOptions: { composite: true, lib: ["es5", "dom"], traceResolution: true }, |
| 30 | + }), |
| 31 | + "/home/src/projects/project4/utils.d.ts": `export const y = 10;`, |
| 32 | + "/home/src/projects/project4/index.ts": `export const z = 10`, |
| 33 | + "/home/src/projects/project4/tsconfig.json": JSON.stringify({ |
| 34 | + compilerOptions: { composite: true, lib: ["esnext", "dom", "webworker"], traceResolution: true }, |
| 35 | + }), |
| 36 | + "/home/src/lib/lib.es5.d.ts": libContent, |
| 37 | + "/home/src/lib/lib.esnext.d.ts": libContent, |
| 38 | + "/home/src/lib/lib.dom.d.ts": "interface DOMInterface { }", |
| 39 | + "/home/src/lib/lib.webworker.d.ts": "interface WebWorkerInterface { }", |
| 40 | + "/home/src/lib/lib.scripthost.d.ts": "interface ScriptHostInterface { }", |
| 41 | + "/home/src/projects/node_modules/@typescript/unlreated/index.d.ts": "export const unrelated = 10;", |
| 42 | + ...libRedirection ? { |
| 43 | + "/home/src/projects/node_modules/@typescript/lib-es5/index.d.ts": libContent, |
| 44 | + "/home/src/projects/node_modules/@typescript/lib-esnext/index.d.ts": libContent, |
| 45 | + "/home/src/projects/node_modules/@typescript/lib-dom/index.d.ts": "interface DOMInterface { }", |
| 46 | + "/home/src/projects/node_modules/@typescript/lib-webworker/index.d.ts": "interface WebworkerInterface { }", |
| 47 | + "/home/src/projects/node_modules/@typescript/lib-scripthost/index.d.ts": "interface ScriptHostInterface { }", |
| 48 | + } : undefined |
| 49 | + }; |
| 50 | +} |
| 51 | + |
| 52 | +export function getFsForLibResolution(libRedirection: true | undefined) { |
| 53 | + return loadProjectFromFiles( |
| 54 | + getFsContentsForLibResolution(libRedirection), |
| 55 | + { |
| 56 | + cwd: "/home/src/projects", |
| 57 | + executingFilePath: "/home/src/lib/tsc.js", |
| 58 | + } |
| 59 | + ); |
| 60 | +} |
| 61 | + |
| 62 | +export function getSysForLibResolution(libRedirection?: true) { |
| 63 | + return createWatchedSystem( |
| 64 | + getFsContentsForLibResolution(libRedirection), |
| 65 | + { |
| 66 | + currentDirectory: "/home/src/projects", |
| 67 | + executingFilePath: "/home/src/lib/tsc.js", |
| 68 | + } |
| 69 | + ); |
| 70 | +} |
| 71 | + |
| 72 | +export function getServerHosForLibResolution(libRedirection?: true) { |
| 73 | + return createServerHost( |
| 74 | + getFsContentsForLibResolution(libRedirection), |
| 75 | + { |
| 76 | + currentDirectory: "/home/src/projects", |
| 77 | + executingFilePath: "/home/src/lib/tsc.js", |
| 78 | + } |
| 79 | + ); |
| 80 | +} |
| 81 | + |
| 82 | +export function getCommandLineArgsForLibResolution(withoutConfig: true | undefined) { |
| 83 | + return withoutConfig ? |
| 84 | + ["project1/core.d.ts", "project1/utils.d.ts", "project1/file.ts", "project1/index.ts", "project1/file2.ts", "--lib", "es5,dom", "--traceResolution", "--explainFiles"] : |
| 85 | + ["-p", "project1", "--explainFiles"]; |
| 86 | +} |
0 commit comments