This commit is contained in:
2024-03-22 03:47:51 +05:30
parent 8bcf3d211e
commit 89819f6fe2
28440 changed files with 3211033 additions and 2 deletions

20
node_modules/detect-port/LICENSE generated vendored Normal file
View File

@@ -0,0 +1,20 @@
The MIT License (MIT)
Copyright (c) 2014 - present node-modules and other contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

111
node_modules/detect-port/README.md generated vendored Normal file
View File

@@ -0,0 +1,111 @@
[![logo][logo-image]][logo-url]
---
[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][codecov-image]][codecov-url]
[![npm download][download-image]][download-url]
[logo-image]: ./logo.png
[logo-url]: https://npmjs.org/package/detect-port
[npm-image]: https://img.shields.io/npm/v/detect-port.svg
[npm-url]: https://npmjs.org/package/detect-port
[travis-image]: https://img.shields.io/travis/node-modules/detect-port.svg
[travis-url]: https://travis-ci.org/node-modules/detect-port
[codecov-image]: https://img.shields.io/coveralls/node-modules/detect-port.svg
[codecov-url]: https://codecov.io/gh/node-modules/detect-port
[download-image]: https://img.shields.io/npm/dm/detect-port.svg
[download-url]: https://npmjs.org/package/detect-port
> Node.js implementation of port detector
## Who are using or has used
- ⭐⭐⭐[eggjs/egg](//github.com/eggjs/egg)
- ⭐⭐⭐[alibaba/ice](//github.com/alibaba/ice)
- ⭐⭐⭐[alibaba/uirecorder](//github.com/alibaba/uirecorder)
- ⭐⭐⭐[facebook/create-react-app](//github.com/facebook/create-react-app/blob/main/packages/react-dev-utils/package.json)
- ⭐⭐⭐[facebook/flipper](//github.com/facebook/flipper)
- ⭐⭐⭐[umijs/umi](//github.com/umijs/umi)
- ⭐⭐⭐[gatsbyjs/gatsby](//github.com/gatsbyjs/gatsby)
- ⭐⭐⭐[electron-react-boilerplate/electron-react-boilerplate](//github.com/electron-react-boilerplate/electron-react-boilerplate)
- ⭐⭐⭐[zeit/micro](//github.com/zeit/micro)
- ⭐⭐⭐[rails/webpacker](//github.com/rails/webpacker)
- ⭐⭐⭐[storybookjs/storybook](//github.com/storybookjs/storybook)
[For more](//github.com/node-modules/detect-port/network/dependents)
## Usage
```bash
$ npm i detect-port --save
```
```javascript
const detect = require('detect-port');
/**
* use as a promise
*/
detect(port)
.then(_port => {
if (port == _port) {
console.log(`port: ${port} was not occupied`);
} else {
console.log(`port: ${port} was occupied, try port: ${_port}`);
}
})
.catch(err => {
console.log(err);
});
```
## Command Line Tool
```bash
$ npm i detect-port -g
```
### Quick Start
```bash
# get an available port randomly
$ detect
# detect pointed port
$ detect 80
# output verbose log
$ detect --verbose
# more help
$ detect --help
```
## FAQ
Most likely network error, check that your `/etc/hosts` and make sure the content below:
```
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
```
<!-- GITCONTRIBUTOR_START -->
## Contributors
|[<img src="https://avatars.githubusercontent.com/u/1011681?v=4" width="100px;"/><br/><sub><b>xudafeng</b></sub>](https://github.com/xudafeng)<br/>|[<img src="https://avatars.githubusercontent.com/u/156269?v=4" width="100px;"/><br/><sub><b>fengmk2</b></sub>](https://github.com/fengmk2)<br/>|[<img src="https://avatars.githubusercontent.com/u/1044425?v=4" width="100px;"/><br/><sub><b>ziczhu</b></sub>](https://github.com/ziczhu)<br/>|[<img src="https://avatars.githubusercontent.com/u/810438?v=4" width="100px;"/><br/><sub><b>gaearon</b></sub>](https://github.com/gaearon)<br/>|[<img src="https://avatars.githubusercontent.com/u/34906299?v=4" width="100px;"/><br/><sub><b>chnliquan</b></sub>](https://github.com/chnliquan)<br/>|[<img src="https://avatars.githubusercontent.com/u/360661?v=4" width="100px;"/><br/><sub><b>popomore</b></sub>](https://github.com/popomore)<br/>|
| :---: | :---: | :---: | :---: | :---: | :---: |
[<img src="https://avatars.githubusercontent.com/u/52845048?v=4" width="100px;"/><br/><sub><b>snapre</b></sub>](https://github.com/snapre)<br/>|[<img src="https://avatars.githubusercontent.com/u/56271907?v=4" width="100px;"/><br/><sub><b>yavuzakyuz</b></sub>](https://github.com/yavuzakyuz)<br/>|[<img src="https://avatars.githubusercontent.com/u/197375?v=4" width="100px;"/><br/><sub><b>antife-yinyue</b></sub>](https://github.com/antife-yinyue)<br/>
This project follows the git-contributor [spec](https://github.com/xudafeng/git-contributor), auto updated at `Wed Sep 21 2022 23:10:27 GMT+0800`.
<!-- GITCONTRIBUTOR_END -->
## License
[MIT](LICENSE)

79
node_modules/detect-port/bin/detect-port.js generated vendored Executable file
View File

@@ -0,0 +1,79 @@
#!/usr/bin/env node
'use strict';
const pkg = require('../package');
const args = process.argv.slice(2);
let arg_0 = args[0];
if (arg_0 && [ '-v', '--version' ].includes(arg_0.toLowerCase())) {
console.log(pkg.version);
process.exit(0);
}
const removeByValue = (arr, val) => {
for (let i = 0; i < arr.length; i++) {
if (arr[i] === val) {
arr.splice(i, 1);
break;
}
}
};
const main = require('..');
const port = parseInt(arg_0, 10);
const isVerbose = args.includes('--verbose');
removeByValue(args, '--verbose');
arg_0 = args[0];
if (!arg_0) {
const random = Math.floor(9000 + Math.random() * (65535 - 9000));
main(random, (err, port) => {
if (isVerbose) {
if (err) {
console.log(`get available port failed with ${err}`);
}
console.log(`get available port ${port} randomly`);
} else {
console.log(port || random);
}
});
} else if (isNaN(port)) {
console.log();
console.log(` \u001b[37m${pkg.description}\u001b[0m`);
console.log();
console.log(' Usage:');
console.log();
console.log(` ${pkg.name} [port]`);
console.log();
console.log(' Options:');
console.log();
console.log(' -v, --version output version and exit');
console.log(' -h, --help output usage information');
console.log(' --verbose output verbose log');
console.log();
console.log(' Further help:');
console.log();
console.log(` ${pkg.homepage}`);
console.log();
} else {
main(port, (err, _port) => {
if (isVerbose) {
if (err) {
console.log(`get available port failed with ${err}`);
}
if (port !== _port) {
console.log(`port ${port} was occupied`);
}
console.log(`get available port ${_port}`);
} else {
console.log(_port || port);
}
});
}

4
node_modules/detect-port/index.js generated vendored Normal file
View File

@@ -0,0 +1,4 @@
'use strict';
module.exports = require('./lib/detect-port');
module.exports.waitPort = require('./lib/wait-port');

120
node_modules/detect-port/lib/detect-port.js generated vendored Normal file
View File

@@ -0,0 +1,120 @@
'use strict';
const net = require('net');
const address = require('address');
const debug = require('debug')('detect-port');
module.exports = (port, callback) => {
let hostname = '';
if (typeof port === 'object' && port) {
hostname = port.hostname;
callback = port.callback;
port = port.port;
} else {
if (typeof port === 'function') {
callback = port;
port = null;
}
}
port = parseInt(port) || 0;
let maxPort = port + 10;
if (maxPort > 65535) {
maxPort = 65535;
}
debug('detect free port between [%s, %s)', port, maxPort);
if (typeof callback === 'function') {
return tryListen(port, maxPort, hostname, callback);
}
// promise
return new Promise(resolve => {
tryListen(port, maxPort, hostname, (_, realPort) => {
resolve(realPort);
});
});
};
function tryListen(port, maxPort, hostname, callback) {
function handleError() {
port++;
if (port >= maxPort) {
debug('port: %s >= maxPort: %s, give up and use random port', port, maxPort);
port = 0;
maxPort = 0;
}
tryListen(port, maxPort, hostname, callback);
}
// use user hostname
if (hostname) {
listen(port, hostname, (err, realPort) => {
if (err) {
if (err.code === 'EADDRNOTAVAIL') {
return callback(new Error('the ip that is not unknown on the machine'));
}
return handleError();
}
callback(null, realPort);
});
} else {
// 1. check null
listen(port, null, (err, realPort) => {
// ignore random listening
if (port === 0) {
return callback(err, realPort);
}
if (err) {
return handleError(err);
}
// 2. check 0.0.0.0
listen(port, '0.0.0.0', err => {
if (err) {
return handleError(err);
}
// 3. check localhost
listen(port, 'localhost', err => {
// if localhost refer to the ip that is not unkonwn on the machine, you will see the error EADDRNOTAVAIL
// https://stackoverflow.com/questions/10809740/listen-eaddrnotavail-error-in-node-js
if (err && err.code !== 'EADDRNOTAVAIL') {
return handleError(err);
}
// 4. check current ip
listen(port, address.ip(), (err, realPort) => {
if (err) {
return handleError(err);
}
callback(null, realPort);
});
});
});
});
}
}
function listen(port, hostname, callback) {
const server = new net.Server();
server.on('error', err => {
debug('listen %s:%s error: %s', hostname, port, err);
server.close();
if (err.code === 'ENOTFOUND') {
debug('ignore dns ENOTFOUND error, get free %s:%s', hostname, port);
return callback(null, port);
}
return callback(err);
});
server.listen(port, hostname, () => {
port = server.address().port;
server.close();
debug('get free %s:%s', hostname, port);
return callback(null, port);
});
}

32
node_modules/detect-port/lib/wait-port.js generated vendored Normal file
View File

@@ -0,0 +1,32 @@
'use strict';
const debug = require('debug')('wait-port');
const detect = require('./detect-port');
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms));
async function waitPort(port, options = {}) {
const { retryInterval = 1000, retries = Infinity } = options;
let count = 1;
async function loop() {
debug('retries', retries, 'count', count);
if (count > retries) {
const err = new Error('retries exceeded');
err.retries = retries;
err.count = count;
throw err;
}
count++;
const freePort = await detect(port);
if (freePort === port) {
await sleep(retryInterval);
return loop();
}
return true;
}
return await loop();
}
module.exports = waitPort;

50
node_modules/detect-port/package.json generated vendored Normal file
View File

@@ -0,0 +1,50 @@
{
"name": "detect-port",
"version": "1.5.1",
"description": "Node.js implementation of port detector",
"keywords": [
"detect",
"port"
],
"bin": {
"detect": "./bin/detect-port.js",
"detect-port": "./bin/detect-port.js"
},
"main": "index.js",
"files": [
"bin",
"lib",
"index.js"
],
"repository": {
"type": "git",
"url": "git://github.com/node-modules/detect-port.git"
},
"dependencies": {
"address": "^1.0.1",
"debug": "4"
},
"devDependencies": {
"command-line-test": "1",
"egg-bin": "^5.2.0",
"egg-ci": "^2.1.0",
"eslint": "^8.23.1",
"eslint-config-egg": "^12.0.0",
"git-contributor": "1",
"mm": "^2.1.0",
"pedding": "^1.1.0",
"power-assert": "^1.6.1"
},
"scripts": {
"test": "egg-bin test",
"ci": "npm run lint && egg-bin cov",
"lint": "eslint .",
"contributor": "git-contributor"
},
"ci": {
"os": "linux",
"version": "14, 16, 18"
},
"homepage": "https://github.com/node-modules/detect-port",
"license": "MIT"
}