fork of hey-api/openapi-ts because I need some additional things
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: update client import paths

Lubos 763240d8 f2c428fc

+19 -27
+19 -24
packages/openapi-python/src/generate/client.ts
··· 2 2 import path from 'node:path'; 3 3 import { fileURLToPath } from 'node:url'; 4 4 5 - import type { IProject, ProjectRenderMeta } from '@hey-api/codegen-core'; 5 + import type { IProject } from '@hey-api/codegen-core'; 6 6 import type { DefinePlugin, OutputHeader } from '@hey-api/shared'; 7 7 import { ensureDirSync, outputHeaderToPrefix } from '@hey-api/shared'; 8 8 ··· 108 108 filePath, 109 109 header, 110 110 isDevMode, 111 - meta, 112 111 renamed, 113 112 }: { 114 113 filePath: string; 115 114 header?: string; 116 115 isDevMode?: boolean; 117 - meta: ProjectRenderMeta; 118 116 renamed: Map<string, string>; 119 117 }): void { 120 118 let content = fs.readFileSync(filePath, 'utf8'); 121 119 122 120 // Dev mode: rewrite source bundle imports to match output structure 123 121 if (isDevMode) { 124 - // ../../client-core/bundle/foo -> ../core/foo 125 - content = content.replace(/from\s+['"]\.\.\/\.\.\/client-core\/bundle\//g, "from '../core/"); 126 - // ../../client-core/bundle' (index import) 127 - content = content.replace(/from\s+['"]\.\.\/\.\.\/client-core\/bundle['"]/g, "from '../core'"); 122 + // ...client_core.bundle.foo -> ..core.foo 123 + content = content.replace( 124 + /from\s+(\.{3,})\.?client_core\.bundle\./g, 125 + (match, dots) => `from ${dots === '...' ? '..' : dots.slice(0, -1)}core.`, 126 + ); 127 + // ...client_core.bundle (index import) -> ..core 128 + content = content.replace( 129 + /from\s+(\.{3,})\.?client_core\.bundle['"]?/g, 130 + (match, dots) => `from ${dots === '...' ? '..' : dots.slice(0, -1)}core`, 131 + ); 128 132 } 129 133 130 - content = content.replace(/from\s+['"](\.\.?\/[^'"]*?)['"]/g, (match, importPath) => { 131 - const importIndex = match.indexOf(importPath); 132 - const extension = path.extname(importPath); 133 - const fileName = path.basename(importPath, extension); 134 - const importDir = path.dirname(importPath); 135 - const replacedName = 136 - (renamed.get(fileName) ?? fileName) + 137 - (meta.importFileExtension ? meta.importFileExtension : extension); 138 - const replacedMatch = 139 - match.slice(0, importIndex) + 140 - [importDir, replacedName].filter(Boolean).join('/') + 141 - match.slice(importIndex + importPath.length); 142 - return replacedMatch; 134 + content = content.replace(/from\s+(.+?)\s+import/g, (match, importPath) => { 135 + const cleanPath = importPath.replace(/^['"]|['"]$/g, ''); 136 + if (!cleanPath.startsWith('.')) return match; 137 + const leadingDots = cleanPath.match(/^\.+/)?.[0] || ''; 138 + const moduleName = cleanPath.replace(/^\.+/, ''); 139 + if (!moduleName) return match; 140 + const replacedName = renamed.get(moduleName) ?? moduleName; 141 + return `from ${leadingDots}${replacedName} import`; 143 142 }); 144 143 145 144 const fileHeader = header ?? ''; ··· 154 153 */ 155 154 export function generateClientBundle({ 156 155 header, 157 - meta, 158 156 outputPath, 159 157 plugin, 160 158 project, 161 159 }: { 162 160 header?: OutputHeader; 163 - meta: ProjectRenderMeta; 164 161 outputPath: string; 165 162 plugin: DefinePlugin<Client.Config & { name: string }>['Config']; 166 163 project: IProject; ··· 210 207 // replaceImports({ 211 208 // filePath: path.resolve(coreOutputPath, file), 212 209 // isDevMode: devMode, 213 - // meta, 214 210 // renamed, 215 211 // }); 216 212 // } ··· 221 217 filePath: path.resolve(clientOutputPath, file), 222 218 header: headerPrefix, 223 219 isDevMode: devMode, 224 - meta, 225 220 renamed, 226 221 }); 227 222 }
-3
packages/openapi-python/src/generate/output.ts
··· 25 25 // @ts-expect-error 26 26 config._FRAGILE_CLIENT_BUNDLE_RENAMED = generateClientBundle({ 27 27 header: config.output.header, 28 - meta: { 29 - importFileExtension: config.output.importFileExtension, 30 - }, 31 28 outputPath, 32 29 // @ts-expect-error 33 30 plugin: client,