Skip to content

Commit 75399f8

Browse files
authored
Add Turborepo (#2027)
* Add Turborepo * Increase timeout for Windows
1 parent 86b7125 commit 75399f8

File tree

16 files changed

+587
-811
lines changed

16 files changed

+587
-811
lines changed

.github/workflows/ci.yml

+8-8
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
- main
77
pull_request:
88

9+
env:
10+
GITHUB_TOKEN: ${{ secrets.OPENAPI_TS_BOT_GITHUB_TOKEN }}
11+
912
concurrency:
1013
group: ci-${{ github.ref }}
1114
cancel-in-progress: true
@@ -20,7 +23,7 @@ jobs:
2023
node-version: 22
2124
- uses: pnpm/action-setup@v4
2225
with:
23-
version: latest
26+
version: 9.14.4
2427
run_install: true
2528
- run: pnpm run lint
2629
test-node-versions:
@@ -35,9 +38,8 @@ jobs:
3538
node-version: ${{ matrix.node-version }}
3639
- uses: pnpm/action-setup@v4
3740
with:
38-
version: latest
41+
version: 9.14.4
3942
run_install: true
40-
- run: pnpm run build
4143
- run: pnpm test
4244
test-e2e:
4345
runs-on: ubuntu-latest
@@ -48,7 +50,7 @@ jobs:
4850
node-version: 22
4951
- uses: pnpm/action-setup@v4
5052
with:
51-
version: latest
53+
version: 9.14.4
5254
run_install: true
5355
- run: pnpm exec playwright install --with-deps
5456
- run: pnpm run test-e2e
@@ -61,9 +63,8 @@ jobs:
6163
node-version: 22
6264
- uses: pnpm/action-setup@v4
6365
with:
64-
version: latest
66+
version: 9.14.4
6567
run_install: true
66-
- run: pnpm run build
6768
- run: pnpm test
6869
test-windows:
6970
runs-on: windows-latest
@@ -74,7 +75,6 @@ jobs:
7475
node-version: 22
7576
- uses: pnpm/action-setup@v4
7677
with:
77-
version: latest
78+
version: 9.14.4
7879
run_install: true
79-
- run: pnpm run build
8080
- run: pnpm test

.github/workflows/release.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on:
55
branches:
66
- main
77

8+
env:
9+
GITHUB_TOKEN: ${{ secrets.OPENAPI_TS_BOT_GITHUB_TOKEN }}
10+
811
jobs:
912
changelog:
1013
runs-on: ubuntu-latest
@@ -19,15 +22,13 @@ jobs:
1922
node-version: 22
2023
- uses: pnpm/action-setup@v4
2124
with:
22-
version: latest
25+
version: 9.14.4
2326
run_install: true
24-
- run: pnpm run build
2527
- uses: changesets/action@v1
2628
with:
2729
version: pnpm run version
2830
publish: pnpm exec changeset publish
2931
commit: "[ci] release"
3032
title: "[ci] release"
3133
env:
32-
GITHUB_TOKEN: ${{ secrets.OPENAPI_TS_BOT_GITHUB_TOKEN }}
3334
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/size-limit.yml

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
name: "Size Limit"
2+
23
on:
34
pull_request:
45
branches: [main]
56
types: [opened, synchronize]
67

8+
env:
9+
GITHUB_TOKEN: ${{ secrets.OPENAPI_TS_BOT_GITHUB_TOKEN }}
10+
711
jobs:
812
size-limit:
913
permissions:
@@ -17,7 +21,7 @@ jobs:
1721
node-version: 22
1822
- uses: pnpm/action-setup@v4
1923
with:
20-
version: latest
24+
version: 9.14.4
2125
run_install: true
2226
- uses: andresz1/[email protected]
2327
with:

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.DS_Store
2+
.turbo
23
dist
34
node_modules
45
coverage

CONTRIBUTING.md

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,38 @@
11
# Contributing
22

3-
Contributions are welcome! T
3+
Contributions are welcome!
44

55
## Setup
66

7-
This monorepo uses [pnpm workspaces](https://pnpm.io/) that lets packages pull from local versions rather than remote. After installing pnpm, running this command from the root will set everything up:
7+
This monorepo uses [pnpm workspaces](https://pnpm.io/) that lets packages pull from local versions rather than remote. It also uses [Turborepo](https://turbo.build/repo/docs) to run commands more easily. After installing pnpm, running the following commands from the root will set everything up:
88

99
```sh
1010
pnpm i
11+
pnpm run build
1112
```
1213

14+
## Workspace vs local commands
15+
16+
The “workspace“ is the root `package.json`. Running commands here will run on all packages. For example, running `pnpm run build` in the workspace root will build all packages. But running `cd packages/openapi-typescript && pnpm run build` will only build that one package.
17+
18+
It’s worth noting that some packages depend on others in the monorepo. For example, `openapi-fetch` depends on `openapi-typescript` building built. `openapi-react-query` relies on `openapi-fetch` which relies on `openapi-typescript`. If running commands per-package, you’d have to manually build each package before the test suite could run. But running `pnpm run build` in the workspace root once will build all packages for you, so that you can run any test suite.
19+
20+
> ![NOTE]
21+
>
22+
> Note that if any package changes, be sure to rebuild before running tests! Of course, CI will always do this, but in case you see differences between local vs CI, this is usually the culprit—a stale build.
23+
24+
Again, Turborepo is there so that you don’t have to think about all the packages as much, if you’re just contributing to one. But these tips may help you troubleshoot if something unexpected happens.
25+
1326
## Structure
1427

1528
This monorepo has 2 main sections: the `docs/` that deploy to `openapi-ts.dev`, and `packages/` which are all the npm packages. Each npm package has its own `CONTRIBUTING.md` doc that describes setup needed for that package.
1629

1730
```
18-
┬── docs/ # openapi-ts.dev
19-
31+
┬── docs/
2032
└── packages/
21-
├── openapi-fetch/ # openapi-fetch package
33+
├── openapi-fetch/
34+
├── openapi-react-query/
35+
├── openapi-typescript/
2236
├── openapi-typescript-helpers/
23-
│ # openapi-typescript package
24-
└── openapi-typescript/ # openapi-typescript package
37+
└── swr-openapi/
2538
```

docs/data/contributors.json

+1-1
Large diffs are not rendered by default.

docs/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
"scripts": {
77
"build": "pnpm run update-contributors && vitepress build && cp _redirects .vitepress/dist",
88
"dev": "pnpm run update-contributors && vitepress dev",
9-
"tokens": "co build",
109
"update-contributors": "node scripts/update-contributors.js"
1110
},
1211
"devDependencies": {
13-
"vitepress": "1.3.2"
12+
"vitepress": "1.5.0"
1413
}
1514
}

package.json

+8-6
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@
77
"name": "Drew Powers",
88
"email": "[email protected]"
99
},
10+
"packageManager": "[email protected]",
1011
"scripts": {
11-
"build": "pnpm run -r --filter \"!*docs\" --aggregate-output build",
12-
"lint": "pnpm run -r --parallel --aggregate-output lint",
12+
"build": "turbo run build",
13+
"lint": "turbo run lint",
1314
"dev": "pnpm run -r --parallel --filter \"{packages/*}\" --aggregate-output dev",
14-
"format": "pnpm run -r --parallel --aggregate-output format",
15-
"test": "pnpm run -r --parallel --aggregate-output test",
16-
"test-e2e": "pnpm run -r --parallel --aggregate-output test-e2e",
17-
"size": "pnpm run build && size-limit",
15+
"format": "turbo run format",
16+
"test": "turbo run test",
17+
"test-e2e": "turbo run test-e2e",
18+
"size": "turbo run size-limit",
1819
"version": "pnpm run build && changeset version && pnpm i"
1920
},
2021
"devDependencies": {
@@ -27,6 +28,7 @@
2728
"del-cli": "^5.1.0",
2829
"prettier": "^3.4.1",
2930
"size-limit": "^11.1.6",
31+
"turbo": "^2.3.3",
3032
"typescript": "^5.7.2",
3133
"vitest": "^2.1.6"
3234
},

packages/openapi-fetch/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"devDependencies": {
7373
"axios": "^1.7.8",
7474
"del-cli": "^5.1.0",
75-
"esbuild": "^0.23.1",
75+
"esbuild": "^0.24.0",
7676
"execa": "^8.0.1",
7777
"feature-fetch": "^0.0.15",
7878
"openapi-typescript": "workspace:^",

packages/openapi-metadata/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"@types/node": "^22.10.1",
7171
"@vitest/coverage-v8": "^2.1.6",
7272
"del-cli": "^5.1.0",
73-
"esbuild": "^0.20.2",
73+
"esbuild": "^0.24.0",
7474
"execa": "^8.0.1",
7575
"reflect-metadata": "^0.2.2",
7676
"tsup": "^8.3.5",

packages/openapi-react-query/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"@types/react": "18.3.1",
7171
"@vitejs/plugin-react": "^4.3.4",
7272
"del-cli": "^5.1.0",
73-
"esbuild": "^0.20.2",
73+
"esbuild": "^0.24.0",
7474
"execa": "^8.0.1",
7575
"msw": "^2.6.6",
7676
"openapi-fetch": "workspace:^",

packages/openapi-typescript/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@
7272
"@types/js-yaml": "^4.0.9",
7373
"degit": "^2.8.4",
7474
"del-cli": "^5.1.0",
75-
"esbuild": "^0.20.2",
75+
"esbuild": "^0.24.0",
7676
"execa": "^8.0.1",
7777
"strip-ansi": "^7.1.0",
7878
"typescript": "^5.7.2",

packages/openapi-typescript/test/cjs.test.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,20 @@
22
const { fileURLToPath } = require("node:url");
33
const { astToString, default: openapiTS } = require("../dist/index.cjs");
44

5+
const TIMEOUT = 10_000;
6+
57
describe("CJS bundle", () => {
6-
it("basic", async () => {
7-
const output = `/**
8+
test(
9+
"basic",
10+
async () => {
11+
const output = `/**
812
* This file was auto-generated by openapi-typescript.
913
* Do not make direct changes to the file.
1014
*/
1115
1216
${astToString(await openapiTS(new URL("../examples/stripe-api.yaml", import.meta.url)))}`;
13-
expect(output).toMatchFileSnapshot(fileURLToPath(new URL("../examples/stripe-api.ts", import.meta.url)));
14-
});
17+
expect(output).toMatchFileSnapshot(fileURLToPath(new URL("../examples/stripe-api.ts", import.meta.url)));
18+
},
19+
{ timeout: TIMEOUT },
20+
);
1521
});

packages/openapi-typescript/test/yaml.test.ts

+22-12
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@ import { execa } from "execa";
22
import os from "node:os";
33
import { fileURLToPath } from "node:url";
44

5+
const TIMEOUT = 10_000;
6+
57
const root = new URL("../", import.meta.url);
68
const cwd = os.platform() === "win32" ? fileURLToPath(root) : root; // execa bug: fileURLToPath required on Windows
79
const cmd = "./bin/cli.js";
810

911
describe("YAML features", () => {
10-
test("merge", async () => {
11-
const result = await execa(cmd, ["./test/fixtures/yaml-merge.yaml"], {
12-
cwd,
13-
});
14-
expect(result.stdout).toBe(`/**
12+
test(
13+
"merge",
14+
async () => {
15+
const result = await execa(cmd, ["./test/fixtures/yaml-merge.yaml"], {
16+
cwd,
17+
});
18+
expect(result.stdout).toBe(`/**
1519
* This file was auto-generated by openapi-typescript.
1620
* Do not make direct changes to the file.
1721
*/
@@ -84,13 +88,17 @@ export interface operations {
8488
};
8589
};
8690
}`);
87-
});
91+
},
92+
{ timeout: TIMEOUT },
93+
);
8894

89-
test("not ignore path item components in paths", async () => {
90-
const result = await execa(cmd, ["./test/fixtures/path-item-components.yaml"], {
91-
cwd,
92-
});
93-
expect(result.stdout).toBe(`/**
95+
test(
96+
"not ignore path item components in paths",
97+
async () => {
98+
const result = await execa(cmd, ["./test/fixtures/path-item-components.yaml"], {
99+
cwd,
100+
});
101+
expect(result.stdout).toBe(`/**
94102
* This file was auto-generated by openapi-typescript.
95103
* Do not make direct changes to the file.
96104
*/
@@ -165,5 +173,7 @@ export interface operations {
165173
};
166174
};
167175
}`);
168-
});
176+
},
177+
{ timeout: TIMEOUT },
178+
);
169179
});

0 commit comments

Comments
 (0)