Files

3198 lines
99 KiB
JavaScript

/*
THIS IS A GENERATED/BUNDLED FILE BY ESBUILD
if you want to view the source, please visit the github repository of this plugin
*/
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 __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
var __commonJS = (cb, mod) => function __require() {
return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};
var __export = (target, all) => {
__markAsModule(target);
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __reExport = (target, module2, desc) => {
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
for (let key of __getOwnPropNames(module2))
if (!__hasOwnProp.call(target, key) && key !== "default")
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
}
return target;
};
var __toModule = (module2) => {
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
};
var __async = (__this, __arguments, generator) => {
return new Promise((resolve, reject) => {
var fulfilled = (value) => {
try {
step(generator.next(value));
} catch (e) {
reject(e);
}
};
var rejected = (value) => {
try {
step(generator.throw(value));
} catch (e) {
reject(e);
}
};
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
step((generator = generator.apply(__this, __arguments)).next());
});
};
// node_modules/fs.realpath/old.js
var require_old = __commonJS({
"node_modules/fs.realpath/old.js"(exports) {
var pathModule = require("path");
var isWindows = process.platform === "win32";
var fs2 = require("fs");
var DEBUG = process.env.NODE_DEBUG && /fs/.test(process.env.NODE_DEBUG);
function rethrow() {
var callback;
if (DEBUG) {
var backtrace = new Error();
callback = debugCallback;
} else
callback = missingCallback;
return callback;
function debugCallback(err) {
if (err) {
backtrace.message = err.message;
err = backtrace;
missingCallback(err);
}
}
function missingCallback(err) {
if (err) {
if (process.throwDeprecation)
throw err;
else if (!process.noDeprecation) {
var msg = "fs: missing callback " + (err.stack || err.message);
if (process.traceDeprecation)
console.trace(msg);
else
console.error(msg);
}
}
}
}
function maybeCallback(cb) {
return typeof cb === "function" ? cb : rethrow();
}
var normalize = pathModule.normalize;
if (isWindows) {
nextPartRe = /(.*?)(?:[\/\\]+|$)/g;
} else {
nextPartRe = /(.*?)(?:[\/]+|$)/g;
}
var nextPartRe;
if (isWindows) {
splitRootRe = /^(?:[a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/][^\\\/]+)?[\\\/]*/;
} else {
splitRootRe = /^[\/]*/;
}
var splitRootRe;
exports.realpathSync = function realpathSync(p, cache) {
p = pathModule.resolve(p);
if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
return cache[p];
}
var original = p, seenLinks = {}, knownHard = {};
var pos;
var current;
var base;
var previous;
start();
function start() {
var m = splitRootRe.exec(p);
pos = m[0].length;
current = m[0];
base = m[0];
previous = "";
if (isWindows && !knownHard[base]) {
fs2.lstatSync(base);
knownHard[base] = true;
}
}
while (pos < p.length) {
nextPartRe.lastIndex = pos;
var result = nextPartRe.exec(p);
previous = current;
current += result[0];
base = previous + result[1];
pos = nextPartRe.lastIndex;
if (knownHard[base] || cache && cache[base] === base) {
continue;
}
var resolvedLink;
if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
resolvedLink = cache[base];
} else {
var stat = fs2.lstatSync(base);
if (!stat.isSymbolicLink()) {
knownHard[base] = true;
if (cache)
cache[base] = base;
continue;
}
var linkTarget = null;
if (!isWindows) {
var id = stat.dev.toString(32) + ":" + stat.ino.toString(32);
if (seenLinks.hasOwnProperty(id)) {
linkTarget = seenLinks[id];
}
}
if (linkTarget === null) {
fs2.statSync(base);
linkTarget = fs2.readlinkSync(base);
}
resolvedLink = pathModule.resolve(previous, linkTarget);
if (cache)
cache[base] = resolvedLink;
if (!isWindows)
seenLinks[id] = linkTarget;
}
p = pathModule.resolve(resolvedLink, p.slice(pos));
start();
}
if (cache)
cache[original] = p;
return p;
};
exports.realpath = function realpath(p, cache, cb) {
if (typeof cb !== "function") {
cb = maybeCallback(cache);
cache = null;
}
p = pathModule.resolve(p);
if (cache && Object.prototype.hasOwnProperty.call(cache, p)) {
return process.nextTick(cb.bind(null, null, cache[p]));
}
var original = p, seenLinks = {}, knownHard = {};
var pos;
var current;
var base;
var previous;
start();
function start() {
var m = splitRootRe.exec(p);
pos = m[0].length;
current = m[0];
base = m[0];
previous = "";
if (isWindows && !knownHard[base]) {
fs2.lstat(base, function(err) {
if (err)
return cb(err);
knownHard[base] = true;
LOOP();
});
} else {
process.nextTick(LOOP);
}
}
function LOOP() {
if (pos >= p.length) {
if (cache)
cache[original] = p;
return cb(null, p);
}
nextPartRe.lastIndex = pos;
var result = nextPartRe.exec(p);
previous = current;
current += result[0];
base = previous + result[1];
pos = nextPartRe.lastIndex;
if (knownHard[base] || cache && cache[base] === base) {
return process.nextTick(LOOP);
}
if (cache && Object.prototype.hasOwnProperty.call(cache, base)) {
return gotResolvedLink(cache[base]);
}
return fs2.lstat(base, gotStat);
}
function gotStat(err, stat) {
if (err)
return cb(err);
if (!stat.isSymbolicLink()) {
knownHard[base] = true;
if (cache)
cache[base] = base;
return process.nextTick(LOOP);
}
if (!isWindows) {
var id = stat.dev.toString(32) + ":" + stat.ino.toString(32);
if (seenLinks.hasOwnProperty(id)) {
return gotTarget(null, seenLinks[id], base);
}
}
fs2.stat(base, function(err2) {
if (err2)
return cb(err2);
fs2.readlink(base, function(err3, target) {
if (!isWindows)
seenLinks[id] = target;
gotTarget(err3, target);
});
});
}
function gotTarget(err, target, base2) {
if (err)
return cb(err);
var resolvedLink = pathModule.resolve(previous, target);
if (cache)
cache[base2] = resolvedLink;
gotResolvedLink(resolvedLink);
}
function gotResolvedLink(resolvedLink) {
p = pathModule.resolve(resolvedLink, p.slice(pos));
start();
}
};
}
});
// node_modules/fs.realpath/index.js
var require_fs = __commonJS({
"node_modules/fs.realpath/index.js"(exports, module2) {
module2.exports = realpath;
realpath.realpath = realpath;
realpath.sync = realpathSync;
realpath.realpathSync = realpathSync;
realpath.monkeypatch = monkeypatch;
realpath.unmonkeypatch = unmonkeypatch;
var fs2 = require("fs");
var origRealpath = fs2.realpath;
var origRealpathSync = fs2.realpathSync;
var version = process.version;
var ok = /^v[0-5]\./.test(version);
var old = require_old();
function newError(er) {
return er && er.syscall === "realpath" && (er.code === "ELOOP" || er.code === "ENOMEM" || er.code === "ENAMETOOLONG");
}
function realpath(p, cache, cb) {
if (ok) {
return origRealpath(p, cache, cb);
}
if (typeof cache === "function") {
cb = cache;
cache = null;
}
origRealpath(p, cache, function(er, result) {
if (newError(er)) {
old.realpath(p, cache, cb);
} else {
cb(er, result);
}
});
}
function realpathSync(p, cache) {
if (ok) {
return origRealpathSync(p, cache);
}
try {
return origRealpathSync(p, cache);
} catch (er) {
if (newError(er)) {
return old.realpathSync(p, cache);
} else {
throw er;
}
}
}
function monkeypatch() {
fs2.realpath = realpath;
fs2.realpathSync = realpathSync;
}
function unmonkeypatch() {
fs2.realpath = origRealpath;
fs2.realpathSync = origRealpathSync;
}
}
});
// node_modules/concat-map/index.js
var require_concat_map = __commonJS({
"node_modules/concat-map/index.js"(exports, module2) {
module2.exports = function(xs, fn) {
var res = [];
for (var i = 0; i < xs.length; i++) {
var x = fn(xs[i], i);
if (isArray(x))
res.push.apply(res, x);
else
res.push(x);
}
return res;
};
var isArray = Array.isArray || function(xs) {
return Object.prototype.toString.call(xs) === "[object Array]";
};
}
});
// node_modules/balanced-match/index.js
var require_balanced_match = __commonJS({
"node_modules/balanced-match/index.js"(exports, module2) {
"use strict";
module2.exports = balanced;
function balanced(a, b, str) {
if (a instanceof RegExp)
a = maybeMatch(a, str);
if (b instanceof RegExp)
b = maybeMatch(b, str);
var r = range(a, b, str);
return r && {
start: r[0],
end: r[1],
pre: str.slice(0, r[0]),
body: str.slice(r[0] + a.length, r[1]),
post: str.slice(r[1] + b.length)
};
}
function maybeMatch(reg, str) {
var m = str.match(reg);
return m ? m[0] : null;
}
balanced.range = range;
function range(a, b, str) {
var begs, beg, left, right, result;
var ai = str.indexOf(a);
var bi = str.indexOf(b, ai + 1);
var i = ai;
if (ai >= 0 && bi > 0) {
if (a === b) {
return [ai, bi];
}
begs = [];
left = str.length;
while (i >= 0 && !result) {
if (i == ai) {
begs.push(i);
ai = str.indexOf(a, i + 1);
} else if (begs.length == 1) {
result = [begs.pop(), bi];
} else {
beg = begs.pop();
if (beg < left) {
left = beg;
right = bi;
}
bi = str.indexOf(b, i + 1);
}
i = ai < bi && ai >= 0 ? ai : bi;
}
if (begs.length) {
result = [left, right];
}
}
return result;
}
}
});
// node_modules/brace-expansion/index.js
var require_brace_expansion = __commonJS({
"node_modules/brace-expansion/index.js"(exports, module2) {
var concatMap = require_concat_map();
var balanced = require_balanced_match();
module2.exports = expandTop;
var escSlash = "\0SLASH" + Math.random() + "\0";
var escOpen = "\0OPEN" + Math.random() + "\0";
var escClose = "\0CLOSE" + Math.random() + "\0";
var escComma = "\0COMMA" + Math.random() + "\0";
var escPeriod = "\0PERIOD" + Math.random() + "\0";
function numeric(str) {
return parseInt(str, 10) == str ? parseInt(str, 10) : str.charCodeAt(0);
}
function escapeBraces(str) {
return str.split("\\\\").join(escSlash).split("\\{").join(escOpen).split("\\}").join(escClose).split("\\,").join(escComma).split("\\.").join(escPeriod);
}
function unescapeBraces(str) {
return str.split(escSlash).join("\\").split(escOpen).join("{").split(escClose).join("}").split(escComma).join(",").split(escPeriod).join(".");
}
function parseCommaParts(str) {
if (!str)
return [""];
var parts = [];
var m = balanced("{", "}", str);
if (!m)
return str.split(",");
var pre = m.pre;
var body = m.body;
var post = m.post;
var p = pre.split(",");
p[p.length - 1] += "{" + body + "}";
var postParts = parseCommaParts(post);
if (post.length) {
p[p.length - 1] += postParts.shift();
p.push.apply(p, postParts);
}
parts.push.apply(parts, p);
return parts;
}
function expandTop(str) {
if (!str)
return [];
if (str.substr(0, 2) === "{}") {
str = "\\{\\}" + str.substr(2);
}
return expand(escapeBraces(str), true).map(unescapeBraces);
}
function embrace(str) {
return "{" + str + "}";
}
function isPadded(el) {
return /^-?0\d/.test(el);
}
function lte(i, y) {
return i <= y;
}
function gte(i, y) {
return i >= y;
}
function expand(str, isTop) {
var expansions = [];
var m = balanced("{", "}", str);
if (!m || /\$$/.test(m.pre))
return [str];
var isNumericSequence = /^-?\d+\.\.-?\d+(?:\.\.-?\d+)?$/.test(m.body);
var isAlphaSequence = /^[a-zA-Z]\.\.[a-zA-Z](?:\.\.-?\d+)?$/.test(m.body);
var isSequence = isNumericSequence || isAlphaSequence;
var isOptions = m.body.indexOf(",") >= 0;
if (!isSequence && !isOptions) {
if (m.post.match(/,.*\}/)) {
str = m.pre + "{" + m.body + escClose + m.post;
return expand(str);
}
return [str];
}
var n;
if (isSequence) {
n = m.body.split(/\.\./);
} else {
n = parseCommaParts(m.body);
if (n.length === 1) {
n = expand(n[0], false).map(embrace);
if (n.length === 1) {
var post = m.post.length ? expand(m.post, false) : [""];
return post.map(function(p) {
return m.pre + n[0] + p;
});
}
}
}
var pre = m.pre;
var post = m.post.length ? expand(m.post, false) : [""];
var N;
if (isSequence) {
var x = numeric(n[0]);
var y = numeric(n[1]);
var width = Math.max(n[0].length, n[1].length);
var incr = n.length == 3 ? Math.abs(numeric(n[2])) : 1;
var test = lte;
var reverse = y < x;
if (reverse) {
incr *= -1;
test = gte;
}
var pad = n.some(isPadded);
N = [];
for (var i = x; test(i, y); i += incr) {
var c;
if (isAlphaSequence) {
c = String.fromCharCode(i);
if (c === "\\")
c = "";
} else {
c = String(i);
if (pad) {
var need = width - c.length;
if (need > 0) {
var z = new Array(need + 1).join("0");
if (i < 0)
c = "-" + z + c.slice(1);
else
c = z + c;
}
}
}
N.push(c);
}
} else {
N = concatMap(n, function(el) {
return expand(el, false);
});
}
for (var j = 0; j < N.length; j++) {
for (var k = 0; k < post.length; k++) {
var expansion = pre + N[j] + post[k];
if (!isTop || isSequence || expansion)
expansions.push(expansion);
}
}
return expansions;
}
}
});
// node_modules/minimatch/minimatch.js
var require_minimatch = __commonJS({
"node_modules/minimatch/minimatch.js"(exports, module2) {
module2.exports = minimatch;
minimatch.Minimatch = Minimatch;
var path = { sep: "/" };
try {
path = require("path");
} catch (er) {
}
var GLOBSTAR = minimatch.GLOBSTAR = Minimatch.GLOBSTAR = {};
var expand = require_brace_expansion();
var plTypes = {
"!": { open: "(?:(?!(?:", close: "))[^/]*?)" },
"?": { open: "(?:", close: ")?" },
"+": { open: "(?:", close: ")+" },
"*": { open: "(?:", close: ")*" },
"@": { open: "(?:", close: ")" }
};
var qmark = "[^/]";
var star = qmark + "*?";
var twoStarDot = "(?:(?!(?:\\/|^)(?:\\.{1,2})($|\\/)).)*?";
var twoStarNoDot = "(?:(?!(?:\\/|^)\\.).)*?";
var reSpecials = charSet("().*{}+?[]^$\\!");
function charSet(s) {
return s.split("").reduce(function(set, c) {
set[c] = true;
return set;
}, {});
}
var slashSplit = /\/+/;
minimatch.filter = filter;
function filter(pattern, options) {
options = options || {};
return function(p, i, list) {
return minimatch(p, pattern, options);
};
}
function ext(a, b) {
a = a || {};
b = b || {};
var t = {};
Object.keys(b).forEach(function(k) {
t[k] = b[k];
});
Object.keys(a).forEach(function(k) {
t[k] = a[k];
});
return t;
}
minimatch.defaults = function(def) {
if (!def || !Object.keys(def).length)
return minimatch;
var orig = minimatch;
var m = function minimatch2(p, pattern, options) {
return orig.minimatch(p, pattern, ext(def, options));
};
m.Minimatch = function Minimatch2(pattern, options) {
return new orig.Minimatch(pattern, ext(def, options));
};
return m;
};
Minimatch.defaults = function(def) {
if (!def || !Object.keys(def).length)
return Minimatch;
return minimatch.defaults(def).Minimatch;
};
function minimatch(p, pattern, options) {
if (typeof pattern !== "string") {
throw new TypeError("glob pattern string required");
}
if (!options)
options = {};
if (!options.nocomment && pattern.charAt(0) === "#") {
return false;
}
if (pattern.trim() === "")
return p === "";
return new Minimatch(pattern, options).match(p);
}
function Minimatch(pattern, options) {
if (!(this instanceof Minimatch)) {
return new Minimatch(pattern, options);
}
if (typeof pattern !== "string") {
throw new TypeError("glob pattern string required");
}
if (!options)
options = {};
pattern = pattern.trim();
if (path.sep !== "/") {
pattern = pattern.split(path.sep).join("/");
}
this.options = options;
this.set = [];
this.pattern = pattern;
this.regexp = null;
this.negate = false;
this.comment = false;
this.empty = false;
this.make();
}
Minimatch.prototype.debug = function() {
};
Minimatch.prototype.make = make;
function make() {
if (this._made)
return;
var pattern = this.pattern;
var options = this.options;
if (!options.nocomment && pattern.charAt(0) === "#") {
this.comment = true;
return;
}
if (!pattern) {
this.empty = true;
return;
}
this.parseNegate();
var set = this.globSet = this.braceExpand();
if (options.debug)
this.debug = console.error;
this.debug(this.pattern, set);
set = this.globParts = set.map(function(s) {
return s.split(slashSplit);
});
this.debug(this.pattern, set);
set = set.map(function(s, si, set2) {
return s.map(this.parse, this);
}, this);
this.debug(this.pattern, set);
set = set.filter(function(s) {
return s.indexOf(false) === -1;
});
this.debug(this.pattern, set);
this.set = set;
}
Minimatch.prototype.parseNegate = parseNegate;
function parseNegate() {
var pattern = this.pattern;
var negate = false;
var options = this.options;
var negateOffset = 0;
if (options.nonegate)
return;
for (var i = 0, l = pattern.length; i < l && pattern.charAt(i) === "!"; i++) {
negate = !negate;
negateOffset++;
}
if (negateOffset)
this.pattern = pattern.substr(negateOffset);
this.negate = negate;
}
minimatch.braceExpand = function(pattern, options) {
return braceExpand(pattern, options);
};
Minimatch.prototype.braceExpand = braceExpand;
function braceExpand(pattern, options) {
if (!options) {
if (this instanceof Minimatch) {
options = this.options;
} else {
options = {};
}
}
pattern = typeof pattern === "undefined" ? this.pattern : pattern;
if (typeof pattern === "undefined") {
throw new TypeError("undefined pattern");
}
if (options.nobrace || !pattern.match(/\{.*\}/)) {
return [pattern];
}
return expand(pattern);
}
Minimatch.prototype.parse = parse;
var SUBPARSE = {};
function parse(pattern, isSub) {
if (pattern.length > 1024 * 64) {
throw new TypeError("pattern is too long");
}
var options = this.options;
if (!options.noglobstar && pattern === "**")
return GLOBSTAR;
if (pattern === "")
return "";
var re = "";
var hasMagic = !!options.nocase;
var escaping = false;
var patternListStack = [];
var negativeLists = [];
var stateChar;
var inClass = false;
var reClassStart = -1;
var classStart = -1;
var patternStart = pattern.charAt(0) === "." ? "" : options.dot ? "(?!(?:^|\\/)\\.{1,2}(?:$|\\/))" : "(?!\\.)";
var self = this;
function clearStateChar() {
if (stateChar) {
switch (stateChar) {
case "*":
re += star;
hasMagic = true;
break;
case "?":
re += qmark;
hasMagic = true;
break;
default:
re += "\\" + stateChar;
break;
}
self.debug("clearStateChar %j %j", stateChar, re);
stateChar = false;
}
}
for (var i = 0, len = pattern.length, c; i < len && (c = pattern.charAt(i)); i++) {
this.debug("%s %s %s %j", pattern, i, re, c);
if (escaping && reSpecials[c]) {
re += "\\" + c;
escaping = false;
continue;
}
switch (c) {
case "/":
return false;
case "\\":
clearStateChar();
escaping = true;
continue;
case "?":
case "*":
case "+":
case "@":
case "!":
this.debug("%s %s %s %j <-- stateChar", pattern, i, re, c);
if (inClass) {
this.debug(" in class");
if (c === "!" && i === classStart + 1)
c = "^";
re += c;
continue;
}
self.debug("call clearStateChar %j", stateChar);
clearStateChar();
stateChar = c;
if (options.noext)
clearStateChar();
continue;
case "(":
if (inClass) {
re += "(";
continue;
}
if (!stateChar) {
re += "\\(";
continue;
}
patternListStack.push({
type: stateChar,
start: i - 1,
reStart: re.length,
open: plTypes[stateChar].open,
close: plTypes[stateChar].close
});
re += stateChar === "!" ? "(?:(?!(?:" : "(?:";
this.debug("plType %j %j", stateChar, re);
stateChar = false;
continue;
case ")":
if (inClass || !patternListStack.length) {
re += "\\)";
continue;
}
clearStateChar();
hasMagic = true;
var pl = patternListStack.pop();
re += pl.close;
if (pl.type === "!") {
negativeLists.push(pl);
}
pl.reEnd = re.length;
continue;
case "|":
if (inClass || !patternListStack.length || escaping) {
re += "\\|";
escaping = false;
continue;
}
clearStateChar();
re += "|";
continue;
case "[":
clearStateChar();
if (inClass) {
re += "\\" + c;
continue;
}
inClass = true;
classStart = i;
reClassStart = re.length;
re += c;
continue;
case "]":
if (i === classStart + 1 || !inClass) {
re += "\\" + c;
escaping = false;
continue;
}
if (inClass) {
var cs = pattern.substring(classStart + 1, i);
try {
RegExp("[" + cs + "]");
} catch (er) {
var sp = this.parse(cs, SUBPARSE);
re = re.substr(0, reClassStart) + "\\[" + sp[0] + "\\]";
hasMagic = hasMagic || sp[1];
inClass = false;
continue;
}
}
hasMagic = true;
inClass = false;
re += c;
continue;
default:
clearStateChar();
if (escaping) {
escaping = false;
} else if (reSpecials[c] && !(c === "^" && inClass)) {
re += "\\";
}
re += c;
}
}
if (inClass) {
cs = pattern.substr(classStart + 1);
sp = this.parse(cs, SUBPARSE);
re = re.substr(0, reClassStart) + "\\[" + sp[0];
hasMagic = hasMagic || sp[1];
}
for (pl = patternListStack.pop(); pl; pl = patternListStack.pop()) {
var tail = re.slice(pl.reStart + pl.open.length);
this.debug("setting tail", re, pl);
tail = tail.replace(/((?:\\{2}){0,64})(\\?)\|/g, function(_, $1, $2) {
if (!$2) {
$2 = "\\";
}
return $1 + $1 + $2 + "|";
});
this.debug("tail=%j\n %s", tail, tail, pl, re);
var t = pl.type === "*" ? star : pl.type === "?" ? qmark : "\\" + pl.type;
hasMagic = true;
re = re.slice(0, pl.reStart) + t + "\\(" + tail;
}
clearStateChar();
if (escaping) {
re += "\\\\";
}
var addPatternStart = false;
switch (re.charAt(0)) {
case ".":
case "[":
case "(":
addPatternStart = true;
}
for (var n = negativeLists.length - 1; n > -1; n--) {
var nl = negativeLists[n];
var nlBefore = re.slice(0, nl.reStart);
var nlFirst = re.slice(nl.reStart, nl.reEnd - 8);
var nlLast = re.slice(nl.reEnd - 8, nl.reEnd);
var nlAfter = re.slice(nl.reEnd);
nlLast += nlAfter;
var openParensBefore = nlBefore.split("(").length - 1;
var cleanAfter = nlAfter;
for (i = 0; i < openParensBefore; i++) {
cleanAfter = cleanAfter.replace(/\)[+*?]?/, "");
}
nlAfter = cleanAfter;
var dollar = "";
if (nlAfter === "" && isSub !== SUBPARSE) {
dollar = "$";
}
var newRe = nlBefore + nlFirst + nlAfter + dollar + nlLast;
re = newRe;
}
if (re !== "" && hasMagic) {
re = "(?=.)" + re;
}
if (addPatternStart) {
re = patternStart + re;
}
if (isSub === SUBPARSE) {
return [re, hasMagic];
}
if (!hasMagic) {
return globUnescape(pattern);
}
var flags = options.nocase ? "i" : "";
try {
var regExp = new RegExp("^" + re + "$", flags);
} catch (er) {
return new RegExp("$.");
}
regExp._glob = pattern;
regExp._src = re;
return regExp;
}
minimatch.makeRe = function(pattern, options) {
return new Minimatch(pattern, options || {}).makeRe();
};
Minimatch.prototype.makeRe = makeRe;
function makeRe() {
if (this.regexp || this.regexp === false)
return this.regexp;
var set = this.set;
if (!set.length) {
this.regexp = false;
return this.regexp;
}
var options = this.options;
var twoStar = options.noglobstar ? star : options.dot ? twoStarDot : twoStarNoDot;
var flags = options.nocase ? "i" : "";
var re = set.map(function(pattern) {
return pattern.map(function(p) {
return p === GLOBSTAR ? twoStar : typeof p === "string" ? regExpEscape(p) : p._src;
}).join("\\/");
}).join("|");
re = "^(?:" + re + ")$";
if (this.negate)
re = "^(?!" + re + ").*$";
try {
this.regexp = new RegExp(re, flags);
} catch (ex) {
this.regexp = false;
}
return this.regexp;
}
minimatch.match = function(list, pattern, options) {
options = options || {};
var mm = new Minimatch(pattern, options);
list = list.filter(function(f) {
return mm.match(f);
});
if (mm.options.nonull && !list.length) {
list.push(pattern);
}
return list;
};
Minimatch.prototype.match = match;
function match(f, partial) {
this.debug("match", f, this.pattern);
if (this.comment)
return false;
if (this.empty)
return f === "";
if (f === "/" && partial)
return true;
var options = this.options;
if (path.sep !== "/") {
f = f.split(path.sep).join("/");
}
f = f.split(slashSplit);
this.debug(this.pattern, "split", f);
var set = this.set;
this.debug(this.pattern, "set", set);
var filename;
var i;
for (i = f.length - 1; i >= 0; i--) {
filename = f[i];
if (filename)
break;
}
for (i = 0; i < set.length; i++) {
var pattern = set[i];
var file2 = f;
if (options.matchBase && pattern.length === 1) {
file2 = [filename];
}
var hit = this.matchOne(file2, pattern, partial);
if (hit) {
if (options.flipNegate)
return true;
return !this.negate;
}
}
if (options.flipNegate)
return false;
return this.negate;
}
Minimatch.prototype.matchOne = function(file2, pattern, partial) {
var options = this.options;
this.debug("matchOne", { "this": this, file: file2, pattern });
this.debug("matchOne", file2.length, pattern.length);
for (var fi = 0, pi = 0, fl = file2.length, pl = pattern.length; fi < fl && pi < pl; fi++, pi++) {
this.debug("matchOne loop");
var p = pattern[pi];
var f = file2[fi];
this.debug(pattern, p, f);
if (p === false)
return false;
if (p === GLOBSTAR) {
this.debug("GLOBSTAR", [pattern, p, f]);
var fr = fi;
var pr = pi + 1;
if (pr === pl) {
this.debug("** at the end");
for (; fi < fl; fi++) {
if (file2[fi] === "." || file2[fi] === ".." || !options.dot && file2[fi].charAt(0) === ".")
return false;
}
return true;
}
while (fr < fl) {
var swallowee = file2[fr];
this.debug("\nglobstar while", file2, fr, pattern, pr, swallowee);
if (this.matchOne(file2.slice(fr), pattern.slice(pr), partial)) {
this.debug("globstar found match!", fr, fl, swallowee);
return true;
} else {
if (swallowee === "." || swallowee === ".." || !options.dot && swallowee.charAt(0) === ".") {
this.debug("dot detected!", file2, fr, pattern, pr);
break;
}
this.debug("globstar swallow a segment, and continue");
fr++;
}
}
if (partial) {
this.debug("\n>>> no match, partial?", file2, fr, pattern, pr);
if (fr === fl)
return true;
}
return false;
}
var hit;
if (typeof p === "string") {
if (options.nocase) {
hit = f.toLowerCase() === p.toLowerCase();
} else {
hit = f === p;
}
this.debug("string match", p, f, hit);
} else {
hit = f.match(p);
this.debug("pattern match", p, f, hit);
}
if (!hit)
return false;
}
if (fi === fl && pi === pl) {
return true;
} else if (fi === fl) {
return partial;
} else if (pi === pl) {
var emptyFileEnd = fi === fl - 1 && file2[fi] === "";
return emptyFileEnd;
}
throw new Error("wtf?");
};
function globUnescape(s) {
return s.replace(/\\(.)/g, "$1");
}
function regExpEscape(s) {
return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
}
}
});
// node_modules/inherits/inherits_browser.js
var require_inherits_browser = __commonJS({
"node_modules/inherits/inherits_browser.js"(exports, module2) {
if (typeof Object.create === "function") {
module2.exports = function inherits(ctor, superCtor) {
if (superCtor) {
ctor.super_ = superCtor;
ctor.prototype = Object.create(superCtor.prototype, {
constructor: {
value: ctor,
enumerable: false,
writable: true,
configurable: true
}
});
}
};
} else {
module2.exports = function inherits(ctor, superCtor) {
if (superCtor) {
ctor.super_ = superCtor;
var TempCtor = function() {
};
TempCtor.prototype = superCtor.prototype;
ctor.prototype = new TempCtor();
ctor.prototype.constructor = ctor;
}
};
}
}
});
// node_modules/path-is-absolute/index.js
var require_path_is_absolute = __commonJS({
"node_modules/path-is-absolute/index.js"(exports, module2) {
"use strict";
function posix(path) {
return path.charAt(0) === "/";
}
function win32(path) {
var splitDeviceRe = /^([a-zA-Z]:|[\\\/]{2}[^\\\/]+[\\\/]+[^\\\/]+)?([\\\/])?([\s\S]*?)$/;
var result = splitDeviceRe.exec(path);
var device = result[1] || "";
var isUnc = Boolean(device && device.charAt(1) !== ":");
return Boolean(result[2] || isUnc);
}
module2.exports = process.platform === "win32" ? win32 : posix;
module2.exports.posix = posix;
module2.exports.win32 = win32;
}
});
// node_modules/glob/common.js
var require_common = __commonJS({
"node_modules/glob/common.js"(exports) {
exports.setopts = setopts;
exports.ownProp = ownProp;
exports.makeAbs = makeAbs;
exports.finish = finish;
exports.mark = mark;
exports.isIgnored = isIgnored;
exports.childrenIgnored = childrenIgnored;
function ownProp(obj, field) {
return Object.prototype.hasOwnProperty.call(obj, field);
}
var fs2 = require("fs");
var path = require("path");
var minimatch = require_minimatch();
var isAbsolute = require_path_is_absolute();
var Minimatch = minimatch.Minimatch;
function alphasort(a, b) {
return a.localeCompare(b, "en");
}
function setupIgnores(self, options) {
self.ignore = options.ignore || [];
if (!Array.isArray(self.ignore))
self.ignore = [self.ignore];
if (self.ignore.length) {
self.ignore = self.ignore.map(ignoreMap);
}
}
function ignoreMap(pattern) {
var gmatcher = null;
if (pattern.slice(-3) === "/**") {
var gpattern = pattern.replace(/(\/\*\*)+$/, "");
gmatcher = new Minimatch(gpattern, { dot: true });
}
return {
matcher: new Minimatch(pattern, { dot: true }),
gmatcher
};
}
function setopts(self, pattern, options) {
if (!options)
options = {};
if (options.matchBase && pattern.indexOf("/") === -1) {
if (options.noglobstar) {
throw new Error("base matching requires globstar");
}
pattern = "**/" + pattern;
}
self.silent = !!options.silent;
self.pattern = pattern;
self.strict = options.strict !== false;
self.realpath = !!options.realpath;
self.realpathCache = options.realpathCache || Object.create(null);
self.follow = !!options.follow;
self.dot = !!options.dot;
self.mark = !!options.mark;
self.nodir = !!options.nodir;
if (self.nodir)
self.mark = true;
self.sync = !!options.sync;
self.nounique = !!options.nounique;
self.nonull = !!options.nonull;
self.nosort = !!options.nosort;
self.nocase = !!options.nocase;
self.stat = !!options.stat;
self.noprocess = !!options.noprocess;
self.absolute = !!options.absolute;
self.fs = options.fs || fs2;
self.maxLength = options.maxLength || Infinity;
self.cache = options.cache || Object.create(null);
self.statCache = options.statCache || Object.create(null);
self.symlinks = options.symlinks || Object.create(null);
setupIgnores(self, options);
self.changedCwd = false;
var cwd = process.cwd();
if (!ownProp(options, "cwd"))
self.cwd = cwd;
else {
self.cwd = path.resolve(options.cwd);
self.changedCwd = self.cwd !== cwd;
}
self.root = options.root || path.resolve(self.cwd, "/");
self.root = path.resolve(self.root);
if (process.platform === "win32")
self.root = self.root.replace(/\\/g, "/");
self.cwdAbs = isAbsolute(self.cwd) ? self.cwd : makeAbs(self, self.cwd);
if (process.platform === "win32")
self.cwdAbs = self.cwdAbs.replace(/\\/g, "/");
self.nomount = !!options.nomount;
options.nonegate = true;
options.nocomment = true;
self.minimatch = new Minimatch(pattern, options);
self.options = self.minimatch.options;
}
function finish(self) {
var nou = self.nounique;
var all = nou ? [] : Object.create(null);
for (var i = 0, l = self.matches.length; i < l; i++) {
var matches = self.matches[i];
if (!matches || Object.keys(matches).length === 0) {
if (self.nonull) {
var literal = self.minimatch.globSet[i];
if (nou)
all.push(literal);
else
all[literal] = true;
}
} else {
var m = Object.keys(matches);
if (nou)
all.push.apply(all, m);
else
m.forEach(function(m2) {
all[m2] = true;
});
}
}
if (!nou)
all = Object.keys(all);
if (!self.nosort)
all = all.sort(alphasort);
if (self.mark) {
for (var i = 0; i < all.length; i++) {
all[i] = self._mark(all[i]);
}
if (self.nodir) {
all = all.filter(function(e) {
var notDir = !/\/$/.test(e);
var c = self.cache[e] || self.cache[makeAbs(self, e)];
if (notDir && c)
notDir = c !== "DIR" && !Array.isArray(c);
return notDir;
});
}
}
if (self.ignore.length)
all = all.filter(function(m2) {
return !isIgnored(self, m2);
});
self.found = all;
}
function mark(self, p) {
var abs = makeAbs(self, p);
var c = self.cache[abs];
var m = p;
if (c) {
var isDir = c === "DIR" || Array.isArray(c);
var slash = p.slice(-1) === "/";
if (isDir && !slash)
m += "/";
else if (!isDir && slash)
m = m.slice(0, -1);
if (m !== p) {
var mabs = makeAbs(self, m);
self.statCache[mabs] = self.statCache[abs];
self.cache[mabs] = self.cache[abs];
}
}
return m;
}
function makeAbs(self, f) {
var abs = f;
if (f.charAt(0) === "/") {
abs = path.join(self.root, f);
} else if (isAbsolute(f) || f === "") {
abs = f;
} else if (self.changedCwd) {
abs = path.resolve(self.cwd, f);
} else {
abs = path.resolve(f);
}
if (process.platform === "win32")
abs = abs.replace(/\\/g, "/");
return abs;
}
function isIgnored(self, path2) {
if (!self.ignore.length)
return false;
return self.ignore.some(function(item) {
return item.matcher.match(path2) || !!(item.gmatcher && item.gmatcher.match(path2));
});
}
function childrenIgnored(self, path2) {
if (!self.ignore.length)
return false;
return self.ignore.some(function(item) {
return !!(item.gmatcher && item.gmatcher.match(path2));
});
}
}
});
// node_modules/glob/sync.js
var require_sync = __commonJS({
"node_modules/glob/sync.js"(exports, module2) {
module2.exports = globSync;
globSync.GlobSync = GlobSync;
var rp = require_fs();
var minimatch = require_minimatch();
var Minimatch = minimatch.Minimatch;
var Glob = require_glob().Glob;
var util = require("util");
var path = require("path");
var assert = require("assert");
var isAbsolute = require_path_is_absolute();
var common = require_common();
var setopts = common.setopts;
var ownProp = common.ownProp;
var childrenIgnored = common.childrenIgnored;
var isIgnored = common.isIgnored;
function globSync(pattern, options) {
if (typeof options === "function" || arguments.length === 3)
throw new TypeError("callback provided to sync glob\nSee: https://github.com/isaacs/node-glob/issues/167");
return new GlobSync(pattern, options).found;
}
function GlobSync(pattern, options) {
if (!pattern)
throw new Error("must provide pattern");
if (typeof options === "function" || arguments.length === 3)
throw new TypeError("callback provided to sync glob\nSee: https://github.com/isaacs/node-glob/issues/167");
if (!(this instanceof GlobSync))
return new GlobSync(pattern, options);
setopts(this, pattern, options);
if (this.noprocess)
return this;
var n = this.minimatch.set.length;
this.matches = new Array(n);
for (var i = 0; i < n; i++) {
this._process(this.minimatch.set[i], i, false);
}
this._finish();
}
GlobSync.prototype._finish = function() {
assert(this instanceof GlobSync);
if (this.realpath) {
var self = this;
this.matches.forEach(function(matchset, index) {
var set = self.matches[index] = Object.create(null);
for (var p in matchset) {
try {
p = self._makeAbs(p);
var real = rp.realpathSync(p, self.realpathCache);
set[real] = true;
} catch (er) {
if (er.syscall === "stat")
set[self._makeAbs(p)] = true;
else
throw er;
}
}
});
}
common.finish(this);
};
GlobSync.prototype._process = function(pattern, index, inGlobStar) {
assert(this instanceof GlobSync);
var n = 0;
while (typeof pattern[n] === "string") {
n++;
}
var prefix;
switch (n) {
case pattern.length:
this._processSimple(pattern.join("/"), index);
return;
case 0:
prefix = null;
break;
default:
prefix = pattern.slice(0, n).join("/");
break;
}
var remain = pattern.slice(n);
var read;
if (prefix === null)
read = ".";
else if (isAbsolute(prefix) || isAbsolute(pattern.join("/"))) {
if (!prefix || !isAbsolute(prefix))
prefix = "/" + prefix;
read = prefix;
} else
read = prefix;
var abs = this._makeAbs(read);
if (childrenIgnored(this, read))
return;
var isGlobStar = remain[0] === minimatch.GLOBSTAR;
if (isGlobStar)
this._processGlobStar(prefix, read, abs, remain, index, inGlobStar);
else
this._processReaddir(prefix, read, abs, remain, index, inGlobStar);
};
GlobSync.prototype._processReaddir = function(prefix, read, abs, remain, index, inGlobStar) {
var entries = this._readdir(abs, inGlobStar);
if (!entries)
return;
var pn = remain[0];
var negate = !!this.minimatch.negate;
var rawGlob = pn._glob;
var dotOk = this.dot || rawGlob.charAt(0) === ".";
var matchedEntries = [];
for (var i = 0; i < entries.length; i++) {
var e = entries[i];
if (e.charAt(0) !== "." || dotOk) {
var m;
if (negate && !prefix) {
m = !e.match(pn);
} else {
m = e.match(pn);
}
if (m)
matchedEntries.push(e);
}
}
var len = matchedEntries.length;
if (len === 0)
return;
if (remain.length === 1 && !this.mark && !this.stat) {
if (!this.matches[index])
this.matches[index] = Object.create(null);
for (var i = 0; i < len; i++) {
var e = matchedEntries[i];
if (prefix) {
if (prefix.slice(-1) !== "/")
e = prefix + "/" + e;
else
e = prefix + e;
}
if (e.charAt(0) === "/" && !this.nomount) {
e = path.join(this.root, e);
}
this._emitMatch(index, e);
}
return;
}
remain.shift();
for (var i = 0; i < len; i++) {
var e = matchedEntries[i];
var newPattern;
if (prefix)
newPattern = [prefix, e];
else
newPattern = [e];
this._process(newPattern.concat(remain), index, inGlobStar);
}
};
GlobSync.prototype._emitMatch = function(index, e) {
if (isIgnored(this, e))
return;
var abs = this._makeAbs(e);
if (this.mark)
e = this._mark(e);
if (this.absolute) {
e = abs;
}
if (this.matches[index][e])
return;
if (this.nodir) {
var c = this.cache[abs];
if (c === "DIR" || Array.isArray(c))
return;
}
this.matches[index][e] = true;
if (this.stat)
this._stat(e);
};
GlobSync.prototype._readdirInGlobStar = function(abs) {
if (this.follow)
return this._readdir(abs, false);
var entries;
var lstat;
var stat;
try {
lstat = this.fs.lstatSync(abs);
} catch (er) {
if (er.code === "ENOENT") {
return null;
}
}
var isSym = lstat && lstat.isSymbolicLink();
this.symlinks[abs] = isSym;
if (!isSym && lstat && !lstat.isDirectory())
this.cache[abs] = "FILE";
else
entries = this._readdir(abs, false);
return entries;
};
GlobSync.prototype._readdir = function(abs, inGlobStar) {
var entries;
if (inGlobStar && !ownProp(this.symlinks, abs))
return this._readdirInGlobStar(abs);
if (ownProp(this.cache, abs)) {
var c = this.cache[abs];
if (!c || c === "FILE")
return null;
if (Array.isArray(c))
return c;
}
try {
return this._readdirEntries(abs, this.fs.readdirSync(abs));
} catch (er) {
this._readdirError(abs, er);
return null;
}
};
GlobSync.prototype._readdirEntries = function(abs, entries) {
if (!this.mark && !this.stat) {
for (var i = 0; i < entries.length; i++) {
var e = entries[i];
if (abs === "/")
e = abs + e;
else
e = abs + "/" + e;
this.cache[e] = true;
}
}
this.cache[abs] = entries;
return entries;
};
GlobSync.prototype._readdirError = function(f, er) {
switch (er.code) {
case "ENOTSUP":
case "ENOTDIR":
var abs = this._makeAbs(f);
this.cache[abs] = "FILE";
if (abs === this.cwdAbs) {
var error = new Error(er.code + " invalid cwd " + this.cwd);
error.path = this.cwd;
error.code = er.code;
throw error;
}
break;
case "ENOENT":
case "ELOOP":
case "ENAMETOOLONG":
case "UNKNOWN":
this.cache[this._makeAbs(f)] = false;
break;
default:
this.cache[this._makeAbs(f)] = false;
if (this.strict)
throw er;
if (!this.silent)
console.error("glob error", er);
break;
}
};
GlobSync.prototype._processGlobStar = function(prefix, read, abs, remain, index, inGlobStar) {
var entries = this._readdir(abs, inGlobStar);
if (!entries)
return;
var remainWithoutGlobStar = remain.slice(1);
var gspref = prefix ? [prefix] : [];
var noGlobStar = gspref.concat(remainWithoutGlobStar);
this._process(noGlobStar, index, false);
var len = entries.length;
var isSym = this.symlinks[abs];
if (isSym && inGlobStar)
return;
for (var i = 0; i < len; i++) {
var e = entries[i];
if (e.charAt(0) === "." && !this.dot)
continue;
var instead = gspref.concat(entries[i], remainWithoutGlobStar);
this._process(instead, index, true);
var below = gspref.concat(entries[i], remain);
this._process(below, index, true);
}
};
GlobSync.prototype._processSimple = function(prefix, index) {
var exists = this._stat(prefix);
if (!this.matches[index])
this.matches[index] = Object.create(null);
if (!exists)
return;
if (prefix && isAbsolute(prefix) && !this.nomount) {
var trail = /[\/\\]$/.test(prefix);
if (prefix.charAt(0) === "/") {
prefix = path.join(this.root, prefix);
} else {
prefix = path.resolve(this.root, prefix);
if (trail)
prefix += "/";
}
}
if (process.platform === "win32")
prefix = prefix.replace(/\\/g, "/");
this._emitMatch(index, prefix);
};
GlobSync.prototype._stat = function(f) {
var abs = this._makeAbs(f);
var needDir = f.slice(-1) === "/";
if (f.length > this.maxLength)
return false;
if (!this.stat && ownProp(this.cache, abs)) {
var c = this.cache[abs];
if (Array.isArray(c))
c = "DIR";
if (!needDir || c === "DIR")
return c;
if (needDir && c === "FILE")
return false;
}
var exists;
var stat = this.statCache[abs];
if (!stat) {
var lstat;
try {
lstat = this.fs.lstatSync(abs);
} catch (er) {
if (er && (er.code === "ENOENT" || er.code === "ENOTDIR")) {
this.statCache[abs] = false;
return false;
}
}
if (lstat && lstat.isSymbolicLink()) {
try {
stat = this.fs.statSync(abs);
} catch (er) {
stat = lstat;
}
} else {
stat = lstat;
}
}
this.statCache[abs] = stat;
var c = true;
if (stat)
c = stat.isDirectory() ? "DIR" : "FILE";
this.cache[abs] = this.cache[abs] || c;
if (needDir && c === "FILE")
return false;
return c;
};
GlobSync.prototype._mark = function(p) {
return common.mark(this, p);
};
GlobSync.prototype._makeAbs = function(f) {
return common.makeAbs(this, f);
};
}
});
// node_modules/wrappy/wrappy.js
var require_wrappy = __commonJS({
"node_modules/wrappy/wrappy.js"(exports, module2) {
module2.exports = wrappy;
function wrappy(fn, cb) {
if (fn && cb)
return wrappy(fn)(cb);
if (typeof fn !== "function")
throw new TypeError("need wrapper function");
Object.keys(fn).forEach(function(k) {
wrapper[k] = fn[k];
});
return wrapper;
function wrapper() {
var args = new Array(arguments.length);
for (var i = 0; i < args.length; i++) {
args[i] = arguments[i];
}
var ret = fn.apply(this, args);
var cb2 = args[args.length - 1];
if (typeof ret === "function" && ret !== cb2) {
Object.keys(cb2).forEach(function(k) {
ret[k] = cb2[k];
});
}
return ret;
}
}
}
});
// node_modules/once/once.js
var require_once = __commonJS({
"node_modules/once/once.js"(exports, module2) {
var wrappy = require_wrappy();
module2.exports = wrappy(once);
module2.exports.strict = wrappy(onceStrict);
once.proto = once(function() {
Object.defineProperty(Function.prototype, "once", {
value: function() {
return once(this);
},
configurable: true
});
Object.defineProperty(Function.prototype, "onceStrict", {
value: function() {
return onceStrict(this);
},
configurable: true
});
});
function once(fn) {
var f = function() {
if (f.called)
return f.value;
f.called = true;
return f.value = fn.apply(this, arguments);
};
f.called = false;
return f;
}
function onceStrict(fn) {
var f = function() {
if (f.called)
throw new Error(f.onceError);
f.called = true;
return f.value = fn.apply(this, arguments);
};
var name = fn.name || "Function wrapped with `once`";
f.onceError = name + " shouldn't be called more than once";
f.called = false;
return f;
}
}
});
// node_modules/inflight/inflight.js
var require_inflight = __commonJS({
"node_modules/inflight/inflight.js"(exports, module2) {
var wrappy = require_wrappy();
var reqs = Object.create(null);
var once = require_once();
module2.exports = wrappy(inflight);
function inflight(key, cb) {
if (reqs[key]) {
reqs[key].push(cb);
return null;
} else {
reqs[key] = [cb];
return makeres(key);
}
}
function makeres(key) {
return once(function RES() {
var cbs = reqs[key];
var len = cbs.length;
var args = slice(arguments);
try {
for (var i = 0; i < len; i++) {
cbs[i].apply(null, args);
}
} finally {
if (cbs.length > len) {
cbs.splice(0, len);
process.nextTick(function() {
RES.apply(null, args);
});
} else {
delete reqs[key];
}
}
});
}
function slice(args) {
var length = args.length;
var array = [];
for (var i = 0; i < length; i++)
array[i] = args[i];
return array;
}
}
});
// node_modules/glob/glob.js
var require_glob = __commonJS({
"node_modules/glob/glob.js"(exports, module2) {
module2.exports = glob;
var rp = require_fs();
var minimatch = require_minimatch();
var Minimatch = minimatch.Minimatch;
var inherits = require_inherits_browser();
var EE = require("events").EventEmitter;
var path = require("path");
var assert = require("assert");
var isAbsolute = require_path_is_absolute();
var globSync = require_sync();
var common = require_common();
var setopts = common.setopts;
var ownProp = common.ownProp;
var inflight = require_inflight();
var util = require("util");
var childrenIgnored = common.childrenIgnored;
var isIgnored = common.isIgnored;
var once = require_once();
function glob(pattern, options, cb) {
if (typeof options === "function")
cb = options, options = {};
if (!options)
options = {};
if (options.sync) {
if (cb)
throw new TypeError("callback provided to sync glob");
return globSync(pattern, options);
}
return new Glob(pattern, options, cb);
}
glob.sync = globSync;
var GlobSync = glob.GlobSync = globSync.GlobSync;
glob.glob = glob;
function extend(origin, add) {
if (add === null || typeof add !== "object") {
return origin;
}
var keys = Object.keys(add);
var i = keys.length;
while (i--) {
origin[keys[i]] = add[keys[i]];
}
return origin;
}
glob.hasMagic = function(pattern, options_) {
var options = extend({}, options_);
options.noprocess = true;
var g = new Glob(pattern, options);
var set = g.minimatch.set;
if (!pattern)
return false;
if (set.length > 1)
return true;
for (var j = 0; j < set[0].length; j++) {
if (typeof set[0][j] !== "string")
return true;
}
return false;
};
glob.Glob = Glob;
inherits(Glob, EE);
function Glob(pattern, options, cb) {
if (typeof options === "function") {
cb = options;
options = null;
}
if (options && options.sync) {
if (cb)
throw new TypeError("callback provided to sync glob");
return new GlobSync(pattern, options);
}
if (!(this instanceof Glob))
return new Glob(pattern, options, cb);
setopts(this, pattern, options);
this._didRealPath = false;
var n = this.minimatch.set.length;
this.matches = new Array(n);
if (typeof cb === "function") {
cb = once(cb);
this.on("error", cb);
this.on("end", function(matches) {
cb(null, matches);
});
}
var self = this;
this._processing = 0;
this._emitQueue = [];
this._processQueue = [];
this.paused = false;
if (this.noprocess)
return this;
if (n === 0)
return done();
var sync = true;
for (var i = 0; i < n; i++) {
this._process(this.minimatch.set[i], i, false, done);
}
sync = false;
function done() {
--self._processing;
if (self._processing <= 0) {
if (sync) {
process.nextTick(function() {
self._finish();
});
} else {
self._finish();
}
}
}
}
Glob.prototype._finish = function() {
assert(this instanceof Glob);
if (this.aborted)
return;
if (this.realpath && !this._didRealpath)
return this._realpath();
common.finish(this);
this.emit("end", this.found);
};
Glob.prototype._realpath = function() {
if (this._didRealpath)
return;
this._didRealpath = true;
var n = this.matches.length;
if (n === 0)
return this._finish();
var self = this;
for (var i = 0; i < this.matches.length; i++)
this._realpathSet(i, next);
function next() {
if (--n === 0)
self._finish();
}
};
Glob.prototype._realpathSet = function(index, cb) {
var matchset = this.matches[index];
if (!matchset)
return cb();
var found = Object.keys(matchset);
var self = this;
var n = found.length;
if (n === 0)
return cb();
var set = this.matches[index] = Object.create(null);
found.forEach(function(p, i) {
p = self._makeAbs(p);
rp.realpath(p, self.realpathCache, function(er, real) {
if (!er)
set[real] = true;
else if (er.syscall === "stat")
set[p] = true;
else
self.emit("error", er);
if (--n === 0) {
self.matches[index] = set;
cb();
}
});
});
};
Glob.prototype._mark = function(p) {
return common.mark(this, p);
};
Glob.prototype._makeAbs = function(f) {
return common.makeAbs(this, f);
};
Glob.prototype.abort = function() {
this.aborted = true;
this.emit("abort");
};
Glob.prototype.pause = function() {
if (!this.paused) {
this.paused = true;
this.emit("pause");
}
};
Glob.prototype.resume = function() {
if (this.paused) {
this.emit("resume");
this.paused = false;
if (this._emitQueue.length) {
var eq = this._emitQueue.slice(0);
this._emitQueue.length = 0;
for (var i = 0; i < eq.length; i++) {
var e = eq[i];
this._emitMatch(e[0], e[1]);
}
}
if (this._processQueue.length) {
var pq = this._processQueue.slice(0);
this._processQueue.length = 0;
for (var i = 0; i < pq.length; i++) {
var p = pq[i];
this._processing--;
this._process(p[0], p[1], p[2], p[3]);
}
}
}
};
Glob.prototype._process = function(pattern, index, inGlobStar, cb) {
assert(this instanceof Glob);
assert(typeof cb === "function");
if (this.aborted)
return;
this._processing++;
if (this.paused) {
this._processQueue.push([pattern, index, inGlobStar, cb]);
return;
}
var n = 0;
while (typeof pattern[n] === "string") {
n++;
}
var prefix;
switch (n) {
case pattern.length:
this._processSimple(pattern.join("/"), index, cb);
return;
case 0:
prefix = null;
break;
default:
prefix = pattern.slice(0, n).join("/");
break;
}
var remain = pattern.slice(n);
var read;
if (prefix === null)
read = ".";
else if (isAbsolute(prefix) || isAbsolute(pattern.join("/"))) {
if (!prefix || !isAbsolute(prefix))
prefix = "/" + prefix;
read = prefix;
} else
read = prefix;
var abs = this._makeAbs(read);
if (childrenIgnored(this, read))
return cb();
var isGlobStar = remain[0] === minimatch.GLOBSTAR;
if (isGlobStar)
this._processGlobStar(prefix, read, abs, remain, index, inGlobStar, cb);
else
this._processReaddir(prefix, read, abs, remain, index, inGlobStar, cb);
};
Glob.prototype._processReaddir = function(prefix, read, abs, remain, index, inGlobStar, cb) {
var self = this;
this._readdir(abs, inGlobStar, function(er, entries) {
return self._processReaddir2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
});
};
Glob.prototype._processReaddir2 = function(prefix, read, abs, remain, index, inGlobStar, entries, cb) {
if (!entries)
return cb();
var pn = remain[0];
var negate = !!this.minimatch.negate;
var rawGlob = pn._glob;
var dotOk = this.dot || rawGlob.charAt(0) === ".";
var matchedEntries = [];
for (var i = 0; i < entries.length; i++) {
var e = entries[i];
if (e.charAt(0) !== "." || dotOk) {
var m;
if (negate && !prefix) {
m = !e.match(pn);
} else {
m = e.match(pn);
}
if (m)
matchedEntries.push(e);
}
}
var len = matchedEntries.length;
if (len === 0)
return cb();
if (remain.length === 1 && !this.mark && !this.stat) {
if (!this.matches[index])
this.matches[index] = Object.create(null);
for (var i = 0; i < len; i++) {
var e = matchedEntries[i];
if (prefix) {
if (prefix !== "/")
e = prefix + "/" + e;
else
e = prefix + e;
}
if (e.charAt(0) === "/" && !this.nomount) {
e = path.join(this.root, e);
}
this._emitMatch(index, e);
}
return cb();
}
remain.shift();
for (var i = 0; i < len; i++) {
var e = matchedEntries[i];
var newPattern;
if (prefix) {
if (prefix !== "/")
e = prefix + "/" + e;
else
e = prefix + e;
}
this._process([e].concat(remain), index, inGlobStar, cb);
}
cb();
};
Glob.prototype._emitMatch = function(index, e) {
if (this.aborted)
return;
if (isIgnored(this, e))
return;
if (this.paused) {
this._emitQueue.push([index, e]);
return;
}
var abs = isAbsolute(e) ? e : this._makeAbs(e);
if (this.mark)
e = this._mark(e);
if (this.absolute)
e = abs;
if (this.matches[index][e])
return;
if (this.nodir) {
var c = this.cache[abs];
if (c === "DIR" || Array.isArray(c))
return;
}
this.matches[index][e] = true;
var st = this.statCache[abs];
if (st)
this.emit("stat", e, st);
this.emit("match", e);
};
Glob.prototype._readdirInGlobStar = function(abs, cb) {
if (this.aborted)
return;
if (this.follow)
return this._readdir(abs, false, cb);
var lstatkey = "lstat\0" + abs;
var self = this;
var lstatcb = inflight(lstatkey, lstatcb_);
if (lstatcb)
self.fs.lstat(abs, lstatcb);
function lstatcb_(er, lstat) {
if (er && er.code === "ENOENT")
return cb();
var isSym = lstat && lstat.isSymbolicLink();
self.symlinks[abs] = isSym;
if (!isSym && lstat && !lstat.isDirectory()) {
self.cache[abs] = "FILE";
cb();
} else
self._readdir(abs, false, cb);
}
};
Glob.prototype._readdir = function(abs, inGlobStar, cb) {
if (this.aborted)
return;
cb = inflight("readdir\0" + abs + "\0" + inGlobStar, cb);
if (!cb)
return;
if (inGlobStar && !ownProp(this.symlinks, abs))
return this._readdirInGlobStar(abs, cb);
if (ownProp(this.cache, abs)) {
var c = this.cache[abs];
if (!c || c === "FILE")
return cb();
if (Array.isArray(c))
return cb(null, c);
}
var self = this;
self.fs.readdir(abs, readdirCb(this, abs, cb));
};
function readdirCb(self, abs, cb) {
return function(er, entries) {
if (er)
self._readdirError(abs, er, cb);
else
self._readdirEntries(abs, entries, cb);
};
}
Glob.prototype._readdirEntries = function(abs, entries, cb) {
if (this.aborted)
return;
if (!this.mark && !this.stat) {
for (var i = 0; i < entries.length; i++) {
var e = entries[i];
if (abs === "/")
e = abs + e;
else
e = abs + "/" + e;
this.cache[e] = true;
}
}
this.cache[abs] = entries;
return cb(null, entries);
};
Glob.prototype._readdirError = function(f, er, cb) {
if (this.aborted)
return;
switch (er.code) {
case "ENOTSUP":
case "ENOTDIR":
var abs = this._makeAbs(f);
this.cache[abs] = "FILE";
if (abs === this.cwdAbs) {
var error = new Error(er.code + " invalid cwd " + this.cwd);
error.path = this.cwd;
error.code = er.code;
this.emit("error", error);
this.abort();
}
break;
case "ENOENT":
case "ELOOP":
case "ENAMETOOLONG":
case "UNKNOWN":
this.cache[this._makeAbs(f)] = false;
break;
default:
this.cache[this._makeAbs(f)] = false;
if (this.strict) {
this.emit("error", er);
this.abort();
}
if (!this.silent)
console.error("glob error", er);
break;
}
return cb();
};
Glob.prototype._processGlobStar = function(prefix, read, abs, remain, index, inGlobStar, cb) {
var self = this;
this._readdir(abs, inGlobStar, function(er, entries) {
self._processGlobStar2(prefix, read, abs, remain, index, inGlobStar, entries, cb);
});
};
Glob.prototype._processGlobStar2 = function(prefix, read, abs, remain, index, inGlobStar, entries, cb) {
if (!entries)
return cb();
var remainWithoutGlobStar = remain.slice(1);
var gspref = prefix ? [prefix] : [];
var noGlobStar = gspref.concat(remainWithoutGlobStar);
this._process(noGlobStar, index, false, cb);
var isSym = this.symlinks[abs];
var len = entries.length;
if (isSym && inGlobStar)
return cb();
for (var i = 0; i < len; i++) {
var e = entries[i];
if (e.charAt(0) === "." && !this.dot)
continue;
var instead = gspref.concat(entries[i], remainWithoutGlobStar);
this._process(instead, index, true, cb);
var below = gspref.concat(entries[i], remain);
this._process(below, index, true, cb);
}
cb();
};
Glob.prototype._processSimple = function(prefix, index, cb) {
var self = this;
this._stat(prefix, function(er, exists) {
self._processSimple2(prefix, index, er, exists, cb);
});
};
Glob.prototype._processSimple2 = function(prefix, index, er, exists, cb) {
if (!this.matches[index])
this.matches[index] = Object.create(null);
if (!exists)
return cb();
if (prefix && isAbsolute(prefix) && !this.nomount) {
var trail = /[\/\\]$/.test(prefix);
if (prefix.charAt(0) === "/") {
prefix = path.join(this.root, prefix);
} else {
prefix = path.resolve(this.root, prefix);
if (trail)
prefix += "/";
}
}
if (process.platform === "win32")
prefix = prefix.replace(/\\/g, "/");
this._emitMatch(index, prefix);
cb();
};
Glob.prototype._stat = function(f, cb) {
var abs = this._makeAbs(f);
var needDir = f.slice(-1) === "/";
if (f.length > this.maxLength)
return cb();
if (!this.stat && ownProp(this.cache, abs)) {
var c = this.cache[abs];
if (Array.isArray(c))
c = "DIR";
if (!needDir || c === "DIR")
return cb(null, c);
if (needDir && c === "FILE")
return cb();
}
var exists;
var stat = this.statCache[abs];
if (stat !== void 0) {
if (stat === false)
return cb(null, stat);
else {
var type = stat.isDirectory() ? "DIR" : "FILE";
if (needDir && type === "FILE")
return cb();
else
return cb(null, type, stat);
}
}
var self = this;
var statcb = inflight("stat\0" + abs, lstatcb_);
if (statcb)
self.fs.lstat(abs, statcb);
function lstatcb_(er, lstat) {
if (lstat && lstat.isSymbolicLink()) {
return self.fs.stat(abs, function(er2, stat2) {
if (er2)
self._stat2(f, abs, null, lstat, cb);
else
self._stat2(f, abs, er2, stat2, cb);
});
} else {
self._stat2(f, abs, er, lstat, cb);
}
}
};
Glob.prototype._stat2 = function(f, abs, er, stat, cb) {
if (er && (er.code === "ENOENT" || er.code === "ENOTDIR")) {
this.statCache[abs] = false;
return cb();
}
var needDir = f.slice(-1) === "/";
this.statCache[abs] = stat;
if (abs.slice(-1) === "/" && stat && !stat.isDirectory())
return cb(null, false, stat);
var c = true;
if (stat)
c = stat.isDirectory() ? "DIR" : "FILE";
this.cache[abs] = this.cache[abs] || c;
if (needDir && c === "FILE")
return cb();
return cb(null, c, stat);
};
}
});
// node_modules/rimraf/rimraf.js
var require_rimraf = __commonJS({
"node_modules/rimraf/rimraf.js"(exports, module2) {
var assert = require("assert");
var path = require("path");
var fs2 = require("fs");
var glob = void 0;
try {
glob = require_glob();
} catch (_err) {
}
var defaultGlobOpts = {
nosort: true,
silent: true
};
var timeout = 0;
var isWindows = process.platform === "win32";
var defaults = (options) => {
const methods = [
"unlink",
"chmod",
"stat",
"lstat",
"rmdir",
"readdir"
];
methods.forEach((m) => {
options[m] = options[m] || fs2[m];
m = m + "Sync";
options[m] = options[m] || fs2[m];
});
options.maxBusyTries = options.maxBusyTries || 3;
options.emfileWait = options.emfileWait || 1e3;
if (options.glob === false) {
options.disableGlob = true;
}
if (options.disableGlob !== true && glob === void 0) {
throw Error("glob dependency not found, set `options.disableGlob = true` if intentional");
}
options.disableGlob = options.disableGlob || false;
options.glob = options.glob || defaultGlobOpts;
};
var rimraf = (p, options, cb) => {
if (typeof options === "function") {
cb = options;
options = {};
}
assert(p, "rimraf: missing path");
assert.equal(typeof p, "string", "rimraf: path should be a string");
assert.equal(typeof cb, "function", "rimraf: callback function required");
assert(options, "rimraf: invalid options argument provided");
assert.equal(typeof options, "object", "rimraf: options should be object");
defaults(options);
let busyTries = 0;
let errState = null;
let n = 0;
const next = (er) => {
errState = errState || er;
if (--n === 0)
cb(errState);
};
const afterGlob = (er, results) => {
if (er)
return cb(er);
n = results.length;
if (n === 0)
return cb();
results.forEach((p2) => {
const CB = (er2) => {
if (er2) {
if ((er2.code === "EBUSY" || er2.code === "ENOTEMPTY" || er2.code === "EPERM") && busyTries < options.maxBusyTries) {
busyTries++;
return setTimeout(() => rimraf_(p2, options, CB), busyTries * 100);
}
if (er2.code === "EMFILE" && timeout < options.emfileWait) {
return setTimeout(() => rimraf_(p2, options, CB), timeout++);
}
if (er2.code === "ENOENT")
er2 = null;
}
timeout = 0;
next(er2);
};
rimraf_(p2, options, CB);
});
};
if (options.disableGlob || !glob.hasMagic(p))
return afterGlob(null, [p]);
options.lstat(p, (er, stat) => {
if (!er)
return afterGlob(null, [p]);
glob(p, options.glob, afterGlob);
});
};
var rimraf_ = (p, options, cb) => {
assert(p);
assert(options);
assert(typeof cb === "function");
options.lstat(p, (er, st) => {
if (er && er.code === "ENOENT")
return cb(null);
if (er && er.code === "EPERM" && isWindows)
fixWinEPERM(p, options, er, cb);
if (st && st.isDirectory())
return rmdir(p, options, er, cb);
options.unlink(p, (er2) => {
if (er2) {
if (er2.code === "ENOENT")
return cb(null);
if (er2.code === "EPERM")
return isWindows ? fixWinEPERM(p, options, er2, cb) : rmdir(p, options, er2, cb);
if (er2.code === "EISDIR")
return rmdir(p, options, er2, cb);
}
return cb(er2);
});
});
};
var fixWinEPERM = (p, options, er, cb) => {
assert(p);
assert(options);
assert(typeof cb === "function");
options.chmod(p, 438, (er2) => {
if (er2)
cb(er2.code === "ENOENT" ? null : er);
else
options.stat(p, (er3, stats) => {
if (er3)
cb(er3.code === "ENOENT" ? null : er);
else if (stats.isDirectory())
rmdir(p, options, er, cb);
else
options.unlink(p, cb);
});
});
};
var fixWinEPERMSync = (p, options, er) => {
assert(p);
assert(options);
try {
options.chmodSync(p, 438);
} catch (er2) {
if (er2.code === "ENOENT")
return;
else
throw er;
}
let stats;
try {
stats = options.statSync(p);
} catch (er3) {
if (er3.code === "ENOENT")
return;
else
throw er;
}
if (stats.isDirectory())
rmdirSync(p, options, er);
else
options.unlinkSync(p);
};
var rmdir = (p, options, originalEr, cb) => {
assert(p);
assert(options);
assert(typeof cb === "function");
options.rmdir(p, (er) => {
if (er && (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM"))
rmkids(p, options, cb);
else if (er && er.code === "ENOTDIR")
cb(originalEr);
else
cb(er);
});
};
var rmkids = (p, options, cb) => {
assert(p);
assert(options);
assert(typeof cb === "function");
options.readdir(p, (er, files) => {
if (er)
return cb(er);
let n = files.length;
if (n === 0)
return options.rmdir(p, cb);
let errState;
files.forEach((f) => {
rimraf(path.join(p, f), options, (er2) => {
if (errState)
return;
if (er2)
return cb(errState = er2);
if (--n === 0)
options.rmdir(p, cb);
});
});
});
};
var rimrafSync = (p, options) => {
options = options || {};
defaults(options);
assert(p, "rimraf: missing path");
assert.equal(typeof p, "string", "rimraf: path should be a string");
assert(options, "rimraf: missing options");
assert.equal(typeof options, "object", "rimraf: options should be object");
let results;
if (options.disableGlob || !glob.hasMagic(p)) {
results = [p];
} else {
try {
options.lstatSync(p);
results = [p];
} catch (er) {
results = glob.sync(p, options.glob);
}
}
if (!results.length)
return;
for (let i = 0; i < results.length; i++) {
const p2 = results[i];
let st;
try {
st = options.lstatSync(p2);
} catch (er) {
if (er.code === "ENOENT")
return;
if (er.code === "EPERM" && isWindows)
fixWinEPERMSync(p2, options, er);
}
try {
if (st && st.isDirectory())
rmdirSync(p2, options, null);
else
options.unlinkSync(p2);
} catch (er) {
if (er.code === "ENOENT")
return;
if (er.code === "EPERM")
return isWindows ? fixWinEPERMSync(p2, options, er) : rmdirSync(p2, options, er);
if (er.code !== "EISDIR")
throw er;
rmdirSync(p2, options, er);
}
}
};
var rmdirSync = (p, options, originalEr) => {
assert(p);
assert(options);
try {
options.rmdirSync(p);
} catch (er) {
if (er.code === "ENOENT")
return;
if (er.code === "ENOTDIR")
throw originalEr;
if (er.code === "ENOTEMPTY" || er.code === "EEXIST" || er.code === "EPERM")
rmkidsSync(p, options);
}
};
var rmkidsSync = (p, options) => {
assert(p);
assert(options);
options.readdirSync(p).forEach((f) => rimrafSync(path.join(p, f), options));
const retries = isWindows ? 100 : 1;
let i = 0;
do {
let threw = true;
try {
const ret = options.rmdirSync(p, options);
threw = false;
return ret;
} finally {
if (++i < retries && threw)
continue;
}
} while (true);
};
module2.exports = rimraf;
rimraf.sync = rimrafSync;
}
});
// node_modules/tmp/lib/tmp.js
var require_tmp = __commonJS({
"node_modules/tmp/lib/tmp.js"(exports, module2) {
var fs2 = require("fs");
var os = require("os");
var path = require("path");
var crypto = require("crypto");
var _c = { fs: fs2.constants, os: os.constants };
var rimraf = require_rimraf();
var RANDOM_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
var TEMPLATE_PATTERN = /XXXXXX/;
var DEFAULT_TRIES = 3;
var CREATE_FLAGS = (_c.O_CREAT || _c.fs.O_CREAT) | (_c.O_EXCL || _c.fs.O_EXCL) | (_c.O_RDWR || _c.fs.O_RDWR);
var IS_WIN32 = os.platform() === "win32";
var EBADF = _c.EBADF || _c.os.errno.EBADF;
var ENOENT = _c.ENOENT || _c.os.errno.ENOENT;
var DIR_MODE = 448;
var FILE_MODE = 384;
var EXIT = "exit";
var _removeObjects = [];
var FN_RMDIR_SYNC = fs2.rmdirSync.bind(fs2);
var FN_RIMRAF_SYNC = rimraf.sync;
var _gracefulCleanup = false;
function tmpName(options, callback) {
const args = _parseArguments(options, callback), opts = args[0], cb = args[1];
try {
_assertAndSanitizeOptions(opts);
} catch (err) {
return cb(err);
}
let tries = opts.tries;
(function _getUniqueName() {
try {
const name = _generateTmpName(opts);
fs2.stat(name, function(err) {
if (!err) {
if (tries-- > 0)
return _getUniqueName();
return cb(new Error("Could not get a unique tmp filename, max tries reached " + name));
}
cb(null, name);
});
} catch (err) {
cb(err);
}
})();
}
function tmpNameSync(options) {
const args = _parseArguments(options), opts = args[0];
_assertAndSanitizeOptions(opts);
let tries = opts.tries;
do {
const name = _generateTmpName(opts);
try {
fs2.statSync(name);
} catch (e) {
return name;
}
} while (tries-- > 0);
throw new Error("Could not get a unique tmp filename, max tries reached");
}
function file2(options, callback) {
const args = _parseArguments(options, callback), opts = args[0], cb = args[1];
tmpName(opts, function _tmpNameCreated(err, name) {
if (err)
return cb(err);
fs2.open(name, CREATE_FLAGS, opts.mode || FILE_MODE, function _fileCreated(err2, fd) {
if (err2)
return cb(err2);
if (opts.discardDescriptor) {
return fs2.close(fd, function _discardCallback(possibleErr) {
return cb(possibleErr, name, void 0, _prepareTmpFileRemoveCallback(name, -1, opts, false));
});
} else {
const discardOrDetachDescriptor = opts.discardDescriptor || opts.detachDescriptor;
cb(null, name, fd, _prepareTmpFileRemoveCallback(name, discardOrDetachDescriptor ? -1 : fd, opts, false));
}
});
});
}
function fileSync(options) {
const args = _parseArguments(options), opts = args[0];
const discardOrDetachDescriptor = opts.discardDescriptor || opts.detachDescriptor;
const name = tmpNameSync(opts);
var fd = fs2.openSync(name, CREATE_FLAGS, opts.mode || FILE_MODE);
if (opts.discardDescriptor) {
fs2.closeSync(fd);
fd = void 0;
}
return {
name,
fd,
removeCallback: _prepareTmpFileRemoveCallback(name, discardOrDetachDescriptor ? -1 : fd, opts, true)
};
}
function dir(options, callback) {
const args = _parseArguments(options, callback), opts = args[0], cb = args[1];
tmpName(opts, function _tmpNameCreated(err, name) {
if (err)
return cb(err);
fs2.mkdir(name, opts.mode || DIR_MODE, function _dirCreated(err2) {
if (err2)
return cb(err2);
cb(null, name, _prepareTmpDirRemoveCallback(name, opts, false));
});
});
}
function dirSync(options) {
const args = _parseArguments(options), opts = args[0];
const name = tmpNameSync(opts);
fs2.mkdirSync(name, opts.mode || DIR_MODE);
return {
name,
removeCallback: _prepareTmpDirRemoveCallback(name, opts, true)
};
}
function _removeFileAsync(fdPath, next) {
const _handler = function(err) {
if (err && !_isENOENT(err)) {
return next(err);
}
next();
};
if (0 <= fdPath[0])
fs2.close(fdPath[0], function() {
fs2.unlink(fdPath[1], _handler);
});
else
fs2.unlink(fdPath[1], _handler);
}
function _removeFileSync(fdPath) {
let rethrownException = null;
try {
if (0 <= fdPath[0])
fs2.closeSync(fdPath[0]);
} catch (e) {
if (!_isEBADF(e) && !_isENOENT(e))
throw e;
} finally {
try {
fs2.unlinkSync(fdPath[1]);
} catch (e) {
if (!_isENOENT(e))
rethrownException = e;
}
}
if (rethrownException !== null) {
throw rethrownException;
}
}
function _prepareTmpFileRemoveCallback(name, fd, opts, sync) {
const removeCallbackSync = _prepareRemoveCallback(_removeFileSync, [fd, name], sync);
const removeCallback = _prepareRemoveCallback(_removeFileAsync, [fd, name], sync, removeCallbackSync);
if (!opts.keep)
_removeObjects.unshift(removeCallbackSync);
return sync ? removeCallbackSync : removeCallback;
}
function _prepareTmpDirRemoveCallback(name, opts, sync) {
const removeFunction = opts.unsafeCleanup ? rimraf : fs2.rmdir.bind(fs2);
const removeFunctionSync = opts.unsafeCleanup ? FN_RIMRAF_SYNC : FN_RMDIR_SYNC;
const removeCallbackSync = _prepareRemoveCallback(removeFunctionSync, name, sync);
const removeCallback = _prepareRemoveCallback(removeFunction, name, sync, removeCallbackSync);
if (!opts.keep)
_removeObjects.unshift(removeCallbackSync);
return sync ? removeCallbackSync : removeCallback;
}
function _prepareRemoveCallback(removeFunction, fileOrDirName, sync, cleanupCallbackSync) {
let called = false;
return function _cleanupCallback(next) {
if (!called) {
const toRemove = cleanupCallbackSync || _cleanupCallback;
const index = _removeObjects.indexOf(toRemove);
if (index >= 0)
_removeObjects.splice(index, 1);
called = true;
if (sync || removeFunction === FN_RMDIR_SYNC || removeFunction === FN_RIMRAF_SYNC) {
return removeFunction(fileOrDirName);
} else {
return removeFunction(fileOrDirName, next || function() {
});
}
}
};
}
function _garbageCollector() {
if (!_gracefulCleanup)
return;
while (_removeObjects.length) {
try {
_removeObjects[0]();
} catch (e) {
}
}
}
function _randomChars(howMany) {
let value = [], rnd = null;
try {
rnd = crypto.randomBytes(howMany);
} catch (e) {
rnd = crypto.pseudoRandomBytes(howMany);
}
for (var i = 0; i < howMany; i++) {
value.push(RANDOM_CHARS[rnd[i] % RANDOM_CHARS.length]);
}
return value.join("");
}
function _isBlank(s) {
return s === null || _isUndefined(s) || !s.trim();
}
function _isUndefined(obj) {
return typeof obj === "undefined";
}
function _parseArguments(options, callback) {
if (typeof options === "function") {
return [{}, options];
}
if (_isUndefined(options)) {
return [{}, callback];
}
const actualOptions = {};
for (const key of Object.getOwnPropertyNames(options)) {
actualOptions[key] = options[key];
}
return [actualOptions, callback];
}
function _generateTmpName(opts) {
const tmpDir = opts.tmpdir;
if (!_isUndefined(opts.name))
return path.join(tmpDir, opts.dir, opts.name);
if (!_isUndefined(opts.template))
return path.join(tmpDir, opts.dir, opts.template).replace(TEMPLATE_PATTERN, _randomChars(6));
const name = [
opts.prefix ? opts.prefix : "tmp",
"-",
process.pid,
"-",
_randomChars(12),
opts.postfix ? "-" + opts.postfix : ""
].join("");
return path.join(tmpDir, opts.dir, name);
}
function _assertAndSanitizeOptions(options) {
options.tmpdir = _getTmpDir(options);
const tmpDir = options.tmpdir;
if (!_isUndefined(options.name))
_assertIsRelative(options.name, "name", tmpDir);
if (!_isUndefined(options.dir))
_assertIsRelative(options.dir, "dir", tmpDir);
if (!_isUndefined(options.template)) {
_assertIsRelative(options.template, "template", tmpDir);
if (!options.template.match(TEMPLATE_PATTERN))
throw new Error(`Invalid template, found "${options.template}".`);
}
if (!_isUndefined(options.tries) && isNaN(options.tries) || options.tries < 0)
throw new Error(`Invalid tries, found "${options.tries}".`);
options.tries = _isUndefined(options.name) ? options.tries || DEFAULT_TRIES : 1;
options.keep = !!options.keep;
options.detachDescriptor = !!options.detachDescriptor;
options.discardDescriptor = !!options.discardDescriptor;
options.unsafeCleanup = !!options.unsafeCleanup;
options.dir = _isUndefined(options.dir) ? "" : path.relative(tmpDir, _resolvePath(options.dir, tmpDir));
options.template = _isUndefined(options.template) ? void 0 : path.relative(tmpDir, _resolvePath(options.template, tmpDir));
options.template = _isBlank(options.template) ? void 0 : path.relative(options.dir, options.template);
options.name = _isUndefined(options.name) ? void 0 : _sanitizeName(options.name);
options.prefix = _isUndefined(options.prefix) ? "" : options.prefix;
options.postfix = _isUndefined(options.postfix) ? "" : options.postfix;
}
function _resolvePath(name, tmpDir) {
const sanitizedName = _sanitizeName(name);
if (sanitizedName.startsWith(tmpDir)) {
return path.resolve(sanitizedName);
} else {
return path.resolve(path.join(tmpDir, sanitizedName));
}
}
function _sanitizeName(name) {
if (_isBlank(name)) {
return name;
}
return name.replace(/["']/g, "");
}
function _assertIsRelative(name, option, tmpDir) {
if (option === "name") {
if (path.isAbsolute(name))
throw new Error(`${option} option must not contain an absolute path, found "${name}".`);
let basename = path.basename(name);
if (basename === ".." || basename === "." || basename !== name)
throw new Error(`${option} option must not contain a path, found "${name}".`);
} else {
if (path.isAbsolute(name) && !name.startsWith(tmpDir)) {
throw new Error(`${option} option must be relative to "${tmpDir}", found "${name}".`);
}
let resolvedPath = _resolvePath(name, tmpDir);
if (!resolvedPath.startsWith(tmpDir))
throw new Error(`${option} option must be relative to "${tmpDir}", found "${resolvedPath}".`);
}
}
function _isEBADF(error) {
return _isExpectedError(error, -EBADF, "EBADF");
}
function _isENOENT(error) {
return _isExpectedError(error, -ENOENT, "ENOENT");
}
function _isExpectedError(error, errno, code) {
return IS_WIN32 ? error.code === code : error.code === code && error.errno === errno;
}
function setGracefulCleanup() {
_gracefulCleanup = true;
}
function _getTmpDir(options) {
return path.resolve(_sanitizeName(options && options.tmpdir || os.tmpdir()));
}
process.addListener(EXIT, _garbageCollector);
Object.defineProperty(module2.exports, "tmpdir", {
enumerable: true,
configurable: false,
get: function() {
return _getTmpDir();
}
});
module2.exports.dir = dir;
module2.exports.dirSync = dirSync;
module2.exports.file = file2;
module2.exports.fileSync = fileSync;
module2.exports.tmpName = tmpName;
module2.exports.tmpNameSync = tmpNameSync;
module2.exports.setGracefulCleanup = setGracefulCleanup;
}
});
// src/main.ts
__export(exports, {
default: () => GraphvizPlugin
});
var import_obsidian2 = __toModule(require("obsidian"));
// src/setting.ts
var import_obsidian = __toModule(require("obsidian"));
var DEFAULT_SETTINGS = {
dotPath: "dot",
renderer: "dot",
imageFormat: "png"
};
var GraphvizSettingsTab = class extends import_obsidian.PluginSettingTab {
constructor(plugin) {
super(plugin.app, plugin);
this.plugin = plugin;
}
display() {
const { containerEl } = this;
containerEl.empty();
new import_obsidian.Setting(containerEl).setName("Graphviz renderer").setDesc("Please choose the Graphviz renderer, after that, you will need to restart obsidian.").addDropdown((dropdown) => dropdown.addOption("dot", "dot").addOption("d3_graphviz", "D3 Graphviz (experimental)").setValue(this.plugin.settings.renderer).onChange((value) => __async(this, null, function* () {
this.plugin.settings.renderer = value;
yield this.plugin.saveSettings();
})));
new import_obsidian.Setting(containerEl).setName("Dot Path").setDesc("Dot executable path").addText((text) => text.setPlaceholder(DEFAULT_SETTINGS.dotPath).setValue(this.plugin.settings.dotPath).onChange((value) => __async(this, null, function* () {
this.plugin.settings.dotPath = value;
yield this.plugin.saveSettings();
})));
new import_obsidian.Setting(containerEl).setName("Image format").setDesc("Graphviz output format.").addDropdown((dropdown) => dropdown.addOption("png", "png").addOption("svg", "svg").setValue(this.plugin.settings.imageFormat).onChange((value) => __async(this, null, function* () {
this.plugin.settings.imageFormat = value;
yield this.plugin.saveSettings();
})));
}
};
// src/processors.ts
var tmp = __toModule(require_tmp());
var fs = __toModule(require("fs"));
var import_child_process = __toModule(require("child_process"));
var import_crypto = __toModule(require("crypto"));
var Processors = class {
constructor(plugin) {
this.imageMimeType = new Map([
["png", "image/png"],
["svg", "image/svg+xml"]
]);
this.plugin = plugin;
}
writeDotFile(sourceFile) {
return __async(this, null, function* () {
return new Promise((resolve, reject) => {
const cmdPath = this.plugin.settings.dotPath;
const imageFormat = this.plugin.settings.imageFormat;
const parameters = [`-T${imageFormat}`, sourceFile];
console.debug(`Starting dot process ${cmdPath}, ${parameters}`);
const dotProcess = (0, import_child_process.spawn)(cmdPath, parameters);
const outData = [];
let errData = "";
dotProcess.stdout.on("data", function(data) {
outData.push(data);
});
dotProcess.stderr.on("data", function(data) {
errData += data;
});
dotProcess.stdin.end();
dotProcess.on("exit", function(code) {
if (code !== 0) {
reject(`"${cmdPath} ${parameters}" failed, error code: ${code}, stderr: ${errData}`);
} else {
resolve(Buffer.concat(outData));
}
});
dotProcess.on("error", function(err) {
reject(`"${cmdPath} ${parameters}" failed, ${err}`);
});
});
});
}
convertToImage(source) {
return __async(this, null, function* () {
const self = this;
return new Promise((resolve, reject) => {
tmp.file(function(err, tmpPath, fd, _) {
if (err)
reject(err);
fs.write(fd, source, function(err2) {
if (err2) {
reject(`write to ${tmpPath} error ${err2}`);
return;
}
fs.close(fd, function(err3) {
if (err3) {
reject(`close ${tmpPath} error ${err3}`);
return;
}
return self.writeDotFile(tmpPath).then((data) => resolve(data)).catch((message) => reject(message));
});
});
});
});
});
}
imageProcessor(source, el, _) {
return __async(this, null, function* () {
try {
console.debug("Call image processor");
const imageData = yield this.convertToImage(source);
const blob = new Blob([imageData], { "type": this.imageMimeType.get(this.plugin.settings.imageFormat) });
const url = window.URL || window.webkitURL;
const blobUrl = url.createObjectURL(blob);
const img = document.createElement("img");
img.src = blobUrl;
el.appendChild(img);
} catch (errMessage) {
console.error("convert to image error", errMessage);
const pre = document.createElement("pre");
const code = document.createElement("code");
pre.appendChild(code);
code.setText(errMessage);
el.appendChild(pre);
}
});
}
d3graphvizProcessor(source, el, _) {
return __async(this, null, function* () {
console.debug("Call d3graphvizProcessor");
const div = document.createElement("div");
const graphId = "d3graph_" + (0, import_crypto.createHash)("md5").update(source).digest("hex").substring(0, 6);
div.setAttr("id", graphId);
div.setAttr("style", "text-align: center");
el.appendChild(div);
const script = document.createElement("script");
const escapedSource = source.replaceAll("\\", "\\\\").replaceAll("`", "\\`");
script.text = `if( typeof d3 != 'undefined') {
d3.select("#${graphId}").graphviz()
.onerror(d3error)
.renderDot(\`${escapedSource}\`);
}
function d3error (err) {
d3.select("#${graphId}").html(\`<div class="d3graphvizError"> d3.graphviz(): \`+err.toString()+\`</div>\`);
console.error('Caught error on ${graphId}: ', err);
}`;
el.appendChild(script);
});
}
};
// src/main.ts
var GraphvizPlugin = class extends import_obsidian2.Plugin {
onload() {
return __async(this, null, function* () {
console.debug("Load graphviz plugin");
yield this.loadSettings();
this.addSettingTab(new GraphvizSettingsTab(this));
const processors = new Processors(this);
const d3Sources = [
"https://d3js.org/d3.v5.min.js",
"https://unpkg.com/@hpcc-js/wasm@0.3.11/dist/index.min.js",
"https://unpkg.com/d3-graphviz@3.0.5/build/d3-graphviz.js"
];
this.app.workspace.onLayoutReady(() => {
switch (this.settings.renderer) {
case "d3_graphviz":
for (const src of d3Sources) {
const script = document.createElement("script");
script.src = src;
(document.head || document.documentElement).appendChild(script);
}
this.registerMarkdownCodeBlockProcessor("dot", processors.d3graphvizProcessor.bind(processors));
break;
default:
this.registerMarkdownCodeBlockProcessor("dot", processors.imageProcessor.bind(processors));
}
});
});
}
onunload() {
console.debug("Unload graphviz plugin");
}
loadSettings() {
return __async(this, null, function* () {
this.settings = Object.assign({}, DEFAULT_SETTINGS, yield this.loadData());
return Promise.resolve();
});
}
saveSettings() {
return __async(this, null, function* () {
yield this.saveData(this.settings);
});
}
};
/*!
* Tmp
*
* Copyright (c) 2011-2017 KARASZI Istvan <github@spam.raszi.hu>
*
* MIT Licensed
*/