Skip to content

Commit 9faffc9

Browse files
authored
Merge pull request #26717 from Microsoft/buildWatchReporting30
[release-3.0] Refactor ts build and report watch status when doing --build --watch
2 parents 945fa54 + 88096a3 commit 9faffc9

File tree

16 files changed

+887
-616
lines changed

16 files changed

+887
-616
lines changed

src/compiler/commandLineParser.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -797,10 +797,11 @@ namespace ts {
797797
}
798798

799799
function getOptionNameMap(): OptionNameMap {
800-
if (optionNameMapCache) {
801-
return optionNameMapCache;
802-
}
800+
return optionNameMapCache || (optionNameMapCache = createOptionNameMap(optionDeclarations));
801+
}
803802

803+
/*@internal*/
804+
export function createOptionNameMap(optionDeclarations: ReadonlyArray<CommandLineOption>): OptionNameMap {
804805
const optionNameMap = createMap<CommandLineOption>();
805806
const shortOptionNames = createMap<string>();
806807
forEach(optionDeclarations, option => {
@@ -810,8 +811,7 @@ namespace ts {
810811
}
811812
});
812813

813-
optionNameMapCache = { optionNameMap, shortOptionNames };
814-
return optionNameMapCache;
814+
return { optionNameMap, shortOptionNames };
815815
}
816816

817817
/* @internal */
@@ -961,7 +961,12 @@ namespace ts {
961961
}
962962

