2014-07-13 01:04:16 +02:00
// This file contains the build logic for the public repo
var fs = require ( "fs" ) ;
2014-12-02 00:32:52 +01:00
var os = require ( "os" ) ;
2014-07-13 01:04:16 +02:00
var path = require ( "path" ) ;
2015-03-04 07:12:06 +01:00
var child_process = require ( "child_process" ) ;
2015-09-18 06:04:33 +02:00
var Linter = require ( "tslint" ) ;
2016-03-24 21:32:41 +01:00
var readline = require ( "readline" ) ;
2014-07-13 01:04:16 +02:00
// Variables
var compilerDirectory = "src/compiler/" ;
var servicesDirectory = "src/services/" ;
2015-02-12 04:43:10 +01:00
var serverDirectory = "src/server/" ;
2014-07-13 01:04:16 +02:00
var harnessDirectory = "src/harness/" ;
var libraryDirectory = "src/lib/" ;
2014-07-24 13:53:42 +02:00
var scriptsDirectory = "scripts/" ;
2014-10-17 03:13:26 +02:00
var unittestsDirectory = "tests/cases/unittests/" ;
2014-09-26 23:36:18 +02:00
var docDirectory = "doc/" ;
2014-07-13 01:04:16 +02:00
var builtDirectory = "built/" ;
var builtLocalDirectory = "built/local/" ;
2015-07-27 19:07:07 +02:00
var LKGDirectory = "lib/" ;
2014-07-13 01:04:16 +02:00
var copyright = "CopyrightNotice.txt" ;
var thirdParty = "ThirdPartyNoticeText.txt" ;
2014-07-22 07:08:27 +02:00
// add node_modules to path so we don't need global modules, prefer the modules by adding them first
2014-07-24 04:30:13 +02:00
var nodeModulesPathPrefix = path . resolve ( "./node_modules/.bin/" ) + path . delimiter ;
if ( process . env . path !== undefined ) {
process . env . path = nodeModulesPathPrefix + process . env . path ;
2015-03-04 07:12:06 +01:00
} else if ( process . env . PATH !== undefined ) {
2014-07-24 04:30:13 +02:00
process . env . PATH = nodeModulesPathPrefix + process . env . PATH ;
}
2014-07-22 07:08:27 +02:00
2014-07-13 01:04:16 +02:00
var compilerSources = [
"core.ts" ,
"sys.ts" ,
"types.ts" ,
"scanner.ts" ,
"parser.ts" ,
2014-12-11 01:42:41 +01:00
"utilities.ts" ,
2014-07-13 01:04:16 +02:00
"binder.ts" ,
"checker.ts" ,
2016-02-04 03:11:32 +01:00
"factory.ts" ,
"visitor.ts" ,
2016-02-12 19:49:09 +01:00
"transformers/destructuring.ts" ,
"transformers/ts.ts" ,
"transformers/module/es6.ts" ,
"transformers/module/system.ts" ,
"transformers/module/module.ts" ,
"transformers/jsx.ts" ,
"transformers/es7.ts" ,
"transformers/es6.ts" ,
2016-02-09 21:39:46 +01:00
"transformer.ts" ,
2015-11-24 07:38:05 +01:00
"sourcemap.ts" ,
2016-02-09 22:43:40 +01:00
"comments.ts" ,
"printer.ts" ,
2015-03-19 00:37:52 +01:00
"declarationEmitter.ts" ,
2014-07-13 01:04:16 +02:00
"emitter.ts" ,
2014-12-16 22:28:38 +01:00
"program.ts" ,
2014-07-13 01:04:16 +02:00
"commandLineParser.ts" ,
2014-08-07 08:21:53 +02:00
"tsc.ts" ,
2014-07-13 01:04:16 +02:00
"diagnosticInformationMap.generated.ts"
] . map ( function ( f ) {
return path . join ( compilerDirectory , f ) ;
} ) ;
var servicesSources = [
"core.ts" ,
2014-12-11 01:42:41 +01:00
"sys.ts" ,
2014-07-13 01:04:16 +02:00
"types.ts" ,
"scanner.ts" ,
"parser.ts" ,
2014-12-11 01:42:41 +01:00
"utilities.ts" ,
2014-07-13 01:04:16 +02:00
"binder.ts" ,
"checker.ts" ,
2016-02-04 03:11:32 +01:00
"factory.ts" ,
"visitor.ts" ,
2016-02-12 19:49:09 +01:00
"transformers/destructuring.ts" ,
"transformers/ts.ts" ,
"transformers/module/es6.ts" ,
"transformers/module/system.ts" ,
"transformers/module/module.ts" ,
"transformers/jsx.ts" ,
"transformers/es7.ts" ,
"transformers/es6.ts" ,
2016-02-09 21:39:46 +01:00
"transformer.ts" ,
2015-11-24 07:38:05 +01:00
"sourcemap.ts" ,
2016-02-09 22:43:40 +01:00
"comments.ts" ,
"printer.ts" ,
2015-03-19 00:37:52 +01:00
"declarationEmitter.ts" ,
2014-12-11 01:42:41 +01:00
"emitter.ts" ,
2014-12-16 22:28:38 +01:00
"program.ts" ,
2015-01-12 01:20:19 +01:00
"commandLineParser.ts" ,
2014-12-11 01:42:41 +01:00
"diagnosticInformationMap.generated.ts"
2014-07-13 01:04:16 +02:00
] . map ( function ( f ) {
return path . join ( compilerDirectory , f ) ;
} ) . concat ( [
2014-10-18 00:39:31 +02:00
"breakpoints.ts" ,
2015-03-19 00:37:52 +01:00
"navigateTo.ts" ,
2014-12-11 01:42:41 +01:00
"navigationBar.ts" ,
"outliningElementsCollector.ts" ,
2015-02-20 09:22:41 +01:00
"patternMatcher.ts" ,
2014-07-13 01:04:16 +02:00
"services.ts" ,
"shims.ts" ,
2014-09-24 04:00:45 +02:00
"signatureHelp.ts" ,
2014-09-30 23:20:58 +02:00
"utilities.ts" ,
2014-12-11 01:42:41 +01:00
"formatting/formatting.ts" ,
"formatting/formattingContext.ts" ,
"formatting/formattingRequestKind.ts" ,
"formatting/formattingScanner.ts" ,
"formatting/references.ts" ,
"formatting/rule.ts" ,
"formatting/ruleAction.ts" ,
"formatting/ruleDescriptor.ts" ,
"formatting/ruleFlag.ts" ,
"formatting/ruleOperation.ts" ,
"formatting/ruleOperationContext.ts" ,
"formatting/rules.ts" ,
"formatting/rulesMap.ts" ,
"formatting/rulesProvider.ts" ,
"formatting/smartIndenter.ts" ,
"formatting/tokenRange.ts"
2014-07-13 01:04:16 +02:00
] . map ( function ( f ) {
return path . join ( servicesDirectory , f ) ;
} ) ) ;
2015-10-29 00:02:16 +01:00
var serverCoreSources = [
2015-02-12 04:43:10 +01:00
"node.d.ts" ,
"editorServices.ts" ,
2015-02-16 03:49:22 +01:00
"protocol.d.ts" ,
"session.ts" ,
2015-02-12 04:43:10 +01:00
"server.ts"
] . map ( function ( f ) {
return path . join ( serverDirectory , f ) ;
2015-10-28 23:42:15 +01:00
} ) ;
2015-10-29 00:02:16 +01:00
var serverSources = serverCoreSources . concat ( servicesSources ) ;
2015-02-12 04:43:10 +01:00
2015-06-10 02:00:35 +02:00
var languageServiceLibrarySources = [
"editorServices.ts" ,
"protocol.d.ts" ,
"session.ts"
] . map ( function ( f ) {
return path . join ( serverDirectory , f ) ;
2015-06-17 21:39:02 +02:00
} ) . concat ( servicesSources ) ;
2015-06-10 02:00:35 +02:00
2015-07-15 02:47:15 +02:00
var harnessCoreSources = [
2014-07-13 01:04:16 +02:00
"harness.ts" ,
"sourceMapRecorder.ts" ,
2014-07-29 19:37:01 +02:00
"harnessLanguageService.ts" ,
"fourslash.ts" ,
2014-07-13 01:04:16 +02:00
"runnerbase.ts" ,
"compilerRunner.ts" ,
"typeWriter.ts" ,
2014-07-29 19:37:01 +02:00
"fourslashRunner.ts" ,
2014-07-13 01:04:16 +02:00
"projectsRunner.ts" ,
2014-08-21 00:26:33 +02:00
"loggedIO.ts" ,
2014-07-13 01:04:16 +02:00
"rwcRunner.ts" ,
2014-11-17 20:01:05 +01:00
"test262Runner.ts" ,
2014-07-29 19:37:01 +02:00
"runner.ts"
2014-07-13 01:04:16 +02:00
] . map ( function ( f ) {
return path . join ( harnessDirectory , f ) ;
2015-07-15 02:47:15 +02:00
} ) ;
var harnessSources = harnessCoreSources . concat ( [
2014-12-10 01:39:52 +01:00
"incrementalParser.ts" ,
2015-05-28 19:14:18 +02:00
"jsDocParsing.ts" ,
2014-10-30 01:36:39 +01:00
"services/colorization.ts" ,
2014-10-25 01:03:59 +02:00
"services/documentRegistry.ts" ,
2015-02-20 09:22:41 +01:00
"services/preProcessFile.ts" ,
2015-04-01 02:30:57 +02:00
"services/patternMatcher.ts" ,
2015-07-22 01:05:03 +02:00
"session.ts" ,
2015-04-08 07:54:06 +02:00
"versionCache.ts" ,
2015-05-27 05:18:13 +02:00
"convertToBase64.ts" ,
2015-06-24 06:06:57 +02:00
"transpile.ts" ,
2015-08-04 02:42:29 +02:00
"reuseProgramStructure.ts" ,
2015-08-18 03:31:12 +02:00
"cachingInServerLSHost.ts" ,
2015-10-29 12:56:13 +01:00
"moduleResolution.ts" ,
2016-03-15 19:44:33 +01:00
"tsconfigParsing.ts" ,
2016-03-15 19:45:21 +01:00
"commandLineParsing.ts" ,
"convertCompilerOptionsFromJson.ts" ,
2016-06-03 20:02:35 +02:00
"convertTypingOptionsFromJson.ts" ,
"tsserverProjectSystem.ts"
2014-10-17 03:13:26 +02:00
] . map ( function ( f ) {
return path . join ( unittestsDirectory , f ) ;
2015-02-12 04:43:10 +01:00
} ) ) . concat ( [
2015-02-16 03:49:22 +01:00
"protocol.d.ts" ,
"session.ts" ,
2015-02-12 04:43:10 +01:00
"client.ts" ,
2016-04-09 00:37:13 +02:00
"editorServices.ts"
2015-02-12 04:43:10 +01:00
] . map ( function ( f ) {
return path . join ( serverDirectory , f ) ;
2014-10-17 03:13:26 +02:00
} ) ) ;
2014-07-13 01:04:16 +02:00
var librarySourceMap = [
2016-04-18 22:27:33 +02:00
{ target : "lib.core.d.ts" , sources : [ "header.d.ts" , "core.d.ts" ] } ,
{ target : "lib.dom.d.ts" , sources : [ "importcore.d.ts" , "intl.d.ts" , "dom.generated.d.ts" ] } ,
{ target : "lib.webworker.d.ts" , sources : [ "importcore.d.ts" , "intl.d.ts" , "webworker.generated.d.ts" ] } ,
{ target : "lib.scriptHost.d.ts" , sources : [ "importcore.d.ts" , "scriptHost.d.ts" ] } ,
{ target : "lib.d.ts" , sources : [ "header.d.ts" , "core.d.ts" , "intl.d.ts" , "dom.generated.d.ts" , "webworker.importscripts.d.ts" , "scriptHost.d.ts" ] } ,
{ target : "lib.core.es6.d.ts" , sources : [ "header.d.ts" , "core.d.ts" , "es6.d.ts" ] } ,
{ target : "lib.es6.d.ts" , sources : [ "header.d.ts" , "es6.d.ts" , "core.d.ts" , "intl.d.ts" , "dom.generated.d.ts" , "dom.es6.d.ts" , "webworker.importscripts.d.ts" , "scriptHost.d.ts" ] } ,
{ target : "lib.core.es7.d.ts" , sources : [ "header.d.ts" , "core.d.ts" , "es6.d.ts" , "es7.d.ts" ] } ,
{ target : "lib.es7.d.ts" , sources : [ "header.d.ts" , "es6.d.ts" , "es7.d.ts" , "core.d.ts" , "intl.d.ts" , "dom.generated.d.ts" , "dom.es6.d.ts" , "webworker.importscripts.d.ts" , "scriptHost.d.ts" ] }
2016-05-25 23:14:32 +02:00
] ;
2016-03-28 22:19:17 +02:00
var es2015LibrarySources = [
2016-04-05 07:02:12 +02:00
"es2015.core.d.ts" ,
2016-03-28 22:19:17 +02:00
"es2015.collection.d.ts" ,
"es2015.generator.d.ts" ,
"es2015.iterable.d.ts" ,
"es2015.promise.d.ts" ,
"es2015.proxy.d.ts" ,
"es2015.reflect.d.ts" ,
"es2015.symbol.d.ts" ,
2016-05-19 22:31:21 +02:00
"es2015.symbol.wellknown.d.ts"
2014-07-13 01:04:16 +02:00
] ;
2016-03-28 22:19:17 +02:00
var es2015LibrarySourceMap = es2015LibrarySources . map ( function ( source ) {
2016-02-06 02:00:45 +01:00
return { target : "lib." + source , sources : [ "header.d.ts" , source ] } ;
} ) ;
2016-03-28 22:19:17 +02:00
var es2016LibrarySource = [ "es2016.array.include.d.ts" ] ;
2016-02-06 02:00:45 +01:00
2016-05-19 22:31:21 +02:00
var es2016LibrarySourceMap = es2016LibrarySource . map ( function ( source ) {
2016-02-06 02:00:45 +01:00
return { target : "lib." + source , sources : [ "header.d.ts" , source ] } ;
2016-05-19 22:31:21 +02:00
} ) ;
2016-02-06 02:00:45 +01:00
2016-05-10 23:22:00 +02:00
var es2017LibrarySource = [ "es2017.object.d.ts" ] ;
2016-05-19 22:31:21 +02:00
var es2017LibrarySourceMap = es2017LibrarySource . map ( function ( source ) {
2016-02-06 02:00:45 +01:00
return { target : "lib." + source , sources : [ "header.d.ts" , source ] } ;
2016-05-19 22:31:21 +02:00
} ) ;
2016-02-06 02:00:45 +01:00
2016-05-19 22:31:21 +02:00
var hostsLibrarySources = [ "dom.generated.d.ts" , "webworker.importscripts.d.ts" , "scripthost.d.ts" ] ;
2016-02-06 02:00:45 +01:00
var librarySourceMap = [
// Host library
2016-05-19 22:31:21 +02:00
{ target : "lib.dom.d.ts" , sources : [ "header.d.ts" , "dom.generated.d.ts" ] } ,
{ target : "lib.dom.iterable.d.ts" , sources : [ "header.d.ts" , "dom.iterable.d.ts" ] } ,
{ target : "lib.webworker.d.ts" , sources : [ "header.d.ts" , "webworker.generated.d.ts" ] } ,
{ target : "lib.scripthost.d.ts" , sources : [ "header.d.ts" , "scripthost.d.ts" ] } ,
2016-02-06 02:00:45 +01:00
// JavaScript library
{ target : "lib.es5.d.ts" , sources : [ "header.d.ts" , "es5.d.ts" ] } ,
2016-03-28 22:19:17 +02:00
{ target : "lib.es2015.d.ts" , sources : [ "header.d.ts" , "es2015.d.ts" ] } ,
{ target : "lib.es2016.d.ts" , sources : [ "header.d.ts" , "es2016.d.ts" ] } ,
2016-05-10 23:22:00 +02:00
{ target : "lib.es2017.d.ts" , sources : [ "header.d.ts" , "es2017.d.ts" ] } ,
2016-05-26 10:16:29 +02:00
2016-02-06 02:00:45 +01:00
// JavaScript + all host library
2016-05-19 22:31:21 +02:00
{ target : "lib.d.ts" , sources : [ "header.d.ts" , "es5.d.ts" ] . concat ( hostsLibrarySources ) } ,
{ target : "lib.es6.d.ts" , sources : [ "header.d.ts" , "es5.d.ts" ] . concat ( es2015LibrarySources , hostsLibrarySources , "dom.iterable.d.ts" ) }
2016-05-10 23:22:00 +02:00
] . concat ( es2015LibrarySourceMap , es2016LibrarySourceMap , es2017LibrarySourceMap ) ;
2016-02-06 02:00:45 +01:00
2014-07-13 01:04:16 +02:00
var libraryTargets = librarySourceMap . map ( function ( f ) {
return path . join ( builtLocalDirectory , f . target ) ;
} ) ;
// Prepends the contents of prefixFile to destinationFile
function prependFile ( prefixFile , destinationFile ) {
if ( ! fs . existsSync ( prefixFile ) ) {
fail ( prefixFile + " does not exist!" ) ;
}
if ( ! fs . existsSync ( destinationFile ) ) {
fail ( destinationFile + " failed to be created!" ) ;
}
var temp = "temptemp" ;
jake . cpR ( prefixFile , temp , { silent : true } ) ;
fs . appendFileSync ( temp , fs . readFileSync ( destinationFile ) ) ;
fs . renameSync ( temp , destinationFile ) ;
}
// concatenate a list of sourceFiles to a destinationFile
function concatenateFiles ( destinationFile , sourceFiles ) {
var temp = "temptemp" ;
// Copy the first file to temp
if ( ! fs . existsSync ( sourceFiles [ 0 ] ) ) {
fail ( sourceFiles [ 0 ] + " does not exist!" ) ;
}
jake . cpR ( sourceFiles [ 0 ] , temp , { silent : true } ) ;
// append all files in sequence
for ( var i = 1 ; i < sourceFiles . length ; i ++ ) {
if ( ! fs . existsSync ( sourceFiles [ i ] ) ) {
fail ( sourceFiles [ i ] + " does not exist!" ) ;
}
fs . appendFileSync ( temp , fs . readFileSync ( sourceFiles [ i ] ) ) ;
}
// Move the file to the final destination
fs . renameSync ( temp , destinationFile ) ;
}
2014-11-04 21:18:32 +01:00
var useDebugMode = true ;
2016-05-19 22:31:21 +02:00
var host = process . env . TYPESCRIPT_HOST || process . env . host || "node" ;
2014-09-02 21:19:58 +02:00
var compilerFilename = "tsc.js" ;
2015-09-18 22:13:26 +02:00
var LKGCompiler = path . join ( LKGDirectory , compilerFilename ) ;
var builtLocalCompiler = path . join ( builtLocalDirectory , compilerFilename ) ;
2015-03-04 07:12:06 +01:00
/ * C o m p i l e s a f i l e f r o m a l i s t o f s o u r c e s
2014-07-13 01:04:16 +02:00
* @param outFile : the target file name
* @param sources : an array of the names of the source files
* @param prereqs : prerequisite tasks to compiling the file
* @param prefixes : a list of files to prepend to the target file
* @param useBuiltCompiler : true to use the built compiler , false to use the LKG
2016-02-10 09:20:40 +01:00
* @parap { Object } opts - property bag containing auxiliary options
* @param { boolean } opts.noOutFile : true to compile without using -- out
* @param { boolean } opts.generateDeclarations : true to compile using -- declaration
* @param { string } opts.outDir : value for '--outDir' command line option
* @param { boolean } opts.keepComments : false to compile using -- removeComments
* @param { boolean } opts.preserveConstEnums : true if compiler should keep const enums in code
* @param { boolean } opts.noResolve : true if compiler should not include non - rooted files in compilation
* @param { boolean } opts.stripInternal : true if compiler should remove declarations marked as @internal
* @param { boolean } opts.noMapRoot : true if compiler omit mapRoot option
2014-12-11 01:42:41 +01:00
* @param callback : a function to execute after the compilation process ends
2014-07-13 01:04:16 +02:00
* /
2016-02-10 09:20:40 +01:00
function compileFile ( outFile , sources , prereqs , prefixes , useBuiltCompiler , opts , callback ) {
2014-07-13 01:04:16 +02:00
file ( outFile , prereqs , function ( ) {
2015-09-18 22:13:26 +02:00
var compilerPath = useBuiltCompiler ? builtLocalCompiler : LKGCompiler ;
2015-11-03 01:57:07 +01:00
var options = "--noImplicitAny --noEmitOnError --pretty" ;
2016-02-10 09:20:40 +01:00
opts = opts || { } ;
2015-04-01 03:00:02 +02:00
// Keep comments when specifically requested
// or when in debug mode.
2016-02-10 09:20:40 +01:00
if ( ! ( opts . keepComments || useDebugMode ) ) {
2015-04-01 03:00:02 +02:00
options += " --removeComments" ;
2014-12-11 01:42:41 +01:00
}
2016-02-10 09:20:40 +01:00
if ( opts . generateDeclarations ) {
2014-12-11 01:42:41 +01:00
options += " --declaration" ;
2014-10-08 05:51:23 +02:00
}
2014-11-04 20:27:34 +01:00
2016-02-10 09:20:40 +01:00
if ( opts . preserveConstEnums || useDebugMode ) {
2014-12-11 01:42:41 +01:00
options += " --preserveConstEnums" ;
}
2016-02-10 09:20:40 +01:00
if ( opts . outDir ) {
options += " --outDir " + opts . outDir ;
2014-12-11 01:42:41 +01:00
}
2016-02-10 09:20:40 +01:00
if ( ! opts . noOutFile ) {
2014-12-11 01:42:41 +01:00
options += " --out " + outFile ;
2015-10-21 00:14:18 +02:00
}
else {
2016-04-09 00:37:13 +02:00
options += " --module commonjs" ;
2014-12-11 01:42:41 +01:00
}
2016-02-10 09:20:40 +01:00
if ( opts . noResolve ) {
2014-12-11 01:42:41 +01:00
options += " --noResolve" ;
2014-07-13 01:04:16 +02:00
}
2014-08-04 21:06:50 +02:00
2014-07-13 01:04:16 +02:00
if ( useDebugMode ) {
2016-02-10 09:20:40 +01:00
options += " -sourcemap" ;
if ( ! opts . noMapRoot ) {
options += " -mapRoot file:///" + path . resolve ( path . dirname ( outFile ) ) ;
}
2014-07-13 01:04:16 +02:00
}
2014-12-11 01:42:41 +01:00
2016-02-10 09:20:40 +01:00
if ( opts . stripInternal ) {
2016-04-09 00:37:13 +02:00
options += " --stripInternal" ;
2015-02-03 22:47:46 +01:00
}
2016-04-09 00:31:31 +02:00
if ( useBuiltCompiler && ! environmentVariableIsDisabled ( "USE_TRANSFORMS" ) ) {
2016-04-08 02:07:12 +02:00
console . warn ( "\u001b[93mwarning: 'USE_TRANSFORMS' environment variable is not set to 'false'. Experimental transforms will be enabled by default.\u001b[0m" ) ;
2016-02-23 01:10:32 +01:00
}
2015-09-18 22:13:26 +02:00
var cmd = host + " " + compilerPath + " " + options + " " ;
2014-12-11 01:42:41 +01:00
cmd = cmd + sources . join ( " " ) ;
2015-03-04 07:12:06 +01:00
console . log ( cmd + "\n" ) ;
2014-12-11 01:42:41 +01:00
2015-03-04 07:12:06 +01:00
var ex = jake . createExec ( [ cmd ] ) ;
// Add listeners for output and error
ex . addListener ( "stdout" , function ( output ) {
process . stdout . write ( output ) ;
} ) ;
ex . addListener ( "stderr" , function ( error ) {
process . stderr . write ( error ) ;
} ) ;
ex . addListener ( "cmdEnd" , function ( ) {
2014-07-13 01:04:16 +02:00
if ( ! useDebugMode && prefixes && fs . existsSync ( outFile ) ) {
for ( var i in prefixes ) {
prependFile ( prefixes [ i ] , outFile ) ;
}
}
2014-12-02 00:32:52 +01:00
if ( callback ) {
callback ( ) ;
}
2015-03-04 07:12:06 +01:00
complete ( ) ;
} ) ;
ex . addListener ( "error" , function ( ) {
2014-07-13 01:04:16 +02:00
fs . unlinkSync ( outFile ) ;
2014-12-12 17:49:21 +01:00
fail ( "Compilation of " + outFile + " unsuccessful" ) ;
2014-07-13 01:04:16 +02:00
} ) ;
2015-03-04 07:12:06 +01:00
ex . run ( ) ;
2014-07-13 01:04:16 +02:00
} , { async : true } ) ;
}
// Prerequisite task for built directory and library typings
directory ( builtLocalDirectory ) ;
for ( var i in libraryTargets ) {
( function ( i ) {
var entry = librarySourceMap [ i ] ;
var target = libraryTargets [ i ] ;
var sources = [ copyright ] . concat ( entry . sources . map ( function ( s ) {
return path . join ( libraryDirectory , s ) ;
} ) ) ;
file ( target , [ builtLocalDirectory ] . concat ( sources ) , function ( ) {
concatenateFiles ( target , sources ) ;
} ) ;
} ) ( i ) ;
}
// Lib target to build the library files
desc ( "Builds the library targets" ) ;
task ( "lib" , libraryTargets ) ;
// Generate diagnostics
var processDiagnosticMessagesJs = path . join ( scriptsDirectory , "processDiagnosticMessages.js" ) ;
var processDiagnosticMessagesTs = path . join ( scriptsDirectory , "processDiagnosticMessages.ts" ) ;
var diagnosticMessagesJson = path . join ( compilerDirectory , "diagnosticMessages.json" ) ;
var diagnosticInfoMapTs = path . join ( compilerDirectory , "diagnosticInformationMap.generated.ts" ) ;
2015-10-27 21:20:12 +01:00
var generatedDiagnosticMessagesJSON = path . join ( compilerDirectory , "diagnosticMessages.generated.json" ) ;
var builtGeneratedDiagnosticMessagesJSON = path . join ( builtLocalDirectory , "diagnosticMessages.generated.json" ) ;
2014-07-13 01:04:16 +02:00
2015-07-15 21:56:00 +02:00
file ( processDiagnosticMessagesTs ) ;
2014-08-01 02:20:57 +02:00
2014-07-13 01:04:16 +02:00
// processDiagnosticMessages script
compileFile ( processDiagnosticMessagesJs ,
[ processDiagnosticMessagesTs ] ,
[ processDiagnosticMessagesTs ] ,
[ ] ,
2014-12-02 00:32:52 +01:00
/*useBuiltCompiler*/ false ) ;
2014-07-13 01:04:16 +02:00
// The generated diagnostics map; built for the compiler and for the 'generate-diagnostics' task
file ( diagnosticInfoMapTs , [ processDiagnosticMessagesJs , diagnosticMessagesJson ] , function ( ) {
2015-09-18 22:13:26 +02:00
var cmd = host + " " + processDiagnosticMessagesJs + " " + diagnosticMessagesJson ;
2015-03-04 07:12:06 +01:00
console . log ( cmd ) ;
var ex = jake . createExec ( [ cmd ] ) ;
// Add listeners for output and error
ex . addListener ( "stdout" , function ( output ) {
process . stdout . write ( output ) ;
} ) ;
ex . addListener ( "stderr" , function ( error ) {
process . stderr . write ( error ) ;
} ) ;
ex . addListener ( "cmdEnd" , function ( ) {
complete ( ) ;
} ) ;
ex . run ( ) ;
2015-07-30 17:00:29 +02:00
} , { async : true } ) ;
2014-07-13 01:04:16 +02:00
2015-10-27 22:16:05 +01:00
file ( builtGeneratedDiagnosticMessagesJSON , [ generatedDiagnosticMessagesJSON ] , function ( ) {
if ( fs . existsSync ( builtLocalDirectory ) ) {
jake . cpR ( generatedDiagnosticMessagesJSON , builtGeneratedDiagnosticMessagesJSON ) ;
}
2015-10-28 19:40:33 +01:00
} ) ;
2015-10-27 22:16:05 +01:00
2014-07-13 01:04:16 +02:00
desc ( "Generates a diagnostic file in TypeScript based on an input JSON file" ) ;
2015-07-30 17:00:29 +02:00
task ( "generate-diagnostics" , [ diagnosticInfoMapTs ] ) ;
2014-07-13 01:04:16 +02:00
2015-07-15 21:56:00 +02:00
// Publish nightly
var configureNightlyJs = path . join ( scriptsDirectory , "configureNightly.js" ) ;
var configureNightlyTs = path . join ( scriptsDirectory , "configureNightly.ts" ) ;
var packageJson = "package.json" ;
2015-07-23 21:53:41 +02:00
var programTs = path . join ( compilerDirectory , "program.ts" ) ;
2015-07-15 21:56:00 +02:00
file ( configureNightlyTs ) ;
compileFile ( /*outfile*/ configureNightlyJs ,
/*sources*/ [ configureNightlyTs ] ,
/*prereqs*/ [ configureNightlyTs ] ,
/*prefixes*/ [ ] ,
/*useBuiltCompiler*/ false ,
2016-02-10 09:20:40 +01:00
{ noOutFile : false , generateDeclarations : false , keepComments : false , noResolve : false , stripInternal : false } ) ;
2015-07-23 21:32:17 +02:00
task ( "setDebugMode" , function ( ) {
2015-07-15 21:56:00 +02:00
useDebugMode = true ;
} ) ;
2015-07-23 21:32:17 +02:00
task ( "configure-nightly" , [ configureNightlyJs ] , function ( ) {
2015-09-18 22:13:26 +02:00
var cmd = host + " " + configureNightlyJs + " " + packageJson + " " + programTs ;
2015-07-23 21:32:17 +02:00
console . log ( cmd ) ;
exec ( cmd ) ;
} , { async : true } ) ;
2015-07-15 21:56:00 +02:00
desc ( "Configure, build, test, and publish the nightly release." ) ;
2015-07-23 21:32:17 +02:00
task ( "publish-nightly" , [ "configure-nightly" , "LKG" , "clean" , "setDebugMode" , "runtests" ] , function ( ) {
var cmd = "npm publish --tag next" ;
2015-07-15 21:56:00 +02:00
console . log ( cmd ) ;
2015-07-23 21:32:17 +02:00
exec ( cmd ) ;
} ) ;
2015-07-15 21:56:00 +02:00
2015-09-18 02:55:07 +02:00
var scriptsTsdJson = path . join ( scriptsDirectory , "tsd.json" ) ;
file ( scriptsTsdJson ) ;
task ( "tsd-scripts" , [ scriptsTsdJson ] , function ( ) {
var cmd = "tsd --config " + scriptsTsdJson + " install" ;
2016-04-09 00:37:13 +02:00
console . log ( cmd ) ;
2015-09-18 02:55:07 +02:00
exec ( cmd ) ;
2016-04-09 00:37:13 +02:00
} , { async : true } ) ;
2015-09-18 02:55:07 +02:00
var importDefinitelyTypedTestsDirectory = path . join ( scriptsDirectory , "importDefinitelyTypedTests" ) ;
var importDefinitelyTypedTestsJs = path . join ( importDefinitelyTypedTestsDirectory , "importDefinitelyTypedTests.js" ) ;
var importDefinitelyTypedTestsTs = path . join ( importDefinitelyTypedTestsDirectory , "importDefinitelyTypedTests.ts" ) ;
2015-09-18 22:13:26 +02:00
file ( importDefinitelyTypedTestsTs ) ;
file ( importDefinitelyTypedTestsJs , [ "tsd-scripts" , importDefinitelyTypedTestsTs ] , function ( ) {
var cmd = host + " " + LKGCompiler + " -p " + importDefinitelyTypedTestsDirectory ;
2015-09-18 02:55:07 +02:00
console . log ( cmd ) ;
exec ( cmd ) ;
2015-09-18 22:13:26 +02:00
} , { async : true } ) ;
task ( "importDefinitelyTypedTests" , [ importDefinitelyTypedTestsJs ] , function ( ) {
var cmd = host + " " + importDefinitelyTypedTestsJs + " ./ ../DefinitelyTyped" ;
console . log ( cmd ) ;
exec ( cmd ) ;
} , { async : true } ) ;
2015-09-18 02:55:07 +02:00
2014-07-13 01:04:16 +02:00
// Local target to build the compiler and services
2014-09-02 21:19:58 +02:00
var tscFile = path . join ( builtLocalDirectory , compilerFilename ) ;
2014-08-07 08:21:53 +02:00
compileFile ( tscFile , compilerSources , [ builtLocalDirectory , copyright ] . concat ( compilerSources ) , [ copyright ] , /*useBuiltCompiler:*/ false ) ;
2014-07-13 01:04:16 +02:00
2014-08-07 08:21:53 +02:00
var servicesFile = path . join ( builtLocalDirectory , "typescriptServices.js" ) ;
2016-02-10 09:20:40 +01:00
var servicesFileInBrowserTest = path . join ( builtLocalDirectory , "typescriptServicesInBrowserTest.js" ) ;
2015-04-09 23:15:07 +02:00
var standaloneDefinitionsFile = path . join ( builtLocalDirectory , "typescriptServices.d.ts" ) ;
2015-02-01 06:14:28 +01:00
var nodePackageFile = path . join ( builtLocalDirectory , "typescript.js" ) ;
2015-04-09 23:15:07 +02:00
var nodeDefinitionsFile = path . join ( builtLocalDirectory , "typescript.d.ts" ) ;
2015-09-08 21:26:29 +02:00
var nodeStandaloneDefinitionsFile = path . join ( builtLocalDirectory , "typescript_standalone.d.ts" ) ;
2015-04-09 23:15:07 +02:00
2014-12-13 01:17:30 +01:00
compileFile ( servicesFile , servicesSources , [ builtLocalDirectory , copyright ] . concat ( servicesSources ) ,
/*prefixes*/ [ copyright ] ,
/*useBuiltCompiler*/ true ,
2016-02-10 09:20:40 +01:00
{ noOutFile : false , generateDeclarations : true , preserveConstEnums : true , keepComments : true , noResolve : false , stripInternal : true } ,
2015-07-10 01:39:58 +02:00
/*callback*/ function ( ) {
2015-02-01 06:14:28 +01:00
jake . cpR ( servicesFile , nodePackageFile , { silent : true } ) ;
2014-12-02 00:32:52 +01:00
2015-04-09 23:15:07 +02:00
prependFile ( copyright , standaloneDefinitionsFile ) ;
2014-12-11 01:42:41 +01:00
2015-09-08 21:26:29 +02:00
// Stanalone/web definition file using global 'ts' namespace
2015-04-09 23:15:07 +02:00
jake . cpR ( standaloneDefinitionsFile , nodeDefinitionsFile , { silent : true } ) ;
var definitionFileContents = fs . readFileSync ( nodeDefinitionsFile ) . toString ( ) ;
2015-10-27 21:48:37 +01:00
definitionFileContents = definitionFileContents . replace ( /^(\s*)(export )?const enum (\S+) {(\s*)$/gm , '$1$2enum $3 {$4' ) ;
fs . writeFileSync ( standaloneDefinitionsFile , definitionFileContents ) ;
2015-09-08 21:26:29 +02:00
// Official node package definition file, pointed to by 'typings' in package.json
// Created by appending 'export = ts;' at the end of the standalone file to turn it into an external module
var nodeDefinitionsFileContents = definitionFileContents + "\r\nexport = ts;" ;
fs . writeFileSync ( nodeDefinitionsFile , nodeDefinitionsFileContents ) ;
2015-11-24 07:38:05 +01:00
// Node package definition file to be distributed without the package. Created by replacing
2015-09-08 21:26:29 +02:00
// 'ts' namespace with '"typescript"' as a module.
var nodeStandaloneDefinitionsFileContents = definitionFileContents . replace ( /declare (namespace|module) ts/g , 'declare module "typescript"' ) ;
fs . writeFileSync ( nodeStandaloneDefinitionsFile , nodeStandaloneDefinitionsFileContents ) ;
2015-04-09 23:15:07 +02:00
} ) ;
2014-12-11 01:42:41 +01:00
2016-02-10 09:20:40 +01:00
compileFile ( servicesFileInBrowserTest , servicesSources , [ builtLocalDirectory , copyright ] . concat ( servicesSources ) ,
/*prefixes*/ [ copyright ] ,
/*useBuiltCompiler*/ true ,
{ noOutFile : false , generateDeclarations : true , preserveConstEnums : true , keepComments : true , noResolve : false , stripInternal : true , noMapRoot : true } ,
/*callback*/ function ( ) {
var content = fs . readFileSync ( servicesFileInBrowserTest ) . toString ( ) ;
var i = content . lastIndexOf ( "\n" ) ;
fs . writeFileSync ( servicesFileInBrowserTest , content . substring ( 0 , i ) + "\r\n//# sourceURL=../built/local/typeScriptServices.js" + content . substring ( i ) ) ;
} ) ;
2016-03-21 19:54:10 +01:00
2014-07-13 01:04:16 +02:00
2015-02-16 03:52:17 +01:00
var serverFile = path . join ( builtLocalDirectory , "tsserver.js" ) ;
2015-02-12 04:43:10 +01:00
compileFile ( serverFile , serverSources , [ builtLocalDirectory , copyright ] . concat ( serverSources ) , /*prefixes*/ [ copyright ] , /*useBuiltCompiler*/ true ) ;
2016-05-19 22:32:27 +02:00
var tsserverLibraryFile = path . join ( builtLocalDirectory , "tsserverlibrary.js" ) ;
2016-05-21 21:36:06 +02:00
var tsserverLibraryDefinitionFile = path . join ( builtLocalDirectory , "tsserverlibrary.d.ts" ) ;
2015-06-10 02:00:35 +02:00
compileFile (
2016-05-19 22:31:21 +02:00
tsserverLibraryFile ,
2015-07-10 01:39:58 +02:00
languageServiceLibrarySources ,
2015-06-17 21:39:02 +02:00
[ builtLocalDirectory , copyright ] . concat ( languageServiceLibrarySources ) ,
2015-07-10 01:39:58 +02:00
/*prefixes*/ [ copyright ] ,
/*useBuiltCompiler*/ true ,
2016-02-10 09:20:40 +01:00
{ noOutFile : false , generateDeclarations : true } ) ;
2015-06-10 02:00:35 +02:00
// Local target to build the language service server library
desc ( "Builds language service server library" ) ;
2016-05-21 21:36:06 +02:00
task ( "lssl" , [ tsserverLibraryFile , tsserverLibraryDefinitionFile ] ) ;
2015-06-10 02:00:35 +02:00
2014-07-13 01:04:16 +02:00
// Local target to build the compiler and services
desc ( "Builds the full compiler and services" ) ;
2015-10-27 22:16:05 +01:00
task ( "local" , [ "generate-diagnostics" , "lib" , tscFile , servicesFile , nodeDefinitionsFile , serverFile , builtGeneratedDiagnosticMessagesJSON ] ) ;
2014-07-13 01:04:16 +02:00
2015-02-04 14:52:45 +01:00
// Local target to build only tsc.js
desc ( "Builds only the compiler" ) ;
task ( "tsc" , [ "generate-diagnostics" , "lib" , tscFile ] ) ;
2014-07-13 01:04:16 +02:00
// Local target to build the compiler and services
2014-11-04 21:18:32 +01:00
desc ( "Sets release mode flag" ) ;
task ( "release" , function ( ) {
useDebugMode = false ;
2014-07-13 01:04:16 +02:00
} ) ;
// Set the default task to "local"
task ( "default" , [ "local" ] ) ;
// Cleans the built directory
desc ( "Cleans the compiler output, declare files, and tests" ) ;
task ( "clean" , function ( ) {
jake . rmRf ( builtDirectory ) ;
} ) ;
2014-09-26 23:36:18 +02:00
// Generate Markdown spec
var word2mdJs = path . join ( scriptsDirectory , "word2md.js" ) ;
var word2mdTs = path . join ( scriptsDirectory , "word2md.ts" ) ;
var specWord = path . join ( docDirectory , "TypeScript Language Specification.docx" ) ;
var specMd = path . join ( docDirectory , "spec.md" ) ;
file ( word2mdTs ) ;
// word2md script
compileFile ( word2mdJs ,
[ word2mdTs ] ,
[ word2mdTs ] ,
[ ] ,
2014-12-02 00:32:52 +01:00
/*useBuiltCompiler*/ false ) ;
2014-09-26 23:36:18 +02:00
// The generated spec.md; built for the 'generate-spec' task
file ( specMd , [ word2mdJs , specWord ] , function ( ) {
2014-10-08 05:51:23 +02:00
var specWordFullPath = path . resolve ( specWord ) ;
2015-12-08 22:55:59 +01:00
var specMDFullPath = path . resolve ( specMd ) ;
var cmd = "cscript //nologo " + word2mdJs + ' "' + specWordFullPath + '" ' + '"' + specMDFullPath + '"' ;
2015-03-04 07:12:06 +01:00
console . log ( cmd ) ;
child_process . exec ( cmd , function ( ) {
complete ( ) ;
} ) ;
2015-07-30 17:00:29 +02:00
} , { async : true } ) ;
2014-09-26 23:36:18 +02:00
desc ( "Generates a Markdown version of the Language Specification" ) ;
2015-07-30 17:00:29 +02:00
task ( "generate-spec" , [ specMd ] ) ;
2014-09-26 23:36:18 +02:00
2014-07-13 01:04:16 +02:00
// Makes a new LKG. This target does not build anything, but errors if not all the outputs are present in the built/local directory
desc ( "Makes a new LKG out of the built js files" ) ;
2016-05-19 22:16:24 +02:00
task ( "LKG" , [ "clean" , "release" , "local" , "lssl" ] . concat ( libraryTargets ) , function ( ) {
2016-05-21 21:36:06 +02:00
var expectedFiles = [ tscFile , servicesFile , serverFile , nodePackageFile , nodeDefinitionsFile , standaloneDefinitionsFile , tsserverLibraryFile , tsserverLibraryDefinitionFile ] . concat ( libraryTargets ) ;
2014-07-13 01:04:16 +02:00
var missingFiles = expectedFiles . filter ( function ( f ) {
return ! fs . existsSync ( f ) ;
} ) ;
if ( missingFiles . length > 0 ) {
fail ( "Cannot replace the LKG unless all built targets are present in directory " + builtLocalDirectory +
". The following files are missing:\n" + missingFiles . join ( "\n" ) ) ;
}
// Copy all the targets into the LKG directory
jake . mkdirP ( LKGDirectory ) ;
for ( i in expectedFiles ) {
jake . cpR ( expectedFiles [ i ] , LKGDirectory ) ;
}
//var resourceDirectories = fs.readdirSync(builtLocalResourcesDirectory).map(function(p) { return path.join(builtLocalResourcesDirectory, p); });
//resourceDirectories.map(function(d) {
// jake.cpR(d, LKGResourcesDirectory);
//});
} ) ;
// Test directory
directory ( builtLocalDirectory ) ;
// Task to build the tests infrastructure using the built compiler
var run = path . join ( builtLocalDirectory , "run.js" ) ;
2014-08-07 08:21:53 +02:00
compileFile ( run , harnessSources , [ builtLocalDirectory , tscFile ] . concat ( libraryTargets ) . concat ( harnessSources ) , [ ] , /*useBuiltCompiler:*/ true ) ;
2014-07-13 01:04:16 +02:00
2016-04-09 00:37:13 +02:00
var internalTests = "internal/" ;
2015-01-30 19:32:07 +01:00
2014-07-13 01:04:16 +02:00
var localBaseline = "tests/baselines/local/" ;
var refBaseline = "tests/baselines/reference/" ;
2015-02-02 21:52:26 +01:00
var localRwcBaseline = path . join ( internalTests , "baselines/rwc/local" ) ;
var refRwcBaseline = path . join ( internalTests , "baselines/rwc/reference" ) ;
2014-07-13 01:04:16 +02:00
2015-02-02 21:52:26 +01:00
var localTest262Baseline = path . join ( internalTests , "baselines/test262/local" ) ;
var refTest262Baseline = path . join ( internalTests , "baselines/test262/reference" ) ;
2014-11-17 20:01:05 +01:00
2014-07-13 01:04:16 +02:00
desc ( "Builds the test infrastructure using the built compiler" ) ;
task ( "tests" , [ "local" , run ] . concat ( libraryTargets ) ) ;
2015-07-10 01:39:58 +02:00
function exec ( cmd , completeHandler , errorHandler ) {
2015-03-04 07:12:06 +01:00
var ex = jake . createExec ( [ cmd ] , { windowsVerbatimArguments : true } ) ;
// Add listeners for output and error
ex . addListener ( "stdout" , function ( output ) {
process . stdout . write ( output ) ;
} ) ;
ex . addListener ( "stderr" , function ( error ) {
process . stderr . write ( error ) ;
} ) ;
2014-07-13 01:04:16 +02:00
ex . addListener ( "cmdEnd" , function ( ) {
2014-07-17 21:32:51 +02:00
if ( completeHandler ) {
completeHandler ( ) ;
}
2015-03-04 07:12:06 +01:00
complete ( ) ;
2014-07-13 01:04:16 +02:00
} ) ;
2015-03-04 07:12:06 +01:00
ex . addListener ( "error" , function ( e , status ) {
2015-07-10 01:39:58 +02:00
if ( errorHandler ) {
errorHandler ( e , status ) ;
} else {
fail ( "Process exited with code " + status ) ;
}
} ) ;
2014-12-17 00:28:36 +01:00
ex . run ( ) ;
2014-07-13 01:04:16 +02:00
}
function cleanTestDirs() {
// Clean the local baselines directory
if ( fs . existsSync ( localBaseline ) ) {
jake . rmRf ( localBaseline ) ;
}
2015-01-30 19:32:07 +01:00
// Clean the local Rwc baselines directory
2014-07-13 01:04:16 +02:00
if ( fs . existsSync ( localRwcBaseline ) ) {
jake . rmRf ( localRwcBaseline ) ;
}
2015-01-30 19:32:07 +01:00
jake . mkdirP ( localRwcBaseline ) ;
2015-03-19 00:37:52 +01:00
jake . mkdirP ( localTest262Baseline ) ;
2014-07-13 01:04:16 +02:00
jake . mkdirP ( localBaseline ) ;
}
// used to pass data from jake command line directly to run.js
2016-06-01 03:43:51 +02:00
function writeTestConfigFile ( tests , light , taskConfigFolder , workerCount , stackTraceLimit ) {
2016-03-26 02:49:50 +01:00
var testConfig ;
if ( tests ) {
2016-06-01 03:43:51 +02:00
( testConfig || ( testConfig = { } ) ) . test = [ tests ] ;
2016-03-26 02:49:50 +01:00
}
if ( light ) {
( testConfig || ( testConfig = { } ) ) . light = light ;
}
2016-06-01 03:43:51 +02:00
if ( workerCount ) {
( testConfig || ( testConfig = { } ) ) . workerCount = workerCount ;
}
if ( taskConfigFolder ) {
( testConfig || ( testConfig = { } ) ) . taskConfigFolder = taskConfigFolder ;
}
2016-03-24 21:32:41 +01:00
if ( /^(\d+|full)$/ . test ( stackTraceLimit ) ) {
2016-03-26 02:49:50 +01:00
( testConfig || ( testConfig = { } ) ) . stackTraceLimit = stackTraceLimit ;
2016-03-24 21:32:41 +01:00
}
2016-03-26 02:49:50 +01:00
if ( testConfig ) {
var testConfigContents = JSON . stringify ( testConfig ) ;
2016-06-01 03:43:51 +02:00
console . log ( 'Running tests with config: ' + testConfigContents ) ;
fs . writeFileSync ( 'test.config' , testConfigContents ) ;
2016-03-26 02:49:50 +01:00
}
2014-07-13 01:04:16 +02:00
}
2014-07-17 21:32:51 +02:00
function deleteTemporaryProjectOutput() {
2015-02-02 21:52:26 +01:00
if ( fs . existsSync ( path . join ( localBaseline , "projectOutput/" ) ) ) {
jake . rmRf ( path . join ( localBaseline , "projectOutput/" ) ) ;
2014-07-17 21:32:51 +02:00
}
}
2016-05-26 10:16:29 +02:00
function runTestsAndWriteOutput ( file , defaultSubsets ) {
2016-03-24 21:32:41 +01:00
cleanTestDirs ( ) ;
var tests = process . env . test || process . env . tests || process . env . t ;
var light = process . env . light || false ;
var testConfigFile = 'test.config' ;
if ( fs . existsSync ( testConfigFile ) ) {
fs . unlinkSync ( testConfigFile ) ;
}
2016-03-26 02:49:50 +01:00
writeTestConfigFile ( testConfigFile , tests , light , 10 ) ;
2016-03-24 21:32:41 +01:00
if ( tests && tests . toLocaleLowerCase ( ) === "rwc" ) {
testTimeout = 100000 ;
}
2016-05-26 10:16:29 +02:00
var subsetRegexes ;
var subsets ;
2016-05-27 07:12:22 +02:00
if ( tests || defaultSubsets . length === 0 ) {
2016-05-26 10:16:29 +02:00
subsetRegexes = [ tests ] ;
subsets = [ tests ] ;
}
else {
2016-05-27 07:12:22 +02:00
subsets = [ ] ;
subsetRegexes = [ ] ;
negations = [ ] ;
2016-06-02 19:57:28 +02:00
for ( var i = 0 ; i < defaultSubsets . length ; ++ i ) {
var subset = defaultSubsets [ i ] ;
2016-05-27 07:12:22 +02:00
subsets . push ( subset . name ) ;
subsetRegexes . push ( subset . pattern ) ;
negations . push ( subset . pattern ) ;
}
2016-05-26 10:16:29 +02:00
subsets . push ( "other" ) ;
2016-05-27 07:12:22 +02:00
subsetRegexes . push ( "^(?!" + negations . join ( "|" ) + ")" ) ;
2016-03-24 21:32:41 +01:00
}
2016-03-26 02:49:50 +01:00
2016-03-24 21:32:41 +01:00
var out = fs . createWriteStream ( file ) ;
2016-05-26 10:16:29 +02:00
var outFileNames = subsetRegexes . length !== 1 ? [ ] : undefined ;
2016-03-24 21:32:41 +01:00
var tapRange = /^(\d+)\.\.(\d+)(?:$|\r\n?|\n)/ ;
var tapOk = /^ok\s/ ;
2016-03-26 02:49:50 +01:00
var tapNotOk = /^not\sok\s/ ;
2016-05-26 10:16:29 +02:00
var tapComment = /^#(?: (tests|pass|fail) (\d+)$)?/ ;
2016-03-24 21:32:41 +01:00
var typeError = /^\s+TypeError:/ ;
2016-03-25 01:48:31 +01:00
var debugError = /^\s+Error:\sDebug\sFailure\./ ;
2016-05-26 10:16:29 +02:00
var progress = new ProgressBar ( ) ;
var totalTypeErrorCount = 0 ;
var totalDebugErrorCount = 0 ;
var totalReportedTestCount = 0 ;
var totalReportedPassCount = 0 ;
var totalReportedFailCount = 0 ;
var counter = subsetRegexes . length ;
var errorStatus ;
subsetRegexes . forEach ( function ( subsetRegex , i ) {
var expectedTestCount = 0 ;
var testCount = 0 ;
var failureCount = 0 ;
var successCount = 0 ;
var reportedTestCount = 0 ;
var reportedPassCount = 0 ;
var reportedFailCount = 0 ;
var comments = [ ] ;
var typeErrorCount = 0 ;
var debugErrorCount = 0 ;
var outFileName ;
var outFile ;
if ( subsetRegexes . length === 1 ) {
outFile = out ;
}
else {
outFileName = path . join ( os . tmpdir ( ) , path . basename ( file ) + "." + i ) ;
outFileNames [ i ] = outFileName ;
outFile = fs . createWriteStream ( outFileName ) ;
2016-03-24 21:32:41 +01:00
}
2016-05-26 10:16:29 +02:00
var args = [ ] ;
args . push ( "-R" , "tap" ) ;
args . push ( "--no-colors" ) ;
args . push ( "-t" , testTimeout ) ;
if ( subsetRegex ) {
args . push ( "-g" , '"' + subsetRegex + '"' ) ;
2016-03-24 21:32:41 +01:00
}
2016-05-26 10:16:29 +02:00
args . push ( run ) ;
var cmd = "mocha " + args . join ( " " ) ;
if ( subsetRegexes . length === 1 ) {
console . log ( cmd ) ;
2016-03-24 21:32:41 +01:00
}
2016-05-26 10:16:29 +02:00
updateProgress ( 0 ) ;
var p = child_process . spawn (
process . platform === "win32" ? "cmd" : "/bin/sh" ,
process . platform === "win32" ? [ "/c" , cmd ] : [ "-c" , cmd ] , {
windowsVerbatimArguments : true ,
env : { NODE_ENV : "development" }
} ) ;
var rl = readline . createInterface ( {
input : p.stdout ,
terminal : false
} ) ;
var start ;
var end ;
rl . on ( "line" , function ( line ) {
if ( ! start ) start = Date . now ( ) ;
var m = tapRange . exec ( line ) ;
if ( m ) {
expectedTestCount = parseInt ( m [ 2 ] ) ;
return ;
2016-03-24 21:32:41 +01:00
}
2016-05-26 10:16:29 +02:00
if ( tapOk . test ( line ) ) {
outFile . write ( line . replace ( /^ok\s+\d+\s+/ , "ok " ) + os . EOL ) ;
successCount ++ ;
2016-03-24 21:32:41 +01:00
}
2016-05-26 10:16:29 +02:00
else if ( tapNotOk . test ( line ) ) {
outFile . write ( line . replace ( /^not\s+ok\s+\d+\s+/ , "not ok " ) + os . EOL ) ;
failureCount ++ ;
2016-03-25 01:48:31 +01:00
}
2016-05-26 10:16:29 +02:00
else {
m = tapComment . exec ( line ) ;
if ( m ) {
if ( m [ 1 ] === "tests" ) {
end = Date . now ( ) ;
reportedTestCount = parseInt ( m [ 2 ] ) ;
}
else if ( m [ 1 ] === "pass" ) {
reportedPassCount = parseInt ( m [ 2 ] ) ;
}
else if ( m [ 1 ] === "fail" ) {
reportedFailCount = parseInt ( m [ 2 ] ) ;
}
else {
outFile . write ( line + os . EOL ) ;
}
}
else {
outFile . write ( line + os . EOL ) ;
if ( typeError . test ( line ) ) {
typeErrorCount ++ ;
}
else if ( debugError . test ( line ) ) {
debugErrorCount ++ ;
}
}
return ;
}
testCount ++ ;
var percentComplete = testCount * 100 / expectedTestCount ;
updateProgress ( percentComplete ) ;
} ) ;
2016-03-24 21:32:41 +01:00
2016-05-26 10:16:29 +02:00
p . on ( "exit" , function ( status ) {
totalReportedTestCount += reportedTestCount ;
totalReportedPassCount += reportedPassCount ;
totalReportedFailCount += reportedFailCount ;
totalTypeErrorCount += typeErrorCount ;
totalDebugErrorCount += debugErrorCount ;
2016-03-24 21:32:41 +01:00
2016-05-26 10:16:29 +02:00
var duration = end - start ;
var summary =
"pass: " + reportedPassCount + "/" + reportedTestCount +
", duration: " + ( duration / 1000 ) . toFixed ( 2 ) + "s" ;
updateProgress ( 100 , summary ) ;
if ( subsetRegexes . length !== 1 ) {
outFile . close ( ) ;
}
if ( status && ! errorStatus ) {
errorStatus = status ;
}
counter -- ;
if ( counter === 0 ) {
if ( subsetRegexes . length !== 1 ) {
concatenate ( ) ;
}
else {
finish ( ) ;
}
}
} ) ;
function updateProgress ( percentComplete , status ) {
var title = status || ( percentComplete < 100 ? "running..." : "done" ) ;
if ( subsetRegexes . length !== 1 ) {
title = "[" + subsets [ i ] + "] " + title ;
}
progress . update ( percentComplete ,
/*foregroundColor*/ failureCount > 0
? "red"
: successCount === expectedTestCount
? "green"
: "cyan" ,
/*backgroundColor*/ "gray" ,
title ,
i
) ;
}
2016-03-24 21:32:41 +01:00
} ) ;
2016-05-26 10:16:29 +02:00
function concatenate() {
if ( outFileNames . length > 0 ) {
var outFileName = outFileNames . shift ( ) ;
var outFile = fs . createReadStream ( outFileName ) ;
outFile . pipe ( out , { end : false } ) ;
outFile . on ( "end" , function ( ) {
fs . unlinkSync ( outFileName ) ;
concatenate ( ) ;
} ) ;
return ;
2016-03-24 21:32:41 +01:00
}
2016-05-26 10:16:29 +02:00
finish ( ) ;
}
2016-03-24 21:32:41 +01:00
2016-05-26 10:16:29 +02:00
function finish() {
out . write (
"# tests " + totalReportedTestCount + os . EOL +
"# pass " + totalReportedPassCount + os . EOL +
"# fail " + totalReportedFailCount + os . EOL ) ;
console . log ( "# tests " + totalReportedTestCount ) ;
console . log ( "# pass " + totalReportedPassCount ) ;
console . log ( "# fail " + totalReportedFailCount ) ;
if ( totalTypeErrorCount ) {
console . log ( "# type errors " + totalTypeErrorCount ) ;
2016-03-24 21:32:41 +01:00
}
2016-05-26 10:16:29 +02:00
if ( totalDebugErrorCount ) {
console . log ( "# debug errors " + totalDebugErrorCount ) ;
2016-03-25 01:48:31 +01:00
}
2016-03-24 21:32:41 +01:00
deleteTemporaryProjectOutput ( ) ;
2016-05-26 10:16:29 +02:00
if ( totalReportedFailCount ) {
fail ( "Test failures reported: " + totalReportedFailCount ) ;
2016-03-26 02:49:50 +01:00
}
else {
complete ( ) ;
}
2016-05-26 10:16:29 +02:00
}
2016-03-24 21:32:41 +01:00
}
2016-06-01 03:43:51 +02:00
function runConsoleTests ( defaultReporter , runInParallel , dirty ) {
2016-04-13 03:40:39 +02:00
if ( ! dirty ) {
cleanTestDirs ( ) ;
}
2015-09-05 03:01:43 +02:00
var debug = process . env . debug || process . env . d ;
2014-07-18 00:26:50 +02:00
tests = process . env . test || process . env . tests || process . env . t ;
2015-04-29 21:13:35 +02:00
var light = process . env . light || false ;
2016-03-25 22:29:22 +01:00
var stackTraceLimit = process . env . stackTraceLimit || 1 ;
2014-07-13 01:04:16 +02:00
var testConfigFile = 'test.config' ;
2016-04-09 00:31:31 +02:00
if ( fs . existsSync ( testConfigFile ) ) {
2014-07-13 01:04:16 +02:00
fs . unlinkSync ( testConfigFile ) ;
}
2016-05-24 01:00:56 +02:00
var workerCount , taskConfigsFolder ;
if ( runInParallel ) {
// generate name to store task configuration files
var prefix = os . tmpdir ( ) + "/ts-tests" ;
var i = 1 ;
do {
taskConfigsFolder = prefix + i ;
i ++ ;
} while ( fs . existsSync ( taskConfigsFolder ) ) ;
fs . mkdirSync ( taskConfigsFolder ) ;
workerCount = process . env . workerCount || os . cpus ( ) . length ;
}
2014-09-03 19:37:32 +02:00
2016-05-24 01:00:56 +02:00
if ( tests || light || taskConfigsFolder ) {
2016-06-01 03:43:51 +02:00
writeTestConfigFile ( tests , light , taskConfigsFolder , workerCount , stackTraceLimit ) ;
2014-07-13 01:04:16 +02:00
}
2014-09-03 19:37:32 +02:00
if ( tests && tests . toLocaleLowerCase ( ) === "rwc" ) {
2015-02-19 22:52:50 +01:00
testTimeout = 100000 ;
2014-09-03 19:37:32 +02:00
}
2016-04-09 00:37:13 +02:00
colors = process . env . colors || process . env . color ;
2015-02-24 01:16:26 +01:00
colors = colors ? ' --no-colors ' : ' --colors ' ;
2015-10-26 18:25:01 +01:00
reporter = process . env . reporter || process . env . r || defaultReporter ;
2016-05-16 20:53:44 +02:00
var lintFlag = process . env . lint !== 'false' ;
2015-10-26 18:25:01 +01:00
2014-07-26 02:01:01 +02:00
// timeout normally isn't necessary but Travis-CI has been timing out on compiler baselines occasionally
// default timeout is 2sec which really should be enough, but maybe we just need a small amount longer
2016-05-24 01:00:56 +02:00
if ( ! runInParallel ) {
tests = tests ? ' -g "' + tests + '"' : '' ;
2015-10-24 01:27:44 +02:00
var cmd = "mocha" + ( debug ? " --debug-brk" : "" ) + " -R " + reporter + tests + colors + ' -t ' + testTimeout + ' ' + run ;
console . log ( cmd ) ;
2016-05-20 22:40:34 +02:00
exec ( cmd , function ( ) {
2016-05-24 23:29:52 +02:00
runLinter ( ) ;
2016-05-20 22:40:34 +02:00
finish ( ) ;
2016-05-26 01:23:51 +02:00
} , function ( e , status ) {
finish ( status ) ;
} ) ;
2016-06-01 03:43:51 +02:00
2015-10-26 18:25:01 +01:00
}
else {
2016-06-01 03:43:51 +02:00
// run task to load all tests and partition them between workers
2016-05-24 01:00:56 +02:00
var cmd = "mocha " + " -R min " + colors + run ;
2015-10-24 01:27:44 +02:00
console . log ( cmd ) ;
2016-05-24 01:00:56 +02:00
exec ( cmd , function ( ) {
// read all configuration files and spawn a worker for every config
var configFiles = fs . readdirSync ( taskConfigsFolder ) ;
var counter = configFiles . length ;
2016-05-26 01:23:51 +02:00
var firstErrorStatus ;
2016-05-24 01:00:56 +02:00
// schedule work for chunks
configFiles . forEach ( function ( f ) {
var configPath = path . join ( taskConfigsFolder , f ) ;
var workerCmd = "mocha" + " -t " + testTimeout + " -R " + reporter + " " + colors + " " + run + " --config='" + configPath + "'" ;
console . log ( workerCmd ) ;
2016-06-01 03:43:51 +02:00
exec ( workerCmd , finishWorker , finishWorker )
2016-05-24 01:00:56 +02:00
} ) ;
2016-05-25 09:06:47 +02:00
2016-05-27 18:51:30 +02:00
function finishWorker ( e , errorStatus ) {
2016-05-24 01:00:56 +02:00
counter -- ;
2016-05-26 01:23:51 +02:00
if ( firstErrorStatus === undefined && errorStatus !== undefined ) {
firstErrorStatus = errorStatus ;
2016-05-25 09:06:47 +02:00
}
2016-05-26 01:23:51 +02:00
if ( counter !== 0 ) {
2015-10-26 18:25:01 +01:00
complete ( ) ;
2016-05-25 23:14:32 +02:00
}
2016-05-26 01:23:51 +02:00
else {
// last worker clean everything and runs linter in case if there were no errors
2016-05-24 01:00:56 +02:00
deleteTemporaryProjectOutput ( ) ;
jake . rmRf ( taskConfigsFolder ) ;
2016-05-26 01:23:51 +02:00
if ( firstErrorStatus === undefined ) {
runLinter ( ) ;
2016-05-25 09:06:47 +02:00
complete ( ) ;
2016-05-26 01:23:51 +02:00
}
else {
failWithStatus ( firstErrorStatus ) ;
}
2016-05-24 01:00:56 +02:00
}
2015-10-26 18:25:01 +01:00
}
2016-05-24 01:00:56 +02:00
} ) ;
}
2016-06-01 03:43:51 +02:00
2016-05-26 01:23:51 +02:00
function failWithStatus ( status ) {
fail ( "Process exited with code " + status ) ;
}
2016-06-01 03:43:51 +02:00
2016-05-26 01:23:51 +02:00
function finish ( errorStatus ) {
2016-05-24 01:00:56 +02:00
deleteTemporaryProjectOutput ( ) ;
2016-05-26 01:23:51 +02:00
if ( errorStatus !== undefined ) {
failWithStatus ( errorStatus ) ;
2016-05-20 22:40:34 +02:00
}
2016-05-26 01:23:51 +02:00
else {
complete ( ) ;
}
2016-05-24 01:00:56 +02:00
}
function runLinter() {
2016-06-01 03:43:51 +02:00
if ( ! lintFlag || dirty ) {
2016-05-24 01:00:56 +02:00
return ;
}
var lint = jake . Task [ 'lint' ] ;
lint . addListener ( 'complete' , function ( ) {
complete ( ) ;
2015-10-02 21:45:33 +02:00
} ) ;
2016-05-24 01:00:56 +02:00
lint . invoke ( ) ;
}
2015-10-26 18:25:01 +01:00
}
var testTimeout = 20000 ;
desc ( "Runs all the tests in parallel using the built run.js file. Optional arguments are: t[ests]=category1|category2|... d[ebug]=true." ) ;
task ( "runtests-parallel" , [ "build-rules" , "tests" , builtLocalDirectory ] , function ( ) {
2016-05-24 01:00:56 +02:00
runConsoleTests ( 'min' , /*runInParallel*/ true ) ;
2015-10-24 01:27:44 +02:00
} , { async : true } ) ;
2016-05-16 20:53:44 +02:00
desc ( "Runs the tests using the built run.js file. Optional arguments are: t[ests]=regex r[eporter]=[list|spec|json|<more>] d[ebug]=true color[s]=false lint=true." ) ;
2015-10-03 01:21:20 +02:00
task ( "runtests" , [ "build-rules" , "tests" , builtLocalDirectory ] , function ( ) {
2016-05-24 01:00:56 +02:00
runConsoleTests ( 'mocha-fivemat-progress-reporter' , /*runInParallel*/ false ) ;
2014-07-13 01:04:16 +02:00
} , { async : true } ) ;
2016-03-24 21:32:41 +01:00
task ( "runtests-file" , [ "build-rules" , "tests" , builtLocalDirectory ] , function ( ) {
2016-05-27 07:12:22 +02:00
var subsets = [ ] ;
var cores = os . cpus ( ) . length ;
if ( cores > 1 ) {
subsets . push ( { name : "conformance" , pattern : "^conformance\\b" } ) ;
subsets . push ( { name : "compiler" , pattern : "^compiler\\b" } ) ;
subsets . push ( { name : "projects" , pattern : "^Projects\\b" } ) ;
if ( cores > 4 ) {
subsets . push ( { name : "fourslash" , pattern : "^fourslash\\b" } ) ;
subsets . push ( { name : "fourslash (shims, shims-pp, server)" , pattern : "^fourslash-" } ) ;
}
else {
subsets . push ( { name : "fourslash" , pattern : "^fourslash" } ) ;
}
}
runTestsAndWriteOutput ( "tests/baselines/local/testresults.tap" , subsets ) ;
2016-03-24 21:32:41 +01:00
} , { async : true } ) ;
2016-05-27 07:12:22 +02:00
2016-04-13 03:40:39 +02:00
task ( "runtests-dirty" , [ "build-rules" , "tests" , builtLocalDirectory ] , function ( ) {
2016-06-01 20:43:23 +02:00
runConsoleTests ( "mocha-fivemat-progress-reporter" , /*runInParallel*/ false , /*dirty*/ true ) ;
2016-04-13 03:40:39 +02:00
} , { async : true } ) ;
2016-03-24 21:32:41 +01:00
2015-07-30 17:00:29 +02:00
desc ( "Generates code coverage data via instanbul" ) ;
2014-07-25 01:03:13 +02:00
task ( "generate-code-coverage" , [ "tests" , builtLocalDirectory ] , function ( ) {
2014-09-02 23:22:14 +02:00
var cmd = 'istanbul cover node_modules/mocha/bin/_mocha -- -R min -t ' + testTimeout + ' ' + run ;
2015-03-04 07:12:06 +01:00
console . log ( cmd ) ;
2014-09-18 20:49:40 +02:00
exec ( cmd ) ;
2014-07-25 01:03:13 +02:00
} , { async : true } ) ;
2014-07-13 01:04:16 +02:00
// Browser tests
2016-05-19 22:31:21 +02:00
var nodeServerOutFile = "tests/webTestServer.js" ;
var nodeServerInFile = "tests/webTestServer.ts" ;
2016-02-10 09:20:40 +01:00
compileFile ( nodeServerOutFile , [ nodeServerInFile ] , [ builtLocalDirectory , tscFile ] , [ ] , /*useBuiltCompiler:*/ true , { noOutFile : true } ) ;
2014-07-13 01:04:16 +02:00
desc ( "Runs browserify on run.js to produce a file suitable for running tests in the browser" ) ;
task ( "browserify" , [ "tests" , builtLocalDirectory , nodeServerOutFile ] , function ( ) {
2016-04-08 01:13:28 +02:00
var cmd = 'browserify built/local/run.js -t ./scripts/browserify-optional -o built/local/bundle.js' ;
2014-07-13 01:04:16 +02:00
exec ( cmd ) ;
} , { async : true } ) ;
desc ( "Runs the tests using the built run.js file like 'jake runtests'. Syntax is jake runtests-browser. Additional optional parameters tests=[regex], port=, browser=[chrome|IE]" ) ;
2016-02-10 09:20:40 +01:00
task ( "runtests-browser" , [ "tests" , "browserify" , builtLocalDirectory , servicesFileInBrowserTest ] , function ( ) {
2014-07-13 01:04:16 +02:00
cleanTestDirs ( ) ;
2016-04-09 00:37:13 +02:00
host = "node" ;
2014-07-18 00:26:50 +02:00
port = process . env . port || process . env . p || '8888' ;
browser = process . env . browser || process . env . b || "IE" ;
tests = process . env . test || process . env . tests || process . env . t ;
2015-04-29 21:13:35 +02:00
var light = process . env . light || false ;
2014-07-13 01:04:16 +02:00
var testConfigFile = 'test.config' ;
if ( fs . existsSync ( testConfigFile ) ) {
fs . unlinkSync ( testConfigFile ) ;
}
2015-04-29 21:13:35 +02:00
if ( tests || light ) {
2016-05-31 19:17:45 +02:00
writeTestConfigFile ( tests , light ) ;
2014-07-13 01:04:16 +02:00
}
tests = tests ? tests : '' ;
2016-04-09 00:37:13 +02:00
var cmd = host + " tests/webTestServer.js " + port + " " + browser + " " + tests ;
2015-03-04 07:12:06 +01:00
console . log ( cmd ) ;
2014-07-13 01:04:16 +02:00
exec ( cmd ) ;
} , { async : true } ) ;
2014-12-04 15:27:24 +01:00
function getDiffTool() {
2016-04-09 00:37:13 +02:00
var program = process . env [ 'DIFF' ] ;
2014-12-04 20:15:00 +01:00
if ( ! program ) {
2015-07-30 17:00:29 +02:00
fail ( "Add the 'DIFF' environment variable to the path of the program you want to use." ) ;
2014-12-04 20:15:00 +01:00
}
2014-12-04 15:27:24 +01:00
return program ;
}
2014-07-13 01:04:16 +02:00
// Baseline Diff
2014-12-04 20:15:00 +01:00
desc ( "Diffs the compiler baselines using the diff tool specified by the 'DIFF' environment variable" ) ;
2014-07-13 01:04:16 +02:00
task ( 'diff' , function ( ) {
2014-12-04 15:27:24 +01:00
var cmd = '"' + getDiffTool ( ) + '" ' + refBaseline + ' ' + localBaseline ;
2015-07-30 17:00:29 +02:00
console . log ( cmd ) ;
2014-07-13 01:04:16 +02:00
exec ( cmd ) ;
} , { async : true } ) ;
2014-12-04 20:15:00 +01:00
desc ( "Diffs the RWC baselines using the diff tool specified by the 'DIFF' environment variable" ) ;
2014-07-13 01:04:16 +02:00
task ( 'diff-rwc' , function ( ) {
2014-12-04 15:27:24 +01:00
var cmd = '"' + getDiffTool ( ) + '" ' + refRwcBaseline + ' ' + localRwcBaseline ;
2015-07-30 17:00:29 +02:00
console . log ( cmd ) ;
2014-07-13 01:04:16 +02:00
exec ( cmd ) ;
} , { async : true } ) ;
desc ( "Builds the test sources and automation in debug mode" ) ;
task ( "tests-debug" , [ "setDebugMode" , "tests" ] ) ;
// Makes the test results the new baseline
desc ( "Makes the most recent test results the new baseline, overwriting the old baseline" ) ;
task ( "baseline-accept" , function ( hardOrSoft ) {
2016-04-09 00:37:13 +02:00
if ( ! hardOrSoft || hardOrSoft === "hard" ) {
2014-07-13 01:04:16 +02:00
jake . rmRf ( refBaseline ) ;
fs . renameSync ( localBaseline , refBaseline ) ;
}
2016-04-09 00:37:13 +02:00
else if ( hardOrSoft === "soft" ) {
2014-07-13 01:04:16 +02:00
var files = jake . readdirR ( localBaseline ) ;
for ( var i in files ) {
jake . cpR ( files [ i ] , refBaseline ) ;
}
jake . rmRf ( path . join ( refBaseline , "local" ) ) ;
}
} ) ;
desc ( "Makes the most recent rwc test results the new baseline, overwriting the old baseline" ) ;
task ( "baseline-accept-rwc" , function ( ) {
jake . rmRf ( refRwcBaseline ) ;
fs . renameSync ( localRwcBaseline , refRwcBaseline ) ;
} ) ;
2014-11-17 20:01:05 +01:00
desc ( "Makes the most recent test262 test results the new baseline, overwriting the old baseline" ) ;
task ( "baseline-accept-test262" , function ( ) {
jake . rmRf ( refTest262Baseline ) ;
fs . renameSync ( localTest262Baseline , refTest262Baseline ) ;
} ) ;
2014-07-13 01:04:16 +02:00
// Webhost
var webhostPath = "tests/webhost/webtsc.ts" ;
var webhostJsPath = "tests/webhost/webtsc.js" ;
2014-12-02 00:32:52 +01:00
compileFile ( webhostJsPath , [ webhostPath ] , [ tscFile , webhostPath ] . concat ( libraryTargets ) , [ ] , /*useBuiltCompiler*/ true ) ;
2014-07-13 01:04:16 +02:00
desc ( "Builds the tsc web host" ) ;
task ( "webhost" , [ webhostJsPath ] , function ( ) {
2014-09-02 23:22:14 +02:00
jake . cpR ( path . join ( builtLocalDirectory , "lib.d.ts" ) , "tests/webhost/" , { silent : true } ) ;
2014-07-13 01:04:16 +02:00
} ) ;
2015-03-04 07:12:06 +01:00
// Perf compiler
var perftscPath = "tests/perftsc.ts" ;
var perftscJsPath = "built/local/perftsc.js" ;
compileFile ( perftscJsPath , [ perftscPath ] , [ tscFile , perftscPath , "tests/perfsys.ts" ] . concat ( libraryTargets ) , [ ] , /*useBuiltCompiler*/ true ) ;
desc ( "Builds augmented version of the compiler for perf tests" ) ;
task ( "perftsc" , [ perftscJsPath ] ) ;
2014-09-02 21:19:58 +02:00
// Instrumented compiler
var loggedIOpath = harnessDirectory + 'loggedIO.ts' ;
var loggedIOJsPath = builtLocalDirectory + 'loggedIO.js' ;
2014-09-02 23:22:14 +02:00
file ( loggedIOJsPath , [ builtLocalDirectory , loggedIOpath ] , function ( ) {
var temp = builtLocalDirectory + 'temp' ;
2014-09-02 21:19:58 +02:00
jake . mkdirP ( temp ) ;
var options = "--outdir " + temp + ' ' + loggedIOpath ;
var cmd = host + " " + LKGDirectory + compilerFilename + " " + options + " " ;
2015-03-04 07:12:06 +01:00
console . log ( cmd + "\n" ) ;
var ex = jake . createExec ( [ cmd ] ) ;
ex . addListener ( "cmdEnd" , function ( ) {
2014-09-02 23:22:14 +02:00
fs . renameSync ( temp + '/harness/loggedIO.js' , loggedIOJsPath ) ;
jake . rmRf ( temp ) ;
complete ( ) ;
2014-09-02 21:19:58 +02:00
} ) ;
2015-03-04 07:12:06 +01:00
ex . run ( ) ;
2014-09-02 21:19:58 +02:00
} , { async : true } ) ;
var instrumenterPath = harnessDirectory + 'instrumenter.ts' ;
var instrumenterJsPath = builtLocalDirectory + 'instrumenter.js' ;
2015-03-19 01:23:40 +01:00
compileFile ( instrumenterJsPath , [ instrumenterPath ] , [ tscFile , instrumenterPath ] . concat ( libraryTargets ) , [ ] , /*useBuiltCompiler*/ true ) ;
2014-09-02 21:19:58 +02:00
desc ( "Builds an instrumented tsc.js" ) ;
task ( 'tsc-instrumented' , [ loggedIOJsPath , instrumenterJsPath , tscFile ] , function ( ) {
2014-09-02 23:22:14 +02:00
var cmd = host + ' ' + instrumenterJsPath + ' record iocapture ' + builtLocalDirectory + compilerFilename ;
2015-03-04 07:12:06 +01:00
console . log ( cmd ) ;
var ex = jake . createExec ( [ cmd ] ) ;
ex . addListener ( "cmdEnd" , function ( ) {
complete ( ) ;
} ) ;
ex . run ( ) ;
2014-09-02 23:22:14 +02:00
} , { async : true } ) ;
2015-06-23 18:05:49 +02:00
desc ( "Updates the sublime plugin's tsserver" ) ;
2015-07-10 20:09:22 +02:00
task ( "update-sublime" , [ "local" , serverFile ] , function ( ) {
2015-06-23 18:05:49 +02:00
jake . cpR ( serverFile , "../TypeScript-Sublime-Plugin/tsserver/" ) ;
jake . cpR ( serverFile + ".map" , "../TypeScript-Sublime-Plugin/tsserver/" ) ;
} ) ;
2015-07-10 01:39:58 +02:00
2015-08-26 03:09:32 +02:00
var tslintRuleDir = "scripts/tslint" ;
2016-04-09 00:37:13 +02:00
var tslintRules = [
2015-08-26 03:09:32 +02:00
"nextLineRule" ,
2015-11-04 20:02:43 +01:00
"preferConstRule" ,
2015-10-22 20:35:48 +02:00
"booleanTriviaRule" ,
2015-12-02 00:14:24 +01:00
"typeOperatorSpacingRule" ,
2015-12-02 01:19:40 +01:00
"noInOperatorRule" ,
"noIncrementDecrementRule"
2016-04-09 00:37:13 +02:00
] ;
2015-08-26 03:09:32 +02:00
var tslintRulesFiles = tslintRules . map ( function ( p ) {
return path . join ( tslintRuleDir , p + ".ts" ) ;
} ) ;
var tslintRulesOutFiles = tslintRules . map ( function ( p ) {
return path . join ( builtLocalDirectory , "tslint" , p + ".js" ) ;
} ) ;
desc ( "Compiles tslint rules to js" ) ;
task ( "build-rules" , tslintRulesOutFiles ) ;
tslintRulesFiles . forEach ( function ( ruleFile , i ) {
2016-02-10 09:20:40 +01:00
compileFile ( tslintRulesOutFiles [ i ] , [ ruleFile ] , [ ruleFile ] , [ ] , /*useBuiltCompiler*/ false ,
{ noOutFile : true , generateDeclarations : false , outDir : path.join ( builtLocalDirectory , "tslint" ) } ) ;
2015-08-26 03:09:32 +02:00
} ) ;
2015-09-18 06:04:33 +02:00
function getLinterOptions() {
return {
configuration : require ( "./tslint.json" ) ,
formatter : "prose" ,
formattersDirectory : undefined ,
rulesDirectory : "built/local/tslint"
} ;
}
function lintFileContents ( options , path , contents ) {
var ll = new Linter ( path , contents , options ) ;
2016-04-09 00:37:13 +02:00
console . log ( "Linting '" + path + "'." ) ;
2015-09-18 06:04:33 +02:00
return ll . lint ( ) ;
}
function lintFile ( options , path ) {
var contents = fs . readFileSync ( path , "utf8" ) ;
return lintFileContents ( options , path , contents ) ;
}
function lintFileAsync ( options , path , cb ) {
fs . readFile ( path , "utf8" , function ( err , contents ) {
if ( err ) {
return cb ( err ) ;
}
var result = lintFileContents ( options , path , contents ) ;
cb ( undefined , result ) ;
} ) ;
}
2015-10-28 23:42:15 +01:00
var lintTargets = compilerSources
2016-05-24 19:17:16 +02:00
. concat ( harnessSources )
2016-05-20 18:40:13 +02:00
// Other harness sources
. concat ( [ "instrumenter.ts" ] . map ( function ( f ) { return path . join ( harnessDirectory , f ) } ) )
2015-11-21 01:28:58 +01:00
. concat ( serverCoreSources )
2015-12-23 01:12:07 +01:00
. concat ( tslintRulesFiles )
2016-05-25 15:32:55 +02:00
. concat ( servicesSources ) ;
2015-09-18 06:04:33 +02:00
2016-05-24 22:57:12 +02:00
2016-05-18 16:41:37 +02:00
desc ( "Runs tslint on the compiler sources. Optional arguments are: f[iles]=regex" ) ;
2015-08-26 03:09:32 +02:00
task ( "lint" , [ "build-rules" ] , function ( ) {
2015-09-18 06:04:33 +02:00
var lintOptions = getLinterOptions ( ) ;
2015-12-02 00:05:08 +01:00
var failed = 0 ;
2016-05-18 16:41:37 +02:00
var fileMatcher = RegExp ( process . env . f || process . env . file || process . env . files || "" ) ;
2016-05-24 22:57:12 +02:00
var done = { } ;
2015-07-23 22:59:41 +02:00
for ( var i in lintTargets ) {
2016-05-18 16:41:37 +02:00
var target = lintTargets [ i ] ;
2016-05-24 22:57:12 +02:00
if ( ! done [ target ] && fileMatcher . test ( target ) ) {
2016-05-18 16:41:37 +02:00
var result = lintFile ( lintOptions , target ) ;
if ( result . failureCount > 0 ) {
console . log ( result . output ) ;
failed += result . failureCount ;
}
2016-05-24 22:57:12 +02:00
done [ target ] = true ;
2015-09-18 06:04:33 +02:00
}
2015-07-10 01:39:58 +02:00
}
2015-12-02 00:05:08 +01:00
if ( failed > 0 ) {
fail ( 'Linter errors.' , failed ) ;
}
2015-09-18 06:04:33 +02:00
} ) ;
2015-09-25 20:32:08 +02:00
/ * *
* This is required because file watches on Windows get fires _twice_
* when a file changes on some node / windows version configuations
* ( node v4 and win 10 , for example ) . By not running a lint for a file
* which already has a pending lint , we avoid duplicating our work .
* ( And avoid printing duplicate results ! )
* /
2015-09-18 06:04:33 +02:00
var lintSemaphores = { } ;
function lintWatchFile ( filename ) {
fs . watch ( filename , { persistent : true } , function ( event ) {
if ( event !== "change" ) {
return ;
}
2015-11-24 07:38:05 +01:00
2015-09-18 06:04:33 +02:00
if ( ! lintSemaphores [ filename ] ) {
lintSemaphores [ filename ] = true ;
lintFileAsync ( getLinterOptions ( ) , filename , function ( err , result ) {
delete lintSemaphores [ filename ] ;
if ( err ) {
console . log ( err ) ;
return ;
}
if ( result . failureCount > 0 ) {
console . log ( "***Lint failure***" ) ;
for ( var i = 0 ; i < result . failures . length ; i ++ ) {
var failure = result . failures [ i ] ;
2015-09-21 21:48:08 +02:00
var start = failure . startPosition . lineAndCharacter ;
var end = failure . endPosition . lineAndCharacter ;
console . log ( "warning " + filename + " (" + ( start . line + 1 ) + "," + ( start . character + 1 ) + "," + ( end . line + 1 ) + "," + ( end . character + 1 ) + "): " + failure . failure ) ;
2015-09-18 06:04:33 +02:00
}
2015-09-21 21:48:08 +02:00
console . log ( "*** Total " + result . failureCount + " failures." ) ;
2015-09-18 06:04:33 +02:00
}
} ) ;
}
} ) ;
}
desc ( "Watches files for changes to rerun a lint pass" ) ;
task ( "lint-server" , [ "build-rules" ] , function ( ) {
2015-09-21 21:48:08 +02:00
console . log ( "Watching ./src for changes to linted files" ) ;
for ( var i = 0 ; i < lintTargets . length ; i ++ ) {
2015-09-18 06:04:33 +02:00
lintWatchFile ( lintTargets [ i ] ) ;
}
} ) ;
2016-03-24 21:32:41 +01:00
2016-05-26 10:16:29 +02:00
function ProgressBar() {
this . _progress = [ ] ;
this . _lineCount = 0 ;
2016-03-24 21:32:41 +01:00
}
ProgressBar . prototype = {
progressChars : [ "\u0020" , "\u2591" , "\u2592" , "\u2593" , "\u2588" ] ,
colors : {
foreground : {
black : "\u001b[90m" ,
red : "\u001b[91m" ,
green : "\u001b[92m" ,
yellow : "\u001b[93m" ,
blue : "\u001b[94m" ,
magenta : "\u001b[95m" ,
cyan : "\u001b[96m" ,
white : "\u001b[97m" ,
gray : "\u001b[37m"
} ,
background : {
black : "\u001b[40m" ,
red : "\u001b[41m" ,
green : "\u001b[42m" ,
yellow : "\u001b[43m" ,
blue : "\u001b[44m" ,
magenta : "\u001b[45m" ,
cyan : "\u001b[46m" ,
white : "\u001b[47m" ,
gray : "\u001b[100m"
} ,
reset : "\u001b[0m"
} ,
2016-05-26 10:16:29 +02:00
update : function ( percentComplete , foregroundColor , backgroundColor , title , index ) {
if ( index === undefined ) index = 0 ;
2016-03-24 21:32:41 +01:00
var progress = "" ;
for ( var i = 0 ; i < 100 ; i += 4 ) {
progress += this . progressChars [ Math . floor ( Math . max ( 0 , Math . min ( 4 , percentComplete - i ) ) ) ] ;
}
foregroundColor = foregroundColor && this . colors . foreground [ foregroundColor ] ;
backgroundColor = backgroundColor && this . colors . background [ backgroundColor ] ;
if ( foregroundColor || backgroundColor ) {
if ( foregroundColor ) {
progress = foregroundColor + progress ;
}
if ( backgroundColor ) {
progress = backgroundColor + progress ;
}
progress += this . colors . reset ;
}
2016-05-26 10:16:29 +02:00
if ( title ) {
progress += " " + title ;
2016-03-24 21:32:41 +01:00
}
2016-05-26 10:16:29 +02:00
if ( this . _progress [ index ] !== progress ) {
this . _progress [ index ] = progress ;
this . _print ( index ) ;
2016-03-24 21:32:41 +01:00
}
} ,
clear : function ( ) {
if ( this . _lastProgress ) {
readline . moveCursor ( process . stdout , - process . stdout . columns , 0 ) ;
readline . clearLine ( process . stdout , 1 ) ;
this . _lastProgress = undefined ;
this . visible = false ;
}
} ,
2016-05-26 10:16:29 +02:00
_print : function ( index ) {
readline . moveCursor ( process . stdout , - process . stdout . columns , - this . _lineCount ) ;
var lineCount = 0 ;
for ( var i = 0 ; i < this . _progress . length ; i ++ ) {
if ( i === index ) {
readline . clearLine ( process . stdout , 1 ) ;
process . stdout . write ( this . _progress [ i ] + os . EOL ) ;
}
else {
readline . moveCursor ( process . stdout , - process . stdout . columns , + 1 ) ;
}
lineCount ++ ;
}
this . _lineCount = lineCount ;
2016-03-24 21:32:41 +01:00
}
2016-04-09 00:31:31 +02:00
} ;
function environmentVariableIsEnabled ( name ) {
return /^(y(es)?|t(rue)?|on|enabled?|1|\+)$/ . test ( process . env [ name ] ) ;
}
function environmentVariableIsDisabled ( name ) {
return /^(no?|f(alse)?|off|disabled?|0|-)$/ . test ( process . env [ name ] ) ;
2016-04-14 01:03:53 +02:00
}