@patchstack/connect 0.2.4 → 0.2.5
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.
- package/README.md +6 -3
- package/dist/cli.js +486 -23
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +482 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -3
- package/dist/index.d.ts +11 -3
- package/dist/index.js +478 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -32,6 +32,7 @@ var src_exports = {};
|
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
DEFAULT_ENDPOINT: () => DEFAULT_ENDPOINT,
|
|
34
34
|
PatchstackError: () => PatchstackError,
|
|
35
|
+
buildClaimUrl: () => buildClaimUrl,
|
|
35
36
|
buildEndpointUrl: () => buildEndpointUrl,
|
|
36
37
|
buildWirePayload: () => buildWirePayload,
|
|
37
38
|
compareVersions: () => compareVersions,
|
|
@@ -46,8 +47,8 @@ __export(src_exports, {
|
|
|
46
47
|
module.exports = __toCommonJS(src_exports);
|
|
47
48
|
|
|
48
49
|
// src/parsers/index.ts
|
|
49
|
-
var
|
|
50
|
-
var
|
|
50
|
+
var import_promises5 = require("fs/promises");
|
|
51
|
+
var import_node_path4 = __toESM(require("path"), 1);
|
|
51
52
|
|
|
52
53
|
// src/types.ts
|
|
53
54
|
var PatchstackError = class extends Error {
|
|
@@ -254,9 +255,452 @@ async function isPlainDirectory(dir) {
|
|
|
254
255
|
}
|
|
255
256
|
}
|
|
256
257
|
|
|
258
|
+
// src/parsers/pnpm.ts
|
|
259
|
+
var import_promises3 = require("fs/promises");
|
|
260
|
+
async function parsePnpmLockfile(lockfilePath) {
|
|
261
|
+
let raw;
|
|
262
|
+
try {
|
|
263
|
+
raw = await (0, import_promises3.readFile)(lockfilePath, "utf8");
|
|
264
|
+
} catch (cause) {
|
|
265
|
+
throw new PatchstackError(
|
|
266
|
+
`Could not read lockfile at ${lockfilePath}`,
|
|
267
|
+
"LOCKFILE_NOT_FOUND",
|
|
268
|
+
cause
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
const lines = raw.split(/\r?\n/);
|
|
272
|
+
const directNames = collectDirectDepNames(lines);
|
|
273
|
+
const packageKeys = collectPackagesBlockKeys(lines);
|
|
274
|
+
if (packageKeys.length === 0) {
|
|
275
|
+
throw new PatchstackError(
|
|
276
|
+
`Lockfile at ${lockfilePath} has no "packages" entries`,
|
|
277
|
+
"LOCKFILE_PARSE_ERROR"
|
|
278
|
+
);
|
|
279
|
+
}
|
|
280
|
+
const entries = [];
|
|
281
|
+
for (const key of packageKeys) {
|
|
282
|
+
const parsed = parsePackageKey(key);
|
|
283
|
+
if (parsed === null) {
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
entries.push({
|
|
287
|
+
name: parsed.name,
|
|
288
|
+
version: parsed.version,
|
|
289
|
+
direct: directNames.has(parsed.name)
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
return entries;
|
|
293
|
+
}
|
|
294
|
+
function parsePackageKey(rawKey) {
|
|
295
|
+
let k = rawKey.trim();
|
|
296
|
+
if (k.length === 0) {
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
if (k.startsWith("'") && k.endsWith("'") || k.startsWith('"') && k.endsWith('"')) {
|
|
300
|
+
k = k.slice(1, -1);
|
|
301
|
+
}
|
|
302
|
+
if (k.startsWith("/")) {
|
|
303
|
+
k = k.slice(1);
|
|
304
|
+
}
|
|
305
|
+
const parenIdx = k.indexOf("(");
|
|
306
|
+
if (parenIdx >= 0) {
|
|
307
|
+
k = k.slice(0, parenIdx);
|
|
308
|
+
}
|
|
309
|
+
let scopePrefix = "";
|
|
310
|
+
let body = k;
|
|
311
|
+
if (k.startsWith("@")) {
|
|
312
|
+
const firstSlash = k.indexOf("/");
|
|
313
|
+
if (firstSlash <= 0) {
|
|
314
|
+
return null;
|
|
315
|
+
}
|
|
316
|
+
scopePrefix = k.slice(0, firstSlash + 1);
|
|
317
|
+
body = k.slice(firstSlash + 1);
|
|
318
|
+
}
|
|
319
|
+
const slashIdx = body.indexOf("/");
|
|
320
|
+
const atIdx = body.indexOf("@");
|
|
321
|
+
let sepIdx;
|
|
322
|
+
if (slashIdx < 0 && atIdx < 0) {
|
|
323
|
+
return null;
|
|
324
|
+
} else if (slashIdx < 0) {
|
|
325
|
+
sepIdx = atIdx;
|
|
326
|
+
} else if (atIdx < 0) {
|
|
327
|
+
sepIdx = slashIdx;
|
|
328
|
+
} else {
|
|
329
|
+
sepIdx = Math.min(slashIdx, atIdx);
|
|
330
|
+
}
|
|
331
|
+
const name = scopePrefix + body.slice(0, sepIdx);
|
|
332
|
+
let version = body.slice(sepIdx + 1);
|
|
333
|
+
const underscoreIdx = version.indexOf("_");
|
|
334
|
+
if (underscoreIdx >= 0) {
|
|
335
|
+
version = version.slice(0, underscoreIdx);
|
|
336
|
+
}
|
|
337
|
+
if (name.length === 0 || version.length === 0) {
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
return { name, version };
|
|
341
|
+
}
|
|
342
|
+
function indentOf(line) {
|
|
343
|
+
let i = 0;
|
|
344
|
+
while (i < line.length && line[i] === " ") {
|
|
345
|
+
i++;
|
|
346
|
+
}
|
|
347
|
+
return i;
|
|
348
|
+
}
|
|
349
|
+
function isBlankOrComment(line) {
|
|
350
|
+
const trimmed = line.trim();
|
|
351
|
+
return trimmed.length === 0 || trimmed.startsWith("#");
|
|
352
|
+
}
|
|
353
|
+
function collectPackagesBlockKeys(lines) {
|
|
354
|
+
const keys = [];
|
|
355
|
+
let inBlock = false;
|
|
356
|
+
let childIndent = null;
|
|
357
|
+
for (const line of lines) {
|
|
358
|
+
if (isBlankOrComment(line)) {
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
const indent = indentOf(line);
|
|
362
|
+
if (!inBlock) {
|
|
363
|
+
if (indent === 0 && line.trim() === "packages:") {
|
|
364
|
+
inBlock = true;
|
|
365
|
+
}
|
|
366
|
+
continue;
|
|
367
|
+
}
|
|
368
|
+
if (indent === 0) {
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
if (childIndent === null) {
|
|
372
|
+
childIndent = indent;
|
|
373
|
+
}
|
|
374
|
+
if (indent !== childIndent) {
|
|
375
|
+
continue;
|
|
376
|
+
}
|
|
377
|
+
const content = line.slice(indent);
|
|
378
|
+
if (!content.endsWith(":")) {
|
|
379
|
+
continue;
|
|
380
|
+
}
|
|
381
|
+
keys.push(content.slice(0, -1));
|
|
382
|
+
}
|
|
383
|
+
return keys;
|
|
384
|
+
}
|
|
385
|
+
function collectDirectDepNames(lines) {
|
|
386
|
+
const names = /* @__PURE__ */ new Set();
|
|
387
|
+
collectFromImporters(lines, names);
|
|
388
|
+
for (const section of ["dependencies", "devDependencies", "optionalDependencies"]) {
|
|
389
|
+
collectFromTopLevelSection(lines, section, names);
|
|
390
|
+
}
|
|
391
|
+
return names;
|
|
392
|
+
}
|
|
393
|
+
var DEP_SECTIONS = /* @__PURE__ */ new Set([
|
|
394
|
+
"dependencies",
|
|
395
|
+
"devDependencies",
|
|
396
|
+
"optionalDependencies"
|
|
397
|
+
]);
|
|
398
|
+
function collectFromImporters(lines, out) {
|
|
399
|
+
let inImporters = false;
|
|
400
|
+
let importerIndent = null;
|
|
401
|
+
let inDepSection = false;
|
|
402
|
+
let depSectionIndent = null;
|
|
403
|
+
let leafIndent = null;
|
|
404
|
+
for (const line of lines) {
|
|
405
|
+
if (isBlankOrComment(line)) {
|
|
406
|
+
continue;
|
|
407
|
+
}
|
|
408
|
+
const indent = indentOf(line);
|
|
409
|
+
const trimmed = line.trim();
|
|
410
|
+
if (!inImporters) {
|
|
411
|
+
if (indent === 0 && trimmed === "importers:") {
|
|
412
|
+
inImporters = true;
|
|
413
|
+
}
|
|
414
|
+
continue;
|
|
415
|
+
}
|
|
416
|
+
if (indent === 0) {
|
|
417
|
+
break;
|
|
418
|
+
}
|
|
419
|
+
if (importerIndent === null) {
|
|
420
|
+
importerIndent = indent;
|
|
421
|
+
}
|
|
422
|
+
if (indent === importerIndent) {
|
|
423
|
+
inDepSection = false;
|
|
424
|
+
depSectionIndent = null;
|
|
425
|
+
leafIndent = null;
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
if (!inDepSection) {
|
|
429
|
+
const key = stripTrailingColon(trimmed);
|
|
430
|
+
if (key !== null && DEP_SECTIONS.has(key)) {
|
|
431
|
+
inDepSection = true;
|
|
432
|
+
depSectionIndent = indent;
|
|
433
|
+
}
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
if (depSectionIndent !== null && indent <= depSectionIndent) {
|
|
437
|
+
inDepSection = false;
|
|
438
|
+
depSectionIndent = null;
|
|
439
|
+
leafIndent = null;
|
|
440
|
+
const key = stripTrailingColon(trimmed);
|
|
441
|
+
if (key !== null && DEP_SECTIONS.has(key)) {
|
|
442
|
+
inDepSection = true;
|
|
443
|
+
depSectionIndent = indent;
|
|
444
|
+
}
|
|
445
|
+
continue;
|
|
446
|
+
}
|
|
447
|
+
if (leafIndent === null) {
|
|
448
|
+
leafIndent = indent;
|
|
449
|
+
}
|
|
450
|
+
if (indent !== leafIndent) {
|
|
451
|
+
continue;
|
|
452
|
+
}
|
|
453
|
+
const name = extractLeafName(trimmed);
|
|
454
|
+
if (name !== null) {
|
|
455
|
+
out.add(name);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
function collectFromTopLevelSection(lines, section, out) {
|
|
460
|
+
let inSection = false;
|
|
461
|
+
let leafIndent = null;
|
|
462
|
+
for (const line of lines) {
|
|
463
|
+
if (isBlankOrComment(line)) {
|
|
464
|
+
continue;
|
|
465
|
+
}
|
|
466
|
+
const indent = indentOf(line);
|
|
467
|
+
const trimmed = line.trim();
|
|
468
|
+
if (!inSection) {
|
|
469
|
+
if (indent === 0 && trimmed === `${section}:`) {
|
|
470
|
+
inSection = true;
|
|
471
|
+
}
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
if (indent === 0) {
|
|
475
|
+
break;
|
|
476
|
+
}
|
|
477
|
+
if (leafIndent === null) {
|
|
478
|
+
leafIndent = indent;
|
|
479
|
+
}
|
|
480
|
+
if (indent !== leafIndent) {
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
483
|
+
const name = extractLeafName(trimmed);
|
|
484
|
+
if (name !== null) {
|
|
485
|
+
out.add(name);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
function stripTrailingColon(s) {
|
|
490
|
+
if (!s.endsWith(":")) {
|
|
491
|
+
return null;
|
|
492
|
+
}
|
|
493
|
+
return s.slice(0, -1).trim();
|
|
494
|
+
}
|
|
495
|
+
function extractLeafName(trimmed) {
|
|
496
|
+
const colonIdx = trimmed.indexOf(":");
|
|
497
|
+
if (colonIdx < 0) {
|
|
498
|
+
return null;
|
|
499
|
+
}
|
|
500
|
+
let name = trimmed.slice(0, colonIdx).trim();
|
|
501
|
+
if (name.length === 0) {
|
|
502
|
+
return null;
|
|
503
|
+
}
|
|
504
|
+
if (name.startsWith("'") && name.endsWith("'") || name.startsWith('"') && name.endsWith('"')) {
|
|
505
|
+
name = name.slice(1, -1);
|
|
506
|
+
}
|
|
507
|
+
return name.length > 0 ? name : null;
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
// src/parsers/yarn.ts
|
|
511
|
+
var import_promises4 = require("fs/promises");
|
|
512
|
+
var import_node_path3 = __toESM(require("path"), 1);
|
|
513
|
+
async function parseYarnLockfile(lockfilePath) {
|
|
514
|
+
let raw;
|
|
515
|
+
try {
|
|
516
|
+
raw = await (0, import_promises4.readFile)(lockfilePath, "utf8");
|
|
517
|
+
} catch (cause) {
|
|
518
|
+
throw new PatchstackError(
|
|
519
|
+
`Could not read lockfile at ${lockfilePath}`,
|
|
520
|
+
"LOCKFILE_NOT_FOUND",
|
|
521
|
+
cause
|
|
522
|
+
);
|
|
523
|
+
}
|
|
524
|
+
const blocks = parseBlocks(raw);
|
|
525
|
+
if (blocks.length === 0) {
|
|
526
|
+
throw new PatchstackError(
|
|
527
|
+
`Lockfile at ${lockfilePath} contains no package entries`,
|
|
528
|
+
"LOCKFILE_PARSE_ERROR"
|
|
529
|
+
);
|
|
530
|
+
}
|
|
531
|
+
const directNames = await readDirectDepNames(import_node_path3.default.dirname(lockfilePath));
|
|
532
|
+
const entries = [];
|
|
533
|
+
const seen = /* @__PURE__ */ new Set();
|
|
534
|
+
for (const block of blocks) {
|
|
535
|
+
if (block.version.length === 0 || block.names.size === 0) {
|
|
536
|
+
continue;
|
|
537
|
+
}
|
|
538
|
+
for (const name of block.names) {
|
|
539
|
+
const dedupKey = `${name}@${block.version}`;
|
|
540
|
+
if (seen.has(dedupKey)) {
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
|
+
seen.add(dedupKey);
|
|
544
|
+
entries.push({
|
|
545
|
+
name,
|
|
546
|
+
version: block.version,
|
|
547
|
+
direct: directNames.has(name)
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
return entries;
|
|
552
|
+
}
|
|
553
|
+
function parseBlocks(raw) {
|
|
554
|
+
const lines = raw.split(/\r?\n/);
|
|
555
|
+
const blocks = [];
|
|
556
|
+
let current = null;
|
|
557
|
+
const finalize = () => {
|
|
558
|
+
if (current !== null && current.version.length > 0 && current.names.size > 0) {
|
|
559
|
+
blocks.push(current);
|
|
560
|
+
}
|
|
561
|
+
current = null;
|
|
562
|
+
};
|
|
563
|
+
for (const line of lines) {
|
|
564
|
+
const trimmed = line.trim();
|
|
565
|
+
if (trimmed.length === 0 || trimmed.startsWith("#")) {
|
|
566
|
+
continue;
|
|
567
|
+
}
|
|
568
|
+
const indent = countLeadingSpaces(line);
|
|
569
|
+
if (indent === 0) {
|
|
570
|
+
finalize();
|
|
571
|
+
if (!trimmed.endsWith(":")) {
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
const keyLine = trimmed.slice(0, -1);
|
|
575
|
+
const names = /* @__PURE__ */ new Set();
|
|
576
|
+
for (const spec of splitDescriptors(keyLine)) {
|
|
577
|
+
const name = extractName(spec);
|
|
578
|
+
if (name !== null) {
|
|
579
|
+
names.add(name);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
current = { names, version: "" };
|
|
583
|
+
continue;
|
|
584
|
+
}
|
|
585
|
+
if (current === null) {
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
588
|
+
const version = parseVersionField(trimmed);
|
|
589
|
+
if (version !== null) {
|
|
590
|
+
current.version = version;
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
finalize();
|
|
594
|
+
return blocks;
|
|
595
|
+
}
|
|
596
|
+
function countLeadingSpaces(line) {
|
|
597
|
+
let i = 0;
|
|
598
|
+
while (i < line.length && line[i] === " ") {
|
|
599
|
+
i++;
|
|
600
|
+
}
|
|
601
|
+
return i;
|
|
602
|
+
}
|
|
603
|
+
function splitDescriptors(keyLine) {
|
|
604
|
+
const parts = [];
|
|
605
|
+
let current = "";
|
|
606
|
+
let quote = null;
|
|
607
|
+
for (let i = 0; i < keyLine.length; i++) {
|
|
608
|
+
const c = keyLine[i];
|
|
609
|
+
if (quote !== null) {
|
|
610
|
+
current += c;
|
|
611
|
+
if (c === quote) {
|
|
612
|
+
quote = null;
|
|
613
|
+
}
|
|
614
|
+
continue;
|
|
615
|
+
}
|
|
616
|
+
if (c === '"' || c === "'") {
|
|
617
|
+
quote = c;
|
|
618
|
+
current += c;
|
|
619
|
+
continue;
|
|
620
|
+
}
|
|
621
|
+
if (c === ",") {
|
|
622
|
+
const piece = current.trim();
|
|
623
|
+
if (piece.length > 0) {
|
|
624
|
+
parts.push(piece);
|
|
625
|
+
}
|
|
626
|
+
current = "";
|
|
627
|
+
continue;
|
|
628
|
+
}
|
|
629
|
+
current += c;
|
|
630
|
+
}
|
|
631
|
+
const tail = current.trim();
|
|
632
|
+
if (tail.length > 0) {
|
|
633
|
+
parts.push(tail);
|
|
634
|
+
}
|
|
635
|
+
return parts;
|
|
636
|
+
}
|
|
637
|
+
function extractName(rawSpec) {
|
|
638
|
+
let s = rawSpec.trim();
|
|
639
|
+
if (s.length === 0) {
|
|
640
|
+
return null;
|
|
641
|
+
}
|
|
642
|
+
if (s.startsWith('"') && s.endsWith('"') || s.startsWith("'") && s.endsWith("'")) {
|
|
643
|
+
s = s.slice(1, -1);
|
|
644
|
+
}
|
|
645
|
+
const atIdx = s.lastIndexOf("@");
|
|
646
|
+
if (atIdx <= 0) {
|
|
647
|
+
return null;
|
|
648
|
+
}
|
|
649
|
+
const name = s.slice(0, atIdx);
|
|
650
|
+
return name.length > 0 ? name : null;
|
|
651
|
+
}
|
|
652
|
+
function parseVersionField(content) {
|
|
653
|
+
if (!content.startsWith("version")) {
|
|
654
|
+
return null;
|
|
655
|
+
}
|
|
656
|
+
const after = content.slice("version".length);
|
|
657
|
+
const firstChar = after.charAt(0);
|
|
658
|
+
if (firstChar !== " " && firstChar !== " " && firstChar !== ":") {
|
|
659
|
+
return null;
|
|
660
|
+
}
|
|
661
|
+
let rest = firstChar === ":" ? after.slice(1) : after;
|
|
662
|
+
rest = rest.trim();
|
|
663
|
+
if (rest.length === 0) {
|
|
664
|
+
return null;
|
|
665
|
+
}
|
|
666
|
+
if (rest.startsWith('"') && rest.endsWith('"') || rest.startsWith("'") && rest.endsWith("'")) {
|
|
667
|
+
rest = rest.slice(1, -1);
|
|
668
|
+
}
|
|
669
|
+
return rest.length > 0 ? rest : null;
|
|
670
|
+
}
|
|
671
|
+
async function readDirectDepNames(cwd) {
|
|
672
|
+
const names = /* @__PURE__ */ new Set();
|
|
673
|
+
let raw;
|
|
674
|
+
try {
|
|
675
|
+
raw = await (0, import_promises4.readFile)(import_node_path3.default.join(cwd, "package.json"), "utf8");
|
|
676
|
+
} catch {
|
|
677
|
+
return names;
|
|
678
|
+
}
|
|
679
|
+
let parsed;
|
|
680
|
+
try {
|
|
681
|
+
parsed = JSON.parse(raw);
|
|
682
|
+
} catch {
|
|
683
|
+
return names;
|
|
684
|
+
}
|
|
685
|
+
if (typeof parsed !== "object" || parsed === null) {
|
|
686
|
+
return names;
|
|
687
|
+
}
|
|
688
|
+
const obj = parsed;
|
|
689
|
+
for (const field of ["dependencies", "devDependencies", "optionalDependencies", "peerDependencies"]) {
|
|
690
|
+
const section = obj[field];
|
|
691
|
+
if (typeof section !== "object" || section === null) {
|
|
692
|
+
continue;
|
|
693
|
+
}
|
|
694
|
+
for (const name of Object.keys(section)) {
|
|
695
|
+
names.add(name);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
return names;
|
|
699
|
+
}
|
|
700
|
+
|
|
257
701
|
// src/parsers/index.ts
|
|
258
702
|
async function detectLockfile(cwd) {
|
|
259
|
-
const npmLock =
|
|
703
|
+
const npmLock = import_node_path4.default.join(cwd, "package-lock.json");
|
|
260
704
|
if (await exists(npmLock)) {
|
|
261
705
|
return {
|
|
262
706
|
ecosystem: "npm",
|
|
@@ -265,7 +709,7 @@ async function detectLockfile(cwd) {
|
|
|
265
709
|
strategy: "npm-lockfile"
|
|
266
710
|
};
|
|
267
711
|
}
|
|
268
|
-
const bunLock =
|
|
712
|
+
const bunLock = import_node_path4.default.join(cwd, "bun.lock");
|
|
269
713
|
if (await exists(bunLock)) {
|
|
270
714
|
return {
|
|
271
715
|
ecosystem: "npm",
|
|
@@ -274,7 +718,7 @@ async function detectLockfile(cwd) {
|
|
|
274
718
|
strategy: "node-modules-walk"
|
|
275
719
|
};
|
|
276
720
|
}
|
|
277
|
-
const bunLockB =
|
|
721
|
+
const bunLockB = import_node_path4.default.join(cwd, "bun.lockb");
|
|
278
722
|
if (await exists(bunLockB)) {
|
|
279
723
|
return {
|
|
280
724
|
ecosystem: "npm",
|
|
@@ -283,19 +727,23 @@ async function detectLockfile(cwd) {
|
|
|
283
727
|
strategy: "node-modules-walk"
|
|
284
728
|
};
|
|
285
729
|
}
|
|
286
|
-
const
|
|
287
|
-
if (await exists(yarnLock)) {
|
|
288
|
-
throw new PatchstackError(
|
|
289
|
-
"yarn.lock detected but not yet supported. Run `npm install` to generate a package-lock.json, or open an issue at github.com/patchstack/connect.",
|
|
290
|
-
"LOCKFILE_UNSUPPORTED"
|
|
291
|
-
);
|
|
292
|
-
}
|
|
293
|
-
const pnpmLock = import_node_path3.default.join(cwd, "pnpm-lock.yaml");
|
|
730
|
+
const pnpmLock = import_node_path4.default.join(cwd, "pnpm-lock.yaml");
|
|
294
731
|
if (await exists(pnpmLock)) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
732
|
+
return {
|
|
733
|
+
ecosystem: "npm",
|
|
734
|
+
filePath: pnpmLock,
|
|
735
|
+
filename: "pnpm-lock.yaml",
|
|
736
|
+
strategy: "pnpm-lockfile"
|
|
737
|
+
};
|
|
738
|
+
}
|
|
739
|
+
const yarnLock = import_node_path4.default.join(cwd, "yarn.lock");
|
|
740
|
+
if (await exists(yarnLock)) {
|
|
741
|
+
return {
|
|
742
|
+
ecosystem: "npm",
|
|
743
|
+
filePath: yarnLock,
|
|
744
|
+
filename: "yarn.lock",
|
|
745
|
+
strategy: "yarn-lockfile"
|
|
746
|
+
};
|
|
299
747
|
}
|
|
300
748
|
throw new PatchstackError(
|
|
301
749
|
`No lockfile found in ${cwd}. Expected one of: package-lock.json, bun.lock, bun.lockb, yarn.lock, pnpm-lock.yaml.`,
|
|
@@ -311,13 +759,17 @@ async function runStrategy(detected, cwd) {
|
|
|
311
759
|
switch (detected.strategy) {
|
|
312
760
|
case "npm-lockfile":
|
|
313
761
|
return parseNpmLockfile(detected.filePath);
|
|
762
|
+
case "pnpm-lockfile":
|
|
763
|
+
return parsePnpmLockfile(detected.filePath);
|
|
764
|
+
case "yarn-lockfile":
|
|
765
|
+
return parseYarnLockfile(detected.filePath);
|
|
314
766
|
case "node-modules-walk":
|
|
315
767
|
return walkNodeModules(cwd);
|
|
316
768
|
}
|
|
317
769
|
}
|
|
318
770
|
async function exists(filePath) {
|
|
319
771
|
try {
|
|
320
|
-
await (0,
|
|
772
|
+
await (0, import_promises5.access)(filePath);
|
|
321
773
|
return true;
|
|
322
774
|
} catch {
|
|
323
775
|
return false;
|
|
@@ -427,12 +879,16 @@ function compareSegments(a, b) {
|
|
|
427
879
|
}
|
|
428
880
|
|
|
429
881
|
// src/client.ts
|
|
430
|
-
var DEFAULT_ENDPOINT = "
|
|
882
|
+
var DEFAULT_ENDPOINT = "https://api.patchstack.com/monitor/pulse/manifest";
|
|
431
883
|
var DEFAULT_TIMEOUT_MS = 3e4;
|
|
432
884
|
function buildEndpointUrl(base, siteUuid) {
|
|
433
885
|
const trimmed = base.replace(/\/$/, "");
|
|
434
886
|
return siteUuid !== void 0 && siteUuid !== null && siteUuid.length > 0 ? `${trimmed}/${encodeURIComponent(siteUuid)}` : trimmed;
|
|
435
887
|
}
|
|
888
|
+
function buildClaimUrl(endpoint, siteUuid) {
|
|
889
|
+
const origin = new URL(endpoint).origin;
|
|
890
|
+
return `${origin}/monitor/claim?site=${encodeURIComponent(siteUuid)}`;
|
|
891
|
+
}
|
|
436
892
|
async function postManifest(config, payload) {
|
|
437
893
|
const url = buildEndpointUrl(config.endpoint, config.siteUuid);
|
|
438
894
|
const timeoutMs = config.timeoutMs;
|
|
@@ -500,8 +956,8 @@ function isTimeoutError(cause) {
|
|
|
500
956
|
}
|
|
501
957
|
|
|
502
958
|
// src/config.ts
|
|
503
|
-
var
|
|
504
|
-
var
|
|
959
|
+
var import_promises6 = require("fs/promises");
|
|
960
|
+
var import_node_path5 = __toESM(require("path"), 1);
|
|
505
961
|
var CONFIG_FILENAME = ".patchstackrc.json";
|
|
506
962
|
async function resolveConfig(options) {
|
|
507
963
|
const fromFile = await readConfigFile(options.cwd);
|
|
@@ -528,9 +984,9 @@ async function resolveConfig(options) {
|
|
|
528
984
|
};
|
|
529
985
|
}
|
|
530
986
|
async function writeConfigFile(cwd, config) {
|
|
531
|
-
const target =
|
|
987
|
+
const target = import_node_path5.default.join(cwd, CONFIG_FILENAME);
|
|
532
988
|
const content = JSON.stringify(config, null, 2) + "\n";
|
|
533
|
-
await (0,
|
|
989
|
+
await (0, import_promises6.writeFile)(target, content, "utf8");
|
|
534
990
|
return target;
|
|
535
991
|
}
|
|
536
992
|
async function persistSiteUuid(cwd, siteUuid) {
|
|
@@ -538,10 +994,10 @@ async function persistSiteUuid(cwd, siteUuid) {
|
|
|
538
994
|
return writeConfigFile(cwd, { ...existing, siteUuid });
|
|
539
995
|
}
|
|
540
996
|
async function readConfigFile(cwd) {
|
|
541
|
-
const target =
|
|
997
|
+
const target = import_node_path5.default.join(cwd, CONFIG_FILENAME);
|
|
542
998
|
let raw;
|
|
543
999
|
try {
|
|
544
|
-
raw = await (0,
|
|
1000
|
+
raw = await (0, import_promises6.readFile)(target, "utf8");
|
|
545
1001
|
} catch (err) {
|
|
546
1002
|
if (err.code === "ENOENT") {
|
|
547
1003
|
return {};
|
|
@@ -607,6 +1063,7 @@ async function scanAndReport(options = {}) {
|
|
|
607
1063
|
0 && (module.exports = {
|
|
608
1064
|
DEFAULT_ENDPOINT,
|
|
609
1065
|
PatchstackError,
|
|
1066
|
+
buildClaimUrl,
|
|
610
1067
|
buildEndpointUrl,
|
|
611
1068
|
buildWirePayload,
|
|
612
1069
|
compareVersions,
|