@ariestools/toolchain 8.7.4 → 8.7.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/dist/actions/api-exposure/analyzer/analyzePackage.d.ts.map +1 -1
- package/dist/actions/api-exposure/analyzer/depSignals.d.ts +8 -0
- package/dist/actions/api-exposure/analyzer/depSignals.d.ts.map +1 -1
- package/dist/actions/api-exposure/analyzer/importedPackages.d.ts +15 -0
- package/dist/actions/api-exposure/analyzer/importedPackages.d.ts.map +1 -0
- package/dist/actions/api-exposure/config.d.ts +3 -1
- package/dist/actions/api-exposure/config.d.ts.map +1 -1
- package/dist/actions/api-exposure/rules.d.ts.map +1 -1
- package/dist/actions/deplint/checkPackage/getUnsatisfiedPeerDependencies.d.ts +18 -1
- package/dist/actions/deplint/checkPackage/getUnsatisfiedPeerDependencies.d.ts.map +1 -1
- package/dist/actions/deplint/rules.d.ts.map +1 -1
- package/dist/actions/deplint/rulesMisplaced.d.ts.map +1 -1
- package/dist/actions/deplint/snapshot.d.ts.map +1 -1
- package/dist/actions/deplint/types.d.ts +7 -1
- package/dist/actions/deplint/types.d.ts.map +1 -1
- package/dist/actions/package/compile/ApiExposureConfig.d.ts +16 -0
- package/dist/actions/package/compile/ApiExposureConfig.d.ts.map +1 -1
- package/dist/bin/skills.mjs +2073 -1205
- package/dist/bin/skills.mjs.map +1 -1
- package/dist/bin/xy.mjs +203 -27
- package/dist/bin/xy.mjs.map +1 -1
- package/package.json +6 -6
package/dist/bin/xy.mjs
CHANGED
|
@@ -23097,6 +23097,10 @@ function isTerminalPackage$1(location) {
|
|
|
23097
23097
|
}
|
|
23098
23098
|
//#endregion
|
|
23099
23099
|
//#region src/actions/deplint/checkPackage/getUnsatisfiedPeerDependencies.ts
|
|
23100
|
+
/** True when the policy (if any) obliges this package to forward `peer`. */
|
|
23101
|
+
function isPeerForwarded(policy, peer) {
|
|
23102
|
+
return policy === void 0 || policy.mode === "always" || policy.importedModules.has(peer);
|
|
23103
|
+
}
|
|
23100
23104
|
function readDepPackageJson(location, dep) {
|
|
23101
23105
|
const depPkgPath = findDepPackageJson(location, dep);
|
|
23102
23106
|
if (depPkgPath == null || depPkgPath.length === 0) return void 0;
|
|
@@ -23278,21 +23282,39 @@ function findDeclaredPeerVersionMismatches(name, location, peerDependencies, pee
|
|
|
23278
23282
|
}
|
|
23279
23283
|
return results;
|
|
23280
23284
|
}
|
|
23281
|
-
|
|
23282
|
-
|
|
23283
|
-
|
|
23285
|
+
/**
|
|
23286
|
+
* Resolves how the peer's runtime contract binds this package. An explicit
|
|
23287
|
+
* `peerOptional` override vouches for the contract; otherwise
|
|
23288
|
+
* `peerForwarding: 'when-used'` demotes never-imported chain peers to a
|
|
23289
|
+
* local dev need (installers resolve the consumer-side contract).
|
|
23290
|
+
*/
|
|
23291
|
+
function resolveRuntimeContract(peer, sources, ctx) {
|
|
23292
|
+
const { location, forcePeerOptional, forwarding } = ctx;
|
|
23284
23293
|
const isPeerForced = forcePeerOptional?.has(peer) ?? false;
|
|
23294
|
+
const isForwarded = isPeerForced || isPeerForwarded(forwarding, peer);
|
|
23285
23295
|
const runtimeSources = sources.filter((s) => s.isRuntimeDep);
|
|
23286
|
-
const
|
|
23296
|
+
const hasRuntimeContract = runtimeSources.length > 0 && (isPeerForced || !isPeerOptionalInAll(location, peer, runtimeSources));
|
|
23297
|
+
const directRuntimeSources = sources.filter((s) => s.isRuntimeDep && !s.chain);
|
|
23298
|
+
const shouldForwardRuntime = directRuntimeSources.length > 0 && isForwarded && (isPeerForced || !isPeerOptionalInAll(location, peer, directRuntimeSources));
|
|
23299
|
+
return {
|
|
23300
|
+
hasRuntimeSource: hasRuntimeContract && isForwarded,
|
|
23301
|
+
isInherited: hasRuntimeContract && !isForwarded,
|
|
23302
|
+
shouldForwardRuntime
|
|
23303
|
+
};
|
|
23304
|
+
}
|
|
23305
|
+
function classifyPeer(peer, sources, ctx) {
|
|
23306
|
+
const { location, depsSet, devDepsSet, peerDepsSet, isTerminal, forceDevs } = ctx;
|
|
23307
|
+
if (forceDevs.has(peer)) return void 0;
|
|
23308
|
+
const { hasRuntimeSource, isInherited, shouldForwardRuntime } = resolveRuntimeContract(peer, sources, ctx);
|
|
23287
23309
|
if (!depsSet.has(peer) && !devDepsSet.has(peer)) return {
|
|
23288
23310
|
hasRuntimeSource,
|
|
23311
|
+
...isInherited && { inherited: true },
|
|
23289
23312
|
peer,
|
|
23290
23313
|
reason: "missing",
|
|
23291
23314
|
sources,
|
|
23292
23315
|
versionRange: resolveVersionRange(location, sources, peer)
|
|
23293
23316
|
};
|
|
23294
|
-
|
|
23295
|
-
if (directRuntimeSources.length > 0 && (isPeerForced || !isPeerOptionalInAll(location, peer, directRuntimeSources)) && !isTerminal && !depsSet.has(peer) && !peerDepsSet.has(peer)) return {
|
|
23317
|
+
if (shouldForwardRuntime && !isTerminal && !depsSet.has(peer) && !peerDepsSet.has(peer)) return {
|
|
23296
23318
|
hasRuntimeSource,
|
|
23297
23319
|
peer,
|
|
23298
23320
|
reason: "under-exposed",
|
|
@@ -23312,13 +23334,14 @@ function classifyPeer(peer, sources, ctx) {
|
|
|
23312
23334
|
versionRange
|
|
23313
23335
|
};
|
|
23314
23336
|
}
|
|
23315
|
-
function findUnsatisfiedPeers({ name, location }, { dependencies, devDependencies, peerDependencies, peerDependencyVersions }, exclude, isTerminal, forcePeerOptional, forceDevs) {
|
|
23337
|
+
function findUnsatisfiedPeers({ name, location }, { dependencies, devDependencies, peerDependencies, peerDependencyVersions }, exclude, isTerminal, forcePeerOptional, forceDevs, forwarding) {
|
|
23316
23338
|
const peerSources = collectPeerSources(location, dependencies, devDependencies, peerDependencies);
|
|
23317
23339
|
const ctx = {
|
|
23318
23340
|
depsSet: new Set(dependencies),
|
|
23319
23341
|
devDepsSet: new Set(devDependencies),
|
|
23320
23342
|
forceDevs: forceDevs ?? /* @__PURE__ */ new Set(),
|
|
23321
23343
|
forcePeerOptional,
|
|
23344
|
+
forwarding,
|
|
23322
23345
|
isTerminal: isTerminal ?? isTerminalPackage$1(location),
|
|
23323
23346
|
location,
|
|
23324
23347
|
peerDepsSet: new Set(peerDependencies)
|
|
@@ -23521,6 +23544,12 @@ const AEI_RULES = [
|
|
|
23521
23544
|
id: "aei.signal.required-peer",
|
|
23522
23545
|
kind: "dep-signal"
|
|
23523
23546
|
},
|
|
23547
|
+
{
|
|
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",
|
|
23550
|
+
id: "aei.signal.inherited-peer",
|
|
23551
|
+
kind: "dep-signal"
|
|
23552
|
+
},
|
|
23524
23553
|
{
|
|
23525
23554
|
defaultWeight: 40,
|
|
23526
23555
|
description: "Dependency uses a global registry",
|
|
@@ -23675,6 +23704,10 @@ function matchingOverrides(packages, dependency) {
|
|
|
23675
23704
|
});
|
|
23676
23705
|
return exact === void 0 ? globs : [...globs, exact];
|
|
23677
23706
|
}
|
|
23707
|
+
function resolvePeerForwarding(peerForwarding = "always") {
|
|
23708
|
+
if (peerForwarding !== "always" && peerForwarding !== "when-used") throw new TypeError("commands.apiExposure.peerForwarding must be \"always\" or \"when-used\"");
|
|
23709
|
+
return peerForwarding;
|
|
23710
|
+
}
|
|
23678
23711
|
function normalizeApiExposureConfig(config) {
|
|
23679
23712
|
const globalRuleSettings = config?.rules ?? {};
|
|
23680
23713
|
validateRuleIds("commands.apiExposure.rules", globalRuleSettings);
|
|
@@ -23720,6 +23753,7 @@ function normalizeApiExposureConfig(config) {
|
|
|
23720
23753
|
};
|
|
23721
23754
|
return {
|
|
23722
23755
|
classificationFor,
|
|
23756
|
+
peerForwarding: resolvePeerForwarding(config?.peerForwarding),
|
|
23723
23757
|
ruleFor,
|
|
23724
23758
|
rules: globalRules,
|
|
23725
23759
|
thresholds: resolveThresholds(config?.thresholds),
|
|
@@ -24020,6 +24054,41 @@ const FACTORY_NAME_PATTERN = /^(?:create|make|build)[A-Z_]/;
|
|
|
24020
24054
|
const REGISTRY_NAME_PATTERN = /registry|container/i;
|
|
24021
24055
|
/** Cap on how much of a dependency's types entry we parse for signals. */
|
|
24022
24056
|
const MAX_TYPES_FILE_BYTES = 1e6;
|
|
24057
|
+
const pnpmVirtualStoreCache = /* @__PURE__ */ new Map();
|
|
24058
|
+
/** Walks up from `startDir` looking for a `node_modules/.pnpm` virtual store. */
|
|
24059
|
+
function findPnpmVirtualStoreEntries(startDir) {
|
|
24060
|
+
let current = PATH.resolve(startDir);
|
|
24061
|
+
while (true) {
|
|
24062
|
+
const candidate = PATH.join(current, "node_modules", ".pnpm");
|
|
24063
|
+
if (fs.existsSync(candidate)) {
|
|
24064
|
+
const cached = pnpmVirtualStoreCache.get(candidate);
|
|
24065
|
+
if (cached !== void 0) return cached;
|
|
24066
|
+
try {
|
|
24067
|
+
const entries = fs.readdirSync(candidate);
|
|
24068
|
+
pnpmVirtualStoreCache.set(candidate, entries);
|
|
24069
|
+
return entries;
|
|
24070
|
+
} catch {
|
|
24071
|
+
return;
|
|
24072
|
+
}
|
|
24073
|
+
}
|
|
24074
|
+
const parent = PATH.dirname(current);
|
|
24075
|
+
if (parent === current) return void 0;
|
|
24076
|
+
current = parent;
|
|
24077
|
+
}
|
|
24078
|
+
}
|
|
24079
|
+
/**
|
|
24080
|
+
* True when the install tree holds more than one version of the dependency —
|
|
24081
|
+
* the duplication-risk condition of the tree-shaking modifier
|
|
24082
|
+
* (API-EXPOSURE-INDEX.md section 9). Only the pnpm virtual store can be read
|
|
24083
|
+
* cheaply; on other layouts the answer is unknown, so the modifier keeps its
|
|
24084
|
+
* historical behavior and applies.
|
|
24085
|
+
*/
|
|
24086
|
+
function hasInstalledVersionMultiplicity(workspaceDir, dependency) {
|
|
24087
|
+
const entries = findPnpmVirtualStoreEntries(workspaceDir);
|
|
24088
|
+
if (entries === void 0) return true;
|
|
24089
|
+
const prefix = `${dependency.replace("/", "+")}@`;
|
|
24090
|
+
return new Set(entries.filter((entry) => entry.startsWith(prefix)).map((entry) => entry.slice(prefix.length).split("_", 1)[0])).size > 1;
|
|
24091
|
+
}
|
|
24023
24092
|
/** Walks up from `startDir` looking for `node_modules/<dependency>/package.json`. */
|
|
24024
24093
|
function findDependencyDir(startDir, dependency) {
|
|
24025
24094
|
let current = PATH.resolve(startDir);
|
|
@@ -24441,6 +24510,42 @@ function getExposureFindings({ entryFiles, fileLabel, program }) {
|
|
|
24441
24510
|
return findings;
|
|
24442
24511
|
}
|
|
24443
24512
|
//#endregion
|
|
24513
|
+
//#region src/actions/api-exposure/analyzer/importedPackages.ts
|
|
24514
|
+
/**
|
|
24515
|
+
* Extracts the external package name from a module specifier, if any.
|
|
24516
|
+
* Relative paths, `#` subpath imports, and `node:` builtins are internal.
|
|
24517
|
+
*/
|
|
24518
|
+
function packageNameFromSpecifier(specifier) {
|
|
24519
|
+
if (specifier.startsWith(".") || specifier.startsWith("#") || specifier.startsWith("node:")) return void 0;
|
|
24520
|
+
const parts = specifier.split("/");
|
|
24521
|
+
if (specifier.startsWith("@")) return parts.length > 1 ? `${parts[0]}/${parts[1]}` : void 0;
|
|
24522
|
+
return parts[0] === "" ? void 0 : parts[0];
|
|
24523
|
+
}
|
|
24524
|
+
function collectFileImports(sourceFile, imported) {
|
|
24525
|
+
for (const statement of sourceFile.statements) {
|
|
24526
|
+
const moduleSpecifier = ts.isImportDeclaration(statement) || ts.isExportDeclaration(statement) ? statement.moduleSpecifier : void 0;
|
|
24527
|
+
if (moduleSpecifier === void 0 || !ts.isStringLiteral(moduleSpecifier)) continue;
|
|
24528
|
+
const name = packageNameFromSpecifier(moduleSpecifier.text);
|
|
24529
|
+
if (name !== void 0) imported.add(name);
|
|
24530
|
+
}
|
|
24531
|
+
}
|
|
24532
|
+
/**
|
|
24533
|
+
* Collects the external packages the workspace's own source files import
|
|
24534
|
+
* (static imports and re-exports reachable from the entry points). This is
|
|
24535
|
+
* the "does this package use the dependency itself" signal consumed by the
|
|
24536
|
+
* `peerForwarding: 'when-used'` policy — a peer contract inherited from a
|
|
24537
|
+
* dependency chain only forwards conclusively when the package appears here.
|
|
24538
|
+
*/
|
|
24539
|
+
function getImportedPackages(program, workspaceDir) {
|
|
24540
|
+
const imported = /* @__PURE__ */ new Set();
|
|
24541
|
+
for (const sourceFile of program.getSourceFiles()) {
|
|
24542
|
+
const { fileName } = sourceFile;
|
|
24543
|
+
if (!fileName.startsWith(workspaceDir) || fileName.includes("node_modules")) continue;
|
|
24544
|
+
collectFileImports(sourceFile, imported);
|
|
24545
|
+
}
|
|
24546
|
+
return imported;
|
|
24547
|
+
}
|
|
24548
|
+
//#endregion
|
|
24444
24549
|
//#region src/actions/api-exposure/analyzer/program.ts
|
|
24445
24550
|
function createSharedProgramCache() {
|
|
24446
24551
|
return { sourceFiles: /* @__PURE__ */ new Map() };
|
|
@@ -24497,6 +24602,7 @@ function readManifestSections(workspaceDir) {
|
|
|
24497
24602
|
return {
|
|
24498
24603
|
dependencies: new Set(Object.keys(pkg.dependencies ?? {})),
|
|
24499
24604
|
devDependencies: new Set(Object.keys(pkg.devDependencies ?? {})),
|
|
24605
|
+
isPrivate: pkg.private === true,
|
|
24500
24606
|
peerDependencies: new Set(Object.keys(pkg.peerDependencies ?? {})),
|
|
24501
24607
|
sideEffectsFree: pkg.sideEffects === false
|
|
24502
24608
|
};
|
|
@@ -24504,6 +24610,7 @@ function readManifestSections(workspaceDir) {
|
|
|
24504
24610
|
return {
|
|
24505
24611
|
dependencies: /* @__PURE__ */ new Set(),
|
|
24506
24612
|
devDependencies: /* @__PURE__ */ new Set(),
|
|
24613
|
+
isPrivate: false,
|
|
24507
24614
|
peerDependencies: /* @__PURE__ */ new Set(),
|
|
24508
24615
|
sideEffectsFree: false
|
|
24509
24616
|
};
|
|
@@ -24524,11 +24631,30 @@ function couplingSourceFiles(workspaceDir, programFiles) {
|
|
|
24524
24631
|
return findFilesByGlob(workspaceDir, "./src/**/*.{ts,tsx,mts,cts}", ["**/node_modules/**"]).filter((file) => !file.endsWith(".d.ts"));
|
|
24525
24632
|
}
|
|
24526
24633
|
const PROVIDED_CLOSURE_DEPTH = 2;
|
|
24527
|
-
|
|
24528
|
-
|
|
24529
|
-
|
|
24530
|
-
|
|
24634
|
+
/**
|
|
24635
|
+
* Exposure of these rules requires the dependency's code at runtime; every
|
|
24636
|
+
* other exposure rule only leaks *types*. Coupling rules are runtime by
|
|
24637
|
+
* definition. Used to decide whether a devDependency (e.g. `@types/express`)
|
|
24638
|
+
* can vouch for an unlisted, provided dependency.
|
|
24639
|
+
*/
|
|
24640
|
+
const RUNTIME_EXPOSURE_RULES = /* @__PURE__ */ new Set([
|
|
24641
|
+
"aei.exposure.class-extends",
|
|
24642
|
+
"aei.exposure.exported-constant",
|
|
24643
|
+
"aei.exposure.exported-owned-value",
|
|
24644
|
+
"aei.exposure.named-reexport",
|
|
24645
|
+
"aei.exposure.star-reexport"
|
|
24531
24646
|
]);
|
|
24647
|
+
function isTypeOnlyExposure(findings) {
|
|
24648
|
+
return findings.every((finding) => !RUNTIME_EXPOSURE_RULES.has(finding.ruleId) && !finding.ruleId.startsWith("aei.coupling."));
|
|
24649
|
+
}
|
|
24650
|
+
/**
|
|
24651
|
+
* The `@types/*` spelling(s) of a package name. Symbol attribution maps
|
|
24652
|
+
* `@types/foo` declarations back to `foo` (exposureWalk), so the provided
|
|
24653
|
+
* check must also look for the DefinitelyTyped package in provider closures.
|
|
24654
|
+
*/
|
|
24655
|
+
function typesAliasesOf(target) {
|
|
24656
|
+
return target.startsWith("@") ? [`@types/${target.slice(1).replace("/", "__")}`] : [`@types/${target}`];
|
|
24657
|
+
}
|
|
24532
24658
|
/**
|
|
24533
24659
|
* True when `target` is provided by the dependency closure of one of the
|
|
24534
24660
|
* package's declared deps (depth-limited, mirroring the peer-chain walk).
|
|
@@ -24547,7 +24673,8 @@ function readDeclaredDependencies(workspaceDir, dep) {
|
|
|
24547
24673
|
return [];
|
|
24548
24674
|
}
|
|
24549
24675
|
}
|
|
24550
|
-
function isProvidedByDeclaredDeps(workspaceDir, declared,
|
|
24676
|
+
function isProvidedByDeclaredDeps(workspaceDir, declared, targets) {
|
|
24677
|
+
const targetSet = new Set(targets);
|
|
24551
24678
|
const visited = /* @__PURE__ */ new Set();
|
|
24552
24679
|
let frontier = [...declared];
|
|
24553
24680
|
for (let depth = 0; depth <= PROVIDED_CLOSURE_DEPTH; depth++) {
|
|
@@ -24556,7 +24683,7 @@ function isProvidedByDeclaredDeps(workspaceDir, declared, target) {
|
|
|
24556
24683
|
for (const dep of unvisited) {
|
|
24557
24684
|
visited.add(dep);
|
|
24558
24685
|
const dependencies = readDeclaredDependencies(workspaceDir, dep);
|
|
24559
|
-
if (dependencies.
|
|
24686
|
+
if (dependencies.some((dependency) => targetSet.has(dependency))) return true;
|
|
24560
24687
|
next.push(...dependencies);
|
|
24561
24688
|
}
|
|
24562
24689
|
frontier = next;
|
|
@@ -24568,20 +24695,28 @@ function requiredPeerEvidence(sources) {
|
|
|
24568
24695
|
const chains = [...new Set(sources.map((source) => source.chain?.join(" > ") ?? source.requiredBy))];
|
|
24569
24696
|
return `required as a peer by ${chains.slice(0, 3).join(", ")}${chains.length > 3 ? ` (+${chains.length - 3} more)` : ""}`;
|
|
24570
24697
|
}
|
|
24571
|
-
function assessDependency({ config, dependency, isSelfOrInternal, isTerminal, raw, refTypes, requiredPeerSources, sections, workspaceDir }) {
|
|
24698
|
+
function assessDependency({ config, dependency, importedPackages, isSelfOrInternal, isTerminal, raw, refTypes, requiredPeerSources, sections, workspaceDir }) {
|
|
24572
24699
|
const dependencyRaw = raw.filter((finding) => finding.dependency === dependency);
|
|
24573
24700
|
const signals = getDependencySignals(workspaceDir, dependency);
|
|
24574
24701
|
if (signals !== void 0) dependencyRaw.push(...signals.findings);
|
|
24575
24702
|
const peerSources = requiredPeerSources.get(dependency);
|
|
24576
|
-
if (peerSources !== void 0 && !isSelfOrInternal(dependency) && !sections.dependencies.has(dependency))
|
|
24577
|
-
dependency
|
|
24578
|
-
|
|
24579
|
-
|
|
24580
|
-
|
|
24581
|
-
|
|
24582
|
-
|
|
24703
|
+
if (peerSources !== void 0 && !isSelfOrInternal(dependency) && !sections.dependencies.has(dependency)) {
|
|
24704
|
+
const isForwarded = config.peerForwarding === "always" || importedPackages === void 0 || importedPackages.has(dependency);
|
|
24705
|
+
dependencyRaw.push(isForwarded ? {
|
|
24706
|
+
dependency,
|
|
24707
|
+
evidence: requiredPeerEvidence(peerSources),
|
|
24708
|
+
file: "(peer-chain)",
|
|
24709
|
+
ruleId: "aei.signal.required-peer"
|
|
24710
|
+
} : {
|
|
24711
|
+
dependency,
|
|
24712
|
+
evidence: `${requiredPeerEvidence(peerSources)} — never imported here; the installer resolves the contract (peerForwarding: when-used)`,
|
|
24713
|
+
file: "(peer-chain)",
|
|
24714
|
+
ruleId: "aei.signal.inherited-peer"
|
|
24715
|
+
});
|
|
24716
|
+
}
|
|
24717
|
+
if (config.treeShaking && sections.sideEffectsFree && signals?.esm === true && hasInstalledVersionMultiplicity(workspaceDir, dependency)) dependencyRaw.push({
|
|
24583
24718
|
dependency,
|
|
24584
|
-
evidence: "sideEffects: false package with ESM dependency — peers improve deduplication",
|
|
24719
|
+
evidence: "sideEffects: false package with ESM dependency installed at multiple versions — peers improve deduplication",
|
|
24585
24720
|
file: "(package)",
|
|
24586
24721
|
ruleId: "aei.modifier.tree-shaking"
|
|
24587
24722
|
});
|
|
@@ -24590,6 +24725,7 @@ function assessDependency({ config, dependency, isSelfOrInternal, isTerminal, ra
|
|
|
24590
24725
|
const resolved = resolveRecommendation(score.recommendation, findings, {
|
|
24591
24726
|
config,
|
|
24592
24727
|
dependency,
|
|
24728
|
+
importedPackages,
|
|
24593
24729
|
isSelfOrInternal,
|
|
24594
24730
|
isTerminal,
|
|
24595
24731
|
raw,
|
|
@@ -24614,6 +24750,22 @@ function assessDependency({ config, dependency, isSelfOrInternal, isTerminal, ra
|
|
|
24614
24750
|
};
|
|
24615
24751
|
}
|
|
24616
24752
|
/**
|
|
24753
|
+
* True when the unlisted dependency's exposure is provided (and
|
|
24754
|
+
* version-managed) by the package's declared sections. Runtime sections can
|
|
24755
|
+
* vouch for anything; devDependencies (e.g. `@types/express`) can only vouch
|
|
24756
|
+
* for purely type-level exposure — and a directly declared `@types/*`
|
|
24757
|
+
* spelling of the dependency itself (e.g. `@types/express-serve-static-core`
|
|
24758
|
+
* for exposure attributed to `express-serve-static-core`) is the most direct
|
|
24759
|
+
* provider of all.
|
|
24760
|
+
*/
|
|
24761
|
+
function isProvidedBySections(dependency, findings, sections, workspaceDir) {
|
|
24762
|
+
if (findings.some((finding) => finding.ruleId === "aei.signal.required-peer")) return false;
|
|
24763
|
+
const aliases = typesAliasesOf(dependency);
|
|
24764
|
+
const targets = [dependency, ...aliases];
|
|
24765
|
+
const isTypeOnly = isTypeOnlyExposure(findings);
|
|
24766
|
+
return isTypeOnly && aliases.some((alias) => sections.dependencies.has(alias) || sections.peerDependencies.has(alias) || sections.devDependencies.has(alias)) || isProvidedByDeclaredDeps(workspaceDir, [...sections.dependencies, ...sections.peerDependencies], targets) || isTypeOnly && isProvidedByDeclaredDeps(workspaceDir, [...sections.devDependencies], targets);
|
|
24767
|
+
}
|
|
24768
|
+
/**
|
|
24617
24769
|
* Applies the override precedence chain from spec section 11 to a scored
|
|
24618
24770
|
* recommendation. Returns undefined when the assessment should be suppressed
|
|
24619
24771
|
* entirely (the `aei.exposure.provided-transitive` reporting gate, off by
|
|
@@ -24622,10 +24774,13 @@ function assessDependency({ config, dependency, isSelfOrInternal, isTerminal, ra
|
|
|
24622
24774
|
function resolveRecommendation(scored, findings, { config, dependency, isSelfOrInternal, isTerminal, refTypes, sections, workspaceDir }) {
|
|
24623
24775
|
const classification = config.classificationFor(dependency) ?? refTypes?.get(dependency);
|
|
24624
24776
|
if (classification !== void 0) return [classification === "peer" ? "peer" : "dependency", "override"];
|
|
24625
|
-
if (isTerminal === true)
|
|
24777
|
+
if (isTerminal === true) {
|
|
24778
|
+
if (sections.isPrivate && currentSectionOf(dependency, sections) === "devDependencies") return void 0;
|
|
24779
|
+
return ["dependency", "terminal"];
|
|
24780
|
+
}
|
|
24626
24781
|
if (isSelfOrInternal(dependency)) return ["dependency", "workspace-internal"];
|
|
24627
24782
|
if (dependency.startsWith("@types/")) return ["dependency", "types-package"];
|
|
24628
|
-
if (
|
|
24783
|
+
if (currentSectionOf(dependency, sections) === "unlisted" && isProvidedBySections(dependency, findings, sections, workspaceDir)) return config.ruleFor("aei.exposure.provided-transitive", dependency)?.enabled === true ? ["review", "provided"] : void 0;
|
|
24629
24784
|
return [scored, "score"];
|
|
24630
24785
|
}
|
|
24631
24786
|
/**
|
|
@@ -24640,6 +24795,7 @@ function analyzeWorkspaceApiExposure({ cache, config, isTerminal, refTypes, work
|
|
|
24640
24795
|
const requiredPeerSources = getRuntimeRootedNonOptionalTransitivePeerSources(workspaceDir, getDependenciesFromPackageJson(PATH.join(workspaceDir, "package.json")), { excludeSatisfiedInChain: true });
|
|
24641
24796
|
const entryPoints = resolveEntryPoints(workspaceDir);
|
|
24642
24797
|
const program = createExposureProgram(workspaceDir, entryPoints, cache);
|
|
24798
|
+
const importedPackages = program === void 0 || config.peerForwarding !== "when-used" ? void 0 : getImportedPackages(program, workspaceDir);
|
|
24643
24799
|
const raw = [];
|
|
24644
24800
|
if (program !== void 0) raw.push(...getExposureFindings({
|
|
24645
24801
|
entryFiles: entryPoints,
|
|
@@ -24658,6 +24814,7 @@ function analyzeWorkspaceApiExposure({ cache, config, isTerminal, refTypes, work
|
|
|
24658
24814
|
])].filter((dependency) => dependency !== workspace.name).toSorted().map((dependency) => assessDependency({
|
|
24659
24815
|
config,
|
|
24660
24816
|
dependency,
|
|
24817
|
+
importedPackages,
|
|
24661
24818
|
isSelfOrInternal,
|
|
24662
24819
|
isTerminal,
|
|
24663
24820
|
raw,
|
|
@@ -29139,6 +29296,15 @@ function resolvePeerDeclaredVersion(context, dep) {
|
|
|
29139
29296
|
function shouldSkipAeiPeerDemotion(context, dep, version) {
|
|
29140
29297
|
return context.isTerminalPackage || context.classifierMode !== "aei" || context.forcePeers.has(dep) || dep.startsWith("@types/") || version.startsWith("workspace:");
|
|
29141
29298
|
}
|
|
29299
|
+
/**
|
|
29300
|
+
* A peer this package never imports is not a placement candidate — demoting
|
|
29301
|
+
* it into `dependencies` would immediately make it an unused dependency. If
|
|
29302
|
+
* it is genuinely unneeded, `dep.peerDependencies.unused` removes it instead.
|
|
29303
|
+
*/
|
|
29304
|
+
function isImportedAnywhere(context, dep) {
|
|
29305
|
+
const { externalAllImports, externalDistImports, externalDistTypeImports } = context.sourceParams;
|
|
29306
|
+
return externalAllImports.includes(dep) || externalDistImports.includes(dep) || externalDistTypeImports.includes(dep);
|
|
29307
|
+
}
|
|
29142
29308
|
function evaluateMisplacedPeer(context, dep, version) {
|
|
29143
29309
|
if (context.forceDeps.has(dep)) return {
|
|
29144
29310
|
alreadyInTarget: context.packageParams.dependencies.includes(dep),
|
|
@@ -29162,6 +29328,7 @@ function evaluateMisplacedPeer(context, dep, version) {
|
|
|
29162
29328
|
version
|
|
29163
29329
|
};
|
|
29164
29330
|
if (shouldSkipAeiPeerDemotion(context, dep, version)) return void 0;
|
|
29331
|
+
if (!isImportedAnywhere(context, dep)) return void 0;
|
|
29165
29332
|
if (context.classifyDependency(dep) !== "dependency") return void 0;
|
|
29166
29333
|
return {
|
|
29167
29334
|
alreadyInTarget: context.packageParams.dependencies.includes(dep),
|
|
@@ -29631,12 +29798,12 @@ const unsatisfiedPeersRule = {
|
|
|
29631
29798
|
severity: "error"
|
|
29632
29799
|
},
|
|
29633
29800
|
evaluate(context) {
|
|
29634
|
-
const findings = findUnsatisfiedPeers(context.workspace, context.packageParams, context.exclude, context.isTerminalPackage, context.forcePeerOptional, context.forceDevs);
|
|
29801
|
+
const findings = findUnsatisfiedPeers(context.workspace, context.packageParams, context.exclude, context.isTerminalPackage, context.forcePeerOptional, context.forceDevs, context.peerForwarding);
|
|
29635
29802
|
for (const finding of findings) {
|
|
29636
29803
|
const requiredBy = finding.sources.map((source) => source.requiredBy).join(", ");
|
|
29637
29804
|
const chain = finding.sources.find((source) => (source.chain && source.chain.length > 0) ?? false)?.chain?.join(" -> ");
|
|
29638
29805
|
const evidence = chain != null && chain.length > 0 ? [`via ${chain}`] : void 0;
|
|
29639
|
-
const message = finding.reason === "version-mismatch" ? `Peer dependency version mismatch ${finding.peer} — installed ${finding.installedVersion ?? "unknown"} does not satisfy ${finding.versionRange} (required by ${requiredBy})` : finding.reason === "under-exposed" ? `Under-exposed peer dependency ${finding.peer} (required by ${requiredBy}) — in devDependencies only; must also be in dependencies or peerDependencies` : finding.hasRuntimeSource ? `Unsatisfied peer dependency ${finding.peer} (required by ${requiredBy}) — must be in dependencies or peerDependencies` : `Unsatisfied peer dependency ${finding.peer} (required by devDependency ${requiredBy}) — must be in dependencies, devDependencies, or peerDependencies`;
|
|
29806
|
+
const message = finding.reason === "version-mismatch" ? `Peer dependency version mismatch ${finding.peer} — installed ${finding.installedVersion ?? "unknown"} does not satisfy ${finding.versionRange} (required by ${requiredBy})` : finding.reason === "under-exposed" ? `Under-exposed peer dependency ${finding.peer} (required by ${requiredBy}) — in devDependencies only; must also be in dependencies or peerDependencies` : finding.hasRuntimeSource ? `Unsatisfied peer dependency ${finding.peer} (required by ${requiredBy}) — must be in dependencies or peerDependencies` : finding.inherited === true ? `Unsatisfied peer dependency ${finding.peer} (required by ${requiredBy}) — never imported here (peerForwarding: when-used); needed in devDependencies for local resolution` : `Unsatisfied peer dependency ${finding.peer} (required by devDependency ${requiredBy}) — must be in dependencies, devDependencies, or peerDependencies`;
|
|
29640
29807
|
context.report({
|
|
29641
29808
|
data: { finding },
|
|
29642
29809
|
dependency: finding.peer,
|
|
@@ -30016,8 +30183,16 @@ function buildWorkspaceContext(workspace, options = {}) {
|
|
|
30016
30183
|
const packageMetaStarted = performance.now();
|
|
30017
30184
|
const packageJsonPath = `${workspace.location}/package.json`;
|
|
30018
30185
|
const packageParams = getDependenciesFromPackageJson(packageJsonPath);
|
|
30186
|
+
const peerForwarding = options.classifier === "aei" && options.apiExposureConfig?.peerForwarding === "when-used" ? {
|
|
30187
|
+
importedModules: /* @__PURE__ */ new Set([
|
|
30188
|
+
...sourceParams.externalAllImports,
|
|
30189
|
+
...sourceParams.externalDistImports,
|
|
30190
|
+
...sourceParams.externalDistTypeImports
|
|
30191
|
+
]),
|
|
30192
|
+
mode: "when-used"
|
|
30193
|
+
} : void 0;
|
|
30019
30194
|
const requiredTransitivePeers = getRequiredNonOptionalTransitivePeers(workspace.location, packageParams);
|
|
30020
|
-
const runtimeRootedRequired = getRuntimeRootedNonOptionalTransitivePeers(workspace.location, packageParams);
|
|
30195
|
+
const runtimeRootedRequired = new Set([...getRuntimeRootedNonOptionalTransitivePeers(workspace.location, packageParams)].filter((peer) => isPeerForwarded(peerForwarding, peer)));
|
|
30021
30196
|
const packageClassification = classifyDeplintPackage(workspace.location, terminalOverride);
|
|
30022
30197
|
if (phases !== void 0) phases.packageMetaMs = performance.now() - packageMetaStarted;
|
|
30023
30198
|
return {
|
|
@@ -30037,6 +30212,7 @@ function buildWorkspaceContext(workspace, options = {}) {
|
|
|
30037
30212
|
packageKind: packageClassification.kind,
|
|
30038
30213
|
packageJsonPath,
|
|
30039
30214
|
packageParams,
|
|
30215
|
+
peerForwarding,
|
|
30040
30216
|
peerRangeBound: options.peerRangeBound,
|
|
30041
30217
|
peerRangeForm: options.peerRangeForm ?? "shorthand",
|
|
30042
30218
|
sourceParams,
|