fix: fix invalid path to node with sh execution (#1213)

Hoping this will resolve:
https://forums.unraid.net/topic/187498-unable-to-install-my-server-plugin/


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Improved command-line execution behavior for enhanced compatibility
across different environments.
- Enhanced the version retrieval process by allowing the system to
locate configuration details from multiple potential sources.
- Introduced a build enhancement that conditionally injects a startup
script into bundled outputs, improving script portability and user
experience.
- Specified the Node.js interpreter path in the application
configuration for better execution control.
- Added a symbolic link for the Node.js binary to enhance accessibility.

- **Bug Fixes**
- Enhanced error handling for locating the `package.json` file,
providing feedback when no valid file is found.

- **Chores**
- Removed unnecessary shell script that modified the system's `PATH`
environment variable.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Eli Bosley
2025-03-04 16:13:47 -05:00
committed by GitHub
parent dbcedad039
commit f1838bf69a
6 changed files with 30 additions and 15 deletions

View File

@@ -11,6 +11,7 @@
"max_restarts": 10,
"min_uptime": 10000,
"watch": false,
"interpreter": "/usr/local/node/bin/node",
"ignore_watch": ["node_modules", "src", ".env.*", "myservers.cfg"],
"log_file": "/var/log/graphql-api.log",
"kill_timeout": 10000

View File

@@ -1,5 +1,3 @@
#!/usr/bin/env node
import '@app/dotenv.js';
import { execa } from 'execa';

View File

@@ -1,16 +1,30 @@
import { readFileSync } from 'node:fs';
import { homedir } from 'node:os';
import { dirname, join } from 'node:path';
import { join } from 'node:path';
import { fileURLToPath } from 'node:url';
const getPackageJsonVersion = () => {
try {
// Use import.meta.resolve to get the URL of package.json
const packageJsonUrl = import.meta.resolve('../package.json');
const packageJsonPath = fileURLToPath(packageJsonUrl);
const packageJson = readFileSync(packageJsonPath, 'utf-8');
const packageJsonObject = JSON.parse(packageJson);
return packageJsonObject.version;
// Try different possible locations for package.json
const possibleLocations = ['../package.json', '../../package.json'];
for (const location of possibleLocations) {
try {
const packageJsonUrl = import.meta.resolve(location);
const packageJsonPath = fileURLToPath(packageJsonUrl);
const packageJson = readFileSync(packageJsonPath, 'utf-8');
const packageJsonObject = JSON.parse(packageJson);
if (packageJsonObject.version) {
return packageJsonObject.version;
}
} catch {
// Continue to next location if this one fails
}
}
// If we get here, we couldn't find a valid package.json in any location
console.error('Could not find package.json in any of the expected locations');
return undefined;
} catch (error) {
console.error('Failed to load package.json:', error);
return undefined;

View File

@@ -90,6 +90,12 @@ export default defineConfig(({ mode }): ViteUserConfig => {
entryFileNames: '[name].js',
format: 'es',
interop: 'auto',
banner: (chunk) => {
if (chunk.fileName === 'main.js' || chunk.fileName === 'cli.js') {
return '#!/usr/local/node/bin/node\n';
}
return '';
},
},
preserveEntrySignatures: 'strict',
external: [

View File

@@ -907,9 +907,11 @@ fi
# Create symlink to unraid-api binary (to allow usage elsewhere)
ln -sf /usr/local/node/bin/node /usr/local/bin/node
ln -sf ${unraid_binary_path} /usr/local/sbin/unraid-api
ln -sf ${unraid_binary_path} /usr/bin/unraid-api
logger "Starting flash backup (if enabled)"
echo "/etc/rc.d/rc.flash_backup start" | at -M now &>/dev/null
. /root/.bashrc

View File

@@ -1,6 +0,0 @@
#! /bin/bash
# Add Node.js binary path to PATH if not already present
if [[ ":$PATH:" != *":/usr/local/node/bin:"* ]]; then
export PATH="/usr/local/node/bin:$PATH"
fi