UNPKG

1.32 kBJavaScriptView Raw
1'use strict'
2
3module.exports = {
4 injectModules: function() {
5 if (process.env.pmx !== 'false') {
6 const pmx = require('@pm2/io')
7
8 let conf = {}
9 const hasSpecificConfig = typeof process.env.io === 'string' || process.env.trace === 'true'
10 // pmx is already init, no need to do it twice
11 if (hasSpecificConfig === false) return
12
13 if (process.env.io) {
14 const io = JSON.parse(process.env.io)
15 conf = io.conf ? io.conf : conf
16 }
17 pmx.init(Object.assign({
18 tracing: process.env.trace === 'true' || false
19 }, conf))
20 }
21 },
22 isESModule(exec_path) {
23 var fs = require('fs')
24 var path = require('path')
25 var semver = require('semver')
26 var data
27
28 if (semver.satisfies(process.version, '< 13.3.0'))
29 return false
30
31 if (path.extname(exec_path) === '.mjs')
32 return true
33
34 try {
35 data = JSON.parse(fs.readFileSync(path.join(path.dirname(exec_path), 'package.json')))
36 if (data.type === 'module')
37 return true
38 else
39 return false
40 } catch(e) {
41 }
42
43 try {
44 data = JSON.parse(fs.readFileSync(path.join(path.dirname(exec_path), '..', 'package.json')))
45 if (data.type === 'module')
46 return true
47 else
48 return false
49 } catch(e) {
50 return false
51 }
52 }
53}