Skip to content

Commit

Permalink
Merge pull request #1686 from hey-api/ci/turbo
Browse files Browse the repository at this point in the history
ci: add turborepo
  • Loading branch information
mrlubos authored Feb 8, 2025
2 parents 6787e25 + f102df1 commit bb504c5
Show file tree
Hide file tree
Showing 24 changed files with 427 additions and 687 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ jobs:
run: pnpm install

- name: Build packages
run: pnpm --filter './packages/**' run build
run: pnpm build --filter="@hey-api/**"

- name: Build examples
if: matrix.node-version == '22.11.0' && matrix.os == 'ubuntu-latest'
run: pnpm --filter './examples/**' --filter '!./examples/openapi-ts-sample' run build
run: pnpm build --filter="@examples/**"

- name: Run linter
run: pnpm lint
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ coverage
.nuxt
.output
.svelte-kit
.turbo

# test files
test/generated
Expand Down
10 changes: 5 additions & 5 deletions examples/openapi-ts-tanstack-svelte-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,18 @@
"@fontsource/fira-mono": "5.0.0",
"@hey-api/openapi-ts": "workspace:*",
"@neoconfetti/svelte": "2.0.0",
"@sveltejs/adapter-auto": "3.0.0",
"@sveltejs/kit": "2.8.3",
"@sveltejs/vite-plugin-svelte": "3.0.0",
"@sveltejs/adapter-auto": "4.0.0",
"@sveltejs/kit": "2.17.1",
"@sveltejs/vite-plugin-svelte": "5.0.3",
"@types/eslint": "9.6.0",
"eslint": "9.17.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-svelte": "2.36.0",
"globals": "15.14.0",
"prettier": "3.4.2",
"prettier-plugin-svelte": "3.1.2",
"svelte": "4.2.19",
"svelte-check": "3.6.0",
"svelte": "5.19.9",
"svelte-check": "4.1.4",
"typescript": "5.5.3",
"typescript-eslint": "8.19.1",
"vite": "6.0.9",
Expand Down
6 changes: 5 additions & 1 deletion examples/openapi-ts-tanstack-svelte-query/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import { sveltekit } from '@sveltejs/kit/vite';
import { defineConfig } from 'vitest/config';

