Bundle info paths as relative to tsbuildinfo file

This commit is contained in:
Sheetal Nandi
2019-06-19 14:49:13 -07:00
parent 9446fc0c0c
commit b9fc44ece7
92 changed files with 1334 additions and 1309 deletions
+37 -13
View File
@@ -249,14 +249,16 @@ 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);
bundleBuildInfo = {
commonSourceDirectory: host.getCommonSourceDirectory(),
sourceFiles: sourceFileOrBundle.sourceFiles.map(file => file.fileName)
commonSourceDirectory: relativeToBuildInfo(host.getCommonSourceDirectory()),
sourceFiles: sourceFileOrBundle.sourceFiles.map(file => relativeToBuildInfo(file.fileName))
};
}
emitJsFileOrBundle(sourceFileOrBundle, jsFilePath, sourceMapFilePath);
emitDeclarationFileOrBundle(sourceFileOrBundle, declarationFilePath, declarationMapPath);
emitJsFileOrBundle(sourceFileOrBundle, jsFilePath, sourceMapFilePath, relativeToBuildInfo);
emitDeclarationFileOrBundle(sourceFileOrBundle, declarationFilePath, declarationMapPath, relativeToBuildInfo);
emitBuildInfo(bundleBuildInfo, buildInfoPath);
if (!emitSkipped && emittedFilesList) {
@@ -278,6 +280,10 @@ namespace ts {
emittedFilesList.push(declarationMapPath);
}
}
function relativeToBuildInfo(path: string) {
return ensurePathIsNonModuleName(getRelativePathFromDirectory(buildInfoDirectory!, path, host.getCanonicalFileName));
}
}
function emitBuildInfo(bundle: BundleBuildInfo | undefined, buildInfoPath: string | undefined) {
@@ -291,7 +297,11 @@ namespace ts {
writeFile(host, emitterDiagnostics, buildInfoPath, getBuildInfoText({ bundle, program, version }), /*writeByteOrderMark*/ false);
}
function emitJsFileOrBundle(sourceFileOrBundle: SourceFile | Bundle | undefined, jsFilePath: string | undefined, sourceMapFilePath: string | undefined) {
function emitJsFileOrBundle(
sourceFileOrBundle: SourceFile | Bundle | undefined,
jsFilePath: string | undefined,
sourceMapFilePath: string | undefined,
relativeToBuildInfo: (path: string) => string) {
if (!sourceFileOrBundle || emitOnlyDtsFiles || !jsFilePath) {
return;
}
@@ -314,7 +324,8 @@ namespace ts {
inlineSourceMap: compilerOptions.inlineSourceMap,
inlineSources: compilerOptions.inlineSources,
extendedDiagnostics: compilerOptions.extendedDiagnostics,
writeBundleFileInfo: !!bundleBuildInfo
writeBundleFileInfo: !!bundleBuildInfo,
relativeToBuildInfo
};
// Create a printer to print the nodes
@@ -335,7 +346,11 @@ namespace ts {
if (bundleBuildInfo) bundleBuildInfo.js = printer.bundleFileInfo;
}
function emitDeclarationFileOrBundle(sourceFileOrBundle: SourceFile | Bundle | undefined, declarationFilePath: string | undefined, declarationMapPath: string | undefined) {
function emitDeclarationFileOrBundle(
sourceFileOrBundle: SourceFile | Bundle | undefined,
declarationFilePath: string | undefined,
declarationMapPath: string | undefined,
relativeToBuildInfo: (path: string) => string) {
if (!sourceFileOrBundle || !(declarationFilePath && !isInJSFile(sourceFileOrBundle))) {
return;
}
@@ -366,7 +381,8 @@ namespace ts {
extendedDiagnostics: compilerOptions.extendedDiagnostics,
onlyPrintJsDocStyle: true,
writeBundleFileInfo: !!bundleBuildInfo,
recordInternalSection: !!bundleBuildInfo
recordInternalSection: !!bundleBuildInfo,
relativeToBuildInfo
};
const declarationPrinter = createPrinter(printerOptions, {
@@ -613,10 +629,10 @@ namespace ts {
getNewLine(): string;
}
function createSourceFilesFromBundleBuildInfo(bundle: BundleBuildInfo): ReadonlyArray<SourceFile> {
function createSourceFilesFromBundleBuildInfo(bundle: BundleBuildInfo, buildInfoDirectory: string): ReadonlyArray<SourceFile> {
const sourceFiles = bundle.sourceFiles.map(fileName => {
const sourceFile = createNode(SyntaxKind.SourceFile, 0, 0) as SourceFile;
sourceFile.fileName = fileName;
sourceFile.fileName = getNormalizedAbsolutePath(fileName, buildInfoDirectory);
sourceFile.text = "";
sourceFile.statements = createNodeArray();
return sourceFile;
@@ -660,6 +676,7 @@ namespace ts {
const buildInfo = getBuildInfo(buildInfoText);
if (!buildInfo.bundle || !buildInfo.bundle.js || (declarationText && !buildInfo.bundle.dts)) return buildInfoPath!;
const buildInfoDirectory = getDirectoryPath(buildInfoPath!);
const ownPrependInput = createInputFiles(
jsFileText,
declarationText!,
@@ -675,11 +692,11 @@ namespace ts {
);
const outputFiles: OutputFile[] = [];
const prependNodes = createPrependNodes(config.projectReferences, getCommandLine, f => host.readFile(f));
const sourceFilesForJsEmit = createSourceFilesFromBundleBuildInfo(buildInfo.bundle);
const sourceFilesForJsEmit = createSourceFilesFromBundleBuildInfo(buildInfo.bundle, buildInfoDirectory);
const emitHost: EmitHost = {
getPrependNodes: memoize(() => [...prependNodes, ownPrependInput]),
getCanonicalFileName: host.getCanonicalFileName,
getCommonSourceDirectory: () => buildInfo.bundle!.commonSourceDirectory,
getCommonSourceDirectory: () => getNormalizedAbsolutePath(buildInfo.bundle!.commonSourceDirectory, buildInfoDirectory),
getCompilerOptions: () => config.options,
getCurrentDirectory: () => host.getCurrentDirectory(),
getNewLine: () => host.getNewLine(),
@@ -774,6 +791,7 @@ namespace ts {
let write = writeBase;
let isOwnFileEmit: boolean;
const bundleFileInfo = printerOptions.writeBundleFileInfo ? { sections: [] } as BundleFileInfo : undefined;
const relativeToBuildInfo = bundleFileInfo ? Debug.assertDefined(printerOptions.relativeToBuildInfo) : undefined;
const recordInternalSection = printerOptions.recordInternalSection;
let sourceFileTextPos = 0;
let sourceFileTextKind: BundleFileTextLikeKind = BundleFileSectionKind.Text;
@@ -942,7 +960,13 @@ namespace ts {
if (prepend.oldFileOfCurrentEmit) bundleFileInfo.sections.push(...newSections);
else {
newSections.forEach(section => Debug.assert(isBundleFileTextLike(section)));
bundleFileInfo.sections.push({ pos, end: writer.getTextPos(), kind: BundleFileSectionKind.Prepend, data: (prepend as UnparsedSource).fileName, texts: newSections as BundleFileTextLike[] });
bundleFileInfo.sections.push({
pos,
end: writer.getTextPos(),
kind: BundleFileSectionKind.Prepend,
data: relativeToBuildInfo!((prepend as UnparsedSource).fileName),
texts: newSections as BundleFileTextLike[]
});
}
}
}
+1
View File
@@ -5726,6 +5726,7 @@ namespace ts {
/*@internal*/ writeBundleFileInfo?: boolean;
/*@internal*/ recordInternalSection?: boolean;
/*@internal*/ stripInternal?: boolean;
/*@internal*/ relativeToBuildInfo?: (path: string) => string;
}
/* @internal */
@@ -322,8 +322,8 @@ namespace ts.tscWatch {
path: `${project}/out.tsbuildinfo`,
content: getBuildInfoText({
bundle: {
commonSourceDirectory: `${project}/`,
sourceFiles: [file1.path, file2.path],
commonSourceDirectory: relativeToBuildInfo(`${project}/out.tsbuildinfo`, `${project}/`),
sourceFiles: [file1Path, file2Path],
js: {
sections: [
{ pos: 0, end: outFile.content.length, kind: BundleFileSectionKind.Text }
@@ -550,8 +550,8 @@ namespace ts.tscWatch {
path: `${project}/out.tsbuildinfo`,
content: getBuildInfoText({
bundle: {
commonSourceDirectory: `${project}/`,
sourceFiles: [file1.path, file2.path],
commonSourceDirectory: relativeToBuildInfo(`${project}/out.tsbuildinfo`, `${project}/`),
sourceFiles: [file1Path, file2Path],
js: {
sections: [
{ pos: 0, end: outFile.content.length, kind: BundleFileSectionKind.Text }