@@ -881,8 +881,9 @@ module.exports = class Package {
881881 requireMainModule ( ) {
882882 if ( this . bundledPackage && this . packageManager . packagesCache [ this . name ] ) {
883883 if ( this . packageManager . packagesCache [ this . name ] . main ) {
884- this . mainModule = require ( this . packageManager . packagesCache [ this . name ]
885- . main ) ;
884+ this . mainModule = this . _require (
885+ this . packageManager . packagesCache [ this . name ] . main
886+ ) ;
886887 return this . mainModule ;
887888 }
888889 } else if ( this . mainModuleRequired ) {
@@ -904,7 +905,7 @@ module.exports = class Package {
904905
905906 const previousViewProviderCount = this . viewRegistry . getViewProviderCount ( ) ;
906907 const previousDeserializerCount = this . deserializerManager . getDeserializerCount ( ) ;
907- this . mainModule = require ( mainModulePath ) ;
908+ this . mainModule = this . _require ( mainModulePath ) ;
908909 if (
909910 this . viewRegistry . getViewProviderCount ( ) ===
910911 previousViewProviderCount &&
@@ -921,6 +922,27 @@ module.exports = class Package {
921922 }
922923 }
923924
925+ // a require function with both ES5 and ES6 default export support
926+ _require ( path ) {
927+ const modul = require ( path ) ;
928+ if ( modul === null || modul === undefined ) {
929+ // if null do not bother
930+ return modul ;
931+ } else {
932+ if (
933+ modul . __esModule === true &&
934+ typeof modul . default === 'object' &&
935+ typeof modul . default . activate === 'function'
936+ ) {
937+ // __esModule flag is true and the activate function exists inside it, which means
938+ // an object containing the main functions (e.g. activate, etc) is default exported
939+ return modul . default ;
940+ } else {
941+ return modul ;
942+ }
943+ }
944+ }
945+
924946 getMainModulePath ( ) {
925947 if ( this . resolvedMainModulePath ) return this . mainModulePath ;
926948 this . resolvedMainModulePath = true ;
0 commit comments