Skip to content

Commit 7f59d37

Browse files
committed
fix(core): clearing cache of required actions when changed
1 parent 39a5739 commit 7f59d37

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/bp/core/services/action/action-service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ export class ScopedActionService {
6363
if (key.toLowerCase().indexOf(`/actions`) > -1) {
6464
this._scriptsCache.clear()
6565
this._actionsCache = undefined
66+
67+
// Clearing cache for files required in actions
68+
Object.keys(require.cache)
69+
.filter(r => r.match(/(\\|\/)actions(\\|\/)/g))
70+
.map(file => delete require.cache[file])
6671
}
6772
})
6873
}

src/bp/core/services/hook/hook-service.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { IO } from 'botpress/sdk'
33
import { ObjectCache } from 'common/object-cache'
44
import { UntrustedSandbox } from 'core/misc/code-sandbox'
55
import { printObject } from 'core/misc/print'
6+
import { WorkspaceUserAttributes } from 'core/repositories/workspace_users'
67
import { inject, injectable, tagged } from 'inversify'
78
import _ from 'lodash'
89
import path from 'path'
@@ -13,7 +14,6 @@ import { requireAtPaths } from '../../modules/require'
1314
import { TYPES } from '../../types'
1415
import { VmRunner } from '../action/vm'
1516
import { Incident } from '../alerting-service'
16-
import { WorkspaceUserAttributes } from 'core/repositories/workspace_users'
1717

1818
const debug = DEBUG('hooks')
1919

@@ -144,6 +144,11 @@ export class HookService {
144144
if (key.toLowerCase().indexOf(`/hooks/`) > -1) {
145145
// clear the cache if there's any file that has changed in the `hooks` folder
146146
this._scriptsCache.clear()
147+
148+
// Clearing cache for files required in hooks
149+
Object.keys(require.cache)
150+
.filter(r => r.match(/(\\|\/)hooks(\\|\/)/g))
151+
.map(file => delete require.cache[file])
147152
}
148153
})
149154
}

0 commit comments

Comments
 (0)