diff --git a/package.json b/package.json
--- a/package.json
+++ b/package.json
@@ -16,12 +16,9 @@
"scripts": {
"build": "pnpm --recursive build",
"changeset": "changeset",
- "client-axios": "pnpm --filter @hey-api/client-axios --",
- "client-core": "pnpm --filter @hey-api/client-core --",
- "client-fetch": "pnpm --filter @hey-api/client-fetch --",
- "client-nextjs": "pnpm --filter @hey-api/client-nextjs --",
+ "client": "sh ./scripts/client.sh",
"docs": "pnpm --filter @hey-api/docs --",
- "example": "pnpm --filter @examples/openapi-ts-axios --",
+ "example": "sh ./scripts/example.sh",
"format": "prettier --write .",
"lint:fix": "prettier --check . && eslint . --fix",
"lint": "prettier --check . && eslint .",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -134,6 +134,55 @@
specifier: 5.2.10
version: 5.2.10(@types/node@20.12.7)
+ examples/openapi-ts-fetch:
+ dependencies:
+ '@hey-api/client-fetch':
+ specifier: workspace:*
+ version: link:../../packages/client-fetch
+ react:
+ specifier: 18.2.0
+ version: 18.2.0
+ react-dom:
+ specifier: 18.2.0
+ version: 18.2.0(react@18.2.0)
+ devDependencies:
+ '@hey-api/openapi-ts':
+ specifier: workspace:*
+ version: link:../../packages/openapi-ts
+ '@types/react':
+ specifier: 18.2.79
+ version: 18.2.79
+ '@types/react-dom':
+ specifier: 18.2.25
+ version: 18.2.25
+ '@typescript-eslint/eslint-plugin':
+ specifier: 7.7.1
+ version: 7.7.1(@typescript-eslint/parser@7.7.1)(eslint@8.57.0)(typescript@5.4.5)
+ '@typescript-eslint/parser':
+ specifier: 7.7.1
+ version: 7.7.1(eslint@8.57.0)(typescript@5.4.5)
+ '@vitejs/plugin-react':
+ specifier: 4.2.1
+ version: 4.2.1(vite@5.2.10)
+ eslint:
+ specifier: 8.57.0
+ version: 8.57.0
+ eslint-plugin-react-hooks:
+ specifier: 4.6.0
+ version: 4.6.0(eslint@8.57.0)
+ eslint-plugin-react-refresh:
+ specifier: 0.4.6
+ version: 0.4.6(eslint@8.57.0)
+ prettier:
+ specifier: 3.2.5
+ version: 3.2.5
+ typescript:
+ specifier: 5.4.5
+ version: 5.4.5
+ vite:
+ specifier: 5.2.10
+ version: 5.2.10(@types/node@20.12.7)
+
packages/client-axios:
dependencies:
'@hey-api/client-core':
diff --git a/scripts/client.sh b/scripts/client.sh
new file mode 100644
--- /dev/null
+++ b/scripts/client.sh
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+pnpm --filter @hey-api/client-$1 -- $2
diff --git a/scripts/example.sh b/scripts/example.sh
new file mode 100644
--- /dev/null
+++ b/scripts/example.sh
@@ -0,0 +1,3 @@
+#!/usr/bin/env bash
+
+pnpm --filter @example/openapi-ts-$1 -- $2
diff --git a/examples/openapi-ts-axios/package.json b/examples/openapi-ts-axios/package.json
--- a/examples/openapi-ts-axios/package.json
+++ b/examples/openapi-ts-axios/package.json
@@ -1,5 +1,5 @@
{
- "name": "@examples/openapi-ts-axios",
+ "name": "@example/openapi-ts-axios",
"private": true,
"version": "0.0.0",
"type": "module",
diff --git a/examples/openapi-ts-fetch/.gitignore b/examples/openapi-ts-fetch/.gitignore
new file mode 100644
--- /dev/null
+++ b/examples/openapi-ts-fetch/.gitignore
@@ -0,0 +1,24 @@
+# Logs
+logs
+*.log
+npm-debug.log*
+yarn-debug.log*
+yarn-error.log*
+pnpm-debug.log*
+lerna-debug.log*
+
+node_modules
+dist
+dist-ssr
+*.local
+
+# Editor directories and files
+.vscode/*
+!.vscode/extensions.json
+.idea
+.DS_Store
+*.suo
+*.ntvs*
+*.njsproj
+*.sln
+*.sw?
diff --git a/examples/openapi-ts-fetch/index.html b/examples/openapi-ts-fetch/index.html
new file mode 100644
--- /dev/null
+++ b/examples/openapi-ts-fetch/index.html
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+ Hey API + Fetch API Demo
+
+
+
+
+
+
diff --git a/examples/openapi-ts-fetch/openapi-ts.config.ts b/examples/openapi-ts-fetch/openapi-ts.config.ts
new file mode 100644
--- /dev/null
+++ b/examples/openapi-ts-fetch/openapi-ts.config.ts
@@ -0,0 +1,10 @@
+import { defineConfig } from '@hey-api/openapi-ts';
+
+export default defineConfig({
+ base: 'https://petstore3.swagger.io/api/v3',
+ format: 'prettier',
+ input:
+ 'https://raw.githubusercontent.com/swagger-api/swagger-petstore/master/src/main/resources/openapi.yaml',
+ lint: 'eslint',
+ output: './src/client',
+});
diff --git a/examples/openapi-ts-fetch/package.json b/examples/openapi-ts-fetch/package.json
new file mode 100644
--- /dev/null
+++ b/examples/openapi-ts-fetch/package.json
@@ -0,0 +1,32 @@
+{
+ "name": "@example/openapi-ts-fetch",
+ "private": true,
+ "version": "0.0.0",
+ "type": "module",
+ "scripts": {
+ "build": "tsc && vite build",
+ "dev": "vite",
+ "lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
+ "openapi-ts": "openapi-ts",
+ "preview": "vite preview"
+ },
+ "dependencies": {
+ "@hey-api/client-fetch": "workspace:*",
+ "react": "18.2.0",
+ "react-dom": "18.2.0"
+ },
+ "devDependencies": {
+ "@hey-api/openapi-ts": "workspace:*",
+ "@types/react": "18.2.79",
+ "@types/react-dom": "18.2.25",
+ "@typescript-eslint/eslint-plugin": "7.7.1",
+ "@typescript-eslint/parser": "7.7.1",
+ "@vitejs/plugin-react": "4.2.1",
+ "eslint": "8.57.0",
+ "eslint-plugin-react-hooks": "4.6.0",
+ "eslint-plugin-react-refresh": "0.4.6",
+ "prettier": "3.2.5",
+ "typescript": "5.4.5",
+ "vite": "5.2.10"
+ }
+}
diff --git a/examples/openapi-ts-fetch/tsconfig.json b/examples/openapi-ts-fetch/tsconfig.json
new file mode 100644
--- /dev/null
+++ b/examples/openapi-ts-fetch/tsconfig.json
@@ -0,0 +1,25 @@
+{
+ "compilerOptions": {
+ "target": "ES2020",
+ "useDefineForClassFields": true,
+ "lib": ["ES2020", "DOM", "DOM.Iterable"],
+ "module": "ESNext",
+ "skipLibCheck": true,
+
+ /* Bundler mode */
+ "moduleResolution": "bundler",
+ "allowImportingTsExtensions": true,
+ "resolveJsonModule": true,
+ "isolatedModules": true,
+ "noEmit": true,
+ "jsx": "react-jsx",
+
+ /* Linting */
+ "strict": true,
+ "noUnusedLocals": true,
+ "noUnusedParameters": true,
+ "noFallthroughCasesInSwitch": true
+ },
+ "include": ["src"],
+ "references": [{ "path": "./tsconfig.node.json" }]
+}
diff --git a/examples/openapi-ts-fetch/tsconfig.node.json b/examples/openapi-ts-fetch/tsconfig.node.json
new file mode 100644
--- /dev/null
+++ b/examples/openapi-ts-fetch/tsconfig.node.json
@@ -0,0 +1,11 @@
+{
+ "compilerOptions": {
+ "composite": true,
+ "skipLibCheck": true,
+ "module": "ESNext",
+ "moduleResolution": "bundler",
+ "allowSyntheticDefaultImports": true,
+ "strict": true
+ },
+ "include": ["vite.config.ts"]
+}
diff --git a/examples/openapi-ts-fetch/vite.config.ts b/examples/openapi-ts-fetch/vite.config.ts
new file mode 100644
--- /dev/null
+++ b/examples/openapi-ts-fetch/vite.config.ts
@@ -0,0 +1,7 @@
+import react from '@vitejs/plugin-react';
+import { defineConfig } from 'vite';
+
+// https://vitejs.dev/config/
+export default defineConfig({
+ plugins: [react()],
+});
diff --git a/packages/client-fetch/package.json b/packages/client-fetch/package.json
--- a/packages/client-fetch/package.json
+++ b/packages/client-fetch/package.json
@@ -26,13 +26,16 @@
"typescript",
"vue"
],
- "main": "./dist/index.cjs",
- "types": "./dist/index.d.ts",
+ "exports": {
+ "import": "./dist/node/index.mjs",
+ "require": "./dist/node/index.cjs",
+ "types": "./dist/node/index.d.ts"
+ },
"scripts": {
"build-bundle": "rollup --config rollup.config.ts --configPlugin typescript",
"build-types-check": "tsc --project tsconfig.check.json",
"build-types-roll": "rollup --config rollup.dts.config.ts --configPlugin typescript && rimraf temp",
- "build-types-temp": "tsc --emitDeclarationOnly --outDir temp -p src",
+ "build-types-temp": "tsc --emitDeclarationOnly --outDir temp -p src/node",
"build-types": "pnpm build-types-temp && pnpm build-types-roll && pnpm build-types-check",
"build": "pnpm clean && pnpm build-bundle && pnpm build-types",
"clean": "rimraf dist coverage node_modules/.cache",
diff --git a/packages/client-fetch/rollup.config.ts b/packages/client-fetch/rollup.config.ts
--- a/packages/client-fetch/rollup.config.ts
+++ b/packages/client-fetch/rollup.config.ts
@@ -20,28 +20,48 @@
];
function createConfig(isProduction: boolean) {
- return defineConfig({
- external: externalDependencies,
- input: path.resolve(__dirname, 'src/index.ts'),
- output: {
- file: path.resolve(__dirname, 'dist/index.cjs'),
- format: 'cjs',
- },
- plugins: [
- typescript({
- declaration: false,
- tsconfig: path.resolve(__dirname, 'src/tsconfig.json'),
- }),
- commonjs({
- sourceMap: false,
- }),
- isProduction && terser(),
- ],
- });
+ return [
+ defineConfig({
+ external: externalDependencies,
+ input: path.resolve(__dirname, 'src/node/index.ts'),
+ output: {
+ file: path.resolve(__dirname, 'dist/node/index.cjs'),
+ format: 'cjs',
+ },
+ plugins: [
+ typescript({
+ declaration: false,
+ tsconfig: path.resolve(__dirname, 'src/node/tsconfig.json'),
+ }),
+ commonjs({
+ sourceMap: false,
+ }),
+ isProduction && terser(),
+ ],
+ }),
+ defineConfig({
+ external: externalDependencies,
+ input: path.resolve(__dirname, 'src/node/index.ts'),
+ output: {
+ file: path.resolve(__dirname, 'dist/node/index.mjs'),
+ format: 'esm',
+ },
+ plugins: [
+ typescript({
+ declaration: false,
+ tsconfig: path.resolve(__dirname, 'src/node/tsconfig.json'),
+ }),
+ commonjs({
+ sourceMap: false,
+ }),
+ isProduction && terser(),
+ ],
+ }),
+ ];
}
export default (commandLineArgs: any): RollupOptions[] => {
const isDev = commandLineArgs.watch;
const isProduction = !isDev;
- return defineConfig([createConfig(isProduction)]);
+ return defineConfig(createConfig(isProduction));
};
diff --git a/packages/client-fetch/rollup.dts.config.ts b/packages/client-fetch/rollup.dts.config.ts
--- a/packages/client-fetch/rollup.dts.config.ts
+++ b/packages/client-fetch/rollup.dts.config.ts
@@ -6,10 +6,10 @@
export default defineConfig({
external: externalDependencies,
input: {
- index: './temp/index.d.ts',
+ index: './temp/node/index.d.ts',
},
output: {
- dir: './dist',
+ dir: './dist/node',
format: 'cjs',
},
plugins: [dts({ respectExternal: true })],
diff --git a/examples/openapi-ts-axios/src/App.tsx b/examples/openapi-ts-axios/src/App.tsx
--- a/examples/openapi-ts-axios/src/App.tsx
+++ b/examples/openapi-ts-axios/src/App.tsx
@@ -37,7 +37,7 @@
alt="Hey API logo"
/>
- @hey-api/openapi-ts example
+ @hey-api/openapi-ts 🤝 Axios