meodp 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/README.md +28 -1
  2. package/dist/check/cli.cjs +130 -39
  3. package/dist/check/cli.mjs +130 -39
  4. package/dist/check/index.cjs +12 -8
  5. package/dist/check/index.d.cts +5 -68
  6. package/dist/check/index.d.mts +5 -68
  7. package/dist/check/index.d.ts +5 -68
  8. package/dist/check/index.mjs +4 -2
  9. package/dist/cli/main.cjs +59 -6
  10. package/dist/cli/main.mjs +59 -6
  11. package/dist/config/index.cjs +7 -0
  12. package/dist/config/index.d.cts +47 -0
  13. package/dist/config/index.d.mts +47 -0
  14. package/dist/config/index.d.ts +47 -0
  15. package/dist/config/index.mjs +5 -0
  16. package/dist/notify/cli.cjs +107 -0
  17. package/dist/notify/cli.d.cts +3 -0
  18. package/dist/notify/cli.d.mts +3 -0
  19. package/dist/notify/cli.d.ts +3 -0
  20. package/dist/notify/cli.mjs +101 -0
  21. package/dist/notify/email.cjs +38 -0
  22. package/dist/notify/email.d.cts +29 -0
  23. package/dist/notify/email.d.mts +29 -0
  24. package/dist/notify/email.d.ts +29 -0
  25. package/dist/notify/email.mjs +35 -0
  26. package/dist/notify/feishu.cjs +162 -0
  27. package/dist/notify/feishu.d.cts +74 -0
  28. package/dist/notify/feishu.d.mts +74 -0
  29. package/dist/notify/feishu.d.ts +74 -0
  30. package/dist/notify/feishu.mjs +157 -0
  31. package/dist/notify/index.cjs +64 -0
  32. package/dist/notify/index.d.cts +27 -0
  33. package/dist/notify/index.d.mts +27 -0
  34. package/dist/notify/index.d.ts +27 -0
  35. package/dist/notify/index.mjs +62 -0
  36. package/dist/shared/{meodp.a0bcc3e7.cjs → meodp.2b00b0ae.cjs} +13 -365
  37. package/dist/shared/meodp.4f1da070.d.cts +41 -0
  38. package/dist/shared/meodp.63483e20.cjs +30 -0
  39. package/dist/shared/meodp.80ff918d.mjs +465 -0
  40. package/dist/shared/meodp.8369c4c1.d.ts +41 -0
  41. package/dist/shared/meodp.93e06e00.d.cts +64 -0
  42. package/dist/shared/meodp.93e06e00.d.mts +64 -0
  43. package/dist/shared/meodp.93e06e00.d.ts +64 -0
  44. package/dist/shared/{meodp.d0916bc5.mjs → meodp.9c706389.mjs} +1 -350
  45. package/dist/shared/meodp.a704f8db.d.mts +41 -0
  46. package/dist/shared/meodp.c4c70565.cjs +477 -0
  47. package/dist/shared/meodp.f96d0510.mjs +24 -0
  48. package/package.json +50 -3
@@ -1,187 +1,8 @@
1
1
  'use strict';
2
2
 
3
- const promises = require('node:timers/promises');
4
- const linkinator = require('linkinator');
5
- const node_os = require('node:os');
6
3
  const node_crypto = require('node:crypto');
7
- const promises$1 = require('node:fs/promises');
4
+ const promises = require('node:fs/promises');
8
5
  const path = require('node:path');
