mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
utils: fix locate-pm2
This commit is contained in:
8 files changed
+38
-31
No files matched your search
@@ -3,12 +3,15 @@ import path from 'path';
|
||||
|
||||
const PATH = process.env.PATH?.split(':') || [];
|
||||
|
||||
/* eslint-disable import/no-dynamic-require */
|
||||
// @ts-ignore
|
||||
const pm2: typeof import('pm2') | null = (() => {
|
||||
for (const dir of PATH) {
|
||||
try {
|
||||
const info = fs.readlinkSync(path.resolve(dir, 'pm2'));
|
||||
const p = path.resolve(dir, info);
|
||||
if (p.startsWith('/nix')) return require(`${p.split('/bin')[0]}/lib/node_modules/pm2`);
|
||||
// installed by yarn
|
||||
return require(`${p.split('.bin')[0]}pm2`); // eslint-disable-line import/no-dynamic-require
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user