Skip to content

Commit 6e8c44f

Browse files
authored
Ports #14566 to release-2.2 (#14571)
* use ES6 library when building tslint rules (#14474) * Merge pull request #14553 from Microsoft/fixBuildBreak Add --lib es6 to @types/node dependent targets * allow passing --logFile and --logVerbosity parameter to tsserver (#14566) * fix linter issues
1 parent f6b1738 commit 6e8c44f

File tree

10 files changed

+84
-43
lines changed

10 files changed

+84
-43
lines changed

Jakefile.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,14 @@ function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts
317317
if (opts.stripInternal) {
318318
options += " --stripInternal";
319319
}
320-
321-
options += " --target es5 --lib es5,scripthost --noUnusedLocals --noUnusedParameters";
320+
options += " --target es5";
321+
if (opts.lib) {
322+
options += " --lib " + opts.lib
323+
}
324+
else {
325+
options += " --lib es5,scripthost"
326+
}
327+
options += " --noUnusedLocals --noUnusedParameters";
322328

323329
var cmd = host + " " + compilerPath + " " + options + " ";
324330
cmd = cmd + sources.join(" ");
@@ -405,7 +411,7 @@ compileFile(buildProtocolJs,
405411
[buildProtocolTs],
406412
[],
407413
/*useBuiltCompiler*/ false,
408-
{noOutFile: true});
414+
{ noOutFile: true, lib: "es6" });
409415

410416
file(buildProtocolDts, [buildProtocolTs, buildProtocolJs, typescriptServicesDts], function() {
411417

@@ -567,16 +573,16 @@ compileFile(
567573
file(typescriptServicesDts, [servicesFile]);
568574

569575
var cancellationTokenFile = path.join(builtLocalDirectory, "cancellationToken.js");
570-
compileFile(cancellationTokenFile, cancellationTokenSources, [builtLocalDirectory].concat(cancellationTokenSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { outDir: builtLocalDirectory, noOutFile: true });
576+
compileFile(cancellationTokenFile, cancellationTokenSources, [builtLocalDirectory].concat(cancellationTokenSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], outDir: builtLocalDirectory, noOutFile: true, lib: "es6" });
571577

572578
var typingsInstallerFile = path.join(builtLocalDirectory, "typingsInstaller.js");
573-
compileFile(typingsInstallerFile, typingsInstallerSources, [builtLocalDirectory].concat(typingsInstallerSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { outDir: builtLocalDirectory, noOutFile: false });
579+
compileFile(typingsInstallerFile, typingsInstallerSources, [builtLocalDirectory].concat(typingsInstallerSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], outDir: builtLocalDirectory, noOutFile: false, lib: "es6,scripthost" });
574580

575581
var watchGuardFile = path.join(builtLocalDirectory, "watchGuard.js");
576-
compileFile(watchGuardFile, watchGuardSources, [builtLocalDirectory].concat(watchGuardSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { outDir: builtLocalDirectory, noOutFile: false });
582+
compileFile(watchGuardFile, watchGuardSources, [builtLocalDirectory].concat(watchGuardSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], outDir: builtLocalDirectory, noOutFile: false, lib: "es6" });
577583

578584
var serverFile = path.join(builtLocalDirectory, "tsserver.js");
579-
compileFile(serverFile, serverSources, [builtLocalDirectory, copyright, cancellationTokenFile, typingsInstallerFile, watchGuardFile].concat(serverSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], preserveConstEnums: true });
585+
compileFile(serverFile, serverSources, [builtLocalDirectory, copyright, cancellationTokenFile, typingsInstallerFile, watchGuardFile].concat(serverSources).concat(servicesSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], preserveConstEnums: true, lib: "es6,scripthost" });
580586
var tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js");
581587
var tsserverLibraryDefinitionFile = path.join(builtLocalDirectory, "tsserverlibrary.d.ts");
582588
compileFile(
@@ -700,7 +706,7 @@ compileFile(
700706
/*prereqs*/[builtLocalDirectory, tscFile].concat(libraryTargets).concat(servicesSources).concat(harnessSources),
701707
/*prefixes*/[],
702708
/*useBuiltCompiler:*/ true,
703-
/*opts*/ { inlineSourceMap: true, types: ["node", "mocha", "chai"] });
709+
/*opts*/ { inlineSourceMap: true, types: ["node", "mocha", "chai"], lib: "es6,scripthost" });
704710

705711
var internalTests = "internal/";
706712

@@ -1077,7 +1083,7 @@ desc("Compiles tslint rules to js");
10771083
task("build-rules", ["build-rules-start"].concat(tslintRulesOutFiles).concat(["build-rules-end"]));
10781084
tslintRulesFiles.forEach(function (ruleFile, i) {
10791085
compileFile(tslintRulesOutFiles[i], [ruleFile], [ruleFile], [], /*useBuiltCompiler*/ false,
1080-
{ noOutFile: true, generateDeclarations: false, outDir: path.join(builtLocalDirectory, "tslint") });
1086+
{ noOutFile: true, generateDeclarations: false, outDir: path.join(builtLocalDirectory, "tslint"), lib: "es6" });
10811087
});
10821088

