mockaton 12.3.7 → 12.4.0

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.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "mockaton",
3
3
  "description": "HTTP Mock Server",
4
4
  "type": "module",
5
- "version": "12.3.7",
5
+ "version": "12.4.0",
6
6
  "exports": {
7
7
  ".": {
8
8
  "import": "./index.js",
@@ -1,4 +1,4 @@
1
- import { execFileSync } from 'node:child_process'
1
+ import { spawnSync } from 'node:child_process'
2
2
 
3
3
 
4
4
  export const openInBrowser = (async () => {
@@ -11,13 +11,22 @@ export const openInBrowser = (async () => {
11
11
  })()
12
12
 
13
13
  function _openInBrowser(address) {
14
+ let opener
14
15
  switch (process.platform) {
15
16
  case 'darwin':
16
- execFileSync('open', [address])
17
+ opener = 'open'
17
18
  break
18
19
  case 'win32':
19
- execFileSync('start', [address])
20
+ opener = 'start'
20
21
  break
22
+ default:
23
+ opener = ['xdg-open', 'gnome-open', 'kde-open'].find(hasCommand)
21
24
  }
25
+ if (opener)
26
+ spawnSync(opener, [address])
22
27
  }
23
28
 
29
+ function hasCommand(cmd) {
30
+ const { status } = spawnSync('command', ['-v', cmd], { stdio: 'ignore' })
31
+ return status === 0
32
+ }