9
- const node_buffer = require('node:buffer');
10
- const node_util = require('node:util');
11
- const node_zlib = require('node:zlib');
12
- const fastXmlParser = require('fast-xml-parser');
13
-
14
- function normalizeUrl(value) {
15
- const url = new URL(value);
16
- if (!["http:", "https:"].includes(url.protocol) || url.username || url.password)
17
- throw new Error("Expected an HTTP(S) URL without embedded credentials");
18
- url.hash = "";
19
- return url.href;
20
- }
21
- function normalizeTargets(input) {
22
- if (!Array.isArray(input))
23
- throw new TypeError("Input must be an array of URLs or objects with a url field");
24
- const seen = /* @__PURE__ */ new Set();
25
- return input.map((item, index) => {
26
- const value = typeof item === "string" ? { url: item } : item;
27
- if (!value || typeof value !== "object" || !("url" in value) || typeof value.url !== "string")
28
- throw new TypeError(`Invalid link at index ${index}: expected a url string`);
29
- let url;
30
- try {
31
- url = normalizeUrl(value.url.trim());
32
- } catch {
33
- throw new TypeError(`Invalid HTTP(S) URL at index ${index}`);
34
- }
35
- if ("name" in value && value.name !== void 0 && typeof value.name !== "string")
36
- throw new TypeError(`Invalid name at index ${index}: expected a string`);
37
- return { url, ..."name" in value && typeof value.name === "string" ? { name: value.name } : {} };
38
- }).filter((item) => {
39
- if (seen.has(item.url))
40
- return false;
41
- seen.add(item.url);
42
- return true;
43
- });
44
- }
45
-
46
- function integerOption(value, fallback, name, minimum, maximum) {
47
- const result = value ?? fallback;
48
- if (!Number.isInteger(result) || result < minimum || result > maximum)
49
- throw new RangeError(`${name} must be an integer between ${minimum} and ${maximum}`);
50
- return result;
51
- }
52
- function normalizeCheckOptions(options) {
53
- const concurrency = integerOption(options.concurrency, 5, "concurrency", 1, 100);
54
- const timeoutMs = integerOption(options.timeoutMs, 1e4, "timeoutMs", 1, 3e5);
55
- const retries = integerOption(options.retries, 1, "retries", 0, 5);
56
- const maxRedirects = integerOption(options.maxRedirects, 5, "maxRedirects", 0, 20);
57
- const observer = options.observer ?? node_os.hostname();
58
- if (!observer.trim())
59
- throw new TypeError("observer must not be empty");
60
- if (options.previousReport && options.previousReport.observer !== observer)
61
- throw new Error("Previous report belongs to another observer; use a separate history file");
62
- return { concurrency, timeoutMs, retries, maxRedirects, observer };
63
- }
64
-
65
- function failureDetail(result) {
66
- const error = result.failureDetails?.find((item) => item instanceof Error);
67
- const parts = [];
68
- let current = error;
69
- for (let depth = 0; current && typeof current === "object" && depth < 5; depth++) {
70
- for (const key of ["name", "code", "message"]) {
71
- const value = Reflect.get(current, key);
72
- if (typeof value === "string")
73
- parts.push(value);
74
- }
75
- current = "cause" in current ? current.cause : void 0;
76
- }
77
- const detail = parts.join(": ") || `HTTP ${result.status ?? 0}`;
78
- if (/ENOTFOUND|EAI_AGAIN|EAI_FAIL/.test(detail))
79
- return { reason: "dns", detail };
80
- if (/CERT|TLS|SSL/i.test(detail))
81
- return { reason: "tls", detail };
82
- if (/timeout|timed out|ETIMEDOUT|UND_ERR_.*TIMEOUT/i.test(detail))
83
- return { reason: "timeout", detail };
84
- return { reason: result.status ? "http" : "network", detail };
85
- }
86
- async function probe(url, timeoutMs, maxRedirects) {
87
- const redirects = [];
88
- const visited = /* @__PURE__ */ new Set();
89
- let current = url;
90
- for (; ; ) {
91
- visited.add(current);
92
- const checker = new linkinator.LinkChecker();
93
- const { links } = await checker.check({
94
- path: current,
95
- recurse: false,
96
- concurrency: 1,
97
- timeout: timeoutMs,
98
- retry: false,
99
- retryErrors: false,
100
- redirects: "error",
101
- linksToSkip: async (candidate) => candidate !== current
102
- });
103
- const result = links.find((item) => item.url === current && !item.parent);
104
- if (!result)
105
- throw new Error("The HTTP checker returned no result for the requested URL");
106
- const httpStatus = result.status || void 0;
107
- const base = { finalUrl: current, httpStatus, redirects };
108
- if (httpStatus && [301, 302, 303, 307, 308].includes(httpStatus)) {
109
- const response = result.failureDetails?.find((item) => "headers" in item);
110
- const location = response && "headers" in response ? response.headers.location : void 0;
111
- let next;
112
- try {
113
- if (!location)
114
- throw new Error("Missing redirect location");
115
- next = normalizeUrl(new URL(location, current).href);
116
- } catch {
117
- return { ...base, status: "unavailable", reason: "redirect", detail: "Missing or invalid HTTP(S) redirect destination" };
118
- }
119
- redirects.push({ url: current, status: httpStatus, location: next });
120
- if (visited.has(next) || redirects.length > maxRedirects) {
121
- return {
122
- ...base,
123
- status: "unavailable",
124
- reason: "redirect",
125
- detail: visited.has(next) ? "Redirect loop" : "Redirect limit exceeded"
126
- };
127
- }
128
- current = next;
129
- continue;
130
- }
131
- if (httpStatus && httpStatus >= 200 && httpStatus < 300)
132
- return { ...base, status: "reachable" };
133
- if (httpStatus && [401, 403, 429, 451, 999].includes(httpStatus))
134
- return { ...base, status: "restricted", reason: "http", detail: `HTTP ${httpStatus}: access requires review` };
135
- return { ...base, status: "unavailable", ...failureDetail(result) };
136
- }
137
- }
138
- async function checkLinks(input, options = {}) {
139
- const targets = normalizeTargets(input);
140
- const { concurrency, timeoutMs, retries, maxRedirects, observer } = normalizeCheckOptions(options);
141
- const startedAt = (/* @__PURE__ */ new Date()).toISOString();
142
- const previous = new Map(options.previousReport?.results.map((item) => [item.url, item]));
143
- const results = [];
144
- let cursor = 0;
145
- await Promise.all(Array.from({ length: Math.min(concurrency, targets.length) }, async () => {
146
- while (cursor < targets.length) {
147
- const index = cursor++;
148
- const target = targets[index];
149
- const start = Date.now();
150
- let attempts = 0;
151
- let observation;
152
- do {
153
- if (attempts > 0)
154
- await promises.setTimeout(500 * 2 ** (attempts - 1));
155
- attempts++;
156
- observation = await probe(target.url, timeoutMs, maxRedirects);
157
- } while (attempts <= retries && observation.status === "unavailable" && observation.reason !== "redirect" && (!observation.httpStatus || observation.httpStatus >= 500));
158
- const checkedAt = (/* @__PURE__ */ new Date()).toISOString();
159
- const old = previous.get(target.url);
160
- const failed = observation.status === "unavailable";
161
- const result = {
162
- ...target,
163
- ...observation,
164
- checkedAt,
165
- durationMs: Date.now() - start,
166
- attempts,
167
- consecutiveFailures: failed ? (old?.status === "unavailable" ? old.consecutiveFailures : 0) + 1 : 0,
168
- firstFailureAt: failed ? old?.status === "unavailable" ? old.firstFailureAt ?? checkedAt : checkedAt : void 0,
169
- lastSuccessAt: observation.status === "reachable" ? checkedAt : old?.lastSuccessAt,
170
- changed: Boolean(old && (old.status !== observation.status || old.finalUrl !== observation.finalUrl)),
171
- recovered: observation.status === "reachable" && old?.status === "unavailable"
172
- };
173
- results[index] = result;
174
- await options.onResult?.(result);
175
- }
176
- }));
177
- const summary = { total: results.length, reachable: 0, restricted: 0, unavailable: 0, redirected: 0, recovered: 0 };
178
- for (const result of results) {
179
- summary[result.status]++;
180
- summary.redirected += Number(result.redirects.length > 0);
181
- summary.recovered += Number(result.recovered);
182
- }
183
- return { schemaVersion: 1, observer, startedAt, completedAt: (/* @__PURE__ */ new Date()).toISOString(), summary, results };
184
- }
185
6
 
