mirror of
https://github.com/whyour/qinglong.git
synced 2025-11-22 16:38:33 +08:00
修复 homedir 权限
This commit is contained in:
parent
8f23c61fee
commit
72d4c8bfd4
|
|
@ -4,6 +4,8 @@ import os from 'os';
|
|||
import chokidar from 'chokidar';
|
||||
import config from '../config/index';
|
||||
import { promiseExec } from '../config/util';
|
||||
import { W_OK } from 'constants';
|
||||
import Logger from './logger';
|
||||
|
||||
async function linkToNodeModule(src: string, dst?: string) {
|
||||
const target = path.join(config.rootPath, 'node_modules', dst || src);
|
||||
|
|
@ -17,19 +19,29 @@ async function linkToNodeModule(src: string, dst?: string) {
|
|||
} catch (error) { }
|
||||
}
|
||||
|
||||
async function ensureDirWritable(dir: string) {
|
||||
try {
|
||||
await fs.access(dir, W_OK);
|
||||
return true;
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
async function linkCommand() {
|
||||
const homeDir = os.homedir();
|
||||
const userBinDir = path.join(homeDir, 'bin');
|
||||
let userBinDir = path.join(homeDir, 'bin');
|
||||
|
||||
try {
|
||||
if (!(await ensureDirWritable(homeDir))) {
|
||||
const commandPath = await promiseExec('which node');
|
||||
userBinDir = path.dirname(commandPath);
|
||||
}
|
||||
await fs.mkdir(userBinDir, { recursive: true });
|
||||
await linkCommandToDir(userBinDir);
|
||||
} catch (error) {
|
||||
const commandPath = await promiseExec('which node');
|
||||
const commandDir = path.dirname(commandPath);
|
||||
return await linkCommandToDir(commandDir);
|
||||
Logger.error('Linking command failed:', error);
|
||||
}
|
||||
|
||||
await linkCommandToDir(userBinDir);
|
||||
}
|
||||
|
||||
async function linkCommandToDir(commandDir: string) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user