Skip to content

Commit

Permalink
Added compatibility to bundlers (closes #144 #152 #153) #154 (#163)
Browse files Browse the repository at this point in the history
* feat: added bundling compatibility

* chore: 3.0.1 changelog

* fix: use methods for require to prepare gwmi

Co-authored-by: tabarra <tabarra@vexguard.net>
  • Loading branch information
soyuka and tabarra authored Oct 25, 2022
1 parent 6a49aa4 commit 61480f7
Show file tree
Hide file tree
Showing 3 changed files with 1,364 additions and 1,272 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### 3.0.1

- removed dynamic requires to allow for bundling #154
- add ibm platform (os400) #158

### 3.0

- removes node 8 support
Expand Down
13 changes: 9 additions & 4 deletions lib/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
const fs = require('fs')
const os = require('os')

const requireMap = {
ps: () => require('./ps'),
procfile: () => require('./procfile'),
wmic: () => require('./wmic')
}

const platformToMethod = {
aix: 'ps',
os400: 'ps',
Expand All @@ -18,7 +24,6 @@ const platformToMethod = {
win: 'wmic'
}

const ps = require('./ps')
let platform = os.platform()

if (fs.existsSync('/etc/alpine-release')) {
Expand All @@ -31,7 +36,7 @@ if (platform.match(/^win/)) {

let stat
try {
stat = require('./' + platformToMethod[platform])
stat = requireMap[platformToMethod[platform]]()
} catch (err) {}

/**
Expand All @@ -50,10 +55,10 @@ try {
function get (pids, options, callback) {
let fn = stat
if (platform !== 'win' && options.usePs === true) {
fn = ps
fn = requireMap.ps()
}

if (stat === undefined) {
if (fn === undefined) {
return callback(new Error(os.platform() + ' is not supported yet, please open an issue (https://github.com/soyuka/pidusage)'))
}

Expand Down
Loading

0 comments on commit 61480f7

Please sign in to comment.