Build project if existing project was built with different compiler version

This commit is contained in:
Sheetal Nandi
2019-03-08 15:14:34 -08:00
parent ecb2ce429d
commit 68e28da141
8 changed files with 65 additions and 17 deletions
+4
View File
@@ -4044,6 +4044,10 @@
"category": "Message",
"code": 6380
},
"Project '{0}' is out of date because output for it was generated with version '{1}' that differs with current version '{2}'": {
"category": "Message",
"code": 6381
},
"The expected type comes from property '{0}' which is declared here on type '{1}'": {
"category": "Message",
+7 -2
View File
@@ -466,6 +466,11 @@ namespace ts {
return JSON.stringify(buildInfo, undefined, 2);
}
/*@internal*/
export function getBuildInfo(buildInfoText: string) {
return JSON.parse(buildInfoText) as BuildInfo;
}
/*@internal*/
export const notImplementedResolver: EmitResolver = {
hasGlobalName: notImplemented,
@@ -560,7 +565,7 @@ namespace ts {
// error if no source map or for now if inline sourcemap
if ((declarationMapPath && !declarationMapText) || config.options.inlineSourceMap) return declarationMapPath || "inline sourcemap decoding";
const buildInfo = JSON.parse(buildInfoText) as BuildInfo;
const buildInfo = getBuildInfo(buildInfoText);
if (!buildInfo.bundle || !buildInfo.bundle.js || (declarationText && !buildInfo.bundle.dts)) return buildInfoPath!;
const ownPrependInput = createInputFiles(
jsFileText,
@@ -599,7 +604,7 @@ namespace ts {
if (sourceMapText === text) return;
break;
case buildInfoPath:
const newBuildInfo = JSON.parse(text) as BuildInfo;
const newBuildInfo = getBuildInfo(text);
newBuildInfo.program = buildInfo.program;
// Update sourceFileInfo
const { js, dts, sourceFiles } = buildInfo.bundle!;
+3 -3
View File
@@ -2891,10 +2891,10 @@ namespace ts {
return result !== undefined ? result : `/* Input file ${path} was missing */\r\n`;
};
let buildInfo: BuildInfo | false;
const getBuildInfo = (getText: () => string | undefined) => {
const getAndCacheBuildInfo = (getText: () => string | undefined) => {
if (buildInfo === undefined) {
const result = getText();
buildInfo = result !== undefined ? JSON.parse(result) as BuildInfo : false;
buildInfo = result !== undefined ? getBuildInfo(result) : false;
}
return buildInfo || undefined;
};
@@ -2908,7 +2908,7 @@ namespace ts {
javascriptMapText: { get() { return textGetter(javascriptMapPath); } }, // TODO:: if there is inline sourceMap in jsFile, use that
declarationText: { get() { return definedTextGetter(Debug.assertDefined(javascriptMapTextOrDeclarationPath)); } },
declarationMapText: { get() { return textGetter(declarationMapPath); } }, // TODO:: if there is inline sourceMap in dtsFile, use that
buildInfo: { get() { return getBuildInfo(() => textGetter(declarationMapTextOrBuildInfoPath)); } }
buildInfo: { get() { return getAndCacheBuildInfo(() => textGetter(declarationMapTextOrBuildInfoPath)); } }
});
}
else {
+32 -1
View File
@@ -79,6 +79,7 @@ namespace ts {
UpstreamOutOfDate,
UpstreamBlocked,
ComputingUpstream,
TsVersionOutputOfDate,
/**
* Projects with no outputs (i.e. "solution" files)
@@ -96,6 +97,7 @@ namespace ts {
| Status.UpstreamOutOfDate
| Status.UpstreamBlocked
| Status.ComputingUpstream
| Status.TsVersionOutOfDate
| Status.ContainerOnly;
export namespace Status {
@@ -181,6 +183,11 @@ namespace ts {
type: UpToDateStatusType.ComputingUpstream;
}
export interface TsVersionOutOfDate {
type: UpToDateStatusType.TsVersionOutputOfDate;
version: string;
}
/**
* One or more of the project's outputs is older than the newest output of
* an upstream project.
@@ -454,6 +461,8 @@ namespace ts {
return result;
};
const buildInfoChecked = createFileMap<true>(toPath);
// Watch state
const builderPrograms = createFileMap<T>(toPath);
const diagnostics = createFileMap<ReadonlyArray<Diagnostic>>(toPath);
@@ -499,6 +508,7 @@ namespace ts {
projectStatus.clear();
missingRoots.clear();
globalDependencyGraph = undefined;
buildInfoChecked.clear();
diagnostics.clear();
projectPendingBuild.clear();
@@ -844,6 +854,21 @@ namespace ts {
};
}
if (!buildInfoChecked.hasKey(project.options.configFilePath as ResolvedConfigFileName)) {
buildInfoChecked.setValue(project.options.configFilePath as ResolvedConfigFileName, true);
const buildInfoPath = getOutputPathForBuildInfo(project.options);
if (buildInfoPath) {
const value = readFileWithCache(buildInfoPath);
const buildInfo = value && getBuildInfo(value);
if (buildInfo && buildInfo.version !== version) {
return {
type: UpToDateStatusType.TsVersionOutputOfDate,
version: buildInfo.version
};
}
}
}
if (usesPrepend && pseudoUpToDate) {
return {
type: UpToDateStatusType.OutOfDateWithPrepend,
@@ -1220,7 +1245,8 @@ namespace ts {
if (!buildInfoPath) return undefined;
const content = readFileWithCache(buildInfoPath);
if (!content) return undefined;
const buildInfo = JSON.parse(content) as BuildInfo;
const buildInfo = getBuildInfo(content);
if (buildInfo.version !== version) return undefined;
return buildInfo.program && createBuildProgramUsingProgramBuildInfo(buildInfo.program) as any as T;
}
@@ -1545,6 +1571,11 @@ namespace ts {
return formatMessage(Diagnostics.Failed_to_parse_file_0_Colon_1,
relName(configFileName),
status.reason);
case UpToDateStatusType.TsVersionOutputOfDate:
return formatMessage(Diagnostics.Project_0_is_out_of_date_because_output_for_it_was_generated_with_version_1_that_differs_with_current_version_2,
relName(configFileName),
status.version,
version);
case UpToDateStatusType.ContainerOnly:
// Don't report status on "solution" projects
case UpToDateStatusType.ComputingUpstream: