mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-16 05:38: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 path = plugs.base;
|
||||||
const localPath = plugs.local;
|
const localPath = plugs.local;
|
||||||
|
|
||||||
|
patchModuleLoad();
|
||||||
|
|
||||||
// caches
|
// caches
|
||||||
let plugins = config.getPlugins();
|
let plugins = config.getPlugins();
|
||||||
let paths = getPaths();
|
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() {
|
function checkDeprecatedExtendKeymaps() {
|
||||||
modules.forEach(plugin => {
|
modules.forEach(plugin => {
|
||||||
if (plugin.extendKeymaps) {
|
if (plugin.extendKeymaps) {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,8 @@ import notify from './notify';
|
||||||
const Module = require('module');
|
const Module = require('module');
|
||||||
const originalLoad = Module._load;
|
const originalLoad = Module._load;
|
||||||
Module._load = function _load(path) {
|
Module._load = function _load(path) {
|
||||||
|
// PLEASE NOTE: Code changes here, also need to be changed in
|
||||||
|
// app/plugins.js
|
||||||
switch (path) {
|
switch (path) {
|
||||||
case 'react':
|
case 'react':
|
||||||
return React;
|
return React;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue