Skip to content

Commit

Permalink
Make pluginmanager delete all relative modules from cache insted
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiiks committed Aug 26, 2018
1 parent 23b8e2d commit 8146e0e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
9 changes: 0 additions & 9 deletions client/src/modules/pluginapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,6 @@ export default class PluginApi {
return null;
}

relativeRequire(file) {
const absolutePath = path.join(this.pluginPath, file);
delete Globals.require.cache[Globals.require.resolve(absolutePath)];
return Globals.require(absolutePath);
}
get relative() {
return this.relativeRequire.bind(this);
}

get Api() { return this }

get AsyncEventEmitter() { return AsyncEventEmitter }
Expand Down
6 changes: 6 additions & 0 deletions client/src/modules/pluginmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ export default class extends ContentManager {

static unloadContentHook(content, reload) {
delete Globals.require.cache[Globals.require.resolve(content.paths.mainPath)];
const uncache = [];
for (const required in Globals.require.cache) {
if (!required.includes(content.paths.contentPath)) continue;
uncache.push(Globals.require.resolve(required));
}
for (const u of uncache) delete Globals.require.cache[u];
}

/**
Expand Down
10 changes: 5 additions & 5 deletions tests/ext/plugins/Custom Elements Example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
* This is an example of how you should add custom elements instead of manipulating the DOM directly
*/

// Import custom components
const customVueComponent = require('./components/vuecomponent');
const customReactComponent = require('./components/reactcomponent');

module.exports = (Plugin, Api, Vendor) => {

// Destructure some apis
const { Logger, ReactComponents, Patcher, monkeyPatch, Reflection, Utils, CssUtils, VueInjector, Vuewrap, relative } = Api;
const { Logger, ReactComponents, Patcher, monkeyPatch, Reflection, Utils, CssUtils, VueInjector, Vuewrap, requireUncached } = Api;
const { Vue } = Vendor;
const { React } = Reflection.modules; // This should be in vendor

// Import custom components from relative paths
const customVueComponent = relative('./components/vuecomponent');
const customReactComponent = relative('./components/reactcomponent');

return class extends Plugin {

async onStart() {
Expand Down

0 comments on commit 8146e0e

Please sign in to comment.