mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-17 17:36:08 +08:00
22 lines
630 B
TypeScript
22 lines
630 B
TypeScript
import fs from 'fs';
|
|
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`);
|
|
} catch (e) { }
|
|
}
|
|
return null;
|
|
})();
|
|
|
|
export default pm2;
|