@@ -28,7 +28,6 @@ import minimist = require("minimist");
2828import browserify = require( "browserify" ) ;
2929import through2 = require( "through2" ) ;
3030import merge2 = require( "merge2" ) ;
31- import intoStream = require( "into-stream" ) ;
3231import * as os from "os" ;
3332import fold = require( "travis-fold" ) ;
3433const gulp = helpMaker ( originalGulp ) ;
@@ -39,25 +38,25 @@ Error.stackTraceLimit = 1000;
3938
4039const cmdLineOptions = minimist ( process . argv . slice ( 2 ) , {
4140 boolean : [ "debug" , "inspect" , "light" , "colors" , "lint" , "soft" ] ,
42- string : [ "browser" , "tests" , "host" , "reporter" , "stackTraceLimit" ] ,
41+ string : [ "browser" , "tests" , "host" , "reporter" , "stackTraceLimit" , "timeout" ] ,
4342 alias : {
4443 b : "browser" ,
45- d : "debug" ,
46- t : "tests " ,
47- test : "tests" ,
44+ d : "debug" , "debug-brk" : "debug" ,
45+ i : "inspect" , "inspect-brk" : "inspect ",
46+ t : "tests" , test : "tests" ,
4847 r : "reporter" ,
49- color : "colors" ,
50- f : "files" ,
51- file : "files" ,
48+ c : "colors" , color : "colors" ,
49+ f : "files" , file : "files" ,
5250 w : "workers" ,
5351 } ,
5452 default : {
5553 soft : false ,
5654 colors : process . env . colors || process . env . color || true ,
57- debug : process . env . debug || process . env . d ,
58- inspect : process . env . inspect ,
55+ debug : process . env . debug || process . env [ "debug-brk" ] || process . env . d ,
56+ inspect : process . env . inspect || process . env [ "inspect-brk" ] || process . env . i ,
5957 host : process . env . TYPESCRIPT_HOST || process . env . host || "node" ,
6058 browser : process . env . browser || process . env . b || "IE" ,
59+ timeout : process . env . timeout || 40000 ,
6160 tests : process . env . test || process . env . tests || process . env . t ,
6261 light : process . env . light || false ,
6362 reporter : process . env . reporter || process . env . r ,
@@ -256,14 +255,8 @@ function needsUpdate(source: string | string[], dest: string | string[]): boolea
256255 return true ;
257256}
258257
259- // Doing tsconfig inheritance manually. https://github.com/ivogabe/gulp-typescript/issues/459
260- const tsconfigBase = JSON . parse ( fs . readFileSync ( "src/tsconfig-base.json" , "utf-8" ) ) . compilerOptions ;
261-
262258function getCompilerSettings ( base : tsc . Settings , useBuiltCompiler ?: boolean ) : tsc . Settings {
263259 const copy : tsc . Settings = { } ;
264- for ( const key in tsconfigBase ) {
265- copy [ key ] = tsconfigBase [ key ] ;
266- }
267260 for ( const key in base ) {
268261 copy [ key ] = base [ key ] ;
269262 }
@@ -300,7 +293,7 @@ gulp.task("configure-nightly", "Runs scripts/configureNightly.ts to prepare a bu
300293 exec ( host , [ configureNightlyJs , packageJson , versionFile ] , done , done ) ;
301294} ) ;
302295gulp . task ( "publish-nightly" , "Runs `npm publish --tag next` to create a new nightly build on npm" , [ "LKG" ] , ( ) => {
303- return runSequence ( "clean" , "useDebugMode" , "runtests" , ( done ) => {
296+ return runSequence ( "clean" , "useDebugMode" , "runtests-parallel " , ( done ) => {
304297 exec ( "npm" , [ "publish" , "--tag" , "next" ] , done , done ) ;
305298 } ) ;
306299} ) ;
@@ -470,10 +463,11 @@ gulp.task(serverFile, /*help*/ false, [servicesFile, typingsInstallerJs, cancell
470463 . pipe ( gulp . dest ( "src/server" ) ) ;
471464} ) ;
472465
466+ const typesMapJson = path . join ( builtLocalDirectory , "typesMap.json" ) ;
473467const tsserverLibraryFile = path . join ( builtLocalDirectory , "tsserverlibrary.js" ) ;
474468const tsserverLibraryDefinitionFile = path . join ( builtLocalDirectory , "tsserverlibrary.d.ts" ) ;
475469
476- gulp . task ( tsserverLibraryFile , /*help*/ false , [ servicesFile ] , ( done ) => {
470+ gulp . task ( tsserverLibraryFile , /*help*/ false , [ servicesFile , typesMapJson ] , ( done ) => {
477471 const serverLibraryProject = tsc . createProject ( "src/server/tsconfig.library.json" , getCompilerSettings ( { } , /*useBuiltCompiler*/ true ) ) ;
478472 const { js, dts} : { js : NodeJS . ReadableStream , dts : NodeJS . ReadableStream } = serverLibraryProject . src ( )
479473 . pipe ( sourcemaps . init ( ) )
@@ -492,6 +486,15 @@ gulp.task(tsserverLibraryFile, /*help*/ false, [servicesFile], (done) => {
492486 ] ) ;
493487} ) ;
494488
489+ gulp . task ( typesMapJson , /*help*/ false , [ ] , ( ) => {
490+ return gulp . src ( "src/server/typesMap.json" )
491+ . pipe ( insert . transform ( ( contents , file ) => {
492+ JSON . parse ( contents ) ;
493+ return contents ;
494+ } ) )
495+ . pipe ( gulp . dest ( builtLocalDirectory ) ) ;
496+ } ) ;
497+
495498gulp . task ( "lssl" , "Builds language service server library" , [ tsserverLibraryFile ] ) ;
496499gulp . task ( "local" , "Builds the full compiler and services" , [ builtLocalCompiler , servicesFile , serverFile , builtGeneratedDiagnosticMessagesJSON , tsserverLibraryFile ] ) ;
497500gulp . task ( "tsc" , "Builds only the compiler" , [ builtLocalCompiler ] ) ;
@@ -561,7 +564,7 @@ gulp.task(run, /*help*/ false, [servicesFile], () => {
561564 . pipe ( newer ( run ) )
562565 . pipe ( sourcemaps . init ( ) )
563566 . pipe ( testProject ( ) )
564- . pipe ( sourcemaps . write ( "." , { includeContent : false , sourceRoot : "../../ " } ) )
567+ . pipe ( sourcemaps . write ( "." , { includeContent : false , sourceRoot : "." } ) )
565568 . pipe ( gulp . dest ( "src/harness" ) ) ;
566569} ) ;
567570
@@ -594,11 +597,11 @@ function restoreSavedNodeEnv() {
594597 process . env . NODE_ENV = savedNodeEnv ;
595598}
596599
597- let testTimeout = 40000 ;
598600function runConsoleTests ( defaultReporter : string , runInParallel : boolean , done : ( e ?: any ) => void ) {
599601 const lintFlag = cmdLineOptions [ "lint" ] ;
600602 cleanTestDirs ( ( err ) => {
601603 if ( err ) { console . error ( err ) ; failWithStatus ( err , 1 ) ; }
604+ let testTimeout = cmdLineOptions [ "timeout" ] ;
602605 const debug = cmdLineOptions [ "debug" ] ;
603606 const inspect = cmdLineOptions [ "inspect" ] ;
604607 const tests = cmdLineOptions [ "tests" ] ;
@@ -637,12 +640,6 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
637640 // default timeout is 2sec which really should be enough, but maybe we just need a small amount longer
638641 if ( ! runInParallel ) {
639642 const args = [ ] ;
640- if ( inspect ) {
641- args . push ( "--inspect" ) ;
642- }
643- if ( inspect || debug ) {
644- args . push ( "--debug-brk" ) ;
645- }
646643 args . push ( "-R" , reporter ) ;
647644 if ( tests ) {
648645 args . push ( "-g" , `"${ tests } "` ) ;
@@ -653,7 +650,15 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
653650 else {
654651 args . push ( "--no-colors" ) ;
655652 }
656- args . push ( "-t" , testTimeout ) ;
653+ if ( inspect ) {
654+ args . unshift ( "--inspect-brk" ) ;
655+ }
656+ else if ( debug ) {
657+ args . unshift ( "--debug-brk" ) ;
658+ }
659+ else {
660+ args . push ( "-t" , testTimeout ) ;
661+ }
657662 args . push ( run ) ;
658663 setNodeEnvToDevelopment ( ) ;
659664 exec ( mocha , args , lintThenFinish , function ( e , status ) {
@@ -673,7 +678,7 @@ function runConsoleTests(defaultReporter: string, runInParallel: boolean, done:
673678 }
674679 args . push ( run ) ;
675680 setNodeEnvToDevelopment ( ) ;
676- runTestsInParallel ( taskConfigsFolder , run , { testTimeout : testTimeout , noColors : colors === " --no-colors " } , function ( err ) {
681+ runTestsInParallel ( taskConfigsFolder , run , { testTimeout, noColors : colors === " --no-colors " } , function ( err ) {
677682 // last worker clean everything and runs linter in case if there were no errors
678683 del ( taskConfigsFolder ) . then ( ( ) => {
679684 if ( ! err ) {
@@ -741,50 +746,75 @@ gulp.task(nodeServerOutFile, /*help*/ false, [servicesFile], () => {
741746
742747import convertMap = require( "convert-source-map" ) ;
743748import sorcery = require( "sorcery" ) ;
744- declare module "convert-source-map" {
745- export function fromSource ( source : string , largeSource ?: boolean ) : SourceMapConverter ;
746- }
749+ import Vinyl = require ( "vinyl" ) ;
750+
751+ const bundlePath = path . resolve ( "built/local/bundle.js" ) ;
747752
748753gulp . task ( "browserify" , "Runs browserify on run.js to produce a file suitable for running tests in the browser" , [ servicesFile ] , ( done ) => {
749- const testProject = tsc . createProject ( "src/harness/tsconfig.json" , getCompilerSettings ( { outFile : "../../built/local/bundle.js" } , /*useBuiltCompiler*/ true ) ) ;
750- return testProject . src ( )
751- . pipe ( newer ( "built/local/bundle.js" ) )
754+ const testProject = tsc . createProject ( "src/harness/tsconfig.json" , getCompilerSettings ( { outFile : bundlePath , inlineSourceMap : true } , /*useBuiltCompiler*/ true ) ) ;
755+ let originalMap : any ;
756+ let prebundledContent : string ;
757+ browserify ( testProject . src ( )
758+ . pipe ( newer ( bundlePath ) )
752759 . pipe ( sourcemaps . init ( ) )
753760 . pipe ( testProject ( ) )
754761 . pipe ( through2 . obj ( ( file , enc , next ) => {
755- const originalMap = file . sourceMap ;
756- const prebundledContent = file . contents . toString ( ) ;
762+ if ( originalMap ) {
763+ throw new Error ( "Should only recieve one file!" ) ;
764+ }
765+ console . log ( `Saving sourcemaps for ${ file . path } ` ) ;
766+ originalMap = file . sourceMap ;
767+ prebundledContent = file . contents . toString ( ) ;
757768 // Make paths absolute to help sorcery deal with all the terrible paths being thrown around
758769 originalMap . sources = originalMap . sources . map ( s => path . resolve ( path . join ( "src/harness" , s ) ) ) ;
759- // intoStream (below) makes browserify think the input file is named this , so this is what it puts in the sourcemap
770+ // browserify names input files this when they are streamed in , so this is what it puts in the sourcemap
760771 originalMap . file = "built/local/_stream_0.js" ;
761772
762- browserify ( intoStream ( file . contents ) , { debug : true } )
763- . bundle ( ( err , res ) => {
764- // assumes file.contents is a Buffer
765- const maps = JSON . parse ( convertMap . fromSource ( res . toString ( ) , /*largeSource*/ true ) . toJSON ( ) ) ;
766- delete maps . sourceRoot ;
767- maps . sources = maps . sources . map ( s => path . resolve ( s === "_stream_0.js" ? "built/local/_stream_0.js" : s ) ) ;
768- // Strip browserify's inline comments away (could probably just let sorcery do this, but then we couldn't fix the paths)
769- file . contents = new Buffer ( convertMap . removeComments ( res . toString ( ) ) ) ;
770- const chain = sorcery . loadSync ( "built/local/bundle.js" , {
771- content : {
772- "built/local/_stream_0.js" : prebundledContent ,
773- "built/local/bundle.js" : file . contents . toString ( )
774- } ,
775- sourcemaps : {
776- "built/local/_stream_0.js" : originalMap ,
777- "built/local/bundle.js" : maps ,
778- "node_modules/source-map-support/source-map-support.js" : undefined ,
779- }
780- } ) ;
781- const finalMap = chain . apply ( ) ;
782- file . sourceMap = finalMap ;
783- next ( /*err*/ undefined , file ) ;
784- } ) ;
773+ next ( /*err*/ undefined , file . contents ) ;
785774 } ) )
786- . pipe ( sourcemaps . write ( "." , { includeContent : false } ) )
787- . pipe ( gulp . dest ( "src/harness" ) ) ;
775+ . on ( "error" , err => {
776+ return done ( err ) ;
777+ } ) , { debug : true , basedir : __dirname } ) // Attach error handler to inner stream
778+ . bundle ( ( err , contents ) => {
779+ if ( err ) {
780+ if ( err . message . match ( / C a n n o t f i n d m o d u l e ' .* _ s t r e a m _ 0 .j s ' / ) ) {
781+ return done ( ) ; // Browserify errors when we pass in no files when `newer` filters the input, we should count that as a success, though
782+ }
783+ return done ( err ) ;
784+ }
785+ const stringContent = contents . toString ( ) ;
786+ const file = new Vinyl ( { contents, path : bundlePath } ) ;
787+ console . log ( `Fixing sourcemaps for ${ file . path } ` ) ;
788+ // assumes contents is a Buffer, since that's what browserify yields
789+ const maps = convertMap . fromSource ( stringContent , /*largeSource*/ true ) . toObject ( ) ;
790+ delete maps . sourceRoot ;
791+ maps . sources = maps . sources . map ( s => path . resolve ( s === "_stream_0.js" ? "built/local/_stream_0.js" : s ) ) ;
792+ // Strip browserify's inline comments away (could probably just let sorcery do this, but then we couldn't fix the paths)
793+ file . contents = new Buffer ( convertMap . removeComments ( stringContent ) ) ;
794+ const chain = sorcery . loadSync ( bundlePath , {
795+ content : {
796+ "built/local/_stream_0.js" : prebundledContent ,
797+ [ bundlePath ] : stringContent
798+ } ,
799+ sourcemaps : {
800+ "built/local/_stream_0.js" : originalMap ,
801+ [ bundlePath ] : maps ,
802+ "node_modules/source-map-support/source-map-support.js" : undefined ,
803+ }
804+ } ) ;
805+ const finalMap = chain . apply ( ) ;
806+ file . sourceMap = finalMap ;
807+
808+ const stream = through2 . obj ( ( file , enc , callback ) => {
809+ return callback ( /*err*/ undefined , file ) ;
810+ } ) ;
811+ stream . pipe ( sourcemaps . write ( "." , { includeContent : false } ) )
812+ . pipe ( gulp . dest ( "." ) )
813+ . on ( "end" , done )
814+ . on ( "error" , done ) ;
815+ stream . write ( file ) ;
816+ stream . end ( ) ;
817+ } ) ;
788818} ) ;
789819
790820
@@ -838,6 +868,7 @@ gulp.task("runtests-browser", "Runs the tests using the built run.js file like '
838868} ) ;
839869
840870gulp . task ( "generate-code-coverage" , "Generates code coverage data via istanbul" , [ "tests" ] , ( done ) => {
871+ const testTimeout = cmdLineOptions [ "timeout" ] ;
841872 exec ( "istanbul" , [ "cover" , "node_modules/mocha/bin/_mocha" , "--" , "-R" , "min" , "-t" , testTimeout . toString ( ) , run ] , done , done ) ;
842873} ) ;
843874
@@ -947,7 +978,7 @@ const instrumenterPath = path.join(harnessDirectory, "instrumenter.ts");
947978const instrumenterJsPath = path . join ( builtLocalDirectory , "instrumenter.js" ) ;
948979gulp . task ( instrumenterJsPath , /*help*/ false , [ servicesFile ] , ( ) => {
949980 const settings : tsc . Settings = getCompilerSettings ( {
950- outFile : instrumenterJsPath ,
981+ module : "commonjs" ,
951982 target : "es5" ,
952983 lib : [
953984 "es6" ,
@@ -959,8 +990,8 @@ gulp.task(instrumenterJsPath, /*help*/ false, [servicesFile], () => {
959990 . pipe ( newer ( instrumenterJsPath ) )
960991 . pipe ( sourcemaps . init ( ) )
961992 . pipe ( tsc ( settings ) )
962- . pipe ( sourcemaps . write ( "." ) )
963- . pipe ( gulp . dest ( "." ) ) ;
993+ . pipe ( sourcemaps . write ( builtLocalDirectory ) )
994+ . pipe ( gulp . dest ( builtLocalDirectory ) ) ;
964995} ) ;
965996
966997gulp . task ( "tsc-instrumented" , "Builds an instrumented tsc.js" , [ "local" , loggedIOJsPath , instrumenterJsPath , servicesFile ] , ( done ) => {
0 commit comments