Skip to content

Commit 0432418

Browse files
committed
fix: bundle clients from compiled index file
1 parent 7eebbef commit 0432418

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2046
-4735
lines changed

.changeset/eight-squids-crash.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
'@hey-api/client-axios': patch
3+
'@hey-api/client-fetch': patch
4+
'@hey-api/client-nuxt': patch
5+
'@hey-api/openapi-ts': patch
6+
---
7+
8+
fix: bundle clients from compiled index file

examples/openapi-ts-sample/openapi-ts.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { defineConfig } from '@hey-api/openapi-ts';
22

33
export default defineConfig({
44
client: '@hey-api/client-fetch',
5-
input:
6-
'../../packages/openapi-ts/test/spec/2.0.x/body-response-text-plain.yaml',
5+
input: '../../packages/openapi-ts/test/spec/3.1.x/body-nested-array.yaml',
76
output: {
87
format: 'prettier',
98
lint: 'eslint',

examples/openapi-ts-sample/src/App.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import { postFoo } from './client/sdk.gen';
1414
function App() {
1515
const onClick = async () => {
1616
postFoo({
17-
body: 'foo',
17+
body: {
18+
foo: [[1, 2]],
19+
},
1820
});
1921
};
2022

examples/openapi-ts-sample/src/client/sdk.gen.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
33
import {
44
createClient,
55
createConfig,
6+
formDataBodySerializer,
67
type Options,
78
} from '@hey-api/client-fetch';
89

9-
import type { PostFooData, PostFooResponse } from './types.gen';
10+
import type { PostFooData } from './types.gen';
1011

1112
export const client = createClient(createConfig());
1213

1314
export const postFoo = <ThrowOnError extends boolean = false>(
1415
options: Options<PostFooData, ThrowOnError>,
1516
) =>
16-
(options?.client ?? client).post<PostFooResponse, unknown, ThrowOnError>({
17-
bodySerializer: null,
17+
(options?.client ?? client).post<unknown, unknown, ThrowOnError>({
18+
...formDataBodySerializer,
1819
url: '/foo',
1920
...options,
2021
headers: {
21-
'Content-Type': 'text/plain',
22+
'Content-Type': null,
2223
...options?.headers,
2324
},
2425
});
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
// This file is auto-generated by @hey-api/openapi-ts
22

33
export type PostFooData = {
4-
body: string;
4+
body: {
5+
foo: Array<Array<number>>;
6+
};
57
path?: never;
68
query?: never;
79
url: '/foo';
@@ -11,7 +13,5 @@ export type PostFooResponses = {
1113
/**
1214
* OK
1315
*/
14-
200: string;
16+
200: unknown;
1517
};
16-
17-
export type PostFooResponse = PostFooResponses[keyof PostFooResponses];

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
"husky": "9.1.7",
5858
"lint-staged": "15.3.0",
5959
"prettier": "3.4.2",
60+
"rollup": "4.31.0",
61+
"rollup-plugin-dts": "6.1.1",
6062
"tsup": "8.3.5",
6163
"typescript": "5.5.3",
6264
"typescript-eslint": "8.19.1",

packages/client-axios/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
"src"
5555
],
5656
"scripts": {
57-
"build": "tsup && pnpm check-exports",
57+
"build": "tsup && rollup -c && pnpm check-exports",
5858
"check-exports": "attw --pack .",
5959
"dev": "tsup --watch",
6060
"prepublishOnly": "pnpm build",
@@ -68,6 +68,7 @@
6868
"axios": ">= 1.0.0 < 2"
6969
},
7070
"devDependencies": {
71+
"@hey-api/client-core": "workspace:*",
7172
"axios": "1.7.9"
7273
}
7374
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import path from 'node:path';
2+
3+
import { defineConfig } from 'rollup';
4+
import dts from 'rollup-plugin-dts';
5+
6+
const files = ['index.d.ts', 'index.d.cts'];
7+
8+
export default files.map((file) =>
9+
defineConfig({
10+
external: (id) => {
11+
const normalizedId = id.split(path.sep).join('/');
12+
if (normalizedId === '@hey-api/client-core') {
13+
return false;
14+
}
15+
return (
16+
!normalizedId.startsWith('/') && !/^[a-zA-Z]:\//.test(normalizedId)
17+
);
18+
},
19+
input: `./dist/${file}`,
20+
output: {
21+
file: `./dist/${file}`,
22+
format: 'es',
23+
},
24+
plugins: [
25+
dts({
26+
respectExternal: true,
27+
}),
28+
],
29+
}),
30+
);

packages/client-axios/src/__tests__/utils.test.ts

Lines changed: 2 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,7 @@
1+
import type { Auth } from '@hey-api/client-core';
12
import { describe, expect, it, vi } from 'vitest';
23

3-
import type { Auth } from '../types';
4-
import {
5-
axiosHeadersKeywords,
6-
getAuthToken,
7-
mergeHeaders,
8-
setAuthParams,
9-
} from '../utils';
10-
11-
describe('getAuthToken', () => {
12-
it('returns bearer token', async () => {
13-
const auth = vi.fn().mockReturnValue('foo');
14-
const token = await getAuthToken(
15-
{
16-
scheme: 'bearer',
17-
type: 'http',
18-
},
19-
auth,
20-
);
21-
expect(auth).toHaveBeenCalled();
22-
expect(token).toBe('Bearer foo');
23-
});
24-
25-
it('returns basic token', async () => {
26-
const auth = vi.fn().mockReturnValue('foo:bar');
27-
const token = await getAuthToken(
28-
{
29-
scheme: 'basic',
30-
type: 'http',
31-
},
32-
auth,
33-
);
34-
expect(auth).toHaveBeenCalled();
35-
expect(token).toBe(`Basic ${btoa('foo:bar')}`);
36-
});
37-
38-
it('returns raw token', async () => {
39-
const auth = vi.fn().mockReturnValue('foo');
40-
const token = await getAuthToken(
41-
{
42-
type: 'http',
43-
},
44-
auth,
45-
);
46-
expect(auth).toHaveBeenCalled();
47-
expect(token).toBe('foo');
48-
});
49-
50-
it('returns nothing when auth function is undefined', async () => {
51-
const token = await getAuthToken(
52-
{
53-
type: 'http',
54-
},
55-
undefined,
56-
);
57-
expect(token).toBeUndefined();
58-
});
59-
});
4+
import { axiosHeadersKeywords, mergeHeaders, setAuthParams } from '../utils';
605

616
describe('mergeHeaders', () => {
627
it.each(axiosHeadersKeywords)(

packages/client-axios/src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,17 @@ export const createClient = (config: Config): Client => {
110110
};
111111

112112
export type {
113-
Auth,
114113
Client,
115114
Config,
116115
Options,
117116
OptionsLegacyParser,
118117
RequestOptions,
119118
RequestResult,
120119
} from './types';
120+
export { createConfig } from './utils';
121+
export type { Auth, QuerySerializerOptions } from '@hey-api/client-core';
121122
export {
122-
createConfig,
123123
formDataBodySerializer,
124124
jsonBodySerializer,
125125
urlSearchParamsBodySerializer,
126-
} from './utils';
126+
} from '@hey-api/client-core';

0 commit comments

Comments
 (0)