@prisma/cli-init
Version:
Init CLI for Prisma
1,544 lines (1,532 loc) • 119 kB
JavaScript
import { createRequire } from 'node:module'; const require = createRequire(import.meta.url);
import {
Engine,
encodeAPIKey,
ensureDirectory,
getDataDirPath,
integer,
literal,
minLength,
minValue,
number,
object,
optional,
parseJson,
pipe,
readDirectoryNames,
readFileAsText,
safeParse,
streamAsTextTo,
string,
url,
withResolvers,
y
} from "./chunk-XE2LPBET.js";
import {
credentialsFile,
poll,
printPpgInitOutput,
requestOrThrow,
successMessage
} from "./chunk-FY2W4YAF.js";
import {
__commonJS,
__require,
__toESM
} from "./chunk-YX4UTTNJ.js";
// ../../node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/polyfills.js
var require_polyfills = __commonJS({
"../../node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/polyfills.js"(exports, module) {
"use strict";
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(d2) {
cwd = null;
chdir.call(process, d2);
};
if (Object.setPrototypeOf)
Object.setPrototypeOf(process.chdir, chdir);
}
var chdir;
module.exports = patch;
function patch(fs3) {
if (constants.hasOwnProperty("O_SYMLINK") && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./)) {
patchLchmod(fs3);
}
if (!fs3.lutimes) {
patchLutimes(fs3);
}
fs3.chown = chownFix(fs3.chown);
fs3.fchown = chownFix(fs3.fchown);
fs3.lchown = chownFix(fs3.lchown);
fs3.chmod = chmodFix(fs3.chmod);
fs3.fchmod = chmodFix(fs3.fchmod);
fs3.lchmod = chmodFix(fs3.lchmod);
fs3.chownSync = chownFixSync(fs3.chownSync);
fs3.fchownSync = chownFixSync(fs3.fchownSync);
fs3.lchownSync = chownFixSync(fs3.lchownSync);
fs3.chmodSync = chmodFixSync(fs3.chmodSync);
fs3.fchmodSync = chmodFixSync(fs3.fchmodSync);
fs3.lchmodSync = chmodFixSync(fs3.lchmodSync);
fs3.stat = statFix(fs3.stat);
fs3.fstat = statFix(fs3.fstat);
fs3.lstat = statFix(fs3.lstat);
fs3.statSync = statFixSync(fs3.statSync);
fs3.fstatSync = statFixSync(fs3.fstatSync);
fs3.lstatSync = statFixSync(fs3.lstatSync);
if (fs3.chmod && !fs3.lchmod) {
fs3.lchmod = function(path3, mode, cb) {
if (cb)
process.nextTick(cb);
};
fs3.lchmodSync = function() {
};
}
if (fs3.chown && !fs3.lchown) {
fs3.lchown = function(path3, uid, gid, cb) {
if (cb)
process.nextTick(cb);
};
fs3.lchownSync = function() {
};
}
if (platform === "win32") {
fs3.rename = typeof fs3.rename !== "function" ? fs3.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() {
fs3.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;
}(fs3.rename);
}
fs3.read = typeof fs3.read !== "function" ? fs3.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(fs3, fd, buffer, offset, length, position, callback);
}
callback_.apply(this, arguments);
};
}
return fs$read.call(fs3, fd, buffer, offset, length, position, callback);
}
if (Object.setPrototypeOf)
Object.setPrototypeOf(read, fs$read);
return read;
}(fs3.read);
fs3.readSync = typeof fs3.readSync !== "function" ? fs3.readSync : /* @__PURE__ */ function(fs$readSync) {
return function(fd, buffer, offset, length, position) {
var eagCounter = 0;
while (true) {
try {
return fs$readSync.call(fs3, fd, buffer, offset, length, position);
} catch (er) {
if (er.code === "EAGAIN" && eagCounter < 10) {
eagCounter++;
continue;
}
throw er;
}
}
};
}(fs3.readSync);
function patchLchmod(fs4) {
fs4.lchmod = function(path3, mode, callback) {
fs4.open(
path3,
constants.O_WRONLY | constants.O_SYMLINK,
mode,
function(err, fd) {
if (err) {
if (callback)
callback(err);
return;
}
fs4.fchmod(fd, mode, function(err2) {
fs4.close(fd, function(err22) {
if (callback)
callback(err2 || err22);
});
});
}
);
};
fs4.lchmodSync = function(path3, mode) {
var fd = fs4.openSync(path3, constants.O_WRONLY | constants.O_SYMLINK, mode);
var threw = true;
var ret;
try {
ret = fs4.fchmodSync(fd, mode);
threw = false;
} finally {
if (threw) {
try {
fs4.closeSync(fd);
} catch (er) {
}
} else {
fs4.closeSync(fd);
}
}
return ret;
};
}
function patchLutimes(fs4) {
if (constants.hasOwnProperty("O_SYMLINK") && fs4.futimes) {
fs4.lutimes = function(path3, at, mt, cb) {
fs4.open(path3, constants.O_SYMLINK, function(er, fd) {
if (er) {
if (cb)
cb(er);
return;
}
fs4.futimes(fd, at, mt, function(er2) {
fs4.close(fd, function(er22) {
if (cb)
cb(er2 || er22);
});
});
});
};
fs4.lutimesSync = function(path3, at, mt) {
var fd = fs4.openSync(path3, constants.O_SYMLINK);
var ret;
var threw = true;
try {
ret = fs4.futimesSync(fd, at, mt);
threw = false;
} finally {
if (threw) {
try {
fs4.closeSync(fd);
} catch (er) {
}
} else {
fs4.closeSync(fd);
}
}
return ret;
};
} else if (fs4.futimes) {
fs4.lutimes = function(_a, _b, _c, cb) {
if (cb)
process.nextTick(cb);
};
fs4.lutimesSync = function() {
};
}
}
function chmodFix(orig) {
if (!orig)
return orig;
return function(target, mode, cb) {
return orig.call(fs3, 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(fs3, 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(fs3, 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(fs3, 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(fs3, target, options, callback) : orig.call(fs3, target, callback);
};
}
function statFixSync(orig) {
if (!orig)
return orig;
return function(target, options) {
var stats = options ? orig.call(fs3, target, options) : orig.call(fs3, 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/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/legacy-streams.js
var require_legacy_streams = __commonJS({
"../../node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/legacy-streams.js"(exports, module) {
"use strict";
var Stream = __require("stream").Stream;
module.exports = legacy;
function legacy(fs3) {
return {
ReadStream,
WriteStream
};
function ReadStream(path3, options) {
if (!(this instanceof ReadStream))
return new ReadStream(path3, options);
Stream.call(this);
var self = this;
this.path = path3;
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;
}
fs3.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(path3, options) {
if (!(this instanceof WriteStream))
return new WriteStream(path3, options);
Stream.call(this);
this.path = path3;
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 = fs3.open;
this._queue.push([this._open, this.path, this.flags, this.mode, void 0]);
this.flush();
}
}
}
}
});
// ../../node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/clone.js
var require_clone = __commonJS({
"../../node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/clone.js"(exports, module) {
"use strict";
module.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/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/graceful-fs.js
var require_graceful_fs = __commonJS({
"../../node_modules/.pnpm/graceful-fs@4.2.11/node_modules/graceful-fs/graceful-fs.js"(exports, module) {
"use strict";
var fs3 = __require("fs");
var polyfills = require_polyfills();
var legacy = require_legacy_streams();
var clone = require_clone();
var util = __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 (util.debuglog)
debug = util.debuglog("gfs4");
else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || ""))
debug = function() {
var m = util.format.apply(util, arguments);
m = "GFS4: " + m.split(/\n/).join("\nGFS4: ");
console.error(m);
};
if (!fs3[gracefulQueue]) {
queue = global[gracefulQueue] || [];
publishQueue(fs3, queue);
fs3.close = function(fs$close) {
function close(fd, cb) {
return fs$close.call(fs3, fd, function(err) {
if (!err) {
resetQueue();
}
if (typeof cb === "function")
cb.apply(this, arguments);
});
}
Object.defineProperty(close, previousSymbol, {
value: fs$close
});
return close;
}(fs3.close);
fs3.closeSync = function(fs$closeSync) {
function closeSync(fd) {
fs$closeSync.apply(fs3, arguments);
resetQueue();
}
Object.defineProperty(closeSync, previousSymbol, {
value: fs$closeSync
});
return closeSync;
}(fs3.closeSync);
if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) {
process.on("exit", function() {
debug(fs3[gracefulQueue]);
__require("assert").equal(fs3[gracefulQueue].length, 0);
});
}
}
var queue;
if (!global[gracefulQueue]) {
publishQueue(global, fs3[gracefulQueue]);
}
module.exports = patch(clone(fs3));
if (process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs3.__patched) {
module.exports = patch(fs3);
fs3.__patched = true;
}
function patch(fs4) {
polyfills(fs4);
fs4.gracefulify = patch;
fs4.createReadStream = createReadStream;
fs4.createWriteStream = createWriteStream;
var fs$readFile = fs4.readFile;
fs4.readFile = readFile;
function readFile(path3, options, cb) {
if (typeof options === "function")
cb = options, options = null;
return go$readFile(path3, options, cb);
function go$readFile(path4, options2, cb2, startTime) {
return fs$readFile(path4, options2, function(err) {
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
enqueue([go$readFile, [path4, options2, cb2], err, startTime || Date.now(), Date.now()]);
else {
if (typeof cb2 === "function")
cb2.apply(this, arguments);
}
});
}
}
var fs$writeFile = fs4.writeFile;
fs4.writeFile = writeFile2;
function writeFile2(path3, data, options, cb) {
if (typeof options === "function")
cb = options, options = null;
return go$writeFile(path3, data, options, cb);
function go$writeFile(path4, data2, options2, cb2, startTime) {
return fs$writeFile(path4, data2, options2, function(err) {
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
enqueue([go$writeFile, [path4, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
else {
if (typeof cb2 === "function")
cb2.apply(this, arguments);
}
});
}
}
var fs$appendFile = fs4.appendFile;
if (fs$appendFile)
fs4.appendFile = appendFile;
function appendFile(path3, data, options, cb) {
if (typeof options === "function")
cb = options, options = null;
return go$appendFile(path3, data, options, cb);
function go$appendFile(path4, data2, options2, cb2, startTime) {
return fs$appendFile(path4, data2, options2, function(err) {
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
enqueue([go$appendFile, [path4, data2, options2, cb2], err, startTime || Date.now(), Date.now()]);
else {
if (typeof cb2 === "function")
cb2.apply(this, arguments);
}
});
}
}
var fs$copyFile = fs4.copyFile;
if (fs$copyFile)
fs4.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 = fs4.readdir;
fs4.readdir = readdir;
var noReaddirOptionVersions = /^v[0-5]\./;
function readdir(path3, options, cb) {
if (typeof options === "function")
cb = options, options = null;
var go$readdir = noReaddirOptionVersions.test(process.version) ? function go$readdir2(path4, options2, cb2, startTime) {
return fs$readdir(path4, fs$readdirCallback(
path4,
options2,
cb2,
startTime
));
} : function go$readdir2(path4, options2, cb2, startTime) {
return fs$readdir(path4, options2, fs$readdirCallback(
path4,
options2,
cb2,
startTime
));
};
return go$readdir(path3, options, cb);
function fs$readdirCallback(path4, options2, cb2, startTime) {
return function(err, files) {
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
enqueue([
go$readdir,
[path4, 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(fs4);
ReadStream = legStreams.ReadStream;
WriteStream = legStreams.WriteStream;
}
var fs$ReadStream = fs4.ReadStream;
if (fs$ReadStream) {
ReadStream.prototype = Object.create(fs$ReadStream.prototype);
ReadStream.prototype.open = ReadStream$open;
}
var fs$WriteStream = fs4.WriteStream;
if (fs$WriteStream) {
WriteStream.prototype = Object.create(fs$WriteStream.prototype);
WriteStream.prototype.open = WriteStream$open;
}
Object.defineProperty(fs4, "ReadStream", {
get: function() {
return ReadStream;
},
set: function(val) {
ReadStream = val;
},
enumerable: true,
configurable: true
});
Object.defineProperty(fs4, "WriteStream", {
get: function() {
return WriteStream;
},
set: function(val) {
WriteStream = val;
},
enumerable: true,
configurable: true
});
var FileReadStream = ReadStream;
Object.defineProperty(fs4, "FileReadStream", {
get: function() {
return FileReadStream;
},
set: function(val) {
FileReadStream = val;
},
enumerable: true,
configurable: true
});
var FileWriteStream = WriteStream;
Object.defineProperty(fs4, "FileWriteStream", {
get: function() {
return FileWriteStream;
},
set: function(val) {
FileWriteStream = val;
},
enumerable: true,
configurable: true
});
function ReadStream(path3, 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(path3, 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(path3, options) {
return new fs4.ReadStream(path3, options);
}
function createWriteStream(path3, options) {
return new fs4.WriteStream(path3, options);
}
var fs$open = fs4.open;
fs4.open = open;
function open(path3, flags, mode, cb) {
if (typeof mode === "function")
cb = mode, mode = null;
return go$open(path3, flags, mode, cb);
function go$open(path4, flags2, mode2, cb2, startTime) {
return fs$open(path4, flags2, mode2, function(err, fd) {
if (err && (err.code === "EMFILE" || err.code === "ENFILE"))
enqueue([go$open, [path4, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]);
else {
if (typeof cb2 === "function")
cb2.apply(this, arguments);
}
});
}
}
return fs4;
}
function enqueue(elem) {
debug("ENQUEUE", elem[0].name, elem[1]);
fs3[gracefulQueue].push(elem);
retry();
}
var retryTimer;
function resetQueue() {
var now = Date.now();
for (var i = 0; i < fs3[gracefulQueue].length; ++i) {
if (fs3[gracefulQueue][i].length > 2) {
fs3[gracefulQueue][i][3] = now;
fs3[gracefulQueue][i][4] = now;
}
}
retry();
}
function retry() {
clearTimeout(retryTimer);
retryTimer = void 0;
if (fs3[gracefulQueue].length === 0)
return;
var elem = fs3[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 {
fs3[gracefulQueue].push(elem);
}
}
if (retryTimer === void 0) {
retryTimer = setTimeout(retry, 0);
}
}
}
});
// ../../node_modules/.pnpm/retry@0.12.0/node_modules/retry/lib/retry_operation.js
var require_retry_operation = __commonJS({
"../../node_modules/.pnpm/retry@0.12.0/node_modules/retry/lib/retry_operation.js"(exports, module) {
"use strict";
function RetryOperation(timeouts, options) {
if (typeof options === "boolean") {
options = { forever: options };
}
this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
this._timeouts = timeouts;
this._options = options || {};
this._maxRetryTime = options && options.maxRetryTime || Infinity;
this._fn = null;
this._errors = [];
this._attempts = 1;
this._operationTimeout = null;
this._operationTimeoutCb = null;
this._timeout = null;
this._operationStart = null;
if (this._options.forever) {
this._cachedTimeouts = this._timeouts.slice(0);
}
}
module.exports = RetryOperation;
RetryOperation.prototype.reset = function() {
this._attempts = 1;
this._timeouts = this._originalTimeouts;
};
RetryOperation.prototype.stop = function() {
if (this._timeout) {
clearTimeout(this._timeout);
}
this._timeouts = [];
this._cachedTimeouts = null;
};
RetryOperation.prototype.retry = function(err) {
if (this._timeout) {
clearTimeout(this._timeout);
}
if (!err) {
return false;
}
var currentTime = (/* @__PURE__ */ new Date()).getTime();
if (err && currentTime - this._operationStart >= this._maxRetryTime) {
this._errors.unshift(new Error("RetryOperation timeout occurred"));
return false;
}
this._errors.push(err);
var timeout = this._timeouts.shift();
if (timeout === void 0) {
if (this._cachedTimeouts) {
this._errors.splice(this._errors.length - 1, this._errors.length);
this._timeouts = this._cachedTimeouts.slice(0);
timeout = this._timeouts.shift();
} else {
return false;
}
}
var self = this;
var timer = setTimeout(function() {
self._attempts++;
if (self._operationTimeoutCb) {
self._timeout = setTimeout(function() {
self._operationTimeoutCb(self._attempts);
}, self._operationTimeout);
if (self._options.unref) {
self._timeout.unref();
}
}
self._fn(self._attempts);
}, timeout);
if (this._options.unref) {
timer.unref();
}
return true;
};
RetryOperation.prototype.attempt = function(fn, timeoutOps) {
this._fn = fn;
if (timeoutOps) {
if (timeoutOps.timeout) {
this._operationTimeout = timeoutOps.timeout;
}
if (timeoutOps.cb) {
this._operationTimeoutCb = timeoutOps.cb;
}
}
var self = this;
if (this._operationTimeoutCb) {
this._timeout = setTimeout(function() {
self._operationTimeoutCb();
}, self._operationTimeout);
}
this._operationStart = (/* @__PURE__ */ new Date()).getTime();
this._fn(this._attempts);
};
RetryOperation.prototype.try = function(fn) {
console.log("Using RetryOperation.try() is deprecated");
this.attempt(fn);
};
RetryOperation.prototype.start = function(fn) {
console.log("Using RetryOperation.start() is deprecated");
this.attempt(fn);
};
RetryOperation.prototype.start = RetryOperation.prototype.try;
RetryOperation.prototype.errors = function() {
return this._errors;
};
RetryOperation.prototype.attempts = function() {
return this._attempts;
};
RetryOperation.prototype.mainError = function() {
if (this._errors.length === 0) {
return null;
}
var counts = {};
var mainError = null;
var mainErrorCount = 0;
for (var i = 0; i < this._errors.length; i++) {
var error = this._errors[i];
var message = error.message;
var count = (counts[message] || 0) + 1;
counts[message] = count;
if (count >= mainErrorCount) {
mainError = error;
mainErrorCount = count;
}
}
return mainError;
};
}
});
// ../../node_modules/.pnpm/retry@0.12.0/node_modules/retry/lib/retry.js
var require_retry = __commonJS({
"../../node_modules/.pnpm/retry@0.12.0/node_modules/retry/lib/retry.js"(exports) {
"use strict";
var RetryOperation = require_retry_operation();
exports.operation = function(options) {
var timeouts = exports.timeouts(options);
return new RetryOperation(timeouts, {
forever: options && options.forever,
unref: options && options.unref,
maxRetryTime: options && options.maxRetryTime
});
};
exports.timeouts = function(options) {
if (options instanceof Array) {
return [].concat(options);
}
var opts = {
retries: 10,
factor: 2,
minTimeout: 1 * 1e3,
maxTimeout: Infinity,
randomize: false
};
for (var key in options) {
opts[key] = options[key];
}
if (opts.minTimeout > opts.maxTimeout) {
throw new Error("minTimeout is greater than maxTimeout");
}
var timeouts = [];
for (var i = 0; i < opts.retries; i++) {
timeouts.push(this.createTimeout(i, opts));
}
if (options && options.forever && !timeouts.length) {
timeouts.push(this.createTimeout(i, opts));
}
timeouts.sort(function(a2, b) {
return a2 - b;
});
return timeouts;
};
exports.createTimeout = function(attempt, opts) {
var random = opts.randomize ? Math.random() + 1 : 1;
var timeout = Math.round(random * opts.minTimeout * Math.pow(opts.factor, attempt));
timeout = Math.min(timeout, opts.maxTimeout);
return timeout;
};
exports.wrap = function(obj, options, methods) {
if (options instanceof Array) {
methods = options;
options = null;
}
if (!methods) {
methods = [];
for (var key in obj) {
if (typeof obj[key] === "function") {
methods.push(key);
}
}
}
for (var i = 0; i < methods.length; i++) {
var method = methods[i];
var original = obj[method];
obj[method] = function retryWrapper(original2) {
var op = exports.operation(options);
var args = Array.prototype.slice.call(arguments, 1);
var callback = args.pop();
args.push(function(err) {
if (op.retry(err)) {
return;
}
if (err) {
arguments[0] = op.mainError();
}
callback.apply(this, arguments);
});
op.attempt(function() {
original2.apply(obj, args);
});
}.bind(obj, original);
obj[method].options = options;
}
};
}
});
// ../../node_modules/.pnpm/retry@0.12.0/node_modules/retry/index.js
var require_retry2 = __commonJS({
"../../node_modules/.pnpm/retry@0.12.0/node_modules/retry/index.js"(exports, module) {
"use strict";
module.exports = require_retry();
}
});
// ../../node_modules/.pnpm/signal-exit@3.0.7/node_modules/signal-exit/signals.js
var require_signals = __commonJS({
"../../node_modules/.pnpm/signal-exit@3.0.7/node_modules/signal-exit/signals.js"(exports, module) {
"use strict";
module.exports = [
"SIGABRT",
"SIGALRM",
"SIGHUP",
"SIGINT",
"SIGTERM"
];
if (process.platform !== "win32") {
module.exports.push(
"SIGVTALRM",
"SIGXCPU",
"SIGXFSZ",
"SIGUSR2",
"SIGTRAP",
"SIGSYS",
"SIGQUIT",
"SIGIOT"
// should detect profiler and enable/disable accordingly.
// see #21
// 'SIGPROF'
);
}
if (process.platform === "linux") {
module.exports.push(
"SIGIO",
"SIGPOLL",
"SIGPWR",
"SIGSTKFLT",
"SIGUNUSED"
);
}
}
});
// ../../node_modules/.pnpm/signal-exit@3.0.7/node_modules/signal-exit/index.js
var require_signal_exit = __commonJS({
"../../node_modules/.pnpm/signal-exit@3.0.7/node_modules/signal-exit/index.js"(exports, module) {
"use strict";
var process2 = global.process;
var processOk = function(process3) {
return process3 && typeof process3 === "object" && typeof process3.removeListener === "function" && typeof process3.emit === "function" && typeof process3.reallyExit === "function" && typeof process3.listeners === "function" && typeof process3.kill === "function" && typeof process3.pid === "number" && typeof process3.on === "function";
};
if (!processOk(process2)) {
module.exports = function() {
return function() {
};
};
} else {
assert = __require("assert");
signals = require_signals();
isWin = /^win/i.test(process2.platform);
EE = __require("events");
if (typeof EE !== "function") {
EE = EE.EventEmitter;
}
if (process2.__signal_exit_emitter__) {
emitter = process2.__signal_exit_emitter__;
} else {
emitter = process2.__signal_exit_emitter__ = new EE();
emitter.count = 0;
emitter.emitted = {};
}
if (!emitter.infinite) {
emitter.setMaxListeners(Infinity);
emitter.infinite = true;
}
module.exports = function(cb, opts) {
if (!processOk(global.process)) {
return function() {
};
}
assert.equal(typeof cb, "function", "a callback must be provided for exit handler");
if (loaded === false) {
load();
}
var ev = "exit";
if (opts && opts.alwaysLast) {
ev = "afterexit";
}
var remove = function() {
emitter.removeListener(ev, cb);
if (emitter.listeners("exit").length === 0 && emitter.listeners("afterexit").length === 0) {
unload();
}
};
emitter.on(ev, cb);
return remove;
};
unload = function unload2() {
if (!loaded || !processOk(global.process)) {
return;
}
loaded = false;
signals.forEach(function(sig) {
try {
process2.removeListener(sig, sigListeners[sig]);
} catch (er) {
}
});
process2.emit = originalProcessEmit;
process2.reallyExit = originalProcessReallyExit;
emitter.count -= 1;
};
module.exports.unload = unload;
emit = function emit2(event, code, signal) {
if (emitter.emitted[event]) {
return;
}
emitter.emitted[event] = true;
emitter.emit(event, code, signal);
};
sigListeners = {};
signals.forEach(function(sig) {
sigListeners[sig] = function listener() {
if (!processOk(global.process)) {
return;
}
var listeners = process2.listeners(sig);
if (listeners.length === emitter.count) {
unload();
emit("exit", null, sig);
emit("afterexit", null, sig);
if (isWin && sig === "SIGHUP") {
sig = "SIGINT";
}
process2.kill(process2.pid, sig);
}
};
});
module.exports.signals = function() {
return signals;
};
loaded = false;
load = function load2() {
if (loaded || !processOk(global.process)) {
return;
}
loaded = true;
emitter.count += 1;
signals = signals.filter(function(sig) {
try {
process2.on(sig, sigListeners[sig]);
return true;
} catch (er) {
return false;
}
});
process2.emit = processEmit;
process2.reallyExit = processReallyExit;
};
module.exports.load = load;
originalProcessReallyExit = process2.reallyExit;
processReallyExit = function processReallyExit2(code) {
if (!processOk(global.process)) {
return;
}
process2.exitCode = code || /* istanbul ignore next */
0;
emit("exit", process2.exitCode, null);
emit("afterexit", process2.exitCode, null);
originalProcessReallyExit.call(process2, process2.exitCode);
};
originalProcessEmit = process2.emit;
processEmit = function processEmit2(ev, arg) {
if (ev === "exit" && processOk(global.process)) {
if (arg !== void 0) {
process2.exitCode = arg;
}
var ret = originalProcessEmit.apply(this, arguments);
emit("exit", process2.exitCode, null);
emit("afterexit", process2.exitCode, null);
return ret;
} else {
return originalProcessEmit.apply(this, arguments);
}
};
}
var assert;
var signals;
var isWin;
var EE;
var emitter;
var unload;
var emit;
var sigListeners;
var loaded;
var load;
var originalProcessReallyExit;
var processReallyExit;
var originalProcessEmit;
var processEmit;
}
});
// ../../node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/mtime-precision.js
var require_mtime_precision = __commonJS({
"../../node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/mtime-precision.js"(exports, module) {
"use strict";
var cacheSymbol = Symbol();
function probe(file, fs3, callback) {
const cachedPrecision = fs3[cacheSymbol];
if (cachedPrecision) {
return fs3.stat(file, (err, stat) => {
if (err) {
return callback(err);
}
callback(null, stat.mtime, cachedPrecision);
});
}
const mtime = new Date(Math.ceil(Date.now() / 1e3) * 1e3 + 5);
fs3.utimes(file, mtime, mtime, (err) => {
if (err) {
return callback(err);
}
fs3.stat(file, (err2, stat) => {
if (err2) {
return callback(err2);
}
const precision = stat.mtime.getTime() % 1e3 === 0 ? "s" : "ms";
Object.defineProperty(fs3, cacheSymbol, { value: precision });
callback(null, stat.mtime, precision);
});
});
}
function getMtime(precision) {
let now = Date.now();
if (precision === "s") {
now = Math.ceil(now / 1e3) * 1e3;
}
return new Date(now);
}
module.exports.probe = probe;
module.exports.getMtime = getMtime;
}
});
// ../../node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/lockfile.js
var require_lockfile = __commonJS({
"../../node_modules/.pnpm/proper-lockfile@4.1.2/node_modules/proper-lockfile/lib/lockfile.js"(exports, module) {
"use strict";
var path3 = __require("path");
var fs3 = require_graceful_fs();
var retry = require_retry2();
var onExit = require_signal_exit();
var mtimePrecision = require_mtime_precision();
var locks = {};
function getLockFile(file, options) {
return options.lockfilePath || `${file}.lock`;
}
function resolveCanonicalPath(file, options, callback) {
if (!options.realpath) {
return callback(null, path3.resolve(file));
}
options.fs.realpath(file, callback);
}
function acquireLock(file, options, callback) {
const lockfilePath = getLockFile(file, options);
options.fs.mkdir(lockfilePath, (err) => {
if (!err) {
return mtimePrecision.probe(lockfilePath, options.fs, (err2, mtime, mtimePrecision2) => {
if (err2) {
options.fs.rmdir(lockfilePath, () => {
});
return callback(err2);
}
callback(null, mtime, mtimePrecision2);
});
}
if (err.code !== "EEXIST") {
return callback(err);
}
if (options.stale <= 0) {
return callback(Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED", file }));
}
options.fs.stat(lockfilePath, (err2, stat) => {
if (err2) {
if (err2.code === "ENOENT") {
return acquireLock(file, { ...options, stale: 0 }, callback);
}
return callback(err2);
}
if (!isLockStale(stat, options)) {
return callback(Object.assign(new Error("Lock file is already being held"), { code: "ELOCKED", file }));
}
removeLock(file, options, (err3) => {
if (err3) {
return callback(err3);
}
acquireLock(file, { ...options, stale: 0 }, callback);
});
});
});
}
function isLockStale(stat, options) {
return stat.mtime.getTime() < Date.now() - options.stale;
}
function removeLock(file, options, callback) {
options.fs.rmdir(getLockFile(file, options), (err) => {
if (err && err.code !== "ENOENT") {
return callback(err);
}
callback();
});
}
function updateLock(file, options) {
const lock3 = locks[file];
if (lock3.updateTimeout) {
return;
}
lock3.updateDelay = lock3.updateDelay || options.update;
lock3.updateTimeout = setTimeout(() => {
lock3.updateTimeout = null;
options.fs.stat(lock3.lockfilePath, (err, stat) => {
const isOverThreshold = lock3.lastUpdate + options.stale < Date.now();
if (err) {
if (err.code === "ENOENT" || isOverThreshold) {
return setLockAsCompromised(file, lock3, Object.assign(err, { code: "ECOMPROMISED" }));
}
lock3.updateDelay = 1e3;
return updateLock(file, options);
}
const isMtimeOurs = lock3.mtime.getTime() === stat.mtime.getTime();
if (!isMtimeOurs) {
return setLockAsCompromised(
file,
lock3,
Object.assign(
new Error("Unable to update lock within the stale threshold"),
{ code: "ECOMPROMISED" }
)
);
}
const mtime = mtimePrecision.getMtime(lock3.mtimePrecision);
options.fs.utimes(lock3.lockfilePath, mtime, mtime, (err2) => {
const isOverThreshold2 = lock3.lastUpdate + options.stale < Date.now();
if (lock3.released) {
return;
}
if (err2) {
if (err2.code === "ENOENT" || isOverThreshold2) {
return setLockAsCompromised(file, lock3, Object.assign(err2, { code: "ECOMPROMISED" }));
}
lock3.updateDelay = 1e3;
return updateLock(file, options);
}
lock3.mtime = mtime;
lock3.lastUpdate = Date.now();
lock3.updateDelay = null;
updateLock(file, options);
});
});
}, lock3.updateDelay);
if (lock3.updateTimeout.unref) {
lock3.updateTimeout.unref();
}
}
function setLockAsCompromised(file, lock3, err) {
lock3.released = true;
if (lock3.updateTimeout) {
clearTimeout(lock3.updateTimeout);
}
if (locks[file] === lock3) {
delete locks[file];
}
lock3.options.onCompromised(err);
}
function lock2(file, options, callback) {
options = {
stale: 1e4,
update: null,
realpath: true,
retries: 0,
fs: fs3,
onCompromised: (err) => {
throw err;
},
...options
};
options.retries = options.retries || 0;
options.retries = typeof options.retries === "number" ? { retries: options.retries } : options.retries;
options.stale = Math.max(options.stale || 0, 2e3);
options.update = options.update == null ? options.stale / 2 : options.update || 0;
options.update = Math.max(Math.min(options.update, options.stale / 2), 1e3);
resolveCanonicalPath(file, options, (err, file2) => {
if (err) {
return callback(err);
}
const operation = retry.operation(options.retries);
operation.attempt(() => {
acquireLock(file2, options, (err2, mtime, mtimePrecision2) => {
if (operation.retry(err2)) {
return;
}
if (err2) {
return callback(operation.mainError());
}
const lock3 = locks[file2] = {
lockfilePath: getLockFile(file2, options),
mtime,
mtimePrecision: mtimePrecision2,
options,
lastUpdate: Date.now()
};
updateLock(file2, options);
callback(null, (releasedCallback) => {
if (lock3.released) {
return releasedCallback && releasedCallback(Object.assign(new Error("Lock is already released"), { code: "ERELEASED" }));
}
unlock2(file2, { ...options, realpath: false }, releasedCallback);
});
});
});
});
}
function unlock2(file, options, callback) {
options = {
fs: fs3,
realpath: true,
...options
};
resolveCanonicalPath(file, options, (err, file2) => {
if (err) {
return callback(err);
}
const lock3 = locks[file2];
if (!lock3) {
return callback(Object.assign(new Error("Lock is not acquired/owned by you"), { code: "ENOTACQUIRED" }));
}
lock3.updateTimeout && clearTimeout(lock3.updateTimeout);
lock3.released = true;
delete locks[file2];
removeLock(file2, options, callback);
});
}
function check2(file, options, callback) {
options = {
stale: 1e4,
realpath: true,
fs: fs3,
...options
};
options.stale = Math.max(options.stale || 0, 2e3);
resolveCanonicalPath(file, options, (err, file2) => {
if (err) {
return callback(err);
}
options.fs.stat(getLockFile(file2, options), (err2, stat) => {
if (err2) {
return err2.code === "ENOENT" ? callback(null, false) : callback(err2);
}
return callback(null, !isLockStale(stat, options));
});
});
}
function getLocks() {
return locks;
}
onExit(() => {
for (const file in locks) {
const options = locks[file].options;
try {
options.fs.rmdirSync(getLockFile(file, options));
} catch (e) {
}