@@ -70,9 +70,20 @@ export interface IConcatFile {
7070 sources : IFile [ ] ;
7171}
7272
73+ export interface IBundleData {
74+ graph : IGraph ;
75+ bundles : { [ moduleId :string ] :string [ ] ; } ;
76+ }
77+
7378export interface IBundleResult {
7479 files : IConcatFile [ ] ;
7580 cssInlinedResources : string [ ] ;
81+ bundleData : IBundleData ;
82+ }
83+
84+ interface IPartialBundleResult {
85+ files : IConcatFile [ ] ;
86+ bundleData : IBundleData ;
7687}
7788
7889export interface ILoaderConfig {
@@ -100,16 +111,17 @@ export function bundle(entryPoints:IEntryPoint[], config:ILoaderConfig, callback
100111
101112 loader ( Object . keys ( entryPointsMap ) , ( ) => {
102113 let modules = < IBuildModuleInfo [ ] > loader . getBuildInfo ( ) ;
103- let resultFiles = emitEntryPoints ( modules , entryPointsMap ) ;
114+ let partialResult = emitEntryPoints ( modules , entryPointsMap ) ;
104115 let cssInlinedResources = loader ( 'vs/css' ) . getInlinedResources ( ) ;
105116 callback ( null , {
106- files : resultFiles ,
107- cssInlinedResources : cssInlinedResources
117+ files : partialResult . files ,
118+ cssInlinedResources : cssInlinedResources ,
119+ bundleData : partialResult . bundleData
108120 } ) ;
109121 } , ( err ) => callback ( err , null ) ) ;
110122}
111123
112- function emitEntryPoints ( modules :IBuildModuleInfo [ ] , entryPoints :IEntryPointMap ) : IConcatFile [ ] {
124+ function emitEntryPoints ( modules :IBuildModuleInfo [ ] , entryPoints :IEntryPointMap ) : IPartialBundleResult {
113125 let modulesMap : IBuildModuleInfoMap = { } ;
114126 modules . forEach ( ( m :IBuildModuleInfo ) => {
115127 modulesMap [ m . id ] = m ;
@@ -124,6 +136,10 @@ function emitEntryPoints(modules:IBuildModuleInfo[], entryPoints:IEntryPointMap)
124136
125137 let result : IConcatFile [ ] = [ ] ;
126138 let usedPlugins : IPluginMap = { } ;
139+ let bundleData :IBundleData = {
140+ graph : modulesGraph ,
141+ bundles : { }
142+ } ;
127143
128144 Object . keys ( entryPoints ) . forEach ( ( moduleToBundle :string ) => {
129145 let info = entryPoints [ moduleToBundle ] ;
@@ -142,6 +158,8 @@ function emitEntryPoints(modules:IBuildModuleInfo[], entryPoints:IEntryPointMap)
142158 return allDependencies [ module ] ;
143159 } ) ;
144160
161+ bundleData . bundles [ moduleToBundle ] = includedModules ;
162+
145163 let res = emitEntryPoint ( modulesMap , modulesGraph , moduleToBundle , includedModules ) ;
146164
147165 result = result . concat ( res . files ) ;
@@ -166,7 +184,61 @@ function emitEntryPoints(modules:IBuildModuleInfo[], entryPoints:IEntryPointMap)
166184 }
167185 } ) ;
168186
169- return result ;
187+ return {
188+ files : removeDuplicateTSBoilerplate ( result ) ,
189+ bundleData : bundleData
190+ } ;
191+ }
192+
193+ function removeDuplicateTSBoilerplate ( destFiles :IConcatFile [ ] ) :IConcatFile [ ] {
194+ // Taken from typescript compiler => emitFiles
195+ let BOILERPLATE = [
196+ { start : / ^ v a r _ _ e x t e n d s / , end : / ^ } ; $ / } ,
197+ { start : / ^ v a r _ _ a s s i g n / , end : / ^ } ; $ / } ,
198+ { start : / ^ v a r _ _ d e c o r a t e / , end : / ^ } ; $ / } ,
199+ { start : / ^ v a r _ _ m e t a d a t a / , end : / ^ } ; $ / } ,
200+ { start : / ^ v a r _ _ p a r a m / , end : / ^ } ; $ / } ,
201+ { start : / ^ v a r _ _ a w a i t e r / , end : / ^ } ; $ / } ,
202+ ] ;
203+
204+ destFiles . forEach ( ( destFile ) => {
205+ let SEEN_BOILERPLATE = [ ] ;
206+ destFile . sources . forEach ( ( source ) => {
207+ let lines = source . contents . split ( / \r \n | \n | \r / ) ;
208+ let newLines : string [ ] = [ ] ;
209+ let IS_REMOVING_BOILERPLATE = false , END_BOILERPLATE : RegExp ;
210+
211+ for ( let i = 0 ; i < lines . length ; i ++ ) {
212+ let line = lines [ i ] ;
213+ if ( IS_REMOVING_BOILERPLATE ) {
214+ newLines . push ( '' ) ;
215+ if ( END_BOILERPLATE . test ( line ) ) {
216+ IS_REMOVING_BOILERPLATE = false ;
217+ }
218+ } else {
219+ for ( let j = 0 ; j < BOILERPLATE . length ; j ++ ) {
220+ let boilerplate = BOILERPLATE [ j ] ;
221+ if ( boilerplate . start . test ( line ) ) {
222+ if ( SEEN_BOILERPLATE [ j ] ) {
223+ IS_REMOVING_BOILERPLATE = true ;
224+ END_BOILERPLATE = boilerplate . end ;
225+ } else {
226+ SEEN_BOILERPLATE [ j ] = true ;
227+ }
228+ }
229+ }
230+ if ( IS_REMOVING_BOILERPLATE ) {
231+ newLines . push ( '' ) ;
232+ } else {
233+ newLines . push ( line ) ;
234+ }
235+ }
236+ }
237+ source . contents = newLines . join ( '\n' ) ;
238+ } ) ;
239+ } ) ;
240+
241+ return destFiles ;
170242}
171243
172244interface IPluginMap {
0 commit comments