Skip to content

Commit ed0a653

Browse files
committed
Merge branch 'master' into transforms
2 parents 990e130 + 36b6113 commit ed0a653

File tree

803 files changed

+20608
-35374
lines changed

Some content is hidden

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

803 files changed

+20608
-35374
lines changed

.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,25 @@ node_js:
66
- '0.10'
77

88
sudo: false
9+
10+
matrix:
11+
fast_finish: true
12+
include:
13+
- os: osx
14+
node_js: stable
15+
osx_image: xcode7.3
16+
17+
branches:
18+
only:
19+
- master
20+
- transforms
21+
22+
install:
23+
- npm uninstall typescript
24+
- npm uninstall tslint
25+
- npm install
26+
- npm update
27+
28+
cache:
29+
directories:
30+
- node_modules

Gulpfile.ts

Lines changed: 89 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ import newer = require("gulp-newer");
1111
import tsc = require("gulp-typescript");
1212
declare module "gulp-typescript" {
1313
interface Settings {
14-
stripInternal?: boolean;
14+
pretty?: boolean;
1515
newLine?: string;
16+
noImplicitThis?: boolean;
17+
stripInternal?: boolean;
18+
types?: string[];
1619
}
1720
interface CompileStream extends NodeJS.ReadWriteStream {} // Either gulp or gulp-typescript has some odd typings which don't reflect reality, making this required
1821
}
@@ -56,7 +59,6 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
5659
browser: process.env.browser || process.env.b || "IE",
5760
tests: process.env.test || process.env.tests || process.env.t,
5861
light: process.env.light || false,
59-
port: process.env.port || process.env.p || "8888",
6062
reporter: process.env.reporter || process.env.r,
6163
lint: process.env.lint || true,
6264
files: process.env.f || process.env.file || process.env.files || "",
@@ -82,12 +84,9 @@ let host = cmdLineOptions["host"];
8284

8385
// Constants
8486
const compilerDirectory = "src/compiler/";
85-
const servicesDirectory = "src/services/";
86-
const serverDirectory = "src/server/";
8787
const harnessDirectory = "src/harness/";
8888
const libraryDirectory = "src/lib/";
8989
const scriptsDirectory = "scripts/";
90-
const unittestsDirectory = "tests/cases/unittests/";
9190
const docDirectory = "doc/";
9291

9392
const builtDirectory = "built/";
@@ -104,69 +103,6 @@ const nodeModulesPathPrefix = path.resolve("./node_modules/.bin/");
104103
const isWin = /^win/.test(process.platform);
105104
const mocha = path.join(nodeModulesPathPrefix, "mocha") + (isWin ? ".cmd" : "");
106105

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

