Skip to main content
Module

x/ts_morph/bootstrap/ts_morph_bootstrap.d.ts>Project

TypeScript Compiler API wrapper for static analysis and programmatic code changes.
Very Popular
Go to Latest
class Project
import { Project } from "https://deno.land/x/ts_morph@15.1.0/bootstrap/ts_morph_bootstrap.d.ts";

Project that holds source files.

Constructors

new
private
Project()

Properties

readonly
compilerOptions: CompilerOptionsContainer

Gets the compiler options for modification.

readonly
fileSystem: FileSystemHost

Gets the file system host used for this project.

Methods

addSourceFileAtPath(filePath: string, options?: { scriptKind?: ts.ScriptKind; }): Promise<ts.SourceFile>

Asynchronously adds an existing source file from a file path or throws if it doesn't exist.

Will return the source file if it was already added.

addSourceFileAtPathIfExists(filePath: string, options?: { scriptKind?: ts.ScriptKind; }): Promise<ts.SourceFile | undefined>

Asynchronously adds a source file from a file path if it exists or returns undefined.

Will return the source file if it was already added.

addSourceFileAtPathIfExistsSync(filePath: string, options?: { scriptKind?: ts.ScriptKind; }): ts.SourceFile | undefined

Synchronously adds a source file from a file path if it exists or returns undefined.

Will return the source file if it was already added.

addSourceFileAtPathSync(filePath: string, options?: { scriptKind?: ts.ScriptKind; }): ts.SourceFile

Synchronously adds an existing source file from a file path or throws if it doesn't exist.

Will return the source file if it was already added.

addSourceFilesByPaths(fileGlobs: string | ReadonlyArray<string>): Promise<ts.SourceFile[]>

Asynchronously adds source files based on file globs.

addSourceFilesByPathsSync(fileGlobs: string | ReadonlyArray<string>): ts.SourceFile[]

Synchronously adds source files based on file globs.

addSourceFilesFromTsConfig(tsConfigFilePath: string): Promise<ts.SourceFile[]>

Asynchronously adds all the source files from the specified tsconfig.json.

Note that this is done by default when specifying a tsconfig file in the constructor and not explicitly setting the skipAddingSourceFilesFromTsConfig option to true.

addSourceFilesFromTsConfigSync(tsConfigFilePath: string): ts.SourceFile[]

Synchronously adds all the source files from the specified tsconfig.json.

Note that this is done by default when specifying a tsconfig file in the constructor and not explicitly setting the skipAddingSourceFilesFromTsConfig option to true.

createProgram(options?: ts.CreateProgramOptions): ts.Program

Creates a new program. Note: You should get a new program any time source files are added, removed, or changed.

createSourceFile(
filePath: string,
sourceFileText?: string,
options?: { scriptKind?: ts.ScriptKind; },
): ts.SourceFile

Creates a source file at the specified file path with the specified text.

Note: The file will not be created and saved to the file system until .save() is called on the source file.

formatDiagnosticsWithColorAndContext(diagnostics: ReadonlyArray<ts.Diagnostic>, opts?: { newLineChar?: "\n" | "\r\n"; }): string

Formats an array of diagnostics with their color and context into a string.

getLanguageService(): ts.LanguageService

Gets the language service.

getModuleResolutionHost(): ts.ModuleResolutionHost

Gets a ts.ModuleResolutionHost for the project.

getSourceFile(fileNameOrPath: string): ts.SourceFile | undefined

Gets a source file by a file name or file path. Returns undefined if none exists.

getSourceFile(searchFunction: (file: ts.SourceFile) => boolean): ts.SourceFile | undefined

Gets a source file by a search function. Returns undefined if none exists.

getSourceFileOrThrow(fileNameOrPath: string): ts.SourceFile

Gets a source file by a file name or file path. Throws an error if it doesn't exist.

getSourceFileOrThrow(searchFunction: (file: ts.SourceFile) => boolean): ts.SourceFile

Gets a source file by a search function. Throws an error if it doesn't exist.

getSourceFiles(): ts.SourceFile[]

Gets the source files in the project.

removeSourceFile(filePath: string): void

Removes the source file at the provided file path.

removeSourceFile(sourceFile: ts.SourceFile): void

Removes the provided source file based on its fileName.

Adds the source files the project's source files depend on to the project.

updateSourceFile(
filePath: string,
sourceFileText: string,
options?: { scriptKind?: ts.ScriptKind; },
): ts.SourceFile

Updates the source file stored in the project at the specified path.

updateSourceFile(newSourceFile: ts.SourceFile): ts.SourceFile

Updates the source file stored in the project. The fileName of the source file object is used to tell which file to update.