Skip to content

Commit 01ec0d6

Browse files
committed
fix(config): fix json config loading
1 parent e868e3e commit 01ec0d6

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

packages/config/src/index.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
1+
import fs from 'fs/promises'
22
import { findUp } from 'find-up-simple'
33
import type {
44
ReleaserStepsOptions,
@@ -143,6 +143,20 @@ async function loadAndSetIfQuery(
143143
}
144144
}
145145

146+
async function importConfig(path: string) {
147+
if (path.endsWith('.json')) {
148+
const json = await fs.readFile(path, 'utf-8')
149+
const config = JSON.parse(json) as SimpleReleaseConfig
150+
151+
return config
152+
}
153+
154+
const module = await import(path) as SimpleReleaseConfig | { default: SimpleReleaseConfig }
155+
const config = 'default' in module ? module.default : module
156+
157+
return config
158+
}
159+
146160
/**
147161
* Load simple-release config.
148162
* @param requirements
@@ -172,8 +186,7 @@ export async function load(
172186

173187
if (foundPath) {
174188
try {
175-
const module = await import(foundPath) as SimpleReleaseConfig | { default: SimpleReleaseConfig }
176-
const config = 'default' in module ? module.default : module
189+
const config = await importConfig(foundPath)
177190

178191
validate(config, reqs)
179192

0 commit comments

Comments
 (0)