Skip to content

Commit

Permalink
pnpm run (#1507)
Browse files Browse the repository at this point in the history
* Use pnpm run, update deps

* Fix styleguide warning

* Require typescript as peerDep

* Fix openapi-fetch dep

* Run build in test jobs

* Exclude docs from CI build

* Fix build
  • Loading branch information
drwpow committed Jan 19, 2024
1 parent 9c68402 commit 799194d
Show file tree
Hide file tree
Showing 15 changed files with 705 additions and 1,047 deletions.
15 changes: 3 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@ concurrency:
cancel-in-progress: true

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: pnpm/action-setup@v2
with:
version: latest
- run: pnpm i
- run: pnpm run build
lint:
runs-on: ubuntu-latest
steps:
Expand All @@ -49,6 +37,7 @@ jobs:
with:
version: latest
- run: pnpm i
- run: pnpm run build
- run: pnpm test
test-macos:
runs-on: macos-latest
Expand All @@ -61,6 +50,7 @@ jobs:
with:
version: latest
- run: pnpm i
- run: pnpm run build
- run: pnpm test
env:
CI_ENV: macos
Expand All @@ -75,6 +65,7 @@ jobs:
with:
version: latest
- run: pnpm i
- run: pnpm run build
- run: pnpm test
env:
CI_ENV: windows
2 changes: 1 addition & 1 deletion docs/data/contributors.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ _Note: OpenAPI 2.x is supported with versions `5.x` and previous_
This library requires the latest version of [Node.js](https://nodejs.org) installed (20.x or higher recommended). With that present, run the following in your project:

```bash
npm i -D openapi-typescript@next
npm i -D openapi-typescript@next typescript
```

::: tip Highly recommended
Expand Down
2 changes: 1 addition & 1 deletion docs/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The Node API may be useful if dealing with dynamically-created schemas, or you
## Setup

```bash
npm i --save-dev openapi-typescript@next
npm i --save-dev openapi-typescript@next typescript
```

::: tip Recommended
Expand Down
2 changes: 1 addition & 1 deletion docs/openapi-fetch/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Install this library along with [openapi-typescript](/introduction):

```bash
npm i openapi-fetch
npm i -D openapi-typescript
npm i -D openapi-typescript typescript
```

::: tip Highly recommended
Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
"update-contributors": "node scripts/update-contributors.js"
},
"devDependencies": {
"vitepress": "1.0.0-rc.35"
"vitepress": "1.0.0-rc.39"
}
}
30 changes: 10 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,24 @@
"email": "drew@pow.rs"
},
"scripts": {
"build": "run-s -s build:*",
"build:openapi-typescript": "cd packages/openapi-typescript && pnpm run build",
"build:openapi-typescript-helpers": "cd packages/openapi-typescript-helpers && pnpm run build",
"build:openapi-fetch": "cd packages/openapi-fetch && pnpm run build",
"lint": "run-p -s lint:*",
"lint:openapi-typescript": "cd packages/openapi-typescript && pnpm run lint",
"lint:openapi-typescript-helpers": "cd packages/openapi-typescript-helpers && pnpm run lint",
"lint:openapi-fetch": "cd packages/openapi-fetch && pnpm run lint",
"test": "pnpm run build && run-p test:*",
"test:openapi-typescript": "cd packages/openapi-typescript && pnpm test",
"test:openapi-typescript-helpers": "cd packages/openapi-typescript-helpers && pnpm test",
"test:openapi-fetch": "cd packages/openapi-fetch && pnpm test",
"build": "pnpm run -r --parallel --filter \"!*docs\" build",
"lint": "pnpm run -r --parallel lint",
"test": "pnpm run -r --parallel test",
"version": "pnpm run build && changeset version && pnpm i"
},
"devDependencies": {
"@changesets/changelog-github": "^0.4.8",
"@changesets/changelog-github": "^0.5.0",
"@changesets/cli": "^2.27.1",
"@typescript-eslint/eslint-plugin": "^6.14.0",
"@typescript-eslint/parser": "^6.14.0",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"@typescript-eslint/parser": "^6.19.0",
"del-cli": "^5.1.0",
"eslint": "^8.55.0",
"eslint": "^8.56.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-prettier": "^5.0.1",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-vitest": "^0.2.8",
"npm-run-all": "^4.1.5",
"prettier": "^3.1.1",
"prettier": "^3.2.4",
"typescript": "^5.3.3"
}
}
1 change: 1 addition & 0 deletions packages/openapi-fetch/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
test/v1.d.ts
test/v1.yaml
test/fixtures/
2 changes: 1 addition & 1 deletion packages/openapi-fetch/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Install this library along with [openapi-typescript](../openapi-typescript):

