Skip to content

Commit 975da25

Browse files
Fixing JS plugin hot reloading
1 parent 17c71fe commit 975da25

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

plugins/combat/combat.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ const action = async details => {
44
const { player, npc } = details;
55

66
npc.updateFlags.addDamage(1, DamageType.DAMAGE, 4, 5);
7+
npc.say(`Ow!`);
78

8-
await wait(1000);
9+
await wait(100);
910

1011
player.updateFlags.addDamage(1, DamageType.DAMAGE, 9, 10);
1112
};

src/plugins/commands/reload-plugins.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ const action: commandAction = (details) => {
77

88
player.sendLogMessage('Reloading plugins...', details.isConsole);
99

10+
// Delete node cache for all the old JS plugins
11+
for(const path in require.cache) {
12+
if(!path.endsWith('.js')) {
13+
continue;
14+
}
15+
if(path.indexOf('node_modules') !== -1 || path.indexOf('dist') !== -1) {
16+
continue;
17+
}
18+
if(path.indexOf('rune.js') !== -1 || path.indexOf('plugins') === -1) {
19+
continue;
20+
}
21+
22+
delete require.cache[path];
23+
}
1024

1125
injectPlugins()
1226
.then(() => player.sendLogMessage('Plugins reloaded.', details.isConsole))

src/plugins/plugin-loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export const pluginFilter = (pluginIds: number | number[], searchId: number, plu
5757

5858
const readdir = util.promisify(fs.readdir);
5959
const stat = util.promisify(fs.stat);
60-
const blacklist = ['plugin-loader.js', 'plugin.js'];
60+
const blacklist = ['plugin-loader.js', 'plugin.js', 'rune.js'];
6161

6262
async function* getFiles(directory: string): AsyncGenerator<string> {
6363
const files = await readdir(directory);

0 commit comments

Comments
 (0)