export default defineConfig({
plugins: [sveltekit()],
// @ts-ignore
plugins: [
// @ts-expect-error
sveltekit(),
],
test: {
include: ['src/**/*.{test,spec}.{js,ts}'],
},
Expand Down
3 changes: 1 addition & 2 deletions examples/openapi-ts-tanstack-vue-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
"openapi-ts": "openapi-ts",
"preview": "vite preview",
"test:unit": "vitest",
"typecheck:old": "vue-tsc --build --force",
"typecheck": "vue-tsc --version"
"typecheck": "vue-tsc --build --force"
},
"dependencies": {
"@hey-api/client-fetch": "workspace:*",
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@
"funding": "https://github.com/sponsors/hey-api",
"type": "module",
"scripts": {
"build": "pnpm --recursive --filter '!./examples/openapi-ts-sample' build",
"build": "turbo run build --filter=\"!@example/openapi-ts-sample\"",
"changeset": "changeset",
"client": "sh ./scripts/client.sh",
"docs": "pnpm --filter @hey-api/docs --",
"example": "sh ./scripts/example.sh",
"format": "prettier --write .",
"lint:fix": "prettier --check --write . && eslint . --fix",
"lint": "prettier --check . && eslint .",
"openapi-ts": "pnpm --filter @hey-api/openapi-ts --",
"openapi-ts": "turbo run $1 --filter=\"@hey-api/openapi-ts\"",
"prepare": "husky",
"test:coverage": "pnpm --recursive test:coverage",
"test:e2e": "pnpm --recursive test:e2e",
"test:update": "pnpm --recursive test:update",
"test": "pnpm --recursive test",
"typecheck": "pnpm --recursive --filter '!./examples/openapi-ts-sample' typecheck"
"test:coverage": "turbo run test:coverage",
"test:e2e": "turbo run test:e2e",
"test:update": "turbo run test:update",
"test": "turbo run test",
"typecheck": "turbo run typecheck --filter=\"!@example/openapi-ts-sample\"",
"vitepress": "turbo run $1 --filter=\"@hey-api/docs\""
},
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=22.11.0"
Expand All @@ -60,6 +60,7 @@
"rollup": "4.31.0",
"rollup-plugin-dts": "6.1.1",
"tsup": "8.3.5",
"turbo": "2.4.0",
"typescript": "5.5.3",
"typescript-eslint": "8.19.1",
"vitest": "1.6.0"
Expand Down
22 changes: 13 additions & 9 deletions packages/openapi-ts/src/createClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ export const createClient = async ({
let context: IR.Context | undefined;

if (data) {
if (_watch) {
console.clear();
console.log(`⏳ Input changed, generating from ${inputPath}`);
} else {
console.log(`⏳ Generating from ${inputPath}`);
if (config.logs.level !== 'silent') {
if (_watch) {
console.clear();
console.log(`⏳ Input changed, generating from ${inputPath}`);
} else {
console.log(`⏳ Generating from ${inputPath}`);
}
}

Performance.start('parser');
Expand Down Expand Up @@ -83,10 +85,12 @@ export const createClient = async ({
if (!config.dryRun) {
processOutput({ config });

const outputPath = process.env.INIT_CWD
? `./${path.relative(process.env.INIT_CWD, config.output.path)}`
: config.output.path;
console.log(`🚀 Done! Your output is in ${outputPath}`);
if (config.logs.level !== 'silent') {
const outputPath = process.env.INIT_CWD
? `./${path.relative(process.env.INIT_CWD, config.output.path)}`
: config.output.path;
console.log(`🚀 Done! Your output is in ${outputPath}`);
}
}
Performance.end('postprocess');
}
Expand Down
1 change: 1 addition & 0 deletions packages/openapi-ts/src/openApi/2.0.x/parser/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ export const parseOperation = ({
securitySchemesMap: Map<string, SecuritySchemeObject>;
}) => {
ensureUniqueOperationId({
context,
id: operation.operationId,
method,
operationIds,
Expand Down
1 change: 1 addition & 0 deletions packages/openapi-ts/src/openApi/3.0.x/parser/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ export const parseOperation = ({
securitySchemesMap: Map<string, SecuritySchemeObject>;
}) => {
ensureUniqueOperationId({
context,
id: operation.operationId,
method,
operationIds,
Expand Down
1 change: 1 addition & 0 deletions packages/openapi-ts/src/openApi/3.1.x/parser/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export const parseOperation = ({
securitySchemesMap: Map<string, SecuritySchemeObject>;
}) => {
ensureUniqueOperationId({
context,
id: operation.operationId,
method,
operationIds,
Expand Down
14 changes: 14 additions & 0 deletions packages/openapi-ts/src/openApi/__tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { afterEach, describe, expect, it, vi } from 'vitest';

import type { Config } from '../../types/config';
import { type OpenApi, parseLegacy, parseOpenApiSpec } from '..';
import type { OpenApiV3_0_X } from '../3.0.x';
import { parseV3_0_X } from '../3.0.x';
Expand All @@ -14,6 +15,19 @@ vi.mock('../3.0.x', () => ({
vi.mock('../3.1.x', () => ({
parseV3_1_X: vi.fn(),
}));
vi.mock('../../utils/config', () => {
const config: Partial<Config> = {
logs: {
level: 'silent',
path: '',
},
pluginOrder: [],
};
return {
getConfig: () => config,
isLegacyClient: vi.fn().mockReturnValue(true),
};
});

describe('parse', () => {
afterEach(() => {
Expand Down
12 changes: 8 additions & 4 deletions packages/openapi-ts/src/openApi/shared/utils/operation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import { sanitizeNamespaceIdentifier } from '../../common/parser/sanitize';
* future, we should add a strict check and throw on duplicate identifiers.
*/
export const ensureUniqueOperationId = ({
context,
id,
method,
operationIds,
path,
}: {
context: IR.Context;
id: string | undefined;
method: IR.OperationObject['method'];
operationIds: Map<string, string>;
Expand All @@ -25,10 +27,12 @@ export const ensureUniqueOperationId = ({
const operationKey = `${method.toUpperCase()} ${path}`;

if (operationIds.has(id)) {
// TODO: parser - support throw on duplicate
console.warn(
`❗️ Duplicate operationId: ${id} in ${operationKey}. Please ensure your operation IDs are unique. This behavior is not supported and will likely lead to unexpected results.`,
);
if (context.config.logs.level !== 'silent') {
// TODO: parser - support throw on duplicate
console.warn(
`❗️ Duplicate operationId: ${id} in ${operationKey}. Please ensure your operation IDs are unique. This behavior is not supported and will likely lead to unexpected results.`,
);
}
} else {
operationIds.set(id, operationKey);
}
Expand Down
12 changes: 8 additions & 4 deletions packages/openapi-ts/src/openApi/v2/parser/getOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const getOperations = ({
const operationIds = new Map<string, string>();
const operations: Operation[] = [];

const config = getConfig();

for (const path in openApi.paths) {
const pathItem = openApi.paths[path]!;
const pathParameters = getOperationParameters({
Expand All @@ -40,17 +42,19 @@ export const getOperations = ({

if (op.operationId) {
if (operationIds.has(op.operationId)) {
console.warn(
`❗️ Duplicate operationId: ${op.operationId} in ${operationKey}. Please ensure your operation IDs are unique. This behavior is not supported and will likely lead to unexpected results.`,
);
if (config.logs.level !== 'silent') {
console.warn(
`❗️ Duplicate operationId: ${op.operationId} in ${operationKey}. Please ensure your operation IDs are unique. This behavior is not supported and will likely lead to unexpected results.`,
);
}
} else {
operationIds.set(op.operationId, operationKey);
}
}

if (
operationFilterFn({
config: getConfig(),
config,
operationKey,
})
) {
Expand Down
12 changes: 8 additions & 4 deletions packages/openapi-ts/src/openApi/v3/parser/getOperations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export const getOperations = ({
const operationIds = new Map<string, string>();
const operations: Operation[] = [];

const config = getConfig();

for (const path in openApi.paths) {
const pathItem = openApi.paths[path]!;
const pathParameters = getOperationParameters({
Expand All @@ -40,17 +42,19 @@ export const getOperations = ({

if (op.operationId) {
if (operationIds.has(op.operationId)) {
console.warn(
`❗️ Duplicate operationId: ${op.operationId} in ${operationKey}. Please ensure your operation IDs are unique. This behavior is not supported and will likely lead to unexpected results.`,
);
if (config.logs.level !== 'silent') {
console.warn(
`❗️ Duplicate operationId: ${op.operationId} in ${operationKey}. Please ensure your operation IDs are unique. This behavior is not supported and will likely lead to unexpected results.`,
);
}
} else {
operationIds.set(op.operationId, operationKey);
}
}

if (
operationFilterFn({
config: getConfig(),
config,
operationKey,
})
) {
Expand Down
3 changes: 3 additions & 0 deletions packages/openapi-ts/test/2.0.x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ describe(`OpenAPI ${version}`, () => {
version,
typeof userConfig.input === 'string' ? userConfig.input : '',
),
logs: {
level: 'silent',
},
output: path.join(
outputDir,
typeof userConfig.output === 'string' ? userConfig.output : '',
Expand Down
3 changes: 3 additions & 0 deletions packages/openapi-ts/test/3.0.x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ describe(`OpenAPI ${version}`, () => {
version,
typeof userConfig.input === 'string' ? userConfig.input : '',
),
logs: {
level: 'silent',
},
output: path.join(
outputDir,
typeof userConfig.output === 'string' ? userConfig.output : '',
Expand Down
3 changes: 3 additions & 0 deletions packages/openapi-ts/test/3.1.x.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ describe(`OpenAPI ${version}`, () => {
version,
typeof userConfig.input === 'string' ? userConfig.input : '',
),
logs: {
level: 'silent',
},
output: path.join(
outputDir,
typeof userConfig.output === 'string' ? userConfig.output : '',
Expand Down
Loading

0 comments on commit bb504c5

Please sign in to comment.