Skip to content

Commit

Permalink
feat: split runtime from codegen package
Browse files Browse the repository at this point in the history
in order to allow for more efficient package handling

- remove husky and lint-staged in favor of linting in ci
  in order to reduce tooling packages required
- switch package to type=module
- switch to vite
  in order to provide cjs and mjs entries
- switch to vitest
  less config, less packages, faster
- introduce packages/ folder
  #monorepostyle

BREAKING CHANGE:

package has been split and imports have been cleaned up

old                        | new
---------------------------|--------------------------
oazapfts/runtime           | @oazapfts/runtime
oazapfts/lib/runtime       | @oazapfts/runtime
oazapfts/runtime/query     | @oazapfts/runtime/query
oazapfts/lib/runtime/query | @oazapfts/runtime/query
 - new -                   | @oazapfts/runtime/headers
 - new -                   | @oazapfts/runtime/util
oazapfts/codegen           | oazapfts
oazapfts/lib/codegen       | oazapfts

non-generated code using oazapfts types and imports
will most likely need to be migrated

generated clients should now have @oazapfts/runtime as
dependency instead of oazapfts

`handle`, `ok`, `okify` and `optimistic` runtime helpers have been moved to `@oazapfts/runtime`
along with other exports that mainly have been used internally.
When you miss something from `oazapfts` package, try importing it from `@oazapfts/runtime`

ref #568
fix #401
  • Loading branch information
Xiphe committed Feb 13, 2024
1 parent 6f44487 commit eb4cca4
Show file tree
Hide file tree
Showing 63 changed files with 3,943 additions and 8,342 deletions.
20 changes: 18 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: CI
on:
push:
branches: [main]
branches: [main, alpha, beta]
pull_request:
branches: [main]
jobs:
Expand All @@ -14,8 +14,24 @@ jobs:
node-version: 20
check-latest: true
- run: npm ci
- run: npx prettier -c .
- run: npm test
- run: npx semantic-release
- run: |
set -e # Exit immediately if a command exits with a non-zero status.
cd packages/runtime
npm install semantic-release-monorepo --no-save
npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- run: |
set -e # Exit immediately if a command exits with a non-zero status.
cp README.md packages/codegen/README.md
cd packages/codegen
npm install semantic-release-monorepo --no-save
npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
lib/
packages/codegen/dist/
packages/runtime/dist/
node_modules/
.idea/
.vscode/
4 changes: 0 additions & 4 deletions .husky/pre-commit

This file was deleted.

1 change: 0 additions & 1 deletion .npmignore

This file was deleted.

2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18
20
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ npm install oazapfts
```

> **Note**
> With version 3.0.0 oazapfts has become a runtime dependency and the generated code does no longer include all the fetch logic.
> With version 3.0.0 oazapfts has become a runtime dependency and the generated code does no longer include all the fetch logic.
> As with 6.0.0 the runtime has been moved to a separate package, `@oazapfts/runtime`.
## Usage

Expand Down Expand Up @@ -145,7 +146,7 @@ if (res.status === 404) {
The above code can be simplified by using the `handle` helper:

```ts
import { handle } from "oazapfts";
import { handle } from "@oazapfts/runtime";

