Skip to content

Commit d07261a

Browse files
committed
ensure tsd cache directory exists
1 parent 512ec04 commit d07261a

5 files changed

Lines changed: 18 additions & 21 deletions

File tree

‎src/server/server.ts‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace ts.server {
7777
});
7878

7979
function compress(s: string): CompressedData {
80-
const data = zlib.gzipSync(new Buffer(s, "utf8"));
80+
const data = zlib.gzipSync(new Buffer(s, "utf8"));
8181
return { data, length: data.length, compressionKind: "gzip" };
8282
}
8383

@@ -167,7 +167,7 @@ namespace ts.server {
167167
constructor(private readonly logger: server.Logger) {
168168
switch (process.platform) {
169169
case "win32":
170-
this.cachePath = normalizeSlashes(combinePaths(process.env.LOCALAPPDATA || process.env.APPDATA, "Microsoft/TypeScript"));
170+
this.cachePath = normalizeSlashes(combinePaths(process.env.LOCALAPPDATA || process.env.APPDATA, "Microsoft/TypeScript"));
171171
break;
172172
case "darwin":
173173
case "linux":
@@ -177,6 +177,7 @@ namespace ts.server {
177177
}
178178

179179
bind(session: Session) {
180+
this.session = session;
180181
if (this.logger.hasLevel(LogLevel.requestTime)) {
181182
this.logger.info("Binding...")
182183
}
@@ -202,15 +203,11 @@ namespace ts.server {
202203
this.installer.send(request);
203204
}
204205

205-
C = 1;
206206
private handleMessage(response: InstallTypingsResponse) {
207207
if (this.logger.hasLevel(LogLevel.verbose)) {
208208
this.logger.info(`Received response: ${JSON.stringify(response)}`)
209209
}
210-
require("fs").appendFileSync("E:\\sources\\git\\tss.txt", this.C + " !!!::" + JSON.stringify(response) + "\r\n");
211-
this.C++;
212210
this.session.onTypingsInstalled(response);
213-
require("fs").appendFileSync("E:\\sources\\git\\tss.txt", this.C + " !!!::" + "done" + "\r\n");
214211
}
215212
}
216213

@@ -293,7 +290,7 @@ namespace ts.server {
293290
}
294291
traceToConsole = logEnv.traceToConsole;
295292
}
296-
return new Logger(fileName, traceToConsole, detailLevel);
293+
return new Logger(fileName, traceToConsole, detailLevel);
297294
}
298295
// This places log file in the directory containing editorServices.js
299296
// TODO: check that this location is writable
@@ -448,7 +445,7 @@ namespace ts.server {
448445

449446
const useSingleInferredProject = sys.args.some(arg => arg === "--useSingleInferredProject");
450447
const ioSession = new IOSession(sys, cancellationToken, useSingleInferredProject, logger);
451-
process.on("uncaughtException", function(err: Error) {
448+
process.on("uncaughtException", function (err: Error) {
452449
ioSession.logError(err, "unknown");
453450
});
454451
// Start listening

‎src/server/session.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,6 +1459,7 @@ namespace ts.server {
14591459
}
14601460
this.projectService.typingsCache.updateTypingsForProject(response.projectName, response.compilerOptions, response.typingOptions, response.typings);
14611461
project.updateGraph();
1462+
14621463
}
14631464

14641465
public onMessage(message: string) {

‎src/server/types.d.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ declare namespace ts.server {
3333

3434
export interface InstallTypingHost extends JsTyping.TypingResolutionHost {
3535
writeFile(path: string, content: string): void;
36+
createDirectory(path: string): void;
3637
}
3738
}

‎src/server/typingsInstaller/nodeTypingsInstaller.ts‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,7 @@ namespace ts.server.typingsInstaller {
4242
return sys;
4343
}
4444

45-
C = 1;
46-
4745
protected sendResponse(response: InstallTypingsResponse) {
48-
(<any>response).___id = [this.C];
49-
this.C++;
50-
log("sendResponse::" + JSON.stringify(response));
5146
process.send(response);
5247
}
5348

‎src/server/typingsInstaller/typingsInstaller.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
/// <reference path="../types.d.ts"/>
33

44
namespace ts.server.typingsInstaller {
5-
export function log(s: string) {
6-
require("fs").appendFileSync("E:\\sources\\git\\installer.txt", s + "\r\n");
7-
}
85
const DefaultTsdSettings = JSON.stringify({
96
version: "v4",
107
repo: "DefinitelyTyped/DefinitelyTyped",
@@ -22,15 +19,13 @@ namespace ts.server.typingsInstaller {
2219
if (!this.isTsdInstalled) {
2320
this.isTsdInstalled = this.installPackage("tsd");
2421
}
25-
log(`start ${this.isTsdInstalled}`);
2622
}
2723

2824
install(req: InstallTypingsRequest) {
2925
if (!this.isTsdInstalled) {
3026
return;
3127
}
3228

33-
log(`install ${JSON.stringify(req)}`);
3429
const discoverTypingsResult = JsTyping.discoverTypings(
3530
this.getInstallTypingHost(),
3631
req.fileNames,
@@ -40,7 +35,6 @@ namespace ts.server.typingsInstaller {
4035
req.typingOptions,
4136
req.compilerOptions);
4237

43-
log(`install ${JSON.stringify(discoverTypingsResult)}`);
4438
// respond with whatever cached typings we have now
4539
this.sendResponse(this.createResponse(req, discoverTypingsResult.cachedTypingPaths));
4640
// start watching files
@@ -51,7 +45,6 @@ namespace ts.server.typingsInstaller {
5145

5246
private installTypings(req: InstallTypingsRequest, currentlyCachedTypings: string[], typingsToInstall: string[]) {
5347
typingsToInstall = filter(typingsToInstall, x => !hasProperty(this.missingTypings, x));
54-
log(`install ${JSON.stringify(typingsToInstall)}`);
5548
if (typingsToInstall.length === 0) {
5649
return;
5750
}
@@ -60,18 +53,28 @@ namespace ts.server.typingsInstaller {
6053
const host = this.getInstallTypingHost();
6154
const tsdPath = combinePaths(req.cachePath, "tsd.json");
6255
if (!host.fileExists(tsdPath)) {
56+
this.ensureDirectoryExists(req.cachePath, host);
6357
host.writeFile(tsdPath, DefaultTsdSettings);
6458
}
6559

6660
this.runTsd(req.cachePath, typingsToInstall, installedTypings => {
6761
// TODO: record new missing package names
6862
// TODO: watch project directory
6963
installedTypings = installedTypings.map(x => getNormalizedAbsolutePath(x, req.cachePath));
70-
log(`include ${JSON.stringify(installedTypings)}`);
7164
this.sendResponse(this.createResponse(req, currentlyCachedTypings.concat(installedTypings)));
7265
});
7366
}
7467

68+
private ensureDirectoryExists(directory: string, host: InstallTypingHost): void {
69+
const directoryName = getDirectoryPath(directory);
70+
if (!host.directoryExists(directoryName)) {
71+
this.ensureDirectoryExists(directoryName, host);
72+
}
73+
if (!host.directoryExists(directory)) {
74+
host.createDirectory(directory);
75+
}
76+
}
77+
7578
private watchFiles(files: string[]) {
7679
// TODO: start watching files
7780
}

0 commit comments

Comments
 (0)