@ariestools/toolchain 8.7.6 → 8.7.8

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 (27) hide show
  1. package/dist/actions/api-exposure/analyzer/analyzePackage.d.ts.map +1 -1
  2. package/dist/actions/api-exposure/analyzer/importedPackages.d.ts +19 -5
  3. package/dist/actions/api-exposure/analyzer/importedPackages.d.ts.map +1 -1
  4. package/dist/actions/api-exposure/rules.d.ts.map +1 -1
  5. package/dist/actions/deplint/checkPackage/getUnsatisfiedPeerDependencies.d.ts +16 -6
  6. package/dist/actions/deplint/checkPackage/getUnsatisfiedPeerDependencies.d.ts.map +1 -1
  7. package/dist/actions/deplint/getInternalSurfaceVouchedPeers.d.ts +13 -0
  8. package/dist/actions/deplint/getInternalSurfaceVouchedPeers.d.ts.map +1 -0
  9. package/dist/actions/deplint/packageJsonEditor.d.ts +3 -2
  10. package/dist/actions/deplint/packageJsonEditor.d.ts.map +1 -1
  11. package/dist/actions/deplint/resolvePeerBumpFixes.d.ts.map +1 -1
  12. package/dist/actions/deplint/snapshot.d.ts.map +1 -1
  13. package/dist/actions/package/compile/ApiExposureConfig.d.ts +16 -4
  14. package/dist/actions/package/compile/ApiExposureConfig.d.ts.map +1 -1
  15. package/dist/actions/package/compile/XyConfig.d.ts +2 -2
  16. package/dist/bin/package/build.mjs +4 -2
  17. package/dist/bin/package/build.mjs.map +1 -1
  18. package/dist/bin/package/compile.mjs +4 -2
  19. package/dist/bin/package/compile.mjs.map +1 -1
  20. package/dist/bin/package/recompile.mjs +4 -2
  21. package/dist/bin/package/recompile.mjs.map +1 -1
  22. package/dist/bin/package/sync-layout.mjs +4 -2
  23. package/dist/bin/package/sync-layout.mjs.map +1 -1
  24. package/dist/bin/xy.mjs +293 -120
  25. package/dist/bin/xy.mjs.map +1 -1
  26. package/dist/pm/pnpmPackageManager.d.ts.map +1 -1
  27. package/package.json +4 -4
package/dist/bin/xy.mjs CHANGED
@@ -4976,7 +4976,7 @@ var PnpmPackageManager = class {
4976
4976
  return ["pnpm", ["xy", ...args]];
4977
4977
  }
4978
4978
  versionApply() {
4979
- return ["pnpm", ["install", "--lockfile-only"]];
4979
+ return this.install();
4980
4980
  }
