Skip to content

Commit 4c24744

Browse files
authored
ports #12237, #12258 and #12259 into master (#12274)
* treat failures to resolve module name as missing packages (#12237) * added extra check to prevent multiple installation of the same typing, added version field to telemetry event (#12258) * added extra check to prevent multiple installation of the same typing, added version field to telemetry event * use ts.version * switch to execSync to ensure that no install orders are interleaved (#12259) * Make sure version is public * Update file with version string for nightly release
1 parent d96a0ad commit 4c24744

File tree

9 files changed

+57
-40
lines changed

9 files changed

+57
-40
lines changed

Gulpfile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ for (const i in libraryTargets) {
177177
const configureNightlyJs = path.join(scriptsDirectory, "configureNightly.js");
178178
const configureNightlyTs = path.join(scriptsDirectory, "configureNightly.ts");
179179
const packageJson = "package.json";
180-
const programTs = path.join(compilerDirectory, "program.ts");
180+
const versionFile = path.join(compilerDirectory, "core.ts");
181181

182182
function needsUpdate(source: string | string[], dest: string | string[]): boolean {
183183
if (typeof source === "string" && typeof dest === "string") {
@@ -285,7 +285,7 @@ gulp.task(configureNightlyJs, false, [], () => {
285285

286286
// Nightly management tasks
287287
gulp.task("configure-nightly", "Runs scripts/configureNightly.ts to prepare a build for nightly publishing", [configureNightlyJs], (done) => {
288-
exec(host, [configureNightlyJs, packageJson, programTs], done, done);
288+
exec(host, [configureNightlyJs, packageJson, versionFile], done, done);
289289
});
290290
gulp.task("publish-nightly", "Runs `npm publish --tag next` to create a new nightly build on npm", ["LKG"], () => {
291291
return runSequence("clean", "useDebugMode", "runtests", (done) => {

Jakefile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ task("generate-diagnostics", [diagnosticInfoMapTs]);
593593
var configureNightlyJs = path.join(scriptsDirectory, "configureNightly.js");
594594
var configureNightlyTs = path.join(scriptsDirectory, "configureNightly.ts");
595595
var packageJson = "package.json";
596-
var programTs = path.join(compilerDirectory, "program.ts");
596+
var versionFile = path.join(compilerDirectory, "core.ts");
597597

598598
file(configureNightlyTs);
599599

@@ -609,7 +609,7 @@ task("setDebugMode", function () {
609609
});
610610

611611
task("configure-nightly", [configureNightlyJs], function () {
612-
var cmd = host + " " + configureNightlyJs + " " + packageJson + " " + programTs;
612+
var cmd = host + " " + configureNightlyJs + " " + packageJson + " " + versionFile;
613613
console.log(cmd);
614614
exec(cmd);
615615
}, { async: true });

src/compiler/core.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
/// <reference path="types.ts"/>
22
/// <reference path="performance.ts" />
33

4+
namespace ts {
5+
/** The version of the TypeScript compiler release */
6+
export const version = "2.2.0";
7+
}
8+
49
/* @internal */
510
namespace ts {
611
/**

src/compiler/program.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
/// <reference path="core.ts" />
44

55
namespace ts {
6-
/** The version of the TypeScript compiler release */
7-
8-
export const version = "2.2.0";
9-
106
const emptyArray: any[] = [];
117

128
export function findConfigFile(searchPath: string, fileExists: (fileName: string) => boolean, configName = "tsconfig.json"): string {

src/server/protocol.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,6 +2106,11 @@ namespace ts.server.protocol {
21062106
* true if install request succeeded, otherwise - false
21072107
*/
21082108
installSuccess: boolean;
2109+
2110+
/**
2111+
* version of typings installer
2112+
*/
2113+
typingsInstallerVersion: string;
21092114
}
21102115

21112116
export interface NavBarResponse extends Response {

src/server/server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,8 @@ namespace ts.server {
300300
telemetryEventName: "typingsInstalled",
301301
payload: {
302302
installedPackages: response.packagesToInstall.join(","),
303-
installSuccess: response.installSuccess
303+
installSuccess: response.installSuccess,
304+
typingsInstallerVersion: response.typingsInstallerVersion
304305
}
305306
};
306307
const eventName: protocol.TelemetryEventName = "telemetry";

src/server/types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ declare namespace ts.server {
6969
readonly packagesToInstall: ReadonlyArray<string>;
7070
readonly kind: EventInstall;
7171
readonly installSuccess: boolean;
72+
readonly typingsInstallerVersion: string;
7273
}
7374

7475
export interface InstallTypingHost extends JsTyping.TypingResolutionHost {

src/server/typingsInstaller/nodeTypingsInstaller.ts

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,12 @@ namespace ts.server.typingsInstaller {
6161
return combinePaths(normalizeSlashes(globalTypingsCacheLocation), `node_modules/${TypesRegistryPackageName}/index.json`);
6262
}
6363

64-
65-
type Exec = {
66-
(command: string, options: { cwd: string }, callback?: (error: Error, stdout: string, stderr: string) => void): any
67-
};
68-
6964
type ExecSync = {
70-
(command: string, options: { cwd: string, stdio: "ignore" }): any
71-
};
65+
(command: string, options: { cwd: string, stdio?: "ignore" }): any
66+
}
7267

7368
export class NodeTypingsInstaller extends TypingsInstaller {
74-
private readonly exec: Exec;
69+
private readonly execSync: ExecSync;
7570
private readonly npmPath: string;
7671
readonly typesRegistry: Map<void>;
7772

@@ -87,16 +82,15 @@ namespace ts.server.typingsInstaller {
8782
this.log.writeLine(`Process id: ${process.pid}`);
8883
}
8984
this.npmPath = getNPMLocation(process.argv[0]);
90-
let execSync: ExecSync;
91-
({ exec: this.exec, execSync } = require("child_process"));
85+
({ execSync: this.execSync } = require("child_process"));
9286

9387
this.ensurePackageDirectoryExists(globalTypingsCacheLocation);
9488

9589
try {
9690
if (this.log.isEnabled()) {
9791
this.log.writeLine(`Updating ${TypesRegistryPackageName} npm package...`);
9892
}
99-
execSync(`${this.npmPath} install ${TypesRegistryPackageName}`, { cwd: globalTypingsCacheLocation, stdio: "ignore" });
93+
this.execSync(`${this.npmPath} install ${TypesRegistryPackageName}`, { cwd: globalTypingsCacheLocation, stdio: "ignore" });
10094
}
10195
catch (e) {
10296
if (this.log.isEnabled()) {
@@ -135,13 +129,21 @@ namespace ts.server.typingsInstaller {
135129
}
136130
const command = `${this.npmPath} install ${args.join(" ")} --save-dev`;
137131
const start = Date.now();
138-
this.exec(command, { cwd }, (err, stdout, stderr) => {
139-
if (this.log.isEnabled()) {
140-
this.log.writeLine(`npm install #${requestId} took: ${Date.now() - start} ms${sys.newLine}stdout: ${stdout}${sys.newLine}stderr: ${stderr}`);
141-
}
142-
// treat absence of error as success
143-
onRequestCompleted(!err);
144-
});
132+
let stdout: Buffer;
133+
let stderr: Buffer;
134+
let hasError = false;
135+
try {
136+
stdout = this.execSync(command, { cwd });
137+
}
138+
catch (e) {
139+
stdout = e.stdout;
140+
stderr = e.stderr;
141+
hasError = true;
142+
}
143+
if (this.log.isEnabled()) {
144+
this.log.writeLine(`npm install #${requestId} took: ${Date.now() - start} ms${sys.newLine}stdout: ${stdout && stdout.toString()}${sys.newLine}stderr: ${stderr && stderr.toString()}`);
145+
}
146+
onRequestCompleted(!hasError);
145147
}
146148
}
147149

src/server/typingsInstaller/typingsInstaller.ts

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,17 @@ namespace ts.server.typingsInstaller {
1919
writeLine: noop
2020
};
2121

22-
function typingToFileName(cachePath: string, packageName: string, installTypingHost: InstallTypingHost): string {
23-
const result = resolveModuleName(packageName, combinePaths(cachePath, "index.d.ts"), { moduleResolution: ModuleResolutionKind.NodeJs }, installTypingHost);
24-
return result.resolvedModule && result.resolvedModule.resolvedFileName;
22+
function typingToFileName(cachePath: string, packageName: string, installTypingHost: InstallTypingHost, log: Log): string {
23+
try {
24+
const result = resolveModuleName(packageName, combinePaths(cachePath, "index.d.ts"), { moduleResolution: ModuleResolutionKind.NodeJs }, installTypingHost);
25+
return result.resolvedModule && result.resolvedModule.resolvedFileName;
26+
}
27+
catch (e) {
28+
if (log.isEnabled()) {
29+
log.writeLine(`Failed to resolve ${packageName} in folder '${cachePath}': ${(<Error>e).message}`);
30+
}
31+
return undefined;
32+
}
2533
}
2634

2735
export enum PackageNameValidationResult {
@@ -192,8 +200,9 @@ namespace ts.server.typingsInstaller {
192200
if (!packageName) {
193201
continue;
194202
}
195-
const typingFile = typingToFileName(cacheLocation, packageName, this.installTypingHost);
203+
const typingFile = typingToFileName(cacheLocation, packageName, this.installTypingHost, this.log);
196204
if (!typingFile) {
205+
this.missingTypingsSet[packageName] = true;
197206
continue;
198207
}
199208
const existingTypingFile = this.packageNameToTypingLocation[packageName];
@@ -224,7 +233,7 @@ namespace ts.server.typingsInstaller {
224233
}
225234
const result: string[] = [];
226235
for (const typing of typingsToInstall) {
227-
if (this.missingTypingsSet[typing]) {
236+
if (this.missingTypingsSet[typing] || this.packageNameToTypingLocation[typing]) {
228237
continue;
229238
}
230239
const validationResult = validatePackageName(typing);
@@ -305,7 +314,8 @@ namespace ts.server.typingsInstaller {
305314
this.sendResponse(<TypingsInstallEvent>{
306315
kind: EventInstall,
307316
packagesToInstall: scopedTypings,
308-
installSuccess: ok
317+
installSuccess: ok,
318+
typingsInstallerVersion: ts.version // qualified explicitly to prevent occasional shadowing
309319
});
310320
}
311321

@@ -321,16 +331,13 @@ namespace ts.server.typingsInstaller {
321331

322332
// TODO: watch project directory
323333
if (this.log.isEnabled()) {
324-
this.log.writeLine(`Requested to install typings ${JSON.stringify(scopedTypings)}, installed typings ${JSON.stringify(scopedTypings)}`);
334+
this.log.writeLine(`Installed typings ${JSON.stringify(scopedTypings)}`);
325335
}
326336
const installedTypingFiles: string[] = [];
327-
for (const t of scopedTypings) {
328-
const packageName = getBaseFileName(t);
329-
if (!packageName) {
330-
continue;
331-
}
332-
const typingFile = typingToFileName(cachePath, packageName, this.installTypingHost);
337+
for (const packageName of filteredTypings) {
338+
const typingFile = typingToFileName(cachePath, packageName, this.installTypingHost, this.log);
333339
if (!typingFile) {
340+
this.missingTypingsSet[packageName] = true;
334341
continue;
335342
}
336343
if (!this.packageNameToTypingLocation[packageName]) {

0 commit comments

Comments
 (0)