Files
Shifted/node_modules/@prisma/fetch-engine/dist/chunk-J5S3UHYB.js
2026-02-10 01:14:19 +00:00

2589 lines
83 KiB
JavaScript

"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 __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);
var chunk_J5S3UHYB_exports = {};
__export(chunk_J5S3UHYB_exports, {
download: () => download,
getBinaryName: () => getBinaryName,
getVersion: () => getVersion,
maybeCopyToTmp: () => maybeCopyToTmp,
plusX: () => plusX,
vercelPkgPathRegex: () => vercelPkgPathRegex
});
module.exports = __toCommonJS(chunk_J5S3UHYB_exports);
var import_chunk_MWVY55RY = require("./chunk-MWVY55RY.js");
var import_chunk_7JLQJWOR = require("./chunk-7JLQJWOR.js");
var import_chunk_3VVCXIQ5 = require("./chunk-3VVCXIQ5.js");
var import_chunk_CY52DY2B = require("./chunk-CY52DY2B.js");
var import_chunk_LONQL55G = require("./chunk-LONQL55G.js");
var import_chunk_QFA3XBMW = require("./chunk-QFA3XBMW.js");
var import_chunk_FKGWOTGU = require("./chunk-FKGWOTGU.js");
var import_chunk_QGM4M3NI = require("./chunk-QGM4M3NI.js");
var import_node_fs = __toESM(require("node:fs"));
var import_node_path = __toESM(require("node:path"));
var import_node_util = require("node:util");
var import_debug = __toESM(require("@prisma/debug"));
var import_get_platform = require("@prisma/get-platform");
var import_node_buffer = require("node:buffer");
var import_node_path2 = __toESM(require("node:path"));
var import_node_child_process = __toESM(require("node:child_process"));
var import_node_process = __toESM(require("node:process"));
var import_node_process2 = __toESM(require("node:process"));
var import_node_path3 = __toESM(require("node:path"));
var import_node_url = require("node:url");
var import_node_process3 = __toESM(require("node:process"));
var import_node_os = require("node:os");
var import_node_os2 = require("node:os");
var import_node_os3 = __toESM(require("node:os"));
var import_node_fs2 = require("node:fs");
var import_node_child_process2 = require("node:child_process");
var import_node_fs3 = require("node:fs");
var import_promises = require("node:timers/promises");
var import_node_buffer2 = require("node:buffer");
var import_node_child_process3 = require("node:child_process");
var import_node_util2 = require("node:util");
var import_node_process4 = __toESM(require("node:process"));
var require_windows = (0, import_chunk_QGM4M3NI.__commonJS)({
"../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/windows.js"(exports, module2) {
"use strict";
module2.exports = isexe;
isexe.sync = sync;
var fs2 = (0, import_chunk_QGM4M3NI.__require)("fs");
function checkPathExt(path4, options) {
var pathext = options.pathExt !== void 0 ? options.pathExt : process.env.PATHEXT;
if (!pathext) {
return true;
}
pathext = pathext.split(";");
if (pathext.indexOf("") !== -1) {
return true;
}
for (var i = 0; i < pathext.length; i++) {
var p = pathext[i].toLowerCase();
if (p && path4.substr(-p.length).toLowerCase() === p) {
return true;
}
}
return false;
}
function checkStat(stat, path4, options) {
if (!stat.isSymbolicLink() && !stat.isFile()) {
return false;
}
return checkPathExt(path4, options);
}
function isexe(path4, options, cb) {
fs2.stat(path4, function(er, stat) {
cb(er, er ? false : checkStat(stat, path4, options));
});
}
function sync(path4, options) {
return checkStat(fs2.statSync(path4), path4, options);
}
}
});
var require_mode = (0, import_chunk_QGM4M3NI.__commonJS)({
"../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/mode.js"(exports, module2) {
"use strict";
module2.exports = isexe;
isexe.sync = sync;
var fs2 = (0, import_chunk_QGM4M3NI.__require)("fs");
function isexe(path4, options, cb) {
fs2.stat(path4, function(er, stat) {
cb(er, er ? false : checkStat(stat, options));
});
}
function sync(path4, options) {
return checkStat(fs2.statSync(path4), options);
}
function checkStat(stat, options) {
return stat.isFile() && checkMode(stat, options);
}
function checkMode(stat, options) {
var mod = stat.mode;
var uid = stat.uid;
var gid = stat.gid;
var myUid = options.uid !== void 0 ? options.uid : process.getuid && process.getuid();
var myGid = options.gid !== void 0 ? options.gid : process.getgid && process.getgid();
var u = parseInt("100", 8);
var g = parseInt("010", 8);
var o = parseInt("001", 8);
var ug = u | g;
var ret = mod & o || mod & g && gid === myGid || mod & u && uid === myUid || mod & ug && myUid === 0;
return ret;
}
}
});
var require_isexe = (0, import_chunk_QGM4M3NI.__commonJS)({
"../../node_modules/.pnpm/isexe@2.0.0/node_modules/isexe/index.js"(exports, module2) {
"use strict";
var fs2 = (0, import_chunk_QGM4M3NI.__require)("fs");
var core;
if (process.platform === "win32" || global.TESTING_WINDOWS) {
core = require_windows();
} else {
core = require_mode();
}
module2.exports = isexe;
isexe.sync = sync;
function isexe(path4, options, cb) {
if (typeof options === "function") {
cb = options;
options = {};
}
if (!cb) {
if (typeof Promise !== "function") {
throw new TypeError("callback not provided");
}
return new Promise(function(resolve, reject) {
isexe(path4, options || {}, function(er, is) {
if (er) {
reject(er);
} else {
resolve(is);
}
});
});
}
core(path4, options || {}, function(er, is) {
if (er) {
if (er.code === "EACCES" || options && options.ignoreErrors) {
er = null;
is = false;
}
}
cb(er, is);
});
}
function sync(path4, options) {
try {
return core.sync(path4, options || {});
} catch (er) {
if (options && options.ignoreErrors || er.code === "EACCES") {
return false;
} else {
throw er;
}
}
}
}
});
var require_which = (0, import_chunk_QGM4M3NI.__commonJS)({
"../../node_modules/.pnpm/which@2.0.2/node_modules/which/which.js"(exports, module2) {
"use strict";
var isWindows = process.platform === "win32" || process.env.OSTYPE === "cygwin" || process.env.OSTYPE === "msys";
var path4 = (0, import_chunk_QGM4M3NI.__require)("path");
var COLON = isWindows ? ";" : ":";
var isexe = require_isexe();
var getNotFoundError = (cmd) => Object.assign(new Error(`not found: ${cmd}`), { code: "ENOENT" });
var getPathInfo = (cmd, opt) => {
const colon = opt.colon || COLON;
const pathEnv = cmd.match(/\//) || isWindows && cmd.match(/\\/) ? [""] : [
// windows always checks the cwd first
...isWindows ? [process.cwd()] : [],
...(opt.path || process.env.PATH || /* istanbul ignore next: very unusual */
"").split(colon)
];
const pathExtExe = isWindows ? opt.pathExt || process.env.PATHEXT || ".EXE;.CMD;.BAT;.COM" : "";
const pathExt = isWindows ? pathExtExe.split(colon) : [""];
if (isWindows) {
if (cmd.indexOf(".") !== -1 && pathExt[0] !== "")
pathExt.unshift("");
}
return {
pathEnv,
pathExt,
pathExtExe
};
};
var which = (cmd, opt, cb) => {
if (typeof opt === "function") {
cb = opt;
opt = {};
}
if (!opt)
opt = {};
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
const found = [];
const step = (i) => new Promise((resolve, reject) => {
if (i === pathEnv.length)
return opt.all && found.length ? resolve(found) : reject(getNotFoundError(cmd));
const ppRaw = pathEnv[i];
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
const pCmd = path4.join(pathPart, cmd);
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
resolve(subStep(p, i, 0));
});
const subStep = (p, i, ii) => new Promise((resolve, reject) => {
if (ii === pathExt.length)
return resolve(step(i + 1));
const ext = pathExt[ii];
isexe(p + ext, { pathExt: pathExtExe }, (er, is) => {
if (!er && is) {
if (opt.all)
found.push(p + ext);
else
return resolve(p + ext);
}
return resolve(subStep(p, i, ii + 1));
});
});
return cb ? step(0).then((res) => cb(null, res), cb) : step(0);
};
var whichSync = (cmd, opt) => {
opt = opt || {};
const { pathEnv, pathExt, pathExtExe } = getPathInfo(cmd, opt);
const found = [];
for (let i = 0; i < pathEnv.length; i++) {
const ppRaw = pathEnv[i];
const pathPart = /^".*"$/.test(ppRaw) ? ppRaw.slice(1, -1) : ppRaw;
const pCmd = path4.join(pathPart, cmd);
const p = !pathPart && /^\.[\\\/]/.test(cmd) ? cmd.slice(0, 2) + pCmd : pCmd;
for (let j = 0; j < pathExt.length; j++) {
const cur = p + pathExt[j];
try {
const is = isexe.sync(cur, { pathExt: pathExtExe });
if (is) {
if (opt.all)
found.push(cur);
else
return cur;
}
} catch (ex) {
}
}
}
if (opt.all && found.length)
return found;
if (opt.nothrow)
return null;
throw getNotFoundError(cmd);
};
module2.exports = which;
which.sync = whichSync;
}
});
var require_path_key = (0, import_chunk_QGM4M3NI.__commonJS)({
"../../node_modules/.pnpm/path-key@3.1.1/node_modules/path-key/index.js"(exports, module2) {
"use strict";
var pathKey2 = (options = {}) => {
const environment = options.env || process.env;
const platform = options.platform || process.platform;
if (platform !== "win32") {
return "PATH";
}
return Object.keys(environment).reverse().find((key) => key.toUpperCase() === "PATH") || "Path";
};
module2.exports = pathKey2;
module2.exports.default = pathKey2;
}
});
var require_resolveCommand = (0, import_chunk_QGM4M3NI.__commonJS)({
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/resolveCommand.js"(exports, module2) {
"use strict";
var path4 = (0, import_chunk_QGM4M3NI.__require)("path");
var which = require_which();
var getPathKey = require_path_key();
function resolveCommandAttempt(parsed, withoutPathExt) {
const env = parsed.options.env || process.env;
const cwd = process.cwd();
const hasCustomCwd = parsed.options.cwd != null;
const shouldSwitchCwd = hasCustomCwd && process.chdir !== void 0 && !process.chdir.disabled;
if (shouldSwitchCwd) {
try {
process.chdir(parsed.options.cwd);
} catch (err) {
}
}
let resolved;
try {
resolved = which.sync(parsed.command, {
path: env[getPathKey({ env })],
pathExt: withoutPathExt ? path4.delimiter : void 0
});
} catch (e) {
} finally {
if (shouldSwitchCwd) {
process.chdir(cwd);
}
}
if (resolved) {
resolved = path4.resolve(hasCustomCwd ? parsed.options.cwd : "", resolved);
}
return resolved;
}
function resolveCommand(parsed) {
return resolveCommandAttempt(parsed) || resolveCommandAttempt(parsed, true);
}
module2.exports = resolveCommand;
}
});
var require_escape = (0, import_chunk_QGM4M3NI.__commonJS)({
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/escape.js"(exports, module2) {
"use strict";
var metaCharsRegExp = /([()\][%!^"`<>&|;, *?])/g;
function escapeCommand(arg) {
arg = arg.replace(metaCharsRegExp, "^$1");
return arg;
}
function escapeArgument(arg, doubleEscapeMetaChars) {
arg = `${arg}`;
arg = arg.replace(/(?=(\\+?)?)\1"/g, '$1$1\\"');
arg = arg.replace(/(?=(\\+?)?)\1$/, "$1$1");
arg = `"${arg}"`;
arg = arg.replace(metaCharsRegExp, "^$1");
if (doubleEscapeMetaChars) {
arg = arg.replace(metaCharsRegExp, "^$1");
}
return arg;
}
module2.exports.command = escapeCommand;
module2.exports.argument = escapeArgument;
}
});
var require_shebang_regex = (0, import_chunk_QGM4M3NI.__commonJS)({
"../../node_modules/.pnpm/shebang-regex@3.0.0/node_modules/shebang-regex/index.js"(exports, module2) {
"use strict";
module2.exports = /^#!(.*)/;
}
});
var require_shebang_command = (0, import_chunk_QGM4M3NI.__commonJS)({
"../../node_modules/.pnpm/shebang-command@2.0.0/node_modules/shebang-command/index.js"(exports, module2) {
"use strict";
var shebangRegex = require_shebang_regex();
module2.exports = (string = "") => {
const match = string.match(shebangRegex);
if (!match) {
return null;
}
const [path4, argument] = match[0].replace(/#! ?/, "").split(" ");
const binary = path4.split("/").pop();
if (binary === "env") {
return argument;
}
return argument ? `${binary} ${argument}` : binary;
};
}
});
var require_readShebang = (0, import_chunk_QGM4M3NI.__commonJS)({
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/util/readShebang.js"(exports, module2) {
"use strict";
var fs2 = (0, import_chunk_QGM4M3NI.__require)("fs");
var shebangCommand = require_shebang_command();
function readShebang(command) {
const size = 150;
const buffer = Buffer.alloc(size);
let fd;
try {
fd = fs2.openSync(command, "r");
fs2.readSync(fd, buffer, 0, size, 0);
fs2.closeSync(fd);
} catch (e) {
}
return shebangCommand(buffer.toString());
}
module2.exports = readShebang;
}
});
var require_parse = (0, import_chunk_QGM4M3NI.__commonJS)({
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/parse.js"(exports, module2) {
"use strict";
var path4 = (0, import_chunk_QGM4M3NI.__require)("path");
var resolveCommand = require_resolveCommand();
var escape = require_escape();
var readShebang = require_readShebang();
var isWin = process.platform === "win32";
var isExecutableRegExp = /\.(?:com|exe)$/i;
var isCmdShimRegExp = /node_modules[\\/].bin[\\/][^\\/]+\.cmd$/i;
function detectShebang(parsed) {
parsed.file = resolveCommand(parsed);
const shebang = parsed.file && readShebang(parsed.file);
if (shebang) {
parsed.args.unshift(parsed.file);
parsed.command = shebang;
return resolveCommand(parsed);
}
return parsed.file;
}
function parseNonShell(parsed) {
if (!isWin) {
return parsed;
}
const commandFile = detectShebang(parsed);
const needsShell = !isExecutableRegExp.test(commandFile);
if (parsed.options.forceShell || needsShell) {
const needsDoubleEscapeMetaChars = isCmdShimRegExp.test(commandFile);
parsed.command = path4.normalize(parsed.command);
parsed.command = escape.command(parsed.command);
parsed.args = parsed.args.map((arg) => escape.argument(arg, needsDoubleEscapeMetaChars));
const shellCommand = [parsed.command].concat(parsed.args).join(" ");
parsed.args = ["/d", "/s", "/c", `"${shellCommand}"`];
parsed.command = process.env.comspec || "cmd.exe";
parsed.options.windowsVerbatimArguments = true;
}
return parsed;
}
function parse(command, args, options) {
if (args && !Array.isArray(args)) {
options = args;
args = null;
}
args = args ? args.slice(0) : [];
options = Object.assign({}, options);
const parsed = {
command,
args,
options,
file: void 0,
original: {
command,
args
}
};
return options.shell ? parsed : parseNonShell(parsed);
}
module2.exports = parse;
}
});
var require_enoent = (0, import_chunk_QGM4M3NI.__commonJS)({
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/lib/enoent.js"(exports, module2) {
"use strict";
var isWin = process.platform === "win32";
function notFoundError(original, syscall) {
return Object.assign(new Error(`${syscall} ${original.command} ENOENT`), {
code: "ENOENT",
errno: "ENOENT",
syscall: `${syscall} ${original.command}`,
path: original.command,
spawnargs: original.args
});
}
function hookChildProcess(cp, parsed) {
if (!isWin) {
return;
}
const originalEmit = cp.emit;
cp.emit = function(name, arg1) {
if (name === "exit") {
const err = verifyENOENT(arg1, parsed);
if (err) {
return originalEmit.call(cp, "error", err);
}
}
return originalEmit.apply(cp, arguments);
};
}
function verifyENOENT(status, parsed) {
if (isWin && status === 1 && !parsed.file) {
return notFoundError(parsed.original, "spawn");
}
return null;
}
function verifyENOENTSync(status, parsed) {
if (isWin && status === 1 && !parsed.file) {
return notFoundError(parsed.original, "spawnSync");
}
return null;
}
module2.exports = {
hookChildProcess,
verifyENOENT,
verifyENOENTSync,
notFoundError
};
}
});
var require_cross_spawn = (0, import_chunk_QGM4M3NI.__commonJS)({
"../../node_modules/.pnpm/cross-spawn@7.0.6/node_modules/cross-spawn/index.js"(exports, module2) {
"use strict";
var cp = (0, import_chunk_QGM4M3NI.__require)("child_process");
var parse = require_parse();
var enoent = require_enoent();
function spawn(command, args, options) {
const parsed = parse(command, args, options);
const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
enoent.hookChildProcess(spawned, parsed);
return spawned;
}
function spawnSync(command, args, options) {
const parsed = parse(command, args, options);
const result = cp.spawnSync(parsed.command, parsed.args, parsed.options);
result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
return result;
}
module2.exports = spawn;
module2.exports.spawn = spawn;
module2.exports.sync = spawnSync;
module2.exports._parse = parse;
module2.exports._enoent = enoent;
}
});
var require_merge_stream = (0, import_chunk_QGM4M3NI.__commonJS)({
"../../node_modules/.pnpm/merge-stream@2.0.0/node_modules/merge-stream/index.js"(exports, module2) {
"use strict";
var { PassThrough } = (0, import_chunk_QGM4M3NI.__require)("stream");
module2.exports = function() {
var sources = [];
var output = new PassThrough({ objectMode: true });
output.setMaxListeners(0);
output.add = add;
output.isEmpty = isEmpty;
output.on("unpipe", remove);
Array.prototype.slice.call(arguments).forEach(add);
return output;
function add(source) {
if (Array.isArray(source)) {
source.forEach(add);
return this;
}
sources.push(source);
source.once("end", remove.bind(null, source));
source.once("error", output.emit.bind(output, "error"));
source.pipe(output, { end: false });
return this;
}
function isEmpty() {
return sources.length == 0;
}
function remove(source) {
sources = sources.filter(function(it) {
return it !== source;
});
if (!sources.length && output.readable) {
output.end();
}
}
};
}
});
var require_package = (0, import_chunk_QGM4M3NI.__commonJS)({
"package.json"(exports, module2) {
module2.exports = {
name: "@prisma/fetch-engine",
version: "6.19.2",
description: "This package is intended for Prisma's internal use",
main: "dist/index.js",
types: "dist/index.d.ts",
license: "Apache-2.0",
author: "Tim Suchanek <suchanek@prisma.io>",
homepage: "https://www.prisma.io",
repository: {
type: "git",
url: "https://github.com/prisma/prisma.git",
directory: "packages/fetch-engine"
},
bugs: "https://github.com/prisma/prisma/issues",
enginesOverride: {},
devDependencies: {
"@types/node": "18.19.76",
"@types/progress": "2.0.7",
del: "6.1.1",
execa: "8.0.1",
"find-cache-dir": "5.0.0",
"fs-extra": "11.3.0",
hasha: "5.2.2",
"http-proxy-agent": "7.0.2",
"https-proxy-agent": "7.0.6",
kleur: "4.1.5",
"node-fetch": "3.3.2",
"p-filter": "4.1.0",
"p-map": "4.0.0",
"p-retry": "4.6.2",
progress: "2.0.3",
"temp-dir": "2.0.0",
tempy: "1.0.1",
"timeout-signal": "2.0.0",
typescript: "5.4.5"
},
dependencies: {
"@prisma/debug": "workspace:*",
"@prisma/engines-version": "7.1.1-3.c2990dca591cba766e3b7ef5d9e8a84796e47ab7",
"@prisma/get-platform": "workspace:*"
},
scripts: {
dev: "DEV=true tsx helpers/build.ts",
build: "tsx helpers/build.ts",
test: "vitest run",
prepublishOnly: "pnpm run build"
},
files: [
"README.md",
"dist"
],
sideEffects: false
};
}
});
var import_cross_spawn = (0, import_chunk_QGM4M3NI.__toESM)(require_cross_spawn(), 1);
function stripFinalNewline(input) {
const LF = typeof input === "string" ? "\n" : "\n".charCodeAt();
const CR = typeof input === "string" ? "\r" : "\r".charCodeAt();
if (input[input.length - 1] === LF) {
input = input.slice(0, -1);
}
if (input[input.length - 1] === CR) {
input = input.slice(0, -1);
}
return input;
}
function pathKey(options = {}) {
const {
env = process.env,
platform = process.platform
} = options;
if (platform !== "win32") {
return "PATH";
}
return Object.keys(env).reverse().find((key) => key.toUpperCase() === "PATH") || "Path";
}
var npmRunPath = ({
cwd = import_node_process2.default.cwd(),
path: pathOption = import_node_process2.default.env[pathKey()],
preferLocal = true,
execPath = import_node_process2.default.execPath,
addExecPath = true
} = {}) => {
const cwdString = cwd instanceof URL ? (0, import_node_url.fileURLToPath)(cwd) : cwd;
const cwdPath = import_node_path3.default.resolve(cwdString);
const result = [];
if (preferLocal) {
applyPreferLocal(result, cwdPath);
}
if (addExecPath) {
applyExecPath(result, execPath, cwdPath);
}
return [...result, pathOption].join(import_node_path3.default.delimiter);
};
var applyPreferLocal = (result, cwdPath) => {
let previous;
while (previous !== cwdPath) {
result.push(import_node_path3.default.join(cwdPath, "node_modules/.bin"));
previous = cwdPath;
cwdPath = import_node_path3.default.resolve(cwdPath, "..");
}
};
var applyExecPath = (result, execPath, cwdPath) => {
const execPathString = execPath instanceof URL ? (0, import_node_url.fileURLToPath)(execPath) : execPath;
result.push(import_node_path3.default.resolve(cwdPath, execPathString, ".."));
};
var npmRunPathEnv = ({ env = import_node_process2.default.env, ...options } = {}) => {
env = { ...env };
const pathName = pathKey({ env });
options.path = env[pathName];
env[pathName] = npmRunPath(options);
return env;
};
var copyProperty = (to, from, property, ignoreNonConfigurable) => {
if (property === "length" || property === "prototype") {
return;
}
if (property === "arguments" || property === "caller") {
return;
}
const toDescriptor = Object.getOwnPropertyDescriptor(to, property);
const fromDescriptor = Object.getOwnPropertyDescriptor(from, property);
if (!canCopyProperty(toDescriptor, fromDescriptor) && ignoreNonConfigurable) {
return;
}
Object.defineProperty(to, property, fromDescriptor);
};
var canCopyProperty = function(toDescriptor, fromDescriptor) {
return toDescriptor === void 0 || toDescriptor.configurable || toDescriptor.writable === fromDescriptor.writable && toDescriptor.enumerable === fromDescriptor.enumerable && toDescriptor.configurable === fromDescriptor.configurable && (toDescriptor.writable || toDescriptor.value === fromDescriptor.value);
};
var changePrototype = (to, from) => {
const fromPrototype = Object.getPrototypeOf(from);
if (fromPrototype === Object.getPrototypeOf(to)) {
return;
}
Object.setPrototypeOf(to, fromPrototype);
};
var wrappedToString = (withName, fromBody) => `/* Wrapped ${withName}*/
${fromBody}`;
var toStringDescriptor = Object.getOwnPropertyDescriptor(Function.prototype, "toString");
var toStringName = Object.getOwnPropertyDescriptor(Function.prototype.toString, "name");
var changeToString = (to, from, name) => {
const withName = name === "" ? "" : `with ${name.trim()}() `;
const newToString = wrappedToString.bind(null, withName, from.toString());
Object.defineProperty(newToString, "name", toStringName);
Object.defineProperty(to, "toString", { ...toStringDescriptor, value: newToString });
};
function mimicFunction(to, from, { ignoreNonConfigurable = false } = {}) {
const { name } = to;
for (const property of Reflect.ownKeys(from)) {
copyProperty(to, from, property, ignoreNonConfigurable);
}
changePrototype(to, from);
changeToString(to, from, name);
return to;
}
var calledFunctions = /* @__PURE__ */ new WeakMap();
var onetime = (function_, options = {}) => {
if (typeof function_ !== "function") {
throw new TypeError("Expected a function");
}
let returnValue;
let callCount = 0;
const functionName = function_.displayName || function_.name || "<anonymous>";
const onetime2 = function(...arguments_) {
calledFunctions.set(onetime2, ++callCount);
if (callCount === 1) {
returnValue = function_.apply(this, arguments_);
function_ = null;
} else if (options.throw === true) {
throw new Error(`Function \`${functionName}\` can only be called once`);
}
return returnValue;
};
mimicFunction(onetime2, function_);
calledFunctions.set(onetime2, callCount);
return onetime2;
};
onetime.callCount = (function_) => {
if (!calledFunctions.has(function_)) {
throw new Error(`The given function \`${function_.name}\` is not wrapped by the \`onetime\` package`);
}
return calledFunctions.get(function_);
};
var onetime_default = onetime;
var getRealtimeSignals = () => {
const length = SIGRTMAX - SIGRTMIN + 1;
return Array.from({ length }, getRealtimeSignal);
};
var getRealtimeSignal = (value, index) => ({
name: `SIGRT${index + 1}`,
number: SIGRTMIN + index,
action: "terminate",
description: "Application-specific signal (realtime)",
standard: "posix"
});
var SIGRTMIN = 34;
var SIGRTMAX = 64;
var SIGNALS = [
{
name: "SIGHUP",
number: 1,
action: "terminate",
description: "Terminal closed",
standard: "posix"
},
{
name: "SIGINT",
number: 2,
action: "terminate",
description: "User interruption with CTRL-C",
standard: "ansi"
},
{
name: "SIGQUIT",
number: 3,
action: "core",
description: "User interruption with CTRL-\\",
standard: "posix"
},
{
name: "SIGILL",
number: 4,
action: "core",
description: "Invalid machine instruction",
standard: "ansi"
},
{
name: "SIGTRAP",
number: 5,
action: "core",
description: "Debugger breakpoint",
standard: "posix"
},
{
name: "SIGABRT",
number: 6,
action: "core",
description: "Aborted",
standard: "ansi"
},
{
name: "SIGIOT",
number: 6,
action: "core",
description: "Aborted",
standard: "bsd"
},
{
name: "SIGBUS",
number: 7,
action: "core",
description: "Bus error due to misaligned, non-existing address or paging error",
standard: "bsd"
},
{
name: "SIGEMT",
number: 7,
action: "terminate",
description: "Command should be emulated but is not implemented",
standard: "other"
},
{
name: "SIGFPE",
number: 8,
action: "core",
description: "Floating point arithmetic error",
standard: "ansi"
},
{
name: "SIGKILL",
number: 9,
action: "terminate",
description: "Forced termination",
standard: "posix",
forced: true
},
{
name: "SIGUSR1",
number: 10,
action: "terminate",
description: "Application-specific signal",
standard: "posix"
},
{
name: "SIGSEGV",
number: 11,
action: "core",
description: "Segmentation fault",
standard: "ansi"
},
{
name: "SIGUSR2",
number: 12,
action: "terminate",
description: "Application-specific signal",
standard: "posix"
},
{
name: "SIGPIPE",
number: 13,
action: "terminate",
description: "Broken pipe or socket",
standard: "posix"
},
{
name: "SIGALRM",
number: 14,
action: "terminate",
description: "Timeout or timer",
standard: "posix"
},
{
name: "SIGTERM",
number: 15,
action: "terminate",
description: "Termination",
standard: "ansi"
},
{
name: "SIGSTKFLT",
number: 16,
action: "terminate",
description: "Stack is empty or overflowed",
standard: "other"
},
{
name: "SIGCHLD",
number: 17,
action: "ignore",
description: "Child process terminated, paused or unpaused",
standard: "posix"
},
{
name: "SIGCLD",
number: 17,
action: "ignore",
description: "Child process terminated, paused or unpaused",
standard: "other"
},
{
name: "SIGCONT",
number: 18,
action: "unpause",
description: "Unpaused",
standard: "posix",
forced: true
},
{
name: "SIGSTOP",
number: 19,
action: "pause",
description: "Paused",
standard: "posix",
forced: true
},
{
name: "SIGTSTP",
number: 20,
action: "pause",
description: 'Paused using CTRL-Z or "suspend"',
standard: "posix"
},
{
name: "SIGTTIN",
number: 21,
action: "pause",
description: "Background process cannot read terminal input",
standard: "posix"
},
{
name: "SIGBREAK",
number: 21,
action: "terminate",
description: "User interruption with CTRL-BREAK",
standard: "other"
},
{
name: "SIGTTOU",
number: 22,
action: "pause",
description: "Background process cannot write to terminal output",
standard: "posix"
},
{
name: "SIGURG",
number: 23,
action: "ignore",
description: "Socket received out-of-band data",
standard: "bsd"
},
{
name: "SIGXCPU",
number: 24,
action: "core",
description: "Process timed out",
standard: "bsd"
},
{
name: "SIGXFSZ",
number: 25,
action: "core",
description: "File too big",
standard: "bsd"
},
{
name: "SIGVTALRM",
number: 26,
action: "terminate",
description: "Timeout or timer",
standard: "bsd"
},
{
name: "SIGPROF",
number: 27,
action: "terminate",
description: "Timeout or timer",
standard: "bsd"
},
{
name: "SIGWINCH",
number: 28,
action: "ignore",
description: "Terminal window size changed",
standard: "bsd"
},
{
name: "SIGIO",
number: 29,
action: "terminate",
description: "I/O is available",
standard: "other"
},
{
name: "SIGPOLL",
number: 29,
action: "terminate",
description: "Watched event",
standard: "other"
},
{
name: "SIGINFO",
number: 29,
action: "ignore",
description: "Request for process information",
standard: "other"
},
{
name: "SIGPWR",
number: 30,
action: "terminate",
description: "Device running out of power",
standard: "systemv"
},
{
name: "SIGSYS",
number: 31,
action: "core",
description: "Invalid system call",
standard: "other"
},
{
name: "SIGUNUSED",
number: 31,
action: "terminate",
description: "Invalid system call",
standard: "other"
}
];
var getSignals = () => {
const realtimeSignals = getRealtimeSignals();
const signals2 = [...SIGNALS, ...realtimeSignals].map(normalizeSignal);
return signals2;
};
var normalizeSignal = ({
name,
number: defaultNumber,
description,
action,
forced = false,
standard
}) => {
const {
signals: { [name]: constantSignal }
} = import_node_os2.constants;
const supported = constantSignal !== void 0;
const number = supported ? constantSignal : defaultNumber;
return { name, number, description, supported, action, forced, standard };
};
var getSignalsByName = () => {
const signals2 = getSignals();
return Object.fromEntries(signals2.map(getSignalByName));
};
var getSignalByName = ({
name,
number,
description,
supported,
action,
forced,
standard
}) => [name, { name, number, description, supported, action, forced, standard }];
var signalsByName = getSignalsByName();
var getSignalsByNumber = () => {
const signals2 = getSignals();
const length = SIGRTMAX + 1;
const signalsA = Array.from(
{ length },
(value, number) => getSignalByNumber(number, signals2)
);
return Object.assign({}, ...signalsA);
};
var getSignalByNumber = (number, signals2) => {
const signal = findSignalByNumber(number, signals2);
if (signal === void 0) {
return {};
}
const { name, description, supported, action, forced, standard } = signal;
return {
[number]: {
name,
number,
description,
supported,
action,
forced,
standard
}
};
};
var findSignalByNumber = (number, signals2) => {
const signal = signals2.find(({ name }) => import_node_os.constants.signals[name] === number);
if (signal !== void 0) {
return signal;
}
return signals2.find((signalA) => signalA.number === number);
};
var signalsByNumber = getSignalsByNumber();
var getErrorPrefix = ({ timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled }) => {
if (timedOut) {
return `timed out after ${timeout} milliseconds`;
}
if (isCanceled) {
return "was canceled";
}
if (errorCode !== void 0) {
return `failed with ${errorCode}`;
}
if (signal !== void 0) {
return `was killed with ${signal} (${signalDescription})`;
}
if (exitCode !== void 0) {
return `failed with exit code ${exitCode}`;
}
return "failed";
};
var makeError = ({
stdout,
stderr,
all,
error,
signal,
exitCode,
command,
escapedCommand,
timedOut,
isCanceled,
killed,
parsed: { options: { timeout, cwd = import_node_process3.default.cwd() } }
}) => {
exitCode = exitCode === null ? void 0 : exitCode;
signal = signal === null ? void 0 : signal;
const signalDescription = signal === void 0 ? void 0 : signalsByName[signal].description;
const errorCode = error && error.code;
const prefix = getErrorPrefix({ timedOut, timeout, errorCode, signal, signalDescription, exitCode, isCanceled });
const execaMessage = `Command ${prefix}: ${command}`;
const isError = Object.prototype.toString.call(error) === "[object Error]";
const shortMessage = isError ? `${execaMessage}
${error.message}` : execaMessage;
const message = [shortMessage, stderr, stdout].filter(Boolean).join("\n");
if (isError) {
error.originalMessage = error.message;
error.message = message;
} else {
error = new Error(message);
}
error.shortMessage = shortMessage;
error.command = command;
error.escapedCommand = escapedCommand;
error.exitCode = exitCode;
error.signal = signal;
error.signalDescription = signalDescription;
error.stdout = stdout;
error.stderr = stderr;
error.cwd = cwd;
if (all !== void 0) {
error.all = all;
}
if ("bufferedData" in error) {
delete error.bufferedData;
}
error.failed = true;
error.timedOut = Boolean(timedOut);
error.isCanceled = isCanceled;
error.killed = killed && !timedOut;
return error;
};
var aliases = ["stdin", "stdout", "stderr"];
var hasAlias = (options) => aliases.some((alias) => options[alias] !== void 0);
var normalizeStdio = (options) => {
if (!options) {
return;
}
const { stdio } = options;
if (stdio === void 0) {
return aliases.map((alias) => options[alias]);
}
if (hasAlias(options)) {
throw new Error(`It's not possible to provide \`stdio\` in combination with one of ${aliases.map((alias) => `\`${alias}\``).join(", ")}`);
}
if (typeof stdio === "string") {
return stdio;
}
if (!Array.isArray(stdio)) {
throw new TypeError(`Expected \`stdio\` to be of type \`string\` or \`Array\`, got \`${typeof stdio}\``);
}
const length = Math.max(stdio.length, aliases.length);
return Array.from({ length }, (value, index) => stdio[index]);
};
var signals = [];
signals.push("SIGHUP", "SIGINT", "SIGTERM");
if (process.platform !== "win32") {
signals.push(
"SIGALRM",
"SIGABRT",
"SIGVTALRM",
"SIGXCPU",
"SIGXFSZ",
"SIGUSR2",
"SIGTRAP",
"SIGSYS",
"SIGQUIT",
"SIGIOT"
// should detect profiler and enable/disable accordingly.
// see #21
// 'SIGPROF'
);
}
if (process.platform === "linux") {
signals.push("SIGIO", "SIGPOLL", "SIGPWR", "SIGSTKFLT");
}
var processOk = (process7) => !!process7 && typeof process7 === "object" && typeof process7.removeListener === "function" && typeof process7.emit === "function" && typeof process7.reallyExit === "function" && typeof process7.listeners === "function" && typeof process7.kill === "function" && typeof process7.pid === "number" && typeof process7.on === "function";
var kExitEmitter = Symbol.for("signal-exit emitter");
var global2 = globalThis;
var ObjectDefineProperty = Object.defineProperty.bind(Object);
var Emitter = class {
emitted = {
afterExit: false,
exit: false
};
listeners = {
afterExit: [],
exit: []
};
count = 0;
id = Math.random();
constructor() {
if (global2[kExitEmitter]) {
return global2[kExitEmitter];
}
ObjectDefineProperty(global2, kExitEmitter, {
value: this,
writable: false,
enumerable: false,
configurable: false
});
}
on(ev, fn) {
this.listeners[ev].push(fn);
}
removeListener(ev, fn) {
const list = this.listeners[ev];
const i = list.indexOf(fn);
if (i === -1) {
return;
}
if (i === 0 && list.length === 1) {
list.length = 0;
} else {
list.splice(i, 1);
}
}
emit(ev, code, signal) {
if (this.emitted[ev]) {
return false;
}
this.emitted[ev] = true;
let ret = false;
for (const fn of this.listeners[ev]) {
ret = fn(code, signal) === true || ret;
}
if (ev === "exit") {
ret = this.emit("afterExit", code, signal) || ret;
}
return ret;
}
};
var SignalExitBase = class {
};
var signalExitWrap = (handler) => {
return {
onExit(cb, opts) {
return handler.onExit(cb, opts);
},
load() {
return handler.load();
},
unload() {
return handler.unload();
}
};
};
var SignalExitFallback = class extends SignalExitBase {
onExit() {
return () => {
};
}
load() {
}
unload() {
}
};
var SignalExit = class extends SignalExitBase {
// "SIGHUP" throws an `ENOSYS` error on Windows,
// so use a supported signal instead
/* c8 ignore start */
#hupSig = process4.platform === "win32" ? "SIGINT" : "SIGHUP";
/* c8 ignore stop */
#emitter = new Emitter();
#process;
#originalProcessEmit;
#originalProcessReallyExit;
#sigListeners = {};
#loaded = false;
constructor(process7) {
super();
this.#process = process7;
this.#sigListeners = {};
for (const sig of signals) {
this.#sigListeners[sig] = () => {
const listeners = this.#process.listeners(sig);
let { count } = this.#emitter;
const p = process7;
if (typeof p.__signal_exit_emitter__ === "object" && typeof p.__signal_exit_emitter__.count === "number") {
count += p.__signal_exit_emitter__.count;
}
if (listeners.length === count) {
this.unload();
const ret = this.#emitter.emit("exit", null, sig);
const s = sig === "SIGHUP" ? this.#hupSig : sig;
if (!ret)
process7.kill(process7.pid, s);
}
};
}
this.#originalProcessReallyExit = process7.reallyExit;
this.#originalProcessEmit = process7.emit;
}
onExit(cb, opts) {
if (!processOk(this.#process)) {
return () => {
};
}
if (this.#loaded === false) {
this.load();
}
const ev = opts?.alwaysLast ? "afterExit" : "exit";
this.#emitter.on(ev, cb);
return () => {
this.#emitter.removeListener(ev, cb);
if (this.#emitter.listeners["exit"].length === 0 && this.#emitter.listeners["afterExit"].length === 0) {
this.unload();
}
};
}
load() {
if (this.#loaded) {
return;
}
this.#loaded = true;
this.#emitter.count += 1;
for (const sig of signals) {
try {
const fn = this.#sigListeners[sig];
if (fn)
this.#process.on(sig, fn);
} catch (_) {
}
}
this.#process.emit = (ev, ...a) => {
return this.#processEmit(ev, ...a);
};
this.#process.reallyExit = (code) => {
return this.#processReallyExit(code);
};
}
unload() {
if (!this.#loaded) {
return;
}
this.#loaded = false;
signals.forEach((sig) => {
const listener = this.#sigListeners[sig];
if (!listener) {
throw new Error("Listener not defined for signal: " + sig);
}
try {
this.#process.removeListener(sig, listener);
} catch (_) {
}
});
this.#process.emit = this.#originalProcessEmit;
this.#process.reallyExit = this.#originalProcessReallyExit;
this.#emitter.count -= 1;
}
#processReallyExit(code) {
if (!processOk(this.#process)) {
return 0;
}
this.#process.exitCode = code || 0;
this.#emitter.emit("exit", this.#process.exitCode, null);
return this.#originalProcessReallyExit.call(this.#process, this.#process.exitCode);
}
#processEmit(ev, ...args) {
const og = this.#originalProcessEmit;
if (ev === "exit" && processOk(this.#process)) {
if (typeof args[0] === "number") {
this.#process.exitCode = args[0];
}
const ret = og.call(this.#process, ev, ...args);
this.#emitter.emit("exit", this.#process.exitCode, null);
return ret;
} else {
return og.call(this.#process, ev, ...args);
}
}
};
var process4 = globalThis.process;
var {
/**
* Called when the process is exiting, whether via signal, explicit
* exit, or running out of stuff to do.
*
* If the global process object is not suitable for instrumentation,
* then this will be a no-op.
*
* Returns a function that may be used to unload signal-exit.
*/
onExit,
/**
* Load the listeners. Likely you never need to call this, unless
* doing a rather deep integration with signal-exit functionality.
* Mostly exposed for the benefit of testing.
*
* @internal
*/
load,
/**
* Unload the listeners. Likely you never need to call this, unless
* doing a rather deep integration with signal-exit functionality.
* Mostly exposed for the benefit of testing.
*
* @internal
*/
unload
} = signalExitWrap(processOk(process4) ? new SignalExit(process4) : new SignalExitFallback());
var DEFAULT_FORCE_KILL_TIMEOUT = 1e3 * 5;
var spawnedKill = (kill, signal = "SIGTERM", options = {}) => {
const killResult = kill(signal);
setKillTimeout(kill, signal, options, killResult);
return killResult;
};
var setKillTimeout = (kill, signal, options, killResult) => {
if (!shouldForceKill(signal, options, killResult)) {
return;
}
const timeout = getForceKillAfterTimeout(options);
const t = setTimeout(() => {
kill("SIGKILL");
}, timeout);
if (t.unref) {
t.unref();
}
};
var shouldForceKill = (signal, { forceKillAfterTimeout }, killResult) => isSigterm(signal) && forceKillAfterTimeout !== false && killResult;
var isSigterm = (signal) => signal === import_node_os3.default.constants.signals.SIGTERM || typeof signal === "string" && signal.toUpperCase() === "SIGTERM";
var getForceKillAfterTimeout = ({ forceKillAfterTimeout = true }) => {
if (forceKillAfterTimeout === true) {
return DEFAULT_FORCE_KILL_TIMEOUT;
}
if (!Number.isFinite(forceKillAfterTimeout) || forceKillAfterTimeout < 0) {
throw new TypeError(`Expected the \`forceKillAfterTimeout\` option to be a non-negative integer, got \`${forceKillAfterTimeout}\` (${typeof forceKillAfterTimeout})`);
}
return forceKillAfterTimeout;
};
var spawnedCancel = (spawned, context) => {
const killResult = spawned.kill();
if (killResult) {
context.isCanceled = true;
}
};
var timeoutKill = (spawned, signal, reject) => {
spawned.kill(signal);
reject(Object.assign(new Error("Timed out"), { timedOut: true, signal }));
};
var setupTimeout = (spawned, { timeout, killSignal = "SIGTERM" }, spawnedPromise) => {
if (timeout === 0 || timeout === void 0) {
return spawnedPromise;
}
let timeoutId;
const timeoutPromise = new Promise((resolve, reject) => {
timeoutId = setTimeout(() => {
timeoutKill(spawned, killSignal, reject);
}, timeout);
});
const safeSpawnedPromise = spawnedPromise.finally(() => {
clearTimeout(timeoutId);
});
return Promise.race([timeoutPromise, safeSpawnedPromise]);
};
var validateTimeout = ({ timeout }) => {
if (timeout !== void 0 && (!Number.isFinite(timeout) || timeout < 0)) {
throw new TypeError(`Expected the \`timeout\` option to be a non-negative integer, got \`${timeout}\` (${typeof timeout})`);
}
};
var setExitHandler = async (spawned, { cleanup, detached }, timedPromise) => {
if (!cleanup || detached) {
return timedPromise;
}
const removeExitHandler = onExit(() => {
spawned.kill();
});
return timedPromise.finally(() => {
removeExitHandler();
});
};
function isStream(stream) {
return stream !== null && typeof stream === "object" && typeof stream.pipe === "function";
}
function isWritableStream(stream) {
return isStream(stream) && stream.writable !== false && typeof stream._write === "function" && typeof stream._writableState === "object";
}
var isExecaChildProcess = (target) => target instanceof import_node_child_process2.ChildProcess && typeof target.then === "function";
var pipeToTarget = (spawned, streamName, target) => {
if (typeof target === "string") {
spawned[streamName].pipe((0, import_node_fs2.createWriteStream)(target));
return spawned;
}
if (isWritableStream(target)) {
spawned[streamName].pipe(target);
return spawned;
}
if (!isExecaChildProcess(target)) {
throw new TypeError("The second argument must be a string, a stream or an Execa child process.");
}
if (!isWritableStream(target.stdin)) {
throw new TypeError("The target child process's stdin must be available.");
}
spawned[streamName].pipe(target.stdin);
return target;
};
var addPipeMethods = (spawned) => {
if (spawned.stdout !== null) {
spawned.pipeStdout = pipeToTarget.bind(void 0, spawned, "stdout");
}
if (spawned.stderr !== null) {
spawned.pipeStderr = pipeToTarget.bind(void 0, spawned, "stderr");
}
if (spawned.all !== void 0) {
spawned.pipeAll = pipeToTarget.bind(void 0, spawned, "all");
}
};
var getStreamContents = async (stream, { init, convertChunk, getSize, truncateChunk, addChunk, getFinalChunk, finalize }, { maxBuffer = Number.POSITIVE_INFINITY } = {}) => {
if (!isAsyncIterable(stream)) {
throw new Error("The first argument must be a Readable, a ReadableStream, or an async iterable.");
}
const state = init();
state.length = 0;
try {
for await (const chunk of stream) {
const chunkType = getChunkType(chunk);
const convertedChunk = convertChunk[chunkType](chunk, state);
appendChunk({ convertedChunk, state, getSize, truncateChunk, addChunk, maxBuffer });
}
appendFinalChunk({ state, convertChunk, getSize, truncateChunk, addChunk, getFinalChunk, maxBuffer });
return finalize(state);
} catch (error) {
error.bufferedData = finalize(state);
throw error;
}
};
var appendFinalChunk = ({ state, getSize, truncateChunk, addChunk, getFinalChunk, maxBuffer }) => {
const convertedChunk = getFinalChunk(state);
if (convertedChunk !== void 0) {
appendChunk({ convertedChunk, state, getSize, truncateChunk, addChunk, maxBuffer });
}
};
var appendChunk = ({ convertedChunk, state, getSize, truncateChunk, addChunk, maxBuffer }) => {
const chunkSize = getSize(convertedChunk);
const newLength = state.length + chunkSize;
if (newLength <= maxBuffer) {
addNewChunk(convertedChunk, state, addChunk, newLength);
return;
}
const truncatedChunk = truncateChunk(convertedChunk, maxBuffer - state.length);
if (truncatedChunk !== void 0) {
addNewChunk(truncatedChunk, state, addChunk, maxBuffer);
}
throw new MaxBufferError();
};
var addNewChunk = (convertedChunk, state, addChunk, newLength) => {
state.contents = addChunk(convertedChunk, state, newLength);
state.length = newLength;
};
var isAsyncIterable = (stream) => typeof stream === "object" && stream !== null && typeof stream[Symbol.asyncIterator] === "function";
var getChunkType = (chunk) => {
const typeOfChunk = typeof chunk;
if (typeOfChunk === "string") {
return "string";
}
if (typeOfChunk !== "object" || chunk === null) {
return "others";
}
if (globalThis.Buffer?.isBuffer(chunk)) {
return "buffer";
}
const prototypeName = objectToString.call(chunk);
if (prototypeName === "[object ArrayBuffer]") {
return "arrayBuffer";
}
if (prototypeName === "[object DataView]") {
return "dataView";
}
if (Number.isInteger(chunk.byteLength) && Number.isInteger(chunk.byteOffset) && objectToString.call(chunk.buffer) === "[object ArrayBuffer]") {
return "typedArray";
}
return "others";
};
var { toString: objectToString } = Object.prototype;
var MaxBufferError = class extends Error {
name = "MaxBufferError";
constructor() {
super("maxBuffer exceeded");
}
};
var identity = (value) => value;
var noop = () => void 0;
var getContentsProp = ({ contents }) => contents;
var throwObjectStream = (chunk) => {
throw new Error(`Streams in object mode are not supported: ${String(chunk)}`);
};
var getLengthProp = (convertedChunk) => convertedChunk.length;
async function getStreamAsArrayBuffer(stream, options) {
return getStreamContents(stream, arrayBufferMethods, options);
}
var initArrayBuffer = () => ({ contents: new ArrayBuffer(0) });
var useTextEncoder = (chunk) => textEncoder.encode(chunk);
var textEncoder = new TextEncoder();
var useUint8Array = (chunk) => new Uint8Array(chunk);
var useUint8ArrayWithOffset = (chunk) => new Uint8Array(chunk.buffer, chunk.byteOffset, chunk.byteLength);
var truncateArrayBufferChunk = (convertedChunk, chunkSize) => convertedChunk.slice(0, chunkSize);
var addArrayBufferChunk = (convertedChunk, { contents, length: previousLength }, length) => {
const newContents = hasArrayBufferResize() ? resizeArrayBuffer(contents, length) : resizeArrayBufferSlow(contents, length);
new Uint8Array(newContents).set(convertedChunk, previousLength);
return newContents;
};
var resizeArrayBufferSlow = (contents, length) => {
if (length <= contents.byteLength) {
return contents;
}
const arrayBuffer = new ArrayBuffer(getNewContentsLength(length));
new Uint8Array(arrayBuffer).set(new Uint8Array(contents), 0);
return arrayBuffer;
};
var resizeArrayBuffer = (contents, length) => {
if (length <= contents.maxByteLength) {
contents.resize(length);
return contents;
}
const arrayBuffer = new ArrayBuffer(length, { maxByteLength: getNewContentsLength(length) });
new Uint8Array(arrayBuffer).set(new Uint8Array(contents), 0);
return arrayBuffer;
};
var getNewContentsLength = (length) => SCALE_FACTOR ** Math.ceil(Math.log(length) / Math.log(SCALE_FACTOR));
var SCALE_FACTOR = 2;
var finalizeArrayBuffer = ({ contents, length }) => hasArrayBufferResize() ? contents : contents.slice(0, length);
var hasArrayBufferResize = () => "resize" in ArrayBuffer.prototype;
var arrayBufferMethods = {
init: initArrayBuffer,
convertChunk: {
string: useTextEncoder,
buffer: useUint8Array,
arrayBuffer: useUint8Array,
dataView: useUint8ArrayWithOffset,
typedArray: useUint8ArrayWithOffset,
others: throwObjectStream
},
getSize: getLengthProp,
truncateChunk: truncateArrayBufferChunk,
addChunk: addArrayBufferChunk,
getFinalChunk: noop,
finalize: finalizeArrayBuffer
};
async function getStreamAsBuffer(stream, options) {
if (!("Buffer" in globalThis)) {
throw new Error("getStreamAsBuffer() is only supported in Node.js");
}
try {
return arrayBufferToNodeBuffer(await getStreamAsArrayBuffer(stream, options));
} catch (error) {
if (error.bufferedData !== void 0) {
error.bufferedData = arrayBufferToNodeBuffer(error.bufferedData);
}
throw error;
}
}
var arrayBufferToNodeBuffer = (arrayBuffer) => globalThis.Buffer.from(arrayBuffer);
async function getStreamAsString(stream, options) {
return getStreamContents(stream, stringMethods, options);
}
var initString = () => ({ contents: "", textDecoder: new TextDecoder() });
var useTextDecoder = (chunk, { textDecoder }) => textDecoder.decode(chunk, { stream: true });
var addStringChunk = (convertedChunk, { contents }) => contents + convertedChunk;
var truncateStringChunk = (convertedChunk, chunkSize) => convertedChunk.slice(0, chunkSize);
var getFinalStringChunk = ({ textDecoder }) => {
const finalChunk = textDecoder.decode();
return finalChunk === "" ? void 0 : finalChunk;
};
var stringMethods = {
init: initString,
convertChunk: {
string: identity,
buffer: useTextDecoder,
arrayBuffer: useTextDecoder,
dataView: useTextDecoder,
typedArray: useTextDecoder,
others: throwObjectStream
},
getSize: getLengthProp,
truncateChunk: truncateStringChunk,
addChunk: addStringChunk,
getFinalChunk: getFinalStringChunk,
finalize: getContentsProp
};
var import_merge_stream = (0, import_chunk_QGM4M3NI.__toESM)(require_merge_stream(), 1);
var validateInputOptions = (input) => {
if (input !== void 0) {
throw new TypeError("The `input` and `inputFile` options cannot be both set.");
}
};
var getInputSync = ({ input, inputFile }) => {
if (typeof inputFile !== "string") {
return input;
}
validateInputOptions(input);
return (0, import_node_fs3.readFileSync)(inputFile);
};
var handleInputSync = (options) => {
const input = getInputSync(options);
if (isStream(input)) {
throw new TypeError("The `input` option cannot be a stream in sync mode");
}
return input;
};
var getInput = ({ input, inputFile }) => {
if (typeof inputFile !== "string") {
return input;
}
validateInputOptions(input);
return (0, import_node_fs3.createReadStream)(inputFile);
};
var handleInput = (spawned, options) => {
const input = getInput(options);
if (input === void 0) {
return;
}
if (isStream(input)) {
input.pipe(spawned.stdin);
} else {
spawned.stdin.end(input);
}
};
var makeAllStream = (spawned, { all }) => {
if (!all || !spawned.stdout && !spawned.stderr) {
return;
}
const mixed = (0, import_merge_stream.default)();
if (spawned.stdout) {
mixed.add(spawned.stdout);
}
if (spawned.stderr) {
mixed.add(spawned.stderr);
}
return mixed;
};
var getBufferedData = async (stream, streamPromise) => {
if (!stream || streamPromise === void 0) {
return;
}
await (0, import_promises.setTimeout)(0);
stream.destroy();
try {
return await streamPromise;
} catch (error) {
return error.bufferedData;
}
};
var getStreamPromise = (stream, { encoding, buffer, maxBuffer }) => {
if (!stream || !buffer) {
return;
}
if (encoding === "utf8" || encoding === "utf-8") {
return getStreamAsString(stream, { maxBuffer });
}
if (encoding === null || encoding === "buffer") {
return getStreamAsBuffer(stream, { maxBuffer });
}
return applyEncoding(stream, maxBuffer, encoding);
};
var applyEncoding = async (stream, maxBuffer, encoding) => {
const buffer = await getStreamAsBuffer(stream, { maxBuffer });
return buffer.toString(encoding);
};
var getSpawnedResult = async ({ stdout, stderr, all }, { encoding, buffer, maxBuffer }, processDone) => {
const stdoutPromise = getStreamPromise(stdout, { encoding, buffer, maxBuffer });
const stderrPromise = getStreamPromise(stderr, { encoding, buffer, maxBuffer });
const allPromise = getStreamPromise(all, { encoding, buffer, maxBuffer: maxBuffer * 2 });
try {
return await Promise.all([processDone, stdoutPromise, stderrPromise, allPromise]);
} catch (error) {
return Promise.all([
{ error, signal: error.signal, timedOut: error.timedOut },
getBufferedData(stdout, stdoutPromise),
getBufferedData(stderr, stderrPromise),
getBufferedData(all, allPromise)
]);
}
};
var nativePromisePrototype = (async () => {
})().constructor.prototype;
var descriptors = ["then", "catch", "finally"].map((property) => [
property,
Reflect.getOwnPropertyDescriptor(nativePromisePrototype, property)
]);
var mergePromise = (spawned, promise) => {
for (const [property, descriptor] of descriptors) {
const value = typeof promise === "function" ? (...args) => Reflect.apply(descriptor.value, promise(), args) : descriptor.value.bind(promise);
Reflect.defineProperty(spawned, property, { ...descriptor, value });
}
};
var getSpawnedPromise = (spawned) => new Promise((resolve, reject) => {
spawned.on("exit", (exitCode, signal) => {
resolve({ exitCode, signal });
});
spawned.on("error", (error) => {
reject(error);
});
if (spawned.stdin) {
spawned.stdin.on("error", (error) => {
reject(error);
});
}
});
var normalizeArgs = (file, args = []) => {
if (!Array.isArray(args)) {
return [file];
}
return [file, ...args];
};
var NO_ESCAPE_REGEXP = /^[\w.-]+$/;
var escapeArg = (arg) => {
if (typeof arg !== "string" || NO_ESCAPE_REGEXP.test(arg)) {
return arg;
}
return `"${arg.replaceAll('"', '\\"')}"`;
};
var joinCommand = (file, args) => normalizeArgs(file, args).join(" ");
var getEscapedCommand = (file, args) => normalizeArgs(file, args).map((arg) => escapeArg(arg)).join(" ");
var SPACES_REGEXP = / +/g;
var parseExpression = (expression) => {
const typeOfExpression = typeof expression;
if (typeOfExpression === "string") {
return expression;
}
if (typeOfExpression === "number") {
return String(expression);
}
if (typeOfExpression === "object" && expression !== null && !(expression instanceof import_node_child_process3.ChildProcess) && "stdout" in expression) {
const typeOfStdout = typeof expression.stdout;
if (typeOfStdout === "string") {
return expression.stdout;
}
if (import_node_buffer2.Buffer.isBuffer(expression.stdout)) {
return expression.stdout.toString();
}
throw new TypeError(`Unexpected "${typeOfStdout}" stdout in template expression`);
}
throw new TypeError(`Unexpected "${typeOfExpression}" in template expression`);
};
var concatTokens = (tokens, nextTokens, isNew) => isNew || tokens.length === 0 || nextTokens.length === 0 ? [...tokens, ...nextTokens] : [
...tokens.slice(0, -1),
`${tokens.at(-1)}${nextTokens[0]}`,
...nextTokens.slice(1)
];
var parseTemplate = ({ templates, expressions, tokens, index, template }) => {
const templateString = template ?? templates.raw[index];
const templateTokens = templateString.split(SPACES_REGEXP).filter(Boolean);
const newTokens = concatTokens(
tokens,
templateTokens,
templateString.startsWith(" ")
);
if (index === expressions.length) {
return newTokens;
}
const expression = expressions[index];
const expressionTokens = Array.isArray(expression) ? expression.map((expression2) => parseExpression(expression2)) : [parseExpression(expression)];
return concatTokens(
newTokens,
expressionTokens,
templateString.endsWith(" ")
);
};
var parseTemplates = (templates, expressions) => {
let tokens = [];
for (const [index, template] of templates.entries()) {
tokens = parseTemplate({ templates, expressions, tokens, index, template });
}
return tokens;
};
var verboseDefault = (0, import_node_util2.debuglog)("execa").enabled;
var padField = (field, padding) => String(field).padStart(padding, "0");
var getTimestamp = () => {
const date = /* @__PURE__ */ new Date();
return `${padField(date.getHours(), 2)}:${padField(date.getMinutes(), 2)}:${padField(date.getSeconds(), 2)}.${padField(date.getMilliseconds(), 3)}`;
};
var logCommand = (escapedCommand, { verbose }) => {
if (!verbose) {
return;
}
import_node_process4.default.stderr.write(`[${getTimestamp()}] ${escapedCommand}
`);
};
var DEFAULT_MAX_BUFFER = 1e3 * 1e3 * 100;
var getEnv = ({ env: envOption, extendEnv, preferLocal, localDir, execPath }) => {
const env = extendEnv ? { ...import_node_process.default.env, ...envOption } : envOption;
if (preferLocal) {
return npmRunPathEnv({ env, cwd: localDir, execPath });
}
return env;
};
var handleArguments = (file, args, options = {}) => {
const parsed = import_cross_spawn.default._parse(file, args, options);
file = parsed.command;
args = parsed.args;
options = parsed.options;
options = {
maxBuffer: DEFAULT_MAX_BUFFER,
buffer: true,
stripFinalNewline: true,
extendEnv: true,
preferLocal: false,
localDir: options.cwd || import_node_process.default.cwd(),
execPath: import_node_process.default.execPath,
encoding: "utf8",
reject: true,
cleanup: true,
all: false,
windowsHide: true,
verbose: verboseDefault,
...options
};
options.env = getEnv(options);
options.stdio = normalizeStdio(options);
if (import_node_process.default.platform === "win32" && import_node_path2.default.basename(file, ".exe") === "cmd") {
args.unshift("/q");
}
return { file, args, options, parsed };
};
var handleOutput = (options, value, error) => {
if (typeof value !== "string" && !import_node_buffer.Buffer.isBuffer(value)) {
return error === void 0 ? void 0 : "";
}
if (options.stripFinalNewline) {
return stripFinalNewline(value);
}
return value;
};
function execa(file, args, options) {
const parsed = handleArguments(file, args, options);
const command = joinCommand(file, args);
const escapedCommand = getEscapedCommand(file, args);
logCommand(escapedCommand, parsed.options);
validateTimeout(parsed.options);
let spawned;
try {
spawned = import_node_child_process.default.spawn(parsed.file, parsed.args, parsed.options);
} catch (error) {
const dummySpawned = new import_node_child_process.default.ChildProcess();
const errorPromise = Promise.reject(makeError({
error,
stdout: "",
stderr: "",
all: "",
command,
escapedCommand,
parsed,
timedOut: false,
isCanceled: false,
killed: false
}));
mergePromise(dummySpawned, errorPromise);
return dummySpawned;
}
const spawnedPromise = getSpawnedPromise(spawned);
const timedPromise = setupTimeout(spawned, parsed.options, spawnedPromise);
const processDone = setExitHandler(spawned, parsed.options, timedPromise);
const context = { isCanceled: false };
spawned.kill = spawnedKill.bind(null, spawned.kill.bind(spawned));
spawned.cancel = spawnedCancel.bind(null, spawned, context);
const handlePromise = async () => {
const [{ error, exitCode, signal, timedOut }, stdoutResult, stderrResult, allResult] = await getSpawnedResult(spawned, parsed.options, processDone);
const stdout = handleOutput(parsed.options, stdoutResult);
const stderr = handleOutput(parsed.options, stderrResult);
const all = handleOutput(parsed.options, allResult);
if (error || exitCode !== 0 || signal !== null) {
const returnedError = makeError({
error,
exitCode,
signal,
stdout,
stderr,
all,
command,
escapedCommand,
parsed,
timedOut,
isCanceled: context.isCanceled || (parsed.options.signal ? parsed.options.signal.aborted : false),
killed: spawned.killed
});
if (!parsed.options.reject) {
return returnedError;
}
throw returnedError;
}
return {
command,
escapedCommand,
exitCode: 0,
stdout,
stderr,
all,
failed: false,
timedOut: false,
isCanceled: false,
killed: false
};
};
const handlePromiseOnce = onetime_default(handlePromise);
handleInput(spawned, parsed.options);
spawned.all = makeAllStream(spawned, parsed.options);
addPipeMethods(spawned);
mergePromise(spawned, handlePromiseOnce);
return spawned;
}
function execaSync(file, args, options) {
const parsed = handleArguments(file, args, options);
const command = joinCommand(file, args);
const escapedCommand = getEscapedCommand(file, args);
logCommand(escapedCommand, parsed.options);
const input = handleInputSync(parsed.options);
let result;
try {
result = import_node_child_process.default.spawnSync(parsed.file, parsed.args, { ...parsed.options, input });
} catch (error) {
throw makeError({
error,
stdout: "",
stderr: "",
all: "",
command,
escapedCommand,
parsed,
timedOut: false,
isCanceled: false,
killed: false
});
}
const stdout = handleOutput(parsed.options, result.stdout, result.error);
const stderr = handleOutput(parsed.options, result.stderr, result.error);
if (result.error || result.status !== 0 || result.signal !== null) {
const error = makeError({
stdout,
stderr,
error: result.error,
signal: result.signal,
exitCode: result.status,
command,
escapedCommand,
parsed,
timedOut: result.error && result.error.code === "ETIMEDOUT",
isCanceled: false,
killed: result.signal !== null
});
if (!parsed.options.reject) {
return error;
}
throw error;
}
return {
command,
escapedCommand,
exitCode: 0,
stdout,
stderr,
failed: false,
timedOut: false,
isCanceled: false,
killed: false
};
}
var normalizeScriptStdin = ({ input, inputFile, stdio }) => input === void 0 && inputFile === void 0 && stdio === void 0 ? { stdin: "inherit" } : {};
var normalizeScriptOptions = (options = {}) => ({
preferLocal: true,
...normalizeScriptStdin(options),
...options
});
function create$(options) {
function $2(templatesOrOptions, ...expressions) {
if (!Array.isArray(templatesOrOptions)) {
return create$({ ...options, ...templatesOrOptions });
}
const [file, ...args] = parseTemplates(templatesOrOptions, expressions);
return execa(file, args, normalizeScriptOptions(options));
}
$2.sync = (templates, ...expressions) => {
if (!Array.isArray(templates)) {
throw new TypeError("Please use $(options).sync`command` instead of $.sync(options)`command`.");
}
const [file, ...args] = parseTemplates(templates, expressions);
return execaSync(file, args, normalizeScriptOptions(options));
};
return $2;
}
var $ = create$();
var import_fs_extra = (0, import_chunk_QGM4M3NI.__toESM)((0, import_chunk_LONQL55G.require_lib)());
async function pMap(iterable, mapper, {
concurrency = Number.POSITIVE_INFINITY,
stopOnError = true,
signal
} = {}) {
return new Promise((resolve_, reject_) => {
if (iterable[Symbol.iterator] === void 0 && iterable[Symbol.asyncIterator] === void 0) {
throw new TypeError(`Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof iterable})`);
}
if (typeof mapper !== "function") {
throw new TypeError("Mapper function is required");
}
if (!(Number.isSafeInteger(concurrency) && concurrency >= 1 || concurrency === Number.POSITIVE_INFINITY)) {
throw new TypeError(`Expected \`concurrency\` to be an integer from 1 and up or \`Infinity\`, got \`${concurrency}\` (${typeof concurrency})`);
}
const result = [];
const errors = [];
const skippedIndexesMap = /* @__PURE__ */ new Map();
let isRejected = false;
let isResolved = false;
let isIterableDone = false;
let resolvingCount = 0;
let currentIndex = 0;
const iterator = iterable[Symbol.iterator] === void 0 ? iterable[Symbol.asyncIterator]() : iterable[Symbol.iterator]();
const signalListener = () => {
reject(signal.reason);
};
const cleanup = () => {
signal?.removeEventListener("abort", signalListener);
};
const resolve = (value) => {
resolve_(value);
cleanup();
};
const reject = (reason) => {
isRejected = true;
isResolved = true;
reject_(reason);
cleanup();
};
if (signal) {
if (signal.aborted) {
reject(signal.reason);
}
signal.addEventListener("abort", signalListener, { once: true });
}
const next = async () => {
if (isResolved) {
return;
}
const nextItem = await iterator.next();
const index = currentIndex;
currentIndex++;
if (nextItem.done) {
isIterableDone = true;
if (resolvingCount === 0 && !isResolved) {
if (!stopOnError && errors.length > 0) {
reject(new AggregateError(errors));
return;
}
isResolved = true;
if (skippedIndexesMap.size === 0) {
resolve(result);
return;
}
const pureResult = [];
for (const [index2, value] of result.entries()) {
if (skippedIndexesMap.get(index2) === pMapSkip) {
continue;
}
pureResult.push(value);
}
resolve(pureResult);
}
return;
}
resolvingCount++;
(async () => {
try {
const element = await nextItem.value;
if (isResolved) {
return;
}
const value = await mapper(element, index);
if (value === pMapSkip) {
skippedIndexesMap.set(index, value);
}
result[index] = value;
resolvingCount--;
await next();
} catch (error) {
if (stopOnError) {
reject(error);
} else {
errors.push(error);
resolvingCount--;
try {
await next();
} catch (error2) {
reject(error2);
}
}
}
})();
};
(async () => {
for (let index = 0; index < concurrency; index++) {
try {
await next();
} catch (error) {
reject(error);
break;
}
if (isIterableDone || isRejected) {
break;
}
}
})();
});
}
var pMapSkip = Symbol("skip");
async function pFilter(iterable, filterer, options) {
const values = await pMap(
iterable,
(element, index) => Promise.all([filterer(element, index), element]),
options
);
return values.filter((value) => Boolean(value[0])).map((value) => value[1]);
}
var import_temp_dir = (0, import_chunk_QGM4M3NI.__toESM)((0, import_chunk_CY52DY2B.require_temp_dir)());
var { enginesOverride } = require_package();
var debug = (0, import_debug.default)("prisma:fetch-engine:download");
var exists = (0, import_node_util.promisify)(import_node_fs.default.exists);
var channel = "master";
var vercelPkgPathRegex = /^((\w:[\\\/])|\/)snapshot[\/\\]/;
async function download(options) {
if (!options.binaries || Object.values(options.binaries).length === 0) {
return {};
}
if (enginesOverride?.["branch"] || enginesOverride?.["folder"]) {
options.version = "_local_";
options.skipCacheIntegrityCheck = true;
}
const { binaryTarget, ...os2 } = await (0, import_get_platform.getPlatformInfo)();
if (os2.targetDistro && ["nixos"].includes(os2.targetDistro) && !(0, import_chunk_QFA3XBMW.allEngineEnvVarsSet)(Object.keys(options.binaries))) {
console.error(
`${(0, import_chunk_QFA3XBMW.yellow)("Warning")} Precompiled engine files are not available for ${os2.targetDistro}, please provide the paths via environment variables, see https://pris.ly/d/custom-engines`
);
} else if (["freebsd11", "freebsd12", "freebsd13", "freebsd14", "freebsd15", "openbsd", "netbsd"].includes(binaryTarget)) {
console.error(
`${(0, import_chunk_QFA3XBMW.yellow)(
"Warning"
)} Precompiled engine files are not available for ${binaryTarget}. Read more about building your own engines at https://pris.ly/d/build-engines`
);
} else if ("libquery-engine" in options.binaries) {
(0, import_get_platform.assertNodeAPISupported)();
}
const opts = {
...options,
binaryTargets: options.binaryTargets ?? [binaryTarget],
version: options.version ?? "latest",
binaries: options.binaries
};
const binaryJobs = Object.entries(opts.binaries).flatMap(
([binaryName, targetFolder]) => opts.binaryTargets.map((binaryTarget2) => {
const fileName = getBinaryName(binaryName, binaryTarget2);
const targetFilePath = import_node_path.default.join(targetFolder, fileName);
return {
binaryName,
targetFolder,
binaryTarget: binaryTarget2,
fileName,
targetFilePath,
envVarPath: (0, import_chunk_QFA3XBMW.getBinaryEnvVarPath)(binaryName)?.path,
skipCacheIntegrityCheck: !!opts.skipCacheIntegrityCheck
};
})
);
if (process.env.BINARY_DOWNLOAD_VERSION) {
debug(`process.env.BINARY_DOWNLOAD_VERSION is set to "${process.env.BINARY_DOWNLOAD_VERSION}"`);
opts.version = process.env.BINARY_DOWNLOAD_VERSION;
}
if (opts.printVersion) {
console.log(`version: ${opts.version}`);
}
const binariesToDownload = await pFilter(binaryJobs, async (job) => {
const needsToBeDownloaded = await binaryNeedsToBeDownloaded(job, binaryTarget, opts.version);
const isSupported = import_get_platform.binaryTargets.includes(job.binaryTarget);
const shouldDownload = isSupported && !job.envVarPath && // this is for custom binaries
needsToBeDownloaded;
if (needsToBeDownloaded && !isSupported) {
throw new Error(`Unknown binaryTarget ${job.binaryTarget} and no custom engine files were provided`);
}
return shouldDownload;
});
if (binariesToDownload.length > 0) {
const cleanupPromise = (0, import_chunk_3VVCXIQ5.cleanupCache)();
let finishBar;
let setProgress;
if (opts.showProgress) {
const collectiveBar = getCollectiveBar(opts);
finishBar = collectiveBar.finishBar;
setProgress = collectiveBar.setProgress;
}
const promises = binariesToDownload.map((job) => {
const downloadUrl = (0, import_chunk_LONQL55G.getDownloadUrl)({
channel: "all_commits",
version: opts.version,
binaryTarget: job.binaryTarget,
binaryName: job.binaryName
});
debug(`${downloadUrl} will be downloaded to ${job.targetFilePath}`);
return downloadBinary({
...job,
downloadUrl,
version: opts.version,
failSilent: opts.failSilent,
progressCb: setProgress ? setProgress(job.targetFilePath) : void 0
});
});
await Promise.all(promises);
await cleanupPromise;
if (finishBar) {
finishBar();
}
}
const binaryPaths = binaryJobsToBinaryPaths(binaryJobs);
if (__dirname.match(vercelPkgPathRegex)) {
for (const engineType in binaryPaths) {
const binaryTargets2 = binaryPaths[engineType];
for (const binaryTarget2 in binaryTargets2) {
const binaryPath = binaryTargets2[binaryTarget2];
binaryTargets2[binaryTarget2] = await maybeCopyToTmp(binaryPath);
}
}
}
return binaryPaths;
}
function getCollectiveBar(options) {
const hasNodeAPI = "libquery-engine" in options.binaries;
const bar = (0, import_chunk_MWVY55RY.getBar)(
`Downloading Prisma engines${hasNodeAPI ? " for Node-API" : ""} for ${options.binaryTargets?.map((p) => (0, import_chunk_QFA3XBMW.bold)(p)).join(" and ")}`
);
const progressMap = {};
const numDownloads = Object.values(options.binaries).length * Object.values(options?.binaryTargets ?? []).length;
const setProgress = (sourcePath) => (progress) => {
progressMap[sourcePath] = progress;
const progressValues = Object.values(progressMap);
const totalProgress = progressValues.reduce((acc, curr) => {
return acc + curr;
}, 0) / numDownloads;
if (options.progressCb) {
options.progressCb(totalProgress);
}
if (bar) {
bar.update(totalProgress);
}
};
return {
setProgress,
finishBar: () => {
bar.update(1);
bar.terminate();
}
};
}
function binaryJobsToBinaryPaths(jobs) {
return jobs.reduce((acc, job) => {
if (!acc[job.binaryName]) {
acc[job.binaryName] = {};
}
acc[job.binaryName][job.binaryTarget] = job.envVarPath || job.targetFilePath;
return acc;
}, {});
}
async function binaryNeedsToBeDownloaded(job, nativePlatform, version) {
if (job.envVarPath && import_node_fs.default.existsSync(job.envVarPath)) {
return false;
}
const targetExists = await exists(job.targetFilePath);
const cachedFile = await getCachedBinaryPath({
...job,
version
});
if (cachedFile) {
if (job.skipCacheIntegrityCheck === true) {
await (0, import_chunk_LONQL55G.overwriteFile)(cachedFile, job.targetFilePath);
return false;
}
const sha256FilePath = cachedFile + ".sha256";
if (await exists(sha256FilePath)) {
const sha256File = await import_node_fs.default.promises.readFile(sha256FilePath, "utf-8");
const sha256Cache = await (0, import_chunk_FKGWOTGU.getHash)(cachedFile);
if (sha256File === sha256Cache) {
if (!targetExists) {
debug(`copying ${cachedFile} to ${job.targetFilePath}`);
await import_node_fs.default.promises.utimes(cachedFile, /* @__PURE__ */ new Date(), /* @__PURE__ */ new Date());
await (0, import_chunk_LONQL55G.overwriteFile)(cachedFile, job.targetFilePath);
}
const targetSha256 = await (0, import_chunk_FKGWOTGU.getHash)(job.targetFilePath);
if (sha256File !== targetSha256) {
debug(`overwriting ${job.targetFilePath} with ${cachedFile} as hashes do not match`);
await (0, import_chunk_LONQL55G.overwriteFile)(cachedFile, job.targetFilePath);
}
return false;
} else {
return true;
}
} else if (process.env.PRISMA_ENGINES_CHECKSUM_IGNORE_MISSING) {
debug(
`the checksum file ${sha256FilePath} is missing but this was ignored because the PRISMA_ENGINES_CHECKSUM_IGNORE_MISSING environment variable is set`
);
if (targetExists) {
return false;
}
if (cachedFile) {
debug(`copying ${cachedFile} to ${job.targetFilePath}`);
await (0, import_chunk_LONQL55G.overwriteFile)(cachedFile, job.targetFilePath);
return false;
}
return true;
} else {
return true;
}
}
if (!targetExists) {
debug(`file ${job.targetFilePath} does not exist and must be downloaded`);
return true;
}
if (job.binaryTarget === nativePlatform) {
const currentVersion = await getVersion(job.targetFilePath, job.binaryName);
if (currentVersion?.includes(version) !== true) {
debug(`file ${job.targetFilePath} exists but its version is ${currentVersion} and we expect ${version}`);
return true;
}
}
return false;
}
async function getVersion(enginePath, binaryName) {
try {
if (binaryName === "libquery-engine") {
(0, import_get_platform.assertNodeAPISupported)();
const commitHash = (0, import_chunk_QGM4M3NI.__require)(enginePath).version().commit;
return `${"libquery-engine"} ${commitHash}`;
} else {
const result = await execa(enginePath, ["--version"]);
return result.stdout;
}
} catch {
}
return void 0;
}
function getBinaryName(binaryName, binaryTarget) {
if (binaryName === "libquery-engine") {
return `${(0, import_get_platform.getNodeAPIName)(binaryTarget, "fs")}`;
}
const extension = binaryTarget === "windows" ? ".exe" : "";
return `${binaryName}-${binaryTarget}${extension}`;
}
async function getCachedBinaryPath({
version,
binaryTarget,
binaryName
}) {
const cacheDir = await (0, import_chunk_LONQL55G.getCacheDir)(channel, version, binaryTarget);
if (!cacheDir) {
return null;
}
const cachedTargetPath = import_node_path.default.join(cacheDir, binaryName);
if (!import_node_fs.default.existsSync(cachedTargetPath)) {
return null;
}
if (version !== "latest") {
return cachedTargetPath;
}
if (await exists(cachedTargetPath)) {
return cachedTargetPath;
}
return null;
}
async function downloadBinary(options) {
const { version, progressCb, targetFilePath, downloadUrl } = options;
const targetDir = import_node_path.default.dirname(targetFilePath);
try {
import_node_fs.default.accessSync(targetDir, import_node_fs.default.constants.W_OK);
await (0, import_fs_extra.ensureDir)(targetDir);
} catch (e) {
if (options.failSilent || e.code !== "EACCES") {
return;
} else {
throw new Error(`Can't write to ${targetDir} please make sure you install "prisma" with the right permissions.`);
}
}
debug(`Downloading ${downloadUrl} to ${targetFilePath} ...`);
if (progressCb) {
progressCb(0);
}
const { sha256, zippedSha256 } = await (0, import_chunk_CY52DY2B.downloadZip)(downloadUrl, targetFilePath, progressCb);
if (progressCb) {
progressCb(1);
}
(0, import_chunk_7JLQJWOR.chmodPlusX)(targetFilePath);
await saveFileToCache(options, version, sha256, zippedSha256);
}
async function saveFileToCache(job, version, sha256, zippedSha256) {
const cacheDir = await (0, import_chunk_LONQL55G.getCacheDir)(channel, version, job.binaryTarget);
if (!cacheDir) {
return;
}
const cachedTargetPath = import_node_path.default.join(cacheDir, job.binaryName);
const cachedSha256Path = import_node_path.default.join(cacheDir, job.binaryName + ".sha256");
const cachedSha256ZippedPath = import_node_path.default.join(cacheDir, job.binaryName + ".gz.sha256");
try {
await (0, import_chunk_LONQL55G.overwriteFile)(job.targetFilePath, cachedTargetPath);
if (sha256 != null) {
await import_node_fs.default.promises.writeFile(cachedSha256Path, sha256);
}
if (zippedSha256 != null) {
await import_node_fs.default.promises.writeFile(cachedSha256ZippedPath, zippedSha256);
}
} catch (e) {
debug(e);
}
}
async function maybeCopyToTmp(file) {
if (__dirname.match(vercelPkgPathRegex)) {
const targetDir = import_node_path.default.join(import_temp_dir.default, "prisma-binaries");
await (0, import_fs_extra.ensureDir)(targetDir);
const target = import_node_path.default.join(targetDir, import_node_path.default.basename(file));
const data = await import_node_fs.default.promises.readFile(file);
await import_node_fs.default.promises.writeFile(target, data);
plusX(target);
return target;
}
return file;
}
function plusX(file) {
const s = import_node_fs.default.statSync(file);
const newMode = s.mode | 64 | 8 | 1;
if (s.mode === newMode) {
return;
}
const base8 = newMode.toString(8).slice(-3);
import_node_fs.default.chmodSync(file, base8);
}