@cubing/dev-config 0.6.2 → 0.6.3
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/bin/package.json.ts +69 -16
- package/package.json +1 -1
package/bin/package.json.ts
CHANGED
|
@@ -155,7 +155,7 @@ try {
|
|
|
155
155
|
break;
|
|
156
156
|
}
|
|
157
157
|
default:
|
|
158
|
-
throw new Error("Invalid
|
|
158
|
+
throw new Error("Invalid subcommand.") as never;
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
|
|
@@ -485,7 +485,7 @@ function checkPath(
|
|
|
485
485
|
break;
|
|
486
486
|
}
|
|
487
487
|
default:
|
|
488
|
-
throw new Error("Invalid
|
|
488
|
+
throw new Error("Invalid subcommand.") as never;
|
|
489
489
|
}
|
|
490
490
|
}
|
|
491
491
|
}
|
|
@@ -520,14 +520,15 @@ checkPath(["types"], { expectPrefix: ResolutionPrefix.Relative });
|
|
|
520
520
|
checkPath(["module"], { expectPrefix: ResolutionPrefix.Relative });
|
|
521
521
|
checkPath(["browser"], { expectPrefix: ResolutionPrefix.Relative });
|
|
522
522
|
|
|
523
|
-
|
|
524
|
-
|
|
523
|
+
const { exports } = packageJSON;
|
|
524
|
+
if (exports) {
|
|
525
|
+
for (const [subpath, value] of Object.entries(exports)) {
|
|
525
526
|
if (!value) {
|
|
526
527
|
// biome-ignore lint/complexity/noUselessContinue: Explicit control flow.
|
|
527
528
|
continue;
|
|
528
529
|
} else if (typeof value === "string") {
|
|
529
530
|
// TODO: error?
|
|
530
|
-
checkPath(["exports", [
|
|
531
|
+
checkPath(["exports", [subpath]], {
|
|
531
532
|
expectPrefix: ResolutionPrefix.Relative,
|
|
532
533
|
});
|
|
533
534
|
} else if (value === null) {
|
|
@@ -542,25 +543,70 @@ if (packageJSON.exports) {
|
|
|
542
543
|
|
|
543
544
|
checks.push(
|
|
544
545
|
(async () => {
|
|
545
|
-
const { breadcrumbString } = traverse(["exports", [
|
|
546
|
+
const { breadcrumbString } = traverse(["exports", [subpath]]);
|
|
547
|
+
const fixingLines = [];
|
|
546
548
|
const orderingErrorLines = [];
|
|
547
549
|
/**
|
|
548
550
|
* https://nodejs.org/api/packages.html#conditional-exports
|
|
549
551
|
*/
|
|
552
|
+
let updateKeys = false;
|
|
550
553
|
if (keys.includes("types")) {
|
|
551
554
|
if (keys[0] !== "types") {
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
+
switch (subcommand) {
|
|
556
|
+
case "check": {
|
|
557
|
+
orderingErrorLines.push(
|
|
558
|
+
` ↪ "types" must be the first export if present — 📝 fixable!`,
|
|
559
|
+
);
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
case "format": {
|
|
563
|
+
fixingLines.push(
|
|
564
|
+
` ↪ "types" must be the first export if present — 📝 fixing!`,
|
|
565
|
+
);
|
|
566
|
+
keys.splice(keys.indexOf("types"), 1);
|
|
567
|
+
keys.splice(0, 0, "types");
|
|
568
|
+
updateKeys = true;
|
|
569
|
+
break;
|
|
570
|
+
}
|
|
571
|
+
default:
|
|
572
|
+
throw new Error("Invalid subcommand.") as never;
|
|
573
|
+
}
|
|
555
574
|
}
|
|
556
575
|
}
|
|
557
576
|
if (keys.includes("default")) {
|
|
558
577
|
if (keys.at(-1) !== "default") {
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
578
|
+
switch (subcommand) {
|
|
579
|
+
case "check": {
|
|
580
|
+
orderingErrorLines.push(
|
|
581
|
+
` ↪ "default" must be the last export if present — 📝 fixable!`,
|
|
582
|
+
);
|
|
583
|
+
break;
|
|
584
|
+
}
|
|
585
|
+
case "format": {
|
|
586
|
+
fixingLines.push(
|
|
587
|
+
` ↪ "default" must be the last export if present — 📝 fixing!`,
|
|
588
|
+
);
|
|
589
|
+
keys.splice(keys.indexOf("default"), 1);
|
|
590
|
+
keys.push("default");
|
|
591
|
+
updateKeys = true;
|
|
592
|
+
break;
|
|
593
|
+
}
|
|
594
|
+
default:
|
|
595
|
+
throw new Error("Invalid subcommand.") as never;
|
|
596
|
+
}
|
|
562
597
|
}
|
|
563
598
|
}
|
|
599
|
+
if (updateKeys) {
|
|
600
|
+
// TODO: avoid type wrangling.
|
|
601
|
+
const newConditionalExports: Record<string, string> = {};
|
|
602
|
+
for (const key of keys) {
|
|
603
|
+
newConditionalExports[key] = (value as Record<string, string>)[
|
|
604
|
+
key
|
|
605
|
+
];
|
|
606
|
+
}
|
|
607
|
+
(exports as Record<string, Record<string, string>>)[subpath] =
|
|
608
|
+
newConditionalExports;
|
|
609
|
+
}
|
|
564
610
|
for (const key of keys) {
|
|
565
611
|
// Note `"require"` is *emphatically not allowed*.
|
|
566
612
|
if (!["types", "import", "default"].includes(key)) {
|
|
@@ -569,19 +615,26 @@ if (packageJSON.exports) {
|
|
|
569
615
|
);
|
|
570
616
|
}
|
|
571
617
|
}
|
|
572
|
-
if (orderingErrorLines) {
|
|
573
|
-
exitCode =
|
|
618
|
+
if (orderingErrorLines.length > 0) {
|
|
619
|
+
exitCode = 1;
|
|
574
620
|
return [
|
|
575
621
|
`❌ ${breadcrumbString} — Invalid keys:`,
|
|
576
622
|
...orderingErrorLines,
|
|
577
623
|
].join("\n");
|
|
578
624
|
} else {
|
|
579
|
-
|
|
625
|
+
if (fixingLines.length > 0) {
|
|
626
|
+
return [
|
|
627
|
+
`✅ ${breadcrumbString} — Fixing key ordering:`,
|
|
628
|
+
...fixingLines,
|
|
629
|
+
].join("\n");
|
|
630
|
+
} else {
|
|
631
|
+
return `✅ ${breadcrumbString} — Key set and ordering is okay.`;
|
|
632
|
+
}
|
|
580
633
|
}
|
|
581
634
|
})(),
|
|
582
635
|
);
|
|
583
636
|
for (const secondaryKey of keys) {
|
|
584
|
-
checkPath(["exports", [
|
|
637
|
+
checkPath(["exports", [subpath], secondaryKey], {
|
|
585
638
|
expectPrefix: ResolutionPrefix.Relative,
|
|
586
639
|
});
|
|
587
640
|
}
|