@ariestools/toolchain 8.7.6 → 8.7.7
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/importedPackages.d.ts +19 -5
- package/dist/actions/api-exposure/analyzer/importedPackages.d.ts.map +1 -1
- package/dist/actions/api-exposure/rules.d.ts.map +1 -1
- package/dist/actions/deplint/checkPackage/getUnsatisfiedPeerDependencies.d.ts +16 -6
- package/dist/actions/deplint/checkPackage/getUnsatisfiedPeerDependencies.d.ts.map +1 -1
- package/dist/actions/deplint/getInternalSurfaceVouchedPeers.d.ts +13 -0
- package/dist/actions/deplint/getInternalSurfaceVouchedPeers.d.ts.map +1 -0
- package/dist/actions/deplint/snapshot.d.ts.map +1 -1
- package/dist/actions/package/compile/ApiExposureConfig.d.ts +16 -4
- package/dist/actions/package/compile/ApiExposureConfig.d.ts.map +1 -1
- package/dist/bin/package/build.mjs +4 -2
- package/dist/bin/package/build.mjs.map +1 -1
- package/dist/bin/package/compile.mjs +4 -2
- package/dist/bin/package/compile.mjs.map +1 -1
- package/dist/bin/package/recompile.mjs +4 -2
- package/dist/bin/package/recompile.mjs.map +1 -1
- package/dist/bin/package/sync-layout.mjs +4 -2
- package/dist/bin/package/sync-layout.mjs.map +1 -1
- package/dist/bin/xy.mjs +284 -114
- package/dist/bin/xy.mjs.map +1 -1
- package/package.json +4 -4
package/dist/bin/xy.mjs
CHANGED
|
@@ -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
|
|
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-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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)
|
|
24662
|
-
*
|
|
24663
|
-
* `peerForwarding: 'when-used'`
|
|
24664
|
-
*
|
|
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
|
|
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,
|
|
24789
|
+
collectFileImports(sourceFile, seen);
|
|
24672
24790
|
}
|
|
24673
|
-
return
|
|
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
|
-
|
|
24845
|
-
|
|
24846
|
-
|
|
24847
|
-
|
|
24848
|
-
|
|
24849
|
-
|
|
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
|
|
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;
|
|
@@ -30247,6 +30341,80 @@ async function loadDeplintRules(config) {
|
|
|
30247
30341
|
return normalizeDeplintRules(plugins.flatMap((plugin) => plugin.rules), config, new Set(builtInDeplintPlugin.rules.map((rule) => rule.id)));
|
|
30248
30342
|
}
|
|
30249
30343
|
//#endregion
|
|
30344
|
+
//#region src/actions/deplint/getInternalSurfaceVouchedPeers.ts
|
|
30345
|
+
/** Bound on recursion through nested workspace-internal surfaces. */
|
|
30346
|
+
const MAX_INTERNAL_SURFACE_DEPTH = 3;
|
|
30347
|
+
const surfaceImportsCache = /* @__PURE__ */ new Map();
|
|
30348
|
+
function resolveInternalSurface(baseDir, name) {
|
|
30349
|
+
const manifestPath = findDepPackageJson(baseDir, name);
|
|
30350
|
+
if (manifestPath === void 0) return void 0;
|
|
30351
|
+
try {
|
|
30352
|
+
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
|
30353
|
+
let dir = PATH.dirname(manifestPath);
|
|
30354
|
+
try {
|
|
30355
|
+
dir = fs.realpathSync(dir);
|
|
30356
|
+
} catch {}
|
|
30357
|
+
return {
|
|
30358
|
+
dir,
|
|
30359
|
+
peerDependencies: Object.keys(manifest.peerDependencies ?? {})
|
|
30360
|
+
};
|
|
30361
|
+
} catch {
|
|
30362
|
+
return;
|
|
30363
|
+
}
|
|
30364
|
+
}
|
|
30365
|
+
/**
|
|
30366
|
+
* External package names referenced by a package's shipped surface: import
|
|
30367
|
+
* specifiers in its dist runtime and emitted d.ts. Falls back to src when
|
|
30368
|
+
* no dist exists (unbuilt workspace), mirroring deplint's own fallback.
|
|
30369
|
+
*/
|
|
30370
|
+
function getSurfaceImports(dir) {
|
|
30371
|
+
const cached = surfaceImportsCache.get(dir);
|
|
30372
|
+
if (cached !== void 0) return cached;
|
|
30373
|
+
let files = findFilesByGlob(dir, "dist/**/*.{js,mjs,cjs,ts,mts,cts}", ["**/node_modules/**"]);
|
|
30374
|
+
if (files.length === 0) files = findFilesByGlob(dir, "src/**/*.{ts,tsx,mts,cts}", ["**/node_modules/**"]);
|
|
30375
|
+
const imports = /* @__PURE__ */ new Set();
|
|
30376
|
+
for (const file of files) {
|
|
30377
|
+
const [valueImports, typeImports] = getImportsFromFile(file, {}, {});
|
|
30378
|
+
for (const name of valueImports) imports.add(name);
|
|
30379
|
+
for (const name of typeImports) imports.add(name);
|
|
30380
|
+
}
|
|
30381
|
+
surfaceImportsCache.set(dir, imports);
|
|
30382
|
+
return imports;
|
|
30383
|
+
}
|
|
30384
|
+
/**
|
|
30385
|
+
* Peers vouched for by workspace-internal packages whose surface this
|
|
30386
|
+
* package ships. A pure re-export barrel never names the peers it
|
|
30387
|
+
* re-exposes in its own imports or emitted d.ts, so scan-based forwarding
|
|
30388
|
+
* evidence (`PeerForwardingPolicy.importedModules`) cannot see them. The
|
|
30389
|
+
* re-exported internal package's own shipped surface is the next-best
|
|
30390
|
+
* authority: any peer it declares AND references from its dist runtime or
|
|
30391
|
+
* emitted d.ts flows through every package that ships its surface.
|
|
30392
|
+
* Recurses through nested internal surfaces (a barrel re-exporting a
|
|
30393
|
+
* facade re-exporting core), depth-limited.
|
|
30394
|
+
*/
|
|
30395
|
+
function getInternalSurfaceVouchedPeers(location, shippedImports, workspaceNames) {
|
|
30396
|
+
const vouched = /* @__PURE__ */ new Set();
|
|
30397
|
+
const visited = /* @__PURE__ */ new Set();
|
|
30398
|
+
const visitSurface = ({ baseDir, name }) => {
|
|
30399
|
+
if (visited.has(name)) return [];
|
|
30400
|
+
visited.add(name);
|
|
30401
|
+
const surface = resolveInternalSurface(baseDir, name);
|
|
30402
|
+
if (surface === void 0) return [];
|
|
30403
|
+
const surfaceImports = getSurfaceImports(surface.dir);
|
|
30404
|
+
for (const peer of surface.peerDependencies) if (surfaceImports.has(peer)) vouched.add(peer);
|
|
30405
|
+
return [...surfaceImports].filter((imported) => workspaceNames.has(imported)).map((imported) => ({
|
|
30406
|
+
baseDir: surface.dir,
|
|
30407
|
+
name: imported
|
|
30408
|
+
}));
|
|
30409
|
+
};
|
|
30410
|
+
let frontier = [...new Set(shippedImports)].filter((name) => workspaceNames.has(name)).map((name) => ({
|
|
30411
|
+
baseDir: location,
|
|
30412
|
+
name
|
|
30413
|
+
}));
|
|
30414
|
+
for (let depth = 0; depth < MAX_INTERNAL_SURFACE_DEPTH && frontier.length > 0; depth++) frontier = frontier.flatMap((ref) => visitSurface(ref));
|
|
30415
|
+
return vouched;
|
|
30416
|
+
}
|
|
30417
|
+
//#endregion
|
|
30250
30418
|
//#region src/actions/deplint/snapshot.ts
|
|
30251
30419
|
function buildUnusedDependencyExclude(options, requiredTransitivePeers) {
|
|
30252
30420
|
return /* @__PURE__ */ new Set([
|
|
@@ -30323,14 +30491,16 @@ function buildWorkspaceContext(workspace, options = {}) {
|
|
|
30323
30491
|
const packageMetaStarted = performance.now();
|
|
30324
30492
|
const packageJsonPath = `${workspace.location}/package.json`;
|
|
30325
30493
|
const packageParams = getDependenciesFromPackageJson(packageJsonPath);
|
|
30326
|
-
const
|
|
30327
|
-
|
|
30494
|
+
const forwardingMode = options.classifier === "aei" ? options.apiExposureConfig?.peerForwarding ?? "always" : "always";
|
|
30495
|
+
const peerForwarding = forwardingMode === "always" ? void 0 : {
|
|
30496
|
+
importedModules: forwardingMode === "when-exposed" ? /* @__PURE__ */ new Set([...sourceParams.externalDistImports, ...sourceParams.externalDistTypeImports]) : /* @__PURE__ */ new Set([
|
|
30328
30497
|
...sourceParams.externalAllImports,
|
|
30329
30498
|
...sourceParams.externalDistImports,
|
|
30330
30499
|
...sourceParams.externalDistTypeImports
|
|
30331
30500
|
]),
|
|
30332
|
-
mode:
|
|
30333
|
-
|
|
30501
|
+
mode: forwardingMode,
|
|
30502
|
+
vouchedPeers: options.workspaceNames === void 0 ? void 0 : getInternalSurfaceVouchedPeers(workspace.location, [...sourceParams.externalDistImports, ...sourceParams.externalDistTypeImports], options.workspaceNames)
|
|
30503
|
+
};
|
|
30334
30504
|
const requiredTransitivePeers = getRequiredNonOptionalTransitivePeers(workspace.location, packageParams);
|
|
30335
30505
|
const runtimeRootedRequired = new Set([...getRuntimeRootedNonOptionalTransitivePeers(workspace.location, packageParams)].filter((peer) => isPeerForwarded(peerForwarding, peer)));
|
|
30336
30506
|
const packageClassification = classifyDeplintPackage(workspace.location, terminalOverride);
|