mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 21:06:50 -05:00
Update the builder to take options aligning with the WatchCompilerHost
This commit is contained in:
@@ -66,6 +66,15 @@ namespace ts {
|
||||
export function createBuilder(options: BuilderOptions, builderType: BuilderType.SemanticDiagnosticsBuilder): SemanticDiagnosticsBuilder;
|
||||
export function createBuilder(options: BuilderOptions, builderType: BuilderType.EmitAndSemanticDiagnosticsBuilder): EmitAndSemanticDiagnosticsBuilder;
|
||||
export function createBuilder(options: BuilderOptions, builderType: BuilderType) {
|
||||
/**
|
||||
* Create the canonical file name for identity
|
||||
*/
|
||||
const getCanonicalFileName = createGetCanonicalFileName(options.useCaseSensitiveFileNames());
|
||||
/**
|
||||
* Computing hash to for signature verification
|
||||
*/
|
||||
const computeHash = options.createHash || identity;
|
||||
|
||||
/**
|
||||
* Information of the file eg. its version, signature etc
|
||||
*/
|
||||
@@ -572,7 +581,7 @@ namespace ts {
|
||||
else {
|
||||
const emitOutput = getFileEmitOutput(program, sourceFile, /*emitOnlyDtsFiles*/ true, cancellationToken);
|
||||
if (emitOutput.outputFiles && emitOutput.outputFiles.length > 0) {
|
||||
latestSignature = options.computeHash(emitOutput.outputFiles[0].text);
|
||||
latestSignature = computeHash(emitOutput.outputFiles[0].text);
|
||||
}
|
||||
else {
|
||||
latestSignature = prevSignature;
|
||||
@@ -609,7 +618,7 @@ namespace ts {
|
||||
// Handle triple slash references
|
||||
if (sourceFile.referencedFiles && sourceFile.referencedFiles.length > 0) {
|
||||
for (const referencedFile of sourceFile.referencedFiles) {
|
||||
const referencedPath = toPath(referencedFile.fileName, sourceFileDirectory, options.getCanonicalFileName);
|
||||
const referencedPath = toPath(referencedFile.fileName, sourceFileDirectory, getCanonicalFileName);
|
||||
addReferencedFile(referencedPath);
|
||||
}
|
||||
}
|
||||
@@ -622,7 +631,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
const fileName = resolvedTypeReferenceDirective.resolvedFileName;
|
||||
const typeFilePath = toPath(fileName, sourceFileDirectory, options.getCanonicalFileName);
|
||||
const typeFilePath = toPath(fileName, sourceFileDirectory, getCanonicalFileName);
|
||||
addReferencedFile(typeFilePath);
|
||||
});
|
||||
}
|
||||
@@ -738,8 +747,14 @@ namespace ts {
|
||||
export type AffectedFileResult<T> = { result: T; affected: SourceFile | Program; } | undefined;
|
||||
|
||||
export interface BuilderOptions {
|
||||
getCanonicalFileName: (fileName: string) => string;
|
||||
computeHash: (data: string) => string;
|
||||
/**
|
||||
* return true if file names are treated with case sensitivity
|
||||
*/
|
||||
useCaseSensitiveFileNames(): boolean;
|
||||
/**
|
||||
* If provided this would be used this hash instead of actual file shape text for detecting changes
|
||||
*/
|
||||
createHash?: (data: string) => string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -277,10 +277,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function createBuilderProgram(host: BuilderEmitHost): BuilderProgram {
|
||||
const builder = createEmitAndSemanticDiagnosticsBuilder({
|
||||
getCanonicalFileName: createGetCanonicalFileName(host.useCaseSensitiveFileNames()),
|
||||
computeHash: host.createHash ? host.createHash : identity
|
||||
});
|
||||
const builder = createEmitAndSemanticDiagnosticsBuilder(host);
|
||||
let program: Program;
|
||||
return {
|
||||
getCurrentDirectory: () => program.getCurrentDirectory(),
|
||||
@@ -325,9 +322,7 @@ namespace ts {
|
||||
/**
|
||||
* Host needed to emit files and report errors using builder
|
||||
*/
|
||||
export interface BuilderEmitHost {
|
||||
useCaseSensitiveFileNames(): boolean;
|
||||
createHash?: (data: string) => string;
|
||||
export interface BuilderEmitHost extends BuilderOptions {
|
||||
writeFile: WriteFileCallback;
|
||||
reportDiagnostic: DiagnosticReporter;
|
||||
writeFileName?: (s: string) => void;
|
||||
|
||||
@@ -81,10 +81,7 @@ namespace ts {
|
||||
});
|
||||
|
||||
function makeAssertChanges(getProgram: () => Program): (fileNames: ReadonlyArray<string>) => void {
|
||||
const builder = createEmitAndSemanticDiagnosticsBuilder({
|
||||
getCanonicalFileName: identity,
|
||||
computeHash: identity
|
||||
});
|
||||
const builder = createEmitAndSemanticDiagnosticsBuilder({ useCaseSensitiveFileNames: returnTrue, });
|
||||
return fileNames => {
|
||||
const program = getProgram();
|
||||
builder.updateProgram(program);
|
||||
@@ -97,10 +94,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function makeAssertChangesWithCancellationToken(getProgram: () => Program): (fileNames: ReadonlyArray<string>, cancelAfterEmitLength?: number) => void {
|
||||
const builder = createEmitAndSemanticDiagnosticsBuilder({
|
||||
getCanonicalFileName: identity,
|
||||
computeHash: identity
|
||||
});
|
||||
const builder = createEmitAndSemanticDiagnosticsBuilder({ useCaseSensitiveFileNames: returnTrue, });
|
||||
let cancel = false;
|
||||
const cancellationToken: CancellationToken = {
|
||||
isCancellationRequested: () => cancel,
|
||||
|
||||
@@ -462,8 +462,8 @@ namespace ts.server {
|
||||
this.updateGraph();
|
||||
if (!this.builder) {
|
||||
this.builder = createInternalBuilder({
|
||||
getCanonicalFileName: this.projectService.toCanonicalFileName,
|
||||
computeHash: data => this.projectService.host.createHash(data)
|
||||
useCaseSensitiveFileNames: () => this.useCaseSensitiveFileNames(),
|
||||
createHash: data => this.projectService.host.createHash(data)
|
||||
});
|
||||
}
|
||||
this.builder.updateProgram(this.program);
|
||||
|
||||
Reference in New Issue
Block a user