1
1
import fs from 'node:fs' ;
2
- import { createRequire } from 'node:module' ;
3
2
import path from 'node:path' ;
3
+ import { fileURLToPath } from 'node:url' ;
4
4
5
5
import ts from 'typescript' ;
6
6
@@ -12,11 +12,8 @@ import type { Config } from '../types/config';
12
12
import { splitNameAndExtension } from './file' ;
13
13
import { ensureDirSync , relativeModulePath } from './utils' ;
14
14
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 ) ;
20
17
21
18
const getClientSrcPath = ( name : string ) => {
22
19
const pluginFilePathComponents = name . split ( path . sep ) ;
@@ -161,7 +158,7 @@ export const generateClientBundle = ({
161
158
// copy client core
162
159
const coreOutputPath = path . resolve ( outputPath , 'core' ) ;
163
160
ensureDirSync ( coreOutputPath ) ;
164
- const coreDistPath = path . resolve ( packageRoot , 'dist' , 'clients' , 'core' ) ;
161
+ const coreDistPath = path . resolve ( __dirname , 'clients' , 'core' ) ;
165
162
copyRecursivePnP ( coreDistPath , coreOutputPath ) ;
166
163
167
164
if ( ! legacy ) {
@@ -179,8 +176,7 @@ export const generateClientBundle = ({
179
176
ensureDirSync ( clientOutputPath ) ;
180
177
const clientDistFolderName = plugin . name . slice ( '@hey-api/client-' . length ) ;
181
178
const clientDistPath = path . resolve (
182
- packageRoot ,
183
- 'dist' ,
179
+ __dirname ,
184
180
'clients' ,
185
181
clientDistFolderName ,
186
182
) ;
0 commit comments