ensure tsd cache directory exists

This commit is contained in:
Vladimir Matveev 2016-08-12 23:04:17 -07:00
parent 512ec04d29
commit d07261af4f
5 changed files with 18 additions and 21 deletions

View file

@ -77,7 +77,7 @@ namespace ts.server {
});
function compress(s: string): CompressedData {
const data = zlib.gzipSync(new Buffer(s, "utf8"));
const data = zlib.gzipSync(new Buffer(s, "utf8"));
return { data, length: data.length, compressionKind: "gzip" };
}
@ -167,7 +167,7 @@ namespace ts.server {
constructor(private readonly logger: server.Logger) {
switch (process.platform) {
case "win32":
this.cachePath = normalizeSlashes(combinePaths(process.env.LOCALAPPDATA || process.env.APPDATA, "Microsoft/TypeScript"));
this.cachePath = normalizeSlashes(combinePaths(process.env.LOCALAPPDATA || process.env.APPDATA, "Microsoft/TypeScript"));
break;
case "darwin":
case "linux":
@ -177,6 +177,7 @@ namespace ts.server {
}
bind(session: Session) {
this.session = session;
if (this.logger.hasLevel(LogLevel.requestTime)) {
this.logger.info("Binding...")
}
@ -202,15 +203,11 @@ namespace ts.server {
this.installer.send(request);
}
C = 1;
private handleMessage(response: InstallTypingsResponse) {
if (this.logger.hasLevel(LogLevel.verbose)) {
this.logger.info(`Received response: ${JSON.stringify(response)}`)
}
require("fs").appendFileSync("E:\\sources\\git\\tss.txt", this.C + " !!!::" + JSON.stringify(response) + "\r\n");
this.C++;
this.session.onTypingsInstalled(response);
require("fs").appendFileSync("E:\\sources\\git\\tss.txt", this.C + " !!!::" + "done" + "\r\n");
}
}
@ -293,7 +290,7 @@ namespace ts.server {
}
traceToConsole = logEnv.traceToConsole;
}
return new Logger(fileName, traceToConsole, detailLevel);
return new Logger(fileName, traceToConsole, detailLevel);
}
// This places log file in the directory containing editorServices.js
// TODO: check that this location is writable
@ -448,7 +445,7 @@ namespace ts.server {
const useSingleInferredProject = sys.args.some(arg => arg === "--useSingleInferredProject");
const ioSession = new IOSession(sys, cancellationToken, useSingleInferredProject, logger);
process.on("uncaughtException", function(err: Error) {
process.on("uncaughtException", function (err: Error) {
ioSession.logError(err, "unknown");
});
// Start listening

View file

@ -1459,6 +1459,7 @@ namespace ts.server {
}
this.projectService.typingsCache.updateTypingsForProject(response.projectName, response.compilerOptions, response.typingOptions, response.typings);
project.updateGraph();
}
public onMessage(message: string) {

View file

@ -33,5 +33,6 @@ declare namespace ts.server {
export interface InstallTypingHost extends JsTyping.TypingResolutionHost {
writeFile(path: string, content: string): void;
createDirectory(path: string): void;
}
}

View file

@ -42,12 +42,7 @@ namespace ts.server.typingsInstaller {
return sys;
}
C = 1;
protected sendResponse(response: InstallTypingsResponse) {
(<any>response).___id = [this.C];
this.C++;
log("sendResponse::" + JSON.stringify(response));
process.send(response);
}

View file

@ -2,9 +2,6 @@
/// <reference path="../types.d.ts"/>
namespace ts.server.typingsInstaller {
export function log(s: string) {
require("fs").appendFileSync("E:\\sources\\git\\installer.txt", s + "\r\n");
}
const DefaultTsdSettings = JSON.stringify({
version: "v4",
repo: "DefinitelyTyped/DefinitelyTyped",
@ -22,7 +19,6 @@ namespace ts.server.typingsInstaller {
if (!this.isTsdInstalled) {
this.isTsdInstalled = this.installPackage("tsd");
}
log(`start ${this.isTsdInstalled}`);
}
install(req: InstallTypingsRequest) {
@ -30,7 +26,6 @@ namespace ts.server.typingsInstaller {
return;
}
log(`install ${JSON.stringify(req)}`);
const discoverTypingsResult = JsTyping.discoverTypings(
this.getInstallTypingHost(),
req.fileNames,
@ -40,7 +35,6 @@ namespace ts.server.typingsInstaller {
req.typingOptions,
req.compilerOptions);
log(`install ${JSON.stringify(discoverTypingsResult)}`);
// respond with whatever cached typings we have now
this.sendResponse(this.createResponse(req, discoverTypingsResult.cachedTypingPaths));
// start watching files
@ -51,7 +45,6 @@ namespace ts.server.typingsInstaller {
private installTypings(req: InstallTypingsRequest, currentlyCachedTypings: string[], typingsToInstall: string[]) {
typingsToInstall = filter(typingsToInstall, x => !hasProperty(this.missingTypings, x));
log(`install ${JSON.stringify(typingsToInstall)}`);
if (typingsToInstall.length === 0) {
return;
}
@ -60,6 +53,7 @@ namespace ts.server.typingsInstaller {
const host = this.getInstallTypingHost();
const tsdPath = combinePaths(req.cachePath, "tsd.json");
if (!host.fileExists(tsdPath)) {
this.ensureDirectoryExists(req.cachePath, host);
host.writeFile(tsdPath, DefaultTsdSettings);
}
@ -67,11 +61,20 @@ namespace ts.server.typingsInstaller {
// TODO: record new missing package names
// TODO: watch project directory
installedTypings = installedTypings.map(x => getNormalizedAbsolutePath(x, req.cachePath));
log(`include ${JSON.stringify(installedTypings)}`);
this.sendResponse(this.createResponse(req, currentlyCachedTypings.concat(installedTypings)));
});
}
private ensureDirectoryExists(directory: string, host: InstallTypingHost): void {
const directoryName = getDirectoryPath(directory);
if (!host.directoryExists(directoryName)) {
this.ensureDirectoryExists(directoryName, host);
}
if (!host.directoryExists(directory)) {
host.createDirectory(directory);
}
}
private watchFiles(files: string[]) {
// TODO: start watching files
}