307243
function getCompilerSettings(base: tsc.Settings, useBuiltCompiler?: boolean): tsc.Settings {
308244
const copy: tsc.Settings = {};
245+
copy.noEmitOnError = true;
246+
copy.noImplicitAny = true;
247+
copy.noImplicitThis = true;
248+
copy.pretty = true;
249+
copy.types = [];
309250
for (const key in base) {
310251
copy[key] = base[key];
311252
}
@@ -492,21 +433,18 @@ const tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js")
492433
const tsserverLibraryDefinitionFile = path.join(builtLocalDirectory, "tsserverlibrary.d.ts");
493434

494435
gulp.task(tsserverLibraryFile, false, [servicesFile], (done) => {
495-
const settings: tsc.Settings = getCompilerSettings({
496-
declaration: true,
497-
outFile: tsserverLibraryFile
498-
}, /*useBuiltCompiler*/ true);
499-
const {js, dts}: {js: NodeJS.ReadableStream, dts: NodeJS.ReadableStream} = gulp.src(languageServiceLibrarySources)
436+
const serverLibraryProject = tsc.createProject("src/server/tsconfig.library.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
437+
const {js, dts}: {js: NodeJS.ReadableStream, dts: NodeJS.ReadableStream} = serverLibraryProject.src()
500438
.pipe(sourcemaps.init())
501439
.pipe(newer(tsserverLibraryFile))
502-
.pipe(tsc(settings));
440+
.pipe(tsc(serverLibraryProject));
503441

504442
return merge2([
505443
js.pipe(prependCopyright())
506444
.pipe(sourcemaps.write("."))
507-
.pipe(gulp.dest(".")),
445+
.pipe(gulp.dest(builtLocalDirectory)),
508446
dts.pipe(prependCopyright())
509-
.pipe(gulp.dest("."))
447+
.pipe(gulp.dest(builtLocalDirectory))
510448
]);
511449
});
512450

@@ -575,15 +513,13 @@ gulp.task("LKG", "Makes a new LKG out of the built js files", ["clean", "dontUse
575513
// Task to build the tests infrastructure using the built compiler
576514
const run = path.join(builtLocalDirectory, "run.js");
577515
gulp.task(run, false, [servicesFile], () => {
578-
const settings: tsc.Settings = getCompilerSettings({
579-
outFile: run
580-
}, /*useBuiltCompiler*/ true);
581-
return gulp.src(harnessSources)
516+
const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/true));
517+
return testProject.src()
582518
.pipe(newer(run))
583519
.pipe(sourcemaps.init())
584-
.pipe(tsc(settings))
520+
.pipe(tsc(testProject))
585521
.pipe(sourcemaps.write(".", { includeContent: false, sourceRoot: "../../" }))
586-
.pipe(gulp.dest("."));
522+
.pipe(gulp.dest(builtLocalDirectory));
587523
});
588524

589525
const internalTests = "internal/";
@@ -757,23 +693,50 @@ gulp.task(nodeServerOutFile, false, [servicesFile], () => {
757693
.pipe(gulp.dest(path.dirname(nodeServerOutFile)));
758694
});
759695

696+
import convertMap = require("convert-source-map");
697+
import sorcery = require("sorcery");
698+
declare module "convert-source-map" {
699+
export function fromSource(source: string, largeSource?: boolean): SourceMapConverter;
700+
}
701+
760702
gulp.task("browserify", "Runs browserify on run.js to produce a file suitable for running tests in the browser", [servicesFile], (done) => {
761-
const settings: tsc.Settings = getCompilerSettings({
762-
outFile: "built/local/bundle.js"
763-
}, /*useBuiltCompiler*/ true);
764-
return gulp.src(harnessSources)
703+
const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({ outFile: "built/local/bundle.js" }, /*useBuiltCompiler*/ true));
704+
return testProject.src()
765705
.pipe(newer("built/local/bundle.js"))
766706
.pipe(sourcemaps.init())
767-
.pipe(tsc(settings))
707+
.pipe(tsc(testProject))
768708
.pipe(through2.obj((file, enc, next) => {
769-
browserify(intoStream(file.contents))
709+
const originalMap = file.sourceMap;
710+
const prebundledContent = file.contents.toString();
711+
// Make paths absolute to help sorcery deal with all the terrible paths being thrown around
712+
originalMap.sources = originalMap.sources.map(s => path.resolve("src", s));
713+
// intoStream (below) makes browserify think the input file is named this, so this is what it puts in the sourcemap
714+
originalMap.file = "built/local/_stream_0.js";
715+
716+
browserify(intoStream(file.contents), { debug: true })
770717
.bundle((err, res) => {
771718
// assumes file.contents is a Buffer
772-
file.contents = res;
719+
const maps = JSON.parse(convertMap.fromSource(res.toString(), /*largeSource*/true).toJSON());
720+
delete maps.sourceRoot;
721+
maps.sources = maps.sources.map(s => path.resolve(s === "_stream_0.js" ? "built/local/_stream_0.js" : s));
722+
// Strip browserify's inline comments away (could probably just let sorcery do this, but then we couldn't fix the paths)
723+
file.contents = new Buffer(convertMap.removeComments(res.toString()));
724+
const chain = sorcery.loadSync("built/local/bundle.js", {
725+
content: {
726+
"built/local/_stream_0.js": prebundledContent,
727+
"built/local/bundle.js": file.contents.toString()
728+
},
729+
sourcemaps: {
730+
"built/local/_stream_0.js": originalMap,
731+
"built/local/bundle.js": maps,
732+
}
733+
});
734+
const finalMap = chain.apply();
735+
file.sourceMap = finalMap;
773736
next(undefined, file);
774737
});
775738
}))
776-
.pipe(sourcemaps.write(".", { includeContent: false, sourceRoot: "../../" }))
739+
.pipe(sourcemaps.write(".", { includeContent: false }))
777740
.pipe(gulp.dest("."));
778741
});
779742

@@ -802,7 +765,7 @@ function writeTestConfigFile(tests: string, light: boolean, taskConfigsFolder?:
802765
}
803766

804767

805-
gulp.task("runtests-browser", "Runs the tests using the built run.js file like 'gulp runtests'. Syntax is gulp runtests-browser. Additional optional parameters --tests=[regex], --port=, --browser=[chrome|IE]", ["browserify", nodeServerOutFile], (done) => {
768+
gulp.task("runtests-browser", "Runs the tests using the built run.js file like 'gulp runtests'. Syntax is gulp runtests-browser. Additional optional parameters --tests=[regex], --browser=[chrome|IE]", ["browserify", nodeServerOutFile], (done) => {
806769
cleanTestDirs((err) => {
807770
if (err) { console.error(err); done(err); process.exit(1); }
808771
host = "node";
@@ -817,9 +780,6 @@ gulp.task("runtests-browser", "Runs the tests using the built run.js file like '
817780
}
818781

819782
const args = [nodeServerOutFile];
820-
if (cmdLineOptions["port"]) {
821-
args.push(cmdLineOptions["port"]);
822-
}
823783
if (cmdLineOptions["browser"]) {
824784
args.push(cmdLineOptions["browser"]);
825785
}
@@ -954,37 +914,20 @@ gulp.task("update-sublime", "Updates the sublime plugin's tsserver", ["local", s
954914
return gulp.src([serverFile, serverFile + ".map"]).pipe(gulp.dest("../TypeScript-Sublime-Plugin/tsserver/"));
955915
});
956916

957-
958-
const tslintRuleDir = "scripts/tslint";
959-
const tslintRules = [
960-
"nextLineRule",
961-
"preferConstRule",
962-
"booleanTriviaRule",
963-
"typeOperatorSpacingRule",
964-
"noInOperatorRule",
965-
"noIncrementDecrementRule",
966-
"objectLiteralSurroundingSpaceRule",
967-
];
968-
const tslintRulesFiles = tslintRules.map(function(p) {
969-
return path.join(tslintRuleDir, p + ".ts");
970-
});
971-
const tslintRulesOutFiles = tslintRules.map(function(p, i) {
972-
const pathname = path.join(builtLocalDirectory, "tslint", p + ".js");
973-
gulp.task(pathname, false, [], () => {
974-
const settings: tsc.Settings = getCompilerSettings({ module: "commonjs" }, /*useBuiltCompiler*/ false);
975-
return gulp.src(tslintRulesFiles[i])
976-
.pipe(newer(pathname))
977-
.pipe(sourcemaps.init())
978-
.pipe(tsc(settings))
979-
.pipe(sourcemaps.write("."))
980-
.pipe(gulp.dest(path.join(builtLocalDirectory, "tslint")));
981-
});
982-
return pathname;
917+
gulp.task("build-rules", "Compiles tslint rules to js", () => {
918+
const settings: tsc.Settings = getCompilerSettings({ module: "commonjs" }, /*useBuiltCompiler*/ false);
919+
const dest = path.join(builtLocalDirectory, "tslint");
920+
return gulp.src("scripts/tslint/**/*.ts")
921+
.pipe(newer({
922+
dest,
923+
ext: ".js"
924+
}))
925+
.pipe(sourcemaps.init())
926+
.pipe(tsc(settings))
927+
.pipe(sourcemaps.write("."))
928+
.pipe(gulp.dest(dest));
983929
});
984930

985-
gulp.task("build-rules", "Compiles tslint rules to js", tslintRulesOutFiles);
986-
987-
988931
function getLinterOptions() {
989932
return {
990933
configuration: require("./tslint.json"),
@@ -1005,36 +948,38 @@ function lintFile(options, path) {
1005948
return lintFileContents(options, path, contents);
1006949
}
1007950

1008-
const lintTargets = ["Gulpfile.ts"]
1009-
.concat(compilerSources)
1010-
.concat(harnessSources)
1011-
// Other harness sources
1012-
.concat(["instrumenter.ts"].map(function(f) { return path.join(harnessDirectory, f); }))
1013-
.concat(serverCoreSources)
1014-
.concat(tslintRulesFiles)
1015-
.concat(servicesSources);
951+
const lintTargets = [
952+
"Gulpfile.ts",
953+
"src/compiler/**/*.ts",
954+
"src/harness/**/*.ts",
955+
"!src/harness/unittests/services/formatting/**/*.ts",
956+
"src/server/**/*.ts",
957+
"scripts/tslint/**/*.ts",
958+
"src/services/**/*.ts",
959+
"tests/*.ts", "tests/webhost/*.ts" // Note: does *not* descend recursively
960+
];
1016961

1017962

1018963
gulp.task("lint", "Runs tslint on the compiler sources. Optional arguments are: --f[iles]=regex", ["build-rules"], () => {
964+
const fileMatcher = RegExp(cmdLineOptions["files"]);
1019965
const lintOptions = getLinterOptions();
1020966
let failed = 0;
1021-
const fileMatcher = RegExp(cmdLineOptions["files"]);
1022-
const done = {};
1023-
for (const i in lintTargets) {
1024-
const target = lintTargets[i];
1025-
if (!done[target] && fileMatcher.test(target)) {
1026-
const result = lintFile(lintOptions, target);
967+
return gulp.src(lintTargets)
968+
.pipe(insert.transform((contents, file) => {
969+
if (!fileMatcher.test(file.path)) return contents;
970+
const result = lintFile(lintOptions, file.path);
1027971
if (result.failureCount > 0) {
1028972
console.log(result.output);
1029973
failed += result.failureCount;
1030974
}
1031-
done[target] = true;
1032-
}
1033-
}
1034-
if (failed > 0) {
1035-
console.error("Linter errors.");
1036-
process.exit(1);
1037-
}
975+
return contents; // TODO (weswig): Automatically apply fixes? :3
976+
}))
977+
.on("end", () => {
978+
if (failed > 0) {
979+
console.error("Linter errors.");
980+
process.exit(1);
981+
}
982+
});
1038983
});
1039984

1040985

0 commit comments

Comments
 (0)