[Pkg-javascript-commits] [node-typescript] 01/03: New upstream version 2.0.7
Julien Puydt
julien.puydt at laposte.net
Sun Nov 6 09:16:20 UTC 2016
This is an automated email from the git hooks/post-receive script.
jpuydt-guest pushed a commit to branch master
in repository node-typescript.
commit 8b525d51a1ef949318a7f402e2ec5b7a38fbb840
Author: Julien Puydt <julien.puydt at laposte.net>
Date: Sun Nov 6 10:13:57 2016 +0100
New upstream version 2.0.7
---
lib/tsc.js | 2 +-
lib/tsserver.js | 47 +++--
lib/tsserverlibrary.d.ts | 18 +-
lib/tsserverlibrary.js | 47 +++--
lib/typescript.js | 47 +++--
lib/typescriptServices.js | 47 +++--
lib/typingsInstaller.js | 211 +++++++++------------
package.json | 2 +-
src/compiler/program.ts | 2 +-
src/harness/unittests/tsserverProjectSystem.ts | 32 ++--
src/harness/unittests/typingsInstaller.ts | 187 ++++++++----------
.../typingsInstaller/nodeTypingsInstaller.ts | 121 ++++++------
src/server/typingsInstaller/typingsInstaller.ts | 115 ++++-------
src/services/formatting/formatting.ts | 30 ++-
src/services/formatting/rulesProvider.ts | 6 +-
src/services/services.ts | 12 +-
16 files changed, 477 insertions(+), 449 deletions(-)
diff --git a/lib/tsc.js b/lib/tsc.js
index 9d72acf..fff7700 100644
--- a/lib/tsc.js
+++ b/lib/tsc.js
@@ -37138,7 +37138,7 @@ var ts;
})(ts || (ts = {}));
var ts;
(function (ts) {
- ts.version = "2.0.6";
+ ts.version = "2.0.7";
var emptyArray = [];
function findConfigFile(searchPath, fileExists, configName) {
if (configName === void 0) { configName = "tsconfig.json"; }
diff --git a/lib/tsserver.js b/lib/tsserver.js
index 63f1b11..9ce9c5c 100644
--- a/lib/tsserver.js
+++ b/lib/tsserver.js
@@ -38527,7 +38527,7 @@ var ts;
})(ts || (ts = {}));
var ts;
(function (ts) {
- ts.version = "2.0.6";
+ ts.version = "2.0.7";
var emptyArray = [];
function findConfigFile(searchPath, fileExists, configName) {
if (configName === void 0) { configName = "tsconfig.json"; }
@@ -43823,6 +43823,9 @@ var ts;
return this.rulesMap;
};
RulesProvider.prototype.ensureUpToDate = function (options) {
+ this.ensureUpToDateWorker(ts.toEditorSettings(options));
+ };
+ RulesProvider.prototype.ensureUpToDateWorker = function (options) {
if (!this.options || !ts.compareDataObjects(this.options, options)) {
var activeRules = this.createActiveRules(options);
var rulesMap = formatting.RulesMap.create(activeRules);
@@ -43921,6 +43924,10 @@ var ts;
var formatting;
(function (formatting) {
function formatOnEnter(position, sourceFile, rulesProvider, options) {
+ return formatOnEnterWorker(position, sourceFile, rulesProvider, ts.toEditorSettings(options));
+ }
+ formatting.formatOnEnter = formatOnEnter;
+ function formatOnEnterWorker(position, sourceFile, rulesProvider, options) {
var line = sourceFile.getLineAndCharacterOfPosition(position).line;
if (line === 0) {
return [];
@@ -43938,31 +43945,47 @@ var ts;
};
return formatSpan(span, sourceFile, options, rulesProvider, 2);
}
- formatting.formatOnEnter = formatOnEnter;
+ formatting.formatOnEnterWorker = formatOnEnterWorker;
function formatOnSemicolon(position, sourceFile, rulesProvider, options) {
- return formatOutermostParent(position, 23, sourceFile, options, rulesProvider, 3);
+ return formatOnSemicolonWorker(position, sourceFile, rulesProvider, ts.toEditorSettings(options));
}
formatting.formatOnSemicolon = formatOnSemicolon;
+ function formatOnSemicolonWorker(position, sourceFile, rulesProvider, options) {
+ return formatOutermostParent(position, 23, sourceFile, options, rulesProvider, 3);
+ }
+ formatting.formatOnSemicolonWorker = formatOnSemicolonWorker;
function formatOnClosingCurly(position, sourceFile, rulesProvider, options) {
- return formatOutermostParent(position, 16, sourceFile, options, rulesProvider, 4);
+ return formatOnClosingCurlyWorker(position, sourceFile, rulesProvider, ts.toEditorSettings(options));
}
formatting.formatOnClosingCurly = formatOnClosingCurly;
+ function formatOnClosingCurlyWorker(position, sourceFile, rulesProvider, options) {
+ return formatOutermostParent(position, 16, sourceFile, options, rulesProvider, 4);
+ }
+ formatting.formatOnClosingCurlyWorker = formatOnClosingCurlyWorker;
function formatDocument(sourceFile, rulesProvider, options) {
+ return formatDocumentWorker(sourceFile, rulesProvider, ts.toEditorSettings(options));
+ }
+ formatting.formatDocument = formatDocument;
+ function formatDocumentWorker(sourceFile, rulesProvider, options) {
var span = {
pos: 0,
end: sourceFile.text.length
};
return formatSpan(span, sourceFile, options, rulesProvider, 0);
}
- formatting.formatDocument = formatDocument;
+ formatting.formatDocumentWorker = formatDocumentWorker;
function formatSelection(start, end, sourceFile, rulesProvider, options) {
+ return formatSelectionWorker(start, end, sourceFile, rulesProvider, ts.toEditorSettings(options));
+ }
+ formatting.formatSelection = formatSelection;
+ function formatSelectionWorker(start, end, sourceFile, rulesProvider, options) {
var span = {
pos: ts.getLineStartPositionForPosition(start, sourceFile),
end: end
};
return formatSpan(span, sourceFile, options, rulesProvider, 1);
}
- formatting.formatSelection = formatSelection;
+ formatting.formatSelectionWorker = formatSelectionWorker;
function formatOutermostParent(position, expectedLastToken, sourceFile, options, rulesProvider, requestKind) {
var parent = findOutermostParent(position, expectedLastToken, sourceFile);
if (!parent) {
@@ -46888,7 +46911,7 @@ var ts;
if (!ruleProvider) {
ruleProvider = new ts.formatting.RulesProvider();
}
- ruleProvider.ensureUpToDate(options);
+ ruleProvider.ensureUpToDateWorker(options);
return ruleProvider;
}
function synchronizeHostData() {
@@ -50857,24 +50880,24 @@ var ts;
function getFormattingEditsForRange(fileName, start, end, optionsOrSettings) {
var settings = toEditorSettings(optionsOrSettings);
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
- return ts.formatting.formatSelection(start, end, sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatSelectionWorker(start, end, sourceFile, getRuleProvider(settings), settings);
}
function getFormattingEditsForDocument(fileName, optionsOrSettings) {
var settings = toEditorSettings(optionsOrSettings);
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
- return ts.formatting.formatDocument(sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatDocumentWorker(sourceFile, getRuleProvider(settings), settings);
}
function getFormattingEditsAfterKeystroke(fileName, position, key, optionsOrSettings) {
var settings = toEditorSettings(optionsOrSettings);
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
if (key === "}") {
- return ts.formatting.formatOnClosingCurly(position, sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatOnClosingCurlyWorker(position, sourceFile, getRuleProvider(settings), settings);
}
else if (key === ";") {
- return ts.formatting.formatOnSemicolon(position, sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatOnSemicolonWorker(position, sourceFile, getRuleProvider(settings), settings);
}
else if (key === "\n") {
- return ts.formatting.formatOnEnter(position, sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatOnEnterWorker(position, sourceFile, getRuleProvider(settings), settings);
}
return [];
}
diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts
index 3104e24..a07ac62 100644
--- a/lib/tsserverlibrary.d.ts
+++ b/lib/tsserverlibrary.d.ts
@@ -8739,7 +8739,8 @@ declare namespace ts.formatting {
getRuleName(rule: Rule): string;
getRuleByName(name: string): Rule;
getRulesMap(): RulesMap;
- ensureUpToDate(options: ts.FormatCodeSettings): void;
+ ensureUpToDate(options: ts.FormatCodeSettings | ts.FormatCodeOptions): void;
+ ensureUpToDateWorker(options: ts.FormatCodeSettings): void;
private createActiveRules(options);
}
}
@@ -8752,11 +8753,16 @@ declare namespace ts.formatting {
token: TextRangeWithKind;
trailingTrivia: TextRangeWithKind[];
}
- function formatOnEnter(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[];
- function formatOnSemicolon(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[];
- function formatOnClosingCurly(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[];
- function formatDocument(sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[];
- function formatSelection(start: number, end: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[];
+ function formatOnEnter(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings | FormatCodeOptions): TextChange[];
+ function formatOnEnterWorker(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[];
+ function formatOnSemicolon(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings | FormatCodeOptions): TextChange[];
+ function formatOnSemicolonWorker(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[];
+ function formatOnClosingCurly(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings | FormatCodeOptions): TextChange[];
+ function formatOnClosingCurlyWorker(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[];
+ function formatDocument(sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings | FormatCodeOptions): TextChange[];
+ function formatDocumentWorker(sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[];
+ function formatSelection(start: number, end: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings | FormatCodeOptions): TextChange[];
+ function formatSelectionWorker(start: number, end: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[];
function getIndentationString(indentation: number, options: EditorSettings): string;
}
declare namespace ts.formatting {
diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js
index 2dfa6f7..8b468b4 100644
--- a/lib/tsserverlibrary.js
+++ b/lib/tsserverlibrary.js
@@ -38527,7 +38527,7 @@ var ts;
})(ts || (ts = {}));
var ts;
(function (ts) {
- ts.version = "2.0.6";
+ ts.version = "2.0.7";
var emptyArray = [];
function findConfigFile(searchPath, fileExists, configName) {
if (configName === void 0) { configName = "tsconfig.json"; }
@@ -43823,6 +43823,9 @@ var ts;
return this.rulesMap;
};
RulesProvider.prototype.ensureUpToDate = function (options) {
+ this.ensureUpToDateWorker(ts.toEditorSettings(options));
+ };
+ RulesProvider.prototype.ensureUpToDateWorker = function (options) {
if (!this.options || !ts.compareDataObjects(this.options, options)) {
var activeRules = this.createActiveRules(options);
var rulesMap = formatting.RulesMap.create(activeRules);
@@ -43921,6 +43924,10 @@ var ts;
var formatting;
(function (formatting) {
function formatOnEnter(position, sourceFile, rulesProvider, options) {
+ return formatOnEnterWorker(position, sourceFile, rulesProvider, ts.toEditorSettings(options));
+ }
+ formatting.formatOnEnter = formatOnEnter;
+ function formatOnEnterWorker(position, sourceFile, rulesProvider, options) {
var line = sourceFile.getLineAndCharacterOfPosition(position).line;
if (line === 0) {
return [];
@@ -43938,31 +43945,47 @@ var ts;
};
return formatSpan(span, sourceFile, options, rulesProvider, 2);
}
- formatting.formatOnEnter = formatOnEnter;
+ formatting.formatOnEnterWorker = formatOnEnterWorker;
function formatOnSemicolon(position, sourceFile, rulesProvider, options) {
- return formatOutermostParent(position, 23, sourceFile, options, rulesProvider, 3);
+ return formatOnSemicolonWorker(position, sourceFile, rulesProvider, ts.toEditorSettings(options));
}
formatting.formatOnSemicolon = formatOnSemicolon;
+ function formatOnSemicolonWorker(position, sourceFile, rulesProvider, options) {
+ return formatOutermostParent(position, 23, sourceFile, options, rulesProvider, 3);
+ }
+ formatting.formatOnSemicolonWorker = formatOnSemicolonWorker;
function formatOnClosingCurly(position, sourceFile, rulesProvider, options) {
- return formatOutermostParent(position, 16, sourceFile, options, rulesProvider, 4);
+ return formatOnClosingCurlyWorker(position, sourceFile, rulesProvider, ts.toEditorSettings(options));
}
formatting.formatOnClosingCurly = formatOnClosingCurly;
+ function formatOnClosingCurlyWorker(position, sourceFile, rulesProvider, options) {
+ return formatOutermostParent(position, 16, sourceFile, options, rulesProvider, 4);
+ }
+ formatting.formatOnClosingCurlyWorker = formatOnClosingCurlyWorker;
function formatDocument(sourceFile, rulesProvider, options) {
+ return formatDocumentWorker(sourceFile, rulesProvider, ts.toEditorSettings(options));
+ }
+ formatting.formatDocument = formatDocument;
+ function formatDocumentWorker(sourceFile, rulesProvider, options) {
var span = {
pos: 0,
end: sourceFile.text.length
};
return formatSpan(span, sourceFile, options, rulesProvider, 0);
}
- formatting.formatDocument = formatDocument;
+ formatting.formatDocumentWorker = formatDocumentWorker;
function formatSelection(start, end, sourceFile, rulesProvider, options) {
+ return formatSelectionWorker(start, end, sourceFile, rulesProvider, ts.toEditorSettings(options));
+ }
+ formatting.formatSelection = formatSelection;
+ function formatSelectionWorker(start, end, sourceFile, rulesProvider, options) {
var span = {
pos: ts.getLineStartPositionForPosition(start, sourceFile),
end: end
};
return formatSpan(span, sourceFile, options, rulesProvider, 1);
}
- formatting.formatSelection = formatSelection;
+ formatting.formatSelectionWorker = formatSelectionWorker;
function formatOutermostParent(position, expectedLastToken, sourceFile, options, rulesProvider, requestKind) {
var parent = findOutermostParent(position, expectedLastToken, sourceFile);
if (!parent) {
@@ -46888,7 +46911,7 @@ var ts;
if (!ruleProvider) {
ruleProvider = new ts.formatting.RulesProvider();
}
- ruleProvider.ensureUpToDate(options);
+ ruleProvider.ensureUpToDateWorker(options);
return ruleProvider;
}
function synchronizeHostData() {
@@ -50857,24 +50880,24 @@ var ts;
function getFormattingEditsForRange(fileName, start, end, optionsOrSettings) {
var settings = toEditorSettings(optionsOrSettings);
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
- return ts.formatting.formatSelection(start, end, sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatSelectionWorker(start, end, sourceFile, getRuleProvider(settings), settings);
}
function getFormattingEditsForDocument(fileName, optionsOrSettings) {
var settings = toEditorSettings(optionsOrSettings);
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
- return ts.formatting.formatDocument(sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatDocumentWorker(sourceFile, getRuleProvider(settings), settings);
}
function getFormattingEditsAfterKeystroke(fileName, position, key, optionsOrSettings) {
var settings = toEditorSettings(optionsOrSettings);
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
if (key === "}") {
- return ts.formatting.formatOnClosingCurly(position, sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatOnClosingCurlyWorker(position, sourceFile, getRuleProvider(settings), settings);
}
else if (key === ";") {
- return ts.formatting.formatOnSemicolon(position, sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatOnSemicolonWorker(position, sourceFile, getRuleProvider(settings), settings);
}
else if (key === "\n") {
- return ts.formatting.formatOnEnter(position, sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatOnEnterWorker(position, sourceFile, getRuleProvider(settings), settings);
}
return [];
}
diff --git a/lib/typescript.js b/lib/typescript.js
index 2fa3e8a..7c73600 100644
--- a/lib/typescript.js
+++ b/lib/typescript.js
@@ -44687,7 +44687,7 @@ var ts;
var ts;
(function (ts) {
/** The version of the TypeScript compiler release */
- ts.version = "2.0.6";
+ ts.version = "2.0.7";
var emptyArray = [];
function findConfigFile(searchPath, fileExists, configName) {
if (configName === void 0) { configName = "tsconfig.json"; }
@@ -51874,6 +51874,9 @@ var ts;
return this.rulesMap;
};
RulesProvider.prototype.ensureUpToDate = function (options) {
+ this.ensureUpToDateWorker(ts.toEditorSettings(options));
+ };
+ RulesProvider.prototype.ensureUpToDateWorker = function (options) {
if (!this.options || !ts.compareDataObjects(this.options, options)) {
var activeRules = this.createActiveRules(options);
var rulesMap = formatting.RulesMap.create(activeRules);
@@ -51981,6 +51984,10 @@ var ts;
Constants[Constants["Unknown"] = -1] = "Unknown";
})(Constants || (Constants = {}));
function formatOnEnter(position, sourceFile, rulesProvider, options) {
+ return formatOnEnterWorker(position, sourceFile, rulesProvider, ts.toEditorSettings(options));
+ }
+ formatting.formatOnEnter = formatOnEnter;
+ function formatOnEnterWorker(position, sourceFile, rulesProvider, options) {
var line = sourceFile.getLineAndCharacterOfPosition(position).line;
if (line === 0) {
return [];
@@ -52008,24 +52015,40 @@ var ts;
};
return formatSpan(span, sourceFile, options, rulesProvider, 2 /* FormatOnEnter */);
}
- formatting.formatOnEnter = formatOnEnter;
+ formatting.formatOnEnterWorker = formatOnEnterWorker;
function formatOnSemicolon(position, sourceFile, rulesProvider, options) {
- return formatOutermostParent(position, 23 /* SemicolonToken */, sourceFile, options, rulesProvider, 3 /* FormatOnSemicolon */);
+ return formatOnSemicolonWorker(position, sourceFile, rulesProvider, ts.toEditorSettings(options));
}
formatting.formatOnSemicolon = formatOnSemicolon;
+ function formatOnSemicolonWorker(position, sourceFile, rulesProvider, options) {
+ return formatOutermostParent(position, 23 /* SemicolonToken */, sourceFile, options, rulesProvider, 3 /* FormatOnSemicolon */);
+ }
+ formatting.formatOnSemicolonWorker = formatOnSemicolonWorker;
function formatOnClosingCurly(position, sourceFile, rulesProvider, options) {
- return formatOutermostParent(position, 16 /* CloseBraceToken */, sourceFile, options, rulesProvider, 4 /* FormatOnClosingCurlyBrace */);
+ return formatOnClosingCurlyWorker(position, sourceFile, rulesProvider, ts.toEditorSettings(options));
}
formatting.formatOnClosingCurly = formatOnClosingCurly;
+ function formatOnClosingCurlyWorker(position, sourceFile, rulesProvider, options) {
+ return formatOutermostParent(position, 16 /* CloseBraceToken */, sourceFile, options, rulesProvider, 4 /* FormatOnClosingCurlyBrace */);
+ }
+ formatting.formatOnClosingCurlyWorker = formatOnClosingCurlyWorker;
function formatDocument(sourceFile, rulesProvider, options) {
+ return formatDocumentWorker(sourceFile, rulesProvider, ts.toEditorSettings(options));
+ }
+ formatting.formatDocument = formatDocument;
+ function formatDocumentWorker(sourceFile, rulesProvider, options) {
var span = {
pos: 0,
end: sourceFile.text.length
};
return formatSpan(span, sourceFile, options, rulesProvider, 0 /* FormatDocument */);
}
- formatting.formatDocument = formatDocument;
+ formatting.formatDocumentWorker = formatDocumentWorker;
function formatSelection(start, end, sourceFile, rulesProvider, options) {
+ return formatSelectionWorker(start, end, sourceFile, rulesProvider, ts.toEditorSettings(options));
+ }
+ formatting.formatSelection = formatSelection;
+ function formatSelectionWorker(start, end, sourceFile, rulesProvider, options) {
// format from the beginning of the line
var span = {
pos: ts.getLineStartPositionForPosition(start, sourceFile),
@@ -52033,7 +52056,7 @@ var ts;
};
return formatSpan(span, sourceFile, options, rulesProvider, 1 /* FormatSelection */);
}
- formatting.formatSelection = formatSelection;
+ formatting.formatSelectionWorker = formatSelectionWorker;
function formatOutermostParent(position, expectedLastToken, sourceFile, options, rulesProvider, requestKind) {
var parent = findOutermostParent(position, expectedLastToken, sourceFile);
if (!parent) {
@@ -55451,7 +55474,7 @@ var ts;
if (!ruleProvider) {
ruleProvider = new ts.formatting.RulesProvider();
}
- ruleProvider.ensureUpToDate(options);
+ ruleProvider.ensureUpToDateWorker(options);
return ruleProvider;
}
function synchronizeHostData() {
@@ -60083,24 +60106,24 @@ var ts;
function getFormattingEditsForRange(fileName, start, end, optionsOrSettings) {
var settings = toEditorSettings(optionsOrSettings);
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
- return ts.formatting.formatSelection(start, end, sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatSelectionWorker(start, end, sourceFile, getRuleProvider(settings), settings);
}
function getFormattingEditsForDocument(fileName, optionsOrSettings) {
var settings = toEditorSettings(optionsOrSettings);
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
- return ts.formatting.formatDocument(sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatDocumentWorker(sourceFile, getRuleProvider(settings), settings);
}
function getFormattingEditsAfterKeystroke(fileName, position, key, optionsOrSettings) {
var settings = toEditorSettings(optionsOrSettings);
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
if (key === "}") {
- return ts.formatting.formatOnClosingCurly(position, sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatOnClosingCurlyWorker(position, sourceFile, getRuleProvider(settings), settings);
}
else if (key === ";") {
- return ts.formatting.formatOnSemicolon(position, sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatOnSemicolonWorker(position, sourceFile, getRuleProvider(settings), settings);
}
else if (key === "\n") {
- return ts.formatting.formatOnEnter(position, sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatOnEnterWorker(position, sourceFile, getRuleProvider(settings), settings);
}
return [];
}
diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js
index 2fa3e8a..7c73600 100644
--- a/lib/typescriptServices.js
+++ b/lib/typescriptServices.js
@@ -44687,7 +44687,7 @@ var ts;
var ts;
(function (ts) {
/** The version of the TypeScript compiler release */
- ts.version = "2.0.6";
+ ts.version = "2.0.7";
var emptyArray = [];
function findConfigFile(searchPath, fileExists, configName) {
if (configName === void 0) { configName = "tsconfig.json"; }
@@ -51874,6 +51874,9 @@ var ts;
return this.rulesMap;
};
RulesProvider.prototype.ensureUpToDate = function (options) {
+ this.ensureUpToDateWorker(ts.toEditorSettings(options));
+ };
+ RulesProvider.prototype.ensureUpToDateWorker = function (options) {
if (!this.options || !ts.compareDataObjects(this.options, options)) {
var activeRules = this.createActiveRules(options);
var rulesMap = formatting.RulesMap.create(activeRules);
@@ -51981,6 +51984,10 @@ var ts;
Constants[Constants["Unknown"] = -1] = "Unknown";
})(Constants || (Constants = {}));
function formatOnEnter(position, sourceFile, rulesProvider, options) {
+ return formatOnEnterWorker(position, sourceFile, rulesProvider, ts.toEditorSettings(options));
+ }
+ formatting.formatOnEnter = formatOnEnter;
+ function formatOnEnterWorker(position, sourceFile, rulesProvider, options) {
var line = sourceFile.getLineAndCharacterOfPosition(position).line;
if (line === 0) {
return [];
@@ -52008,24 +52015,40 @@ var ts;
};
return formatSpan(span, sourceFile, options, rulesProvider, 2 /* FormatOnEnter */);
}
- formatting.formatOnEnter = formatOnEnter;
+ formatting.formatOnEnterWorker = formatOnEnterWorker;
function formatOnSemicolon(position, sourceFile, rulesProvider, options) {
- return formatOutermostParent(position, 23 /* SemicolonToken */, sourceFile, options, rulesProvider, 3 /* FormatOnSemicolon */);
+ return formatOnSemicolonWorker(position, sourceFile, rulesProvider, ts.toEditorSettings(options));
}
formatting.formatOnSemicolon = formatOnSemicolon;
+ function formatOnSemicolonWorker(position, sourceFile, rulesProvider, options) {
+ return formatOutermostParent(position, 23 /* SemicolonToken */, sourceFile, options, rulesProvider, 3 /* FormatOnSemicolon */);
+ }
+ formatting.formatOnSemicolonWorker = formatOnSemicolonWorker;
function formatOnClosingCurly(position, sourceFile, rulesProvider, options) {
- return formatOutermostParent(position, 16 /* CloseBraceToken */, sourceFile, options, rulesProvider, 4 /* FormatOnClosingCurlyBrace */);
+ return formatOnClosingCurlyWorker(position, sourceFile, rulesProvider, ts.toEditorSettings(options));
}
formatting.formatOnClosingCurly = formatOnClosingCurly;
+ function formatOnClosingCurlyWorker(position, sourceFile, rulesProvider, options) {
+ return formatOutermostParent(position, 16 /* CloseBraceToken */, sourceFile, options, rulesProvider, 4 /* FormatOnClosingCurlyBrace */);
+ }
+ formatting.formatOnClosingCurlyWorker = formatOnClosingCurlyWorker;
function formatDocument(sourceFile, rulesProvider, options) {
+ return formatDocumentWorker(sourceFile, rulesProvider, ts.toEditorSettings(options));
+ }
+ formatting.formatDocument = formatDocument;
+ function formatDocumentWorker(sourceFile, rulesProvider, options) {
var span = {
pos: 0,
end: sourceFile.text.length
};
return formatSpan(span, sourceFile, options, rulesProvider, 0 /* FormatDocument */);
}
- formatting.formatDocument = formatDocument;
+ formatting.formatDocumentWorker = formatDocumentWorker;
function formatSelection(start, end, sourceFile, rulesProvider, options) {
+ return formatSelectionWorker(start, end, sourceFile, rulesProvider, ts.toEditorSettings(options));
+ }
+ formatting.formatSelection = formatSelection;
+ function formatSelectionWorker(start, end, sourceFile, rulesProvider, options) {
// format from the beginning of the line
var span = {
pos: ts.getLineStartPositionForPosition(start, sourceFile),
@@ -52033,7 +52056,7 @@ var ts;
};
return formatSpan(span, sourceFile, options, rulesProvider, 1 /* FormatSelection */);
}
- formatting.formatSelection = formatSelection;
+ formatting.formatSelectionWorker = formatSelectionWorker;
function formatOutermostParent(position, expectedLastToken, sourceFile, options, rulesProvider, requestKind) {
var parent = findOutermostParent(position, expectedLastToken, sourceFile);
if (!parent) {
@@ -55451,7 +55474,7 @@ var ts;
if (!ruleProvider) {
ruleProvider = new ts.formatting.RulesProvider();
}
- ruleProvider.ensureUpToDate(options);
+ ruleProvider.ensureUpToDateWorker(options);
return ruleProvider;
}
function synchronizeHostData() {
@@ -60083,24 +60106,24 @@ var ts;
function getFormattingEditsForRange(fileName, start, end, optionsOrSettings) {
var settings = toEditorSettings(optionsOrSettings);
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
- return ts.formatting.formatSelection(start, end, sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatSelectionWorker(start, end, sourceFile, getRuleProvider(settings), settings);
}
function getFormattingEditsForDocument(fileName, optionsOrSettings) {
var settings = toEditorSettings(optionsOrSettings);
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
- return ts.formatting.formatDocument(sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatDocumentWorker(sourceFile, getRuleProvider(settings), settings);
}
function getFormattingEditsAfterKeystroke(fileName, position, key, optionsOrSettings) {
var settings = toEditorSettings(optionsOrSettings);
var sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
if (key === "}") {
- return ts.formatting.formatOnClosingCurly(position, sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatOnClosingCurlyWorker(position, sourceFile, getRuleProvider(settings), settings);
}
else if (key === ";") {
- return ts.formatting.formatOnSemicolon(position, sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatOnSemicolonWorker(position, sourceFile, getRuleProvider(settings), settings);
}
else if (key === "\n") {
- return ts.formatting.formatOnEnter(position, sourceFile, getRuleProvider(settings), settings);
+ return ts.formatting.formatOnEnterWorker(position, sourceFile, getRuleProvider(settings), settings);
}
return [];
}
diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js
index 94e6f80..3fcd60a 100644
--- a/lib/typingsInstaller.js
+++ b/lib/typingsInstaller.js
@@ -5733,11 +5733,10 @@ 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, log) {
if (log === void 0) { log = nullLog; }
+ this.installTypingHost = installTypingHost;
this.globalCachePath = globalCachePath;
this.safeListPath = safeListPath;
this.throttleLimit = throttleLimit;
@@ -5752,10 +5751,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);
};
@@ -5854,7 +5851,7 @@ var ts;
}
this.knownCachesSet[cacheLocation] = true;
};
- TypingsInstaller.prototype.filterTypings = function (typingsToInstall) {
+ TypingsInstaller.prototype.filterAndMapToScopedName = function (typingsToInstall) {
if (typingsToInstall.length === 0) {
return typingsToInstall;
}
@@ -5866,7 +5863,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;
@@ -5893,42 +5897,48 @@ var ts;
}
return result;
};
+ TypingsInstaller.prototype.ensurePackageDirectoryExists = function (directory) {
+ var npmConfigPath = ts.combinePaths(directory, "package.json");
+ if (this.log.isEnabled()) {
+ this.log.writeLine("Npm config file: " + npmConfigPath);
+ }
+ if (!this.installTypingHost.fileExists(npmConfigPath)) {
+ if (this.log.isEnabled()) {
+ this.log.writeLine("Npm config file: '" + npmConfigPath + "' is missing, creating new one...");
+ }
+ this.ensureDirectoryExists(directory, this.installTypingHost);
+ this.installTypingHost.writeFile(npmConfigPath, "{}");
+ }
+ };
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) {
+ 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;
}
- var npmConfigPath = ts.combinePaths(cachePath, "package.json");
- if (this.log.isEnabled()) {
- this.log.writeLine("Npm config file: " + npmConfigPath);
- }
- if (!this.installTypingHost.fileExists(npmConfigPath)) {
- if (this.log.isEnabled()) {
- this.log.writeLine("Npm config file: '" + npmConfigPath + "' is missing, creating new one...");
+ this.ensurePackageDirectoryExists(cachePath);
+ var requestId = this.installRunCount;
+ this.installRunCount++;
+ this.installTypingsAsync(requestId, scopedTypings, cachePath, function (ok) {
+ if (!ok) {
+ return;
}
- this.ensureDirectoryExists(cachePath, 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));
+ _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;
@@ -5941,49 +5951,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)) {
@@ -6025,8 +5995,8 @@ var ts;
kind: "set"
};
};
- 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 () {
@@ -6034,7 +6004,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();
@@ -6079,21 +6049,55 @@ 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) {
- _super.call(this, globalTypingsCacheLocation, ts.toPath("typingSafeList.json", __dirname, ts.createGetCanonicalFileName(ts.sys.useCaseSensitiveFileNames)), throttleLimit, log);
- this.installTypingHost = ts.sys;
+ _super.call(this, ts.sys, globalTypingsCacheLocation, ts.toPath("typingSafeList.json", __dirname, ts.createGetCanonicalFileName(ts.sys.useCaseSensitiveFileNames)), throttleLimit, log);
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);
+ 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":
@@ -6113,54 +6117,19 @@ 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));
@@ -6186,7 +6155,7 @@ var ts;
process.exit(0);
});
var installer = new NodeTypingsInstaller(globalTypingsCacheLocation, 5, log);
- installer.init();
+ installer.listen();
})(typingsInstaller = server.typingsInstaller || (server.typingsInstaller = {}));
})(server = ts.server || (ts.server = {}));
})(ts || (ts = {}));
diff --git a/package.json b/package.json
index d495971..a5792ee 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
"name": "typescript",
"author": "Microsoft Corp.",
"homepage": "http://typescriptlang.org/",
- "version": "2.0.6",
+ "version": "2.0.7",
"license": "Apache-2.0",
"description": "TypeScript is a language for application scale JavaScript development",
"keywords": [
diff --git a/src/compiler/program.ts b/src/compiler/program.ts
index 1b42a4a..904577c 100644
--- a/src/compiler/program.ts
+++ b/src/compiler/program.ts
@@ -5,7 +5,7 @@
namespace ts {
/** The version of the TypeScript compiler release */
- export const version = "2.0.6";
+ export const version = "2.0.7";
const emptyArray: any[] = [];
diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts
index f389375..be161c4 100644
--- a/src/harness/unittests/tsserverProjectSystem.ts
+++ b/src/harness/unittests/tsserverProjectSystem.ts
@@ -17,7 +17,6 @@ namespace ts.projectSystem {
};
export interface PostExecAction {
- readonly requestKind: TI.RequestKind;
readonly success: boolean;
readonly callback: TI.RequestCompletedAction;
}
@@ -50,9 +49,13 @@ namespace ts.projectSystem {
export class TestTypingsInstaller extends TI.TypingsInstaller implements server.ITypingsInstaller {
protected projectService: server.ProjectService;
- constructor(readonly globalTypingsCacheLocation: string, throttleLimit: number, readonly installTypingHost: server.ServerHost, log?: TI.Log) {
- super(globalTypingsCacheLocation, safeList.path, throttleLimit, log);
- this.init();
+ constructor(
+ readonly globalTypingsCacheLocation: string,
+ throttleLimit: number,
+ installTypingHost: server.ServerHost,
+ readonly typesRegistry = createMap<void>(),
+ log?: TI.Log) {
+ super(installTypingHost, globalTypingsCacheLocation, safeList.path, throttleLimit, log);
}
safeFileList = safeList.path;
@@ -66,9 +69,8 @@ namespace ts.projectSystem {
}
}
- checkPendingCommands(expected: TI.RequestKind[]) {
- assert.equal(this.postExecActions.length, expected.length, `Expected ${expected.length} post install actions`);
- this.postExecActions.forEach((act, i) => assert.equal(act.requestKind, expected[i], "Unexpected post install action"));
+ checkPendingCommands(expectedCount: number) {
+ assert.equal(this.postExecActions.length, expectedCount, `Expected ${expectedCount} post install actions`);
}
onProjectClosed(p: server.Project) {
@@ -82,15 +84,8 @@ namespace ts.projectSystem {
return this.installTypingHost;
}
- executeRequest(requestKind: TI.RequestKind, requestId: number, args: string[], cwd: string, cb: TI.RequestCompletedAction): void {
- switch (requestKind) {
- case TI.NpmViewRequest:
- case TI.NpmInstallRequest:
- break;
- default:
- assert.isTrue(false, `request ${requestKind} is not supported`);
- }
- this.addPostExecAction(requestKind, "success", cb);
+ installWorker(requestId: number, args: string[], cwd: string, cb: TI.RequestCompletedAction): void {
+ this.addPostExecAction("success", cb);
}
sendResponse(response: server.SetTypings | server.InvalidateCachedTypings) {
@@ -102,12 +97,11 @@ namespace ts.projectSystem {
this.install(request);
}
- addPostExecAction(requestKind: TI.RequestKind, stdout: string | string[], cb: TI.RequestCompletedAction) {
+ addPostExecAction(stdout: string | string[], cb: TI.RequestCompletedAction) {
const out = typeof stdout === "string" ? stdout : createNpmPackageJsonString(stdout);
const action: PostExecAction = {
success: !!out,
- callback: cb,
- requestKind
+ callback: cb
};
this.postExecActions.push(action);
}
diff --git a/src/harness/unittests/typingsInstaller.ts b/src/harness/unittests/typingsInstaller.ts
index fd949ce..dec8a9c 100644
--- a/src/harness/unittests/typingsInstaller.ts
+++ b/src/harness/unittests/typingsInstaller.ts
@@ -8,6 +8,15 @@ namespace ts.projectSystem {
interface InstallerParams {
globalTypingsCacheLocation?: string;
throttleLimit?: number;
+ typesRegistry?: Map<void>;
+ }
+
+ function createTypesRegistry(...list: string[]): Map<void> {
+ const map = createMap<void>();
+ for (const l of list) {
+ map[l] = undefined;
+ }
+ return map;
}
class Installer extends TestTypingsInstaller {
@@ -16,35 +25,24 @@ namespace ts.projectSystem {
(p && p.globalTypingsCacheLocation) || "/a/data",
(p && p.throttleLimit) || 5,
host,
+ (p && p.typesRegistry),
log);
}
- installAll(expectedView: typeof TI.NpmViewRequest[], expectedInstall: typeof TI.NpmInstallRequest[]) {
- this.checkPendingCommands(expectedView);
- this.executePendingCommands();
- this.checkPendingCommands(expectedInstall);
+ installAll(expectedCount: number) {
+ this.checkPendingCommands(expectedCount);
this.executePendingCommands();
}
}
describe("typingsInstaller", () => {
- function executeCommand(self: Installer, host: TestServerHost, installedTypings: string[], typingFiles: FileOrFolder[], requestKind: TI.RequestKind, cb: TI.RequestCompletedAction): void {
- switch (requestKind) {
- case TI.NpmInstallRequest:
- self.addPostExecAction(requestKind, installedTypings, success => {
- for (const file of typingFiles) {
- host.createFileOrFolder(file, /*createParentDirectory*/ true);
- }
- cb(success);
- });
- break;
- case TI.NpmViewRequest:
- self.addPostExecAction(requestKind, installedTypings, cb);
- break;
- default:
- assert.isTrue(false, `unexpected request kind ${requestKind}`);
- break;
- }
+ function executeCommand(self: Installer, host: TestServerHost, installedTypings: string[], typingFiles: FileOrFolder[], cb: TI.RequestCompletedAction): void {
+ self.addPostExecAction(installedTypings, success => {
+ for (const file of typingFiles) {
+ host.createFileOrFolder(file, /*createParentDirectory*/ true);
+ }
+ cb(success);
+ });
}
it("configured projects (typings installed) 1", () => {
const file1 = {
@@ -79,12 +77,12 @@ namespace ts.projectSystem {
const host = createServerHost([file1, tsconfig, packageJson]);
const installer = new (class extends Installer {
constructor() {
- super(host);
+ super(host, { typesRegistry: createTypesRegistry("jquery") });
}
- executeRequest(requestKind: TI.RequestKind, requestId: number, args: string[], cwd: string, cb: server.typingsInstaller.RequestCompletedAction) {
+ installWorker(requestId: number, args: string[], cwd: string, cb: server.typingsInstaller.RequestCompletedAction) {
const installedTypings = ["@types/jquery"];
const typingFiles = [jquery];
- executeCommand(this, host, installedTypings, typingFiles, requestKind, cb);
+ executeCommand(this, host, installedTypings, typingFiles, cb);
}
})();
@@ -95,7 +93,7 @@ namespace ts.projectSystem {
const p = projectService.configuredProjects[0];
checkProjectActualFiles(p, [file1.path]);
- installer.installAll([TI.NpmViewRequest], [TI.NpmInstallRequest]);
+ installer.installAll(/*expectedCount*/ 1);
checkNumberOfProjects(projectService, { configuredProjects: 1 });
checkProjectActualFiles(p, [file1.path, jquery.path]);
@@ -123,12 +121,12 @@ namespace ts.projectSystem {
const host = createServerHost([file1, packageJson]);
const installer = new (class extends Installer {
constructor() {
- super(host);
+ super(host, { typesRegistry: createTypesRegistry("jquery") });
}
- executeRequest(requestKind: TI.RequestKind, requestId: number, args: string[], cwd: string, cb: server.typingsInstaller.RequestCompletedAction) {
+ installWorker(requestId: number, args: string[], cwd: string, cb: server.typingsInstaller.RequestCompletedAction) {
const installedTypings = ["@types/jquery"];
const typingFiles = [jquery];
- executeCommand(this, host, installedTypings, typingFiles, requestKind, cb);
+ executeCommand(this, host, installedTypings, typingFiles, cb);
}
})();
@@ -139,7 +137,7 @@ namespace ts.projectSystem {
const p = projectService.inferredProjects[0];
checkProjectActualFiles(p, [file1.path]);
- installer.installAll([TI.NpmViewRequest], [TI.NpmInstallRequest]);
+ installer.installAll(/*expectedCount*/ 1);
checkNumberOfProjects(projectService, { inferredProjects: 1 });
checkProjectActualFiles(p, [file1.path, jquery.path]);
@@ -167,7 +165,7 @@ namespace ts.projectSystem {
options: {},
rootFiles: [toExternalFile(file1.path)]
});
- installer.checkPendingCommands([]);
+ installer.checkPendingCommands(/*expectedCount*/ 0);
// by default auto discovery will kick in if project contain only .js/.d.ts files
// in this case project contain only ts files - no auto discovery
projectService.checkNumberOfProjects({ externalProjects: 1 });
@@ -181,7 +179,7 @@ namespace ts.projectSystem {
const host = createServerHost([file1]);
const installer = new (class extends Installer {
constructor() {
- super(host);
+ super(host, { typesRegistry: createTypesRegistry("jquery") });
}
enqueueInstallTypingsRequest() {
assert(false, "auto discovery should not be enabled");
@@ -196,7 +194,7 @@ namespace ts.projectSystem {
rootFiles: [toExternalFile(file1.path)],
typingOptions: { include: ["jquery"] }
});
- installer.checkPendingCommands([]);
+ installer.checkPendingCommands(/*expectedCount*/ 0);
// by default auto discovery will kick in if project contain only .js/.d.ts files
// in this case project contain only ts files - no auto discovery even if typing options is set
projectService.checkNumberOfProjects({ externalProjects: 1 });
@@ -215,16 +213,16 @@ namespace ts.projectSystem {
let enqueueIsCalled = false;
const installer = new (class extends Installer {
constructor() {
- super(host);
+ super(host, { typesRegistry: createTypesRegistry("jquery") });
}
enqueueInstallTypingsRequest(project: server.Project, typingOptions: TypingOptions) {
enqueueIsCalled = true;
super.enqueueInstallTypingsRequest(project, typingOptions);
}
- executeRequest(requestKind: TI.RequestKind, requestId: number, args: string[], cwd: string, cb: TI.RequestCompletedAction): void {
- const installedTypings = ["@types/jquery"];
+ installWorker(requestId: number, args: string[], cwd: string, cb: TI.RequestCompletedAction): void {
+ const installedTypings = ["@types/node"];
const typingFiles = [jquery];
- executeCommand(this, host, installedTypings, typingFiles, requestKind, cb);
+ executeCommand(this, host, installedTypings, typingFiles, cb);
}
})();
@@ -234,11 +232,11 @@ namespace ts.projectSystem {
projectFileName,
options: {},
rootFiles: [toExternalFile(file1.path)],
- typingOptions: { enableAutoDiscovery: true, include: ["node"] }
+ typingOptions: { enableAutoDiscovery: true, include: ["jquery"] }
});
assert.isTrue(enqueueIsCalled, "expected enqueueIsCalled to be true");
- installer.installAll([TI.NpmViewRequest], [TI.NpmInstallRequest]);
+ installer.installAll(/*expectedCount*/ 1);
// autoDiscovery is set in typing options - use it even if project contains only .ts files
projectService.checkNumberOfProjects({ externalProjects: 1 });
@@ -273,12 +271,12 @@ namespace ts.projectSystem {
const host = createServerHost([file1, file2, file3]);
const installer = new (class extends Installer {
constructor() {
- super(host);
+ super(host, { typesRegistry: createTypesRegistry("lodash", "react") });
}
- executeRequest(requestKind: TI.RequestKind, requestId: number, args: string[], cwd: string, cb: TI.RequestCompletedAction): void {
+ installWorker(requestId: number, args: string[], cwd: string, cb: TI.RequestCompletedAction): void {
const installedTypings = ["@types/lodash", "@types/react"];
const typingFiles = [lodash, react];
- executeCommand(this, host, installedTypings, typingFiles, requestKind, cb);
+ executeCommand(this, host, installedTypings, typingFiles, cb);
}
})();
@@ -295,7 +293,7 @@ namespace ts.projectSystem {
projectService.checkNumberOfProjects({ externalProjects: 1 });
checkProjectActualFiles(p, [file1.path, file2.path, file3.path]);
- installer.installAll([TI.NpmViewRequest, TI.NpmViewRequest], [TI.NpmInstallRequest], );
+ installer.installAll(/*expectedCount*/ 1);
checkNumberOfProjects(projectService, { externalProjects: 1 });
checkProjectActualFiles(p, [file1.path, file2.path, file3.path, lodash.path, react.path]);
@@ -317,16 +315,16 @@ namespace ts.projectSystem {
let enqueueIsCalled = false;
const installer = new (class extends Installer {
constructor() {
- super(host);
+ super(host, { typesRegistry: createTypesRegistry("jquery") });
}
enqueueInstallTypingsRequest(project: server.Project, typingOptions: TypingOptions) {
enqueueIsCalled = true;
super.enqueueInstallTypingsRequest(project, typingOptions);
}
- executeRequest(requestKind: TI.RequestKind, requestId: number, args: string[], cwd: string, cb: TI.RequestCompletedAction): void {
+ installWorker(requestId: number, args: string[], cwd: string, cb: TI.RequestCompletedAction): void {
const installedTypings: string[] = [];
const typingFiles: FileOrFolder[] = [];
- executeCommand(this, host, installedTypings, typingFiles, requestKind, cb);
+ executeCommand(this, host, installedTypings, typingFiles, cb);
}
})();
@@ -343,7 +341,7 @@ namespace ts.projectSystem {
projectService.checkNumberOfProjects({ externalProjects: 1 });
checkProjectActualFiles(p, [file1.path, file2.path]);
- installer.checkPendingCommands([]);
+ installer.checkPendingCommands(/*expectedCount*/ 0);
checkNumberOfProjects(projectService, { externalProjects: 1 });
checkProjectActualFiles(p, [file1.path, file2.path]);
@@ -396,12 +394,12 @@ namespace ts.projectSystem {
const host = createServerHost([file1, file2, file3, packageJson]);
const installer = new (class extends Installer {
constructor() {
- super(host);
+ super(host, { typesRegistry: createTypesRegistry("jquery", "commander", "moment", "express") });
}
- executeRequest(requestKind: TI.RequestKind, requestId: number, args: string[], cwd: string, cb: TI.RequestCompletedAction): void {
+ installWorker(requestId: number, args: string[], cwd: string, cb: TI.RequestCompletedAction): void {
const installedTypings = ["@types/commander", "@types/express", "@types/jquery", "@types/moment"];
const typingFiles = [commander, express, jquery, moment];
- executeCommand(this, host, installedTypings, typingFiles, requestKind, cb);
+ executeCommand(this, host, installedTypings, typingFiles, cb);
}
})();
@@ -418,10 +416,7 @@ namespace ts.projectSystem {
projectService.checkNumberOfProjects({ externalProjects: 1 });
checkProjectActualFiles(p, [file1.path, file2.path, file3.path]);
- installer.installAll(
- [TI.NpmViewRequest, TI.NpmViewRequest, TI.NpmViewRequest, TI.NpmViewRequest],
- [TI.NpmInstallRequest]
- );
+ installer.installAll(/*expectedCount*/ 1);
checkNumberOfProjects(projectService, { externalProjects: 1 });
checkProjectActualFiles(p, [file1.path, file2.path, file3.path, commander.path, express.path, jquery.path, moment.path]);
@@ -475,11 +470,11 @@ namespace ts.projectSystem {
const host = createServerHost([lodashJs, commanderJs, file3, packageJson]);
const installer = new (class extends Installer {
constructor() {
- super(host, { throttleLimit: 3 });
+ super(host, { throttleLimit: 3, typesRegistry: createTypesRegistry("commander", "express", "jquery", "moment", "lodash") });
}
- executeRequest(requestKind: TI.RequestKind, requestId: number, args: string[], cwd: string, cb: TI.RequestCompletedAction): void {
+ installWorker(requestId: number, args: string[], cwd: string, cb: TI.RequestCompletedAction): void {
const installedTypings = ["@types/commander", "@types/express", "@types/jquery", "@types/moment", "@types/lodash"];
- executeCommand(this, host, installedTypings, typingFiles, requestKind, cb);
+ executeCommand(this, host, installedTypings, typingFiles, cb);
}
})();
@@ -495,18 +490,7 @@ namespace ts.projectSystem {
const p = projectService.externalProjects[0];
projectService.checkNumberOfProjects({ externalProjects: 1 });
checkProjectActualFiles(p, [lodashJs.path, commanderJs.path, file3.path]);
- // expected 3 view requests in the queue
- installer.checkPendingCommands([TI.NpmViewRequest, TI.NpmViewRequest, TI.NpmViewRequest]);
- assert.equal(installer.pendingRunRequests.length, 2, "expected 2 pending requests");
-
- // push view requests
- installer.executePendingCommands();
- // expected 2 remaining view requests in the queue
- installer.checkPendingCommands([TI.NpmViewRequest, TI.NpmViewRequest]);
- // push view requests
- installer.executePendingCommands();
- // expected one install request
- installer.checkPendingCommands([TI.NpmInstallRequest]);
+ installer.checkPendingCommands(/*expectedCount*/ 1);
installer.executePendingCommands();
// expected all typings file to exist
for (const f of typingFiles) {
@@ -565,22 +549,17 @@ namespace ts.projectSystem {
const host = createServerHost([lodashJs, commanderJs, file3]);
const installer = new (class extends Installer {
constructor() {
- super(host, { throttleLimit: 3 });
+ super(host, { throttleLimit: 1, typesRegistry: createTypesRegistry("commander", "jquery", "lodash", "cordova", "gulp", "grunt") });
}
- executeRequest(requestKind: TI.RequestKind, requestId: number, args: string[], cwd: string, cb: TI.RequestCompletedAction): void {
- if (requestKind === TI.NpmInstallRequest) {
- let typingFiles: (FileOrFolder & { typings: string })[] = [];
- if (args.indexOf("@types/commander") >= 0) {
- typingFiles = [commander, jquery, lodash, cordova];
- }
- else {
- typingFiles = [grunt, gulp];
- }
- executeCommand(this, host, typingFiles.map(f => f.typings), typingFiles, requestKind, cb);
+ installWorker(requestId: number, args: string[], cwd: string, cb: TI.RequestCompletedAction): void {
+ let typingFiles: (FileOrFolder & { typings: string })[] = [];
+ if (args.indexOf("@types/commander") >= 0) {
+ typingFiles = [commander, jquery, lodash, cordova];
}
else {
- executeCommand(this, host, [], [], requestKind, cb);
+ typingFiles = [grunt, gulp];
}
+ executeCommand(this, host, typingFiles.map(f => f.typings), typingFiles, cb);
}
})();
@@ -594,8 +573,8 @@ namespace ts.projectSystem {
typingOptions: { include: ["jquery", "cordova"] }
});
- installer.checkPendingCommands([TI.NpmViewRequest, TI.NpmViewRequest, TI.NpmViewRequest]);
- assert.equal(installer.pendingRunRequests.length, 1, "expect one throttled request");
+ installer.checkPendingCommands(/*expectedCount*/ 1);
+ assert.equal(installer.pendingRunRequests.length, 0, "expect no throttled requests");
// Create project #2 with 2 typings
const projectFileName2 = "/a/app/test2.csproj";
@@ -605,7 +584,7 @@ namespace ts.projectSystem {
rootFiles: [toExternalFile(file3.path)],
typingOptions: { include: ["grunt", "gulp"] }
});
- assert.equal(installer.pendingRunRequests.length, 3, "expect three throttled request");
+ assert.equal(installer.pendingRunRequests.length, 1, "expect one throttled request");
const p1 = projectService.externalProjects[0];
const p2 = projectService.externalProjects[1];
@@ -613,16 +592,12 @@ namespace ts.projectSystem {
checkProjectActualFiles(p1, [lodashJs.path, commanderJs.path, file3.path]);
checkProjectActualFiles(p2, [file3.path]);
-
installer.executePendingCommands();
- // expected one view request from the first project and two - from the second one
- installer.checkPendingCommands([TI.NpmViewRequest, TI.NpmViewRequest, TI.NpmViewRequest]);
- assert.equal(installer.pendingRunRequests.length, 0, "expected no throttled requests");
- installer.executePendingCommands();
+ // expected one install request from the second project
+ installer.checkPendingCommands(/*expectedCount*/ 1);
+ assert.equal(installer.pendingRunRequests.length, 0, "expected no throttled requests");
- // should be two install requests from both projects
- installer.checkPendingCommands([TI.NpmInstallRequest, TI.NpmInstallRequest]);
installer.executePendingCommands();
checkProjectActualFiles(p1, [lodashJs.path, commanderJs.path, file3.path, commander.path, jquery.path, lodash.path, cordova.path]);
@@ -653,12 +628,12 @@ namespace ts.projectSystem {
const host = createServerHost([app, jsconfig, jquery, jqueryPackage]);
const installer = new (class extends Installer {
constructor() {
- super(host, { globalTypingsCacheLocation: "/tmp" });
+ super(host, { globalTypingsCacheLocation: "/tmp", typesRegistry: createTypesRegistry("jquery") });
}
- executeRequest(requestKind: TI.RequestKind, requestId: number, args: string[], cwd: string, cb: server.typingsInstaller.RequestCompletedAction) {
+ installWorker(requestId: number, args: string[], cwd: string, cb: server.typingsInstaller.RequestCompletedAction) {
const installedTypings = ["@types/jquery"];
const typingFiles = [jqueryDTS];
- executeCommand(this, host, installedTypings, typingFiles, requestKind, cb);
+ executeCommand(this, host, installedTypings, typingFiles, cb);
}
})();
@@ -669,7 +644,7 @@ namespace ts.projectSystem {
const p = projectService.configuredProjects[0];
checkProjectActualFiles(p, [app.path]);
- installer.installAll([TI.NpmViewRequest], [TI.NpmInstallRequest]);
+ installer.installAll(/*expectedCount*/ 1);
checkNumberOfProjects(projectService, { configuredProjects: 1 });
checkProjectActualFiles(p, [app.path, jqueryDTS.path]);
@@ -699,12 +674,12 @@ namespace ts.projectSystem {
const host = createServerHost([app, jsconfig, bowerJson]);
const installer = new (class extends Installer {
constructor() {
- super(host, { globalTypingsCacheLocation: "/tmp" });
+ super(host, { globalTypingsCacheLocation: "/tmp", typesRegistry: createTypesRegistry("jquery") });
}
- executeRequest(requestKind: TI.RequestKind, requestId: number, args: string[], cwd: string, cb: server.typingsInstaller.RequestCompletedAction) {
+ installWorker(requestId: number, args: string[], cwd: string, cb: server.typingsInstaller.RequestCompletedAction) {
const installedTypings = ["@types/jquery"];
const typingFiles = [jqueryDTS];
- executeCommand(this, host, installedTypings, typingFiles, requestKind, cb);
+ executeCommand(this, host, installedTypings, typingFiles, cb);
}
})();
@@ -715,7 +690,7 @@ namespace ts.projectSystem {
const p = projectService.configuredProjects[0];
checkProjectActualFiles(p, [app.path]);
- installer.installAll([TI.NpmViewRequest], [TI.NpmInstallRequest]);
+ installer.installAll(/*expectedCount*/ 1);
checkNumberOfProjects(projectService, { configuredProjects: 1 });
checkProjectActualFiles(p, [app.path, jqueryDTS.path]);
@@ -742,23 +717,23 @@ namespace ts.projectSystem {
const host = createServerHost([f, brokenPackageJson]);
const installer = new (class extends Installer {
constructor() {
- super(host, { globalTypingsCacheLocation: cachePath });
+ super(host, { globalTypingsCacheLocation: cachePath, typesRegistry: createTypesRegistry("commander") });
}
- executeRequest(requestKind: TI.RequestKind, requestId: number, args: string[], cwd: string, cb: server.typingsInstaller.RequestCompletedAction) {
+ installWorker(requestId: number, args: string[], cwd: string, cb: server.typingsInstaller.RequestCompletedAction) {
const installedTypings = ["@types/commander"];
const typingFiles = [commander];
- executeCommand(this, host, installedTypings, typingFiles, requestKind, cb);
+ executeCommand(this, host, installedTypings, typingFiles, cb);
}
})();
const service = createProjectService(host, { typingsInstaller: installer });
service.openClientFile(f.path);
- installer.checkPendingCommands([]);
+ installer.checkPendingCommands(/*expectedCount*/ 0);
host.reloadFS([f, fixedPackageJson]);
host.triggerFileWatcherCallback(fixedPackageJson.path, /*removed*/ false);
- // expected one view and one install request
- installer.installAll([TI.NpmViewRequest], [TI.NpmInstallRequest]);
+ // expected install request
+ installer.installAll(/*expectedCount*/ 1);
service.checkNumberOfProjects({ inferredProjects: 1 });
checkProjectActualFiles(service.inferredProjects[0], [f.path, commander.path]);
@@ -809,14 +784,14 @@ namespace ts.projectSystem {
constructor() {
super(host, { globalTypingsCacheLocation: "/tmp" }, { isEnabled: () => true, writeLine: msg => messages.push(msg) });
}
- executeRequest(requestKind: TI.RequestKind, requestId: number, args: string[], cwd: string, cb: server.typingsInstaller.RequestCompletedAction) {
+ installWorker(requestId: number, args: string[], cwd: string, cb: server.typingsInstaller.RequestCompletedAction) {
assert(false, "runCommand should not be invoked");
}
})();
const projectService = createProjectService(host, { typingsInstaller: installer });
projectService.openClientFile(f1.path);
- installer.checkPendingCommands([]);
+ installer.checkPendingCommands(/*expectedCount*/ 0);
assert.isTrue(messages.indexOf("Package name '; say ‘Hello from TypeScript!’ #' contains non URI safe characters") > 0, "should find package with invalid name");
});
});
diff --git a/src/server/typingsInstaller/nodeTypingsInstaller.ts b/src/server/typingsInstaller/nodeTypingsInstaller.ts
index 0449356..cce894d 100644
--- a/src/server/typingsInstaller/nodeTypingsInstaller.ts
+++ b/src/server/typingsInstaller/nodeTypingsInstaller.ts
@@ -33,28 +33,51 @@ namespace ts.server.typingsInstaller {
}
}
- type HttpGet = {
- (url: string, callback: (response: HttpResponse) => void): NodeJS.EventEmitter;
+ interface TypesRegistryFile {
+ entries: MapLike<void>;
}
- interface HttpResponse extends NodeJS.ReadableStream {
- statusCode: number;
- statusMessage: string;
- destroy(): void;
+ function loadTypesRegistryFile(typesRegistryFilePath: string, host: InstallTypingHost, log: Log): Map<void> {
+ if (!host.fileExists(typesRegistryFilePath)) {
+ if (log.isEnabled()) {
+ log.writeLine(`Types registry file '${typesRegistryFilePath}' does not exist`);
+ }
+ return createMap<void>();
+ }
+ try {
+ const content = <TypesRegistryFile>JSON.parse(host.readFile(typesRegistryFilePath));
+ return createMap<void>(content.entries);
+ }
+ catch (e) {
+ if (log.isEnabled()) {
+ log.writeLine(`Error when loading types registry file '${typesRegistryFilePath}': ${(<Error>e).message}, ${(<Error>e).stack}`);
+ }
+ return createMap<void>();
+ }
}
+ const TypesRegistryPackageName = "types-registry";
+ function getTypesRegistryFileLocation(globalTypingsCacheLocation: string): string {
+ return combinePaths(normalizeSlashes(globalTypingsCacheLocation), `node_modules/${TypesRegistryPackageName}/index.json`);
+ }
+
+
type Exec = {
(command: string, options: { cwd: string }, callback?: (error: Error, stdout: string, stderr: string) => void): any
}
+ type ExecSync = {
+ (command: string, options: { cwd: string, stdio: "ignore" }): any
+ }
+
export class NodeTypingsInstaller extends TypingsInstaller {
private readonly exec: Exec;
- private readonly httpGet: HttpGet;
private readonly npmPath: string;
- readonly installTypingHost: InstallTypingHost = sys;
+ readonly typesRegistry: Map<void>;
constructor(globalTypingsCacheLocation: string, throttleLimit: number, log: Log) {
super(
+ sys,
globalTypingsCacheLocation,
toPath("typingSafeList.json", __dirname, createGetCanonicalFileName(sys.useCaseSensitiveFileNames)),
throttleLimit,
@@ -63,12 +86,27 @@ namespace ts.server.typingsInstaller {
this.log.writeLine(`Process id: ${process.pid}`);
}
this.npmPath = getNPMLocation(process.argv[0]);
- this.exec = require("child_process").exec;
- this.httpGet = require("http").get;
+ let execSync: ExecSync;
+ ({ exec: this.exec, execSync } = require("child_process"));
+
+ 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: ${(<Error>e).message}`);
+ }
+ }
+
+ this.typesRegistry = loadTypesRegistryFile(getTypesRegistryFileLocation(globalTypingsCacheLocation), this.installTypingHost, this.log);
}
- init() {
- super.init();
+ listen() {
process.on("message", (req: DiscoverTypings | CloseProject) => {
switch (req.kind) {
case "discover":
@@ -90,54 +128,19 @@ namespace ts.server.typingsInstaller {
}
}
- protected executeRequest(requestKind: RequestKind, requestId: number, args: string[], cwd: string, onRequestCompleted: RequestCompletedAction): void {
+ protected installWorker(requestId: number, args: string[], cwd: string, onRequestCompleted: RequestCompletedAction): void {
if (this.log.isEnabled()) {
- this.log.writeLine(`#${requestId} executing ${requestKind}, arguments'${JSON.stringify(args)}'.`);
- }
- switch (requestKind) {
- case NpmViewRequest: {
- // const command = `${self.npmPath} view @types/${typing} --silent name`;
- // use http request to global npm registry instead of running npm view
- Debug.assert(args.length === 1);
- const url = `http://registry.npmjs.org/@types%2f${args[0]}`;
- const start = Date.now();
- this.httpGet(url, response => {
- let ok = false;
- if (this.log.isEnabled()) {
- this.log.writeLine(`${requestKind} #${requestId} request to ${url}:: status code ${response.statusCode}, status message '${response.statusMessage}', took ${Date.now() - start} ms`);
- }
- switch (response.statusCode) {
- case 200: // OK
- case 301: // redirect - Moved - treat package as present
- case 302: // redirect - Found - treat package as present
- ok = true;
- break;
- }
- response.destroy();
- onRequestCompleted(ok);
- }).on("error", (err: Error) => {
- if (this.log.isEnabled()) {
- this.log.writeLine(`${requestKind} #${requestId} query to npm registry failed with error ${err.message}, stack ${err.stack}`);
- }
- onRequestCompleted(/*success*/ false);
- });
- }
- break;
- case NpmInstallRequest: {
- const command = `${this.npmPath} install ${args.join(" ")} --save-dev`;
- const start = Date.now();
- this.exec(command, { cwd }, (err, stdout, stderr) => {
- if (this.log.isEnabled()) {
- this.log.writeLine(`${requestKind} #${requestId} took: ${Date.now() - start} ms${sys.newLine}stdout: ${stdout}${sys.newLine}stderr: ${stderr}`);
- }
- // treat any output on stdout as success
- onRequestCompleted(!!stdout);
- });
- }
- break;
- default:
- Debug.assert(false, `Unknown request kind ${requestKind}`);
+ this.log.writeLine(`#${requestId} with arguments'${JSON.stringify(args)}'.`);
}
+ const command = `${this.npmPath} install ${args.join(" ")} --save-dev`;
+ const start = Date.now();
+ this.exec(command, { cwd }, (err, stdout, stderr) => {
+ if (this.log.isEnabled()) {
+ this.log.writeLine(`npm install #${requestId} took: ${Date.now() - start} ms${sys.newLine}stdout: ${stdout}${sys.newLine}stderr: ${stderr}`);
+ }
+ // treat any output on stdout as success
+ onRequestCompleted(!!stdout);
+ });
}
}
@@ -163,5 +166,5 @@ namespace ts.server.typingsInstaller {
process.exit(0);
});
const installer = new NodeTypingsInstaller(globalTypingsCacheLocation, /*throttleLimit*/5, log);
- installer.init();
+ installer.listen();
}
\ No newline at end of file
diff --git a/src/server/typingsInstaller/typingsInstaller.ts b/src/server/typingsInstaller/typingsInstaller.ts
index 029a861..9cb1e00 100644
--- a/src/server/typingsInstaller/typingsInstaller.ts
+++ b/src/server/typingsInstaller/typingsInstaller.ts
@@ -60,14 +60,8 @@ namespace ts.server.typingsInstaller {
return PackageNameValidationResult.Ok;
}
- export const NpmViewRequest: "npm view" = "npm view";
- export const NpmInstallRequest: "npm install" = "npm install";
-
- export type RequestKind = typeof NpmViewRequest | typeof NpmInstallRequest;
-
export type RequestCompletedAction = (success: boolean) => void;
type PendingRequest = {
- requestKind: RequestKind;
requestId: number;
args: string[];
cwd: string;
@@ -84,9 +78,10 @@ namespace ts.server.typingsInstaller {
private installRunCount = 1;
private inFlightRequestCount = 0;
- abstract readonly installTypingHost: InstallTypingHost;
+ abstract readonly typesRegistry: Map<void>;
constructor(
+ readonly installTypingHost: InstallTypingHost,
readonly globalCachePath: string,
readonly safeListPath: Path,
readonly throttleLimit: number,
@@ -94,9 +89,6 @@ namespace ts.server.typingsInstaller {
if (this.log.isEnabled()) {
this.log.writeLine(`Global cache location '${globalCachePath}', safe file path '${safeListPath}'`);
}
- }
-
- init() {
this.processCacheLocation(this.globalCachePath);
}
@@ -221,7 +213,7 @@ namespace ts.server.typingsInstaller {
this.knownCachesSet[cacheLocation] = true;
}
- private filterTypings(typingsToInstall: string[]) {
+ private filterAndMapToScopedName(typingsToInstall: string[]) {
if (typingsToInstall.length === 0) {
return typingsToInstall;
}
@@ -232,7 +224,14 @@ namespace ts.server.typingsInstaller {
}
const 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 {
// add typing name to missing set so we won't process it again
@@ -261,43 +260,51 @@ namespace ts.server.typingsInstaller {
return result;
}
- private installTypings(req: DiscoverTypings, cachePath: string, currentlyCachedTypings: string[], typingsToInstall: string[]) {
+ protected ensurePackageDirectoryExists(directory: string) {
+ const npmConfigPath = combinePaths(directory, "package.json");
if (this.log.isEnabled()) {
- this.log.writeLine(`Installing typings ${JSON.stringify(typingsToInstall)}`);
+ this.log.writeLine(`Npm config file: ${npmConfigPath}`);
}
- typingsToInstall = this.filterTypings(typingsToInstall);
- if (typingsToInstall.length === 0) {
+ if (!this.installTypingHost.fileExists(npmConfigPath)) {
if (this.log.isEnabled()) {
- this.log.writeLine(`All typings are known to be missing or invalid - no need to go any further`);
+ this.log.writeLine(`Npm config file: '${npmConfigPath}' is missing, creating new one...`);
}
- return;
+ this.ensureDirectoryExists(directory, this.installTypingHost);
+ this.installTypingHost.writeFile(npmConfigPath, "{}");
}
+ }
- const npmConfigPath = combinePaths(cachePath, "package.json");
+ private installTypings(req: DiscoverTypings, cachePath: string, currentlyCachedTypings: string[], typingsToInstall: string[]) {
if (this.log.isEnabled()) {
- this.log.writeLine(`Npm config file: ${npmConfigPath}`);
+ this.log.writeLine(`Installing typings ${JSON.stringify(typingsToInstall)}`);
}
- if (!this.installTypingHost.fileExists(npmConfigPath)) {
+ const scopedTypings = this.filterAndMapToScopedName(typingsToInstall);
+ if (scopedTypings.length === 0) {
if (this.log.isEnabled()) {
- this.log.writeLine(`Npm config file: '${npmConfigPath}' is missing, creating new one...`);
+ this.log.writeLine(`All typings are known to be missing or invalid - no need to go any further`);
}
- this.ensureDirectoryExists(cachePath, this.installTypingHost);
- this.installTypingHost.writeFile(npmConfigPath, "{}");
+ return;
}
- this.runInstall(cachePath, typingsToInstall, installedTypings => {
+ this.ensurePackageDirectoryExists(cachePath);
+
+ const requestId = this.installRunCount;
+ this.installRunCount++;
+
+ this.installTypingsAsync(requestId, scopedTypings, cachePath, ok => {
+ if (!ok) {
+ return;
+ }
// TODO: watch project directory
if (this.log.isEnabled()) {
- this.log.writeLine(`Requested to install typings ${JSON.stringify(typingsToInstall)}, installed typings ${JSON.stringify(installedTypings)}`);
+ this.log.writeLine(`Requested to install typings ${JSON.stringify(scopedTypings)}, installed typings ${JSON.stringify(scopedTypings)}`);
}
- const installedPackages: Map<true> = createMap<true>();
const installedTypingFiles: string[] = [];
- for (const t of installedTypings) {
+ for (const t of scopedTypings) {
const packageName = getBaseFileName(t);
if (!packageName) {
continue;
}
- installedPackages[packageName] = true;
const typingFile = typingToFileName(cachePath, packageName, this.installTypingHost);
if (!typingFile) {
continue;
@@ -310,53 +317,11 @@ namespace ts.server.typingsInstaller {
if (this.log.isEnabled()) {
this.log.writeLine(`Installed typing files ${JSON.stringify(installedTypingFiles)}`);
}
- for (const toInstall of typingsToInstall) {
- 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)));
});
}
- private runInstall(cachePath: string, typingsToInstall: string[], postInstallAction: (installedTypings: string[]) => void): void {
- const requestId = this.installRunCount;
-
- this.installRunCount++;
- let execInstallCmdCount = 0;
- const filteredTypings: string[] = [];
- for (const typing of typingsToInstall) {
- filterExistingTypings(this, typing);
- }
-
- function filterExistingTypings(self: TypingsInstaller, typing: string) {
- self.execAsync(NpmViewRequest, requestId, [typing], cachePath, ok => {
- if (ok) {
- filteredTypings.push(typing);
- }
- execInstallCmdCount++;
- if (execInstallCmdCount === typingsToInstall.length) {
- installFilteredTypings(self, filteredTypings);
- }
- });
- }
-
- function installFilteredTypings(self: TypingsInstaller, filteredTypings: string[]) {
- if (filteredTypings.length === 0) {
- postInstallAction([]);
- return;
- }
- const scopedTypings = filteredTypings.map(t => "@types/" + t);
- self.execAsync(NpmInstallRequest, requestId, scopedTypings, cachePath, ok => {
- postInstallAction(ok ? scopedTypings : []);
- });
- }
- }
-
private ensureDirectoryExists(directory: string, host: InstallTypingHost): void {
const directoryName = getDirectoryPath(directory);
if (!host.directoryExists(directoryName)) {
@@ -402,8 +367,8 @@ namespace ts.server.typingsInstaller {
};
}
- private execAsync(requestKind: RequestKind, requestId: number, args: string[], cwd: string, onRequestCompleted: RequestCompletedAction): void {
- this.pendingRunRequests.unshift({ requestKind, requestId, args, cwd, onRequestCompleted });
+ private installTypingsAsync(requestId: number, args: string[], cwd: string, onRequestCompleted: RequestCompletedAction): void {
+ this.pendingRunRequests.unshift({ requestId, args, cwd, onRequestCompleted });
this.executeWithThrottling();
}
@@ -411,7 +376,7 @@ namespace ts.server.typingsInstaller {
while (this.inFlightRequestCount < this.throttleLimit && this.pendingRunRequests.length) {
this.inFlightRequestCount++;
const request = this.pendingRunRequests.pop();
- this.executeRequest(request.requestKind, request.requestId, request.args, request.cwd, ok => {
+ this.installWorker(request.requestId, request.args, request.cwd, ok => {
this.inFlightRequestCount--;
request.onRequestCompleted(ok);
this.executeWithThrottling();
@@ -419,7 +384,7 @@ namespace ts.server.typingsInstaller {
}
}
- protected abstract executeRequest(requestKind: RequestKind, requestId: number, args: string[], cwd: string, onRequestCompleted: RequestCompletedAction): void;
+ protected abstract installWorker(requestId: number, args: string[], cwd: string, onRequestCompleted: RequestCompletedAction): void;
protected abstract sendResponse(response: SetTypings | InvalidateCachedTypings): void;
}
}
\ No newline at end of file
diff --git a/src/services/formatting/formatting.ts b/src/services/formatting/formatting.ts
index b998d57..76ec744 100644
--- a/src/services/formatting/formatting.ts
+++ b/src/services/formatting/formatting.ts
@@ -67,7 +67,11 @@ namespace ts.formatting {
delta: number;
}
- export function formatOnEnter(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[] {
+ export function formatOnEnter(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings | FormatCodeOptions): TextChange[] {
+ return formatOnEnterWorker(position, sourceFile, rulesProvider, toEditorSettings(options));
+ }
+
+ export function formatOnEnterWorker(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[] {
const line = sourceFile.getLineAndCharacterOfPosition(position).line;
if (line === 0) {
return [];
@@ -96,15 +100,27 @@ namespace ts.formatting {
return formatSpan(span, sourceFile, options, rulesProvider, FormattingRequestKind.FormatOnEnter);
}
- export function formatOnSemicolon(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[] {
+ export function formatOnSemicolon(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings | FormatCodeOptions): TextChange[] {
+ return formatOnSemicolonWorker(position, sourceFile, rulesProvider, toEditorSettings(options));
+ }
+
+ export function formatOnSemicolonWorker(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[] {
return formatOutermostParent(position, SyntaxKind.SemicolonToken, sourceFile, options, rulesProvider, FormattingRequestKind.FormatOnSemicolon);
}
- export function formatOnClosingCurly(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[] {
+ export function formatOnClosingCurly(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings | FormatCodeOptions): TextChange[] {
+ return formatOnClosingCurlyWorker(position, sourceFile, rulesProvider, toEditorSettings(options));
+ }
+
+ export function formatOnClosingCurlyWorker(position: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[] {
return formatOutermostParent(position, SyntaxKind.CloseBraceToken, sourceFile, options, rulesProvider, FormattingRequestKind.FormatOnClosingCurlyBrace);
}
- export function formatDocument(sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[] {
+ export function formatDocument(sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings | FormatCodeOptions): TextChange[] {
+ return formatDocumentWorker(sourceFile, rulesProvider, toEditorSettings(options));
+ }
+
+ export function formatDocumentWorker(sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[] {
const span = {
pos: 0,
end: sourceFile.text.length
@@ -112,7 +128,11 @@ namespace ts.formatting {
return formatSpan(span, sourceFile, options, rulesProvider, FormattingRequestKind.FormatDocument);
}
- export function formatSelection(start: number, end: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[] {
+ export function formatSelection(start: number, end: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings | FormatCodeOptions): TextChange[] {
+ return formatSelectionWorker(start, end, sourceFile, rulesProvider, toEditorSettings(options));
+ }
+
+ export function formatSelectionWorker(start: number, end: number, sourceFile: SourceFile, rulesProvider: RulesProvider, options: FormatCodeSettings): TextChange[] {
// format from the beginning of the line
const span = {
pos: getLineStartPositionForPosition(start, sourceFile),
diff --git a/src/services/formatting/rulesProvider.ts b/src/services/formatting/rulesProvider.ts
index eff951e..e06c39e 100644
--- a/src/services/formatting/rulesProvider.ts
+++ b/src/services/formatting/rulesProvider.ts
@@ -24,7 +24,11 @@ namespace ts.formatting {
return this.rulesMap;
}
- public ensureUpToDate(options: ts.FormatCodeSettings) {
+ public ensureUpToDate(options: ts.FormatCodeSettings | ts.FormatCodeOptions) {
+ this.ensureUpToDateWorker(toEditorSettings(options));
+ }
+
+ public ensureUpToDateWorker(options: ts.FormatCodeSettings) {
if (!this.options || !ts.compareDataObjects(this.options, options)) {
const activeRules = this.createActiveRules(options);
const rulesMap = RulesMap.create(activeRules);
diff --git a/src/services/services.ts b/src/services/services.ts
index cc4d762..6eedf36 100644
--- a/src/services/services.ts
+++ b/src/services/services.ts
@@ -3164,7 +3164,7 @@ namespace ts {
ruleProvider = new formatting.RulesProvider();
}
- ruleProvider.ensureUpToDate(options);
+ ruleProvider.ensureUpToDateWorker(options);
return ruleProvider;
}
@@ -8509,13 +8509,13 @@ namespace ts {
function getFormattingEditsForRange(fileName: string, start: number, end: number, optionsOrSettings: FormatCodeOptions | FormatCodeSettings): TextChange[] {
const settings = toEditorSettings(optionsOrSettings);
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
- return formatting.formatSelection(start, end, sourceFile, getRuleProvider(settings), settings);
+ return formatting.formatSelectionWorker(start, end, sourceFile, getRuleProvider(settings), settings);
}
function getFormattingEditsForDocument(fileName: string, optionsOrSettings: FormatCodeOptions | FormatCodeSettings): TextChange[] {
const settings = toEditorSettings(optionsOrSettings);
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
- return formatting.formatDocument(sourceFile, getRuleProvider(settings), settings);
+ return formatting.formatDocumentWorker(sourceFile, getRuleProvider(settings), settings);
}
function getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, optionsOrSettings: FormatCodeOptions | FormatCodeSettings): TextChange[] {
@@ -8523,13 +8523,13 @@ namespace ts {
const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName);
if (key === "}") {
- return formatting.formatOnClosingCurly(position, sourceFile, getRuleProvider(settings), settings);
+ return formatting.formatOnClosingCurlyWorker(position, sourceFile, getRuleProvider(settings), settings);
}
else if (key === ";") {
- return formatting.formatOnSemicolon(position, sourceFile, getRuleProvider(settings), settings);
+ return formatting.formatOnSemicolonWorker(position, sourceFile, getRuleProvider(settings), settings);
}
else if (key === "\n") {
- return formatting.formatOnEnter(position, sourceFile, getRuleProvider(settings), settings);
+ return formatting.formatOnEnterWorker(position, sourceFile, getRuleProvider(settings), settings);
}
return [];
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-typescript.git
More information about the Pkg-javascript-commits
mailing list