186
7
  function parseReport(data) {
187
8
  const invalid = (field) => {
@@ -363,27 +184,27 @@ function formatReport(report, format = "markdown") {
363
184
  ].join("\n");
364
185
  }
365
186
  async function writeReports(report, directory) {
366
- await promises$1.mkdir(directory, { recursive: true });
187
+ await promises.mkdir(directory, { recursive: true });
367
188
  const paths = { json: path.join(directory, "report.json"), markdown: path.join(directory, "report.md"), html: path.join(directory, "report.html") };
368
- await promises$1.writeFile(paths.json, formatReport(report, "json"));
369
- await promises$1.writeFile(paths.markdown, formatReport(report, "markdown"));
370
- await promises$1.writeFile(paths.html, formatReport(report, "html"));
189
+ await promises.writeFile(paths.json, formatReport(report, "json"));
190
+ await promises.writeFile(paths.markdown, formatReport(report, "markdown"));
191
+ await promises.writeFile(paths.html, formatReport(report, "html"));
371
192
  return paths;
372
193
  }
373
194
  async function writeReportSite(report, directory, options = {}) {
374
195
  const html = createReportHtml(report, { dataUrl: report ? "./report.json" : void 0, ...options });
375
- await promises$1.mkdir(directory, { recursive: true });
196
+ await promises.mkdir(directory, { recursive: true });
376
197
  const index = path.join(directory, "index.html");
377
198
  const json = report ? path.join(directory, "report.json") : void 0;
378
199
  if (json)
379
- await promises$1.writeFile(json, formatReport(report, "json"));
380
- await promises$1.writeFile(index, html);
200
+ await promises.writeFile(json, formatReport(report, "json"));
201
+ await promises.writeFile(index, html);
381
202
  return { index, json };
382
203
  }
383
204
  async function readReport(path) {
384
205
  let data;
385
206
  try {
386
- data = JSON.parse(await promises$1.readFile(path, "utf8"));
207
+ data = JSON.parse(await promises.readFile(path, "utf8"));
387
208
  } catch (error) {
388
209
  if (error && typeof error === "object" && "code" in error && error.code === "ENOENT")
389
210
  return void 0;
@@ -392,189 +213,16 @@ async function readReport(path) {
392
213
  return parseReport(data);
393
214
  }
394
215
  async function saveReport(report, path$1) {
395
- await promises$1.mkdir(path.dirname(path$1), { recursive: true });
216
+ await promises.mkdir(path.dirname(path$1), { recursive: true });
396
217
  const temporary = `${path$1}.${node_crypto.randomUUID()}.tmp`;
397
- await promises$1.writeFile(temporary, formatReport(report, "json"));
398
- await promises$1.rename(temporary, path$1);
399
- }
400
-
401
- const unzip = node_util.promisify(node_zlib.gunzip);
402
- class DocumentError extends Error {
403
- constructor(message, retryable = false) {
404
- super(message);
405
- this.retryable = retryable;
406
- }
407
- }
408
- function discoveryOptions(options) {
409
- const normalized = normalizeCheckOptions(options);
410
- if (options.discover !== void 0 && typeof options.discover !== "boolean")
411
- throw new TypeError("discover must be a boolean");
412
- return {
413
- ...normalized,
414
- maxUrls: integerOption(options.maxUrls, 1e4, "maxUrls", 1, 5e4),
415
- maxSitemaps: integerOption(options.maxSitemaps, 100, "maxSitemaps", 1, 1e4),
416
- maxSitemapBytes: integerOption(options.maxSitemapBytes, 10 * 1024 * 1024, "maxSitemapBytes", 1, 100 * 1024 * 1024)
417
- };
418
- }
419
- async function readDocument(source, options, allowMissing = false) {
420
- for (let attempt = 0; ; attempt++) {
421
- try {
422
- let url = source;
423
- const visited = /* @__PURE__ */ new Set();
424
- for (; ; ) {
425
- visited.add(url);
426
- const response = await fetch(url, {
427
- redirect: "manual",
428
- signal: AbortSignal.timeout(options.timeoutMs)
429
- });
430
- if ([301, 302, 303, 307, 308].includes(response.status)) {
431
- await response.body?.cancel();
432
- const location = response.headers.get("location");
433
- let next;
434
- try {
435
- if (!location)
436
- throw new Error("Missing location");
437
- next = normalizeUrl(new URL(location, url).href);
438
- } catch {
439
- throw new DocumentError(`Invalid sitemap/robots redirect from ${url}`);
440
- }
441
- if (visited.has(next) || visited.size > options.maxRedirects)
442
- throw new DocumentError(`Sitemap/robots redirect loop or limit exceeded: ${url}`);
443
- url = next;
444
- continue;
445
- }
446
- if (!response.ok) {
447
- await response.body?.cancel();
448
- if (allowMissing && [404, 410].includes(response.status))
449
- return void 0;
450
- throw new DocumentError(`Unable to read ${url}: HTTP ${response.status}`, response.status >= 500);
451
- }
452
- const chunks = [];
453
- let size = 0;
454
- if (response.body) {
455
- const reader = response.body.getReader();
456
- try {
457
- for (; ; ) {
458
- const { done, value } = await reader.read();
459
- if (done)
460
- break;
461
- size += value.byteLength;
462
- if (size > options.maxSitemapBytes)
463
- throw new DocumentError(`Discovery document exceeds maxSitemapBytes: ${url}`);
464
- chunks.push(value);
465
- }
466
- } finally {
467
- await reader.cancel().catch(() => {
468
- });
469
- reader.releaseLock();
470
- }
471
- }
472
- let body = node_buffer.Buffer.concat(chunks);
473
- if (body[0] === 31 && body[1] === 139) {
474
- try {
475
- body = await unzip(body, { maxOutputLength: options.maxSitemapBytes });
476
- } catch {
477
- throw new DocumentError(`Invalid gzip or decompressed document exceeds maxSitemapBytes: ${url}`);
478
- }
479
- }
480
- return { url, text: body.toString("utf8") };
481
- }
482
- } catch (error) {
483
- if (attempt >= options.retries || error instanceof DocumentError && !error.retryable)
484
- throw new Error(`Sitemap discovery failed: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
485
- await promises.setTimeout(500 * 2 ** attempt);
486
- }
487
- }
488
- }
489
- function parseLocations(text, source) {
490
- if (/<!DOCTYPE|<!ENTITY/i.test(text) || fastXmlParser.XMLValidator.validate(text) !== true)
491
- throw new Error(`Invalid sitemap XML: ${source}`);
492
- const parser = new fastXmlParser.XMLParser({
493
- ignoreAttributes: true,
494
- removeNSPrefix: true,
495
- parseTagValue: false,
496
- isArray: (name) => name === "url" || name === "sitemap"
497
- });
498
- const document = parser.parse(text);
499
- const roots = Object.keys(document).filter((key) => !key.startsWith("?"));
500
- if (roots.length !== 1 || !["urlset", "sitemapindex"].includes(roots[0]))
501
- throw new Error(`Expected a sitemap urlset or sitemapindex: ${source}`);
502
- const isIndex = roots[0] === "sitemapindex";
503
- const root = document[roots[0]];
504
- if (root?.[isIndex ? "url" : "sitemap"])
505
- throw new Error(`Mixed sitemap index and page entries: ${source}`);
506
- const entries = root?.[isIndex ? "sitemap" : "url"] ?? [];
507
- const urls = entries.map((entry) => {
508
- if (!entry || typeof entry !== "object" || !("loc" in entry) || typeof entry.loc !== "string" || !entry.loc.trim())
509
- throw new Error(`Missing or invalid sitemap loc: ${source}`);
510
- try {
511
- return normalizeUrl(new URL(entry.loc.trim(), source).href);
512
- } catch {
513
- throw new Error(`Invalid HTTP(S) URL in sitemap: ${source}`);
514
- }
515
- });
516
- return { isIndex, urls };
517
- }
518
- async function readSitemapUrls(source, options = {}) {
519
- const input = normalizeUrl(source.trim());
520
- const config = discoveryOptions(options);
521
- let pending = [input];
522
- if (options.discover) {
523
- const robots = await readDocument(new URL("/robots.txt", input).href, config, true);
524
- const declared = robots?.text.split(/\r?\n/).flatMap((line) => {
525
- const match = line.match(/^\s*sitemap\s*:\s*(\S+)/i);
526
- return match ? [normalizeUrl(new URL(match[1], robots.url).href)] : [];
527
- }) ?? [];
528
- pending = declared.length ? declared : [new URL("/sitemap.xml", input).href];
529
- }
530
- const queued = new Set(pending);
531
- pending = [...queued];
532
- const visited = /* @__PURE__ */ new Set();
533
- const pages = /* @__PURE__ */ new Set();
534
- let documentCount = 0;
535
- for (let cursor = 0; cursor < pending.length; cursor++) {
536
- const url = pending[cursor];
537
- if (visited.has(url))
538
- continue;
539
- if (++documentCount > config.maxSitemaps)
540
- throw new Error("Sitemap discovery exceeds maxSitemaps; no pages were checked");
541
- visited.add(url);
542
- const document = await readDocument(url, config);
543
- if (!document)
544
- throw new Error(`Unable to read sitemap: ${url}`);
545
- visited.add(document.url);
546
- const { isIndex, urls } = parseLocations(document.text, document.url);
547
- for (const location of urls) {
548
- if (isIndex) {
549
- if (!queued.has(location) && !visited.has(location)) {
550
- queued.add(location);
551
- pending.push(location);
552
- }
553
- } else {
554
- pages.add(location);
555
- if (pages.size > config.maxUrls)
556
- throw new Error("Sitemap discovery exceeds maxUrls; no pages were checked");
557
- }
558
- }
559
- }
560
- if (!pages.size)
561
- throw new Error("Sitemap discovery found no page URLs; no pages were checked");
562
- return [...pages];
563
- }
564
- async function checkSitemap(source, options = {}) {
565
- const startedAt = (/* @__PURE__ */ new Date()).toISOString();
566
- const urls = await readSitemapUrls(source, options);
567
- const report = await checkLinks(urls, options);
568
- return { ...report, startedAt };
218
+ await promises.writeFile(temporary, formatReport(report, "json"));
219
+ await promises.rename(temporary, path$1);
569
220
  }
570
221
 
571
- exports.checkLinks = checkLinks;
572
- exports.checkSitemap = checkSitemap;
222
+ exports.createReportHtml = createReportHtml;
573
223
  exports.formatReport = formatReport;
574
- exports.normalizeTargets = normalizeTargets;
575
224
  exports.parseReport = parseReport;
576
225
  exports.readReport = readReport;
577
- exports.readSitemapUrls = readSitemapUrls;
578
226
  exports.saveReport = saveReport;
579
227
  exports.writeReportSite = writeReportSite;
580
228
  exports.writeReports = writeReports;
@@ -0,0 +1,41 @@
1
+ import { C as CheckReport } from './meodp.93e06e00.cjs';
2
+
3
+ interface ReportSiteOptions {
4
+ /** Automatically load this HTTP(S) or relative JSON URL when hosted. */
5
+ dataUrl?: string;
6
+ }
7
+
8
+ type ReporterName = 'json' | 'markdown' | 'html';
9
+ type HtmlReporterOptions = ReportSiteOptions & ({
10
+ outputFolder?: string;
11
+ outputFile?: never;
12
+ } | {
13
+ outputFile: string;
14
+ outputFolder?: never;
15
+ });
16
+ type ReporterDescription = ReporterName | readonly ['json' | 'markdown', {
17
+ outputFile?: string;
18
+ }?] | readonly ['html', HtmlReporterOptions?];
19
+ /** A name, a list of names, or a list of [name, options] tuples. */
20
+ type ReporterConfig = ReporterName | readonly ReporterDescription[];
21
+ interface ReporterOutput {
22
+ reporter: ReporterName;
23
+ files: string[];
24
+ }
25
+ interface ReporterOptions extends ReportSiteOptions {
26
+ /** Default directory for reporters without explicit output paths. */
27
+ outputDir?: string;
28
+ /** Resolve relative output paths from this directory (default: working directory). */
29
+ cwd?: string;
30
+ }
31
+ /** Run built-in reporters on saved data; no network requests or browser launch. */
32
+ declare function writeReporters(report: CheckReport | undefined, reporter: ReporterConfig, options?: ReporterOptions): Promise<ReporterOutput[]>;
33
+
34
+ interface ReportVerificationOptions {
35
+ url: string;
36
+ attempts?: number;
37
+ delayMs?: number;
38
+ }
39
+ declare function waitForReport(expected: CheckReport, { url, attempts, delayMs }: ReportVerificationOptions): Promise<void>;
40
+
41
+ export { type HtmlReporterOptions as H, type ReporterConfig as R, type ReportVerificationOptions as a, type ReportSiteOptions as b, type ReporterDescription as c, type ReporterName as d, type ReporterOptions as e, type ReporterOutput as f, waitForReport as g, writeReporters as w };
@@ -0,0 +1,30 @@
1
+ 'use strict';
2
+
3
+ const promises = require('node:fs/promises');
4
+ const path = require('node:path');
5
+ const process = require('node:process');
6
+ const c12 = require('c12');
7
+
8
+ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e.default : e; }
9
+
10
+ const process__default = /*#__PURE__*/_interopDefaultCompat(process);
11
+
12
+ async function loadProjectConfig(file) {
13
+ if (file)
14
+ await promises.access(path.resolve(file));
15
+ const { config, configFile } = await c12.loadConfig({
16
+ name: "meodp",
17
+ cwd: process__default.cwd(),
18
+ configFile: file ? path.resolve(file) : void 0,
19
+ rcFile: false,
20
+ globalRc: false,
21
+ dotenv: false,
22
+ packageJson: false,
23
+ extend: false,
24
+ giget: false
25
+ });
26
+ const root = configFile ? path.dirname(configFile) : process__default.cwd();
27
+ return { config, path: (value) => path.resolve(root, value) };
28
+ }
29
+
30
+ exports.loadProjectConfig = loadProjectConfig;