shared.mjs 8.5 KB

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