mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-13 04:28:41 -09:00
Fix plugin module hijacking on main process (#2866)
Fixes some plugin loading (like hyperline)
This commit is contained in:
parent
0199c44915
commit
f75895a176
2 changed files with 36 additions and 0 deletions
|
|
@ -17,6 +17,8 @@ const cache = new Config();
|
|||
const path = plugs.base;
|
||||
const localPath = plugs.local;
|
||||
|
||||
patchModuleLoad();
|
||||
|
||||
// caches
|
||||
let plugins = config.getPlugins();
|
||||
let paths = getPaths();
|
||||
|
|
@ -43,6 +45,38 @@ config.subscribe(() => {
|
|||
}
|
||||
});
|
||||
|
||||
// patching Module._load
|
||||
// so plugins can `require` them without needing their own version
|
||||
// https://github.com/zeit/hyper/issues/619
|
||||
function patchModuleLoad() {
|
||||
const React = require('react');
|
||||
const PureComponent = React.PureComponent;
|
||||
const ReactDOM = require('react-dom');
|
||||
|
||||
const Module = require('module');
|
||||
const originalLoad = Module._load;
|
||||
Module._load = function _load(modulePath) {
|
||||
// PLEASE NOTE: Code changes here, also need to be changed in
|
||||
// lib/utils/plugins.js
|
||||
switch (modulePath) {
|
||||
case 'react':
|
||||
return React;
|
||||
case 'react-dom':
|
||||
return ReactDOM;
|
||||
case 'hyper/component':
|
||||
return PureComponent;
|
||||
// These return Object, since they work differently on the backend, than on the frontend.
|
||||
// Still needs to be here, to prevent errors, while loading plugins.
|
||||
case 'hyper/Notification':
|
||||
case 'hyper/notify':
|
||||
case 'hyper/decorate':
|
||||
return Object;
|
||||
default:
|
||||
return originalLoad.apply(this, arguments);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function checkDeprecatedExtendKeymaps() {
|
||||
modules.forEach(plugin => {
|
||||
if (plugin.extendKeymaps) {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ import notify from './notify';
|
|||
const Module = require('module');
|
||||
const originalLoad = Module._load;
|
||||
Module._load = function _load(path) {
|
||||
// PLEASE NOTE: Code changes here, also need to be changed in
|
||||
// app/plugins.js
|
||||
switch (path) {
|
||||
case 'react':
|
||||
return React;
|
||||
|
|
|
|||
Loading…
Reference in a new issue