MCPcopy
hub / github.com/Unitech/pm2 / isESModule

Function isESModule

lib/ProcessUtils.js:22–50  ·  view source on GitHub ↗
(exec_path)

Source from the content-addressed store, hash-verified

20 }
21 },
22 isESModule(exec_path) {
23 var fs = require('fs')
24 var path = require('path')
25 var data
26
27 var findPackageJson = function(directory) {
28 var file = path.join(directory, 'package.json')
29 if (fs.existsSync(file) && fs.statSync(file).isFile()) {
30 return file;
31 }
32 var parent = path.resolve(directory, '..')
33 if (parent === directory) {
34 return null;
35 }
36 return findPackageJson(parent)
37 }
38
39 if (path.extname(exec_path) === '.mjs')
40 return true
41
42 try {
43 data = JSON.parse(fs.readFileSync(findPackageJson(path.dirname(exec_path))))
44 if (data.type === 'module')
45 return true
46 else
47 return false
48 } catch(e) {
49 }
50 }
51}

Callers

nothing calls this directly

Calls 2

findPackageJsonFunction · 0.85
parseMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…