```bash
npm i openapi-fetch
npm i -D openapi-typescript
npm i -D openapi-typescript typescript
```

> **Highly recommended**: enable [noUncheckedIndexedAccess](https://www.typescriptlang.org/tsconfig#noUncheckedIndexedAccess) in your `tsconfig.json` ([docs](/advanced#enable-nouncheckedindexaccess-in-your-tsconfigjson))
Expand Down
13 changes: 6 additions & 7 deletions packages/openapi-fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@
"build:js": "mkdir -p dist && cp src/* dist",
"build:js-min": "esbuild --bundle src/index.js --format=esm --minify --outfile=dist/index.min.js && cp dist/index.d.ts dist/index.min.d.ts",
"build:cjs": "esbuild --bundle src/index.js --format=cjs --outfile=dist/cjs/index.cjs && cp dist/index.d.ts dist/cjs/index.d.cts",
"lint": "pnpm run lint:js",
"lint": "pnpm run \"/^lint:/\"",
"lint:js": "eslint \"{src,test}/**/*.{js,ts}\"",
"lint:prettier": "prettier --check \"{src,test}/**/*\"",
"generate-types": "cd ../openapi-typescript && pnpm run build && cd ../openapi-fetch ../openapi-typescript/bin/cli.js ./test/fixtures/api.yaml -o ./test/fixtures/v7-beta.test.ts && npx openapi-typescript ./test/fixtures/api.yaml -o ./test/fixtures/api.d.ts",
"pretest": "pnpm run generate-types",
"test": "run-p -s test:*",
"test": "pnpm run \"/^test:/\"",
"test:js": "vitest run",
"test:ts": "tsc --noEmit",
"version": "pnpm run prepare && pnpm run build"
Expand All @@ -66,17 +66,16 @@
"openapi-typescript-helpers": "^0.0.6"
},
"devDependencies": {
"axios": "^1.6.2",
"axios": "^1.6.5",
"del-cli": "^5.1.0",
"esbuild": "^0.19.9",
"esbuild": "^0.19.11",
"nanostores": "^0.9.5",
"npm-run-all": "^4.1.5",
"openapi-typescript": "^6.7.2",
"openapi-typescript": "^6.7.3",
"openapi-typescript-codegen": "^0.25.0",
"openapi-typescript-fetch": "^1.1.3",
"superagent": "^8.1.2",
"typescript": "^5.3.3",
"vitest": "^1.1.0",
"vitest": "^1.2.1",
"vitest-fetch-mock": "^0.2.2"
}
}
21 changes: 10 additions & 11 deletions packages/openapi-fetch/src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,20 @@ export type ParamsOption<T> = T extends {
: { params: T["parameters"] }
: DefaultParamsOption;

export type RequestBodyOption<T> = OperationRequestBodyContent<T> extends never
? { body?: never }
: undefined extends OperationRequestBodyContent<T>
? { body?: OperationRequestBodyContent<T> }
: { body: OperationRequestBodyContent<T> };
export type RequestBodyOption<T> =
OperationRequestBodyContent<T> extends never
? { body?: never }
: undefined extends OperationRequestBodyContent<T>
? { body?: OperationRequestBodyContent<T> }
: { body: OperationRequestBodyContent<T> };

export type FetchOptions<T> = RequestOptions<T> & Omit<RequestInit, "body">;

/** This type helper makes the 2nd function param required if params/requestBody are required; otherwise, optional */
export type MaybeOptionalInit<
P extends {},
M extends keyof P,
> = HasRequiredKeys<FetchOptions<FilterKeys<P, M>>> extends never
? [(FetchOptions<FilterKeys<P, M>> | undefined)?]
: [FetchOptions<FilterKeys<P, M>>];
export type MaybeOptionalInit<P extends {}, M extends keyof P> =
HasRequiredKeys<FetchOptions<FilterKeys<P, M>>> extends never
? [(FetchOptions<FilterKeys<P, M>> | undefined)?]
: [FetchOptions<FilterKeys<P, M>>];

export type FetchResponse<T, O extends FetchOptions> =
| {
Expand Down
8 changes: 5 additions & 3 deletions packages/openapi-typescript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The code is [MIT-licensed](./LICENSE) and free for use.
This library requires the latest version of <a href="https://nodejs.org/en" target="_blank" rel="noopener noreferrer">Node.js</a> installed (20.x or higher recommended). With that present, run the following in your project:

```bash
npm i -D openapi-typescript
npm i -D openapi-typescript typescript
```

> **Tip**
Expand Down Expand Up @@ -57,8 +57,10 @@ type MyType = components["schemas"]["MyType"];
type EndpointParams = paths["/my/endpoint"]["parameters"];

// Response obj
type SuccessResponse = paths["/my/endpoint"]["get"]["responses"][200]["content"]["application/json"]["schema"];
type ErrorResponse = paths["/my/endpoint"]["get"]["responses"][500]["content"]["application/json"]["schema"];
type SuccessResponse =
paths["/my/endpoint"]["get"]["responses"][200]["content"]["application/json"]["schema"];
type ErrorResponse =
paths["/my/endpoint"]["get"]["responses"][500]["content"]["application/json"]["schema"];
```

#### 🦠 Globbing local schemas
Expand Down
21 changes: 12 additions & 9 deletions packages/openapi-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,40 +40,43 @@
"url": "https://github.com/drwpow/openapi-typescript/issues"
},
"scripts": {
"build": "run-s -s build:*",
"build": "pnpm run build:clean && pnpm run build:esm && pnpm run build:cjs",
"build:clean": "del dist",
"build:esm": "tsc -p tsconfig.build.json",
"build:cjs": "esbuild --bundle --platform=node --target=es2019 --outfile=dist/index.cjs --external:@redocly/ajv --external:@redocly/openapi-core --external:typescript src/index.ts",
"dev": "tsc -p tsconfig.build.json --watch",
"download:schemas": "vite-node ./scripts/download-schemas.ts",
"format": "prettier --write \"src/**/*\"",
"lint": "run-p -s lint:*",
"lint": "pnpm run \"/^lint:/\"",
"lint:js": "eslint \"{src,test}/**/*.{js,ts}\"",
"lint:prettier": "prettier --check \"src/**/*\"",
"test": "run-p -s test:*",
"test": "pnpm run \"/^test:/\"",
"test:examples": "tsc -p tsconfig.examples.json --noEmit",
"test:js": "vitest run",
"test:ts": "tsc --noEmit",
"update:examples": "pnpm run build && pnpm run download:schemas && vite-node ./scripts/update-examples.ts",
"prepublish": "pnpm run build",
"version": "pnpm run build"
},
"peerDependencies": {
"typescript": "^5.x"
},
"dependencies": {
"@redocly/openapi-core": "^1.5.0",
"@redocly/openapi-core": "^1.6.0",
"ansi-colors": "^4.1.3",
"supports-color": "^9.4.0",
"typescript": "^5.3.3",
"yargs-parser": "^21.1.1"
},
"devDependencies": {
"@types/degit": "^2.8.6",
"@types/js-yaml": "^4.0.9",
"@types/node": "^20.10.4",
"@types/node": "^20.11.5",
"degit": "^2.8.4",
"del-cli": "^5.1.0",
"esbuild": "^0.19.9",
"esbuild": "^0.19.11",
"execa": "^7.2.0",
"vite-node": "^1.0.4",
"vitest": "^1.1.0"
"typescript": "^5.3.3",
"vite-node": "^1.2.1",
"vitest": "^1.2.1"
}
}
7 changes: 2 additions & 5 deletions packages/openapi-typescript/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,8 @@ export default async function openapiTS(
options.redocly ??
(await createConfig(
{
// @ts-expect-error This is OK
styleguide: {
rules: {
"operation-operationId-unique": { severity: "error" }, // throw error on duplicate operationIDs
},
rules: {
"operation-operationId-unique": { severity: "error" }, // throw error on duplicate operationIDs
},
},
{ extends: ["minimal"] },
Expand Down

0 comments on commit 799194d

Please sign in to comment.