If you would like to manually specify the path to a tsconfig.json file then specify that:
const project = await createProject({ tsConfigFilePath: "packages/my-library/tsconfig.json",});// output all the source files that were addedconsole.log(project.getSourceFiles().map(s => s.fileName));
Note: You can override any tsconfig.json options by also providing a compilerOptions object.
For your convenience, this will automatically add all the associated source files from the tsconfig.json. If you don't wish to do that, then you will need to explicitly set skipAddingFilesFromTsConfig to true:
Custom module resolution can be specified by providing a resolution host factory function. This also supports providing custom type reference directive resolution.
For example:
import { createProject, ts } from "@ts-morph/bootstrap";// This is deno style module resolution.// Ex. `import { MyClass } from "./MyClass.ts"`;const project = await createProject({ resolutionHost: (moduleResolutionHost, getCompilerOptions) => { return { resolveModuleNames: (moduleNames, containingFile) => { const compilerOptions = getCompilerOptions(); const resolvedModules: ts.ResolvedModule[] = []; for (const moduleName of moduleNames.map(removeTsExtension)) { const result = ts.resolveModuleName(
Adding Source Files
Use the following methods:
const sourceFiles = await project.addSourceFilesByPaths("**/*.ts"); or provide an array of file globs.
const sourceFile = await project.addSourceFileAtPath("src/my-file.ts"); or use addSourceFileAtPathIfExists(filePath)