@@ -34,8 +34,26 @@ var webpack = require('webpack');
3434var webpackGulp = require ( 'webpack-stream' ) ;
3535var root = path . resolve ( path . join ( __dirname , '..' , '..' ) ) ;
3636function fromLocal ( extensionPath , sourceMappingURLBase ) {
37+ var webpackFilename = path . join ( extensionPath , 'extension.webpack.config.js' ) ;
38+ if ( fs . existsSync ( webpackFilename ) ) {
39+ return fromLocalWebpack ( extensionPath , sourceMappingURLBase ) ;
40+ }
41+ else {
42+ return fromLocalNormal ( extensionPath ) ;
43+ }
44+ }
45+ exports . fromLocal = fromLocal ;
46+ function fromLocalWebpack ( extensionPath , sourceMappingURLBase ) {
3747 var result = es . through ( ) ;
38- vsce . listFiles ( { cwd : extensionPath , packageManager : vsce . PackageManager . Yarn } ) . then ( function ( fileNames ) {
48+ var packagedDependencies = [ ] ;
49+ var packageJsonConfig = require ( path . join ( extensionPath , 'package.json' ) ) ;
50+ var webpackRootConfig = require ( path . join ( extensionPath , 'extension.webpack.config.js' ) ) ;
51+ for ( var key in webpackRootConfig . externals ) {
52+ if ( key in packageJsonConfig . dependencies ) {
53+ packagedDependencies . push ( key ) ;
54+ }
55+ }
56+ vsce . listFiles ( { cwd : extensionPath , packageManager : vsce . PackageManager . Yarn , packagedDependencies : packagedDependencies } ) . then ( function ( fileNames ) {
3957 var files = fileNames
4058 . map ( function ( fileName ) { return path . join ( extensionPath , fileName ) ; } )
4159 . map ( function ( filePath ) { return new File ( {
@@ -48,76 +66,86 @@ function fromLocal(extensionPath, sourceMappingURLBase) {
4866 // check for a webpack configuration files, then invoke webpack
4967 // and merge its output with the files stream. also rewrite the package.json
5068 // file to a new entry point
51- var pattern = path . join ( extensionPath , '/**/extension.webpack.config.js' ) ;
52- var webpackConfigLocations = glob . sync ( pattern , { ignore : [ '**/node_modules' ] } ) ;
53- if ( webpackConfigLocations . length ) {
54- var packageJsonFilter = filter ( function ( f ) {
55- if ( path . basename ( f . path ) === 'package.json' ) {
56- // only modify package.json's next to the webpack file.
57- // to be safe, use existsSync instead of path comparison.
58- return fs . existsSync ( path . join ( path . dirname ( f . path ) , 'extension.webpack.config.js' ) ) ;
69+ var webpackConfigLocations = glob . sync ( path . join ( extensionPath , '/**/extension.webpack.config.js' ) , { ignore : [ '**/node_modules' ] } ) ;
70+ var packageJsonFilter = filter ( function ( f ) {
71+ if ( path . basename ( f . path ) === 'package.json' ) {
72+ // only modify package.json's next to the webpack file.
73+ // to be safe, use existsSync instead of path comparison.
74+ return fs . existsSync ( path . join ( path . dirname ( f . path ) , 'extension.webpack.config.js' ) ) ;
75+ }
76+ return false ;
77+ } , { restore : true } ) ;
78+ var patchFilesStream = filesStream
79+ . pipe ( packageJsonFilter )
80+ . pipe ( buffer ( ) )
81+ . pipe ( json ( function ( data ) {
82+ // hardcoded entry point directory!
83+ data . main = data . main . replace ( '/out/' , / d i s t / ) ;
84+ return data ;
85+ } ) )
86+ . pipe ( packageJsonFilter . restore ) ;
87+ var webpackStreams = webpackConfigLocations . map ( function ( webpackConfigPath ) {
88+ var webpackDone = function ( err , stats ) {
89+ util . log ( "Bundled extension: " + util . colors . yellow ( path . join ( path . basename ( extensionPath ) , path . relative ( extensionPath , webpackConfigPath ) ) ) + "..." ) ;
90+ if ( err ) {
91+ result . emit ( 'error' , err ) ;
5992 }
60- return false ;
61- } , { restore : true } ) ;
62- var patchFilesStream = filesStream
63- . pipe ( packageJsonFilter )
64- . pipe ( buffer ( ) )
65- . pipe ( json ( function ( data ) {
66- // hardcoded entry point directory!
67- data . main = data . main . replace ( '/out/' , / d i s t / ) ;
68- return data ;
93+ var compilation = stats . compilation ;
94+ if ( compilation . errors . length > 0 ) {
95+ result . emit ( 'error' , compilation . errors . join ( '\n' ) ) ;
96+ }
97+ if ( compilation . warnings . length > 0 ) {
98+ result . emit ( 'error' , compilation . warnings . join ( '\n' ) ) ;
99+ }
100+ } ;
101+ var webpackConfig = __assign ( { } , require ( webpackConfigPath ) , { mode : 'production' } ) ;
102+ var relativeOutputPath = path . relative ( extensionPath , webpackConfig . output . path ) ;
103+ return webpackGulp ( webpackConfig , webpack , webpackDone )
104+ . pipe ( es . through ( function ( data ) {
105+ data . stat = data . stat || { } ;
106+ data . base = extensionPath ;
107+ this . emit ( 'data' , data ) ;
69108 } ) )
70- . pipe ( packageJsonFilter . restore ) ;
71- var webpackStreams = webpackConfigLocations . map ( function ( webpackConfigPath ) {
72- var webpackDone = function ( err , stats ) {
73- util . log ( "Bundled extension: " + util . colors . yellow ( path . join ( path . basename ( extensionPath ) , path . relative ( extensionPath , webpackConfigPath ) ) ) + "..." ) ;
74- if ( err ) {
75- result . emit ( 'error' , err ) ;
76- }
77- var compilation = stats . compilation ;
78- if ( compilation . errors . length > 0 ) {
79- result . emit ( 'error' , compilation . errors . join ( '\n' ) ) ;
80- }
81- if ( compilation . warnings . length > 0 ) {
82- result . emit ( 'error' , compilation . warnings . join ( '\n' ) ) ;
83- }
84- } ;
85- var webpackConfig = __assign ( { } , require ( webpackConfigPath ) , { mode : 'production' } ) ;
86- var relativeOutputPath = path . relative ( extensionPath , webpackConfig . output . path ) ;
87- return webpackGulp ( webpackConfig , webpack , webpackDone )
88- . pipe ( es . through ( function ( data ) {
89- data . stat = data . stat || { } ;
90- data . base = extensionPath ;
91- this . emit ( 'data' , data ) ;
92- } ) )
93- . pipe ( es . through ( function ( data ) {
94- // source map handling:
95- // * rewrite sourceMappingURL
96- // * save to disk so that upload-task picks this up
97- if ( sourceMappingURLBase ) {
98- var contents = data . contents . toString ( 'utf8' ) ;
99- data . contents = Buffer . from ( contents . replace ( / \n \/ \/ # s o u r c e M a p p i n g U R L = ( .* ) $ / gm, function ( _m , g1 ) {
100- return "\n//# sourceMappingURL=" + sourceMappingURLBase + "/extensions/" + path . basename ( extensionPath ) + "/" + relativeOutputPath + "/" + g1 ;
101- } ) , 'utf8' ) ;
102- if ( / \. j s \. m a p $ / . test ( data . path ) ) {
103- if ( ! fs . existsSync ( path . dirname ( data . path ) ) ) {
104- fs . mkdirSync ( path . dirname ( data . path ) ) ;
105- }
106- fs . writeFileSync ( data . path , data . contents ) ;
109+ . pipe ( es . through ( function ( data ) {
110+ // source map handling:
111+ // * rewrite sourceMappingURL
112+ // * save to disk so that upload-task picks this up
113+ if ( sourceMappingURLBase ) {
114+ var contents = data . contents . toString ( 'utf8' ) ;
115+ data . contents = Buffer . from ( contents . replace ( / \n \/ \/ # s o u r c e M a p p i n g U R L = ( .* ) $ / gm, function ( _m , g1 ) {
116+ return "\n//# sourceMappingURL=" + sourceMappingURLBase + "/extensions/" + path . basename ( extensionPath ) + "/" + relativeOutputPath + "/" + g1 ;
117+ } ) , 'utf8' ) ;
118+ if ( / \. j s \. m a p $ / . test ( data . path ) ) {
119+ if ( ! fs . existsSync ( path . dirname ( data . path ) ) ) {
120+ fs . mkdirSync ( path . dirname ( data . path ) ) ;
107121 }
122+ fs . writeFileSync ( data . path , data . contents ) ;
108123 }
109- this . emit ( 'data' , data ) ;
110- } ) ) ;
111- } ) ;
112- es . merge . apply ( es , webpackStreams . concat ( [ patchFilesStream ] ) ) . pipe ( result ) ;
113- }
114- else {
115- filesStream . pipe ( result ) ;
116- }
124+ }
125+ this . emit ( 'data' , data ) ;
126+ } ) ) ;
127+ } ) ;
128+ es . merge . apply ( es , webpackStreams . concat ( [ patchFilesStream ] ) ) . pipe ( result ) ;
117129 } ) . catch ( function ( err ) { return result . emit ( 'error' , err ) ; } ) ;
118130 return result . pipe ( stats_1 . createStatsStream ( path . basename ( extensionPath ) ) ) ;
119131}
120- exports . fromLocal = fromLocal ;
132+ function fromLocalNormal ( extensionPath ) {
133+ var result = es . through ( ) ;
134+ vsce . listFiles ( { cwd : extensionPath , packageManager : vsce . PackageManager . Yarn } )
135+ . then ( function ( fileNames ) {
136+ var files = fileNames
137+ . map ( function ( fileName ) { return path . join ( extensionPath , fileName ) ; } )
138+ . map ( function ( filePath ) { return new File ( {
139+ path : filePath ,
140+ stat : fs . statSync ( filePath ) ,
141+ base : extensionPath ,
142+ contents : fs . createReadStream ( filePath )
143+ } ) ; } ) ;
144+ es . readArray ( files ) . pipe ( result ) ;
145+ } )
146+ . catch ( function ( err ) { return result . emit ( 'error' , err ) ; } ) ;
147+ return result ;
148+ }
121149function error ( err ) {
122150 var result = es . through ( ) ;
123151 setTimeout ( function ( ) { return result . emit ( 'error' , err ) ; } ) ;
0 commit comments