4981
4981
  versionBump(type) {
4982
4982
  return [["pnpm", [
@@ -23099,7 +23099,7 @@ function isTerminalPackage$1(location) {
23099
23099
  //#region src/actions/deplint/checkPackage/getUnsatisfiedPeerDependencies.ts
23100
23100
  /** True when the policy (if any) obliges this package to forward `peer`. */
23101
23101
  function isPeerForwarded(policy, peer) {
23102
- return policy === void 0 || policy.mode === "always" || policy.importedModules.has(peer);
23102
+ return policy === void 0 || policy.mode === "always" || policy.importedModules.has(peer) || (policy.vouchedPeers?.has(peer) ?? false);
23103
23103
  }
23104
23104
  function readDepPackageJson(location, dep) {
23105
23105
  const depPkgPath = findDepPackageJson(location, dep);
@@ -23546,10 +23546,22 @@ const AEI_RULES = [
23546
23546
  },
23547
23547
  {
23548
23548
  defaultWeight: 0,
23549
- description: "Peer contract inherited from a runtime dependency chain for a package never imported here (peerForwarding: when-used) — installers resolve it; no forwarding required",
23549
+ description: "Peer contract inherited from a runtime dependency chain for a package neither imported nor exposed here (peerForwarding: when-used) — installers resolve it; no forwarding required",
23550
23550
  id: "aei.signal.inherited-peer",
23551
23551
  kind: "dep-signal"
23552
23552
  },
23553
+ {
23554
+ defaultWeight: 0,
23555
+ description: "Chain peer neither exposed through the package API nor value-imported (peerForwarding: when-exposed) — declaring it in own dependencies (provider pattern) discharges the contract",
23556
+ id: "aei.signal.absorbable-peer",
23557
+ kind: "dep-signal"
23558
+ },
23559
+ {
23560
+ defaultWeight: 0,
23561
+ description: "Peer contract imposed only by dependency chains whose roots this package imports exclusively as types — the chains never execute here, so no runtime contract exists to forward",
23562
+ id: "aei.signal.type-only-chain-peer",
23563
+ kind: "dep-signal"
23564
+ },
23553
23565
  {
23554
23566
  defaultWeight: 40,
23555
23567
  description: "Dependency uses a global registry",
@@ -23711,7 +23723,7 @@ function matchingOverrides(packages, dependency) {
23711
23723
  return exact === void 0 ? globs : [...globs, exact];
23712
23724
  }
23713
23725
  function resolvePeerForwarding(peerForwarding = "always") {
23714
- if (peerForwarding !== "always" && peerForwarding !== "when-used") throw new TypeError("commands.apiExposure.peerForwarding must be \"always\" or \"when-used\"");
23726
+ if (peerForwarding !== "always" && peerForwarding !== "when-used" && peerForwarding !== "when-exposed") throw new TypeError("commands.apiExposure.peerForwarding must be \"always\", \"when-used\", or \"when-exposed\"");
23715
23727
  return peerForwarding;
23716
23728
  }
23717
23729
  function normalizeApiExposureConfig(config) {
@@ -24637,6 +24649,88 @@ function getExposureFindings({ entryFiles, fileLabel, program }) {
24637
24649
  return findings;
24638
24650
  }
24639
24651
  //#endregion
24652
+ //#region src/actions/deplint/sourceFileCache.ts
24653
+ const cache$2 = /* @__PURE__ */ new Map();
24654
+ function scriptKindForPath(filePath) {
24655
+ if (/\.(?:mjs|cjs|js)$/i.test(filePath)) return ts.ScriptKind.JS;
24656
+ if (/\.tsx$/i.test(filePath)) return ts.ScriptKind.TSX;
24657
+ if (/\.jsx$/i.test(filePath)) return ts.ScriptKind.JSX;
24658
+ }
24659
+ function getCachedSourceFile(filePath) {
24660
+ const cached = cache$2.get(filePath);
24661
+ if (cached !== void 0) return cached;
24662
+ const sourceCode = fs.readFileSync(filePath, "utf8");
24663
+ const entry = {
24664
+ sourceCode,
24665
+ sourceFile: ts.createSourceFile(PATH.basename(filePath), sourceCode, ts.ScriptTarget.Latest, true, scriptKindForPath(filePath))
24666
+ };
24667
+ cache$2.set(filePath, entry);
24668
+ return entry;
24669
+ }
24670
+ /** Like getCachedSourceFile, but returns undefined when the file cannot be read. */
24671
+ function tryGetCachedSourceFile(filePath) {
24672
+ const cached = cache$2.get(filePath);
24673
+ if (cached !== void 0) return cached;
24674
+ try {
24675
+ return getCachedSourceFile(filePath);
24676
+ } catch {
24677
+ return;
24678
+ }
24679
+ }
24680
+ function clearSourceFileCache() {
24681
+ cache$2.clear();
24682
+ }
24683
+ //#endregion
24684
+ //#region src/actions/deplint/getImportsFromFile.ts
24685
+ function isTypeOnlyImportClause(clause) {
24686
+ if (clause === void 0) return false;
24687
+ if ("phaseModifier" in clause) {
24688
+ const mod = clause.phaseModifier;
24689
+ return (typeof mod === "number" ? mod : mod?.kind) === ts.SyntaxKind.TypeKeyword;
24690
+ }
24691
+ return clause.isTypeOnly ?? false;
24692
+ }
24693
+ function getImportsFromFile(filePath, importPaths, typeImportPaths) {
24694
+ const { sourceFile } = getCachedSourceFile(filePath);
24695
+ const imports = [];
24696
+ const typeImports = [];
24697
+ const isDeclarationFile = filePath.endsWith(".d.ts") || filePath.endsWith(".d.mts") || filePath.endsWith(".d.cts");
24698
+ function visit(node) {
24699
+ if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
24700
+ const moduleSpecifier = node.moduleSpecifier?.getFullText();
24701
+ const isTypeImport = ts.isImportDeclaration(node) ? isTypeOnlyImportClause(node.importClause) : false;
24702
+ if (typeof moduleSpecifier === "string") {
24703
+ const trimmed = moduleSpecifier.replaceAll(/['"]/g, "").trim();
24704
+ if (isTypeImport || isDeclarationFile) typeImports.push(trimmed);
24705
+ else imports.push(trimmed);
24706
+ }
24707
+ } else if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
24708
+ const [arg] = node.arguments;
24709
+ if (ts.isStringLiteral(arg)) imports.push(arg.text);
24710
+ } else if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "require" && node.arguments.length > 0 && ts.isStringLiteral(node.arguments[0])) imports.push(node.arguments[0].text);
24711
+ ts.forEachChild(node, visit);
24712
+ }
24713
+ visit(sourceFile);
24714
+ for (const ref of sourceFile.typeReferenceDirectives) typeImports.push(ref.fileName);
24715
+ const importsStartsWithExcludes = [
24716
+ ".",
24717
+ "#",
24718
+ "node:"
24719
+ ];
24720
+ const isValidImport = (imp) => importsStartsWithExcludes.every((exc) => !imp.startsWith(exc)) && !imp.includes("*") && !imp.includes("!");
24721
+ const cleanedImports = imports.filter(isValidImport).map(getBasePackageName);
24722
+ const cleanedTypeImports = typeImports.filter(isValidImport).map(getBasePackageName);
24723
+ for (const imp of cleanedImports) {
24724
+ importPaths[imp] ??= [];
24725
+ importPaths[imp].push(filePath);
24726
+ }
24727
+ for (const imp of cleanedTypeImports) {
24728
+ typeImportPaths[imp] ??= [];
24729
+ typeImportPaths[imp].push(filePath);
24730
+ }
24731
+ return [cleanedImports, cleanedTypeImports];
24732
+ }
24733
+ //#endregion
24640
24734
  //#region src/actions/api-exposure/analyzer/importedPackages.ts
24641
24735
  /**
24642
24736
  * Extracts the external package name from a module specifier, if any.
@@ -24648,29 +24742,56 @@ function packageNameFromSpecifier(specifier) {
24648
24742
  if (specifier.startsWith("@")) return parts.length > 1 ? `${parts[0]}/${parts[1]}` : void 0;
24649
24743
  return parts[0] === "" ? void 0 : parts[0];
24650
24744
  }
24651
- function collectFileImports(sourceFile, imported) {
24745
+ /**
24746
+ * True when every binding the statement introduces is type-only, so the
24747
+ * statement is erased at compile time and never executes the module.
24748
+ */
24749
+ function isTypeOnlyStatement(statement) {
24750
+ if (ts.isImportDeclaration(statement)) {
24751
+ const clause = statement.importClause;
24752
+ if (clause === void 0) return false;
24753
+ if (isTypeOnlyImportClause(clause)) return true;
24754
+ if (clause.name !== void 0) return false;
24755
+ const bindings = clause.namedBindings;
24756
+ return bindings !== void 0 && ts.isNamedImports(bindings) && bindings.elements.length > 0 && bindings.elements.every((element) => element.isTypeOnly);
24757
+ }
24758
+ if (statement.isTypeOnly) return true;
24759
+ const clause = statement.exportClause;
24760
+ return clause !== void 0 && ts.isNamedExports(clause) && clause.elements.length > 0 && clause.elements.every((element) => element.isTypeOnly);
24761
+ }
24762
+ function collectFileImports(sourceFile, seen) {
24652
24763
  for (const statement of sourceFile.statements) {
24653
- const moduleSpecifier = ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement) ? statement.moduleSpecifier : void 0;
24764
+ if (!ts.isImportDeclaration(statement) && !ts.isExportDeclaration(statement)) continue;
24765
+ const { moduleSpecifier } = statement;
24654
24766
  if (moduleSpecifier === void 0 || !ts.isStringLiteral(moduleSpecifier)) continue;
24655
24767
  const name = packageNameFromSpecifier(moduleSpecifier.text);
24656
- if (name !== void 0) imported.add(name);
24768
+ if (name === void 0) continue;
24769
+ if (isTypeOnlyStatement(statement)) seen.typeSeen.add(name);
24770
+ else seen.valueSeen.add(name);
24657
24771
  }
24658
24772
  }
24659
24773
  /**
24660
24774
  * Collects the external packages the workspace's own source files import
24661
- * (static imports and re-exports reachable from the entry points). This is
24662
- * the "does this package use the dependency itself" signal consumed by the
24663
- * `peerForwarding: 'when-used'` policy — a peer contract inherited from a
24664
- * dependency chain only forwards conclusively when the package appears here.
24775
+ * (static imports and re-exports reachable from the entry points), split
24776
+ * into value-position imports and exclusively-type-only imports. This feeds
24777
+ * two policies: `peerForwarding: 'when-used'`/`'when-exposed'` (does this
24778
+ * package need the peer itself) and the type-only chain-root check (does the
24779
+ * dependency imposing a peer contract ever execute here).
24665
24780
  */
24666
24781
  function getImportedPackages(program, workspaceDir) {
24667
- const imported = /* @__PURE__ */ new Set();
24782
+ const seen = {
24783
+ typeSeen: /* @__PURE__ */ new Set(),
24784
+ valueSeen: /* @__PURE__ */ new Set()
24785
+ };
24668
24786
  for (const sourceFile of program.getSourceFiles()) {
24669
24787
  const { fileName } = sourceFile;
24670
24788
  if (!fileName.startsWith(workspaceDir) || fileName.includes("node_modules")) continue;
24671
- collectFileImports(sourceFile, imported);
24789
+ collectFileImports(sourceFile, seen);
24672
24790
  }
24673
- return imported;
24791
+ return {
24792
+ typeOnly: new Set([...seen.typeSeen].filter((name) => !seen.valueSeen.has(name))),
24793
+ value: seen.valueSeen
24794
+ };
24674
24795
  }
24675
24796
  //#endregion
24676
24797
  //#region src/actions/api-exposure/analyzer/program.ts
@@ -24835,25 +24956,80 @@ function requiredPeerEvidence(sources) {
24835
24956
  const chains = [...new Set(sources.map((source) => source.chain?.join(" > ") ?? source.requiredBy))];
24836
24957
  return `required as a peer by ${chains.slice(0, 3).join(", ")}${chains.length > 3 ? ` (+${chains.length - 3} more)` : ""}`;
24837
24958
  }
24959
+ /**
24960
+ * Exposure evidence for the `'when-exposed'` forwarding policy: any enabled
24961
+ * exposure-rule finding means the dependency's types are part of this
24962
+ * package's public contract, so consumers interact with the dependency.
24963
+ */
24964
+ function hasEnabledExposure(raw, dependency, config) {
24965
+ return raw.some((finding) => finding.ruleId.startsWith("aei.exposure.") && config.ruleFor(finding.ruleId, dependency)?.enabled === true);
24966
+ }
24967
+ /**
24968
+ * The distinct chain roots when every chain imposing the peer contract is
24969
+ * rooted at a package this one imports exclusively as types — such chains
24970
+ * never execute at runtime here. Undefined when any root is (or may be)
24971
+ * a runtime import.
24972
+ */
24973
+ function typeOnlyChainRoots(peerSources, importedPackages) {
24974
+ if (importedPackages === void 0) return void 0;
24975
+ const roots = [...new Set(peerSources.map((source) => source.chain?.[0] ?? source.requiredBy))];
24976
+ return roots.every((root) => importedPackages.typeOnly.has(root)) ? roots : void 0;
24977
+ }
24978
+ /**
24979
+ * Resolves an unmet chain peer contract to a finding under the configured
24980
+ * forwarding policy (spec sections 6/8). Conclusive forwarding
24981
+ * (`aei.signal.required-peer`, ∞) applies under `'always'`, whenever usage
24982
+ * is unknown (no program), or when the policy's own-usage/exposure test
24983
+ * passes. Exposure is conclusive in both evidence-based modes — a peer
24984
+ * whose types reach this package's public API (e.g. through a re-exported
24985
+ * workspace-internal surface) is part of its contract even when this
24986
+ * package's own files never import it. Otherwise the contract downgrades
24987
+ * to the informational rule that best explains why no forwarding is
24988
+ * required here.
24989
+ */
24990
+ function peerChainFinding({ config, dependency, hasExposure, importedPackages, peerSources }) {
24991
+ const evidence = requiredPeerEvidence(peerSources);
24992
+ const file = "(peer-chain)";
24993
+ const valueImported = importedPackages?.value.has(dependency) ?? false;
24994
+ const typeImported = importedPackages?.typeOnly.has(dependency) ?? false;
24995
+ if (config.peerForwarding === "always" || importedPackages === void 0 || hasExposure || valueImported || config.peerForwarding === "when-used" && typeImported) return {
24996
+ dependency,
24997
+ evidence,
24998
+ file,
24999
+ ruleId: "aei.signal.required-peer"
25000
+ };
25001
+ const typeOnlyRoots = typeOnlyChainRoots(peerSources, importedPackages);
25002
+ if (typeOnlyRoots !== void 0) return {
25003
+ dependency,
25004
+ evidence: `${evidence} — but ${typeOnlyRoots.length === 1 ? `${typeOnlyRoots[0]} is imported only as types here` : `${typeOnlyRoots.join(", ")} are imported only as types here`}; the chain never executes at runtime, so there is no contract to forward`,
25005
+ file,
25006
+ ruleId: "aei.signal.type-only-chain-peer"
25007
+ };
25008
+ if (config.peerForwarding === "when-exposed") return {
25009
+ dependency,
25010
+ evidence: `${evidence} — neither exposed through this package's API nor value-imported; declaring it in this package's own dependencies (the provider pattern) discharges the contract (peerForwarding: when-exposed)`,
25011
+ file,
25012
+ ruleId: "aei.signal.absorbable-peer"
25013
+ };
25014
+ return {
25015
+ dependency,
25016
+ evidence: `${evidence} — neither imported nor exposed here; the installer resolves the contract (peerForwarding: when-used)`,
25017
+ file,
25018
+ ruleId: "aei.signal.inherited-peer"
25019
+ };
25020
+ }
24838
25021
  function assessDependency({ config, dependency, importedPackages, isSelfOrInternal, isTerminal, raw, refTypes, requiredPeerSources, sections, workspaceDir }) {
24839
25022
  const dependencyRaw = raw.filter((finding) => finding.dependency === dependency);
24840
25023
  const signals = getDependencySignals(workspaceDir, dependency);
24841
25024
  if (signals !== void 0) dependencyRaw.push(...signals.findings);
24842
25025
  const peerSources = requiredPeerSources.get(dependency);
24843
- if (peerSources !== void 0 && !isSelfOrInternal(dependency) && !sections.dependencies.has(dependency)) {
24844
- const isForwarded = config.peerForwarding === "always" || importedPackages === void 0 || importedPackages.has(dependency);
24845
- dependencyRaw.push(isForwarded ? {
24846
- dependency,
24847
- evidence: requiredPeerEvidence(peerSources),
24848
- file: "(peer-chain)",
24849
- ruleId: "aei.signal.required-peer"
24850
- } : {
24851
- dependency,
24852
- evidence: `${requiredPeerEvidence(peerSources)} — never imported here; the installer resolves the contract (peerForwarding: when-used)`,
24853
- file: "(peer-chain)",
24854
- ruleId: "aei.signal.inherited-peer"
24855
- });
24856
- }
25026
+ if (peerSources !== void 0 && !isSelfOrInternal(dependency) && !sections.dependencies.has(dependency)) dependencyRaw.push(peerChainFinding({
25027
+ config,
25028
+ dependency,
25029
+ hasExposure: hasEnabledExposure(dependencyRaw, dependency, config),
25030
+ importedPackages,
25031
+ peerSources
25032
+ }));
24857
25033
  if (config.treeShaking && sections.sideEffectsFree && signals?.esm === true && hasInstalledVersionMultiplicity(workspaceDir, dependency)) dependencyRaw.push({
24858
25034
  dependency,
24859
25035
  evidence: "sideEffects: false package with ESM dependency installed at multiple versions — peers improve deduplication",
@@ -24935,7 +25111,7 @@ function analyzeWorkspaceApiExposure({ cache, config, isTerminal, refTypes, work
24935
25111
  const requiredPeerSources = getRuntimeRootedNonOptionalTransitivePeerSources(workspaceDir, getDependenciesFromPackageJson(PATH.join(workspaceDir, "package.json")), { excludeSatisfiedInChain: true });
24936
25112
  const entryPoints = resolveEntryPoints(workspaceDir);
24937
25113
  const program = createExposureProgram(workspaceDir, entryPoints, cache);
24938
- const importedPackages = program === void 0 || config.peerForwarding !== "when-used" ? void 0 : getImportedPackages(program, workspaceDir);
25114
+ const importedPackages = program === void 0 || config.peerForwarding === "always" ? void 0 : getImportedPackages(program, workspaceDir);
24939
25115
  const raw = [];
24940
25116
  if (program !== void 0) raw.push(...getExposureFindings({
24941
25117
  entryFiles: entryPoints,
@@ -25346,38 +25522,6 @@ function analyzeBarrel(barrelPkg, fromDir, scopePrefix) {
25346
25522
  return [...collected].toSorted((a, b) => a.localeCompare(b));
25347
25523
  }
25348
25524
  //#endregion
25349
- //#region src/actions/deplint/sourceFileCache.ts
25350
- const cache$2 = /* @__PURE__ */ new Map();
25351
- function scriptKindForPath(filePath) {
25352
- if (/\.(?:mjs|cjs|js)$/i.test(filePath)) return ts.ScriptKind.JS;
25353
- if (/\.tsx$/i.test(filePath)) return ts.ScriptKind.TSX;
25354
- if (/\.jsx$/i.test(filePath)) return ts.ScriptKind.JSX;
25355
- }
25356
- function getCachedSourceFile(filePath) {
25357
- const cached = cache$2.get(filePath);
25358
- if (cached !== void 0) return cached;
25359
- const sourceCode = fs.readFileSync(filePath, "utf8");
25360
- const entry = {
25361
- sourceCode,
25362
- sourceFile: ts.createSourceFile(PATH.basename(filePath), sourceCode, ts.ScriptTarget.Latest, true, scriptKindForPath(filePath))
25363
- };
25364
- cache$2.set(filePath, entry);
25365
- return entry;
25366
- }
25367
- /** Like getCachedSourceFile, but returns undefined when the file cannot be read. */
25368
- function tryGetCachedSourceFile(filePath) {
25369
- const cached = cache$2.get(filePath);
25370
- if (cached !== void 0) return cached;
25371
- try {
25372
- return getCachedSourceFile(filePath);
25373
- } catch {
25374
- return;
25375
- }
25376
- }
25377
- function clearSourceFileCache() {
25378
- cache$2.clear();
25379
- }
25380
- //#endregion
25381
25525
  //#region src/actions/deplint/findFiles.ts
25382
25526
  const codeExtensions$1 = "*.{ts,tsx,mts,cts,js,mjs,cjs}";
25383
25527
  const codeExtensionRe = /\.(?:ts|tsx|mts|cts|js|mjs|cjs)$/i;
@@ -27710,56 +27854,6 @@ function getTypesFromTsconfigs(location) {
27710
27854
  return [...packages];
27711
27855
  }
27712
27856
  //#endregion
27713
- //#region src/actions/deplint/getImportsFromFile.ts
27714
- function isTypeOnlyImportClause(clause) {
27715
- if (clause === void 0) return false;
27716
- if ("phaseModifier" in clause) {
27717
- const mod = clause.phaseModifier;
27718
- return (typeof mod === "number" ? mod : mod?.kind) === ts.SyntaxKind.TypeKeyword;
27719
- }
27720
- return clause.isTypeOnly ?? false;
27721
- }
27722
- function getImportsFromFile(filePath, importPaths, typeImportPaths) {
27723
- const { sourceFile } = getCachedSourceFile(filePath);
27724
- const imports = [];
27725
- const typeImports = [];
27726
- const isDeclarationFile = filePath.endsWith(".d.ts") || filePath.endsWith(".d.mts") || filePath.endsWith(".d.cts");
27727
- function visit(node) {
27728
- if (ts.isImportDeclaration(node) || ts.isExportDeclaration(node)) {
27729
- const moduleSpecifier = node.moduleSpecifier?.getFullText();
27730
- const isTypeImport = ts.isImportDeclaration(node) ? isTypeOnlyImportClause(node.importClause) : false;
27731
- if (typeof moduleSpecifier === "string") {
27732
- const trimmed = moduleSpecifier.replaceAll(/['"]/g, "").trim();
27733
- if (isTypeImport || isDeclarationFile) typeImports.push(trimmed);
27734
- else imports.push(trimmed);
27735
- }
27736
- } else if (ts.isCallExpression(node) && node.expression.kind === ts.SyntaxKind.ImportKeyword) {
27737
- const [arg] = node.arguments;
27738
- if (ts.isStringLiteral(arg)) imports.push(arg.text);
27739
- } else if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "require" && node.arguments.length > 0 && ts.isStringLiteral(node.arguments[0])) imports.push(node.arguments[0].text);
27740
- ts.forEachChild(node, visit);
27741
- }
27742
- visit(sourceFile);
27743
- for (const ref of sourceFile.typeReferenceDirectives) typeImports.push(ref.fileName);
27744
- const importsStartsWithExcludes = [
27745
- ".",
27746
- "#",
27747
- "node:"
27748
- ];
27749
- const isValidImport = (imp) => importsStartsWithExcludes.every((exc) => !imp.startsWith(exc)) && !imp.includes("*") && !imp.includes("!");
27750
- const cleanedImports = imports.filter(isValidImport).map(getBasePackageName);
27751
- const cleanedTypeImports = typeImports.filter(isValidImport).map(getBasePackageName);
27752
- for (const imp of cleanedImports) {
27753
- importPaths[imp] ??= [];
27754
- importPaths[imp].push(filePath);
27755
- }
27756
- for (const imp of cleanedTypeImports) {
27757
- typeImportPaths[imp] ??= [];
27758
- typeImportPaths[imp].push(filePath);
27759
- }
27760
- return [cleanedImports, cleanedTypeImports];
27761
- }
27762
- //#endregion
27763
27857
  //#region src/actions/deplint/getStorybookConfigImports.ts
27764
27858
  const storybookMainPattern = /(?:^|[\\/])\.storybook[\\/]main\.[cm]?[jt]sx?$/;
27765
27859
  const npmPackageNamePattern = /^@?[a-z0-9][\w./-]*$/i;
@@ -28811,6 +28905,10 @@ function formatFullVersion(version) {
28811
28905
  if (version == null || version.length === 0) return void 0;
28812
28906
  return import_semver.default.parse(version)?.version;
28813
28907
  }
28908
+ function formatPeerCaretVersion(version) {
28909
+ const parsed = import_semver.default.parse(version);
28910
+ return parsed ? `^${parsed.major}.${parsed.minor}` : void 0;
28911
+ }
28814
28912
  /**
28815
28913
  * Format an installed version as a broad peerDependency range. The upper
28816
28914
  * bound is the next major (`'major'`, default) or next minor (`'minor'`):
@@ -28884,15 +28982,14 @@ function resolveExpectedPeerVersion(location, dep, devRange, boundType) {
28884
28982
  }
28885
28983
  /**
28886
28984
  * Compute the non-broad peerDependency range for a dep. The result is a
28887
- * caret range anchored at a full three-part lower bound. Prefer the sibling
28985
+ * caret range anchored at a major-minor lower bound. Prefer the sibling
28888
28986
  * devDependency floor; fall back to the current peer range and then the
28889
28987
  * installed version.
28890
28988
  */
28891
28989
  function resolveExpectedPeerShorthandVersion(location, dep, devRange, peerRange) {
28892
28990
  const lower = resolvePeerLowerBound(location, dep, devRange, peerRange);
28893
28991
  if (lower == null || lower.length === 0) return "*";
28894
- const version = formatFullVersion(lower);
28895
- return version ? `^${version}` : "*";
28992
+ return formatPeerCaretVersion(lower) ?? "*";
28896
28993
  }
28897
28994
  /**
28898
28995
  * Single entry-point used by every rule that writes a peerDependency range.
@@ -30122,7 +30219,7 @@ const peerDependencyRangeStyleRule = {
30122
30219
  expected
30123
30220
  },
30124
30221
  dependency: dep,
30125
- message: form === "broad" ? `peerDependency ${dep} range ${current} should use broad form ${expected}` : `peerDependency ${dep} range ${current} should use full-patch caret form ${expected}`
30222
+ message: form === "broad" ? `peerDependency ${dep} range ${current} should use broad form ${expected}` : `peerDependency ${dep} range ${current} should use major-minor caret form ${expected}`
30126
30223
  });
30127
30224
  }
30128
30225
  },
@@ -30247,6 +30344,80 @@ async function loadDeplintRules(config) {
30247
30344
  return normalizeDeplintRules(plugins.flatMap((plugin) => plugin.rules), config, new Set(builtInDeplintPlugin.rules.map((rule) => rule.id)));
30248
30345
  }
30249
30346
  //#endregion
30347
+ //#region src/actions/deplint/getInternalSurfaceVouchedPeers.ts
30348
+ /** Bound on recursion through nested workspace-internal surfaces. */
30349
+ const MAX_INTERNAL_SURFACE_DEPTH = 3;
30350
+ const surfaceImportsCache = /* @__PURE__ */ new Map();
30351
+ function resolveInternalSurface(baseDir, name) {
30352
+ const manifestPath = findDepPackageJson(baseDir, name);
30353
+ if (manifestPath === void 0) return void 0;
30354
+ try {
30355
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
30356
+ let dir = PATH.dirname(manifestPath);
30357
+ try {
30358
+ dir = fs.realpathSync(dir);
30359
+ } catch {}
30360
+ return {
30361
+ dir,
30362
+ peerDependencies: Object.keys(manifest.peerDependencies ?? {})
30363
+ };
30364
+ } catch {
30365
+ return;
30366
+ }
30367
+ }
30368
+ /**
30369
+ * External package names referenced by a package's shipped surface: import
30370
+ * specifiers in its dist runtime and emitted d.ts. Falls back to src when
30371
+ * no dist exists (unbuilt workspace), mirroring deplint's own fallback.
30372
+ */
30373
+ function getSurfaceImports(dir) {
30374
+ const cached = surfaceImportsCache.get(dir);
30375
+ if (cached !== void 0) return cached;
30376
+ let files = findFilesByGlob(dir, "dist/**/*.{js,mjs,cjs,ts,mts,cts}", ["**/node_modules/**"]);
30377
+ if (files.length === 0) files = findFilesByGlob(dir, "src/**/*.{ts,tsx,mts,cts}", ["**/node_modules/**"]);
30378
+ const imports = /* @__PURE__ */ new Set();
30379
+ for (const file of files) {
30380
+ const [valueImports, typeImports] = getImportsFromFile(file, {}, {});
30381
+ for (const name of valueImports) imports.add(name);
30382
+ for (const name of typeImports) imports.add(name);
30383
+ }
30384
+ surfaceImportsCache.set(dir, imports);
30385
+ return imports;
30386
+ }
30387
+ /**
30388
+ * Peers vouched for by workspace-internal packages whose surface this
30389
+ * package ships. A pure re-export barrel never names the peers it
30390
+ * re-exposes in its own imports or emitted d.ts, so scan-based forwarding
30391
+ * evidence (`PeerForwardingPolicy.importedModules`) cannot see them. The
30392
+ * re-exported internal package's own shipped surface is the next-best
30393
+ * authority: any peer it declares AND references from its dist runtime or
30394
+ * emitted d.ts flows through every package that ships its surface.
30395
+ * Recurses through nested internal surfaces (a barrel re-exporting a
30396
+ * facade re-exporting core), depth-limited.
30397
+ */
30398
+ function getInternalSurfaceVouchedPeers(location, shippedImports, workspaceNames) {
30399
+ const vouched = /* @__PURE__ */ new Set();
30400
+ const visited = /* @__PURE__ */ new Set();
30401
+ const visitSurface = ({ baseDir, name }) => {
30402
+ if (visited.has(name)) return [];
30403
+ visited.add(name);
30404
+ const surface = resolveInternalSurface(baseDir, name);
30405
+ if (surface === void 0) return [];
30406
+ const surfaceImports = getSurfaceImports(surface.dir);
30407
+ for (const peer of surface.peerDependencies) if (surfaceImports.has(peer)) vouched.add(peer);
30408
+ return [...surfaceImports].filter((imported) => workspaceNames.has(imported)).map((imported) => ({
30409
+ baseDir: surface.dir,
30410
+ name: imported
30411
+ }));
30412
+ };
30413
+ let frontier = [...new Set(shippedImports)].filter((name) => workspaceNames.has(name)).map((name) => ({
30414
+ baseDir: location,
30415
+ name
30416
+ }));
30417
+ for (let depth = 0; depth < MAX_INTERNAL_SURFACE_DEPTH && frontier.length > 0; depth++) frontier = frontier.flatMap((ref) => visitSurface(ref));
30418
+ return vouched;
30419
+ }
30420
+ //#endregion
30250
30421
  //#region src/actions/deplint/snapshot.ts
30251
30422
  function buildUnusedDependencyExclude(options, requiredTransitivePeers) {
30252
30423
  return /* @__PURE__ */ new Set([
@@ -30323,14 +30494,16 @@ function buildWorkspaceContext(workspace, options = {}) {
30323
30494
  const packageMetaStarted = performance.now();
30324
30495
  const packageJsonPath = `${workspace.location}/package.json`;
30325
30496
  const packageParams = getDependenciesFromPackageJson(packageJsonPath);
30326
- const peerForwarding = options.classifier === "aei" && options.apiExposureConfig?.peerForwarding === "when-used" ? {
30327
- importedModules: /* @__PURE__ */ new Set([
30497
+ const forwardingMode = options.classifier === "aei" ? options.apiExposureConfig?.peerForwarding ?? "always" : "always";
30498
+ const peerForwarding = forwardingMode === "always" ? void 0 : {
30499
+ importedModules: forwardingMode === "when-exposed" ? /* @__PURE__ */ new Set([...sourceParams.externalDistImports, ...sourceParams.externalDistTypeImports]) : /* @__PURE__ */ new Set([
30328
30500
  ...sourceParams.externalAllImports,
30329
30501
  ...sourceParams.externalDistImports,
30330
30502
  ...sourceParams.externalDistTypeImports
30331
30503
  ]),
30332
- mode: "when-used"
30333
- } : void 0;
30504
+ mode: forwardingMode,
30505
+ vouchedPeers: options.workspaceNames === void 0 ? void 0 : getInternalSurfaceVouchedPeers(workspace.location, [...sourceParams.externalDistImports, ...sourceParams.externalDistTypeImports], options.workspaceNames)
30506
+ };
30334
30507
  const requiredTransitivePeers = getRequiredNonOptionalTransitivePeers(workspace.location, packageParams);
30335
30508
  const runtimeRootedRequired = new Set([...getRuntimeRootedNonOptionalTransitivePeers(workspace.location, packageParams)].filter((peer) => isPeerForwarded(peerForwarding, peer)));
30336
30509
  const packageClassification = classifyDeplintPackage(workspace.location, terminalOverride);
@@ -30813,7 +30986,7 @@ function pickUpgradeTarget(manifest, peer, installedPeerVersion, currentRange) {
30813
30986
  return absoluteBest;
30814
30987
  }
30815
30988
  function buildBumpedRange(resolvedVersion, section) {
30816
- return section === "peerDependencies" ? `^${resolvedVersion}` : `~${resolvedVersion}`;
30989
+ return section === "peerDependencies" ? formatPeerCaretVersion(resolvedVersion) ?? `^${resolvedVersion}` : `~${resolvedVersion}`;
30817
30990
  }
30818
30991
  function resolveOneFix(fix, manifest, resolutionCache, loggedKeys) {
30819
30992
  const cacheKey = keyOf(fix);