shared.cjs 9.2 KB

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