@@ -881,8 +881,9 @@ module.exports = class Package {
881
881
requireMainModule ( ) {
882
882
if ( this . bundledPackage && this . packageManager . packagesCache [ this . name ] ) {
883
883
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
+ ) ;
886
887
return this . mainModule ;
887
888
}
888
889
} else if ( this . mainModuleRequired ) {
@@ -904,7 +905,7 @@ module.exports = class Package {
904
905
905
906
const previousViewProviderCount = this . viewRegistry . getViewProviderCount ( ) ;
906
907
const previousDeserializerCount = this . deserializerManager . getDeserializerCount ( ) ;
907
- this . mainModule = require ( mainModulePath ) ;
908
+ this . mainModule = this . _require ( mainModulePath ) ;
908
909
if (
909
910
this . viewRegistry . getViewProviderCount ( ) ===
910
911
previousViewProviderCount &&
@@ -921,6 +922,27 @@ module.exports = class Package {
921
922
}
922
923
}
923
924
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
+
924
946
getMainModulePath ( ) {
925
947
if ( this . resolvedMainModulePath ) return this . mainModulePath ;
926
948
this . resolvedMainModulePath = true ;
0 commit comments