11import fs from 'node:fs' ;
2- import { createRequire } from 'node:module' ;
32import path from 'node:path' ;
3+ import { fileURLToPath } from 'node:url' ;
44
55import ts from 'typescript' ;
66
@@ -12,11 +12,8 @@ import type { Config } from '../types/config';
1212import { splitNameAndExtension } from './file' ;
1313import { ensureDirSync , relativeModulePath } from './utils' ;
1414
15- // Use require.resolve to find the package root, then construct the path
16- // This approach works with Yarn PnP and doesn't rely on specific file exports
17- const packageRoot = path . dirname (
18- createRequire ( import . meta. url ) . resolve ( '@hey-api/openapi-ts/package.json' ) ,
19- ) ;
15+ const __filename = fileURLToPath ( import . meta. url ) ;
16+ const __dirname = path . dirname ( __filename ) ;
2017
2118const getClientSrcPath = ( name : string ) => {
2219 const pluginFilePathComponents = name . split ( path . sep ) ;
@@ -161,7 +158,7 @@ export const generateClientBundle = ({
161158 // copy client core
162159 const coreOutputPath = path . resolve ( outputPath , 'core' ) ;
163160 ensureDirSync ( coreOutputPath ) ;
164- const coreDistPath = path . resolve ( packageRoot , 'dist' , 'clients' , 'core' ) ;
161+ const coreDistPath = path . resolve ( __dirname , 'clients' , 'core' ) ;
165162 copyRecursivePnP ( coreDistPath , coreOutputPath ) ;
166163
167164 if ( ! legacy ) {
@@ -179,8 +176,7 @@ export const generateClientBundle = ({
179176 ensureDirSync ( clientOutputPath ) ;
180177 const clientDistFolderName = plugin . name . slice ( '@hey-api/client-' . length ) ;
181178 const clientDistPath = path . resolve (
182- packageRoot ,
183- 'dist' ,
179+ __dirname ,
184180 'clients' ,
185181 clientDistFolderName ,
186182 ) ;
0 commit comments