storybook
Version:
Storybook: Develop, document, and test UI components in isolation
1,190 lines (1,179 loc) • 377 kB
JavaScript
import CJS_COMPAT_NODE_URL_e6wt3b00afv from 'node:url';
import CJS_COMPAT_NODE_PATH_e6wt3b00afv from 'node:path';
import CJS_COMPAT_NODE_MODULE_e6wt3b00afv from "node:module";
var __filename = CJS_COMPAT_NODE_URL_e6wt3b00afv.fileURLToPath(import.meta.url);
var __dirname = CJS_COMPAT_NODE_PATH_e6wt3b00afv.dirname(__filename);
var require = CJS_COMPAT_NODE_MODULE_e6wt3b00afv.createRequire(import.meta.url);
// ------------------------------------------------------------
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
// ------------------------------------------------------------
import {
toEstree
} from "../_node-chunks/chunk-5Y43X4M3.js";
import {
StatusTypeIdMismatchError
} from "../_node-chunks/chunk-FH6FG5OK.js";
import {
debounce,
generateStoryFile,
getErrorLevel,
getWsToken,
isTelemetryEnabled,
mapStaticDir,
parseStaticDir,
sendTelemetryError,
useStatics,
withTelemetry
} from "../_node-chunks/chunk-HUYNFPPD.js";
import {
detectPnp
} from "../_node-chunks/chunk-GGY4RY3A.js";
import "../_node-chunks/chunk-TLLE3QWR.js";
import {
StorybookError
} from "../_node-chunks/chunk-RPUWA7TT.js";
import {
telemetry
} from "../_node-chunks/chunk-NU7VJVPP.js";
import "../_node-chunks/chunk-BFUOXQW6.js";
import {
optionalEnvToBoolean,
require_cross_spawn,
resolveImport,
supportedExtensions,
userOrAutoTitleFromSpecifier
} from "../_node-chunks/chunk-3LP2BDDH.js";
import "../_node-chunks/chunk-F3OIOXPV.js";
import "../_node-chunks/chunk-K6XUTR7B.js";
import {
logger,
require_pretty_hrtime
} from "../_node-chunks/chunk-CSY5TWXV.js";
import "../_node-chunks/chunk-L5XXUDIG.js";
import "../_node-chunks/chunk-GHPI5GQW.js";
import {
invariant,
up2 as up
} from "../_node-chunks/chunk-QLBU4TY7.js";
import "../_node-chunks/chunk-O3R4PADZ.js";
import {
importModule,
resolvePackageDir
} from "../_node-chunks/chunk-QAXH75FV.js";
import {
dirname,
isAbsolute,
join,
relative,
resolve
} from "../_node-chunks/chunk-SHPY6CCW.js";
import {
slash
} from "../_node-chunks/chunk-SOP5BQAH.js";
import "../_node-chunks/chunk-ZITP4QZO.js";
import {
Tag
} from "../_node-chunks/chunk-YQB7TYP2.js";
import {
require_dist
} from "../_node-chunks/chunk-TIXVVIDQ.js";
import {
require_lib,
require_src
} from "../_node-chunks/chunk-VVZFLDFE.js";
import {
require_picocolors
} from "../_node-chunks/chunk-25S2XFFS.js";
import {
__commonJS,
__require,
__toESM
} from "../_node-chunks/chunk-LF7MVXPB.js";
// ../../node_modules/glob-to-regexp/index.js
var require_glob_to_regexp = __commonJS({
"../../node_modules/glob-to-regexp/index.js"(exports, module) {
module.exports = function(glob, opts) {
if (typeof glob != "string")
throw new TypeError("Expected a string");
for (var str = String(glob), reStr = "", extended = opts ? !!opts.extended : !1, globstar = opts ? !!opts.globstar : !1, inGroup = !1, flags = opts && typeof opts.flags == "string" ? opts.flags : "", c, i = 0, len = str.length; i < len; i++)
switch (c = str[i], c) {
case "/":
case "$":
case "^":
case "+":
case ".":
case "(":
case ")":
case "=":
case "!":
case "|":
reStr += "\\" + c;
break;
case "?":
if (extended) {
reStr += ".";
break;
}
case "[":
case "]":
if (extended) {
reStr += c;
break;
}
case "{":
if (extended) {
inGroup = !0, reStr += "(";
break;
}
case "}":
if (extended) {
inGroup = !1, reStr += ")";
break;
}
case ",":
if (inGroup) {
reStr += "|";
break;
}
reStr += "\\" + c;
break;
case "*":
for (var prevChar = str[i - 1], starCount = 1; str[i + 1] === "*"; )
starCount++, i++;
var nextChar = str[i + 1];
if (!globstar)
reStr += ".*";
else {
var isGlobstar = starCount > 1 && (prevChar === "/" || prevChar === void 0) && (nextChar === "/" || nextChar === void 0);
isGlobstar ? (reStr += "((?:[^/]*(?:/|$))*)", i++) : reStr += "([^/]*)";
}
break;
default:
reStr += c;
}
return (!flags || !~flags.indexOf("g")) && (reStr = "^" + reStr + "$"), new RegExp(reStr, flags);
};
}
});
// ../../node_modules/watchpack/lib/LinkResolver.js
var require_LinkResolver = __commonJS({
"../../node_modules/watchpack/lib/LinkResolver.js"(exports, module) {
"use strict";
var fs = __require("fs"), path2 = __require("path"), EXPECTED_ERRORS = /* @__PURE__ */ new Set(["EINVAL", "ENOENT"]);
process.platform === "win32" && EXPECTED_ERRORS.add("UNKNOWN");
var LinkResolver = class {
constructor() {
this.cache = /* @__PURE__ */ new Map();
}
/**
* @param {string} file path to file or directory
* @returns {readonly string[]} array of file and all symlinks contributed in the resolving process (first item is the resolved file)
*/
resolve(file) {
let cacheEntry = this.cache.get(file);
if (cacheEntry !== void 0)
return cacheEntry;
let parent = path2.dirname(file);
if (parent === file) {
let result = Object.freeze([file]);
return this.cache.set(file, result), result;
}
let parentResolved = this.resolve(parent), realFile = file;
if (parentResolved[0] !== parent) {
let basename4 = path2.basename(file);
realFile = path2.resolve(parentResolved[0], basename4);
}
try {
let linkContent = fs.readlinkSync(realFile), resolvedLink = path2.resolve(parentResolved[0], linkContent), linkResolved = this.resolve(resolvedLink), result;
if (linkResolved.length > 1 && parentResolved.length > 1) {
let resultSet = new Set(linkResolved);
resultSet.add(realFile);
for (let i = 1; i < parentResolved.length; i++)
resultSet.add(parentResolved[i]);
result = Object.freeze([...resultSet]);
} else parentResolved.length > 1 ? (result = [...parentResolved], result[0] = linkResolved[0], result.push(realFile), Object.freeze(result)) : linkResolved.length > 1 ? (result = [...linkResolved], result.push(realFile), Object.freeze(result)) : result = Object.freeze([
// the resolve real location
linkResolved[0],
// add the link
realFile
]);
return this.cache.set(file, result), result;
} catch (err) {
if (
/** @type {NodeJS.ErrnoException} */
err.code && !EXPECTED_ERRORS.has(
/** @type {NodeJS.ErrnoException} */
err.code
)
)
throw err;
let result = [...parentResolved];
return result[0] = realFile, Object.freeze(result), this.cache.set(file, result), result;
}
}
};
module.exports = LinkResolver;
}
});
// ../../node_modules/graceful-fs/polyfills.js
var require_polyfills = __commonJS({
"../../node_modules/graceful-fs/polyfills.js"(exports, module) {
var constants = __require("constants"), origCwd = process.cwd, cwd = null, platform = process.env.GRACEFUL_FS_PLATFORM || process.platform;
process.cwd = function() {
return cwd || (cwd = origCwd.call(process)), cwd;
};
try {
process.cwd();
} catch {
}
typeof process.chdir == "function" && (chdir = process.chdir, process.chdir = function(d) {
cwd = null, chdir.call(process, d);
}, Object.setPrototypeOf && Object.setPrototypeOf(process.chdir, chdir));
var chdir;
module.exports = patch;
function patch(fs) {
constants.hasOwnProperty("O_SYMLINK") && process.version.match(/^v0\.6\.[0-2]|^v0\.5\./) && patchLchmod(fs), fs.lutimes || patchLutimes(fs), fs.chown = chownFix(fs.chown), fs.fchown = chownFix(fs.fchown), fs.lchown = chownFix(fs.lchown), fs.chmod = chmodFix(fs.chmod), fs.fchmod = chmodFix(fs.fchmod), fs.lchmod = chmodFix(fs.lchmod), fs.chownSync = chownFixSync(fs.chownSync), fs.fchownSync = chownFixSync(fs.fchownSync), fs.lchownSync = chownFixSync(fs.lchownSync), fs.chmodSync = chmodFixSync(fs.chmodSync), fs.fchmodSync = chmodFixSync(fs.fchmodSync), fs.lchmodSync = chmodFixSync(fs.lchmodSync), fs.stat = statFix(fs.stat), fs.fstat = statFix(fs.fstat), fs.lstat = statFix(fs.lstat), fs.statSync = statFixSync(fs.statSync), fs.fstatSync = statFixSync(fs.fstatSync), fs.lstatSync = statFixSync(fs.lstatSync), fs.chmod && !fs.lchmod && (fs.lchmod = function(path2, mode, cb) {
cb && process.nextTick(cb);
}, fs.lchmodSync = function() {
}), fs.chown && !fs.lchown && (fs.lchown = function(path2, uid, gid, cb) {
cb && process.nextTick(cb);
}, fs.lchownSync = function() {
}), platform === "win32" && (fs.rename = typeof fs.rename != "function" ? fs.rename : (function(fs$rename) {
function rename(from, to, cb) {
var start = Date.now(), 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() {
fs.stat(to, function(stater, st) {
stater && stater.code === "ENOENT" ? fs$rename(from, to, CB) : cb(er);
});
}, backoff), backoff < 100 && (backoff += 10);
return;
}
cb && cb(er);
});
}
return Object.setPrototypeOf && Object.setPrototypeOf(rename, fs$rename), rename;
})(fs.rename)), fs.read = typeof fs.read != "function" ? fs.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)
return eagCounter++, fs$read.call(fs, fd, buffer, offset, length, position, callback);
callback_.apply(this, arguments);
};
}
return fs$read.call(fs, fd, buffer, offset, length, position, callback);
}
return Object.setPrototypeOf && Object.setPrototypeOf(read, fs$read), read;
})(fs.read), fs.readSync = typeof fs.readSync != "function" ? fs.readSync : /* @__PURE__ */ (function(fs$readSync) {
return function(fd, buffer, offset, length, position) {
for (var eagCounter = 0; ; )
try {
return fs$readSync.call(fs, fd, buffer, offset, length, position);
} catch (er) {
if (er.code === "EAGAIN" && eagCounter < 10) {
eagCounter++;
continue;
}
throw er;
}
};
})(fs.readSync);
function patchLchmod(fs2) {
fs2.lchmod = function(path2, mode, callback) {
fs2.open(
path2,
constants.O_WRONLY | constants.O_SYMLINK,
mode,
function(err, fd) {
if (err) {
callback && callback(err);
return;
}
fs2.fchmod(fd, mode, function(err2) {
fs2.close(fd, function(err22) {
callback && callback(err2 || err22);
});
});
}
);
}, fs2.lchmodSync = function(path2, mode) {
var fd = fs2.openSync(path2, constants.O_WRONLY | constants.O_SYMLINK, mode), threw = !0, ret;
try {
ret = fs2.fchmodSync(fd, mode), threw = !1;
} finally {
if (threw)
try {
fs2.closeSync(fd);
} catch {
}
else
fs2.closeSync(fd);
}
return ret;
};
}
function patchLutimes(fs2) {
constants.hasOwnProperty("O_SYMLINK") && fs2.futimes ? (fs2.lutimes = function(path2, at, mt, cb) {
fs2.open(path2, constants.O_SYMLINK, function(er, fd) {
if (er) {
cb && cb(er);
return;
}
fs2.futimes(fd, at, mt, function(er2) {
fs2.close(fd, function(er22) {
cb && cb(er2 || er22);
});
});
});
}, fs2.lutimesSync = function(path2, at, mt) {
var fd = fs2.openSync(path2, constants.O_SYMLINK), ret, threw = !0;
try {
ret = fs2.futimesSync(fd, at, mt), threw = !1;
} finally {
if (threw)
try {
fs2.closeSync(fd);
} catch {
}
else
fs2.closeSync(fd);
}
return ret;
}) : fs2.futimes && (fs2.lutimes = function(_a, _b, _c, cb) {
cb && process.nextTick(cb);
}, fs2.lutimesSync = function() {
});
}
function chmodFix(orig) {
return orig && function(target, mode, cb) {
return orig.call(fs, target, mode, function(er) {
chownErOk(er) && (er = null), cb && cb.apply(this, arguments);
});
};
}
function chmodFixSync(orig) {
return orig && function(target, mode) {
try {
return orig.call(fs, target, mode);
} catch (er) {
if (!chownErOk(er)) throw er;
}
};
}
function chownFix(orig) {
return orig && function(target, uid, gid, cb) {
return orig.call(fs, target, uid, gid, function(er) {
chownErOk(er) && (er = null), cb && cb.apply(this, arguments);
});
};
}
function chownFixSync(orig) {
return orig && function(target, uid, gid) {
try {
return orig.call(fs, target, uid, gid);
} catch (er) {
if (!chownErOk(er)) throw er;
}
};
}
function statFix(orig) {
return orig && function(target, options, cb) {
typeof options == "function" && (cb = options, options = null);
function callback(er, stats) {
stats && (stats.uid < 0 && (stats.uid += 4294967296), stats.gid < 0 && (stats.gid += 4294967296)), cb && cb.apply(this, arguments);
}
return options ? orig.call(fs, target, options, callback) : orig.call(fs, target, callback);
};
}
function statFixSync(orig) {
return orig && function(target, options) {
var stats = options ? orig.call(fs, target, options) : orig.call(fs, target);
return stats && (stats.uid < 0 && (stats.uid += 4294967296), stats.gid < 0 && (stats.gid += 4294967296)), stats;
};
}
function chownErOk(er) {
if (!er || er.code === "ENOSYS")
return !0;
var nonroot = !process.getuid || process.getuid() !== 0;
return !!(nonroot && (er.code === "EINVAL" || er.code === "EPERM"));
}
}
}
});
// ../../node_modules/graceful-fs/legacy-streams.js
var require_legacy_streams = __commonJS({
"../../node_modules/graceful-fs/legacy-streams.js"(exports, module) {
var Stream = __require("stream").Stream;
module.exports = legacy;
function legacy(fs) {
return {
ReadStream,
WriteStream
};
function ReadStream(path2, options) {
if (!(this instanceof ReadStream)) return new ReadStream(path2, options);
Stream.call(this);
var self2 = this;
this.path = path2, this.fd = null, this.readable = !0, this.paused = !1, this.flags = "r", this.mode = 438, this.bufferSize = 64 * 1024, options = options || {};
for (var keys = Object.keys(options), index = 0, length = keys.length; index < length; index++) {
var key = keys[index];
this[key] = options[key];
}
if (this.encoding && this.setEncoding(this.encoding), this.start !== void 0) {
if (typeof this.start != "number")
throw TypeError("start must be a Number");
if (this.end === void 0)
this.end = 1 / 0;
else if (typeof this.end != "number")
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() {
self2._read();
});
return;
}
fs.open(this.path, this.flags, this.mode, function(err, fd) {
if (err) {
self2.emit("error", err), self2.readable = !1;
return;
}
self2.fd = fd, self2.emit("open", fd), self2._read();
});
}
function WriteStream(path2, options) {
if (!(this instanceof WriteStream)) return new WriteStream(path2, options);
Stream.call(this), this.path = path2, this.fd = null, this.writable = !0, this.flags = "w", this.encoding = "binary", this.mode = 438, this.bytesWritten = 0, options = options || {};
for (var keys = Object.keys(options), index = 0, length = keys.length; index < length; index++) {
var key = keys[index];
this[key] = options[key];
}
if (this.start !== void 0) {
if (typeof this.start != "number")
throw TypeError("start must be a Number");
if (this.start < 0)
throw new Error("start must be >= zero");
this.pos = this.start;
}
this.busy = !1, this._queue = [], this.fd === null && (this._open = fs.open, this._queue.push([this._open, this.path, this.flags, this.mode, void 0]), this.flush());
}
}
}
});
// ../../node_modules/graceful-fs/clone.js
var require_clone = __commonJS({
"../../node_modules/graceful-fs/clone.js"(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);
return Object.getOwnPropertyNames(obj).forEach(function(key) {
Object.defineProperty(copy, key, Object.getOwnPropertyDescriptor(obj, key));
}), copy;
}
}
});
// ../../node_modules/graceful-fs/graceful-fs.js
var require_graceful_fs = __commonJS({
"../../node_modules/graceful-fs/graceful-fs.js"(exports, module) {
var fs = __require("fs"), polyfills = require_polyfills(), legacy = require_legacy_streams(), clone = require_clone(), util = __require("util"), gracefulQueue, previousSymbol;
typeof Symbol == "function" && typeof Symbol.for == "function" ? (gracefulQueue = Symbol.for("graceful-fs.queue"), previousSymbol = Symbol.for("graceful-fs.previous")) : (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;
util.debuglog ? debug = util.debuglog("gfs4") : /\bgfs4\b/i.test(process.env.NODE_DEBUG || "") && (debug = function() {
var m = util.format.apply(util, arguments);
m = "GFS4: " + m.split(/\n/).join(`
GFS4: `), console.error(m);
});
fs[gracefulQueue] || (queue = global[gracefulQueue] || [], publishQueue(fs, queue), fs.close = (function(fs$close) {
function close(fd, cb) {
return fs$close.call(fs, fd, function(err) {
err || resetQueue(), typeof cb == "function" && cb.apply(this, arguments);
});
}
return Object.defineProperty(close, previousSymbol, {
value: fs$close
}), close;
})(fs.close), fs.closeSync = (function(fs$closeSync) {
function closeSync(fd) {
fs$closeSync.apply(fs, arguments), resetQueue();
}
return Object.defineProperty(closeSync, previousSymbol, {
value: fs$closeSync
}), closeSync;
})(fs.closeSync), /\bgfs4\b/i.test(process.env.NODE_DEBUG || "") && process.on("exit", function() {
debug(fs[gracefulQueue]), __require("assert").equal(fs[gracefulQueue].length, 0);
}));
var queue;
global[gracefulQueue] || publishQueue(global, fs[gracefulQueue]);
module.exports = patch(clone(fs));
process.env.TEST_GRACEFUL_FS_GLOBAL_PATCH && !fs.__patched && (module.exports = patch(fs), fs.__patched = !0);
function patch(fs2) {
polyfills(fs2), fs2.gracefulify = patch, fs2.createReadStream = createReadStream, fs2.createWriteStream = createWriteStream2;
var fs$readFile = fs2.readFile;
fs2.readFile = readFile5;
function readFile5(path2, options, cb) {
return typeof options == "function" && (cb = options, options = null), go$readFile(path2, options, cb);
function go$readFile(path3, options2, cb2, startTime) {
return fs$readFile(path3, options2, function(err) {
err && (err.code === "EMFILE" || err.code === "ENFILE") ? enqueue([go$readFile, [path3, options2, cb2], err, startTime || Date.now(), Date.now()]) : typeof cb2 == "function" && cb2.apply(this, arguments);
});
}
}
var fs$writeFile = fs2.writeFile;
fs2.writeFile = writeFile5;
function writeFile5(path2, data, options, cb) {
return typeof options == "function" && (cb = options, options = null), go$writeFile(path2, data, options, cb);
function go$writeFile(path3, data2, options2, cb2, startTime) {
return fs$writeFile(path3, data2, options2, function(err) {
err && (err.code === "EMFILE" || err.code === "ENFILE") ? enqueue([go$writeFile, [path3, data2, options2, cb2], err, startTime || Date.now(), Date.now()]) : typeof cb2 == "function" && cb2.apply(this, arguments);
});
}
}
var fs$appendFile = fs2.appendFile;
fs$appendFile && (fs2.appendFile = appendFile);
function appendFile(path2, data, options, cb) {
return typeof options == "function" && (cb = options, options = null), go$appendFile(path2, data, options, cb);
function go$appendFile(path3, data2, options2, cb2, startTime) {
return fs$appendFile(path3, data2, options2, function(err) {
err && (err.code === "EMFILE" || err.code === "ENFILE") ? enqueue([go$appendFile, [path3, data2, options2, cb2], err, startTime || Date.now(), Date.now()]) : typeof cb2 == "function" && cb2.apply(this, arguments);
});
}
}
var fs$copyFile = fs2.copyFile;
fs$copyFile && (fs2.copyFile = copyFile);
function copyFile(src, dest, flags, cb) {
return typeof flags == "function" && (cb = flags, flags = 0), go$copyFile(src, dest, flags, cb);
function go$copyFile(src2, dest2, flags2, cb2, startTime) {
return fs$copyFile(src2, dest2, flags2, function(err) {
err && (err.code === "EMFILE" || err.code === "ENFILE") ? enqueue([go$copyFile, [src2, dest2, flags2, cb2], err, startTime || Date.now(), Date.now()]) : typeof cb2 == "function" && cb2.apply(this, arguments);
});
}
}
var fs$readdir = fs2.readdir;
fs2.readdir = readdir;
var noReaddirOptionVersions = /^v[0-5]\./;
function readdir(path2, options, cb) {
typeof options == "function" && (cb = options, options = null);
var go$readdir = noReaddirOptionVersions.test(process.version) ? function(path3, options2, cb2, startTime) {
return fs$readdir(path3, fs$readdirCallback(
path3,
options2,
cb2,
startTime
));
} : function(path3, options2, cb2, startTime) {
return fs$readdir(path3, options2, fs$readdirCallback(
path3,
options2,
cb2,
startTime
));
};
return go$readdir(path2, options, cb);
function fs$readdirCallback(path3, options2, cb2, startTime) {
return function(err, files) {
err && (err.code === "EMFILE" || err.code === "ENFILE") ? enqueue([
go$readdir,
[path3, options2, cb2],
err,
startTime || Date.now(),
Date.now()
]) : (files && files.sort && files.sort(), typeof cb2 == "function" && cb2.call(this, err, files));
};
}
}
if (process.version.substr(0, 4) === "v0.8") {
var legStreams = legacy(fs2);
ReadStream = legStreams.ReadStream, WriteStream = legStreams.WriteStream;
}
var fs$ReadStream = fs2.ReadStream;
fs$ReadStream && (ReadStream.prototype = Object.create(fs$ReadStream.prototype), ReadStream.prototype.open = ReadStream$open);
var fs$WriteStream = fs2.WriteStream;
fs$WriteStream && (WriteStream.prototype = Object.create(fs$WriteStream.prototype), WriteStream.prototype.open = WriteStream$open), Object.defineProperty(fs2, "ReadStream", {
get: function() {
return ReadStream;
},
set: function(val) {
ReadStream = val;
},
enumerable: !0,
configurable: !0
}), Object.defineProperty(fs2, "WriteStream", {
get: function() {
return WriteStream;
},
set: function(val) {
WriteStream = val;
},
enumerable: !0,
configurable: !0
});
var FileReadStream = ReadStream;
Object.defineProperty(fs2, "FileReadStream", {
get: function() {
return FileReadStream;
},
set: function(val) {
FileReadStream = val;
},
enumerable: !0,
configurable: !0
});
var FileWriteStream = WriteStream;
Object.defineProperty(fs2, "FileWriteStream", {
get: function() {
return FileWriteStream;
},
set: function(val) {
FileWriteStream = val;
},
enumerable: !0,
configurable: !0
});
function ReadStream(path2, options) {
return this instanceof ReadStream ? (fs$ReadStream.apply(this, arguments), this) : ReadStream.apply(Object.create(ReadStream.prototype), arguments);
}
function ReadStream$open() {
var that = this;
open3(that.path, that.flags, that.mode, function(err, fd) {
err ? (that.autoClose && that.destroy(), that.emit("error", err)) : (that.fd = fd, that.emit("open", fd), that.read());
});
}
function WriteStream(path2, options) {
return this instanceof WriteStream ? (fs$WriteStream.apply(this, arguments), this) : WriteStream.apply(Object.create(WriteStream.prototype), arguments);
}
function WriteStream$open() {
var that = this;
open3(that.path, that.flags, that.mode, function(err, fd) {
err ? (that.destroy(), that.emit("error", err)) : (that.fd = fd, that.emit("open", fd));
});
}
function createReadStream(path2, options) {
return new fs2.ReadStream(path2, options);
}
function createWriteStream2(path2, options) {
return new fs2.WriteStream(path2, options);
}
var fs$open = fs2.open;
fs2.open = open3;
function open3(path2, flags, mode, cb) {
return typeof mode == "function" && (cb = mode, mode = null), go$open(path2, flags, mode, cb);
function go$open(path3, flags2, mode2, cb2, startTime) {
return fs$open(path3, flags2, mode2, function(err, fd) {
err && (err.code === "EMFILE" || err.code === "ENFILE") ? enqueue([go$open, [path3, flags2, mode2, cb2], err, startTime || Date.now(), Date.now()]) : typeof cb2 == "function" && cb2.apply(this, arguments);
});
}
}
return fs2;
}
function enqueue(elem) {
debug("ENQUEUE", elem[0].name, elem[1]), fs[gracefulQueue].push(elem), retry();
}
var retryTimer;
function resetQueue() {
for (var now = Date.now(), i = 0; i < fs[gracefulQueue].length; ++i)
fs[gracefulQueue][i].length > 2 && (fs[gracefulQueue][i][3] = now, fs[gracefulQueue][i][4] = now);
retry();
}
function retry() {
if (clearTimeout(retryTimer), retryTimer = void 0, fs[gracefulQueue].length !== 0) {
var elem = fs[gracefulQueue].shift(), fn = elem[0], args = elem[1], err = elem[2], startTime = elem[3], 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();
typeof cb == "function" && cb.call(null, err);
} else {
var sinceAttempt = Date.now() - lastTime, sinceStart = Math.max(lastTime - startTime, 1), desiredDelay = Math.min(sinceStart * 1.2, 100);
sinceAttempt >= desiredDelay ? (debug("RETRY", fn.name, args), fn.apply(null, args.concat([startTime]))) : fs[gracefulQueue].push(elem);
}
retryTimer === void 0 && (retryTimer = setTimeout(retry, 0));
}
}
}
});
// ../../node_modules/watchpack/lib/reducePlan.js
var require_reducePlan = __commonJS({
"../../node_modules/watchpack/lib/reducePlan.js"(exports, module) {
"use strict";
var path2 = __require("path");
module.exports = (plan, limit) => {
let treeMap = /* @__PURE__ */ new Map();
for (let [target, value] of plan)
treeMap.set(target, {
target,
parent: void 0,
children: void 0,
entries: 1,
active: !0,
value
});
let currentCount = treeMap.size;
for (let node of treeMap.values()) {
let parentPath = path2.dirname(node.target);
if (parentPath !== node.target) {
let parent = treeMap.get(parentPath);
if (parent === void 0)
parent = {
target: parentPath,
parent: void 0,
children: [node],
entries: node.entries,
active: !1,
value: void 0
}, treeMap.set(parentPath, parent), node.parent = parent;
else {
node.parent = parent, parent.children === void 0 ? parent.children = [node] : parent.children.push(node);
do
parent.entries += node.entries, parent = parent.parent;
while (parent);
}
}
}
for (; currentCount > limit; ) {
let overLimit = currentCount - limit, bestNode, bestCost = 1 / 0;
for (let node of treeMap.values()) {
if (node.entries <= 1 || !node.children || !node.parent || node.children.length === 0 || node.children.length === 1 && !node.value) continue;
let cost = node.entries - 1 >= overLimit ? node.entries - 1 - overLimit : overLimit - node.entries + 1 + limit * 0.3;
cost < bestCost && (bestNode = node, bestCost = cost);
}
if (!bestNode) break;
let reduction = bestNode.entries - 1;
bestNode.active = !0, bestNode.entries = 1, currentCount -= reduction;
let { parent } = bestNode;
for (; parent; )
parent.entries -= reduction, parent = parent.parent;
let queue = new Set(bestNode.children);
for (let node of queue)
if (node.active = !1, node.entries = 0, node.children)
for (let child of node.children) queue.add(child);
}
let newPlan = /* @__PURE__ */ new Map();
for (let rootNode of treeMap.values()) {
if (!rootNode.active) continue;
let map = /* @__PURE__ */ new Map(), queue = /* @__PURE__ */ new Set([rootNode]);
for (let node of queue)
if (!(node.active && node !== rootNode)) {
if (node.value)
if (Array.isArray(node.value))
for (let item of node.value)
map.set(item, node.target);
else
map.set(node.value, node.target);
if (node.children)
for (let child of node.children)
queue.add(child);
}
newPlan.set(rootNode.target, map);
}
return newPlan;
};
}
});
// ../../node_modules/watchpack/lib/watchEventSource.js
var require_watchEventSource = __commonJS({
"../../node_modules/watchpack/lib/watchEventSource.js"(exports, module) {
"use strict";
var { EventEmitter } = __require("events"), fs = __require("fs"), path2 = __require("path"), reducePlan = require_reducePlan(), IS_OSX = __require("os").platform() === "darwin", IS_WIN = __require("os").platform() === "win32", SUPPORTS_RECURSIVE_WATCHING = IS_OSX || IS_WIN, watcherLimit = (
// @ts-expect-error avoid additional checks
+process.env.WATCHPACK_WATCHER_LIMIT || (IS_OSX ? 20 : 1e4)
), recursiveWatcherLogging = !!process.env.WATCHPACK_RECURSIVE_WATCHER_LOGGING, isBatch = !1, watcherCount = 0, pendingWatchers = /* @__PURE__ */ new Map(), recursiveWatchers = /* @__PURE__ */ new Map(), directWatchers = /* @__PURE__ */ new Map(), underlyingWatcher = /* @__PURE__ */ new Map();
function createEPERMError(filePath) {
let error = (
/** @type {NodeJS.ErrnoException} */
new Error(`Operation not permitted: ${filePath}`)
);
return error.code = "EPERM", error;
}
function createHandleChangeEvent(watcher, filePath, handleChangeEvent) {
return (type, filename) => {
if (type === "rename" && path2.isAbsolute(filename) && path2.basename(filename) === path2.basename(filePath)) {
IS_OSX || watcher.emit("error", createEPERMError(filename));
return;
}
handleChangeEvent(type, filename);
};
}
var DirectWatcher = class {
/**
* @param {string} filePath file path
*/
constructor(filePath) {
this.filePath = filePath, this.watchers = /* @__PURE__ */ new Set(), this.watcher = void 0;
try {
let watcher = fs.watch(filePath);
this.watcher = watcher;
let handleChangeEvent = createHandleChangeEvent(
watcher,
filePath,
(type, filename) => {
for (let w of this.watchers)
w.emit("change", type, filename);
}
);
watcher.on("change", handleChangeEvent), watcher.on("error", (error) => {
for (let w of this.watchers)
w.emit("error", error);
});
} catch (err) {
process.nextTick(() => {
for (let w of this.watchers)
w.emit("error", err);
});
}
watcherCount++;
}
/**
* @param {Watcher} watcher a watcher
*/
add(watcher) {
underlyingWatcher.set(watcher, this), this.watchers.add(watcher);
}
/**
* @param {Watcher} watcher a watcher
*/
remove(watcher) {
this.watchers.delete(watcher), this.watchers.size === 0 && (directWatchers.delete(this.filePath), watcherCount--, this.watcher && this.watcher.close());
}
getWatchers() {
return this.watchers;
}
}, RecursiveWatcher = class {
/**
* @param {string} rootPath a root path
*/
constructor(rootPath) {
this.rootPath = rootPath, this.mapWatcherToPath = /* @__PURE__ */ new Map(), this.mapPathToWatchers = /* @__PURE__ */ new Map(), this.watcher = void 0;
try {
let watcher = fs.watch(rootPath, {
recursive: !0
});
this.watcher = watcher, watcher.on("change", (type, filename) => {
if (filename) {
let dir = path2.dirname(
/** @type {string} */
filename
), watchers = this.mapPathToWatchers.get(dir);
if (recursiveWatcherLogging && process.stderr.write(
`[watchpack] dispatch ${type} event in recursive watcher (${this.rootPath}) for '${filename}' to ${watchers ? watchers.size : 0} watchers
`
), watchers === void 0) return;
for (let w of watchers)
w.emit(
"change",
/** @type {EventType} */
type,
path2.basename(
/** @type {string} */
filename
)
);
} else {
recursiveWatcherLogging && process.stderr.write(
`[watchpack] dispatch ${type} event in recursive watcher (${this.rootPath}) to all watchers
`
);
for (let w of this.mapWatcherToPath.keys())
w.emit(
"change",
/** @type {EventType} */
type
);
}
}), watcher.on("error", (error) => {
for (let w of this.mapWatcherToPath.keys())
w.emit("error", error);
});
} catch (err) {
process.nextTick(() => {
for (let w of this.mapWatcherToPath.keys())
w.emit("error", err);
});
}
watcherCount++, recursiveWatcherLogging && process.stderr.write(
`[watchpack] created recursive watcher at ${rootPath}
`
);
}
/**
* @param {string} filePath a file path
* @param {Watcher} watcher a watcher
*/
add(filePath, watcher) {
underlyingWatcher.set(watcher, this);
let subpath = filePath.slice(this.rootPath.length + 1) || ".";
this.mapWatcherToPath.set(watcher, subpath);
let set = this.mapPathToWatchers.get(subpath);
if (set === void 0) {
let newSet = /* @__PURE__ */ new Set();
newSet.add(watcher), this.mapPathToWatchers.set(subpath, newSet);
} else
set.add(watcher);
}
/**
* @param {Watcher} watcher a watcher
*/
remove(watcher) {
let subpath = this.mapWatcherToPath.get(watcher);
if (!subpath) return;
this.mapWatcherToPath.delete(watcher);
let set = (
/** @type {WatcherSet} */
this.mapPathToWatchers.get(subpath)
);
set.delete(watcher), set.size === 0 && this.mapPathToWatchers.delete(subpath), this.mapWatcherToPath.size === 0 && (recursiveWatchers.delete(this.rootPath), watcherCount--, this.watcher && this.watcher.close(), recursiveWatcherLogging && process.stderr.write(
`[watchpack] closed recursive watcher at ${this.rootPath}
`
));
}
getWatchers() {
return this.mapWatcherToPath;
}
}, Watcher = class extends EventEmitter {
constructor() {
super();
}
close() {
if (pendingWatchers.has(this)) {
pendingWatchers.delete(this);
return;
}
underlyingWatcher.get(this).remove(this), underlyingWatcher.delete(this);
}
}, createDirectWatcher = (filePath) => {
let existing = directWatchers.get(filePath);
if (existing !== void 0) return existing;
let w = new DirectWatcher(filePath);
return directWatchers.set(filePath, w), w;
}, createRecursiveWatcher = (rootPath) => {
let existing = recursiveWatchers.get(rootPath);
if (existing !== void 0) return existing;
let w = new RecursiveWatcher(rootPath);
return recursiveWatchers.set(rootPath, w), w;
}, execute = () => {
let map = /* @__PURE__ */ new Map(), addWatcher = (watcher, filePath) => {
let entry = map.get(filePath);
entry === void 0 ? map.set(filePath, watcher) : Array.isArray(entry) ? entry.push(watcher) : map.set(filePath, [entry, watcher]);
};
for (let [watcher, filePath] of pendingWatchers)
addWatcher(watcher, filePath);
if (pendingWatchers.clear(), !SUPPORTS_RECURSIVE_WATCHING || watcherLimit - watcherCount >= map.size) {
for (let [filePath, entry] of map) {
let w = createDirectWatcher(filePath);
if (Array.isArray(entry))
for (let item of entry) w.add(item);
else
w.add(entry);
}
return;
}
for (let watcher of recursiveWatchers.values())
for (let [w, subpath] of watcher.getWatchers())
addWatcher(w, path2.join(watcher.rootPath, subpath));
for (let watcher of directWatchers.values())
for (let w of watcher.getWatchers())
addWatcher(w, watcher.filePath);
let plan = reducePlan(map, watcherLimit * 0.9);
for (let [filePath, entry] of plan)
if (entry.size === 1)
for (let [watcher, filePath2] of entry) {
let w = createDirectWatcher(filePath2), old = underlyingWatcher.get(watcher);
old !== w && (w.add(watcher), old !== void 0 && old.remove(watcher));
}
else {
let filePaths = new Set(entry.values());
if (filePaths.size > 1) {
let w = createRecursiveWatcher(filePath);
for (let [watcher, watcherPath] of entry) {
let old = underlyingWatcher.get(watcher);
old !== w && (w.add(watcherPath, watcher), old !== void 0 && old.remove(watcher));
}
} else
for (let filePath2 of filePaths) {
let w = createDirectWatcher(filePath2);
for (let watcher of entry.keys()) {
let old = underlyingWatcher.get(watcher);
old !== w && (w.add(watcher), old !== void 0 && old.remove(watcher));
}
}
}
};
module.exports.Watcher = Watcher;
module.exports.batch = (fn) => {
isBatch = !0;
try {
fn();
} finally {
isBatch = !1, execute();
}
};
module.exports.createHandleChangeEvent = createHandleChangeEvent;
module.exports.getNumberOfWatchers = () => watcherCount;
module.exports.watch = (filePath) => {
let watcher = new Watcher(), directWatcher = directWatchers.get(filePath);
if (directWatcher !== void 0)
return directWatcher.add(watcher), watcher;
let current = filePath;
for (; ; ) {
let recursiveWatcher = recursiveWatchers.get(current);
if (recursiveWatcher !== void 0)
return recursiveWatcher.add(filePath, watcher), watcher;
let parent = path2.dirname(current);
if (parent === current) break;
current = parent;
}
return pendingWatchers.set(watcher, filePath), isBatch || execute(), watcher;
};
module.exports.watcherLimit = watcherLimit;
}
});
// ../../node_modules/watchpack/lib/DirectoryWatcher.js
var require_DirectoryWatcher = __commonJS({
"../../node_modules/watchpack/lib/DirectoryWatcher.js"(exports, module) {
"use strict";
var { EventEmitter } = __require("events"), path2 = __require("path"), fs = require_graceful_fs(), watchEventSource = require_watchEventSource(), EXISTANCE_ONLY_TIME_ENTRY = Object.freeze({}), FS_ACCURACY = 2e3, IS_OSX = __require("os").platform() === "darwin", IS_WIN = __require("os").platform() === "win32", { WATCHPACK_POLLING } = process.env, FORCE_POLLING = (
// @ts-expect-error avoid additional checks
`${+WATCHPACK_POLLING}` === WATCHPACK_POLLING ? +WATCHPACK_POLLING : !!WATCHPACK_POLLING && WATCHPACK_POLLING !== "false"
);
function withoutCase(str) {
return str.toLowerCase();
}
function needCalls(times, callback) {
return function() {
if (--times === 0)
return callback();
};
}
function fixupEntryAccuracy(entry) {
entry.accuracy > FS_ACCURACY && (entry.safeTime = entry.safeTime - entry.accuracy + FS_ACCURACY, entry.accuracy = FS_ACCURACY);
}
function ensureFsAccuracy(mtime) {
mtime && (FS_ACCURACY > 1 && mtime % 1 !== 0 ? FS_ACCURACY = 1 : FS_ACCURACY > 10 && mtime % 10 !== 0 ? FS_ACCURACY = 10 : FS_ACCURACY > 100 && mtime % 100 !== 0 ? FS_ACCURACY = 100 : FS_ACCURACY > 1e3 && mtime % 1e3 !== 0 && (FS_ACCURACY = 1e3));
}
var Watcher = class extends EventEmitter {
/**
* @param {DirectoryWatcher} directoryWatcher a directory watcher
* @param {string} target a target to watch
* @param {number=} startTime start time
*/
constructor(directoryWatcher, target, startTime) {
super(), this.directoryWatcher = directoryWatcher, this.path = target, this.startTime = startTime && +startTime;
}
/**
* @param {number} mtime mtime
* @param {boolean} initial true when initial, otherwise false
* @returns {boolean} true of start time less than mtile, otherwise false
*/
checkStartTime(mtime, initial) {
let { startTime } = this;
return typeof startTime != "number" ? !initial : startTime <= mtime;
}
close() {
this.emit("closed");
}
}, DirectoryWatcher = class extends EventEmitter {
/**
* @param {WatcherManager} watcherManager a watcher manager
* @param {string} directoryPath directory path
* @param {DirectoryWatcherOptions=} options options
*/
constructor(watcherManager, directoryPath, options = {}) {
super(), FORCE_POLLING && (options.poll = FORCE_POLLING), this.watcherManager = watcherManager, this.options = options, this.path = directoryPath, this.files = /* @__PURE__ */ new Map(), this.filesWithoutCase = /* @__PURE__ */ new Map(), this.directories = /* @__PURE__ */ new Map(), this.lastWatchEvent = 0, this.initialScan = !0, this.ignored = options.ignored || (() => !1), this.nestedWatching = !1, this.polledWatching = typeof options.poll == "number" ? options.poll : options.poll ? 5007 : !1, this.timeout = void 0, this.initialScanRemoved = /* @__PURE__ */ new Set(), this.initialScanFinished = void 0, this.watchers = /* @__PURE__ */ new Map(), this.parentWatcher = null, this.refs = 0, this._activeEvents = /* @__PURE__ */ new Map(), this.closed = !1, this.scanning = !1, this.scanAgain = !1, this.scanAgainInitial = !1, this.createWatcher(), this.doScan(!0);
}
createWatcher() {
try {
this.polledWatching ? this.watcher = /** @type {EventSourceWatcher} */
{
close: () => {
this.timeout && (clearTimeout(this.timeout), this.timeout = void 0);
}
} : (IS_OSX && this.watchInParentDirectory(), this.watcher = /** @type {EventSourceWatcher} */
watchEventSource.watch(this.path), this.watcher.on("change", this.onWatchEvent.bind(this)), this.watcher.on("error", this.onWatcherError.bind(this)));
} catch (err) {
this.onWatcherError(err);
}
}
/**
* @template {(watcher: Watcher<EventMap>) => void} T
* @param {string} path path
* @param {T} fn function
*/
forEachWatcher(path3, fn) {
let watchers = this.watchers.get(withoutCase(path3));
if (watchers !== void 0)
for (let w of watchers)
fn(w);
}
/**
* @param {string} itemPath an item path
* @param {boolean} initial true when initial, otherwise false
* @param {EventType} type even type
*/
setMissing(itemPath, initial, type) {
this.initialScan && this.initialScanRemoved.add(itemPath);
let oldDirectory = this.directories.get(itemPath);
if (oldDirectory && (this.nestedWatching && oldDirectory.close(), this.directories.delete(itemPath), this.forEachWatcher(itemPath, (w) => w.emit("remove", type)), initial || this.forEachWatcher(
this.path,
(w) => w.emit("change", itemPath, null, type, initial)
)), this.files.get(itemPath)) {
this.files.delete(itemPath);
let key = withoutCase(itemPath), count = (
/** @type {number} */
this.filesWithoutCase.get(key) - 1
);
count <= 0 ? (this.filesWithoutCase.delete(key), this.forEachWatcher(itemPath, (w) => w.emit("remove", type))) : this.filesWithoutCase.set(key, count), initial || this.forEachWatcher(
this.path,
(w) => w.emit("change", itemPath, null, type, initial)
);
}
}
/**
* @param {string} target a target to set file time
* @param {number} mtime mtime
* @param {boolean} initial true when initial, otherwise false
* @param {boolean} ignoreWhenEqual true to ignore when equal, otherwise false
* @param {EventType} type type
*/
setFileTime(target, mtime, initial, ignoreWhenEqual, type) {
let now = Date.now();
if (this.ignored(target)) return;
let old = this.files.get(target), safeTime, accuracy;
if (initial)
safeTime = Math.min(now, mtime) + FS_ACCURACY, accuracy = FS_ACCURACY;
else if (safeTime = now, accuracy = 0, old && old.timestamp === mtime && mtime + FS_ACCURACY < now)
return;
if (!(ignoreWhenEqual && old && old.timestamp === mtime)) {
if (this.files.set(target, {
safeTime,
accuracy,
timestamp: mtime
}), old)
initial || this.forEachWatcher(target, (w) => w.emit("change", mtime, type));
else {
let key = withoutCase(target), count = this.filesWithoutCase.get(key);
this.filesWithoutCase.set(key,