await handle(api.getPetById(1), {
200(pet) {
Expand Down Expand Up @@ -192,7 +193,7 @@ Sometimes you might want to use the optimistic mode for some of your API calls,
In that case, you can use the `ok`-helper function to selectively apply optimistic response handling:

```ts
import { ok } from "oazapfts";
import { ok } from "@oazapfts/runtime";

const pet = await ok(api.getPetById(1));
```
Expand Down
5 changes: 3 additions & 2 deletions demo/api.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { handle, ok, okify, optimistic } from "oazapfts/lib/index";
import { describe, it, expect, vi } from "vitest";
import { handle, ok, okify, optimistic } from "@oazapfts/runtime";
import * as api from "./api";
import * as optimisticApi from "./optimisticApi";
import * as enumApi from "./enumApi";
Expand Down Expand Up @@ -338,7 +339,7 @@ describe("--optimistic", () => {
describe("multipart", () => {
it("is able to upload multiple files along with complex data", async () => {
/* Test was flaky when hitting the mock server, so we're mocking the fetch */
const customFetch = jest.fn((url, init) => {
const customFetch = vi.fn((url, init) => {
return {
headers: new Headers({
"content-type": "application/json",
Expand Down
4 changes: 2 additions & 2 deletions demo/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* DO NOT MODIFY - This file has been generated using oazapfts.
* See https://www.npmjs.com/package/oazapfts
*/
import * as Oazapfts from "oazapfts/lib/runtime";
import * as QS from "oazapfts/lib/runtime/query";
import * as Oazapfts from "@oazapfts/runtime";
import * as QS from "@oazapfts/runtime/query";
export const defaults: Oazapfts.Defaults<Oazapfts.CustomHeaders> = {
headers: {},
baseUrl: "https://petstore.swagger.io/v2",
Expand Down
4 changes: 2 additions & 2 deletions demo/enumApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* DO NOT MODIFY - This file has been generated using oazapfts.
* See https://www.npmjs.com/package/oazapfts
*/
import * as Oazapfts from "oazapfts/lib/runtime";
import * as QS from "oazapfts/lib/runtime/query";
import * as Oazapfts from "@oazapfts/runtime";
import * as QS from "@oazapfts/runtime/query";
export const defaults: Oazapfts.Defaults<Oazapfts.CustomHeaders> = {
headers: {},
baseUrl: "https://petstore.swagger.io/v2",
Expand Down
4 changes: 2 additions & 2 deletions demo/mergedReadWriteApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* DO NOT MODIFY - This file has been generated using oazapfts.
* See https://www.npmjs.com/package/oazapfts
*/
import * as Oazapfts from "oazapfts/lib/runtime";
import * as QS from "oazapfts/lib/runtime/query";
import * as Oazapfts from "@oazapfts/runtime";
import * as QS from "@oazapfts/runtime/query";
export const defaults: Oazapfts.Defaults<Oazapfts.CustomHeaders> = {
headers: {},
baseUrl: "https://petstore.swagger.io/v2",
Expand Down
4 changes: 2 additions & 2 deletions demo/objectStyleArgument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* DO NOT MODIFY - This file has been generated using oazapfts.
* See https://www.npmjs.com/package/oazapfts
*/
import * as Oazapfts from "oazapfts/lib/runtime";
import * as QS from "oazapfts/lib/runtime/query";
import * as Oazapfts from "@oazapfts/runtime";
import * as QS from "@oazapfts/runtime/query";
export const defaults: Oazapfts.Defaults<Oazapfts.CustomHeaders> = {
headers: {},
baseUrl: "https://petstore.swagger.io/v2",
Expand Down
4 changes: 2 additions & 2 deletions demo/optimisticApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* DO NOT MODIFY - This file has been generated using oazapfts.
* See https://www.npmjs.com/package/oazapfts
*/
import * as Oazapfts from "oazapfts/lib/runtime";
import * as QS from "oazapfts/lib/runtime/query";
import * as Oazapfts from "@oazapfts/runtime";
import * as QS from "@oazapfts/runtime/query";
export const defaults: Oazapfts.Defaults<Oazapfts.CustomHeaders> = {
headers: {},
baseUrl: "https://petstore.swagger.io/v2",
Expand Down
16 changes: 3 additions & 13 deletions demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
{
"extends": "../tsconfig.base.json",
"compilerOptions": {
"target": "esnext",
"sourceMap": true,
"declaration": true,
"lib": ["es2015", "dom"],
"module": "commonjs",
"strict": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"noUnusedLocals": false,
"baseUrl": ".",
"paths": {
"oazapfts/lib/*": ["../lib/*"]
"@oazapfts/runtime": ["../packages/runtime/dist"],
"@oazapfts/runtime/*": ["../packages/runtime/dist/*"]
}
}
}
9 changes: 0 additions & 9 deletions jest.config.ts

This file was deleted.

Loading

0 comments on commit eb4cca4

Please sign in to comment.