1import { combinePaths, Extension, fileExtensionIs, ResolvedConfigFileName } from "./_namespaces/ts"; 2 3/** @internal */ 4export enum UpToDateStatusType { 5 Unbuildable, 6 UpToDate, 7 /** 8 * The project appears out of date because its upstream inputs are newer than its outputs, 9 * but all of its outputs are actually newer than the previous identical outputs of its (.d.ts) inputs. 10 * This means we can Pseudo-build (just touch timestamps), as if we had actually built this project. 11 */ 12 UpToDateWithUpstreamTypes, 13 /** 14 * The project appears out of date because its upstream inputs are newer than its outputs, 15 * but all of its outputs are actually newer than the previous identical outputs of its (.d.ts) inputs. 16 * This means we can Pseudo-build (just manipulate outputs), as if we had actually built this project. 17 */ 18 OutOfDateWithPrepend, 19 OutputMissing, 20 ErrorReadingFile, 21 OutOfDateWithSelf, 22 OutOfDateWithUpstream, 23 OutOfDateBuildInfo, 24 UpstreamOutOfDate, 25 UpstreamBlocked, 26 ComputingUpstream, 27 TsVersionOutputOfDate, 28 UpToDateWithInputFileText, 29 30 /** 31 * Projects with no outputs (i.e. "solution" files) 32 */ 33 ContainerOnly, 34 ForceBuild, 35} 36 37/** @internal */ 38export type UpToDateStatus = 39 | Status.Unbuildable 40 | Status.UpToDate 41 | Status.OutOfDateWithPrepend 42 | Status.OutputMissing 43 | Status.ErrorReadingFile 44 | Status.OutOfDateWithSelf 45 | Status.OutOfDateWithUpstream 46 | Status.OutOfDateBuildInfo 47 | Status.UpstreamOutOfDate 48 | Status.UpstreamBlocked 49 | Status.ComputingUpstream 50 | Status.TsVersionOutOfDate 51 | Status.ContainerOnly 52 | Status.ForceBuild; 53 54/** @internal */ 55export namespace Status { 56 /** 57 * The project can't be built at all in its current state. For example, 58 * its config file cannot be parsed, or it has a syntax error or missing file 59 */ 60 export interface Unbuildable { 61 type: UpToDateStatusType.Unbuildable; 62 reason: string; 63 } 64 65 /** 66 * This project doesn't have any outputs, so "is it up to date" is a meaningless question. 67 */ 68 export interface ContainerOnly { 69 type: UpToDateStatusType.ContainerOnly; 70 } 71 72 /** 73 * The project is up to date with respect to its inputs. 74 * We track what the newest input file is. 75 */ 76 export interface UpToDate { 77 type: UpToDateStatusType.UpToDate | UpToDateStatusType.UpToDateWithUpstreamTypes | UpToDateStatusType.UpToDateWithInputFileText; 78 newestInputFileTime?: Date; 79 newestInputFileName?: string; 80 oldestOutputFileName: string; 81 } 82 83 /** 84 * The project is up to date with respect to its inputs except for prepend output changed (no declaration file change in prepend). 85 */ 86 export interface OutOfDateWithPrepend { 87 type: UpToDateStatusType.OutOfDateWithPrepend; 88 outOfDateOutputFileName: string; 89 newerProjectName: string; 90 } 91 92 /** 93 * One or more of the outputs of the project does not exist. 94 */ 95 export interface OutputMissing { 96 type: UpToDateStatusType.OutputMissing; 97 /** 98 * The name of the first output file that didn't exist 99 */ 100 missingOutputFileName: string; 101 } 102 103 /** Error reading file */ 104 export interface ErrorReadingFile { 105 type: UpToDateStatusType.ErrorReadingFile; 106 fileName: string; 107 } 108 109 /** 110 * One or more of the project's outputs is older than its newest input. 111 */ 112 export interface OutOfDateWithSelf { 113 type: UpToDateStatusType.OutOfDateWithSelf; 114 outOfDateOutputFileName: string; 115 newerInputFileName: string; 116 } 117 118 /** 119 * Buildinfo indicates that build is out of date 120 */ 121 export interface OutOfDateBuildInfo { 122 type: UpToDateStatusType.OutOfDateBuildInfo, 123 buildInfoFile: string; 124 } 125 126 /** 127 * This project depends on an out-of-date project, so shouldn't be built yet 128 */ 129 export interface UpstreamOutOfDate { 130 type: UpToDateStatusType.UpstreamOutOfDate; 131 upstreamProjectName: string; 132 } 133 134 /** 135 * This project depends an upstream project with build errors 136 */ 137 export interface UpstreamBlocked { 138 type: UpToDateStatusType.UpstreamBlocked; 139 upstreamProjectName: string; 140 upstreamProjectBlocked: boolean; 141 } 142 143 /** 144 * Computing status of upstream projects referenced 145 */ 146 export interface ComputingUpstream { 147 type: UpToDateStatusType.ComputingUpstream; 148 } 149 150 export interface TsVersionOutOfDate { 151 type: UpToDateStatusType.TsVersionOutputOfDate; 152 version: string; 153 } 154 155 /** 156 * One or more of the project's outputs is older than the newest output of 157 * an upstream project. 158 */ 159 export interface OutOfDateWithUpstream { 160 type: UpToDateStatusType.OutOfDateWithUpstream; 161 outOfDateOutputFileName: string; 162 newerProjectName: string; 163 } 164 165 export interface ForceBuild { 166 type: UpToDateStatusType.ForceBuild; 167 } 168} 169 170/** @internal */ 171export function resolveConfigFileProjectName(project: string): ResolvedConfigFileName { 172 if (fileExtensionIs(project, Extension.Json)) { 173 return project as ResolvedConfigFileName; 174 } 175 176 return combinePaths(project, "tsconfig.json") as ResolvedConfigFileName; 177}