Skip to content

Commit d5d4a46

Browse files
committed
fix: cjs项目读取配置失败
1 parent f96d401 commit d5d4a46

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

src/lib/read-config.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import path from 'node:path';
22
import { pathToFileURL } from 'node:url';
3-
import { tsImport } from 'tsx/esm/api';
3+
import { require } from 'tsx/cjs/api';
44
import type { OpenapiClientConfig } from '../define-config';
55

6-
export const readConfig = async () => {
7-
const { default: content } = await tsImport(
8-
pathToFileURL(path.resolve('openapi.config.ts')).toString(),
9-
import.meta.url,
10-
);
6+
export const readConfig = () => {
7+
const { default: content } = require(pathToFileURL(
8+
path.resolve('openapi.config.ts'),
9+
).toString(), import.meta.url);
1110
return content as OpenapiClientConfig[];
1211
};

test/lib/read-config.test.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { expect, test } from 'vitest';
22
import { readConfig } from '../../src/lib/read-config';
33

44
test('从根目录获取', async () => {
5-
const config = await readConfig();
6-
expect(config).toMatchInlineSnapshot(`
5+
expect(readConfig()).toMatchInlineSnapshot(`
76
[
87
{
98
"path": "./openapi/openapi.json",

0 commit comments

Comments
 (0)