(filename: string, config: Record<string, any> = {})
| 5 | import { getYamlContent, getRootHome } from '@serverless-devs/utils'; |
| 6 | |
| 7 | function execDaemon(filename: string, config: Record<string, any> = {}) { |
| 8 | // 测试环境不上报 |
| 9 | if (process.env.NODE_ENV === 'test') return; |
| 10 | // set analysis+ |
| 11 | const data = getYamlContent(path.join(getRootHome(), 'set-config.yml')); |
| 12 | if (data?.analysis === 'disable' && filename === 'report.js') return; |
| 13 | const filePath = path.join(__dirname, 'daemon', filename); |
| 14 | if (!fs.existsSync(filePath)) return; |
| 15 | if (process.env['serverless_devs_daemon_enable'] === 'false') { |
| 16 | logger.info(`It is detected that the environment variable 'serverless_devs_daemon_enable' is false and the daemon: ${filePath} will run in the main process`); |
| 17 | return spawn(process.execPath, [filePath, JSON.stringify(config)], { |
| 18 | stdio: 'inherit', |
| 19 | }); |
| 20 | } |
| 21 | |
| 22 | return spawn(process.execPath, [filePath, JSON.stringify(config)], { |
| 23 | detached: true, |
| 24 | stdio: 'ignore', |
| 25 | }).unref(); |
| 26 | } |
| 27 | |
| 28 | export default execDaemon; |
no outgoing calls
no test coverage detected