Skip to content

Commit

Permalink
Merge pull request #5267 from THernandez03/findNearestPackageJson
Browse files Browse the repository at this point in the history
Fix: #5266 - Find the nearest package.json
  • Loading branch information
Unitech authored Jan 20, 2022
2 parents 4db38ea + 4007cf5 commit f17cd4c
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions lib/ProcessUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,31 @@ module.exports = {
var semver = require('semver')
var data

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)
}

if (semver.satisfies(process.version, '< 13.3.0'))
return false

if (path.extname(exec_path) === '.mjs')
return true

try {
data = JSON.parse(fs.readFileSync(path.join(path.dirname(exec_path), 'package.json')))
data = JSON.parse(fs.readFileSync(findPackageJson(path.dirname(exec_path))))
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
return false
} catch(e) {
return false
}
}
}

0 comments on commit f17cd4c

Please sign in to comment.