2014-07-13 01:04:16 +02:00
// This file contains the build logic for the public repo
2017-09-15 00:42:06 +02:00
// @ts-check
2014-07-13 01:04:16 +02:00
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" ) ;
2016-08-11 18:53:38 +02:00
var fold = require ( "travis-fold" ) ;
2017-02-08 03:14:23 +01:00
var ts = require ( "./lib/typescript" ) ;
2014-07-13 01:04:16 +02:00
// Variables
var compilerDirectory = "src/compiler/" ;
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/" ;
2016-07-12 02:42:52 +02:00
var unittestsDirectory = "src/harness/unittests/" ;
2014-09-26 23:36:18 +02:00
var docDirectory = "doc/" ;
2017-10-03 02:16:08 +02:00
var lclDirectory = "src/loc/lcl" ;
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" ;
2017-06-08 21:24:20 +02:00
var defaultTestTimeout = 40000 ;
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 ) {
2016-08-19 23:34:14 +02:00
process . env . path = nodeModulesPathPrefix + process . env . path ;
2017-03-22 21:01:53 +01:00
}
else if ( process . env . PATH !== undefined ) {
2016-08-19 23:34:14 +02:00
process . env . PATH = nodeModulesPathPrefix + process . env . PATH ;
2014-07-24 04:30:13 +02:00
}
2014-07-22 07:08:27 +02:00
2017-02-08 03:14:23 +01:00
function filesFromConfig ( configPath ) {
var configText = fs . readFileSync ( configPath ) . toString ( ) ;
2017-09-15 00:42:06 +02:00
var config = ts . parseConfigFileTextToJson ( configPath , configText ) ;
2017-02-08 03:14:23 +01:00
if ( config . error ) {
throw new Error ( diagnosticsToString ( [ config . error ] ) ) ;
}
const configFileContent = ts . parseJsonConfigFileContent ( config . config , ts . sys , path . dirname ( configPath ) ) ;
if ( configFileContent . errors && configFileContent . errors . length ) {
throw new Error ( diagnosticsToString ( configFileContent . errors ) ) ;
}
return configFileContent . fileNames ;
function diagnosticsToString ( s ) {
return s . map ( function ( e ) { return ts . flattenDiagnosticMessageText ( e . messageText , ts . sys . newLine ) ; } ) . join ( ts . sys . newLine ) ;
}
}
2016-08-12 23:00:50 +02:00
function toNs ( diff ) {
return diff [ 0 ] * 1 e9 + diff [ 1 ] ;
}
function mark() {
if ( ! fold . isTravis ( ) ) return ;
var stamp = process . hrtime ( ) ;
var id = Math . floor ( Math . random ( ) * 0xFFFFFFFF ) . toString ( 16 ) ;
console . log ( "travis_time:start:" + id + "\r" ) ;
return {
stamp : stamp ,
id : id
} ;
}
function measure ( marker ) {
if ( ! fold . isTravis ( ) ) return ;
var diff = process . hrtime ( marker . stamp ) ;
var total = [ marker . stamp [ 0 ] + diff [ 0 ] , marker . stamp [ 1 ] + diff [ 1 ] ] ;
console . log ( "travis_time:end:" + marker . id + ":start=" + toNs ( marker . stamp ) + ",finish=" + toNs ( total ) + ",duration=" + toNs ( diff ) + "\r" ) ;
}
2017-06-09 02:18:58 +02:00
function removeConstModifierFromEnumDeclarations ( text ) {
return text . replace ( /^(\s*)(export )?const enum (\S+) {(\s*)$/gm , '$1$2enum $3 {$4' ) ;
}
2017-02-08 03:14:23 +01:00
var compilerSources = filesFromConfig ( "./src/compiler/tsconfig.json" ) ;
var servicesSources = filesFromConfig ( "./src/services/tsconfig.json" ) ;
var cancellationTokenSources = filesFromConfig ( path . join ( serverDirectory , "cancellationToken/tsconfig.json" ) ) ;
var typingsInstallerSources = filesFromConfig ( path . join ( serverDirectory , "typingsInstaller/tsconfig.json" ) ) ;
2017-02-16 19:32:01 +01:00
var watchGuardSources = filesFromConfig ( path . join ( serverDirectory , "watchGuard/tsconfig.json" ) ) ;
2017-02-08 03:14:23 +01:00
var serverSources = filesFromConfig ( path . join ( serverDirectory , "tsconfig.json" ) )
var languageServiceLibrarySources = filesFromConfig ( path . join ( serverDirectory , "tsconfig.library.json" ) ) ;
2015-06-10 02:00:35 +02:00
2017-07-28 01:07:50 +02:00
var typesMapOutputPath = path . join ( builtLocalDirectory , 'typesMap.json' ) ;
2015-07-15 02:47:15 +02:00
var harnessCoreSources = [
2014-07-13 01:04:16 +02:00
"harness.ts" ,
2015-12-17 00:49:31 +01:00
"virtualFileSystem.ts" ,
2017-07-27 00:12:03 +02:00
"virtualFileSystemWithWatch.ts" ,
2014-07-13 01:04:16 +02:00
"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" ,
2017-11-08 22:28:35 +01:00
"externalCompileRunner.ts" ,
2014-11-17 20:01:05 +01:00
"test262Runner.ts" ,
2017-09-15 00:42:06 +02:00
"./parallel/shared.ts" ,
"./parallel/host.ts" ,
"./parallel/worker.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" ,
2016-03-16 22:09:45 +01:00
"transpile.ts" ,
2015-08-04 02:42:29 +02:00
"reuseProgramStructure.ts" ,
2016-12-09 01:17:42 +01:00
"textStorage.ts" ,
2015-10-29 12:56:13 +01:00
"moduleResolution.ts" ,
2016-03-15 19:44:33 +01:00
"tsconfigParsing.ts" ,
2017-10-04 22:30:37 +02:00
"builder.ts" ,
2016-03-15 19:45:21 +01:00
"commandLineParsing.ts" ,
2016-07-25 23:48:41 +02:00
"configurationExtension.ts" ,
2016-03-15 19:45:21 +01:00
"convertCompilerOptionsFromJson.ts" ,
2016-11-19 02:46:06 +01:00
"convertTypeAcquisitionFromJson.ts" ,
2016-06-18 00:34:06 +02:00
"tsserverProjectSystem.ts" ,
2017-07-27 00:12:03 +02:00
"tscWatchMode.ts" ,
2016-08-30 20:47:08 +02:00
"compileOnSave.ts" ,
"typingsInstaller.ts" ,
"projectErrors.ts" ,
2016-08-18 00:23:28 +02:00
"matchFiles.ts" ,
"initializeTSConfig.ts" ,
2017-09-26 19:37:25 +02:00
"extractConstants.ts" ,
2017-09-27 01:26:12 +02:00
"extractFunctions.ts" ,
2017-09-27 01:46:32 +02:00
"extractRanges.ts" ,
"extractTestHelpers.ts" ,
2017-01-30 22:40:42 +01:00
"printer.ts" ,
2017-03-15 19:44:36 +01:00
"textChanges.ts" ,
2017-05-25 22:30:27 +02:00
"telemetry.ts" ,
2017-02-07 23:36:15 +01:00
"transform.ts" ,
"customTransforms.ts" ,
2017-06-07 01:39:41 +02:00
"programMissingFiles.ts" ,
2016-07-20 23:58:46 +02:00
"symbolWalker.ts" ,
2017-09-07 06:56:16 +02:00
"languageService.ts" ,
2017-10-03 02:37:40 +02:00
"publicApi.ts" ,
2017-10-18 03:45:21 +02:00
"hostNewLineSupport.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 ( [
2016-10-12 20:02:56 +02:00
"protocol.ts" ,
2016-06-25 02:15:36 +02:00
"utilities.ts" ,
2016-06-01 01:51:00 +02:00
"scriptVersionCache.ts" ,
2016-06-25 02:15:36 +02:00
"scriptInfo.ts" ,
"project.ts" ,
2016-08-12 20:04:43 +02:00
"typingsCache.ts" ,
2016-06-25 02:15:36 +02:00
"editorServices.ts" ,
"session.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
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-08-19 23:34:14 +02:00
var es2015LibrarySourceMap = es2015LibrarySources . map ( function ( source ) {
return { target : "lib." + source , sources : [ "header.d.ts" , source ] } ;
2016-02-06 02:00:45 +01:00
} ) ;
2016-08-19 23:34:14 +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-23 17:41:44 +02:00
var es2017LibrarySource = [
"es2017.object.d.ts" ,
2016-11-10 21:43:51 +01:00
"es2017.sharedmemory.d.ts" ,
2017-05-24 18:50:38 +02:00
"es2017.string.d.ts" ,
2017-11-04 09:08:00 +01:00
"es2017.intl.d.ts" ,
"es2017.typedarrays.d.ts" ,
2016-05-23 17:41:44 +02:00
] ;
2016-05-10 23:22:00 +02:00
2016-05-19 22:31:21 +02:00
var es2017LibrarySourceMap = es2017LibrarySource . map ( function ( source ) {
2016-05-10 23:22:00 +02:00
return { target : "lib." + source , sources : [ "header.d.ts" , source ] } ;
2016-05-19 22:31:21 +02:00
} ) ;
2016-05-10 23:22:00 +02:00
2016-12-30 23:10:11 +01:00
var esnextLibrarySource = [
"esnext.asynciterable.d.ts"
] ;
var esnextLibrarySourceMap = esnextLibrarySource . map ( function ( source ) {
return { target : "lib." + source , sources : [ "header.d.ts" , source ] } ;
} ) ;
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 = [
2016-08-19 23:34:14 +02:00
// Host library
{ 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" ] } ,
// JavaScript library
{ target : "lib.es5.d.ts" , sources : [ "header.d.ts" , "es5.d.ts" ] } ,
{ target : "lib.es2015.d.ts" , sources : [ "header.d.ts" , "es2015.d.ts" ] } ,
{ target : "lib.es2016.d.ts" , sources : [ "header.d.ts" , "es2016.d.ts" ] } ,
{ target : "lib.es2017.d.ts" , sources : [ "header.d.ts" , "es2017.d.ts" ] } ,
2016-12-30 23:10:11 +01:00
{ target : "lib.esnext.d.ts" , sources : [ "header.d.ts" , "esnext.d.ts" ] } ,
2016-08-19 23:34:14 +02:00
// JavaScript + all host library
{ target : "lib.d.ts" , sources : [ "header.d.ts" , "es5.d.ts" ] . concat ( hostsLibrarySources ) } ,
2017-04-05 22:48:35 +02:00
{ target : "lib.es6.d.ts" , sources : [ "header.d.ts" , "es5.d.ts" ] . concat ( es2015LibrarySources , hostsLibrarySources , "dom.iterable.d.ts" ) } ,
{ target : "lib.es2016.full.d.ts" , sources : [ "header.d.ts" , "es2016.d.ts" ] . concat ( hostsLibrarySources , "dom.iterable.d.ts" ) } ,
{ target : "lib.es2017.full.d.ts" , sources : [ "header.d.ts" , "es2017.d.ts" ] . concat ( hostsLibrarySources , "dom.iterable.d.ts" ) } ,
{ target : "lib.esnext.full.d.ts" , sources : [ "header.d.ts" , "esnext.d.ts" ] . concat ( hostsLibrarySources , "dom.iterable.d.ts" ) } ,
2016-12-30 23:10:11 +01:00
] . concat ( es2015LibrarySourceMap , es2016LibrarySourceMap , es2017LibrarySourceMap , esnextLibrarySourceMap ) ;
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 ) ;
} ) ;
2017-10-19 00:46:09 +02:00
/ * *
* . lcg file is what localization team uses to know what messages to localize .
* The file is always generated in 'enu\diagnosticMessages.generated.json.lcg'
* /
var generatedLCGFile = path . join ( builtLocalDirectory , "enu" , "diagnosticMessages.generated.json.lcg" ) ;
/ * *
* The localization target produces the two following transformations :
* 1 . 'src\loc\lcl\<locale>\diagnosticMessages.generated.json.lcl' = > 'built\local\<locale>\diagnosticMessages.generated.json'
* convert localized resources into a . json file the compiler can understand
* 2 . 'src\compiler\diagnosticMessages.generated.json' = > 'built\local\ENU\diagnosticMessages.generated.json.lcg'
* generate the lcg file ( source of messages to localize ) from the diagnosticMessages . generated . json
* /
var localizationTargets = [ "cs" , "de" , "es" , "fr" , "it" , "ja" , "ko" , "pl" , "pt-BR" , "ru" , "tr" , "zh-CN" , "zh-TW" ] . map ( function ( f ) {
return path . join ( builtLocalDirectory , f ) ;
} ) . concat ( path . dirname ( generatedLCGFile ) ) ;
2014-07-13 01:04:16 +02:00
// 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" ;
2016-08-19 23:34:14 +02:00
jake . cpR ( prefixFile , temp , { silent : true } ) ;
2014-07-13 01:04:16 +02:00
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" ;
// append all files in sequence
2016-12-14 23:40:04 +01:00
var text = "" ;
for ( var i = 0 ; i < sourceFiles . length ; i ++ ) {
2014-07-13 01:04:16 +02:00
if ( ! fs . existsSync ( sourceFiles [ i ] ) ) {
2016-08-19 23:34:14 +02:00
fail ( sourceFiles [ i ] + " does not exist!" ) ;
2014-07-13 01:04:16 +02:00
}
2016-12-14 23:40:04 +01:00
if ( i > 0 ) { text += "\n\n" ; }
text += fs . readFileSync ( sourceFiles [ i ] ) . toString ( ) . replace ( /\r?\n/g , "\n" ) ;
2014-07-13 01:04:16 +02:00
}
2016-12-14 23:40:04 +01:00
fs . writeFileSync ( temp , text ) ;
2014-07-13 01:04:16 +02:00
// 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
2016-06-11 03:22:20 +02:00
* @param { boolean } opts.inlineSourceMap : true if compiler should inline sourceMap
2016-07-12 01:00:16 +02:00
* @param { Array } opts.types : array of types to include in compilation
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 ( ) {
2016-06-07 19:32:03 +02:00
if ( process . env . USE_TRANSFORMS === "false" ) {
useBuiltCompiler = false ;
}
2016-08-12 23:00:50 +02:00
var startCompileTime = mark ( ) ;
2016-02-10 09:20:40 +01:00
opts = opts || { } ;
2016-07-12 01:00:16 +02:00
var compilerPath = useBuiltCompiler ? builtLocalCompiler : LKGCompiler ;
2017-06-29 04:44:15 +02:00
var options = "--noImplicitAny --noImplicitThis --alwaysStrict --noEmitOnError --types "
2016-07-12 01:00:16 +02:00
if ( opts . types ) {
options += opts . types . join ( "," ) ;
}
options += " --pretty" ;
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-05-19 22:31:21 +02:00
options += " --module commonjs" ;
2014-12-11 01:42:41 +01:00
}
2016-08-19 23:34:14 +02: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-06-11 03:22:20 +02:00
if ( opts . inlineSourceMap ) {
options += " --inlineSourceMap --inlineSources" ;
2017-03-22 21:01:53 +01:00
}
else {
2016-06-11 03:22:20 +02:00
options += " -sourcemap" ;
}
2017-03-22 21:01:53 +01:00
}
2017-10-03 02:37:40 +02:00
options += " --newLine LF" ;
2014-12-11 01:42:41 +01:00
2016-02-10 09:20:40 +01:00
if ( opts . stripInternal ) {
2016-05-19 22:31:21 +02:00
options += " --stripInternal" ;
2015-02-03 22:47:46 +01:00
}
2017-03-06 00:41:47 +01:00
options += " --target es5" ;
if ( opts . lib ) {
options += " --lib " + opts . lib
}
else {
2017-03-10 16:10:58 +01:00
options += " --lib es5"
2017-03-06 00:41:47 +01:00
}
options += " --noUnusedLocals --noUnusedParameters" ;
2016-10-18 16:34:48 +02: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
2016-08-19 23:34:14 +02:00
ex . addListener ( "stdout" , function ( output ) {
2015-03-04 07:12:06 +01:00
process . stdout . write ( output ) ;
} ) ;
2016-08-19 23:34:14 +02:00
ex . addListener ( "stderr" , function ( error ) {
2015-03-04 07:12:06 +01:00
process . stderr . write ( error ) ;
} ) ;
2016-08-19 23:34:14 +02:00
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
2016-08-12 23:00:50 +02:00
measure ( startCompileTime ) ;
2015-03-04 07:12:06 +01:00
complete ( ) ;
} ) ;
2016-08-19 23:34:14 +02:00
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" ) ;
2016-08-12 23:00:50 +02:00
measure ( startCompileTime ) ;
2014-07-13 01:04:16 +02:00
} ) ;
2015-03-04 07:12:06 +01:00
ex . run ( ) ;
2016-08-19 23:34:14 +02:00
} , { async : true } ) ;
2014-07-13 01:04:16 +02:00
}
// 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 ) ;
} ) ) ;
2016-08-19 23:34:14 +02:00
file ( target , [ builtLocalDirectory ] . concat ( sources ) , function ( ) {
2014-07-13 01:04:16 +02:00
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 ,
2016-08-19 23:34:14 +02:00
[ processDiagnosticMessagesTs ] ,
[ processDiagnosticMessagesTs ] ,
[ ] ,
2017-10-03 02:16:08 +02:00
/*useBuiltCompiler*/ false ) ;
// Localize diagnostics script
var generateLocalizedDiagnosticMessagesJs = path . join ( scriptsDirectory , "generateLocalizedDiagnosticMessages.js" ) ;
var generateLocalizedDiagnosticMessagesTs = path . join ( scriptsDirectory , "generateLocalizedDiagnosticMessages.ts" ) ;
file ( generateLocalizedDiagnosticMessagesTs ) ;
compileFile ( generateLocalizedDiagnosticMessagesJs ,
[ generateLocalizedDiagnosticMessagesTs ] ,
[ generateLocalizedDiagnosticMessagesTs ] ,
[ ] ,
/*useBuiltCompiler*/ false , { noOutFile : true , types : [ "node" , "xml2js" ] } ) ;
// Localize diagnostics
file ( generatedLCGFile , [ generateLocalizedDiagnosticMessagesJs , diagnosticInfoMapTs , generatedDiagnosticMessagesJSON ] , function ( ) {
var cmd = host + " " + generateLocalizedDiagnosticMessagesJs + " " + lclDirectory + " " + builtLocalDirectory + " " + generatedDiagnosticMessagesJSON ;
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 ( ) ;
} , { async : true } ) ;
task ( "localize" , [ generatedLCGFile ] ) ;
2014-07-13 01:04:16 +02:00
2016-10-12 20:02:56 +02:00
var buildProtocolTs = path . join ( scriptsDirectory , "buildProtocol.ts" ) ;
var buildProtocolJs = path . join ( scriptsDirectory , "buildProtocol.js" ) ;
var buildProtocolDts = path . join ( builtLocalDirectory , "protocol.d.ts" ) ;
var typescriptServicesDts = path . join ( builtLocalDirectory , "typescriptServices.d.ts" ) ;
2017-07-28 01:07:50 +02:00
var typesMapJson = path . join ( builtLocalDirectory , "typesMap.json" ) ;
2016-10-12 20:02:56 +02:00
file ( buildProtocolTs ) ;
compileFile ( buildProtocolJs ,
[ buildProtocolTs ] ,
[ buildProtocolTs ] ,
[ ] ,
/*useBuiltCompiler*/ false ,
2017-03-09 08:10:14 +01:00
{ noOutFile : true , lib : "es6" } ) ;
2016-10-12 20:02:56 +02:00
file ( buildProtocolDts , [ buildProtocolTs , buildProtocolJs , typescriptServicesDts ] , function ( ) {
var protocolTs = path . join ( serverDirectory , "protocol.ts" ) ;
var cmd = host + " " + buildProtocolJs + " " + protocolTs + " " + typescriptServicesDts + " " + buildProtocolDts ;
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 ( ) ;
} , { async : true } )
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 ( ) {
2016-08-19 23:34:14 +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
2016-08-19 23:34:14 +02:00
ex . addListener ( "stdout" , function ( output ) {
2015-03-04 07:12:06 +01:00
process . stdout . write ( output ) ;
} ) ;
2016-08-19 23:34:14 +02:00
ex . addListener ( "stderr" , function ( error ) {
2015-03-04 07:12:06 +01:00
process . stderr . write ( error ) ;
} ) ;
2016-08-19 23:34:14 +02:00
ex . addListener ( "cmdEnd" , function ( ) {
2015-03-04 07:12:06 +01:00
complete ( ) ;
} ) ;
ex . run ( ) ;
2016-08-19 23:34:14 +02:00
} , { async : true } ) ;
2014-07-13 01:04:16 +02:00
2016-08-19 23:34:14 +02:00
file ( builtGeneratedDiagnosticMessagesJSON , [ generatedDiagnosticMessagesJSON ] , function ( ) {
2015-10-27 22:16:05 +01:00
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" ;
2016-11-15 21:53:46 +01:00
var versionFile = path . join ( compilerDirectory , "core.ts" ) ;
2015-07-15 21:56:00 +02:00
file ( configureNightlyTs ) ;
compileFile ( /*outfile*/ configureNightlyJs ,
2016-08-19 23:34:14 +02:00
/*sources*/ [ configureNightlyTs ] ,
/*prereqs*/ [ configureNightlyTs ] ,
/*prefixes*/ [ ] ,
2015-07-15 21:56:00 +02:00
/*useBuiltCompiler*/ false ,
2016-08-19 23:34:14 +02:00
{ noOutFile : false , generateDeclarations : false , keepComments : false , noResolve : false , stripInternal : false } ) ;
2015-07-23 21:32:17 +02:00
2016-08-19 23:34:14 +02:00
task ( "setDebugMode" , function ( ) {
2015-07-15 21:56:00 +02:00
useDebugMode = true ;
} ) ;
2016-08-19 23:34:14 +02:00
task ( "configure-nightly" , [ configureNightlyJs ] , function ( ) {
2016-11-15 21:53:46 +01:00
var cmd = host + " " + configureNightlyJs + " " + packageJson + " " + versionFile ;
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." ) ;
2017-07-25 19:50:46 +02:00
task ( "publish-nightly" , [ "configure-nightly" , "LKG" , "clean" , "setDebugMode" , "runtests-parallel" ] , function ( ) {
2015-07-23 21:32:17 +02:00
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 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 ) ;
2017-06-03 00:01:38 +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" ) ;
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
2016-08-19 23:34:14 +02:00
compileFile ( servicesFile , servicesSources , [ builtLocalDirectory , copyright ] . concat ( servicesSources ) ,
/*prefixes*/ [ copyright ] ,
2014-12-13 01:17:30 +01:00
/*useBuiltCompiler*/ true ,
2016-08-19 23:34:14 +02:00
/*opts*/ {
noOutFile : false ,
generateDeclarations : true ,
preserveConstEnums : true ,
keepComments : true ,
noResolve : false ,
stripInternal : true
} ,
2015-07-10 01:39:58 +02:00
/*callback*/ function ( ) {
2016-08-19 23:34:14 +02:00
jake . cpR ( servicesFile , nodePackageFile , { silent : true } ) ;
2014-12-02 00:32:52 +01:00
2016-08-19 23:34:14 +02:00
prependFile ( copyright , standaloneDefinitionsFile ) ;
2014-12-11 01:42:41 +01:00
2016-08-19 23:34:14 +02:00
// Stanalone/web definition file using global 'ts' namespace
jake . cpR ( standaloneDefinitionsFile , nodeDefinitionsFile , { silent : true } ) ;
var definitionFileContents = fs . readFileSync ( nodeDefinitionsFile ) . toString ( ) ;
2017-06-09 02:18:58 +02:00
definitionFileContents = removeConstModifierFromEnumDeclarations ( definitionFileContents )
2016-08-19 23:34:14 +02:00
fs . writeFileSync ( standaloneDefinitionsFile , definitionFileContents ) ;
2015-09-08 21:26:29 +02:00
2016-08-19 23:34:14 +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
2017-10-03 02:37:40 +02:00
var nodeDefinitionsFileContents = definitionFileContents + "\nexport = ts;" ;
2016-08-19 23:34:14 +02:00
fs . writeFileSync ( nodeDefinitionsFile , nodeDefinitionsFileContents ) ;
2015-09-08 21:26:29 +02:00
2016-08-19 23:34:14 +02:00
// Node package definition file to be distributed without the package. Created by replacing
// 'ts' namespace with '"typescript"' as a module.
var nodeStandaloneDefinitionsFileContents = definitionFileContents . replace ( /declare (namespace|module) ts/g , 'declare module "typescript"' ) ;
fs . writeFileSync ( nodeStandaloneDefinitionsFile , nodeStandaloneDefinitionsFileContents ) ;
} ) ;
2014-12-11 01:42:41 +01:00
2016-10-12 20:02:56 +02:00
file ( typescriptServicesDts , [ servicesFile ] ) ;
2016-06-15 02:30:55 +02:00
var cancellationTokenFile = path . join ( builtLocalDirectory , "cancellationToken.js" ) ;
2017-03-09 08:03:30 +01:00
compileFile ( cancellationTokenFile , cancellationTokenSources , [ builtLocalDirectory ] . concat ( cancellationTokenSources ) , /*prefixes*/ [ copyright ] , /*useBuiltCompiler*/ true , { types : [ "node" ] , outDir : builtLocalDirectory , noOutFile : true , lib : "es6" } ) ;
2016-06-15 02:30:55 +02:00
2016-08-12 23:01:23 +02:00
var typingsInstallerFile = path . join ( builtLocalDirectory , "typingsInstaller.js" ) ;
2017-03-10 16:10:58 +01:00
compileFile ( typingsInstallerFile , typingsInstallerSources , [ builtLocalDirectory ] . concat ( typingsInstallerSources ) , /*prefixes*/ [ copyright ] , /*useBuiltCompiler*/ true , { types : [ "node" ] , outDir : builtLocalDirectory , noOutFile : false , lib : "es6" } ) ;
2016-08-12 23:01:23 +02:00
2017-02-16 19:32:01 +01:00
var watchGuardFile = path . join ( builtLocalDirectory , "watchGuard.js" ) ;
2017-03-09 08:03:30 +01:00
compileFile ( watchGuardFile , watchGuardSources , [ builtLocalDirectory ] . concat ( watchGuardSources ) , /*prefixes*/ [ copyright ] , /*useBuiltCompiler*/ true , { types : [ "node" ] , outDir : builtLocalDirectory , noOutFile : false , lib : "es6" } ) ;
2017-02-16 19:32:01 +01:00
2015-02-16 03:52:17 +01:00
var serverFile = path . join ( builtLocalDirectory , "tsserver.js" ) ;
2017-03-10 16:10:58 +01:00
compileFile ( serverFile , serverSources , [ builtLocalDirectory , copyright , cancellationTokenFile , typingsInstallerFile , watchGuardFile ] . concat ( serverSources ) . concat ( servicesSources ) , /*prefixes*/ [ copyright ] , /*useBuiltCompiler*/ true , { types : [ "node" ] , preserveConstEnums : true , lib : "es6" } ) ;
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" ) ;
2017-07-28 01:07:50 +02:00
file ( typesMapOutputPath , function ( ) {
var content = fs . readFileSync ( path . join ( serverDirectory , 'typesMap.json' ) ) ;
// Validate that it's valid JSON
try {
2017-09-15 00:42:06 +02:00
JSON . parse ( content . toString ( ) ) ;
2017-07-28 01:07:50 +02:00
} catch ( e ) {
console . log ( "Parse error in typesMap.json: " + e ) ;
}
fs . writeFileSync ( typesMapOutputPath , content ) ;
} ) ;
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 ,
2016-08-05 23:16:29 +02:00
[ builtLocalDirectory , copyright , builtLocalCompiler ] . concat ( languageServiceLibrarySources ) . concat ( libraryTargets ) ,
2016-08-19 23:34:14 +02:00
/*prefixes*/ [ copyright ] ,
2015-07-10 01:39:58 +02:00
/*useBuiltCompiler*/ true ,
2017-10-03 20:18:22 +02:00
{ noOutFile : false , generateDeclarations : true , stripInternal : true , preserveConstEnums : true , keepComments : true } ,
2017-01-05 00:56:16 +01:00
/*callback*/ function ( ) {
2017-01-01 02:37:51 +01:00
prependFile ( copyright , tsserverLibraryDefinitionFile ) ;
2017-01-05 00:56:16 +01:00
// Appending exports at the end of the server library
var tsserverLibraryDefinitionFileContents =
2017-01-12 23:01:04 +01:00
fs . readFileSync ( tsserverLibraryDefinitionFile ) . toString ( ) +
2017-10-03 02:37:40 +02:00
"\nexport = ts;" +
"\nexport as namespace ts;" ;
2017-06-09 02:18:58 +02:00
tsserverLibraryDefinitionFileContents = removeConstModifierFromEnumDeclarations ( tsserverLibraryDefinitionFileContents ) ;
2017-01-05 00:56:16 +01:00
2017-01-01 02:37:51 +01:00
fs . writeFileSync ( tsserverLibraryDefinitionFile , tsserverLibraryDefinitionFileContents ) ;
} ) ;
2015-06-10 02:00:35 +02:00
// Local target to build the language service server library
desc ( "Builds language service server library" ) ;
2017-07-28 01:07:50 +02:00
task ( "lssl" , [ tsserverLibraryFile , tsserverLibraryDefinitionFile , typesMapOutputPath ] ) ;
2015-06-10 02:00:35 +02:00
2016-08-11 18:53:38 +02:00
desc ( "Emit the start of the build fold" ) ;
2016-08-19 23:34:14 +02:00
task ( "build-fold-start" , [ ] , function ( ) {
2016-08-11 18:53:38 +02:00
if ( fold . isTravis ( ) ) console . log ( fold . start ( "build" ) ) ;
} ) ;
desc ( "Emit the end of the build fold" ) ;
2016-08-19 23:34:14 +02:00
task ( "build-fold-end" , [ ] , function ( ) {
2016-08-11 18:53:38 +02:00
if ( fold . isTravis ( ) ) console . log ( fold . end ( "build" ) ) ;
} ) ;
2014-07-13 01:04:16 +02:00
// Local target to build the compiler and services
desc ( "Builds the full compiler and services" ) ;
2017-10-03 02:16:08 +02:00
task ( "local" , [ "build-fold-start" , "generate-diagnostics" , "lib" , tscFile , servicesFile , nodeDefinitionsFile , serverFile , buildProtocolDts , builtGeneratedDiagnosticMessagesJSON , "lssl" , "localize" , "build-fold-end" ] ) ;
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" ) ;
2016-08-19 23:34:14 +02:00
task ( "release" , function ( ) {
2014-11-04 21:18:32 +01:00
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" ) ;
2016-08-19 23:34:14 +02:00
task ( "clean" , function ( ) {
2014-07-13 01:04:16 +02:00
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 ,
2016-08-19 23:34:14 +02:00
[ 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 ( ) ;
} ) ;
2016-08-19 23:34:14 +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-08-19 23:34:14 +02:00
task ( "LKG" , [ "clean" , "release" , "local" ] . concat ( libraryTargets ) , function ( ) {
2017-10-03 02:16:08 +02:00
var expectedFiles = [ tscFile , servicesFile , serverFile , nodePackageFile , nodeDefinitionsFile , standaloneDefinitionsFile , tsserverLibraryFile , tsserverLibraryDefinitionFile , cancellationTokenFile , typingsInstallerFile , buildProtocolDts , watchGuardFile ] .
concat ( libraryTargets ) .
2017-10-19 00:46:09 +02:00
concat ( localizationTargets ) ;
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 +
2016-08-19 23:34:14 +02:00
". The following files are missing:\n" + missingFiles . join ( "\n" ) ) ;
2014-07-13 01:04:16 +02:00
}
// 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" ) ;
2016-06-11 03:22:20 +02:00
compileFile (
/*outFile*/ run ,
/*source*/ harnessSources ,
2017-10-03 02:37:40 +02:00
/*prereqs*/ [ builtLocalDirectory , tscFile , tsserverLibraryFile ] . concat ( libraryTargets ) . concat ( servicesSources ) . concat ( harnessSources ) ,
2016-08-19 23:34:14 +02:00
/*prefixes*/ [ ] ,
2016-06-11 03:22:20 +02:00
/*useBuiltCompiler:*/ true ,
2017-08-10 23:34:04 +02:00
/*opts*/ { types : [ "node" , "mocha" , "chai" ] , lib : "es6" } ) ;
2014-07-13 01:04:16 +02:00
2016-05-19 22:31:21 +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 ) {
2017-09-15 00:42:06 +02:00
var ex = jake . createExec ( [ cmd ] , { windowsVerbatimArguments : true , interactive : true } ) ;
2015-03-04 07:12:06 +01:00
// Add listeners for output and error
2016-08-19 23:34:14 +02:00
ex . addListener ( "stdout" , function ( output ) {
2015-03-04 07:12:06 +01:00
process . stdout . write ( output ) ;
} ) ;
2016-08-19 23:34:14 +02:00
ex . addListener ( "stderr" , function ( error ) {
2015-03-04 07:12:06 +01:00
process . stderr . write ( error ) ;
} ) ;
2016-08-19 23:34:14 +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
} ) ;
2016-08-19 23:34:14 +02:00
ex . addListener ( "error" , function ( e , status ) {
if ( errorHandler ) {
2015-07-10 01:39:58 +02:00
errorHandler ( e , status ) ;
2017-03-22 21:01:53 +01:00
}
else {
2015-07-10 01:39:58 +02:00
fail ( "Process exited with code " + status ) ;
}
} ) ;
2014-12-17 00:28:36 +01:00
ex . run ( ) ;
2014-07-13 01:04:16 +02:00
}
2017-09-15 01:22:14 +02:00
const del = require ( "del" ) ;
2014-07-13 01:04:16 +02:00
function cleanTestDirs() {
// Clean the local baselines directory
if ( fs . existsSync ( localBaseline ) ) {
2017-09-15 01:22:14 +02:00
del . sync ( localBaseline ) ;
2014-07-13 01:04:16 +02:00
}
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 ) ) {
2017-09-15 01:22:14 +02:00
del . sync ( localRwcBaseline ) ;
2014-07-13 01:04:16 +02:00
}
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
2017-11-06 20:24:17 +01:00
function writeTestConfigFile ( tests , runners , light , taskConfigsFolder , workerCount , stackTraceLimit , colors ) {
2016-09-15 02:25:56 +02:00
var testConfigContents = JSON . stringify ( {
2017-11-06 20:24:17 +01:00
runners : runners ? runners . split ( "," ) : undefined ,
2016-06-07 19:32:03 +02:00
test : tests ? [ tests ] : undefined ,
light : light ,
workerCount : workerCount ,
taskConfigsFolder : taskConfigsFolder ,
2017-09-15 00:42:06 +02:00
stackTraceLimit : stackTraceLimit ,
noColor : ! colors
2016-06-07 19:32:03 +02:00
} ) ;
2014-09-18 20:49:40 +02:00
fs . writeFileSync ( 'test.config' , testConfigContents ) ;
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-24 01:00:56 +02:00
function runConsoleTests ( defaultReporter , runInParallel ) {
2016-06-07 19:32:03 +02:00
var dirty = process . env . dirty ;
2016-04-13 03:40:39 +02:00
if ( ! dirty ) {
cleanTestDirs ( ) ;
}
2017-06-08 21:24:20 +02:00
var debug = process . env . debug || process . env [ "debug-brk" ] || process . env . d ;
var inspect = process . env . inspect || process . env [ "inspect-brk" ] || process . env . i ;
2017-06-06 22:33:19 +02:00
var testTimeout = process . env . timeout || defaultTestTimeout ;
2017-11-06 20:24:17 +01:00
var runners = process . env . runners || process . env . runner || process . env . ru ;
2017-06-06 22:33:19 +02:00
var tests = process . env . test || process . env . tests || process . env . t ;
2017-10-20 02:15:54 +02:00
var light = process . env . light === undefined || process . env . light !== "false" ;
2016-06-07 19:32:03 +02:00
var stackTraceLimit = process . env . stackTraceLimit ;
2014-07-13 01:04:16 +02:00
var testConfigFile = 'test.config' ;
2016-08-19 23:34:14 +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 ) ;
2017-06-06 22:33:19 +02:00
workerCount = process . env . workerCount || process . env . p || os . cpus ( ) . length ;
2016-05-24 01:00:56 +02:00
}
2014-09-03 19:37:32 +02:00
2017-11-06 20:24:17 +01:00
if ( tests || runners || light || taskConfigsFolder ) {
writeTestConfigFile ( tests , runners , light , taskConfigsFolder , workerCount , stackTraceLimit , colors ) ;
2014-07-13 01:04:16 +02:00
}
2014-09-03 19:37:32 +02:00
if ( tests && tests . toLocaleLowerCase ( ) === "rwc" ) {
2016-11-22 02:25:38 +01:00
testTimeout = 800000 ;
2014-09-03 19:37:32 +02:00
}
2017-07-25 23:35:22 +02:00
var colorsFlag = process . env . color || process . env . colors ;
var colors = colorsFlag !== "false" && colorsFlag !== "0" ;
2017-02-07 23:36:15 +01:00
var reporter = process . env . reporter || process . env . r || defaultReporter ;
var bail = process . env . bail || process . env . b ;
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-08-19 23:34:14 +02:00
if ( ! runInParallel ) {
2016-08-12 23:00:50 +02:00
var startTime = mark ( ) ;
2017-02-07 23:36:15 +01:00
var args = [ ] ;
args . push ( "-R" , reporter ) ;
if ( tests ) {
args . push ( "-g" , ` " ${ tests } " ` ) ;
}
if ( colors ) {
args . push ( "--colors" ) ;
}
else {
args . push ( "--no-colors" ) ;
}
if ( bail ) {
args . push ( "--bail" ) ;
}
2017-06-08 21:24:20 +02:00
if ( inspect ) {
args . unshift ( "--inspect-brk" ) ;
}
else if ( debug ) {
args . unshift ( "--debug-brk" ) ;
}
else {
args . push ( "-t" , testTimeout ) ;
}
2017-02-07 23:36:15 +01:00
args . push ( run ) ;
var cmd = "mocha " + args . join ( " " ) ;
2015-10-24 01:27:44 +02:00
console . log ( cmd ) ;
2016-06-10 07:07:07 +02:00
var savedNodeEnv = process . env . NODE_ENV ;
process . env . NODE_ENV = "development" ;
2016-05-20 22:40:34 +02:00
exec ( cmd , function ( ) {
2016-06-10 07:07:07 +02:00
process . env . NODE_ENV = savedNodeEnv ;
2016-08-12 23:00:50 +02:00
measure ( startTime ) ;
2016-05-24 23:29:52 +02:00
runLinter ( ) ;
2016-05-20 22:40:34 +02:00
finish ( ) ;
2016-08-19 23:34:14 +02:00
} , function ( e , status ) {
2016-06-10 07:07:07 +02:00
process . env . NODE_ENV = savedNodeEnv ;
2016-08-12 23:00:50 +02:00
measure ( startTime ) ;
2016-05-26 01:23:51 +02:00
finish ( status ) ;
} ) ;
2016-06-06 20:37:59 +02:00
2016-05-24 01:00:56 +02:00
}
else {
2016-06-10 07:07:07 +02:00
var savedNodeEnv = process . env . NODE_ENV ;
process . env . NODE_ENV = "development" ;
2016-08-12 23:00:50 +02:00
var startTime = mark ( ) ;
2017-09-15 00:42:06 +02:00
exec ( host + " " + run , function ( ) {
2016-06-10 07:07:07 +02:00
process . env . NODE_ENV = savedNodeEnv ;
2016-08-12 23:00:50 +02:00
measure ( startTime ) ;
2017-09-15 00:42:06 +02:00
runLinter ( ) ;
finish ( ) ;
} , function ( e , status ) {
process . env . NODE_ENV = savedNodeEnv ;
measure ( startTime ) ;
finish ( status ) ;
2016-05-24 01:00:56 +02:00
} ) ;
}
2016-06-06 20:37:59 +02:00
2016-05-26 01:23:51 +02:00
function failWithStatus ( status ) {
fail ( "Process exited with code " + status ) ;
}
2016-06-06 20:37:59 +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 ( ) ;
} ) ;
lint . invoke ( ) ;
}
2015-10-26 18:25:01 +01:00
}
desc ( "Runs all the tests in parallel using the built run.js file. Optional arguments are: t[ests]=category1|category2|... d[ebug]=true." ) ;
2016-08-19 23:34:14 +02:00
task ( "runtests-parallel" , [ "build-rules" , "tests" , builtLocalDirectory ] , function ( ) {
2016-05-24 01:00:56 +02:00
runConsoleTests ( 'min' , /*runInParallel*/ true ) ;
2016-08-19 23:34:14 +02:00
} , { async : true } ) ;
2015-10-24 01:27:44 +02:00
[Transforms] Merge master 06/14/2016 (#9169)
* Remove check narrowing only certain types, add test showing issues with this
* string literal case test
* Reconcile fix with CFA work
* Defaultable -> NotNarrowable to align with use
* Missed a defaultable in comments
* Add test for narrowing to unions of string literals
* Rewrite isInStringLiteral to accomodate for unterminated strings
* Refactor signatureHelp to expose helper functions
* Add support for completion in string literals
* Remove unused check
* Use const instead of let
* Fix error
* Formatting changes
* Use shorthand properties
* Add failing test for #8738
* Sort baseline reference identifier by name
* Detects assignment to internal module export clause, fixes #8738
* add SharedArrayBuffer
fix
* Factor out assignment op check
* Add test for composite assignment
* Factor out the behaviour and handles x++ and ++x
* Handles ES3 default as identifier name
* Fix missing else statement
* isNameOfExportedDeclarationInNonES6Module
* Reorder options alphabetically
* Mark diagnostics, and skipDefaultLibCheck as internal
* Allow an import of "foo.js" to be matched by a file "foo.ts"
* Improve loadModuleFromFile code
* Respond to PR comments
* Respond to more PR comments
* Fix test
* Actually merge from master
* Revert to old tryLoad implementation
* Run fixupParentReferences when parsing isolated jsDocComment
* initial revision of unit test support for project system in tsserver
* Allow wildcard ("*") patterns in ambient module declarations
* Add non-widening forms of null and undefined
* Create separate control flows for property declarations with initializers
* Add regression test
* Allow trailing commas in function parameter and argument lists
* Add tests
* Remove unused variable
* Add null check and CR feedback
* Support shorthand ambient module declarations
* Revert "Merge pull request #7235 from weswigham/narrow-all-types"
This reverts commit ef0f6c8fe4f94a7e294cfe42d7025c9dca6535d5, reversing
changes made to 9f087cb62ade7a879e23c229df752fc8f87d679c.
* reuse the fixupParentReferences function
* Improve typing of && operator with --strictNullChecks
* Add test
* Respond to PR comments
* Respond to PR comments
* Add merging tests
* Use a function `stringify` to simplify calls to `JSON.stringify(xyz, undefined, 2)`
* Update tests
* Fix mistake
* Include indent in navigation bar protocol
Previously navbar01 test had indents when run in the browser but not when run from node. Now they run the same.
* Remove unnecessary restrictions in property access narrowing
* Fix fourslash test
* Add regression test
* Consider property declarations to be control flow containers
* Adding regression test
* Remove restriction on --target es5 and --module es6
* change type definition for Object.create
* Fix signature help
* Add "implicit any" warning for shorthand ambient modules
* Remove trailing whitespace
* Support using string values in enums for CompilerOptions in transpile methods
* Remove trailing whitespace in jakefile
* Make `jake runtests-browser` support test regexes with spaces
For example: `jake runtests-browser t="transpile .js files"` now works.
* Add another test
* factor out isJsxOrTsxExtension
* Move to a conformance test
* Revert "Revert "Merge pull request #7235 from weswigham/narrow-all-types""
This reverts commit fc3e040c5167868ed623612e8f33fb3beedf73b1.
* Use inclusive flag, as originally done, but include almost everything
* Add additional tests
* Respond to PR comments
* Fix typo
* add tests for tsserver project system
* Fix test
* Allow case comparison to undefined and null in strict null checking mode
* Remove incorrectly added tests
* check if moduleResolution when verifying that program can be reused
* more tests for module resolution change and exclude
* Fix linting issues
* Merge JSDoc of assignments from function expressions
* Allow nested assignments in type guards
* Add tests
* Improve order of parameter's merged jsdoc
* Force LF newlines for LKG builds/non debug builds
Fixes 6630
* Create intersection types in type guards for unrelated types
* Split commentsFunction test into expr/decl
And renumber.
* Remove TODO comments
* Accept new baselines
* Add tests
* Remove comments
* Fix test helper
* Recognize relative path using in outDir property (#9025)
* Recognize relative path using in outDir property
* Add projects tests
* Add project .json files
* Update baselines
* Add comments
* Add test case
The test passes in 1.8 and fails in master.
* Return trace when exception happens
* Remove Long-Done TODO
AFAIK, the harness sources have been concatenated into `run.js` for as long as I've known. This stops executing them twice (and in turn makes debugging tests much easier, since you no longer have to debug into eval'd code).
* Allow primitive type guards with typeof on right
Previously, only type guards of the form `typeof x === 'string'` were
allowed. Now you can write `'string' === typeof x`.
* Primitive type guards are now order independent
* Fix comments in tests
* Add handleing for classes
* Add more tests for target=es5 module=es6
* addExportToArgumentListKind
* Accept baseline
* Add more tests
* Adds progress indicators to the runtests-parallel build task.
* Fixed typo
* Fix comment
* Add test for out-of-range error
* Use proper method of not resolving alias
* Fix module loading error
(commandLineOptions_stringToEnum would be undefined if optionDeclarations wasn't loaded yet)
* Update tests
* Contextually type return statement in async function
* Remove stale files
* Undo change
* Improve perf
* Improve tests
* Fix sourcemaps for debugging tests
* Allow --sourceRoot with --inlineSources option
Fixes #8445
* this in parameter initializers resolves to class
Accept baselines now that the test passes.
* Add tests for more kinds of import/export
* Fix7334 Disallow async in functionExpression and ArrowFunction (#9062)
* Error when using async modifier in function-expression and arrow-function when target es5
* Add tests and baselines
* Resolve function-this in parameter initialisers when explicitly provided
* Allow null/undefined guard with null/undefined on left
Also add a test with baselines.
* Code review comments
* Update more diagnostic messages ES6->2015
Fix #8996 CC @mhegazy.
* Fixes an issue with runtests-parallel when global mocha is not installed.
* Update LKG
* Add tests
* fix baselines
* Salsa: get members of variables whose initialisers are functions
* Test adding members to JS variables whose initialisers are functions
* Recommend runtests-parallel in CONTRIBUTING
* Allow empty lists on command line
* Remove single-comma empty array form
* Remove trailing whitespace
* Implicit type inclusion changes
* Only inlineSourceMap when debugging through jake-browser (#9080)
* Only inlineSourceMap when debugging through jake-browser
* Address PR: fix typo in opt's property
* minor fix: add missing return clause
* Use camel-case instead of snake-case (#9134)
* Baseline fix, CR comments, lint
* CR changes
* Add test for jsdoc in navigation bar
* Fixes runtests-parallel not reporting failure for failed tests.
* Fix decorator metadata emit for rest arg with no type
* Add isDefinition to ReferenceEntry
Clients can now easily tell if the reference is to a definition or a
usage.
* Test isDefinition
* Add option to bail out of `jake runtests` when one test fails
* Absolute-ify paths in both places
* Refactor
* Add unit test
* lint
* Added tests.
* Accepted baselines.
* Emit 'exports.' if the shorthand is a general export.
* Accepted baselines.
* Emit 'Promise' decorator metadata return type for async methods
* Respond to PR comment
* Unescape identifiers used in code completion
* Make isDefinition required.
For the deprecated getOccurrencesAtPosition, isDefinition is always false.
* Add more isDefinition tests and fix computed property bug
* Fix bug: do unescaping in the right place, so that it only affects escaped javascript identifiers
* Use `isLiteralComputedPropertyDeclarationName`
2016-06-15 00:00:40 +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 bail=false dirty=false." ) ;
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 ) ;
2016-08-19 23:34:14 +02:00
} , { async : true } ) ;
2014-07-13 01:04:16 +02: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 ( ) {
2017-06-08 21:24:20 +02:00
var testTimeout = process . env . timeout || defaultTestTimeout ;
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" ;
2017-03-07 22:40:15 +01:00
compileFile ( nodeServerOutFile , [ nodeServerInFile ] , [ builtLocalDirectory , tscFile ] , [ ] , /*useBuiltCompiler:*/ true , { noOutFile : true , lib : "es6" } ) ;
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" ) ;
2017-08-10 23:34:04 +02:00
task ( "browserify" , [ ] , function ( ) {
// Shell out to `gulp`, since we do the work to handle sourcemaps correctly w/o inline maps there
var cmd = 'gulp browserify --silent' ;
2014-07-13 01:04:16 +02:00
exec ( cmd ) ;
2016-08-19 23:34:14 +02:00
} , { async : true } ) ;
2014-07-13 01:04:16 +02:00
2016-07-28 22:40:05 +02:00
desc ( "Runs the tests using the built run.js file like 'jake runtests'. Syntax is jake runtests-browser. Additional optional parameters tests=[regex], browser=[chrome|IE]" ) ;
2017-08-10 23:34:04 +02:00
task ( "runtests-browser" , [ "browserify" , nodeServerOutFile ] , function ( ) {
2014-07-13 01:04:16 +02:00
cleanTestDirs ( ) ;
2016-05-19 22:31:21 +02:00
host = "node" ;
2017-09-15 00:42:06 +02:00
var browser = process . env . browser || process . env . b || ( os . platform ( ) === "linux" ? "chrome" : "IE" ) ;
2017-11-06 20:24:17 +01:00
var runners = process . env . runners || process . env . runner || process . env . ru ;
2017-09-15 00:42:06 +02:00
var 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' ;
2016-08-19 23:34:14 +02:00
if ( fs . existsSync ( testConfigFile ) ) {
2014-07-13 01:04:16 +02:00
fs . unlinkSync ( testConfigFile ) ;
}
2017-11-06 20:24:17 +01:00
if ( tests || runners || light ) {
writeTestConfigFile ( tests , runners , light ) ;
2014-07-13 01:04:16 +02:00
}
tests = tests ? tests : '' ;
2016-07-28 22:40:05 +02:00
var cmd = host + " tests/webTestServer.js " + browser + " " + JSON . stringify ( tests ) ;
2015-03-04 07:12:06 +01:00
console . log ( cmd ) ;
2014-07-13 01:04:16 +02:00
exec ( cmd ) ;
2016-08-19 23:34:14 +02:00
} , { async : true } ) ;
2014-07-13 01:04:16 +02:00
2014-12-04 15:27:24 +01:00
function getDiffTool() {
2016-05-19 22:31:21 +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 ( ) {
2016-08-19 23:34:14 +02: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 ) ;
2016-08-19 23:34:14 +02:00
} , { async : true } ) ;
2014-07-13 01:04:16 +02:00
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 ( ) {
2016-08-19 23:34:14 +02: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 ) ;
2016-08-19 23:34:14 +02:00
} , { async : true } ) ;
2014-07-13 01:04:16 +02:00
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" ) ;
2016-08-19 23:34:14 +02:00
task ( "baseline-accept" , function ( ) {
2016-11-22 02:25:31 +01:00
acceptBaseline ( localBaseline , refBaseline ) ;
2016-08-19 23:34:14 +02:00
} ) ;
2016-11-22 02:25:31 +01:00
function acceptBaseline ( sourceFolder , targetFolder ) {
2016-08-19 23:34:14 +02:00
console . log ( 'Accept baselines from ' + sourceFolder + ' to ' + targetFolder ) ;
2016-08-08 23:30:27 +02:00
var deleteEnding = '.delete' ;
2017-02-14 07:13:48 +01:00
acceptBaselineFolder ( sourceFolder , targetFolder ) ;
function acceptBaselineFolder ( sourceFolder , targetFolder ) {
var files = fs . readdirSync ( sourceFolder ) ;
for ( var i in files ) {
var filename = files [ i ] ;
var fullLocalPath = path . join ( sourceFolder , filename ) ;
var stat = fs . statSync ( fullLocalPath ) ;
if ( stat . isFile ( ) ) {
if ( filename . substr ( filename . length - deleteEnding . length ) === deleteEnding ) {
filename = filename . substr ( 0 , filename . length - deleteEnding . length ) ;
fs . unlinkSync ( path . join ( targetFolder , filename ) ) ;
2016-09-09 19:13:18 +02:00
}
2017-03-22 21:01:53 +01:00
else {
2017-02-14 07:13:48 +01:00
var target = path . join ( targetFolder , filename ) ;
if ( fs . existsSync ( target ) ) {
fs . unlinkSync ( target ) ;
}
2017-09-15 01:22:14 +02:00
jake . mkdirP ( path . dirname ( target ) ) ;
2017-02-14 07:13:48 +01:00
fs . renameSync ( path . join ( sourceFolder , filename ) , target ) ;
2016-09-09 19:13:18 +02:00
}
2017-02-14 07:13:48 +01:00
}
else if ( stat . isDirectory ( ) ) {
acceptBaselineFolder ( fullLocalPath , path . join ( targetFolder , filename ) ) ;
2016-08-19 23:34:14 +02:00
}
2014-07-13 01:04:16 +02:00
}
}
2016-08-19 23:34:14 +02:00
}
2014-07-13 01:04:16 +02:00
desc ( "Makes the most recent rwc test results the new baseline, overwriting the old baseline" ) ;
2016-08-19 23:34:14 +02:00
task ( "baseline-accept-rwc" , function ( ) {
2016-11-22 02:25:31 +01:00
acceptBaseline ( localRwcBaseline , refRwcBaseline ) ;
2014-07-13 01:04:16 +02:00
} ) ;
2014-11-17 20:01:05 +01:00
desc ( "Makes the most recent test262 test results the new baseline, overwriting the old baseline" ) ;
2016-08-19 23:34:14 +02:00
task ( "baseline-accept-test262" , function ( ) {
2016-11-22 02:25:31 +01:00
acceptBaseline ( localTest262Baseline , refTest262Baseline ) ;
2014-11-17 20:01:05 +01:00
} ) ;
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" ) ;
2016-08-19 23:34:14 +02:00
task ( "webhost" , [ webhostJsPath ] , function ( ) {
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' ;
2016-08-19 23:34:14 +02:00
file ( loggedIOJsPath , [ builtLocalDirectory , loggedIOpath ] , function ( ) {
2014-09-02 23:22:14 +02:00
var temp = builtLocalDirectory + 'temp' ;
2014-09-02 21:19:58 +02:00
jake . mkdirP ( temp ) ;
2017-05-25 22:23:00 +02:00
var options = "--target es5 --lib es6 --types --outdir " + temp + ' ' + loggedIOpath ;
2014-09-02 21:19:58 +02:00
var cmd = host + " " + LKGDirectory + compilerFilename + " " + options + " " ;
2015-03-04 07:12:06 +01:00
console . log ( cmd + "\n" ) ;
var ex = jake . createExec ( [ cmd ] ) ;
2016-08-19 23:34:14 +02:00
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 ( ) ;
2016-08-19 23:34:14 +02:00
} , { async : true } ) ;
2014-09-02 21:19:58 +02:00
var instrumenterPath = harnessDirectory + 'instrumenter.ts' ;
var instrumenterJsPath = builtLocalDirectory + 'instrumenter.js' ;
2017-08-23 00:39:10 +02:00
compileFile ( instrumenterJsPath , [ instrumenterPath ] , [ tscFile , instrumenterPath ] . concat ( libraryTargets ) , [ ] , /*useBuiltCompiler*/ true , { lib : "es6" , types : [ "node" ] , noOutFile : true , outDir : builtLocalDirectory } ) ;
2014-09-02 21:19:58 +02:00
2017-09-27 00:55:21 +02:00
desc ( "Builds an instrumented tsc.js - run with test=[testname]" ) ;
2016-08-19 23:34:14 +02:00
task ( 'tsc-instrumented' , [ loggedIOJsPath , instrumenterJsPath , tscFile ] , function ( ) {
2017-09-27 00:55:21 +02:00
var test = process . env . test || process . env . tests || process . env . t || "iocapture" ;
var cmd = host + ' ' + instrumenterJsPath + " record " + test + " " + builtLocalDirectory + compilerFilename ;
2015-03-04 07:12:06 +01:00
console . log ( cmd ) ;
var ex = jake . createExec ( [ cmd ] ) ;
2016-08-19 23:34:14 +02:00
ex . addListener ( "cmdEnd" , function ( ) {
2015-03-04 07:12:06 +01:00
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" ) ;
2016-08-19 23:34:14 +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
2017-09-21 17:36:50 +02:00
var tslintRuleDir = "scripts/tslint/rules" ;
2016-05-19 22:31:21 +02:00
var tslintRules = [
2015-10-22 20:35:48 +02:00
"booleanTriviaRule" ,
2017-08-09 02:20:25 +02:00
"debugAssertRule" ,
"nextLineRule" ,
"noBomRule" ,
2016-06-23 21:32:14 +02:00
"noIncrementDecrementRule" ,
2017-08-09 02:20:25 +02:00
"noInOperatorRule" ,
2017-03-01 18:28:51 +01:00
"noTypeAssertionWhitespaceRule" ,
2017-08-09 02:20:25 +02:00
"objectLiteralSurroundingSpaceRule" ,
"typeOperatorSpacingRule" ,
2016-05-19 22:31:21 +02:00
] ;
2016-08-19 23:34:14 +02:00
var tslintRulesFiles = tslintRules . map ( function ( p ) {
2015-08-26 03:09:32 +02:00
return path . join ( tslintRuleDir , p + ".ts" ) ;
} ) ;
2016-08-19 23:34:14 +02:00
var tslintRulesOutFiles = tslintRules . map ( function ( p ) {
2017-09-21 17:36:50 +02:00
return path . join ( builtLocalDirectory , "tslint/rules" , p + ".js" ) ;
} ) ;
var tslintFormattersDir = "scripts/tslint/formatters" ;
var tslintFormatters = [
"autolinkableStylishFormatter" ,
] ;
var tslintFormatterFiles = tslintFormatters . map ( function ( p ) {
return path . join ( tslintFormattersDir , p + ".ts" ) ;
} ) ;
var tslintFormattersOutFiles = tslintFormatters . map ( function ( p ) {
return path . join ( builtLocalDirectory , "tslint/formatters" , p + ".js" ) ;
2015-08-26 03:09:32 +02:00
} ) ;
desc ( "Compiles tslint rules to js" ) ;
2017-09-21 17:36:50 +02:00
task ( "build-rules" , [ "build-rules-start" ] . concat ( tslintRulesOutFiles ) . concat ( tslintFormattersOutFiles ) . concat ( [ "build-rules-end" ] ) ) ;
2016-08-19 23:34:14 +02:00
tslintRulesFiles . forEach ( function ( ruleFile , i ) {
2016-02-10 09:20:40 +01:00
compileFile ( tslintRulesOutFiles [ i ] , [ ruleFile ] , [ ruleFile ] , [ ] , /*useBuiltCompiler*/ false ,
2017-09-21 17:36:50 +02:00
{ noOutFile : true , generateDeclarations : false , outDir : path.join ( builtLocalDirectory , "tslint/rules" ) , lib : "es6" } ) ;
} ) ;
tslintFormatterFiles . forEach ( function ( ruleFile , i ) {
compileFile ( tslintFormattersOutFiles [ i ] , [ ruleFile ] , [ ruleFile ] , [ ] , /*useBuiltCompiler*/ false ,
{ noOutFile : true , generateDeclarations : false , outDir : path.join ( builtLocalDirectory , "tslint/formatters" ) , lib : "es6" } ) ;
2015-08-26 03:09:32 +02:00
} ) ;
2016-08-11 18:53:38 +02:00
desc ( "Emit the start of the build-rules fold" ) ;
2016-08-19 23:34:14 +02:00
task ( "build-rules-start" , [ ] , function ( ) {
2016-08-11 18:53:38 +02:00
if ( fold . isTravis ( ) ) console . log ( fold . start ( "build-rules" ) ) ;
} ) ;
desc ( "Emit the end of the build-rules fold" ) ;
2016-08-19 23:34:14 +02:00
task ( "build-rules-end" , [ ] , function ( ) {
2016-08-11 18:53:38 +02:00
if ( fold . isTravis ( ) ) console . log ( fold . end ( "build-rules" ) ) ;
} ) ;
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
2016-08-19 23:34:14 +02:00
. concat ( [ "instrumenter.ts" ] . map ( function ( f ) { return path . join ( harnessDirectory , f ) } ) )
2017-02-08 03:14:23 +01:00
. concat ( serverSources )
2015-12-23 01:12:07 +01:00
. concat ( tslintRulesFiles )
2016-06-23 19:12:14 +02:00
. concat ( servicesSources )
2016-08-17 23:47:54 +02:00
. concat ( typingsInstallerSources )
. concat ( cancellationTokenSources )
2016-07-27 16:26:28 +02:00
. concat ( [ "Gulpfile.ts" ] )
2017-02-08 03:14:23 +01:00
. concat ( [ nodeServerInFile , perftscPath , "tests/perfsys.ts" , webhostPath ] )
. map ( function ( p ) { return path . resolve ( p ) } ) ;
// keep only unique items
lintTargets = Array . from ( new Set ( lintTargets ) ) ;
2015-09-18 06:04:33 +02:00
2016-08-15 19:45:46 +02:00
function sendNextFile ( files , child , callback , failures ) {
var file = files . pop ( ) ;
if ( file ) {
console . log ( "Linting '" + file + "'." ) ;
2016-08-19 23:34:14 +02:00
child . send ( { kind : "file" , name : file } ) ;
2016-08-15 19:45:46 +02:00
}
else {
2016-08-19 23:34:14 +02:00
child . send ( { kind : "close" } ) ;
2016-08-15 19:45:46 +02:00
callback ( failures ) ;
}
}
function spawnLintWorker ( files , callback ) {
var child = child_process . fork ( "./scripts/parallel-lint" ) ;
var failures = 0 ;
2016-08-19 23:34:14 +02:00
child . on ( "message" , function ( data ) {
2016-08-15 19:45:46 +02:00
switch ( data . kind ) {
case "result" :
if ( data . failures > 0 ) {
failures += data . failures ;
console . log ( data . output ) ;
}
sendNextFile ( files , child , callback , failures ) ;
break ;
case "error" :
console . error ( data . error ) ;
failures ++ ;
sendNextFile ( files , child , callback , failures ) ;
break ;
}
} ) ;
sendNextFile ( files , child , callback , failures ) ;
}
2015-09-18 06:04:33 +02:00
2016-05-18 16:41:37 +02:00
desc ( "Runs tslint on the compiler sources. Optional arguments are: f[iles]=regex" ) ;
2017-03-20 16:42:27 +01:00
task ( "lint" , [ "build-rules" ] , ( ) = > {
2016-08-11 18:53:38 +02:00
if ( fold . isTravis ( ) ) console . log ( fold . start ( "lint" ) ) ;
2017-03-20 16:42:27 +01:00
const fileMatcher = process . env . f || process . env . file || process . env . files ;
const files = fileMatcher
? ` src/**/ ${ fileMatcher } `
2017-11-03 01:20:18 +01:00
: "Gulpfile.ts 'scripts/generateLocalizedDiagnosticMessages.ts' 'scripts/tslint/**/*.ts' 'src/**/*.ts' --exclude 'src/lib/*.d.ts'" ;
2017-09-21 17:36:50 +02:00
const cmd = ` node node_modules/tslint/bin/tslint ${ files } --formatters-dir ./built/local/tslint/formatters --format autolinkableStylish ` ;
2017-03-20 16:42:27 +01:00
console . log ( "Linting: " + cmd ) ;
jake . exec ( [ cmd ] , { interactive : true } , ( ) = > {
if ( fold . isTravis ( ) ) console . log ( fold . end ( "lint" ) ) ;
complete ( ) ;
2015-09-18 06:04:33 +02:00
} ) ;
2017-03-20 16:42:27 +01:00
} ) ;