Skip to content
Draft
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
31 changes: 29 additions & 2 deletions packages/openapi-ts/src/plugins/@hey-api/client-core/client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import path from 'node:path';

import { parseUrl } from '@hey-api/shared';

import { getTypedConfig } from '../../../config/utils';
Expand Down Expand Up @@ -41,9 +43,34 @@ export const createClient: PluginHandler = ({ plugin }) => {
});

const { runtimeConfigPath } = plugin.config;
const symbolCreateClientConfig = runtimeConfigPath
let resolvedRuntimeConfigPath: string | undefined;
if (runtimeConfigPath) {
const config = getTypedConfig(plugin);
const outputPath = config.output.path;

// Path resolution strategy:
// - Paths starting with './' or absolute paths are assumed to be relative to CWD (project root)
// and need to be resolved to be relative to the output directory
// - Paths starting with '../' or without './' prefix are assumed to be already relative
// to the output directory and are used as-is
if (runtimeConfigPath.startsWith('./') || path.isAbsolute(runtimeConfigPath)) {
// Resolve the runtimeConfigPath from the current working directory
const absoluteRuntimeConfigPath = path.resolve(runtimeConfigPath);
// Calculate the relative path from the output directory to the runtime config file
resolvedRuntimeConfigPath = path.relative(outputPath, absoluteRuntimeConfigPath);
// Ensure the path uses forward slashes and starts with ./ or ../
resolvedRuntimeConfigPath = resolvedRuntimeConfigPath.split(path.sep).join('/');
if (!resolvedRuntimeConfigPath.startsWith('.')) {
resolvedRuntimeConfigPath = `./${resolvedRuntimeConfigPath}`;
}
} else {
// Path is already relative to output (e.g., '../hey-api' or 'my-config'), use it as-is
resolvedRuntimeConfigPath = runtimeConfigPath;
}
}
const symbolCreateClientConfig = resolvedRuntimeConfigPath
? plugin.symbol('createClientConfig', {
external: runtimeConfigPath,
external: resolvedRuntimeConfigPath,
})
: undefined;

Expand Down