This commit is contained in:
darenhsu
2022-07-17 13:16:16 +08:00
parent 84759556ff
commit befd344ab0
28070 changed files with 4008428 additions and 1 deletions
+37
View File
@@ -0,0 +1,37 @@
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
## [1.0.0](https://github.com/nuxt-contrib/get-port-please/compare/v0.0.6...v1.0.0) (2020-06-16)
### [0.0.6](https://github.com/nuxt-contrib/get-port-please/compare/v0.0.5...v0.0.6) (2020-06-01)
### [0.0.5](https://github.com/nuxt-contrib/get-port-please/compare/v0.0.4...v0.0.5) (2020-06-01)
### Bug Fixes
* name is not defined ([c1829f1](https://github.com/nuxt-contrib/get-port-please/commit/c1829f12cfaf5304661ef16d744bbc66a2610a2d))
### [0.0.4](https://github.com/nuxt-contrib/get-port-please/compare/v0.0.3...v0.0.4) (2020-06-01)
### Features
* name and random options ([ccea688](https://github.com/nuxt-contrib/get-port-please/commit/ccea68889f440d0760412caff696dccfeac3144f))
### [0.0.3](https://github.com/nuxt-contrib/get-port-please/compare/v0.0.2...v0.0.3) (2020-06-01)
### Bug Fixes
* **types:** use interface instead of type infering ([09135eb](https://github.com/nuxt-contrib/get-port-please/commit/09135ebf0b7c96533b68cabdf8a9c512415e00b8))
### [0.0.2](https://github.com/nuxt-contrib/get-port-please/compare/v0.0.1...v0.0.2) (2020-06-01)
### 0.0.1 (2020-05-31)
### Bug Fixes
* set version to 0 ([79c01ef](https://github.com/nuxt-contrib/get-port-please/commit/79c01ef53e9425345bc0ec2cf58287b1fc940a7c))
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Pooya Parsa
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.
+70
View File
@@ -0,0 +1,70 @@
# get-port-please
> Get an available TCP port to listen
[![npm](https://img.shields.io/npm/dt/get-port-please.svg?style=flat-square)](https://npmjs.com/package/get-port-please)
[![npm (scoped with tag)](https://img.shields.io/npm/v/get-port-please/latest.svg?style=flat-square)](https://npmjs.com/package/get-port-please)
## Usage
Install package:
```bash
yarn add get-port-please
# or
or npm install get-port-please
```
```js
const getPort = require('get-port-please')
// or
import getPort from 'get-port-please'
```
```ts
function getPort(options?: GetPortOptions): Promise<number>
```
Try sequence is: port > ports > memo > random
## Options
```ts
interface GetPortOptions {
name?: string
random?: boolean
port?: number
ports?: number[]
memoDir?: string
memoName?: string
}
```
### `name`
Unique name for port memorizing. Default is `default`.
### `random`
If enabled, `port` and `ports` will be ignored. Default is `false`.
### `port`
First port to check. Default is `process.env.PORT || 3000`
### `ports`
Alternative ports to check. Default is `[4000, 5000, 6000, 7000]`
### `memoDir` / `memoName`
Options passed to [fs-memo](https://github.com/nuxt-contrib/fs-memo)
- Default dir: `node_modules/get-port/dist`
- Defalt name: `.get-port`
## License
MIT
+10
View File
@@ -0,0 +1,10 @@
interface GetPortOptions {
name?: string;
random?: boolean;
port?: number;
ports?: number[];
memoDir?: string;
memoName?: string;
}
export default function getPort(options?: GetPortOptions): Promise<number>;
export {};
+310
View File
@@ -0,0 +1,310 @@
'use strict';
var net = require('net');
var fsMemo = require('fs-memo');
function _await(value, then, direct) {
if (direct) {
return then ? then(value) : value;
}
if (!value || !value.then) {
value = Promise.resolve(value);
}
return then ? value.then(then) : value;
}
var checkPorts = _async(function (ports) {
var _exit = false;
return _continue(_forOf(ports, function (p) {
return _await(checkPort(p), function (r) {
if (r) {
_exit = true;
return r;
}
});
}, function () {
return _exit;
}), function (_result) {
return _exit ? _result : checkPort(0);
});
});
function _async(f) {
return function () {
var arguments$1 = arguments;
for (var args = [], i = 0; i < arguments.length; i++) {
args[i] = arguments$1[i];
}
try {
return Promise.resolve(f.apply(this, args));
} catch (e) {
return Promise.reject(e);
}
};
}
var getPort = _async(function (options) {
var opts = Object.assign({}, defaults, options);
var portsToCheck = [];
if (!opts.random) {
// options.port
if (opts.port) {
portsToCheck.push(opts.port);
} // options.ports
if (Array.isArray(opts.ports)) {
portsToCheck.push.apply(portsToCheck, opts.ports);
}
} // Memo
var memoOptions = {
name: opts.memoName,
dir: opts.memoDir
};
var memoKey = 'port_' + opts.name;
return _await(fsMemo.getMemo(memoOptions), function (memo) {
if (memo[memoKey]) {
portsToCheck.push(memo[memoKey]);
}
return _await(checkPorts(portsToCheck), function (availablePort) {
var obj;
// Persist
return _await(fsMemo.setMemo(( obj = {}, obj[memoKey] = availablePort, obj ), memoOptions), function () {
return availablePort;
});
});
});
});
var _iteratorSymbol = /*#__PURE__*/typeof Symbol !== "undefined" ? Symbol.iterator || (Symbol.iterator = Symbol("Symbol.iterator")) : "@@iterator";
function _settle(pact, state, value) {
if (!pact.s) {
if (value instanceof _Pact) {
if (value.s) {
if (state & 1) {
state = value.s;
}
value = value.v;
} else {
value.o = _settle.bind(null, pact, state);
return;
}
}
if (value && value.then) {
value.then(_settle.bind(null, pact, state), _settle.bind(null, pact, 2));
return;
}
pact.s = state;
pact.v = value;
var observer = pact.o;
if (observer) {
observer(pact);
}
}
}
var _Pact = /*#__PURE__*/function () {
function _Pact() {}
_Pact.prototype.then = function (onFulfilled, onRejected) {
var result = new _Pact();
var state = this.s;
if (state) {
var callback = state & 1 ? onFulfilled : onRejected;
if (callback) {
try {
_settle(result, 1, callback(this.v));
} catch (e) {
_settle(result, 2, e);
}
return result;
} else {
return this;
}
}
this.o = function (_this) {
try {
var value = _this.v;
if (_this.s & 1) {
_settle(result, 1, onFulfilled ? onFulfilled(value) : value);
} else if (onRejected) {
_settle(result, 1, onRejected(value));
} else {
_settle(result, 2, value);
}
} catch (e) {
_settle(result, 2, e);
}
};
return result;
};
return _Pact;
}();
function _isSettledPact(thenable) {
return thenable instanceof _Pact && thenable.s & 1;
}
function _forTo(array, body, check) {
var i = -1,
pact,
reject;
function _cycle(result) {
try {
while (++i < array.length && (!check || !check())) {
result = body(i);
if (result && result.then) {
if (_isSettledPact(result)) {
result = result.v;
} else {
result.then(_cycle, reject || (reject = _settle.bind(null, pact = new _Pact(), 2)));
return;
}
}
}
if (pact) {
_settle(pact, 1, result);
} else {
pact = result;
}
} catch (e) {
_settle(pact || (pact = new _Pact()), 2, e);
}
}
_cycle();
return pact;
}
var defaults = {
name: 'default',
random: false,
port: parseInt(process.env.PORT || '') || 3000,
ports: [4000, 5000, 6000, 7000],
memoDir: __dirname,
memoName: '.get-port'
};
function _forOf(target, body, check) {
if (typeof target[_iteratorSymbol] === "function") {
var iterator = target[_iteratorSymbol](),
step,
pact,
reject;
function _cycle(result) {
try {
while (!(step = iterator.next()).done && (!check || !check())) {
result = body(step.value);
if (result && result.then) {
if (_isSettledPact(result)) {
result = result.v;
} else {
result.then(_cycle, reject || (reject = _settle.bind(null, pact = new _Pact(), 2)));
return;
}
}
}
if (pact) {
_settle(pact, 1, result);
} else {
pact = result;
}
} catch (e) {
_settle(pact || (pact = new _Pact()), 2, e);
}
}
_cycle();
if (iterator.return) {
var _fixup = function (value) {
try {
if (!step.done) {
iterator.return();
}
} catch (e) {}
return value;
};
if (pact && pact.then) {
return pact.then(_fixup, function (e) {
throw _fixup(e);
});
}
_fixup();
}
return pact;
} // No support for Symbol.iterator
if (!("length" in target)) {
throw new TypeError("Object is not iterable");
} // Handle live collections properly
var values = [];
for (var i = 0; i < target.length; i++) {
values.push(target[i]);
}
return _forTo(values, function (i) {
return body(values[i]);
}, check);
}
function _continue(value, then) {
return value && value.then ? value.then(then) : then(value);
}
function checkPort(port) {
return new Promise(function (resolve) {
var server = net.createServer();
server.unref();
server.on('error', function () {
resolve(false);
});
server.listen({
port: port
}, function () {
var ref = server.address();
var port = ref.port;
server.close(function () {
resolve(port);
});
});
});
}
module.exports = getPort;
+64
View File
@@ -0,0 +1,64 @@
{
"_args": [
[
"get-port-please@1.0.0",
"/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series"
]
],
"_from": "get-port-please@1.0.0",
"_id": "get-port-please@1.0.0",
"_inBundle": false,
"_integrity": "sha512-4hylsMS0Uqa4jjwXVS+QWMntWL7CQouAlv4BEmiycavPqOp3ytGf4V4yqy8FnbBboHq5orCXuZyftuXbANk+Mg==",
"_location": "/get-port-please",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "get-port-please@1.0.0",
"name": "get-port-please",
"escapedName": "get-port-please",
"rawSpec": "1.0.0",
"saveSpec": null,
"fetchSpec": "1.0.0"
},
"_requiredBy": [
"/@nuxt/loading-screen"
],
"_resolved": "https://registry.npmjs.org/get-port-please/-/get-port-please-1.0.0.tgz",
"_spec": "1.0.0",
"_where": "/mnt/Foxconn/Digitalent/Deverloper/liff-push_2series",
"bugs": {
"url": "https://github.com/nuxt-contrib/get-port-please/issues"
},
"dependencies": {
"fs-memo": "^1.0.0"
},
"description": "Get an available TCP port to listen",
"devDependencies": {
"@nuxtjs/eslint-config-typescript": "latest",
"@types/node": "latest",
"bili": "latest",
"eslint": "latest",
"rollup-plugin-typescript2": "latest",
"standard-version": "latest",
"typescript": "latest"
},
"files": [
"dist"
],
"homepage": "https://github.com/nuxt-contrib/get-port-please#readme",
"license": "MIT",
"main": "dist/index.js",
"name": "get-port-please",
"repository": {
"type": "git",
"url": "git+https://github.com/nuxt-contrib/get-port-please.git"
},
"scripts": {
"build": "bili src/index.ts --minimal",
"lint": "eslint --ext ts .",
"release": "yarn build && standard-version && npm publish && git push --follow-tags"
},
"types": "dist/index.d.ts",
"version": "1.0.0"
}