Skip to content

Commit e426257

Browse files
committed
Revert more baselines, add jake task for typemock
1 parent b4c3bd4 commit e426257

773 files changed

Lines changed: 4449 additions & 4289 deletions

File tree

Some content is hidden

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

Gulpfile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ gulp.task("LKG", "Makes a new LKG out of the built js files", ["clean", "dontUse
609609
});
610610

611611
gulp.task("typemock", () => {
612-
const typemock = tsc.createProject("scripts/typemock/src/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
612+
const typemock = tsc.createProject("scripts/typemock/tsconfig.json", getCompilerSettings({}, /*useBuiltCompiler*/ true));
613613
return typemock.src()
614614
.pipe(sourcemaps.init())
615615
.pipe(newer("scripts/typemock/dist"))

Jakefile.js

Lines changed: 177 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// This file contains the build logic for the public repo
22
// @ts-check
3+
/// <reference types="jake" />
34

45
var fs = require("fs");
56
var os = require("os");
@@ -225,120 +226,190 @@ var compilerFilename = "tsc.js";
225226
var LKGCompiler = path.join(LKGDirectory, compilerFilename);
226227
var builtLocalCompiler = path.join(builtLocalDirectory, compilerFilename);
227228

228-
/* Compiles a file from a list of sources
229-
* @param outFile: the target file name
230-
* @param sources: an array of the names of the source files
231-
* @param prereqs: prerequisite tasks to compiling the file
232-
* @param prefixes: a list of files to prepend to the target file
233-
* @param useBuiltCompiler: true to use the built compiler, false to use the LKG
234-
* @parap {Object} opts - property bag containing auxiliary options
235-
* @param {boolean} opts.noOutFile: true to compile without using --out
236-
* @param {boolean} opts.generateDeclarations: true to compile using --declaration
237-
* @param {string} opts.outDir: value for '--outDir' command line option
238-
* @param {boolean} opts.keepComments: false to compile using --removeComments
239-
* @param {boolean} opts.preserveConstEnums: true if compiler should keep const enums in code
240-
* @param {boolean} opts.noResolve: true if compiler should not include non-rooted files in compilation
241-
* @param {boolean} opts.stripInternal: true if compiler should remove declarations marked as @internal
242-
* @param {boolean} opts.inlineSourceMap: true if compiler should inline sourceMap
243-
* @param {Array} opts.types: array of types to include in compilation
244-
* @param callback: a function to execute after the compilation process ends
245-
*/
246-
function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts, callback) {
247-
file(outFile, prereqs, function() {
248-
if (process.env.USE_TRANSFORMS === "false") {
249-
useBuiltCompiler = false;
250-
}
251-
var startCompileTime = mark();
252-
opts = opts || {};
253-
var compilerPath = useBuiltCompiler ? builtLocalCompiler : LKGCompiler;
254-
var options = "--noImplicitAny --noImplicitThis --alwaysStrict --noEmitOnError --types "
255-
if (opts.types) {
256-
options += opts.types.join(",");
229+
/**
230+
* Executes the compiler
231+
* @param {boolean} useBuiltCompiler
232+
* @param {string[]} args
233+
* @param {function([Error]): void} [callback] A callback to execute after the compilation process ends.
234+
*/
235+
function execCompiler(useBuiltCompiler, args, callback) {
236+
var compilerPath = useBuiltCompiler ? builtLocalCompiler : LKGCompiler;
237+
var cmd = host + " " + compilerPath + " " + args.join(" ");
238+
console.log(cmd + "\n");
239+
240+
var ex = jake.createExec([cmd]);
241+
// Add listeners for output and error
242+
ex.addListener("stdout", function (output) {
243+
process.stdout.write(output);
244+
});
245+
ex.addListener("stderr", function (error) {
246+
process.stderr.write(error);
247+
});
248+
ex.addListener("cmdEnd", function () {
249+
if (callback) {
250+
callback();
257251
}
258-
options += " --pretty";
259-
// Keep comments when specifically requested
260-
// or when in debug mode.
261-
if (!(opts.keepComments || useDebugMode)) {
262-
options += " --removeComments";
252+
});
253+
ex.addListener("error", function (error) {
254+
if (callback) {
255+
callback(error || new Error("Compilation unsuccessful"));
263256
}
257+
});
258+
ex.run();
259+
}
264260

265-
if (opts.generateDeclarations) {
266-
options += " --declaration";
267-
}
261+
/** Compiles a file from a list of sources
262+
* @param {string} outFile value for '--out' command line option
263+
* @param {string[]} sources an array of the names of the source files
264+
* @param {string[]} prefixes a list of files to prepend to the target file
265+
* @param {boolean} useBuiltCompiler true to use the built compiler, false to use the LKG
266+
* @param {object} [opts] property bag containing auxiliary options
267+
* @param {string} [opts.outDir] value for '--outDir' command line option
268+
* @param {boolean} [opts.noOutFile] true to compile without using --out
269+
* @param {string[]} [opts.types] array of types to include in compilation
270+
* @param {string} [opts.target] compilation target (default 'es5').
271+
* @param {string} [opts.lib] explicit libs to include.
272+
* @param {boolean} [opts.generateDeclarations] true to compile using --declaration
273+
* @param {boolean} [opts.keepComments] false to compile using --removeComments
274+
* @param {boolean} [opts.preserveConstEnums] true if compiler should keep const enums in code
275+
* @param {boolean} [opts.noResolve] true if compiler should not include non-rooted files in compilation
276+
* @param {boolean} [opts.stripInternal] true if compiler should remove declarations marked as @internal
277+
* @param {boolean} [opts.sourceMap] true if the compiler should emit source maps
278+
* @param {boolean} [opts.inlineSourceMap] true if compiler should inline sourceMap
279+
* @param {boolean} [opts.allowUnused] Allow unused locals and identifiers.
280+
* @param {boolean} [opts.strict] Compiles with '--strict'
281+
* @param {string} [opts.project] Compiles with '-p'
282+
* @param {function():void} [callback] a function to execute after the compilation process ends
283+
*/
284+
function compile(outFile, sources, prefixes, useBuiltCompiler, opts, callback) {
285+
var startCompileTime = mark();
286+
opts = opts || {};
287+
var options = [
288+
"--noImplicitAny",
289+
"--noImplicitThis",
290+
"--alwaysStrict",
291+
"--noEmitOnError",
292+
"--pretty",
293+
"--newLine LF"
294+
];
295+
296+
if (opts.strict) {
297+
options.push("--strict");
298+
}
268299

269-
if (opts.preserveConstEnums || useDebugMode) {
270-
options += " --preserveConstEnums";
271-
}
300+
if (!opts.allowUnused) {
301+
options.push("--noUnusedLocals", "--noUnusedParameters");
302+
}
303+
304+
if (opts.types) {
305+
options.push("--types", opts.types.join(","));
306+
}
307+
308+
// Keep comments when specifically requested
309+
// or when in debug mode.
310+
if (!(opts.keepComments || useDebugMode)) {
311+
options.push("--removeComments");
312+
}
272313

314+
if (opts.generateDeclarations) {
315+
options.push("--declaration");
316+
}
317+
318+
if (opts.preserveConstEnums || useDebugMode) {
319+
options.push(" --preserveConstEnums");
320+
}
321+
322+
if (!opts.noOutFile) {
323+
options.push("--out", outFile);
324+
}
325+
else {
273326
if (opts.outDir) {
274-
options += " --outDir " + opts.outDir;
327+
options.push("--outDir", opts.outDir);
275328
}
329+
options.push("--module", "commonjs");
330+
}
331+
332+
if (opts.noResolve) {
333+
options.push("--noResolve");
334+
}
276335

277-
if (!opts.noOutFile) {
278-
options += " --out " + outFile;
336+
if (opts.inlineSourceMap || opts.sourceMap || useDebugMode) {
337+
if (opts.inlineSourceMap) {
338+
options.push("--inlineSourceMap", "--inlineSources");
279339
}
280340
else {
281-
options += " --module commonjs";
341+
options.push("-sourcemap");
282342
}
343+
}
283344

284-
if (opts.noResolve) {
285-
options += " --noResolve";
286-
}
345+
if (opts.stripInternal) {
346+
options.push("--stripInternal");
347+
}
348+
349+
if (opts.target) {
350+
options.push("--target", opts.target);
351+
}
352+
else {
353+
options.push("--target es5");
354+
}
287355

288-
if (useDebugMode) {
289-
if (opts.inlineSourceMap) {
290-
options += " --inlineSourceMap --inlineSources";
356+
if (opts.lib) {
357+
options.push("--lib", opts.lib);
358+
}
359+
else {
360+
options.push("--lib es5");
361+
}
362+
363+
execCompiler(useBuiltCompiler, options.concat(sources), function (error) {
364+
if (error) {
365+
if (outFile) {
366+
fs.unlinkSync(outFile);
367+
fail("Compilation of " + outFile + " unsuccessful");
291368
}
292369
else {
293-
options += " -sourcemap";
370+
fail("Compilation unsuccessful");
294371
}
295372
}
296-
options += " --newLine LF";
297-
298-
if (opts.stripInternal) {
299-
options += " --stripInternal";
300-
}
301-
options += " --target es5";
302-
if (opts.lib) {
303-
options += " --lib " + opts.lib
304-
}
305373
else {
306-
options += " --lib es5"
307-
}
308-
options += " --noUnusedLocals --noUnusedParameters";
309-
310-
var cmd = host + " " + compilerPath + " " + options + " ";
311-
cmd = cmd + sources.join(" ");
312-
console.log(cmd + "\n");
313-
314-
var ex = jake.createExec([cmd]);
315-
// Add listeners for output and error
316-
ex.addListener("stdout", function (output) {
317-
process.stdout.write(output);
318-
});
319-
ex.addListener("stderr", function (error) {
320-
process.stderr.write(error);
321-
});
322-
ex.addListener("cmdEnd", function () {
323-
if (!useDebugMode && prefixes && fs.existsSync(outFile)) {
374+
if (!useDebugMode && prefixes && outFile && fs.existsSync(outFile)) {
324375
for (var i in prefixes) {
325376
prependFile(prefixes[i], outFile);
326377
}
327378
}
328-
379+
329380
if (callback) {
330381
callback();
331382
}
332-
333-
measure(startCompileTime);
383+
334384
complete();
335-
});
336-
ex.addListener("error", function () {
337-
fs.unlinkSync(outFile);
338-
fail("Compilation of " + outFile + " unsuccessful");
339-
measure(startCompileTime);
340-
});
341-
ex.run();
385+
}
386+
measure(startCompileTime);
387+
});
388+
}
389+
390+
/**
391+
* Compiles a file from a list of sources
392+
* @param {string} outFile the target file name
393+
* @param {string[]} sources an array of the names of the source files
394+
* @param {string[]} prereqs prerequisite tasks to compiling the file
395+
* @param {string[]} prefixes a list of files to prepend to the target file
396+
* @param {boolean} useBuiltCompiler true to use the built compiler, false to use the LKG
397+
* @param {object} [opts] property bag containing auxiliary options
398+
* @param {boolean} [opts.noOutFile] true to compile without using --out
399+
* @param {boolean} [opts.generateDeclarations] true to compile using --declaration
400+
* @param {string} [opts.outDir] value for '--outDir' command line option
401+
* @param {boolean} [opts.keepComments] false to compile using --removeComments
402+
* @param {boolean} [opts.preserveConstEnums] true if compiler should keep const enums in code
403+
* @param {boolean} [opts.noResolve] true if compiler should not include non-rooted files in compilation
404+
* @param {boolean} [opts.stripInternal] true if compiler should remove declarations marked as @internal
405+
* @param {boolean} [opts.inlineSourceMap] true if compiler should inline sourceMap
406+
* @param {string[]} [opts.types] array of types to include in compilation
407+
* @param {string} [opts.lib] explicit libs to include.
408+
* @param {function(): void} [callback] a function to execute after the compilation process ends
409+
*/
410+
function compileFile(outFile, sources, prereqs, prefixes, useBuiltCompiler, opts, callback) {
411+
file(outFile, prereqs, function() {
412+
compile(outFile, sources, prefixes, useBuiltCompiler, opts, callback);
342413
}, { async: true });
343414
}
344415

@@ -581,7 +652,7 @@ var serverFile = path.join(builtLocalDirectory, "tsserver.js");
581652
compileFile(serverFile, serverSources, [builtLocalDirectory, copyright, cancellationTokenFile, typingsInstallerFile, watchGuardFile].concat(serverSources).concat(servicesSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], preserveConstEnums: true, lib: "es6" });
582653
var tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js");
583654
var tsserverLibraryDefinitionFile = path.join(builtLocalDirectory, "tsserverlibrary.d.ts");
584-
file(typesMapOutputPath, function() {
655+
file(typesMapOutputPath, undefined, function() {
585656
var content = fs.readFileSync(path.join(serverDirectory, 'typesMap.json'));
586657
// Validate that it's valid JSON
587658
try {
@@ -709,12 +780,25 @@ task("LKG", ["clean", "release", "local"].concat(libraryTargets), function () {
709780
// Test directory
710781
directory(builtLocalDirectory);
711782

783+
task("typemock", function () {
784+
var startCompileTime = mark();
785+
execCompiler(/*useBuiltCompiler*/ true, ["-p", "scripts/typemock/tsconfig.json"], function (error) {
786+
if (error) {
787+
fail("Compilation unsuccessful.");
788+
}
789+
else {
790+
complete();
791+
}
792+
measure(startCompileTime);
793+
});
794+
}, { async: true });
795+
712796
// Task to build the tests infrastructure using the built compiler
713797
var run = path.join(builtLocalDirectory, "run.js");
714798
compileFile(
715799
/*outFile*/ run,
716800
/*source*/ harnessSources,
717-
/*prereqs*/[builtLocalDirectory, tscFile, tsserverLibraryFile].concat(libraryTargets).concat(servicesSources).concat(harnessSources),
801+
/*prereqs*/[builtLocalDirectory, tscFile, tsserverLibraryFile, "typemock"].concat(libraryTargets).concat(servicesSources).concat(harnessSources),
718802
/*prefixes*/[],
719803
/*useBuiltCompiler:*/ true,
720804
/*opts*/ { types: ["node", "mocha", "chai"], lib: "es6" });
@@ -734,7 +818,7 @@ desc("Builds the test infrastructure using the built compiler");
734818
task("tests", ["local", run].concat(libraryTargets));
735819

736820
function exec(cmd, completeHandler, errorHandler) {
737-
var ex = jake.createExec([cmd], { windowsVerbatimArguments: true, interactive: true });
821+
var ex = jake.createExec([cmd], /** @type {jake.ExecOptions} */({ windowsVerbatimArguments: true, interactive: true }));
738822
// Add listeners for output and error
739823
ex.addListener("stdout", function (output) {
740824
process.stdout.write(output);
@@ -1223,8 +1307,8 @@ task("lint", ["build-rules"], () => {
12231307
: "Gulpfile.ts 'scripts/generateLocalizedDiagnosticMessages.ts' 'scripts/tslint/**/*.ts' 'src/**/*.ts' --exclude 'src/lib/*.d.ts'";
12241308
const cmd = `node node_modules/tslint/bin/tslint ${files} --formatters-dir ./built/local/tslint/formatters --format autolinkableStylish`;
12251309
console.log("Linting: " + cmd);
1226-
jake.exec([cmd], { interactive: true }, () => {
1310+
jake.exec([cmd], () => {
12271311
if (fold.isTravis()) console.log(fold.end("lint"));
12281312
complete();
1229-
});
1313+
}, /** @type {jake.ExecOptions} */({ interactive: true }));
12301314
});

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"@types/gulp-help": "latest",
4040
"@types/gulp-newer": "latest",
4141
"@types/gulp-sourcemaps": "latest",
42+
"@types/jake": "0.0.30",
4243
"@types/merge2": "latest",
4344
"@types/minimatch": "latest",
4445
"@types/minimist": "latest",
@@ -50,10 +51,10 @@
5051
"@types/source-map-support": "^0.4.0",
5152
"@types/through2": "latest",
5253
"@types/xml2js": "^0.4.0",
53-
"xml2js": "^0.4.19",
5454
"browser-resolve": "^1.11.2",
5555
"browserify": "latest",
5656
"chai": "latest",
57+
"chalk": "latest",
5758
"convert-source-map": "latest",
5859
"del": "latest",
5960
"gulp": "3.X",
@@ -80,9 +81,9 @@
8081
"ts-node": "latest",
8182
"tslint": "latest",
8283
"typemock": "file:scripts/typemock",
84+
"typescript": "next",
8385
"vinyl": "latest",
84-
"chalk": "latest",
85-
"typescript": "next"
86+
"xml2js": "^0.4.19"
8687
},
8788
"scripts": {
8889
"pretest": "jake tests",

0 commit comments

Comments
 (0)