Update LKG

This commit is contained in:
Mohamed Hegazy 2016-11-04 12:01:20 -07:00
parent f03e04a41e
commit 8e8ec9f81d
5 changed files with 284 additions and 158 deletions

20
lib/protocol.d.ts vendored
View File

@ -1611,6 +1611,26 @@ declare namespace ts.server.protocol {
spans: TextSpan[];
childItems?: NavigationTree[];
}
type TelemetryEventName = "telemetry";
interface TelemetryEvent extends Event {
event: TelemetryEventName;
body: TelemetryEventBody;
}
interface TelemetryEventBody {
telemetryEventName: string;
payload: any;
}
type TypingsInstalledTelemetryEventName = "typingsInstalled";
interface TypingsInstalledTelemetryEventBody extends TelemetryEventBody {
telemetryEventName: TypingsInstalledTelemetryEventName;
payload: TypingsInstalledTelemetryEventPayload;
}
interface TypingsInstalledTelemetryEventPayload {
/**
* Comma separated list of installed typing packages
*/
installedPackages: string;
}
interface NavBarResponse extends Response {
body?: NavigationBarItem[];
}

View File

@ -5868,6 +5868,32 @@ var ts;
})(JsTyping = ts.JsTyping || (ts.JsTyping = {}));
})(ts || (ts = {}));
var ts;
(function (ts) {
var server;
(function (server) {
server.ActionSet = "action::set";
server.ActionInvalidate = "action::invalidate";
server.EventInstall = "event::install";
var Arguments;
(function (Arguments) {
Arguments.GlobalCacheLocation = "--globalTypingsCacheLocation";
Arguments.LogFile = "--logFile";
Arguments.EnableTelemetry = "--enableTelemetry";
})(Arguments = server.Arguments || (server.Arguments = {}));
function hasArgument(argumentName) {
return ts.sys.args.indexOf(argumentName) >= 0;
}
server.hasArgument = hasArgument;
function findArgument(argumentName) {
var index = ts.sys.args.indexOf(argumentName);
return index >= 0 && index < ts.sys.args.length - 1
? ts.sys.args[index + 1]
: undefined;
}
server.findArgument = findArgument;
})(server = ts.server || (ts.server = {}));
})(ts || (ts = {}));
var ts;
(function (ts) {
var server;
(function (server) {
@ -63322,10 +63348,10 @@ var ts;
return;
}
switch (response.kind) {
case "set":
case server.ActionSet:
this.typingsCache.updateTypingsForProject(response.projectName, response.compilerOptions, response.typingOptions, response.unresolvedImports, response.typings);
break;
case "invalidate":
case server.ActionInvalidate:
this.typingsCache.deleteTypingsForProject(response.projectName);
break;
}
@ -66593,8 +66619,9 @@ var ts;
return Logger;
}());
var NodeTypingsInstaller = (function () {
function NodeTypingsInstaller(logger, host, eventPort, globalTypingsCacheLocation, newLine) {
function NodeTypingsInstaller(telemetryEnabled, logger, host, eventPort, globalTypingsCacheLocation, newLine) {
var _this = this;
this.telemetryEnabled = telemetryEnabled;
this.logger = logger;
this.globalTypingsCacheLocation = globalTypingsCacheLocation;
this.newLine = newLine;
@ -66619,15 +66646,21 @@ var ts;
NodeTypingsInstaller.prototype.sendEvent = function (seq, event, body) {
this.socket.write(server.formatMessage({ seq: seq, type: "event", event: event, body: body }, this.logger, Buffer.byteLength, this.newLine), "utf8");
};
NodeTypingsInstaller.prototype.setTelemetrySender = function (telemetrySender) {
this.telemetrySender = telemetrySender;
};
NodeTypingsInstaller.prototype.attach = function (projectService) {
var _this = this;
this.projectService = projectService;
if (this.logger.hasLevel(server.LogLevel.requestTime)) {
this.logger.info("Binding...");
}
var args = ["--globalTypingsCacheLocation", this.globalTypingsCacheLocation];
var args = [server.Arguments.GlobalCacheLocation, this.globalTypingsCacheLocation];
if (this.telemetryEnabled) {
args.push(server.Arguments.EnableTelemetry);
}
if (this.logger.loggingEnabled() && this.logger.getLogFileName()) {
args.push("--logFile", ts.combinePaths(ts.getDirectoryPath(ts.normalizeSlashes(this.logger.getLogFileName())), "ti-" + process.pid + ".log"));
args.push(server.Arguments.LogFile, ts.combinePaths(ts.getDirectoryPath(ts.normalizeSlashes(this.logger.getLogFileName())), "ti-" + process.pid + ".log"));
}
var execArgv = [];
{
@ -66672,8 +66705,21 @@ var ts;
if (this.logger.hasLevel(server.LogLevel.verbose)) {
this.logger.info("Received response: " + JSON.stringify(response));
}
if (response.kind === server.EventInstall) {
if (this.telemetrySender) {
var body = {
telemetryEventName: "typingsInstalled",
payload: {
installedPackages: response.packagesToInstall.join(",")
}
};
var eventName = "telemetry";
this.telemetrySender.event(body, eventName);
}
return;
}
this.projectService.updateTypingsForProject(response);
if (response.kind == "set" && this.socket) {
if (response.kind == server.ActionSet && this.socket) {
this.sendEvent(0, "setTypings", response);
}
};
@ -66681,10 +66727,16 @@ var ts;
}());
var IOSession = (function (_super) {
__extends(IOSession, _super);
function IOSession(host, cancellationToken, installerEventPort, canUseEvents, useSingleInferredProject, disableAutomaticTypingAcquisition, globalTypingsCacheLocation, logger) {
return _super.call(this, host, cancellationToken, useSingleInferredProject, disableAutomaticTypingAcquisition
? server.nullTypingsInstaller
: new NodeTypingsInstaller(logger, host, installerEventPort, globalTypingsCacheLocation, host.newLine), Buffer.byteLength, process.hrtime, logger, canUseEvents) || this;
function IOSession(host, cancellationToken, installerEventPort, canUseEvents, useSingleInferredProject, disableAutomaticTypingAcquisition, globalTypingsCacheLocation, telemetryEnabled, logger) {
var _this;
var typingsInstaller = disableAutomaticTypingAcquisition
? undefined
: new NodeTypingsInstaller(telemetryEnabled, logger, host, installerEventPort, globalTypingsCacheLocation, host.newLine);
_this = _super.call(this, host, cancellationToken, useSingleInferredProject, typingsInstaller || server.nullTypingsInstaller, Buffer.byteLength, process.hrtime, logger, canUseEvents) || this;
if (telemetryEnabled && typingsInstaller) {
typingsInstaller.setTelemetrySender(_this);
}
return _this;
}
IOSession.prototype.exit = function () {
this.logger.info("Exiting...");
@ -66864,17 +66916,16 @@ var ts;
;
var eventPort;
{
var index = sys.args.indexOf("--eventPort");
if (index >= 0 && index < sys.args.length - 1) {
var v = parseInt(sys.args[index + 1]);
if (!isNaN(v)) {
eventPort = v;
}
var str = server.findArgument("--eventPort");
var v = str && parseInt(str);
if (!isNaN(v)) {
eventPort = v;
}
}
var useSingleInferredProject = sys.args.indexOf("--useSingleInferredProject") >= 0;
var disableAutomaticTypingAcquisition = sys.args.indexOf("--disableAutomaticTypingAcquisition") >= 0;
var ioSession = new IOSession(sys, cancellationToken, eventPort, eventPort === undefined, useSingleInferredProject, disableAutomaticTypingAcquisition, getGlobalTypingsCacheLocation(), logger);
var useSingleInferredProject = server.hasArgument("--useSingleInferredProject");
var disableAutomaticTypingAcquisition = server.hasArgument("--disableAutomaticTypingAcquisition");
var telemetryEnabled = server.hasArgument(server.Arguments.EnableTelemetry);
var ioSession = new IOSession(sys, cancellationToken, eventPort, eventPort === undefined, useSingleInferredProject, disableAutomaticTypingAcquisition, getGlobalTypingsCacheLocation(), telemetryEnabled, logger);
process.on("uncaughtException", function (err) {
ioSession.logError(err, "unknown");
});

View File

@ -690,6 +690,23 @@ declare namespace ts.server.protocol {
spans: TextSpan[];
childItems?: NavigationTree[];
}
type TelemetryEventName = "telemetry";
interface TelemetryEvent extends Event {
event: TelemetryEventName;
body: TelemetryEventBody;
}
interface TelemetryEventBody {
telemetryEventName: string;
payload: any;
}
type TypingsInstalledTelemetryEventName = "typingsInstalled";
interface TypingsInstalledTelemetryEventBody extends TelemetryEventBody {
telemetryEventName: TypingsInstalledTelemetryEventName;
payload: TypingsInstalledTelemetryEventPayload;
}
interface TypingsInstalledTelemetryEventPayload {
installedPackages: string;
}
interface NavBarResponse extends Response {
body?: NavigationBarItem[];
}
@ -8398,6 +8415,18 @@ declare namespace ts.JsTyping {
filesToWatch: string[];
};
}
declare namespace ts.server {
const ActionSet: ActionSet;
const ActionInvalidate: ActionInvalidate;
const EventInstall: EventInstall;
namespace Arguments {
const GlobalCacheLocation = "--globalTypingsCacheLocation";
const LogFile = "--logFile";
const EnableTelemetry = "--enableTelemetry";
}
function hasArgument(argumentName: string): boolean;
function findArgument(argumentName: string): string;
}
declare namespace ts.server {
enum LogLevel {
terse = 0,
@ -10902,6 +10931,9 @@ declare namespace ts.server {
fileName: NormalizedPath;
project: Project;
}
interface EventSender {
event(payload: any, eventName: string): void;
}
namespace CommandNames {
const Brace: protocol.CommandTypes.Brace;
const BraceFull: protocol.CommandTypes.BraceFull;
@ -10973,7 +11005,7 @@ declare namespace ts.server {
const GetSupportedCodeFixes: protocol.CommandTypes.GetSupportedCodeFixes;
}
function formatMessage<T extends protocol.Message>(msg: T, logger: server.Logger, byteLength: (s: string, encoding: string) => number, newLine: string): string;
class Session {
class Session implements EventSender {
private host;
protected readonly typingsInstaller: ITypingsInstaller;
private byteLength;

View File

@ -5868,6 +5868,32 @@ var ts;
})(JsTyping = ts.JsTyping || (ts.JsTyping = {}));
})(ts || (ts = {}));
var ts;
(function (ts) {
var server;
(function (server) {
server.ActionSet = "action::set";
server.ActionInvalidate = "action::invalidate";
server.EventInstall = "event::install";
var Arguments;
(function (Arguments) {
Arguments.GlobalCacheLocation = "--globalTypingsCacheLocation";
Arguments.LogFile = "--logFile";
Arguments.EnableTelemetry = "--enableTelemetry";
})(Arguments = server.Arguments || (server.Arguments = {}));
function hasArgument(argumentName) {
return ts.sys.args.indexOf(argumentName) >= 0;
}
server.hasArgument = hasArgument;
function findArgument(argumentName) {
var index = ts.sys.args.indexOf(argumentName);
return index >= 0 && index < ts.sys.args.length - 1
? ts.sys.args[index + 1]
: undefined;
}
server.findArgument = findArgument;
})(server = ts.server || (ts.server = {}));
})(ts || (ts = {}));
var ts;
(function (ts) {
var server;
(function (server) {
@ -63322,10 +63348,10 @@ var ts;
return;
}
switch (response.kind) {
case "set":
case server.ActionSet:
this.typingsCache.updateTypingsForProject(response.projectName, response.compilerOptions, response.typingOptions, response.unresolvedImports, response.typings);
break;
case "invalidate":
case server.ActionInvalidate:
this.typingsCache.deleteTypingsForProject(response.projectName);
break;
}

View File

@ -5868,6 +5868,32 @@ var ts;
})(JsTyping = ts.JsTyping || (ts.JsTyping = {}));
})(ts || (ts = {}));
var ts;
(function (ts) {
var server;
(function (server) {
server.ActionSet = "action::set";
server.ActionInvalidate = "action::invalidate";
server.EventInstall = "event::install";
var Arguments;
(function (Arguments) {
Arguments.GlobalCacheLocation = "--globalTypingsCacheLocation";
Arguments.LogFile = "--logFile";
Arguments.EnableTelemetry = "--enableTelemetry";
})(Arguments = server.Arguments || (server.Arguments = {}));
function hasArgument(argumentName) {
return ts.sys.args.indexOf(argumentName) >= 0;
}
server.hasArgument = hasArgument;
function findArgument(argumentName) {
var index = ts.sys.args.indexOf(argumentName);
return index >= 0 && index < ts.sys.args.length - 1
? ts.sys.args[index + 1]
: undefined;
}
server.findArgument = findArgument;
})(server = ts.server || (ts.server = {}));
})(ts || (ts = {}));
var ts;
(function (ts) {
function trace(host) {
host.trace(ts.formatMessage.apply(undefined, arguments));
@ -6468,14 +6494,14 @@ var ts;
return PackageNameValidationResult.Ok;
}
typingsInstaller.validatePackageName = validatePackageName;
typingsInstaller.NpmViewRequest = "npm view";
typingsInstaller.NpmInstallRequest = "npm install";
var TypingsInstaller = (function () {
function TypingsInstaller(globalCachePath, safeListPath, throttleLimit, log) {
function TypingsInstaller(installTypingHost, globalCachePath, safeListPath, throttleLimit, telemetryEnabled, log) {
if (log === void 0) { log = nullLog; }
this.installTypingHost = installTypingHost;
this.globalCachePath = globalCachePath;
this.safeListPath = safeListPath;
this.throttleLimit = throttleLimit;
this.telemetryEnabled = telemetryEnabled;
this.log = log;
this.packageNameToTypingLocation = ts.createMap();
this.missingTypingsSet = ts.createMap();
@ -6487,10 +6513,8 @@ var ts;
if (this.log.isEnabled()) {
this.log.writeLine("Global cache location '" + globalCachePath + "', safe file path '" + safeListPath + "'");
}
}
TypingsInstaller.prototype.init = function () {
this.processCacheLocation(this.globalCachePath);
};
}
TypingsInstaller.prototype.closeProject = function (req) {
this.closeWatchers(req.projectName);
};
@ -6589,7 +6613,7 @@ var ts;
}
this.knownCachesSet[cacheLocation] = true;
};
TypingsInstaller.prototype.filterTypings = function (typingsToInstall) {
TypingsInstaller.prototype.filterAndMapToScopedName = function (typingsToInstall) {
if (typingsToInstall.length === 0) {
return typingsToInstall;
}
@ -6601,7 +6625,14 @@ var ts;
}
var validationResult = validatePackageName(typing);
if (validationResult === PackageNameValidationResult.Ok) {
result.push(typing);
if (typing in this.typesRegistry) {
result.push("@types/" + typing);
}
else {
if (this.log.isEnabled()) {
this.log.writeLine("Entry for package '" + typing + "' does not exist in local types registry - skipping...");
}
}
}
else {
this.missingTypingsSet[typing] = true;
@ -6631,19 +6662,8 @@ var ts;
}
return result;
};
TypingsInstaller.prototype.installTypings = function (req, cachePath, currentlyCachedTypings, typingsToInstall) {
var _this = this;
if (this.log.isEnabled()) {
this.log.writeLine("Installing typings " + JSON.stringify(typingsToInstall));
}
typingsToInstall = this.filterTypings(typingsToInstall);
if (typingsToInstall.length === 0) {
if (this.log.isEnabled()) {
this.log.writeLine("All typings are known to be missing or invalid - no need to go any further");
}
return;
}
var npmConfigPath = ts.combinePaths(cachePath, "package.json");
TypingsInstaller.prototype.ensurePackageDirectoryExists = function (directory) {
var npmConfigPath = ts.combinePaths(directory, "package.json");
if (this.log.isEnabled()) {
this.log.writeLine("Npm config file: " + npmConfigPath);
}
@ -6651,22 +6671,45 @@ var ts;
if (this.log.isEnabled()) {
this.log.writeLine("Npm config file: '" + npmConfigPath + "' is missing, creating new one...");
}
this.ensureDirectoryExists(cachePath, this.installTypingHost);
this.ensureDirectoryExists(directory, this.installTypingHost);
this.installTypingHost.writeFile(npmConfigPath, "{}");
}
this.runInstall(cachePath, typingsToInstall, function (installedTypings) {
if (_this.log.isEnabled()) {
_this.log.writeLine("Requested to install typings " + JSON.stringify(typingsToInstall) + ", installed typings " + JSON.stringify(installedTypings));
};
TypingsInstaller.prototype.installTypings = function (req, cachePath, currentlyCachedTypings, typingsToInstall) {
var _this = this;
if (this.log.isEnabled()) {
this.log.writeLine("Installing typings " + JSON.stringify(typingsToInstall));
}
var scopedTypings = this.filterAndMapToScopedName(typingsToInstall);
if (scopedTypings.length === 0) {
if (this.log.isEnabled()) {
this.log.writeLine("All typings are known to be missing or invalid - no need to go any further");
}
return;
}
this.ensurePackageDirectoryExists(cachePath);
var requestId = this.installRunCount;
this.installRunCount++;
this.installTypingsAsync(requestId, scopedTypings, cachePath, function (ok) {
if (_this.telemetryEnabled) {
_this.sendResponse({
kind: server.EventInstall,
packagesToInstall: scopedTypings
});
}
if (!ok) {
return;
}
if (_this.log.isEnabled()) {
_this.log.writeLine("Requested to install typings " + JSON.stringify(scopedTypings) + ", installed typings " + JSON.stringify(scopedTypings));
}
var installedPackages = ts.createMap();
var installedTypingFiles = [];
for (var _i = 0, installedTypings_1 = installedTypings; _i < installedTypings_1.length; _i++) {
var t = installedTypings_1[_i];
for (var _i = 0, scopedTypings_1 = scopedTypings; _i < scopedTypings_1.length; _i++) {
var t = scopedTypings_1[_i];
var packageName = ts.getBaseFileName(t);
if (!packageName) {
continue;
}
installedPackages[packageName] = true;
var typingFile = typingToFileName(cachePath, packageName, _this.installTypingHost);
if (!typingFile) {
continue;
@ -6679,49 +6722,9 @@ var ts;
if (_this.log.isEnabled()) {
_this.log.writeLine("Installed typing files " + JSON.stringify(installedTypingFiles));
}
for (var _a = 0, typingsToInstall_2 = typingsToInstall; _a < typingsToInstall_2.length; _a++) {
var toInstall = typingsToInstall_2[_a];
if (!installedPackages[toInstall]) {
if (_this.log.isEnabled()) {
_this.log.writeLine("New missing typing package '" + toInstall + "'");
}
_this.missingTypingsSet[toInstall] = true;
}
}
_this.sendResponse(_this.createSetTypings(req, currentlyCachedTypings.concat(installedTypingFiles)));
});
};
TypingsInstaller.prototype.runInstall = function (cachePath, typingsToInstall, postInstallAction) {
var requestId = this.installRunCount;
this.installRunCount++;
var execInstallCmdCount = 0;
var filteredTypings = [];
for (var _i = 0, typingsToInstall_3 = typingsToInstall; _i < typingsToInstall_3.length; _i++) {
var typing = typingsToInstall_3[_i];
filterExistingTypings(this, typing);
}
function filterExistingTypings(self, typing) {
self.execAsync(typingsInstaller.NpmViewRequest, requestId, [typing], cachePath, function (ok) {
if (ok) {
filteredTypings.push(typing);
}
execInstallCmdCount++;
if (execInstallCmdCount === typingsToInstall.length) {
installFilteredTypings(self, filteredTypings);
}
});
}
function installFilteredTypings(self, filteredTypings) {
if (filteredTypings.length === 0) {
postInstallAction([]);
return;
}
var scopedTypings = filteredTypings.map(function (t) { return "@types/" + t; });
self.execAsync(typingsInstaller.NpmInstallRequest, requestId, scopedTypings, cachePath, function (ok) {
postInstallAction(ok ? scopedTypings : []);
});
}
};
TypingsInstaller.prototype.ensureDirectoryExists = function (directory, host) {
var directoryName = ts.getDirectoryPath(directory);
if (!host.directoryExists(directoryName)) {
@ -6746,7 +6749,7 @@ var ts;
_this.log.writeLine("Got FS notification for " + f + ", handler is already invoked '" + isInvoked + "'");
}
if (!isInvoked) {
_this.sendResponse({ projectName: projectName, kind: "invalidate" });
_this.sendResponse({ projectName: projectName, kind: server.ActionInvalidate });
isInvoked = true;
}
});
@ -6761,11 +6764,11 @@ var ts;
compilerOptions: request.compilerOptions,
typings: typings,
unresolvedImports: request.unresolvedImports,
kind: "set"
kind: server.ActionSet
};
};
TypingsInstaller.prototype.execAsync = function (requestKind, requestId, args, cwd, onRequestCompleted) {
this.pendingRunRequests.unshift({ requestKind: requestKind, requestId: requestId, args: args, cwd: cwd, onRequestCompleted: onRequestCompleted });
TypingsInstaller.prototype.installTypingsAsync = function (requestId, args, cwd, onRequestCompleted) {
this.pendingRunRequests.unshift({ requestId: requestId, args: args, cwd: cwd, onRequestCompleted: onRequestCompleted });
this.executeWithThrottling();
};
TypingsInstaller.prototype.executeWithThrottling = function () {
@ -6773,7 +6776,7 @@ var ts;
var _loop_1 = function () {
this_1.inFlightRequestCount++;
var request = this_1.pendingRunRequests.pop();
this_1.executeRequest(request.requestKind, request.requestId, request.args, request.cwd, function (ok) {
this_1.installWorker(request.requestId, request.args, request.cwd, function (ok) {
_this.inFlightRequestCount--;
request.onRequestCompleted(ok);
_this.executeWithThrottling();
@ -6818,22 +6821,56 @@ var ts;
return "npm";
}
}
function loadTypesRegistryFile(typesRegistryFilePath, host, log) {
if (!host.fileExists(typesRegistryFilePath)) {
if (log.isEnabled()) {
log.writeLine("Types registry file '" + typesRegistryFilePath + "' does not exist");
}
return ts.createMap();
}
try {
var content = JSON.parse(host.readFile(typesRegistryFilePath));
return ts.createMap(content.entries);
}
catch (e) {
if (log.isEnabled()) {
log.writeLine("Error when loading types registry file '" + typesRegistryFilePath + "': " + e.message + ", " + e.stack);
}
return ts.createMap();
}
}
var TypesRegistryPackageName = "types-registry";
function getTypesRegistryFileLocation(globalTypingsCacheLocation) {
return ts.combinePaths(ts.normalizeSlashes(globalTypingsCacheLocation), "node_modules/" + TypesRegistryPackageName + "/index.json");
}
var NodeTypingsInstaller = (function (_super) {
__extends(NodeTypingsInstaller, _super);
function NodeTypingsInstaller(globalTypingsCacheLocation, throttleLimit, log) {
var _this = _super.call(this, globalTypingsCacheLocation, ts.toPath("typingSafeList.json", __dirname, ts.createGetCanonicalFileName(ts.sys.useCaseSensitiveFileNames)), throttleLimit, log) || this;
_this.installTypingHost = ts.sys;
function NodeTypingsInstaller(globalTypingsCacheLocation, throttleLimit, telemetryEnabled, log) {
var _this = _super.call(this, ts.sys, globalTypingsCacheLocation, ts.toPath("typingSafeList.json", __dirname, ts.createGetCanonicalFileName(ts.sys.useCaseSensitiveFileNames)), throttleLimit, telemetryEnabled, log) || this;
if (_this.log.isEnabled()) {
_this.log.writeLine("Process id: " + process.pid);
}
_this.npmPath = getNPMLocation(process.argv[0]);
_this.exec = require("child_process").exec;
_this.httpGet = require("http").get;
var execSync;
(_a = require("child_process"), _this.exec = _a.exec, execSync = _a.execSync, _a);
_this.ensurePackageDirectoryExists(globalTypingsCacheLocation);
try {
if (_this.log.isEnabled()) {
_this.log.writeLine("Updating " + TypesRegistryPackageName + " npm package...");
}
execSync(_this.npmPath + " install " + TypesRegistryPackageName, { cwd: globalTypingsCacheLocation, stdio: "ignore" });
}
catch (e) {
if (_this.log.isEnabled()) {
_this.log.writeLine("Error updating " + TypesRegistryPackageName + " package: " + e.message);
}
}
_this.typesRegistry = loadTypesRegistryFile(getTypesRegistryFileLocation(globalTypingsCacheLocation), _this.installTypingHost, _this.log);
return _this;
var _a;
}
NodeTypingsInstaller.prototype.init = function () {
NodeTypingsInstaller.prototype.listen = function () {
var _this = this;
_super.prototype.init.call(this);
process.on("message", function (req) {
switch (req.kind) {
case "discover":
@ -6853,66 +6890,26 @@ var ts;
this.log.writeLine("Response has been sent.");
}
};
NodeTypingsInstaller.prototype.executeRequest = function (requestKind, requestId, args, cwd, onRequestCompleted) {
NodeTypingsInstaller.prototype.installWorker = function (requestId, args, cwd, onRequestCompleted) {
var _this = this;
if (this.log.isEnabled()) {
this.log.writeLine("#" + requestId + " executing " + requestKind + ", arguments'" + JSON.stringify(args) + "'.");
}
switch (requestKind) {
case typingsInstaller.NpmViewRequest:
{
ts.Debug.assert(args.length === 1);
var url_1 = "http://registry.npmjs.org/@types%2f" + args[0];
var start_2 = Date.now();
this.httpGet(url_1, function (response) {
var ok = false;
if (_this.log.isEnabled()) {
_this.log.writeLine(requestKind + " #" + requestId + " request to " + url_1 + ":: status code " + response.statusCode + ", status message '" + response.statusMessage + "', took " + (Date.now() - start_2) + " ms");
}
switch (response.statusCode) {
case 200:
case 301:
case 302:
ok = true;
break;
}
response.destroy();
onRequestCompleted(ok);
}).on("error", function (err) {
if (_this.log.isEnabled()) {
_this.log.writeLine(requestKind + " #" + requestId + " query to npm registry failed with error " + err.message + ", stack " + err.stack);
}
onRequestCompleted(false);
});
}
break;
case typingsInstaller.NpmInstallRequest:
{
var command = this.npmPath + " install " + args.join(" ") + " --save-dev";
var start_3 = Date.now();
this.exec(command, { cwd: cwd }, function (_err, stdout, stderr) {
if (_this.log.isEnabled()) {
_this.log.writeLine(requestKind + " #" + requestId + " took: " + (Date.now() - start_3) + " ms" + ts.sys.newLine + "stdout: " + stdout + ts.sys.newLine + "stderr: " + stderr);
}
onRequestCompleted(!!stdout);
});
}
break;
default:
ts.Debug.assert(false, "Unknown request kind " + requestKind);
this.log.writeLine("#" + requestId + " with arguments'" + JSON.stringify(args) + "'.");
}
var command = this.npmPath + " install " + args.join(" ") + " --save-dev";
var start = Date.now();
this.exec(command, { cwd: cwd }, function (_err, stdout, stderr) {
if (_this.log.isEnabled()) {
_this.log.writeLine("npm install #" + requestId + " took: " + (Date.now() - start) + " ms" + ts.sys.newLine + "stdout: " + stdout + ts.sys.newLine + "stderr: " + stderr);
}
onRequestCompleted(!!stdout);
});
};
return NodeTypingsInstaller;
}(typingsInstaller.TypingsInstaller));
typingsInstaller.NodeTypingsInstaller = NodeTypingsInstaller;
function findArgument(argumentName) {
var index = ts.sys.args.indexOf(argumentName);
return index >= 0 && index < ts.sys.args.length - 1
? ts.sys.args[index + 1]
: undefined;
}
var logFilePath = findArgument("--logFile");
var globalTypingsCacheLocation = findArgument("--globalTypingsCacheLocation");
var logFilePath = server.findArgument(server.Arguments.LogFile);
var globalTypingsCacheLocation = server.findArgument(server.Arguments.GlobalCacheLocation);
var telemetryEnabled = server.hasArgument(server.Arguments.EnableTelemetry);
var log = new FileLog(logFilePath);
if (log.isEnabled()) {
process.on("uncaughtException", function (e) {
@ -6925,8 +6922,8 @@ var ts;
}
process.exit(0);
});
var installer = new NodeTypingsInstaller(globalTypingsCacheLocation, 5, log);
installer.init();
var installer = new NodeTypingsInstaller(globalTypingsCacheLocation, 5, telemetryEnabled, log);
installer.listen();
})(typingsInstaller = server.typingsInstaller || (server.typingsInstaller = {}));
})(server = ts.server || (ts.server = {}));
})(ts || (ts = {}));