拿掉 build files

This commit is contained in:
2022-07-18 16:33:23 +08:00
parent 41e2287bcb
commit 3707f158a3
31953 changed files with 0 additions and 4411796 deletions
-37
View File
@@ -1,37 +0,0 @@
# 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
@@ -1,21 +0,0 @@
MIT License
Copyright (c) UnJS - 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.
-86
View File
@@ -1,86 +0,0 @@
![get-port-please](https://user-images.githubusercontent.com/904724/101664848-9bc16380-3a4c-11eb-9e3a-faad60c86b2e.png)
# 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
// ESM
import { getPort, checkPort, getRandomPort, waitForPort } from 'get-port-please'
// CommonJS
const { getPort, checkPort, getRandomPort, waitForPort } = require('get-port-please')
```
```ts
getPort(options?: GetPortOptions): Promise<number>
checkPort(port: number, host?: string): Promise<number | false>
waitForPort(port: number, options): Promise<number | false>
```
Try sequence is: port > ports > memo > random
## Options
```ts
interface GetPortOptions {
name?: string
random?: boolean
port?: number
portRange?: [from: number, to: number]
ports?: number[]
host?: string
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.
### `portRange`
Alternative port range to check. Deefault is `[3000,3100]`
### `host`
The host to check. Default is `process.env.HOST` otherwise all available hosts will be checked.
### `memoDir` / `memoName`
Options passed to [fs-memo](https://github.com/unjs/fs-memo)
- Default dir: `node_modules/get-port/dist`
- Defalt name: `.get-port`
## License
MIT
-219
View File
@@ -1,219 +0,0 @@
'use strict';
Object.defineProperty(exports, '__esModule', { value: true });
const net = require('net');
const os = require('os');
const fsMemo = require('fs-memo');
const unsafePorts = /* @__PURE__ */ new Set([
1,
7,
9,
11,
13,
15,
17,
19,
20,
21,
22,
23,
25,
37,
42,
43,
53,
69,
77,
79,
87,
95,
101,
102,
103,
104,
109,
110,
111,
113,
115,
117,
119,
123,
135,
137,
139,
143,
161,
179,
389,
427,
465,
512,
513,
514,
515,
526,
530,
531,
532,
540,
548,
554,
556,
563,
587,
601,
636,
989,
990,
993,
995,
1719,
1720,
1723,
2049,
3659,
4045,
5060,
5061,
6e3,
6566,
6665,
6666,
6667,
6668,
6669,
6697,
10080
]);
function isUnsafePort(port) {
return unsafePorts.has(port);
}
function isSafePort(port) {
return !isUnsafePort(port);
}
async function getPort(config) {
if (typeof config === "number" || typeof config === "string") {
config = { port: parseInt(config + "") };
}
const options = {
name: "default",
random: false,
port: parseInt(process.env.PORT || "") || 3e3,
ports: [],
portRange: [3e3, 3100],
host: void 0,
memoName: "port",
...config
};
if (options.random) {
return getRandomPort(options.host);
}
const portsToCheck = [
options.port,
...options.ports,
...generateRange(options.portRange[0], options.portRange[1])
].filter((port) => port && isSafePort(port));
const memoOptions = { name: options.memoName, dir: options.memoDir };
const memoKey = "port_" + options.name;
const memo = await fsMemo.getMemo(memoOptions);
if (memo[memoKey]) {
portsToCheck.push(memo[memoKey]);
}
const availablePort = await findPort(portsToCheck, options.host);
await fsMemo.setMemo({ [memoKey]: availablePort }, memoOptions);
return availablePort;
}
async function getRandomPort(host) {
const port = await checkPort(0, host);
if (port === false) {
throw new Error("Unable to obtain an available random port number!");
}
return port;
}
async function waitForPort(port, opts = {}) {
const delay = opts.delay || 500;
const retries = opts.retries || 4;
for (let i = retries; i > 0; i--) {
if (await checkPort(port, opts.host) === false) {
return;
}
await new Promise((resolve) => setTimeout(resolve, delay));
}
throw new Error(`Timeout waiting for port ${port} after ${retries} retries with ${delay}ms interval.`);
}
async function checkPort(port, host = process.env.HOST) {
if (!host) {
host = getLocalHosts([void 0, "0.0.0.0"]);
}
if (!Array.isArray(host)) {
return _checkPort(port, host);
}
for (const _host of host) {
const _port = await _checkPort(port, _host);
if (_port === false) {
return false;
}
if (port === 0 && _port !== 0) {
port = _port;
}
}
return port;
}
function generateRange(from, to) {
if (to < from) {
return [];
}
const r = [];
for (let i = from; i < to; i++) {
r.push(i);
}
return r;
}
function _checkPort(port, host) {
return new Promise((resolve) => {
const server = net.createServer();
server.unref();
server.on("error", (err) => {
if (err.code === "EINVAL" || err.code === "EADDRNOTAVAIL") {
resolve(port !== 0 && isSafePort(port) && port);
} else {
resolve(false);
}
});
server.listen({ port, host }, () => {
const { port: port2 } = server.address();
server.close(() => {
resolve(isSafePort(port2) && port2);
});
});
});
}
function getLocalHosts(additional) {
const hosts = new Set(additional);
for (const _interface of Object.values(os.networkInterfaces())) {
for (const config of _interface) {
hosts.add(config.address);
}
}
return Array.from(hosts);
}
async function findPort(ports, host) {
for (const port of ports) {
const r = await checkPort(port, host);
if (r) {
return r;
}
}
return getRandomPort(host);
}
exports.checkPort = checkPort;
exports.getPort = getPort;
exports.getRandomPort = getRandomPort;
exports.isSafePort = isSafePort;
exports.isUnsafePort = isUnsafePort;
exports.waitForPort = waitForPort;
-27
View File
@@ -1,27 +0,0 @@
declare function isUnsafePort(port: number): boolean;
declare function isSafePort(port: number): boolean;
interface GetPortOptions {
name: string;
random: boolean;
port: number;
ports: number[];
portRange: [from: number, to: number];
host: string;
memoDir: string;
memoName: string;
}
declare type GetPortInput = Partial<GetPortOptions> | number | string;
declare type HostAddress = undefined | string;
declare type PortNumber = number;
declare function getPort(config?: GetPortInput): Promise<PortNumber>;
declare function getRandomPort(host?: HostAddress): Promise<number>;
interface WaitForPortOptions {
host?: HostAddress;
delay?: number;
retries?: number;
}
declare function waitForPort(port: PortNumber, opts?: WaitForPortOptions): Promise<void>;
declare function checkPort(port: PortNumber, host?: HostAddress | HostAddress[]): Promise<PortNumber | false>;
export { GetPortInput, GetPortOptions, HostAddress, PortNumber, WaitForPortOptions, checkPort, getPort, getRandomPort, isSafePort, isUnsafePort, waitForPort };
-310
View File
@@ -1,310 +0,0 @@
'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;
-210
View File
@@ -1,210 +0,0 @@
import { createServer } from 'net';
import { networkInterfaces } from 'os';
import { getMemo, setMemo } from 'fs-memo';
const unsafePorts = /* @__PURE__ */ new Set([
1,
7,
9,
11,
13,
15,
17,
19,
20,
21,
22,
23,
25,
37,
42,
43,
53,
69,
77,
79,
87,
95,
101,
102,
103,
104,
109,
110,
111,
113,
115,
117,
119,
123,
135,
137,
139,
143,
161,
179,
389,
427,
465,
512,
513,
514,
515,
526,
530,
531,
532,
540,
548,
554,
556,
563,
587,
601,
636,
989,
990,
993,
995,
1719,
1720,
1723,
2049,
3659,
4045,
5060,
5061,
6e3,
6566,
6665,
6666,
6667,
6668,
6669,
6697,
10080
]);
function isUnsafePort(port) {
return unsafePorts.has(port);
}
function isSafePort(port) {
return !isUnsafePort(port);
}
async function getPort(config) {
if (typeof config === "number" || typeof config === "string") {
config = { port: parseInt(config + "") };
}
const options = {
name: "default",
random: false,
port: parseInt(process.env.PORT || "") || 3e3,
ports: [],
portRange: [3e3, 3100],
host: void 0,
memoName: "port",
...config
};
if (options.random) {
return getRandomPort(options.host);
}
const portsToCheck = [
options.port,
...options.ports,
...generateRange(options.portRange[0], options.portRange[1])
].filter((port) => port && isSafePort(port));
const memoOptions = { name: options.memoName, dir: options.memoDir };
const memoKey = "port_" + options.name;
const memo = await getMemo(memoOptions);
if (memo[memoKey]) {
portsToCheck.push(memo[memoKey]);
}
const availablePort = await findPort(portsToCheck, options.host);
await setMemo({ [memoKey]: availablePort }, memoOptions);
return availablePort;
}
async function getRandomPort(host) {
const port = await checkPort(0, host);
if (port === false) {
throw new Error("Unable to obtain an available random port number!");
}
return port;
}
async function waitForPort(port, opts = {}) {
const delay = opts.delay || 500;
const retries = opts.retries || 4;
for (let i = retries; i > 0; i--) {
if (await checkPort(port, opts.host) === false) {
return;
}
await new Promise((resolve) => setTimeout(resolve, delay));
}
throw new Error(`Timeout waiting for port ${port} after ${retries} retries with ${delay}ms interval.`);
}
async function checkPort(port, host = process.env.HOST) {
if (!host) {
host = getLocalHosts([void 0, "0.0.0.0"]);
}
if (!Array.isArray(host)) {
return _checkPort(port, host);
}
for (const _host of host) {
const _port = await _checkPort(port, _host);
if (_port === false) {
return false;
}
if (port === 0 && _port !== 0) {
port = _port;
}
}
return port;
}
function generateRange(from, to) {
if (to < from) {
return [];
}
const r = [];
for (let i = from; i < to; i++) {
r.push(i);
}
return r;
}
function _checkPort(port, host) {
return new Promise((resolve) => {
const server = createServer();
server.unref();
server.on("error", (err) => {
if (err.code === "EINVAL" || err.code === "EADDRNOTAVAIL") {
resolve(port !== 0 && isSafePort(port) && port);
} else {
resolve(false);
}
});
server.listen({ port, host }, () => {
const { port: port2 } = server.address();
server.close(() => {
resolve(isSafePort(port2) && port2);
});
});
});
}
function getLocalHosts(additional) {
const hosts = new Set(additional);
for (const _interface of Object.values(networkInterfaces())) {
for (const config of _interface) {
hosts.add(config.address);
}
}
return Array.from(hosts);
}
async function findPort(ports, host) {
for (const port of ports) {
const r = await checkPort(port, host);
if (r) {
return r;
}
}
return getRandomPort(host);
}
export { checkPort, getPort, getRandomPort, isSafePort, isUnsafePort, waitForPort };
-73
View File
@@ -1,73 +0,0 @@
{
"_args": [
[
"get-port-please@2.5.0",
"/home/node/nuxt"
]
],
"_from": "get-port-please@2.5.0",
"_id": "get-port-please@2.5.0",
"_inBundle": false,
"_integrity": "sha512-NblPebBznYARC1R2r1qmusbJAAgBr954gWhEZgwTerzR8r3ud6U5PI1SG4Lue43r87aikPPjObs85VieIDK99A==",
"_location": "/get-port-please",
"_phantomChildren": {},
"_requested": {
"type": "version",
"registry": true,
"raw": "get-port-please@2.5.0",
"name": "get-port-please",
"escapedName": "get-port-please",
"rawSpec": "2.5.0",
"saveSpec": null,
"fetchSpec": "2.5.0"
},
"_requiredBy": [
"/@nuxt/loading-screen"
],
"_resolved": "https://registry.npmjs.org/get-port-please/-/get-port-please-2.5.0.tgz",
"_spec": "2.5.0",
"_where": "/home/node/nuxt",
"bugs": {
"url": "https://github.com/unjs/get-port-please/issues"
},
"dependencies": {
"fs-memo": "^1.2.0"
},
"description": "Get an available TCP port to listen",
"devDependencies": {
"@nuxtjs/eslint-config-typescript": "latest",
"@types/node": "latest",
"c8": "latest",
"eslint": "latest",
"standard-version": "latest",
"typescript": "latest",
"unbuild": "latest",
"vitest": "^0.5.5"
},
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.cjs"
}
},
"files": [
"dist"
],
"homepage": "https://github.com/unjs/get-port-please#readme",
"license": "MIT",
"main": "./dist/index.cjs",
"name": "get-port-please",
"packageManager": "pnpm@6.32.3",
"repository": {
"type": "git",
"url": "git+https://github.com/unjs/get-port-please.git"
},
"scripts": {
"build": "unbuild",
"lint": "eslint --ext ts .",
"release": "pnpm build && standard-version && pnpm publish && git push --follow-tags",
"test": "pnpm lint && vitest run"
},
"types": "./dist/index.d.ts",
"version": "2.5.0"
}