@@ -11,8 +11,11 @@ import newer = require("gulp-newer");
11
11
import tsc = require( "gulp-typescript" ) ;
12
12
declare module "gulp-typescript" {
13
13
interface Settings {
14
- stripInternal ?: boolean ;
14
+ pretty ?: boolean ;
15
15
newLine ?: string ;
16
+ noImplicitThis ?: boolean ;
17
+ stripInternal ?: boolean ;
18
+ types ?: string [ ] ;
16
19
}
17
20
interface CompileStream extends NodeJS . ReadWriteStream { } // Either gulp or gulp-typescript has some odd typings which don't reflect reality, making this required
18
21
}
@@ -56,7 +59,6 @@ const cmdLineOptions = minimist(process.argv.slice(2), {
56
59
browser : process . env . browser || process . env . b || "IE" ,
57
60
tests : process . env . test || process . env . tests || process . env . t ,
58
61
light : process . env . light || false ,
59
- port : process . env . port || process . env . p || "8888" ,
60
62
reporter : process . env . reporter || process . env . r ,
61
63
lint : process . env . lint || true ,
62
64
files : process . env . f || process . env . file || process . env . files || "" ,
@@ -82,12 +84,9 @@ let host = cmdLineOptions["host"];
82
84
83
85
// Constants
84
86
const compilerDirectory = "src/compiler/" ;
85
- const servicesDirectory = "src/services/" ;
86
- const serverDirectory = "src/server/" ;
87
87
const harnessDirectory = "src/harness/" ;
88
88
const libraryDirectory = "src/lib/" ;
89
89
const scriptsDirectory = "scripts/" ;
90
- const unittestsDirectory = "tests/cases/unittests/" ;
91
90
const docDirectory = "doc/" ;
92
91
93
92
const builtDirectory = "built/" ;
@@ -104,69 +103,6 @@ const nodeModulesPathPrefix = path.resolve("./node_modules/.bin/");
104
103
const isWin = / ^ w i n / . test ( process . platform ) ;
105
104
const mocha = path . join ( nodeModulesPathPrefix , "mocha" ) + ( isWin ? ".cmd" : "" ) ;
106
105
107
- const compilerSources = require ( "./src/compiler/tsconfig.json" ) . files . map ( ( file ) => path . join ( compilerDirectory , file ) ) ;
108
-
109
- const servicesSources = require ( "./src/services/tsconfig.json" ) . files . map ( ( file ) => path . join ( servicesDirectory , file ) ) ;
110
-
111
- const serverCoreSources = require ( "./src/server/tsconfig.json" ) . files . map ( ( file ) => path . join ( serverDirectory , file ) ) ;
112
-
113
- const languageServiceLibrarySources = [
114
- "editorServices.ts" ,
115
- "protocol.d.ts" ,
116
- "session.ts"
117
- ] . map ( function ( f ) {
118
- return path . join ( serverDirectory , f ) ;
119
- } ) . concat ( servicesSources ) ;
120
-
121
- const harnessCoreSources = [
122
- "harness.ts" ,
123
- "sourceMapRecorder.ts" ,
124
- "harnessLanguageService.ts" ,
125
- "fourslash.ts" ,
126
- "runnerbase.ts" ,
127
- "compilerRunner.ts" ,
128
- "typeWriter.ts" ,
129
- "fourslashRunner.ts" ,
130
- "projectsRunner.ts" ,
131
- "loggedIO.ts" ,
132
- "rwcRunner.ts" ,
133
- "test262Runner.ts" ,
134
- "runner.ts"
135
- ] . map ( function ( f ) {
136
- return path . join ( harnessDirectory , f ) ;
137
- } ) ;
138
-
139
- const harnessSources = harnessCoreSources . concat ( [
140
- "incrementalParser.ts" ,
141
- "jsDocParsing.ts" ,
142
- "services/colorization.ts" ,
143
- "services/documentRegistry.ts" ,
144
- "services/preProcessFile.ts" ,
145
- "services/patternMatcher.ts" ,
146
- "session.ts" ,
147
- "versionCache.ts" ,
148
- "convertToBase64.ts" ,
149
- "transpile.ts" ,
150
- "reuseProgramStructure.ts" ,
151
- "cachingInServerLSHost.ts" ,
152
- "moduleResolution.ts" ,
153
- "tsconfigParsing.ts" ,
154
- "commandLineParsing.ts" ,
155
- "convertCompilerOptionsFromJson.ts" ,
156
- "convertTypingOptionsFromJson.ts" ,
157
- "tsserverProjectSystem.ts" ,
158
- "matchFiles.ts" ,
159
- ] . map ( function ( f ) {
160
- return path . join ( unittestsDirectory , f ) ;
161
- } ) ) . concat ( [
162
- "protocol.d.ts" ,
163
- "session.ts" ,
164
- "client.ts" ,
165
- "editorServices.ts"
166
- ] . map ( function ( f ) {
167
- return path . join ( serverDirectory , f ) ;
168
- } ) ) ;
169
-
170
106
const es2015LibrarySources = [
171
107
"es2015.core.d.ts" ,
172
108
"es2015.collection.d.ts" ,
@@ -306,6 +242,11 @@ function needsUpdate(source: string | string[], dest: string | string[]): boolea
306
242
307
243
function getCompilerSettings ( base : tsc . Settings , useBuiltCompiler ?: boolean ) : tsc . Settings {
308
244
const copy : tsc . Settings = { } ;
245
+ copy . noEmitOnError = true ;
246
+ copy . noImplicitAny = true ;
247
+ copy . noImplicitThis = true ;
248
+ copy . pretty = true ;
249
+ copy . types = [ ] ;
309
250
for ( const key in base ) {
310
251
copy [ key ] = base [ key ] ;
311
252
}
@@ -492,21 +433,18 @@ const tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js")
492
433
const tsserverLibraryDefinitionFile = path . join ( builtLocalDirectory , "tsserverlibrary.d.ts" ) ;
493
434
494
435
gulp . task ( tsserverLibraryFile , false , [ servicesFile ] , ( done ) => {
495
- const settings : tsc . Settings = getCompilerSettings ( {
496
- declaration : true ,
497
- outFile : tsserverLibraryFile
498
- } , /*useBuiltCompiler*/ true ) ;
499
- const { js, dts} : { js : NodeJS . ReadableStream , dts : NodeJS . ReadableStream } = gulp . src ( languageServiceLibrarySources )
436
+ const serverLibraryProject = tsc . createProject ( "src/server/tsconfig.library.json" , getCompilerSettings ( { } , /*useBuiltCompiler*/ true ) ) ;
437
+ const { js, dts} : { js : NodeJS . ReadableStream , dts : NodeJS . ReadableStream } = serverLibraryProject . src ( )
500
438
. pipe ( sourcemaps . init ( ) )
501
439
. pipe ( newer ( tsserverLibraryFile ) )
502
- . pipe ( tsc ( settings ) ) ;
440
+ . pipe ( tsc ( serverLibraryProject ) ) ;
503
441
504
442
return merge2 ( [
505
443
js . pipe ( prependCopyright ( ) )
506
444
. pipe ( sourcemaps . write ( "." ) )
507
- . pipe ( gulp . dest ( "." ) ) ,
445
+ . pipe ( gulp . dest ( builtLocalDirectory ) ) ,
508
446
dts . pipe ( prependCopyright ( ) )
509
- . pipe ( gulp . dest ( "." ) )
447
+ . pipe ( gulp . dest ( builtLocalDirectory ) )
510
448
] ) ;
511
449
} ) ;
512
450
@@ -575,15 +513,13 @@ gulp.task("LKG", "Makes a new LKG out of the built js files", ["clean", "dontUse
575
513
// Task to build the tests infrastructure using the built compiler
576
514
const run = path . join ( builtLocalDirectory , "run.js" ) ;
577
515
gulp . task ( run , false , [ servicesFile ] , ( ) => {
578
- const settings : tsc . Settings = getCompilerSettings ( {
579
- outFile : run
580
- } , /*useBuiltCompiler*/ true ) ;
581
- return gulp . src ( harnessSources )
516
+ const testProject = tsc . createProject ( "src/harness/tsconfig.json" , getCompilerSettings ( { } , /*useBuiltCompiler*/ true ) ) ;
517
+ return testProject . src ( )
582
518
. pipe ( newer ( run ) )
583
519
. pipe ( sourcemaps . init ( ) )
584
- . pipe ( tsc ( settings ) )
520
+ . pipe ( tsc ( testProject ) )
585
521
. pipe ( sourcemaps . write ( "." , { includeContent : false , sourceRoot : "../../" } ) )
586
- . pipe ( gulp . dest ( "." ) ) ;
522
+ . pipe ( gulp . dest ( builtLocalDirectory ) ) ;
587
523
} ) ;
588
524
589
525
const internalTests = "internal/" ;
@@ -757,23 +693,50 @@ gulp.task(nodeServerOutFile, false, [servicesFile], () => {
757
693
. pipe ( gulp . dest ( path . dirname ( nodeServerOutFile ) ) ) ;
758
694
} ) ;
759
695
696
+ import convertMap = require( "convert-source-map" ) ;
697
+ import sorcery = require( "sorcery" ) ;
698
+ declare module "convert-source-map" {
699
+ export function fromSource ( source : string , largeSource ?: boolean ) : SourceMapConverter ;
700
+ }
701
+
760
702
gulp . task ( "browserify" , "Runs browserify on run.js to produce a file suitable for running tests in the browser" , [ servicesFile ] , ( done ) => {
761
- const settings : tsc . Settings = getCompilerSettings ( {
762
- outFile : "built/local/bundle.js"
763
- } , /*useBuiltCompiler*/ true ) ;
764
- return gulp . src ( harnessSources )
703
+ const testProject = tsc . createProject ( "src/harness/tsconfig.json" , getCompilerSettings ( { outFile : "built/local/bundle.js" } , /*useBuiltCompiler*/ true ) ) ;
704
+ return testProject . src ( )
765
705
. pipe ( newer ( "built/local/bundle.js" ) )
766
706
. pipe ( sourcemaps . init ( ) )
767
- . pipe ( tsc ( settings ) )
707
+ . pipe ( tsc ( testProject ) )
768
708
. pipe ( through2 . obj ( ( file , enc , next ) => {
769
- browserify ( intoStream ( file . contents ) )
709
+ const originalMap = file . sourceMap ;
710
+ const prebundledContent = file . contents . toString ( ) ;
711
+ // Make paths absolute to help sorcery deal with all the terrible paths being thrown around
712
+ originalMap . sources = originalMap . sources . map ( s => path . resolve ( "src" , s ) ) ;
713
+ // intoStream (below) makes browserify think the input file is named this, so this is what it puts in the sourcemap
714
+ originalMap . file = "built/local/_stream_0.js" ;
715
+
716
+ browserify ( intoStream ( file . contents ) , { debug : true } )
770
717
. bundle ( ( err , res ) => {
771
718
// assumes file.contents is a Buffer
772
- file . contents = res ;
719
+ const maps = JSON . parse ( convertMap . fromSource ( res . toString ( ) , /*largeSource*/ true ) . toJSON ( ) ) ;
720
+ delete maps . sourceRoot ;
721
+ maps . sources = maps . sources . map ( s => path . resolve ( s === "_stream_0.js" ? "built/local/_stream_0.js" : s ) ) ;
722
+ // Strip browserify's inline comments away (could probably just let sorcery do this, but then we couldn't fix the paths)
723
+ file . contents = new Buffer ( convertMap . removeComments ( res . toString ( ) ) ) ;
724
+ const chain = sorcery . loadSync ( "built/local/bundle.js" , {
725
+ content : {
726
+ "built/local/_stream_0.js" : prebundledContent ,
727
+ "built/local/bundle.js" : file . contents . toString ( )
728
+ } ,
729
+ sourcemaps : {
730
+ "built/local/_stream_0.js" : originalMap ,
731
+ "built/local/bundle.js" : maps ,
732
+ }
733
+ } ) ;
734
+ const finalMap = chain . apply ( ) ;
735
+ file . sourceMap = finalMap ;
773
736
next ( undefined , file ) ;
774
737
} ) ;
775
738
} ) )
776
- . pipe ( sourcemaps . write ( "." , { includeContent : false , sourceRoot : "../../" } ) )
739
+ . pipe ( sourcemaps . write ( "." , { includeContent : false } ) )
777
740
. pipe ( gulp . dest ( "." ) ) ;
778
741
} ) ;
779
742
@@ -802,7 +765,7 @@ function writeTestConfigFile(tests: string, light: boolean, taskConfigsFolder?:
802
765
}
803
766
804
767
805
- gulp . task ( "runtests-browser" , "Runs the tests using the built run.js file like 'gulp runtests'. Syntax is gulp runtests-browser. Additional optional parameters --tests=[regex], --port=, -- browser=[chrome|IE]" , [ "browserify" , nodeServerOutFile ] , ( done ) => {
768
+ gulp . task ( "runtests-browser" , "Runs the tests using the built run.js file like 'gulp runtests'. Syntax is gulp runtests-browser. Additional optional parameters --tests=[regex], --browser=[chrome|IE]" , [ "browserify" , nodeServerOutFile ] , ( done ) => {
806
769
cleanTestDirs ( ( err ) => {
807
770
if ( err ) { console . error ( err ) ; done ( err ) ; process . exit ( 1 ) ; }
808
771
host = "node" ;
@@ -817,9 +780,6 @@ gulp.task("runtests-browser", "Runs the tests using the built run.js file like '
817
780
}
818
781
819
782
const args = [ nodeServerOutFile ] ;
820
- if ( cmdLineOptions [ "port" ] ) {
821
- args . push ( cmdLineOptions [ "port" ] ) ;
822
- }
823
783
if ( cmdLineOptions [ "browser" ] ) {
824
784
args . push ( cmdLineOptions [ "browser" ] ) ;
825
785
}
@@ -954,37 +914,20 @@ gulp.task("update-sublime", "Updates the sublime plugin's tsserver", ["local", s
954
914
return gulp . src ( [ serverFile , serverFile + ".map" ] ) . pipe ( gulp . dest ( "../TypeScript-Sublime-Plugin/tsserver/" ) ) ;
955
915
} ) ;
956
916
957
-
958
- const tslintRuleDir = "scripts/tslint" ;
959
- const tslintRules = [
960
- "nextLineRule" ,
961
- "preferConstRule" ,
962
- "booleanTriviaRule" ,
963
- "typeOperatorSpacingRule" ,
964
- "noInOperatorRule" ,
965
- "noIncrementDecrementRule" ,
966
- "objectLiteralSurroundingSpaceRule" ,
967
- ] ;
968
- const tslintRulesFiles = tslintRules . map ( function ( p ) {
969
- return path . join ( tslintRuleDir , p + ".ts" ) ;
970
- } ) ;
971
- const tslintRulesOutFiles = tslintRules . map ( function ( p , i ) {
972
- const pathname = path . join ( builtLocalDirectory , "tslint" , p + ".js" ) ;
973
- gulp . task ( pathname , false , [ ] , ( ) => {
974
- const settings : tsc . Settings = getCompilerSettings ( { module : "commonjs" } , /*useBuiltCompiler*/ false ) ;
975
- return gulp . src ( tslintRulesFiles [ i ] )
976
- . pipe ( newer ( pathname ) )
977
- . pipe ( sourcemaps . init ( ) )
978
- . pipe ( tsc ( settings ) )
979
- . pipe ( sourcemaps . write ( "." ) )
980
- . pipe ( gulp . dest ( path . join ( builtLocalDirectory , "tslint" ) ) ) ;
981
- } ) ;
982
- return pathname ;
917
+ gulp . task ( "build-rules" , "Compiles tslint rules to js" , ( ) => {
918
+ const settings : tsc . Settings = getCompilerSettings ( { module : "commonjs" } , /*useBuiltCompiler*/ false ) ;
919
+ const dest = path . join ( builtLocalDirectory , "tslint" ) ;
920
+ return gulp . src ( "scripts/tslint/**/*.ts" )
921
+ . pipe ( newer ( {
922
+ dest,
923
+ ext : ".js"
924
+ } ) )
925
+ . pipe ( sourcemaps . init ( ) )
926
+ . pipe ( tsc ( settings ) )
927
+ . pipe ( sourcemaps . write ( "." ) )
928
+ . pipe ( gulp . dest ( dest ) ) ;
983
929
} ) ;
984
930
985
- gulp . task ( "build-rules" , "Compiles tslint rules to js" , tslintRulesOutFiles ) ;
986
-
987
-
988
931
function getLinterOptions ( ) {
989
932
return {
990
933
configuration : require ( "./tslint.json" ) ,
@@ -1005,36 +948,38 @@ function lintFile(options, path) {
1005
948
return lintFileContents ( options , path , contents ) ;
1006
949
}
1007
950
1008
- const lintTargets = [ "Gulpfile.ts" ]
1009
- . concat ( compilerSources )
1010
- . concat ( harnessSources )
1011
- // Other harness sources
1012
- . concat ( [ "instrumenter.ts" ] . map ( function ( f ) { return path . join ( harnessDirectory , f ) ; } ) )
1013
- . concat ( serverCoreSources )
1014
- . concat ( tslintRulesFiles )
1015
- . concat ( servicesSources ) ;
951
+ const lintTargets = [
952
+ "Gulpfile.ts" ,
953
+ "src/compiler/**/*.ts" ,
954
+ "src/harness/**/*.ts" ,
955
+ "!src/harness/unittests/services/formatting/**/*.ts" ,
956
+ "src/server/**/*.ts" ,
957
+ "scripts/tslint/**/*.ts" ,
958
+ "src/services/**/*.ts" ,
959
+ "tests/*.ts" , "tests/webhost/*.ts" // Note: does *not* descend recursively
960
+ ] ;
1016
961
1017
962
1018
963
gulp . task ( "lint" , "Runs tslint on the compiler sources. Optional arguments are: --f[iles]=regex" , [ "build-rules" ] , ( ) => {
964
+ const fileMatcher = RegExp ( cmdLineOptions [ "files" ] ) ;
1019
965
const lintOptions = getLinterOptions ( ) ;
1020
966
let failed = 0 ;
1021
- const fileMatcher = RegExp ( cmdLineOptions [ "files" ] ) ;
1022
- const done = { } ;
1023
- for ( const i in lintTargets ) {
1024
- const target = lintTargets [ i ] ;
1025
- if ( ! done [ target ] && fileMatcher . test ( target ) ) {
1026
- const result = lintFile ( lintOptions , target ) ;
967
+ return gulp . src ( lintTargets )
968
+ . pipe ( insert . transform ( ( contents , file ) => {
969
+ if ( ! fileMatcher . test ( file . path ) ) return contents ;
970
+ const result = lintFile ( lintOptions , file . path ) ;
1027
971
if ( result . failureCount > 0 ) {
1028
972
console . log ( result . output ) ;
1029
973
failed += result . failureCount ;
1030
974
}
1031
- done [ target ] = true ;
1032
- }
1033
- }
1034
- if ( failed > 0 ) {
1035
- console . error ( "Linter errors." ) ;
1036
- process . exit ( 1 ) ;
1037
- }
975
+ return contents ; // TODO (weswig): Automatically apply fixes? :3
976
+ } ) )
977
+ . on ( "end" , ( ) => {
978
+ if ( failed > 0 ) {
979
+ console . error ( "Linter errors." ) ;
980
+ process . exit ( 1 ) ;
981
+ }
982
+ } ) ;
1038
983
} ) ;
1039
984
1040
985
0 commit comments