44 * Licensed under the MIT License. See License.txt in the project root for license information.
55 *--------------------------------------------------------------------------------------------*/
66Object . defineProperty ( exports , "__esModule" , { value : true } ) ;
7- exports . packageMarketplaceExtensionsStream = exports . packageLocalExtensionsStream = exports . fromMarketplace = void 0 ;
7+ exports . packageMarketplaceExtensionsStream = exports . packageLocalWebExtensionsStream = exports . packageLocalExtensionsStream = exports . fromMarketplace = void 0 ;
88const es = require ( "event-stream" ) ;
99const fs = require ( "fs" ) ;
1010const glob = require ( "glob" ) ;
@@ -28,11 +28,7 @@ const util = require('./util');
2828const root = path . dirname ( path . dirname ( __dirname ) ) ;
2929const commit = util . getVersion ( root ) ;
3030const sourceMappingURLBase = `https://ticino.blob.core.windows.net/sourcemaps/${ commit } ` ;
31- function fromLocal ( extensionPath ) {
32- const webpackFilename = path . join ( extensionPath , 'extension.webpack.config.js' ) ;
33- const input = fs . existsSync ( webpackFilename )
34- ? fromLocalWebpack ( extensionPath )
35- : fromLocalNormal ( extensionPath ) ;
31+ function minimizeLanguageJSON ( input ) {
3632 const tmLanguageJsonFilter = filter ( '**/*.tmLanguage.json' , { restore : true } ) ;
3733 return input
3834 . pipe ( tmLanguageJsonFilter )
@@ -43,12 +39,49 @@ function fromLocal(extensionPath) {
4339 } ) )
4440 . pipe ( tmLanguageJsonFilter . restore ) ;
4541}
46- function fromLocalWebpack ( extensionPath ) {
42+ function updateExtensionPackageJSON ( extensionPath , input , update ) {
43+ const packageJsonFilter = filter ( ( f ) => f . path === path . join ( extensionPath , 'package.json' ) , { restore : true } ) ;
44+ return input
45+ . pipe ( packageJsonFilter )
46+ . pipe ( buffer ( ) )
47+ . pipe ( es . mapSync ( ( f ) => {
48+ const data = JSON . parse ( f . contents . toString ( 'utf8' ) ) ;
49+ f . contents = Buffer . from ( JSON . stringify ( update ( data ) ) ) ;
50+ return f ;
51+ } ) )
52+ . pipe ( packageJsonFilter . restore ) ;
53+ }
54+ function fromLocal ( extensionPath , forWeb ) {
55+ const webpackConfigFileName = forWeb ? 'extension-browser.webpack.config.js' : 'extension.webpack.config.js' ;
56+ const isWebPacked = fs . existsSync ( path . join ( extensionPath , webpackConfigFileName ) ) ;
57+ let input = isWebPacked
58+ ? fromLocalWebpack ( extensionPath , webpackConfigFileName )
59+ : fromLocalNormal ( extensionPath ) ;
60+ if ( forWeb ) {
61+ input = updateExtensionPackageJSON ( extensionPath , input , ( data ) => {
62+ if ( data . browser ) {
63+ data . main = data . browser ;
64+ }
65+ data . extensionKind = [ 'web' ] ;
66+ return data ;
67+ } ) ;
68+ }
69+ else if ( isWebPacked ) {
70+ input = updateExtensionPackageJSON ( extensionPath , input , ( data ) => {
71+ if ( data . main ) {
72+ data . main = data . main . replace ( '/out/' , / d i s t / ) ;
73+ }
74+ return data ;
75+ } ) ;
76+ }
77+ return minimizeLanguageJSON ( input ) ;
78+ }
79+ function fromLocalWebpack ( extensionPath , webpackConfigFileName ) {
4780 const result = es . through ( ) ;
4881 const packagedDependencies = [ ] ;
4982 const packageJsonConfig = require ( path . join ( extensionPath , 'package.json' ) ) ;
5083 if ( packageJsonConfig . dependencies ) {
51- const webpackRootConfig = require ( path . join ( extensionPath , 'extension.webpack.config.js' ) ) ;
84+ const webpackRootConfig = require ( path . join ( extensionPath , webpackConfigFileName ) ) ;
5285 for ( const key in webpackRootConfig . externals ) {
5386 if ( key in packageJsonConfig . dependencies ) {
5487 packagedDependencies . push ( key ) ;
@@ -64,30 +97,9 @@ function fromLocalWebpack(extensionPath) {
6497 base : extensionPath ,
6598 contents : fs . createReadStream ( filePath )
6699 } ) ) ;
67- const filesStream = es . readArray ( files ) ;
68100 // check for a webpack configuration files, then invoke webpack
69- // and merge its output with the files stream. also rewrite the package.json
70- // file to a new entry point
71- const webpackConfigLocations = glob . sync ( path . join ( extensionPath , '/**/extension.webpack.config.js' ) , { ignore : [ '**/node_modules' ] } ) ;
72- const packageJsonFilter = filter ( f => {
73- if ( path . basename ( f . path ) === 'package.json' ) {
74- // only modify package.json's next to the webpack file.
75- // to be safe, use existsSync instead of path comparison.
76- return fs . existsSync ( path . join ( path . dirname ( f . path ) , 'extension.webpack.config.js' ) ) ;
77- }
78- return false ;
79- } , { restore : true } ) ;
80- const patchFilesStream = filesStream
81- . pipe ( packageJsonFilter )
82- . pipe ( buffer ( ) )
83- . pipe ( json ( ( data ) => {
84- if ( data . main ) {
85- // hardcoded entry point directory!
86- data . main = data . main . replace ( '/out/' , / d i s t / ) ;
87- }
88- return data ;
89- } ) )
90- . pipe ( packageJsonFilter . restore ) ;
101+ // and merge its output with the files stream.
102+ const webpackConfigLocations = glob . sync ( path . join ( extensionPath , '**' , webpackConfigFileName ) , { ignore : [ '**/node_modules' ] } ) ;
91103 const webpackStreams = webpackConfigLocations . map ( webpackConfigPath => {
92104 const webpackDone = ( err , stats ) => {
93105 fancyLog ( `Bundled extension: ${ ansiColors . yellow ( path . join ( path . basename ( extensionPath ) , path . relative ( extensionPath , webpackConfigPath ) ) ) } ...` ) ;
@@ -121,7 +133,7 @@ function fromLocalWebpack(extensionPath) {
121133 this . emit ( 'data' , data ) ;
122134 } ) ) ;
123135 } ) ;
124- es . merge ( ...webpackStreams , patchFilesStream )
136+ es . merge ( ...webpackStreams , es . readArray ( files ) )
125137 // .pipe(es.through(function (data) {
126138 // // debug
127139 // console.log('out', data.path, data.contents.length);
@@ -198,15 +210,32 @@ function packageLocalExtensionsStream() {
198210 } )
199211 . filter ( ( { name } ) => excludedExtensions . indexOf ( name ) === - 1 )
200212 . filter ( ( { name } ) => builtInExtensions . every ( b => b . name !== name ) ) ;
201- const nodeModules = gulp . src ( 'extensions/node_modules/**' , { base : '.' } ) ;
202213 const localExtensions = localExtensionDescriptions . map ( extension => {
203- return fromLocal ( extension . path )
214+ return fromLocal ( extension . path , false )
204215 . pipe ( rename ( p => p . dirname = `extensions/${ extension . name } /${ p . dirname } ` ) ) ;
205216 } ) ;
217+ const nodeModules = gulp . src ( 'extensions/node_modules/**' , { base : '.' } ) ;
206218 return es . merge ( nodeModules , ...localExtensions )
207219 . pipe ( util2 . setExecutableBit ( [ '**/*.sh' ] ) ) ;
208220}
209221exports . packageLocalExtensionsStream = packageLocalExtensionsStream ;
222+ function packageLocalWebExtensionsStream ( ) {
223+ const localExtensionDescriptions = glob . sync ( 'extensions/*/package.json' )
224+ . filter ( manifestPath => {
225+ const packageJsonConfig = require ( path . join ( root , manifestPath ) ) ;
226+ return ! packageJsonConfig . main || packageJsonConfig . browser ;
227+ } )
228+ . map ( manifestPath => {
229+ const extensionPath = path . dirname ( path . join ( root , manifestPath ) ) ;
230+ const extensionName = path . basename ( extensionPath ) ;
231+ return { name : extensionName , path : extensionPath } ;
232+ } ) ;
233+ return es . merge ( ...localExtensionDescriptions . map ( extension => {
234+ return fromLocal ( extension . path , true )
235+ . pipe ( rename ( p => p . dirname = `extensions/${ extension . name } /${ p . dirname } ` ) ) ;
236+ } ) ) ;
237+ }
238+ exports . packageLocalWebExtensionsStream = packageLocalWebExtensionsStream ;
210239function packageMarketplaceExtensionsStream ( ) {
211240 const extensions = builtInExtensions . map ( extension => {
212241 return fromMarketplace ( extension . name , extension . version , extension . metadata )
0 commit comments