4181 lines
152 KiB
JavaScript
4181 lines
152 KiB
JavaScript
var __bare_os_bundle_exports__ = (() => {
|
|
var __create = Object.create;
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __getProtoOf = Object.getPrototypeOf;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
}) : x)(function(x) {
|
|
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
});
|
|
var __commonJS = (cb, mod) => function __require2() {
|
|
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
};
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
// If the importer is in node compatibility mode or this is not an ESM
|
|
// file that has been converted to a CommonJS file using a Babel-
|
|
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
mod
|
|
));
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
|
|
// ../../node_modules/bare-events/lib/errors.js
|
|
var require_errors = __commonJS({
|
|
"../../node_modules/bare-events/lib/errors.js"(exports, module) {
|
|
module.exports = class EventEmitterError extends Error {
|
|
constructor(msg, code, fn = EventEmitterError, opts) {
|
|
super(`${code}: ${msg}`, opts);
|
|
this.code = code;
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this, fn);
|
|
}
|
|
}
|
|
get name() {
|
|
return "EventEmitterError";
|
|
}
|
|
static OPERATION_ABORTED(cause, msg = "Operation aborted") {
|
|
return new EventEmitterError(msg, "OPERATION_ABORTED", EventEmitterError.OPERATION_ABORTED, {
|
|
cause
|
|
});
|
|
}
|
|
static UNHANDLED_ERROR(cause, msg = "Unhandled error") {
|
|
return new EventEmitterError(msg, "UNHANDLED_ERROR", EventEmitterError.UNHANDLED_ERROR, {
|
|
cause
|
|
});
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-events/index.js
|
|
var require_bare_events = __commonJS({
|
|
"../../node_modules/bare-events/index.js"(exports, module) {
|
|
var errors = require_errors();
|
|
var EventListener = class {
|
|
constructor() {
|
|
this.list = [];
|
|
this.count = 0;
|
|
}
|
|
append(ctx, name, fn, once) {
|
|
this.count++;
|
|
ctx.emit("newListener", name, fn);
|
|
this.list.push([fn, once]);
|
|
}
|
|
prepend(ctx, name, fn, once) {
|
|
this.count++;
|
|
ctx.emit("newListener", name, fn);
|
|
this.list.unshift([fn, once]);
|
|
}
|
|
remove(ctx, name, fn) {
|
|
for (let i = 0, n = this.list.length; i < n; i++) {
|
|
const l = this.list[i];
|
|
if (l[0] === fn) {
|
|
this.list.splice(i, 1);
|
|
if (this.count === 1) delete ctx._events[name];
|
|
ctx.emit("removeListener", name, fn);
|
|
this.count--;
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
removeAll(ctx, name) {
|
|
const list = [...this.list];
|
|
this.list = [];
|
|
if (this.count === list.length) delete ctx._events[name];
|
|
for (let i = list.length - 1; i >= 0; i--) {
|
|
ctx.emit("removeListener", name, list[i][0]);
|
|
}
|
|
this.count -= list.length;
|
|
}
|
|
emit(ctx, name, ...args) {
|
|
const list = [...this.list];
|
|
for (let i = 0, n = list.length; i < n; i++) {
|
|
const l = list[i];
|
|
if (l[1] === true) this.remove(ctx, name, l[0]);
|
|
Reflect.apply(l[0], ctx, args);
|
|
}
|
|
return list.length > 0;
|
|
}
|
|
};
|
|
function appendListener(ctx, name, fn, once) {
|
|
if (ctx._events === void 0) ctx._events = /* @__PURE__ */ Object.create(null);
|
|
const e = ctx._events[name] || (ctx._events[name] = new EventListener());
|
|
e.append(ctx, name, fn, once);
|
|
return ctx;
|
|
}
|
|
function prependListener(ctx, name, fn, once) {
|
|
if (ctx._events === void 0) ctx._events = /* @__PURE__ */ Object.create(null);
|
|
const e = ctx._events[name] || (ctx._events[name] = new EventListener());
|
|
e.prepend(ctx, name, fn, once);
|
|
return ctx;
|
|
}
|
|
function removeListener(ctx, name, fn) {
|
|
if (ctx._events === void 0) return ctx;
|
|
const e = ctx._events[name];
|
|
if (e !== void 0) e.remove(ctx, name, fn);
|
|
return ctx;
|
|
}
|
|
function throwUnhandledError(...args) {
|
|
let err;
|
|
if (args.length > 0) err = args[0];
|
|
if (err instanceof Error === false) err = errors.UNHANDLED_ERROR(err);
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(err, exports.prototype.emit);
|
|
}
|
|
queueMicrotask(() => {
|
|
throw err;
|
|
});
|
|
}
|
|
module.exports = exports = class EventEmitter {
|
|
constructor() {
|
|
this._events = /* @__PURE__ */ Object.create(null);
|
|
}
|
|
addListener(name, fn) {
|
|
return appendListener(this, name, fn, false);
|
|
}
|
|
addOnceListener(name, fn) {
|
|
return appendListener(this, name, fn, true);
|
|
}
|
|
prependListener(name, fn) {
|
|
return prependListener(this, name, fn, false);
|
|
}
|
|
prependOnceListener(name, fn) {
|
|
return prependListener(this, name, fn, true);
|
|
}
|
|
removeListener(name, fn) {
|
|
return removeListener(this, name, fn);
|
|
}
|
|
on(name, fn) {
|
|
return appendListener(this, name, fn, false);
|
|
}
|
|
once(name, fn) {
|
|
return appendListener(this, name, fn, true);
|
|
}
|
|
off(name, fn) {
|
|
return removeListener(this, name, fn);
|
|
}
|
|
emit(name, ...args) {
|
|
if (name === "error" && this._events !== void 0 && this._events.error === void 0) {
|
|
throwUnhandledError(...args);
|
|
}
|
|
if (this._events === void 0) return false;
|
|
const e = this._events[name];
|
|
return e === void 0 ? false : e.emit(this, name, ...args);
|
|
}
|
|
listeners(name) {
|
|
if (this._events === void 0) return [];
|
|
const e = this._events[name];
|
|
return e === void 0 ? [] : [...e.list];
|
|
}
|
|
listenerCount(name) {
|
|
if (this._events === void 0) return 0;
|
|
const e = this._events[name];
|
|
return e === void 0 ? 0 : e.list.length;
|
|
}
|
|
getMaxListeners() {
|
|
return EventEmitter.defaultMaxListeners;
|
|
}
|
|
setMaxListeners(n) {
|
|
}
|
|
removeAllListeners(name) {
|
|
if (arguments.length === 0) {
|
|
for (const key of Reflect.ownKeys(this._events)) {
|
|
if (key === "removeListener") continue;
|
|
this.removeAllListeners(key);
|
|
}
|
|
this.removeAllListeners("removeListener");
|
|
} else {
|
|
const e = this._events[name];
|
|
if (e !== void 0) e.removeAll(this, name);
|
|
}
|
|
return this;
|
|
}
|
|
};
|
|
exports.EventEmitter = exports;
|
|
exports.errors = errors;
|
|
exports.defaultMaxListeners = 10;
|
|
exports.on = function on(emitter, name, opts = {}) {
|
|
const { signal } = opts;
|
|
if (signal && signal.aborted) {
|
|
throw errors.OPERATION_ABORTED(signal.reason);
|
|
}
|
|
let error = null;
|
|
let done = false;
|
|
const events = [];
|
|
const promises = [];
|
|
if (name !== "error") emitter.on("error", onerror);
|
|
if (signal) signal.addEventListener("abort", onabort);
|
|
emitter.on(name, onevent);
|
|
return {
|
|
next() {
|
|
if (events.length) {
|
|
return Promise.resolve({ value: events.shift(), done: false });
|
|
}
|
|
if (error) {
|
|
const err = error;
|
|
error = null;
|
|
return Promise.reject(err);
|
|
}
|
|
if (done) return onclose();
|
|
return new Promise((resolve, reject) => promises.push({ resolve, reject }));
|
|
},
|
|
return() {
|
|
return onclose();
|
|
},
|
|
throw(err) {
|
|
return onerror(err);
|
|
},
|
|
[Symbol.asyncIterator]() {
|
|
return this;
|
|
}
|
|
};
|
|
function onevent(...args) {
|
|
if (promises.length) {
|
|
promises.shift().resolve({ value: args, done: false });
|
|
} else {
|
|
events.push(args);
|
|
}
|
|
}
|
|
function onerror(err) {
|
|
emitter.off(name, onevent).off("error", onerror);
|
|
if (promises.length) {
|
|
promises.shift().reject(err);
|
|
} else {
|
|
error = err;
|
|
}
|
|
return Promise.resolve({ done: true });
|
|
}
|
|
function onabort() {
|
|
signal.removeEventListener("abort", onabort);
|
|
onerror(errors.OPERATION_ABORTED(signal.reason));
|
|
}
|
|
function onclose() {
|
|
emitter.off(name, onevent);
|
|
if (name !== "error") emitter.off("error", onerror);
|
|
if (signal) signal.removeEventListener("abort", onabort);
|
|
done = true;
|
|
if (promises.length) promises.shift().resolve({ done: true });
|
|
return Promise.resolve({ done: true });
|
|
}
|
|
};
|
|
exports.once = function once(emitter, name, opts = {}) {
|
|
const { signal } = opts;
|
|
if (signal && signal.aborted) {
|
|
return Promise.reject(errors.OPERATION_ABORTED(signal.reason));
|
|
}
|
|
return new Promise((resolve, reject) => {
|
|
if (name !== "error") emitter.on("error", onerror);
|
|
if (signal) signal.addEventListener("abort", onabort);
|
|
emitter.once(name, onevent);
|
|
function onevent(...args) {
|
|
if (name !== "error") emitter.off("error", onerror);
|
|
if (signal) signal.removeEventListener("abort", onabort);
|
|
resolve(args);
|
|
}
|
|
function onerror(err) {
|
|
emitter.off(name, onevent);
|
|
if (name !== "error") emitter.off("error", onerror);
|
|
reject(err);
|
|
}
|
|
function onabort() {
|
|
signal.removeEventListener("abort", onabort);
|
|
onerror(errors.OPERATION_ABORTED(signal.reason));
|
|
}
|
|
});
|
|
};
|
|
exports.forward = function forward(from, to, names, opts = {}) {
|
|
if (typeof names === "string") names = [names];
|
|
const { emit = to.emit.bind(to) } = opts;
|
|
const listeners = names.map(
|
|
(name) => function onevent(...args) {
|
|
emit(name, ...args);
|
|
}
|
|
);
|
|
to.on("newListener", (name) => {
|
|
const i = names.indexOf(name);
|
|
if (i !== -1 && to.listenerCount(name) === 0) {
|
|
from.on(name, listeners[i]);
|
|
}
|
|
}).on("removeListener", (name) => {
|
|
const i = names.indexOf(name);
|
|
if (i !== -1 && to.listenerCount(name) === 0) {
|
|
from.off(name, listeners[i]);
|
|
}
|
|
});
|
|
};
|
|
exports.listenerCount = function listenerCount(emitter, name) {
|
|
return emitter.listenerCount(name);
|
|
};
|
|
exports.getMaxListeners = function getMaxListeners(emitter) {
|
|
if (typeof emitter.getMaxListeners === "function") {
|
|
return emitter.getMaxListeners();
|
|
}
|
|
return exports.defaultMaxListeners;
|
|
};
|
|
exports.setMaxListeners = function setMaxListeners(n, ...emitters) {
|
|
if (emitters.length === 0) exports.defaultMaxListeners = n;
|
|
else {
|
|
for (const emitter of emitters) {
|
|
if (typeof emitter.setMaxListeners === "function") {
|
|
emitter.setMaxListeners(n);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/b4a/index.js
|
|
var require_b4a = __commonJS({
|
|
"../../node_modules/b4a/index.js"(exports, module) {
|
|
function isBuffer(value) {
|
|
return Buffer.isBuffer(value) || value instanceof Uint8Array;
|
|
}
|
|
function isEncoding(encoding) {
|
|
return Buffer.isEncoding(encoding);
|
|
}
|
|
function alloc(size, fill2, encoding) {
|
|
return Buffer.alloc(size, fill2, encoding);
|
|
}
|
|
function allocUnsafe(size) {
|
|
return Buffer.allocUnsafe(size);
|
|
}
|
|
function allocUnsafeSlow(size) {
|
|
return Buffer.allocUnsafeSlow(size);
|
|
}
|
|
function byteLength(string, encoding) {
|
|
return Buffer.byteLength(string, encoding);
|
|
}
|
|
function compare(a, b) {
|
|
return Buffer.compare(a, b);
|
|
}
|
|
function concat(buffers, totalLength) {
|
|
return Buffer.concat(buffers, totalLength);
|
|
}
|
|
function copy(source, target, targetStart, start, end) {
|
|
return toBuffer(source).copy(target, targetStart, start, end);
|
|
}
|
|
function equals(a, b) {
|
|
return toBuffer(a).equals(b);
|
|
}
|
|
function fill(buffer, value, offset, end, encoding) {
|
|
return toBuffer(buffer).fill(value, offset, end, encoding);
|
|
}
|
|
function from(value, encodingOrOffset, length) {
|
|
return Buffer.from(value, encodingOrOffset, length);
|
|
}
|
|
function includes(buffer, value, byteOffset, encoding) {
|
|
return toBuffer(buffer).includes(value, byteOffset, encoding);
|
|
}
|
|
function indexOf(buffer, value, byfeOffset, encoding) {
|
|
return toBuffer(buffer).indexOf(value, byfeOffset, encoding);
|
|
}
|
|
function lastIndexOf(buffer, value, byteOffset, encoding) {
|
|
return toBuffer(buffer).lastIndexOf(value, byteOffset, encoding);
|
|
}
|
|
function swap16(buffer) {
|
|
return toBuffer(buffer).swap16();
|
|
}
|
|
function swap32(buffer) {
|
|
return toBuffer(buffer).swap32();
|
|
}
|
|
function swap64(buffer) {
|
|
return toBuffer(buffer).swap64();
|
|
}
|
|
function toBuffer(buffer) {
|
|
if (Buffer.isBuffer(buffer)) return buffer;
|
|
return Buffer.from(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
}
|
|
function toString(buffer, encoding, start, end) {
|
|
return toBuffer(buffer).toString(encoding, start, end);
|
|
}
|
|
function write(buffer, string, offset, length, encoding) {
|
|
return toBuffer(buffer).write(string, offset, length, encoding);
|
|
}
|
|
function readDoubleBE(buffer, offset) {
|
|
return toBuffer(buffer).readDoubleBE(offset);
|
|
}
|
|
function readDoubleLE(buffer, offset) {
|
|
return toBuffer(buffer).readDoubleLE(offset);
|
|
}
|
|
function readFloatBE(buffer, offset) {
|
|
return toBuffer(buffer).readFloatBE(offset);
|
|
}
|
|
function readFloatLE(buffer, offset) {
|
|
return toBuffer(buffer).readFloatLE(offset);
|
|
}
|
|
function readInt32BE(buffer, offset) {
|
|
return toBuffer(buffer).readInt32BE(offset);
|
|
}
|
|
function readInt32LE(buffer, offset) {
|
|
return toBuffer(buffer).readInt32LE(offset);
|
|
}
|
|
function readUInt32BE(buffer, offset) {
|
|
return toBuffer(buffer).readUInt32BE(offset);
|
|
}
|
|
function readUInt32LE(buffer, offset) {
|
|
return toBuffer(buffer).readUInt32LE(offset);
|
|
}
|
|
function writeDoubleBE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeDoubleBE(value, offset);
|
|
}
|
|
function writeDoubleLE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeDoubleLE(value, offset);
|
|
}
|
|
function writeFloatBE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeFloatBE(value, offset);
|
|
}
|
|
function writeFloatLE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeFloatLE(value, offset);
|
|
}
|
|
function writeInt32BE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeInt32BE(value, offset);
|
|
}
|
|
function writeInt32LE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeInt32LE(value, offset);
|
|
}
|
|
function writeUInt32BE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeUInt32BE(value, offset);
|
|
}
|
|
function writeUInt32LE(buffer, value, offset) {
|
|
return toBuffer(buffer).writeUInt32LE(value, offset);
|
|
}
|
|
module.exports = {
|
|
isBuffer,
|
|
isEncoding,
|
|
alloc,
|
|
allocUnsafe,
|
|
allocUnsafeSlow,
|
|
byteLength,
|
|
compare,
|
|
concat,
|
|
copy,
|
|
equals,
|
|
fill,
|
|
from,
|
|
includes,
|
|
indexOf,
|
|
lastIndexOf,
|
|
swap16,
|
|
swap32,
|
|
swap64,
|
|
toBuffer,
|
|
toString,
|
|
write,
|
|
readDoubleBE,
|
|
readDoubleLE,
|
|
readFloatBE,
|
|
readFloatLE,
|
|
readInt32BE,
|
|
readInt32LE,
|
|
readUInt32BE,
|
|
readUInt32LE,
|
|
writeDoubleBE,
|
|
writeDoubleLE,
|
|
writeFloatBE,
|
|
writeFloatLE,
|
|
writeInt32BE,
|
|
writeInt32LE,
|
|
writeUInt32BE,
|
|
writeUInt32LE
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-semver/lib/constants.js
|
|
var require_constants = __commonJS({
|
|
"../../node_modules/bare-semver/lib/constants.js"(exports, module) {
|
|
module.exports = {
|
|
EQ: 1,
|
|
LT: 2,
|
|
LTE: 3,
|
|
GT: 4,
|
|
GTE: 5
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-semver/lib/errors.js
|
|
var require_errors2 = __commonJS({
|
|
"../../node_modules/bare-semver/lib/errors.js"(exports, module) {
|
|
module.exports = class SemVerError extends Error {
|
|
constructor(msg, code, fn = SemVerError) {
|
|
super(`${code}: ${msg}`);
|
|
this.code = code;
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this, fn);
|
|
}
|
|
}
|
|
get name() {
|
|
return "SemVerError";
|
|
}
|
|
static INVALID_VERSION(msg, fn = SemVerError.INVALID_VERSION) {
|
|
return new SemVerError(msg, "INVALID_VERSION", fn);
|
|
}
|
|
static INVALID_RANGE(msg, fn = SemVerError.INVALID_RANGE) {
|
|
return new SemVerError(msg, "INVALID_RANGE", fn);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-semver/lib/version.js
|
|
var require_version = __commonJS({
|
|
"../../node_modules/bare-semver/lib/version.js"(exports, module) {
|
|
var errors = require_errors2();
|
|
var Version = class {
|
|
constructor(major, minor, patch, opts = {}) {
|
|
const { prerelease = [], build = [] } = opts;
|
|
this.major = major;
|
|
this.minor = minor;
|
|
this.patch = patch;
|
|
this.prerelease = prerelease;
|
|
this.build = build;
|
|
}
|
|
compare(version) {
|
|
return exports.compare(this, version);
|
|
}
|
|
toString() {
|
|
let result = `${this.major}.${this.minor}.${this.patch}`;
|
|
if (this.prerelease.length) {
|
|
result += "-" + this.prerelease.join(".");
|
|
}
|
|
if (this.build.length) {
|
|
result += "+" + this.build.join(".");
|
|
}
|
|
return result;
|
|
}
|
|
};
|
|
module.exports = exports = Version;
|
|
exports.parse = function parse(input, state = { position: 0, partial: false, range: false }) {
|
|
let i = state.position;
|
|
let c;
|
|
const unexpected = (expected) => {
|
|
let msg;
|
|
if (i >= input.length) {
|
|
msg = `Unexpected end of input in '${input}'`;
|
|
} else {
|
|
msg = `Unexpected token '${input[i]}' in '${input}' at position ${i}`;
|
|
}
|
|
if (expected) msg += `, ${expected}`;
|
|
throw errors.INVALID_VERSION(msg, unexpected);
|
|
};
|
|
const components = [0, 0, 0];
|
|
let k = 0;
|
|
while (k < 3) {
|
|
c = input[i];
|
|
if (k > 0) {
|
|
if (c === ".") c = input[++i];
|
|
else if (state.range) break;
|
|
else unexpected("expected '.'");
|
|
}
|
|
if (c === "0") {
|
|
i++;
|
|
k++;
|
|
} else if (c >= "1" && c <= "9") {
|
|
let j = 0;
|
|
do
|
|
c = input[i + ++j];
|
|
while (c >= "0" && c <= "9");
|
|
components[k++] = parseInt(input.substring(i, i + j));
|
|
i += j;
|
|
} else unexpected("expected /[0-9]/");
|
|
}
|
|
const prerelease = [];
|
|
if (k === 3 && input[i] === "-") {
|
|
i++;
|
|
while (true) {
|
|
c = input[i];
|
|
let tag = "";
|
|
let j = 0;
|
|
while (c >= "0" && c <= "9") c = input[i + ++j];
|
|
let isNumeric = false;
|
|
if (j) {
|
|
tag += input.substring(i, i + j);
|
|
c = input[i += j];
|
|
isNumeric = tag[0] !== "0" || tag.length === 1;
|
|
}
|
|
j = 0;
|
|
while (c >= "0" && c <= "9" || c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c === "-")
|
|
c = input[i + ++j];
|
|
if (j) {
|
|
tag += input.substring(i, i + j);
|
|
c = input[i += j];
|
|
} else if (!isNumeric) unexpected("expected /[a-zA-Z-]/");
|
|
prerelease.push(tag);
|
|
if (c === ".") c = input[++i];
|
|
else break;
|
|
}
|
|
}
|
|
const build = [];
|
|
if (k === 3 && input[i] === "+") {
|
|
i++;
|
|
while (true) {
|
|
c = input[i];
|
|
let tag = "";
|
|
let j = 0;
|
|
while (c >= "0" && c <= "9" || c >= "a" && c <= "z" || c >= "A" && c <= "Z" || c === "-")
|
|
c = input[i + ++j];
|
|
if (j) {
|
|
tag += input.substring(i, i + j);
|
|
c = input[i += j];
|
|
} else unexpected("expected /[0-9a-zA-Z-]/");
|
|
build.push(tag);
|
|
if (c === ".") c = input[++i];
|
|
else break;
|
|
}
|
|
}
|
|
if (i < input.length && state.partial === false) {
|
|
unexpected("expected end of input");
|
|
}
|
|
state.position = i;
|
|
return new Version(...components, { prerelease, build });
|
|
};
|
|
var integer = /^[0-9]+$/;
|
|
exports.compare = function compare(a, b) {
|
|
if (a.major > b.major) return 1;
|
|
if (a.major < b.major) return -1;
|
|
if (a.minor > b.minor) return 1;
|
|
if (a.minor < b.minor) return -1;
|
|
if (a.patch > b.patch) return 1;
|
|
if (a.patch < b.patch) return -1;
|
|
if (a.prerelease.length === 0) return b.prerelease.length === 0 ? 0 : 1;
|
|
if (b.prerelease.length === 0) return -1;
|
|
let i = 0;
|
|
do {
|
|
let x = a.prerelease[i];
|
|
let y = b.prerelease[i];
|
|
if (x === void 0) return y === void 0 ? 0 : -1;
|
|
if (y === void 0) return 1;
|
|
if (x === y) continue;
|
|
const xInt = integer.test(x);
|
|
const yInt = integer.test(y);
|
|
if (xInt && yInt) {
|
|
x = +x;
|
|
y = +y;
|
|
} else {
|
|
if (xInt) return -1;
|
|
if (yInt) return 1;
|
|
}
|
|
return x > y ? 1 : -1;
|
|
} while (++i);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-semver/lib/comparator.js
|
|
var require_comparator = __commonJS({
|
|
"../../node_modules/bare-semver/lib/comparator.js"(exports, module) {
|
|
var constants = require_constants();
|
|
var symbols = {
|
|
[constants.EQ]: "=",
|
|
[constants.LT]: "<",
|
|
[constants.LTE]: "<=",
|
|
[constants.GT]: ">",
|
|
[constants.GTE]: ">="
|
|
};
|
|
module.exports = class Comparator {
|
|
constructor(operator, version) {
|
|
this.operator = operator;
|
|
this.version = version;
|
|
}
|
|
test(version) {
|
|
const result = version.compare(this.version);
|
|
switch (this.operator) {
|
|
case constants.LT:
|
|
return result < 0;
|
|
case constants.LTE:
|
|
return result <= 0;
|
|
case constants.GT:
|
|
return result > 0;
|
|
case constants.GTE:
|
|
return result >= 0;
|
|
default:
|
|
return result === 0;
|
|
}
|
|
}
|
|
toString() {
|
|
return symbols[this.operator] + this.version;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-semver/lib/range.js
|
|
var require_range = __commonJS({
|
|
"../../node_modules/bare-semver/lib/range.js"(exports, module) {
|
|
var constants = require_constants();
|
|
var errors = require_errors2();
|
|
var Version = require_version();
|
|
var Comparator = require_comparator();
|
|
var Range = class {
|
|
constructor(comparators = []) {
|
|
this.comparators = comparators;
|
|
}
|
|
test(version) {
|
|
for (const set of this.comparators) {
|
|
let matches = true;
|
|
for (const comparator of set) {
|
|
if (comparator.test(version)) continue;
|
|
matches = false;
|
|
break;
|
|
}
|
|
if (matches) return true;
|
|
}
|
|
return false;
|
|
}
|
|
toString() {
|
|
let result = "";
|
|
let first = true;
|
|
for (const set of this.comparators) {
|
|
if (first) first = false;
|
|
else result += " || ";
|
|
result += set.join(" ");
|
|
}
|
|
return result;
|
|
}
|
|
};
|
|
module.exports = exports = Range;
|
|
exports.parse = function parse(input, state = { position: 0, partial: false }) {
|
|
let i = state.position;
|
|
let c;
|
|
const unexpected = (expected) => {
|
|
let msg;
|
|
if (i >= input.length) {
|
|
msg = `Unexpected end of input in '${input}'`;
|
|
} else {
|
|
msg = `Unexpected token '${input[i]}' in '${input}' at position ${i}`;
|
|
}
|
|
if (expected) msg += `, ${expected}`;
|
|
throw errors.INVALID_VERSION(msg, unexpected);
|
|
};
|
|
const comparators = [];
|
|
while (i < input.length) {
|
|
const set = [];
|
|
while (i < input.length) {
|
|
c = input[i];
|
|
let operator = constants.EQ;
|
|
if (c === "<") {
|
|
operator = constants.LT;
|
|
c = input[++i];
|
|
if (c === "=") {
|
|
operator = constants.LTE;
|
|
c = input[++i];
|
|
}
|
|
} else if (c === ">") {
|
|
operator = constants.GT;
|
|
c = input[++i];
|
|
if (c === "=") {
|
|
operator = constants.GTE;
|
|
c = input[++i];
|
|
}
|
|
} else if (c === "=") {
|
|
c = input[++i];
|
|
}
|
|
const state2 = { position: i, partial: true, range: true };
|
|
set.push(new Comparator(operator, Version.parse(input, state2)));
|
|
c = input[i = state2.position];
|
|
while (c === " ") c = input[++i];
|
|
if (c === "|" && input[i + 1] === "|") {
|
|
c = input[i += 2];
|
|
while (c === " ") c = input[++i];
|
|
break;
|
|
}
|
|
if (c && c !== "<" && c !== ">") unexpected("expected '||', '<', or '>'");
|
|
}
|
|
if (set.length) comparators.push(set);
|
|
}
|
|
if (i < input.length && state.partial === false) {
|
|
unexpected("expected end of input");
|
|
}
|
|
state.position = i;
|
|
return new Range(comparators);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-semver/index.js
|
|
var require_bare_semver = __commonJS({
|
|
"../../node_modules/bare-semver/index.js"(exports) {
|
|
exports.constants = require_constants();
|
|
exports.errors = require_errors2();
|
|
var Version = exports.Version = require_version();
|
|
var Range = exports.Range = require_range();
|
|
exports.Comparator = require_comparator();
|
|
exports.satisfies = function satisfies(version, range) {
|
|
if (typeof version === "string") version = Version.parse(version);
|
|
if (typeof range === "string") range = Range.parse(range);
|
|
return range.test(version);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-module-resolve/lib/errors.js
|
|
var require_errors3 = __commonJS({
|
|
"../../node_modules/bare-module-resolve/lib/errors.js"(exports, module) {
|
|
module.exports = class ModuleResolveError extends Error {
|
|
constructor(msg, code, fn = ModuleResolveError) {
|
|
super(`${code}: ${msg}`);
|
|
this.code = code;
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this, fn);
|
|
}
|
|
}
|
|
get name() {
|
|
return "ModuleResolveError";
|
|
}
|
|
static INVALID_MODULE_SPECIFIER(msg) {
|
|
return new ModuleResolveError(
|
|
msg,
|
|
"INVALID_MODULE_SPECIFIER",
|
|
ModuleResolveError.INVALID_MODULE_SPECIFIER
|
|
);
|
|
}
|
|
static INVALID_PACKAGE_TARGET(msg) {
|
|
return new ModuleResolveError(
|
|
msg,
|
|
"INVALID_PACKAGE_TARGET",
|
|
ModuleResolveError.INVALID_PACKAGE_TARGET
|
|
);
|
|
}
|
|
static PACKAGE_PATH_NOT_EXPORTED(msg) {
|
|
return new ModuleResolveError(
|
|
msg,
|
|
"PACKAGE_PATH_NOT_EXPORTED",
|
|
ModuleResolveError.PACKAGE_PATH_NOT_EXPORTED
|
|
);
|
|
}
|
|
static PACKAGE_IMPORT_NOT_DEFINED(msg) {
|
|
return new ModuleResolveError(
|
|
msg,
|
|
"PACKAGE_IMPORT_NOT_DEFINED",
|
|
ModuleResolveError.PACKAGE_IMPORT_NOT_DEFINED
|
|
);
|
|
}
|
|
static UNSUPPORTED_ENGINE(msg) {
|
|
return new ModuleResolveError(msg, "UNSUPPORTED_ENGINE", ModuleResolveError.UNSUPPORTED_ENGINE);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-module-resolve/index.js
|
|
var require_bare_module_resolve = __commonJS({
|
|
"../../node_modules/bare-module-resolve/index.js"(exports, module) {
|
|
var { satisfies } = require_bare_semver();
|
|
var errors = require_errors3();
|
|
module.exports = exports = function resolve(specifier, parentURL, opts, readPackage) {
|
|
if (typeof opts === "function") {
|
|
readPackage = opts;
|
|
opts = {};
|
|
} else if (typeof readPackage !== "function") {
|
|
readPackage = defaultReadPackage;
|
|
}
|
|
return {
|
|
*[Symbol.iterator]() {
|
|
const generator = exports.module(specifier, parentURL, opts);
|
|
let next = generator.next();
|
|
while (next.done !== true) {
|
|
const value = next.value;
|
|
if (value.package) {
|
|
next = generator.next(readPackage(value.package));
|
|
} else {
|
|
next = generator.next(yield value.resolution);
|
|
}
|
|
}
|
|
return next.value;
|
|
},
|
|
async *[Symbol.asyncIterator]() {
|
|
const generator = exports.module(specifier, parentURL, opts);
|
|
let next = generator.next();
|
|
while (next.done !== true) {
|
|
const value = next.value;
|
|
if (value.package) {
|
|
next = generator.next(await readPackage(value.package));
|
|
} else {
|
|
next = generator.next(yield value.resolution);
|
|
}
|
|
}
|
|
return next.value;
|
|
}
|
|
};
|
|
};
|
|
function defaultReadPackage() {
|
|
return null;
|
|
}
|
|
var UNRESOLVED = 0;
|
|
var YIELDED = 1;
|
|
var RESOLVED = YIELDED | 2;
|
|
exports.constants = {
|
|
UNRESOLVED,
|
|
YIELDED,
|
|
RESOLVED
|
|
};
|
|
exports.module = function* (specifier, parentURL, opts = {}) {
|
|
const { resolutions = null, imports = null } = opts;
|
|
if (exports.startsWithWindowsDriveLetter(specifier)) {
|
|
specifier = "/" + specifier;
|
|
}
|
|
let status;
|
|
if (resolutions) {
|
|
status = yield* exports.preresolved(specifier, resolutions, parentURL, opts);
|
|
if (status) return status;
|
|
}
|
|
status = yield* exports.url(specifier, parentURL, opts);
|
|
if (status) return status;
|
|
status = yield* exports.packageImports(specifier, parentURL, opts);
|
|
if (status) return status;
|
|
if (specifier === "." || specifier === ".." || specifier[0] === "/" || specifier[0] === "\\" || specifier.startsWith("./") || specifier.startsWith(".\\") || specifier.startsWith("../") || specifier.startsWith("..\\")) {
|
|
if (imports) {
|
|
status = yield* exports.packageImportsExports(specifier, imports, parentURL, true, opts);
|
|
if (status) return status;
|
|
}
|
|
status = yield* exports.deferred(specifier, opts);
|
|
if (status) return status;
|
|
status = yield* exports.file(specifier, parentURL, false, opts);
|
|
if (status === RESOLVED) return status;
|
|
return yield* exports.directory(specifier, parentURL, opts);
|
|
}
|
|
return yield* exports.package(specifier, parentURL, opts);
|
|
};
|
|
exports.url = function* (url, parentURL, opts = {}) {
|
|
const { imports = null, deferredProtocol = "deferred:", resolutions = null } = opts;
|
|
let resolution;
|
|
try {
|
|
resolution = new URL(url);
|
|
} catch {
|
|
return UNRESOLVED;
|
|
}
|
|
if (imports) {
|
|
const status = yield* exports.packageImportsExports(
|
|
resolution.href,
|
|
imports,
|
|
parentURL,
|
|
true,
|
|
opts
|
|
);
|
|
if (status) return status;
|
|
}
|
|
if (resolution.protocol === deferredProtocol) {
|
|
const specifier = resolution.pathname;
|
|
if (resolutions) {
|
|
const imports2 = resolutions[parentURL.href];
|
|
if (typeof imports2 === "object" && imports2 !== null) {
|
|
opts = {
|
|
...opts,
|
|
resolutions: { ...resolutions, [parentURL.href]: { ...imports2, [specifier]: null } }
|
|
};
|
|
}
|
|
}
|
|
return yield* exports.module(specifier, parentURL, opts);
|
|
}
|
|
if (resolution.protocol === "node:") {
|
|
const specifier = resolution.pathname;
|
|
if (specifier === "." || specifier === ".." || specifier[0] === "/" || specifier.startsWith("./") || specifier.startsWith("../")) {
|
|
throw errors.INVALID_MODULE_SPECIFIER(`Module specifier '${url}' is not a valid package name`);
|
|
}
|
|
return yield* exports.package(specifier, parentURL, opts);
|
|
}
|
|
const resolved = yield { resolution };
|
|
return resolved ? RESOLVED : YIELDED;
|
|
};
|
|
exports.preresolved = function* (specifier, resolutions, parentURL, opts = {}) {
|
|
const imports = resolutions[parentURL.href];
|
|
if (typeof imports === "object" && imports !== null) {
|
|
return yield* exports.packageImportsExports(specifier, imports, parentURL, true, opts);
|
|
}
|
|
return UNRESOLVED;
|
|
};
|
|
exports.deferred = function* (specifier, opts = {}) {
|
|
const { deferredProtocol = "deferred:", defer = [] } = opts;
|
|
if (defer.includes(specifier)) {
|
|
const resolved = yield { resolution: new URL(deferredProtocol + specifier) };
|
|
return resolved ? RESOLVED : YIELDED;
|
|
}
|
|
return UNRESOLVED;
|
|
};
|
|
exports.package = function* (packageSpecifier, parentURL, opts = {}) {
|
|
const { builtins = [] } = opts;
|
|
if (packageSpecifier === "") {
|
|
throw errors.INVALID_MODULE_SPECIFIER(
|
|
`Module specifier '${packageSpecifier}' is not a valid package name`
|
|
);
|
|
}
|
|
let packageName;
|
|
if (packageSpecifier[0] !== "@") {
|
|
packageName = packageSpecifier.split("/", 1).join();
|
|
} else {
|
|
if (!packageSpecifier.includes("/")) {
|
|
throw errors.INVALID_MODULE_SPECIFIER(
|
|
`Module specifier '${packageSpecifier}' is not a valid package name`
|
|
);
|
|
}
|
|
packageName = packageSpecifier.split("/", 2).join("/");
|
|
}
|
|
if (packageName[0] === "." || packageName.includes("\\") || packageName.includes("%")) {
|
|
throw errors.INVALID_MODULE_SPECIFIER(
|
|
`Module specifier '${packageSpecifier}' is not a valid package name`
|
|
);
|
|
}
|
|
let status;
|
|
status = yield* exports.builtinTarget(packageSpecifier, null, builtins, opts);
|
|
if (status) return status;
|
|
status = yield* exports.deferred(packageSpecifier, opts);
|
|
if (status) return status;
|
|
let packageSubpath = "." + packageSpecifier.substring(packageName.length);
|
|
status = yield* exports.packageSelf(packageName, packageSubpath, parentURL, opts);
|
|
if (status) return status;
|
|
parentURL = new URL(parentURL.href);
|
|
for (const packageURL of exports.lookupPackageRoot(packageName, parentURL)) {
|
|
const info = yield { package: packageURL };
|
|
if (info) {
|
|
if (info.engines) exports.validateEngines(packageURL, info.engines, opts);
|
|
if (info.exports) {
|
|
return yield* exports.packageExports(packageURL, packageSubpath, info.exports, opts);
|
|
}
|
|
if (packageSubpath === ".") {
|
|
if (typeof info.main === "string" && info.main !== "") {
|
|
packageSubpath = info.main;
|
|
} else {
|
|
return yield* exports.file("index", packageURL, true, opts);
|
|
}
|
|
}
|
|
status = yield* exports.file(packageSubpath, packageURL, false, opts);
|
|
if (status === RESOLVED) return status;
|
|
return yield* exports.directory(packageSubpath, packageURL, opts);
|
|
}
|
|
}
|
|
return UNRESOLVED;
|
|
};
|
|
exports.packageSelf = function* (packageName, packageSubpath, parentURL, opts = {}) {
|
|
for (const packageURL of exports.lookupPackageScope(parentURL, opts)) {
|
|
const info = yield { package: packageURL };
|
|
if (info) {
|
|
if (info.name !== packageName) return false;
|
|
if (info.exports) {
|
|
return yield* exports.packageExports(packageURL, packageSubpath, info.exports, opts);
|
|
}
|
|
if (packageSubpath === ".") {
|
|
if (typeof info.main === "string" && info.main !== "") {
|
|
packageSubpath = info.main;
|
|
} else {
|
|
return yield* exports.file("index", packageURL, true, opts);
|
|
}
|
|
}
|
|
const status = yield* exports.file(packageSubpath, packageURL, false, opts);
|
|
if (status === RESOLVED) return status;
|
|
return yield* exports.directory(packageSubpath, packageURL, opts);
|
|
}
|
|
}
|
|
return UNRESOLVED;
|
|
};
|
|
exports.packageExports = function* (packageURL, subpath, packageExports, opts = {}) {
|
|
if (subpath === ".") {
|
|
let mainExport;
|
|
if (typeof packageExports === "string" || Array.isArray(packageExports)) {
|
|
mainExport = packageExports;
|
|
} else if (typeof packageExports === "object" && packageExports !== null) {
|
|
const keys = Object.keys(packageExports);
|
|
if (keys.some((key) => key.startsWith("."))) {
|
|
if ("." in packageExports) mainExport = packageExports["."];
|
|
} else {
|
|
mainExport = packageExports;
|
|
}
|
|
}
|
|
if (mainExport) {
|
|
const status = yield* exports.packageTarget(packageURL, mainExport, null, false, opts);
|
|
if (status) return status;
|
|
}
|
|
} else if (typeof packageExports === "object" && packageExports !== null) {
|
|
const keys = Object.keys(packageExports);
|
|
if (keys.every((key) => key.startsWith("."))) {
|
|
const status = yield* exports.packageImportsExports(
|
|
subpath,
|
|
packageExports,
|
|
packageURL,
|
|
false,
|
|
opts
|
|
);
|
|
if (status) return status;
|
|
}
|
|
}
|
|
throw errors.PACKAGE_PATH_NOT_EXPORTED(
|
|
`Package subpath '${subpath}' is not defined by "exports" in '${packageURL}'`
|
|
);
|
|
};
|
|
exports.packageImports = function* (specifier, parentURL, opts = {}) {
|
|
const { imports = null } = opts;
|
|
if (specifier === "#" || specifier.startsWith("#/")) {
|
|
throw errors.INVALID_MODULE_SPECIFIER(
|
|
`Module specifier '${specifier}' is not a valid internal imports specifier`
|
|
);
|
|
}
|
|
for (const packageURL of exports.lookupPackageScope(parentURL, opts)) {
|
|
const info = yield { package: packageURL };
|
|
if (info) {
|
|
if (info.imports) {
|
|
const status = yield* exports.packageImportsExports(
|
|
specifier,
|
|
info.imports,
|
|
packageURL,
|
|
true,
|
|
opts
|
|
);
|
|
if (status) return status;
|
|
}
|
|
if (specifier.startsWith("#")) {
|
|
throw errors.PACKAGE_IMPORT_NOT_DEFINED(
|
|
`Package import specifier '${specifier}' is not defined by "imports" in '${packageURL}'`
|
|
);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
if (imports) {
|
|
const status = yield* exports.packageImportsExports(specifier, imports, parentURL, true, opts);
|
|
if (status) return status;
|
|
}
|
|
return UNRESOLVED;
|
|
};
|
|
exports.packageImportsExports = function* (matchKey, matchObject, packageURL, isImports, opts = {}) {
|
|
if (matchKey in matchObject && !matchKey.includes("*")) {
|
|
const target = matchObject[matchKey];
|
|
return yield* exports.packageTarget(packageURL, target, null, isImports, opts);
|
|
}
|
|
const expansionKeys = Object.keys(matchObject).filter((key) => key.includes("*")).sort(exports.patternKeyCompare);
|
|
for (const expansionKey of expansionKeys) {
|
|
const patternIndex = expansionKey.indexOf("*");
|
|
const patternBase = expansionKey.substring(0, patternIndex);
|
|
if (matchKey.startsWith(patternBase) && matchKey !== patternBase) {
|
|
const patternTrailer = expansionKey.substring(patternIndex + 1);
|
|
if (patternTrailer === "" || matchKey.endsWith(patternTrailer) && matchKey.length >= expansionKey.length) {
|
|
const target = matchObject[expansionKey];
|
|
const patternMatch = matchKey.substring(
|
|
patternBase.length,
|
|
matchKey.length - patternTrailer.length
|
|
);
|
|
return yield* exports.packageTarget(packageURL, target, patternMatch, isImports, opts);
|
|
}
|
|
}
|
|
}
|
|
return UNRESOLVED;
|
|
};
|
|
exports.validateEngines = function validateEngines(packageURL, packageEngines, opts = {}) {
|
|
const { engines = {} } = opts;
|
|
for (const [engine, range] of Object.entries(packageEngines)) {
|
|
if (engine in engines) {
|
|
const version = engines[engine];
|
|
if (!satisfies(version, range)) {
|
|
throw errors.UNSUPPORTED_ENGINE(
|
|
`Package not compatible with engine '${engine}' ${version}, requires range '${range}' defined by "engines" in '${packageURL}'`
|
|
);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
exports.patternKeyCompare = function patternKeyCompare(keyA, keyB) {
|
|
const patternIndexA = keyA.indexOf("*");
|
|
const patternIndexB = keyB.indexOf("*");
|
|
const baseLengthA = patternIndexA === -1 ? keyA.length : patternIndexA + 1;
|
|
const baseLengthB = patternIndexB === -1 ? keyB.length : patternIndexB + 1;
|
|
if (baseLengthA > baseLengthB) return -1;
|
|
if (baseLengthB > baseLengthA) return 1;
|
|
if (patternIndexA === -1) return 1;
|
|
if (patternIndexB === -1) return -1;
|
|
if (keyA.length > keyB.length) return -1;
|
|
if (keyB.length > keyA.length) return 1;
|
|
return 0;
|
|
};
|
|
exports.packageTarget = function* (packageURL, target, patternMatch, isImports, opts = {}) {
|
|
const { conditions = [], matchedConditions = [] } = opts;
|
|
if (typeof target === "string") {
|
|
if (!target.startsWith("./") && !isImports) {
|
|
throw errors.INVALID_PACKAGE_TARGET(
|
|
`Invalid target '${target}' defined by "exports" in '${packageURL}'`
|
|
);
|
|
}
|
|
if (patternMatch !== null) {
|
|
target = target.replaceAll("*", patternMatch);
|
|
}
|
|
const status = yield* exports.url(target, packageURL, opts);
|
|
if (status) return status;
|
|
if (target === "." || target === ".." || target[0] === "/" || target.startsWith("./") || target.startsWith("../")) {
|
|
const resolved = yield { resolution: new URL(target, packageURL) };
|
|
return resolved ? RESOLVED : YIELDED;
|
|
}
|
|
return yield* exports.package(target, packageURL, opts);
|
|
}
|
|
if (Array.isArray(target)) {
|
|
for (const targetValue of target) {
|
|
const status = yield* exports.packageTarget(
|
|
packageURL,
|
|
targetValue,
|
|
patternMatch,
|
|
isImports,
|
|
opts
|
|
);
|
|
if (status) return status;
|
|
}
|
|
} else if (typeof target === "object" && target !== null) {
|
|
let status = UNRESOLVED;
|
|
for (const [condition, targetValue, subset] of exports.conditionMatches(
|
|
target,
|
|
conditions,
|
|
opts
|
|
)) {
|
|
matchedConditions.push(condition);
|
|
status |= yield* exports.packageTarget(packageURL, targetValue, patternMatch, isImports, {
|
|
...opts,
|
|
conditions: subset
|
|
});
|
|
matchedConditions.pop();
|
|
}
|
|
if (status) return status;
|
|
}
|
|
return UNRESOLVED;
|
|
};
|
|
exports.builtinTarget = function* (packageSpecifier, packageVersion, target, opts = {}) {
|
|
const { builtinProtocol = "builtin:", conditions = [], matchedConditions = [] } = opts;
|
|
if (typeof target === "string") {
|
|
const targetParts = target.split("@");
|
|
let targetName;
|
|
let targetVersion;
|
|
if (target[0] !== "@") {
|
|
targetName = targetParts[0];
|
|
targetVersion = targetParts[1] || null;
|
|
} else {
|
|
targetName = targetParts.slice(0, 2).join("@");
|
|
targetVersion = targetParts[2] || null;
|
|
}
|
|
if (packageSpecifier === targetName) {
|
|
if (packageVersion === null && targetVersion === null) {
|
|
const resolved = yield {
|
|
resolution: new URL(builtinProtocol + packageSpecifier)
|
|
};
|
|
return resolved ? RESOLVED : YIELDED;
|
|
}
|
|
let version = null;
|
|
if (packageVersion === null) {
|
|
version = targetVersion;
|
|
} else if (targetVersion === null || packageVersion === targetVersion) {
|
|
version = packageVersion;
|
|
}
|
|
if (version !== null) {
|
|
const resolved = yield {
|
|
resolution: new URL(builtinProtocol + packageSpecifier + "@" + version)
|
|
};
|
|
return resolved ? RESOLVED : YIELDED;
|
|
}
|
|
}
|
|
} else if (Array.isArray(target)) {
|
|
for (const targetValue of target) {
|
|
const status = yield* exports.builtinTarget(
|
|
packageSpecifier,
|
|
packageVersion,
|
|
targetValue,
|
|
opts
|
|
);
|
|
if (status) return status;
|
|
}
|
|
} else if (typeof target === "object" && target !== null) {
|
|
let status = UNRESOLVED;
|
|
for (const [condition, targetValue, subset] of exports.conditionMatches(
|
|
target,
|
|
conditions,
|
|
opts
|
|
)) {
|
|
matchedConditions.push(condition);
|
|
status |= yield* exports.builtinTarget(packageSpecifier, packageVersion, targetValue, {
|
|
...opts,
|
|
conditions: subset
|
|
});
|
|
matchedConditions.pop();
|
|
}
|
|
if (status) return status;
|
|
}
|
|
return UNRESOLVED;
|
|
};
|
|
exports.conditionMatches = function* conditionMatches(target, conditions, opts = {}) {
|
|
if (conditions.every((condition) => typeof condition === "string")) {
|
|
const keys = Object.keys(target);
|
|
for (const condition of keys) {
|
|
if (condition === "default" || conditions.includes(condition)) {
|
|
yield [condition, target[condition], conditions];
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
let yielded = false;
|
|
for (const subset of conditions) {
|
|
if (yield* conditionMatches(target, subset, opts)) {
|
|
yielded = true;
|
|
}
|
|
}
|
|
return yielded;
|
|
};
|
|
exports.lookupPackageRoot = function* (packageName, parentURL) {
|
|
parentURL = new URL(parentURL.href);
|
|
do {
|
|
const packageURL = new URL("node_modules/" + packageName + "/", parentURL);
|
|
const info = yield new URL("package.json", packageURL);
|
|
if (info) return info;
|
|
parentURL.pathname = parentURL.pathname.substring(0, parentURL.pathname.lastIndexOf("/"));
|
|
if (parentURL.pathname.length === 3 && exports.isWindowsDriveLetter(parentURL.pathname.substring(1))) {
|
|
break;
|
|
}
|
|
} while (parentURL.pathname !== "" && parentURL.pathname !== "/");
|
|
return null;
|
|
};
|
|
exports.lookupPackageScope = function* lookupPackageScope(scopeURL, opts = {}) {
|
|
const { resolutions = null } = opts;
|
|
if (resolutions) {
|
|
for (const { resolution } of exports.preresolved("#package", resolutions, scopeURL, opts)) {
|
|
if (resolution) return yield resolution;
|
|
}
|
|
}
|
|
scopeURL = new URL(scopeURL.href);
|
|
do {
|
|
if (scopeURL.pathname.endsWith("/node_modules")) break;
|
|
const info = yield new URL("package.json", scopeURL);
|
|
if (info) return info;
|
|
scopeURL.pathname = scopeURL.pathname.substring(0, scopeURL.pathname.lastIndexOf("/"));
|
|
if (scopeURL.pathname.length === 3 && exports.isWindowsDriveLetter(scopeURL.pathname.substring(1))) {
|
|
break;
|
|
}
|
|
} while (scopeURL.pathname !== "" && scopeURL.pathname !== "/");
|
|
return null;
|
|
};
|
|
exports.file = function* (filename, parentURL, isIndex, opts = {}) {
|
|
if (filename === "." || filename === ".." || filename[filename.length - 1] === "/" || filename[filename.length - 1] === "\\") {
|
|
return UNRESOLVED;
|
|
}
|
|
if (parentURL.protocol === "file:" && /%2f|%5c/i.test(filename)) {
|
|
throw errors.INVALID_MODULE_SPECIFIER(`Module specifier '${filename}' is invalid`);
|
|
}
|
|
const { extensions = [] } = opts;
|
|
let status = UNRESOLVED;
|
|
if (!isIndex) {
|
|
if (yield { resolution: new URL(filename, parentURL) }) {
|
|
return RESOLVED;
|
|
}
|
|
status = YIELDED;
|
|
}
|
|
for (const ext of extensions) {
|
|
if (filename.endsWith(ext)) continue;
|
|
if (yield { resolution: new URL(filename + ext, parentURL) }) {
|
|
return RESOLVED;
|
|
}
|
|
status = YIELDED;
|
|
}
|
|
return status;
|
|
};
|
|
exports.directory = function* (dirname, parentURL, opts = {}) {
|
|
let directoryURL;
|
|
if (dirname[dirname.length - 1] === "/" || dirname[dirname.length - 1] === "\\") {
|
|
directoryURL = new URL(dirname, parentURL);
|
|
} else {
|
|
directoryURL = new URL(dirname + "/", parentURL);
|
|
}
|
|
const info = yield { package: new URL("package.json", directoryURL) };
|
|
if (info) {
|
|
if (info.exports) {
|
|
return yield* exports.packageExports(directoryURL, ".", info.exports, opts);
|
|
}
|
|
if (typeof info.main === "string" && info.main !== "") {
|
|
const status = yield* exports.file(info.main, directoryURL, false, opts);
|
|
if (status === RESOLVED) return status;
|
|
return yield* exports.directory(info.main, directoryURL, opts);
|
|
}
|
|
}
|
|
return yield* exports.file("index", directoryURL, true, opts);
|
|
};
|
|
function isASCIIUpperAlpha(c) {
|
|
return c >= 65 && c <= 90;
|
|
}
|
|
function isASCIILowerAlpha(c) {
|
|
return c >= 97 && c <= 122;
|
|
}
|
|
function isASCIIAlpha(c) {
|
|
return isASCIIUpperAlpha(c) || isASCIILowerAlpha(c);
|
|
}
|
|
exports.isWindowsDriveLetter = function isWindowsDriveLetter(input) {
|
|
return input.length >= 2 && isASCIIAlpha(input.charCodeAt(0)) && (input.charCodeAt(1) === 58 || input.charCodeAt(1) === 124);
|
|
};
|
|
exports.startsWithWindowsDriveLetter = function startsWithWindowsDriveLetter(input) {
|
|
return input.length >= 2 && exports.isWindowsDriveLetter(input) && (input.length === 2 || input.charCodeAt(2) === 47 || input.charCodeAt(2) === 92 || input.charCodeAt(2) === 63 || input.charCodeAt(2) === 35);
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-addon-resolve/lib/errors.js
|
|
var require_errors4 = __commonJS({
|
|
"../../node_modules/bare-addon-resolve/lib/errors.js"(exports, module) {
|
|
module.exports = class AddonResolveError extends Error {
|
|
constructor(msg, code, fn = AddonResolveError) {
|
|
super(`${code}: ${msg}`);
|
|
this.code = code;
|
|
if (Error.captureStackTrace) {
|
|
Error.captureStackTrace(this, fn);
|
|
}
|
|
}
|
|
get name() {
|
|
return "AddonResolveError";
|
|
}
|
|
static INVALID_ADDON_SPECIFIER(msg) {
|
|
return new AddonResolveError(
|
|
msg,
|
|
"INVALID_ADDON_SPECIFIER",
|
|
AddonResolveError.INVALID_ADDON_SPECIFIER
|
|
);
|
|
}
|
|
static INVALID_PACKAGE_NAME(msg) {
|
|
return new AddonResolveError(
|
|
msg,
|
|
"INVALID_PACKAGE_NAME",
|
|
AddonResolveError.INVALID_PACKAGE_NAME
|
|
);
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-addon-resolve/index.js
|
|
var require_bare_addon_resolve = __commonJS({
|
|
"../../node_modules/bare-addon-resolve/index.js"(exports, module) {
|
|
var resolve = require_bare_module_resolve();
|
|
var { Version } = require_bare_semver();
|
|
var errors = require_errors4();
|
|
module.exports = exports = function resolve2(specifier, parentURL, opts, readPackage) {
|
|
if (typeof opts === "function") {
|
|
readPackage = opts;
|
|
opts = {};
|
|
} else if (typeof readPackage !== "function") {
|
|
readPackage = defaultReadPackage;
|
|
}
|
|
return {
|
|
*[Symbol.iterator]() {
|
|
const generator = exports.addon(specifier, parentURL, opts);
|
|
let next = generator.next();
|
|
while (next.done !== true) {
|
|
const value = next.value;
|
|
if (value.package) {
|
|
next = generator.next(readPackage(value.package));
|
|
} else {
|
|
next = generator.next(yield value.resolution);
|
|
}
|
|
}
|
|
return next.value;
|
|
},
|
|
async *[Symbol.asyncIterator]() {
|
|
const generator = exports.addon(specifier, parentURL, opts);
|
|
let next = generator.next();
|
|
while (next.done !== true) {
|
|
const value = next.value;
|
|
if (value.package) {
|
|
next = generator.next(await readPackage(value.package));
|
|
} else {
|
|
next = generator.next(yield value.resolution);
|
|
}
|
|
}
|
|
return next.value;
|
|
}
|
|
};
|
|
};
|
|
function defaultReadPackage() {
|
|
return null;
|
|
}
|
|
var { UNRESOLVED, YIELDED, RESOLVED } = resolve.constants;
|
|
exports.constants = {
|
|
UNRESOLVED,
|
|
YIELDED,
|
|
RESOLVED
|
|
};
|
|
exports.addon = function* (specifier, parentURL, opts = {}) {
|
|
const { resolutions = null } = opts;
|
|
if (exports.startsWithWindowsDriveLetter(specifier)) {
|
|
specifier = "/" + specifier;
|
|
}
|
|
let status;
|
|
if (resolutions) {
|
|
status = yield* resolve.preresolved(specifier, resolutions, parentURL, opts);
|
|
if (status) return status;
|
|
}
|
|
status = yield* exports.url(specifier, parentURL, opts);
|
|
if (status) return status;
|
|
let version = null;
|
|
const i = specifier.lastIndexOf("@");
|
|
if (i > 0) {
|
|
version = specifier.substring(i + 1);
|
|
try {
|
|
Version.parse(version);
|
|
specifier = specifier.substring(0, i);
|
|
} catch {
|
|
version = null;
|
|
}
|
|
}
|
|
if (specifier === "." || specifier === ".." || specifier[0] === "/" || specifier[0] === "\\" || specifier.startsWith("./") || specifier.startsWith(".\\") || specifier.startsWith("../") || specifier.startsWith("..\\")) {
|
|
status = yield* exports.file(specifier, parentURL, opts);
|
|
if (status === RESOLVED) return status;
|
|
return yield* exports.directory(specifier, version, parentURL, opts);
|
|
}
|
|
return yield* exports.package(specifier, version, parentURL, opts);
|
|
};
|
|
exports.url = function* (url, parentURL, opts = {}) {
|
|
let resolution;
|
|
try {
|
|
resolution = new URL(url);
|
|
} catch {
|
|
return UNRESOLVED;
|
|
}
|
|
const resolved = yield { resolution };
|
|
return resolved ? RESOLVED : YIELDED;
|
|
};
|
|
exports.package = function* (packageSpecifier, packageVersion, parentURL, opts = {}) {
|
|
if (packageSpecifier === "") {
|
|
throw errors.INVALID_ADDON_SPECIFIER(
|
|
`Addon specifier '${packageSpecifier}' is not a valid package name`
|
|
);
|
|
}
|
|
let packageName;
|
|
if (packageSpecifier[0] !== "@") {
|
|
packageName = packageSpecifier.split("/", 1).join();
|
|
} else {
|
|
if (!packageSpecifier.includes("/")) {
|
|
throw errors.INVALID_ADDON_SPECIFIER(
|
|
`Addon specifier '${packageSpecifier}' is not a valid package name`
|
|
);
|
|
}
|
|
packageName = packageSpecifier.split("/", 2).join("/");
|
|
}
|
|
if (packageName[0] === "." || packageName.includes("\\") || packageName.includes("%")) {
|
|
throw errors.INVALID_ADDON_SPECIFIER(
|
|
`Addon specifier '${packageSpecifier}' is not a valid package name`
|
|
);
|
|
}
|
|
const packageSubpath = "." + packageSpecifier.substring(packageName.length);
|
|
const status = yield* exports.packageSelf(
|
|
packageName,
|
|
packageSubpath,
|
|
packageVersion,
|
|
parentURL,
|
|
opts
|
|
);
|
|
if (status) return status;
|
|
parentURL = new URL(parentURL.href);
|
|
do {
|
|
const packageURL = new URL("node_modules/" + packageName + "/", parentURL);
|
|
parentURL.pathname = parentURL.pathname.substring(0, parentURL.pathname.lastIndexOf("/"));
|
|
const info = yield { package: new URL("package.json", packageURL) };
|
|
if (info) {
|
|
return yield* exports.directory(packageSubpath, packageVersion, packageURL, opts);
|
|
}
|
|
} while (parentURL.pathname !== "" && parentURL.pathname !== "/");
|
|
return UNRESOLVED;
|
|
};
|
|
exports.packageSelf = function* (packageName, packageSubpath, packageVersion, parentURL, opts = {}) {
|
|
for (const packageURL of resolve.lookupPackageScope(parentURL, opts)) {
|
|
const info = yield { package: packageURL };
|
|
if (info) {
|
|
if (info.name === packageName) {
|
|
return yield* exports.directory(packageSubpath, packageVersion, packageURL, opts);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
return UNRESOLVED;
|
|
};
|
|
exports.lookupPrebuildsScope = function* lookupPrebuildsScope(url, opts = {}) {
|
|
const scopeURL = new URL(url.href);
|
|
do {
|
|
yield new URL("prebuilds/", scopeURL);
|
|
scopeURL.pathname = scopeURL.pathname.substring(0, scopeURL.pathname.lastIndexOf("/"));
|
|
if (scopeURL.pathname.length === 3 && exports.isWindowsDriveLetter(scopeURL.pathname.substring(1))) {
|
|
break;
|
|
}
|
|
} while (scopeURL.pathname !== "" && scopeURL.pathname !== "/");
|
|
};
|
|
exports.file = function* (filename, parentURL, opts = {}) {
|
|
if (filename === "." || filename === ".." || filename[filename.length - 1] === "/" || filename[filename.length - 1] === "\\") {
|
|
return UNRESOLVED;
|
|
}
|
|
if (parentURL.protocol === "file:" && /%2f|%5c/i.test(filename)) {
|
|
throw errors.INVALID_ADDON_SPECIFIER(`Addon specifier '${filename}' is invalid`);
|
|
}
|
|
const { extensions = [] } = opts;
|
|
let status = UNRESOLVED;
|
|
for (let ext of extensions) {
|
|
if (filename.endsWith(ext)) ext = "";
|
|
if (yield { resolution: new URL(filename + ext, parentURL) }) {
|
|
return RESOLVED;
|
|
}
|
|
status = YIELDED;
|
|
}
|
|
return status;
|
|
};
|
|
exports.directory = function* (dirname, version, parentURL, opts = {}) {
|
|
const {
|
|
host = null,
|
|
// Shorthand for single host resolution
|
|
hosts = host !== null ? [host] : [],
|
|
builtins = [],
|
|
matchedConditions = []
|
|
} = opts;
|
|
let directoryURL;
|
|
if (dirname[dirname.length - 1] === "/" || dirname[dirname.length - 1] === "\\") {
|
|
directoryURL = new URL(dirname, parentURL);
|
|
} else {
|
|
directoryURL = new URL(dirname + "/", parentURL);
|
|
}
|
|
const unversioned = version === null;
|
|
let name = null;
|
|
const info = yield { package: new URL("package.json", directoryURL) };
|
|
if (info) {
|
|
if (typeof info.name === "string" && info.name !== "") {
|
|
if (info.name.includes("__")) {
|
|
throw errors.INVALID_PACKAGE_NAME(`Package name '${info.name}' is invalid`);
|
|
}
|
|
name = info.name.replace(/\//g, "__").replace(/^@/, "");
|
|
} else {
|
|
return UNRESOLVED;
|
|
}
|
|
if (typeof info.version === "string" && info.version !== "") {
|
|
if (version !== null && info.version !== version) return UNRESOLVED;
|
|
version = info.version;
|
|
}
|
|
} else {
|
|
return UNRESOLVED;
|
|
}
|
|
let status;
|
|
status = yield* resolve.builtinTarget(name, version, builtins, opts);
|
|
if (status) return status;
|
|
for (const prebuildsURL of exports.lookupPrebuildsScope(directoryURL, opts)) {
|
|
status = UNRESOLVED;
|
|
for (const host2 of hosts) {
|
|
const conditions = host2.split("-");
|
|
const universal = supportsUniversalPrebuilds(host2) ? conditions.with(1, "universal").join("-") : null;
|
|
matchedConditions.push(...conditions);
|
|
if (version !== null) {
|
|
status |= yield* exports.file(host2 + "/" + name + "@" + version, prebuildsURL, opts);
|
|
if (universal) {
|
|
status |= yield* exports.file(universal + "/" + name + "@" + version, prebuildsURL, opts);
|
|
}
|
|
}
|
|
if (unversioned) {
|
|
status |= yield* exports.file(host2 + "/" + name, prebuildsURL, opts);
|
|
if (universal) {
|
|
status |= yield* exports.file(universal + "/" + name, prebuildsURL, opts);
|
|
}
|
|
}
|
|
for (const _ of conditions) matchedConditions.pop();
|
|
}
|
|
if (status === RESOLVED) return status;
|
|
}
|
|
return yield* exports.linked(name, version, opts);
|
|
};
|
|
exports.linked = function* (name, version = null, opts = {}) {
|
|
const {
|
|
linked = true,
|
|
host = null,
|
|
// Shorthand for single host resolution
|
|
hosts = host !== null ? [host] : [],
|
|
matchedConditions = []
|
|
} = opts;
|
|
if (linked === false || hosts.length === 0) return UNRESOLVED;
|
|
let status = UNRESOLVED;
|
|
for (const host2 of hosts) {
|
|
const [platform = null] = host2.split("-", 1);
|
|
if (platform === null) continue;
|
|
matchedConditions.push(platform);
|
|
status |= yield* platformArtefact(name, version, platform, opts);
|
|
matchedConditions.pop();
|
|
}
|
|
return status;
|
|
};
|
|
function* platformArtefact(name, version = null, platform, opts = {}) {
|
|
const { linkedProtocol = "linked:" } = opts;
|
|
if (platform === "darwin" || platform === "ios") {
|
|
if (version !== null) {
|
|
if (yield {
|
|
resolution: new URL(`${linkedProtocol}${name}.${version}.framework/${name}.${version}`)
|
|
}) {
|
|
return RESOLVED;
|
|
}
|
|
if (platform === "darwin") {
|
|
if (yield {
|
|
resolution: new URL(`${linkedProtocol}lib${name}.${version}.dylib`)
|
|
}) {
|
|
return RESOLVED;
|
|
}
|
|
}
|
|
}
|
|
if (yield {
|
|
resolution: new URL(`${linkedProtocol}${name}.framework/${name}`)
|
|
}) {
|
|
return RESOLVED;
|
|
}
|
|
if (platform === "darwin") {
|
|
if (yield {
|
|
resolution: new URL(`${linkedProtocol}lib${name}.dylib`)
|
|
}) {
|
|
return RESOLVED;
|
|
}
|
|
}
|
|
return YIELDED;
|
|
}
|
|
if (platform === "linux" || platform === "android") {
|
|
if (version !== null) {
|
|
if (yield {
|
|
resolution: new URL(`${linkedProtocol}lib${name}.${version}.so`)
|
|
}) {
|
|
return RESOLVED;
|
|
}
|
|
}
|
|
if (yield {
|
|
resolution: new URL(`${linkedProtocol}lib${name}.so`)
|
|
}) {
|
|
return RESOLVED;
|
|
}
|
|
return YIELDED;
|
|
}
|
|
if (platform === "win32") {
|
|
if (version !== null) {
|
|
if (yield {
|
|
resolution: new URL(`${linkedProtocol}${name}-${version}.dll`)
|
|
}) {
|
|
return RESOLVED;
|
|
}
|
|
}
|
|
if (yield {
|
|
resolution: new URL(`${linkedProtocol}${name}.dll`)
|
|
}) {
|
|
return RESOLVED;
|
|
}
|
|
}
|
|
return UNRESOLVED;
|
|
}
|
|
exports.isWindowsDriveLetter = resolve.isWindowsDriveLetter;
|
|
exports.startsWithWindowsDriveLetter = resolve.startsWithWindowsDriveLetter;
|
|
function supportsUniversalPrebuilds(host) {
|
|
return host === "darwin-arm64" || host === "darwin-x64" || host === "ios-arm64-simulator" || host === "ios-x64-simulator";
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/require-addon/lib/node.js
|
|
var require_node = __commonJS({
|
|
"../../node_modules/require-addon/lib/node.js"(exports, module) {
|
|
if (typeof __require.addon === "function") {
|
|
module.exports = __require.addon.bind(__require);
|
|
} else {
|
|
let readPackage2 = function(packageURL) {
|
|
try {
|
|
return __require(url.fileURLToPath(packageURL));
|
|
} catch (err) {
|
|
return null;
|
|
}
|
|
}, isAlpine2 = function() {
|
|
return process.platform === "linux" && fs.existsSync("/etc/alpine-release");
|
|
};
|
|
readPackage = readPackage2, isAlpine = isAlpine2;
|
|
const url = __require("url");
|
|
const fs = __require("fs");
|
|
const resolve = require_bare_addon_resolve();
|
|
let host = process.platform + "-" + process.arch;
|
|
const conditions = ["addon", "node", process.platform, process.arch];
|
|
const extensions = [".node"];
|
|
if (isAlpine2()) {
|
|
host += "-musl";
|
|
conditions.push("musl");
|
|
}
|
|
module.exports = function addon(specifier, parentURL) {
|
|
if (typeof parentURL === "string") parentURL = url.pathToFileURL(parentURL);
|
|
const candidates = [];
|
|
let cause;
|
|
for (const resolution of resolve(
|
|
specifier,
|
|
parentURL,
|
|
{ host, conditions, extensions },
|
|
readPackage2
|
|
)) {
|
|
candidates.push(resolution);
|
|
switch (resolution.protocol) {
|
|
case "file:":
|
|
try {
|
|
return __require(url.fileURLToPath(resolution));
|
|
} catch (err2) {
|
|
cause = err2;
|
|
continue;
|
|
}
|
|
}
|
|
}
|
|
let message = `Cannot find addon '${specifier}' imported from '${parentURL.href}'`;
|
|
if (candidates.length > 0) {
|
|
message += "\nCandidates:";
|
|
message += "\n" + candidates.map((url2) => "- " + url2.href).join("\n");
|
|
}
|
|
const err = new Error(message, cause ? { cause } : {});
|
|
err.code = "ADDON_NOT_FOUND";
|
|
err.specifier = specifier;
|
|
err.referrer = parentURL;
|
|
err.candidates = candidates;
|
|
throw err;
|
|
};
|
|
}
|
|
var readPackage;
|
|
var isAlpine;
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/udx-native/binding.js
|
|
var require_binding = __commonJS({
|
|
"../../node_modules/udx-native/binding.js"(exports, module) {
|
|
__require.addon = require_node();
|
|
module.exports = __require.addon(".", __filename);
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/udx-native/lib/ip.js
|
|
var require_ip = __commonJS({
|
|
"../../node_modules/udx-native/lib/ip.js"(exports) {
|
|
var v4Seg = "(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])";
|
|
var v4Str = `(${v4Seg}[.]){3}${v4Seg}`;
|
|
var IPv4Pattern = new RegExp(`^${v4Str}$`);
|
|
var v6Seg = "(?:[0-9a-fA-F]{1,4})";
|
|
var IPv6Pattern = new RegExp(
|
|
`^((?:${v6Seg}:){7}(?:${v6Seg}|:)|(?:${v6Seg}:){6}(?:${v4Str}|:${v6Seg}|:)|(?:${v6Seg}:){5}(?::${v4Str}|(:${v6Seg}){1,2}|:)|(?:${v6Seg}:){4}(?:(:${v6Seg}){0,1}:${v4Str}|(:${v6Seg}){1,3}|:)|(?:${v6Seg}:){3}(?:(:${v6Seg}){0,2}:${v4Str}|(:${v6Seg}){1,4}|:)|(?:${v6Seg}:){2}(?:(:${v6Seg}){0,3}:${v4Str}|(:${v6Seg}){1,5}|:)|(?:${v6Seg}:){1}(?:(:${v6Seg}){0,4}:${v4Str}|(:${v6Seg}){1,6}|:)|(?::((?::${v6Seg}){0,5}:${v4Str}|(?::${v6Seg}){1,7}|:)))(%[0-9a-zA-Z-.:]{1,})?$`
|
|
);
|
|
var isIPv4 = exports.isIPv4 = function isIPv42(host) {
|
|
return IPv4Pattern.test(host);
|
|
};
|
|
var isIPv6 = exports.isIPv6 = function isIPv62(host) {
|
|
return IPv6Pattern.test(host);
|
|
};
|
|
exports.isIP = function isIP(host) {
|
|
if (isIPv4(host)) return 4;
|
|
if (isIPv6(host)) return 6;
|
|
return 0;
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/udx-native/lib/socket.js
|
|
var require_socket = __commonJS({
|
|
"../../node_modules/udx-native/lib/socket.js"(exports, module) {
|
|
var events = __require("events");
|
|
var b4a = require_b4a();
|
|
var binding = require_binding();
|
|
var ip = require_ip();
|
|
module.exports = class UDXSocket extends events.EventEmitter {
|
|
constructor(udx, opts = {}) {
|
|
super();
|
|
this.udx = udx;
|
|
this._handle = b4a.alloc(binding.sizeof_udx_napi_socket_t);
|
|
this._inited = false;
|
|
this._host = null;
|
|
this._family = 0;
|
|
this._ipv6Only = opts.ipv6Only === true;
|
|
this._reuseAddress = opts.reuseAddress === true;
|
|
this._port = 0;
|
|
this._reqs = [];
|
|
this._free = [];
|
|
this._closing = null;
|
|
this._closed = false;
|
|
this._view64 = new BigUint64Array(
|
|
this._handle.buffer,
|
|
this._handle.byteOffset,
|
|
this._handle.byteLength >> 3
|
|
);
|
|
this.streams = /* @__PURE__ */ new Set();
|
|
this.userData = null;
|
|
}
|
|
get bound() {
|
|
return this._port !== 0;
|
|
}
|
|
get closing() {
|
|
return this._closing !== null;
|
|
}
|
|
get idle() {
|
|
return this.streams.size === 0;
|
|
}
|
|
get busy() {
|
|
return this.streams.size > 0;
|
|
}
|
|
get bytesTransmitted() {
|
|
if (this._inited !== true) return 0;
|
|
return Number(this._view64[binding.offsetof_udx_socket_t_bytes_tx >> 3]);
|
|
}
|
|
get packetsTransmitted() {
|
|
if (this._inited !== true) return 0;
|
|
return Number(this._view64[binding.offsetof_udx_socket_t_packets_tx >> 3]);
|
|
}
|
|
get bytesReceived() {
|
|
if (this._inited !== true) return 0;
|
|
return Number(this._view64[binding.offsetof_udx_socket_t_bytes_rx >> 3]);
|
|
}
|
|
get packetsReceived() {
|
|
if (this._inited !== true) return 0;
|
|
return Number(this._view64[binding.offsetof_udx_socket_t_packets_rx >> 3]);
|
|
}
|
|
get packetsDroppedByKernel() {
|
|
if (this._inited !== true) return 0;
|
|
return Number(this._view64[binding.offsetof_udx_socket_t_packets_dropped_by_kernel >> 3]);
|
|
}
|
|
toJSON() {
|
|
return {
|
|
bound: this.bound,
|
|
closing: this.closing,
|
|
streams: this.streams.size,
|
|
address: this.address(),
|
|
ipv6Only: this._ipv6Only,
|
|
reuseAddress: this._reuseAddress,
|
|
idle: this.idle,
|
|
busy: this.busy
|
|
};
|
|
}
|
|
_init() {
|
|
if (this._inited) return;
|
|
binding.udx_napi_socket_init(
|
|
this.udx._handle,
|
|
this._handle,
|
|
this,
|
|
this._onsend,
|
|
this._onmessage,
|
|
this._onclose,
|
|
this._reallocMessage
|
|
);
|
|
this._inited = true;
|
|
}
|
|
_onsend(id, err) {
|
|
const req = this._reqs[id];
|
|
const onflush = req.onflush;
|
|
req.buffer = null;
|
|
req.onflush = null;
|
|
this._free.push(id);
|
|
onflush(err >= 0);
|
|
if (this._free.length >= 16 && this._free.length === this._reqs.length) {
|
|
this._free = [];
|
|
this._reqs = [];
|
|
}
|
|
}
|
|
_onmessage(len, port, host, family) {
|
|
this.emit("message", this.udx._consumeMessage(len), { host, family, port });
|
|
return this.udx._buffer;
|
|
}
|
|
_onclose() {
|
|
this.emit("close");
|
|
}
|
|
_reallocMessage() {
|
|
return this.udx._reallocMessage();
|
|
}
|
|
_onidle() {
|
|
this.emit("idle");
|
|
}
|
|
_onbusy() {
|
|
this.emit("busy");
|
|
}
|
|
_addStream(stream) {
|
|
if (this.streams.has(stream)) return false;
|
|
this.streams.add(stream);
|
|
if (this.streams.size === 1) this._onbusy();
|
|
return true;
|
|
}
|
|
_removeStream(stream) {
|
|
if (!this.streams.has(stream)) return false;
|
|
this.streams.delete(stream);
|
|
const closed = this._closeMaybe();
|
|
if (this.idle && !closed) this._onidle();
|
|
return true;
|
|
}
|
|
address() {
|
|
if (!this.bound) return null;
|
|
return { host: this._host, family: this._family, port: this._port };
|
|
}
|
|
bind(port, host) {
|
|
if (this.bound) throw new Error("Already bound");
|
|
if (this.closing) throw new Error("Socket is closed");
|
|
if (!port) port = 0;
|
|
let flags = 0;
|
|
if (this._ipv6Only) flags |= binding.UV_UDP_IPV6ONLY;
|
|
if (this._reuseAddress) flags |= binding.UV_UDP_REUSEADDR;
|
|
let family;
|
|
if (host) {
|
|
family = ip.isIP(host);
|
|
if (!family) throw new Error(`${host} is not a valid IP address`);
|
|
if (!this._inited) this._init();
|
|
this._port = binding.udx_napi_socket_bind(this._handle, port, host, family, flags);
|
|
} else {
|
|
if (!this._inited) this._init();
|
|
try {
|
|
host = "::";
|
|
family = 6;
|
|
this._port = binding.udx_napi_socket_bind(this._handle, port, host, family, flags);
|
|
} catch {
|
|
host = "0.0.0.0";
|
|
family = 4;
|
|
this._port = binding.udx_napi_socket_bind(this._handle, port, host, family, flags);
|
|
}
|
|
}
|
|
this._host = host;
|
|
this._family = family;
|
|
this.emit("listening");
|
|
}
|
|
async close() {
|
|
if (this._closing) return this._closing;
|
|
this._closing = new Promise((resolve) => this.once("close", resolve));
|
|
this._closeMaybe();
|
|
return this._closing;
|
|
}
|
|
_closeMaybe() {
|
|
if (this._closed || this._closing === null) return this._closed;
|
|
if (!this._inited) {
|
|
this._closed = true;
|
|
this.emit("close");
|
|
return true;
|
|
}
|
|
if (this.idle) {
|
|
binding.udx_napi_socket_close(this._handle);
|
|
this._closed = true;
|
|
}
|
|
return this._closed;
|
|
}
|
|
setTTL(ttl) {
|
|
if (!this._inited) throw new Error("Socket not active");
|
|
binding.udx_napi_socket_set_ttl(this._handle, ttl);
|
|
}
|
|
getRecvBufferSize() {
|
|
if (!this._inited) throw new Error("Socket not active");
|
|
return binding.udx_napi_socket_get_recv_buffer_size(this._handle);
|
|
}
|
|
setRecvBufferSize(size) {
|
|
if (!this._inited) throw new Error("Socket not active");
|
|
return binding.udx_napi_socket_set_recv_buffer_size(this._handle, size);
|
|
}
|
|
getSendBufferSize() {
|
|
if (!this._inited) throw new Error("Socket not active");
|
|
return binding.udx_napi_socket_get_send_buffer_size(this._handle);
|
|
}
|
|
setSendBufferSize(size) {
|
|
if (!this._inited) throw new Error("Socket not active");
|
|
return binding.udx_napi_socket_set_send_buffer_size(this._handle, size);
|
|
}
|
|
addMembership(group, ifaceAddress) {
|
|
if (!this._inited) throw new Error("Socket not active");
|
|
return binding.udx_napi_socket_set_membership(this._handle, group, ifaceAddress || "", true);
|
|
}
|
|
dropMembership(group, ifaceAddress) {
|
|
if (!this._inited) throw new Error("Socket not active");
|
|
return binding.udx_napi_socket_set_membership(this._handle, group, ifaceAddress || "", false);
|
|
}
|
|
async send(buffer, port, host, ttl) {
|
|
if (this.closing) return false;
|
|
if (!host) host = "127.0.0.1";
|
|
const family = ip.isIP(host);
|
|
if (!family) throw new Error(`${host} is not a valid IP address`);
|
|
if (!this.bound) this.bind(0);
|
|
const id = this._allocSend();
|
|
const req = this._reqs[id];
|
|
req.buffer = buffer;
|
|
const promise = new Promise((resolve) => {
|
|
req.onflush = resolve;
|
|
});
|
|
binding.udx_napi_socket_send_ttl(
|
|
this._handle,
|
|
req.handle,
|
|
id,
|
|
buffer,
|
|
port,
|
|
host,
|
|
family,
|
|
ttl || 0
|
|
);
|
|
return promise;
|
|
}
|
|
trySend(buffer, port, host, ttl) {
|
|
if (this.closing) return;
|
|
if (!host) host = "127.0.0.1";
|
|
const family = ip.isIP(host);
|
|
if (!family) throw new Error(`${host} is not a valid IP address`);
|
|
if (!this.bound) this.bind(0);
|
|
const id = this._allocSend();
|
|
const req = this._reqs[id];
|
|
req.buffer = buffer;
|
|
req.onflush = noop;
|
|
binding.udx_napi_socket_send_ttl(
|
|
this._handle,
|
|
req.handle,
|
|
id,
|
|
buffer,
|
|
port,
|
|
host,
|
|
family,
|
|
ttl || 0
|
|
);
|
|
}
|
|
_allocSend() {
|
|
if (this._free.length > 0) return this._free.pop();
|
|
const handle = b4a.allocUnsafe(binding.sizeof_udx_socket_send_t);
|
|
return this._reqs.push({ handle, buffer: null, onflush: null }) - 1;
|
|
}
|
|
};
|
|
function noop() {
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/events-universal/default.js
|
|
var require_default = __commonJS({
|
|
"../../node_modules/events-universal/default.js"(exports, module) {
|
|
module.exports = __require("events");
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/fast-fifo/fixed-size.js
|
|
var require_fixed_size = __commonJS({
|
|
"../../node_modules/fast-fifo/fixed-size.js"(exports, module) {
|
|
module.exports = class FixedFIFO {
|
|
constructor(hwm) {
|
|
if (!(hwm > 0) || (hwm - 1 & hwm) !== 0) throw new Error("Max size for a FixedFIFO should be a power of two");
|
|
this.buffer = new Array(hwm);
|
|
this.mask = hwm - 1;
|
|
this.top = 0;
|
|
this.btm = 0;
|
|
this.next = null;
|
|
}
|
|
clear() {
|
|
this.top = this.btm = 0;
|
|
this.next = null;
|
|
this.buffer.fill(void 0);
|
|
}
|
|
push(data) {
|
|
if (this.buffer[this.top] !== void 0) return false;
|
|
this.buffer[this.top] = data;
|
|
this.top = this.top + 1 & this.mask;
|
|
return true;
|
|
}
|
|
shift() {
|
|
const last = this.buffer[this.btm];
|
|
if (last === void 0) return void 0;
|
|
this.buffer[this.btm] = void 0;
|
|
this.btm = this.btm + 1 & this.mask;
|
|
return last;
|
|
}
|
|
peek() {
|
|
return this.buffer[this.btm];
|
|
}
|
|
isEmpty() {
|
|
return this.buffer[this.btm] === void 0;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/fast-fifo/index.js
|
|
var require_fast_fifo = __commonJS({
|
|
"../../node_modules/fast-fifo/index.js"(exports, module) {
|
|
var FixedFIFO = require_fixed_size();
|
|
module.exports = class FastFIFO {
|
|
constructor(hwm) {
|
|
this.hwm = hwm || 16;
|
|
this.head = new FixedFIFO(this.hwm);
|
|
this.tail = this.head;
|
|
this.length = 0;
|
|
}
|
|
clear() {
|
|
this.head = this.tail;
|
|
this.head.clear();
|
|
this.length = 0;
|
|
}
|
|
push(val) {
|
|
this.length++;
|
|
if (!this.head.push(val)) {
|
|
const prev = this.head;
|
|
this.head = prev.next = new FixedFIFO(2 * this.head.buffer.length);
|
|
this.head.push(val);
|
|
}
|
|
}
|
|
shift() {
|
|
if (this.length !== 0) this.length--;
|
|
const val = this.tail.shift();
|
|
if (val === void 0 && this.tail.next) {
|
|
const next = this.tail.next;
|
|
this.tail.next = null;
|
|
this.tail = next;
|
|
return this.tail.shift();
|
|
}
|
|
return val;
|
|
}
|
|
peek() {
|
|
const val = this.tail.peek();
|
|
if (val === void 0 && this.tail.next) return this.tail.next.peek();
|
|
return val;
|
|
}
|
|
isEmpty() {
|
|
return this.length === 0;
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/text-decoder/lib/pass-through-decoder.js
|
|
var require_pass_through_decoder = __commonJS({
|
|
"../../node_modules/text-decoder/lib/pass-through-decoder.js"(exports, module) {
|
|
var b4a = require_b4a();
|
|
module.exports = class PassThroughDecoder {
|
|
constructor(encoding) {
|
|
this.encoding = encoding;
|
|
}
|
|
get remaining() {
|
|
return 0;
|
|
}
|
|
decode(data) {
|
|
return b4a.toString(data, this.encoding);
|
|
}
|
|
flush() {
|
|
return "";
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/text-decoder/lib/utf8-decoder.js
|
|
var require_utf8_decoder = __commonJS({
|
|
"../../node_modules/text-decoder/lib/utf8-decoder.js"(exports, module) {
|
|
var b4a = require_b4a();
|
|
module.exports = class UTF8Decoder {
|
|
constructor() {
|
|
this._reset();
|
|
}
|
|
get remaining() {
|
|
return this.bytesSeen;
|
|
}
|
|
decode(data) {
|
|
if (data.byteLength === 0) return "";
|
|
if (this.bytesNeeded === 0 && trailingIncomplete(data, 0) === 0) {
|
|
this.bytesSeen = trailingBytesSeen(data);
|
|
return b4a.toString(data, "utf8");
|
|
}
|
|
let result = "";
|
|
let start = 0;
|
|
if (this.bytesNeeded > 0) {
|
|
while (start < data.byteLength) {
|
|
const byte = data[start];
|
|
if (byte < this.lowerBoundary || byte > this.upperBoundary) {
|
|
result += "\uFFFD";
|
|
this._reset();
|
|
break;
|
|
}
|
|
this.lowerBoundary = 128;
|
|
this.upperBoundary = 191;
|
|
this.codePoint = this.codePoint << 6 | byte & 63;
|
|
this.bytesSeen++;
|
|
start++;
|
|
if (this.bytesSeen === this.bytesNeeded) {
|
|
result += String.fromCodePoint(this.codePoint);
|
|
this._reset();
|
|
break;
|
|
}
|
|
}
|
|
if (this.bytesNeeded > 0) return result;
|
|
}
|
|
const trailing = trailingIncomplete(data, start);
|
|
const end = data.byteLength - trailing;
|
|
if (end > start) result += b4a.toString(data, "utf8", start, end);
|
|
for (let i = end; i < data.byteLength; i++) {
|
|
const byte = data[i];
|
|
if (this.bytesNeeded === 0) {
|
|
if (byte <= 127) {
|
|
this.bytesSeen = 0;
|
|
result += String.fromCharCode(byte);
|
|
} else if (byte >= 194 && byte <= 223) {
|
|
this.bytesNeeded = 2;
|
|
this.bytesSeen = 1;
|
|
this.codePoint = byte & 31;
|
|
} else if (byte >= 224 && byte <= 239) {
|
|
if (byte === 224) this.lowerBoundary = 160;
|
|
else if (byte === 237) this.upperBoundary = 159;
|
|
this.bytesNeeded = 3;
|
|
this.bytesSeen = 1;
|
|
this.codePoint = byte & 15;
|
|
} else if (byte >= 240 && byte <= 244) {
|
|
if (byte === 240) this.lowerBoundary = 144;
|
|
else if (byte === 244) this.upperBoundary = 143;
|
|
this.bytesNeeded = 4;
|
|
this.bytesSeen = 1;
|
|
this.codePoint = byte & 7;
|
|
} else {
|
|
this.bytesSeen = 1;
|
|
result += "\uFFFD";
|
|
}
|
|
continue;
|
|
}
|
|
if (byte < this.lowerBoundary || byte > this.upperBoundary) {
|
|
result += "\uFFFD";
|
|
i--;
|
|
this._reset();
|
|
continue;
|
|
}
|
|
this.lowerBoundary = 128;
|
|
this.upperBoundary = 191;
|
|
this.codePoint = this.codePoint << 6 | byte & 63;
|
|
this.bytesSeen++;
|
|
if (this.bytesSeen === this.bytesNeeded) {
|
|
result += String.fromCodePoint(this.codePoint);
|
|
this._reset();
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
flush() {
|
|
const result = this.bytesNeeded > 0 ? "\uFFFD" : "";
|
|
this._reset();
|
|
return result;
|
|
}
|
|
_reset() {
|
|
this.codePoint = 0;
|
|
this.bytesNeeded = 0;
|
|
this.bytesSeen = 0;
|
|
this.lowerBoundary = 128;
|
|
this.upperBoundary = 191;
|
|
}
|
|
};
|
|
function trailingIncomplete(data, start) {
|
|
const len = data.byteLength;
|
|
if (len <= start) return 0;
|
|
const limit = Math.max(start, len - 4);
|
|
let i = len - 1;
|
|
while (i > limit && (data[i] & 192) === 128) i--;
|
|
if (i < start) return 0;
|
|
const byte = data[i];
|
|
let needed;
|
|
if (byte <= 127) return 0;
|
|
if (byte >= 194 && byte <= 223) needed = 2;
|
|
else if (byte >= 224 && byte <= 239) needed = 3;
|
|
else if (byte >= 240 && byte <= 244) needed = 4;
|
|
else return 0;
|
|
const available = len - i;
|
|
return available < needed ? available : 0;
|
|
}
|
|
function trailingBytesSeen(data) {
|
|
const len = data.byteLength;
|
|
if (len === 0) return 0;
|
|
const last = data[len - 1];
|
|
if (last <= 127) return 0;
|
|
if ((last & 192) !== 128) return 1;
|
|
const limit = Math.max(0, len - 4);
|
|
let i = len - 2;
|
|
while (i >= limit && (data[i] & 192) === 128) i--;
|
|
if (i < 0) return 1;
|
|
const first = data[i];
|
|
let needed;
|
|
if (first >= 194 && first <= 223) needed = 2;
|
|
else if (first >= 224 && first <= 239) needed = 3;
|
|
else if (first >= 240 && first <= 244) needed = 4;
|
|
else return 1;
|
|
if (len - i !== needed) return 1;
|
|
if (needed >= 3) {
|
|
const second = data[i + 1];
|
|
if (first === 224 && second < 160) return 1;
|
|
if (first === 237 && second > 159) return 1;
|
|
if (first === 240 && second < 144) return 1;
|
|
if (first === 244 && second > 143) return 1;
|
|
}
|
|
return 0;
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/text-decoder/index.js
|
|
var require_text_decoder = __commonJS({
|
|
"../../node_modules/text-decoder/index.js"(exports, module) {
|
|
var PassThroughDecoder = require_pass_through_decoder();
|
|
var UTF8Decoder = require_utf8_decoder();
|
|
module.exports = class TextDecoder {
|
|
constructor(encoding = "utf8") {
|
|
this.encoding = normalizeEncoding(encoding);
|
|
switch (this.encoding) {
|
|
case "utf8":
|
|
this.decoder = new UTF8Decoder();
|
|
break;
|
|
case "utf16le":
|
|
case "base64":
|
|
throw new Error("Unsupported encoding: " + this.encoding);
|
|
default:
|
|
this.decoder = new PassThroughDecoder(this.encoding);
|
|
}
|
|
}
|
|
get remaining() {
|
|
return this.decoder.remaining;
|
|
}
|
|
push(data) {
|
|
if (typeof data === "string") return data;
|
|
return this.decoder.decode(data);
|
|
}
|
|
// For Node.js compatibility
|
|
write(data) {
|
|
return this.push(data);
|
|
}
|
|
end(data) {
|
|
let result = "";
|
|
if (data) result = this.push(data);
|
|
result += this.decoder.flush();
|
|
return result;
|
|
}
|
|
};
|
|
function normalizeEncoding(encoding) {
|
|
encoding = encoding.toLowerCase();
|
|
switch (encoding) {
|
|
case "utf8":
|
|
case "utf-8":
|
|
return "utf8";
|
|
case "ucs2":
|
|
case "ucs-2":
|
|
case "utf16le":
|
|
case "utf-16le":
|
|
return "utf16le";
|
|
case "latin1":
|
|
case "binary":
|
|
return "latin1";
|
|
case "base64":
|
|
case "ascii":
|
|
case "hex":
|
|
return encoding;
|
|
default:
|
|
throw new Error("Unknown encoding: " + encoding);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/streamx/index.js
|
|
var require_streamx = __commonJS({
|
|
"../../node_modules/streamx/index.js"(exports, module) {
|
|
var { EventEmitter } = require_default();
|
|
var STREAM_DESTROYED = new Error("Stream was destroyed");
|
|
var PREMATURE_CLOSE = new Error("Premature close");
|
|
var FIFO = require_fast_fifo();
|
|
var TextDecoder = require_text_decoder();
|
|
var qmt = typeof queueMicrotask === "undefined" ? (fn) => global.process.nextTick(fn) : queueMicrotask;
|
|
var MAX = (1 << 29) - 1;
|
|
var OPENING = 1;
|
|
var PREDESTROYING = 2;
|
|
var DESTROYING = 4;
|
|
var DESTROYED = 8;
|
|
var NOT_OPENING = MAX ^ OPENING;
|
|
var NOT_PREDESTROYING = MAX ^ PREDESTROYING;
|
|
var READ_ACTIVE = 1 << 4;
|
|
var READ_UPDATING = 2 << 4;
|
|
var READ_PRIMARY = 4 << 4;
|
|
var READ_QUEUED = 8 << 4;
|
|
var READ_RESUMED = 16 << 4;
|
|
var READ_PIPE_DRAINED = 32 << 4;
|
|
var READ_ENDING = 64 << 4;
|
|
var READ_EMIT_DATA = 128 << 4;
|
|
var READ_EMIT_READABLE = 256 << 4;
|
|
var READ_EMITTED_READABLE = 512 << 4;
|
|
var READ_DONE = 1024 << 4;
|
|
var READ_NEXT_TICK = 2048 << 4;
|
|
var READ_NEEDS_PUSH = 4096 << 4;
|
|
var READ_READ_AHEAD = 8192 << 4;
|
|
var READ_FLOWING = READ_RESUMED | READ_PIPE_DRAINED;
|
|
var READ_ACTIVE_AND_NEEDS_PUSH = READ_ACTIVE | READ_NEEDS_PUSH;
|
|
var READ_PRIMARY_AND_ACTIVE = READ_PRIMARY | READ_ACTIVE;
|
|
var READ_EMIT_READABLE_AND_QUEUED = READ_EMIT_READABLE | READ_QUEUED;
|
|
var READ_RESUMED_READ_AHEAD = READ_RESUMED | READ_READ_AHEAD;
|
|
var READ_NOT_ACTIVE = MAX ^ READ_ACTIVE;
|
|
var READ_NON_PRIMARY = MAX ^ READ_PRIMARY;
|
|
var READ_NON_PRIMARY_AND_PUSHED = MAX ^ (READ_PRIMARY | READ_NEEDS_PUSH);
|
|
var READ_PUSHED = MAX ^ READ_NEEDS_PUSH;
|
|
var READ_PAUSED = MAX ^ READ_RESUMED;
|
|
var READ_NOT_QUEUED = MAX ^ (READ_QUEUED | READ_EMITTED_READABLE);
|
|
var READ_NOT_ENDING = MAX ^ READ_ENDING;
|
|
var READ_PIPE_NOT_DRAINED = MAX ^ READ_FLOWING;
|
|
var READ_NOT_NEXT_TICK = MAX ^ READ_NEXT_TICK;
|
|
var READ_NOT_UPDATING = MAX ^ READ_UPDATING;
|
|
var READ_NO_READ_AHEAD = MAX ^ READ_READ_AHEAD;
|
|
var READ_PAUSED_NO_READ_AHEAD = MAX ^ READ_RESUMED_READ_AHEAD;
|
|
var WRITE_ACTIVE = 1 << 18;
|
|
var WRITE_UPDATING = 2 << 18;
|
|
var WRITE_PRIMARY = 4 << 18;
|
|
var WRITE_QUEUED = 8 << 18;
|
|
var WRITE_UNDRAINED = 16 << 18;
|
|
var WRITE_DONE = 32 << 18;
|
|
var WRITE_EMIT_DRAIN = 64 << 18;
|
|
var WRITE_NEXT_TICK = 128 << 18;
|
|
var WRITE_WRITING = 256 << 18;
|
|
var WRITE_FINISHING = 512 << 18;
|
|
var WRITE_CORKED = 1024 << 18;
|
|
var WRITE_NOT_ACTIVE = MAX ^ (WRITE_ACTIVE | WRITE_WRITING);
|
|
var WRITE_NON_PRIMARY = MAX ^ WRITE_PRIMARY;
|
|
var WRITE_NOT_FINISHING = MAX ^ (WRITE_ACTIVE | WRITE_FINISHING);
|
|
var WRITE_DRAINED = MAX ^ WRITE_UNDRAINED;
|
|
var WRITE_NOT_QUEUED = MAX ^ WRITE_QUEUED;
|
|
var WRITE_NOT_NEXT_TICK = MAX ^ WRITE_NEXT_TICK;
|
|
var WRITE_NOT_UPDATING = MAX ^ WRITE_UPDATING;
|
|
var WRITE_NOT_CORKED = MAX ^ WRITE_CORKED;
|
|
var ACTIVE = READ_ACTIVE | WRITE_ACTIVE;
|
|
var NOT_ACTIVE = MAX ^ ACTIVE;
|
|
var DONE = READ_DONE | WRITE_DONE;
|
|
var DESTROY_STATUS = DESTROYING | DESTROYED | PREDESTROYING;
|
|
var OPEN_STATUS = DESTROY_STATUS | OPENING;
|
|
var AUTO_DESTROY = DESTROY_STATUS | DONE;
|
|
var NON_PRIMARY = WRITE_NON_PRIMARY & READ_NON_PRIMARY;
|
|
var ACTIVE_OR_TICKING = WRITE_NEXT_TICK | READ_NEXT_TICK;
|
|
var TICKING = ACTIVE_OR_TICKING & NOT_ACTIVE;
|
|
var IS_OPENING = OPEN_STATUS | TICKING;
|
|
var READ_PRIMARY_STATUS = OPEN_STATUS | READ_ENDING | READ_DONE;
|
|
var READ_STATUS = OPEN_STATUS | READ_DONE | READ_QUEUED;
|
|
var READ_ENDING_STATUS = OPEN_STATUS | READ_ENDING | READ_QUEUED;
|
|
var READ_READABLE_STATUS = OPEN_STATUS | READ_EMIT_READABLE | READ_QUEUED | READ_EMITTED_READABLE;
|
|
var SHOULD_NOT_READ = OPEN_STATUS | READ_ACTIVE | READ_ENDING | READ_DONE | READ_NEEDS_PUSH | READ_READ_AHEAD;
|
|
var READ_BACKPRESSURE_STATUS = DESTROY_STATUS | READ_ENDING | READ_DONE;
|
|
var READ_UPDATE_SYNC_STATUS = READ_UPDATING | OPEN_STATUS | READ_NEXT_TICK | READ_PRIMARY;
|
|
var READ_NEXT_TICK_OR_OPENING = READ_NEXT_TICK | OPENING;
|
|
var WRITE_PRIMARY_STATUS = OPEN_STATUS | WRITE_FINISHING | WRITE_DONE;
|
|
var WRITE_QUEUED_AND_UNDRAINED = WRITE_QUEUED | WRITE_UNDRAINED;
|
|
var WRITE_QUEUED_AND_ACTIVE = WRITE_QUEUED | WRITE_ACTIVE;
|
|
var WRITE_DRAIN_STATUS = WRITE_QUEUED | WRITE_UNDRAINED | OPEN_STATUS | WRITE_ACTIVE;
|
|
var WRITE_STATUS = OPEN_STATUS | WRITE_ACTIVE | WRITE_QUEUED | WRITE_CORKED;
|
|
var WRITE_PRIMARY_AND_ACTIVE = WRITE_PRIMARY | WRITE_ACTIVE;
|
|
var WRITE_ACTIVE_AND_WRITING = WRITE_ACTIVE | WRITE_WRITING;
|
|
var WRITE_FINISHING_STATUS = OPEN_STATUS | WRITE_FINISHING | WRITE_QUEUED_AND_ACTIVE | WRITE_DONE;
|
|
var WRITE_BACKPRESSURE_STATUS = WRITE_UNDRAINED | DESTROY_STATUS | WRITE_FINISHING | WRITE_DONE;
|
|
var WRITE_UPDATE_SYNC_STATUS = WRITE_UPDATING | OPEN_STATUS | WRITE_NEXT_TICK | WRITE_PRIMARY;
|
|
var WRITE_DROP_DATA = WRITE_FINISHING | WRITE_DONE | DESTROY_STATUS;
|
|
var asyncIterator = Symbol.asyncIterator || Symbol("asyncIterator");
|
|
var WritableState = class {
|
|
constructor(stream, { highWaterMark = 16384, map = null, mapWritable, byteLength, byteLengthWritable } = {}) {
|
|
this.stream = stream;
|
|
this.queue = new FIFO();
|
|
this.highWaterMark = highWaterMark;
|
|
this.buffered = 0;
|
|
this.error = null;
|
|
this.pipeline = null;
|
|
this.drains = null;
|
|
this.byteLength = byteLengthWritable || byteLength || defaultByteLength;
|
|
this.map = mapWritable || map;
|
|
this.afterWrite = afterWrite.bind(this);
|
|
this.afterUpdateNextTick = updateWriteNT.bind(this);
|
|
}
|
|
get ending() {
|
|
return (this.stream._duplexState & WRITE_FINISHING) !== 0;
|
|
}
|
|
get ended() {
|
|
return (this.stream._duplexState & WRITE_DONE) !== 0;
|
|
}
|
|
push(data) {
|
|
if ((this.stream._duplexState & WRITE_DROP_DATA) !== 0) return false;
|
|
if (this.map !== null) data = this.map(data);
|
|
this.buffered += this.byteLength(data);
|
|
this.queue.push(data);
|
|
if (this.buffered < this.highWaterMark) {
|
|
this.stream._duplexState |= WRITE_QUEUED;
|
|
return true;
|
|
}
|
|
this.stream._duplexState |= WRITE_QUEUED_AND_UNDRAINED;
|
|
return false;
|
|
}
|
|
shift() {
|
|
const data = this.queue.shift();
|
|
this.buffered -= this.byteLength(data);
|
|
if (this.buffered === 0) this.stream._duplexState &= WRITE_NOT_QUEUED;
|
|
return data;
|
|
}
|
|
end(data) {
|
|
if (typeof data === "function") this.stream.once("finish", data);
|
|
else if (data !== void 0 && data !== null) this.push(data);
|
|
this.stream._duplexState = (this.stream._duplexState | WRITE_FINISHING) & WRITE_NON_PRIMARY;
|
|
}
|
|
autoBatch(data, cb) {
|
|
const buffer = [];
|
|
const stream = this.stream;
|
|
buffer.push(data);
|
|
while ((stream._duplexState & WRITE_STATUS) === WRITE_QUEUED_AND_ACTIVE) {
|
|
buffer.push(stream._writableState.shift());
|
|
}
|
|
if ((stream._duplexState & OPEN_STATUS) !== 0) return cb(null);
|
|
stream._writev(buffer, cb);
|
|
}
|
|
update() {
|
|
const stream = this.stream;
|
|
stream._duplexState |= WRITE_UPDATING;
|
|
do {
|
|
while ((stream._duplexState & WRITE_STATUS) === WRITE_QUEUED) {
|
|
const data = this.shift();
|
|
stream._duplexState |= WRITE_ACTIVE_AND_WRITING;
|
|
stream._write(data, this.afterWrite);
|
|
}
|
|
if ((stream._duplexState & WRITE_PRIMARY_AND_ACTIVE) === 0) this.updateNonPrimary();
|
|
} while (this.continueUpdate() === true);
|
|
stream._duplexState &= WRITE_NOT_UPDATING;
|
|
}
|
|
updateNonPrimary() {
|
|
const stream = this.stream;
|
|
if ((stream._duplexState & WRITE_FINISHING_STATUS) === WRITE_FINISHING) {
|
|
stream._duplexState = stream._duplexState | WRITE_ACTIVE;
|
|
stream._final(afterFinal.bind(this));
|
|
return;
|
|
}
|
|
if ((stream._duplexState & DESTROY_STATUS) === DESTROYING) {
|
|
if ((stream._duplexState & ACTIVE_OR_TICKING) === 0) {
|
|
stream._duplexState |= ACTIVE;
|
|
stream._destroy(afterDestroy.bind(this));
|
|
}
|
|
return;
|
|
}
|
|
if ((stream._duplexState & IS_OPENING) === OPENING) {
|
|
stream._duplexState = (stream._duplexState | ACTIVE) & NOT_OPENING;
|
|
stream._open(afterOpen.bind(this));
|
|
}
|
|
}
|
|
continueUpdate() {
|
|
if ((this.stream._duplexState & WRITE_NEXT_TICK) === 0) return false;
|
|
this.stream._duplexState &= WRITE_NOT_NEXT_TICK;
|
|
return true;
|
|
}
|
|
updateCallback() {
|
|
if ((this.stream._duplexState & WRITE_UPDATE_SYNC_STATUS) === WRITE_PRIMARY) this.update();
|
|
else this.updateNextTick();
|
|
}
|
|
updateNextTick() {
|
|
if ((this.stream._duplexState & WRITE_NEXT_TICK) !== 0) return;
|
|
this.stream._duplexState |= WRITE_NEXT_TICK;
|
|
if ((this.stream._duplexState & WRITE_UPDATING) === 0) qmt(this.afterUpdateNextTick);
|
|
}
|
|
};
|
|
var ReadableState = class {
|
|
constructor(stream, { highWaterMark = 16384, map = null, mapReadable, byteLength, byteLengthReadable } = {}) {
|
|
this.stream = stream;
|
|
this.queue = new FIFO();
|
|
this.highWaterMark = highWaterMark === 0 ? 1 : highWaterMark;
|
|
this.buffered = 0;
|
|
this.readAhead = highWaterMark > 0;
|
|
this.error = null;
|
|
this.pipeline = null;
|
|
this.byteLength = byteLengthReadable || byteLength || defaultByteLength;
|
|
this.map = mapReadable || map;
|
|
this.pipeTo = null;
|
|
this.afterRead = afterRead.bind(this);
|
|
this.afterUpdateNextTick = updateReadNT.bind(this);
|
|
}
|
|
get ending() {
|
|
return (this.stream._duplexState & READ_ENDING) !== 0;
|
|
}
|
|
get ended() {
|
|
return (this.stream._duplexState & READ_DONE) !== 0;
|
|
}
|
|
pipe(pipeTo, cb) {
|
|
if (this.pipeTo !== null) throw new Error("Can only pipe to one destination");
|
|
if (typeof cb !== "function") cb = null;
|
|
this.stream._duplexState |= READ_PIPE_DRAINED;
|
|
this.pipeTo = pipeTo;
|
|
this.pipeline = new Pipeline(this.stream, pipeTo, cb);
|
|
if (cb) this.stream.on("error", noop);
|
|
if (isStreamx(pipeTo)) {
|
|
pipeTo._writableState.pipeline = this.pipeline;
|
|
if (cb) pipeTo.on("error", noop);
|
|
pipeTo.on("finish", this.pipeline.finished.bind(this.pipeline));
|
|
} else {
|
|
const onerror = this.pipeline.done.bind(this.pipeline, pipeTo);
|
|
const onclose = this.pipeline.done.bind(this.pipeline, pipeTo, null);
|
|
pipeTo.on("error", onerror);
|
|
pipeTo.on("close", onclose);
|
|
pipeTo.on("finish", this.pipeline.finished.bind(this.pipeline));
|
|
}
|
|
pipeTo.on("drain", afterDrain.bind(this));
|
|
this.stream.emit("piping", pipeTo);
|
|
pipeTo.emit("pipe", this.stream);
|
|
}
|
|
push(data) {
|
|
const stream = this.stream;
|
|
if (data === null) {
|
|
this.highWaterMark = 0;
|
|
stream._duplexState = (stream._duplexState | READ_ENDING) & READ_NON_PRIMARY_AND_PUSHED;
|
|
return false;
|
|
}
|
|
if (this.map !== null) {
|
|
data = this.map(data);
|
|
if (data === null) {
|
|
stream._duplexState &= READ_PUSHED;
|
|
return this.buffered < this.highWaterMark;
|
|
}
|
|
}
|
|
this.buffered += this.byteLength(data);
|
|
this.queue.push(data);
|
|
stream._duplexState = (stream._duplexState | READ_QUEUED) & READ_PUSHED;
|
|
return this.buffered < this.highWaterMark;
|
|
}
|
|
shift() {
|
|
const data = this.queue.shift();
|
|
this.buffered -= this.byteLength(data);
|
|
if (this.buffered === 0) this.stream._duplexState &= READ_NOT_QUEUED;
|
|
return data;
|
|
}
|
|
unshift(data) {
|
|
const pending = [this.map !== null ? this.map(data) : data];
|
|
while (this.buffered > 0) pending.push(this.shift());
|
|
for (let i = 0; i < pending.length - 1; i++) {
|
|
const data2 = pending[i];
|
|
this.buffered += this.byteLength(data2);
|
|
this.queue.push(data2);
|
|
}
|
|
this.push(pending[pending.length - 1]);
|
|
}
|
|
read() {
|
|
const stream = this.stream;
|
|
if ((stream._duplexState & READ_STATUS) === READ_QUEUED) {
|
|
const data = this.shift();
|
|
if (this.pipeTo !== null && this.pipeTo.write(data) === false)
|
|
stream._duplexState &= READ_PIPE_NOT_DRAINED;
|
|
if ((stream._duplexState & READ_EMIT_DATA) !== 0) stream.emit("data", data);
|
|
return data;
|
|
}
|
|
if (this.readAhead === false) {
|
|
stream._duplexState |= READ_READ_AHEAD;
|
|
this.updateNextTick();
|
|
}
|
|
return null;
|
|
}
|
|
drain() {
|
|
const stream = this.stream;
|
|
while ((stream._duplexState & READ_STATUS) === READ_QUEUED && (stream._duplexState & READ_FLOWING) !== 0) {
|
|
const data = this.shift();
|
|
if (this.pipeTo !== null && this.pipeTo.write(data) === false)
|
|
stream._duplexState &= READ_PIPE_NOT_DRAINED;
|
|
if ((stream._duplexState & READ_EMIT_DATA) !== 0) stream.emit("data", data);
|
|
}
|
|
}
|
|
update() {
|
|
const stream = this.stream;
|
|
stream._duplexState |= READ_UPDATING;
|
|
do {
|
|
this.drain();
|
|
while (this.buffered < this.highWaterMark && (stream._duplexState & SHOULD_NOT_READ) === READ_READ_AHEAD) {
|
|
stream._duplexState |= READ_ACTIVE_AND_NEEDS_PUSH;
|
|
stream._read(this.afterRead);
|
|
this.drain();
|
|
}
|
|
if ((stream._duplexState & READ_READABLE_STATUS) === READ_EMIT_READABLE_AND_QUEUED) {
|
|
stream._duplexState |= READ_EMITTED_READABLE;
|
|
stream.emit("readable");
|
|
}
|
|
if ((stream._duplexState & READ_PRIMARY_AND_ACTIVE) === 0) this.updateNonPrimary();
|
|
} while (this.continueUpdate() === true);
|
|
stream._duplexState &= READ_NOT_UPDATING;
|
|
}
|
|
updateNonPrimary() {
|
|
const stream = this.stream;
|
|
if ((stream._duplexState & READ_ENDING_STATUS) === READ_ENDING) {
|
|
stream._duplexState = (stream._duplexState | READ_DONE) & READ_NOT_ENDING;
|
|
stream.emit("end");
|
|
if ((stream._duplexState & AUTO_DESTROY) === DONE) stream._duplexState |= DESTROYING;
|
|
if (this.pipeTo !== null) this.pipeTo.end();
|
|
}
|
|
if ((stream._duplexState & DESTROY_STATUS) === DESTROYING) {
|
|
if ((stream._duplexState & ACTIVE_OR_TICKING) === 0) {
|
|
stream._duplexState |= ACTIVE;
|
|
stream._destroy(afterDestroy.bind(this));
|
|
}
|
|
return;
|
|
}
|
|
if ((stream._duplexState & IS_OPENING) === OPENING) {
|
|
stream._duplexState = (stream._duplexState | ACTIVE) & NOT_OPENING;
|
|
stream._open(afterOpen.bind(this));
|
|
}
|
|
}
|
|
continueUpdate() {
|
|
if ((this.stream._duplexState & READ_NEXT_TICK) === 0) return false;
|
|
this.stream._duplexState &= READ_NOT_NEXT_TICK;
|
|
return true;
|
|
}
|
|
updateCallback() {
|
|
if ((this.stream._duplexState & READ_UPDATE_SYNC_STATUS) === READ_PRIMARY) this.update();
|
|
else this.updateNextTick();
|
|
}
|
|
updateNextTickIfOpen() {
|
|
if ((this.stream._duplexState & READ_NEXT_TICK_OR_OPENING) !== 0) return;
|
|
this.stream._duplexState |= READ_NEXT_TICK;
|
|
if ((this.stream._duplexState & READ_UPDATING) === 0) qmt(this.afterUpdateNextTick);
|
|
}
|
|
updateNextTick() {
|
|
if ((this.stream._duplexState & READ_NEXT_TICK) !== 0) return;
|
|
this.stream._duplexState |= READ_NEXT_TICK;
|
|
if ((this.stream._duplexState & READ_UPDATING) === 0) qmt(this.afterUpdateNextTick);
|
|
}
|
|
};
|
|
var TransformState = class {
|
|
constructor(stream) {
|
|
this.data = null;
|
|
this.afterTransform = afterTransform.bind(stream);
|
|
this.afterFinal = null;
|
|
}
|
|
};
|
|
var Pipeline = class {
|
|
constructor(src, dst, cb) {
|
|
this.from = src;
|
|
this.to = dst;
|
|
this.afterPipe = cb;
|
|
this.error = null;
|
|
this.pipeToFinished = false;
|
|
}
|
|
finished() {
|
|
this.pipeToFinished = true;
|
|
}
|
|
done(stream, err) {
|
|
if (err) this.error = err;
|
|
if (stream === this.to) {
|
|
this.to = null;
|
|
if (this.from !== null) {
|
|
if ((this.from._duplexState & READ_DONE) === 0 || !this.pipeToFinished) {
|
|
this.from.destroy(this.error || new Error("Writable stream closed prematurely"));
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
if (stream === this.from) {
|
|
this.from = null;
|
|
if (this.to !== null) {
|
|
if ((stream._duplexState & READ_DONE) === 0) {
|
|
this.to.destroy(this.error || new Error("Readable stream closed before ending"));
|
|
}
|
|
return;
|
|
}
|
|
}
|
|
if (this.afterPipe !== null) this.afterPipe(this.error);
|
|
this.to = this.from = this.afterPipe = null;
|
|
}
|
|
};
|
|
function afterDrain() {
|
|
this.stream._duplexState |= READ_PIPE_DRAINED;
|
|
this.updateCallback();
|
|
}
|
|
function afterFinal(err) {
|
|
const stream = this.stream;
|
|
if (err) stream.destroy(err);
|
|
if ((stream._duplexState & DESTROY_STATUS) === 0) {
|
|
stream._duplexState |= WRITE_DONE;
|
|
stream.emit("finish");
|
|
}
|
|
if ((stream._duplexState & AUTO_DESTROY) === DONE) {
|
|
stream._duplexState |= DESTROYING;
|
|
}
|
|
stream._duplexState &= WRITE_NOT_FINISHING;
|
|
if ((stream._duplexState & WRITE_UPDATING) === 0) this.update();
|
|
else this.updateNextTick();
|
|
}
|
|
function afterDestroy(err) {
|
|
const stream = this.stream;
|
|
if (!err && this.error !== STREAM_DESTROYED) err = this.error;
|
|
if (err) stream.emit("error", err);
|
|
stream._duplexState |= DESTROYED;
|
|
stream.emit("close");
|
|
const rs = stream._readableState;
|
|
const ws = stream._writableState;
|
|
if (rs !== null && rs.pipeline !== null) rs.pipeline.done(stream, err);
|
|
if (ws !== null) {
|
|
while (ws.drains !== null && ws.drains.length > 0) ws.drains.shift().resolve(false);
|
|
if (ws.pipeline !== null) ws.pipeline.done(stream, err);
|
|
}
|
|
}
|
|
function afterWrite(err) {
|
|
const stream = this.stream;
|
|
if (err) stream.destroy(err);
|
|
stream._duplexState &= WRITE_NOT_ACTIVE;
|
|
if (this.drains !== null) tickDrains(this.drains);
|
|
if ((stream._duplexState & WRITE_DRAIN_STATUS) === WRITE_UNDRAINED) {
|
|
stream._duplexState &= WRITE_DRAINED;
|
|
if ((stream._duplexState & WRITE_EMIT_DRAIN) === WRITE_EMIT_DRAIN) {
|
|
stream.emit("drain");
|
|
}
|
|
}
|
|
this.updateCallback();
|
|
}
|
|
function afterRead(err) {
|
|
if (err) this.stream.destroy(err);
|
|
this.stream._duplexState &= READ_NOT_ACTIVE;
|
|
if (this.readAhead === false && (this.stream._duplexState & READ_RESUMED) === 0)
|
|
this.stream._duplexState &= READ_NO_READ_AHEAD;
|
|
this.updateCallback();
|
|
}
|
|
function updateReadNT() {
|
|
if ((this.stream._duplexState & READ_UPDATING) === 0) {
|
|
this.stream._duplexState &= READ_NOT_NEXT_TICK;
|
|
this.update();
|
|
}
|
|
}
|
|
function updateWriteNT() {
|
|
if ((this.stream._duplexState & WRITE_UPDATING) === 0) {
|
|
this.stream._duplexState &= WRITE_NOT_NEXT_TICK;
|
|
this.update();
|
|
}
|
|
}
|
|
function tickDrains(drains) {
|
|
for (let i = 0; i < drains.length; i++) {
|
|
if (--drains[i].writes === 0) {
|
|
drains.shift().resolve(true);
|
|
i--;
|
|
}
|
|
}
|
|
}
|
|
function afterOpen(err) {
|
|
const stream = this.stream;
|
|
if (err) stream.destroy(err);
|
|
if ((stream._duplexState & DESTROYING) === 0) {
|
|
if ((stream._duplexState & READ_PRIMARY_STATUS) === 0) stream._duplexState |= READ_PRIMARY;
|
|
if ((stream._duplexState & WRITE_PRIMARY_STATUS) === 0) stream._duplexState |= WRITE_PRIMARY;
|
|
stream.emit("open");
|
|
}
|
|
stream._duplexState &= NOT_ACTIVE;
|
|
if (stream._writableState !== null) {
|
|
stream._writableState.updateCallback();
|
|
}
|
|
if (stream._readableState !== null) {
|
|
stream._readableState.updateCallback();
|
|
}
|
|
}
|
|
function afterTransform(err, data) {
|
|
if (data !== void 0 && data !== null) this.push(data);
|
|
this._writableState.afterWrite(err);
|
|
}
|
|
function newListener(name) {
|
|
if (this._readableState !== null) {
|
|
if (name === "data") {
|
|
this._duplexState |= READ_EMIT_DATA | READ_RESUMED_READ_AHEAD;
|
|
this._readableState.updateNextTick();
|
|
}
|
|
if (name === "readable") {
|
|
this._duplexState |= READ_EMIT_READABLE;
|
|
this._readableState.updateNextTick();
|
|
}
|
|
}
|
|
if (this._writableState !== null) {
|
|
if (name === "drain") {
|
|
this._duplexState |= WRITE_EMIT_DRAIN;
|
|
this._writableState.updateNextTick();
|
|
}
|
|
}
|
|
}
|
|
var Stream = class extends EventEmitter {
|
|
constructor(opts) {
|
|
super();
|
|
this._duplexState = 0;
|
|
this._readableState = null;
|
|
this._writableState = null;
|
|
if (opts) {
|
|
if (opts.open) this._open = opts.open;
|
|
if (opts.destroy) this._destroy = opts.destroy;
|
|
if (opts.predestroy) this._predestroy = opts.predestroy;
|
|
if (opts.signal) {
|
|
opts.signal.addEventListener("abort", abort.bind(this));
|
|
}
|
|
}
|
|
this.on("newListener", newListener);
|
|
}
|
|
_open(cb) {
|
|
cb(null);
|
|
}
|
|
_destroy(cb) {
|
|
cb(null);
|
|
}
|
|
_predestroy() {
|
|
}
|
|
get readable() {
|
|
return this._readableState !== null ? true : void 0;
|
|
}
|
|
get writable() {
|
|
return this._writableState !== null ? true : void 0;
|
|
}
|
|
get destroyed() {
|
|
return (this._duplexState & DESTROYED) !== 0;
|
|
}
|
|
get destroying() {
|
|
return (this._duplexState & DESTROY_STATUS) !== 0;
|
|
}
|
|
destroy(err) {
|
|
if ((this._duplexState & DESTROY_STATUS) === 0) {
|
|
if (!err) err = STREAM_DESTROYED;
|
|
this._duplexState = (this._duplexState | DESTROYING) & NON_PRIMARY;
|
|
if (this._readableState !== null) {
|
|
this._readableState.highWaterMark = 0;
|
|
this._readableState.error = err;
|
|
}
|
|
if (this._writableState !== null) {
|
|
this._writableState.highWaterMark = 0;
|
|
this._writableState.error = err;
|
|
}
|
|
this._duplexState |= PREDESTROYING;
|
|
this._predestroy();
|
|
this._duplexState &= NOT_PREDESTROYING;
|
|
if (this._readableState !== null) this._readableState.updateNextTick();
|
|
if (this._writableState !== null) this._writableState.updateNextTick();
|
|
}
|
|
}
|
|
};
|
|
var Readable = class _Readable extends Stream {
|
|
constructor(opts) {
|
|
super(opts);
|
|
this._duplexState |= OPENING | WRITE_DONE | READ_READ_AHEAD;
|
|
this._readableState = new ReadableState(this, opts);
|
|
if (opts) {
|
|
if (this._readableState.readAhead === false) this._duplexState &= READ_NO_READ_AHEAD;
|
|
if (opts.read) this._read = opts.read;
|
|
if (opts.eagerOpen) this._readableState.updateNextTick();
|
|
if (opts.encoding) this.setEncoding(opts.encoding);
|
|
}
|
|
}
|
|
setEncoding(encoding) {
|
|
const dec = new TextDecoder(encoding);
|
|
const map = this._readableState.map || echo;
|
|
this._readableState.map = mapOrSkip;
|
|
return this;
|
|
function mapOrSkip(data) {
|
|
const next = dec.push(data);
|
|
return next === "" && (data.byteLength !== 0 || dec.remaining > 0) ? null : map(next);
|
|
}
|
|
}
|
|
_read(cb) {
|
|
cb(null);
|
|
}
|
|
pipe(dest, cb) {
|
|
this._readableState.updateNextTick();
|
|
this._readableState.pipe(dest, cb);
|
|
return dest;
|
|
}
|
|
read() {
|
|
this._readableState.updateNextTick();
|
|
return this._readableState.read();
|
|
}
|
|
push(data) {
|
|
this._readableState.updateNextTickIfOpen();
|
|
return this._readableState.push(data);
|
|
}
|
|
unshift(data) {
|
|
this._readableState.updateNextTickIfOpen();
|
|
return this._readableState.unshift(data);
|
|
}
|
|
resume() {
|
|
this._duplexState |= READ_RESUMED_READ_AHEAD;
|
|
this._readableState.updateNextTick();
|
|
return this;
|
|
}
|
|
pause() {
|
|
this._duplexState &= this._readableState.readAhead === false ? READ_PAUSED_NO_READ_AHEAD : READ_PAUSED;
|
|
return this;
|
|
}
|
|
static _fromAsyncIterator(ite, opts) {
|
|
let destroy;
|
|
const rs = new _Readable({
|
|
...opts,
|
|
read(cb) {
|
|
ite.next().then(push).then(cb.bind(null, null)).catch(cb);
|
|
},
|
|
predestroy() {
|
|
destroy = ite.return();
|
|
},
|
|
destroy(cb) {
|
|
if (!destroy) return cb(null);
|
|
destroy.then(cb.bind(null, null)).catch(cb);
|
|
}
|
|
});
|
|
return rs;
|
|
function push(data) {
|
|
if (data.done) rs.push(null);
|
|
else rs.push(data.value);
|
|
}
|
|
}
|
|
static from(data, opts) {
|
|
if (isReadStreamx(data)) return data;
|
|
if (data[asyncIterator]) return this._fromAsyncIterator(data[asyncIterator](), opts);
|
|
if (!Array.isArray(data)) data = data === void 0 ? [] : [data];
|
|
let i = 0;
|
|
return new _Readable({
|
|
...opts,
|
|
read(cb) {
|
|
this.push(i === data.length ? null : data[i++]);
|
|
cb(null);
|
|
}
|
|
});
|
|
}
|
|
static isBackpressured(rs) {
|
|
return (rs._duplexState & READ_BACKPRESSURE_STATUS) !== 0 || rs._readableState.buffered >= rs._readableState.highWaterMark;
|
|
}
|
|
static isPaused(rs) {
|
|
return (rs._duplexState & READ_RESUMED) === 0;
|
|
}
|
|
[asyncIterator]() {
|
|
const stream = this;
|
|
let error = null;
|
|
let promiseResolve = null;
|
|
let promiseReject = null;
|
|
this.on("error", (err) => {
|
|
error = err;
|
|
});
|
|
this.on("readable", onreadable);
|
|
this.on("close", onclose);
|
|
return {
|
|
[asyncIterator]() {
|
|
return this;
|
|
},
|
|
next() {
|
|
return new Promise(function(resolve, reject) {
|
|
promiseResolve = resolve;
|
|
promiseReject = reject;
|
|
const data = stream.read();
|
|
if (data !== null) ondata(data);
|
|
else if ((stream._duplexState & DESTROYED) !== 0) ondata(null);
|
|
});
|
|
},
|
|
return() {
|
|
return destroy(null);
|
|
},
|
|
throw(err) {
|
|
return destroy(err);
|
|
}
|
|
};
|
|
function onreadable() {
|
|
if (promiseResolve !== null) ondata(stream.read());
|
|
}
|
|
function onclose() {
|
|
if (promiseResolve !== null) ondata(null);
|
|
}
|
|
function ondata(data) {
|
|
if (promiseReject === null) return;
|
|
if (error) promiseReject(error);
|
|
else if (data === null && (stream._duplexState & READ_DONE) === 0)
|
|
promiseReject(STREAM_DESTROYED);
|
|
else promiseResolve({ value: data, done: data === null });
|
|
promiseReject = promiseResolve = null;
|
|
}
|
|
function destroy(err) {
|
|
stream.destroy(err);
|
|
return new Promise((resolve, reject) => {
|
|
if (stream._duplexState & DESTROYED) return resolve({ value: void 0, done: true });
|
|
stream.once("close", function() {
|
|
if (err) reject(err);
|
|
else resolve({ value: void 0, done: true });
|
|
});
|
|
});
|
|
}
|
|
}
|
|
};
|
|
var Writable = class extends Stream {
|
|
constructor(opts) {
|
|
super(opts);
|
|
this._duplexState |= OPENING | READ_DONE;
|
|
this._writableState = new WritableState(this, opts);
|
|
if (opts) {
|
|
if (opts.writev) this._writev = opts.writev;
|
|
if (opts.write) this._write = opts.write;
|
|
if (opts.final) this._final = opts.final;
|
|
if (opts.eagerOpen) this._writableState.updateNextTick();
|
|
}
|
|
}
|
|
cork() {
|
|
this._duplexState |= WRITE_CORKED;
|
|
}
|
|
uncork() {
|
|
this._duplexState &= WRITE_NOT_CORKED;
|
|
this._writableState.updateNextTick();
|
|
}
|
|
_writev(batch, cb) {
|
|
cb(null);
|
|
}
|
|
_write(data, cb) {
|
|
this._writableState.autoBatch(data, cb);
|
|
}
|
|
_final(cb) {
|
|
cb(null);
|
|
}
|
|
static isBackpressured(ws) {
|
|
return (ws._duplexState & WRITE_BACKPRESSURE_STATUS) !== 0;
|
|
}
|
|
static drained(ws) {
|
|
if (ws.destroyed) return Promise.resolve(false);
|
|
const state = ws._writableState;
|
|
const pending = isWritev(ws) ? Math.min(1, state.queue.length) : state.queue.length;
|
|
const writes = pending + (ws._duplexState & WRITE_WRITING ? 1 : 0);
|
|
if (writes === 0) return Promise.resolve(true);
|
|
if (state.drains === null) state.drains = [];
|
|
return new Promise((resolve) => {
|
|
state.drains.push({ writes, resolve });
|
|
});
|
|
}
|
|
write(data) {
|
|
this._writableState.updateNextTick();
|
|
return this._writableState.push(data);
|
|
}
|
|
end(data) {
|
|
this._writableState.updateNextTick();
|
|
this._writableState.end(data);
|
|
return this;
|
|
}
|
|
};
|
|
var Duplex = class extends Readable {
|
|
// and Writable
|
|
constructor(opts) {
|
|
super(opts);
|
|
this._duplexState = OPENING | this._duplexState & READ_READ_AHEAD;
|
|
this._writableState = new WritableState(this, opts);
|
|
if (opts) {
|
|
if (opts.writev) this._writev = opts.writev;
|
|
if (opts.write) this._write = opts.write;
|
|
if (opts.final) this._final = opts.final;
|
|
}
|
|
}
|
|
cork() {
|
|
this._duplexState |= WRITE_CORKED;
|
|
}
|
|
uncork() {
|
|
this._duplexState &= WRITE_NOT_CORKED;
|
|
this._writableState.updateNextTick();
|
|
}
|
|
_writev(batch, cb) {
|
|
cb(null);
|
|
}
|
|
_write(data, cb) {
|
|
this._writableState.autoBatch(data, cb);
|
|
}
|
|
_final(cb) {
|
|
cb(null);
|
|
}
|
|
write(data) {
|
|
this._writableState.updateNextTick();
|
|
return this._writableState.push(data);
|
|
}
|
|
end(data) {
|
|
this._writableState.updateNextTick();
|
|
this._writableState.end(data);
|
|
return this;
|
|
}
|
|
};
|
|
var Transform = class extends Duplex {
|
|
constructor(opts) {
|
|
super(opts);
|
|
this._transformState = new TransformState(this);
|
|
if (opts) {
|
|
if (opts.transform) this._transform = opts.transform;
|
|
if (opts.flush) this._flush = opts.flush;
|
|
}
|
|
}
|
|
_write(data, cb) {
|
|
if (this._readableState.buffered >= this._readableState.highWaterMark) {
|
|
this._transformState.data = data;
|
|
} else {
|
|
this._transform(data, this._transformState.afterTransform);
|
|
}
|
|
}
|
|
_read(cb) {
|
|
if (this._transformState.data !== null) {
|
|
const data = this._transformState.data;
|
|
this._transformState.data = null;
|
|
cb(null);
|
|
this._transform(data, this._transformState.afterTransform);
|
|
} else {
|
|
cb(null);
|
|
}
|
|
}
|
|
destroy(err) {
|
|
super.destroy(err);
|
|
if (this._transformState.data !== null) {
|
|
this._transformState.data = null;
|
|
this._transformState.afterTransform();
|
|
}
|
|
}
|
|
_transform(data, cb) {
|
|
cb(null, data);
|
|
}
|
|
_flush(cb) {
|
|
cb(null);
|
|
}
|
|
_final(cb) {
|
|
this._transformState.afterFinal = cb;
|
|
this._flush(transformAfterFlush.bind(this));
|
|
}
|
|
};
|
|
var PassThrough = class extends Transform {
|
|
};
|
|
function transformAfterFlush(err, data) {
|
|
const cb = this._transformState.afterFinal;
|
|
if (err) return cb(err);
|
|
if (data !== null && data !== void 0) this.push(data);
|
|
this.push(null);
|
|
cb(null);
|
|
}
|
|
function pipelinePromise(...streams) {
|
|
return new Promise((resolve, reject) => {
|
|
return pipeline(...streams, (err) => {
|
|
if (err) return reject(err);
|
|
resolve();
|
|
});
|
|
});
|
|
}
|
|
function pipeline(stream, ...streams) {
|
|
const all = Array.isArray(stream) ? [...stream, ...streams] : [stream, ...streams];
|
|
const done = all.length && typeof all[all.length - 1] === "function" ? all.pop() : null;
|
|
if (all.length < 2) throw new Error("Pipeline requires at least 2 streams");
|
|
let src = all[0];
|
|
let dest = null;
|
|
let error = null;
|
|
for (let i = 1; i < all.length; i++) {
|
|
dest = all[i];
|
|
if (isStreamx(src)) {
|
|
src.pipe(dest, onerror);
|
|
} else {
|
|
errorHandle(src, true, i > 1, onerror);
|
|
src.pipe(dest);
|
|
}
|
|
src = dest;
|
|
}
|
|
if (done) {
|
|
let fin = false;
|
|
const autoDestroy = isStreamx(dest) || !!(dest._writableState && dest._writableState.autoDestroy);
|
|
dest.on("error", (err) => {
|
|
if (error === null) error = err;
|
|
});
|
|
dest.on("finish", () => {
|
|
fin = true;
|
|
if (!autoDestroy) done(error);
|
|
});
|
|
if (autoDestroy) {
|
|
dest.on("close", () => done(error || (fin ? null : PREMATURE_CLOSE)));
|
|
}
|
|
}
|
|
return dest;
|
|
function errorHandle(s, rd, wr, onerror2) {
|
|
s.on("error", onerror2);
|
|
s.on("close", onclose);
|
|
function onclose() {
|
|
if (rd && s._readableState && !s._readableState.ended) return onerror2(PREMATURE_CLOSE);
|
|
if (wr && s._writableState && !s._writableState.ended) return onerror2(PREMATURE_CLOSE);
|
|
}
|
|
}
|
|
function onerror(err) {
|
|
if (!err || error) return;
|
|
error = err;
|
|
for (const s of all) {
|
|
s.destroy(err);
|
|
}
|
|
}
|
|
}
|
|
function echo(s) {
|
|
return s;
|
|
}
|
|
function isStream(stream) {
|
|
return !!stream._readableState || !!stream._writableState;
|
|
}
|
|
function isStreamx(stream) {
|
|
return typeof stream._duplexState === "number" && isStream(stream);
|
|
}
|
|
function isEnding(stream) {
|
|
return !!stream._readableState && stream._readableState.ending;
|
|
}
|
|
function isEnded(stream) {
|
|
return !!stream._readableState && stream._readableState.ended;
|
|
}
|
|
function isFinishing(stream) {
|
|
return !!stream._writableState && stream._writableState.ending;
|
|
}
|
|
function isFinished(stream) {
|
|
return !!stream._writableState && stream._writableState.ended;
|
|
}
|
|
function getStreamError(stream, opts = {}) {
|
|
const err = stream._readableState && stream._readableState.error || stream._writableState && stream._writableState.error;
|
|
return !opts.all && err === STREAM_DESTROYED ? null : err;
|
|
}
|
|
function isReadStreamx(stream) {
|
|
return isStreamx(stream) && stream.readable;
|
|
}
|
|
function isDisturbed(stream) {
|
|
return (stream._duplexState & OPENING) !== OPENING || (stream._duplexState & DESTROYING) === DESTROYING || (stream._duplexState & ACTIVE_OR_TICKING) !== 0;
|
|
}
|
|
function isTypedArray(data) {
|
|
return typeof data === "object" && data !== null && typeof data.byteLength === "number";
|
|
}
|
|
function defaultByteLength(data) {
|
|
return isTypedArray(data) ? data.byteLength : 1024;
|
|
}
|
|
function noop() {
|
|
}
|
|
function abort() {
|
|
this.destroy(new Error("Stream aborted."));
|
|
}
|
|
function isWritev(s) {
|
|
return s._writev !== Writable.prototype._writev && s._writev !== Duplex.prototype._writev;
|
|
}
|
|
module.exports = {
|
|
pipeline,
|
|
pipelinePromise,
|
|
isStream,
|
|
isStreamx,
|
|
isEnding,
|
|
isEnded,
|
|
isFinishing,
|
|
isFinished,
|
|
isDisturbed,
|
|
getStreamError,
|
|
Stream,
|
|
Writable,
|
|
Readable,
|
|
Duplex,
|
|
Transform,
|
|
// Export PassThrough for compatibility with Node.js core's stream module
|
|
PassThrough
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/udx-native/lib/stream.js
|
|
var require_stream = __commonJS({
|
|
"../../node_modules/udx-native/lib/stream.js"(exports, module) {
|
|
var streamx = require_streamx();
|
|
var b4a = require_b4a();
|
|
var binding = require_binding();
|
|
var ip = require_ip();
|
|
var MAX_PACKET = 2048;
|
|
var BUFFER_SIZE = 65536 + MAX_PACKET;
|
|
module.exports = class UDXStream extends streamx.Duplex {
|
|
constructor(udx, id, opts = {}) {
|
|
super({ mapWritable: toBuffer, eagerOpen: true });
|
|
this.udx = udx;
|
|
this.socket = null;
|
|
this._handle = b4a.alloc(binding.sizeof_udx_napi_stream_t);
|
|
this._view = new Uint32Array(
|
|
this._handle.buffer,
|
|
this._handle.byteOffset,
|
|
this._handle.byteLength >> 2
|
|
);
|
|
this._view16 = new Uint16Array(
|
|
this._handle.buffer,
|
|
this._handle.byteOffset,
|
|
this._handle.byteLength >> 1
|
|
);
|
|
this._view64 = new BigUint64Array(
|
|
this._handle.buffer,
|
|
this._handle.byteOffset,
|
|
this._handle.byteLength >> 3
|
|
);
|
|
this._wreqs = [];
|
|
this._wfree = [];
|
|
this._sreqs = [];
|
|
this._sfree = [];
|
|
this._closed = false;
|
|
this._flushing = 0;
|
|
this._flushes = [];
|
|
this._buffer = null;
|
|
this._reallocData();
|
|
this._onwrite = null;
|
|
this._ondestroy = null;
|
|
this._firewall = opts.firewall || firewallAll;
|
|
this._remoteChanging = null;
|
|
this._previousSocket = null;
|
|
this.id = id;
|
|
this.remoteId = 0;
|
|
this.remoteHost = null;
|
|
this.remoteFamily = 0;
|
|
this.remotePort = 0;
|
|
this.userData = null;
|
|
binding.udx_napi_stream_init(
|
|
this.udx._handle,
|
|
this._handle,
|
|
id,
|
|
opts.framed ? 1 : 0,
|
|
this,
|
|
this._ondata,
|
|
this._onend,
|
|
this._ondrain,
|
|
this._onack,
|
|
this._onsend,
|
|
this._onmessage,
|
|
this._onclose,
|
|
this._onfirewall,
|
|
this._onremotechanged,
|
|
this._reallocData,
|
|
this._reallocMessage
|
|
);
|
|
if (opts.seq) binding.udx_napi_stream_set_seq(this._handle, opts.seq);
|
|
binding.udx_napi_stream_recv_start(this._handle, this._buffer);
|
|
}
|
|
get connected() {
|
|
return this.socket !== null;
|
|
}
|
|
get mtu() {
|
|
return this._view16[binding.offsetof_udx_stream_t_mtu >> 1];
|
|
}
|
|
get rtt() {
|
|
return this._view[binding.offsetof_udx_stream_t_srtt >> 2];
|
|
}
|
|
get cwnd() {
|
|
return this._view[binding.offsetof_udx_stream_t_cwnd >> 2];
|
|
}
|
|
get rtoCount() {
|
|
return this._view16[binding.offsetof_udx_stream_t_rto_count >> 1];
|
|
}
|
|
get retransmits() {
|
|
return this._view16[binding.offsetof_udx_stream_t_retransmit_count >> 1];
|
|
}
|
|
get fastRecoveries() {
|
|
return this._view16[binding.offsetof_udx_stream_t_fast_recovery_count >> 1];
|
|
}
|
|
get inflight() {
|
|
return this._view[binding.offsetof_udx_stream_t_inflight >> 2];
|
|
}
|
|
get bytesTransmitted() {
|
|
return Number(this._view64[binding.offsetof_udx_stream_t_bytes_tx >> 3]);
|
|
}
|
|
get packetsTransmitted() {
|
|
return Number(this._view64[binding.offsetof_udx_stream_t_packets_tx >> 3]);
|
|
}
|
|
get bytesReceived() {
|
|
return Number(this._view64[binding.offsetof_udx_stream_t_bytes_rx >> 3]);
|
|
}
|
|
get packetsReceived() {
|
|
return Number(this._view64[binding.offsetof_udx_stream_t_packets_rx >> 3]);
|
|
}
|
|
get localHost() {
|
|
return this.socket ? this.socket.address().host : null;
|
|
}
|
|
get localFamily() {
|
|
return this.socket ? this.socket.address().family : 0;
|
|
}
|
|
get localPort() {
|
|
return this.socket ? this.socket.address().port : 0;
|
|
}
|
|
setInteractive(bool) {
|
|
if (!this._closed) return;
|
|
binding.udx_napi_stream_set_mode(this._handle, bool ? 0 : 1);
|
|
}
|
|
connect(socket, remoteId, port, host, opts = {}) {
|
|
if (this._closed) return;
|
|
if (this.connected) throw new Error("Already connected");
|
|
if (socket.closing) throw new Error("Socket is closed");
|
|
if (typeof host === "object") {
|
|
opts = host;
|
|
host = null;
|
|
}
|
|
if (!host) host = "127.0.0.1";
|
|
const family = ip.isIP(host);
|
|
if (!family) throw new Error(`${host} is not a valid IP address`);
|
|
if (!(port > 0 && port < 65536)) throw new Error(`${port} is not a valid port`);
|
|
if (!socket.bound) socket.bind(0);
|
|
this.remoteId = remoteId;
|
|
this.remotePort = port;
|
|
this.remoteHost = host;
|
|
this.remoteFamily = family;
|
|
this.socket = socket;
|
|
if (opts.ack) binding.udx_napi_stream_set_ack(this._handle, opts.ack);
|
|
binding.udx_napi_stream_connect(this._handle, socket._handle, remoteId, port, host, family);
|
|
this.socket._addStream(this);
|
|
this.emit("connect");
|
|
}
|
|
changeRemote(socket, remoteId, port, host) {
|
|
if (this._remoteChanging) throw new Error("Remote already changing");
|
|
if (!this.connected) throw new Error("Not yet connected");
|
|
if (socket.closing) throw new Error("Socket is closed");
|
|
if (this.socket.udx !== socket.udx) {
|
|
throw new Error("Cannot change to a socket on another UDX instance");
|
|
}
|
|
if (!host) host = "127.0.0.1";
|
|
const family = ip.isIP(host);
|
|
if (!family) throw new Error(`${host} is not a valid IP address`);
|
|
if (!(port > 0 && port < 65536)) throw new Error(`${port} is not a valid port`);
|
|
if (this.socket !== socket) this._previousSocket = this.socket;
|
|
this.remoteId = remoteId;
|
|
this.remotePort = port;
|
|
this.remoteHost = host;
|
|
this.remoteFamily = family;
|
|
this.socket = socket;
|
|
this._remoteChanging = new Promise((resolve, reject) => {
|
|
const onchanged = () => {
|
|
this.off("close", onclose);
|
|
resolve();
|
|
};
|
|
const onclose = () => {
|
|
this.off("remote-changed", onchanged);
|
|
reject(new Error("Stream is closed"));
|
|
};
|
|
this.once("remote-changed", onchanged).once("close", onclose);
|
|
});
|
|
binding.udx_napi_stream_change_remote(
|
|
this._handle,
|
|
socket._handle,
|
|
remoteId,
|
|
port,
|
|
host,
|
|
family
|
|
);
|
|
this.socket._addStream(this);
|
|
return this._remoteChanging;
|
|
}
|
|
relayTo(destination) {
|
|
if (this._closed) return;
|
|
binding.udx_napi_stream_relay_to(this._handle, destination._handle);
|
|
}
|
|
async send(buffer) {
|
|
if (!this.connected || this._closed) return false;
|
|
const id = this._allocSend();
|
|
const req = this._sreqs[id];
|
|
req.buffer = buffer;
|
|
const promise = new Promise((resolve) => {
|
|
req.onflush = resolve;
|
|
});
|
|
binding.udx_napi_stream_send(this._handle, req.handle, id, buffer);
|
|
return promise;
|
|
}
|
|
trySend(buffer) {
|
|
if (!this.connected || this._closed) return;
|
|
const id = this._allocSend();
|
|
const req = this._sreqs[id];
|
|
req.buffer = buffer;
|
|
req.onflush = noop;
|
|
binding.udx_napi_stream_send(this._handle, req.handle, id, buffer);
|
|
}
|
|
async flush() {
|
|
if (await streamx.Writable.drained(this) === false) return false;
|
|
if (this.destroying) return false;
|
|
const missing = this._wreqs.length - this._wfree.length;
|
|
if (missing === 0) return true;
|
|
return new Promise((resolve) => {
|
|
this._flushes.push({ flush: this._flushing++, missing, resolve });
|
|
});
|
|
}
|
|
toJSON() {
|
|
return {
|
|
id: this.id,
|
|
connected: this.connected,
|
|
destroying: this.destroying,
|
|
destroyed: this.destroyed,
|
|
remoteId: this.remoteId,
|
|
remoteHost: this.remoteHost,
|
|
remoteFamily: this.remoteFamily,
|
|
remotePort: this.remotePort,
|
|
mtu: this.mtu,
|
|
rtt: this.rtt,
|
|
cwnd: this.cwnd,
|
|
inflight: this.inflight,
|
|
socket: this.socket ? this.socket.toJSON() : null
|
|
};
|
|
}
|
|
_read(cb) {
|
|
cb(null);
|
|
}
|
|
_writeContinue(err) {
|
|
if (this._onwrite === null) return;
|
|
const cb = this._onwrite;
|
|
this._onwrite = null;
|
|
cb(err);
|
|
}
|
|
_destroyContinue(err) {
|
|
if (this._ondestroy === null) return;
|
|
const cb = this._ondestroy;
|
|
this._ondestroy = null;
|
|
cb(err);
|
|
}
|
|
_writev(buffers, cb) {
|
|
if (!this.connected)
|
|
throw customError("Writing while not connected not currently supported", "ERR_ASSERTION");
|
|
let drained = true;
|
|
if (buffers.length === 1) {
|
|
const id = this._allocWrite(1);
|
|
const req = this._wreqs[id];
|
|
req.flush = this._flushing;
|
|
req.buffer = buffers[0];
|
|
drained = binding.udx_napi_stream_write(this._handle, req.handle, id, req.buffer) !== 0;
|
|
} else {
|
|
const id = this._allocWrite(nextBatchSize(buffers.length));
|
|
const req = this._wreqs[id];
|
|
req.flush = this._flushing;
|
|
req.buffers = buffers;
|
|
drained = binding.udx_napi_stream_writev(this._handle, req.handle, id, req.buffers) !== 0;
|
|
}
|
|
if (drained) cb(null);
|
|
else this._onwrite = cb;
|
|
}
|
|
_final(cb) {
|
|
const id = this._allocWrite(1);
|
|
const req = this._wreqs[id];
|
|
req.flush = this._flushes;
|
|
req.buffer = b4a.allocUnsafe(0);
|
|
const drained = binding.udx_napi_stream_write_end(this._handle, req.handle, id, req.buffer) !== 0;
|
|
if (drained) cb(null);
|
|
else this._onwrite = cb;
|
|
}
|
|
_predestroy() {
|
|
if (!this._closed) binding.udx_napi_stream_destroy(this._handle);
|
|
this._closed = true;
|
|
this._writeContinue(null);
|
|
}
|
|
_destroy(cb) {
|
|
if (this.connected) this._ondestroy = cb;
|
|
else cb(null);
|
|
}
|
|
_ondata(read) {
|
|
this.push(this._consumeData(read));
|
|
return this._buffer;
|
|
}
|
|
_onend(read) {
|
|
if (read > 0) this.push(this._consumeData(read));
|
|
this.push(null);
|
|
}
|
|
_ondrain() {
|
|
this._writeContinue(null);
|
|
}
|
|
_flushAck(flush) {
|
|
for (let i = this._flushes.length - 1; i >= 0; i--) {
|
|
const f = this._flushes[i];
|
|
if (f.flush < flush) break;
|
|
f.missing--;
|
|
}
|
|
while (this._flushes.length > 0 && this._flushes[0].missing === 0) {
|
|
this._flushes.shift().resolve(true);
|
|
}
|
|
}
|
|
_onack(id) {
|
|
const req = this._wreqs[id];
|
|
req.buffers = req.buffer = null;
|
|
this._wfree.push(id);
|
|
if (this._flushes.length > 0) this._flushAck(req.flush);
|
|
if (this._wfree.length >= 64 && this._wfree.length === this._wreqs.length) {
|
|
this._wfree = [];
|
|
this._wreqs = [];
|
|
}
|
|
}
|
|
_onsend(id, err) {
|
|
const req = this._sreqs[id];
|
|
const onflush = req.onflush;
|
|
req.buffer = null;
|
|
req.onflush = null;
|
|
this._sfree.push(id);
|
|
onflush(err >= 0);
|
|
if (this._sfree.length >= 16 && this._sfree.length === this._sreqs.length) {
|
|
this._sfree = [];
|
|
this._sreqs = [];
|
|
}
|
|
}
|
|
_onmessage(len) {
|
|
this.emit("message", this.udx._consumeMessage(len));
|
|
return this.udx._buffer;
|
|
}
|
|
_onclose(err) {
|
|
this._closed = true;
|
|
if (this.socket) {
|
|
this.socket._removeStream(this);
|
|
this.socket = null;
|
|
}
|
|
if (this._previousSocket) {
|
|
this._previousSocket._removeStream(this);
|
|
this._previousSocket = null;
|
|
}
|
|
if (!err) return this._destroyContinue(null);
|
|
if (this._ondestroy === null) this.destroy(err);
|
|
else this._destroyContinue(err);
|
|
}
|
|
_onfirewall(socket, port, host, family) {
|
|
return this._firewall(socket, port, host, family) ? 1 : 0;
|
|
}
|
|
_onremotechanged() {
|
|
if (this._previousSocket) {
|
|
this._previousSocket._removeStream(this);
|
|
this._previousSocket = null;
|
|
}
|
|
this._remoteChanging = null;
|
|
this.emit("remote-changed");
|
|
}
|
|
_consumeData(len) {
|
|
const next = this._buffer.subarray(0, len);
|
|
this._buffer = this._buffer.subarray(len);
|
|
if (this._buffer.byteLength < MAX_PACKET) this._reallocData();
|
|
return next;
|
|
}
|
|
_reallocData() {
|
|
this._buffer = b4a.allocUnsafe(BUFFER_SIZE);
|
|
return this._buffer;
|
|
}
|
|
_reallocMessage() {
|
|
return this.udx._reallocMessage();
|
|
}
|
|
_allocWrite(size) {
|
|
if (this._wfree.length === 0) {
|
|
const handle = b4a.allocUnsafe(binding.udx_napi_stream_write_sizeof(size));
|
|
return this._wreqs.push({
|
|
handle,
|
|
size,
|
|
buffers: null,
|
|
buffer: null,
|
|
flush: 0
|
|
}) - 1;
|
|
}
|
|
const free = this._wfree.pop();
|
|
if (size === 1) return free;
|
|
const next = this._wreqs[free];
|
|
if (next.size < size) {
|
|
next.handle = b4a.allocUnsafe(binding.udx_napi_stream_write_sizeof(size));
|
|
next.size = size;
|
|
}
|
|
return free;
|
|
}
|
|
_allocSend() {
|
|
if (this._sfree.length > 0) return this._sfree.pop();
|
|
const handle = b4a.allocUnsafe(binding.sizeof_udx_stream_send_t);
|
|
return this._sreqs.push({ handle, buffer: null, resolve: null, reject: null }) - 1;
|
|
}
|
|
};
|
|
function noop() {
|
|
}
|
|
function toBuffer(data) {
|
|
return typeof data === "string" ? b4a.from(data) : data;
|
|
}
|
|
function firewallAll(socket, port, host) {
|
|
return true;
|
|
}
|
|
function customError(message, code) {
|
|
const error = new Error(message);
|
|
error.code = code;
|
|
return error;
|
|
}
|
|
function nextBatchSize(n) {
|
|
if (n === 1) return 1;
|
|
if (n < 8) return 8;
|
|
if (n < 16) return 16;
|
|
if (n < 32) return 32;
|
|
if (n < 64) return 64;
|
|
return n;
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/udx-native/lib/network-interfaces.js
|
|
var require_network_interfaces = __commonJS({
|
|
"../../node_modules/udx-native/lib/network-interfaces.js"(exports, module) {
|
|
var events = __require("events");
|
|
var b4a = require_b4a();
|
|
var binding = require_binding();
|
|
module.exports = class NetworkInterfaces extends events.EventEmitter {
|
|
constructor(udx) {
|
|
super();
|
|
this._handle = b4a.alloc(binding.sizeof_udx_napi_interface_event_t);
|
|
this._watching = false;
|
|
this._destroying = null;
|
|
binding.udx_napi_interface_event_init(
|
|
udx._handle,
|
|
this._handle,
|
|
this,
|
|
this._onevent,
|
|
this._onclose
|
|
);
|
|
this.interfaces = binding.udx_napi_interface_event_get_addrs(this._handle);
|
|
}
|
|
_onclose() {
|
|
this.emit("close");
|
|
}
|
|
_onevent() {
|
|
this.interfaces = binding.udx_napi_interface_event_get_addrs(this._handle);
|
|
this.emit("change", this.interfaces);
|
|
}
|
|
watch() {
|
|
if (this._watching) return this;
|
|
this._watching = true;
|
|
binding.udx_napi_interface_event_start(this._handle);
|
|
return this;
|
|
}
|
|
unwatch() {
|
|
if (!this._watching) return this;
|
|
this._watching = false;
|
|
binding.udx_napi_interface_event_stop(this._handle);
|
|
return this;
|
|
}
|
|
async destroy() {
|
|
if (this._destroying) return this._destroying;
|
|
this._destroying = events.once(this, "close");
|
|
binding.udx_napi_interface_event_close(this._handle);
|
|
return this._destroying;
|
|
}
|
|
[Symbol.iterator]() {
|
|
return this.interfaces[Symbol.iterator]();
|
|
}
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/udx-native/lib/udx.js
|
|
var require_udx = __commonJS({
|
|
"../../node_modules/udx-native/lib/udx.js"(exports, module) {
|
|
var b4a = require_b4a();
|
|
var binding = require_binding();
|
|
var ip = require_ip();
|
|
var Socket = require_socket();
|
|
var Stream = require_stream();
|
|
var NetworkInterfaces = require_network_interfaces();
|
|
var MAX_MESSAGE = 4096;
|
|
var BUFFER_SIZE = 65536 + MAX_MESSAGE;
|
|
module.exports = class UDX {
|
|
constructor() {
|
|
this._handle = b4a.alloc(binding.sizeof_udx_napi_t);
|
|
this._watchers = /* @__PURE__ */ new Set();
|
|
this._view64 = new BigUint64Array(
|
|
this._handle.buffer,
|
|
this._handle.byteOffset,
|
|
this._handle.byteLength >> 3
|
|
);
|
|
this._buffer = null;
|
|
this._reallocMessage();
|
|
binding.udx_napi_init(this._handle, this._buffer);
|
|
}
|
|
static isIPv4(host) {
|
|
return ip.isIPv4(host);
|
|
}
|
|
static isIPv6(host) {
|
|
return ip.isIPv6(host);
|
|
}
|
|
static isIP(host) {
|
|
return ip.isIP(host);
|
|
}
|
|
get bytesTransmitted() {
|
|
return Number(this._view64[binding.offsetof_udx_t_bytes_tx >> 3]);
|
|
}
|
|
get packetsTransmitted() {
|
|
return Number(this._view64[binding.offsetof_udx_t_packets_tx >> 3]);
|
|
}
|
|
get bytesReceived() {
|
|
return Number(this._view64[binding.offsetof_udx_t_bytes_rx >> 3]);
|
|
}
|
|
get packetsReceived() {
|
|
return Number(this._view64[binding.offsetof_udx_t_packets_rx >> 3]);
|
|
}
|
|
get packetsDroppedByKernel() {
|
|
return Number(this._view64[binding.offsetof_udx_t_packets_dropped_by_kernel >> 3]);
|
|
}
|
|
_consumeMessage(len) {
|
|
const next = this._buffer.subarray(0, len);
|
|
this._buffer = this._buffer.subarray(len);
|
|
if (this._buffer.byteLength < MAX_MESSAGE) this._reallocMessage();
|
|
return next;
|
|
}
|
|
_reallocMessage() {
|
|
this._buffer = b4a.allocUnsafe(BUFFER_SIZE);
|
|
return this._buffer;
|
|
}
|
|
createSocket(opts) {
|
|
return new Socket(this, opts);
|
|
}
|
|
createStream(id, opts) {
|
|
return new Stream(this, id, opts);
|
|
}
|
|
networkInterfaces() {
|
|
let [watcher = null] = this._watchers;
|
|
if (watcher) return watcher.interfaces;
|
|
watcher = new NetworkInterfaces(this);
|
|
watcher.destroy();
|
|
return watcher.interfaces;
|
|
}
|
|
watchNetworkInterfaces(onchange) {
|
|
const watcher = new NetworkInterfaces(this);
|
|
this._watchers.add(watcher);
|
|
watcher.on("close", () => {
|
|
this._watchers.delete(watcher);
|
|
});
|
|
if (onchange) watcher.on("change", onchange);
|
|
return watcher.watch();
|
|
}
|
|
async lookup(host, opts = {}) {
|
|
const { family = 0 } = opts;
|
|
const req = b4a.alloc(binding.sizeof_udx_napi_lookup_t);
|
|
const ctx = {
|
|
req,
|
|
resolve: null,
|
|
reject: null
|
|
};
|
|
const promise = new Promise((resolve, reject) => {
|
|
ctx.resolve = resolve;
|
|
ctx.reject = reject;
|
|
});
|
|
binding.udx_napi_lookup(this._handle, req, host, family, ctx, onlookup);
|
|
return promise;
|
|
}
|
|
};
|
|
function onlookup(err, host, family) {
|
|
if (err) this.reject(err);
|
|
else this.resolve({ host, family });
|
|
}
|
|
}
|
|
});
|
|
|
|
// ../../node_modules/bare-dgram/index.js
|
|
var require_bare_dgram = __commonJS({
|
|
"../../node_modules/bare-dgram/index.js"(exports) {
|
|
var EventEmitter = require_bare_events();
|
|
var UDX = require_udx();
|
|
var udx = new UDX();
|
|
var Socket = exports.Socket = class Socket extends EventEmitter {
|
|
constructor(opts = {}) {
|
|
super();
|
|
this._remotePort = -1;
|
|
this._remoteAddress = null;
|
|
this._remoteFamily = 0;
|
|
this._socket = udx.createSocket(opts);
|
|
this._socket.on("error", (err) => this.emit("error", err)).on("close", () => this.emit("close")).on(
|
|
"listening",
|
|
() => queueMicrotask(() => this.emit("listening"))
|
|
/* Deferred for Node.js compatibility */
|
|
).on("message", (message, address) => this.emit("message", message, {
|
|
address: address.host,
|
|
family: `IPv${address.family}`,
|
|
port: address.port
|
|
}));
|
|
}
|
|
address() {
|
|
const address = this._socket.address();
|
|
if (address === null) return null;
|
|
return {
|
|
address: address.host,
|
|
family: `IPv${address.family}`,
|
|
port: address.port
|
|
};
|
|
}
|
|
remoteAddress() {
|
|
if (this._remotePort === -1) return null;
|
|
return {
|
|
address: this._remoteAddress,
|
|
family: `IPv${this._remoteFamily}`,
|
|
port: this._remotePort
|
|
};
|
|
}
|
|
bind(port, address, cb) {
|
|
if (typeof port === "function") {
|
|
cb = port;
|
|
port = 0;
|
|
address = null;
|
|
} else if (typeof address === "function") {
|
|
cb = address;
|
|
address = null;
|
|
}
|
|
if (typeof port === "object" && port !== null) {
|
|
const opts = port || {};
|
|
port = opts.port || null;
|
|
address = opts.address || null;
|
|
}
|
|
if (cb) this.once("listening", cb);
|
|
this._socket.bind(port, address);
|
|
return this;
|
|
}
|
|
connect(port, address, cb) {
|
|
if (typeof address === "function") {
|
|
cb = address;
|
|
address = null;
|
|
}
|
|
this._remotePort = port;
|
|
this._remoteAddress = address;
|
|
this._remoteFamily = UDX.isIP(address);
|
|
if (cb) this.once("connect", cb);
|
|
queueMicrotask(() => this.emit("connect"));
|
|
}
|
|
async close(cb) {
|
|
try {
|
|
await this._socket.close();
|
|
if (cb) cb(null);
|
|
} catch (err) {
|
|
if (cb) cb(err);
|
|
else throw err;
|
|
}
|
|
}
|
|
async send(buffer, offset, length, port, address, cb) {
|
|
if (typeof buffer === "string") buffer = Buffer.from(buffer);
|
|
if (typeof offset === "function") {
|
|
cb = offset;
|
|
offset = 0;
|
|
length = buffer.byteLength;
|
|
port = 0;
|
|
address = null;
|
|
} else if (typeof length === "function") {
|
|
cb = length;
|
|
port = offset;
|
|
address = null;
|
|
offset = 0;
|
|
length = buffer.byteLength;
|
|
} else if (typeof port === "function") {
|
|
cb = port;
|
|
if (typeof length === "string") {
|
|
port = offset;
|
|
address = length;
|
|
offset = 0;
|
|
length = buffer.byteLength;
|
|
} else {
|
|
port = 0;
|
|
address = null;
|
|
}
|
|
} else if (typeof address === "function") {
|
|
cb = address;
|
|
if (typeof port === "string") {
|
|
address = port;
|
|
port = 0;
|
|
} else {
|
|
address = null;
|
|
}
|
|
}
|
|
if (typeof offset === "string") {
|
|
address = offset;
|
|
port = 0;
|
|
offset = 0;
|
|
length = buffer.byteLength;
|
|
}
|
|
if (typeof length === "string") {
|
|
address = length;
|
|
port = offset;
|
|
offset = 0;
|
|
length = buffer.byteLength;
|
|
} else if (typeof length !== "number") {
|
|
port = offset;
|
|
address = null;
|
|
offset = 0;
|
|
length = buffer.byteLength;
|
|
}
|
|
if (!port) port = this._remotePort;
|
|
if (!address) address = this._remoteAddress;
|
|
if (offset !== 0 || length !== buffer.byteLength) {
|
|
buffer = buffer.subarray(offset, offset + length);
|
|
}
|
|
try {
|
|
await this._socket.send(buffer, port, address);
|
|
if (cb) cb(null);
|
|
} catch (err) {
|
|
if (cb) cb(err);
|
|
else throw err;
|
|
}
|
|
}
|
|
};
|
|
exports.createSocket = function createSocket(opts, cb) {
|
|
if (typeof opts === "string") opts = {};
|
|
const socket = new Socket(opts);
|
|
if (cb) socket.on("message", cb);
|
|
return socket;
|
|
};
|
|
}
|
|
});
|
|
|
|
// ../../bare-lib-entry-bareDgram.js
|
|
var bare_lib_entry_bareDgram_exports = {};
|
|
__export(bare_lib_entry_bareDgram_exports, {
|
|
default: () => bare_lib_entry_bareDgram_default
|
|
});
|
|
var import_bare_dgram = __toESM(require_bare_dgram());
|
|
var bare_lib_entry_bareDgram_default = import_bare_dgram.default;
|
|
return __toCommonJS(bare_lib_entry_bareDgram_exports);
|
|
})();
|
|
;(function(){var g=globalThis;var s="__bare_os_stdlib__";g[s]=g[s]||{};var e=typeof __bare_os_bundle_exports__!=="undefined"?__bare_os_bundle_exports__:void 0;var v=e!=null&&typeof e==="object"&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;g[s]["bareDgram"]=v;})();
|