@openpkg-ts/sdk 0.53.0 → 0.54.0
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/README.md +3 -3
- package/dist/index.d.ts +4 -51
- package/dist/index.js +185 -562
- package/package.json +1 -5
package/README.md
CHANGED
|
@@ -89,11 +89,11 @@ const { spec, diagnostics, verification } = await extractSpec({
|
|
|
89
89
|
maxTypeDepth: 4,
|
|
90
90
|
only: ['use*'], // filter by pattern
|
|
91
91
|
ignore: ['*Internal'], // exclude by pattern
|
|
92
|
-
followExternal: ['@ai-sdk/*'], // or true
|
|
92
|
+
followExternal: ['@ai-sdk/*'], // or true
|
|
93
93
|
});
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
Specs record `generation.entryPoint` and `generation.entryPointSource` (`types` / `exports` / `fallback` / `explicit` / `llm`).
|
|
97
97
|
|
|
98
98
|
### resolveTarget
|
|
99
99
|
|
|
@@ -111,7 +111,7 @@ if (resolved.kind === 'ok') {
|
|
|
111
111
|
}
|
|
112
112
|
```
|
|
113
113
|
|
|
114
|
-
|
|
114
|
+
GitHub URLs clone via `gh` if present, else `git clone --depth 1`.
|
|
115
115
|
|
|
116
116
|
### diffSpecs
|
|
117
117
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,42 +1,5 @@
|
|
|
1
1
|
import { BreakingSeverity, CategorizedBreaking, calculateNextVersion, categorizeBreakingChanges, diffSpec, diffSpec as diffSpec2, MemberChangeInfo, recommendSemverBump, SemverBump, SemverRecommendation, SpecDiff } from "@openpkg-ts/spec";
|
|
2
2
|
import { EntryPointDetectionMethod, OpenPkg } from "@openpkg-ts/spec";
|
|
3
|
-
declare const JEV_MODEL = "typesafe-ai/jev";
|
|
4
|
-
declare const JEV_CONFIDENCE = .5;
|
|
5
|
-
type ChoiceQuestion = {
|
|
6
|
-
type: "choice";
|
|
7
|
-
instructions: string;
|
|
8
|
-
criteria: Record<string, string>;
|
|
9
|
-
};
|
|
10
|
-
type ScoreQuestion = {
|
|
11
|
-
type: "score";
|
|
12
|
-
instructions: string;
|
|
13
|
-
criteria: string[];
|
|
14
|
-
};
|
|
15
|
-
type EvaluateQuestion = ChoiceQuestion | ScoreQuestion;
|
|
16
|
-
type EvaluateRequest = {
|
|
17
|
-
model: string;
|
|
18
|
-
state: unknown;
|
|
19
|
-
questions: Record<string, EvaluateQuestion>;
|
|
20
|
-
providerOptions?: {
|
|
21
|
-
gateway?: {
|
|
22
|
-
zeroDataRetention?: boolean;
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
type EvaluateAnswer = {
|
|
27
|
-
choice?: string;
|
|
28
|
-
score?: number;
|
|
29
|
-
probabilities?: Record<string, number>;
|
|
30
|
-
};
|
|
31
|
-
type EvaluateResult = {
|
|
32
|
-
answers: Record<string, EvaluateAnswer>;
|
|
33
|
-
providerMetadata?: {
|
|
34
|
-
typesafe?: {
|
|
35
|
-
confidence?: Record<string, number>;
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
type EvaluateFn = (request: EvaluateRequest) => Promise<EvaluateResult>;
|
|
40
3
|
/** Configuration for resolving external package re-exports */
|
|
41
4
|
interface ExternalsConfig {
|
|
42
5
|
/** Package patterns to resolve (globs supported, e.g., "@myorg/*") */
|
|
@@ -84,9 +47,7 @@ interface ExtractOptions {
|
|
|
84
47
|
* - `false` → disable the reachability-expansion pass entirely
|
|
85
48
|
* - default → workspace siblings only; everything else stubbed
|
|
86
49
|
*/
|
|
87
|
-
followExternal?: boolean | string[]
|
|
88
|
-
evaluate?: EvaluateFn;
|
|
89
|
-
decisions?: "heuristic" | "jev";
|
|
50
|
+
followExternal?: boolean | string[];
|
|
90
51
|
/** Callback when properties are truncated */
|
|
91
52
|
onTruncation?: (typeName: string, actual: number, limit: number) => void;
|
|
92
53
|
}
|
|
@@ -189,13 +150,11 @@ interface OpenpkgConfig {
|
|
|
189
150
|
* them as opaque stubs. `true` follows every dependency; a string[] follows
|
|
190
151
|
* only the named packages (by declaring package name). Default: stub.
|
|
191
152
|
*/
|
|
192
|
-
followExternal?: boolean | string[]
|
|
153
|
+
followExternal?: boolean | string[];
|
|
193
154
|
/** Only extract these exports (supports * wildcards). */
|
|
194
155
|
only?: string[];
|
|
195
156
|
/** Ignore these exports (supports * wildcards). */
|
|
196
157
|
ignore?: string[];
|
|
197
|
-
/** Use Jev for package/entry routing. Requires AI_GATEWAY_API_KEY. */
|
|
198
|
-
decisions?: "heuristic" | "jev";
|
|
199
158
|
}
|
|
200
159
|
/** Default config filename */
|
|
201
160
|
declare const CONFIG_FILENAME = "openpkg.config.json";
|
|
@@ -1077,8 +1036,6 @@ type ResolveTargetOptions = {
|
|
|
1077
1036
|
input?: string;
|
|
1078
1037
|
intent?: string;
|
|
1079
1038
|
cwd?: string;
|
|
1080
|
-
decisions?: "heuristic" | "jev";
|
|
1081
|
-
evaluate?: EvaluateFn;
|
|
1082
1039
|
clone?: CloneFn;
|
|
1083
1040
|
};
|
|
1084
1041
|
type ResolveOk = {
|
|
@@ -1106,11 +1063,7 @@ type ResolveExplicit = {
|
|
|
1106
1063
|
entryFile: string;
|
|
1107
1064
|
entryPointSource: "explicit";
|
|
1108
1065
|
};
|
|
1109
|
-
type
|
|
1110
|
-
kind: "unavailable";
|
|
1111
|
-
reason: string;
|
|
1112
|
-
};
|
|
1113
|
-
type ResolveTargetResult = (ResolveOk | ResolveAmbiguous | ResolveNeedsBuild | ResolveEmpty | ResolveExplicit | ResolveUnavailable) & {
|
|
1066
|
+
type ResolveTargetResult = (ResolveOk | ResolveAmbiguous | ResolveNeedsBuild | ResolveEmpty | ResolveExplicit) & {
|
|
1114
1067
|
/** Present when this resolution owns a temp clone. Call after extraction. */
|
|
1115
1068
|
cleanup?: () => void;
|
|
1116
1069
|
};
|
|
@@ -2030,4 +1983,4 @@ declare function findDiscriminatorProperty(unionTypes: ts16.Type[], checker: ts1
|
|
|
2030
1983
|
import ts17 from "typescript";
|
|
2031
1984
|
declare function isExported(node: ts17.Node): boolean;
|
|
2032
1985
|
declare function getNodeName(node: ts17.Node): string | undefined;
|
|
2033
|
-
export { zodAdapter, writtenTypeText, withDescription2 as withDescription, withDeprecated, validateSpec, valibotAdapter, typeboxAdapter, toToolSchema, toSearchIndexJSON, toSearchIndex2 as toSearchIndex, toPagefindRecords2 as toPagefindRecords, toNavigation2 as toNavigation, toMarkdown2 as toMarkdown, toJsonSchema, toJSONString, toJSON2 as toJSON, toHTML2 as toHTML, toFumadocsMetaJSON, toDocusaurusSidebarJS, toAlgoliaRecords2 as toAlgoliaRecords, stripUndefinedFromType, stripTsExtensions, sortByName, shouldEmitAliasTypeText, serializeVariable, serializeTypeAlias, serializeInterface, serializeFunctionExport, serializeEnum, serializeClass, scrubImportQualifiers, schemasAreEqual, schemaIsAny, resolveTypeRef, resolveTarget, resolveExportTarget, resolveCompiledPath, renderTypeText, registerReferencedTypes, registerAdapter, recommendSemverBump, query, pickEntry, parseGithubRepo, normalizeType, normalizeSchema, normalizeMembers, normalizeExport, mergeConfig, loadSpec, loadConfig, listExports, isTypeReference, isTypeOnlyExport, isSymbolDeprecated, isStandardJSONSchema, isSchemaType, isRemoteInput, isReadonlyPropertySymbol, isPureRefSchema, isProperty, isPrimitiveName, isPathLikeInput, isMethod, isExported, isEntryFilePath, isBuiltinSymbol, isBuiltinGeneric, isAnonymous, groupByVisibility, getValidationErrors, getTypeOrigin, getSourceLocation, getProperties, getParamDescription, getNonNullableType, getNodeName, getMethods, getMemberBadges, getJSDocComment, getExportKind, getExport2 as getExport, getAvailableVersions, toMarkdown2 as generateDocs, formatTypeParameters, formatSchema, formatReturnType, formatParameters, formatMappedType, formatConditionalType, formatBadges, findWorkspaceRoot, findDiscriminatorProperty, findAdapter, filterSpec, extractTypeParameters, extractStandardSchemasFromTs, extractStandardSchemasFromProject, extractStandardSchemas, extractSpec, extractSchemaType, extractParameters, extract, exportToMarkdown, exportToJsonSchema, ensureNonEmptySchema, diffSpec2 as diffSpecs, diffSpec, detectTsRuntime, deduplicateSchemas, decoratePropertySchema, declaredTypeNode, createProgram, createDocs, cloneRemote, categorizeBreakingChanges, catalogPackages, calculateNextVersion, bundleRefs, buildSignatureString, buildSchema, buildObjectSchema, buildFunctionSchema, assertSpec, asStandardSchema, arktypeAdapter, TypeRegistry, TypeReference2 as TypeReference, TsRuntime, ToolSchemaResult, ToolSchemaProvider, ToToolSchemaOptions, ToJsonSchemaOptions, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, StandardJSONSchemaTarget, StandardJSONSchemaOptions, SpecMappedType, SpecError, SpecDiff, SpecConditionalType, SkippedExportDetail, SimplifiedSpec, SimplifiedSignature, SimplifiedReturn, SimplifiedParameter, SimplifiedMember, SimplifiedExport, SimplifiedExample, SerializerContext, SemverRecommendation, SemverBump, SearchRecord, SearchOptions, SearchIndex, SchemaVersion, SchemaExtractionResult, SchemaAdapter, STRING_PROTOTYPE_METHODS,
|
|
1986
|
+
export { zodAdapter, writtenTypeText, withDescription2 as withDescription, withDeprecated, validateSpec, valibotAdapter, typeboxAdapter, toToolSchema, toSearchIndexJSON, toSearchIndex2 as toSearchIndex, toPagefindRecords2 as toPagefindRecords, toNavigation2 as toNavigation, toMarkdown2 as toMarkdown, toJsonSchema, toJSONString, toJSON2 as toJSON, toHTML2 as toHTML, toFumadocsMetaJSON, toDocusaurusSidebarJS, toAlgoliaRecords2 as toAlgoliaRecords, stripUndefinedFromType, stripTsExtensions, sortByName, shouldEmitAliasTypeText, serializeVariable, serializeTypeAlias, serializeInterface, serializeFunctionExport, serializeEnum, serializeClass, scrubImportQualifiers, schemasAreEqual, schemaIsAny, resolveTypeRef, resolveTarget, resolveExportTarget, resolveCompiledPath, renderTypeText, registerReferencedTypes, registerAdapter, recommendSemverBump, query, pickEntry, parseGithubRepo, normalizeType, normalizeSchema, normalizeMembers, normalizeExport, mergeConfig, loadSpec, loadConfig, listExports, isTypeReference, isTypeOnlyExport, isSymbolDeprecated, isStandardJSONSchema, isSchemaType, isRemoteInput, isReadonlyPropertySymbol, isPureRefSchema, isProperty, isPrimitiveName, isPathLikeInput, isMethod, isExported, isEntryFilePath, isBuiltinSymbol, isBuiltinGeneric, isAnonymous, groupByVisibility, getValidationErrors, getTypeOrigin, getSourceLocation, getProperties, getParamDescription, getNonNullableType, getNodeName, getMethods, getMemberBadges, getJSDocComment, getExportKind, getExport2 as getExport, getAvailableVersions, toMarkdown2 as generateDocs, formatTypeParameters, formatSchema, formatReturnType, formatParameters, formatMappedType, formatConditionalType, formatBadges, findWorkspaceRoot, findDiscriminatorProperty, findAdapter, filterSpec, extractTypeParameters, extractStandardSchemasFromTs, extractStandardSchemasFromProject, extractStandardSchemas, extractSpec, extractSchemaType, extractParameters, extract, exportToMarkdown, exportToJsonSchema, ensureNonEmptySchema, diffSpec2 as diffSpecs, diffSpec, detectTsRuntime, deduplicateSchemas, decoratePropertySchema, declaredTypeNode, createProgram, createDocs, cloneRemote, categorizeBreakingChanges, catalogPackages, calculateNextVersion, bundleRefs, buildSignatureString, buildSchema, buildObjectSchema, buildFunctionSchema, assertSpec, asStandardSchema, arktypeAdapter, TypeRegistry, TypeReference2 as TypeReference, TsRuntime, ToolSchemaResult, ToolSchemaProvider, ToToolSchemaOptions, ToJsonSchemaOptions, StandardSchemaExtractionResult, StandardSchemaExtractionOutput, StandardJSONSchemaV1, StandardJSONSchemaTarget, StandardJSONSchemaOptions, SpecMappedType, SpecError, SpecDiff, SpecConditionalType, SkippedExportDetail, SimplifiedSpec, SimplifiedSignature, SimplifiedReturn, SimplifiedParameter, SimplifiedMember, SimplifiedExport, SimplifiedExample, SerializerContext, SemverRecommendation, SemverBump, SearchRecord, SearchOptions, SearchIndex, SchemaVersion, SchemaExtractionResult, SchemaAdapter, STRING_PROTOTYPE_METHODS, ResolveTargetResult, ResolveTargetOptions, ResolveOk, ResolveNeedsBuild, ResolveExplicit, ResolveEmpty, ResolveAmbiguous, QueryBuilder, ProjectExtractionOutput, ProjectExtractionInfo, ProgramResult, ProgramOptions, PagefindRecord, PackageRecord, PRIMITIVES, OpenpkgConfig, NormalizeOptions, NavOptions, NavItem, NavGroup, NavFormat, NUMBER_PROTOTYPE_METHODS, MemberChangeInfo, MarkdownOptions, LoadOptions, ListExportsResult, ListExportsOptions, LATEST_VERSION, JsonSchemaDocument, JSONSchema, JSONOptions, HTMLOptions, GroupBy, GetExportResult, GetExportOptions, GenericNav, FumadocsMetaItem, FumadocsMeta, FormatSchemaOptions, ForgottenExport, FilterResult, FilterCriteria, ExtractionWarningCode, ExtractionWarning, ExtractStandardSchemasOptions, ExtractResult, ExtractOptions, ExtractFromProjectOptions, ExternalsConfig, ExportVerification, ExportTracker, ExportMarkdownOptions, ExportItem, DocusaurusSidebarItem, DocusaurusSidebar, DocsInstance, Diagnostic, CloneFn, CategorizedBreaking, CacheManagerOptions, CacheManager, CONFIG_FILENAME, BundleResult, BundleOptions, BuiltinSchema, BreakingSeverity, BUILTIN_TYPE_SCHEMAS, AsStandardSchemaOptions, AlgoliaRecord, ARRAY_PROTOTYPE_METHODS };
|
package/dist/index.js
CHANGED
|
@@ -78,70 +78,9 @@ function mergeConfig(fileConfig, cliOptions) {
|
|
|
78
78
|
...hasExternals ? { externals } : {},
|
|
79
79
|
followExternal: cliOptions.followExternal ?? fileConfig.followExternal,
|
|
80
80
|
only: cliOptions.only ?? fileConfig.only,
|
|
81
|
-
ignore: cliOptions.ignore ?? fileConfig.ignore
|
|
82
|
-
decisions: cliOptions.decisions ?? fileConfig.decisions
|
|
81
|
+
ignore: cliOptions.ignore ?? fileConfig.ignore
|
|
83
82
|
};
|
|
84
83
|
}
|
|
85
|
-
// src/core/decisions.ts
|
|
86
|
-
var JEV_MODEL = "typesafe-ai/jev";
|
|
87
|
-
var JEV_CONFIDENCE = 0.5;
|
|
88
|
-
var MAX_JEV_QUESTIONS = 50;
|
|
89
|
-
async function loadEvaluate() {
|
|
90
|
-
try {
|
|
91
|
-
const specifier = "ai";
|
|
92
|
-
const mod = await import(specifier);
|
|
93
|
-
if (typeof mod.experimental_evaluate !== "function") {
|
|
94
|
-
throw new Error("ai.experimental_evaluate is not a function");
|
|
95
|
-
}
|
|
96
|
-
return (request) => mod.experimental_evaluate({
|
|
97
|
-
...request,
|
|
98
|
-
providerOptions: {
|
|
99
|
-
gateway: { zeroDataRetention: true },
|
|
100
|
-
...request.providerOptions
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
} catch (err) {
|
|
104
|
-
const msg = err instanceof Error ? err.message : String(err);
|
|
105
|
-
throw new Error(`--jev requires the ai package (AI SDK ≥7.0.105): bun add ai
|
|
106
|
-
${msg}`);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
function namedConfidence(result, id) {
|
|
110
|
-
const named = result.providerMetadata?.typesafe?.confidence?.[id];
|
|
111
|
-
return typeof named === "number" ? named : undefined;
|
|
112
|
-
}
|
|
113
|
-
function choiceConfidence(result, id, choice) {
|
|
114
|
-
const named = namedConfidence(result, id);
|
|
115
|
-
if (named !== undefined)
|
|
116
|
-
return named;
|
|
117
|
-
const p = result.answers[id]?.probabilities?.[choice];
|
|
118
|
-
return typeof p === "number" ? p : 0;
|
|
119
|
-
}
|
|
120
|
-
async function jevEvaluate(evaluate, state, questions) {
|
|
121
|
-
return evaluate({
|
|
122
|
-
model: JEV_MODEL,
|
|
123
|
-
state: JSON.parse(JSON.stringify(state)),
|
|
124
|
-
questions,
|
|
125
|
-
providerOptions: { gateway: { zeroDataRetention: true } }
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
async function jevChoice(args) {
|
|
129
|
-
const keys = Object.keys(args.criteria);
|
|
130
|
-
if (keys.length < 2)
|
|
131
|
-
return null;
|
|
132
|
-
const id = args.id ?? "choice";
|
|
133
|
-
const result = await jevEvaluate(args.evaluate, args.state, {
|
|
134
|
-
[id]: {
|
|
135
|
-
type: "choice",
|
|
136
|
-
instructions: args.instructions,
|
|
137
|
-
criteria: args.criteria
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
const choice = result.answers[id]?.choice;
|
|
141
|
-
if (!choice || !(choice in args.criteria))
|
|
142
|
-
return null;
|
|
143
|
-
return { choice, confidence: choiceConfidence(result, id, choice) };
|
|
144
|
-
}
|
|
145
84
|
// src/core/loader.ts
|
|
146
85
|
import * as fs2 from "node:fs";
|
|
147
86
|
import { validateSpec } from "@openpkg-ts/spec";
|
|
@@ -1612,10 +1551,6 @@ function pickEntry(pkgDir) {
|
|
|
1612
1551
|
const best = [...cands].sort((a, b) => scoreCandidate(b) - scoreCandidate(a))[0];
|
|
1613
1552
|
return { entryFile: best.abs, entryPointSource: methodFor(best) };
|
|
1614
1553
|
}
|
|
1615
|
-
function listEntryCandidates(pkgDir) {
|
|
1616
|
-
const pkg = readJson(path2.join(pkgDir, "package.json")) ?? {};
|
|
1617
|
-
return collectCandidates(pkgDir, pkg);
|
|
1618
|
-
}
|
|
1619
1554
|
function isIgnoredPath(dir) {
|
|
1620
1555
|
const norm = dir.split(path2.sep).join("/");
|
|
1621
1556
|
return /\/(examples|fixtures|__tests__|test-fixtures)(\/|$)/.test(norm);
|
|
@@ -1666,76 +1601,9 @@ function buildCommand(pkg) {
|
|
|
1666
1601
|
return "bun run build";
|
|
1667
1602
|
return;
|
|
1668
1603
|
}
|
|
1669
|
-
function
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
} catch {
|
|
1673
|
-
return "";
|
|
1674
|
-
}
|
|
1675
|
-
}
|
|
1676
|
-
async function jevPickPackage(candidates, ctx) {
|
|
1677
|
-
if (!ctx.evaluate || candidates.length < 2)
|
|
1678
|
-
return null;
|
|
1679
|
-
const criteria = {};
|
|
1680
|
-
const byId = new Map;
|
|
1681
|
-
for (const [i, pkg] of candidates.entries()) {
|
|
1682
|
-
const id = `p${i}`;
|
|
1683
|
-
byId.set(id, pkg);
|
|
1684
|
-
criteria[id] = `${pkg.name} — ${pkg.description ?? pkg.dir}${pkg.hasSrc ? " (src)" : ""}`;
|
|
1685
|
-
}
|
|
1686
|
-
const picked = await jevChoice({
|
|
1687
|
-
evaluate: ctx.evaluate,
|
|
1688
|
-
instructions: "Which package is the public TypeScript SDK to extract? Prefer the named product, not examples, wasm glue, or private packages.",
|
|
1689
|
-
criteria,
|
|
1690
|
-
state: {
|
|
1691
|
-
intent: ctx.intent ?? null,
|
|
1692
|
-
catalog: candidates.map((p, i) => ({
|
|
1693
|
-
id: `p${i}`,
|
|
1694
|
-
name: p.name,
|
|
1695
|
-
description: p.description ?? null,
|
|
1696
|
-
hasSrc: p.hasSrc,
|
|
1697
|
-
hasDist: p.hasDist,
|
|
1698
|
-
types: p.types ?? p.typings ?? null,
|
|
1699
|
-
private: p.private
|
|
1700
|
-
}))
|
|
1701
|
-
},
|
|
1702
|
-
id: "package"
|
|
1703
|
-
});
|
|
1704
|
-
if (!picked || picked.confidence < JEV_CONFIDENCE)
|
|
1705
|
-
return null;
|
|
1706
|
-
return byId.get(picked.choice) ?? null;
|
|
1707
|
-
}
|
|
1708
|
-
async function jevPickEntry(cands, ctx) {
|
|
1709
|
-
if (!ctx.evaluate || cands.length < 2)
|
|
1710
|
-
return null;
|
|
1711
|
-
const criteria = {};
|
|
1712
|
-
const byId = new Map;
|
|
1713
|
-
for (const [i, c] of cands.entries()) {
|
|
1714
|
-
const id = `c${i}`;
|
|
1715
|
-
byId.set(id, c);
|
|
1716
|
-
criteria[id] = `${c.rel} (${c.source})`;
|
|
1717
|
-
}
|
|
1718
|
-
const picked = await jevChoice({
|
|
1719
|
-
evaluate: ctx.evaluate,
|
|
1720
|
-
instructions: "Which file is the best OpenPkg entry point? Prefer TypeScript source over .d.ts/.js. Prefer the package root public API.",
|
|
1721
|
-
criteria,
|
|
1722
|
-
state: {
|
|
1723
|
-
candidates: cands.map((c, i) => ({
|
|
1724
|
-
id: `c${i}`,
|
|
1725
|
-
path: c.rel,
|
|
1726
|
-
source: c.source,
|
|
1727
|
-
head: head(c.abs)
|
|
1728
|
-
}))
|
|
1729
|
-
},
|
|
1730
|
-
id: "entry"
|
|
1731
|
-
});
|
|
1732
|
-
if (!picked || picked.confidence < JEV_CONFIDENCE)
|
|
1733
|
-
return null;
|
|
1734
|
-
return byId.get(picked.choice) ?? null;
|
|
1735
|
-
}
|
|
1736
|
-
async function finishPackage(pkg, ctx) {
|
|
1737
|
-
const cands = listEntryCandidates(pkg.dir);
|
|
1738
|
-
if (!cands.length) {
|
|
1604
|
+
function finishPackage(pkg) {
|
|
1605
|
+
const picked = pickEntry(pkg.dir);
|
|
1606
|
+
if (!picked) {
|
|
1739
1607
|
return {
|
|
1740
1608
|
kind: "needs-build",
|
|
1741
1609
|
package: pkg,
|
|
@@ -1743,24 +1611,9 @@ async function finishPackage(pkg, ctx) {
|
|
|
1743
1611
|
...buildCommand(pkg) ? { command: buildCommand(pkg) } : {}
|
|
1744
1612
|
};
|
|
1745
1613
|
}
|
|
1746
|
-
|
|
1747
|
-
let chosen = heuristic;
|
|
1748
|
-
let source = methodFor(heuristic);
|
|
1749
|
-
if (ctx.decisions === "jev" && cands.length >= 2) {
|
|
1750
|
-
const jev = await jevPickEntry(cands, ctx);
|
|
1751
|
-
if (jev) {
|
|
1752
|
-
chosen = jev;
|
|
1753
|
-
source = "llm";
|
|
1754
|
-
}
|
|
1755
|
-
}
|
|
1756
|
-
return {
|
|
1757
|
-
kind: "ok",
|
|
1758
|
-
package: pkg,
|
|
1759
|
-
entryFile: chosen.abs,
|
|
1760
|
-
entryPointSource: source
|
|
1761
|
-
};
|
|
1614
|
+
return { kind: "ok", package: pkg, ...picked };
|
|
1762
1615
|
}
|
|
1763
|
-
|
|
1616
|
+
function resolveLocal(abs, startDir, intent) {
|
|
1764
1617
|
const catalog = catalogPackages(startDir);
|
|
1765
1618
|
if (!catalog.length) {
|
|
1766
1619
|
return { kind: "empty", reason: "no JS/TS packages found" };
|
|
@@ -1768,9 +1621,8 @@ async function resolveLocal(abs, startDir, ctx) {
|
|
|
1768
1621
|
const root = findWorkspaceRoot(startDir);
|
|
1769
1622
|
const pointed = catalog.find((p) => p.dir === abs);
|
|
1770
1623
|
if (pointed && (isExtractable(pointed) || pointed.dir !== root)) {
|
|
1771
|
-
return finishPackage(pointed
|
|
1624
|
+
return finishPackage(pointed);
|
|
1772
1625
|
}
|
|
1773
|
-
const intent = ctx.intent;
|
|
1774
1626
|
if (intent) {
|
|
1775
1627
|
const scored = catalog.map((p) => ({ p, n: intentScore(p, intent) })).filter((x) => x.n > 0).sort((a, b) => b.n - a.n);
|
|
1776
1628
|
if (!scored.length) {
|
|
@@ -1778,61 +1630,30 @@ async function resolveLocal(abs, startDir, ctx) {
|
|
|
1778
1630
|
}
|
|
1779
1631
|
const top = scored.filter((x) => x.n === scored[0].n).map((x) => x.p);
|
|
1780
1632
|
if (top.length === 1)
|
|
1781
|
-
return finishPackage(top[0]
|
|
1782
|
-
if (ctx.decisions === "jev") {
|
|
1783
|
-
const jev = await jevPickPackage(top, ctx);
|
|
1784
|
-
if (jev)
|
|
1785
|
-
return finishPackage(jev, ctx);
|
|
1786
|
-
}
|
|
1633
|
+
return finishPackage(top[0]);
|
|
1787
1634
|
return { kind: "ambiguous", candidates: top };
|
|
1788
1635
|
}
|
|
1789
1636
|
const enclosed = enclosingPackage(startDir, catalog);
|
|
1790
1637
|
if (enclosed && enclosed.dir !== root)
|
|
1791
|
-
return finishPackage(enclosed
|
|
1638
|
+
return finishPackage(enclosed);
|
|
1792
1639
|
const extractable = catalog.filter(isExtractable);
|
|
1793
1640
|
if (extractable.length === 1)
|
|
1794
|
-
return finishPackage(extractable[0]
|
|
1795
|
-
if (extractable.length > 1)
|
|
1796
|
-
if (ctx.decisions === "jev") {
|
|
1797
|
-
const jev = await jevPickPackage(extractable, ctx);
|
|
1798
|
-
if (jev)
|
|
1799
|
-
return finishPackage(jev, ctx);
|
|
1800
|
-
}
|
|
1641
|
+
return finishPackage(extractable[0]);
|
|
1642
|
+
if (extractable.length > 1)
|
|
1801
1643
|
return { kind: "ambiguous", candidates: extractable };
|
|
1802
|
-
}
|
|
1803
1644
|
if (catalog.length === 1)
|
|
1804
|
-
return finishPackage(catalog[0]
|
|
1645
|
+
return finishPackage(catalog[0]);
|
|
1805
1646
|
return { kind: "empty", reason: "no extractable JS/TS packages found" };
|
|
1806
1647
|
}
|
|
1807
1648
|
async function resolveTarget(options = {}) {
|
|
1808
1649
|
const cwd = path2.resolve(options.cwd ?? process.cwd());
|
|
1809
1650
|
const raw = options.input?.trim() || cwd;
|
|
1810
|
-
const
|
|
1811
|
-
const ctx = {
|
|
1812
|
-
decisions,
|
|
1813
|
-
evaluate: options.evaluate,
|
|
1814
|
-
intent: options.intent?.trim() || undefined
|
|
1815
|
-
};
|
|
1816
|
-
if (decisions === "jev" && !ctx.evaluate) {
|
|
1817
|
-
if (!process.env.AI_GATEWAY_API_KEY) {
|
|
1818
|
-
return {
|
|
1819
|
-
kind: "unavailable",
|
|
1820
|
-
reason: `--jev requires AI_GATEWAY_API_KEY
|
|
1821
|
-
https://vercel.com/docs/ai-gateway
|
|
1822
|
-
omit --jev to stay local`
|
|
1823
|
-
};
|
|
1824
|
-
}
|
|
1825
|
-
try {
|
|
1826
|
-
ctx.evaluate = await loadEvaluate();
|
|
1827
|
-
} catch (err) {
|
|
1828
|
-
return { kind: "unavailable", reason: err instanceof Error ? err.message : String(err) };
|
|
1829
|
-
}
|
|
1830
|
-
}
|
|
1651
|
+
const intent = options.intent?.trim() || undefined;
|
|
1831
1652
|
if (isRemoteInput(raw)) {
|
|
1832
1653
|
const owned = !options.clone;
|
|
1833
1654
|
try {
|
|
1834
1655
|
const cloned = await (options.clone ?? cloneRemote)(raw);
|
|
1835
|
-
const result =
|
|
1656
|
+
const result = resolveLocal(cloned, cloned, intent);
|
|
1836
1657
|
if (!owned)
|
|
1837
1658
|
return result;
|
|
1838
1659
|
return {
|
|
@@ -1854,7 +1675,7 @@ async function resolveTarget(options = {}) {
|
|
|
1854
1675
|
return { kind: "empty", reason: `input does not exist: ${options.input?.trim() || raw}` };
|
|
1855
1676
|
}
|
|
1856
1677
|
const startDir = existsDir(abs) ? abs : cwd;
|
|
1857
|
-
return resolveLocal(abs, startDir,
|
|
1678
|
+
return resolveLocal(abs, startDir, intent);
|
|
1858
1679
|
}
|
|
1859
1680
|
// src/primitives/filter.ts
|
|
1860
1681
|
function matchesExport(exp, criteria) {
|
|
@@ -1962,9 +1783,82 @@ function filterSpec(spec, criteria) {
|
|
|
1962
1783
|
// src/primitives/get.ts
|
|
1963
1784
|
import ts13 from "typescript";
|
|
1964
1785
|
|
|
1965
|
-
// src/ast/
|
|
1786
|
+
// src/ast/type-identity.ts
|
|
1966
1787
|
import * as path3 from "node:path";
|
|
1967
1788
|
import ts from "typescript";
|
|
1789
|
+
var NODE_MODULES_PKG = /node_modules\/(@[^/]+\/[^/]+|[^/]+)/g;
|
|
1790
|
+
function packageNameFromPath(fileName) {
|
|
1791
|
+
return [...fileName.matchAll(NODE_MODULES_PKG)].at(-1)?.[1];
|
|
1792
|
+
}
|
|
1793
|
+
function packageLabel(fileName, workspacePackages) {
|
|
1794
|
+
let pkg = packageNameFromPath(fileName);
|
|
1795
|
+
if (!pkg) {
|
|
1796
|
+
for (const [name, dir] of workspacePackages) {
|
|
1797
|
+
if (fileName.startsWith(`${path3.resolve(dir)}${path3.sep}`)) {
|
|
1798
|
+
pkg = name;
|
|
1799
|
+
break;
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
return (pkg ?? "local").replace(/^@/, "").replace(/\//g, "-");
|
|
1804
|
+
}
|
|
1805
|
+
function declKey(symbol, checker) {
|
|
1806
|
+
let resolved = symbol;
|
|
1807
|
+
if (symbol.flags & ts.SymbolFlags.Alias) {
|
|
1808
|
+
try {
|
|
1809
|
+
resolved = checker.getAliasedSymbol(symbol);
|
|
1810
|
+
} catch {}
|
|
1811
|
+
}
|
|
1812
|
+
const decl = resolved.declarations?.[0];
|
|
1813
|
+
if (!decl)
|
|
1814
|
+
return;
|
|
1815
|
+
return `${decl.getSourceFile().fileName}#${decl.getStart()}`;
|
|
1816
|
+
}
|
|
1817
|
+
function resolveTypeId(symbol, ctx) {
|
|
1818
|
+
const cached = ctx.typeIds.get(symbol);
|
|
1819
|
+
if (cached)
|
|
1820
|
+
return cached;
|
|
1821
|
+
const key = declKey(symbol, ctx.typeChecker);
|
|
1822
|
+
if (key) {
|
|
1823
|
+
const existing = ctx.declIds.get(key);
|
|
1824
|
+
if (existing) {
|
|
1825
|
+
ctx.typeIds.set(symbol, existing);
|
|
1826
|
+
return existing;
|
|
1827
|
+
}
|
|
1828
|
+
}
|
|
1829
|
+
const claim = (id) => {
|
|
1830
|
+
ctx.typeIds.set(symbol, id);
|
|
1831
|
+
if (key)
|
|
1832
|
+
ctx.declIds.set(key, id);
|
|
1833
|
+
ctx.idOwner.set(id, key ?? id);
|
|
1834
|
+
return id;
|
|
1835
|
+
};
|
|
1836
|
+
const name = symbol.getName();
|
|
1837
|
+
const owner = ctx.idOwner.get(name);
|
|
1838
|
+
if (!owner || owner === key)
|
|
1839
|
+
return claim(name);
|
|
1840
|
+
const file = symbol.declarations?.[0]?.getSourceFile().fileName ?? "";
|
|
1841
|
+
const scoped = `${packageLabel(file, ctx.workspacePackages)}.${name}`;
|
|
1842
|
+
const scopedOwner = ctx.idOwner.get(scoped);
|
|
1843
|
+
if (!scopedOwner || scopedOwner === key)
|
|
1844
|
+
return claim(scoped);
|
|
1845
|
+
let n = 2;
|
|
1846
|
+
while (ctx.idOwner.has(`${name}_${n}`))
|
|
1847
|
+
n++;
|
|
1848
|
+
return claim(`${name}_${n}`);
|
|
1849
|
+
}
|
|
1850
|
+
function typeRefId(type, ctx) {
|
|
1851
|
+
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
1852
|
+
if (!symbol)
|
|
1853
|
+
return "";
|
|
1854
|
+
if (!ctx)
|
|
1855
|
+
return symbol.getName();
|
|
1856
|
+
return resolveTypeId(symbol, ctx);
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
// src/ast/utils.ts
|
|
1860
|
+
import * as path4 from "node:path";
|
|
1861
|
+
import ts2 from "typescript";
|
|
1968
1862
|
var INLINE_TAG_RE = /(^|[^\\])\{@([a-zA-Z][a-zA-Z0-9]*)((?:[^}\\]|\\.)*)\}/g;
|
|
1969
1863
|
function parseInlineTags(...texts) {
|
|
1970
1864
|
const inlineTags = [];
|
|
@@ -2058,12 +1952,12 @@ function extractSeeTagText(tag) {
|
|
|
2058
1952
|
if (Array.isArray(tag.comment)) {
|
|
2059
1953
|
const parts = [];
|
|
2060
1954
|
for (const part of tag.comment) {
|
|
2061
|
-
if (
|
|
1955
|
+
if (ts2.isJSDocLink(part) || ts2.isJSDocLinkCode(part) || ts2.isJSDocLinkPlain(part)) {
|
|
2062
1956
|
if (part.name) {
|
|
2063
1957
|
try {
|
|
2064
1958
|
parts.push(part.name.getText());
|
|
2065
1959
|
} catch {
|
|
2066
|
-
if (
|
|
1960
|
+
if (ts2.isIdentifier(part.name)) {
|
|
2067
1961
|
parts.push(part.name.text);
|
|
2068
1962
|
}
|
|
2069
1963
|
}
|
|
@@ -2071,7 +1965,7 @@ function extractSeeTagText(tag) {
|
|
|
2071
1965
|
if (part.text) {
|
|
2072
1966
|
parts.push(part.text);
|
|
2073
1967
|
}
|
|
2074
|
-
} else if (part.kind ===
|
|
1968
|
+
} else if (part.kind === ts2.SyntaxKind.JSDocText) {
|
|
2075
1969
|
parts.push(part.text);
|
|
2076
1970
|
}
|
|
2077
1971
|
}
|
|
@@ -2080,13 +1974,13 @@ function extractSeeTagText(tag) {
|
|
|
2080
1974
|
return result;
|
|
2081
1975
|
}
|
|
2082
1976
|
}
|
|
2083
|
-
return typeof tag.comment === "string" ? tag.comment :
|
|
1977
|
+
return typeof tag.comment === "string" ? tag.comment : ts2.getTextOfJSDocComment(tag.comment) ?? "";
|
|
2084
1978
|
}
|
|
2085
1979
|
function getJSDocComment(node, symbol, checker) {
|
|
2086
|
-
const jsDocTags =
|
|
1980
|
+
const jsDocTags = ts2.getJSDocTags(node);
|
|
2087
1981
|
const commentLevelTags = [];
|
|
2088
1982
|
const tags = jsDocTags.map((tag) => {
|
|
2089
|
-
const rawText = typeof tag.comment === "string" ? tag.comment :
|
|
1983
|
+
const rawText = typeof tag.comment === "string" ? tag.comment : ts2.getTextOfJSDocComment(tag.comment) ?? "";
|
|
2090
1984
|
const { retained, hoisted } = tag.tagName.text === "see" ? { retained: rawText, hoisted: [] } : splitCommentLevelTags(rawText);
|
|
2091
1985
|
commentLevelTags.push(...hoisted);
|
|
2092
1986
|
if (tag.tagName.text === "param") {
|
|
@@ -2123,12 +2017,12 @@ function getJSDocComment(node, symbol, checker) {
|
|
|
2123
2017
|
}
|
|
2124
2018
|
return withInlineTags({ name: tag.tagName.text, text: rawText }, retained);
|
|
2125
2019
|
});
|
|
2126
|
-
const jsDocComments =
|
|
2020
|
+
const jsDocComments = ts2.getJSDocCommentsAndTags(node).filter(ts2.isJSDoc);
|
|
2127
2021
|
let description;
|
|
2128
2022
|
if (jsDocComments.length > 0) {
|
|
2129
2023
|
const firstDoc = jsDocComments[0];
|
|
2130
2024
|
if (firstDoc.comment) {
|
|
2131
|
-
description = typeof firstDoc.comment === "string" ? firstDoc.comment :
|
|
2025
|
+
description = typeof firstDoc.comment === "string" ? firstDoc.comment : ts2.getTextOfJSDocComment(firstDoc.comment);
|
|
2132
2026
|
}
|
|
2133
2027
|
}
|
|
2134
2028
|
if (!description && symbol && checker) {
|
|
@@ -2149,7 +2043,7 @@ function getJSDocComment(node, symbol, checker) {
|
|
|
2149
2043
|
}
|
|
2150
2044
|
function getSourceLocation(node, sourceFile) {
|
|
2151
2045
|
const { line } = sourceFile.getLineAndCharacterOfPosition(node.getStart(sourceFile));
|
|
2152
|
-
const relative3 =
|
|
2046
|
+
const relative3 = path4.relative(process.cwd(), sourceFile.fileName);
|
|
2153
2047
|
const file = relative3.startsWith("..") ? sourceFile.fileName : relative3;
|
|
2154
2048
|
return {
|
|
2155
2049
|
file,
|
|
@@ -2169,7 +2063,7 @@ function getParamDescription(propertyName, jsdocTags, inferredAlias) {
|
|
|
2169
2063
|
}
|
|
2170
2064
|
const isMatch = tagParamName === propertyName || inferredAlias && tagParamName === `${inferredAlias}.${propertyName}` || tagParamName.endsWith(`.${propertyName}`);
|
|
2171
2065
|
if (isMatch) {
|
|
2172
|
-
const comment = typeof tag.comment === "string" ? tag.comment :
|
|
2066
|
+
const comment = typeof tag.comment === "string" ? tag.comment : ts2.getTextOfJSDocComment(tag.comment);
|
|
2173
2067
|
return stripParamSeparator(comment);
|
|
2174
2068
|
}
|
|
2175
2069
|
}
|
|
@@ -2182,11 +2076,11 @@ function extractVarianceModifiers(modifiers) {
|
|
|
2182
2076
|
let hasOut = false;
|
|
2183
2077
|
let isConst;
|
|
2184
2078
|
for (const mod of modifiers) {
|
|
2185
|
-
if (mod.kind ===
|
|
2079
|
+
if (mod.kind === ts2.SyntaxKind.InKeyword)
|
|
2186
2080
|
hasIn = true;
|
|
2187
|
-
if (mod.kind ===
|
|
2081
|
+
if (mod.kind === ts2.SyntaxKind.OutKeyword)
|
|
2188
2082
|
hasOut = true;
|
|
2189
|
-
if (mod.kind ===
|
|
2083
|
+
if (mod.kind === ts2.SyntaxKind.ConstKeyword)
|
|
2190
2084
|
isConst = true;
|
|
2191
2085
|
}
|
|
2192
2086
|
const variance = hasIn && hasOut ? "inout" : hasIn ? "in" : hasOut ? "out" : undefined;
|
|
@@ -2208,7 +2102,7 @@ function extractTypeParameters(node, checker) {
|
|
|
2208
2102
|
const defType = checker.getTypeAtLocation(tp.default);
|
|
2209
2103
|
defaultType = checker.typeToString(defType);
|
|
2210
2104
|
}
|
|
2211
|
-
const { variance, isConst } = extractVarianceModifiers(
|
|
2105
|
+
const { variance, isConst } = extractVarianceModifiers(ts2.getModifiers(tp));
|
|
2212
2106
|
return {
|
|
2213
2107
|
name,
|
|
2214
2108
|
...constraint ? { constraint } : {},
|
|
@@ -2229,7 +2123,7 @@ function isSymbolDeprecated(symbol) {
|
|
|
2229
2123
|
return { deprecated: true, reason };
|
|
2230
2124
|
}
|
|
2231
2125
|
for (const declaration of symbol.getDeclarations() ?? []) {
|
|
2232
|
-
const tag =
|
|
2126
|
+
const tag = ts2.getJSDocDeprecatedTag(declaration);
|
|
2233
2127
|
if (tag) {
|
|
2234
2128
|
let reason;
|
|
2235
2129
|
if (typeof tag.comment === "string") {
|
|
@@ -2239,10 +2133,10 @@ function isSymbolDeprecated(symbol) {
|
|
|
2239
2133
|
}
|
|
2240
2134
|
return { deprecated: true, reason };
|
|
2241
2135
|
}
|
|
2242
|
-
if (
|
|
2136
|
+
if (ts2.isExportSpecifier(declaration)) {
|
|
2243
2137
|
const exportDecl = declaration.parent?.parent;
|
|
2244
|
-
if (exportDecl &&
|
|
2245
|
-
const parentTag =
|
|
2138
|
+
if (exportDecl && ts2.isExportDeclaration(exportDecl)) {
|
|
2139
|
+
const parentTag = ts2.getJSDocDeprecatedTag(exportDecl);
|
|
2246
2140
|
if (parentTag) {
|
|
2247
2141
|
let reason;
|
|
2248
2142
|
if (typeof parentTag.comment === "string") {
|
|
@@ -2287,8 +2181,8 @@ function extractTypeParametersFromSignature(signature, checker) {
|
|
|
2287
2181
|
const tpSymbol = tp.getSymbol();
|
|
2288
2182
|
const declarations = tpSymbol?.getDeclarations() ?? [];
|
|
2289
2183
|
for (const decl of declarations) {
|
|
2290
|
-
if (
|
|
2291
|
-
({ variance, isConst } = extractVarianceModifiers(
|
|
2184
|
+
if (ts2.isTypeParameterDeclaration(decl)) {
|
|
2185
|
+
({ variance, isConst } = extractVarianceModifiers(ts2.getModifiers(decl)));
|
|
2292
2186
|
break;
|
|
2293
2187
|
}
|
|
2294
2188
|
}
|
|
@@ -2302,60 +2196,60 @@ function extractTypeParametersFromSignature(signature, checker) {
|
|
|
2302
2196
|
});
|
|
2303
2197
|
}
|
|
2304
2198
|
function getExportKind(declaration, type) {
|
|
2305
|
-
if (
|
|
2199
|
+
if (ts2.isFunctionDeclaration(declaration) || ts2.isFunctionExpression(declaration))
|
|
2306
2200
|
return "function";
|
|
2307
|
-
if (
|
|
2201
|
+
if (ts2.isClassDeclaration(declaration))
|
|
2308
2202
|
return "class";
|
|
2309
|
-
if (
|
|
2203
|
+
if (ts2.isInterfaceDeclaration(declaration))
|
|
2310
2204
|
return "interface";
|
|
2311
|
-
if (
|
|
2205
|
+
if (ts2.isTypeAliasDeclaration(declaration))
|
|
2312
2206
|
return "type";
|
|
2313
|
-
if (
|
|
2207
|
+
if (ts2.isEnumDeclaration(declaration))
|
|
2314
2208
|
return "enum";
|
|
2315
|
-
if (
|
|
2209
|
+
if (ts2.isModuleDeclaration(declaration) || ts2.isNamespaceExport(declaration))
|
|
2316
2210
|
return "namespace";
|
|
2317
|
-
if (
|
|
2211
|
+
if (ts2.isVariableDeclaration(declaration) && type.getConstructSignatures().length > 0)
|
|
2318
2212
|
return "class";
|
|
2319
|
-
if (
|
|
2213
|
+
if (ts2.isVariableDeclaration(declaration) && type.getCallSignatures().length > 0)
|
|
2320
2214
|
return "function";
|
|
2321
2215
|
return "variable";
|
|
2322
2216
|
}
|
|
2323
2217
|
|
|
2324
2218
|
// src/compiler/program.ts
|
|
2325
2219
|
import * as fs4 from "node:fs";
|
|
2326
|
-
import * as
|
|
2327
|
-
import
|
|
2220
|
+
import * as path5 from "node:path";
|
|
2221
|
+
import ts3 from "typescript";
|
|
2328
2222
|
function isJsFile(file) {
|
|
2329
2223
|
return /\.(js|mjs|cjs|jsx)$/.test(file);
|
|
2330
2224
|
}
|
|
2331
2225
|
function getScriptKind(file) {
|
|
2332
2226
|
if (/\.tsx$/.test(file))
|
|
2333
|
-
return
|
|
2227
|
+
return ts3.ScriptKind.TSX;
|
|
2334
2228
|
if (/\.jsx$/.test(file))
|
|
2335
|
-
return
|
|
2229
|
+
return ts3.ScriptKind.JSX;
|
|
2336
2230
|
if (/\.(js|mjs|cjs)$/.test(file))
|
|
2337
|
-
return
|
|
2338
|
-
return
|
|
2231
|
+
return ts3.ScriptKind.JS;
|
|
2232
|
+
return ts3.ScriptKind.TS;
|
|
2339
2233
|
}
|
|
2340
2234
|
var DEFAULT_COMPILER_OPTIONS = {
|
|
2341
|
-
target:
|
|
2342
|
-
module:
|
|
2235
|
+
target: ts3.ScriptTarget.Latest,
|
|
2236
|
+
module: ts3.ModuleKind.NodeNext,
|
|
2343
2237
|
lib: ["lib.es2021.d.ts"],
|
|
2344
2238
|
declaration: true,
|
|
2345
|
-
moduleResolution:
|
|
2239
|
+
moduleResolution: ts3.ModuleResolutionKind.NodeNext,
|
|
2346
2240
|
strict: true
|
|
2347
2241
|
};
|
|
2348
2242
|
function resolveWorkspaceEntry(pkgDir) {
|
|
2349
2243
|
const candidates = [
|
|
2350
|
-
|
|
2351
|
-
|
|
2352
|
-
|
|
2244
|
+
path5.join(pkgDir, "src", "index.ts"),
|
|
2245
|
+
path5.join(pkgDir, "src", "index.tsx"),
|
|
2246
|
+
path5.join(pkgDir, "index.ts")
|
|
2353
2247
|
];
|
|
2354
2248
|
try {
|
|
2355
|
-
const pkg = JSON.parse(fs4.readFileSync(
|
|
2249
|
+
const pkg = JSON.parse(fs4.readFileSync(path5.join(pkgDir, "package.json"), "utf-8"));
|
|
2356
2250
|
for (const field of [pkg.types, pkg.typings]) {
|
|
2357
2251
|
if (typeof field === "string") {
|
|
2358
|
-
candidates.push(
|
|
2252
|
+
candidates.push(path5.resolve(pkgDir, field));
|
|
2359
2253
|
}
|
|
2360
2254
|
}
|
|
2361
2255
|
} catch {}
|
|
@@ -2367,51 +2261,51 @@ function isDirentDir2(parent, entry) {
|
|
|
2367
2261
|
if (!entry.isSymbolicLink())
|
|
2368
2262
|
return false;
|
|
2369
2263
|
try {
|
|
2370
|
-
return fs4.statSync(
|
|
2264
|
+
return fs4.statSync(path5.join(parent, entry.name)).isDirectory();
|
|
2371
2265
|
} catch {
|
|
2372
2266
|
return false;
|
|
2373
2267
|
}
|
|
2374
2268
|
}
|
|
2375
2269
|
function extensionOf(file) {
|
|
2376
2270
|
if (file.endsWith(".d.mts"))
|
|
2377
|
-
return
|
|
2271
|
+
return ts3.Extension.Dmts;
|
|
2378
2272
|
if (file.endsWith(".d.cts"))
|
|
2379
|
-
return
|
|
2273
|
+
return ts3.Extension.Dcts;
|
|
2380
2274
|
if (file.endsWith(".d.ts"))
|
|
2381
|
-
return
|
|
2275
|
+
return ts3.Extension.Dts;
|
|
2382
2276
|
if (file.endsWith(".mts"))
|
|
2383
|
-
return
|
|
2277
|
+
return ts3.Extension.Mts;
|
|
2384
2278
|
if (file.endsWith(".cts"))
|
|
2385
|
-
return
|
|
2279
|
+
return ts3.Extension.Cts;
|
|
2386
2280
|
if (file.endsWith(".tsx"))
|
|
2387
|
-
return
|
|
2281
|
+
return ts3.Extension.Tsx;
|
|
2388
2282
|
if (file.endsWith(".ts"))
|
|
2389
|
-
return
|
|
2283
|
+
return ts3.Extension.Ts;
|
|
2390
2284
|
if (file.endsWith(".mjs"))
|
|
2391
|
-
return
|
|
2285
|
+
return ts3.Extension.Mjs;
|
|
2392
2286
|
if (file.endsWith(".cjs"))
|
|
2393
|
-
return
|
|
2287
|
+
return ts3.Extension.Cjs;
|
|
2394
2288
|
if (file.endsWith(".jsx"))
|
|
2395
|
-
return
|
|
2289
|
+
return ts3.Extension.Jsx;
|
|
2396
2290
|
if (file.endsWith(".js"))
|
|
2397
|
-
return
|
|
2398
|
-
return
|
|
2291
|
+
return ts3.Extension.Js;
|
|
2292
|
+
return ts3.Extension.Ts;
|
|
2399
2293
|
}
|
|
2400
2294
|
function resolveProjectReferences(configPath, parsedConfig) {
|
|
2401
2295
|
const additionalFiles = [];
|
|
2402
2296
|
if (!parsedConfig.projectReferences?.length) {
|
|
2403
2297
|
return additionalFiles;
|
|
2404
2298
|
}
|
|
2405
|
-
const configDir =
|
|
2299
|
+
const configDir = path5.dirname(configPath);
|
|
2406
2300
|
for (const ref of parsedConfig.projectReferences) {
|
|
2407
|
-
const refPath =
|
|
2408
|
-
const refConfigPath = fs4.existsSync(
|
|
2301
|
+
const refPath = path5.resolve(configDir, ref.path);
|
|
2302
|
+
const refConfigPath = fs4.existsSync(path5.join(refPath, "tsconfig.json")) ? path5.join(refPath, "tsconfig.json") : refPath;
|
|
2409
2303
|
if (!fs4.existsSync(refConfigPath))
|
|
2410
2304
|
continue;
|
|
2411
|
-
const refConfigFile =
|
|
2305
|
+
const refConfigFile = ts3.readConfigFile(refConfigPath, ts3.sys.readFile);
|
|
2412
2306
|
if (refConfigFile.error)
|
|
2413
2307
|
continue;
|
|
2414
|
-
const refParsed =
|
|
2308
|
+
const refParsed = ts3.parseJsonConfigFileContent(refConfigFile.config, ts3.sys, path5.dirname(refConfigPath));
|
|
2415
2309
|
additionalFiles.push(...refParsed.fileNames);
|
|
2416
2310
|
}
|
|
2417
2311
|
return additionalFiles;
|
|
@@ -2444,7 +2338,7 @@ function buildWorkspaceMap(baseDir) {
|
|
|
2444
2338
|
let rootDir;
|
|
2445
2339
|
let workspaceGlobs2 = [];
|
|
2446
2340
|
for (let i = 0;i < 10; i++) {
|
|
2447
|
-
const pnpmPath =
|
|
2341
|
+
const pnpmPath = path5.join(currentDir, "pnpm-workspace.yaml");
|
|
2448
2342
|
if (fs4.existsSync(pnpmPath)) {
|
|
2449
2343
|
try {
|
|
2450
2344
|
const yamlContent = fs4.readFileSync(pnpmPath, "utf-8");
|
|
@@ -2455,7 +2349,7 @@ function buildWorkspaceMap(baseDir) {
|
|
|
2455
2349
|
}
|
|
2456
2350
|
} catch {}
|
|
2457
2351
|
}
|
|
2458
|
-
const pkgPath =
|
|
2352
|
+
const pkgPath = path5.join(currentDir, "package.json");
|
|
2459
2353
|
if (fs4.existsSync(pkgPath)) {
|
|
2460
2354
|
try {
|
|
2461
2355
|
const pkg = JSON.parse(fs4.readFileSync(pkgPath, "utf-8"));
|
|
@@ -2466,7 +2360,7 @@ function buildWorkspaceMap(baseDir) {
|
|
|
2466
2360
|
}
|
|
2467
2361
|
} catch {}
|
|
2468
2362
|
}
|
|
2469
|
-
const parent =
|
|
2363
|
+
const parent = path5.dirname(currentDir);
|
|
2470
2364
|
if (parent === currentDir)
|
|
2471
2365
|
break;
|
|
2472
2366
|
currentDir = parent;
|
|
@@ -2475,15 +2369,15 @@ function buildWorkspaceMap(baseDir) {
|
|
|
2475
2369
|
return;
|
|
2476
2370
|
const packages = new Map;
|
|
2477
2371
|
for (const glob of workspaceGlobs2) {
|
|
2478
|
-
const globDir =
|
|
2372
|
+
const globDir = path5.join(rootDir, glob.replace(/\/\*$/, ""));
|
|
2479
2373
|
if (!fs4.existsSync(globDir) || !fs4.statSync(globDir).isDirectory())
|
|
2480
2374
|
continue;
|
|
2481
2375
|
const entries = fs4.readdirSync(globDir, { withFileTypes: true });
|
|
2482
2376
|
for (const entry of entries) {
|
|
2483
2377
|
if (!isDirentDir2(globDir, entry))
|
|
2484
2378
|
continue;
|
|
2485
|
-
const pkgDir =
|
|
2486
|
-
const pkgJsonPath =
|
|
2379
|
+
const pkgDir = path5.join(globDir, entry.name);
|
|
2380
|
+
const pkgJsonPath = path5.join(pkgDir, "package.json");
|
|
2487
2381
|
if (!fs4.existsSync(pkgJsonPath))
|
|
2488
2382
|
continue;
|
|
2489
2383
|
try {
|
|
@@ -2501,7 +2395,7 @@ function discoverAmbientTypePackages(baseDir) {
|
|
|
2501
2395
|
const seen = new Set;
|
|
2502
2396
|
let currentDir = baseDir;
|
|
2503
2397
|
for (let i = 0;i < 10; i++) {
|
|
2504
|
-
const typesDir =
|
|
2398
|
+
const typesDir = path5.join(currentDir, "node_modules", "@types");
|
|
2505
2399
|
try {
|
|
2506
2400
|
if (fs4.existsSync(typesDir) && fs4.statSync(typesDir).isDirectory()) {
|
|
2507
2401
|
for (const entry of fs4.readdirSync(typesDir, { withFileTypes: true })) {
|
|
@@ -2514,7 +2408,7 @@ function discoverAmbientTypePackages(baseDir) {
|
|
|
2514
2408
|
}
|
|
2515
2409
|
}
|
|
2516
2410
|
} catch {}
|
|
2517
|
-
const parent =
|
|
2411
|
+
const parent = path5.dirname(currentDir);
|
|
2518
2412
|
if (parent === currentDir)
|
|
2519
2413
|
break;
|
|
2520
2414
|
currentDir = parent;
|
|
@@ -2523,24 +2417,24 @@ function discoverAmbientTypePackages(baseDir) {
|
|
|
2523
2417
|
}
|
|
2524
2418
|
function createProgram(options) {
|
|
2525
2419
|
const { content } = options;
|
|
2526
|
-
const entryFile =
|
|
2527
|
-
const baseDir =
|
|
2528
|
-
let configPath =
|
|
2420
|
+
const entryFile = path5.resolve(options.entryFile);
|
|
2421
|
+
const baseDir = path5.resolve(options.baseDir ?? path5.dirname(entryFile));
|
|
2422
|
+
let configPath = ts3.findConfigFile(baseDir, ts3.sys.fileExists, "tsconfig.json");
|
|
2529
2423
|
if (!configPath) {
|
|
2530
|
-
configPath =
|
|
2424
|
+
configPath = ts3.findConfigFile(baseDir, ts3.sys.fileExists, "jsconfig.json");
|
|
2531
2425
|
}
|
|
2532
2426
|
let compilerOptions = { ...DEFAULT_COMPILER_OPTIONS };
|
|
2533
2427
|
let additionalRootFiles = [];
|
|
2534
2428
|
if (configPath) {
|
|
2535
|
-
const configFile =
|
|
2536
|
-
const parsedConfig =
|
|
2429
|
+
const configFile = ts3.readConfigFile(configPath, ts3.sys.readFile);
|
|
2430
|
+
const parsedConfig = ts3.parseJsonConfigFileContent(configFile.config, ts3.sys, path5.dirname(configPath));
|
|
2537
2431
|
compilerOptions = { ...compilerOptions, ...parsedConfig.options };
|
|
2538
2432
|
additionalRootFiles = resolveProjectReferences(configPath, parsedConfig);
|
|
2539
2433
|
let sourceFiles = parsedConfig.fileNames.filter((f) => !f.includes(".test.") && !f.includes(".spec.") && !f.includes("/dist/") && !f.includes("/node_modules/"));
|
|
2540
2434
|
if (/\.d\.[cm]?ts$/.test(entryFile)) {
|
|
2541
2435
|
sourceFiles = sourceFiles.filter((f) => {
|
|
2542
2436
|
try {
|
|
2543
|
-
return !
|
|
2437
|
+
return !ts3.getOutputFileNames(parsedConfig, f, !ts3.sys.useCaseSensitiveFileNames).some((out) => path5.resolve(out) === entryFile);
|
|
2544
2438
|
} catch {
|
|
2545
2439
|
return true;
|
|
2546
2440
|
}
|
|
@@ -2568,7 +2462,7 @@ function createProgram(options) {
|
|
|
2568
2462
|
}
|
|
2569
2463
|
}
|
|
2570
2464
|
const workspaceMap = buildWorkspaceMap(baseDir);
|
|
2571
|
-
const compilerHost =
|
|
2465
|
+
const compilerHost = ts3.createCompilerHost(compilerOptions, true);
|
|
2572
2466
|
let inMemorySource;
|
|
2573
2467
|
if (workspaceMap) {
|
|
2574
2468
|
compilerHost.resolveModuleNameLiterals = (moduleLiterals, containingFile, redirectedReference, options2, containingSourceFile) => moduleLiterals.map((literal) => {
|
|
@@ -2585,12 +2479,12 @@ function createProgram(options) {
|
|
|
2585
2479
|
};
|
|
2586
2480
|
}
|
|
2587
2481
|
}
|
|
2588
|
-
const mode =
|
|
2589
|
-
return
|
|
2482
|
+
const mode = ts3.getModeForUsageLocation(containingSourceFile, literal, options2);
|
|
2483
|
+
return ts3.resolveModuleName(literal.text, containingFile, options2, compilerHost, undefined, redirectedReference, mode);
|
|
2590
2484
|
});
|
|
2591
2485
|
}
|
|
2592
2486
|
if (content !== undefined) {
|
|
2593
|
-
inMemorySource =
|
|
2487
|
+
inMemorySource = ts3.createSourceFile(entryFile, content, ts3.ScriptTarget.Latest, true, getScriptKind(entryFile));
|
|
2594
2488
|
const originalGetSourceFile = compilerHost.getSourceFile.bind(compilerHost);
|
|
2595
2489
|
compilerHost.getSourceFile = (fileName, languageVersion, onError, shouldCreateNewSourceFile) => {
|
|
2596
2490
|
if (fileName === entryFile) {
|
|
@@ -2600,7 +2494,7 @@ function createProgram(options) {
|
|
|
2600
2494
|
};
|
|
2601
2495
|
}
|
|
2602
2496
|
const rootFiles = [entryFile, ...additionalRootFiles];
|
|
2603
|
-
const program =
|
|
2497
|
+
const program = ts3.createProgram(rootFiles, compilerOptions, compilerHost);
|
|
2604
2498
|
const sourceFile = inMemorySource ?? program.getSourceFile(entryFile);
|
|
2605
2499
|
return {
|
|
2606
2500
|
program,
|
|
@@ -2621,77 +2515,6 @@ import ts5 from "typescript";
|
|
|
2621
2515
|
// src/types/schema-builder.ts
|
|
2622
2516
|
import ts4 from "typescript";
|
|
2623
2517
|
|
|
2624
|
-
// src/ast/type-identity.ts
|
|
2625
|
-
import * as path5 from "node:path";
|
|
2626
|
-
import ts3 from "typescript";
|
|
2627
|
-
var NODE_MODULES_PKG = /node_modules\/(@[^/]+\/[^/]+|[^/]+)/;
|
|
2628
|
-
function packageLabel(fileName, workspacePackages) {
|
|
2629
|
-
const match = fileName.match(NODE_MODULES_PKG);
|
|
2630
|
-
let pkg = match?.[1];
|
|
2631
|
-
if (!pkg) {
|
|
2632
|
-
for (const [name, dir] of workspacePackages) {
|
|
2633
|
-
if (fileName.startsWith(`${path5.resolve(dir)}${path5.sep}`)) {
|
|
2634
|
-
pkg = name;
|
|
2635
|
-
break;
|
|
2636
|
-
}
|
|
2637
|
-
}
|
|
2638
|
-
}
|
|
2639
|
-
return (pkg ?? "local").replace(/^@/, "").replace(/\//g, "-");
|
|
2640
|
-
}
|
|
2641
|
-
function declKey(symbol, checker) {
|
|
2642
|
-
let resolved = symbol;
|
|
2643
|
-
if (symbol.flags & ts3.SymbolFlags.Alias) {
|
|
2644
|
-
try {
|
|
2645
|
-
resolved = checker.getAliasedSymbol(symbol);
|
|
2646
|
-
} catch {}
|
|
2647
|
-
}
|
|
2648
|
-
const decl = resolved.declarations?.[0];
|
|
2649
|
-
if (!decl)
|
|
2650
|
-
return;
|
|
2651
|
-
return `${decl.getSourceFile().fileName}#${decl.getStart()}`;
|
|
2652
|
-
}
|
|
2653
|
-
function resolveTypeId(symbol, ctx) {
|
|
2654
|
-
const cached = ctx.typeIds.get(symbol);
|
|
2655
|
-
if (cached)
|
|
2656
|
-
return cached;
|
|
2657
|
-
const key = declKey(symbol, ctx.typeChecker);
|
|
2658
|
-
if (key) {
|
|
2659
|
-
const existing = ctx.declIds.get(key);
|
|
2660
|
-
if (existing) {
|
|
2661
|
-
ctx.typeIds.set(symbol, existing);
|
|
2662
|
-
return existing;
|
|
2663
|
-
}
|
|
2664
|
-
}
|
|
2665
|
-
const claim = (id) => {
|
|
2666
|
-
ctx.typeIds.set(symbol, id);
|
|
2667
|
-
if (key)
|
|
2668
|
-
ctx.declIds.set(key, id);
|
|
2669
|
-
ctx.idOwner.set(id, key ?? id);
|
|
2670
|
-
return id;
|
|
2671
|
-
};
|
|
2672
|
-
const name = symbol.getName();
|
|
2673
|
-
const owner = ctx.idOwner.get(name);
|
|
2674
|
-
if (!owner || owner === key)
|
|
2675
|
-
return claim(name);
|
|
2676
|
-
const file = symbol.declarations?.[0]?.getSourceFile().fileName ?? "";
|
|
2677
|
-
const scoped = `${packageLabel(file, ctx.workspacePackages)}.${name}`;
|
|
2678
|
-
const scopedOwner = ctx.idOwner.get(scoped);
|
|
2679
|
-
if (!scopedOwner || scopedOwner === key)
|
|
2680
|
-
return claim(scoped);
|
|
2681
|
-
let n = 2;
|
|
2682
|
-
while (ctx.idOwner.has(`${name}_${n}`))
|
|
2683
|
-
n++;
|
|
2684
|
-
return claim(`${name}_${n}`);
|
|
2685
|
-
}
|
|
2686
|
-
function typeRefId(type, ctx) {
|
|
2687
|
-
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
2688
|
-
if (!symbol)
|
|
2689
|
-
return "";
|
|
2690
|
-
if (!ctx)
|
|
2691
|
-
return symbol.getName();
|
|
2692
|
-
return resolveTypeId(symbol, ctx);
|
|
2693
|
-
}
|
|
2694
|
-
|
|
2695
2518
|
// src/schema/builtins.ts
|
|
2696
2519
|
var BUILTIN_TYPE_SCHEMAS = {
|
|
2697
2520
|
Array: { type: "array" },
|
|
@@ -3021,12 +2844,10 @@ function getTypeOrigin(type, _checker) {
|
|
|
3021
2844
|
if (!declarations || declarations.length === 0)
|
|
3022
2845
|
return;
|
|
3023
2846
|
const fileName = declarations[0].getSourceFile().fileName;
|
|
3024
|
-
const
|
|
3025
|
-
if (
|
|
2847
|
+
const pkg = packageNameFromPath(fileName);
|
|
2848
|
+
if (pkg === "typescript")
|
|
3026
2849
|
return;
|
|
3027
|
-
|
|
3028
|
-
return;
|
|
3029
|
-
return match[1];
|
|
2850
|
+
return pkg;
|
|
3030
2851
|
}
|
|
3031
2852
|
function isBuiltinGeneric(name) {
|
|
3032
2853
|
return BUILTIN_GENERICS.has(name);
|
|
@@ -3964,6 +3785,8 @@ class TypeRegistry {
|
|
|
3964
3785
|
return;
|
|
3965
3786
|
if (name.startsWith("__"))
|
|
3966
3787
|
return;
|
|
3788
|
+
if (name.startsWith('"'))
|
|
3789
|
+
return;
|
|
3967
3790
|
if (symbol.flags & ts6.SymbolFlags.EnumMember)
|
|
3968
3791
|
return;
|
|
3969
3792
|
if (symbol.flags & ts6.SymbolFlags.TypeParameter)
|
|
@@ -6145,11 +5968,9 @@ function detectExternalPackage(symbol, checker) {
|
|
|
6145
5968
|
const allDecls = [...targetSymbol.declarations ?? [], ...symbol.declarations ?? []];
|
|
6146
5969
|
for (const decl of allDecls) {
|
|
6147
5970
|
const sf = decl.getSourceFile();
|
|
6148
|
-
|
|
6149
|
-
|
|
6150
|
-
|
|
6151
|
-
return match[1];
|
|
6152
|
-
}
|
|
5971
|
+
const pkg = sf && packageNameFromPath(sf.fileName);
|
|
5972
|
+
if (pkg)
|
|
5973
|
+
return pkg;
|
|
6153
5974
|
if (ts13.isExportSpecifier(decl)) {
|
|
6154
5975
|
const exportDecl = decl.parent?.parent;
|
|
6155
5976
|
if (exportDecl && ts13.isExportDeclaration(exportDecl) && exportDecl.moduleSpecifier) {
|
|
@@ -6973,80 +6794,6 @@ function extractExternalExport(exportName, resolvedModule, program, ctx, visited
|
|
|
6973
6794
|
return specExport;
|
|
6974
6795
|
}
|
|
6975
6796
|
|
|
6976
|
-
// src/builder/jev-extract.ts
|
|
6977
|
-
var FOLLOW_SCORE_LEVELS = [
|
|
6978
|
-
"opaque — a stub is enough",
|
|
6979
|
-
"useful — expanding helps",
|
|
6980
|
-
"essential — needed to understand the public API"
|
|
6981
|
-
];
|
|
6982
|
-
var AMBIGUOUS_CODES = new Set([
|
|
6983
|
-
"FORGOTTEN_EXPORT",
|
|
6984
|
-
"SERIALIZATION_FAILED",
|
|
6985
|
-
"RUNTIME_SCHEMA_ERROR"
|
|
6986
|
-
]);
|
|
6987
|
-
async function selectFollowExternal(refs, evaluate) {
|
|
6988
|
-
const sliced = refs.slice(0, MAX_JEV_QUESTIONS);
|
|
6989
|
-
if (!sliced.length)
|
|
6990
|
-
return [];
|
|
6991
|
-
const questions = {};
|
|
6992
|
-
for (const [i, ref] of sliced.entries()) {
|
|
6993
|
-
questions[`t${i}`] = {
|
|
6994
|
-
type: "score",
|
|
6995
|
-
instructions: `How load-bearing is ${ref.typeName} from ${ref.package} for understanding this public TypeScript API?`,
|
|
6996
|
-
criteria: FOLLOW_SCORE_LEVELS
|
|
6997
|
-
};
|
|
6998
|
-
}
|
|
6999
|
-
const result = await jevEvaluate(evaluate, {
|
|
7000
|
-
types: sliced,
|
|
7001
|
-
task: "OpenPkg extracts a public TS API. Stub opaque externals; expand load-bearing ones."
|
|
7002
|
-
}, questions);
|
|
7003
|
-
const follow = new Set;
|
|
7004
|
-
for (const [i, ref] of sliced.entries()) {
|
|
7005
|
-
const id = `t${i}`;
|
|
7006
|
-
const score = result.answers[id]?.score;
|
|
7007
|
-
if (typeof score !== "number")
|
|
7008
|
-
continue;
|
|
7009
|
-
const conf = namedConfidence(result, id) ?? (score >= 1.5 || score <= 0.5 ? 1 : 0);
|
|
7010
|
-
if (score >= 1.5 || score >= 1 && conf >= JEV_CONFIDENCE)
|
|
7011
|
-
follow.add(ref.package);
|
|
7012
|
-
}
|
|
7013
|
-
return [...follow];
|
|
7014
|
-
}
|
|
7015
|
-
async function calibrateDiagnostics(diagnostics, evaluate) {
|
|
7016
|
-
const targets = diagnostics.map((d, index) => ({ d, index })).filter(({ d }) => d.code && AMBIGUOUS_CODES.has(d.code)).slice(0, MAX_JEV_QUESTIONS);
|
|
7017
|
-
if (targets.length < 1)
|
|
7018
|
-
return;
|
|
7019
|
-
const questions = {};
|
|
7020
|
-
for (const [i, { d }] of targets.entries()) {
|
|
7021
|
-
questions[`d${i}`] = {
|
|
7022
|
-
type: "choice",
|
|
7023
|
-
instructions: `What severity should this extraction diagnostic have? ${d.message}`,
|
|
7024
|
-
criteria: {
|
|
7025
|
-
error: "Blocks a correct spec",
|
|
7026
|
-
warning: "Likely a real API gap",
|
|
7027
|
-
info: "Informational only"
|
|
7028
|
-
}
|
|
7029
|
-
};
|
|
7030
|
-
}
|
|
7031
|
-
const result = await jevEvaluate(evaluate, {
|
|
7032
|
-
diagnostics: targets.map(({ d }) => ({
|
|
7033
|
-
code: d.code,
|
|
7034
|
-
message: d.message,
|
|
7035
|
-
severity: d.severity
|
|
7036
|
-
}))
|
|
7037
|
-
}, questions);
|
|
7038
|
-
for (const [i, { d }] of targets.entries()) {
|
|
7039
|
-
const id = `d${i}`;
|
|
7040
|
-
const choice = result.answers[id]?.choice;
|
|
7041
|
-
if (choice !== "error" && choice !== "warning" && choice !== "info")
|
|
7042
|
-
continue;
|
|
7043
|
-
const conf = namedConfidence(result, id) ?? result.answers[id]?.probabilities?.[choice] ?? 0;
|
|
7044
|
-
if (conf < JEV_CONFIDENCE)
|
|
7045
|
-
continue;
|
|
7046
|
-
d.severity = choice;
|
|
7047
|
-
}
|
|
7048
|
-
}
|
|
7049
|
-
|
|
7050
6797
|
// src/builder/schema-merger.ts
|
|
7051
6798
|
function mergeRuntimeSchemas(staticExports, runtimeSchemas) {
|
|
7052
6799
|
let merged = 0;
|
|
@@ -7214,7 +6961,6 @@ function hasInternalTag(typeName, program, sourceFile) {
|
|
|
7214
6961
|
|
|
7215
6962
|
// src/builder/type-expansion.ts
|
|
7216
6963
|
import ts18 from "typescript";
|
|
7217
|
-
var NODE_MODULES_PKG2 = /node_modules\/(@[^/]+\/[^/]+|[^/]+)/;
|
|
7218
6964
|
function isLibFile(fileName) {
|
|
7219
6965
|
return fileName.includes("/typescript/lib/lib.") || fileName.includes("\\typescript\\lib\\lib.");
|
|
7220
6966
|
}
|
|
@@ -7242,91 +6988,12 @@ function createExternalExpansionPredicate(opts) {
|
|
|
7242
6988
|
const fileName = decl.getSourceFile().fileName;
|
|
7243
6989
|
if (isLibFile(fileName))
|
|
7244
6990
|
return false;
|
|
7245
|
-
const
|
|
7246
|
-
if (
|
|
7247
|
-
return packageAllowed(
|
|
6991
|
+
const pkg = packageNameFromPath(fileName);
|
|
6992
|
+
if (pkg)
|
|
6993
|
+
return packageAllowed(pkg);
|
|
7248
6994
|
return true;
|
|
7249
6995
|
};
|
|
7250
6996
|
}
|
|
7251
|
-
function collectReferencedExternals(exportedSymbols, checker, workspacePackages) {
|
|
7252
|
-
const out = [];
|
|
7253
|
-
const seen = new Set;
|
|
7254
|
-
const visited = new Set;
|
|
7255
|
-
const consider = (symbol) => {
|
|
7256
|
-
if (!symbol)
|
|
7257
|
-
return;
|
|
7258
|
-
const decl = symbol.declarations?.[0];
|
|
7259
|
-
if (!decl)
|
|
7260
|
-
return;
|
|
7261
|
-
const fileName = decl.getSourceFile().fileName;
|
|
7262
|
-
if (isLibFile(fileName))
|
|
7263
|
-
return;
|
|
7264
|
-
const match = fileName.match(NODE_MODULES_PKG2);
|
|
7265
|
-
if (!match)
|
|
7266
|
-
return;
|
|
7267
|
-
const pkg = match[1];
|
|
7268
|
-
if (pkg === "typescript" || workspacePackages.has(pkg))
|
|
7269
|
-
return;
|
|
7270
|
-
const typeName = symbol.getName();
|
|
7271
|
-
if (typeName.startsWith("__"))
|
|
7272
|
-
return;
|
|
7273
|
-
const key = `${pkg}:${typeName}`;
|
|
7274
|
-
if (seen.has(key))
|
|
7275
|
-
return;
|
|
7276
|
-
seen.add(key);
|
|
7277
|
-
out.push({ typeName, package: pkg });
|
|
7278
|
-
};
|
|
7279
|
-
const visit = (type, depth) => {
|
|
7280
|
-
if (!type || depth > 20 || visited.has(type))
|
|
7281
|
-
return;
|
|
7282
|
-
visited.add(type);
|
|
7283
|
-
const symbol = type.aliasSymbol ?? type.getSymbol();
|
|
7284
|
-
consider(symbol);
|
|
7285
|
-
for (const arg of type.aliasTypeArguments ?? [])
|
|
7286
|
-
visit(arg, depth + 1);
|
|
7287
|
-
const typeRef = type;
|
|
7288
|
-
if (typeRef.target) {
|
|
7289
|
-
for (const arg of checker.getTypeArguments(typeRef) ?? [])
|
|
7290
|
-
visit(arg, depth + 1);
|
|
7291
|
-
}
|
|
7292
|
-
if (type.isUnion() || type.isIntersection()) {
|
|
7293
|
-
for (const t of type.types)
|
|
7294
|
-
visit(t, depth + 1);
|
|
7295
|
-
}
|
|
7296
|
-
const fileName = symbol?.declarations?.[0]?.getSourceFile().fileName;
|
|
7297
|
-
if (fileName) {
|
|
7298
|
-
if (isLibFile(fileName))
|
|
7299
|
-
return;
|
|
7300
|
-
const match = fileName.match(NODE_MODULES_PKG2);
|
|
7301
|
-
if (match && !workspacePackages.has(match[1]))
|
|
7302
|
-
return;
|
|
7303
|
-
}
|
|
7304
|
-
if (!(type.flags & ts18.TypeFlags.Object || type.isClassOrInterface()))
|
|
7305
|
-
return;
|
|
7306
|
-
if (type.isClassOrInterface()) {
|
|
7307
|
-
for (const base of checker.getBaseTypes(type) ?? [])
|
|
7308
|
-
visit(base, depth + 1);
|
|
7309
|
-
}
|
|
7310
|
-
for (const prop of type.getProperties()) {
|
|
7311
|
-
if (prop.getName().startsWith("__@"))
|
|
7312
|
-
continue;
|
|
7313
|
-
visit(checker.getTypeOfSymbol(prop), depth + 1);
|
|
7314
|
-
}
|
|
7315
|
-
for (const sig of [...type.getCallSignatures(), ...type.getConstructSignatures()]) {
|
|
7316
|
-
for (const param of sig.getParameters())
|
|
7317
|
-
visit(checker.getTypeOfSymbol(param), depth + 1);
|
|
7318
|
-
visit(sig.getReturnType(), depth + 1);
|
|
7319
|
-
}
|
|
7320
|
-
for (const info of checker.getIndexInfosOfType(type)) {
|
|
7321
|
-
visit(info.type, depth + 1);
|
|
7322
|
-
}
|
|
7323
|
-
};
|
|
7324
|
-
for (const symbol of exportedSymbols) {
|
|
7325
|
-
visit(checker.getTypeOfSymbol(symbol), 0);
|
|
7326
|
-
visit(checker.getDeclaredTypeOfSymbol(symbol), 0);
|
|
7327
|
-
}
|
|
7328
|
-
return out;
|
|
7329
|
-
}
|
|
7330
6997
|
function expandReachableTypes(exportedSymbols, ctx, opts) {
|
|
7331
6998
|
if (opts.followExternal === false)
|
|
7332
6999
|
return;
|
|
@@ -7795,44 +7462,7 @@ async function extract(options) {
|
|
|
7795
7462
|
...included ? {} : { skipReason: "filtered" }
|
|
7796
7463
|
});
|
|
7797
7464
|
}
|
|
7798
|
-
|
|
7799
|
-
let evaluate = options.evaluate;
|
|
7800
|
-
if (followExternal === "auto" && !evaluate && options.decisions !== "jev") {
|
|
7801
|
-
diagnostics.push({
|
|
7802
|
-
message: "followExternal auto requires decisions: 'jev' (or an injected evaluate)",
|
|
7803
|
-
severity: "error",
|
|
7804
|
-
code: "JEV_UNAVAILABLE"
|
|
7805
|
-
});
|
|
7806
|
-
followExternal = undefined;
|
|
7807
|
-
}
|
|
7808
|
-
const wantsJev = options.decisions === "jev";
|
|
7809
|
-
if (wantsJev && !evaluate) {
|
|
7810
|
-
if (process.env.AI_GATEWAY_API_KEY) {
|
|
7811
|
-
try {
|
|
7812
|
-
evaluate = await loadEvaluate();
|
|
7813
|
-
} catch (err) {
|
|
7814
|
-
diagnostics.push({
|
|
7815
|
-
message: err instanceof Error ? err.message : String(err),
|
|
7816
|
-
severity: "error",
|
|
7817
|
-
code: "JEV_UNAVAILABLE"
|
|
7818
|
-
});
|
|
7819
|
-
}
|
|
7820
|
-
} else if (followExternal === "auto") {
|
|
7821
|
-
diagnostics.push({
|
|
7822
|
-
message: "followExternal auto requires --jev and AI_GATEWAY_API_KEY",
|
|
7823
|
-
severity: "error",
|
|
7824
|
-
code: "JEV_UNAVAILABLE"
|
|
7825
|
-
});
|
|
7826
|
-
}
|
|
7827
|
-
}
|
|
7828
|
-
if (followExternal === "auto") {
|
|
7829
|
-
if (!evaluate) {
|
|
7830
|
-
followExternal = undefined;
|
|
7831
|
-
} else {
|
|
7832
|
-
const refs = collectReferencedExternals(exportedSymbols, typeChecker, result.workspacePackages ?? new Map);
|
|
7833
|
-
followExternal = await selectFollowExternal(refs, evaluate);
|
|
7834
|
-
}
|
|
7835
|
-
}
|
|
7465
|
+
const followExternal = options.followExternal;
|
|
7836
7466
|
const ctx = createContext(program, sourceFile, {
|
|
7837
7467
|
maxTypeDepth,
|
|
7838
7468
|
includePrivate,
|
|
@@ -7864,12 +7494,10 @@ async function extract(options) {
|
|
|
7864
7494
|
const allDecls = [...targetSymbol.declarations ?? [], ...symbol.declarations ?? []];
|
|
7865
7495
|
for (const decl of allDecls) {
|
|
7866
7496
|
const sf = decl.getSourceFile();
|
|
7867
|
-
|
|
7868
|
-
|
|
7869
|
-
|
|
7870
|
-
|
|
7871
|
-
break;
|
|
7872
|
-
}
|
|
7497
|
+
const pkg = sf && packageNameFromPath(sf.fileName);
|
|
7498
|
+
if (pkg) {
|
|
7499
|
+
externalPackage = pkg;
|
|
7500
|
+
break;
|
|
7873
7501
|
}
|
|
7874
7502
|
if (ts19.isExportSpecifier(decl)) {
|
|
7875
7503
|
const exportDecl = decl.parent?.parent;
|
|
@@ -8075,9 +7703,6 @@ async function extract(options) {
|
|
|
8075
7703
|
suggestion: "Check serialization errors for these exports"
|
|
8076
7704
|
});
|
|
8077
7705
|
}
|
|
8078
|
-
if (evaluate) {
|
|
8079
|
-
await calibrateDiagnostics(diagnostics, evaluate);
|
|
8080
|
-
}
|
|
8081
7706
|
return {
|
|
8082
7707
|
spec,
|
|
8083
7708
|
diagnostics,
|
|
@@ -8998,8 +8623,6 @@ export {
|
|
|
8998
8623
|
PRIMITIVES,
|
|
8999
8624
|
NUMBER_PROTOTYPE_METHODS,
|
|
9000
8625
|
LATEST_VERSION,
|
|
9001
|
-
JEV_MODEL,
|
|
9002
|
-
JEV_CONFIDENCE,
|
|
9003
8626
|
CacheManager,
|
|
9004
8627
|
CONFIG_FILENAME,
|
|
9005
8628
|
BUILTIN_TYPE_SCHEMAS,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openpkg-ts/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.54.0",
|
|
4
4
|
"description": "TypeScript API extraction SDK - programmatic primitives for OpenPkg specs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"openpkg",
|
|
@@ -48,13 +48,9 @@
|
|
|
48
48
|
"typescript": "^5.0.0 || ^6.0.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"ai": "^7.0.105",
|
|
52
51
|
"shiki": "^1.0.0"
|
|
53
52
|
},
|
|
54
53
|
"peerDependenciesMeta": {
|
|
55
|
-
"ai": {
|
|
56
|
-
"optional": true
|
|
57
|
-
},
|
|
58
54
|
"shiki": {
|
|
59
55
|
"optional": true
|
|
60
56
|
}
|