mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-09 20:51:43 -06:00
Add baselining of modules and type refs
This commit is contained in:
parent
3172629f21
commit
e1600ab800
@ -35,6 +35,7 @@ export interface TestTscCompile extends TestTscCompileLikeBase {
|
||||
baselineReadFileCalls?: boolean;
|
||||
baselinePrograms?: boolean;
|
||||
baselineDependencies?: boolean;
|
||||
baselineModulesAndTypeRefs?: boolean;
|
||||
}
|
||||
|
||||
export type CommandLineProgram = [ts.Program, ts.BuilderProgram?];
|
||||
@ -206,6 +207,11 @@ export function testTscCompile(input: TestTscCompile) {
|
||||
baselinePrograms(baseline, getPrograms!, ts.emptyArray, baselineDependencies);
|
||||
sys.write(baseline.join("\n"));
|
||||
}
|
||||
if (input.baselineModulesAndTypeRefs) {
|
||||
const baseline: string[] = [];
|
||||
baselineModulesAndTypeRefs(baseline, getPrograms!());
|
||||
sys.write(baseline.join("\n"));
|
||||
}
|
||||
if (baselineReadFileCalls) {
|
||||
sys.write(`readFiles:: ${JSON.stringify(actualReadFileMap, /*replacer*/ undefined, " ")} `);
|
||||
}
|
||||
@ -249,6 +255,40 @@ function storeDtsSignatures(sys: TscCompileSystem, programs: readonly CommandLin
|
||||
}
|
||||
}
|
||||
|
||||
function baselineCache<T>(baseline: string[], cacheType: string, cache: ts.ModeAwareCache<T> | undefined) {
|
||||
if (!cache?.size()) return;
|
||||
baseline.push(`${cacheType}:`);
|
||||
cache.forEach((resolved, key, mode) => baseline.push(`${key}: ${mode ? ts.getNameOfCompilerOptionValue(mode, ts.moduleOptionDeclaration.type) + ": " : ""}${JSON.stringify(
|
||||
{ ...resolved, refCount: undefined, files: undefined, isInvalidated: undefined, },
|
||||
/*replacer*/ undefined,
|
||||
2,
|
||||
)}`));
|
||||
}
|
||||
|
||||
export function baselineModulesAndTypeRefs(baseline: string[], programs: readonly CommandLineProgram[]) {
|
||||
for (const [program] of programs) {
|
||||
for (const f of program.getSourceFiles()) {
|
||||
if (!f.resolvedModules && !f.resolvedTypeReferenceDirectiveNames && !f.packageJsonScope) continue;
|
||||
baseline.push(`File: ${f.fileName}`);
|
||||
if (f.packageJsonScope) {
|
||||
baseline.push(`packageJsonScope:: ${JSON.stringify(
|
||||
f.packageJsonScope,
|
||||
/*replacer*/ undefined,
|
||||
2,
|
||||
)}`);
|
||||
}
|
||||
baselineCache(baseline, "resolvedModules", f.resolvedModules);
|
||||
baselineCache(baseline, "resolvedTypeReferenceDirectiveNames", f.resolvedTypeReferenceDirectiveNames);
|
||||
baseline.push("");
|
||||
}
|
||||
const autoTypes = program.getAutomaticTypeDirectiveResolutions();
|
||||
if (autoTypes.size()) {
|
||||
baselineCache(baseline, "automaticTypeDirectiveResolutions", autoTypes);
|
||||
baseline.push("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function baselinePrograms(baseline: string[], getPrograms: () => readonly CommandLineProgram[], oldPrograms: readonly (CommandLineProgram | undefined)[], baselineDependencies: boolean | undefined) {
|
||||
const programs = getPrograms();
|
||||
for (let i = 0; i < programs.length; i++) {
|
||||
@ -903,7 +943,7 @@ export interface VerifyTscWithEditsInput extends TestTscCompile {
|
||||
*/
|
||||
export function verifyTsc({
|
||||
subScenario, fs, scenario, commandLineArgs, environmentVariables,
|
||||
baselineSourceMap, modifyFs, baselineReadFileCalls, baselinePrograms,
|
||||
baselineSourceMap, modifyFs, baselineReadFileCalls, baselinePrograms, baselineDependencies, baselineModulesAndTypeRefs,
|
||||
edits
|
||||
}: VerifyTscWithEditsInput) {
|
||||
describe(`tsc ${commandLineArgs.join(" ")} ${scenario}:: ${subScenario}`, () => {
|
||||
@ -921,6 +961,8 @@ export function verifyTsc({
|
||||
baselineSourceMap,
|
||||
baselineReadFileCalls,
|
||||
baselinePrograms,
|
||||
baselineDependencies,
|
||||
baselineModulesAndTypeRefs,
|
||||
environmentVariables,
|
||||
});
|
||||
edits?.forEach((
|
||||
@ -937,6 +979,8 @@ export function verifyTsc({
|
||||
baselineSourceMap,
|
||||
baselineReadFileCalls,
|
||||
baselinePrograms,
|
||||
baselineDependencies,
|
||||
baselineModulesAndTypeRefs,
|
||||
environmentVariables,
|
||||
}));
|
||||
});
|
||||
|
||||
@ -12,6 +12,7 @@ import {
|
||||
TestServerHostTrackingWrittenFiles,
|
||||
} from "../virtualFileSystemWithWatch";
|
||||
import {
|
||||
baselineModulesAndTypeRefs,
|
||||
baselinePrograms,
|
||||
commandLineCallbacks,
|
||||
CommandLineCallbacks,
|
||||
@ -42,6 +43,7 @@ export interface TscWatchCompileChange<T extends ts.BuilderProgram = ts.EmitAndS
|
||||
export interface TscWatchCheckOptions {
|
||||
baselineSourceMap?: boolean;
|
||||
baselineDependencies?: boolean;
|
||||
baselineModulesAndTypeRefs?: boolean;
|
||||
}
|
||||
export interface TscWatchCompileBase<T extends ts.BuilderProgram = ts.EmitAndSemanticDiagnosticsBuilderProgram> extends TscWatchCheckOptions {
|
||||
scenario: string;
|
||||
@ -66,7 +68,7 @@ function tscWatchCompile(input: TscWatchCompile) {
|
||||
const {
|
||||
scenario, subScenario,
|
||||
commandLineArgs, edits,
|
||||
baselineSourceMap, baselineDependencies
|
||||
baselineSourceMap, baselineDependencies, baselineModulesAndTypeRefs,
|
||||
} = input;
|
||||
|
||||
if (!isWatch(commandLineArgs)) sys.exit = exitCode => sys.exitCode = exitCode;
|
||||
@ -86,6 +88,7 @@ function tscWatchCompile(input: TscWatchCompile) {
|
||||
getPrograms,
|
||||
baselineSourceMap,
|
||||
baselineDependencies,
|
||||
baselineModulesAndTypeRefs,
|
||||
edits,
|
||||
watchOrSolution
|
||||
});
|
||||
@ -184,7 +187,7 @@ export interface RunWatchBaseline<T extends ts.BuilderProgram> extends BaselineB
|
||||
export function runWatchBaseline<T extends ts.BuilderProgram = ts.EmitAndSemanticDiagnosticsBuilderProgram>({
|
||||
scenario, subScenario, commandLineArgs,
|
||||
getPrograms, sys, baseline, oldSnap,
|
||||
baselineSourceMap, baselineDependencies,
|
||||
baselineSourceMap, baselineDependencies, baselineModulesAndTypeRefs,
|
||||
edits, watchOrSolution
|
||||
}: RunWatchBaseline<T>) {
|
||||
baseline.push(`${sys.getExecutingFilePath()} ${commandLineArgs.join(" ")}`);
|
||||
@ -196,6 +199,7 @@ export function runWatchBaseline<T extends ts.BuilderProgram = ts.EmitAndSemanti
|
||||
oldSnap,
|
||||
baselineSourceMap,
|
||||
baselineDependencies,
|
||||
baselineModulesAndTypeRefs,
|
||||
});
|
||||
|
||||
if (edits) {
|
||||
@ -210,6 +214,7 @@ export function runWatchBaseline<T extends ts.BuilderProgram = ts.EmitAndSemanti
|
||||
oldSnap,
|
||||
baselineSourceMap,
|
||||
baselineDependencies,
|
||||
baselineModulesAndTypeRefs,
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -228,10 +233,11 @@ export interface WatchBaseline extends BaselineBase, TscWatchCheckOptions {
|
||||
oldPrograms: readonly (CommandLineProgram | undefined)[];
|
||||
getPrograms: () => readonly CommandLineProgram[];
|
||||
}
|
||||
export function watchBaseline({ baseline, getPrograms, oldPrograms, sys, oldSnap, baselineSourceMap, baselineDependencies }: WatchBaseline) {
|
||||
export function watchBaseline({ baseline, getPrograms, oldPrograms, sys, oldSnap, baselineSourceMap, baselineDependencies, baselineModulesAndTypeRefs: shouldBaselineModulesAndTypeRefs }: WatchBaseline) {
|
||||
if (baselineSourceMap) generateSourceMapBaselineFiles(sys);
|
||||
sys.serializeOutput(baseline);
|
||||
const programs = baselinePrograms(baseline, getPrograms, oldPrograms, baselineDependencies);
|
||||
if (shouldBaselineModulesAndTypeRefs) baselineModulesAndTypeRefs(baseline, programs);
|
||||
sys.serializeWatches(baseline);
|
||||
baseline.push(`exitCode:: ExitStatus.${ts.ExitStatus[sys.exitCode as ts.ExitStatus]}`, "");
|
||||
sys.diff(baseline, oldSnap);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user