@kubb/ast 5.18.1 → 5.18.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/dist/index.cjs CHANGED
@@ -720,6 +720,12 @@ function extractStringsFromNodes(nodes) {
720
720
  return collected.join("\n");
721
721
  }
722
722
  // src/utils/combineFileMembers.ts
723
+ /**
724
+ * File-member merging. `combineImports` and `combineExports` deduplicate and sort the import and
725
+ * export entries of one file, while `combineSources` deduplicates source entries in original order.
726
+ * `combineImports` also drops imports nothing references. This works on a file's members, not on
727
+ * schema content.
728
+ */
723
729
  const IDENTIFIER_RUN = /[\w$]+/g;
724
730
  /**
725
731
  * How many imports a file needs before indexing the source beats scanning it once per name.
@@ -733,15 +739,24 @@ function importLocalName(item) {
733
739
  return typeof item === "string" ? item : item.name ?? item.propertyName;
734
740
  }
735
741
  /**
742
+ * Returns the specifier a member is written with: POSIX and relative to the importing file when it
743
+ * has a `root`, like `getRelativePath` in parser-ts. Sorting on it keeps the order the same on every OS.
744
+ */
745
+ function specifier(node) {
746
+ if (!node.root) return node.path;
747
+ const relative = node_path.default.relative(node_path.default.dirname(node.root), node.path).replaceAll("\\", "/");
748
+ return relative.startsWith("../") ? relative : `./${relative}`;
749
+ }
750
+ /**
736
751
  * Computes a multi-level sort key for exports and imports:
737
- * non-array names first (wildcards/namespace aliases). Type-only before value. Alphabetical path. Unnamed before named.
752
+ * non-array names first (wildcards/namespace aliases). Type-only before value. Alphabetical specifier. Unnamed before named.
738
753
  */
739
754
  function sortKey(node) {
740
755
  const isArray = Array.isArray(node.name) ? "1" : "0";
741
756
  const typeOnly = node.isTypeOnly ? "0" : "1";
742
757
  const hasName = node.name != null ? "1" : "0";
743
758
  const name = Array.isArray(node.name) ? node.name.toSorted().join("\0") : node.name ?? "";
744
- return `${isArray}:${typeOnly}:${node.path}:${hasName}:${name}`;
759
+ return `${isArray}:${typeOnly}:${specifier(node)}:${hasName}:${name}`;
745
760
  }
746
761
  /**
747
762
  * Sorts members by {@link sortKey}. Keys are computed once per node, not per comparison.