mirror of
https://github.com/tauri-apps/tauri.git
synced 2026-04-03 10:11:15 +02:00
fix(cli.js): audit (#1989)
This commit is contained in:
committed by
GitHub
parent
546f4cc4cd
commit
a819f5c9cf
@@ -107,6 +107,8 @@
|
||||
},
|
||||
"resolutions": {
|
||||
"**/lodash": "4.17.21",
|
||||
"**/hosted-git-info": "4.0.2"
|
||||
"**/hosted-git-info": "4.0.2",
|
||||
"**/normalize-url": "6.0.1",
|
||||
"**/trim-newlines": "3.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
// Copyright 2019-2021 Tauri Programme within The Commons Conservancy
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
// forked from https://github.com/quasarframework/quasar/blob/dev/app/lib/helpers/net.js
|
||||
|
||||
import net from 'net'
|
||||
|
||||
async function findClosestOpenPort(
|
||||
port: number,
|
||||
host: string
|
||||
): Promise<number> {
|
||||
return await isPortAvailable(port, host).then((isAvailable) => {
|
||||
if (isAvailable) {
|
||||
return port
|
||||
} else if (port < 65535) {
|
||||
return findClosestOpenPort(port + 1, host)
|
||||
} else {
|
||||
throw new Error('ERROR_NETWORK_PORT_NOT_AVAIL')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async function isPortAvailable(port: number, host: string): Promise<boolean> {
|
||||
return await new Promise((resolve, reject) => {
|
||||
const tester = net
|
||||
.createServer()
|
||||
.once('error', (err: NodeJS.ErrnoException) => {
|
||||
if (err.code === 'EADDRNOTAVAIL') {
|
||||
reject(new Error('ERROR_NETWORK_ADDRESS_NOT_AVAIL'))
|
||||
} else if (err.code === 'EADDRINUSE') {
|
||||
resolve(false) // host/port in use
|
||||
} else {
|
||||
reject(err)
|
||||
}
|
||||
})
|
||||
.once('listening', () => {
|
||||
tester
|
||||
.once('close', () => {
|
||||
resolve(true) // found available host/port
|
||||
})
|
||||
.close()
|
||||
})
|
||||
.on('error', (err: any) => {
|
||||
reject(err)
|
||||
})
|
||||
.listen(port, host)
|
||||
})
|
||||
}
|
||||
|
||||
export { findClosestOpenPort, isPortAvailable }
|
||||
@@ -36,10 +36,10 @@ export const spawn = (
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/prefer-optional-chain
|
||||
onClose && onClose(code ?? 0, runner.pid)
|
||||
onClose && onClose(code ?? 0, runner.pid ?? 0)
|
||||
})
|
||||
|
||||
return runner.pid
|
||||
return runner.pid ?? 0
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user