@@ -21,23 +21,29 @@ import * as fancyLog from 'fancy-log';
21
21
import * as ansiColors from 'ansi-colors' ;
22
22
const buffer = require ( 'gulp-buffer' ) ;
23
23
import json = require( 'gulp-json-editor' ) ;
24
+ import * as jsoncParser from 'jsonc-parser' ;
24
25
const webpack = require ( 'webpack' ) ;
25
26
const webpackGulp = require ( 'webpack-stream' ) ;
26
27
const util = require ( './util' ) ;
27
28
const root = path . dirname ( path . dirname ( __dirname ) ) ;
28
29
const commit = util . getVersion ( root ) ;
29
30
const sourceMappingURLBase = `https://ticino.blob.core.windows.net/sourcemaps/${ commit } ` ;
30
31
31
- function minimizeLanguageJSON ( input : Stream ) : Stream {
32
- const tmLanguageJsonFilter = filter ( '**/*.tmLanguage. json' , { restore : true } ) ;
32
+ function minifyExtensionResources ( input : Stream ) : Stream {
33
+ const jsonFilter = filter ( [ '**/*.json' , '**/*.code-snippets' ] , { restore : true } ) ;
33
34
return input
34
- . pipe ( tmLanguageJsonFilter )
35
+ . pipe ( jsonFilter )
35
36
. pipe ( buffer ( ) )
36
37
. pipe ( es . mapSync ( ( f : File ) => {
37
- f . contents = Buffer . from ( JSON . stringify ( JSON . parse ( f . contents . toString ( 'utf8' ) ) ) ) ;
38
+ const errors : jsoncParser . ParseError [ ] = [ ] ;
39
+ const value = jsoncParser . parse ( f . contents . toString ( 'utf8' ) , errors ) ;
40
+ if ( errors . length === 0 ) {
41
+ // file parsed OK => just stringify to drop whitespace and comments
42
+ f . contents = Buffer . from ( JSON . stringify ( value ) ) ;
43
+ }
38
44
return f ;
39
45
} ) )
40
- . pipe ( tmLanguageJsonFilter . restore ) ;
46
+ . pipe ( jsonFilter . restore ) ;
41
47
}
42
48
43
49
function updateExtensionPackageJSON ( input : Stream , update : ( data : any ) => any ) : Stream {
@@ -63,6 +69,9 @@ function fromLocal(extensionPath: string, forWeb: boolean): Stream {
63
69
64
70
if ( forWeb ) {
65
71
input = updateExtensionPackageJSON ( input , ( data : any ) => {
72
+ delete data . scripts ;
73
+ delete data . dependencies ;
74
+ delete data . devDependencies ;
66
75
if ( data . browser ) {
67
76
data . main = data . browser ;
68
77
}
@@ -71,14 +80,17 @@ function fromLocal(extensionPath: string, forWeb: boolean): Stream {
71
80
} ) ;
72
81
} else if ( isWebPacked ) {
73
82
input = updateExtensionPackageJSON ( input , ( data : any ) => {
83
+ delete data . scripts ;
84
+ delete data . dependencies ;
85
+ delete data . devDependencies ;
74
86
if ( data . main ) {
75
87
data . main = data . main . replace ( '/out/' , / d i s t / ) ;
76
88
}
77
89
return data ;
78
90
} ) ;
79
91
}
80
92
81
- return minimizeLanguageJSON ( input ) ;
93
+ return input ;
82
94
}
83
95
84
96
@@ -243,7 +255,7 @@ interface IBuiltInExtension {
243
255
244
256
const builtInExtensions : IBuiltInExtension [ ] = JSON . parse ( fs . readFileSync ( path . join ( __dirname , '../../product.json' ) , 'utf8' ) ) . builtInExtensions ;
245
257
246
- export function packageLocalExtensionsStream ( ) : NodeJS . ReadWriteStream {
258
+ export function packageLocalExtensionsStream ( ) : Stream {
247
259
const localExtensionDescriptions = ( < string [ ] > glob . sync ( 'extensions/*/package.json' ) )
248
260
. map ( manifestPath => {
249
261
const extensionPath = path . dirname ( path . join ( root , manifestPath ) ) ;
@@ -260,11 +272,13 @@ export function packageLocalExtensionsStream(): NodeJS.ReadWriteStream {
260
272
} ) ;
261
273
262
274
const nodeModules = gulp . src ( 'extensions/node_modules/**' , { base : '.' } ) ;
263
- return es . merge ( nodeModules , ...localExtensions )
264
- . pipe ( util2 . setExecutableBit ( [ '**/*.sh' ] ) ) ;
275
+ return minifyExtensionResources (
276
+ es . merge ( nodeModules , ...localExtensions )
277
+ . pipe ( util2 . setExecutableBit ( [ '**/*.sh' ] ) )
278
+ ) ;
265
279
}
266
280
267
- export function packageLocalWebExtensionsStream ( ) : NodeJS . ReadWriteStream {
281
+ export function packageLocalWebExtensionsStream ( ) : Stream {
268
282
const localExtensionDescriptions = ( < string [ ] > glob . sync ( 'extensions/*/package.json' ) )
269
283
. filter ( manifestPath => {
270
284
const packageJsonConfig = require ( path . join ( root , manifestPath ) ) ;
@@ -276,23 +290,27 @@ export function packageLocalWebExtensionsStream(): NodeJS.ReadWriteStream {
276
290
return { name : extensionName , path : extensionPath } ;
277
291
} ) ;
278
292
279
- return es . merge ( ...localExtensionDescriptions . map ( extension => {
280
- return fromLocal ( extension . path , true )
281
- . pipe ( rename ( p => p . dirname = `extensions/${ extension . name } /${ p . dirname } ` ) ) ;
282
- } ) ) ;
293
+ return minifyExtensionResources (
294
+ es . merge ( ...localExtensionDescriptions . map ( extension => {
295
+ return fromLocal ( extension . path , true )
296
+ . pipe ( rename ( p => p . dirname = `extensions/${ extension . name } /${ p . dirname } ` ) ) ;
297
+ } ) )
298
+ ) ;
283
299
}
284
300
285
- export function packageMarketplaceExtensionsStream ( ) : NodeJS . ReadWriteStream {
301
+ export function packageMarketplaceExtensionsStream ( ) : Stream {
286
302
const extensions = builtInExtensions . map ( extension => {
287
303
return fromMarketplace ( extension . name , extension . version , extension . metadata )
288
304
. pipe ( rename ( p => p . dirname = `extensions/${ extension . name } /${ p . dirname } ` ) ) ;
289
305
} ) ;
290
306
291
- return es . merge ( extensions )
292
- . pipe ( util2 . setExecutableBit ( [ '**/*.sh' ] ) ) ;
307
+ return minifyExtensionResources (
308
+ es . merge ( extensions )
309
+ . pipe ( util2 . setExecutableBit ( [ '**/*.sh' ] ) )
310
+ ) ;
293
311
}
294
312
295
- export function packageMarketplaceWebExtensionsStream ( builtInExtensions : IBuiltInExtension [ ] ) : NodeJS . ReadWriteStream {
313
+ export function packageMarketplaceWebExtensionsStream ( builtInExtensions : IBuiltInExtension [ ] ) : Stream {
296
314
const extensions = builtInExtensions
297
315
. map ( extension => {
298
316
const input = fromMarketplace ( extension . name , extension . version , extension . metadata )
@@ -305,7 +323,9 @@ export function packageMarketplaceWebExtensionsStream(builtInExtensions: IBuiltI
305
323
return data ;
306
324
} ) ;
307
325
} ) ;
308
- return es . merge ( extensions ) ;
326
+ return minifyExtensionResources (
327
+ es . merge ( extensions )
328
+ ) ;
309
329
}
310
330
311
331
export interface IScannedBuiltinExtension {
@@ -336,7 +356,7 @@ export function scanBuiltinExtensions(extensionsRoot: string, forWeb: boolean):
336
356
337
357
if ( packageNLS ) {
338
358
// temporary
339
- packageJSON = translatePackageJSON ( packageJSON , path . join ( extensionsRoot , extensionFolder , packageNLS ) )
359
+ packageJSON = translatePackageJSON ( packageJSON , path . join ( extensionsRoot , extensionFolder , packageNLS ) ) ;
340
360
}
341
361
scannedExtensions . push ( {
342
362
extensionPath : extensionFolder ,
0 commit comments