shared.cjs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. "use strict";
  2. var __create = Object.create;
  3. var __defProp = Object.defineProperty;
  4. var __defProps = Object.defineProperties;
  5. var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
  6. var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
  7. var __getOwnPropNames = Object.getOwnPropertyNames;
  8. var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  9. var __getProtoOf = Object.getPrototypeOf;
  10. var __hasOwnProp = Object.prototype.hasOwnProperty;
  11. var __propIsEnum = Object.prototype.propertyIsEnumerable;
  12. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  13. var __spreadValues = (a, b) => {
  14. for (var prop in b || (b = {}))
  15. if (__hasOwnProp.call(b, prop))
  16. __defNormalProp(a, prop, b[prop]);
  17. if (__getOwnPropSymbols)
  18. for (var prop of __getOwnPropSymbols(b)) {
  19. if (__propIsEnum.call(b, prop))
  20. __defNormalProp(a, prop, b[prop]);
  21. }
  22. return a;
  23. };
  24. var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
  25. var __export = (target, all) => {
  26. for (var name in all)
  27. __defProp(target, name, { get: all[name], enumerable: true });
  28. };
  29. var __copyProps = (to, from, except, desc) => {
  30. if (from && typeof from === "object" || typeof from === "function") {
  31. for (let key of __getOwnPropNames(from))
  32. if (!__hasOwnProp.call(to, key) && key !== except)
  33. __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  34. }
  35. return to;
  36. };
  37. var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  38. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  39. mod
  40. ));
  41. var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
  42. var __publicField = (obj, key, value) => {
  43. __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
  44. return value;
  45. };
  46. var __accessCheck = (obj, member, msg) => {
  47. if (!member.has(obj))
  48. throw TypeError("Cannot " + msg);
  49. };
  50. var __privateGet = (obj, member, getter) => {
  51. __accessCheck(obj, member, "read from private field");
  52. return getter ? getter.call(obj) : member.get(obj);
  53. };
  54. var __privateAdd = (obj, member, value) => {
  55. if (member.has(obj))
  56. throw TypeError("Cannot add the same private member more than once");
  57. member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
  58. };
  59. var __privateSet = (obj, member, value, setter) => {
  60. __accessCheck(obj, member, "write to private field");
  61. setter ? setter.call(obj, value) : member.set(obj, value);
  62. return value;
  63. };
  64. var __privateWrapper = (obj, member, setter, getter) => ({
  65. set _(value) {
  66. __privateSet(obj, member, value, setter);
  67. },
  68. get _() {
  69. return __privateGet(obj, member, getter);
  70. }
  71. });
  72. // shared.ts
  73. var shared_exports = {};
  74. __export(shared_exports, {
  75. isPackageListed: () => isPackageListed,
  76. loadPackageJSON: () => loadPackageJSON
  77. });
  78. module.exports = __toCommonJS(shared_exports);
  79. var import_fs = require("fs");
  80. // node_modules/.pnpm/find-up@6.3.0/node_modules/find-up/index.js
  81. var import_node_path2 = __toESM(require("path"), 1);
  82. var import_node_url2 = require("url");
  83. // node_modules/.pnpm/locate-path@7.1.1/node_modules/locate-path/index.js
  84. var import_node_process = __toESM(require("process"), 1);
  85. var import_node_path = __toESM(require("path"), 1);
  86. var import_node_fs = __toESM(require("fs"), 1);
  87. var import_node_url = require("url");
  88. // node_modules/.pnpm/yocto-queue@1.0.0/node_modules/yocto-queue/index.js
  89. var Node = class {
  90. constructor(value) {
  91. __publicField(this, "value");
  92. __publicField(this, "next");
  93. this.value = value;
  94. }
  95. };
  96. var _head, _tail, _size;
  97. var Queue = class {
  98. constructor() {
  99. __privateAdd(this, _head, void 0);
  100. __privateAdd(this, _tail, void 0);
  101. __privateAdd(this, _size, void 0);
  102. this.clear();
  103. }
  104. enqueue(value) {
  105. const node = new Node(value);
  106. if (__privateGet(this, _head)) {
  107. __privateGet(this, _tail).next = node;
  108. __privateSet(this, _tail, node);
  109. } else {
  110. __privateSet(this, _head, node);
  111. __privateSet(this, _tail, node);
  112. }
  113. __privateWrapper(this, _size)._++;
  114. }
  115. dequeue() {
  116. const current = __privateGet(this, _head);
  117. if (!current) {
  118. return;
  119. }
  120. __privateSet(this, _head, __privateGet(this, _head).next);
  121. __privateWrapper(this, _size)._--;
  122. return current.value;
  123. }
  124. clear() {
  125. __privateSet(this, _head, void 0);
  126. __privateSet(this, _tail, void 0);
  127. __privateSet(this, _size, 0);
  128. }
  129. get size() {
  130. return __privateGet(this, _size);
  131. }
  132. *[Symbol.iterator]() {
  133. let current = __privateGet(this, _head);
  134. while (current) {
  135. yield current.value;
  136. current = current.next;
  137. }
  138. }
  139. };
  140. _head = new WeakMap();
  141. _tail = new WeakMap();
  142. _size = new WeakMap();
  143. // node_modules/.pnpm/p-limit@4.0.0/node_modules/p-limit/index.js
  144. function pLimit(concurrency) {
  145. if (!((Number.isInteger(concurrency) || concurrency === Number.POSITIVE_INFINITY) && concurrency > 0)) {
  146. throw new TypeError("Expected `concurrency` to be a number from 1 and up");
  147. }
  148. const queue = new Queue();
  149. let activeCount = 0;
  150. const next = () => {
  151. activeCount--;
  152. if (queue.size > 0) {
  153. queue.dequeue()();
  154. }
  155. };
  156. const run = async (fn, resolve, args) => {
  157. activeCount++;
  158. const result = (async () => fn(...args))();
  159. resolve(result);
  160. try {
  161. await result;
  162. } catch (e) {
  163. }
  164. next();
  165. };
  166. const enqueue = (fn, resolve, args) => {
  167. queue.enqueue(run.bind(void 0, fn, resolve, args));
  168. (async () => {
  169. await Promise.resolve();
  170. if (activeCount < concurrency && queue.size > 0) {
  171. queue.dequeue()();
  172. }
  173. })();
  174. };
  175. const generator = (fn, ...args) => new Promise((resolve) => {
  176. enqueue(fn, resolve, args);
  177. });
  178. Object.defineProperties(generator, {
  179. activeCount: {
  180. get: () => activeCount
  181. },
  182. pendingCount: {
  183. get: () => queue.size
  184. },
  185. clearQueue: {
  186. value: () => {
  187. queue.clear();
  188. }
  189. }
  190. });
  191. return generator;
  192. }
  193. // node_modules/.pnpm/p-locate@6.0.0/node_modules/p-locate/index.js
  194. var EndError = class extends Error {
  195. constructor(value) {
  196. super();
  197. this.value = value;
  198. }
  199. };
  200. var testElement = async (element, tester) => tester(await element);
  201. var finder = async (element) => {
  202. const values = await Promise.all(element);
  203. if (values[1] === true) {
  204. throw new EndError(values[0]);
  205. }
  206. return false;
  207. };
  208. async function pLocate(iterable, tester, {
  209. concurrency = Number.POSITIVE_INFINITY,
  210. preserveOrder = true
  211. } = {}) {
  212. const limit = pLimit(concurrency);
  213. const items = [...iterable].map((element) => [element, limit(testElement, element, tester)]);
  214. const checkLimit = pLimit(preserveOrder ? 1 : Number.POSITIVE_INFINITY);
  215. try {
  216. await Promise.all(items.map((element) => checkLimit(finder, element)));
  217. } catch (error) {
  218. if (error instanceof EndError) {
  219. return error.value;
  220. }
  221. throw error;
  222. }
  223. }
  224. // node_modules/.pnpm/locate-path@7.1.1/node_modules/locate-path/index.js
  225. var typeMappings = {
  226. directory: "isDirectory",
  227. file: "isFile"
  228. };
  229. function checkType(type) {
  230. if (Object.hasOwnProperty.call(typeMappings, type)) {
  231. return;
  232. }
  233. throw new Error(`Invalid type specified: ${type}`);
  234. }
  235. var matchType = (type, stat) => stat[typeMappings[type]]();
  236. var toPath = (urlOrPath) => urlOrPath instanceof URL ? (0, import_node_url.fileURLToPath)(urlOrPath) : urlOrPath;
  237. async function locatePath(paths, {
  238. cwd = import_node_process.default.cwd(),
  239. type = "file",
  240. allowSymlinks = true,
  241. concurrency,
  242. preserveOrder
  243. } = {}) {
  244. checkType(type);
  245. cwd = toPath(cwd);
  246. const statFunction = allowSymlinks ? import_node_fs.promises.stat : import_node_fs.promises.lstat;
  247. return pLocate(paths, async (path_) => {
  248. try {
  249. const stat = await statFunction(import_node_path.default.resolve(cwd, path_));
  250. return matchType(type, stat);
  251. } catch (e) {
  252. return false;
  253. }
  254. }, { concurrency, preserveOrder });
  255. }
  256. // node_modules/.pnpm/path-exists@5.0.0/node_modules/path-exists/index.js
  257. var import_node_fs2 = __toESM(require("fs"), 1);
  258. // node_modules/.pnpm/find-up@6.3.0/node_modules/find-up/index.js
  259. var toPath2 = (urlOrPath) => urlOrPath instanceof URL ? (0, import_node_url2.fileURLToPath)(urlOrPath) : urlOrPath;
  260. var findUpStop = Symbol("findUpStop");
  261. async function findUpMultiple(name, options = {}) {
  262. let directory = import_node_path2.default.resolve(toPath2(options.cwd) || "");
  263. const { root } = import_node_path2.default.parse(directory);
  264. const stopAt = import_node_path2.default.resolve(directory, options.stopAt || root);
  265. const limit = options.limit || Number.POSITIVE_INFINITY;
  266. const paths = [name].flat();
  267. const runMatcher = async (locateOptions) => {
  268. if (typeof name !== "function") {
  269. return locatePath(paths, locateOptions);
  270. }
  271. const foundPath = await name(locateOptions.cwd);
  272. if (typeof foundPath === "string") {
  273. return locatePath([foundPath], locateOptions);
  274. }
  275. return foundPath;
  276. };
  277. const matches = [];
  278. while (true) {
  279. const foundPath = await runMatcher(__spreadProps(__spreadValues({}, options), { cwd: directory }));
  280. if (foundPath === findUpStop) {
  281. break;
  282. }
  283. if (foundPath) {
  284. matches.push(import_node_path2.default.resolve(directory, foundPath));
  285. }
  286. if (directory === stopAt || matches.length >= limit) {
  287. break;
  288. }
  289. directory = import_node_path2.default.dirname(directory);
  290. }
  291. return matches;
  292. }
  293. async function findUp(name, options = {}) {
  294. const matches = await findUpMultiple(name, __spreadProps(__spreadValues({}, options), { limit: 1 }));
  295. return matches[0];
  296. }
  297. // shared.ts
  298. async function loadPackageJSON(cwd = process.cwd()) {
  299. const path3 = await findUp("package.json", { cwd });
  300. if (!path3 || !(0, import_fs.existsSync)(path3))
  301. return null;
  302. return JSON.parse(await import_fs.promises.readFile(path3, "utf-8"));
  303. }
  304. async function isPackageListed(name, cwd) {
  305. const pkg = await loadPackageJSON(cwd) || {};
  306. return name in (pkg.dependencies || {}) || name in (pkg.devDependencies || {});
  307. }
  308. // Annotate the CommonJS export names for ESM import in node:
  309. 0 && (module.exports = {
  310. isPackageListed,
  311. loadPackageJSON
  312. });