@@ -28,7 +28,6 @@ import minimist = require("minimist");
28
28
import browserify = require( "browserify" ) ;
29
29
import through2 = require( "through2" ) ;
30
30
import merge2 = require( "merge2" ) ;
31
- import intoStream = require( "into-stream" ) ;
32
31
import * as os from "os" ;
33
32
import fold = require( "travis-fold" ) ;
34
33
const gulp = helpMaker ( originalGulp ) ;
@@ -294,7 +293,7 @@ gulp.task("configure-nightly", "Runs scripts/configureNightly.ts to prepare a bu
294
293
exec ( host , [ configureNightlyJs , packageJson , versionFile ] , done , done ) ;
295
294
} ) ;
296
295
gulp . task ( "publish-nightly" , "Runs `npm publish --tag next` to create a new nightly build on npm" , [ "LKG" ] , ( ) => {
297
- return runSequence ( "clean" , "useDebugMode" , "runtests" , ( done ) => {
296
+ return runSequence ( "clean" , "useDebugMode" , "runtests-parallel " , ( done ) => {
298
297
exec ( "npm" , [ "publish" , "--tag" , "next" ] , done , done ) ;
299
298
} ) ;
300
299
} ) ;
@@ -737,50 +736,75 @@ gulp.task(nodeServerOutFile, /*help*/ false, [servicesFile], () => {
737
736
738
737
import convertMap = require( "convert-source-map" ) ;
739
738
import sorcery = require( "sorcery" ) ;
740
- declare module "convert-source-map" {
741
- export function fromSource ( source : string , largeSource ?: boolean ) : SourceMapConverter ;
742
- }
739
+ import Vinyl = require( "vinyl" ) ;
743
740
744
- gulp . task ( "browserify" , "Runs browserify on run.js to produce a file suitable for running tests in the browser" , [ servicesFile , run ] , ( done ) => {
745
- const testProject = tsc . createProject ( "src/harness/tsconfig.json" , getCompilerSettings ( { outFile : "../../built/local/bundle.js" } , /*useBuiltCompiler*/ true ) ) ;
746
- return testProject . src ( )
747
- . pipe ( newer ( "built/local/bundle.js" ) )
741
+ const bundlePath = path . resolve ( "built/local/bundle.js" ) ;
742
+
743
+ gulp . task ( "browserify" , "Runs browserify on run.js to produce a file suitable for running tests in the browser" , [ servicesFile ] , ( done ) => {
744
+ const testProject = tsc . createProject ( "src/harness/tsconfig.json" , getCompilerSettings ( { outFile : bundlePath , inlineSourceMap : true } , /*useBuiltCompiler*/ true ) ) ;
745
+ let originalMap : any ;
746
+ let prebundledContent : string ;
747
+ browserify ( testProject . src ( )
748
+ . pipe ( newer ( bundlePath ) )
748
749
. pipe ( sourcemaps . init ( ) )
749
750
. pipe ( testProject ( ) )
750
751
. pipe ( through2 . obj ( ( file , enc , next ) => {
751
- const originalMap = file . sourceMap ;
752
- const prebundledContent = file . contents . toString ( ) ;
752
+ if ( originalMap ) {
753
+ throw new Error ( "Should only recieve one file!" ) ;
754
+ }
755
+ console . log ( `Saving sourcemaps for ${ file . path } ` ) ;
756
+ originalMap = file . sourceMap ;
757
+ prebundledContent = file . contents . toString ( ) ;
753
758
// Make paths absolute to help sorcery deal with all the terrible paths being thrown around
754
759
originalMap . sources = originalMap . sources . map ( s => path . resolve ( path . join ( "src/harness" , s ) ) ) ;
755
- // intoStream (below) makes browserify think the input file is named this , so this is what it puts in the sourcemap
760
+ // browserify names input files this when they are streamed in , so this is what it puts in the sourcemap
756
761
originalMap . file = "built/local/_stream_0.js" ;
757
762
758
- browserify ( intoStream ( file . contents ) , { debug : true } )
759
- . bundle ( ( err , res ) => {
760
- // assumes file.contents is a Buffer
761
- const maps = JSON . parse ( convertMap . fromSource ( res . toString ( ) , /*largeSource*/ true ) . toJSON ( ) ) ;
762
- delete maps . sourceRoot ;
763
- maps . sources = maps . sources . map ( s => path . resolve ( s === "_stream_0.js" ? "built/local/_stream_0.js" : s ) ) ;
764
- // Strip browserify's inline comments away (could probably just let sorcery do this, but then we couldn't fix the paths)
765
- file . contents = new Buffer ( convertMap . removeComments ( res . toString ( ) ) ) ;
766
- const chain = sorcery . loadSync ( "built/local/bundle.js" , {
767
- content : {
768
- "built/local/_stream_0.js" : prebundledContent ,
769
- "built/local/bundle.js" : file . contents . toString ( )
770
- } ,
771
- sourcemaps : {
772
- "built/local/_stream_0.js" : originalMap ,
773
- "built/local/bundle.js" : maps ,
774
- "node_modules/source-map-support/source-map-support.js" : undefined ,
775
- }
776
- } ) ;
777
- const finalMap = chain . apply ( ) ;
778
- file . sourceMap = finalMap ;
779
- next ( /*err*/ undefined , file ) ;
780
- } ) ;
763
+ next ( /*err*/ undefined , file . contents ) ;
781
764
} ) )
782
- . pipe ( sourcemaps . write ( "." , { includeContent : false } ) )
783
- . pipe ( gulp . dest ( "src/harness" ) ) ;
765
+ . on ( "error" , err => {
766
+ return done ( err ) ;
767
+ } ) , { debug : true , basedir : __dirname } ) // Attach error handler to inner stream
768
+ . bundle ( ( err , contents ) => {
769
+ if ( err ) {
770
+ 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 ' / ) ) {
771
+ return done ( ) ; // Browserify errors when we pass in no files when `newer` filters the input, we should count that as a success, though
772
+ }
773
+ return done ( err ) ;
774
+ }
775
+ const stringContent = contents . toString ( ) ;
776
+ const file = new Vinyl ( { contents, path : bundlePath } ) ;
777
+ console . log ( `Fixing sourcemaps for ${ file . path } ` ) ;
778
+ // assumes contents is a Buffer, since that's what browserify yields
779
+ const maps = convertMap . fromSource ( stringContent , /*largeSource*/ true ) . toObject ( ) ;
780
+ delete maps . sourceRoot ;
781
+ maps . sources = maps . sources . map ( s => path . resolve ( s === "_stream_0.js" ? "built/local/_stream_0.js" : s ) ) ;
782
+ // Strip browserify's inline comments away (could probably just let sorcery do this, but then we couldn't fix the paths)
783
+ file . contents = new Buffer ( convertMap . removeComments ( stringContent ) ) ;
784
+ const chain = sorcery . loadSync ( bundlePath , {
785
+ content : {
786
+ "built/local/_stream_0.js" : prebundledContent ,
787
+ [ bundlePath ] : stringContent
788
+ } ,
789
+ sourcemaps : {
790
+ "built/local/_stream_0.js" : originalMap ,
791
+ [ bundlePath ] : maps ,
792
+ "node_modules/source-map-support/source-map-support.js" : undefined ,
793
+ }
794
+ } ) ;
795
+ const finalMap = chain . apply ( ) ;
796
+ file . sourceMap = finalMap ;
797
+
798
+ const stream = through2 . obj ( ( file , enc , callback ) => {
799
+ return callback ( /*err*/ undefined , file ) ;
800
+ } ) ;
801
+ stream . pipe ( sourcemaps . write ( "." , { includeContent : false } ) )
802
+ . pipe ( gulp . dest ( "." ) )
803
+ . on ( "end" , done )
804
+ . on ( "error" , done ) ;
805
+ stream . write ( file ) ;
806
+ stream . end ( ) ;
807
+ } ) ;
784
808
} ) ;
785
809
786
810
0 commit comments