Skip to content

Commit c737e05

Browse files
committed
feat: add rollup-plugin
1 parent 764a2b8 commit c737e05

File tree

10 files changed

+229
-2
lines changed

10 files changed

+229
-2
lines changed

.changeset/empty-horses-invent.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hey-api/rollup-plugin': minor
3+
---
4+
5+
feat: initial release

packages/rollup-plugin/.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
.DS_Store
2+
.idea
3+
.tsup
4+
.tmp
5+
junit.xml
6+
logs
7+
node_modules
8+
npm-debug.log*
9+
temp
10+
yarn-debug.log*
11+
yarn-error.log*
12+
13+
*.iml
14+
dist
15+
coverage
16+
.env
17+
18+
# test files
19+
test/generated
20+
test/e2e/generated
21+
generated/

packages/rollup-plugin/LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Hey API
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/rollup-plugin/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<div align="center">
2+
<img alt="Hey API logo" height="150" src="https://heyapi.dev/images/logo-300w.png" width="150">
3+
<h1 align="center"><b>Vite/Rollup Plugin</b></h1>
4+
<p align="center">🚀 Vite/Rollup plugin for `@hey-api/openapi-ts` codegen.</p>
5+
</div>
6+
7+
## Platform
8+
9+
Our platform for OpenAPI specifications is now available. Automatically update your code when the APIs it depends on change. [Find out more](https://heyapi.dev/openapi-ts/integrations).
10+
11+
## Documentation
12+
13+
Please visit our [website](https://heyapi.dev/) for documentation, guides, migrating, and more.
14+
15+
## Sponsors
16+
17+
Love Hey API? Become our [sponsor](https://github.com/sponsors/hey-api).
18+
19+
<p>
20+
<a href="https://kutt.it/pkEZyc" target="_blank">
21+
<img alt="Stainless logo" height="50" src="https://heyapi.dev/images/stainless-logo-wordmark-480w.jpeg" />
22+
</a>
23+
</p>
24+
25+
## Usage
26+
27+
Add to `plugins` inside your Vite/Rollup configuration.
28+
29+
```ts
30+
import { heyApiPlugin } from '@hey-api/rollup-plugin';
31+
32+
export default defineConfig({
33+
plugins: [
34+
heyApiPlugin({
35+
config: {
36+
// optional configuration instead of using the configuration file
37+
},
38+
}),
39+
],
40+
});
41+
```

packages/rollup-plugin/package.json

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{
2+
"name": "@hey-api/rollup-plugin",
3+
"version": "0.0.0",
4+
"description": "🚀 Vite/Rollup plugin for `@hey-api/openapi-ts` codegen.",
5+
"homepage": "https://heyapi.dev/",
6+
"repository": {
7+
"type": "git",
8+
"url": "git+https://github.com/hey-api/openapi-ts.git"
9+
},
10+
"bugs": {
11+
"url": "https://github.com/hey-api/openapi-ts/issues"
12+
},
13+
"license": "MIT",
14+
"author": {
15+
"email": "[email protected]",
16+
"name": "Hey API",
17+
"url": "https://heyapi.dev"
18+
},
19+
"funding": "https://github.com/sponsors/hey-api",
20+
"keywords": [
21+
"codegen",
22+
"openapi",
23+
"plugin",
24+
"rollup",
25+
"rollup-plugin",
26+
"vite",
27+
"vite-plugin",
28+
"swagger"
29+
],
30+
"type": "module",
31+
"main": "./dist/index.cjs",
32+
"module": "./dist/index.js",
33+
"types": "./dist/index.d.ts",
34+
"exports": {
35+
".": {
36+
"import": {
37+
"types": "./dist/index.d.ts",
38+
"default": "./dist/index.js"
39+
},
40+
"require": {
41+
"types": "./dist/index.d.cts",
42+
"default": "./dist/index.cjs"
43+
}
44+
},
45+
"./package.json": "./package.json"
46+
},
47+
"files": [
48+
"dist",
49+
"LICENSE.md"
50+
],
51+
"scripts": {
52+
"build": "tsup && pnpm check-exports",
53+
"check-exports": "attw --pack .",
54+
"dev": "tsup --watch",
55+
"prepublishOnly": "pnpm build"
56+
},
57+
"peerDependencies": {
58+
"@hey-api/openapi-ts": "< 2"
59+
},
60+
"devDependencies": {
61+
"@hey-api/openapi-ts": "workspace:*",
62+
"typescript": "5.5.3",
63+
"vite": "6.0.9"
64+
}
65+
}

packages/rollup-plugin/src/index.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { createClient, type UserConfig } from '@hey-api/openapi-ts';
2+
3+
export function heyApiPlugin(options?: {
4+
/**
5+
* `@hey-api/openapi-ts` configuration options.
6+
*/
7+
config?: UserConfig;
8+
}) {
9+
return {
10+
buildStart: async () => {
11+
// @ts-expect-error
12+
await createClient(options?.config ?? {});
13+
},
14+
name: 'hey-api-plugin',
15+
};
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"declaration": true,
4+
"esModuleInterop": true,
5+
"module": "ESNext",
6+
"moduleResolution": "Bundler",
7+
"noImplicitOverride": true,
8+
"noUncheckedIndexedAccess": true,
9+
"noUnusedLocals": true,
10+
"strict": true,
11+
"target": "ES2022",
12+
"useUnknownInCatchVariables": false
13+
}
14+
}

packages/rollup-plugin/tsconfig.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"extends": "./tsconfig.base.json",
3+
"compilerOptions": {
4+
"declaration": false,
5+
"esModuleInterop": true,
6+
"resolveJsonModule": true,
7+
"skipLibCheck": true
8+
}
9+
}

packages/rollup-plugin/tsup.config.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { defineConfig } from 'tsup';
2+
3+
export default defineConfig((options) => ({
4+
banner(ctx) {
5+
/**
6+
* fix dynamic require in ESM
7+
* @link https://github.com/hey-api/openapi-ts/issues/1079
8+
*/
9+
if (ctx.format === 'esm') {
10+
return {
11+
js: "import { createRequire } from 'module'; const require = createRequire(import.meta.url);",
12+
};
13+
}
14+
},
15+
clean: true,
16+
dts: true,
17+
entry: ['src/index.ts'],
18+
format: ['cjs', 'esm'],
19+
minify: !options.watch,
20+
shims: false,
21+
sourcemap: true,
22+
treeshake: true,
23+
}));

pnpm-lock.yaml

Lines changed: 14 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)