拿掉 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
-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 };