Skip to content

Commit

Permalink
fix: look for package.json in parent folder
Browse files Browse the repository at this point in the history
  • Loading branch information
Unitech committed Jan 20, 2020
1 parent 5166826 commit cafc8e5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
22 changes: 16 additions & 6 deletions lib/ProcessUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
module.exports = {
injectModules: function() {
if (process.env.pmx !== 'false') {
const pmx = require('@pm2/io');
const pmx = require('@pm2/io')

let conf = {};
let conf = {}
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

if (process.env.io) {
const io = JSON.parse(process.env.io);
conf = io.conf ? io.conf : conf;
const io = JSON.parse(process.env.io)
conf = io.conf ? io.conf : conf
}
pmx.init(Object.assign({
tracing: process.env.trace === 'true' || false
Expand All @@ -23,6 +23,7 @@ module.exports = {
var fs = require('fs')
var path = require('path')
var semver = require('semver')
var data

if (semver.satisfies(process.version, '< 13.3.0'))
return false
Expand All @@ -31,7 +32,16 @@ module.exports = {
return true

try {
var data = JSON.parse(fs.readFileSync(path.join(path.dirname(exec_path), 'package.json')))
data = JSON.parse(fs.readFileSync(path.join(path.dirname(exec_path), 'package.json')))
if (data.type === 'module')
return true
else
return false
} catch(e) {
}

try {
data = JSON.parse(fs.readFileSync(path.join(path.dirname(exec_path), '..', 'package.json')))
if (data.type === 'module')
return true
else
Expand All @@ -40,4 +50,4 @@ module.exports = {
return false
}
}
};
}
8 changes: 8 additions & 0 deletions test/e2e/esmodule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ sleep 2
should 'should have detected es module via .mjs file extension and started 1 app' 'online' 1
should 'should have application in stable state' 'restart_time: 1' 1

$pm2 save

$pm2 update

sleep 2
should 'should have detected es module via .mjs file extension and started 1 app' 'online' 1
should 'should have application in stable state' 'restart_time: 0' 1

#### CLUSTER MODE

cd $file_path/esmodules/mjs
Expand Down

0 comments on commit cafc8e5

Please sign in to comment.