shared.mjs 7.4 KB

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