Skip to content

Add Turborepo #2027

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
- main
pull_request:

env:
GITHUB_TOKEN: ${{ secrets.OPENAPI_TS_BOT_GITHUB_TOKEN }}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: this was added because Turborepo adds a “shield” around env vars and doesn’t accidentally expose something sensitive, so you declare what to expose. But the flipside is it throws an error when this isn’t set. I may be missing a configuration setting, but until then, this was simpler.


concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
Expand All @@ -20,7 +23,7 @@ jobs:
node-version: 22
- uses: pnpm/action-setup@v4
with:
version: latest
version: 9.14.4
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Turborepo does require version-locking the package manager, which is the only annoyance I have with it. So this can be bumped any time! But sadly we can’t be as loosey-goosey with it as before.

run_install: true
- run: pnpm run lint
test-node-versions:
Expand All @@ -35,9 +38,8 @@ jobs:
node-version: ${{ matrix.node-version }}
- uses: pnpm/action-setup@v4
with:
version: latest
version: 9.14.4
run_install: true
- run: pnpm run build
- run: pnpm test
test-e2e:
runs-on: ubuntu-latest
Expand All @@ -48,7 +50,7 @@ jobs:
node-version: 22
- uses: pnpm/action-setup@v4
with:
version: latest
version: 9.14.4
run_install: true
- run: pnpm exec playwright install --with-deps
- run: pnpm run test-e2e
Expand All @@ -61,9 +63,8 @@ jobs:
node-version: 22
- uses: pnpm/action-setup@v4
with:
version: latest
version: 9.14.4
run_install: true
- run: pnpm run build
- run: pnpm test
test-windows:
runs-on: windows-latest
Expand All @@ -74,7 +75,6 @@ jobs:
node-version: 22
- uses: pnpm/action-setup@v4
with:
version: latest
version: 9.14.4
run_install: true
- run: pnpm run build
- run: pnpm test
7 changes: 4 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
branches:
- main

env:
GITHUB_TOKEN: ${{ secrets.OPENAPI_TS_BOT_GITHUB_TOKEN }}

