fix(core): don't skip loading runtime modules if one is improperly resolved (#10193)

This commit is contained in:
Ivan Ehreshi 2024-06-14 05:56:56 -07:00 committed by GitHub
parent 940fc7dcbb
commit e0ca3d1af8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 1 deletions

View File

@ -150,7 +150,10 @@ export default class ModuleContainer {
// Prevent adding buildModules-listed entries in production // Prevent adding buildModules-listed entries in production
if (this.options.buildModules.includes(handler) && this.options._start) { if (this.options.buildModules.includes(handler) && this.options._start) {
return if (handler) {
return
}
consola.warn('Module not resolved:', src)
} }
// Resolve handler // Resolve handler

View File

@ -431,6 +431,28 @@ describe('core: module', () => {
await expect(module.addModule('moduleTest')).rejects.toThrow('Module should export a function: moduleTest') await expect(module.addModule('moduleTest')).rejects.toThrow('Module should export a function: moduleTest')
}) })
test('should prevent adding same handler to modules and buildModules', async () => {
const handler = jest.fn(() => true)
handler.meta = {
name: 'moduleTest'
}
const module = new ModuleContainer({
resolver: { requireModule },
options: {
...defaultOptions,
buildModules: [handler],
_start: true
}
})
const result = await module.addModule({ handler }, true)
expect(result).toBeUndefined()
expect(handler).toBeCalledTimes(0)
expect(module.requiredModules.moduleTest).toBeUndefined()
})
test('should prevent multiple adding when requireOnce is enabled', async () => { test('should prevent multiple adding when requireOnce is enabled', async () => {
const module = new ModuleContainer({ const module = new ModuleContainer({
resolver: { requireModule }, resolver: { requireModule },