1
1
/// <reference path="scripts/types/ambient.d.ts" />
2
- /// <reference types="q" />
3
-
4
2
import * as cp from "child_process" ;
5
3
import * as path from "path" ;
6
4
import * as fs from "fs" ;
@@ -13,16 +11,19 @@ import newer = require("gulp-newer");
13
11
import tsc = require( "gulp-typescript" ) ;
14
12
declare module "gulp-typescript" {
15
13
interface Settings {
16
- stripInternal ?: boolean ;
14
+ pretty ?: boolean ;
17
15
newLine ?: string ;
16
+ noImplicitThis ?: boolean ;
17
+ stripInternal ?: boolean ;
18
+ types ?: string [ ] ;
18
19
}
19
20
interface CompileStream extends NodeJS . ReadWriteStream { } // Either gulp or gulp-typescript has some odd typings which don't reflect reality, making this required
20
21
}
21
22
import * as insert from "gulp-insert" ;
22
23
import * as sourcemaps from "gulp-sourcemaps" ;
24
+ import Q = require( "q" ) ;
23
25
declare global {
24
- // This is silly. We include Q because orchestrator (a part of gulp) depends on it, but its not included.
25
- // `del` further depends on `Promise` (and is also not included), so we just, patch the global scope's Promise to Q's
26
+ // `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
27
type Promise < T > = Q . Promise < T > ;
27
28
}
28
29
import del = require( "del" ) ;
@@ -84,12 +85,9 @@ let host = cmdLineOptions["host"];
84
85
85
86
// Constants
86
87
const compilerDirectory = "src/compiler/" ;
87
- const servicesDirectory = "src/services/" ;
88
- const serverDirectory = "src/server/" ;
89
88
const harnessDirectory = "src/harness/" ;
90
89
const libraryDirectory = "src/lib/" ;
91
90
const scriptsDirectory = "scripts/" ;
92
- const unittestsDirectory = "tests/cases/unittests/" ;
93
91
const docDirectory = "doc/" ;
94
92
95
93
const builtDirectory = "built/" ;
@@ -106,69 +104,6 @@ const nodeModulesPathPrefix = path.resolve("./node_modules/.bin/");
106
104
const isWin = / ^ w i n / . test ( process . platform ) ;
107
105
const mocha = path . join ( nodeModulesPathPrefix , "mocha" ) + ( isWin ? ".cmd" : "" ) ;
108
106
109
- const compilerSources = require ( "./src/compiler/tsconfig.json" ) . files . map ( ( file ) => path . join ( compilerDirectory , file ) ) ;
110
-
111
- const servicesSources = require ( "./src/services/tsconfig.json" ) . files . map ( ( file ) => path . join ( servicesDirectory , file ) ) ;
112
-
113
- const serverCoreSources = require ( "./src/server/tsconfig.json" ) . files . map ( ( file ) => path . join ( serverDirectory , file ) ) ;
114
-
115
- const languageServiceLibrarySources = [
116
- "editorServices.ts" ,
117
- "protocol.d.ts" ,
118
- "session.ts"
119
- ] . map ( function ( f ) {
120
- return path . join ( serverDirectory , f ) ;
121
- } ) . concat ( servicesSources ) ;
122
-
123
- const harnessCoreSources = [
124
- "harness.ts" ,
125
- "sourceMapRecorder.ts" ,
126
- "harnessLanguageService.ts" ,
127
- "fourslash.ts" ,
128
- "runnerbase.ts" ,
129
- "compilerRunner.ts" ,
130
- "typeWriter.ts" ,
131
- "fourslashRunner.ts" ,
132
- "projectsRunner.ts" ,
133
- "loggedIO.ts" ,
134
- "rwcRunner.ts" ,
135
- "test262Runner.ts" ,
136
- "runner.ts"
137
- ] . map ( function ( f ) {
138
- return path . join ( harnessDirectory , f ) ;
139
- } ) ;
140
-
141
- const harnessSources = harnessCoreSources . concat ( [
142
- "incrementalParser.ts" ,
143
- "jsDocParsing.ts" ,
144
- "services/colorization.ts" ,
145
- "services/documentRegistry.ts" ,
146
- "services/preProcessFile.ts" ,
147
- "services/patternMatcher.ts" ,
148
- "session.ts" ,
149
- "versionCache.ts" ,
150
- "convertToBase64.ts" ,
151
- "transpile.ts" ,
152
- "reuseProgramStructure.ts" ,
153
- "cachingInServerLSHost.ts" ,
154
- "moduleResolution.ts" ,
155
- "tsconfigParsing.ts" ,
156
- "commandLineParsing.ts" ,
157
- "convertCompilerOptionsFromJson.ts" ,
158
- "convertTypingOptionsFromJson.ts" ,
159
- "tsserverProjectSystem.ts" ,
160
- "matchFiles.ts" ,
161
- ] . map ( function ( f ) {
162
- return path . join ( unittestsDirectory , f ) ;
163
- } ) ) . concat ( [
164
- "protocol.d.ts" ,
165
- "session.ts" ,
166
- "client.ts" ,
167
- "editorServices.ts"
168
- ] . map ( function ( f ) {
169
- return path . join ( serverDirectory , f ) ;
170
- } ) ) ;
171
-
172
107
const es2015LibrarySources = [
173
108
"es2015.core.d.ts" ,
174
109
"es2015.collection.d.ts" ,
@@ -308,6 +243,11 @@ function needsUpdate(source: string | string[], dest: string | string[]): boolea
308
243
309
244
function getCompilerSettings ( base : tsc . Settings , useBuiltCompiler ?: boolean ) : tsc . Settings {
310
245
const copy : tsc . Settings = { } ;
246
+ copy . noEmitOnError = true ;
247
+ copy . noImplicitAny = true ;
248
+ copy . noImplicitThis = true ;
249
+ copy . pretty = true ;
250
+ copy . types = [ ] ;
311
251
for ( const key in base ) {
312
252
copy [ key ] = base [ key ] ;
313
253
}
@@ -494,21 +434,18 @@ const tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js")
494
434
const tsserverLibraryDefinitionFile = path . join ( builtLocalDirectory , "tsserverlibrary.d.ts" ) ;
495
435
496
436
gulp . task ( tsserverLibraryFile , false , [ servicesFile ] , ( done ) => {
497
- const settings : tsc . Settings = getCompilerSettings ( {
498
- declaration : true ,
499
- outFile : tsserverLibraryFile
500
- } , /*useBuiltCompiler*/ true ) ;
501
- const { js, dts} : { js : NodeJS . ReadableStream , dts : NodeJS . ReadableStream } = gulp . src ( languageServiceLibrarySources )
437
+ const serverLibraryProject = tsc . createProject ( "src/server/tsconfig.library.json" , getCompilerSettings ( { } , /*useBuiltCompiler*/ true ) ) ;
438
+ const { js, dts} : { js : NodeJS . ReadableStream , dts : NodeJS . ReadableStream } = serverLibraryProject . src ( )
502
439
. pipe ( sourcemaps . init ( ) )
503
440
. pipe ( newer ( tsserverLibraryFile ) )
504
- . pipe ( tsc ( settings ) ) ;
441
+ . pipe ( tsc ( serverLibraryProject ) ) ;
505
442
506
443
return merge2 ( [
507
444
js . pipe ( prependCopyright ( ) )
508
445
. pipe ( sourcemaps . write ( "." ) )
509
- . pipe ( gulp . dest ( "." ) ) ,
446
+ . pipe ( gulp . dest ( builtLocalDirectory ) ) ,
510
447
dts . pipe ( prependCopyright ( ) )
511
- . pipe ( gulp . dest ( "." ) )
448
+ . pipe ( gulp . dest ( builtLocalDirectory ) )
512
449
] ) ;
513
450
} ) ;
514
451
@@ -577,15 +514,13 @@ gulp.task("LKG", "Makes a new LKG out of the built js files", ["clean", "dontUse
577
514
// Task to build the tests infrastructure using the built compiler
578
515
const run = path . join ( builtLocalDirectory , "run.js" ) ;
579
516
gulp . task ( run , false , [ servicesFile ] , ( ) => {
580
- const settings : tsc . Settings = getCompilerSettings ( {
581
- outFile : run
582
- } , /*useBuiltCompiler*/ true ) ;
583
- return gulp . src ( harnessSources )
517
+ const testProject = tsc . createProject ( "src/harness/tsconfig.json" , getCompilerSettings ( { } , /*useBuiltCompiler*/ true ) ) ;
518
+ return testProject . src ( )
584
519
. pipe ( newer ( run ) )
585
520
. pipe ( sourcemaps . init ( ) )
586
- . pipe ( tsc ( settings ) )
521
+ . pipe ( tsc ( testProject ) )
587
522
. pipe ( sourcemaps . write ( "." , { includeContent : false , sourceRoot : "../../" } ) )
588
- . pipe ( gulp . dest ( "." ) ) ;
523
+ . pipe ( gulp . dest ( builtLocalDirectory ) ) ;
589
524
} ) ;
590
525
591
526
const internalTests = "internal/" ;
@@ -759,23 +694,50 @@ gulp.task(nodeServerOutFile, false, [servicesFile], () => {
759
694
. pipe ( gulp . dest ( path . dirname ( nodeServerOutFile ) ) ) ;
760
695
} ) ;
761
696
697
+ import convertMap = require( "convert-source-map" ) ;
698
+ import sorcery = require( "sorcery" ) ;
699
+ declare module "convert-source-map" {
700
+ export function fromSource ( source : string , largeSource ?: boolean ) : SourceMapConverter ;
701
+ }
702
+
762
703
gulp . task ( "browserify" , "Runs browserify on run.js to produce a file suitable for running tests in the browser" , [ servicesFile ] , ( done ) => {
763
- const settings : tsc . Settings = getCompilerSettings ( {
764
- outFile : "built/local/bundle.js"
765
- } , /*useBuiltCompiler*/ true ) ;
766
- return gulp . src ( harnessSources )
704
+ const testProject = tsc . createProject ( "src/harness/tsconfig.json" , getCompilerSettings ( { outFile : "built/local/bundle.js" } , /*useBuiltCompiler*/ true ) ) ;
705
+ return testProject . src ( )
767
706
. pipe ( newer ( "built/local/bundle.js" ) )
768
707
. pipe ( sourcemaps . init ( ) )
769
- . pipe ( tsc ( settings ) )
708
+ . pipe ( tsc ( testProject ) )
770
709
. pipe ( through2 . obj ( ( file , enc , next ) => {
771
- browserify ( intoStream ( file . contents ) )
710
+ const originalMap = file . sourceMap ;
711
+ const prebundledContent = file . contents . toString ( ) ;
712
+ // Make paths absolute to help sorcery deal with all the terrible paths being thrown around
713
+ originalMap . sources = originalMap . sources . map ( s => path . resolve ( s ) ) ;
714
+ // intoStream (below) makes browserify think the input file is named this, so this is what it puts in the sourcemap
715
+ originalMap . file = "built/local/_stream_0.js" ;
716
+
717
+ browserify ( intoStream ( file . contents ) , { debug : true } )
772
718
. bundle ( ( err , res ) => {
773
719
// assumes file.contents is a Buffer
774
- file . contents = res ;
720
+ const maps = JSON . parse ( convertMap . fromSource ( res . toString ( ) , /*largeSource*/ true ) . toJSON ( ) ) ;
721
+ delete maps . sourceRoot ;
722
+ maps . sources = maps . sources . map ( s => path . resolve ( s === "_stream_0.js" ? "built/local/_stream_0.js" : s ) ) ;
723
+ // Strip browserify's inline comments away (could probably just let sorcery do this, but then we couldn't fix the paths)
724
+ file . contents = new Buffer ( convertMap . removeComments ( res . toString ( ) ) ) ;
725
+ const chain = sorcery . loadSync ( "built/local/bundle.js" , {
726
+ content : {
727
+ "built/local/_stream_0.js" : prebundledContent ,
728
+ "built/local/bundle.js" : file . contents . toString ( )
729
+ } ,
730
+ sourcemaps : {
731
+ "built/local/_stream_0.js" : originalMap ,
732
+ "built/local/bundle.js" : maps ,
733
+ }
734
+ } ) ;
735
+ const finalMap = chain . apply ( ) ;
736
+ file . sourceMap = finalMap ;
775
737
next ( undefined , file ) ;
776
738
} ) ;
777
739
} ) )
778
- . pipe ( sourcemaps . write ( "." , { includeContent : false , sourceRoot : "../../" } ) )
740
+ . pipe ( sourcemaps . write ( "." , { includeContent : false } ) )
779
741
. pipe ( gulp . dest ( "." ) ) ;
780
742
} ) ;
781
743
@@ -1007,36 +969,37 @@ function lintFile(options, path) {
1007
969
return lintFileContents ( options , path , contents ) ;
1008
970
}
1009
971
1010
- const lintTargets = [ "Gulpfile.ts" ]
1011
- . concat ( compilerSources )
1012
- . concat ( harnessSources )
1013
- // Other harness sources
1014
- . concat ( [ "instrumenter.ts" ] . map ( function ( f ) { return path . join ( harnessDirectory , f ) ; } ) )
1015
- . concat ( serverCoreSources )
1016
- . concat ( tslintRulesFiles )
1017
- . concat ( servicesSources ) ;
972
+ const lintTargets = [
973
+ "Gulpfile.ts" ,
974
+ "src/compiler/**/*.ts" ,
975
+ "src/harness/**/*.ts" ,
976
+ "!src/harness/unittests/services/formatting/**/*.ts" ,
977
+ "src/server/**/*.ts" ,
978
+ "scripts/tslint/**/*.ts" ,
979
+ "src/services/**/*.ts" ,
980
+ ] ;
1018
981
1019
982
1020
983
gulp . task ( "lint" , "Runs tslint on the compiler sources. Optional arguments are: --f[iles]=regex" , [ "build-rules" ] , ( ) => {
984
+ const fileMatcher = RegExp ( cmdLineOptions [ "files" ] ) ;
1021
985
const lintOptions = getLinterOptions ( ) ;
1022
986
let failed = 0 ;
1023
- const fileMatcher = RegExp ( cmdLineOptions [ "files" ] ) ;
1024
- const done = { } ;
1025
- for ( const i in lintTargets ) {
1026
- const target = lintTargets [ i ] ;
1027
- if ( ! done [ target ] && fileMatcher . test ( target ) ) {
1028
- const result = lintFile ( lintOptions , target ) ;
987
+ return gulp . src ( lintTargets )
988
+ . pipe ( insert . transform ( ( contents , file ) => {
989
+ if ( ! fileMatcher . test ( file . path ) ) return contents ;
990
+ const result = lintFile ( lintOptions , file . path ) ;
1029
991
if ( result . failureCount > 0 ) {
1030
992
console . log ( result . output ) ;
1031
993
failed += result . failureCount ;
1032
994
}
1033
- done [ target ] = true ;
1034
- }
1035
- }
1036
- if ( failed > 0 ) {
1037
- console . error ( "Linter errors." ) ;
1038
- process . exit ( 1 ) ;
1039
- }
995
+ return contents ; // TODO (weswig): Automatically apply fixes? :3
996
+ } ) )
997
+ . on ( "end" , ( ) => {
998
+ if ( failed > 0 ) {
999
+ console . error ( "Linter errors." ) ;
1000
+ process . exit ( 1 ) ;
1001
+ }
1002
+ } ) ;
1040
1003
} ) ;
1041
1004
1042
1005
0 commit comments