Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/fresh/src/dev/deps.ts>Project

The next-gen web framework.
Extremely Popular
Go to Latest
class Project
import { Project } from "https://deno.land/x/fresh@1.5.3/src/dev/deps.ts";

Project that holds source files.

Constructors

new
Project(options?: ProjectOptions)

Initializes a new instance.

Properties

readonly
compilerOptions: CompilerOptionsContainer

Gets the compiler options for modification.

readonly
manipulationSettings: ManipulationSettingsContainer

Gets the manipulation settings.

Methods

addDirectoryAtPath(dirPath: string, options?: DirectoryAddOptions): Directory

Adds an existing directory from the path or throws if it doesn't exist.

Will return the directory if it was already added.

addDirectoryAtPathIfExists(dirPath: string, options?: DirectoryAddOptions): Directory | undefined

Adds an existing directory from the path or returns undefined if it doesn't exist.

Will return the directory if it was already added.

addSourceFileAtPath(filePath: string): SourceFile

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): SourceFile | undefined

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

Will return the source file if it was already added.

addSourceFilesAtPaths(fileGlobs: string | ReadonlyArray<string>): SourceFile[]

Adds source files based on file globs.

addSourceFilesFromTsConfig(tsConfigFilePath: string): SourceFile[]

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 skipAddingFilesFromTsConfig option to true.

createDirectory(dirPath: string): Directory

Creates a directory at the specified path.

createSourceFile(
filePath: string,
sourceFileText?: string | OptionalKind<SourceFileStructure> | WriterFunction,
options?: SourceFileCreateOptions,
): 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.

createWriter(): CodeBlockWriter

Creates a writer with the current manipulation settings.

emit(emitOptions?: EmitOptions): Promise<EmitResult>

Asynchronously emits all the source files to the file system as JavaScript files.

emitSync(emitOptions?: EmitOptions): EmitResult

Synchronously emits all the source files to the file system as JavaScript files.

emitToMemory(emitOptions?: EmitOptions): MemoryEmitResult

Emits all the source files to memory.

enableLogging(enabled?: boolean): void

Enables logging to the console.

forgetNodesCreatedInBlock<T = void>(block: (remember: (...node: Node[]) => void) => T): T

Forgets the nodes created in the scope of the passed in block.

This is an advanced method that can be used to easily "forget" all the nodes created within the scope of the block.

forgetNodesCreatedInBlock<T = void>(block: (remember: (...node: Node[]) => void) => Promise<T>): Promise<T>

Forgets the nodes created in the scope of the passed in block asynchronously.

This is an advanced method that can be used to easily "forget" all the nodes created within the scope of the block.

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

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

getAmbientModule(moduleName: string): Symbol | undefined

Gets the specified ambient module symbol or returns undefined if not found.

getAmbientModuleOrThrow(moduleName: string, message?: string | (() => string)): Symbol

Gets the specified ambient module symbol or throws if not found.

getAmbientModules(): Symbol[]

Gets the ambient module symbols (ex. modules in the @types folder or node_modules).

getCompilerOptions(): CompilerOptions

Gets the compiler options.

Gets the diagnostics found when parsing the tsconfig.json file provided in the project's constructor.

getDirectories(): Directory[]

Gets all the directories.

getDirectory(dirPath: string): Directory | undefined

Gets a directory by the specified path or returns undefined if it doesn't exist.

getDirectoryOrThrow(dirPath: string, message?: string | (() => string)): Directory

Gets a directory by the specified path or throws if it doesn't exist.

getFileSystem(): FileSystemHost

Gets the file system.

getLanguageService(): LanguageService

Gets the language service.

getModuleResolutionHost(): ts.ModuleResolutionHost

Gets a ts.ModuleResolutionHost for the project.

getPreEmitDiagnostics(): Diagnostic[]

Gets the pre-emit diagnostics.

getProgram(): Program

Gets the program.

getRootDirectories(): Directory[]

Gets the directories without a parent.

getSourceFile(fileNameOrPath: string): SourceFile | undefined

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

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

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

getSourceFileOrThrow(fileNameOrPath: string): SourceFile

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

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

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

getSourceFiles(): SourceFile[]

Gets all the source files added to the project.

getSourceFiles(globPattern: string): SourceFile[]

Gets all the source files added to the project that match a pattern.

getSourceFiles(globPatterns: ReadonlyArray<string>): SourceFile[]

Gets all the source files added to the project that match the passed in patterns.

getTypeChecker(): TypeChecker

Gets the type checker.

removeSourceFile(sourceFile: SourceFile): boolean

Removes a source file from the project.

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

save(): Promise<void>

Saves all the unsaved source files to the file system and deletes all deleted files.

saveSync(): void

Synchronously saves all the unsaved source files to the file system and deletes all deleted files.

Remarks: This might be very slow compared to the asynchronous version if there are a lot of files.