10831089
desc("Emit the start of the build-rules fold");

scripts/parallel-lint.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var tslint = require("tslint");
22
var fs = require("fs");
3+
var path = require("path");
34

45
function getLinterOptions() {
56
return {
@@ -9,7 +10,7 @@ function getLinterOptions() {
910
};
1011
}
1112
function getLinterConfiguration() {
12-
return require("../tslint.json");
13+
return tslint.Configuration.loadConfigurationFromPath(path.join(__dirname, "../tslint.json"));
1314
}
1415

1516
function lintFileContents(options, configuration, path, contents) {

src/harness/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
"declaration": false,
77
"types": [
88
"node", "mocha", "chai"
9+
],
10+
"lib": [
11+
"es6",
12+
"scripthost"
913
]
1014
},
1115
"files": [

src/server/builder.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/// <reference path="..\compiler\commandLineParser.ts" />
22
/// <reference path="..\services\services.ts" />
33
/// <reference path="session.ts" />
4-
/// <reference types="node" />
54

65
namespace ts.server {
76

src/server/cancellationToken/tsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"module": "commonjs",
66
"types": [
77
"node"
8+
],
9+
"lib": [
10+
"es6"
811
]
912
},
1013
"files": [

src/server/server.ts

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ namespace ts.server {
131131
constructor(private readonly logFilename: string,
132132
private readonly traceToConsole: boolean,
133133
private readonly level: LogLevel) {
134+
if (this.logFilename) {
135+
try {
136+
this.fd = fs.openSync(this.logFilename, "w");
137+
}
138+
catch (e) {
139+
// swallow the error and keep logging disabled if file cannot be opened
140+
}
141+
}
134142
}
135143

136144
static padStringRight(str: string, padding: string) {
@@ -175,11 +183,6 @@ namespace ts.server {
175183
}
176184

177185
msg(s: string, type: Msg.Types = Msg.Err) {
178-
if (this.fd < 0) {
179-
if (this.logFilename) {
180-
this.fd = fs.openSync(this.logFilename, "w");
181-
}
182-
}
183186
if (this.fd >= 0 || this.traceToConsole) {
184187
s = s + "\n";
185188
const prefix = Logger.padStringRight(type + " " + this.seq.toString(), " ");
@@ -410,6 +413,9 @@ namespace ts.server {
410413
}
411414

412415
function parseLoggingEnvironmentString(logEnvStr: string): LogOptions {
416+
if (!logEnvStr) {
417+
return {};
418+
}
413419
const logEnv: LogOptions = { logToFile: true };
414420
const args = logEnvStr.split(" ");
415421
const len = args.length - 1;
@@ -422,8 +428,8 @@ namespace ts.server {
422428
logEnv.file = stripQuotes(value);
423429
break;
424430
case "-level":
425-
const level: LogLevel = (<any>LogLevel)[value];
426-
logEnv.detailLevel = typeof level === "number" ? level : LogLevel.normal;
431+
const level = getLogLevel(value);
432+
logEnv.detailLevel = level !== undefined ? level : LogLevel.normal;
427433
break;
428434
case "-traceToConsole":
429435
logEnv.traceToConsole = value.toLowerCase() === "true";
@@ -437,28 +443,32 @@ namespace ts.server {
437443
return logEnv;
438444
}
439445

440-
// TSS_LOG "{ level: "normal | verbose | terse", file?: string}"
441-
function createLoggerFromEnv() {
442-
let fileName: string = undefined;
443-
let detailLevel = LogLevel.normal;
444-
let traceToConsole = false;
445-
const logEnvStr = process.env["TSS_LOG"];
446-
if (logEnvStr) {
447-
const logEnv = parseLoggingEnvironmentString(logEnvStr);
448-
if (logEnv.logToFile) {
449-
if (logEnv.file) {
450-
fileName = logEnv.file;
451-
}
452-
else {
453-
fileName = __dirname + "/.log" + process.pid.toString();
446+
function getLogLevel(level: string) {
447+
if (level) {
448+
const l = level.toLowerCase();
449+
for (const name in LogLevel) {
450+
if (isNaN(+name) && l === name.toLowerCase()) {
451+
return <LogLevel><any>LogLevel[name];
454452
}
455453
}
456-
if (logEnv.detailLevel) {
457-
detailLevel = logEnv.detailLevel;
458-
}
459-
traceToConsole = logEnv.traceToConsole;
460454
}
461-
return new Logger(fileName, traceToConsole, detailLevel);
455+
return undefined;
456+
}
457+
458+
// TSS_LOG "{ level: "normal | verbose | terse", file?: string}"
459+
function createLogger() {
460+
const cmdLineLogFileName = findArgument("--logFile");
461+
const cmdLineVerbosity = getLogLevel(findArgument("--logVerbosity"));
462+
const envLogOptions = parseLoggingEnvironmentString(process.env["TSS_LOG"]);
463+
464+
const logFileName = cmdLineLogFileName
465+
? stripQuotes(cmdLineLogFileName)
466+
: envLogOptions.logToFile
467+
? envLogOptions.file || (__dirname + "/.log" + process.pid.toString())
468+
: undefined;
469+
470+
const logVerbosity = cmdLineVerbosity || envLogOptions.detailLevel;
471+
return new Logger(logFileName, envLogOptions.traceToConsole, logVerbosity)
462472
}
463473
// This places log file in the directory containing editorServices.js
464474
// TODO: check that this location is writable
@@ -555,7 +565,6 @@ namespace ts.server {
555565
// to increase the chunk size or decrease the interval
556566
// time dynamically to match the large reference set?
557567
const pollingWatchedFileSet = createPollingWatchedFileSet();
558-
const logger = createLoggerFromEnv();
559568

560569
const pending: Buffer[] = [];
561570
let canWrite = true;
@@ -607,6 +616,8 @@ namespace ts.server {
607616
return s.length > 2 && s.charCodeAt(0) === CharacterCodes.slash && s.charCodeAt(1) === CharacterCodes.slash;
608617
}
609618

619+
const logger = createLogger();
620+
610621
const sys = <ServerHost>ts.sys;
611622
// use watchGuard process on Windows when node version is 4 or later
612623
const useWatchGuard = process.platform === "win32" && getNodeMajorVersion() >= 4;

src/server/tsconfig.library.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"target": "es5",
1111
"noUnusedLocals": true,
1212
"noUnusedParameters": true,
13-
"declaration": true
13+
"declaration": true,
14+
"types": []
1415
},
1516
"files": [
1617
"editorServices.ts",

src/server/typingsInstaller/nodeTypingsInstaller.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,20 @@ namespace ts.server.typingsInstaller {
1313
} = require("path");
1414

1515
class FileLog implements Log {
16+
private logEnabled = true;
1617
constructor(private readonly logFile?: string) {
1718
}
1819

1920
isEnabled() {
20-
return this.logFile !== undefined;
21+
return this.logEnabled && this.logFile !== undefined;
2122
}
2223
writeLine(text: string) {
23-
fs.appendFileSync(this.logFile, text + sys.newLine);
24+
try {
25+
fs.appendFileSync(this.logFile, text + sys.newLine);
26+
}
27+
catch (e) {
28+
this.logEnabled = false;
29+
}
2430
}
2531
}
2632

src/server/typingsInstaller/tsconfig.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
"outFile": "../../../built/local/typingsInstaller.js",
66
"types": [
77
"node"
8+
],
9+
"lib": [
10+
"es6",
11+
"scripthost"
812
]
913
},
1014
"files": [

src/server/watchGuard/tsconfig.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
11
{
2-
"extends": "../../tsconfig-base",
2+
"extends": "../../tsconfig-base",
33
"compilerOptions": {
44
"removeComments": true,
5-
"outFile": "../../../built/local/watchGuard.js"
5+
"outFile": "../../../built/local/watchGuard.js",
6+
"types": [
7+
"node"
8+
],
9+
"lib": [
10+
"es6"
11+
]
612
},
713
"files": [
814
"watchGuard.ts"

0 commit comments

Comments
 (0)