fix(medusa-core-utils): getConfigFile typings (#2783)
* fix: getConfigFile typeings * Create brave-apes-carry.md Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
7d28eaf8c6
commit
7cced6006a
6
.changeset/brave-apes-carry.md
Normal file
6
.changeset/brave-apes-carry.md
Normal file
@@ -0,0 +1,6 @@
|
||||
---
|
||||
"medusa-core-utils": patch
|
||||
"@medusajs/medusa": patch
|
||||
---
|
||||
|
||||
fix: getConfigFile typings
|
||||
@@ -9,21 +9,20 @@ import { join } from "path"
|
||||
function getConfigFile<TConfig = unknown>(
|
||||
rootDir: string,
|
||||
configName: string
|
||||
): { configModule: TConfig; configFilePath: string } | { error: any } {
|
||||
): { configModule: TConfig; configFilePath: string, error?: any } {
|
||||
const configPath = join(rootDir, configName)
|
||||
let configFilePath = ``
|
||||
let configModule
|
||||
let err
|
||||
|
||||
try {
|
||||
configFilePath = require.resolve(configPath)
|
||||
configModule = require(configFilePath)
|
||||
} catch (err) {
|
||||
return {
|
||||
error: err,
|
||||
}
|
||||
} catch (e) {
|
||||
err = e
|
||||
}
|
||||
|
||||
return { configModule, configFilePath }
|
||||
return { configModule, configFilePath, error: err }
|
||||
}
|
||||
|
||||
export default getConfigFile
|
||||
|
||||
@@ -20,13 +20,10 @@ export const handleConfigError = (error: Error): void => {
|
||||
}
|
||||
|
||||
export default (rootDirectory: string): ConfigModule => {
|
||||
const { configModule, error } = getConfigFile(
|
||||
const { configModule, error } = getConfigFile<ConfigModule>(
|
||||
rootDirectory,
|
||||
`medusa-config`
|
||||
) as {
|
||||
configModule: ConfigModule
|
||||
error: Error | null
|
||||
}
|
||||
)
|
||||
|
||||
if (error) {
|
||||
handleConfigError(error)
|
||||
|
||||
Reference in New Issue
Block a user