@openpkg-ts/extract 0.24.0 → 0.24.1
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/bin/tspec.js
CHANGED
|
@@ -1722,13 +1722,14 @@ function getInheritedMembers(classType, ownMemberNames, ctx, isStatic = false) {
|
|
|
1722
1722
|
const { typeChecker: checker } = ctx;
|
|
1723
1723
|
const inherited = [];
|
|
1724
1724
|
const visited = new Set;
|
|
1725
|
+
const inheritedNames = new Set;
|
|
1725
1726
|
const typeToWalk = isStatic ? classType.getSymbol()?.valueDeclaration && checker.getTypeOfSymbolAtLocation(classType.getSymbol(), classType.getSymbol().valueDeclaration) : classType;
|
|
1726
1727
|
if (!typeToWalk)
|
|
1727
1728
|
return inherited;
|
|
1728
|
-
walkBaseTypes(typeToWalk, ownMemberNames, inherited, visited, ctx, isStatic);
|
|
1729
|
+
walkBaseTypes(typeToWalk, ownMemberNames, inherited, inheritedNames, visited, ctx, isStatic);
|
|
1729
1730
|
return inherited;
|
|
1730
1731
|
}
|
|
1731
|
-
function walkBaseTypes(type, ownMemberNames, inherited, visited, ctx, isStatic) {
|
|
1732
|
+
function walkBaseTypes(type, ownMemberNames, inherited, inheritedNames, visited, ctx, isStatic) {
|
|
1732
1733
|
if (visited.has(type))
|
|
1733
1734
|
return;
|
|
1734
1735
|
visited.add(type);
|
|
@@ -1742,16 +1743,17 @@ function walkBaseTypes(type, ownMemberNames, inherited, visited, ctx, isStatic)
|
|
|
1742
1743
|
const propName = prop.getName();
|
|
1743
1744
|
if (ownMemberNames.has(propName))
|
|
1744
1745
|
continue;
|
|
1745
|
-
if (
|
|
1746
|
+
if (inheritedNames.has(propName))
|
|
1746
1747
|
continue;
|
|
1747
1748
|
if (propName.startsWith("#") || propName.startsWith("__"))
|
|
1748
1749
|
continue;
|
|
1749
1750
|
const member = serializeInheritedMember(prop, baseName, ctx, isStatic);
|
|
1750
1751
|
if (member) {
|
|
1751
1752
|
inherited.push(member);
|
|
1753
|
+
inheritedNames.add(propName);
|
|
1752
1754
|
}
|
|
1753
1755
|
}
|
|
1754
|
-
walkBaseTypes(baseType, ownMemberNames, inherited, visited, ctx, isStatic);
|
|
1756
|
+
walkBaseTypes(baseType, ownMemberNames, inherited, inheritedNames, visited, ctx, isStatic);
|
|
1755
1757
|
}
|
|
1756
1758
|
}
|
|
1757
1759
|
function getStaticMembers(classType, checker) {
|
|
@@ -3092,6 +3094,24 @@ function mergeRuntimeSchemas(staticExports, runtimeSchemas) {
|
|
|
3092
3094
|
}
|
|
3093
3095
|
|
|
3094
3096
|
// src/builder/spec-builder.ts
|
|
3097
|
+
var typeDefinitionCache = null;
|
|
3098
|
+
function getTypeDefinitionCache() {
|
|
3099
|
+
if (!typeDefinitionCache) {
|
|
3100
|
+
typeDefinitionCache = new Map;
|
|
3101
|
+
}
|
|
3102
|
+
return typeDefinitionCache;
|
|
3103
|
+
}
|
|
3104
|
+
var internalTagCache = null;
|
|
3105
|
+
function getInternalTagCache() {
|
|
3106
|
+
if (!internalTagCache) {
|
|
3107
|
+
internalTagCache = new Map;
|
|
3108
|
+
}
|
|
3109
|
+
return internalTagCache;
|
|
3110
|
+
}
|
|
3111
|
+
function clearTypeDefinitionCache() {
|
|
3112
|
+
typeDefinitionCache = null;
|
|
3113
|
+
internalTagCache = null;
|
|
3114
|
+
}
|
|
3095
3115
|
var BUILTIN_TYPES2 = new Set([
|
|
3096
3116
|
"Array",
|
|
3097
3117
|
"ArrayBuffer",
|
|
@@ -3176,6 +3196,7 @@ function shouldSkipDanglingRef(name) {
|
|
|
3176
3196
|
return false;
|
|
3177
3197
|
}
|
|
3178
3198
|
async function extract(options) {
|
|
3199
|
+
clearTypeDefinitionCache();
|
|
3179
3200
|
const {
|
|
3180
3201
|
entryFile,
|
|
3181
3202
|
baseDir,
|
|
@@ -3237,7 +3258,8 @@ async function extract(options) {
|
|
|
3237
3258
|
const meta = await getPackageMeta(entryFile, baseDir);
|
|
3238
3259
|
const types = ctx.typeRegistry.getAll();
|
|
3239
3260
|
const projectBaseDir = baseDir ?? path3.dirname(entryFile);
|
|
3240
|
-
const
|
|
3261
|
+
const definedTypes = new Set(types.map((t) => t.id));
|
|
3262
|
+
const forgottenExports = collectForgottenExports(exports, types, program, sourceFile, exportedIds, projectBaseDir, definedTypes);
|
|
3241
3263
|
for (const forgotten of forgottenExports) {
|
|
3242
3264
|
const refSummary = forgotten.referencedBy.slice(0, 3).map((r) => `${r.exportName} (${r.location})`).join(", ");
|
|
3243
3265
|
const moreRefs = forgotten.referencedBy.length > 3 ? ` +${forgotten.referencedBy.length - 3} more` : "";
|
|
@@ -3320,10 +3342,9 @@ function collectAllRefsWithContext(obj, refs, state) {
|
|
|
3320
3342
|
return;
|
|
3321
3343
|
if (Array.isArray(obj)) {
|
|
3322
3344
|
for (let i = 0;i < obj.length; i++) {
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
});
|
|
3345
|
+
state.path.push(`[${i}]`);
|
|
3346
|
+
collectAllRefsWithContext(obj[i], refs, state);
|
|
3347
|
+
state.path.pop();
|
|
3327
3348
|
}
|
|
3328
3349
|
return;
|
|
3329
3350
|
}
|
|
@@ -3336,31 +3357,34 @@ function collectAllRefsWithContext(obj, refs, state) {
|
|
|
3336
3357
|
typeName,
|
|
3337
3358
|
exportName: state.exportName,
|
|
3338
3359
|
location: state.location,
|
|
3339
|
-
path: state.path.join(".")
|
|
3360
|
+
path: state.path.length > 0 ? state.path.join(".") : undefined
|
|
3340
3361
|
});
|
|
3341
3362
|
refs.set(typeName, existing);
|
|
3342
3363
|
}
|
|
3364
|
+
const prevLocation = state.location;
|
|
3343
3365
|
for (const [key, value] of Object.entries(record)) {
|
|
3344
|
-
let newLocation = state.location;
|
|
3345
3366
|
if (key === "returnType" || key === "returns")
|
|
3346
|
-
|
|
3367
|
+
state.location = "return";
|
|
3347
3368
|
else if (key === "parameters" || key === "params")
|
|
3348
|
-
|
|
3369
|
+
state.location = "parameter";
|
|
3349
3370
|
else if (key === "properties" || key === "members")
|
|
3350
|
-
|
|
3371
|
+
state.location = "property";
|
|
3351
3372
|
else if (key === "extends" || key === "implements")
|
|
3352
|
-
|
|
3373
|
+
state.location = "extends";
|
|
3353
3374
|
else if (key === "typeParameters" || key === "typeParams")
|
|
3354
|
-
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3358
|
-
|
|
3359
|
-
});
|
|
3375
|
+
state.location = "type-parameter";
|
|
3376
|
+
state.path.push(key);
|
|
3377
|
+
collectAllRefsWithContext(value, refs, state);
|
|
3378
|
+
state.path.pop();
|
|
3379
|
+
state.location = prevLocation;
|
|
3360
3380
|
}
|
|
3361
3381
|
}
|
|
3362
3382
|
}
|
|
3363
3383
|
function findTypeDefinition(typeName, program, sourceFile) {
|
|
3384
|
+
const cache = getTypeDefinitionCache();
|
|
3385
|
+
if (cache.has(typeName)) {
|
|
3386
|
+
return cache.get(typeName);
|
|
3387
|
+
}
|
|
3364
3388
|
const checker = program.getTypeChecker();
|
|
3365
3389
|
const findInNode = (node) => {
|
|
3366
3390
|
if ((ts11.isInterfaceDeclaration(node) || ts11.isTypeAliasDeclaration(node) || ts11.isClassDeclaration(node) || ts11.isEnumDeclaration(node)) && node.name?.text === typeName) {
|
|
@@ -3370,19 +3394,26 @@ function findTypeDefinition(typeName, program, sourceFile) {
|
|
|
3370
3394
|
return ts11.forEachChild(node, findInNode);
|
|
3371
3395
|
};
|
|
3372
3396
|
const entryResult = findInNode(sourceFile);
|
|
3373
|
-
if (entryResult)
|
|
3397
|
+
if (entryResult) {
|
|
3398
|
+
cache.set(typeName, entryResult);
|
|
3374
3399
|
return entryResult;
|
|
3400
|
+
}
|
|
3375
3401
|
for (const sf of program.getSourceFiles()) {
|
|
3376
3402
|
if (sf.isDeclarationFile && !sf.fileName.includes("node_modules")) {
|
|
3377
3403
|
const result = findInNode(sf);
|
|
3378
|
-
if (result)
|
|
3404
|
+
if (result) {
|
|
3405
|
+
cache.set(typeName, result);
|
|
3379
3406
|
return result;
|
|
3407
|
+
}
|
|
3380
3408
|
}
|
|
3381
3409
|
}
|
|
3382
3410
|
const symbol = checker.resolveName(typeName, sourceFile, ts11.SymbolFlags.Type, false);
|
|
3383
3411
|
if (symbol?.declarations?.[0]) {
|
|
3384
|
-
|
|
3412
|
+
const result = symbol.declarations[0].getSourceFile().fileName;
|
|
3413
|
+
cache.set(typeName, result);
|
|
3414
|
+
return result;
|
|
3385
3415
|
}
|
|
3416
|
+
cache.set(typeName, undefined);
|
|
3386
3417
|
return;
|
|
3387
3418
|
}
|
|
3388
3419
|
function isExternalType2(definedIn, baseDir) {
|
|
@@ -3395,15 +3426,23 @@ function isExternalType2(definedIn, baseDir) {
|
|
|
3395
3426
|
return !normalizedDefined.startsWith(normalizedBase);
|
|
3396
3427
|
}
|
|
3397
3428
|
function hasInternalTag(typeName, program, sourceFile) {
|
|
3429
|
+
const cache = getInternalTagCache();
|
|
3430
|
+
const cached = cache.get(typeName);
|
|
3431
|
+
if (cached !== undefined) {
|
|
3432
|
+
return cached;
|
|
3433
|
+
}
|
|
3398
3434
|
const checker = program.getTypeChecker();
|
|
3399
3435
|
const symbol = checker.resolveName(typeName, sourceFile, ts11.SymbolFlags.Type, false);
|
|
3400
|
-
if (!symbol)
|
|
3436
|
+
if (!symbol) {
|
|
3437
|
+
cache.set(typeName, false);
|
|
3401
3438
|
return false;
|
|
3439
|
+
}
|
|
3402
3440
|
const jsTags = symbol.getJsDocTags();
|
|
3403
|
-
|
|
3441
|
+
const isInternal = jsTags.some((tag) => tag.name === "internal");
|
|
3442
|
+
cache.set(typeName, isInternal);
|
|
3443
|
+
return isInternal;
|
|
3404
3444
|
}
|
|
3405
|
-
function collectForgottenExports(exports, types, program, sourceFile, exportedIds, baseDir) {
|
|
3406
|
-
const definedTypes = new Set(types.map((t) => t.id));
|
|
3445
|
+
function collectForgottenExports(exports, types, program, sourceFile, exportedIds, baseDir, definedTypes) {
|
|
3407
3446
|
const referencedTypes = new Map;
|
|
3408
3447
|
for (const exp of exports) {
|
|
3409
3448
|
collectAllRefsWithContext(exp, referencedTypes, {
|
package/dist/src/index.js
CHANGED