mirror of
https://github.com/unraid/api.git
synced 2025-12-31 13:39:52 -06:00
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:
@@ -11,6 +11,7 @@
|
|||||||
"max_restarts": 10,
|
"max_restarts": 10,
|
||||||
"min_uptime": 10000,
|
"min_uptime": 10000,
|
||||||
"watch": false,
|
"watch": false,
|
||||||
|
"interpreter": "/usr/local/node/bin/node",
|
||||||
"ignore_watch": ["node_modules", "src", ".env.*", "myservers.cfg"],
|
"ignore_watch": ["node_modules", "src", ".env.*", "myservers.cfg"],
|
||||||
"log_file": "/var/log/graphql-api.log",
|
"log_file": "/var/log/graphql-api.log",
|
||||||
"kill_timeout": 10000
|
"kill_timeout": 10000
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
#!/usr/bin/env node
|
|
||||||
|
|
||||||
import '@app/dotenv.js';
|
import '@app/dotenv.js';
|
||||||
|
|
||||||
import { execa } from 'execa';
|
import { execa } from 'execa';
|
||||||
|
|||||||
@@ -1,16 +1,30 @@
|
|||||||
import { readFileSync } from 'node:fs';
|
import { readFileSync } from 'node:fs';
|
||||||
import { homedir } from 'node:os';
|
import { homedir } from 'node:os';
|
||||||
import { dirname, join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { fileURLToPath } from 'node:url';
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
const getPackageJsonVersion = () => {
|
const getPackageJsonVersion = () => {
|
||||||
try {
|
try {
|
||||||
// Use import.meta.resolve to get the URL of package.json
|
// Try different possible locations for package.json
|
||||||
const packageJsonUrl = import.meta.resolve('../package.json');
|
const possibleLocations = ['../package.json', '../../package.json'];
|
||||||
const packageJsonPath = fileURLToPath(packageJsonUrl);
|
|
||||||
const packageJson = readFileSync(packageJsonPath, 'utf-8');
|
for (const location of possibleLocations) {
|
||||||
const packageJsonObject = JSON.parse(packageJson);
|
try {
|
||||||
return packageJsonObject.version;
|
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) {
|
} catch (error) {
|
||||||
console.error('Failed to load package.json:', error);
|
console.error('Failed to load package.json:', error);
|
||||||
return undefined;
|
return undefined;
|
||||||
|
|||||||
@@ -90,6 +90,12 @@ export default defineConfig(({ mode }): ViteUserConfig => {
|
|||||||
entryFileNames: '[name].js',
|
entryFileNames: '[name].js',
|
||||||
format: 'es',
|
format: 'es',
|
||||||
interop: 'auto',
|
interop: 'auto',
|
||||||
|
banner: (chunk) => {
|
||||||
|
if (chunk.fileName === 'main.js' || chunk.fileName === 'cli.js') {
|
||||||
|
return '#!/usr/local/node/bin/node\n';
|
||||||
|
}
|
||||||
|
return '';
|
||||||
|
},
|
||||||
},
|
},
|
||||||
preserveEntrySignatures: 'strict',
|
preserveEntrySignatures: 'strict',
|
||||||
external: [
|
external: [
|
||||||
|
|||||||
@@ -907,9 +907,11 @@ fi
|
|||||||
|
|
||||||
|
|
||||||
# Create symlink to unraid-api binary (to allow usage elsewhere)
|
# 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/local/sbin/unraid-api
|
||||||
ln -sf ${unraid_binary_path} /usr/bin/unraid-api
|
ln -sf ${unraid_binary_path} /usr/bin/unraid-api
|
||||||
|
|
||||||
|
|
||||||
logger "Starting flash backup (if enabled)"
|
logger "Starting flash backup (if enabled)"
|
||||||
echo "/etc/rc.d/rc.flash_backup start" | at -M now &>/dev/null
|
echo "/etc/rc.d/rc.flash_backup start" | at -M now &>/dev/null
|
||||||
. /root/.bashrc
|
. /root/.bashrc
|
||||||
|
|||||||
@@ -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
|
|
||||||
Reference in New Issue
Block a user