Skip to content

Commit

Permalink
fix(core): clearing cache of required actions when changed
Browse files Browse the repository at this point in the history
  • Loading branch information
allardy committed Aug 8, 2019
1 parent 39a5739 commit 7f59d37
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/bp/core/services/action/action-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ export class ScopedActionService {
if (key.toLowerCase().indexOf(`/actions`) > -1) {
this._scriptsCache.clear()
this._actionsCache = undefined

// Clearing cache for files required in actions
Object.keys(require.cache)
.filter(r => r.match(/(\\|\/)actions(\\|\/)/g))
.map(file => delete require.cache[file])
}
})
}
Expand Down
7 changes: 6 additions & 1 deletion src/bp/core/services/hook/hook-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { IO } from 'botpress/sdk'
import { ObjectCache } from 'common/object-cache'
import { UntrustedSandbox } from 'core/misc/code-sandbox'
import { printObject } from 'core/misc/print'
import { WorkspaceUserAttributes } from 'core/repositories/workspace_users'
import { inject, injectable, tagged } from 'inversify'
import _ from 'lodash'
import path from 'path'
Expand All @@ -13,7 +14,6 @@ import { requireAtPaths } from '../../modules/require'
import { TYPES } from '../../types'
import { VmRunner } from '../action/vm'
import { Incident } from '../alerting-service'
import { WorkspaceUserAttributes } from 'core/repositories/workspace_users'

const debug = DEBUG('hooks')

Expand Down Expand Up @@ -144,6 +144,11 @@ export class HookService {
if (key.toLowerCase().indexOf(`/hooks/`) > -1) {
// clear the cache if there's any file that has changed in the `hooks` folder
this._scriptsCache.clear()

// Clearing cache for files required in hooks
Object.keys(require.cache)
.filter(r => r.match(/(\\|\/)hooks(\\|\/)/g))
.map(file => delete require.cache[file])
}
})
}
Expand Down

0 comments on commit 7f59d37

Please sign in to comment.