bw-hspc-contest-env/shared/dist/cpp.js

2463 lines
78 KiB
JavaScript
Raw Normal View History

2024-03-12 12:11:59 -04:00
"use strict";
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 __commonJS = (cb, mod) => function __require() {
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/tree-kill/index.js
var require_tree_kill = __commonJS({
"node_modules/tree-kill/index.js"(exports2, module2) {
"use strict";
var childProcess = require("child_process");
var spawn2 = childProcess.spawn;
var exec2 = childProcess.exec;
module2.exports = function(pid, signal, callback) {
if (typeof signal === "function" && callback === void 0) {
callback = signal;
signal = void 0;
}
pid = parseInt(pid);
if (Number.isNaN(pid)) {
if (callback) {
return callback(new Error("pid must be a number"));
} else {
throw new Error("pid must be a number");
}
}
var tree = {};
var pidsToProcess = {};
tree[pid] = [];
pidsToProcess[pid] = 1;
switch (process.platform) {
case "win32":
exec2("taskkill /pid " + pid + " /T /F", callback);
break;
case "darwin":
buildProcessTree(pid, tree, pidsToProcess, function(parentPid) {
return spawn2("pgrep", ["-P", parentPid]);
}, function() {
killAll(tree, signal, callback);
});
break;
default:
buildProcessTree(pid, tree, pidsToProcess, function(parentPid) {
return spawn2("ps", ["-o", "pid", "--no-headers", "--ppid", parentPid]);
}, function() {
killAll(tree, signal, callback);
});
break;
}
};
function killAll(tree, signal, callback) {
var killed = {};
try {
Object.keys(tree).forEach(function(pid) {
tree[pid].forEach(function(pidpid) {
if (!killed[pidpid]) {
killPid(pidpid, signal);
killed[pidpid] = 1;
}
});
if (!killed[pid]) {
killPid(pid, signal);
killed[pid] = 1;
}
});
} catch (err) {
if (callback) {
return callback(err);
} else {
throw err;
}
}
if (callback) {
return callback();
}
}
function killPid(pid, signal) {
try {
process.kill(parseInt(pid, 10), signal);
} catch (err) {
if (err.code !== "ESRCH")
throw err;
}
}
function buildProcessTree(parentPid, tree, pidsToProcess, spawnChildProcessesList, cb) {
var ps = spawnChildProcessesList(parentPid);
var allData = "";
ps.stdout.on("data", function(data) {
var data = data.toString("ascii");
allData += data;
});
var onClose = function(code) {
delete pidsToProcess[parentPid];
if (code != 0) {
if (Object.keys(pidsToProcess).length == 0) {
cb();
}
return;
}
allData.match(/\d+/g).forEach(function(pid) {
pid = parseInt(pid, 10);
tree[parentPid].push(pid);
tree[pid] = [];
pidsToProcess[pid] = 1;
buildProcessTree(pid, tree, pidsToProcess, spawnChildProcessesList, cb);
});
};
ps.on("close", onClose);
}
}
});
// node_modules/universalify/index.js
var require_universalify = __commonJS({
"node_modules/universalify/index.js"(exports2) {
"use strict";
exports2.fromCallback = function(fn) {
return Object.defineProperty(function(...args) {
if (typeof args[args.length - 1] === "function")
fn.apply(this, args);
else {
return new Promise((resolve, reject) => {
args.push((err, res) => err != null ? reject(err) : resolve(res));
fn.apply(this, args);
});
}
}, "name", { value: fn.name });
};
exports2.fromPromise = function(fn) {
return Object.defineProperty(function(...args) {
const cb = args[args.length - 1];
if (typeof cb !== "function")
return fn.apply(this, args);
else {
args.pop();
fn.apply(this, args).then((r) => cb(null, r), cb);
}
}, "name", { value: fn.name });
};
}
});
// node_modules/graceful-fs/polyfills.js
var require_polyfills = __commonJS({
"node_modules/graceful-fs/polyfills.js"(exports2, module2) {
var constants = require("constants");
var origCwd = process.cwd;
var cwd = null;
var platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
process.cwd = function() {
if (!cwd)
cwd = origCwd.call(process);
return cwd;
};
try {
process.cwd();
} catch (er) {
}
if (typeof process.chdir === "function") {
chdir = process.chdir;
process.chdir = function(d) {
cwd = null;
chdir.call(process, d);
};
if (Object.setPrototypeOf)
Object.setPrototypeOf(process.chdir, chdir);
}
var chdir;
module2.exports = patch;
function patch(fs2) {
if (constants.hasOwnProperty("O_SYMLINK") && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) {
patchLchmod(fs2);
}
if (!fs2.lutimes) {
patchLutimes(fs2);
}
fs2.chown = chownFix(fs2.chown);
fs2.fchown = chownFix(fs2.fchown);
fs2.lchown = chownFix(fs2.lchown);
fs2.chmod = chmodFix(fs2.chmod);
fs2.fchmod = chmodFix(fs2.fchmod);
fs2.lchmod = chmodFix(fs2.lchmod);
fs2.chownSync = chownFixSync(fs2.chownSync);
fs2.fchownSync = chownFixSync(fs2.fchownSync);
fs2.lchownSync = chownFixSync(fs2.lchownSync);
fs2.chmodSync = chmodFixSync(fs2.chmodSync);
fs2.fchmodSync = chmodFixSync(fs2.fchmodSync);
fs2.lchmodSync = chmodFixSync(fs2.lchmodSync);
fs2.stat = statFix(fs2.stat);
fs2.fstat = statFix(fs2.fstat);
fs2.lstat = statFix(fs2.lstat);
fs2.statSync = statFixSync(fs2.statSync);
fs2.fstatSync = statFixSync(fs2.fstatSync);
fs2.lstatSync = statFixSync(fs2.lstatSync);
if (fs2.chmod && !fs2.lchmod) {
fs2.lchmod = function(path, mode, cb) {
if (cb)
process.nextTick(cb);
};
fs2.lchmodSync = function() {
};
}
if (fs2.chown && !fs2.lchown) {
fs2.lchown = function(path, uid, gid, cb) {
if (cb)
process.nextTick(cb);
};
fs2.lchownSync = function() {
};
}
if (platform === "win32") {
fs2.rename = typeof fs2.rename !== "function" ? fs2.rename : function(fs$rename) {
function rename(from, to, cb) {
var start = Date.now();
var backoff = 0;
fs$rename(from, to, function CB(er) {
if (er && (er.code === "EACCES" || er.code === "EPERM" || er.code === "EBUSY") && Date.now() - start < 6e4) {
setTimeout(function() {
fs2.stat(to, function(stater, st) {
if (stater && stater.code === "ENOENT")
fs$rename(from, to, CB);
else
cb(er);
});
}, backoff);
if (backoff < 100)
backoff += 10;
return;
}
if (cb)
cb(er);
});
}
if (Object.setPrototypeOf)
Object.setPrototypeOf(rename, fs$rename);
return rename;
}(fs2.rename);
}
fs2.read = typeof fs2.read !== "function" ? fs2.read : function(fs$read) {
function read(fd, buffer, offset, length, position, callback_) {
var callback;
if (callback_ && typeof callback_ === "function") {
var eagCounter = 0;
callback = function(er, _, __) {
if (er && er.code === "EAGAIN" && eagCounter < 10) {
eagCounter++;
return fs$read.call(fs2, fd, buffer, offset, length, position, callback);
}
callback_.apply(this, arguments);
};
}
return fs$read.call(fs2, fd, buffer, offset, length, position, callback);
}
if (Object.setPrototypeOf)
Object.setPrototypeOf(read, fs$read);
return read;
}(fs2.read);
fs2.readSync = typeof fs2.readSync !== "function" ? fs2.readSync : /* @__PURE__ */ function(fs$readSync) {
return function(fd, buffer, offset, length, position) {
var eagCounter = 0;
while (true) {
try {
return fs$readSync.call(fs2, fd, buffer, offset, length, position);
} catch (er) {
if (er.code === "EAGAIN" && eagCounter < 10) {
eagCounter++;
continue;
}
throw er;
}
}
};
}(fs2.readSync);
function patchLchmod(fs3) {
fs3.lchmod = function(path, mode, callback) {
fs3.open(
path,
constants.O_WRONLY | constants.O_SYMLINK,
mode,
function(err, fd) {
if (err) {
if (callback)
callback(err);
return;
}
fs3.fchmod(fd, mode, function(err2) {
fs3.close(fd, function(err22) {
if (callback)
callback(err2 || err22);
});
});
}
);
};
fs3.lchmodSync = function(path, mode) {
var fd = fs3.openSync(path, constants.O_WRONLY | constants.O_SYMLINK, mode);
var threw = true;
var ret;
try {
ret = fs3.fchmodSync(fd, mode);
threw = false;
} finally {
if (threw) {
try {
fs3.closeSync(fd);
} catch (er) {
}
} else {
fs3.closeSync(fd);
}
}
return ret;
};
}
function patchLutimes(fs3) {
if (constants.hasOwnProperty("O_SYMLINK") && fs3.futimes) {
fs3.lutimes = function(path, at, mt, cb) {
fs3.open(path, constants.O_SYMLINK, function(er, fd) {
if (er) {
if (cb)
cb(er);
return;
}
fs3.futimes(fd, at, mt, function(er2) {
fs3.close(fd, function(er22) {
if (cb)
cb(er2 || er22);
});
});
});
};
fs3.lutimesSync = function(path, at, mt) {
var fd = fs3.openSync(path, constants.O_SYMLINK);
var ret;
var threw = true;
try {
ret = fs3.futimesSync(fd, at, mt);
threw = false;
} finally {
if (threw) {
try {
fs3.closeSync(fd);
} catch (er) {
}
} else {
fs3.closeSync(fd);
}
}
return ret;
};
} else if (fs3.futimes) {
fs3.lutimes = function(_a, _b, _c, cb) {
if (cb)
process.nextTick(cb);
};
fs3.lutimesSync = function() {
};
}
}
function chmodFix(orig) {
if (!orig)
return orig;
return function(target, mode, cb) {
return orig.call(fs2, target, mode, function(er) {
if (chownErOk(er))
er = null;
if (cb)
cb.apply(this, arguments);
});
};
}
function chmodFixSync(orig) {
if (!orig)
return orig;
return function(target, mode) {
try {
return orig.call(fs2, target, mode);
} catch (er) {
if (!chownErOk(er))
throw er;
}
};
}
function chownFix(orig) {
if (!orig)
return orig;
return function(target, uid, gid, cb) {
return orig.call(fs2, target, uid, gid, function(er) {
if (chownErOk(er))
er = null;
if (cb)
cb.apply(this, arguments);
});
};
}
function chownFixSync(orig) {
if (!orig)
return orig;
return function(target, uid, gid) {
try {
return orig.call(fs2, target, uid, gid);
} catch (er) {
if (!chownErOk(er))
throw er;
}
};
}
function statFix(orig) {
if (!orig)
return orig;
return function(target, options, cb) {
if (typeof options === "function") {
cb = options;
options = null;
}
function callback(er, stats) {
if (stats) {
if (stats.uid < 0)
stats.uid += 4294967296;
if (stats.gid < 0)
stats.gid += 4294967296;
}
if (cb)
cb.apply(this, arguments);
}
return options ? orig.call(fs2, target, options, callback) : orig.call(fs2, target, callback);
};
}
function statFixSync(orig) {
if (!orig)
return orig;
return function(target, options) {
var stats = options ? orig.call(fs2, target, options) : orig.call(fs2, target);
if (stats) {
if (stats.uid < 0)
stats.uid += 4294967296;
if (stats.gid < 0)
stats.gid += 4294967296;
}
return stats;
};
}
function chownErOk(er) {
if (!er)
return true;
if (er.code === "ENOSYS")
return true;
var nonroot = !process.getuid || process.getuid() !== 0;
if (nonroot) {
if (er.code === "EINVAL" || er.code === "EPERM")
return true;
}
return false;
}
}
}
});
// node_modules/graceful-fs/legacy-streams.js
var require_legacy_streams = __commonJS({
"node_modules/graceful-fs/legacy-streams.js"(exports2, module2) {
var Stream = require("stream").Stream;
module2.exports = legacy;
function legacy(fs2) {
return {
ReadStream,
WriteStream
};
function ReadStream(path, options) {
if (!(this instanceof ReadStream))
return new ReadStream(path, options);
Stream.call(this);
var self = this;
this.path = path;
this.fd = null;
this.readable = true;
this.paused = false;
this.flags = "r";
this.mode = 438;
this.bufferSize = 64 * 1024;
options = options || {};
var keys = Object.keys(options);
for (var index = 0, length = keys.length; index < length; index++) {
var key = keys[index];
this[key] = options[key];
}
if (this.encoding)
this.setEncoding(this.encoding);
if (this.start !== void 0) {
if ("number" !== typeof this.start) {
throw TypeError("start must be a Number");
}
if (this.end === void 0) {
this.end = Infinity;
} else if ("number" !== typeof this.end) {
throw TypeError("end must be a Number");
}
if (this.start > this.end) {
throw new Error("start must be <= end");
}
this.pos = this.start;
}
if (this.fd !== null) {
process.nextTick(function() {
self._read();
});
return;
}
fs2.open(this.path, this.flags, this.mode, function(err, fd) {
if (err) {
self.emit("error", err);
self.readable = false;
return;
}
self.fd = fd;
self.emit("open", fd);
self._read();
});
}
function WriteStream(path, options) {
if (!(this instanceof WriteStream))
return new WriteStream(path, options);
Stream.call(this);
this.path = path;
this.fd = null;
this.writable = true;
this.flags = "w";
this.encoding = "binary";
this.mode = 438;
this.bytesWritten = 0;
options = options || {};
var keys = Object.keys(options);
for (var index = 0, length = keys.length; index < length; index++) {
var key = keys[index];
this[key] = options[key];
}
if (this.start !== void 0) {
if ("number" !== typeof this.start) {
throw TypeError("start must be a Number");
}
if (this.start < 0) {
throw new Error("start must be >= zero");
}
this.pos = this.start;
}
this.busy = false;
this._queue = [];
if (this.fd === null) {
this._open = fs2.open;
this._queue.push([this._open, this.path, this.flags, this.mode, void 0]);
this.flush();
}
}
}
}
});
// node_modules/graceful-fs/clone.js
var require_clone = __commonJS({
"node_modules/graceful-fs/clone.js"(exports2, module2) {
"use strict";
module2.exports = clone;
var getPrototypeOf = Object.getPrototypeOf || function(obj) {
return obj.__proto__;
};
function clone(obj) {
if (obj === null || typeof obj !== "object")
return obj;
if (obj instanceof Object)
var copy = { __proto__: getPrototypeOf(obj) };
else
var copy = /* @__PURE__ */ Object.create(null);
Object.getOwnPropertyNames(obj).forEach(function(key) {
Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key));
});
return copy;
}
}
});
// node_modules/graceful-fs/graceful-fs.js
var require_graceful_fs = __commonJS({
"node_modules/graceful-fs/graceful-fs.js"(exports2, module2) {
var fs2 = require("fs");
var polyfills = require_polyfills();
var legacy = require_legacy_streams();
var clone = require_clone();
var util2 = require("util");
var gracefulQueue;
var previousSymbol;
if (typeof Symbol === "function" && typeof Symbol.for === "function") {
gracefulQueue = Symbol.for("graceful-fs.queue");
previousSymbol = Symbol.for("graceful-fs.previous");
} else {
gracefulQueue = "___graceful-fs.queue";
previousSymbol = "___graceful-fs.previous";
}
function noop() {
}
function publishQueue(context, queue2) {
Object.defineProperty(context, gracefulQueue, {
get: function() {
return queue2;
}
});
}
var debug = noop;
if (util2.debuglog)
debug = util2.debuglog("gfs4");
else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || ""))
debug = function() {
var m = util2.format.apply(util2, arguments);
m = "GFS4: " + m.split(/\n/).join("\nGFS4: ");
console.error(m);
};
if (!fs2[gracefulQueue]) {
queue = global[gracefulQueue] || [];
publishQueue(fs2, queue);
fs2.close = function(fs$close) {
function close(fd, cb) {
return fs$close.call(fs2, fd, function(err) {
if (!err) {
resetQueue();
}
if (typeof cb === "function")
cb.apply(this, arguments);
});
}
Object.defineProperty(close, previousSymbol, {
value: fs$close
});
return close;
}(fs2.close);
fs2.closeSync = function(fs$closeSync) {
function closeSync(fd) {
fs$closeSync.apply(fs2, arguments);
resetQueue();
}
Object.defineProperty(closeSync, previousSymbol, {
value: fs$closeSync
});
return closeSync;
}(fs2.closeSync);
if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) {
process.on("exit", function() {
debug(fs2[gracefulQueue]);
require("assert").equal(fs2[gracefulQueue].length, 0);
});
}
}
var queue;
if (!global[gracefulQueue]) {
publishQueue(global, fs2[gracefulQueue]);
}
module2.exports = patch(clone(fs2));
if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs2.__patched) {
module2.exports = patch(fs2);
fs2.__patched = true;
}
function patch(fs3) {
polyfills(fs3);
fs3.gracefulify = patch;
fs3.createReadStream = createReadStream;
fs3.createWriteStream = createWriteStream;
var fs$readFile = fs3.readFile;
fs3.readFile = readFile;
function readFile(path, options, cb) {
if (typeof options === "function")
cb = options, options = null;
return go$readFile(path, options, cb);
function go$readFile(path2, options2, cb2, startTime) {
return fs$readFile(path2, options2, function(err) {
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
enqueue([go$readFile, [path2, options2, cb2], err, startTime || Date.now(), Date.now()]);
else {
if (typeof cb2 === "function")
cb2.apply(this, arguments);
}
});
}
}
var fs$writeFile = fs3.writeFile;
fs3.writeFile = writeFile;
function writeFile(path, data, options, cb) {
if (typeof options === "function")
cb = options, options = null;
return go$writeFile(path, data, options, cb);
function go$writeFile(path2, data2, options2, cb2, startTime) {
return fs$writeFile(path2, data2, options2, function(err) {
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
enqueue([go$writeFile, [path2, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
else {
if (typeof cb2 === "function")
cb2.apply(this, arguments);
}
});
}
}
var fs$appendFile = fs3.appendFile;
if (fs$appendFile)
fs3.appendFile = appendFile;
function appendFile(path, data, options, cb) {
if (typeof options === "function")
cb = options, options = null;
return go$appendFile(path, data, options, cb);
function go$appendFile(path2, data2, options2, cb2, startTime) {
return fs$appendFile(path2, data2, options2, function(err) {
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
enqueue([go$appendFile, [path2, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
else {
if (typeof cb2 === "function")
cb2.apply(this, arguments);
}
});
}
}
var fs$copyFile = fs3.copyFile;
if (fs$copyFile)
fs3.copyFile = copyFile;
function copyFile(src, dest, flags, cb) {
if (typeof flags === "function") {
cb = flags;
flags = 0;
}
return go$copyFile(src, dest, flags, cb);
function go$copyFile(src2, dest2, flags2, cb2, startTime) {
return fs$copyFile(src2, dest2, flags2, function(err) {
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
enqueue([go$copyFile, [src2, dest2, flags2, cb2], err, startTime || Date.now(), Date.now()]);
else {
if (typeof cb2 === "function")
cb2.apply(this, arguments);
}
});
}
}
var fs$readdir = fs3.readdir;
fs3.readdir = readdir;
var noReaddirOptionVersions = /^v[0-5]\./;
function readdir(path, options, cb) {
if (typeof options === "function")
cb = options, options = null;
var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path2, options2, cb2, startTime) {
return fs$readdir(path2, fs$readdirCallback(
path2,
options2,
cb2,
startTime
));
} : function go$readdir2(path2, options2, cb2, startTime) {
return fs$readdir(path2, options2, fs$readdirCallback(
path2,
options2,
cb2,
startTime
));
};
return go$readdir(path, options, cb);
function fs$readdirCallback(path2, options2, cb2, startTime) {
return function(err, files) {
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
enqueue([
go$readdir,
[path2, options2, cb2],
err,
startTime || Date.now(),
Date.now()
]);
else {
if (files && files.sort)
files.sort();
if (typeof cb2 === "function")
cb2.call(this, err, files);
}
};
}
}
if (process.version.substr(0, 4) === "v0.8") {
var legStreams = legacy(fs3);
ReadStream = legStreams.ReadStream;
WriteStream = legStreams.WriteStream;
}
var fs$ReadStream = fs3.ReadStream;
if (fs$ReadStream) {
ReadStream.prototype = Object.create(fs$ReadStream.prototype);
ReadStream.prototype.open = ReadStream$open;
}
var fs$WriteStream = fs3.WriteStream;
if (fs$WriteStream) {
WriteStream.prototype = Object.create(fs$WriteStream.prototype);
WriteStream.prototype.open = WriteStream$open;
}
Object.defineProperty(fs3, "ReadStream", {
get: function() {
return ReadStream;
},
set: function(val) {
ReadStream = val;
},
enumerable: true,
configurable: true
});
Object.defineProperty(fs3, "WriteStream", {
get: function() {
return WriteStream;
},
set: function(val) {
WriteStream = val;
},
enumerable: true,
configurable: true
});
var FileReadStream = ReadStream;
Object.defineProperty(fs3, "FileReadStream", {
get: function() {
return FileReadStream;
},
set: function(val) {
FileReadStream = val;
},
enumerable: true,
configurable: true
});
var FileWriteStream = WriteStream;
Object.defineProperty(fs3, "FileWriteStream", {
get: function() {
return FileWriteStream;
},
set: function(val) {
FileWriteStream = val;
},
enumerable: true,
configurable: true
});
function ReadStream(path, options) {
if (this instanceof ReadStream)
return fs$ReadStream.apply(this, arguments), this;
else
return ReadStream.apply(Object.create(ReadStream.prototype), arguments);
}
function ReadStream$open() {
var that = this;
open(that.path, that.flags, that.mode, function(err, fd) {
if (err) {
if (that.autoClose)
that.destroy();
that.emit("error", err);
} else {
that.fd = fd;
that.emit("open", fd);
that.read();
}
});
}
function WriteStream(path, options) {
if (this instanceof WriteStream)
return fs$WriteStream.apply(this, arguments), this;
else
return WriteStream.apply(Object.create(WriteStream.prototype), arguments);
}
function WriteStream$open() {
var that = this;
open(that.path, that.flags, that.mode, function(err, fd) {
if (err) {
that.destroy();
that.emit("error", err);
} else {
that.fd = fd;
that.emit("open", fd);
}
});
}
function createReadStream(path, options) {
return new fs3.ReadStream(path, options);
}
function createWriteStream(path, options) {
return new fs3.WriteStream(path, options);
}
var fs$open = fs3.open;
fs3.open = open;
function open(path, flags, mode, cb) {
if (typeof mode === "function")
cb = mode, mode = null;
return go$open(path, flags, mode, cb);
function go$open(path2, flags2, mode2, cb2, startTime) {
return fs$open(path2, flags2, mode2, function(err, fd) {
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
enqueue([go$open, [path2, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
else {
if (typeof cb2 === "function")
cb2.apply(this, arguments);
}
});
}
}
return fs3;
}
function enqueue(elem) {
debug("ENQUEUE", elem[0].name, elem[1]);
fs2[gracefulQueue].push(elem);
retry();
}
var retryTimer;
function resetQueue() {
var now = Date.now();
for (var i = 0; i < fs2[gracefulQueue].length; ++i) {
if (fs2[gracefulQueue][i].length > 2) {
fs2[gracefulQueue][i][3] = now;
fs2[gracefulQueue][i][4] = now;
}
}
retry();
}
function retry() {
clearTimeout(retryTimer);
retryTimer = void 0;
if (fs2[gracefulQueue].length === 0)
return;
var elem = fs2[gracefulQueue].shift();
var fn = elem[0];
var args = elem[1];
var err = elem[2];
var startTime = elem[3];
var lastTime = elem[4];
if (startTime === void 0) {
debug("RETRY", fn.name, args);
fn.apply(null, args);
} else if (Date.now() - startTime >= 6e4) {
debug("TIMEOUT", fn.name, args);
var cb = args.pop();
if (typeof cb === "function")
cb.call(null, err);
} else {
var sinceAttempt = Date.now() - lastTime;
var sinceStart = Math.max(lastTime - startTime, 1);
var desiredDelay = Math.min(sinceStart * 1.2, 100);
if (sinceAttempt >= desiredDelay) {
debug("RETRY", fn.name, args);
fn.apply(null, args.concat([startTime]));
} else {
fs2[gracefulQueue].push(elem);
}
}
if (retryTimer === void 0) {
retryTimer = setTimeout(retry, 0);
}
}
}
});
// node_modules/fs-extra/lib/fs/index.js
var require_fs = __commonJS({
"node_modules/fs-extra/lib/fs/index.js"(exports2) {
"use strict";
var u = require_universalify().fromCallback;
var fs2 = require_graceful_fs();
var api = [
"access",
"appendFile",
"chmod",
"chown",
"close",
"copyFile",
"fchmod",
"fchown",
"fdatasync",
"fstat",
"fsync",
"ftruncate",
"futimes",
"lchmod",
"lchown",
"link",
"lstat",
"mkdir",
"mkdtemp",
"open",
"opendir",
"readdir",
"readFile",
"readlink",
"realpath",
"rename",
"rm",
"rmdir",
"stat",
"symlink",
"truncate",
"unlink",
"utimes",
"writeFile"
].filter((key) => {
return typeof fs2[key] === "function";
});
Object.assign(exports2, fs2);
api.forEach((method) => {
exports2[method] = u(fs2[method]);
});
exports2.exists = function(filename, callback) {
if (typeof callback === "function") {
return fs2.exists(filename, callback);
}
return new Promise((resolve) => {
return fs2.exists(filename, resolve);
});
};
exports2.read = function(fd, buffer, offset, length, position, callback) {
if (typeof callback === "function") {
return fs2.read(fd, buffer, offset, length, position, callback);
}
return new Promise((resolve, reject) => {
fs2.read(fd, buffer, offset, length, position, (err, bytesRead, buffer2) => {
if (err)
return reject(err);
resolve({ bytesRead, buffer: buffer2 });
});
});
};
exports2.write = function(fd, buffer, ...args) {
if (typeof args[args.length - 1] === "function") {
return fs2.write(fd, buffer, ...args);
}
return new Promise((resolve, reject) => {
fs2.write(fd, buffer, ...args, (err, bytesWritten, buffer2) => {
if (err)
return reject(err);
resolve({ bytesWritten, buffer: buffer2 });
});
});
};
exports2.readv = function(fd, buffers, ...args) {
if (typeof args[args.length - 1] === "function") {
return fs2.readv(fd, buffers, ...args);
}
return new Promise((resolve, reject) => {
fs2.readv(fd, buffers, ...args, (err, bytesRead, buffers2) => {
if (err)
return reject(err);
resolve({ bytesRead, buffers: buffers2 });
});
});
};
exports2.writev = function(fd, buffers, ...args) {
if (typeof args[args.length - 1] === "function") {
return fs2.writev(fd, buffers, ...args);
}
return new Promise((resolve, reject) => {
fs2.writev(fd, buffers, ...args, (err, bytesWritten, buffers2) => {
if (err)
return reject(err);
resolve({ bytesWritten, buffers: buffers2 });
});
});
};
if (typeof fs2.realpath.native === "function") {
exports2.realpath.native = u(fs2.realpath.native);
} else {
process.emitWarning(
"fs.realpath.native is not a function. Is fs being monkey-patched?",
"Warning",
"fs-extra-WARN0003"
);
}
}
});
// node_modules/fs-extra/lib/mkdirs/utils.js
var require_utils = __commonJS({
"node_modules/fs-extra/lib/mkdirs/utils.js"(exports2, module2) {
"use strict";
var path = require("path");
module2.exports.checkPath = function checkPath(pth) {
if (process.platform === "win32") {
const pathHasInvalidWinCharacters = /[<>:"|?*]/.test(pth.replace(path.parse(pth).root, ""));
if (pathHasInvalidWinCharacters) {
const error = new Error(`Path contains invalid characters: ${pth}`);
error.code = "EINVAL";
throw error;
}
}
};
}
});
// node_modules/fs-extra/lib/mkdirs/make-dir.js
var require_make_dir = __commonJS({
"node_modules/fs-extra/lib/mkdirs/make-dir.js"(exports2, module2) {
"use strict";
var fs2 = require_fs();
var { checkPath } = require_utils();
var getMode = (options) => {
const defaults = { mode: 511 };
if (typeof options === "number")
return options;
return { ...defaults, ...options }.mode;
};
module2.exports.makeDir = async (dir, options) => {
checkPath(dir);
return fs2.mkdir(dir, {
mode: getMode(options),
recursive: true
});
};
module2.exports.makeDirSync = (dir, options) => {
checkPath(dir);
return fs2.mkdirSync(dir, {
mode: getMode(options),
recursive: true
});
};
}
});
// node_modules/fs-extra/lib/mkdirs/index.js
var require_mkdirs = __commonJS({
"node_modules/fs-extra/lib/mkdirs/index.js"(exports2, module2) {
"use strict";
var u = require_universalify().fromPromise;
var { makeDir: _makeDir, makeDirSync } = require_make_dir();
var makeDir = u(_makeDir);
module2.exports = {
mkdirs: makeDir,
mkdirsSync: makeDirSync,
// alias
mkdirp: makeDir,
mkdirpSync: makeDirSync,
ensureDir: makeDir,
ensureDirSync: makeDirSync
};
}
});
// node_modules/fs-extra/lib/path-exists/index.js
var require_path_exists = __commonJS({
"node_modules/fs-extra/lib/path-exists/index.js"(exports2, module2) {
"use strict";
var u = require_universalify().fromPromise;
var fs2 = require_fs();
function pathExists(path) {
return fs2.access(path).then(() => true).catch(() => false);
}
module2.exports = {
pathExists: u(pathExists),
pathExistsSync: fs2.existsSync
};
}
});
// node_modules/fs-extra/lib/util/utimes.js
var require_utimes = __commonJS({
"node_modules/fs-extra/lib/util/utimes.js"(exports2, module2) {
"use strict";
var fs2 = require_fs();
var u = require_universalify().fromPromise;
async function utimesMillis(path, atime, mtime) {
const fd = await fs2.open(path, "r+");
let closeErr = null;
try {
await fs2.futimes(fd, atime, mtime);
} finally {
try {
await fs2.close(fd);
} catch (e) {
closeErr = e;
}
}
if (closeErr) {
throw closeErr;
}
}
function utimesMillisSync(path, atime, mtime) {
const fd = fs2.openSync(path, "r+");
fs2.futimesSync(fd, atime, mtime);
return fs2.closeSync(fd);
}
module2.exports = {
utimesMillis: u(utimesMillis),
utimesMillisSync
};
}
});
// node_modules/fs-extra/lib/util/stat.js
var require_stat = __commonJS({
"node_modules/fs-extra/lib/util/stat.js"(exports2, module2) {
"use strict";
var fs2 = require_fs();
var path = require("path");
var u = require_universalify().fromPromise;
function getStats(src, dest, opts) {
const statFunc = opts.dereference ? (file) => fs2.stat(file, { bigint: true }) : (file) => fs2.lstat(file, { bigint: true });
return Promise.all([
statFunc(src),
statFunc(dest).catch((err) => {
if (err.code === "ENOENT")
return null;
throw err;
})
]).then(([srcStat, destStat]) => ({ srcStat, destStat }));
}
function getStatsSync(src, dest, opts) {
let destStat;
const statFunc = opts.dereference ? (file) => fs2.statSync(file, { bigint: true }) : (file) => fs2.lstatSync(file, { bigint: true });
const srcStat = statFunc(src);
try {
destStat = statFunc(dest);
} catch (err) {
if (err.code === "ENOENT")
return { srcStat, destStat: null };
throw err;
}
return { srcStat, destStat };
}
async function checkPaths(src, dest, funcName, opts) {
const { srcStat, destStat } = await getStats(src, dest, opts);
if (destStat) {
if (areIdentical(srcStat, destStat)) {
const srcBaseName = path.basename(src);
const destBaseName = path.basename(dest);
if (funcName === "move" && srcBaseName !== destBaseName && srcBaseName.toLowerCase() === destBaseName.toLowerCase()) {
return { srcStat, destStat, isChangingCase: true };
}
throw new Error("Source and destination must not be the same.");
}
if (srcStat.isDirectory() && !destStat.isDirectory()) {
throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`);
}
if (!srcStat.isDirectory() && destStat.isDirectory()) {
throw new Error(`Cannot overwrite directory '${dest}' with non-directory '${src}'.`);
}
}
if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
throw new Error(errMsg(src, dest, funcName));
}
return { srcStat, destStat };
}
function checkPathsSync(src, dest, funcName, opts) {
const { srcStat, destStat } = getStatsSync(src, dest, opts);
if (destStat) {
if (areIdentical(srcStat, destStat)) {
const srcBaseName = path.basename(src);
const destBaseName = path.basename(dest);
if (funcName === "move" && srcBaseName !== destBaseName && srcBaseName.toLowerCase() === destBaseName.toLowerCase()) {
return { srcStat, destStat, isChangingCase: true };
}
throw new Error("Source and destination must not be the same.");
}
if (srcStat.isDirectory() && !destStat.isDirectory()) {
throw new Error(`Cannot overwrite non-directory '${dest}' with directory '${src}'.`);
}
if (!srcStat.isDirectory() && destStat.isDirectory()) {
throw new Error(`Cannot overwrite directory '${dest}' with non-directory '${src}'.`);
}
}
if (srcStat.isDirectory() && isSrcSubdir(src, dest)) {
throw new Error(errMsg(src, dest, funcName));
}
return { srcStat, destStat };
}
async function checkParentPaths(src, srcStat, dest, funcName) {
const srcParent = path.resolve(path.dirname(src));
const destParent = path.resolve(path.dirname(dest));
if (destParent === srcParent || destParent === path.parse(destParent).root)
return;
let destStat;
try {
destStat = await fs2.stat(destParent, { bigint: true });
} catch (err) {
if (err.code === "ENOENT")
return;
throw err;
}
if (areIdentical(srcStat, destStat)) {
throw new Error(errMsg(src, dest, funcName));
}
return checkParentPaths(src, srcStat, destParent, funcName);
}
function checkParentPathsSync(src, srcStat, dest, funcName) {
const srcParent = path.resolve(path.dirname(src));
const destParent = path.resolve(path.dirname(dest));
if (destParent === srcParent || destParent === path.parse(destParent).root)
return;
let destStat;
try {
destStat = fs2.statSync(destParent, { bigint: true });
} catch (err) {
if (err.code === "ENOENT")
return;
throw err;
}
if (areIdentical(srcStat, destStat)) {
throw new Error(errMsg(src, dest, funcName));
}
return checkParentPathsSync(src, srcStat, destParent, funcName);
}
function areIdentical(srcStat, destStat) {
return destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev;
}
function isSrcSubdir(src, dest) {
const srcArr = path.resolve(src).split(path.sep).filter((i) => i);
const destArr = path.resolve(dest).split(path.sep).filter((i) => i);
return srcArr.every((cur, i) => destArr[i] === cur);
}
function errMsg(src, dest, funcName) {
return `Cannot ${funcName} '${src}' to a subdirectory of itself, '${dest}'.`;
}
module2.exports = {
// checkPaths
checkPaths: u(checkPaths),
checkPathsSync,
// checkParent
checkParentPaths: u(checkParentPaths),
checkParentPathsSync,
// Misc
isSrcSubdir,
areIdentical
};
}
});
// node_modules/fs-extra/lib/copy/copy.js
var require_copy = __commonJS({
"node_modules/fs-extra/lib/copy/copy.js"(exports2, module2) {
"use strict";
var fs2 = require_fs();
var path = require("path");
var { mkdirs } = require_mkdirs();
var { pathExists } = require_path_exists();
var { utimesMillis } = require_utimes();
var stat = require_stat();
async function copy(src, dest, opts = {}) {
if (typeof opts === "function") {
opts = { filter: opts };
}
opts.clobber = "clobber" in opts ? !!opts.clobber : true;
opts.overwrite = "overwrite" in opts ? !!opts.overwrite : opts.clobber;
if (opts.preserveTimestamps && process.arch === "ia32") {
process.emitWarning(
"Using the preserveTimestamps option in 32-bit node is not recommended;\n\n see https://github.com/jprichardson/node-fs-extra/issues/269",
"Warning",
"fs-extra-WARN0001"
);
}
const { srcStat, destStat } = await stat.checkPaths(src, dest, "copy", opts);
await stat.checkParentPaths(src, srcStat, dest, "copy");
const include = await runFilter(src, dest, opts);
if (!include)
return;
const destParent = path.dirname(dest);
const dirExists = await pathExists(destParent);
if (!dirExists) {
await mkdirs(destParent);
}
await getStatsAndPerformCopy(destStat, src, dest, opts);
}
async function runFilter(src, dest, opts) {
if (!opts.filter)
return true;
return opts.filter(src, dest);
}
async function getStatsAndPerformCopy(destStat, src, dest, opts) {
const statFn = opts.dereference ? fs2.stat : fs2.lstat;
const srcStat = await statFn(src);
if (srcStat.isDirectory())
return onDir(srcStat, destStat, src, dest, opts);
if (srcStat.isFile() || srcStat.isCharacterDevice() || srcStat.isBlockDevice())
return onFile(srcStat, destStat, src, dest, opts);
if (srcStat.isSymbolicLink())
return onLink(destStat, src, dest, opts);
if (srcStat.isSocket())
throw new Error(`Cannot copy a socket file: ${src}`);
if (srcStat.isFIFO())
throw new Error(`Cannot copy a FIFO pipe: ${src}`);
throw new Error(`Unknown file: ${src}`);
}
async function onFile(srcStat, destStat, src, dest, opts) {
if (!destStat)
return copyFile(srcStat, src, dest, opts);
if (opts.overwrite) {
await fs2.unlink(dest);
return copyFile(srcStat, src, dest, opts);
}
if (opts.errorOnExist) {
throw new Error(`'${dest}' already exists`);
}
}
async function copyFile(srcStat, src, dest, opts) {
await fs2.copyFile(src, dest);
if (opts.preserveTimestamps) {
if (fileIsNotWritable(srcStat.mode)) {
await makeFileWritable(dest, srcStat.mode);
}
const updatedSrcStat = await fs2.stat(src);
await utimesMillis(dest, updatedSrcStat.atime, updatedSrcStat.mtime);
}
return fs2.chmod(dest, srcStat.mode);
}
function fileIsNotWritable(srcMode) {
return (srcMode & 128) === 0;
}
function makeFileWritable(dest, srcMode) {
return fs2.chmod(dest, srcMode | 128);
}
async function onDir(srcStat, destStat, src, dest, opts) {
if (!destStat) {
await fs2.mkdir(dest);
}
const items = await fs2.readdir(src);
await Promise.all(items.map(async (item) => {
const srcItem = path.join(src, item);
const destItem = path.join(dest, item);
const include = await runFilter(srcItem, destItem, opts);
if (!include)
return;
const { destStat: destStat2 } = await stat.checkPaths(srcItem, destItem, "copy", opts);
return getStatsAndPerformCopy(destStat2, srcItem, destItem, opts);
}));
if (!destStat) {
await fs2.chmod(dest, srcStat.mode);
}
}
async function onLink(destStat, src, dest, opts) {
let resolvedSrc = await fs2.readlink(src);
if (opts.dereference) {
resolvedSrc = path.resolve(process.cwd(), resolvedSrc);
}
if (!destStat) {
return fs2.symlink(resolvedSrc, dest);
}
let resolvedDest = null;
try {
resolvedDest = await fs2.readlink(dest);
} catch (e) {
if (e.code === "EINVAL" || e.code === "UNKNOWN")
return fs2.symlink(resolvedSrc, dest);
throw e;
}
if (opts.dereference) {
resolvedDest = path.resolve(process.cwd(), resolvedDest);
}
if (stat.isSrcSubdir(resolvedSrc, resolvedDest)) {
throw new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`);
}
if (stat.isSrcSubdir(resolvedDest, resolvedSrc)) {
throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`);
}
await fs2.unlink(dest);
return fs2.symlink(resolvedSrc, dest);
}
module2.exports = copy;
}
});
// node_modules/fs-extra/lib/copy/copy-sync.js
var require_copy_sync = __commonJS({
"node_modules/fs-extra/lib/copy/copy-sync.js"(exports2, module2) {
"use strict";
var fs2 = require_graceful_fs();
var path = require("path");
var mkdirsSync = require_mkdirs().mkdirsSync;
var utimesMillisSync = require_utimes().utimesMillisSync;
var stat = require_stat();
function copySync(src, dest, opts) {
if (typeof opts === "function") {
opts = { filter: opts };
}
opts = opts || {};
opts.clobber = "clobber" in opts ? !!opts.clobber : true;
opts.overwrite = "overwrite" in opts ? !!opts.overwrite : opts.clobber;
if (opts.preserveTimestamps && process.arch === "ia32") {
process.emitWarning(
"Using the preserveTimestamps option in 32-bit node is not recommended;\n\n see https://github.com/jprichardson/node-fs-extra/issues/269",
"Warning",
"fs-extra-WARN0002"
);
}
const { srcStat, destStat } = stat.checkPathsSync(src, dest, "copy", opts);
stat.checkParentPathsSync(src, srcStat, dest, "copy");
if (opts.filter && !opts.filter(src, dest))
return;
const destParent = path.dirname(dest);
if (!fs2.existsSync(destParent))
mkdirsSync(destParent);
return getStats(destStat, src, dest, opts);
}
function getStats(destStat, src, dest, opts) {
const statSync = opts.dereference ? fs2.statSync : fs2.lstatSync;
const srcStat = statSync(src);
if (srcStat.isDirectory())
return onDir(srcStat, destStat, src, dest, opts);
else if (srcStat.isFile() || srcStat.isCharacterDevice() || srcStat.isBlockDevice())
return onFile(srcStat, destStat, src, dest, opts);
else if (srcStat.isSymbolicLink())
return onLink(destStat, src, dest, opts);
else if (srcStat.isSocket())
throw new Error(`Cannot copy a socket file: ${src}`);
else if (srcStat.isFIFO())
throw new Error(`Cannot copy a FIFO pipe: ${src}`);
throw new Error(`Unknown file: ${src}`);
}
function onFile(srcStat, destStat, src, dest, opts) {
if (!destStat)
return copyFile(srcStat, src, dest, opts);
return mayCopyFile(srcStat, src, dest, opts);
}
function mayCopyFile(srcStat, src, dest, opts) {
if (opts.overwrite) {
fs2.unlinkSync(dest);
return copyFile(srcStat, src, dest, opts);
} else if (opts.errorOnExist) {
throw new Error(`'${dest}' already exists`);
}
}
function copyFile(srcStat, src, dest, opts) {
fs2.copyFileSync(src, dest);
if (opts.preserveTimestamps)
handleTimestamps(srcStat.mode, src, dest);
return setDestMode(dest, srcStat.mode);
}
function handleTimestamps(srcMode, src, dest) {
if (fileIsNotWritable(srcMode))
makeFileWritable(dest, srcMode);
return setDestTimestamps(src, dest);
}
function fileIsNotWritable(srcMode) {
return (srcMode & 128) === 0;
}
function makeFileWritable(dest, srcMode) {
return setDestMode(dest, srcMode | 128);
}
function setDestMode(dest, srcMode) {
return fs2.chmodSync(dest, srcMode);
}
function setDestTimestamps(src, dest) {
const updatedSrcStat = fs2.statSync(src);
return utimesMillisSync(dest, updatedSrcStat.atime, updatedSrcStat.mtime);
}
function onDir(srcStat, destStat, src, dest, opts) {
if (!destStat)
return mkDirAndCopy(srcStat.mode, src, dest, opts);
return copyDir(src, dest, opts);
}
function mkDirAndCopy(srcMode, src, dest, opts) {
fs2.mkdirSync(dest);
copyDir(src, dest, opts);
return setDestMode(dest, srcMode);
}
function copyDir(src, dest, opts) {
fs2.readdirSync(src).forEach((item) => copyDirItem(item, src, dest, opts));
}
function copyDirItem(item, src, dest, opts) {
const srcItem = path.join(src, item);
const destItem = path.join(dest, item);
if (opts.filter && !opts.filter(srcItem, destItem))
return;
const { destStat } = stat.checkPathsSync(srcItem, destItem, "copy", opts);
return getStats(destStat, srcItem, destItem, opts);
}
function onLink(destStat, src, dest, opts) {
let resolvedSrc = fs2.readlinkSync(src);
if (opts.dereference) {
resolvedSrc = path.resolve(process.cwd(), resolvedSrc);
}
if (!destStat) {
return fs2.symlinkSync(resolvedSrc, dest);
} else {
let resolvedDest;
try {
resolvedDest = fs2.readlinkSync(dest);
} catch (err) {
if (err.code === "EINVAL" || err.code === "UNKNOWN")
return fs2.symlinkSync(resolvedSrc, dest);
throw err;
}
if (opts.dereference) {
resolvedDest = path.resolve(process.cwd(), resolvedDest);
}
if (stat.isSrcSubdir(resolvedSrc, resolvedDest)) {
throw new Error(`Cannot copy '${resolvedSrc}' to a subdirectory of itself, '${resolvedDest}'.`);
}
if (stat.isSrcSubdir(resolvedDest, resolvedSrc)) {
throw new Error(`Cannot overwrite '${resolvedDest}' with '${resolvedSrc}'.`);
}
return copyLink(resolvedSrc, dest);
}
}
function copyLink(resolvedSrc, dest) {
fs2.unlinkSync(dest);
return fs2.symlinkSync(resolvedSrc, dest);
}
module2.exports = copySync;
}
});
// node_modules/fs-extra/lib/copy/index.js
var require_copy2 = __commonJS({
"node_modules/fs-extra/lib/copy/index.js"(exports2, module2) {
"use strict";
var u = require_universalify().fromPromise;
module2.exports = {
copy: u(require_copy()),
copySync: require_copy_sync()
};
}
});
// node_modules/fs-extra/lib/remove/index.js
var require_remove = __commonJS({
"node_modules/fs-extra/lib/remove/index.js"(exports2, module2) {
"use strict";
var fs2 = require_graceful_fs();
var u = require_universalify().fromCallback;
function remove(path, callback) {
fs2.rm(path, { recursive: true, force: true }, callback);
}
function removeSync2(path) {
fs2.rmSync(path, { recursive: true, force: true });
}
module2.exports = {
remove: u(remove),
removeSync: removeSync2
};
}
});
// node_modules/fs-extra/lib/empty/index.js
var require_empty = __commonJS({
"node_modules/fs-extra/lib/empty/index.js"(exports2, module2) {
"use strict";
var u = require_universalify().fromPromise;
var fs2 = require_fs();
var path = require("path");
var mkdir = require_mkdirs();
var remove = require_remove();
var emptyDir = u(async function emptyDir2(dir) {
let items;
try {
items = await fs2.readdir(dir);
} catch {
return mkdir.mkdirs(dir);
}
return Promise.all(items.map((item) => remove.remove(path.join(dir, item))));
});
function emptyDirSync(dir) {
let items;
try {
items = fs2.readdirSync(dir);
} catch {
return mkdir.mkdirsSync(dir);
}
items.forEach((item) => {
item = path.join(dir, item);
remove.removeSync(item);
});
}
module2.exports = {
emptyDirSync,
emptydirSync: emptyDirSync,
emptyDir,
emptydir: emptyDir
};
}
});
// node_modules/fs-extra/lib/ensure/file.js
var require_file = __commonJS({
"node_modules/fs-extra/lib/ensure/file.js"(exports2, module2) {
"use strict";
var u = require_universalify().fromPromise;
var path = require("path");
var fs2 = require_fs();
var mkdir = require_mkdirs();
async function createFile(file) {
let stats;
try {
stats = await fs2.stat(file);
} catch {
}
if (stats && stats.isFile())
return;
const dir = path.dirname(file);
let dirStats = null;
try {
dirStats = await fs2.stat(dir);
} catch (err) {
if (err.code === "ENOENT") {
await mkdir.mkdirs(dir);
await fs2.writeFile(file, "");
return;
} else {
throw err;
}
}
if (dirStats.isDirectory()) {
await fs2.writeFile(file, "");
} else {
await fs2.readdir(dir);
}
}
function createFileSync(file) {
let stats;
try {
stats = fs2.statSync(file);
} catch {
}
if (stats && stats.isFile())
return;
const dir = path.dirname(file);
try {
if (!fs2.statSync(dir).isDirectory()) {
fs2.readdirSync(dir);
}
} catch (err) {
if (err && err.code === "ENOENT")
mkdir.mkdirsSync(dir);
else
throw err;
}
fs2.writeFileSync(file, "");
}
module2.exports = {
createFile: u(createFile),
createFileSync
};
}
});
// node_modules/fs-extra/lib/ensure/link.js
var require_link = __commonJS({
"node_modules/fs-extra/lib/ensure/link.js"(exports2, module2) {
"use strict";
var u = require_universalify().fromPromise;
var path = require("path");
var fs2 = require_fs();
var mkdir = require_mkdirs();
var { pathExists } = require_path_exists();
var { areIdentical } = require_stat();
async function createLink(srcpath, dstpath) {
let dstStat;
try {
dstStat = await fs2.lstat(dstpath);
} catch {
}
let srcStat;
try {
srcStat = await fs2.lstat(srcpath);
} catch (err) {
err.message = err.message.replace("lstat", "ensureLink");
throw err;
}
if (dstStat && areIdentical(srcStat, dstStat))
return;
const dir = path.dirname(dstpath);
const dirExists = await pathExists(dir);
if (!dirExists) {
await mkdir.mkdirs(dir);
}
await fs2.link(srcpath, dstpath);
}
function createLinkSync(srcpath, dstpath) {
let dstStat;
try {
dstStat = fs2.lstatSync(dstpath);
} catch {
}
try {
const srcStat = fs2.lstatSync(srcpath);
if (dstStat && areIdentical(srcStat, dstStat))
return;
} catch (err) {
err.message = err.message.replace("lstat", "ensureLink");
throw err;
}
const dir = path.dirname(dstpath);
const dirExists = fs2.existsSync(dir);
if (dirExists)
return fs2.linkSync(srcpath, dstpath);
mkdir.mkdirsSync(dir);
return fs2.linkSync(srcpath, dstpath);
}
module2.exports = {
createLink: u(createLink),
createLinkSync
};
}
});
// node_modules/fs-extra/lib/ensure/symlink-paths.js
var require_symlink_paths = __commonJS({
"node_modules/fs-extra/lib/ensure/symlink-paths.js"(exports2, module2) {
"use strict";
var path = require("path");
var fs2 = require_fs();
var { pathExists } = require_path_exists();
var u = require_universalify().fromPromise;
async function symlinkPaths(srcpath, dstpath) {
if (path.isAbsolute(srcpath)) {
try {
await fs2.lstat(srcpath);
} catch (err) {
err.message = err.message.replace("lstat", "ensureSymlink");
throw err;
}
return {
toCwd: srcpath,
toDst: srcpath
};
}
const dstdir = path.dirname(dstpath);
const relativeToDst = path.join(dstdir, srcpath);
const exists = await pathExists(relativeToDst);
if (exists) {
return {
toCwd: relativeToDst,
toDst: srcpath
};
}
try {
await fs2.lstat(srcpath);
} catch (err) {
err.message = err.message.replace("lstat", "ensureSymlink");
throw err;
}
return {
toCwd: srcpath,
toDst: path.relative(dstdir, srcpath)
};
}
function symlinkPathsSync(srcpath, dstpath) {
if (path.isAbsolute(srcpath)) {
const exists2 = fs2.existsSync(srcpath);
if (!exists2)
throw new Error("absolute srcpath does not exist");
return {
toCwd: srcpath,
toDst: srcpath
};
}
const dstdir = path.dirname(dstpath);
const relativeToDst = path.join(dstdir, srcpath);
const exists = fs2.existsSync(relativeToDst);
if (exists) {
return {
toCwd: relativeToDst,
toDst: srcpath
};
}
const srcExists = fs2.existsSync(srcpath);
if (!srcExists)
throw new Error("relative srcpath does not exist");
return {
toCwd: srcpath,
toDst: path.relative(dstdir, srcpath)
};
}
module2.exports = {
symlinkPaths: u(symlinkPaths),
symlinkPathsSync
};
}
});
// node_modules/fs-extra/lib/ensure/symlink-type.js
var require_symlink_type = __commonJS({
"node_modules/fs-extra/lib/ensure/symlink-type.js"(exports2, module2) {
"use strict";
var fs2 = require_fs();
var u = require_universalify().fromPromise;
async function symlinkType(srcpath, type) {
if (type)
return type;
let stats;
try {
stats = await fs2.lstat(srcpath);
} catch {
return "file";
}
return stats && stats.isDirectory() ? "dir" : "file";
}
function symlinkTypeSync(srcpath, type) {
if (type)
return type;
let stats;
try {
stats = fs2.lstatSync(srcpath);
} catch {
return "file";
}
return stats && stats.isDirectory() ? "dir" : "file";
}
module2.exports = {
symlinkType: u(symlinkType),
symlinkTypeSync
};
}
});
// node_modules/fs-extra/lib/ensure/symlink.js
var require_symlink = __commonJS({
"node_modules/fs-extra/lib/ensure/symlink.js"(exports2, module2) {
"use strict";
var u = require_universalify().fromPromise;
var path = require("path");
var fs2 = require_fs();
var { mkdirs, mkdirsSync } = require_mkdirs();
var { symlinkPaths, symlinkPathsSync } = require_symlink_paths();
var { symlinkType, symlinkTypeSync } = require_symlink_type();
var { pathExists } = require_path_exists();
var { areIdentical } = require_stat();
async function createSymlink(srcpath, dstpath, type) {
let stats;
try {
stats = await fs2.lstat(dstpath);
} catch {
}
if (stats && stats.isSymbolicLink()) {
const [srcStat, dstStat] = await Promise.all([
fs2.stat(srcpath),
fs2.stat(dstpath)
]);
if (areIdentical(srcStat, dstStat))
return;
}
const relative = await symlinkPaths(srcpath, dstpath);
srcpath = relative.toDst;
const toType = await symlinkType(relative.toCwd, type);
const dir = path.dirname(dstpath);
if (!await pathExists(dir)) {
await mkdirs(dir);
}
return fs2.symlink(srcpath, dstpath, toType);
}
function createSymlinkSync(srcpath, dstpath, type) {
let stats;
try {
stats = fs2.lstatSync(dstpath);
} catch {
}
if (stats && stats.isSymbolicLink()) {
const srcStat = fs2.statSync(srcpath);
const dstStat = fs2.statSync(dstpath);
if (areIdentical(srcStat, dstStat))
return;
}
const relative = symlinkPathsSync(srcpath, dstpath);
srcpath = relative.toDst;
type = symlinkTypeSync(relative.toCwd, type);
const dir = path.dirname(dstpath);
const exists = fs2.existsSync(dir);
if (exists)
return fs2.symlinkSync(srcpath, dstpath, type);
mkdirsSync(dir);
return fs2.symlinkSync(srcpath, dstpath, type);
}
module2.exports = {
createSymlink: u(createSymlink),
createSymlinkSync
};
}
});
// node_modules/fs-extra/lib/ensure/index.js
var require_ensure = __commonJS({
"node_modules/fs-extra/lib/ensure/index.js"(exports2, module2) {
"use strict";
var { createFile, createFileSync } = require_file();
var { createLink, createLinkSync } = require_link();
var { createSymlink, createSymlinkSync } = require_symlink();
module2.exports = {
// file
createFile,
createFileSync,
ensureFile: createFile,
ensureFileSync: createFileSync,
// link
createLink,
createLinkSync,
ensureLink: createLink,
ensureLinkSync: createLinkSync,
// symlink
createSymlink,
createSymlinkSync,
ensureSymlink: createSymlink,
ensureSymlinkSync: createSymlinkSync
};
}
});
// node_modules/jsonfile/utils.js
var require_utils2 = __commonJS({
"node_modules/jsonfile/utils.js"(exports2, module2) {
function stringify(obj, { EOL = "\n", finalEOL = true, replacer = null, spaces } = {}) {
const EOF = finalEOL ? EOL : "";
const str = JSON.stringify(obj, replacer, spaces);
return str.replace(/\n/g, EOL) + EOF;
}
function stripBom(content) {
if (Buffer.isBuffer(content))
content = content.toString("utf8");
return content.replace(/^\uFEFF/, "");
}
module2.exports = { stringify, stripBom };
}
});
// node_modules/jsonfile/index.js
var require_jsonfile = __commonJS({
"node_modules/jsonfile/index.js"(exports2, module2) {
var _fs;
try {
_fs = require_graceful_fs();
} catch (_) {
_fs = require("fs");
}
var universalify = require_universalify();
var { stringify, stripBom } = require_utils2();
async function _readFile(file, options = {}) {
if (typeof options === "string") {
options = { encoding: options };
}
const fs2 = options.fs || _fs;
const shouldThrow = "throws" in options ? options.throws : true;
let data = await universalify.fromCallback(fs2.readFile)(file, options);
data = stripBom(data);
let obj;
try {
obj = JSON.parse(data, options ? options.reviver : null);
} catch (err) {
if (shouldThrow) {
err.message = `${file}: ${err.message}`;
throw err;
} else {
return null;
}
}
return obj;
}
var readFile = universalify.fromPromise(_readFile);
function readFileSync(file, options = {}) {
if (typeof options === "string") {
options = { encoding: options };
}
const fs2 = options.fs || _fs;
const shouldThrow = "throws" in options ? options.throws : true;
try {
let content = fs2.readFileSync(file, options);
content = stripBom(content);
return JSON.parse(content, options.reviver);
} catch (err) {
if (shouldThrow) {
err.message = `${file}: ${err.message}`;
throw err;
} else {
return null;
}
}
}
async function _writeFile(file, obj, options = {}) {
const fs2 = options.fs || _fs;
const str = stringify(obj, options);
await universalify.fromCallback(fs2.writeFile)(file, str, options);
}
var writeFile = universalify.fromPromise(_writeFile);
function writeFileSync(file, obj, options = {}) {
const fs2 = options.fs || _fs;
const str = stringify(obj, options);
return fs2.writeFileSync(file, str, options);
}
var jsonfile = {
readFile,
readFileSync,
writeFile,
writeFileSync
};
module2.exports = jsonfile;
}
});
// node_modules/fs-extra/lib/json/jsonfile.js
var require_jsonfile2 = __commonJS({
"node_modules/fs-extra/lib/json/jsonfile.js"(exports2, module2) {
"use strict";
var jsonFile = require_jsonfile();
module2.exports = {
// jsonfile exports
readJson: jsonFile.readFile,
readJsonSync: jsonFile.readFileSync,
writeJson: jsonFile.writeFile,
writeJsonSync: jsonFile.writeFileSync
};
}
});
// node_modules/fs-extra/lib/output-file/index.js
var require_output_file = __commonJS({
"node_modules/fs-extra/lib/output-file/index.js"(exports2, module2) {
"use strict";
var u = require_universalify().fromPromise;
var fs2 = require_fs();
var path = require("path");
var mkdir = require_mkdirs();
var pathExists = require_path_exists().pathExists;
async function outputFile(file, data, encoding = "utf-8") {
const dir = path.dirname(file);
if (!await pathExists(dir)) {
await mkdir.mkdirs(dir);
}
return fs2.writeFile(file, data, encoding);
}
function outputFileSync(file, ...args) {
const dir = path.dirname(file);
if (!fs2.existsSync(dir)) {
mkdir.mkdirsSync(dir);
}
fs2.writeFileSync(file, ...args);
}
module2.exports = {
outputFile: u(outputFile),
outputFileSync
};
}
});
// node_modules/fs-extra/lib/json/output-json.js
var require_output_json = __commonJS({
"node_modules/fs-extra/lib/json/output-json.js"(exports2, module2) {
"use strict";
var { stringify } = require_utils2();
var { outputFile } = require_output_file();
async function outputJson(file, data, options = {}) {
const str = stringify(data, options);
await outputFile(file, str, options);
}
module2.exports = outputJson;
}
});
// node_modules/fs-extra/lib/json/output-json-sync.js
var require_output_json_sync = __commonJS({
"node_modules/fs-extra/lib/json/output-json-sync.js"(exports2, module2) {
"use strict";
var { stringify } = require_utils2();
var { outputFileSync } = require_output_file();
function outputJsonSync(file, data, options) {
const str = stringify(data, options);
outputFileSync(file, str, options);
}
module2.exports = outputJsonSync;
}
});
// node_modules/fs-extra/lib/json/index.js
var require_json = __commonJS({
"node_modules/fs-extra/lib/json/index.js"(exports2, module2) {
"use strict";
var u = require_universalify().fromPromise;
var jsonFile = require_jsonfile2();
jsonFile.outputJson = u(require_output_json());
jsonFile.outputJsonSync = require_output_json_sync();
jsonFile.outputJSON = jsonFile.outputJson;
jsonFile.outputJSONSync = jsonFile.outputJsonSync;
jsonFile.writeJSON = jsonFile.writeJson;
jsonFile.writeJSONSync = jsonFile.writeJsonSync;
jsonFile.readJSON = jsonFile.readJson;
jsonFile.readJSONSync = jsonFile.readJsonSync;
module2.exports = jsonFile;
}
});
// node_modules/fs-extra/lib/move/move.js
var require_move = __commonJS({
"node_modules/fs-extra/lib/move/move.js"(exports2, module2) {
"use strict";
var fs2 = require_fs();
var path = require("path");
var { copy } = require_copy2();
var { remove } = require_remove();
var { mkdirp } = require_mkdirs();
var { pathExists } = require_path_exists();
var stat = require_stat();
async function move(src, dest, opts = {}) {
const overwrite = opts.overwrite || opts.clobber || false;
const { srcStat, isChangingCase = false } = await stat.checkPaths(src, dest, "move", opts);
await stat.checkParentPaths(src, srcStat, dest, "move");
const destParent = path.dirname(dest);
const parsedParentPath = path.parse(destParent);
if (parsedParentPath.root !== destParent) {
await mkdirp(destParent);
}
return doRename(src, dest, overwrite, isChangingCase);
}
async function doRename(src, dest, overwrite, isChangingCase) {
if (!isChangingCase) {
if (overwrite) {
await remove(dest);
} else if (await pathExists(dest)) {
throw new Error("dest already exists.");
}
}
try {
await fs2.rename(src, dest);
} catch (err) {
if (err.code !== "EXDEV") {
throw err;
}
await moveAcrossDevice(src, dest, overwrite);
}
}
async function moveAcrossDevice(src, dest, overwrite) {
const opts = {
overwrite,
errorOnExist: true,
preserveTimestamps: true
};
await copy(src, dest, opts);
return remove(src);
}
module2.exports = move;
}
});
// node_modules/fs-extra/lib/move/move-sync.js
var require_move_sync = __commonJS({
"node_modules/fs-extra/lib/move/move-sync.js"(exports2, module2) {
"use strict";
var fs2 = require_graceful_fs();
var path = require("path");
var copySync = require_copy2().copySync;
var removeSync2 = require_remove().removeSync;
var mkdirpSync = require_mkdirs().mkdirpSync;
var stat = require_stat();
function moveSync(src, dest, opts) {
opts = opts || {};
const overwrite = opts.overwrite || opts.clobber || false;
const { srcStat, isChangingCase = false } = stat.checkPathsSync(src, dest, "move", opts);
stat.checkParentPathsSync(src, srcStat, dest, "move");
if (!isParentRoot(dest))
mkdirpSync(path.dirname(dest));
return doRename(src, dest, overwrite, isChangingCase);
}
function isParentRoot(dest) {
const parent = path.dirname(dest);
const parsedPath = path.parse(parent);
return parsedPath.root === parent;
}
function doRename(src, dest, overwrite, isChangingCase) {
if (isChangingCase)
return rename(src, dest, overwrite);
if (overwrite) {
removeSync2(dest);
return rename(src, dest, overwrite);
}
if (fs2.existsSync(dest))
throw new Error("dest already exists.");
return rename(src, dest, overwrite);
}
function rename(src, dest, overwrite) {
try {
fs2.renameSync(src, dest);
} catch (err) {
if (err.code !== "EXDEV")
throw err;
return moveAcrossDevice(src, dest, overwrite);
}
}
function moveAcrossDevice(src, dest, overwrite) {
const opts = {
overwrite,
errorOnExist: true,
preserveTimestamps: true
};
copySync(src, dest, opts);
return removeSync2(src);
}
module2.exports = moveSync;
}
});
// node_modules/fs-extra/lib/move/index.js
var require_move2 = __commonJS({
"node_modules/fs-extra/lib/move/index.js"(exports2, module2) {
"use strict";
var u = require_universalify().fromPromise;
module2.exports = {
move: u(require_move()),
moveSync: require_move_sync()
};
}
});
// node_modules/fs-extra/lib/index.js
var require_lib = __commonJS({
"node_modules/fs-extra/lib/index.js"(exports2, module2) {
"use strict";
module2.exports = {
// Export promiseified graceful-fs:
...require_fs(),
// Export extra methods:
...require_copy2(),
...require_empty(),
...require_ensure(),
...require_json(),
...require_mkdirs(),
...require_move2(),
...require_output_file(),
...require_path_exists(),
...require_remove()
};
}
});
// submission-runner/cpp.cts
var cpp_exports = {};
__export(cpp_exports, {
runCpp: () => runCpp
});
module.exports = __toCommonJS(cpp_exports);
var import_path = require("path");
var import_child_process = require("child_process");
var util = __toESM(require("util"));
// submission-runner/settings.cts
var timeoutSeconds = 30;
// submission-runner/cpp.cts
var import_tree_kill = __toESM(require_tree_kill());
var os = __toESM(require("os"));
var fs = __toESM(require_lib());
var execPromise = util.promisify(import_child_process.exec);
var runCpp = async function(params) {
const tmpDir = os.tmpdir();
const buildDir = (0, import_path.join)(tmpDir, "bwcontest-cpp");
if (fs.existsSync(buildDir)) {
fs.removeSync(buildDir);
}
fs.mkdirSync(buildDir);
console.log(`- BUILD: ${params.problemName}`);
const configureCommand = `cmake -S ${params.srcDir} -B ${buildDir}`;
try {
await execPromise(configureCommand);
} catch (e) {
const buildErrorText = e?.toString() ?? "Unknown build errors.";
console.log("Build errors: " + buildErrorText);
return {
success: false,
runResult: { kind: "CompileFailed", resultKindReason: buildErrorText }
};
}
const compileCommand = `cmake --build ${buildDir} --target ${params.problemName}`;
try {
await execPromise(compileCommand);
} catch (e) {
const buildErrorText = e?.toString() ?? "Unknown build errors.";
console.log("Build errors: " + buildErrorText);
return {
success: false,
runResult: { kind: "CompileFailed", resultKindReason: buildErrorText }
};
}
console.log(`- RUN: ${params.problemName}`);
let runCommand = "";
if (params.cppPlatform === "VisualStudio") {
runCommand = `${(0, import_path.join)(buildDir, "Debug", `${params.problemName}.exe`)}`;
} else {
runCommand = `${(0, import_path.join)(buildDir, params.problemName)}`;
}
try {
let outputBuffer = "";
const child = (0, import_child_process.spawn)(runCommand, { shell: true });
child.stdout.setEncoding("utf8");
child.stdout.on("data", (data) => {
outputBuffer += data.toString();
});
child.stderr.setEncoding("utf8");
child.stderr.on("data", (data) => {
outputBuffer += data.toString();
});
const runStartTime = performance.now();
child.stdin.write(params.input);
child.stdin.end();
let timeLimitExceeded = false;
let completedNormally = false;
return {
success: true,
runResult: new Promise((resolve) => {
child.on("close", () => {
completedNormally = !timeLimitExceeded;
const runEndTime = performance.now();
const runtimeMilliseconds = Math.floor(runEndTime - runStartTime);
if (completedNormally) {
clearTimeout(timeoutHandle);
resolve({
kind: "Completed",
output: outputBuffer,
exitCode: child.exitCode,
runtimeMilliseconds
});
} else {
console.log(`Process terminated, total sandbox time: ${runtimeMilliseconds}ms`);
resolve({
kind: "TimeLimitExceeded",
output: outputBuffer,
resultKindReason: `Timeout after ${timeoutSeconds} seconds`
});
}
});
const timeoutHandle = setTimeout(() => {
if (completedNormally) {
return;
}
console.log(`Run timed out after ${timeoutSeconds} seconds, killing process...`);
timeLimitExceeded = true;
child.stdin.end();
child.stdin.destroy();
child.stdout.destroy();
child.stderr.destroy();
child.kill("SIGKILL");
}, timeoutSeconds * 1e3);
}),
killFunc() {
if (child.pid !== void 0) {
if (!completedNormally && !timeLimitExceeded) {
(0, import_tree_kill.default)(child.pid);
params.outputCallback?.("\n[Manually stopped]");
}
}
}
};
} catch (error) {
return { success: false, runResult: { kind: "RunError" } };
}
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
runCpp
});