jobs:
changelog:
runs-on: ubuntu-latest
Expand All @@ -19,15 +22,13 @@ jobs:
node-version: 22
- uses: pnpm/action-setup@v4
with:
version: latest
version: 9.14.4
run_install: true
- run: pnpm run build
- uses: changesets/action@v1
with:
version: pnpm run version
publish: pnpm exec changeset publish
commit: "[ci] release"
title: "[ci] release"
env:
GITHUB_TOKEN: ${{ secrets.OPENAPI_TS_BOT_GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
6 changes: 5 additions & 1 deletion .github/workflows/size-limit.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
name: "Size Limit"

on:
pull_request:
branches: [main]
types: [opened, synchronize]

env:
GITHUB_TOKEN: ${{ secrets.OPENAPI_TS_BOT_GITHUB_TOKEN }}

jobs:
size-limit:
permissions:
Expand All @@ -17,7 +21,7 @@ jobs:
node-version: 22
- uses: pnpm/action-setup@v4
with:
version: latest
version: 9.14.4
run_install: true
- uses: andresz1/[email protected]
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.turbo
dist
node_modules
coverage
Expand Down
27 changes: 20 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
# Contributing

Contributions are welcome! T
Contributions are welcome!

## Setup

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:
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:

```sh
pnpm i
pnpm run build
```

## Workspace vs local commands

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.

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.

> ![NOTE]
>
> 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.

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.

## Structure

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.

```
┬── docs/ # openapi-ts.dev
┬── docs/
└── packages/
├── openapi-fetch/ # openapi-fetch package
├── openapi-fetch/
├── openapi-react-query/
├── openapi-typescript/
├── openapi-typescript-helpers/
│ # openapi-typescript package
└── openapi-typescript/ # openapi-typescript package
└── swr-openapi/
```
2 changes: 1 addition & 1 deletion docs/data/contributors.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
"scripts": {
"build": "pnpm run update-contributors && vitepress build && cp _redirects .vitepress/dist",
"dev": "pnpm run update-contributors && vitepress dev",
"tokens": "co build",
"update-contributors": "node scripts/update-contributors.js"
},
"devDependencies": {
"vitepress": "1.3.2"
"vitepress": "1.5.0"
}
}
14 changes: 8 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
"name": "Drew Powers",
"email": "[email protected]"
},
"packageManager": "[email protected]",
"scripts": {
"build": "pnpm run -r --filter \"!*docs\" --aggregate-output build",
"lint": "pnpm run -r --parallel --aggregate-output lint",
"build": "turbo run build",
"lint": "turbo run lint",
"dev": "pnpm run -r --parallel --filter \"{packages/*}\" --aggregate-output dev",
"format": "pnpm run -r --parallel --aggregate-output format",
"test": "pnpm run -r --parallel --aggregate-output test",
"test-e2e": "pnpm run -r --parallel --aggregate-output test-e2e",
"size": "pnpm run build && size-limit",
"format": "turbo run format",
"test": "turbo run test",
"test-e2e": "turbo run test-e2e",
"size": "turbo run size-limit",
"version": "pnpm run build && changeset version && pnpm i"
},
"devDependencies": {
Expand All @@ -27,6 +28,7 @@
"del-cli": "^5.1.0",
"prettier": "^3.4.1",
"size-limit": "^11.1.6",
"turbo": "^2.3.3",
"typescript": "^5.7.2",
"vitest": "^2.1.6"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-fetch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"devDependencies": {
"axios": "^1.7.8",
"del-cli": "^5.1.0",
"esbuild": "^0.23.1",
"esbuild": "^0.24.0",
"execa": "^8.0.1",
"feature-fetch": "^0.0.15",
"openapi-typescript": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-metadata/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"@types/node": "^22.10.1",
"@vitest/coverage-v8": "^2.1.6",
"del-cli": "^5.1.0",
"esbuild": "^0.20.2",
"esbuild": "^0.24.0",
"execa": "^8.0.1",
"reflect-metadata": "^0.2.2",
"tsup": "^8.3.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-react-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"@types/react": "18.3.1",
"@vitejs/plugin-react": "^4.3.4",
"del-cli": "^5.1.0",
"esbuild": "^0.20.2",
"esbuild": "^0.24.0",
"execa": "^8.0.1",
"msw": "^2.6.6",
"openapi-fetch": "workspace:^",
Expand Down
2 changes: 1 addition & 1 deletion packages/openapi-typescript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@types/js-yaml": "^4.0.9",
"degit": "^2.8.4",
"del-cli": "^5.1.0",
"esbuild": "^0.20.2",
"esbuild": "^0.24.0",
"execa": "^8.0.1",
"strip-ansi": "^7.1.0",
"typescript": "^5.7.2",
Expand Down
14 changes: 10 additions & 4 deletions packages/openapi-typescript/test/cjs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
const { fileURLToPath } = require("node:url");
const { astToString, default: openapiTS } = require("../dist/index.cjs");

const TIMEOUT = 10_000;

describe("CJS bundle", () => {
it("basic", async () => {
const output = `/**
test(
"basic",
async () => {
const output = `/**
* This file was auto-generated by openapi-typescript.
* Do not make direct changes to the file.
*/

${astToString(await openapiTS(new URL("../examples/stripe-api.yaml", import.meta.url)))}`;
expect(output).toMatchFileSnapshot(fileURLToPath(new URL("../examples/stripe-api.ts", import.meta.url)));
});
expect(output).toMatchFileSnapshot(fileURLToPath(new URL("../examples/stripe-api.ts", import.meta.url)));
},
{ timeout: TIMEOUT },
);
});
34 changes: 22 additions & 12 deletions packages/openapi-typescript/test/yaml.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ import { execa } from "execa";
import os from "node:os";
import { fileURLToPath } from "node:url";

const TIMEOUT = 10_000;

const root = new URL("../", import.meta.url);
const cwd = os.platform() === "win32" ? fileURLToPath(root) : root; // execa bug: fileURLToPath required on Windows
const cmd = "./bin/cli.js";

describe("YAML features", () => {
test("merge", async () => {
const result = await execa(cmd, ["./test/fixtures/yaml-merge.yaml"], {
cwd,
});
expect(result.stdout).toBe(`/**
test(
"merge",
async () => {
const result = await execa(cmd, ["./test/fixtures/yaml-merge.yaml"], {
cwd,
});
expect(result.stdout).toBe(`/**
* This file was auto-generated by openapi-typescript.
* Do not make direct changes to the file.
*/
Expand Down Expand Up @@ -84,13 +88,17 @@ export interface operations {
};
};
}`);
});
},
{ timeout: TIMEOUT },
);

test("not ignore path item components in paths", async () => {
const result = await execa(cmd, ["./test/fixtures/path-item-components.yaml"], {
cwd,
});
expect(result.stdout).toBe(`/**
test(
"not ignore path item components in paths",
async () => {
const result = await execa(cmd, ["./test/fixtures/path-item-components.yaml"], {
cwd,
});
expect(result.stdout).toBe(`/**
* This file was auto-generated by openapi-typescript.
* Do not make direct changes to the file.
*/
Expand Down Expand Up @@ -165,5 +173,7 @@ export interface operations {
};
};
}`);
});
},
{ timeout: TIMEOUT },
);
});
Loading