963963
/** @internal */
964-
export function getOptionFromName(optionName: string, allowShort = false): CommandLineOption | undefined {
964+
export function getOptionFromName(optionName: string, allowShort?: boolean): CommandLineOption | undefined {
965+
return getOptionDeclarationFromName(getOptionNameMap, optionName, allowShort);
966+
}
967+
968+
/*@internal*/
969+
export function getOptionDeclarationFromName(getOptionNameMap: () => OptionNameMap, optionName: string, allowShort = false): CommandLineOption | undefined {
965970
optionName = optionName.toLowerCase();
966971
const { optionNameMap, shortOptionNames } = getOptionNameMap();
967972
// Try to translate short option names to their full equivalents.

src/compiler/diagnosticMessages.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2872,6 +2872,11 @@
28722872
"category": "Error",
28732873
"code": 5071
28742874
},
2875+
"Unknown build option '{0}'.": {
2876+
"category": "Error",
2877+
"code": 5072
2878+
},
2879+
28752880

28762881
"Generates a sourcemap for each corresponding '.d.ts' file.": {
28772882
"category": "Message",

src/compiler/program.ts

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -67,19 +67,24 @@ namespace ts {
6767
}
6868

6969
export function createCompilerHost(options: CompilerOptions, setParentNodes?: boolean): CompilerHost {
70+
return createCompilerHostWorker(options, setParentNodes);
71+
}
72+
/*@internal*/
73+
// TODO(shkamat): update this after reworking ts build API
74+
export function createCompilerHostWorker(options: CompilerOptions, setParentNodes?: boolean, system = sys): CompilerHost {
7075
const existingDirectories = createMap<boolean>();
7176

7277
function getCanonicalFileName(fileName: string): string {
7378
// if underlying system can distinguish between two files whose names differs only in cases then file name already in canonical form.
7479
// otherwise use toLowerCase as a canonical form.
75-
return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
80+
return system.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
7681
}
7782

7883
function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError?: (message: string) => void): SourceFile | undefined {
7984
let text: string | undefined;
8085
try {
8186
performance.mark("beforeIORead");
82-
text = sys.readFile(fileName, options.charset);
87+
text = system.readFile(fileName, options.charset);
8388
performance.mark("afterIORead");
8489
performance.measure("I/O Read", "beforeIORead", "afterIORead");
8590
}
@@ -97,7 +102,7 @@ namespace ts {
97102
if (existingDirectories.has(directoryPath)) {
98103
return true;
99104
}
100-
if (sys.directoryExists(directoryPath)) {
105+
if (system.directoryExists(directoryPath)) {
101106
existingDirectories.set(directoryPath, true);
102107
return true;
103108
}
@@ -108,7 +113,7 @@ namespace ts {
108113
if (directoryPath.length > getRootLength(directoryPath) && !directoryExists(directoryPath)) {
109114
const parentDirectory = getDirectoryPath(directoryPath);
110115
ensureDirectoriesExist(parentDirectory);
111-
sys.createDirectory(directoryPath);
116+
system.createDirectory(directoryPath);
112117
}
113118
}
114119

@@ -119,8 +124,8 @@ namespace ts {
119124
outputFingerprints = createMap<OutputFingerprint>();
120125
}
121126

122-
const hash = sys.createHash!(data); // TODO: GH#18217
123-
const mtimeBefore = sys.getModifiedTime!(fileName); // TODO: GH#18217
127+
const hash = system.createHash!(data); // TODO: GH#18217
128+
const mtimeBefore = system.getModifiedTime!(fileName); // TODO: GH#18217
124129

125130
if (mtimeBefore) {
126131
const fingerprint = outputFingerprints.get(fileName);
@@ -133,9 +138,9 @@ namespace ts {
133138
}
134139
}
135140

136-
sys.writeFile(fileName, data, writeByteOrderMark);
141+
system.writeFile(fileName, data, writeByteOrderMark);
137142

138-
const mtimeAfter = sys.getModifiedTime!(fileName); // TODO: GH#18217
143+
const mtimeAfter = system.getModifiedTime!(fileName) || missingFileModifiedTime; // TODO: GH#18217
139144

140145
outputFingerprints.set(fileName, {
141146
hash,
@@ -149,11 +154,11 @@ namespace ts {
149154
performance.mark("beforeIOWrite");
150155
ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName)));
151156

152-
if (isWatchSet(options) && sys.createHash && sys.getModifiedTime) {
157+
if (isWatchSet(options) && system.createHash && system.getModifiedTime) {
153158
writeFileIfUpdated(fileName, data, writeByteOrderMark);
154159
}
155160
else {
156-
sys.writeFile(fileName, data, writeByteOrderMark);
161+
system.writeFile(fileName, data, writeByteOrderMark);
157162
}
158163

159164
performance.mark("afterIOWrite");
@@ -167,32 +172,29 @@ namespace ts {
167172
}
168173

169174
function getDefaultLibLocation(): string {
170-
return getDirectoryPath(normalizePath(sys.getExecutingFilePath()));
175+
return getDirectoryPath(normalizePath(system.getExecutingFilePath()));
171176
}
172177

173-
const newLine = getNewLineCharacter(options);
174-
const realpath = sys.realpath && ((path: string) => sys.realpath!(path));
178+
const newLine = getNewLineCharacter(options, () => system.newLine);
179+
const realpath = system.realpath && ((path: string) => system.realpath!(path));
175180

176181
return {
177182
getSourceFile,
178183
getDefaultLibLocation,
179184
getDefaultLibFileName: options => combinePaths(getDefaultLibLocation(), getDefaultLibFileName(options)),
180185
writeFile,
181-
getCurrentDirectory: memoize(() => sys.getCurrentDirectory()),
182-
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
186+
getCurrentDirectory: memoize(() => system.getCurrentDirectory()),
187+
useCaseSensitiveFileNames: () => system.useCaseSensitiveFileNames,
183188
getCanonicalFileName,
184189
getNewLine: () => newLine,
185-
fileExists: fileName => sys.fileExists(fileName),
186-
readFile: fileName => sys.readFile(fileName),
187-
trace: (s: string) => sys.write(s + newLine),
188-
directoryExists: directoryName => sys.directoryExists(directoryName),
189-
getEnvironmentVariable: name => sys.getEnvironmentVariable ? sys.getEnvironmentVariable(name) : "",
190-
getDirectories: (path: string) => sys.getDirectories(path),
190+
fileExists: fileName => system.fileExists(fileName),
191+
readFile: fileName => system.readFile(fileName),
192+
trace: (s: string) => system.write(s + newLine),
193+
directoryExists: directoryName => system.directoryExists(directoryName),
194+
getEnvironmentVariable: name => system.getEnvironmentVariable ? system.getEnvironmentVariable(name) : "",
195+
getDirectories: (path: string) => system.getDirectories(path),
191196
realpath,
192-
readDirectory: (path, extensions, include, exclude, depth) => sys.readDirectory(path, extensions, include, exclude, depth),
193-
getModifiedTime: sys.getModifiedTime && (path => sys.getModifiedTime!(path)),
194-
setModifiedTime: sys.setModifiedTime && ((path, date) => sys.setModifiedTime!(path, date)),
195-
deleteFile: sys.deleteFile && (path => sys.deleteFile!(path))
197+
readDirectory: (path, extensions, include, exclude, depth) => system.readDirectory(path, extensions, include, exclude, depth)
196198
};
197199
}
198200

0 commit comments

Comments
 (0)