Skip to content

Commit 5960877

Browse files
authored
Merge pull request #9628 from Microsoft/tsconfig-for-harness
Add tsconfig for harness and tsserverlibrary, remove external dtses
2 parents f19844f + cfe3aad commit 5960877

File tree

121 files changed

+251
-2373
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+251
-2373
lines changed

Gulpfile.ts

Lines changed: 34 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,9 @@ let host = cmdLineOptions["host"];
8585

8686
// Constants
8787
const compilerDirectory = "src/compiler/";
88-
const servicesDirectory = "src/services/";
89-
const serverDirectory = "src/server/";
9088
const harnessDirectory = "src/harness/";
9189
const libraryDirectory = "src/lib/";
9290
const scriptsDirectory = "scripts/";
93-
const unittestsDirectory = "tests/cases/unittests/";
9491
const docDirectory = "doc/";
9592

9693
const builtDirectory = "built/";
@@ -107,69 +104,6 @@ const nodeModulesPathPrefix = path.resolve("./node_modules/.bin/");
107104
const isWin = /^win/.test(process.platform);
108105
const mocha = path.join(nodeModulesPathPrefix, "mocha") + (isWin ? ".cmd" : "");
109106

110-
const compilerSources = require("./src/compiler/tsconfig.json").files.map((file) => path.join(compilerDirectory, file));
111-
112-
const servicesSources = require("./src/services/tsconfig.json").files.map((file) => path.join(servicesDirectory, file));
113-
114-
const serverCoreSources = require("./src/server/tsconfig.json").files.map((file) => path.join(serverDirectory, file));
115-
116-
const languageServiceLibrarySources = [
117-
"editorServices.ts",
118-
"protocol.d.ts",
119-
"session.ts"
120-
].map(function (f) {
121-
return path.join(serverDirectory, f);
122-
}).concat(servicesSources);
123-
124-
const harnessCoreSources = [
125-
"harness.ts",
126-
"sourceMapRecorder.ts",
127-
"harnessLanguageService.ts",
128-
"fourslash.ts",
129-
"runnerbase.ts",
130-
"compilerRunner.ts",
131-
"typeWriter.ts",
132-
"fourslashRunner.ts",
133-
"projectsRunner.ts",
134-
"loggedIO.ts",
135-
"rwcRunner.ts",
136-
"test262Runner.ts",
137-
"runner.ts"
138-
].map(function (f) {
139-
return path.join(harnessDirectory, f);
140-
});
141-
142-
const harnessSources = harnessCoreSources.concat([
143-
"incrementalParser.ts",
144-
"jsDocParsing.ts",
145-
"services/colorization.ts",
146-
"services/documentRegistry.ts",
147-
"services/preProcessFile.ts",
148-
"services/patternMatcher.ts",
149-
"session.ts",
150-
"versionCache.ts",
151-
"convertToBase64.ts",
152-
"transpile.ts",
153-
"reuseProgramStructure.ts",
154-
"cachingInServerLSHost.ts",
155-
"moduleResolution.ts",
156-
"tsconfigParsing.ts",
157-
"commandLineParsing.ts",
158-
"convertCompilerOptionsFromJson.ts",
159-
"convertTypingOptionsFromJson.ts",
160-
"tsserverProjectSystem.ts",
161-
"matchFiles.ts",
162-
].map(function (f) {
163-
return path.join(unittestsDirectory, f);
164-
})).concat([
165-
"protocol.d.ts",
166-
"session.ts",
167-
"client.ts",
168-
"editorServices.ts"
169-
].map(function (f) {
170-
return path.join(serverDirectory, f);
171-
}));
172-
173107
const es2015LibrarySources = [
174108
"es2015.core.d.ts",
175109
"es2015.collection.d.ts",
@@ -500,21 +434,18 @@ const tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js")
500434
const tsserverLibraryDefinitionFile = path.join(builtLocalDirectory, "tsserverlibrary.d.ts");
501435

502436
gulp.task(tsserverLibraryFile, false, [servicesFile], (done) => {
503-
const settings: tsc.Settings = getCompilerSettings({
504-
declaration: true,
505-
outFile: tsserverLibraryFile
506-
}, /*useBuiltCompiler*/ true);
507-
const {js, dts}: {js: NodeJS.ReadableStream, dts: NodeJS.ReadableStream} = gulp.src(languageServiceLibrarySources)
437+
const serverLibraryProject = tsc.createProject("src/server/tsconfig.library.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
438+
const {js, dts}: {js: NodeJS.ReadableStream, dts: NodeJS.ReadableStream} = serverLibraryProject.src()
508439
.pipe(sourcemaps.init())
509440
.pipe(newer(tsserverLibraryFile))
510-
.pipe(tsc(settings));
441+
.pipe(tsc(serverLibraryProject));
511442

512443
return merge2([
513444
js.pipe(prependCopyright())
514445
.pipe(sourcemaps.write("."))
515-
.pipe(gulp.dest(".")),
446+
.pipe(gulp.dest(builtLocalDirectory)),
516447
dts.pipe(prependCopyright())
517-
.pipe(gulp.dest("."))
448+
.pipe(gulp.dest(builtLocalDirectory))
518449
]);
519450
});
520451

@@ -583,15 +514,13 @@ gulp.task("LKG", "Makes a new LKG out of the built js files", ["clean", "dontUse
583514
// Task to build the tests infrastructure using the built compiler
584515
const run = path.join(builtLocalDirectory, "run.js");
585516
gulp.task(run, false, [servicesFile], () => {
586-
const settings: tsc.Settings = getCompilerSettings({
587-
outFile: run
588-
}, /*useBuiltCompiler*/ true);
589-
return gulp.src(harnessSources)
517+
const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
518+
return testProject.src()
590519
.pipe(newer(run))
591520
.pipe(sourcemaps.init())
592-
.pipe(tsc(settings))
521+
.pipe(tsc(testProject))
593522
.pipe(sourcemaps.write(".", { includeContent: false, sourceRoot: "../../" }))
594-
.pipe(gulp.dest("."));
523+
.pipe(gulp.dest(builtLocalDirectory));
595524
});
596525

597526
const internalTests = "internal/";
@@ -766,13 +695,11 @@ gulp.task(nodeServerOutFile, false, [servicesFile], () => {
766695
});
767696

768697
gulp.task("browserify", "Runs browserify on run.js to produce a file suitable for running tests in the browser", [servicesFile], (done) => {
769-
const settings: tsc.Settings = getCompilerSettings({
770-
outFile: "built/local/bundle.js"
771-
}, /*useBuiltCompiler*/ true);
772-
return gulp.src(harnessSources)
698+
const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({ outFile: "built/local/bundle.js" }, /*useBuiltCompiler*/ true));
699+
return testProject.src()
773700
.pipe(newer("built/local/bundle.js"))
774701
.pipe(sourcemaps.init())
775-
.pipe(tsc(settings))
702+
.pipe(tsc(testProject))
776703
.pipe(through2.obj((file, enc, next) => {
777704
browserify(intoStream(file.contents))
778705
.bundle((err, res) => {
@@ -1013,36 +940,37 @@ function lintFile(options, path) {
1013940
return lintFileContents(options, path, contents);
1014941
}
1015942

1016-
const lintTargets = ["Gulpfile.ts"]
1017-
.concat(compilerSources)
1018-
.concat(harnessSources)
1019-
// Other harness sources
1020-
.concat(["instrumenter.ts"].map(function(f) { return path.join(harnessDirectory, f); }))
1021-
.concat(serverCoreSources)
1022-
.concat(tslintRulesFiles)
1023-
.concat(servicesSources);
943+
const lintTargets = [
944+
"Gulpfile.ts",
945+
"src/compiler/**/*.ts",
946+
"src/harness/**/*.ts",
947+
"!src/harness/unittests/services/formatting/**/*.ts",
948+
"src/server/**/*.ts",
949+
"scripts/tslint/**/*.ts",
950+
"src/services/**/*.ts",
951+
];
1024952

1025953

1026954
gulp.task("lint", "Runs tslint on the compiler sources. Optional arguments are: --f[iles]=regex", ["build-rules"], () => {
955+
const fileMatcher = RegExp(cmdLineOptions["files"]);
1027956
const lintOptions = getLinterOptions();
1028957
let failed = 0;
1029-
const fileMatcher = RegExp(cmdLineOptions["files"]);
1030-
const done = {};
1031-
for (const i in lintTargets) {
1032-
const target = lintTargets[i];
1033-
if (!done[target] && fileMatcher.test(target)) {
1034-
const result = lintFile(lintOptions, target);
958+
return gulp.src(lintTargets)
959+
.pipe(insert.transform((contents, file) => {
960+
if (!fileMatcher.test(file.path)) return contents;
961+
const result = lintFile(lintOptions, file.path);
1035962
if (result.failureCount > 0) {
1036963
console.log(result.output);
1037964
failed += result.failureCount;
1038965
}
1039-
done[target] = true;
1040-
}
1041-
}
1042-
if (failed > 0) {
1043-
console.error("Linter errors.");
1044-
process.exit(1);
1045-
}
966+
return contents; // TODO (weswig): Automatically apply fixes? :3
967+
}))
968+
.on("end", () => {
969+
if (failed > 0) {
970+
console.error("Linter errors.");
971+
process.exit(1);
972+
}
973+
});
1046974
});
1047975

1048976

Jakefile.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var serverDirectory = "src/server/";
1414
var harnessDirectory = "src/harness/";
1515
var libraryDirectory = "src/lib/";
1616
var scriptsDirectory = "scripts/";
17-
var unittestsDirectory = "tests/cases/unittests/";
17+
var unittestsDirectory = "src/harness/unittests/";
1818
var docDirectory = "doc/";
1919

2020
var builtDirectory = "built/";
@@ -100,7 +100,6 @@ var servicesSources = [
100100
}));
101101

102102
var serverCoreSources = [
103-
"node.d.ts",
104103
"editorServices.ts",
105104
"protocol.d.ts",
106105
"session.ts",
@@ -279,13 +278,18 @@ var builtLocalCompiler = path.join(builtLocalDirectory, compilerFilename);
279278
* @param {boolean} opts.stripInternal: true if compiler should remove declarations marked as @internal
280279
* @param {boolean} opts.noMapRoot: true if compiler omit mapRoot option
281280
* @param {boolean} opts.inlineSourceMap: true if compiler should inline sourceMap
281+
* @param {Array} opts.types: array of types to include in compilation
282282
* @param callback: a function to execute after the compilation process ends
283283
*/
284284
function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts, callback) {
285285
file(outFile, prereqs, function() {
286-
var compilerPath = useBuiltCompiler ? builtLocalCompiler : LKGCompiler;
287-
var options = "--noImplicitAny --noImplicitThis --noEmitOnError --types --pretty";
288286
opts = opts || {};
287+
var compilerPath = useBuiltCompiler ? builtLocalCompiler : LKGCompiler;
288+
var options = "--noImplicitAny --noImplicitThis --noEmitOnError --types "
289+
if (opts.types) {
290+
options += opts.types.join(",");
291+
}
292+
options += " --pretty";
289293
// Keep comments when specifically requested
290294
// or when in debug mode.
291295
if (!(opts.keepComments || useDebugMode)) {
@@ -548,8 +552,7 @@ compileFile(
548552
});
549553

550554
var serverFile = path.join(builtLocalDirectory, "tsserver.js");
551-
compileFile(serverFile, serverSources,[builtLocalDirectory, copyright].concat(serverSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true);
552-
555+
compileFile(serverFile, serverSources,[builtLocalDirectory, copyright].concat(serverSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"] });
553556
var tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js");
554557
var tsserverLibraryDefinitionFile = path.join(builtLocalDirectory, "tsserverlibrary.d.ts");
555558
compileFile(
@@ -652,7 +655,7 @@ compileFile(
652655
/*prereqs*/ [builtLocalDirectory, tscFile].concat(libraryTargets).concat(harnessSources),
653656
/*prefixes*/ [],
654657
/*useBuiltCompiler:*/ true,
655-
/*opts*/ { inlineSourceMap: true });
658+
/*opts*/ { inlineSourceMap: true, types: ["node", "mocha", "chai"] });
656659

657660
var internalTests = "internal/";
658661

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
},
3131
"devDependencies": {
3232
"@types/browserify": "latest",
33+
"@types/chai": "latest",
3334
"@types/del": "latest",
3435
"@types/glob": "latest",
3536
"@types/gulp": "latest",
@@ -42,6 +43,7 @@
4243
"@types/minimatch": "latest",
4344
"@types/minimist": "latest",
4445
"@types/mkdirp": "latest",
46+
"@types/mocha": "latest",
4547
"@types/node": "latest",
4648
"@types/q": "latest",
4749
"@types/run-sequence": "latest",

0 commit comments

Comments
 (0)