Skip to content

Commit 7cf2bab

Browse files
committed
fix: fix invalid path to node with sh execution
1 parent d8b8339 commit 7cf2bab

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

api/src/cli.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#!/usr/bin/env node
2-
31
import '@app/dotenv.js';
42

53
import { execa } from 'execa';

api/src/environment.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,31 @@
11
import { readFileSync } from 'node:fs';
22
import { homedir } from 'node:os';
3-
import { dirname, join } from 'node:path';
3+
import { join } from 'node:path';
44
import { fileURLToPath } from 'node:url';
55

66
const getPackageJsonVersion = () => {
77
try {
8-
// Use import.meta.resolve to get the URL of package.json
9-
const packageJsonUrl = import.meta.resolve('../package.json');
10-
const packageJsonPath = fileURLToPath(packageJsonUrl);
11-
const packageJson = readFileSync(packageJsonPath, 'utf-8');
12-
const packageJsonObject = JSON.parse(packageJson);
13-
return packageJsonObject.version;
8+
// Try different possible locations for package.json
9+
const possibleLocations = ['../package.json', '../../package.json'];
10+
11+
for (const location of possibleLocations) {
12+
try {
13+
const packageJsonUrl = import.meta.resolve(location);
14+
const packageJsonPath = fileURLToPath(packageJsonUrl);
15+
const packageJson = readFileSync(packageJsonPath, 'utf-8');
16+
const packageJsonObject = JSON.parse(packageJson);
17+
if (packageJsonObject.version) {
18+
return packageJsonObject.version;
19+
}
20+
} catch (error) {
21+
// Continue to next location if this one fails
22+
continue;
23+
}
24+
}
25+
26+
// If we get here, we couldn't find a valid package.json in any location
27+
console.error('Could not find package.json in any of the expected locations');
28+
return undefined;
1429
} catch (error) {
1530
console.error('Failed to load package.json:', error);
1631
return undefined;

api/vite.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,12 @@ export default defineConfig(({ mode }): ViteUserConfig => {
9090
entryFileNames: '[name].js',
9191
format: 'es',
9292
interop: 'auto',
93+
banner: (chunk) => {
94+
if (chunk.fileName === 'main.js' || chunk.fileName === 'cli.js') {
95+
return '#!/bin/sh\n":" //# comment; exec /opt/homebrew/bin/node "$0" "$@" 2>/dev/null || exec /usr/local/node/bin/node "$0" "$@" 2>/dev/null || exec /usr/bin/env node "$0" "$@"\n';
96+
}
97+
return '';
98+
},
9399
},
94100
preserveEntrySignatures: 'strict',
95101
external: [

0 commit comments

Comments
 (0)