mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-11 19:27:35 -06:00
Use absolute paths for buildInfoDirectory
This commit is contained in:
parent
b9fc44ece7
commit
d36099c98d
@ -243,7 +243,7 @@ namespace ts {
|
||||
|
||||
function convertToDiagnostics(diagnostics: ReadonlyArray<ReusableDiagnostic>, newProgram: Program, getCanonicalFileName: GetCanonicalFileName): ReadonlyArray<Diagnostic> {
|
||||
if (!diagnostics.length) return emptyArray;
|
||||
const buildInfoDirectory = getDirectoryPath(getOutputPathForBuildInfo(newProgram.getCompilerOptions())!);
|
||||
const buildInfoDirectory = getDirectoryPath(getNormalizedAbsolutePath(getOutputPathForBuildInfo(newProgram.getCompilerOptions())!, newProgram.getCurrentDirectory()));
|
||||
return diagnostics.map(diagnostic => {
|
||||
const result: Diagnostic = convertToDiagnosticRelatedInformation(diagnostic, newProgram, toPath);
|
||||
result.reportsUnnecessary = diagnostic.reportsUnnecessary;
|
||||
@ -612,7 +612,7 @@ namespace ts {
|
||||
*/
|
||||
function getProgramBuildInfo(state: Readonly<ReusableBuilderProgramState>, getCanonicalFileName: GetCanonicalFileName): ProgramBuildInfo | undefined {
|
||||
if (state.compilerOptions.outFile || state.compilerOptions.out) return undefined;
|
||||
const buildInfoDirectory = getDirectoryPath(getOutputPathForBuildInfo(state.compilerOptions)!);
|
||||
const buildInfoDirectory = getDirectoryPath(getNormalizedAbsolutePath(getOutputPathForBuildInfo(state.compilerOptions)!, Debug.assertDefined(state.program).getCurrentDirectory()));
|
||||
const fileInfos: MapLike<BuilderState.FileInfo> = {};
|
||||
state.fileInfos.forEach((value, key) => {
|
||||
const signature = state.currentAffectedFilesSignatures && state.currentAffectedFilesSignatures.get(key);
|
||||
@ -1015,9 +1015,9 @@ namespace ts {
|
||||
return map;
|
||||
}
|
||||
|
||||
export function createBuildProgramUsingProgramBuildInfo(program: ProgramBuildInfo, buildInfoPath: string, useCaseSensitiveFileNames: boolean): EmitAndSemanticDiagnosticsBuilderProgram {
|
||||
const buildInfoDirectory = getDirectoryPath(buildInfoPath);
|
||||
const getCanonicalFileName = createGetCanonicalFileName(useCaseSensitiveFileNames);
|
||||
export function createBuildProgramUsingProgramBuildInfo(program: ProgramBuildInfo, buildInfoPath: string, host: ReadBuildProgramHost): EmitAndSemanticDiagnosticsBuilderProgram {
|
||||
const buildInfoDirectory = getDirectoryPath(getNormalizedAbsolutePath(buildInfoPath, host.getCurrentDirectory()));
|
||||
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames());
|
||||
|
||||
const fileInfos = createMap<BuilderState.FileInfo>();
|
||||
for (const key in program.fileInfos) {
|
||||
|
||||
@ -251,10 +251,10 @@ namespace ts {
|
||||
function emitSourceFileOrBundle({ jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath, buildInfoPath }: EmitFileNames, sourceFileOrBundle: SourceFile | Bundle | undefined) {
|
||||
let buildInfoDirectory: string | undefined;
|
||||
if (buildInfoPath && sourceFileOrBundle && isBundle(sourceFileOrBundle)) {
|
||||
buildInfoDirectory = getDirectoryPath(buildInfoPath);
|
||||
buildInfoDirectory = getDirectoryPath(getNormalizedAbsolutePath(buildInfoPath, host.getCurrentDirectory()));
|
||||
bundleBuildInfo = {
|
||||
commonSourceDirectory: relativeToBuildInfo(host.getCommonSourceDirectory()),
|
||||
sourceFiles: sourceFileOrBundle.sourceFiles.map(file => relativeToBuildInfo(file.fileName))
|
||||
sourceFiles: sourceFileOrBundle.sourceFiles.map(file => relativeToBuildInfo(getNormalizedAbsolutePath(file.fileName, host.getCurrentDirectory())))
|
||||
};
|
||||
}
|
||||
emitJsFileOrBundle(sourceFileOrBundle, jsFilePath, sourceMapFilePath, relativeToBuildInfo);
|
||||
@ -629,10 +629,14 @@ namespace ts {
|
||||
getNewLine(): string;
|
||||
}
|
||||
|
||||
function createSourceFilesFromBundleBuildInfo(bundle: BundleBuildInfo, buildInfoDirectory: string): ReadonlyArray<SourceFile> {
|
||||
function createSourceFilesFromBundleBuildInfo(bundle: BundleBuildInfo, buildInfoDirectory: string, host: EmitUsingBuildInfoHost): ReadonlyArray<SourceFile> {
|
||||
const sourceFiles = bundle.sourceFiles.map(fileName => {
|
||||
const sourceFile = createNode(SyntaxKind.SourceFile, 0, 0) as SourceFile;
|
||||
sourceFile.fileName = getNormalizedAbsolutePath(fileName, buildInfoDirectory);
|
||||
sourceFile.fileName = getRelativePathFromDirectory(
|
||||
host.getCurrentDirectory(),
|
||||
getNormalizedAbsolutePath(fileName, buildInfoDirectory),
|
||||
!host.useCaseSensitiveFileNames()
|
||||
);
|
||||
sourceFile.text = "";
|
||||
sourceFile.statements = createNodeArray();
|
||||
return sourceFile;
|
||||
@ -676,7 +680,7 @@ namespace ts {
|
||||
|
||||
const buildInfo = getBuildInfo(buildInfoText);
|
||||
if (!buildInfo.bundle || !buildInfo.bundle.js || (declarationText && !buildInfo.bundle.dts)) return buildInfoPath!;
|
||||
const buildInfoDirectory = getDirectoryPath(buildInfoPath!);
|
||||
const buildInfoDirectory = getDirectoryPath(getNormalizedAbsolutePath(buildInfoPath!, host.getCurrentDirectory()));
|
||||
const ownPrependInput = createInputFiles(
|
||||
jsFileText,
|
||||
declarationText!,
|
||||
@ -692,7 +696,7 @@ namespace ts {
|
||||
);
|
||||
const outputFiles: OutputFile[] = [];
|
||||
const prependNodes = createPrependNodes(config.projectReferences, getCommandLine, f => host.readFile(f));
|
||||
const sourceFilesForJsEmit = createSourceFilesFromBundleBuildInfo(buildInfo.bundle, buildInfoDirectory);
|
||||
const sourceFilesForJsEmit = createSourceFilesFromBundleBuildInfo(buildInfo.bundle, buildInfoDirectory, host);
|
||||
const emitHost: EmitHost = {
|
||||
getPrependNodes: memoize(() => [...prependNodes, ownPrependInput]),
|
||||
getCanonicalFileName: host.getCanonicalFileName,
|
||||
|
||||
@ -1298,11 +1298,11 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function getOldProgram<T extends BuilderProgram>({ options, builderPrograms, readFileWithCache, host }: SolutionBuilderState<T>, proj: ResolvedConfigFilePath, parsed: ParsedCommandLine) {
|
||||
function getOldProgram<T extends BuilderProgram>({ options, builderPrograms, compilerHost }: SolutionBuilderState<T>, proj: ResolvedConfigFilePath, parsed: ParsedCommandLine) {
|
||||
if (options.force) return undefined;
|
||||
const value = builderPrograms.get(proj);
|
||||
if (value) return value;
|
||||
return readBuilderProgram(parsed.options, readFileWithCache, host.useCaseSensitiveFileNames()) as any as T;
|
||||
return readBuilderProgram(parsed.options, compilerHost) as any as T;
|
||||
}
|
||||
|
||||
function afterProgramCreate<T extends BuilderProgram>({ host, watch, builderPrograms }: SolutionBuilderState<T>, proj: ResolvedConfigFilePath, program: T) {
|
||||
|
||||
@ -437,16 +437,21 @@ namespace ts {
|
||||
}
|
||||
|
||||
namespace ts {
|
||||
export function readBuilderProgram(compilerOptions: CompilerOptions, readFile: (path: string) => string | undefined, useCaseSensitiveFileNames: boolean) {
|
||||
export interface ReadBuildProgramHost {
|
||||
useCaseSensitiveFileNames(): boolean;
|
||||
getCurrentDirectory(): string;
|
||||
readFile(fileName: string): string | undefined;
|
||||
}
|
||||
export function readBuilderProgram(compilerOptions: CompilerOptions, host: ReadBuildProgramHost) {
|
||||
if (compilerOptions.out || compilerOptions.outFile) return undefined;
|
||||
const buildInfoPath = getOutputPathForBuildInfo(compilerOptions);
|
||||
if (!buildInfoPath) return undefined;
|
||||
const content = readFile(buildInfoPath);
|
||||
const content = host.readFile(buildInfoPath);
|
||||
if (!content) return undefined;
|
||||
const buildInfo = getBuildInfo(content);
|
||||
if (buildInfo.version !== version) return undefined;
|
||||
if (!buildInfo.program) return undefined;
|
||||
return createBuildProgramUsingProgramBuildInfo(buildInfo.program, buildInfoPath, useCaseSensitiveFileNames);
|
||||
return createBuildProgramUsingProgramBuildInfo(buildInfo.program, buildInfoPath, host);
|
||||
}
|
||||
|
||||
export function createIncrementalCompilerHost(options: CompilerOptions, system = sys): CompilerHost {
|
||||
@ -471,7 +476,7 @@ namespace ts {
|
||||
}: IncrementalProgramOptions<T>): T {
|
||||
host = host || createIncrementalCompilerHost(options);
|
||||
createProgram = createProgram || createEmitAndSemanticDiagnosticsBuilderProgram as any as CreateProgram<T>;
|
||||
const oldProgram = readBuilderProgram(options, path => host!.readFile(path), host.useCaseSensitiveFileNames()) as any as T;
|
||||
const oldProgram = readBuilderProgram(options, host) as any as T;
|
||||
return createProgram(rootNames, options, host, oldProgram, configFileParsingDiagnostics, projectReferences);
|
||||
}
|
||||
|
||||
@ -747,7 +752,7 @@ namespace ts {
|
||||
((typeDirectiveNames, containingFile, redirectedReference) => resolutionCache.resolveTypeReferenceDirectives(typeDirectiveNames, containingFile, redirectedReference));
|
||||
const userProvidedResolution = !!host.resolveModuleNames || !!host.resolveTypeReferenceDirectives;
|
||||
|
||||
builderProgram = readBuilderProgram(compilerOptions, path => compilerHost.readFile(path), compilerHost.useCaseSensitiveFileNames()) as any as T;
|
||||
builderProgram = readBuilderProgram(compilerOptions, compilerHost) as any as T;
|
||||
synchronizeProgram();
|
||||
|
||||
// Update the wild card directory watch
|
||||
|
||||
@ -4450,7 +4450,12 @@ declare namespace ts {
|
||||
function createAbstractBuilder(rootNames: ReadonlyArray<string> | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: BuilderProgram, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>, projectReferences?: ReadonlyArray<ProjectReference>): BuilderProgram;
|
||||
}
|
||||
declare namespace ts {
|
||||
function readBuilderProgram(compilerOptions: CompilerOptions, readFile: (path: string) => string | undefined, useCaseSensitiveFileNames: boolean): EmitAndSemanticDiagnosticsBuilderProgram | undefined;
|
||||
interface ReadBuildProgramHost {
|
||||
useCaseSensitiveFileNames(): boolean;
|
||||
getCurrentDirectory(): string;
|
||||
readFile(fileName: string): string | undefined;
|
||||
}
|
||||
function readBuilderProgram(compilerOptions: CompilerOptions, host: ReadBuildProgramHost): EmitAndSemanticDiagnosticsBuilderProgram | undefined;
|
||||
function createIncrementalCompilerHost(options: CompilerOptions, system?: System): CompilerHost;
|
||||
interface IncrementalProgramOptions<T extends BuilderProgram> {
|
||||
rootNames: ReadonlyArray<string>;
|
||||
|
||||
@ -4450,7 +4450,12 @@ declare namespace ts {
|
||||
function createAbstractBuilder(rootNames: ReadonlyArray<string> | undefined, options: CompilerOptions | undefined, host?: CompilerHost, oldProgram?: BuilderProgram, configFileParsingDiagnostics?: ReadonlyArray<Diagnostic>, projectReferences?: ReadonlyArray<ProjectReference>): BuilderProgram;
|
||||
}
|
||||
declare namespace ts {
|
||||
function readBuilderProgram(compilerOptions: CompilerOptions, readFile: (path: string) => string | undefined, useCaseSensitiveFileNames: boolean): EmitAndSemanticDiagnosticsBuilderProgram | undefined;
|
||||
interface ReadBuildProgramHost {
|
||||
useCaseSensitiveFileNames(): boolean;
|
||||
getCurrentDirectory(): string;
|
||||
readFile(fileName: string): string | undefined;
|
||||
}
|
||||
function readBuilderProgram(compilerOptions: CompilerOptions, host: ReadBuildProgramHost): EmitAndSemanticDiagnosticsBuilderProgram | undefined;
|
||||
function createIncrementalCompilerHost(options: CompilerOptions, system?: System): CompilerHost;
|
||||
interface IncrementalProgramOptions<T extends BuilderProgram> {
|
||||
rootNames: ReadonlyArray<string>;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user