2
2
import * as cp from "child_process" ;
3
3
import * as path from "path" ;
4
4
import * as fs from "fs" ;
5
+ import child_process = require( "child_process" ) ;
5
6
import originalGulp = require( "gulp" ) ;
6
7
import helpMaker = require( "gulp-help" ) ;
7
8
import runSequence = require( "run-sequence" ) ;
@@ -21,10 +22,6 @@ declare module "gulp-typescript" {
21
22
import * as insert from "gulp-insert" ;
22
23
import * as sourcemaps from "gulp-sourcemaps" ;
23
24
import Q = require( "q" ) ;
24
- declare global {
25
- // `del` further depends on `Promise` (and is also not included), so we just, patch the global scope's Promise to Q's (which we already include in our deps because gulp depends on it)
26
- type Promise < T > = Q . Promise < T > ;
27
- }
28
25
import del = require( "del" ) ;
29
26
import mkdirP = require( "mkdirp" ) ;
30
27
import minimist = require( "minimist" ) ;
@@ -41,7 +38,7 @@ const {runTestsInParallel} = mochaParallel;
41
38
Error . stackTraceLimit = 1000 ;
42
39
43
40
const cmdLineOptions = minimist ( process . argv . slice ( 2 ) , {
44
- boolean : [ "debug" , "light" , "colors" , "lint" , "soft" ] ,
41
+ boolean : [ "debug" , "inspect" , " light", "colors" , "lint" , "soft" ] ,
45
42
string : [ "browser" , "tests" , "host" , "reporter" , "stackTraceLimit" ] ,
46
43
alias : {
47
44
d : "debug" ,
@@ -57,6 +54,7 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
57
54
soft : false ,
58
55
colors : process . env . colors || process . env . color || true ,
59
56
debug : process . env . debug || process . env . d ,
57
+ inspect : process . env . inspect ,
60
58
host : process . env . TYPESCRIPT_HOST || process . env . host || "node" ,
61
59
browser : process . env . browser || process . env . b || "IE" ,
62
60
tests : process . env . test || process . env . tests || process . env . t ,
@@ -138,6 +136,14 @@ const es2017LibrarySourceMap = es2017LibrarySource.map(function(source) {
138
136
return { target : "lib." + source , sources : [ "header.d.ts" , source ] } ;
139
137
} ) ;
140
138
139
+ const esnextLibrarySource = [
140
+ "esnext.asynciterable.d.ts"
141
+ ] ;
142
+
143
+ const esnextLibrarySourceMap = esnextLibrarySource . map ( function ( source ) {
144
+ return { target : "lib." + source , sources : [ "header.d.ts" , source ] } ;
145
+ } ) ;
146
+
141
147
const hostsLibrarySources = [ "dom.generated.d.ts" , "webworker.importscripts.d.ts" , "scripthost.d.ts" ] ;
142
148
143
149
const librarySourceMap = [
@@ -152,11 +158,12 @@ const librarySourceMap = [
152
158
{ target : "lib.es2015.d.ts" , sources : [ "header.d.ts" , "es2015.d.ts" ] } ,
153
159
{ target : "lib.es2016.d.ts" , sources : [ "header.d.ts" , "es2016.d.ts" ] } ,
154
160
{ target : "lib.es2017.d.ts" , sources : [ "header.d.ts" , "es2017.d.ts" ] } ,
161
+ { target : "lib.esnext.d.ts" , sources : [ "header.d.ts" , "esnext.d.ts" ] } ,
155
162
156
163
// JavaScript + all host library
157
164
{ target : "lib.d.ts" , sources : [ "header.d.ts" , "es5.d.ts" ] . concat ( hostsLibrarySources ) } ,
158
165
{ target : "lib.es6.d.ts" , sources : [ "header.d.ts" , "es5.d.ts" ] . concat ( es2015LibrarySources , hostsLibrarySources , "dom.iterable.d.ts" ) }
159
- ] . concat ( es2015LibrarySourceMap , es2016LibrarySourceMap , es2017LibrarySourceMap ) ;
166
+ ] . concat ( es2015LibrarySourceMap , es2016LibrarySourceMap , es2017LibrarySourceMap , esnextLibrarySourceMap ) ;
160
167
161
168
const libraryTargets = librarySourceMap . map ( function ( f ) {
162
169
return path . join ( builtLocalDirectory , f . target ) ;
@@ -384,7 +391,7 @@ gulp.task(builtLocalCompiler, false, [servicesFile], () => {
384
391
. pipe ( localCompilerProject ( ) )
385
392
. pipe ( prependCopyright ( ) )
386
393
. pipe ( sourcemaps . write ( "." ) )
387
- . pipe ( gulp . dest ( ". " ) ) ;
394
+ . pipe ( gulp . dest ( "src/compiler " ) ) ;
388
395
} ) ;
389
396
390
397
gulp . task ( servicesFile , false , [ "lib" , "generate-diagnostics" ] , ( ) => {
@@ -410,13 +417,13 @@ gulp.task(servicesFile, false, ["lib", "generate-diagnostics"], () => {
410
417
file . path = nodeDefinitionsFile ;
411
418
return content + "\r\nexport = ts;" ;
412
419
} ) )
413
- . pipe ( gulp . dest ( ". " ) ) ,
420
+ . pipe ( gulp . dest ( "src/services " ) ) ,
414
421
completedDts . pipe ( clone ( ) )
415
422
. pipe ( insert . transform ( ( content , file ) => {
416
423
file . path = nodeStandaloneDefinitionsFile ;
417
424
return content . replace ( / d e c l a r e ( n a m e s p a c e | m o d u l e ) t s / g, 'declare module "typescript"' ) ;
418
425
} ) )
419
- ] ) . pipe ( gulp . dest ( ". " ) ) ;
426
+ ] ) . pipe ( gulp . dest ( "src/services " ) ) ;
420
427
} ) ;
421
428
422
429
// cancellationToken.js
@@ -442,7 +449,7 @@ gulp.task(typingsInstallerJs, false, [servicesFile], () => {
442
449
. pipe ( cancellationTokenProject ( ) )
443
450
. pipe ( prependCopyright ( ) )
444
451
. pipe ( sourcemaps . write ( "." ) )
445
- . pipe ( gulp . dest ( ". " ) ) ;
452
+ . pipe ( gulp . dest ( "src/server/typingsInstaller " ) ) ;
446
453
} ) ;
447
454
448
455
const serverFile = path . join ( builtLocalDirectory , "tsserver.js" ) ;
@@ -455,7 +462,7 @@ gulp.task(serverFile, false, [servicesFile, typingsInstallerJs, cancellationToke
455
462
. pipe ( serverProject ( ) )
456
463
. pipe ( prependCopyright ( ) )
457
464
. pipe ( sourcemaps . write ( "." ) )
458
- . pipe ( gulp . dest ( ". " ) ) ;
465
+ . pipe ( gulp . dest ( "src/server " ) ) ;
459
466
} ) ;
460
467
461
468
const tsserverLibraryFile = path . join ( builtLocalDirectory , "tsserverlibrary.js" ) ;
@@ -471,12 +478,12 @@ gulp.task(tsserverLibraryFile, false, [servicesFile], (done) => {
471
478
return merge2 ( [
472
479
js . pipe ( prependCopyright ( ) )
473
480
. pipe ( sourcemaps . write ( "." ) )
474
- . pipe ( gulp . dest ( ". " ) ) ,
481
+ . pipe ( gulp . dest ( "src/server " ) ) ,
475
482
dts . pipe ( prependCopyright ( /*outputCopyright*/ true ) )
476
483
. pipe ( insert . transform ( ( content ) => {
477
484
return content + "\r\nexport = ts;\r\nexport as namespace ts;" ;
478
485
} ) )
479
- . pipe ( gulp . dest ( ". " ) )
486
+ . pipe ( gulp . dest ( "src/server " ) )
480
487
] ) ;
481
488
} ) ;
482
489
@@ -550,7 +557,7 @@ gulp.task(run, false, [servicesFile], () => {
550
557
. pipe ( sourcemaps . init ( ) )
551
558
. pipe ( testProject ( ) )
552
559
. pipe ( sourcemaps . write ( "." , { includeContent : false , sourceRoot : "../../" } ) )
553
- . pipe ( gulp . dest ( ". " ) ) ;
560
+ . pipe ( gulp . dest ( "src/harness " ) ) ;
554
561
} ) ;
555
562
556
563
const internalTests = "internal/" ;
@@ -588,6 +595,7 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
588
595
cleanTestDirs ( ( err ) => {
589
596
if ( err ) { console . error ( err ) ; failWithStatus ( err , 1 ) ; }
590
597
const debug = cmdLineOptions [ "debug" ] ;
598
+ const inspect = cmdLineOptions [ "inspect" ] ;
591
599
const tests = cmdLineOptions [ "tests" ] ;
592
600
const light = cmdLineOptions [ "light" ] ;
593
601
const stackTraceLimit = cmdLineOptions [ "stackTraceLimit" ] ;
@@ -624,7 +632,10 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
624
632
// default timeout is 2sec which really should be enough, but maybe we just need a small amount longer
625
633
if ( ! runInParallel ) {
626
634
const args = [ ] ;
627
- if ( debug ) {
635
+ if ( inspect ) {
636
+ args . push ( "--inspect" ) ;
637
+ }
638
+ if ( inspect || debug ) {
628
639
args . push ( "--debug-brk" ) ;
629
640
}
630
641
args . push ( "-R" , reporter ) ;
@@ -739,7 +750,7 @@ gulp.task("browserify", "Runs browserify on run.js to produce a file suitable fo
739
750
const originalMap = file . sourceMap ;
740
751
const prebundledContent = file . contents . toString ( ) ;
741
752
// Make paths absolute to help sorcery deal with all the terrible paths being thrown around
742
- originalMap . sources = originalMap . sources . map ( s => path . resolve ( s ) ) ;
753
+ originalMap . sources = originalMap . sources . map ( s => path . resolve ( path . join ( "src/harness" , s ) ) ) ;
743
754
// intoStream (below) makes browserify think the input file is named this, so this is what it puts in the sourcemap
744
755
originalMap . file = "built/local/_stream_0.js" ;
745
756
@@ -768,7 +779,7 @@ gulp.task("browserify", "Runs browserify on run.js to produce a file suitable fo
768
779
} ) ;
769
780
} ) )
770
781
. pipe ( sourcemaps . write ( "." , { includeContent : false } ) )
771
- . pipe ( gulp . dest ( ". " ) ) ;
782
+ . pipe ( gulp . dest ( "src/harness " ) ) ;
772
783
} ) ;
773
784
774
785
@@ -950,7 +961,7 @@ gulp.task("update-sublime", "Updates the sublime plugin's tsserver", ["local", s
950
961
} ) ;
951
962
952
963
gulp . task ( "build-rules" , "Compiles tslint rules to js" , ( ) => {
953
- const settings : tsc . Settings = getCompilerSettings ( { module : "commonjs" } , /*useBuiltCompiler*/ false ) ;
964
+ const settings : tsc . Settings = getCompilerSettings ( { module : "commonjs" , "lib" : [ "es6" ] } , /*useBuiltCompiler*/ false ) ;
954
965
const dest = path . join ( builtLocalDirectory , "tslint" ) ;
955
966
return gulp . src ( "scripts/tslint/**/*.ts" )
956
967
. pipe ( newer ( {
@@ -1009,40 +1020,16 @@ function spawnLintWorker(files: {path: string}[], callback: (failures: number) =
1009
1020
}
1010
1021
1011
1022
gulp . task ( "lint" , "Runs tslint on the compiler sources. Optional arguments are: --f[iles]=regex" , [ "build-rules" ] , ( ) => {
1012
- const fileMatcher = RegExp ( cmdLineOptions [ "files" ] ) ;
1013
1023
if ( fold . isTravis ( ) ) console . log ( fold . start ( "lint" ) ) ;
1014
-
1015
- let files : { stat : fs . Stats , path : string } [ ] = [ ] ;
1016
- return gulp . src ( lintTargets , { read : false } )
1017
- . pipe ( through2 . obj ( ( chunk , enc , cb ) => {
1018
- files . push ( chunk ) ;
1019
- cb ( ) ;
1020
- } , ( cb ) => {
1021
- files = files . filter ( file => fileMatcher . test ( file . path ) ) . sort ( ( filea , fileb ) => filea . stat . size - fileb . stat . size ) ;
1022
- const workerCount = cmdLineOptions [ "workers" ] ;
1023
- for ( let i = 0 ; i < workerCount ; i ++ ) {
1024
- spawnLintWorker ( files , finished ) ;
1025
- }
1026
-
1027
- let completed = 0 ;
1028
- let failures = 0 ;
1029
- function finished ( fails ) {
1030
- completed ++ ;
1031
- failures += fails ;
1032
- if ( completed === workerCount ) {
1033
- if ( fold . isTravis ( ) ) console . log ( fold . end ( "lint" ) ) ;
1034
- if ( failures > 0 ) {
1035
- throw new Error ( `Linter errors: ${ failures } ` ) ;
1036
- }
1037
- else {
1038
- cb ( ) ;
1039
- }
1040
- }
1041
- }
1042
- } ) ) ;
1024
+ const fileMatcher = cmdLineOptions [ "files" ] ;
1025
+ const files = fileMatcher
1026
+ ? `src/**/${ fileMatcher } `
1027
+ : "Gulpfile.ts 'src/**/*.ts' --exclude src/lib/es5.d.ts --exclude 'src/lib/*.generated.d.ts'" ;
1028
+ const cmd = `node node_modules/tslint/bin/tslint ${ files } --format stylish` ;
1029
+ console . log ( "Linting: " + cmd ) ;
1030
+ child_process . execSync ( cmd , { stdio : [ 0 , 1 , 2 ] } ) ;
1043
1031
} ) ;
1044
1032
1045
-
1046
1033
gulp . task ( "default" , "Runs 'local'" , [ "local" ] ) ;
1047
1034
1048
1035
gulp . task ( "watch" , "Watches the src/ directory for changes and executes runtests-parallel." , [ ] , ( ) => {
0 commit comments