@alt-stack/zod-openapi 1.0.1 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/zod-openapi.js +40 -4
  2. package/package.json +1 -1
@@ -3,16 +3,52 @@ import { fileURLToPath } from 'url';
3
3
  import { dirname, join } from 'path';
4
4
  import { createRequire } from 'module';
5
5
  import { spawn } from 'child_process';
6
+ import { accessSync, constants } from 'fs';
6
7
 
7
8
  const require = createRequire(import.meta.url);
8
9
  const __dirname = dirname(fileURLToPath(import.meta.url));
9
-
10
- // Resolve tsx and CLI paths
11
- const tsxPath = require.resolve('tsx/cli.mjs');
12
10
  const cliPath = join(__dirname, '../src/cli.ts');
13
11
 
12
+ // Resolve tsx binary from node_modules
13
+ let tsxBinary;
14
+ try {
15
+ const tsxPackagePath = require.resolve('tsx/package.json');
16
+ const tsxPackageDir = dirname(tsxPackagePath);
17
+ // Look for .bin/tsx relative to node_modules
18
+ // In pnpm, it might be in a different location, so trace back to find node_modules
19
+ let currentDir = tsxPackageDir;
20
+ let dotBinPath;
21
+ while (currentDir !== dirname(currentDir)) {
22
+ dotBinPath = join(currentDir, '.bin/tsx');
23
+ try {
24
+ accessSync(dotBinPath, constants.F_OK);
25
+ tsxBinary = dotBinPath;
26
+ break;
27
+ } catch {
28
+ currentDir = dirname(currentDir);
29
+ }
30
+ }
31
+ // If not found, try bin/tsx in the package directory
32
+ if (!tsxBinary) {
33
+ const binPath = join(tsxPackageDir, 'bin/tsx');
34
+ try {
35
+ accessSync(binPath, constants.F_OK);
36
+ tsxBinary = binPath;
37
+ } catch {
38
+ tsxBinary = 'npx';
39
+ }
40
+ }
41
+ } catch {
42
+ // Fallback to npx if tsx is not found
43
+ tsxBinary = 'npx';
44
+ }
45
+
14
46
  // Spawn tsx to run the CLI
15
- const child = spawn('node', [tsxPath, cliPath, ...process.argv.slice(2)], {
47
+ const args = tsxBinary === 'npx'
48
+ ? ['tsx', cliPath, ...process.argv.slice(2)]
49
+ : [cliPath, ...process.argv.slice(2)];
50
+
51
+ const child = spawn(tsxBinary, args, {
16
52
  stdio: 'inherit',
17
53
  cwd: process.cwd(),
18
54
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alt-stack/zod-openapi",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Convert OpenAPI schemas to Zod schemas with TypeScript code generation",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",