Skip to content

Commit b3183e2

Browse files
author
Unitech
committed
advanced Bun support #5893 #5774 #5682 #5675 #5777
#5692
1 parent 7fc9df1 commit b3183e2

File tree

20 files changed

+495
-94
lines changed

20 files changed

+495
-94
lines changed

.github/workflows/node.js.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ jobs:
1010
strategy:
1111
matrix:
1212
node-version: [22.x, 20.x]
13-
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
1413

1514
steps:
1615
- uses: actions/checkout@v3

bin/pm2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
SCRIPT_PATH="$(dirname "$0")/../lib/binaries/CLI.js"
44

55
# Check if 'bun' is available, otherwise use 'node'
6-
if command -v bun &> /dev/null
6+
if command -v bun >/dev/null 2>&1
77
then
88
bun "$SCRIPT_PATH" "$@"
99
else

bin/pm2-dev

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
SCRIPT_PATH="$(dirname "$0")/../lib/binaries/DevCLI.js"
44

55
# Check if 'bun' is available, otherwise use 'node'
6-
if command -v bun &> /dev/null
6+
if command -v bun >/dev/null 2>&1
77
then
88
bun "$SCRIPT_PATH" "$@"
99
else

bin/pm2-docker

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
SCRIPT_PATH="$(dirname "$0")/../lib/binaries/Runtime4Docker.js"
44

55
# Check if 'bun' is available, otherwise use 'node'
6-
if command -v bun &> /dev/null
6+
if command -v bun >/dev/null 2>&1
77
then
88
bun "$SCRIPT_PATH" "$@"
99
else

bin/pm2-runtime

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#!/bin/bash
1+
#!/bin/sh
22

33
SCRIPT_PATH="$(dirname "$0")/../lib/binaries/Runtime4Docker.js"
44

55
# Check if 'bun' is available, otherwise use 'node'
6-
if command -v bun &> /dev/null
6+
if command -v bun >/dev/null 2>&1
77
then
88
bun "$SCRIPT_PATH" "$@"
99
else

bun.lockb

70.1 KB
Binary file not shown.

constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ var csts = {
4545
ERROR_EXIT : 1,
4646
CODE_UNCAUGHTEXCEPTION : 1,
4747

48+
IS_BUN : typeof Bun !== 'undefined',
4849
IS_WINDOWS : (process.platform === 'win32' || process.platform === 'win64' || /^(msys|cygwin)$/.test(process.env.OSTYPE)),
4950
ONLINE_STATUS : 'online',
5051
STOPPED_STATUS : 'stopped',

examples/cluster-http/http.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var http = require('http');
33

44
var server = http.createServer(function(req, res) {
55
res.writeHead(200);
6+
console.log(`New query`)
67
res.end('hey');
78
}).listen(process.env.PORT || 8089, '0.0.0.0', function() {
89
console.log('App listening on port 8089');

lib/API/Serve.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ var url = require('url');
1111
var path = require('path');
1212
var debug = require('debug')('pm2:serve');
1313

14-
var probe = require('@pm2/io');
15-
var errorMeter = probe.meter({
16-
name : '404/sec',
17-
samples : 1,
18-
timeframe : 60
19-
})
14+
// var probe = require('@pm2/io');
15+
// var errorMeter = probe.meter({
16+
// name : '404/sec',
17+
// samples : 1,
18+
// timeframe : 60
19+
// })
2020
/**
2121
* list of supported content types.
2222
*/

lib/API/Startup.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,19 @@ module.exports = function(CLI) {
2121
*/
2222
function isNotRoot(startup_mode, platform, opts, cb) {
2323
Common.printOut(`${cst.PREFIX_MSG}To ${startup_mode} the Startup Script, copy/paste the following command:`);
24+
25+
let pm2_bin_path = require.main.filename
26+
27+
if (pm2_bin_path.includes('/lib/binaries/CLI.js') === true) {
28+
pm2_bin_path = pm2_bin_path.replace('/lib/binaries/CLI.js', '/bin/pm2')
29+
}
30+
2431
if (opts.user) {
2532
console.log('sudo env PATH=$PATH:' + path.dirname(process.execPath) + ' pm2 ' + opts.args[1].name() + ' ' + platform + ' -u ' + opts.user + ' --hp ' + process.env.HOME);
2633
return cb(new Error('You have to run this with elevated rights'));
2734
}
2835
return sexec('whoami', {silent: true}, function(err, stdout, stderr) {
29-
console.log('sudo env PATH=$PATH:' + path.dirname(process.execPath) + ' ' + require.main.filename + ' ' + opts.args[1].name() + ' ' + platform + ' -u ' + stdout.trim() + ' --hp ' + process.env.HOME);
36+
console.log('sudo env PATH=$PATH:' + path.dirname(process.execPath) + ' ' + pm2_bin_path + ' ' + opts.args[1].name() + ' ' + platform + ' -u ' + stdout.trim() + ' --hp ' + process.env.HOME);
3037
return cb(new Error('You have to run this with elevated rights'));
3138
});
3239
}
@@ -336,7 +343,13 @@ module.exports = function(CLI) {
336343
else
337344
envPath = util.format('%s:%s', process.env.PATH || '', path.dirname(process.execPath))
338345

339-
template = template.replace(/%PM2_PATH%/g, process.mainModule.filename)
346+
let pm2_bin_path = require.main.filename
347+
348+
if (pm2_bin_path.includes('/lib/binaries/CLI.js') === true) {
349+
pm2_bin_path = pm2_bin_path.replace('/lib/binaries/CLI.js', '/bin/pm2')
350+
}
351+
352+
template = template.replace(/%PM2_PATH%/g, pm2_bin_path)
340353
.replace(/%NODE_PATH%/g, envPath)
341354
.replace(/%USER%/g, user)
342355
.replace(/%HOME_PATH%/g, opts.hp ? path.resolve(opts.hp, '.pm2') : cst.PM2_ROOT_PATH)

0 commit comments

Comments
 (0)