Skip to content

Commit b216f03

Browse files
author
Unitech
committed
bun support
1 parent 686284d commit b216f03

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

bun.lockb

85 KB
Binary file not shown.

constants.js

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ let cst = {
6161
AGGREGATION_DURATION: useIfDefined(process.env.PM2_DEBUG, process.env.NODE_ENV === 'test' || process.env.NODE_ENV === 'development') ? 0 : 60 * 10,
6262
TRACE_FLUSH_INTERVAL: useIfDefined(process.env.PM2_DEBUG, process.env.NODE_ENV === 'local_test') ? 1000 : 60000,
6363

64+
IS_BUN : typeof Bun !== 'undefined',
6465
PM2_HOME: PM2_HOME,
6566
DAEMON_RPC_PORT: path.resolve(PM2_HOME, 'rpc.sock'),
6667
DAEMON_PUB_PORT: path.resolve(PM2_HOME, 'pub.sock'),

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pm2/agent",
3-
"version": "2.0.4",
3+
"version": "2.1.0",
44
"description": "PM2.io Agent Daemon",
55
"main": "index.js",
66
"directories": {

src/InteractorClient.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,13 @@ module.exports = class InteractorDaemonizer {
179179
const err = testEnv ? 2 : fs.openSync(constants.INTERACTOR_LOG_FILE_PATH, 'a')
180180

181181
let binary = process.execPath
182-
if (binary.indexOf('node') === -1) {
182+
183+
if (cst.IS_BUN === true)
184+
binary = process.execPath
185+
else if (binary.indexOf('node') === -1)
183186
binary = 'node'
184-
}
185-
if (process.env.NODEJS_EXECUTABLE) {
187+
if (process.env.NODEJS_EXECUTABLE)
186188
binary = process.env.NODEJS_EXECUTABLE
187-
}
188189

189190
const child = childProcess.spawn(binary, [InteractorJS], {
190191
silent: false,
@@ -201,7 +202,8 @@ module.exports = class InteractorDaemonizer {
201202
PM2_VERSION: conf.pm2_version,
202203
DEBUG: process.env.DEBUG || 'interactor:*,-interactor:axon,-interactor:websocket,-interactor:pm2:client,-interactor:push'
203204
}, process.env),
204-
stdio: ['ipc', out, err]
205+
stdio: [null, out, err, 'ipc'], // Redirect stdout, stderr, and enable IPC
206+
//stdio: ['ipc', out, err]
205207
})
206208

207209
try {
@@ -222,6 +224,7 @@ module.exports = class InteractorDaemonizer {
222224
if (status === constants.ERROR_EXIT) {
223225
return cb(new Error('Agent has shutdown for unknown reason'))
224226
}
227+
225228
return cb()
226229
})
227230

@@ -235,7 +238,8 @@ module.exports = class InteractorDaemonizer {
235238
const timeout = setTimeout(_ => {
236239
printOut(`${chalk.yellow('[PM2.IO][WARNING]')} Not managed to connect to PM2 Plus, retrying in background.`)
237240
child.removeAllListeners()
238-
child.disconnect()
241+
if (child.disconnect)
242+
child.disconnect()
239243
return cb(null, {}, child)
240244
}, 7000)
241245

@@ -248,6 +252,8 @@ module.exports = class InteractorDaemonizer {
248252
}
249253

250254
child.removeAllListeners('error')
255+
if (cst.IS_BUN === true)
256+
child.removeAllListeners('close')
251257
child.disconnect()
252258

253259
// Handle and show to user the different error message that can happen

src/InteractorDaemon.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ const InteractorDaemon = module.exports = class InteractorDaemon {
3737
this.httpClient = new Utility.HTTPClient()
3838
this._online = true
3939

40-
this._internalDebugger()
40+
if (cst.IS_BUN === false)
41+
this._internalDebugger()
4142
}
4243

4344
/**

0 commit comments

Comments
 (0)