Skip to content

Commit 61480f7

Browse files
soyukatabarra
andauthored
Added compatibility to bundlers (closes #144 #152 #153) #154 (#163)
* feat: added bundling compatibility * chore: 3.0.1 changelog * fix: use methods for require to prepare gwmi Co-authored-by: tabarra <tabarra@vexguard.net>
1 parent 6a49aa4 commit 61480f7

File tree

3 files changed

+1364
-1272
lines changed

3 files changed

+1364
-1272
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
### 3.0.1
2+
3+
- removed dynamic requires to allow for bundling #154
4+
- add ibm platform (os400) #158
5+
16
### 3.0
27

38
- removes node 8 support

lib/stats.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
const fs = require('fs')
44
const os = require('os')
55

6+
const requireMap = {
7+
ps: () => require('./ps'),
8+
procfile: () => require('./procfile'),
9+
wmic: () => require('./wmic')
10+
}
11+
612
const platformToMethod = {
713
aix: 'ps',
814
os400: 'ps',
@@ -18,7 +24,6 @@ const platformToMethod = {
1824
win: 'wmic'
1925
}
2026

21-
const ps = require('./ps')
2227
let platform = os.platform()
2328

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

3237
let stat
3338
try {
34-
stat = require('./' + platformToMethod[platform])
39+
stat = requireMap[platformToMethod[platform]]()
3540
} catch (err) {}
3641

3742
/**
@@ -50,10 +55,10 @@ try {
5055
function get (pids, options, callback) {
5156
let fn = stat
5257
if (platform !== 'win' && options.usePs === true) {
53-
fn = ps
58+
fn = requireMap.ps()
5459
}
5560

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

0 commit comments

Comments
 (0)