Skip to content

Commit

Permalink
Improvements to dts emit for tsbuildinfo (microsoft#43205)
Browse files Browse the repository at this point in the history
* Test update

* Use source file version as default signature for the file whenever there is no dts emit for the file

* json source files from project reference should be able to calculate the signature

* Dont emit declaration map when emitting dts files for force emit for signature
  • Loading branch information
sheetalkamat authored Mar 12, 2021
1 parent 9c73e04 commit 496a1d3
Show file tree
Hide file tree
Showing 35 changed files with 231 additions and 714 deletions.
31 changes: 12 additions & 19 deletions src/compiler/builderState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,16 +316,8 @@ namespace ts {
if (!info) return Debug.fail();

const prevSignature = info.signature;
let latestSignature: string;
if (sourceFile.isDeclarationFile) {
latestSignature = sourceFile.version;
if (exportedModulesMapCache && latestSignature !== prevSignature) {
// All the references in this file are exported
const references = state.referencedMap ? state.referencedMap.get(sourceFile.resolvedPath) : undefined;
exportedModulesMapCache.set(sourceFile.resolvedPath, references || false);
}
}
else {
let latestSignature: string | undefined;
if (!sourceFile.isDeclarationFile) {
const emitOutput = getFileEmitOutput(
programOfThisState,
sourceFile,
Expand All @@ -334,25 +326,26 @@ namespace ts {
/*customTransformers*/ undefined,
/*forceDtsEmit*/ true
);
const firstDts = emitOutput.outputFiles &&
programOfThisState.getCompilerOptions().declarationMap ?
emitOutput.outputFiles.length > 1 ? emitOutput.outputFiles[1] : undefined :
emitOutput.outputFiles.length > 0 ? emitOutput.outputFiles[0] : undefined;
const firstDts = firstOrUndefined(emitOutput.outputFiles);
if (firstDts) {
Debug.assert(fileExtensionIs(firstDts.name, Extension.Dts), "File extension for signature expected to be dts", () => `Found: ${getAnyExtensionFromPath(firstDts.name)} for ${firstDts.name}:: All output files: ${JSON.stringify(emitOutput.outputFiles.map(f => f.name))}`);
latestSignature = (computeHash || generateDjb2Hash)(firstDts.text);
if (exportedModulesMapCache && latestSignature !== prevSignature) {
updateExportedModules(sourceFile, emitOutput.exportedModulesFromDeclarationEmit, exportedModulesMapCache);
}
}
else {
latestSignature = prevSignature!; // TODO: GH#18217
}
// Default is to use file version as signature
if (latestSignature === undefined) {
latestSignature = sourceFile.version;
if (exportedModulesMapCache && latestSignature !== prevSignature) {
// All the references in this file are exported
const references = state.referencedMap ? state.referencedMap.get(sourceFile.resolvedPath) : undefined;
exportedModulesMapCache.set(sourceFile.resolvedPath, references || false);
}

}
cacheToUpdateSignature.set(sourceFile.resolvedPath, latestSignature);

return !prevSignature || latestSignature !== prevSignature;
return latestSignature !== prevSignature;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ namespace ts {
declarationTransform.transformed[0],
declarationPrinter,
{
sourceMap: compilerOptions.declarationMap,
sourceMap: !forceDtsEmit && compilerOptions.declarationMap,
sourceRoot: compilerOptions.sourceRoot,
mapRoot: compilerOptions.mapRoot,
extendedDiagnostics: compilerOptions.extendedDiagnostics,
Expand Down
6 changes: 4 additions & 2 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4215,8 +4215,10 @@ namespace ts {
return !(options.noEmitForJsFiles && isSourceFileJS(sourceFile)) &&
!sourceFile.isDeclarationFile &&
!host.isSourceFileFromExternalLibrary(sourceFile) &&
!(isJsonSourceFile(sourceFile) && host.getResolvedProjectReferenceToRedirect(sourceFile.fileName)) &&
(forceDtsEmit || !host.isSourceOfProjectReferenceRedirect(sourceFile.fileName));
(forceDtsEmit || (
!(isJsonSourceFile(sourceFile) && host.getResolvedProjectReferenceToRedirect(sourceFile.fileName)) &&
!host.isSourceOfProjectReferenceRedirect(sourceFile.fileName)
));
}

export function getSourceFilePathInNewDir(fileName: string, host: EmitHost, newDirPath: string): string {
Expand Down
29 changes: 6 additions & 23 deletions src/testRunner/unittests/tsbuild/javascriptProjectEmit.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace ts {
describe("unittests:: tsbuild:: javascriptProjectEmit:: loads js-based projects and emits them correctly", () => {
describe("unittests:: tsbuild:: javascriptProjectEmit::", () => {
verifyTsc({
scenario: "javascriptProjectEmit",
subScenario: `loads js-based projects and emits them correctly`,
Expand Down Expand Up @@ -87,12 +87,11 @@ namespace ts {
}, symbolLibContent),
commandLineArgs: ["-b", "/src"]
});
});

describe("unittests:: tsbuild:: javascriptProjectEmit:: loads outfile js projects and concatenates them correctly", () => {
let projFs: vfs.FileSystem;
before(() => {
projFs = loadProjectFromFiles({
verifyTscSerializedIncrementalEdits({
scenario: "javascriptProjectEmit",
subScenario: `modifies outfile js projects and concatenates them correctly`,
fs: () => loadProjectFromFiles({
"/src/common/nominal.js": Utils.dedent`
/**
* @template T, Name
Expand Down Expand Up @@ -175,30 +174,14 @@ namespace ts {
"declaration": true
}
}`,
}, symbolLibContent);
});
after(() => {
projFs = undefined!;
});
verifyTsc({
scenario: "javascriptProjectEmit",
subScenario: `loads outfile js projects and concatenates them correctly`,
fs: () => projFs,
commandLineArgs: ["-b", "/src"]
});
verifyTscSerializedIncrementalEdits({
scenario: "javascriptProjectEmit",
subScenario: `modifies outfile js projects and concatenates them correctly`,
fs: () => projFs,
}, symbolLibContent),
commandLineArgs: ["-b", "/src"],
incrementalScenarios: [{
buildKind: BuildKind.IncrementalDtsUnchanged,
modifyFs: fs => replaceText(fs, "/src/sub-project/index.js", "null", "undefined")
}]
});
});

describe("unittests:: tsbuild:: javascriptProjectEmit:: loads js-based projects with non-moved json files and emits them correctly", () => {
verifyTsc({
scenario: "javascriptProjectEmit",
subScenario: `loads js-based projects with non-moved json files and emits them correctly`,
Expand Down
Loading

0 comments on commit 496a1d3

Please sign in to comment.