2018-06-15 17:44:47 +02:00
|
|
|
'use strict'
|
|
|
|
|
|
2018-03-02 17:43:47 +01:00
|
|
|
module.exports = {
|
|
|
|
|
injectModules: function() {
|
2019-05-07 11:08:02 -07:00
|
|
|
if (process.env.pmx !== 'false') {
|
2020-01-20 11:29:14 +01:00
|
|
|
const pmx = require('@pm2/io')
|
2018-06-15 16:59:27 +02:00
|
|
|
|
2020-01-20 11:29:14 +01:00
|
|
|
let conf = {}
|
2019-03-08 15:50:36 +01:00
|
|
|
const hasSpecificConfig = typeof process.env.io === 'string' || process.env.trace === 'true'
|
|
|
|
|
// pmx is already init, no need to do it twice
|
|
|
|
|
if (hasSpecificConfig === false) return
|
2018-06-15 16:59:27 +02:00
|
|
|
|
|
|
|
|
if (process.env.io) {
|
2020-01-20 11:29:14 +01:00
|
|
|
const io = JSON.parse(process.env.io)
|
|
|
|
|
conf = io.conf ? io.conf : conf
|
2018-06-15 16:59:27 +02:00
|
|
|
}
|
2019-03-01 15:52:32 +01:00
|
|
|
pmx.init(Object.assign({
|
|
|
|
|
tracing: process.env.trace === 'true' || false
|
|
|
|
|
}, conf))
|
2018-03-02 17:43:47 +01:00
|
|
|
}
|
2020-01-13 14:52:59 +01:00
|
|
|
},
|
|
|
|
|
isESModule(exec_path) {
|
|
|
|
|
var fs = require('fs')
|
|
|
|
|
var path = require('path')
|
|
|
|
|
var semver = require('semver')
|
2020-01-20 11:29:14 +01:00
|
|
|
var data
|
2020-01-13 14:52:59 +01:00
|
|
|
|
2022-01-08 21:11:45 -03:00
|
|
|
var findPackageJson = function(directory) {
|
|
|
|
|
var file = path.join(directory, 'package.json')
|
|
|
|
|
if (fs.existsSync(file) && fs.statSync(file).isFile()) {
|
|
|
|
|
return file;
|
|
|
|
|
}
|
|
|
|
|
var parent = path.resolve(directory, '..')
|
|
|
|
|
if (parent === directory) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
return findPackageJson(parent)
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-13 14:52:59 +01:00
|
|
|
if (semver.satisfies(process.version, '< 13.3.0'))
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
|
|
if (path.extname(exec_path) === '.mjs')
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
|
|
try {
|
2022-01-08 21:11:45 -03:00
|
|
|
data = JSON.parse(fs.readFileSync(findPackageJson(path.dirname(exec_path))))
|
2020-01-20 11:29:14 +01:00
|
|
|
if (data.type === 'module')
|
|
|
|
|
return true
|
|
|
|
|
else
|
|
|
|
|
return false
|
|
|
|
|
} catch(e) {
|
|
|
|
|
}
|
2018-03-02 17:43:47 +01:00
|
|
|
}
|
2020-01-20 11:29:14 +01:00
|
|
|
}
|