Skip to content

Commit 739a18d

Browse files
authored
Merge pull request #2415 from hey-api/fix/cjs-build
fix: cjs build
2 parents f55a54b + dcc5c4d commit 739a18d

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

packages/openapi-ts/src/generate/client.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from 'node:fs';
2-
import { createRequire } from 'node:module';
32
import path from 'node:path';
3+
import { fileURLToPath } from 'node:url';
44

55
import ts from 'typescript';
66

@@ -12,11 +12,8 @@ import type { Config } from '../types/config';
1212
import { splitNameAndExtension } from './file';
1313
import { 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

2118
const 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

Comments
 (0)