nodestatus-server 1.2.7-beta.4 → 1.2.8-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,22 @@
1
1
  #!/usr/bin/env node
2
- const path = require('path');
2
+ import { spawn } from 'child_process';
3
+ import { platform } from 'os';
4
+ import { dirname, resolve } from 'path';
5
+ import { fileURLToPath } from 'url';
6
+ import { createRequire } from 'module';
3
7
 
4
8
  const args = process.argv.slice(2).join(' ');
9
+ const __dirname = dirname(fileURLToPath(import.meta.url));
5
10
 
6
- const cp = require('child_process');
7
- const { platform } = require('os');
8
- const { resolve } = require('path');
9
-
10
- cp.spawn(platform() === 'win32' ? 'npm.cmd' : 'npm', ['run', 'prestart'], {
11
+ spawn(platform() === 'win32' ? 'npm.cmd' : 'npm', ['run', 'prestart'], {
11
12
  env: process.env,
12
13
  cwd: resolve(__dirname, '../'),
13
14
  stdio: 'inherit'
14
- }).on('close', () => {
15
+ }).on('close', async () => {
15
16
  try {
16
- const pm2 = require('pm2');
17
+ // ES6 import not read NODE_PATH env
18
+ // const pm2 = await import('pm2');
19
+ const pm2 = createRequire(import.meta.url)('pm2');
17
20
  pm2.connect(error => {
18
21
  if (error) {
19
22
  console.log(error);
@@ -22,7 +25,7 @@ cp.spawn(platform() === 'win32' ? 'npm.cmd' : 'npm', ['run', 'prestart'], {
22
25
  pm2.start(
23
26
  {
24
27
  name: 'nodestatus',
25
- script: path.resolve(__dirname, '../build/app.js'),
28
+ script: resolve(__dirname, '../build/app.js'),
26
29
  args
27
30
  },
28
31
  error => {
@@ -35,6 +38,6 @@ cp.spawn(platform() === 'win32' ? 'npm.cmd' : 'npm', ['run', 'prestart'], {
35
38
  console.log(`[ERROR]: ${error.message || error}`);
36
39
  console.log('Something wrong. Please check if you have installed pm2 correctly.');
37
40
  console.log('Fallback to non-pm2 daemon');
38
- require('../build/app');
41
+ await import('../build/app.js');
39
42
  }
40
43
  });
@@ -1,10 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const cp = require('child_process');
4
- const { platform } = require('os');
5
- const { resolve } = require('path');
3
+ import { spawn } from 'child_process';
4
+ import { platform } from 'os';
5
+ import { dirname, resolve } from 'path';
6
+ import { fileURLToPath } from 'url';
6
7
 
7
- cp.spawn(platform() === 'win32' ? 'npm.cmd' : 'npm', ['run', 'start'], {
8
+ const __dirname = dirname(fileURLToPath(import.meta.url));
9
+
10
+ spawn(platform() === 'win32' ? 'npm.cmd' : 'npm', ['run', 'start'], {
8
11
  env: process.env,
9
12
  cwd: resolve(__dirname, '../'),
10
13
  stdio: 'inherit'