mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-10-26 19:24:31 +03:00
support ES6 default require for packages (#21112)
This allows loading the packages that are Es module and export their function wrapped in a default object. This is the case for any package that uses Babel 6, Babel 7, or other modern compilers for transpiling their package.
This commit is contained in:
parent
d93f2dd039
commit
bd189ebce9
21
src/module-utils.js
Normal file
21
src/module-utils.js
Normal file
@ -0,0 +1,21 @@
|
||||
// a require function with both ES5 and ES6 default export support
|
||||
function requireModule(path) {
|
||||
const modul = require(path);
|
||||
if (modul === null || modul === undefined) {
|
||||
// if null do not bother
|
||||
return modul;
|
||||
} else {
|
||||
if (
|
||||
modul.__esModule === true &&
|
||||
(modul.default !== undefined && modul.default !== null)
|
||||
) {
|
||||
// __esModule flag is true and default is exported, which means that
|
||||
// an object containing the main functions (e.g. activate, etc) is default exported
|
||||
return modul.default;
|
||||
} else {
|
||||
return modul;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.requireModule = requireModule;
|
@ -8,6 +8,7 @@ const dedent = require('dedent');
|
||||
const CompileCache = require('./compile-cache');
|
||||
const ModuleCache = require('./module-cache');
|
||||
const BufferedProcess = require('./buffered-process');
|
||||
const { requireModule } = require('./module-utils');
|
||||
|
||||
// Extended: Loads and activates a package's main module and resources such as
|
||||
// stylesheets, keymaps, grammar, editor properties, and menus.
|
||||
@ -881,8 +882,9 @@ module.exports = class Package {
|
||||
requireMainModule() {
|
||||
if (this.bundledPackage && this.packageManager.packagesCache[this.name]) {
|
||||
if (this.packageManager.packagesCache[this.name].main) {
|
||||
this.mainModule = require(this.packageManager.packagesCache[this.name]
|
||||
.main);
|
||||
this.mainModule = requireModule(
|
||||
this.packageManager.packagesCache[this.name].main
|
||||
);
|
||||
return this.mainModule;
|
||||
}
|
||||
} else if (this.mainModuleRequired) {
|
||||
@ -904,7 +906,7 @@ module.exports = class Package {
|
||||
|
||||
const previousViewProviderCount = this.viewRegistry.getViewProviderCount();
|
||||
const previousDeserializerCount = this.deserializerManager.getDeserializerCount();
|
||||
this.mainModule = require(mainModulePath);
|
||||
this.mainModule = requireModule(mainModulePath);
|
||||
if (
|
||||
this.viewRegistry.getViewProviderCount() ===
|
||||
previousViewProviderCount &&
|
||||
|
Loading…
Reference in New Issue
Block a user